Core Techniques and Algorithms in Game Programming2003

Direct3D offers some mechanisms to control how vertex buffers are delivered to the hardware. By knowing these mechanisms, we can ensure optimal performance. To begin with, we need to know how to declare a vertex or index buffer so it is always stored in video memory. This is achieved at creation time. For example, the following call gives Direct3D many cues about where to store the vertex buffer:

CreateVertexBuffer(size, D3DUSAGE_WRITEONLY, fvf, D3DPOOL_MANAGED , buffer);

First, we specify the buffer as write-only, so geometry stored there will never be animated or modified in any way. This is a good thing to do with all your static geometry because it tells Direct3D that no updates to the data will be required, and thus it can be transferred to the most efficient memory region available. Second, notice the parameter D3DPOOL_MANAGED, which tells Direct3D to make sure the vertex buffer is placed wherever performance is best. Combining these two parameters is the best way to ensure efficient rendering because data will be pulled from video or AGP memory directly, skipping the bus.

Another interesting option is checking for hardware vertex processing capabilities texturing and lighting (T&L), shaders, and so on so we can take advantage of them in our application. DirectX allows us to check for hardware vertex processing compliance when we create the device. This is achieved by using the call:

if(FAILED(g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) ) { return false; }

Additionally, remember to use the most efficient delivery methods. Indexed, stripped coordinates are the way to go because vertex and index buffers will save precious memory, and fewer vertices will need to cross the pipeline.

Категории