• Advertisement
Sign in to follow this  

Multiple objects in VertexBuffer (DirectX 9.0)

This topic is 3309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, By 'object' I mean a shape or a mesh. I'm wondering if there is any optimal way to store multiple objects in a Direct3D VertexBuffer. Each object has 10-200 vertices and users are able to add their own objects. Two possibilities come to my mind: 1. Create one big VertexBuffer. When a user generates a new object, its vertices are added to the buffer. When the object is not needed anymore, the space in the buffer may be reused. This solution has two caveats: - Potentially a big part of the buffer will stay 'reserved' for potential objects the user is going to add. It's a waste of memory. - It would require a memory management mechanism (a garbage collector) as reusing the buffer will eventually fragment memory. 2. Another possibility would be to create a separate VertexBuffer for each newly generated object. This solution on the other hand may degrade performance as a new buffer would need to be created and destroyed for each object, all through the COM interfaces. Is there any optimal way to 'expand' the VertexBuffer when a new object is created that would perform well and have optimal memory usage? Thanks in advance, Tar

Share this post


Link to post
Share on other sites
Advertisement
Not a direct answer, but in order to be a "legit" windows app you will need to be able to support a lost device. This means that at any time you need to be able to rebuild your vertex buffers and texture memory when the user does an Alt-Tab, or something else occurs that causes a lost device. If you build your engine to be able to reload all currently needed vertex buffers and texture resources from memory/hard disk on demand, then you will always be able to do your own clean-ups and be well on your way to being a legit app.

Hope that makes sense/helps...

Share this post


Link to post
Share on other sites
Thanks starman2049,
I applied your suggestions and some other tips from Oluseyi. I keep my vertices/indicies in RAM (in case of a lost device and in order to manage memory myself) and load them using memcpy to a single vertex and a single index buffer. Using one big buffer instead of multiple small buffers is more efficient as Oluseyi suggested. I will need to estimate the number of vertices/indicies I will need. Still, there could be a situation when the number of vertices/indicies exceeds the size of the buffers. In such a case I will re-allocate more memory for the buffers dynamically. Such situations should be rare though as expanding the buffers is a costly operation.

Thanks for your help

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement