View Full Version : MRT fragment shader output

James A.
07-16-2011, 05:34 AM
I have 3 colour render buffers attached to my FBO and most of the time I will draw to all of them in the same shader using something like

outFragData[0] = vec4(1.0);
outFragData[1] = vec4(1.0);
outFragData[2] = vec4(1.0);

but what if I only want to draw to one of the colour buffers? is this possible without changing the bound Frame Buffer Object? currently if I draw to only one buffer I will get black coloured data in the remaining buffers, is there a way around this?

07-16-2011, 07:56 AM
A glDrawBuffers() call with the list of color attachments you want to draw to will select a subset of the FBO's attachments. If you're only selecting one, you can use glDrawBuffer(GL_COLOR_ATTACHMENT#) but you'll need to use glDrawBuffers() to restore rendering to all three.

Ilian Dinev
07-16-2011, 07:56 AM
int targets[1]={GL_COLOR_ATTACHMENT0};

Then, you restore drawing to the 3:


James A.
07-16-2011, 08:49 PM
Thanks guys, I figured that is what I'd have to do, I kind of wondering if there was a was of discarding only certian fragment outputs and not all. I guess not.