ben
ben

Reputation: 472

OpenGL - glDrawElements vs Vertex Array Objects

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

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?

Upvotes: 5

Views: 1485

Answers (1)

BDL
BDL

Reputation: 22174

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.

Upvotes: 5

Related Questions