OpenSceneGraph/include/osgViewer/CompositeViewer

157 lines
5.4 KiB
Plaintext
Raw Normal View History

/* -*-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 {
/** CompositeViewer holds one or more views to one or more scenes.*/
class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase
{
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);
2009-01-27 21:23:20 +08:00
/** Set the Stats object used to collect various frame related timing and scene graph stats.*/
2009-01-27 21:23:20 +08:00
virtual void setViewerStats(osg::Stats* stats) { _stats = stats; }
/** Get the Viewers Stats object.*/
virtual osg::Stats* getViewerStats() { return _stats.get(); }
/** Get the Viewers Stats object.*/
virtual const osg::Stats* getViewerStats() const { return _stats.get(); }
2006-11-29 04:35:31 +08:00
void addView(osgViewer::View* view);
Introduced CMake option OSG_PROVIDE_READFILE option that defaults to ON, but when switched to OFF disables the building of the osgDB::read*File() methods, forcing users to use osgDB::readRef*File() methods. The later is preferable as it closes a potential threading bug when using paging databases in conjunction with the osgDB::Registry Object Cache. This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero. Using osgDB::readREf*File() makes sure the a ref_ptr<> is passed back and the referenceCount never goes to zero. To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File() usage. The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group: bool addChild(Node* child); // old method which can only be used with a Node* tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache and multi-threaded loaded more robust. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15164 16af8721-9629-0410-8352-f15c8da7e697
2015-10-22 21:42:19 +08:00
template<class T> void addView(const osg::ref_ptr<T>& view) { addView(view.get()); }
void removeView(osgViewer::View* view);
Introduced CMake option OSG_PROVIDE_READFILE option that defaults to ON, but when switched to OFF disables the building of the osgDB::read*File() methods, forcing users to use osgDB::readRef*File() methods. The later is preferable as it closes a potential threading bug when using paging databases in conjunction with the osgDB::Registry Object Cache. This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero. Using osgDB::readREf*File() makes sure the a ref_ptr<> is passed back and the referenceCount never goes to zero. To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File() usage. The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group: bool addChild(Node* child); // old method which can only be used with a Node* tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache and multi-threaded loaded more robust. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15164 16af8721-9629-0410-8352-f15c8da7e697
2015-10-22 21:42:19 +08:00
template<class T> void removeView(const osg::ref_ptr<T>& view) { removeView(view.get()); }
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(); }
2006-11-29 04:35:31 +08:00
unsigned int getNumViews() const { return _views.size(); }
/** Get whether at least of one of this viewer's 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(); }
virtual double elapsedTime();
virtual osg::FrameStamp* getViewerFrameStamp() { return getFrameStamp(); }
/** Execute a main frame loop.
* Equivalent 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();
/** Check to see if the new frame is required, called by run() when FrameScheme is set to ON_DEMAND.*/
virtual bool checkNeedToDoFrame();
/** check to see if events have been received, return true if events are now available.*/
virtual bool checkEvents();
virtual void advance(double simulationTime=USE_REFERENCE_TIME);
virtual void eventTraversal();
virtual void updateTraversal();
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 getAllThreads(Threads& threads, bool onlyActive=true);
virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true);
virtual void getScenes(Scenes& scenes, bool onlyValid=true);
virtual void getViews(Views& views, bool onlyValid=true);
/** Get the keyboard and mouse usage of this viewer.*/
virtual void getUsage(osg::ApplicationUsage& usage) const;
protected:
void constructorInit();
virtual void viewerInit();
void generateSlavePointerData(osg::Camera* camera, osgGA::GUIEventAdapter& event);
void generatePointerData(osgGA::GUIEventAdapter& event);
void reprojectPointerData(osgGA::GUIEventAdapter& source_event, osgGA::GUIEventAdapter& dest_event);
typedef std::vector< osg::ref_ptr<osgViewer::View> > RefViews;
RefViews _views;
bool _firstFrame;
2009-01-27 21:23:20 +08:00
osg::ref_ptr<osg::Stats> _stats;
osg::Timer_t _startTick;
osg::ref_ptr<osg::FrameStamp> _frameStamp;
osg::observer_ptr<osg::Camera> _cameraWithFocus;
osg::observer_ptr<osgViewer::View> _viewWithFocus;
Introduced CMake option OSG_PROVIDE_READFILE option that defaults to ON, but when switched to OFF disables the building of the osgDB::read*File() methods, forcing users to use osgDB::readRef*File() methods. The later is preferable as it closes a potential threading bug when using paging databases in conjunction with the osgDB::Registry Object Cache. This threading bug occurs when one thread gets an object from the Cache via an osgDB::read*File() call where only a pointer to the object is passed back, so taking a reference to the object is delayed till it gets reassigned to a ref_ptr<>, but at the same time another thread calls a flush of the Object Cache deleting this object as it's referenceCount is now zero. Using osgDB::readREf*File() makes sure the a ref_ptr<> is passed back and the referenceCount never goes to zero. To ensure the OSG builds when OSG_PROVIDE_READFILE is to OFF the many cases of osgDB::read*File() usage had to be replaced with a ref_ptr<> osgDB::readRef*File() usage. The avoid this change causing lots of other client code to be rewritten to handle the use of ref_ptr<> in place of C pointer I introduced a serious of templte methods in various class to adapt ref_ptr<> to the underly C pointer to be passed to old OSG API's, example of this is found in include/osg/Group: bool addChild(Node* child); // old method which can only be used with a Node* tempalte<class T> bool addChild(const osg::ref_ptr<T>& child) { return addChild(child.get()); } // adapter template method These changes together cover 149 modified files, so it's a large submission. This extent of changes are warrent to make use of the Object Cache and multi-threaded loaded more robust. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15164 16af8721-9629-0410-8352-f15c8da7e697
2015-10-22 21:42:19 +08:00
osg::ref_ptr<osgGA::GUIEventAdapter> _previousEvent;
};
}
#endif