OpenGL:如何访问应用程序中所有当前缓冲区的信息?

时间:2014-10-01 14:02:04

标签: opengl buffer extraction

如何访问应用程序中所有当前缓冲区的信息?例如,要知道我的应用程序在某个帧上使用的所有活动VBO。

编辑1: 三十二上校和Reto Koradi的答案给了我一个获取缓冲区信息的一般想法,似乎应用程序没有显示任何缓冲区(glGetVertexAttribiv),但我设法列出了我的当前缓冲区:

GLint isEnabled = GL_TRUE;
for (GLint iAttrib = 1; isEnabled; ++iAttrib) {
    isEnabled = glIsBuffer(iAttrib);
    if (isEnabled) {
        //I'm listing all buffer data in a string vector at the moment
        bufferInfoData.push_back("Buffer: " + std::to_string(iAttrib) + ">");
    }
}

这导致缓冲区1到15的以下输出:

Buffer: 1>
Buffer: 2>
Buffer: 3>
... etc etc
Buffer: 14>
Buffer: 15>

但是,我想知道这些缓冲区中的哪种类型和数据,我也不确定在没有启用计数缓冲区之前是否正确地列出所有缓冲区。

1 个答案:

答案 0 :(得分:1)

要获取用于当前启用的顶点属性的所有缓冲区,可以使用如下代码:

GLint nAttrib = 0;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nAttrib);
for (GLint iAttrib = 0; iAttrib < nAttrib; ++iAttrib) {
    GLint isEnabled = GL_FALSE;
    glGetVertexAttribiv(iAttrib, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &isEnabled);
    if (isEnabled) {
        GLint bufferId = 0;
        glGetVertexAttribiv(iAttrib, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &bufferId);
    }
}

请注意,如果它用于多个属性,则会多次为您提供相同的缓冲区。

相关问题