Added support for using the CompileContext to do GL object deletion.

This commit is contained in:
Robert Osfield 2007-07-22 20:33:20 +00:00
parent 14fcf4f8b3
commit ff267d1ad6
2 changed files with 60 additions and 8 deletions

View File

@ -564,6 +564,8 @@ struct CompositeViewerRenderingOperation : public osg::Operation
_databasePager(databasePager) _databasePager(databasePager)
{ {
_sceneView->getCullVisitor()->setDatabaseRequestHandler(_databasePager.get()); _sceneView->getCullVisitor()->setDatabaseRequestHandler(_databasePager.get());
_flushOperation = new osg::FlushDeletedGLObjectsOperation(0.1);
} }
virtual void operator () (osg::Object*) virtual void operator () (osg::Object*)
@ -577,6 +579,9 @@ struct CompositeViewerRenderingOperation : public osg::Operation
osgViewer::View* view = dynamic_cast<osgViewer::View*>(_sceneView->getCamera()->getView()); osgViewer::View* view = dynamic_cast<osgViewer::View*>(_sceneView->getCamera()->getView());
if (view) _sceneView->setFusionDistance(view->getFusionDistanceMode(), view->getFusionDistanceValue()); if (view) _sceneView->setFusionDistance(view->getFusionDistanceMode(), view->getFusionDistanceValue());
osg::GraphicsContext* compileContext = osg::GraphicsContext::getCompileContext(_sceneView->getState()->getContextID());
osg::GraphicsThread* compileThread = compileContext ? compileContext->getGraphicsThread() : 0;
_sceneView->inheritCullSettings(*(_sceneView->getCamera())); _sceneView->inheritCullSettings(*(_sceneView->getCamera()));
_sceneView->cull(); _sceneView->cull();
_sceneView->draw(); _sceneView->draw();
@ -588,11 +593,19 @@ struct CompositeViewerRenderingOperation : public osg::Operation
_databasePager->compileGLObjects(*(_sceneView->getState()), availableTime); _databasePager->compileGLObjects(*(_sceneView->getState()), availableTime);
} }
_sceneView->flushDeletedGLObjects(availableTime); if (compileThread)
{
compileThread->add(_flushOperation.get());
}
else
{
_sceneView->flushDeletedGLObjects(availableTime);
}
} }
osg::observer_ptr<osgUtil::SceneView> _sceneView; osg::observer_ptr<osgUtil::SceneView> _sceneView;
osg::observer_ptr<osgDB::DatabasePager> _databasePager; osg::observer_ptr<osgDB::DatabasePager> _databasePager;
osg::ref_ptr<osg::FlushDeletedGLObjectsOperation> _flushOperation;
}; };
void CompositeViewer::setUpRenderingSupport() void CompositeViewer::setUpRenderingSupport()

View File

