Graphics Reference
In-Depth Information
(continued)
sequentially. If stride is greater than 0, then we use the
stride value as the pitch to get vertex data for next index.
pointer to the buffer holding vertex attribute data if using
a client-side vertex array. If using a vertex buffer object,
specifies an offset into that buffer.
ptr
Next, we present a few examples that illustrate how to specify vertex
attributes with glVertexAttribPointer . Two methods are commonly
used for allocating and storing vertex attribute data:
• Store vertex attributes together in a single buffer—a method called an
array of structures. The structure represents all attributes of a vertex,
and we have an array of these attributes per vertex.
• Store each vertex attribute in a separate buffer—a method called a
structure of arrays.
Suppose each vertex has four vertex attributes—position, normal, and two
texture coordinates—and these attributes are stored together in one buffer
that is allocated for all vertices. The vertex position attribute is specified
as a vector of three floats ( x , y , z), the vertex normal is also specified as a
vector of three floats, and each texture coordinate is specified as a vector
of two floats. Figure 6-2 gives the memory layout of this buffer. In this
case, the stride of the buffer is the combined size of all attributes that
make up the vertex (one vertex is equal to 10 floats or 40 bytes - 12 bytes
for Position, 12 bytes for Normal, 8 bytes for Tex0, and 8 bytes for Tex1).
x y z x y z s t s t
x y z x y z s t s t
Position Normal Tex0 Tex1
Position Normal Tex0 Tex1
Figure 6-2
Position, Normal, and Two Texture Coordinates Stored as an Array
Example 6-1 describes how these four vertex attributes are specified with
glVertexAttribPointer . Note that we are illustrating how to use client-
side vertex arrays here so that we can explain the concept of specifying
per-vertex data. We recommend that applications use vertex buffer
objects (described later in the chapter) and avoid client-side vertex arrays
to achieve best performance. Client-side vertex arrays are supported in
OpenGL ES 3.0 only for backward compatibility with OpenGL ES 2.0. In
OpenGL ES 3.0, vertex buffer objects are always recommended.
 
Search WWH ::




Custom Search