Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiency when rearranging arrays in OpenGL

Imagine I have a vertex array and an index array. Suppose it is possible to rearrange the elements in the index array so that a single call glDrawElements with GL_TRIANGLE_STRIP draws the desired figure. Another possibility would be to call glDrawElements with GL_TRIANGLES but this would make the index array longer.

Does it really matter in terms of efficiency (I mean real efficiency, not some microoptimizations) which way I choose or is the underlying routine the same anyway?

A side note: The reason I am reluctant to rearrange my elements to use GL_TRIANGLE_STRIP is that because I think that the triangles in the strip will have alternating winding. Am I wrong?

like image 450
Armen Tsirunyan Avatar asked Dec 12 '22 18:12

Armen Tsirunyan


2 Answers

There's no really performance differences between a call with GL_TRIANGLE_STRIP and GL_TRIANGLES.

Now if you can rearrange your indices for maximizing post-transform vertex cache, you can have huge performance gains. I did so years ago for rendering large terrain patches and observed 10 to 15 times FPS speedups (using some kind of Hilbert curve scheme).

like image 127
Stringer Avatar answered Dec 26 '22 05:12

Stringer


I think that GL_TRIANGLE_STRIP and GL_TRIANGLES are quite as efficient, if your indices are ordered in a way to maximize vertex transform cache. Of course it will take more memory to store.

like image 21
tibur Avatar answered Dec 26 '22 04:12

tibur