开发者

XNA, occlusing culling and collision detection

I've put together a quadtree/BSP hybrid prototype to test collision detection and occlusion culling in the engine for an XNA game I'm putting together.

As I understand it, one of the optimizations that hardware acceleration gives us is the ability to store vertex and index lists on the card, so that calls to draw the associated geometry don't have to send the model data for each frame.

In a level with a lot开发者_JAVA技巧 of geometry, how do you manage this in XNA? If I were working in OpenGL, for instance, I'd maintain a list of what's in the card, and just send what needs to be updated. However, the high abstraction level of the XNA framework seems to encapsulate that to such a degree that I can't manage it.

Tell me why I'm wrong, or why I shouldn't be worried.


In XNA the graphics driver decides in which memory your vertex and index buffers will best be located based on the properties of the buffers which you specify. The choices you can make that influence where the buffer is stored include:

  • Whether to use a dynamic buffer or normal buffer

"In situations where your game frequently modifies a vertex buffer, it is recommended that the buffer be instantiated or derived from DynamicVertexBuffer instead of the VertexBuffer class."

  • The usage parameter when you create the buffer

WriteOnly "Indicates that the application only writes to the vertex buffer. If specified, the driver chooses the best memory location for efficient writing and rendering. Attempts to read from a write-only vertex buffer fail."

Summary

Given information by you about how the buffer is going to be used, the graphics driver will generally be able to make a better decision than you could about where to locate the buffer. This is because it knows how much of each type of memory is available and the performance characteristics of the memory for that specific system.

Note: For XNA 3.1 and below with dynamic vertex & index data on the xbox it was faster to store the data in a managed array and use DrawUserPrimitives than to use a DynamicVertexBuffer or DynamicIndexBuffer.

If you do end up using a dynamic buffer you must be careful not to stall the pipeline when using SetData. See http://blogs.msdn.com/b/shawnhar/archive/2008/04/15/stalls-part-two-beware-of-setdata.aspx for details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