Added new areThreadsRunning() method to Viewer and CompositeViewer.
Added removeView(View*) method to CompositeViewer Added stopping/starting of threads in addView/removeView
This commit is contained in:
@@ -28,6 +28,7 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced
|
||||
virtual ~CompositeViewer();
|
||||
|
||||
void addView(osgViewer::View* view);
|
||||
void removeView(osgViewer::View* view);
|
||||
|
||||
osgViewer::View* getView(unsigned i) { return _views[i].get(); }
|
||||
const osgViewer::View* getView(unsigned i) const { return _views[i].get(); }
|
||||
@@ -144,6 +145,9 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced
|
||||
/** Get the graphics operation to call on realization of the viewers graphics windows.*/
|
||||
osg::Operation* getRealizeOperation() { return _realizeOperation.get(); }
|
||||
|
||||
/** Return true if viewer threads are running. */
|
||||
bool areThreadsRunning() const { return _threadsRunning; }
|
||||
|
||||
/** Stop any threads begin run by viewer.*/
|
||||
void stopThreading();
|
||||
|
||||
@@ -169,6 +173,8 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced
|
||||
bool _quitEventSetsDone;
|
||||
|
||||
ThreadingModel _threadingModel;
|
||||
bool _threadsRunning;
|
||||
|
||||
BarrierPosition _endBarrierPosition;
|
||||
|
||||
osg::ref_ptr<osg::BarrierOperation> _startRenderingBarrier;
|
||||
|
||||
@@ -151,6 +151,9 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
|
||||
/** Set up the threading and processor affinity as per the viewers threading model.*/
|
||||
void setUpThreading();
|
||||
|
||||
/** Return true if viewer threads are running. */
|
||||
bool areThreadsRunning() const { return _threadsRunning; }
|
||||
|
||||
/** Stop any threads begin run by viewer.*/
|
||||
void stopThreading();
|
||||
|
||||
|
||||
@@ -81,9 +81,34 @@ CompositeViewer::~CompositeViewer()
|
||||
|
||||
void CompositeViewer::addView(osgViewer::View* view)
|
||||
{
|
||||
bool threadsWereRuinning = _threadsRunning;
|
||||
if (threadsWereRuinning) stopThreading();
|
||||
|
||||
_views.push_back(view);
|
||||
|
||||
setUpRenderingSupport();
|
||||
if (threadsWereRuinning) startThreading();
|
||||
}
|
||||
|
||||
void CompositeViewer::removeView(osgViewer::View* view)
|
||||
{
|
||||
for(Views::iterator itr = _views.begin();
|
||||
itr != _views.end();
|
||||
++itr)
|
||||
{
|
||||
if (*itr == view)
|
||||
{
|
||||
bool threadsWereRuinning = _threadsRunning;
|
||||
if (threadsWereRuinning) stopThreading();
|
||||
|
||||
_views.erase(itr);
|
||||
|
||||
setUpRenderingSupport();
|
||||
if (threadsWereRuinning) startThreading();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CompositeViewer::isRealized() const
|
||||
@@ -188,6 +213,8 @@ void CompositeViewer::setEndBarrierPosition(BarrierPosition bp)
|
||||
|
||||
void CompositeViewer::stopThreading()
|
||||
{
|
||||
if (!_threadsRunning) return;
|
||||
|
||||
if (_numThreadsOnBarrier==0) return;
|
||||
|
||||
osg::notify(osg::INFO)<<"CompositeViewer::stopThreading() - stopping threading"<<std::endl;
|
||||
@@ -278,6 +305,8 @@ unsigned int CompositeViewer::computeNumberOfThreadsIncludingMainRequired()
|
||||
|
||||
void CompositeViewer::startThreading()
|
||||
{
|
||||
if (_threadsRunning) return;
|
||||
|
||||
unsigned int numThreadsIncludingMainThread = computeNumberOfThreadsIncludingMainRequired();
|
||||
|
||||
// return if we don't need multiple threads.
|
||||
@@ -394,6 +423,8 @@ void CompositeViewer::startThreading()
|
||||
// OpenThreads::Thread::YieldCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
_threadsRunning = true;
|
||||
}
|
||||
|
||||
void CompositeViewer::checkWindowStatus()
|
||||
|
||||
Reference in New Issue
Block a user