FBO replacing previous FBO contents entirely

Hey,

I wondered if anyone could give me some advice on a problem I am facing with FBOs.

As a basic example of what i’m trying to do, if I have a screen of 100x100, I create two FBOs, each the same size as the screen. On the first FBO I draw an ‘X’ on the top half, on the second FBO I draw a ‘Y’ on the bottom half. I then blit each FBO to the screen. However, when i do this i only see the contents of the final FBO I drew. Is there a way to allow both FBOs to be seen?

That’s what’s supposed to happen. glBlitFramebuffer() is a copy operation (with optional resizing and/or downsampling). It is not a compositing operation.

For more detail, see: Framebuffer : Blitting in the OpenGL Wiki.

It’s unclear exactly what you want here, or why you think Blit should do it. But consider…

  1. Blitting top-half of 1st FBO to top-half of window, and Blitting bottom-half of 2nd FBO to bottom-half of window.
  2. Blitting the 1st FBO to the window, and then rendering the contents of 2nd FBO onto the window (with blending)
  3. After rendering ‘X’ on 1st FBO, render ‘Y’ on 1st FBO with blending, then blit 1st FBO to window. Delete 2nd FBO.

Thanks @Dark_Photon, I made the mistake of thinking blitting would composite instead of replace.

If it helps makes things any clearer as to what I’m trying to achieve:

  • I initially was not using an FBO (other than the default ‘screen’ FBO). I created a series of external textures (this is on Android ‘GLES11Ext.GL_TEXTURE_EXTERNAL_OES’ vs GL_TEXTURE_2D), drew them to their own quads and rendered them from back to front. This worked well and I was able to achieve the transparency I wanted using:
        GLES32.glEnable(GLES32.GL_BLEND)
        GLES32.glBlendFunc(GLES32.GL_SRC_ALPHA, GLES32.GL_ONE_MINUS_SRC_ALPHA)

This meant that even though the quad filled the screen, if i didn’t draw something to a particular part of the quad, I could see the contents of the quad behind it.

However, I now need to be able to group certain textures so that I can apply transforms to them. My first attempt at this was using an FBO to represent the group, however when drawing these to the screen I was using ‘glBlitFramebuffer’ which as you have rightly pointed out is not the correct approach.

My latest attempt is to take the 2d textures (not external texture if this changes things) from the FBOs and draw those to the screen but I am running into the same problem as I did when using ‘glBlitFrameBuffer’. Is there a way to make the FBO textures behave (in regard to transparency) as my previous textures?

Thanks.

Why? This is not clear.

And what specifically do you mean by “group certain textures”. Do you mean, instead of rendering all layers back-to-front, compositing nearby layers into layer groups and then compositing the layer groups back-to-front? If so, you may find that a different Blend Function will serve you better than (SRC_ALPHA, ONE_MINUS_SRC_ALPHA). In particular, Premultiplied Alpha (ONE, ONE_MINUS_SRC_ALPHA).

Sure. That I can see, there is nothing fundamentally different about what you were doing (before the Blit detour) and what you’re trying to do now.

Perhaps you could illustrate the problem with a specific example?

Obviously, if you don’t rendering something that covers a specific pixel, the result can’t modify that pixel.