PDA

View Full Version : How to do MRT with color buffer from default FBO?



Sergey Nenakhov
11-04-2011, 12:55 PM
Hi,

For my MRT shader I need just 2 color buffers total, and there is already one in the default frame buffer, but I can't find a way to retreive it so that I can attach it to another FBO to do my MRT algorithm. Is this possible to do ?

Thanks.

thokra
11-04-2011, 01:45 PM
If you're hardware is OpenGL 3.0 capable, you can blit the default framebuffer to the color attachment of the FBO.

The GL keeps track of one or read and one or more draw buffers. When you bind the FBO with GL_DRAW_FRAMEBUFFER it's bound as the target for drawing operations. The back buffer of a double-buffered context is initially bound as both a draw and read framebuffer.

You can copy the contents of the back buffer to the FBO by:




// first bind FBO as draw framebuffer
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);

// copy contents from back buffer to color attachment
// this assumes the default fb and the fbo have equal dimensions
void glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);


Please tell if this helps.

Alfonse Reinheart
11-04-2011, 02:55 PM
No. You can't attach an image from the default framebuffer to an FBO. You have to create a new image instead and then copy it to the framebuffer. You can use a blit, as thokra suggests, or draw a full-screen quad.