我有以下代码。我正在尝试创建一个具有两个颜色附件和一个深度模板附件的Multisample Framebuffer。
/* Generate Framebuffer and textures & renderbuffers */
glGenFramebuffers(1, &m_framebuffer);
glGenTextures(1, &m_fboColorAttachment);
glGenTextures(1, &m_fboAdditionalInfo);
glGenRenderbuffers(1,&m_fboRenderbufferDepthStencil);
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
/* setup color output 0 */
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_fboColorAttachment);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA8, renderDimensionsX, renderDimensionsY, GL_FALSE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, m_fboColorAttachment, 0);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
/* setup color output 1 */
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_fboAdditionalInfo);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_R32UI, renderDimensionsX, renderDimensionsY, GL_FALSE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, m_fboAdditionalInfo, 0);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
/* setup depth and stencil */
glBindRenderbuffer(GL_RENDERBUFFER, m_fboRenderbufferDepthStencil);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, renderDimensionsX, renderDimensionsY);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_fboRenderbufferDepthStencil);
auto status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
std::wstring statusStr = L"WTF error";
if(status == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT)
statusStr = L"Attachment";
else if(status == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)
statusStr = L"Missing attachment";
else if(status == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER)
statusStr = L"Draw buffer";
else if(status == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER)
statusStr = L"Read buffer";
else if(status == GL_FRAMEBUFFER_UNSUPPORTED)
statusStr = L"Unsupported";
else if(status == GL_FRAMEBUFFER_UNDEFINED)
statusStr = L"Undefined";
else if(status == GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE)
statusStr = L"Multisample";
else if(status == GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS)
statusStr = L"Layer targets";
drawFuncLog << L"Framebuffer status: " << statusStr << L"\r\n";
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
我正在返回GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
状态。据我所知,所有内容都是以多重采样的形式创建的,并且多重采样级别的数量在附件中匹配。附件不完整显然意味着我的附件之一不完整,我认为是深度模板渲染缓冲区。
答案 0 :(得分:2)
请参见OpenGL 4.6 API Core Profile Specification; 9.4.2 Whole Framebuffer Completeness; page 326:
如果满足以下所有条件,则绑定到目标的帧缓冲区对象被认为是完整的帧缓冲区:
......
- 所有附加纹理的
TEXTURE_FIXED_SAMPLE_LOCATIONS
值都相同;并且,如果附加的图像是渲染缓冲区和纹理的混合,则所有附加的纹理的TEXTURE_FIXED_SAMPLE_LOCATIONS
的值必须为TRUE
。
这意味着您必须将两个纹理附件的GL_TRUE
传递到glTexImage2DMultisample
的最后一个参数,以解决此问题:
glTexImage2DMultisample(
GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA8, renderDimensionsX, renderDimensionsY, GL_TRUE);
glTexImage2DMultisample(
GL_TEXTURE_2D_MULTISAMPLE, 4, GL_R32UI, renderDimensionsX, renderDimensionsY, GL_TRUE);