phoboslab/Ejecta — pull request #145 by vikerman (2013-03-18 16:45:07+00:00)
Title: When switching contexts reset frame/render buffer bindings to the last buffers bound in script

2 changes - Properly reset frame/render buffers in "prepare". Remove glClear from "present"

This is to fix an issue found while porting a Construct 2 sample with WebGL renderer.

https://dl.dropbox.com/u/24635762/construct2_rain_demo.zip

When the context switches back to the WebGL context it is always bound to the view frame and render buffers instead of the last frame / render buffers bound in code. The sample tries to delete the texture attached an offscreen Fbo but since because of context switches it resets the main frame buffer leaving it with no color buffer, resulting in an empty screen.

I have verified this change fixes the issue. Also trying to do a glGetIntegerv( GL_FRAMEBUFFER_BINDING, ... ) just before resetting the framebuffer didn't seem to work. I am guessing this information is lost during the context switch. I didn't change the resize code which uses glGetIntegerv since I didn't have a test case to test it with.

I have also removed the glClear in "present" after presenting the render buffer. This is not a functionality fix but just to remove an extra call which I think is unneeded. The presenRender buffer document seems to indicate that this is already done by the API and setting the kEAGLDrawablePropertyRetainedBacking key will have the effect required by preserveDrawingBuffer - http://developer.apple.com/library/ios/#documentation/OpenGLES/Reference/EAGLContext_ClassRef/Reference/EAGLContext.html#//apple_ref/occ/instm/EAGLContext/presentRenderbuffer: