From 54c579fcae3d1d94fff6049bf263251ec449f686 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 22 Sep 2007 17:39:15 +0000 Subject: [PATCH] Improved the handling of OSG_CONFIG_FILE support. --- src/osgViewer/View.cpp | 20 ++++++++++--- src/osgViewer/Viewer.cpp | 61 ++++++++++++++++++++++------------------ 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index 024e73a09..923d7e901 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -168,16 +168,26 @@ void View::take(osg::View& rhs) { osg::View::take(rhs); +#if 1 osgViewer::View* rhs_osgViewer = dynamic_cast(&rhs); if (rhs_osgViewer) { + // copy across rhs _startTick = rhs_osgViewer->_startTick; _frameStamp = rhs_osgViewer->_frameStamp; - _scene = rhs_osgViewer->_scene; - _cameraManipulator = rhs_osgViewer->_cameraManipulator; - _eventHandlers = rhs_osgViewer->_eventHandlers; + if (rhs_osgViewer->getSceneData()) + { + _scene = rhs_osgViewer->_scene; + } + + if (rhs_osgViewer->_cameraManipulator.valid()) + { + _cameraManipulator = rhs_osgViewer->_cameraManipulator; + } + + _eventHandlers.insert(_eventHandlers.end(), rhs_osgViewer->_eventHandlers.begin(), rhs_osgViewer->_eventHandlers.end()); _coordinateSystemNodePath = rhs_osgViewer->_coordinateSystemNodePath; @@ -196,7 +206,9 @@ void View::take(osg::View& rhs) rhs_osgViewer->_displaySettings; } - +#endif + computeActiveCoordinateSystemNodePath(); + assignSceneDataToCameras(); } osg::GraphicsOperation* View::createRenderer(osg::Camera* camera) diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index ebebc0eb0..fa6a71c4b 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -30,7 +30,7 @@ using namespace osgViewer; -//static osg::ApplicationUsageProxy Viewer_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_CONFIG_FILE ","Specify a viewer configuration file to load by default."); +static osg::ApplicationUsageProxy Viewer_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_CONFIG_FILE ","Specify a viewer configuration file to load by default."); static osg::ApplicationUsageProxy Viewer_e1(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_THREADING ","Set the threading model using by Viewer, can be SingleThreaded, CullDrawThreadPerContext, DrawThreadPerContext or CullThreadPerCameraDrawThreadPerContext."); static osg::ApplicationUsageProxy Viewer_e2(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SCREEN ","Set the default screen that windows should open up on."); static osg::ApplicationUsageProxy Viewer_e3(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_WINDOW x y width height","Set the default window dimensions that windows should open up on."); @@ -182,10 +182,10 @@ void Viewer::take(View& rhs) { osgViewer::View::take(rhs); +#if 1 osgViewer::Viewer* rhs_viewer = dynamic_cast(&rhs); if (rhs_viewer) { -#if 1 // variables left to take. _firstFrame = rhs_viewer->_firstFrame; _done = rhs_viewer->_done; @@ -218,9 +218,8 @@ void Viewer::take(View& rhs) rhs_viewer->_updateVisitor = 0; rhs_viewer->_realizeOperation = 0; rhs_viewer->_currentContext = 0; - -#endif } +#endif } bool Viewer::readConfiguration(const std::string& filename) @@ -259,7 +258,6 @@ bool Viewer::readConfiguration(const std::string& filename) bool Viewer::isRealized() const { - Contexts contexts; const_cast(this)->getContexts(contexts); @@ -991,34 +989,41 @@ void Viewer::realize() // no windows are already set up so set up a default view const char* ptr = 0; - int screenNum = -1; - if ((ptr = getenv("OSG_SCREEN")) != 0) + if ((ptr = getenv("OSG_CONFIG_FILE")) != 0) { - if (strlen(ptr)!=0) screenNum = atoi(ptr); - else screenNum = -1; - } - - int x = -1, y = -1, width = -1, height = -1; - if ((ptr = getenv("OSG_WINDOW")) != 0) - { - std::istringstream iss(ptr); - iss >> x >> y >> width >> height; - } - - if (width>0 && height>0) - { - if (screenNum>=0) setUpViewInWindow(x, y, width, height, screenNum); - else setUpViewInWindow(x,y,width,height); - } - else if (screenNum>=0) - { - setUpViewOnSingleScreen(screenNum); + readConfiguration(ptr); } else { - setUpViewAcrossAllScreens(); - } + int screenNum = -1; + if ((ptr = getenv("OSG_SCREEN")) != 0) + { + if (strlen(ptr)!=0) screenNum = atoi(ptr); + else screenNum = -1; + } + int x = -1, y = -1, width = -1, height = -1; + if ((ptr = getenv("OSG_WINDOW")) != 0) + { + std::istringstream iss(ptr); + iss >> x >> y >> width >> height; + } + + if (width>0 && height>0) + { + if (screenNum>=0) setUpViewInWindow(x, y, width, height, screenNum); + else setUpViewInWindow(x,y,width,height); + } + else if (screenNum>=0) + { + setUpViewOnSingleScreen(screenNum); + } + else + { + setUpViewAcrossAllScreens(); + } + } + getContexts(contexts); }