我正在尝试使用我的Frame Buffer进行多次采样(用于后期处理)。我可以通过忽略Depth Buffer来使它几乎工作,但是我得到的问题是没有渲染的面孔。
我像这样设置了我的普通帧缓冲区
glBindTexture(GL_TEXTURE_2D, m_Texture);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGB, 1280, 720, 0, GL_RGB, GL_UNSIGNED_BYTE, 0
);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_Texture, 0
);
// Create color render buffer
glGenRenderbuffers(1, &m_TexColorBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_TexColorBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB, 1280, 720);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_TexColorBuffer);
// Create depth render buffer (This is optional)
glGenRenderbuffers(1, &m_RBODepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_RBODepthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 1280, 720);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RBODepthBuffer);
然后我还创建了一个像这样的多采样帧缓冲区。
glEnable(GL_MULTISAMPLE);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_Texture);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGB, 1280, 720, GL_FALSE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_Texture, 0);
glGenRenderbuffers(1, &m_TexColorBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_TexColorBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGB, 1280, 720);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_TexColorBuffer);
/* glGenRenderbuffers(1, &m_RBODepthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_RBODepthBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_DEPTH_COMPONENT24, 1280, 720);
glFramebufferRenderbuffer(
GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_RBODepthBuffer
);*/
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_Texture, 0);
此代码(深度缓冲区上注释掉的部分)确实产生了一个正确显示但没有深度的多采样纹理我得到的面部没有渲染或法线方向错误(所以我从模型中看到的角度)。但是,如果我取消注释该部分,那么
glCheckFramebufferStatus(GL_FRAMEBUFFER)
返回
36182
接着是
Error 00000506 after convex fill
最终是一个黑屏。
我正在使用glBlitFramebuffer将多样本fbo复制到单样本fbo(它可以解决前面提到的问题)。
此时真的陷入困境,无法在任何地方找到解决方案!
答案 0 :(得分:1)
所以我找到了答案,感谢源伪造的随机项目的一些过时的文档。
我的错误是GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
有了这个信息,我发现错误意味着什么
GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE is also returned if the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not the same for all attached textures; or, if the attached images are a mix of renderbuffers and textures, the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not GL_TRUE for all attached textures.
所以改变
末尾的GL_FALSEglTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGB, 1280, 720, GL_FALSE);
到GL_TRUE修复它。所以
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGB, 1280, 720, GL_TRUE);