Game Development Reference
In-Depth Information
This only creates the object's name and the reference to the object. To actually create
the object itself, you must bind it to the context.
The bindBuffer() function is invoked to tell on which of the buffer objects the
subsequent functions will operate on. This function is called as follows:
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
The target hint can be ARRAY_BUFFER (vertex buffers).
There are many allocated buffer objects. We need to specify which buffer object we
want to apply the next set of operations on. The bindBuffer() function is used to
make a particular buffer object the current array buffer object or the current element
array buffer object so that the subsequent operations are applied on that buffer
object. The first time the buffer object's name is bound by calling the bindBuffer()
function, the buffer object is allocated with the appropriate default state, and if the
allocation is successful, this allocated object is bound as the current array buffer
object or the current element array buffer object for the rendering context.
However, the actual memory is only allocated when we invoke the
gl.bufferData() API call:
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices),
gl.STATIC_DRAW);
The third parameter in the bufferData API call specifies how to use the buffer
object. The following table explains the different enum values and their usages. In
our topic, we will use the gl.STATIC_DRAW value, but in cases where you might need
to animate individual vertices, you will use the gl.DYNAMIC_DRAW value:
Enum value
Usage
STATIC_DRAW
The buffer object data will be specified by the application
once and used many times to draw primitives.
DYNAMIC_DRAW
The buffer object data will be specified by the application
repeatedly and used many times to draw primitives.
STREAM_DRAW
The buffer object data will be specified by the application
once and used a few times to draw primitives.
The gl.bufferData() API call does not take reference of
the buffer object as a parameter. We do not pass the object
reference because operations are performed on the current
array buffer object or the current element array buffer object.
Search WWH ::




Custom Search