From 6e3c9ad3d3f715b7867eb002d8c87e38dc15d73f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Jun 2007 10:57:02 +0000 Subject: [PATCH] Added support for passing in ArgumentParser in Viewer and CompositeViewer constructor --- applications/osgviewer/osgviewer.cpp | 9 +---- include/osgViewer/CompositeViewer | 7 ++++ include/osgViewer/Viewer | 9 ++++- src/osgViewer/CompositeViewer.cpp | 36 +++++++++++++----- src/osgViewer/Viewer.cpp | 57 +++++++++++++++++++++------- 5 files changed, 87 insertions(+), 31 deletions(-) diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 8dea45f36..c5968fdb4 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -61,6 +61,8 @@ int main(int argc, char** argv) return 1; } + osgViewer::Viewer viewer(arguments); + // report any errors if they have occurred when parsing the program arguments. if (arguments.errors()) { @@ -74,8 +76,6 @@ int main(int argc, char** argv) return 1; } - osgViewer::Viewer viewer; - // set up the camera manipulators. { osg::ref_ptr keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; @@ -120,11 +120,6 @@ int main(int argc, char** argv) // add the record camera path handler viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); - while (arguments.read("--SingleThreaded")) viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); - while (arguments.read("--CullDrawThreadPerContext")) viewer.setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); - while (arguments.read("--DrawThreadPerContext")) viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); - while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) viewer.setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); - unsigned int screenNum; while (arguments.read("--screen",screenNum)) { diff --git a/include/osgViewer/CompositeViewer b/include/osgViewer/CompositeViewer index f2fad849a..f88242251 100644 --- a/include/osgViewer/CompositeViewer +++ b/include/osgViewer/CompositeViewer @@ -14,6 +14,7 @@ #ifndef OSGVIEWER_CompositeViewer #define OSGVIEWER_CompositeViewer 1 +#include #include #include @@ -25,6 +26,9 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced public: CompositeViewer(); + + CompositeViewer(osg::ArgumentParser& arguments); + virtual ~CompositeViewer(); void addView(osgViewer::View* view); @@ -160,7 +164,10 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced protected: + void constructorInit(); + void init(); + void checkWindowStatus(); typedef std::vector< osg::ref_ptr > Views; diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index 7d2703185..1d9225f07 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -14,9 +14,11 @@ #ifndef OSGVIEWER_Viewer #define OSGVIEWER_Viewer 1 +#include +#include #include #include -#include + namespace osgViewer { @@ -26,6 +28,9 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View public: Viewer(); + + Viewer(osg::ArgumentParser& arguments); + virtual ~Viewer(); /** Get whether at least of one of this viewers windows are realized.*/ @@ -175,6 +180,8 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View protected: + void constructorInit(); + void checkWindowStatus(); inline void makeCurrent(osg::GraphicsContext* gc) diff --git a/src/osgViewer/CompositeViewer.cpp b/src/osgViewer/CompositeViewer.cpp index bee0be49f..7fa7696df 100644 --- a/src/osgViewer/CompositeViewer.cpp +++ b/src/osgViewer/CompositeViewer.cpp @@ -15,21 +15,39 @@ #include #include #include +#include #include using namespace osgViewer; -CompositeViewer::CompositeViewer(): - _firstFrame(true), - _done(false), - _keyEventSetsDone(osgGA::GUIEventAdapter::KEY_Escape), - _quitEventSetsDone(true), - _threadingModel(ThreadPerContext), - _endBarrierPosition(AfterSwapBuffers), - _numThreadsOnBarrier(0), - _startTick(0) +CompositeViewer::CompositeViewer() { + constructorInit(); +} + +CompositeViewer::CompositeViewer(osg::ArgumentParser& arguments) +{ + constructorInit(); + + while (arguments.read("--SingleThreaded")) setThreadingModel(SingleThreaded); + while (arguments.read("--ThreadPerContext")) setThreadingModel(ThreadPerContext); + + osg::DisplaySettings::instance()->readCommandLine(arguments); + osgDB::readCommandLine(arguments); +} + +void CompositeViewer::constructorInit() +{ + _firstFrame = true; + _done = false; + _keyEventSetsDone = osgGA::GUIEventAdapter::KEY_Escape; + _quitEventSetsDone = true; + _threadingModel = ThreadPerContext; + _endBarrierPosition = AfterSwapBuffers; + _numThreadsOnBarrier = 0; + _startTick = 0; + // make sure View is safe to reference multi-threaded. setThreadSafeRefUnref(true); diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index f0a32ab57..eea2e4348 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -590,21 +591,49 @@ struct ViewerDoubleBufferedRenderingOperation : public osg::Operation, public Vi }; -Viewer::Viewer(): - _firstFrame(true), - _done(false), - _keyEventSetsDone(osgGA::GUIEventAdapter::KEY_Escape), - _quitEventSetsDone(true), -// _threadingModel(SingleThreaded), -// _threadingModel(CullDrawThreadPerContext), -// _threadingModel(CullThreadPerCameraDrawThreadPerContext), - _threadingModel(AutomaticSelection), - _threadsRunning(false), - _useMainThreadForRenderingTraversal(true), - _endBarrierPosition(AfterSwapBuffers), - _numWindowsOpenAtLastSetUpThreading(0), - _startTick(0) +Viewer::Viewer() { + constructorInit(); + + osg::notify(osg::NOTICE)<<"Here22"<readCommandLine(arguments); + osgDB::readCommandLine(arguments); + + std::string colorStr; + while (arguments.read("--clear-color",colorStr)) + { + float r, g, b; + float a = 1.0f; + int cnt = sscanf( colorStr.c_str(), "%f,%f,%f,%f", &r, &g, &b, &a ); + if( cnt==3 || cnt==4 ) getCamera()->setClearColor( osg::Vec4(r,g,b,a) ); + else osg::notify(osg::WARN)<<"Invalid clear color \""<setFrameNumber(0); _frameStamp->setReferenceTime(0);