Afterglow.Graphics.OpenTK.ApiExamples.QuadWithBuffers.LoadBuffers C# (CSharp) Method

LoadBuffers() private method

private LoadBuffers ( Vector3 vertices, uint indices, Vector3 colors ) : void
vertices Vector3
indices uint
colors Vector3
return void
        private void LoadBuffers(Vector3[] vertices, uint[] indices, Vector3[] colors)
        {
            int size;

            GL.GenBuffers(1, out mVertexBufferId);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mVertexBufferId);
            GL.BufferData(BufferTarget.ArrayBuffer,
                (IntPtr)(vertices.Length * Vector3.SizeInBytes), vertices,
                BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize,
                out size);
            if (vertices.Length * Vector3.SizeInBytes != size)
            {
                throw new ApplicationException("Vertex array not uploaded correctly");
            }

            GL.GenBuffers(1, out mIndexBufferId);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, mIndexBufferId);
            GL.BufferData(BufferTarget.ElementArrayBuffer,
                (IntPtr)(indices.Length * sizeof (uint)), indices,
                BufferUsageHint.StaticDraw);
            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (indices.Length * sizeof (int) != size)
            {
                throw new ApplicationException("Element array not uploaded correctly");
            }

            GL.GenBuffers(1, out mColorBufferId);
            GL.BindBuffer(BufferTarget.ArrayBuffer, mColorBufferId);
            GL.BufferData(BufferTarget.ArrayBuffer,
                (IntPtr)(colors.Length * Vector3.SizeInBytes), colors,
                BufferUsageHint.StaticDraw);

            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize,
                out size);
            if (colors.Length * Vector3.SizeInBytes != size)
            {
                throw new ApplicationException("Vertex array not uploaded correctly");
            }
        }