Game Development Reference
In-Depth Information
We can access the attribute buffer by locking it, as this next code snip-
pet illustrates:
DWORD* buffer = 0;
Mesh->LockAttributeBuffer(lockingFlags, &buffer);
// Read or write to attribute buffer...
Mesh->UnlockAttributeBuffer();
10.3 Drawing
The ID3DXMesh interface provides the DrawSubset(DWORD
AttribId) method to draw the triangles of a particular subset speci-
fied by the AttribId argument. For instance, to draw all the triangles
that live in subset 0, we would write:
Mesh->DrawSubset(0);
To draw the entire mesh, we must draw all the subsets of the mesh. It
is convenient to label subsets in the order 0, 1, 2, …, n-1 , where n is
the number of subsets, and have a corresponding material and texture
array, such that index i refers to the material and texture associated
with subset i . This allows us to render the entire mesh using a simple
loop:
for(inti=0;i<numSubsets; i++)
{
Device->SetMaterial( mtrls[i] );
Device->SetTexture( 0, textures[i] );
Mesh->DrawSubset(i);
}
10.4 Optimizing
The vertices and indices of a mesh can be reorganized to render the
mesh more efficiently. When we do this, we say that we are optimizing
a mesh, and we use the following method to do this:
HRESULT ID3DXMesh::OptimizeInplace(
DWORD Flags,
CONST DWORD* pAdjacencyIn,
DWORD* pAdjacencyOut,
DWORD* pFaceRemap,
LPD3DXBUFFER* ppVertexRemap
);
Search WWH ::




Custom Search