public BufferGroup(IBO ibo, IEnumerable<VBO> vbos)
 {
     Ibo = ibo;
     Vbos.AddRange(vbos);
 }
示例#2
0
 public BufferGroup(IBO ibo, IEnumerable <VBO> vbos)
 {
     Ibo = ibo;
     Vbos.AddRange(vbos);
 }
        /// <summary>
        /// Generates the vertices, normals and indices and creates them for the OpenGL.
        /// This method has to be called once before drawing. 
        /// </summary>
        /// <param name="gl"></param>
        public void GenerateGeometry(OpenGL gl, OGLModelUsage usage)
        {
            GL = gl;
            _usage = usage;

            // Create the data buffers.
            var buffers = OGLBufferId.CreateBufferIds(gl, 3);
            IndexBuffer = new IBO(buffers[0]);
            NormalBuffer = new VBO(buffers[1]);
            VertexBuffer = new VBO(buffers[2]);

            if (AutoCalculateNormals)
            {
                CalculateNormals();
            }

            var vertData = Vertices.SelectMany(v => v.to_array()).ToArray();
            VertexBuffer.BindBuffer(gl); // GL.BindBuffer(OpenGL.GL_ARRAY_BUFFER, VertexBuffer.Buffer.Value);
            VertexBuffer.SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, vertData, usage, 3); // GL.BufferData(OpenGL.GL_ARRAY_BUFFER, vertData, (uint)usage);

            var normData = Normals.SelectMany(v => v.to_array()).ToArray();
            NormalBuffer.BindBuffer(gl); //GL.BindBuffer(OpenGL.GL_ARRAY_BUFFER, NormalBuffer.Buffer.Value);
            NormalBuffer.SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, normData, usage, 3); // GL.BufferData(OpenGL.GL_ARRAY_BUFFER, normData, (uint)usage);

            IndexBuffer.BindBuffer(gl); // GL.BindBuffer(OpenGL.GL_ARRAY_BUFFER, IndexBuffer.Buffer.Value);
            IndexBuffer.SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, Indices, usage, 1); // GL.BufferData(OpenGL.GL_ARRAY_BUFFER, Indices, (uint)usage);

            if (new OGLModelUsage[]{OGLModelUsage.StaticCopy, OGLModelUsage.StaticDraw, OGLModelUsage.StaticRead}.Contains(usage))
            {
                ClearStaticData();
            }
        }