Hi Terry,

I'm not clear on the sequence of events in your app, but it does look
like you are probably doing a couple of things that shouldn't be
required.

First up, it is possible to release all the GL objects in the
scenegraph, flush the deleted GL objects, delete a graphics context,
and then reuse the same ContextID for a new graphics context, as all
the slots for this contextID shoudl be cleared already.  I've tested
this sequence out with using osgViewer and it works fine.

One thing to be wary of is that that you have to do the
osg::flushAllGLObjects(contextID) from the graphics thread of the
graphics context that you are about to delete as it does all the
glDelete's of the various OpenGL object ID's.  If your graphics
context has already been deleted then you'll need to call
osg::discardAllDeletedGLObjects(contextID) which will clear out all
the internal buffers storing the deleted OpenGL object id's without
attempt to do any GL calls.  Note, the osgUtil::SceneView calls just
call the osg::flush/discard.. methods.

If these internal OpenGL object buffers aren't empty when you create
your new graphics context then you'll find the OSG will try to reuse
those OpenGL objects believing them to still be relevant - and this
will cause a range of problems from crashes to missing textures.
Incrementing the ContextID for each new context will work around this
reuse as it'll force the OSG to create a new set of buffer entries for
the new context, but if you manage things correctly it won't be
necessary.

osgViewer will actually do a lot of this work for you, so I'd
recommend using it instead of digging down into the low level
SceneView.

Robert.


On Sun, Oct 25, 2009 at 10:27 PM, Terry Welsh <[email protected]> wrote:
> Thanks for the suggestions Robert.  I played around with rebuilding my
> OpenGL objects some more and found that the necessary steps are:
>
> sceneview->releaseAllGLObjects();
> state->setContextID(state->getContextID() + 1);
>
> For completness's sake, I've been doing this
>
> scenegraphroot->releaseGLObjects();
> sceneview->releaseAllGLObjects();
> sceneview->flushAllDeletedGLObjects();
> state->setContextID(state->getContextID() + 1);
>
> However, the extra two steps don't appear to be necessary.
>
> If I only increment the context ID and do nothing else, most OpenGL
> objects get rebuilt except for the ones that were onscreen at the time
> of the context switch.  This makes it look as if all objects not
> culled on the last frame do not get re-initialized.
>
> So while I have a working solution, it might be fragile since I still
> don't completely understand what's going on inside OSG.  I'd like to
> hear any other thoughts you or anyone else have on this problem.
> --
> Terry Welsh  /  mogumbo 'at' gmail.com
> www.reallyslick.com  /  www.mogumbo.com
>
>
>>
>> Message: 11
>> Date: Mon, 19 Oct 2009 09:01:21 +0100
>> From: Robert Osfield <[email protected]>
>> To: OpenSceneGraph Users <[email protected]>
>> Subject: Re: [osg-users] re-initialize OpenGL objects after window
>>        resize
>> Message-ID:
>>        <[email protected]>
>> Content-Type: text/plain; charset=ISO-8859-1
>>
>> Hi Terry,
>>
>> On Sun, Oct 18, 2009 at 11:12 PM, Terry Welsh <[email protected]> wrote:
>>> I'm working on and OSG/SDL application. ?Resizing the window in Linux
>>> works fine, but resizing it in Windows causes the app to lose all its
>>> OpenGL objects. ?Is there a recommended way to re-initialize all
>>> OpenGL objects?
>>
>> I really wouldn't recommend using SDL for windowing...
>>
>> In your case it does sound like SDL is deleting the original graphics
>> context and then recreating a completely new one on resize.
>>
>>> So far I have been experimenting with SceneView's releaseAllGLObjects,
>>> flushAllDeletedGLObjects, and COMPILE_GLOBJECTS_AT_INIT. ?But this has
>>> mostly led to crashes and hasn't fixed the problem. ?Just thought I
>>> would take a break and see if anyone has any other suggestions....
>>
>> The problem is that the scene graph itself is retaining handles to the
>> original OpenGL objects and still has this around when you try to
>> reapply them to a completely new graphics context, which
>> unsurprisingly causes problems.  The scene graph itself doesn't know
>> about the fact that you've changed the graphics context from
>> underneath it so you'll need to tell it but doing a
>> scenegraph->releaseGLObjects();   The SceneView methods just clean up
>> already released GL objects, so you'd call these after the scenegraph
>> release.
>>
>> Robert.
>>
>>
> _______________________________________________
> 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

Reply via email to