7
\$\begingroup\$

Is it better to use glDrawElements or glDrawArrays when not reusing vertices? There must be some difference, otherwise people would always use glDrawElements?

I suppose the question could be reworded as the following:

Does glDrawElements function the same as glDrawArrays if it is passed a blank indices table?

\$\endgroup\$
7
\$\begingroup\$

glDrawElements() doesn't support a "blank indices table". glDrawElements() must always be given explicit data about in what order vertex indices are to be drawn, either using a pointer to a memory buffer (OpenGL <= 2.1 only), or an offset into a bound VBO.

glDrawArrays() acts like glDrawElements() would if it had been given an array of values [0, 1, 2, ... , n], where 'n' is the count value passed into either function.

In theory, glDrawArrays() requires less data than glDrawElements() (in that the order of indices is implicit, instead of requiring a block of data to be transferred to the GPU), and so it should be marginally faster if your data is in that format. But in practice, the difference is unlikely to be worth worrying about.

\$\endgroup\$
  • \$\begingroup\$ Oh of course. I should not have rushed when writing this, by "blank indices table" I meant a table of indices that would not have any reused indices (0, 1, 2, 3). But this is the exact answer I was looking for! Much appreciated, Trevor. \$\endgroup\$ – badcc Aug 16 '14 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.