OpenGL - auto generation of indices / stride parameter for glDrawArrays

百般思念 提交于 2019-12-04 17:17:19

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​);

The best solution I was able to find is to use glMultiDrawElementsIndirect. The buffer size is lots of smaller than the original one and you can pass all draw-commands with one gl-call. Thanks to derhass for the hint!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!