Graphics Reference
In-Depth Information
to make using vertex arrays even more efficient: vertex array objects
(VAOs). As we have seen, setting up drawing using vertex buffer objects
can require many calls to glBindBuffer , glVertexAttribPointer , and
glEnableVertexAttribArray . To make it faster to switch between vertex
array configurations, OpenGL ES 3.0 introduced vertex array objects. VAOs
provide a single object that contains all of the state required to switch
between vertex array/vertex buffer object configurations.
In fact, there is always a vertex array object that is active in OpenGL
ES 3.0. All of the examples so far in this chapter have operated on the
default vertex array object (the default VAO has the ID of 0). To create a
new vertex array object, you use the glGenVertexArrays function.
void glGenVertexArrays (GLsizei n , GLuint * arrays )
n
number of vertex array object names to return
arrays
pointer to an array of n entries, where allocated vertex
array objects are returned
Once created, the vertex array object can be bound for use using
glBindVertexArray .
void glBindVertexArray (GLuint array )
array
object to be assigned as the current vertex array object
Each VAO contains a full state vector that describes all of the vertex
buffer bindings and vertex client state enables. When the VAO is
bound, its state vector provides the current settings of the vertex buffer
state. After binding the vertex array object using glBindVertexArray ,
subsequent calls that change the vertex array state ( glBindBuffer,
glVertexAttribPointer, glEnableVertexAttribArray , and
glDisableVertexAttribArray ) will affect the new VAO.
In this way, an application can quickly switch between vertex array
configurations by binding a vertex array object that has been set with
state. Rather than having to make many calls to change the vertex array
state, all of the changes can be made in a single function call. Example 6-7
demonstrates the use of a vertex array object at initialization time to set
up the vertex array state. The vertex array state is then set in a single
function call at draw time using glBindVertexArray .
 
 
Search WWH ::




Custom Search