[QUOTE=glnoob;397965]But what I want is this sequence:
0,1,2,3,4,5,6,7,8,9
[/QUOTE]
I get the thinking behind that, but you’re not going to get that as a simple number. Instead, you have to get clever.
What you’re trying to do is have a big array of per-model data. For each draw command, you add another entry into the array for each instance in that draw command. And in your shader, you just fetch from the array by that index.
Since the index you want doesn’t exist, what you need to do in order to pull this off is to build an array, where each element in the array corresponds to a draw command. The value of each element is an index into the per-model data array where that draw command’s data starts.
So your per-model fetching in the shader would look like:
perModelArray[drawIndex[gl_DrawID] + gl_InstanceID]
I wouldn’t worry too much about the performance of this extra layer of indirection. I mean, it’s not going to be good for performance, but it shouldn’t be bad either. Since every vertex of each rendering command will share the same gl_DrawID
, drawIndex[gl_DrawID]
will get stored in the cache pretty quickly, and it’ll stay there for most of the vertices in that command. So given a reasonable number of vertices, it shouldn’t be a problem.
BTW: one of the reasons you can’t just get the kind of index you’re talking about is that gl_DrawID
has to be handled specially. Or more to the point, there are things that gl_InstanceID
can’t do.
For example, if you want to access a texture based on gl_DrawID
by fetching from an array of bindless textures, you can do that. However, if you do it based on gl_InstanceID
, you cannot. The expression using a bindless texture is required to be dynamically uniform, and gl_InstanceID
is not dynamically uniform. So the index sequence you’re wanting isn’t dynamically uniform.
So while you could have each draw call in a multi-draw use different textures through an array of bindless textures, you cannot have different instances within the same draw call do the same.
This is why array textures are still important even in a bindless texture world. Array textures don’t have this requirement, so instances can do as they see fit.
Oh and FYI:
Bugs go here now.