Reputation: 504
So I was looking around for optimizations for my program and I was wandering if using QUADS is the most efficient way of doing it.. I am using Mapped interleaved VBOs for QUADS vertices and TEXTURE coords .
So I want to know if there is a clear performance boost when using one of the following instead of QUADS for rendering:
Note: This needs to include the fact that I am using textures!
Which is the fastest?
Note 2: I looked around and could not find a definitive answer.
Upvotes: 0
Views: 3866
Reputation: 4631
GL_QUAD_STRIP
is deprecated and not supported in the current version of OpenGL, so that's out. Plus, it's not too fast anyway - see this post for a good explanation of why it's no longer supported (save for compatibility purposes).
GL_TRIANGLES
is generally a good way to go. It'll be faster than using outdated functionality. And it's faster in principle, too - quads are broken down into triangles anyway, so you save a bunch of needless work by doing it once CPU side and then saving the GPU work it would have to do. Triangles are a standard and perfectly fine way of specifying shapes.
GL_TRIANGLE_STRIP
is faster than GL_TRIANGLES
because it takes one point, not three, to specify each triangle after the first triangle is specified. The previous two vertices of the triangle before are used. You get connected triangles, but you also use less memory. Because you have to read less, you can process faster. And because your last two vertices were just specified in the last triangle, they're going to be easier to fetch in memory than two other vertices that may come from who knows where. There are also tricks for using degenerate triangle strips for allowing for seamless jumps between triangles.
If you want the best performance of the three, GL_TRIANGLE_STRIP
is the way to go. Unfortunately, unless your data comes already specified for use in a triangle strip, you'll have to order your vertices yourself and remember where to put your degenerate triangles. A good starting point is with height maps (ie terrain). However, optimizing other parts of your code first (eg determining whether to even draw an object) may be a better use of your time. And I may be wrong, I don't think texture use should have an impact on your choice of vertex specification.
Edit: Here is an example of how rendering a square is done with GL_TRIANGLE_STRIP
Vertices: (0,0) (0,1) (1,0) (1,1)
Triangle 1: (0,0) (0,1) (1,0) (1,1)
Triangle 2: (0,0) (0,1) (1,0) (1,1)
Upvotes: 3