Jump to content
  • Advertisement
Sign in to follow this  

Pros and cons of Vertex buffers...

This topic is 4885 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, I am implementing a particle system and have seen an example whereby the programmer has used DrawPrimitiveUP with an array of vertices rather than using setstreamsource on a vertex buffer. Does anybody here know the possible motivation for this and perhaps what the pros and cons to this decision are? I have never seen this used before and it made me curious! Kind regards. Mark Coleman

Share this post


Link to post
Share on other sites
Advertisement
The advantages of a VB are:

1) If you get the batch size right, or rather within the range for ur video card for best efficiency, they are extremely quick.
2) Easy to use, especially if you write a wrapper.

disadvantages
3) if you switch between multiple buffers very frequently it is inefficient and will slow the rendering.
4) if you get the batch size much to large, it'l slow down.

I would suggest using VBs anywhere really, until u know better.

ace

Share this post


Link to post
Share on other sites
Ok, so in my particle system I have a vector containing the maximum number of particles that are permitted. Some of these will be active and some of these will be dead. The index's of the dead ones will be stored in a stack so that they can be reallocated when the time is right.

So my question.

For each alive particle in the vector there will be an entry in the vertex buffer. This way they can all be rendered as a point list. This is where it gets difficult (at least in my head anyway).

When I updated the vertex buffer each frame I will simply lock it and then loop through copying the relevant position and colout data from vector to vertexbuffer so...

Say 400 particles are all alive on order (so the 1st particle is vector[0] and the last is vector[399]). Corresponding to this there will be a vertex buffer with 400 entries (whereby the vertex corresponding to vector[0] will be vertex buffer[0]).

Say particle 237 dies first, so a bool inside the particle is set to say dead and it's index in the vector is added to the 'dead stack'.

But what happens to the vertex buffer? How can I simply remove the vertex buffer entry?

Also what about when the particle becomes alive again? The particle will still be 237th in the vector, but how will I insert this into the correct place in the vertex buffer again?

I suppose the question overall is how to I insert and remove vertices from the vertexbuffer on the fly? Or maybe I am going about this completely the wrong way?

Any help is greatly appreciated.

Kind regards.

Mark Coleman

Share this post


Link to post
Share on other sites
If you make the vertex buffer hold the maximum number of particles then you should be ok.

Since you're filling the buffer each frame, don't add a vertex if that particle is currently 'dead'. Start at index 0, increment the index for each live particle, and when you're done, only drawPrimitive that many vertices (or that many vertices * 4 or * 6 or whatever). Right? There needn't be any relationship between position in your array and position in the vertex buffer.

Share this post


Link to post
Share on other sites
Quote:

disadvantages
3) if you switch between multiple buffers very frequently it is inefficient and will slow the rendering.
4) if you get the batch size much to large, it'l slow down.


I think it's important to add that these points might be "disadvantages" - but there is no better alternative for those cases than using a VB!! In other words, there are *no* cases where it's better to use DrawPrimitivesUP than to use a VB (since DrawPrimitiveUP will create a VB behind the scenes, copy the data into it, render it and then throw away the buffer).

If someone has used DrawPrimitivesUP in an example code it's simply because that person has written bad/slow code.

For particle systems you'll need a dynamic vertex buffer and update it each frame with the live particles only (as has already been explained)

- Kasper

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!