多重采样OpenGL FBO

时间:2015-08-31 12:06:22

标签: opengl fbo multisampling

我正在尝试将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已阅读this主题,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);

请帮帮我。

1 个答案:

答案 0 :(得分:0)

您需要指定已修复的样本位置。例如GL_TRUE的最后一个参数glTexImage2DMultisample

您可以阅读GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE here的原因。