glMultiDrawElementsIndirect用法

时间:2014-05-05 12:09:05

标签: c++ opengl opengl-4

好的,我正在尝试编写一个简单的渲染循环来理解glMultiDrawElementsIndirect。但此刻它冻结了我的整台计算机(Ubuntu 14.04)并迫使我重新启动它。

我将此结构定义为OpenGL规范的指导:

struct DrawElementsIndirectCommand{
    GLuint count;
    GLuint instanceCount;
    GLuint firstIndex;
    GLuint baseVertex;
    GLuint baseInstance;
};

然后我的理解是这个(伪代码):

create vertex array
create vertex buffer
create element buffer
create draw indirect buffer

bind vertex array
bind vertex buffer & allocate some base storage
bind element buffer & allocate some base storage
bind draw indirect buffer & allocate some base storage 

for every mesh in meshes
    load vertices into back of GL_ARRAY_BUFFER
    load elements into back of GL_ELEMENT_ARRAY_BUFFER
    create Draw...Command and put it at the back of GL_DRAW_INDIRECT_BUFFER

然后在我的绘图循环中:

bind vertex array

glMultiDrawElementsIndirect(
    GL_TRIANGLES,
    GL_UNSIGNED_INT,
    nullptr,
    num of commands loaded,
    0
)

这完全冻结了我的电脑D:我真的不认为我理解正确使用glMultiDrawElementsIndirect,这是正确的方法吗?我怎么能像现在这样做呢?我想将所有网格加载到一个块中。

0 个答案:

没有答案