CleanUpOperation added to Viewer

Sometimes there is need to do cleanup with valid graphic contexts
before closing these contexts. The added operation runs a graphics
operation on each context before closing them.
This commit is contained in:
Björn Blissing 2016-06-30 22:09:22 +02:00
parent 876c4882a3
commit ed7d49c5d2
3 changed files with 34 additions and 2 deletions

View File

@ -193,6 +193,11 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object
/** Get the graphics operation to call on realization of the viewers graphics windows.*/
osg::Operation* getRealizeOperation() { return _realizeOperation.get(); }
/** Set the graphics operation to call before the viewers graphics contexts close.*/
void setCleanUpOperation(osg::Operation* op) { _cleanUpOperation = op; }
/** Get the graphics operation to call before the viewers graphics contexts close.*/
osg::Operation* getCleanUpOperation() { return _cleanUpOperation.get(); }
/** Set the incremental compile operation.
* Used to manage the OpenGL object compilation and merging of subgraphs in a way that avoids overloading
@ -336,6 +341,7 @@ protected:
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
osg::ref_ptr<osg::Operation> _realizeOperation;
osg::ref_ptr<osg::Operation> _cleanUpOperation;
osg::ref_ptr<osgUtil::IncrementalCompileOperation> _incrementalCompileOperation;
osg::observer_ptr<osg::GraphicsContext> _currentContext;

View File

@ -126,7 +126,19 @@ CompositeViewer::~CompositeViewer()
citr != contexts.end();
++citr)
{
(*citr)->close();
osg::GraphicsContext* gc = *citr;
// Run destroy operation on each context before closing it
if (_cleanUpOperation.valid() && gc->valid())
{
gc->makeCurrent();
(*_cleanUpOperation)(gc);
gc->releaseContext();
}
gc->close();
}
OSG_INFO<<"finished CompositeViewer::~CompositeViewer()"<<std::endl;

View File

@ -238,7 +238,19 @@ Viewer::~Viewer()
citr != contexts.end();
++citr)
{
(*citr)->close();
osg::GraphicsContext* gc = *citr;
// Run destroy operation on each context before closing it
if (_cleanUpOperation.valid() && gc->valid())
{
gc->makeCurrent();
(*_cleanUpOperation)(gc);
gc->releaseContext();
}
gc->close();
}
//OSG_NOTICE<<"finish Viewer::~Viewer()"<<std::endl;
@ -275,6 +287,7 @@ void Viewer::take(osg::View& rhs)
_updateVisitor = rhs_viewer->_updateVisitor;
_realizeOperation = rhs_viewer->_realizeOperation;
_cleanUpOperation = rhs_viewer->_cleanUpOperation;
_currentContext = rhs_viewer->_currentContext;
@ -287,6 +300,7 @@ void Viewer::take(osg::View& rhs)
rhs_viewer->_updateOperations = 0;
rhs_viewer->_updateVisitor = 0;
rhs_viewer->_realizeOperation = 0;
rhs_viewer->_cleanUpOperation = 0;
rhs_viewer->_currentContext = 0;
}