我正在尝试创建一个立方体贴图纹理来渲染阴影贴图的深度信息。我遇到过我的帧缓冲区不完整。特别是,它会返回一个GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
,根据文档意味着它上面没有附加至少一个图像。
代码是:
GLuint depth_map;
GLuint FramebufferName;
void Renderer::create_shadow_map()
{
//TODO: change render program here
glUseProgram(0);
FramebufferName = 0;
glGenFramebuffers(1, &FramebufferName);
glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
glGenBuffers(1, &depth_map);
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
glBindTexture(GL_TEXTURE_CUBE_MAP, depth_map);
for (unsigned int i = 0; i < 6; ++i)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT,
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
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);
glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depth_map, 0);
glDrawBuffer(GL_NONE); // No color buffer is drawn to.
glReadBuffer(GL_NONE);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
if(glCheckFramebufferStatus(GL_FRAMEBUFFER)==GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
cerr << "shadow map not ok" << endl;
exit(0);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
致电glGetError()
后,我就可以确定问题是glFrameBufferTexture()
行。
所以我假设我要么没有正确生成缓冲区,要么我没有将它连接到帧缓冲区。