Files
OpenSceneGraph/include/osgViewer/Viewer
Robert Osfield 694b304c00 Added Viewer::setEndBarrierPosition method, change Viewer::setKeySetsDone(int) to setKeyEventSetDone(int),
added support for toggling threading model and end barrier position into osgviewer
2007-01-12 21:05:39 +00:00

162 lines
5.8 KiB
C++

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGVIEWER_Viewer
#define OSGVIEWER_Viewer 1
#include <osgViewer/GraphicsWindow>
#include <osgViewer/View>
#include <osgGA/EventVisitor>
namespace osgViewer {
// WARNING ** Under development do not use, yet :-)
/** Viewer holds a single view on to a single scene..*/
class OSGVIEWER_EXPORT Viewer : public osgViewer::View
{
public:
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();
void setDone(bool done) { _done = done; }
bool done() const { return _done; }
osg::FrameStamp* getFrameStamp();
const osg::FrameStamp* getFrameStamp() const;
enum ThreadingModel
{
SingleThreaded,
ThreadPerContext,
ThreadPerCamera
};
/** Set the threading model the rendering traversals will use.*/
void setThreadingModel(ThreadingModel threadingModel);
/** Get the threading model the rendering traversals will use.*/
ThreadingModel getThreadingModel() const { return _threadingModel; }
enum BarrierPosition
{
BeforeSwapBuffers,
AfterSwapBuffers
};
/** Set the position of the end barrier.
* AfterSwapBuffers will may result is slightly higher framerates, by may
* lead to inconcistent swapping between different windows.
* BeforeSwapBuffers may lead to slightly lower framerate, but improve consistency in timing of swap buffers,
* especially important if you are likely to consistently break frame.*/
void setEndBarrierPosition(BarrierPosition bp);
/** Get the end barrier position.*/
BarrierPosition getEndBarrierPosition() const { return _endBarrierPosition; }
/** Set the key event that the viewer checks on each frame to see if the viewer's done flag should be set to
* signal end of viewers main loop.
* Default value is Escape (osgGA::GUIEVentAdapter::KEY_Escape).
* Setting to 0 switches off the feature.*/
void setKeyEventSetsDone(int key) { _keyEventSetsDone = key; }
/** get the key event that the viewer checks on each frame to see if the viewer's done flag.*/
int getKeyEventSetsDone() const { return _keyEventSetsDone; }
/** if the flag is true, the viewer set its done flag when a QUIT_APPLICATION is received, false disables this feature */
void setQuitEventSetsDone(bool flag) { _quitEventSetsDone = flag; }
/** @return true if the viewer respond to the QUIT_APPLICATION-event */
bool getQuitEventSetsDone() const { return _quitEventSetsDone; }
/** 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 int run();
/** Render a complete new frame.
* Calls advance(), eventTraversal(), updateTraversal(), renderingTraversals(). */
virtual void frame();
virtual void advance();
virtual void eventTraversal();
virtual void updateTraversal();
virtual void renderingTraversals();
/** Release all OpenGL objects associated with this viewer's scenegraph. Note, does not deleted the actual OpenGL objects, it just releases them to the pending GL object delete lists which will need flushing once a valid graphics context is obtained.*/
virtual void releaseAllGLObjects();
/** Clean up all OpenGL objects associated with this viewer's scenegraph.*/
virtual void cleanup();
void setCameraWithFocus(osg::Camera* camera) { _cameraWithFocus = camera; }
osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); }
const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); }
typedef std::vector<osg::GraphicsContext*> Contexts;
void getContexts(Contexts& contexts, bool onlyValid=true);
typedef std::vector<osgViewer::GraphicsWindow*> Windows;
void getWindows(Windows& windows, bool onlyValid=true);
protected:
void init();
void stopThreading();
void startThreading();
void checkWindowStatus();
void setUpRenderingSupport();
bool _firstFrame;
bool _done;
int _keyEventSetsDone;
bool _quitEventSetsDone;
ThreadingModel _threadingModel;
BarrierPosition _endBarrierPosition;
osg::ref_ptr<osg::BarrierOperation> _startRenderingBarrier;
osg::ref_ptr<osg::BarrierOperation> _endRenderingDispatchBarrier;
unsigned int computeNumberOfThreadsIncludingMainRequired();
unsigned int _numThreadsOnBarrier;
osg::observer_ptr<osg::Camera> _cameraWithFocus;
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
};
}
#endif