步幅参数的自动生成

步幅参数的自动生成

本文介绍了OpenGL-glDrawArrays的索引/步幅参数的自动生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在渲染具有大量数据点(> 1M)的网格结构.我的数据结构在图片中.

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

所以索引缓冲区的内容如下所示:0, 100, 1, 101, 2, 102, 3, 103, ...

So the content of my index buffer looks like this 0, 100, 1, 101, 2, 102, 3, 103, ...

我对索引缓冲区的巨大尺寸感到恼火,因为我需要定义我的三角带.是否有可能告诉OpenGL以所示方式自动生成这些索引?也许我还没有使用glVertexAttribPointer的一些技巧?

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?

推荐答案

确实有类似这样的功能: glDrawElementsBaseVertex

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

索引缓冲区就是:0, 100, 1, 101, 2, 102, 3, 103,... 98, 198, 99, 199

通过一些调整,您甚至可以使用 glMultiDrawElementsBaseVertex :

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

这篇关于OpenGL-glDrawArrays的索引/步幅参数的自动生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 21:56