I have a flat plane and an index buffer, or EBO with the indices marked on the image:
Now if I call:
glDrawElementsBaseVertex(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0, 0);
I get this:
This I understand. Further, If I do this:
glDrawElementsBaseVertex(GL_TRIANGLES, 9, GL_UNSIGNED_INT, 0, 0);
This makes sense too. But my understanding completely falls apart when I change one of the other parameters. If I do this:
glDrawElementsBaseVertex(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0, 3);
It looks like this:
So by passing the argument 3 to the basevertex argument (the last one), it's started using the index not from 3 positions into the index, and not even from 3 triangles into the index, but it's started about 6 triangles in, or more precisely index number 18. I can't understand this behaviour.
Also, I have read contradicting meanings for the argument of "indices" in these functions:
void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices);
void glDrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type, GLvoid *indices, GLint basevertex);
I've read that the indices pointer gives you the possibility to refer to an index buffer directly by providing a pointer, and if it is null then the index buffer is taken from the currently bound GL_ELEMENT_ARRAY_BUFFER. However from the documentation in one version it says:
indices Specifies a byte offset (cast to a pointer type) into the buffer bound to GL_ELEMENT_ARRAY_BUFFER to start reading indices from.
And in another version it says:
indices Specifies a pointer to the location where the indices are stored.
If I call glDrawElementsBaseVertex with the second last argument (indices) as (void*)3 I get the first triangle drawn red. If I specify (void*)6 I get no triangles highlighted. And if I specify (void*)9 I get the second triangle highlighted.
I can't make sense of any of this. So is it the case that this argument, indices, is NOT an optional pointer to the indices you wish to use instead of using the element array buffer currently bound?