Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL - auto generation of indices / stride parameter for glDrawArrays

I'm rendering a grid-structure with lots of data-points (>1M). The structure of my data is in the picture.

Structure of data-points

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?

like image 859
freakinpenguin Avatar asked Jan 18 '26 02:01

freakinpenguin


1 Answers

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​);
like image 193
ratchet freak Avatar answered Jan 19 '26 19:01

ratchet freak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!