Graphics Reference
In-Depth Information
Example 6-6
Drawing with a Buffer Object per Attribute
(continued)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, userData->vboIds[2]);
glDrawElements(GL_TRIANGLES, numIndices,
GL_UNSIGNED_SHORT, 0);
glDisableVertexAttribArray(VERTEX_POS_INDX);
glDisableVertexAttribArray(VERTEX_COLOR_INDX);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
After the application has finished using the buffer objects, they can be
deleted using the
glDeleteBuffers
command.
void
glDeleteBuffers
(GLsizei
n
, const GLuint *
buffers
)
n
number of buffer objects to be deleted
buffers
array of
n
entries that contain the buffer objects to be deleted
glDeleteBuffers
deletes the buffer objects specified in buffers. Once
a buffer object has been deleted, it can be reused as a new buffer object
that stores vertex attributes or element indices for a different primitive.
As you can see from these examples, using vertex buffer objects
is very easy and requires very little extra work to implement over
vertex arrays. The minimal extra work involved in supporting
vertex buffer objects is well worth it, considering the performance
gain this feature provides. In the next chapter, we discuss how
to draw primitives using commands such as
glDrawArrays
and
glDrawElements
, and how the primitive assembly and rasterization
pipeline stages in OpenGL ES 3.0 work.
So far, we have covered how to load vertex attributes in two different
ways: using client vertex arrays and using vertex buffer objects. Vertex
buffer objects are preferred to client vertex arrays because they can reduce
the amount of data copied between the CPU and GPU and, therefore,
have better performance. In OpenGL ES 3.0, a new feature was introduced