i
i
i
i
i
i
i
i
558 12. Polygonal Techniques
mat. The format specifies whether a vertex contains diffuse or specular
colors, a normal, texture coordinates, etc. The size in bytes of a vertex is
called its stride. Alternately, a set of vertex streams can be used. For ex-
ample, one stream could hold an array of positions p
0
p
1
p
2
...and another
a separate array of normals n
0
n
1
n
2
.... In practice, a single buffer contain-
ing all data for each vertex is generally more efficient on modern GPUs,
but not so much that multiple streams should be avoided [1065]. Multiple
streams can help save storage and transfer time. For example, six house
models with different lighting due to their surroundings could be repre-
sented by six meshes with a different set of illumination colors at each mesh
vertex, merged with a single mesh with positions, normals, and texture
coordinates.
How the vertex buffer is accessed is up to the device’s DrawPrimitive
method. The data can be treated as:
1. A list of individual points.
2. A list of unconnected line segments, i.e., pairs of vertices.
3. A single polyline.
4. A triangle list, where each group of three vertices forms a triangle,
e.g., vertices [0, 1, 2] form one, [3, 4, 5] form the next, etc.
5. A triangle fan, where the first vertex forms a triangle with each suc-
cessive pair of vertices, e.g., [0, 1, 2], [0, 2, 3], [0, 3, 4].
6. A triangle strip, where every group of three contiguous vertices forms
a triangle, e.g., [0, 1, 2], [1, 2, 3], [2, 3, 4].
In DirectX 10, triangles and triangle strips can also include adjacent trian-
gle vertices, for use by the geometry shader (see Section 3.5).
The indices in an index buffer point to vertices in a vertex buffer. The
combination of an index buffer and vertex buffer is used to display the
same types of draw primitives as a “raw” vertex buffer. The difference
is that each vertex in the index/vertex buffer combination needs to be
stored only once in its vertex buffer, versus repetition that can occur in a
vertex buffer without indexing. For example, the triangle mesh structure
can be represented by an index buffer; the first three indices stored in the
index buffer specify the first triangle, the next three the second, etc. See
Figure 12.19 for examples of vertex and index buffer structures.
Which structure to use is dictated by the primitives and the program.
Displaying a simple rectangle is easily done with a vertex buffer using four
vertices as a two-triangle tristrip. One advantage of the index buffer is data
sharing. In the previous section the post-transform cache was explained,