我正在渲染一个包含大量数据点(> 1M)的网格结构。我的数据结构如图所示。
因此我的索引缓冲区的内容看起来像0, 100, 1, 101, 2, 102, 3, 103, ...
我对索引缓冲区的大小有点恼火,我需要定义我的三角形条带。是否有可能告诉OpenGL以显示的方式自动生成这些索引?或者也许是glVertexAttribPointer的一些技巧我还没有?
答案 0 :(得分:2)
确实存在这样的功能:glDrawElementsBaseVertex
所以你可以用以下方式绘制它们:
for(int i=0; i < height-1; i++){
glDrawElementsBaseVertex(GL_TRIANGLE_STRIP, 200, GL_UNSIGNED_INT, 0, i*100);
}
索引缓冲区只是:0, 100, 1, 101, 2, 102, 3, 103,... 98, 198, 99, 199
通过一些调整,您甚至可以使用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);
答案 1 :(得分:0)
我能找到的最佳解决方案是使用glMultiDrawElementsIndirect。缓冲区大小比原始缓冲区大很多,您可以通过一次gl调用传递所有draw-commands。 感谢derhass提示!