Fastest way to copy data for FBO / backbuffer?

I need to copy data either from one FBO to another, or from the FBO to the back buffer, or vice-versa. What is the preferred way of doing this? It would be nice if it treated the back buffer and FBOs the same.

GL_EXT_framebuffer_blit, though has some caveats, check the spec
though if your FBO has a texture attached then perhaps a fullscreen texture (but I assume this will be slower)

Thanks. It seems to be supported on all the SM3 hardware I tried.

If I have an FBO with multiple color attachments, can I blit just one color attachment?


BindFramebufferEXT(READ_FRAMEBUFFER_EXT, 2);
BindFramebufferEXT(DRAW_FRAMEBUFFER_EXT, 1);

glReadBuffer(GL_COLOR_ATTACHMENT0 + x);

BlitFramebufferEXT(0, 0, 640, 480,
                   0, 0, 640, 480,
                   GL_COLOR_BUFFER_BIT,
                   GL_NEAREST);

Brilliant! :smiley:

Thank you.

For the benefit of those reading this, you also need to specify the color attachment to write to:

BindFramebufferEXT(READ_FRAMEBUFFER_EXT, 2);
BindFramebufferEXT(DRAW_FRAMEBUFFER_EXT, 1);

glReadBuffer(GL_COLOR_ATTACHMENT0 + x);
glDrawBuffer(GL_COLOR_ATTACHMENT0 + x);

BlitFramebufferEXT(0, 0, 640, 480,
                   0, 0, 640, 480,
                   GL_COLOR_BUFFER_BIT,
                   GL_NEAREST);

Is it possible to blit from an FBO to the back buffer?

Yes. Just bind fbo with id 0 as DRAW_FRAMEBUFFER_EXT:

glBindFramebufferEXT(DRAW_FRAMEBUFFER_EXT, 0);
glDrawBuffer(GL_BACK);

Hmmm, this does not give control over depth copying. Is there anything I can use for copying the depth buffer from an FBO to the back buffer? What about going from the back buffer to an FBO?

Please read the instructions.. These questions are all answered there.

I assume you are aware, that in your source snippet BlitFramebufferEXT have only GL_COLOR_BUFFER_BIT specified as mask. Not GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. Or not?

What about going from the back buffer to an FBO?

Isn’t it obvious that you should bind 0 as READ_FRAMEBUFFER_BINDING_EXT ?