[osg-submissions] [osg-users] Threading problem when using two viewers

Robert Osfield robert.osfield at gmail.com
Wed Jun 4 08:59:39 PDT 2008


Hi Rudi,

I've pondered about the lazy makeCurrent() that is done within Viewer
when it's running single threaded, and have come to the conclusion
that it's the lack of relaseContext() at the end of a viewer's frame()
that is also something that could cause problems with your usage
model.

What is required for your usage model is a
Viewer::renderingTraversals() method that does a makeCurrent() before
rendering then a relaseContext() after rendering, this allows the
calling thread to do what it wishes with contexts.  The lazy
makeCurrent support in Viewer also on no releaseContext() being called
on subsequent frames, if its actually called at the end of the frame
even the present code will do a makeCurrent() - this means that we
don't need to change anything w.r.t makeCurrent(), only change whether
the renderinTraversals() will call release context or not.

To control whether renderingTraversals() calls releaseContext() I've
introduced a new paramater control via
setReleaseContextAtEndOfFrameHint(), that enables/disables
releaseContext, by default this hint is now on,
so by default renderingTraversals() will call releaseContext().  The
methods docs read:

        /** Hint to tell the renderingTraversals() method whether to
call relaseContext() on the last
          * context that was made current by the thread calling
renderingTraverals().  Note, when
          * running multi-threaded viewer no threads will be made
current or release current.
          * Setting this hint to false can enable the frame loop to be
lazy about calling makeCurrent
          * and releaseContext on each new frame, helping performance.
 However, if you frame loop
          * is managing multiple graphics context all from the main
frame thread then this hint must
          * be left on, otherwise the wrong context could be left
active, introducing errors in rendering.*/
        void setReleaseContextAtEndOfFrameHint(bool hint) {
_releaseContextAtEndOfFrameHint = hint; }

The Viewer::run() method now disables this hint as it knows that no no
other viewers/contexts are being called
as it runs the whole frame loop, allow it to run at full speed - never
doing unncessary makeCurrent()/releaseContext().

For your usage model, the new code should work right right of the bag.

Could you update the latest in SVN and let me know how you get on.

Robert.


More information about the osg-submissions mailing list