Minimizing Resources

[Previous] [Next]

The tips in this section will help you cut down on resources so that your application runs more smoothly and quickly.

High-Cost State Changes

You should draw all non-alpha polygons before drawing all alpha polygons so that you have to toggle alpha (call SetRenderState with D3DRENDERSTATE_ALPHABLENDENABLE for the first parameter and TRUE or FALSE for the second) only twice per frame. Also remember that if you always render something over every pixel, you won't need to clear the back buffer at the start of each frame.

Polygons

By splitting the number of triangles you pass to Direct3D at a time into smaller chunks, you might have a bit more calling overhead, but the transfer is almost the same. However, the 3D engine will be kept busy, most likely finishing a few machine cycles after the processor passes the last polygon, meaning that rendering is much more efficient. Experiment with different batch sizes to see what works best for your program.

Texture Changes

You should always sort your objects by texture and render them in batches to minimize your texture changes. You should limit yourself to fewer than 100 texture changes per frame.

Texture Memory

You should always work toward intelligent texture memory usage. Avoid overcommitting memory whenever possible. If you have to overcommit memory, try to keep the level of overcommitment below 30 percent. For example, if there isn't enough video memory to hold all the textures you need at once, consider dropping the highest mip level. The image quality will be lower, but the graphics will render much faster.

Visibility Grids

You should always design your 3D worlds so that you only submit to Direct3D the data that's currently visible. For example, in an outdoor simulation, you would break the 3D world into a grid and load the objects and triangles for the neighboring grid elements that are visible. As the user moves through the simulation, unload the grid elements that the user can't see and load the ones that become visible.



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net