diff --git a/include/osgViewer/Viewer b/include/osgViewer/Viewer index ea4927a20..556f53caf 100644 --- a/include/osgViewer/Viewer +++ b/include/osgViewer/Viewer @@ -29,6 +29,9 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View Viewer(); virtual ~Viewer(); + /** Get whether at least of one of this viewers windows are realized.*/ + bool isRealized() const; + /** set up windows and associated threads.*/ void realize(); @@ -58,6 +61,13 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View /** Set the key value that the viewer checks on each frame to see if the viewer's done flag.*/ int getKeySetsDone() const { return _keySetsDone; } + /** Execute a main frame loop. + * Equivialant to while (!viewer.done()) viewer.frame(); + * Also calls realize() if the viewer is not already realized, + * and installs trackball manipulator if one is not already assigned. + */ + virtual void run(); + /** Render a complete new frame. * Calls frameAdvance(), frameEventTraversal(), frameUpateTraversal(), frameRenderingTraversals(). */ virtual void frame(); diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index a2bb8f587..4ba9cd793 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -14,9 +14,10 @@ * OpenSceneGraph Public License for more details. */ -#include -#include #include +#include +#include +#include #include @@ -46,6 +47,50 @@ Viewer::~Viewer() //osg::notify(osg::NOTICE)<<"finish Viewer::~Viewer()"<(this)->getContexts(contexts); + + unsigned int numRealizedWindows = 0; + + // clear out all the previously assigned operations + for(Contexts::iterator citr = contexts.begin(); + citr != contexts.end(); + ++citr) + { + if ((*citr)->isRealized()) ++numRealizedWindows; + } + + return numRealizedWindows > 0; +} + +void Viewer::run() +{ + // if we don't have any scene graph assigned then just return + if (!getSceneData()) + { + osg::notify(osg::NOTICE)<<"Warning: Viewer::run() called without a scene graph being assigned to the viewer, cannot run."<