2006-11-27 22:52:07 +08:00
|
|
|
/* -*-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_CompositeViewer
|
|
|
|
#define OSGVIEWER_CompositeViewer 1
|
|
|
|
|
2007-06-06 18:57:02 +08:00
|
|
|
#include <osg/ArgumentParser>
|
2007-08-10 18:52:35 +08:00
|
|
|
#include <osgUtil/UpdateVisitor>
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osgViewer/GraphicsWindow>
|
|
|
|
#include <osgViewer/View>
|
|
|
|
|
|
|
|
namespace osgViewer {
|
|
|
|
|
|
|
|
/** CompsiteViewer holds a or more views to a one more scenes.*/
|
2007-01-17 03:18:32 +08:00
|
|
|
class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced
|
2006-11-27 22:52:07 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
CompositeViewer();
|
2007-06-06 18:57:02 +08:00
|
|
|
|
|
|
|
CompositeViewer(osg::ArgumentParser& arguments);
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
virtual ~CompositeViewer();
|
|
|
|
|
2006-11-29 04:35:31 +08:00
|
|
|
void addView(osgViewer::View* view);
|
2007-05-12 03:25:44 +08:00
|
|
|
void removeView(osgViewer::View* view);
|
2006-11-29 04:35:31 +08:00
|
|
|
|
|
|
|
osgViewer::View* getView(unsigned i) { return _views[i].get(); }
|
|
|
|
const osgViewer::View* getView(unsigned i) const { return _views[i].get(); }
|
|
|
|
|
|
|
|
unsigned int getNumViews() const { return _views.size(); }
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
|
|
|
|
/** 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; }
|
|
|
|
|
|
|
|
void setStartTick(osg::Timer_t tick);
|
|
|
|
osg::Timer_t getStartTick() const { return _startTick; }
|
|
|
|
|
|
|
|
void setReferenceTime(double time=0.0);
|
|
|
|
|
|
|
|
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
|
|
|
|
const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
|
|
|
|
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
|
|
|
|
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
|
|
|
|
|
|
|
|
/** 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();
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
/** Render a complete new frame.
|
2007-01-16 16:56:33 +08:00
|
|
|
* Calls advance(), eventTraversal(), updateTraversal(), renderingTraversals(). */
|
2007-01-25 20:02:51 +08:00
|
|
|
virtual void frame(double simulationTime=USE_REFERENCE_TIME);
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-01-25 20:02:51 +08:00
|
|
|
virtual void advance(double simulationTime=USE_REFERENCE_TIME);
|
2007-01-16 16:56:33 +08:00
|
|
|
|
|
|
|
virtual void eventTraversal();
|
|
|
|
|
|
|
|
virtual void updateTraversal();
|
|
|
|
|
|
|
|
virtual void renderingTraversals();
|
|
|
|
|
|
|
|
|
|
|
|
void setCameraWithFocus(osg::Camera* camera);
|
|
|
|
osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); }
|
|
|
|
const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); }
|
|
|
|
|
|
|
|
osgViewer::View* getViewWithFocus() { return _viewWithFocus.get(); }
|
|
|
|
const osgViewer::View* getViewWithFocus() const { return _viewWithFocus.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);
|
|
|
|
|
|
|
|
typedef std::vector<osgViewer::Scene*> Scenes;
|
|
|
|
void getScenes(Scenes& scenes, bool onlyValid=true);
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-01-29 01:11:21 +08:00
|
|
|
|
|
|
|
/** Set the graphics operation to call on realization of the viewers graphics windows.*/
|
2007-02-03 06:30:36 +08:00
|
|
|
void setRealizeOperation(osg::Operation* op) { _realizeOperation = op; }
|
2007-01-29 01:11:21 +08:00
|
|
|
|
|
|
|
/** Get the graphics operation to call on realization of the viewers graphics windows.*/
|
2007-02-03 06:30:36 +08:00
|
|
|
osg::Operation* getRealizeOperation() { return _realizeOperation.get(); }
|
2007-01-29 01:11:21 +08:00
|
|
|
|
2007-05-12 03:25:44 +08:00
|
|
|
/** Return true if viewer threads are running. */
|
|
|
|
bool areThreadsRunning() const { return _threadsRunning; }
|
|
|
|
|
2007-01-29 01:11:21 +08:00
|
|
|
/** Stop any threads begin run by viewer.*/
|
2007-01-16 16:56:33 +08:00
|
|
|
void stopThreading();
|
2007-01-29 01:11:21 +08:00
|
|
|
|
|
|
|
/** Start any threads required by the viewer, as per viewers ThreadingModel.*/
|
2007-01-16 16:56:33 +08:00
|
|
|
void startThreading();
|
2006-11-27 22:52:07 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2007-06-06 18:57:02 +08:00
|
|
|
void constructorInit();
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
void init();
|
2007-06-06 18:57:02 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
void checkWindowStatus();
|
|
|
|
|
2006-11-29 04:35:31 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<osgViewer::View> > Views;
|
2006-11-27 22:52:07 +08:00
|
|
|
Views _views;
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
bool _firstFrame;
|
|
|
|
|
|
|
|
bool _done;
|
|
|
|
int _keyEventSetsDone;
|
|
|
|
bool _quitEventSetsDone;
|
|
|
|
|
|
|
|
ThreadingModel _threadingModel;
|
2007-05-12 03:25:44 +08:00
|
|
|
bool _threadsRunning;
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
BarrierPosition _endBarrierPosition;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::BarrierOperation> _startRenderingBarrier;
|
|
|
|
osg::ref_ptr<osg::BarrierOperation> _endRenderingDispatchBarrier;
|
|
|
|
|
|
|
|
unsigned int computeNumberOfThreadsIncludingMainRequired();
|
|
|
|
|
|
|
|
unsigned int _numThreadsOnBarrier;
|
|
|
|
|
|
|
|
osg::Timer_t _startTick;
|
|
|
|
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
|
|
|
|
|
|
|
osg::observer_ptr<osg::Camera> _cameraWithFocus;
|
|
|
|
osg::observer_ptr<osgViewer::View> _viewWithFocus;
|
|
|
|
|
|
|
|
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
|
|
|
|
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
|
2007-01-29 01:11:21 +08:00
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
osg::ref_ptr<osg::OperationQueue> _updateOperations;
|
|
|
|
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
|
|
|
|
|
|
|
|
|
2007-02-03 06:30:36 +08:00
|
|
|
osg::ref_ptr<osg::Operation> _realizeOperation;
|
2006-11-27 22:52:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|