Added Viewer::isRealized() and run() methods to make it easier to
set up and run a viewer, taking care of realized() calls if not already done, and assigning trackball manipulator if not already assigned.
This commit is contained in:
parent
9e30014634
commit
552bda4cc5
@ -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();
|
||||
|
@ -14,9 +14,10 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgViewer/Viewer>
|
||||
#include <osgUtil/GLObjectsVisitor>
|
||||
#include <osg/GLExtensions>
|
||||
#include <osgUtil/GLObjectsVisitor>
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgViewer/Viewer>
|
||||
|
||||
#include <osg/io_utils>
|
||||
|
||||
@ -46,6 +47,50 @@ Viewer::~Viewer()
|
||||
//osg::notify(osg::NOTICE)<<"finish Viewer::~Viewer()"<<std::endl;
|
||||
}
|
||||
|
||||
bool Viewer::isRealized() const
|
||||
{
|
||||
|
||||
Contexts contexts;
|
||||
const_cast<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."<<std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getCameraManipulator())
|
||||
{
|
||||
setCameraManipulator(new osgGA::TrackballManipulator());
|
||||
}
|
||||
|
||||
if (!isRealized())
|
||||
{
|
||||
realize();
|
||||
}
|
||||
|
||||
while (!done())
|
||||
{
|
||||
frame();
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::setThreadingModel(ThreadingModel threadingModel)
|
||||
{
|
||||
if (_threadingModel == threadingModel) return;
|
||||
@ -474,6 +519,12 @@ void Viewer::frame()
|
||||
if (_firstFrame)
|
||||
{
|
||||
init();
|
||||
|
||||
if (!isRealized())
|
||||
{
|
||||
realize();
|
||||
}
|
||||
|
||||
_firstFrame = false;
|
||||
}
|
||||
frameAdvance();
|
||||
|
Loading…
Reference in New Issue
Block a user