diff --git a/examples/osgcompositeviewer/osgcompositeviewer.cpp b/examples/osgcompositeviewer/osgcompositeviewer.cpp index fc0203c49..798caca75 100644 --- a/examples/osgcompositeviewer/osgcompositeviewer.cpp +++ b/examples/osgcompositeviewer/osgcompositeviewer.cpp @@ -148,9 +148,7 @@ int main( int argc, char **argv ) osgViewer::View* view = new osgViewer::View; view->setSceneData(osgDB::readNodeFile("fountain.osg")); - osg::ref_ptr statsHandler = new osgViewer::StatsHandler; - view->addEventHandler( statsHandler.get() ); - + view->addEventHandler( new osgViewer::StatsHandler ); view->setUpViewAcrossAllScreens(); view->setCameraManipulator(new osgGA::TrackballManipulator); @@ -186,8 +184,7 @@ int main( int argc, char **argv ) view->setSceneData(scene.get()); view->setCameraManipulator(new osgGA::TrackballManipulator); - osg::ref_ptr statsHandler = new osgViewer::StatsHandler; - view->addEventHandler( statsHandler.get() ); + view->addEventHandler( new osgViewer::StatsHandler ); // add the handler for doing the picking @@ -251,6 +248,9 @@ int main( int argc, char **argv ) view->addEventHandler( new osgViewer::StatsHandler ); view->addEventHandler( new osgViewer::HelpHandler ); + view->addEventHandler( new osgViewer::WindowSizeHandler ); + view->addEventHandler( new osgViewer::ThreadingHandler ); + view->addEventHandler( new osgViewer::RecordCameraPathHandler ); } // view two diff --git a/src/osgViewer/ViewerEventHandlers.cpp b/src/osgViewer/ViewerEventHandlers.cpp index 5ed57748f..34affb7c4 100644 --- a/src/osgViewer/ViewerEventHandlers.cpp +++ b/src/osgViewer/ViewerEventHandlers.cpp @@ -62,7 +62,10 @@ void WindowSizeHandler::getUsage(osg::ApplicationUsage &usage) const bool WindowSizeHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) { - osgViewer::Viewer *viewer = dynamic_cast(&aa); + osgViewer::View* view = dynamic_cast(&aa); + if (!view) return false; + + osgViewer::ViewerBase* viewer = view->getViewerBase(); if (viewer == NULL) { @@ -282,9 +285,13 @@ void ThreadingHandler::getUsage(osg::ApplicationUsage &usage) const bool ThreadingHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) { - osgViewer::Viewer *viewer = dynamic_cast(&aa); + osgViewer::View* view = dynamic_cast(&aa); + if (!view) return false; + + osgViewer::ViewerBase* viewerBase = view->getViewerBase(); + osgViewer::Viewer* viewer = dynamic_cast(viewerBase); - if (viewer == NULL) + if (viewerBase == NULL) { return false; } @@ -301,32 +308,38 @@ bool ThreadingHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIAction { _tickOrLastKeyPress = osg::Timer::instance()->tick(); - switch(viewer->getThreadingModel()) + switch(viewerBase->getThreadingModel()) { - case(osgViewer::Viewer::SingleThreaded): - viewer->setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); + case(osgViewer::ViewerBase::SingleThreaded): + viewerBase->setThreadingModel(osgViewer::ViewerBase::CullDrawThreadPerContext); osg::notify(osg::NOTICE)<<"Threading model 'CullDrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); + case(osgViewer::ViewerBase::CullDrawThreadPerContext): + viewerBase->setThreadingModel(osgViewer::ViewerBase::DrawThreadPerContext); osg::notify(osg::NOTICE)<<"Threading model 'DrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); + case(osgViewer::ViewerBase::DrawThreadPerContext): + viewerBase->setThreadingModel(osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext); osg::notify(osg::NOTICE)<<"Threading model 'CullThreadPerCameraDrawThreadPerContext' selected."<setThreadingModel(osgViewer::Viewer::SingleThreaded); + case(osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext): + viewerBase->setThreadingModel(osgViewer::ViewerBase::SingleThreaded); osg::notify(osg::NOTICE)<<"Threading model 'SingleThreaded' selected."<setThreadingModel(viewer->suggestBestThreadingModel()); +#if 1 + case(osgViewer::ViewerBase::AutomaticSelection): + viewerBase->setThreadingModel(osgViewer::ViewerBase::SingleThreaded); osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<setThreadingModel(viewer->suggestBestThreadingModel()); + osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<getEndBarrierPosition()) { @@ -376,9 +389,9 @@ void RecordCameraPathHandler::getUsage(osg::ApplicationUsage &usage) const bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) { - osgViewer::Viewer* viewer = dynamic_cast(&aa); + osgViewer::View* view = dynamic_cast(&aa); - if (viewer == NULL) + if (view == NULL) { return false; } @@ -396,7 +409,7 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU // calculating when the next insert should happen. if (_currentlyRecording && _delta >= _interval) { - const osg::Matrixd& m = viewer->getCamera()->getInverseViewMatrix(); + const osg::Matrixd& m = view->getCamera()->getInverseViewMatrix(); _animPath->insert(osg::Timer::instance()->delta_s(_animStartTime, time), osg::AnimationPath::ControlPoint(m.getTrans(), m.getRotate())); _delta = 0.0f; } @@ -474,8 +487,8 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU // around of the original MatrixManipulator to restore later. if (_animPathManipulator.valid() && _animPathManipulator->valid()) { - _oldManipulator = viewer->getCameraManipulator(); - viewer->setCameraManipulator(_animPathManipulator.get()); + _oldManipulator = view->getCameraManipulator(); + view->setCameraManipulator(_animPathManipulator.get()); _currentlyPlaying = true; } } @@ -484,7 +497,7 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU else { // Restore the old manipulator if necessary and stop playback. - if(_oldManipulator.valid()) viewer->setCameraManipulator(_oldManipulator.get()); + if(_oldManipulator.valid()) view->setCameraManipulator(_oldManipulator.get()); _currentlyPlaying = false; _oldManipulator = 0; }