Search code examples
c++glslopengl-4

Value of gl_DrawID when calling glMultiDrawElementsIndirect with instance count set to 0


Suppose I have three meshes A, B, C in one VBO and used glMultiDrawElementsIndirect with the instance count set to 1, 0, and 1 for A, B, and C respectively and the draw count set to 3. What would be the value of gl_DrawID in the vertex shader? Would it be 0 for (vertices of) A, 1 for B, 2 for C or would it skip B and assign 1 to C?

The reference website states that this is "equivalent" to calling multiple glDrawElementsInstancedBaseVertexBaseInstance as much as the draw count so the answer should be the first case.


Solution

  • "Draws" are not instances. A particular draw in a multidraw can have instances, but these are separate things. An instance is a repetition of the same mesh with a different instance index (and/or per-instant VS inputs). A draw uses a different mesh (it could be the same mesh, but it doesn't have to be).

    The draw ID for A will be 0, B will have 1, and C will have 2. But since you set the instance count to 0, B won't be drawn at all. It still counts as a draw call however, so the draw ID will be unaffected by the fact that it wasn't drawn.