[osg-users] Problem with makeCurrent implementation in osgViewer

Robert Osfield robert.osfield at gmail.com
Mon Sep 10 06:20:37 PDT 2007


Hi Roger,

If your app makes the context current in a different thread than
osgViewer has for rendering to the same graphics context without
osgViewer knowing about the fact that the context has been stolen from
underneath it then it is not suprising you'll find problems.

You'll need to either add an explicit makeCurrent to make sure the
context is current, or dirty the Viewer in some way so it doesn't
assume that the context is current anymore.

Robert.

On 9/10/07, Roger James <roger at beardandsandals.co.uk> wrote:
>
>
>
>
> In my previous posts "[osg-users] Help - trying to get a wxWidgets
> implementation ofosgViewer::Viewer working!" I described a problem with the
> viewer scene not being updated.
>
>
>
> I have now tracked this down to the implementation of makeCurrent in
> osgViewer. My application renders an osg scene in its main window using osg
> but not using osgViewer. osgViewer is used to render an additional scene in
> a pop up window. If I disable the rendering of the main scene whilst the pop
> up is being displayed all works fine. However if I allow the main window
> rendering loop to run the pop up window is drawn once and then not updated.
> This is because the OpenGL rendering context has been set back that of the
> main window and this change is not being detected. The following check in
> makeCurrent only makes a change if the osg::GraphicsContext the viewer knows
> about is not the current osg::GraphicsContext the viewer knows. This does
> not wok is the current rendering context is not encapsulated in an
> osg::Graphics context that this viewer object knows about.
>
>
>
>         inline void makeCurrent(osg::GraphicsContext* gc)
>
>         {
>
>             if (_currentContext==gc) return;
>
>
>
>             releaseContext();
>
>
>
>             if (gc && gc->valid() && gc->makeCurrent()) _currentContext =
> gc;
>
>         }
>
>
>
> This used to work in SimpleViewer which I assume made an unconditional
> context switch on each frame. This means that the current implementation
> will not work if an application uses OpenGL contexts that are not
> encapsulated by an osg::GraphicsContext. I assume that it also means that
> even if the context is encapsulated it will have to be on the list for a
> particular viewer object for things to work, although I have not checked
> this.
>
>
>
> I have got a work around by unconditionally calling makeCurrent before
> calling frame in the idle  loop.
>
>
>
> Robert, is my analysis correct?
>
>
>
> Roger
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>



More information about the osg-users mailing list