DrawingGL 4.2
glDrawArraysInstancedBaseInstance
Instanced glDrawArrays whose per-instance attributes start at element baseinstance instead of 0.
Signature
void glDrawArraysInstancedBaseInstance(GLenum mode, GLint first, GLsizei count, GLsizei instancecount, GLuint baseinstance);
How it works
Per-instance attributes (divisor 1) normally read element 0 for the first instance. With baseinstance = 100 they read element 100, 101, … So many groups of instances can share one big per-instance buffer, each draw pointing at its own slice, with no rebinding between draws.
Parameters
modeGLenum
Primitive type, e.g. GL_TRIANGLES.
firstGLint
First vertex.
countGLsizei
Vertices per instance.
instancecountGLsizei
Number of instances.
baseinstanceGLuint
Offset added when fetching per-instance attributes.
Tips & pitfalls
gl_InstanceID in the shader still counts from 0; the offset is in gl_BaseInstance (GL 4.6).
Example
example.cpp
1// trees use instances 0..299 of the shared buffer, rocks 300..419
2glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, treeVerts, 300, 0);
3glDrawArraysInstancedBaseInstance(GL_TRIANGLES, treeVerts, rockVerts, 120, 300);