The framebuffer setup should be merged with ActivateContext, but not by simply setting the framebuffer to 0. Currently there are two issues: the one you are seeing(the complaints from opengl), and multithreading issues.
Parts of the code call ActivateContext before setting the fbo: In this case you can get errors in glDrawBuffers. Other parts call the fbo setup before calling ActivateContext. In this case the app can crash after a rendering thread switch because no GL context is active.
Ah, ok, I think I've seen the threading issues as well.
The whole issue is pretty complex unfortunately. One issue is that we cannot select context and drawable separately for onscreen rendering, and pbuffer offscreen rendering. In the case of fbos, the drawable can be set without changing the context.
Another issue is that ActivateContext deals with one buffer only, but with fbo we can have multiple simultaneous ones(GL_ARB_draw_buffers, or multiple render targets in d3d speak). In case of onscreen rendering only one render target may be active from the d3d side, and in case of back/aux and pbuffer offscreen rendering we're limited to one target from the opengl side.
What has to be done in some way is to merge apply_fbo_state() with ActivateContext. My original idea was to select the primary target and the depthstencil buffer in ActivateContext similarly to the existing code, and have higher render targets set in the state manager. Unfortunately drivers do not like that, and we have to set all color and depth attachments of the fbo at once.
Thanks for the info.
- Allan