Esempio n. 1
0
        /// <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();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the buffers in GPU memory.
        /// </summary>
        /// <param name="gl">The GL.</param>
        public void UpdateGeometry(OpenGL gl)
        {
            var verts = Vertices.SelectMany(v => v.to_array()).ToArray();
            var norms = Normals.SelectMany(v => v.to_array()).ToArray();

            VertexBuffer.BindBuffer(gl);                                                      // gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, VertexBufferId.Value);
            VertexBuffer.SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, verts, Usage, 3); // gl.BufferData(OpenGL.GL_ARRAY_BUFFER, verts, (uint)Usage);
            NormalBuffer.BindBuffer(gl);                                                      // gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, NormalBufferId.Value);
            NormalBuffer.SetBufferData(gl, OGLBufferDataTarget.ArrayBuffer, norms, Usage, 3); // gl.BufferData(OpenGL.GL_ARRAY_BUFFER, norms, (uint)Usage);
        }