FBO, textures and MRT problems


I’m having several troubles with FBO use and textures attached to them.

  1. I first have an FBO with two binded textures. After a draw into it, I’d want to use the same FBO but with only one texture bound. How can I unbound the second one ? Is it ok to just call

I’ve tried this but it seems that the glClear() still affects the two textures.
(observed with REMEDY gDebugger)

  1. I want to reuse the same FBO but with others textures attached. Is that enough to bound new textures using glFramebufferTexture2DEXT() or is there something to do to unbound previous textures properly ?
    After a try it seems that the first textures memory is erased once new ones are bound (I observed that they turned to black on gDebugger, but maybe this is a bug or misunderstanding of the software).

Thanks a lot for help.

For question #2, I’ve been using the same FBO to render to different textures for some time and it works just fine. In my experience, it was faster to re-bind a texture with same geometry and format to the 1st color attachment than binding another FBO set up for rendering to that texture (on G80 at least). I was using just one texture as color attachment 0 and a renderbuffer for depth (same one for every textures).

For question #1 it’s possible that once you set up your FBO and used it as render target, you can no longer change the geometry and formats of color attachments. Have to check the spec.

For Q1. Just set glReadBuffer and glDrawBuffer to gl_Color_Attachment0.

Same for question 2 as well. It’s all in what you provide glDrawBuffer/glDrawBuffers. You can have a number of textures attached to the FBO and only render to one or a subset of them. You don’t have to detach them from the FBO. Just make sure the ones you want to draw to are in the DrawBuffers list.

ok, and what about glClear(), does it affects only what was binded by glDrawBuffers() or everything attached to the bound FBO ?

The former:

http://www.opengl.org/sdk/docs/man4/xhtml/glClear.xml :

Multiple color buffers can be cleared simultaneously by selecting more than one buffer at a time using glDrawBuffer.

glDrawBuffers() applies here as well.