我正在尝试将 3D 场景渲染为多重采样 FBO。我使用以下代码 FBO 创建 FBO:
GLuint fbo, vtex, depthbuffer;
glGenTextures(1, &vtex); GLCHECK();
glBindTexture( vtarget, vtex ); GLCHECK();
glTexImage2DMultisample( GL_TEXTURE_2D_MULTISAMPLE, samples /*=4*/, GL_RGBA, width, height, false); GLCHECK();
glBindTexture(vtarget, 0); GLCHECK();
glGenRenderbuffers(1, &depthbuffer); GLCHECK();
glBindRenderbuffer(GL_RENDERBUFFER, depthbuffer); GLCHECK();
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples/*=4*/, GL_DEPTH_COMPONENT32, width, height); GLCHECK();
glBindRenderbuffer(GL_RENDERBUFFER, 0); GLCHECK();
glGenFramebuffers( 1, &fbo );GLCHECK();
glBindFramebuffer( GL_FRAMEBUFFER, fbo );GLCHECK();
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffer); GLCHECK();
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, vtex, 0 ); GLCHECK();
if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE)
{
fprintf(stderr, "Can't allocate frame buffer! Status: 0x%x\n", status);
assert(0);
}
glBindFramebuffer(GL_FRAMEBUFFER, 0); GLCHECK();
我得到错误 GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE。我做错了什么?
A 已阅读 此主题,FBO 文档,但没有帮助。
我可以创建没有深度附件的 FBO。但在这种情况下,当我尝试将它放到屏幕上时它不起作用:
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); GLCHECK();
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); GLCHECK();
glDrawBuffer(GL_BACK); GLCHECK();
glBlitFramebuffer(0, 0, resolution.width, resolution.height, 0, 0, resolution.width, resolution.height, GL_COLOR_BUFFER_BIT, GL_NEAREST); GLCHECK();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
请帮帮我。