Jump to content
  • Advertisement
Sign in to follow this  
MrDoomMaster

Resizing the Vertex Buffer

This topic is 4796 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

I'm using DirectX SDK 9.0c August 2005. I have a class which is in control of drawing line lists and line strips, yet as vertices are added to the class (therefore extending the number of lines that are drawn), the vertex buffer's internal space must be expanded to hold the additional vertices. Is a constant call every frame to CreateVertexBuffer slow? This seems the only way to adjust the size of the Vertex Buffer is to re-create it every time vertices are added. If there is another way I would love to know about it. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Creating a new vertex buffer every frame is slow. Try using a dynamic vertex buffer and filling that every time with (subsections of) the actual data.
Other possibilities are callbacks (even slower) or DrawPrimitiveUP (which also creates a temporary vertex buffer, but may be a bit more optimised by the runtime because the usage pattern is known). Each of these methods mean you hold a copy of the vertex data somewhere in your app's memory.

That you want to resize a buffer implies that you have a buffer with valid data and simply want to add more. Then why not just create a new larger buffer only when you do add data. Don't bother shrinking it.

Share this post


Link to post
Share on other sites
Better yet, screw the vertex buffer, render your primitives using IDirect3DDevice9::DrawPrimitiveUP. Use it when you don't want to use (or can't) use vertex buffers. It's similar to Direct3D Immediate Mode's old IDirect3DDevice7::DrawPrimitive. But depending on how you use it, you are giving up efficiency, so be careful.

Click here

Share this post


Link to post
Share on other sites
DrawPrimitiveUP is typically slower than a custom solution you make yourself. Calling CreateVertexBuffer every frame is slow, too, though.

Of course, when we say "slow" we might mean the difference between 290 and 270 FPS, not the difference between 60 and 30 fps, if it's only for a single vertex buffer.

Depending on how often you add vertices, I would either use a DYNAMIC vertex buffer for NOOVERWRITE/DISCARD locking (a la vertex streaming), or I would allocate a bigger vertex buffer (say, rounded up to the nearest 128 vertices), and resize it upwards only when it actually gets full.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!