DrawingGL 3.1
glDrawElementsInstanced
Indexed version of instanced drawing — the usual way to draw many copies of a model.
Signature
void glDrawElementsInstanced(GLenum mode, GLsizei count, GLenum type, const void *indices, GLsizei instancecount);
How it works
Combines glDrawElements (reuse vertices through an index buffer) with instancing (repeat the whole mesh instancecount times). Loaded models are almost always indexed, so this is the call you will use for them.
Parameters
modeGLenum
Primitive type.
countGLsizei
Indices per instance.
typeGLenum
Index type: GL_UNSIGNED_INT, GL_UNSIGNED_SHORT or GL_UNSIGNED_BYTE.
indicesconst void *
Byte offset into the element buffer.
instancecountGLsizei
Number of instances.
Example
example.cpp
1glBindVertexArray(rockVAO);
2glDrawElementsInstanced(GL_TRIANGLES, rockIndexCount, GL_UNSIGNED_INT, 0, 10000);