Graphics Reference
In-Depth Information
cached and reused by multiple primitives. This can potentially reduce the amount of vertex
shader processing required for a given model.
Using index buffers. Since the index buffer specifies which vertices are to be used in the
primitive setup operations, you must know ahead of time what primitive topology you
will be using otherwise you wouldn't know which order to put the indices into. This is
typically determined well in advance, with the selection of the rendering algorithm and the
geometry loading routines. During the pipeline configuration when preparing to perform
a draw operation, the desired index buffer is bound to the input assembler stage, where it
will be used to generate the input primitives for the pipeline. Since these buffers serve a
very specific purpose, they are normally not bound to the pipeline in other locations. This
binding location is shown in Figure 2.11.
Creating index buffers. When creating an index buffer, we follow the standard buffer
creation process and fill in a D3D11_BUFFER_DESC structure. The description structure of
an index buffer does not change very frequently from buffer to buffer, since this type of
data would normally be defined once in a content creation program and then exported as
is. The index buffer indices normally would not change after the application startup phase.
However, if some new algorithm does require dynamic updating of an index buffer, it can
also be created with the dynamic update properties discussed in the "Vertext Buffers" sec-
tion of this chapter. This could be used in the draw call reduction scheme discussed in the
"Vertext Buffers" section, where multiple sets of geometry are dynamically grouped to-
gether into a single set of vertex and index buffers. A typical creation sequence is provided
in Listing 2.7.
ID3DllBuffer* CreateIndexBuffer( UINT size,
bool dynamic ,
D3D11_SUBRES0URCE_DATA* pData )
{
D3D11_BUFFER_DESC desc;
desc.ByteWidth = size;
desc.MiscFlags = 0;
desc.StructureByteStride = 0;
deSC.BindFlagS = D3D11_BIND_INDEX_BUFFER;
// Select the appropriate usage and CPU access flags based on the passed
// in flags
if ( dynamic )
{
desc.Usage = D3D11_USAGE_DYNAMIC;
desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
}
else
Search WWH ::




Custom Search