5

To clarify, when I say 'default framebuffer' I mean the one provided by the windowing system and what ends up on your monitor.

To improve my rendering speeds for a CAD app, I've managed to separate out the 3D elements from the Qt-handled 2D ones, and they now each render into their own FBO. When the time comes to get them onto the screen, I blit the 3D FBO onto the default FB, and then I want to blend my 2D FBO on top of it.

I've gotten to the blitting part fine, but I can't see how to blend my 2D FBO onto it? Both FBOs are identical in size and format, and they are both the same as the default FB.

I'm sure it's a simple operation, but I can't find anything on the net - presumably I'm missing the right term for what I am trying to do. Although I'm using Qt, I can use native OpenGL commands without issue.

cmannett85
  • 21,725
  • 8
  • 76
  • 119

3 Answers3

7

A blit operation is ultimately a pixel copy operation. If you want to layer one image on top of another, you can't blit it. You must instead render a full-screen quad as a texture and use the proper blending parameters for your blending operation.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • This just seems horribly inefficient though, I have two arrays of pixel values (the buffers) of equal size, ultimately all I need to do is apply a math operation to merge an element of one of them to the corresponding element of the other. Does OpenGL really only treat FBOs as textures? – cmannett85 Jan 23 '12 at 14:50
  • @cbamber85 rendering to texture wouldn't be that inefficient – BЈовић Jan 23 '12 at 15:06
  • 1
    @cbamber85: "Does OpenGL really only treat FBOs as textures?" FBOs are just containers for images. You attach images to FBOs, but the FBO itself doesn't own them. The images come from other objects: textures and renderbuffers. And however "inefficient" it might seem, rendering one image on top of another is exceedingly fast. No vertex transforms. Nothing more than texture sampling in the fragment shader. Plus the API doesn't give you another way to do it, so it is as efficient as it gets. – Nicol Bolas Jan 23 '12 at 15:16
  • Well if that's the way to do it, I can't argue. – cmannett85 Jan 23 '12 at 15:18
  • 1
    @cbamber85: A textured quad is MUCH faster than blit. Also, you can do the blit-and-blend-over in one pass, if using a shader is an option. This will again be MUCH faster (one pass and no blending, i.e. read-modify-write, needed). – Damon Jan 23 '12 at 15:42
1

You can use GL_EXT_framebuffer_blit to blit contents of the framebuffer object to the application framebuffer (or to any other). Although, as the spec states, it is not possible to use blending:

The pixel copy bypasses the fragment pipeline. The only fragment operations which affect the blit are the pixel ownership test and the scissor test.

So any blending means to use fragment shader as suggested. One fullscreen pass with blending should be pretty cheap, I believe there is nothing to worry about.

the swine
  • 10,713
  • 7
  • 58
  • 100
0

use shader to read back from frame buffer. this is OpenGL ES extension, not support by all hardware.

https://www.khronos.org/registry/gles/extensions/EXT/EXT_shader_framebuffer_fetch.txt

andrewchan2022
  • 4,953
  • 45
  • 48