是否可以使用带有立方体贴图颜色附件的深度渲染缓冲区?

Is it possible to use a depth renderbuffer with cubemap color attachment?

我正在尝试创建一个帧缓冲区,其中 GL_TEXTURE_CUBE_MAP 作为颜色附件,GL_DEPTH24_STENCIL8 作为帧缓冲区渲染缓冲区的深度附件。

我相信这会奏效,就像它对具有 GL_TEXTURE_2D 颜色附件的帧缓冲区和具有 GL_DEPTH24_STENCIL8 作为深度分量的渲染缓冲区一样。但是,它似乎不适用于 GL_TEXTURE_CUBE_MAP 颜色附件,因为我收到帧缓冲区不完整错误。另外,请注意,我正在尝试同时创建多个帧缓冲区。

glGenFramebuffers(5, &FBO[0]);
glGenTextures(5, &FBO_texture[0]);
glGenRenderbuffers(5, &FBO_Renderbuffer[0]);

for (unsigned int i = 0; i < 5; i++)
{
    glBindTexture(GL_TEXTURE_CUBE_MAP, FBO_texture[i]);
    for (unsigned int j = 0; j < 6; j++)
    {
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, 0, GL_R16F, shadow_map_width, shadow_map_height, 0, GL_RED, GL_FLOAT, NULL);
    }

    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

    glBindFramebuffer(GL_FRAMEBUFFER, FBO[i]);

    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBO_texture[i], 0);

    glBindRenderbuffer(GL_RENDERBUFFER, FBO_Renderbuffer[i]);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, shadow_map_width, shadow_map_height);

    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, FBO_Renderbuffer[i]);

    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
        LOGGER->log(ERROR, "Renderer :  createFrameBuffers ", "Framebuffer is incomplete!");

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
}

我不明白为什么会出现帧缓冲区不完整错误。我在这里遗漏了什么吗?

没有

您必须为深度缓冲区附件创建格式为 GL_DEPTH24_STENCIL8GL_TEXTURE_CUBE_MAP 纹理。例如:

glGenFramebuffers(5, &FBO[0]);
glGenTextures(5, &FBO_texture[0]);
glGenTextures(5, &FBO_depth_texture[0]);

for (unsigned int i = 0; i < 5; i++)
{
    glBindTexture(GL_TEXTURE_CUBE_MAP, FBO_texture[i]);
    for (unsigned int j = 0; j < 6; j++)
    {
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, 0, GL_R16F, shadow_map_width, shadow_map_height, 0, GL_RED, GL_FLOAT, NULL);
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

    glBindTexture(GL_TEXTURE_CUBE_MAP, FBO_depth_texture[i]);
    for (unsigned int j = 0; j < 6; j++)
    {
        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, 0, GL_DEPTH24_STENCIL8, shadow_map_width, shadow_map_height, 0, GL_DEPTH_STENCIL, GL_FLOAT, NULL);
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

    glBindFramebuffer(GL_FRAMEBUFFER, FBO[i]);
    glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, FBO_texture[i], 0);
    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, FBO_depth_texture[i], 0);

    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
        LOGGER->log(ERROR, "Renderer :  createFrameBuffers ", "Framebuffer is incomplete!");

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}