FirstPerson.MeshBuffer.GenerateBuffers C# (CSharp) Method

GenerateBuffers() public method

public GenerateBuffers ( ) : void
return void
        public void GenerateBuffers()
        {
            if (VertexData != null)
            {
                GL.GenBuffers(1, out VertexBufferID);
                GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferID);
                GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
                                       new IntPtr(VertexData.Length * Vector3.SizeInBytes),
                                       VertexData, BufferUsageHint.StaticDraw);
            }

            if (NormalData != null)
            {
                GL.GenBuffers(1, out NormalBufferID);
                GL.BindBuffer(BufferTarget.ArrayBuffer, NormalBufferID);
                GL.BufferData<Vector3>(BufferTarget.ArrayBuffer,
                                       new IntPtr(NormalData.Length * Vector3.SizeInBytes),
                                       NormalData, BufferUsageHint.StaticDraw);
            }

            if (ColorData != null)
            {
                GL.GenBuffers(1, out ColorBufferID);
                GL.BindBuffer(BufferTarget.ArrayBuffer, ColorBufferID);
                GL.BufferData<int>(BufferTarget.ArrayBuffer,
                                   new IntPtr(ColorData.Length * sizeof(int)),
                                   ColorData, BufferUsageHint.StaticDraw);
            }

            if (IndicesData != null)
            {
                GL.GenBuffers(1, out IndicesBufferID);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndicesBufferID);
                GL.BufferData<uint>(BufferTarget.ElementArrayBuffer,
                                    new IntPtr(IndicesData.Length * sizeof(uint)),
                                    IndicesData, BufferUsageHint.StaticDraw);
            }

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
        }

Usage Example

Exemplo n.º 1
0
 public static MeshBuffer Generate(Vector3[] vertexData, Vector3[] normalData, int[] colorData, uint[] indicesData)
 {
     var meshBuffer = new MeshBuffer(vertexData, normalData, colorData, indicesData);
     meshBuffer.GenerateBuffers();
     return meshBuffer;
 }