如何检索FBO的附件数量

时间:2016-03-07 23:16:59

标签: opengl fbo

如何获取当前绑定FBO的颜色附件数量?我检查了'-|[[:blank:]]+'glGetInteger,但他们没有枚举来获取这些值。

1 个答案:

答案 0 :(得分:4)

未经测试,但应该这样做:

GLint maxAtt = 0;
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAtt);
int nAtt = 0;
for (int iAtt = 0; iAtt < maxAtt; ++iAtt) {
    GLint objType = GL_NONE;
    glGetFramebufferAttachmentParameteriv(
        GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + iAtt,
        GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &objType);
    if (objType != GL_NONE) {
        ++nAtt;
    }
}
// nAtt is the number of color attachments.

您可以使用GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME代替GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE执行类似操作,并将值与0进行比较。