178 lines
6.2 KiB
C++
178 lines
6.2 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_CompositeViewer
|
|
#define OSGVIEWER_CompositeViewer 1
|
|
|
|
#include <osg/ArgumentParser>
|
|
#include <osgUtil/UpdateVisitor>
|
|
#include <osgViewer/GraphicsWindow>
|
|
#include <osgViewer/View>
|
|
|
|
namespace osgViewer {
|
|
|
|
/** CompsiteViewer holds a or more views to a one more scenes.*/
|
|
class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase, public virtual osg::Object
|
|
{
|
|
public:
|
|
|
|
CompositeViewer();
|
|
|
|
CompositeViewer(const CompositeViewer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
|
|
|
CompositeViewer(osg::ArgumentParser& arguments);
|
|
|
|
META_Object(osgViewer,CompositeViewer);
|
|
|
|
virtual ~CompositeViewer();
|
|
|
|
/** read the viewer configuration from a configuration file.*/
|
|
bool readConfiguration(const std::string& filename);
|
|
|
|
void addView(osgViewer::View* view);
|
|
void removeView(osgViewer::View* view);
|
|
|
|
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(); }
|
|
|
|
|
|
/** Get whether at least of one of this viewers windows are realized.*/
|
|
virtual bool isRealized() const;
|
|
|
|
/** set up windows and associated threads.*/
|
|
virtual void realize();
|
|
|
|
virtual void setStartTick(osg::Timer_t tick);
|
|
|
|
void setReferenceTime(double time=0.0);
|
|
|
|
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
|
|
const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
|
|
|
|
/** Set the threading model the rendering traversals will use.*/
|
|
virtual void setThreadingModel(ThreadingModel threadingModel);
|
|
|
|
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
|
|
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
|
|
const osgGA::EventQueue* getEventQueue() const { return _eventQueue.get(); }
|
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
|
|
/** 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(double simulationTime=USE_REFERENCE_TIME);
|
|
|
|
virtual void advance(double simulationTime=USE_REFERENCE_TIME);
|
|
|
|
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(); }
|
|
|
|
virtual void getCameras(Cameras& cameras, bool onlyActive=true);
|
|
|
|
virtual void getContexts(Contexts& contexts, bool onlyValid=true);
|
|
|
|
virtual void getWindows(Windows& windows, bool onlyValid=true);
|
|
|
|
virtual void getAllThreads(Threads& threads, bool onlyActive=true);
|
|
|
|
virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
|
|
|
|
virtual void getScenes(Scenes& scenes, bool onlyValid=true);
|
|
|
|
|
|
/** Set up the threading and processor affinity as per the viewers threading model.*/
|
|
virtual void setUpThreading();
|
|
|
|
/** Stop any threads begin run by viewer.*/
|
|
virtual void stopThreading();
|
|
|
|
/** Start any threads required by the viewer, as per viewers ThreadingModel.*/
|
|
virtual void startThreading();
|
|
|
|
/** Get the keyboard and mouse usage of this viewer.*/
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
|
|
|
protected:
|
|
|
|
void constructorInit();
|
|
|
|
void init();
|
|
|
|
void checkWindowStatus();
|
|
|
|
typedef std::vector< osg::ref_ptr<osgViewer::View> > Views;
|
|
Views _views;
|
|
|
|
bool _firstFrame;
|
|
|
|
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;
|
|
};
|
|
|
|
|
|
}
|
|
|
|
#endif
|