Moved the set of GraphicsContext RenderingOperations into Viewer.

This commit is contained in:
Robert Osfield 2007-01-04 21:49:02 +00:00
parent fc061f7b15
commit 0985a06572
4 changed files with 92 additions and 79 deletions

View File

@ -55,12 +55,9 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
virtual void requestWarpPointer(float x,float y);
public:
void setUpRenderingSupport();
void assignSceneDataToCameras();
protected:
virtual ~View();

View File

@ -94,6 +94,8 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
void startThreading();
void checkWindowStatus();
void setUpRenderingSupport();
bool _firstFrame;
bool _done;

View File

@ -69,7 +69,6 @@ void View::setUpViewAcrossAllScreens()
return;
}
double fovy, aspectRatio, zNear, zFar;
_camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
@ -215,84 +214,10 @@ void View::setUpViewAcrossAllScreens()
}
}
}
setUpRenderingSupport();
assignSceneDataToCameras();
}
// Draw operation, that does a draw on the scene graph.
struct RenderingOperation : public osg::GraphicsOperation
{
RenderingOperation(osgUtil::SceneView* sceneView, osgDB::DatabasePager* databasePager):
osg::GraphicsOperation("Render",true),
_sceneView(sceneView),
_databasePager(databasePager)
{
_sceneView->getCullVisitor()->setDatabaseRequestHandler(_databasePager.get());
}
virtual void operator () (osg::GraphicsContext*)
{
if (!_sceneView) return;
// osg::notify(osg::NOTICE)<<"RenderingOperation"<<std::endl;
_sceneView->cull();
_sceneView->draw();
if (_databasePager.valid())
{
double availableTime = 0.004; // 4 ms
_databasePager->compileGLObjects(*(_sceneView->getState()), availableTime);
_sceneView->flushDeletedGLObjects(availableTime);
}
}
osg::observer_ptr<osgUtil::SceneView> _sceneView;
osg::observer_ptr<osgDB::DatabasePager> _databasePager;
};
void View::setUpRenderingSupport()
{
osg::FrameStamp* frameStamp = _scene->getFrameStamp();
// what should we do with the old sceneViews?
_cameraSceneViewMap.clear();
if (_camera.valid() && _camera->getGraphicsContext())
{
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
_cameraSceneViewMap[_camera] = sceneView;
sceneView->setDefaults();
sceneView->setCamera(_camera.get());
sceneView->setState(_camera->getGraphicsContext()->getState());
sceneView->setSceneData(getSceneData());
sceneView->setFrameStamp(frameStamp);
_camera->getGraphicsContext()->add(new RenderingOperation(sceneView, _scene->getDatabasePager()));
}
for(unsigned i=0; i<getNumSlaves(); ++i)
{
Slave& slave = getSlave(i);
if (slave._camera.valid() && slave._camera->getGraphicsContext())
{
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
_cameraSceneViewMap[slave._camera] = sceneView;
sceneView->setDefaults();
sceneView->setCamera(slave._camera.get());
sceneView->setState(slave._camera->getGraphicsContext()->getState());
sceneView->setSceneData(getSceneData());
sceneView->setFrameStamp(frameStamp);
slave._camera->getGraphicsContext()->add(new RenderingOperation(sceneView, _scene->getDatabasePager()));
}
}
}
void View::assignSceneDataToCameras()
{
osg::Node* sceneData = _scene.valid() ? _scene->getSceneData() : 0;

View File

@ -322,6 +322,93 @@ void Viewer::getWindows(Windows& windows, bool onlyValid)
}
}
// Draw operation, that does a draw on the scene graph.
struct RenderingOperation : public osg::GraphicsOperation
{
RenderingOperation(osgUtil::SceneView* sceneView, osgDB::DatabasePager* databasePager):
osg::GraphicsOperation("Render",true),
_sceneView(sceneView),
_databasePager(databasePager)
{
_sceneView->getCullVisitor()->setDatabaseRequestHandler(_databasePager.get());
}
virtual void operator () (osg::GraphicsContext*)
{
if (!_sceneView) return;
// osg::notify(osg::NOTICE)<<"RenderingOperation"<<std::endl;
_sceneView->cull();
_sceneView->draw();
if (_databasePager.valid())
{
double availableTime = 0.004; // 4 ms
_databasePager->compileGLObjects(*(_sceneView->getState()), availableTime);
_sceneView->flushDeletedGLObjects(availableTime);
}
}
osg::observer_ptr<osgUtil::SceneView> _sceneView;
osg::observer_ptr<osgDB::DatabasePager> _databasePager;
};
void Viewer::setUpRenderingSupport()
{
if (!_scene) return;
osg::FrameStamp* frameStamp = _scene->getFrameStamp();
// what should we do with the old sceneViews?
_cameraSceneViewMap.clear();
Contexts contexts;
getContexts(contexts);
// clear out all the previously assigned operations
for(Contexts::iterator citr = contexts.begin();
citr != contexts.end();
++citr)
{
(*citr)->removeAllOperations();
}
if (_camera.valid() && _camera->getGraphicsContext())
{
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
_cameraSceneViewMap[_camera] = sceneView;
sceneView->setDefaults();
sceneView->setCamera(_camera.get());
sceneView->setState(_camera->getGraphicsContext()->getState());
sceneView->setSceneData(getSceneData());
sceneView->setFrameStamp(frameStamp);
_camera->getGraphicsContext()->add(new RenderingOperation(sceneView, _scene->getDatabasePager()));
}
for(unsigned i=0; i<getNumSlaves(); ++i)
{
Slave& slave = getSlave(i);
if (slave._camera.valid() && slave._camera->getGraphicsContext())
{
osgUtil::SceneView* sceneView = new osgUtil::SceneView;
_cameraSceneViewMap[slave._camera] = sceneView;
sceneView->setDefaults();
sceneView->setCamera(slave._camera.get());
sceneView->setState(slave._camera->getGraphicsContext()->getState());
sceneView->setSceneData(getSceneData());
sceneView->setFrameStamp(frameStamp);
slave._camera->getGraphicsContext()->add(new RenderingOperation(sceneView, _scene->getDatabasePager()));
}
}
}
void Viewer::realize()
{
//osg::notify(osg::INFO)<<"Viewer::realize()"<<std::endl;
@ -345,6 +432,8 @@ void Viewer::realize()
return;
}
setUpRenderingSupport();
for(Contexts::iterator citr = contexts.begin();
citr != contexts.end();
++citr)