ofFbo depthStencilAsTexture aliasing


I’m working with FBO with depthStencilAsTexture as true to do a DOF post-processing after the render in my FBO, but there is no MSAA with depthStencilAsTexture as true.

So what is your advice to get a nice render in an FBO when you need to work with depthmap in post processing ? add a FXAA pass ? try to implement the glTexImage2DMultisample() / texelFetch() ? use a multisampled framebuffer and make texture copy with glBlitFramebuffer() ?

Thanks a lot :slight_smile:

when you use a multisampled fbo there’s always a blit going on so that’s probably the best option (and probably something that should be done internally by ofFbo) just create an fbo with multisample and a renderbuffer for depth then blit it to a non multisample fbo with a texture attachment for the depth and use that second fbo both for getting the color and depth attachments (otherwise there would be 2 blits)

1 Like


Again, thank you for your help, you’re the master :slight_smile:

Anyway, I implemented the solution below that works really fine, but as i’m a beginner in openGL, can you confirme me I do this the right way ? do I have to add the glReadBuffer(GL_BACK); at the end ? (I checked the GL_READ_BUFFER / GL_DRAW_BUFFER state after binding to the previous FBO and everything seems OK, but i just wanted you advise).

    GLint previousFboId = 0;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previousFboId);
    glBindFramebuffer(GL_READ_FRAMEBUFFER, shadowMapFboMSAA.getId());
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, shadowMapFbo.getId());
    glBlitFramebuffer(0, 0, settings.width, settings.height, 0, 0, settings.width, settings.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
    glBlitFramebuffer(0, 0, settings.width, settings.height, 0, 0, settings.width, settings.height,  GL_DEPTH_BUFFER_BIT, GL_NEAREST);
    glBindFramebuffer(GL_FRAMEBUFFER, previousFboId);
1 Like

oh i thought that ofFbo already had a blit method, in anycase that looks correct to me and since you are probably not doing any other reading operations and OF sets the read buffers always when it needs it’s probably ok to leave it like this

1 Like

Indeed, ofFbo have an internal blit method but (as I understand) only for the color attachement, not the depth attachement. So when you want to render in an MSAA ofFbo you can’t access the depthbuffer as a texture because it’s stored into an RBO. So the only solution I found, thanks to you, is to blit the depthbuffer of an MSAA ofFbo to a non MSAA ofFbo and then use the depthbuffer as a texture in post-processing render passes.

Just coming across this issue and going to use your solution @arturo. Is there a reason that multisampled depth textures aren’t allowed by ofFbo? Do they just need to be implemented in there?

I think it’s just to make the most common case simpler: use a multisampled texture to draw but then blit it to a non multisampled to be able to use it. since reading a multisampled texture from a shader is kind of complex and not needed for most cases