Rendering transparent quads sorted in the VBO

Hi all,

Newcomer to OpenGL, I have the following question:

From what I have gathered, vertex order in a VBO is maintained in drawing, so drawing a VBO with 3 vertex triplets will draw the first triangle (=the first 3 vertices in the VBO) first, the second second and the third last. The hardware might cheat a bit internally, but the end result should appear in the screen as if it really happened in this way.

My question is this: Suppose I have several textured quads with transparency (the kind that needs sorting before drawing). If I enter the relevant vertex data in the VBO according to each quads’ depth, that is, if I create the VBO in such a manner that the vertex and thus the quad data is already “sorted” according to which I want to be drawn first, second etc., does this also guarantee that the transparent quads will be drawn correctly when I bind the VBO to the VAO and draw?

While it is trivial to write a short example and see for myself, even if the quads appear correctly on my system, I have no idea if it’s just my system and not everyone else’s, so I thought I’d ask here.

Thanks in advance!

EDIT: To clarify, this is for a 2D project with sprite rendering, in case it makes any difference.

1 Like

Note that the order of vertices in the VBO is only related to the order of triangles if you’re using glDrawArrays or similar. If you’re using e.g. glDrawElements, the EBO determines the order.

The end result is as if the triangles are drawn in the specified order. IOW, if you’re using blending, any “destination” component in the blending equation will include fragments from triangles which are supposed to be drawn earlier.

Realistically, the implementation can only ignore ordering for triangles which don’t overlap, i.e. where the order cannot affect the end result.

Shader invocations aren’t required to be in any particular order, so side-effects other than framebuffer updates (e.g. atomic counters, buffer variables, image load/store) can occur in any order. But for any sequence of operations which read or write a specific framebuffer pixel, those operations have to occur in order. For multiple write operations, the last value written is the one which ends up in the framebuffer. Read operations (e.g. depth or stencil tests) will use the value written by previous operations. Read-modify-write operations (blending, logic ops, stencil increment/decrement) will use the value written by previous operations and the resulting value will affect subsequent operations.

1 Like

I suppose you think in terms of sorting your individual models for using a draw-order where the camera-closest are drawn last … to be sure that the transparency collects impressions all the way through what would lie behind?
If that’s the case

has lost meaning if you draw in 2D.
But, do anticipate that the draw-order will influence the look of overlapping quads.