PDA

View Full Version : Rendering order within a single draw call



Dan Bartlett
01-11-2012, 07:16 AM
If you are drawing in 2D and issue a single draw call (with glDrawXXXX), does OpenGL guarantee that triangles that appear later in the vertex arrays will be drawn over the ones that appear earlier?

I want to update some code to issue shadowed text as a single draw call (code is currently using immediate mode), so was wondering if including the shadowed character before the actual character was enough to ensure the shadow would always be behind the text, or whether the shadowed text would need to be split into a separate draw call.

mbentrup
01-11-2012, 08:23 AM
No, OpenGL will probably draw many triangles in parallel, so the order of fragments output is more or less undefined.

If you are only drawing 2D (and don't use the depth buffer for anything else) you could keep a single draw call by enabling the depth test and just giving the shadow triangles a higher z coordinate that the text triangles.

overlay
01-11-2012, 09:43 AM
1. OpenGL does NOT draw many triangles in parallel:

See Spec 2.1 for example, page 4, section 2.1 OpenGL Fundamentals:

"Commands are always processed in the order in which they are received"
"This means, for example, that one primitive must be drawn completely before any subsequent one can affect the framebuffer"

This is why, if you don't want to use the depth buffer (or if you can't because you have transparent geometry), you can order your primitives based on the camera position to draw in back-to-front order.

2. mbentrup is right for using the depth buffer, if you only have opaque geometry.

Aleksandar
01-11-2012, 02:12 PM
"Commands are always processed in the order in which they are received"
"This means, for example, that one primitive must be drawn completely before any subsequent one can affect the framebuffer"

Exactly! But that is not what Dan asked. A triangle strip with 10.000 triangles is still a single primitive. There is no guarantees that triangles appear later in a primitive is drawn after some triangles appear before them. Furthermore, the calculation is distributed across multiple processing units. It would be nice to hear from someone involved in drivers implementation if there is any additional synchronization.