Sign in to follow this  
Deftoned

Processor Waste: Negligable?

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
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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this