1

I'm trying to draw a simple array of triangles. They are all connected, so I'm currently using DrawArrays and GL_TRIANGLE_STRIP. However, when checking the XCode profiler, it suggests using DrawElements and an indexed array instead.

Should I actually be doing this? I noticed that DrawElements also has an option for TRIANGLE_STRIP, but I don't see an advantage since there aren't any repeated vertices when I use glDrawArrays.

Here's a diagram of the triangles I'm drawing: enter image description here

As you can see there's no repeats as I'm using TRIANGLE_STRIP, so is there any advantage in indexing this?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
MysteryPancake
  • 1,365
  • 1
  • 18
  • 47
  • Profile it and see which is faster. I think your reasoning is correct though. – samgak Dec 03 '16 at 02:10
  • I could profile it, but I'm having some problems getting DrawElements to work, even though all the indices are just numbers going from 0 to 11. I wanted to check here so I don't waste more time trying to get it working – MysteryPancake Dec 03 '16 at 02:16
  • 1
    There's no good reason why indexed drawing should be faster if there are no repeated vertices. – Reto Koradi Dec 03 '16 at 05:59

1 Answers1

1

Usually glDrawElements is faster but and in your case (with only two rows of vertices) it won't affect performance and glDrawElements could be even slower because you have also to handle the index buffer.

In some other cases where you have three or more rows of vertices you will start to have vertex repetitions and you should be using glDrawElements and index your vertex buffer. The advantages of indexing are:

  • not only your 3D model is smaller and consumes less memory but it becomes faster to load it into the graphic card memory. So less memory means also less memory transfers.

  • If your shaders are complex and has too many operations, indexing could impact performance positively. In fact, if you are indexing vertices there is no need to recompute the result for the same vertex multiple times. The result is computed one time, cached and used again when another index points to the same vertex.

  • When you have a deformable object (i.e. the positions of the vertices change due to physical collision), indexing will help. Assume that you didn't index, you will be repeating the same vertices(position) for every triangle. So if you want to change the position of the vertex to simulate collision you will have to update the vertex position for all triangles. However, if you index your vertex buffer, you will only have to change the position of the vertex and keep the index buffer the same.

ELKA
  • 735
  • 6
  • 17