3.c Vertex Arrays

Vertex Arrays were removed from OpenGL in version 3.1. Vertex Buffer Objects are the recommended alternative, since they are both faster and safer.

This is the correct way to use Vertex Arrays in .Net (pseudocode):

struct Vertex
    public Vector3 Position;
    public Vector2 TexCoord;
Vertex[] vertices = new Vertex[100];
    fixed (float* pvertices = vertices)
        GL.VertexPointer(3, VertexPointerType.Float, BlittableValueType.StrideOf(vertices), pvertices);
        GL.TexCoordPointer(2, VertexPointerType.Float, BlittableValueType.StrideOf(vertices), pvertices + sizeof(Vector3));
        GL.DrawArrays(BeginMode.Triangles, 0, vertices.Length);
        GL.Finish();    // Force OpenGL to finish rendering while the arrays are still pinned.

Vertex Arrays use client storage, because they are stored in system memory (not video memory). Since .Net is a Garbage Collected environment, the arrays must remain pinned until the GL.DrawArrays() or GL.DrawElements() call is complete.

If the arrays are unpinned prematurely, they may be moved or collected by the Garbage Collector before the draw call finishes. This will lead to random access violation exceptions and corrupted rendering, issues which can be difficult to trace.

Due to the asynchronous nature of OpenGL, GL.Finish() must be used to ensure that rendering is complete before the arrays are unpinned. However, this call introduces a sync point between the CPU and GPU, which can significantly degrade performance.

Vertex Buffer Objects and Display Lists use server storage (video memory) which does not suffer from this issue. Given the improved performance and safety of server storage, it is recommended to avoid Vertex Arrays completely.

Please visit this discussion in the forum for more information.