Graphics Reference
In-Depth Information
The index of the first input assembler vertex buffer slot to begin binding to, and
how many subsequent buffer slots should be bound, are specified in the StartSlot and
NumBuffers parameters. The list of vertex buffer resource pointers must be assembled
into a contiguous array, and is passed in the ppVertexBuffers parameter. The final two
parameters, pStrides and pOffsets, allow the application to specify the per-vertex step
size for each vertex buffer, as well as an offset to the desired location to begin using each
vertex buffer. Each of these array elements will start being used at the StartSlot index
and will be used to fill NumBuff ens number of slots. This means that the arrays must be
appropriately sized and filled in, or the function will access an invalid memory location. In
addition, to bind the vertex buffers to the input assembler, the buffers must not be bound
for writing at another location in the pipeline. This is a reasonable requirement, since it
would lead to seemingly unpredictable results, with buffers being read from and written to
at the same time.
Index Buffer Usage
When taken on its own, vertex data is interpreted by the input assembler in the order that it
appears within the vertex buffers. This means that if the vertex data is being used to render
triangles, the first three vertices define the first triangle, followed by the next three vertices
for the next triangle, and so on. 5 This can lead to duplicated vertex data in cases where two
adjacent triangles actually reference the same vertex. In fact, this is usually the case—most
triangle meshes have a significant number of adjacent triangles. When the individual vertex
data is specified more than once in the vertex buffer, significant amounts of memory can be
wasted. This inefficiency can be eliminated with the use of index buffers. An index buffer
is used to define the vertex order for each primitive by providing index offsets into the ver-
tex buffers. In this case, each vertex can be specified once, and then an index that points to
it can be used for any triangle that it is a part of. With indexed rendering, the three vertices
to be used in a triangle are specified by three consecutive indices in the index buffer.
To use indexed rendering, an application must bind an index buffer to the input as-
sembler. There is only one slot available for binding an index buffer, and it is only used
during one of the indexed draw calls to specify the order of the vertices used to generate
primitives. To bind the index buffer to the input assembler, the application must use the
ID3DllDeviceContext: :IASetIndexBuffer method. Listing 3.3 demonstrates how to
perform this binding operation. This method provides three simple parameters: a pointer
to the index buffer, the format that the indices are stored in (either 16- or 32-bit unsigned
integers), and finally an offset into the index buffer to begin building primitives from.
5 The ordering of vertices and indices will vary for different primitive types. These are described in more detail
later in this section.
Search WWH ::




Custom Search