5
votes

I need help to see the trade-offs between them.

  • It looks to me that glDrawElements() needs to get the index-data "live" as a parameter.
  • On the other side if I use VAOs then during startup I buffer the data and the driver might decide to put it on the GPU, then during rendering I only bind the VAO and call glDrawArrays().

Is there no way to combine the advantages? Can we buffer the index-data too?

And how would that look in the vertex shader? Can it use the index and look it up in the vertex positions array?

1

1 Answers

5
votes

This information is really a bit hard to find, but one can use glDrawElements also in combination with a VAO. The index data can then (but doesn't have to) be supplied by a ELEMENT_ARRAY_BUFFER. Indexing works then as usual, one does not have to do anything special in the vertex shader. OpenGL ensures already that the indices are used in the correct way during primitiv assembly.

The spec states to this in section 10.3.10:

DrawElements, DrawRangeElements, and DrawElementsInstanced source their indices from the buffer object whose name is bound to ELEMENT_- ARRAY_BUFFER, using their indices parameters as offsets into the buffer object

This basically means, that whenever a ELEMENT_ARRAY_BUFFER is bound, the indices parameter is used as an offset into this buffer (0 means start from the beginning). When no such buffer is bound, the indices pointer specifies the address of a index array.