Game Development Reference
In-Depth Information
13.7 Some Improvements
The implementation of the Terrain class loaded all the vertex data
into one huge vertex buffer. It can be advantageous in both speed and
scalability to divide the geometry of the terrain among multiple vertex
buffers. This brings us to the question: “What size vertex buffer is
best?” The answer depends on the target hardware. Therefore, you
must experiment!
Because dividing up the terrain geometry into many smaller vertex
buffers is largely an exercise in indexing into matrix-like data struc-
tures and data management and doesn't introduce any new concepts,
we omit a detailed discussion of it. Briefly, you basically break your ter-
rain into a matrix of what we will call “blocks.” Each block covers a
rectangular area of the terrain. In addition, each block contains the
geometry (in its own vertex/index buffers) of the terrain that falls
inside the block's area. Then each block is responsible for drawing its
portion of the terrain that it contains.
Alternatively, you can load the terrain geometry into one big
ID3DXMesh interface. Then use the D3DX function D3DXSplitMesh
to divide the terrain mesh into multiple smaller ones. D3DXSplitMesh
is prototyped as:
void D3DXSplitMesh(
const LPD3DXMESH pMeshIn,
const DWORD *pAdjacencyIn,
const DWORD MaxSize,
const DWORD Options,
DWORD *pMeshesOut,
LPD3DXBUFFER *ppMeshArrayOut,
LPD3DXBUFFER *ppAdjacencyArrayOut,
LPD3DXBUFFER *ppFaceRemapArrayOut,
LPD3DXBUFFER *ppVertRemapArrayOut
);
This function takes an input source mesh and splits it into multiple
smaller meshes. The pMeshIn parameter is a pointer to the mesh that
we want to divide up, and pAdjacencyIn is a pointer to its adjacency
array. The MaxSize parameter is used to specify the maximum vertex
count allowed for the resulting meshes. The Options flag is used to
specify the creation options/flags of the resulting meshes. The
pMeshesOut parameter returns the number of created meshes being
returned in the ppMeshArrayOut array buffer. The last three parame-
ters are optional (specify null to ignore them) and return arrays of
adjacency information, face remap info, and vertex remap info for each
of the created meshes.
Search WWH ::




Custom Search