gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:15:22 25 4
gpt4 key购买 nike

我正在尝试创建一个帧缓冲区,并使用GL_TEXTURE_CUBE_MAP作为颜色附件,并将GL_DEPTH24_STENCIL8作为深度缓冲区用于帧缓冲区的渲染缓冲区。
我坚信这会奏效,就像对带有GL_TEXTURE_2D颜色附件的帧缓冲区和以GL_DEPTH24_STENCIL8作为深度组件的渲染缓冲区一样。但是,它对于GL_TEXTURE_CUBE_MAP颜色附件似乎不起作用,因为我收到了Framebuffer Incomplete错误。另外,请注意,我正在尝试一次创建多个Framebuffer。

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);
}
我不明白为什么会收到Framebuffer不完整的错误。我在这里想念什么吗?

最佳答案

没有。
您必须为深度缓冲区附件创建一个格式为GL_TEXTURE_CUBE_MAPGL_DEPTH24_STENCIL8纹理。例如:

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);
}

关于c++ - 是否可以使用带有立方贴图颜色附件的深度渲染缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64712273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com