Graphics Programs Reference
In-Depth Information
▪
GL_STREAM_DRAW
These values are defined as static constants in the
android.opengl.GLES20
class. They provide a hint to OpenGL ES on how the application is going to
use the data stored in the buffer object. Of these values,
GL_STATIC_DRAW
and
GL_DYNAMIC_DRAW
are most commonly used.
As the name suggests,
GL_STATIC_DRAW
is used when the application does not
modify the data stored in the buffer object, whereas
GL_DYNAMIC_DRAW
is used
when the buffer object data is specified repeatedly by the application (and used many
times to draw primitives). In the context of the
Tank Fence
game, only missiles use
the
GL_DYNAMIC_DRAW
buffer usage. The buffer object corresponding to missiles
undergoes rewrites in a repeated manner, so as to update the vertex data (and the cor-
responding indices) representing the centers of missiles. The remaining objects in
this game (that is, the plane, enemy, and player) use the
GL_STATIC_DRAW
buffer
usage.
Note
We will work with the missile objects in
Chapter 6
. They are
introduced here so you can understand the GL_DYNAMIC_DRAW
buffer usage.
So far, we've only looked at how buffer objects are generated and then filled with
corresponding data. We still have not discussed the way in which buffer objects' data
is passed to the
shaders
(to be specific, a vertex shader).
Listing 5-2
shows that doing
so is quite easy and almost similar to how you have been passing data (per-vertex
and index data) without the use of buffer objects.
Passing a buffer object's data (to the
shaders
) also requires you to make this buffer
ableVertexAttribArray
to activate the given attribute location. You may
requires you to explicitly specify the
FloatBuffer
(
java.nio.FloatBuffer
). This is because calling
glBindBuffer
makes
the specified buffer object (as in this case,
array buffer object
) the current buffer
object. Similarly,
glDrawElements
does not require you to explicitly specify
Search WWH ::
Custom Search