How do I get OSG to re-create all GL objects in response to the GL context 
being recreated?

I'm trying to get my Android GLES2 app to gracefully handle switching to/from 
the Activity where OSG is running, as well as to handle sleep/wake.  Whenever 
these happen, the EGL context is lost, and all GL objects (buffers, textures, 
programs, etc.) are silently deleted.

Therefore, the usual approach is to call glGen*()  when the EGL surface is 
recreated.  Calling glDelete* is counter-productive; the GL objects are already 
gone.

I've tried using osg::discardAllGLObjects(), thinking that this will force OSG 
to regenerate the GL objects during the next frame().  It appears to correctly 
discard the VBOs and texture objects, but it does not discard shaders or 
programs.


Code:
void osg::discardAllGLObjects(unsigned int contextID)
{
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
osg::Drawable::discardAllDeletedDisplayLists(contextID);
#endif

#ifdef OSG_GL_FIXED_FUNCTION_AVAILABLE
osg::FragmentProgram::discardDeletedFragmentProgramObjects(contextID);
osg::VertexProgram::discardDeletedVertexProgramObjects(contextID);
#endif

osg::GLBufferObject::discardAllBufferObjects(contextID);
osg::Texture::discardAllTextureObjects(contextID);[/b]

osg::FrameBufferObject::discardDeletedFrameBufferObjects(contextID);
osg::Program::discardDeletedGlPrograms(contextID);
osg::RenderBuffer::discardDeletedRenderBuffers(contextID);
osg::Shader::discardDeletedGlShaders(contextID);
osg::OcclusionQueryNode::discardDeletedQueryObjects(contextID);
}



As you can see, this function will discard shaders and programs which have 
already been deleted, but as far as OSG knows, none of them have been deleted.  
The textures and buffers each have centralized managers, but the shaders and 
programs do not.

How should I approach this problem?  Is there a straightforward way to fix 
osg::discardAllGLObjects() so that it will discard all GL shader objects?  Do I 
need to track all of my osg::Shader instances myself so I can call 
Shader::releaseGLObjects() and Shader::dirtyShader()?

Thanks,
James

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49231#49231





_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to