是否可以使用带有立方体贴图颜色附件的深度渲染缓冲区?
Posted
技术标签:
【中文标题】是否可以使用带有立方体贴图颜色附件的深度渲染缓冲区?【英文标题】:Is it possible to use a depth renderbuffer with cubemap color attachment? 【发布时间】:2020-11-06 09:47:38 【问题描述】:我正在尝试创建一个帧缓冲区,其中 GL_TEXTURE_CUBE_MAP 作为颜色附件,GL_DEPTH24_STENCIL8 作为帧缓冲区渲染缓冲区的深度附件。
我相信这会起作用,就像它对带有 GL_TEXTURE_2D 颜色附件的帧缓冲区和带有 GL_DEPTH24_STENCIL8 作为深度组件的渲染缓冲区一样。但是,它似乎不适用于 GL_TEXTURE_CUBE_MAP 颜色附件,因为我收到 Framebuffer Incomplete 错误。另外,请注意,我正在尝试一次创建多个帧缓冲区。
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);
我不明白为什么会出现帧缓冲区不完整错误。我在这里错过了什么吗?
【问题讨论】:
【参考方案1】:没有。
您必须为深度缓冲区附件创建一个格式为GL_DEPTH24_STENCIL8
的GL_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);
【讨论】:
是的,行得通!这不会给出任何完整性错误。以上是关于是否可以使用带有立方体贴图颜色附件的深度渲染缓冲区?的主要内容,如果未能解决你的问题,请参考以下文章
在 OpenGL ES 中为帧缓冲区使用深度和模板渲染缓冲区附件