I am trying to make multipass offscreen rendering and I stuck in one question ( more like a problem ). What's should be concept of capturing multiple passes? Currently I got this:
Init:
Create FBO #1
Create FBO #2
Create Postprocess shader #1 (lighting)
Create Postprocess shader #2 (gamma, exposure, color control etc..)
Render:
Bind FBO #1
RenderScene();
Unbind FBO
Bind FBO #2
Bind Postprocess shader #1
BIND FBO #1 TEXTURE ( with scene )
DRAWQUAD(); // And apply lighting etc..
Unbind;
// Now simply draw quad with FBO #1 texture.
Bind Postprocess shader #2 // Apply color corrections..
DRAWQUAD();
Unbind;
As I read in some presentation, it's better to use multiple FBOs, but some people say that it's better to use single FBO and switch attachments, - it's faster, but driver may validate too much ( performance will suffer of course ). I am using OSX10.11, OpenGL profiler indeed shows that glBindFramebuffer is x20 slower than glFramebufferTexture(Layer.., attachment). But then in this case if I use single FBO, how should I render to texture? Because now I can't do DRAWQUAD(); twice.. Example of what I think if I will be able to use Single FBO with different attachments.
Init:
Create FBO #1 // Only one frame buffer.
Create Postprocess shader #1 (lighting)
Create Postprocess shader #2 (gamma, exposure, color control etc..)
Render:
Bind FBO #1
RenderScene()
.. What should I do on this stage? because FBO is filled by scene data and I can't just DRAWQUAD(); here.
EDIT: Is it right thing to do?
// glBindFramebuffer #1
// draw to layer 0
// glUnbind
// glBindFramebuffer #1
// draw to layer 1 texture from layer 0 ( quad )
// glUnbind
// glBindFramebuffer #1
// draw to layer 2 texture from layer 1 ( quad too )
// glUnbind
// ... and simply draw quad with layer 2 texture