0

I'm trying to render 3D scene to multisample FBO. I creating FBO with following code 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();

And I get error GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE. What I'm doing wrong?

A have read this topic, FBO documentation, but it doesn't help.

I can create FBO without depth attachment. But in this case it doesn't working when I trying bilt it to the screen:

 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);

Help me please.

Community
  • 1
  • 1

1 Answers1

0

You need to specify fixed sample locations. e.g. GL_TRUE for the last parameter of glTexImage2DMultisample.

You can read about the reasons for GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE here.

RamblingMad
  • 5,332
  • 2
  • 24
  • 48