[osg-submissions] [osg-users] Threading problem when using twoviewers
Wiedemann, Rudolf, OPS3
rudolf.wiedemann at mbda-systems.de
Wed Jun 4 09:44:26 PDT 2008
Hi Robert,
it works fine! Thank you very much!
Sorry for the amateurish code I submitted - after a long day at work one should better return home instead of trying some quick hacks...
Rudi
-----Ursprüngliche Nachricht-----
Von: osg-submissions-bounces at lists.openscenegraph.org [mailto:osg-submissions-bounces at lists.openscenegraph.org] Im Auftrag von Robert Osfield
Gesendet: Mittwoch, 4. Juni 2008 18:00
An: OpenSceneGraph Submissions
Betreff: Re: [osg-submissions] [osg-users] Threading problem when using twoviewers
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.
_______________________________________________
osg-submissions mailing list
osg-submissions at lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
More information about the osg-submissions
mailing list