Graphics Reference
In-Depth Information
glBufferData
will reserve appropriate data storage based on the value of
size
.
The
data
argument can be a
NULL
value, indicating that the reserved data store
remains uninitialized. If
data
is a valid pointer, then the contents of
data
are
copied to the allocated data store. The contents of the buffer object data store
can be initialized or updated using the
glBufferSubData
command.
void
glBufferSubData
(GLenum
target
, GLintptr
offset
,
GLsizeiptr
size
, const void *
data
)
target
can be set to any of the following targets:
GL_ARRAY_BUFFER
GL_ELEMENT_ARRAY_BUFFER
GL_COPY_READ_BUFFER
GL_COPY_WRITE_BUFFER
GL_PIXEL_PACK_BUFFER
GL_PIXEL_UNPACK_BUFFER
GL_TRANSFORM_FEEDBACK_BUFFER
GL_UNIFORM_BUFFER
offset
offset into the buffer data store and number of bytes of the
size
data store that is being modified
data
pointer to the client data that need to be copied into the
buffer object data storage
After the buffer object data store has been initialized or updated using
glBufferData
or
glBufferSubData
, the client data store is no longer
needed and can be released. For static geometry, applications can free the
client data store and reduce the overall system memory consumed by the
application. This might not be possible for dynamic geometry.
We now look at drawing primitives with and without buffer objects.
Example 6-5 describes drawing primitives with and without vertex buffer
objects. Notice that the code to set up the vertex attributes is very similar.
In this example, we use the same buffer object for all attributes of a vertex.
When a
GL_ARRAY_BUFFER
buffer object is used, the
pointer
argument
in
glVertexAttribPointer
changes from being a pointer to the actual
data to being an offset in bytes into the vertex buffer store allocated using
glBufferData
. Similarly, if a valid
GL_ELEMENT_ARRAY_BUFFER
object
is used, the
indices
argument in
glDrawElements
changes from being
a pointer to the actual element indices to being an offset in bytes to the
element index buffer store allocated using
glBufferData
.