Lets say I have four content layers: A, B, C and D; each one represents one type of visual content.
Each layer does several sequential render calls (there are no interleaved render calls from the various layers).
Also, layer B and D need to be rendered to textures in order to apply visual effects. In order to reduce the memory footprint, I use only one FBO with only one texture.
So, at the moment I do:
- Render A content;
- Bind FBO > Render B content > Unbind FBO > Render texture (B content);
- Render C;
- Bind FBO > Render D content > Unbind FBO > Render texture (D content).
My main problem with this approach is that every time I bind/unbind the FBO, the default framebuffer is saved/restored to/from memory.
I cannot simply draw layers B and D to the FBO first , since I cannot change the rendering order of layers.
Is there any better way to do this and avoid many saves/restores of the main framebuffer? Keep in mind that this is an example and the real case is more complex (more layers).