1
\$\begingroup\$

Lately I wondered, which draw command is faster, drawArrays or drawElements. I know difference between them, drawArrays just draws every vertex in the same order they were provided, and drawElements draws vertices based on the provided indices. But I'm still curious which command is faster, or when should I use drawArrays instead of drawElements and vice-versa.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

It depends.

Using glDrawElements requires an index buffer which is an extra, but does allow for removal of duplicate vertices, concatenation of primitives and reuse of vertices via the hardware vertex cache.

Using glDrawArrays is simpler but doesn't have these advantages.

Desktop hardware has been optimized around glDrawElements with GL_TRIANGLES for quite some time - Quake 3 pushed it as the preferred rendering path, so that's the timescale we're talking about.

Some mobile hardware may still have glDrawArrays and GL_TRIANGLE_STRIP as the optimal path.

As always, benchmark on your target platform(s).

\$\endgroup\$
2
  • \$\begingroup\$ Thank you, but if I wrote some wrapper around OpenGL ES 2. Should I use both? \$\endgroup\$ Oct 13, 2016 at 16:31
  • \$\begingroup\$ @АйратНасыров - still the same answer: "it depends". Hardware running ES2 is probably more likely to prefer glDrawArrays with GL_TRIANGLE_STRIP, but it depends on the hardware, not the OS, not the API, and other hardware may be different. \$\endgroup\$ Oct 13, 2016 at 18:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .