OpenGL ES and overlapping triangles with VBO

Some background:

I am very new to OGL. My application is only for 2D. All objects are normal to the viewing direction, and I use spelling projection. I believe that system performance is limited by the number of calls * indicating that I need more.

There is only one object that I need to draw, but it consists of thousands of triangles that potentially overlap. I have the opportunity to pre-calculate the geometry in my specific application and arrange the triangles back, since they have different degrees of transparency. The vertex attribute consists of a color (only), including alpha, which is used in the fragment program.

What I've done:

All primitives are triangles, and I assign three vertices to each triangle of the same color, since the color is constant across the face. I put all the vertices, for all triangles and their colors, in one VBO (16 bits, not many vertices). The index buffer orders the triangles back, and I issue one callback. I use alpha blending (SRC_ALPHA, ONE_MINUS_SRC_ALPHA).

Result:

I see that the result is correctly mixed and displayed on the only computer that I own and test. I have not tried this on others. I searched for quite some time, but in vain, for some kind of definitive answer. BTW, the only reference is in the VBO extension specification, which refers to the "sequence of primitives", but it does not concern what happens when the primitives overlap.

Question:

Is this guaranteed behavior? That is, the result will be the same as issuing several calls in glBegin (...) and glEnd (...) in direct mode (which is guaranteed by the standard)?

Note. Depth buffer and stencil buffer disabled.

+4
source share
1 answer

It is guaranteed by the OpenGL specification that primitives will be displayed in the specified order. Each primitive pulled from the glDraw* command will be displayed in the order indicated by its component vertices.

So yes: if you put the triangles in order, you will get that order when you render them.

+3
source

Source: https://habr.com/ru/post/1411951/


All Articles