如何检索 FBO 的附件数量

How to retrieve number of attachments to FBO

如何获取当前绑定 FBO 的颜色附件数量?我检查了 glGetIntegerglGetFramebufferAttachmentParameteriv 但他们没有枚举来获取这些值。

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

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 进行比较。