Imagine I have a vertex 开发者_如何学Carray 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?
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).
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.
There's probably not much of a performance difference. But it's still recommended that you not use either method in the main render loop. Instead use display lists. I've converted some of my OpenGL code to display lists, and it's way faster because you end up cutting out a ton of CPU->GPU communication.
There's a tutorial here: http://www.lighthouse3d.com/opengl/displaylists/
It all depends on what your driver has to do with your vertex data. If it has to do some processing (turn QUADS into TRIANGLES, like it usually has to do) then it will not be optimal. The only way to see what is optimal for your driver is to measure. Find a opengl benchmark and see which vertex primitives are optimal for your driver.
Since you want to compare GL_TRIANGLE_STRIP and GL_TRIANGLES, most likely you will find the performance loss to be minimal in this case.
精彩评论