I’ve read here as well in other places that attaching/detaching textures and render buffers from a frame buffer object is much faster than switching between fbo’s.
I generally only ever render to one or two texture(s) at a time so I have to create several fbo’s with a single texture and maybe a depth render buffer attached to it. Wouldn’t it be much faster then if I just reused the same fbo and reattached my textures and render buffers or would I run into any problems? For example, is it ok to attach several 1024x1024 RGBA render targets to a FBO, detach them later and bind a bunch of 512x512 RGB render targets to the same FBO?
The third option is fastest:
attach everything to the same fbo. (provided you have only one depth-buffer). Use glDrawBuffers() to switch around stuff. I think in most implementations the depth-buffer rules a lot of things, so try to cluster things around depth-buffers (you may need to attach the same texture onto different fbos). On some implementations, the color-format is important, too (changing from rgba8 to rg32f is expensive).
In all cases, though - renderbuffers, if you use them, are a tricky picky beast. Re-validation of an FBO should take just a hundred nanoseconds, but all mechanics around internal tricks with renderbuffers can make the gpu and drivers break a sweat if configurations change. The only reason I see in using renderbuffers nowadays - is CSAA. Or maybe purposefully allow the driver-configuration-panel (nvidia ctrl panel or CCC) override/add antialiasing settings.
That’s some interesting information, thank you!
attach everything to the same fbo. (provided you have only one depth-buffer). Use glDrawBuffers() to switch around stuff.
this would only work if all my textures are of the same size and format, right? so as soon as I wanted to render to a texture which is only half or a quarter as big as the others (for bloom, etc.), I’d have to create a second fbo anyway.
Yep. The FBO is incomplete if certain criteria, and the dimensions are among them, don’t match for every attachment. This is where my concern comes into play:
@Ilian: This does break down the moment you need two disjunctive depth buffers, right? At that point you’d have to at least swap the depth attachment.
this would only work if all my textures are of the same size and format, right?
No. The formats and sizes don’t have to be the same. The size of the overall FBO will the the smallest size along each dimension. Only for the extension version of FBO does the size have to match; the core version removes this requirement.