Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GL_TRIANGLES or GL_TRIANGLE_STRIP on iOS?

In this document (Apple's iOS documentation on OpenGL), Apple recommends using triangle strips over (indexed) triangles in OpenGL ES on iOS:

For best performance, your models should be submitted as a single unindexed triangle strip using glDrawArrays with as few duplicated vertices as possible.

However, Imagination Technologies (the creators of the graphics chip that's used in iOS devices) suggest the other way round in this document (POWERVR 3D Application Development Recommendations). They specifically write on page 11:

Using an indexed triangle list can be much more efficient than using strips.

My question: who is right? Or am I misunderstanding either document?

like image 912
zmippie Avatar asked Dec 15 '10 07:12

zmippie


1 Answers

TBH I'd believe powerVR. The PowerVR supports a post transform cache. This cache means that indices that are repeated relatively close to where they were last called can totally avoid a re-transform (It just pulls the already transformed value out of the cache). So in the case of a strip that goes 0, 1, 2, 3, 4, 5, 6, 7 it provides no bonus but, in reality, strips aren't generally that simple. There will be some vertex index re-use in there. That re-use can avoid the transform entirely. If strips are optimised to bear this in mind (See the NVTriStrip library!) then you can get MASSIVELY improved performance as many transforms just won't be performed.

Furthermore an added bonus of this is that triangle lists are no longer a performance hindrance as 2 of the vertices you are about to transform ARE in the cache and hence there is no performance hit (other than the upload of 6 bytes per triangle rather than 2 (ish) which is not much in the grand scheme of things). Furthermore because you have no need to perform strip "re-starts" (A restart is performed by repeating the last index of the last triangle and the first index of the next triangle. ie 0,1,2,2,3,3,4,5,6) some complex meshes can be faster than with strips. Add to that the fact that in a unindexed strip each repeated vertex must be sent down in its entirety the amount of data that needs to be sent can be a LOT higher than the amount that needs to be sent in an indexed list (as each vertex is only sent across once and the repeating is done in the far more compact indices).

Of course the MBX (iPhone 3G) does not support post-transform caches which is most likely where apple's advice comes from. The SGX (iPhone 3GS and above) does however so it really depends on what hardware you wish to target. If you are ok targetting 3GS and above then use indexing, otherwise don't. Of course supporting both methods out of the box will give best performance on both platforms.

Of course the best way to see is to try both methods (it really doesn't take long to do so) and see which performs better on the hardware!!

like image 68
Goz Avatar answered Oct 05 '22 10:10

Goz