FBO query

I have a few questions regarding FBO’s, and in-particular the color attachments.

Am I correct in thinking that when you draw it clears all the active attachments? So you can’t draw once to color attachment 0 using gl_FragData[], and then draw again to color attachment 1 using glFragData[]. And then draw both to the screen.

If that is the case, do you think I’m better off drawing both things at once and using my shader to put one output in color attachment 0 and the next into color attachment 1. Though what I’m drawing there really isn’t any easy way of distinguishing the two.

Or would I be better off just creating a second FBO? My main concern is whether or not there is some big performance hit with binding different FBOs?

Am I correct in thinking that when you draw it clears all the active attachments? So you can’t draw once to color attachment 0 using gl_FragData, and then draw again to color attachment 1 using glFragData. And then draw both to the screen.

It’s all about glDrawBuffers. This function provides the mapping between colors output from the fragment shader and colors written to attached buffers.

If there is no binding between an output color and an attached buffer, then no color will be written. If there is such a binding, then a color will be written.

It’s like a switchboard. glDrawBuffers tells OpenGL which outputs go to which buffers. The fragment shader outputs are all numbered, either implicitly with glFragData indices, or explicitly with user-defined fragment shader outputs that are given an index. And the color buffers are numbers. So it’s just a matter of saying which numbers map to which other numbers.

Just because you have an image bound to a buffer does not mean you have to write to it. To do that, a fragment shader output must be mapped to that buffer with glDrawBuffers.

For what you seem to want to do, use glDrawBuffers to switch between which buffer gets written to. You do your first pass, where fragment shader output 0 goes to color buffer 0, then you do your second pass, where fragment shader output 0 goes to color buffer 1.

I see, thanks a lot for the explanation. Fixed the problem I was having :).