• Advertisement
Sign in to follow this  

Processor Waste: Negligable?

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

Hi Guys just got a question to ask about some optimization for a particle engine Right now i am using a VBO to stores the vertices for each of my particles, and each of them has a specified life span, but my question is am i going to be wasting much processing power if i am going: glDrawElements(GL_POINTS, m_numParticles, GL_UNSIGNED_BYTE, 0); because if a particle is dead ie. not visible, i will obviously bee trying to draw it and update it's position. Is this something i can fix or is it really just an acceptable loss?

Share this post


Link to post
Share on other sites
Advertisement
maybe you swap dead particles with the last live particle in your array so your array is effectively sorted alive particles first so that you can pass the proper count of live particles as the m_numParticles

Share this post


Link to post
Share on other sites
Just live with it.
Just draw all the particle and let them be alpha-rejected. You have no chance of testing each particle in an efficient manner which won't kill your CPU.

Share this post


Link to post
Share on other sites
I agree with DrEvil: Since you'll most certainly iterate over the active particles in order to update them you could also perform the swap whenever a particle dies.

You could either use glBufferSubData or map the vertexbuffer to your address space (glMap/glUnmap). I assume you are doing this or something similar already in order to update the particles' positions (you're hopefully not using a transformation matrix for each particle [smile]).

Share this post


Link to post
Share on other sites
Depending on how big your particle array is, swapping particles could give you a lot of performance hit in form of cache misses.

Your cpu will fetch several rows of array to fill the cache, which would speed up access to next element. Then you will suddenly swap to somewhere at the end of that array, and get a cache miss. Your cpu will then dissregard the cache, and get in rows around the element at the end. Then suddenly you would continue from the next element in your "alive" partition, but ooops, it is now out of cache and cpu will now have to repeat the process ...

Of course if your array is not too big, this probably wouldn't be the case. It is worth to do some benchmarking and see what happends.

Checking to see if particle is alive will also mean branching on every particle, which also is a cpu killer.

Relying on alpha rejection sounds like a better deal to me.

Share this post


Link to post
Share on other sites
Quote:
Original post by Deftoned
glDrawElements(GL_POINTS, m_numParticles, GL_UNSIGNED_BYTE, 0);


You should probably use GL_UNSIGNED_SHORT instead.

Share this post


Link to post
Share on other sites
Ok thanks for the advice guys,

Lord Evil i am using the map/unmap option for updates etc.
And V-Man you seem pretty smart so i will take your advice
on the unsigned short thing.
So far i have no particle rendering or anything, the code is
there but untested to the extent of drawing.
Thanks for the continues help guys, hopefully when this is all
done my University group can post up our project as an IOTD.

Share this post


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

  • Advertisement