View Full Version : GL_TRIANGLES or GL_TRIANGLE_STRIP the Preferred Primitive?

03-08-2014, 12:58 PM
I just spent way too much time finding and fixing a shading problem and now I have a question. Does the GL_TRIANGLE_STRIP have serious draw backs? When I first read about them I thought they seemed like a great idea; save a lot of space/time by using less vertices.

Well, the GL_TRIANGLE_STRIP implies the triangles will be in a different order; which is the problem. All of the OPENGL books are using GL_TRIANGLES in their shaders I assume now to avoid the difficulty with the GL_TRIANGLE_STRIP in terms of consistency. Specifically, a
GL_TRIANGLE_STRIP has the following order: v0v1v2, v0v2v3, ..., v0v(n-2)v(n-1). GL_TRIANGLES have the following order: v0v1v2, v3v4v5, ..., v0(n-3)v(n-2)v(n-1).

This inconsistency causes issues in shaders while the consistency of TRIANGLES lends itself real well to fast programmable shader solutions. Of course, we could unravel the GL_TRIANGLE_STRIP inconsistencies in the shaders but doesn't that drawback make GL_TRIANGLES a better solution than GL_TRIANGLE_STRIP?

I assume most will tell me it depends on the condition. However, since most of the books rely on GL_TRIANGLES and not GL_TRIANGLE_STRIP, does that mean they the preferred primitive?
Any help is appreciated...

Dark Photon
03-08-2014, 02:31 PM
Unindexed TRIANGLE_STRIPs, once in-vogue, yield lower performance than properly optimized indexed TRIANGLES. The reason is the work saved (vertex shader executions saved) due to proper use of the post-vertex shader vertex cache (formerly called the post T&L vertex cache).

You can use either indexed TRIANGLES or indexed TRIANGLE_STRIPs to submit your triangles to the GPU, after you've optimized the triangle order. But consider unindexed TRIANGLE_STRIPs dead.

For more details, see:

* Strippers (http://home.comcast.net/%7Etom_forsyth/blog.wiki.html#Strippers) (Forsyth)
* Vertex Cache Optimisation (http://home.comcast.net/%7Etom_forsyth/blog.wiki.html#%5B%5BVertex%20Cache%20Optimisation %5D%5D) (Forsyth)
* Regular mesh vertex cache ordering (http://home.comcast.net/%7Etom_forsyth/blog.wiki.html#%5B%5BRegular%20mesh%20vertex%20cac he%20ordering%5D%5D) (Forsyth)
* Optimal Grid Rendering (http://www.ludicon.com/castano/blog/2009/02/optimal-grid-rendering/) (Castano)

03-08-2014, 03:12 PM
Thanks for the information; no wonder all the texts are using GL_TRIANGLES and index arrays.
I'll read up.