Hi James, You'll need to tell the scene graph first that you are disposing of a graphics context, this can be done via rooNode->releaseGLObjects(State*), then after this the internal buffers of released GL objects will need to be deleted or discarded depending upon whether you have have control over the release of original the context. If you have control over the destruction of the graphics context then simple call rootNode->releaseGLObjects(State*) and then osg::deleteAllGLObjects(contextID) from a thread with context current and then dispose of the context. If you don't have control over the destruction then call the releaseGLObjects(..) then deleteAllGLObjects(..).
Robert. On 10 August 2012 21:48, James Athey <[email protected]> wrote: > 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 > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

