I'm rendering a grid-structure with lots of data-points (>1M). The structure of my data is in the picture.
So the content of my index buffer looks like this 0, 100, 1, 101, 2, 102, 3, 103, ...
I'm a bit annoyed by the huge size of my index-buffer which I need to define my triangle strip. Is there a possibility to tell OpenGL to generate these indices automatically in the showed way? Or maybe some trick with glVertexAttribPointer I haven't though of?
There is indeed a function for something like this: glDrawElementsBaseVertex
so you can draw them all with:
for(int i=0; i < height-1; i++){
glDrawElementsBaseVertex(GL_TRIANGLE_STRIP, 200, GL_UNSIGNED_INT, 0, i*100);
}
the index buffer is then just: 0, 100, 1, 101, 2, 102, 3, 103,... 98, 198, 99, 199
With some tweaking you can even use glMultiDrawElementsBaseVertex
:
GLsizei *count = new GLsizei[height-1];
GLvoid **indices = new GLvoid[height-1];
GLint *basevertex = new GLint[height-1];
for(int i = 0; i< height-1; i++){
count[i]=200;
indices[i]=0;
basevertex[i]=i*100;
}
glMultiDrawElementsBaseVertex(GL_TRIANGLE_STRIP, count, indices, height-1, basevertex);