@ -137,6 +137,8 @@ struct ViewerRenderingOperation : public osg::GraphicsOperation, public ViewerQu
_databasePager(databasePager) _databasePager(databasePager)
{ {
_sceneView->getCullVisitor()->setDatabaseRequestHandler(_databasePager.get()); _sceneView->getCullVisitor()->setDatabaseRequestHandler(_databasePager.get());
_flushOperation = new osg::FlushDeletedGLObjectsOperation(0.1);
} }
osg::Camera* getCamera() { return _sceneView->getCamera(); } osg::Camera* getCamera() { return _sceneView->getCamera(); }
@ -202,7 +204,18 @@ struct ViewerRenderingOperation : public osg::GraphicsOperation, public ViewerQu
{ {
_databasePager->compileGLObjects(*(_sceneView->getState()), availableTime); _databasePager->compileGLObjects(*(_sceneView->getState()), availableTime);
} }
_sceneView->flushDeletedGLObjects(availableTime);
osg::GraphicsContext* compileContext = osg::GraphicsContext::getCompileContext(_sceneView->getState()->getContextID());
osg::GraphicsThread* compileThread = compileContext ? compileContext->getGraphicsThread() : 0;
if (compileThread)
{
compileThread->add(_flushOperation.get());
}
else
{
_sceneView->flushDeletedGLObjects(availableTime);
}
if (aquireGPUStats) if (aquireGPUStats)
{ {
@ -225,8 +238,9 @@ struct ViewerRenderingOperation : public osg::GraphicsOperation, public ViewerQu
} }
osg::observer_ptr<osgUtil::SceneView> _sceneView; osg::observer_ptr<osgUtil::SceneView> _sceneView;
osg::observer_ptr<osgDB::DatabasePager> _databasePager; osg::observer_ptr<osgDB::DatabasePager> _databasePager;
osg::ref_ptr<osg::FlushDeletedGLObjectsOperation> _flushOperation;
}; };
@ -261,6 +275,9 @@ struct ViewerDoubleBufferedRenderingOperation : public osg::Operation, public Vi
_lockHeld[_currentCull] = true; _lockHeld[_currentCull] = true;
} }
_flushOperation = new osg::FlushDeletedGLObjectsOperation(0.1);
// osg::notify(osg::NOTICE)<<"constructed"<<std::endl; // osg::notify(osg::NOTICE)<<"constructed"<<std::endl;
} }
@ -366,6 +383,9 @@ struct ViewerDoubleBufferedRenderingOperation : public osg::Operation, public Vi
osgUtil::SceneView* sceneView = _sceneView[_currentDraw].get(); osgUtil::SceneView* sceneView = _sceneView[_currentDraw].get();
osg::GraphicsContext* compileContext = osg::GraphicsContext::getCompileContext(sceneView->getState()->getContextID());
osg::GraphicsThread* compileThread = compileContext ? compileContext->getGraphicsThread() : 0;
if (sceneView || _done) if (sceneView || _done)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex[_currentDraw]); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex[_currentDraw]);
@ -427,7 +447,14 @@ struct ViewerDoubleBufferedRenderingOperation : public osg::Operation, public Vi
_databasePager->compileGLObjects(*(sceneView->getState()), availableTime); _databasePager->compileGLObjects(*(sceneView->getState()), availableTime);
} }
sceneView->flushDeletedGLObjects(availableTime); if (compileThread)
{
compileThread->add(_flushOperation.get());
}
else
{
sceneView->flushDeletedGLObjects(availableTime);
}
if (aquireGPUStats) if (aquireGPUStats)
{ {
@ -457,6 +484,9 @@ struct ViewerDoubleBufferedRenderingOperation : public osg::Operation, public Vi
osgUtil::SceneView* sceneView = _sceneView[_currentDraw].get(); osgUtil::SceneView* sceneView = _sceneView[_currentDraw].get();
if (!sceneView || _done) return; if (!sceneView || _done) return;
osg::GraphicsContext* compileContext = osg::GraphicsContext::getCompileContext(sceneView->getState()->getContextID());
osg::GraphicsThread* compileThread = compileContext ? compileContext->getGraphicsThread() : 0;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex[_currentDraw]); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex[_currentDraw]);
if (_done) if (_done)
@ -515,7 +545,15 @@ struct ViewerDoubleBufferedRenderingOperation : public osg::Operation, public Vi
{ {
_databasePager->compileGLObjects(*(sceneView->getState()), availableTime); _databasePager->compileGLObjects(*(sceneView->getState()), availableTime);
} }
sceneView->flushDeletedGLObjects(availableTime);
if (compileThread)
{
compileThread->add(_flushOperation.get());
}
else
{
sceneView->flushDeletedGLObjects(availableTime);
}
if (aquireGPUStats) if (aquireGPUStats)
{ {
@ -589,6 +627,7 @@ struct ViewerDoubleBufferedRenderingOperation : public osg::Operation, public Vi
int _frameNumber[2]; int _frameNumber[2];
osg::observer_ptr<osgDB::DatabasePager> _databasePager; osg::observer_ptr<osgDB::DatabasePager> _databasePager;
osg::ref_ptr<osg::FlushDeletedGLObjectsOperation> _flushOperation;
}; };