openglvbodisplaylist

Rendering thousands of moving quads


I have to render large quantities of particles. These particles are simple non-textured quads (squares actually). Oh, and they're moving all the time since they're particles.

I have considered 2 options but as I'm not an OpenGL expert I don't know what's best.

  1. Use VBOs to render them all.
    Pros: faster than immediate mode.
    Cons: (I don't know much about VBOs but) from what I gather the quads' coordinates need to be stored in some buffer in RAM... and all of these coordinates need to be computed by the CPU. So for particle P1(x,y) I would have to compute 4 other coordinates (P2(x-1,y-1), P3(x-1,y+1), P4(x+1,y+1), P5(x+1,y-1)) - that's a lot of work for the CPU!

  2. Use a display list: First create a tiny display list for a single square quad. Then, to render each particle do some pushMatrix, glTranslate, callList, popMatrix.
    Pros: I don't have to compute 4 coordinates manually - glTranlate does that.
    Supposedly display lists are faster than VBOs.
    Cons: Are they faster than VBOs when they contain just one quad?

Mind you: I'm calling OpenGL stuff from Java so there's no smooth way of transforming Java arrays to GPU arrays (everything has to be stored in intermediary FloatBuffers before transfers).


Solution

  • Display Lists are for static geometry. Rendering just one single quad, then changing the transformation, rinse and repeat is horribly inefficient.

    Updating VBOs is better but still not optimal.

    You should look into instanced rendering. Here's a tutorial:

    http://ogldev.atspace.co.uk/www/tutorial33/tutorial33.html

    In the case of simple quads using a geometry shader turning simple GL_POINTS into two GL_TRIANGLES would do the trick as well.