4. Vertex Array Objects

Vertex Array Objects (abbreviation: VAO) are storing vertex attribute setup and VBO related state. This allows to reduce the number of OpenGL calls when drawing from VBOs, because all attribute declaration and pointer setup only needs to be done once (ideally at initialization time) and is afterwards stored in the VAO for later re-use.

But before a VAO can be bound, a handle must be generated:

void GL.GenVertexArrays( uint[] );
void GL.DeleteVertexArrays( uint[] );
bool GL.IsVertexArray( uint );

Binding a VAO is as simple as

void GL.BindVertexArray( uint );

The currently bound VAO records state set by the following commands:

GL.EnableVertexAttribArray()
GL.DisableVertexAttribArray()
GL.VertexAttribPointer()
GL.VertexAttribIPointer()

Indirectly it also saves the state set by GL.BindBuffer() at the point of time when GL.VertexAttribPointer() was called. A more technical description can be found at the OpenGL Wiki.

An example usage:

Initialization:

uint VboHandle;
uint VaoHandle;
 
GL.GenVertexArrays(1, out VaoHandle);
GL.GenBuffers(1, out VboHandle);
 
GL.BindVertexArray(VaoHandle);                     //Make sure to call BindVertexArray() before BindBuffer()
GL.BindBuffer(BufferTarget.ArrayBuffer, VboHandle);
 
GL.BufferData(...);
 
GL.EnableClientState(...);
GL.VertexPointer(...);
GL.EnableVertexAttribArray(...);
 
GL.BindVertexArray(0);

Drawing:

GL.BindVertexArray(VaoHandle);
///Drawing code here
GL.BindVertexArray(0);