Added support for passing in ArgumentParser in Viewer and CompositeViewer constructor

This commit is contained in:
Robert Osfield 2007-06-06 10:57:02 +00:00
parent 3199d7bc85
commit 6e3c9ad3d3
5 changed files with 87 additions and 31 deletions

View File

@ -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<osgGA::KeySwitchMatrixManipulator> 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))
{

View File

@ -14,6 +14,7 @@
#ifndef OSGVIEWER_CompositeViewer
#define OSGVIEWER_CompositeViewer 1
#include <osg/ArgumentParser>
#include <osgViewer/GraphicsWindow>
#include <osgViewer/View>
@ -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<osgViewer::View> > Views;

View File

@ -14,9 +14,11 @@
#ifndef OSGVIEWER_Viewer
#define OSGVIEWER_Viewer 1
#include <osg/ArgumentParser>
#include <osgGA/EventVisitor>
#include <osgViewer/GraphicsWindow>
#include <osgViewer/View>
#include <osgGA/EventVisitor>
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)

View File

@ -15,21 +15,39 @@
#include <osgUtil/GLObjectsVisitor>
#include <osgGA/TrackballManipulator>
#include <osgViewer/CompositeViewer>
#include <osgDB/Registry>
#include <osg/io_utils>
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);

View File

@ -15,6 +15,7 @@
#include <osg/DeleteHandler>
#include <osgUtil/Optimizer>
#include <osgUtil/GLObjectsVisitor>
#include <osgDB/Registry>
#include <osgGA/TrackballManipulator>
#include <osgViewer/Viewer>
@ -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"<<std::endl;
}
Viewer::Viewer(osg::ArgumentParser& arguments)
{
constructorInit();
while (arguments.read("--SingleThreaded")) setThreadingModel(SingleThreaded);
while (arguments.read("--CullDrawThreadPerContext")) setThreadingModel(CullDrawThreadPerContext);
while (arguments.read("--DrawThreadPerContext")) setThreadingModel(DrawThreadPerContext);
while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) setThreadingModel(CullThreadPerCameraDrawThreadPerContext);
osg::DisplaySettings::instance()->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 \""<<colorStr<<"\""<<std::endl;
}
}
void Viewer::constructorInit()
{
_firstFrame = true;
_done = false;
_keyEventSetsDone = osgGA::GUIEventAdapter::KEY_Escape;
_quitEventSetsDone = true;
_threadingModel = AutomaticSelection;
_threadsRunning = false;
_useMainThreadForRenderingTraversal = true;
_endBarrierPosition = AfterSwapBuffers;
_numWindowsOpenAtLastSetUpThreading = 0;
_startTick = 0;
_frameStamp = new osg::FrameStamp;
_frameStamp->setFrameNumber(0);
_frameStamp->setReferenceTime(0);