Added support for optionally calling releaseContext at the end of each

renderinTraversals() to help with cases where uses are driving multiple
contexts from mulitple viewers in a single threaded frame loop.
This commit is contained in:
Robert Osfield 2008-06-04 16:46:14 +00:00
parent 338be0b926
commit 282fa84789
4 changed files with 26 additions and 3 deletions

View File

@ -140,6 +140,18 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
bool getQuitEventSetsDone() const { return _quitEventSetsDone; }
/** 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; }
/** Hint to tell the renderingTraversals() method whether to call relaseContext().*/
bool getReleaseContextAtEndOfFrameHint() const { return _releaseContextAtEndOfFrameHint; }
/** Set the UpdateVisitor. */
void setUpdateVisitor(osgUtil::UpdateVisitor* updateVisitor) { _updateVisitor = updateVisitor; }
@ -225,7 +237,7 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
/** Get the keyboard and mouse usage of this viewer.*/
virtual void getUsage(osg::ApplicationUsage& usage) const = 0;
protected:
inline void makeCurrent(osg::GraphicsContext* gc)
@ -255,6 +267,7 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
bool _done;
int _keyEventSetsDone;
bool _quitEventSetsDone;
bool _releaseContextAtEndOfFrameHint;
ThreadingModel _threadingModel;
bool _threadsRunning;

View File

@ -184,6 +184,8 @@ int CompositeViewer::run()
}
}
setReleaseContextAtEndOfFrameHint(false);
return ViewerBase::run();
}

View File

@ -316,6 +316,8 @@ int Viewer::run()
{
setCameraManipulator(new osgGA::TrackballManipulator());
}
setReleaseContextAtEndOfFrameHint(false);
return ViewerBase::run();
}

View File

@ -43,6 +43,7 @@ ViewerBase::ViewerBase():
_done = false;
_keyEventSetsDone = osgGA::GUIEventAdapter::KEY_Escape;
_quitEventSetsDone = true;
_releaseContextAtEndOfFrameHint = true;
_threadingModel = AutomaticSelection;
_threadsRunning = false;
_endBarrierPosition = AfterSwapBuffers;
@ -55,6 +56,7 @@ ViewerBase::ViewerBase(const ViewerBase& base):
_done = false;
_keyEventSetsDone = osgGA::GUIEventAdapter::KEY_Escape;
_quitEventSetsDone = true;
_releaseContextAtEndOfFrameHint = true;
_threadingModel = AutomaticSelection;
_threadsRunning = false;
_endBarrierPosition = AfterSwapBuffers;
@ -721,8 +723,12 @@ void ViewerBase::renderingTraversals()
_endDynamicDrawBlock->block();
// osg::notify(osg::NOTICE)<<"Time waiting "<<osg::Timer::instance()->delta_m(startTick, osg::Timer::instance()->tick())<<std::endl;;
}
if (_releaseContextAtEndOfFrameHint)
{
osg::notify(osg::NOTICE)<<"Doing release context"<<std::endl;
releaseContext();
}
if (getStats() && getStats()->collectStats("update"))
{