confusion in understanding the behavior of glDrawArraysInstancedBaseInstance

I am trying to figure out what the meaning of the last parameter of the glDrawArraysInstancedBaseInstance API is. Following is the doc of this API excerpted from the Red Book:

[ATTACH=CONFIG]1636[/ATTACH]

I don’t quite understand what "offset"here means. Is it (index of an instanced vertex attribute) + baseInstance? But what if the instanced vertex attribute is the last one which is instanced? Will OpenGL shift the index back to those of earlier instanced vertex attributes? If you have an example code, I would appreciate it if you can share the code with me. Thank you for the help.

read this:
https://www.khronos.org/opengl/wiki/GLAPI/glDrawArraysInstancedBaseInstance

no.

you surely know what glDrawArrays(…) does.

glDrawArraysInstanced(…) does the same, but multiple times (“instancecount” times). in the vertex shader you can determine the current “instance index” using the built-in variable gl_InstanceID. for example, 100 instances causes 100 glDrawArrays(…) invocations, then gl_InstanceID is withn the range [0 ; 99].

glDrawArraysInstancedBaseInstance(…) does the same as glDrawArraysInstanced(…), gl_InstanceID will be the same as in glDrawArraysInstanced(…), BUT the “index offset” of the data pulled from the specified “instance buffer” can be shifted using “baseinstance”.

example:

#version 450 core

layout (location = 2) in float somedata;

and the current VAO pulls data for this attribute from buffer X, then:

glDrawArraysInstancedBaseInstance(…, 0);
starts pulling data for the first instance from the beginning of buffer X

glDrawArraysInstancedBaseInstance(…, 1);
starts pulling data for the first instance from the beginning of buffer X + sizeof(1 float)

so, you are only shifting the starting point from which the instanced data gets pulled …

–> what is it good for ??
if you have multiple glDrawArraysInstanced(…) calls, and you dont want to upload new buffer data after each call, then you can upload ALL the instanced data at once consecutively layed down in the buffer and use “baseinstance” to shift the “starting point” for the instanced buffer data for each call

I have completely got it. Thank you very much, john_connor.