Refactored the way the Scene is used in Viewer and CompositeViewer to ensure
that only on Scene exists per scene graph.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#define OSG_GRAPHICSTHREAD 1
|
||||
|
||||
#include <osg/OperationThread>
|
||||
#include <osg/State>
|
||||
|
||||
namespace osg {
|
||||
|
||||
@@ -117,6 +118,19 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class OSG_EXPORT EndOfDynamicDrawBlock : public OpenThreads::BlockCount, public osg::State::DynamicObjectRenderingCompletedCallback
|
||||
{
|
||||
public:
|
||||
|
||||
EndOfDynamicDrawBlock(unsigned int);
|
||||
|
||||
void completed(osg::State* state);
|
||||
|
||||
protected:
|
||||
|
||||
~EndOfDynamicDrawBlock() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#define OSGVIEWER_CompositeViewer 1
|
||||
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osgUtil/UpdateVisitor>
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
#include <osgViewer/View>
|
||||
|
||||
@@ -196,6 +197,10 @@ class OSGVIEWER_EXPORT CompositeViewer : public osg::Referenced
|
||||
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
|
||||
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
|
||||
|
||||
osg::ref_ptr<osg::OperationQueue> _updateOperations;
|
||||
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Operation> _realizeOperation;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#ifndef OSGVIEWER_SCENE
|
||||
#define OSGVIEWER_SCENE 1
|
||||
|
||||
#include <osgUtil/UpdateVisitor>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <osgGA/EventVisitor>
|
||||
#include <osgDB/DatabasePager>
|
||||
@@ -26,7 +25,7 @@
|
||||
namespace osgViewer{
|
||||
|
||||
/** Scene holds the highe level reference to a single scene graph.*/
|
||||
class OSGVIEWER_EXPORT Scene : public virtual osg::Referenced
|
||||
class OSGVIEWER_EXPORT Scene : public osg::Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -37,38 +36,19 @@ class OSGVIEWER_EXPORT Scene : public virtual osg::Referenced
|
||||
osg::Node* getSceneData();
|
||||
const osg::Node* getSceneData() const;
|
||||
|
||||
void setFrameStamp(osg::FrameStamp* frameStamp);
|
||||
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
|
||||
const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
|
||||
|
||||
void setDatabasePager(osgDB::DatabasePager* dp);
|
||||
osgDB::DatabasePager* getDatabasePager() { return _databasePager.get(); }
|
||||
const osgDB::DatabasePager* getDatabasePager() const { return _databasePager.get(); }
|
||||
|
||||
void setUpdateVisitor(osgUtil::UpdateVisitor* uv) { _updateVisitor = uv; }
|
||||
osgUtil::UpdateVisitor* getUpdateVisitor() { return _updateVisitor.get(); }
|
||||
const osgUtil::UpdateVisitor* getUpdateVisitor() const { return _updateVisitor.get(); }
|
||||
/** Get the Scene object that has the specified node assigned to it.
|
||||
* return 0 if no Scene has yet been assigned the specified node.*/
|
||||
static Scene* getScene(osg::Node* node);
|
||||
|
||||
|
||||
virtual void advance();
|
||||
|
||||
virtual void updateTraversal();
|
||||
|
||||
|
||||
|
||||
public:
|
||||
|
||||
void init();
|
||||
|
||||
protected:
|
||||
|
||||
bool _firstFrame;
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
|
||||
osg::ref_ptr<osg::Node> _sceneData;
|
||||
|
||||
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
|
||||
|
||||
osg::ref_ptr<osgDB::DatabasePager> _databasePager;
|
||||
};
|
||||
|
||||
|
||||
@@ -25,33 +25,6 @@
|
||||
|
||||
namespace osgViewer {
|
||||
|
||||
class OSGVIEWER_EXPORT EndOfDynamicDrawBlock : public osg::State::DynamicObjectRenderingCompletedCallback
|
||||
{
|
||||
public:
|
||||
|
||||
EndOfDynamicDrawBlock(unsigned int);
|
||||
|
||||
void completed(osg::State* state);
|
||||
|
||||
void block();
|
||||
|
||||
void reset();
|
||||
|
||||
void release();
|
||||
|
||||
void setNumOfBlocks(unsigned int blockCount);
|
||||
|
||||
protected:
|
||||
|
||||
~EndOfDynamicDrawBlock();
|
||||
|
||||
OpenThreads::Mutex _mut;
|
||||
OpenThreads::Condition _cond;
|
||||
unsigned int _numberOfBlocks;
|
||||
unsigned int _blockCount;
|
||||
};
|
||||
|
||||
|
||||
/** View holds a single view on a scene, this view may be composed of one or more slave cameras.*/
|
||||
class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
{
|
||||
@@ -63,6 +36,13 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
|
||||
META_Object(osgViewer,View);
|
||||
|
||||
virtual void setStartTick(osg::Timer_t tick);
|
||||
osg::Timer_t getStartTick() const { return _startTick; }
|
||||
|
||||
void setFrameStamp(osg::FrameStamp* fs) { _frameStamp = fs; }
|
||||
osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); }
|
||||
const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); }
|
||||
|
||||
Scene* getScene() { return _scene.get(); }
|
||||
const Scene* getScene() const { return _scene.get(); }
|
||||
|
||||
@@ -75,6 +55,12 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
/** Get the const View's scene graph.*/
|
||||
const osg::Node* getSceneData() const { return _scene.valid() ? _scene->getSceneData() : 0; }
|
||||
|
||||
/** Get the View's database pager.*/
|
||||
osgDB::DatabasePager* getDatabasePager();
|
||||
|
||||
/** Get the const View's database pager.*/
|
||||
const osgDB::DatabasePager* getDatabasePager() const;
|
||||
|
||||
/* Set the EventQueue that View uses to intregrate external non window related events.*/
|
||||
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
|
||||
|
||||
@@ -188,6 +174,9 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
|
||||
virtual osg::GraphicsOperation* createRenderer(osg::Camera* camera);
|
||||
|
||||
osg::Timer_t _startTick;
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
|
||||
osg::ref_ptr<osgViewer::Scene> _scene;
|
||||
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
|
||||
osg::ref_ptr<osgGA::MatrixManipulator> _cameraManipulator;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <osg/ArgumentParser>
|
||||
#include <osgGA/EventVisitor>
|
||||
#include <osgUtil/UpdateVisitor>
|
||||
#include <osgViewer/GraphicsWindow>
|
||||
#include <osgViewer/View>
|
||||
|
||||
@@ -43,15 +44,10 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
|
||||
|
||||
bool done() const { return _done; }
|
||||
|
||||
void setStartTick(osg::Timer_t tick);
|
||||
osg::Timer_t getStartTick() const { return _startTick; }
|
||||
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 sene graph data that viewer with view.*/
|
||||
virtual void setSceneData(osg::Node* node);
|
||||
|
||||
@@ -200,34 +196,34 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
|
||||
}
|
||||
|
||||
|
||||
bool _firstFrame;
|
||||
bool _firstFrame;
|
||||
|
||||
bool _done;
|
||||
int _keyEventSetsDone;
|
||||
bool _quitEventSetsDone;
|
||||
bool _done;
|
||||
int _keyEventSetsDone;
|
||||
bool _quitEventSetsDone;
|
||||
|
||||
ThreadingModel _threadingModel;
|
||||
bool _threadsRunning;
|
||||
ThreadingModel _threadingModel;
|
||||
bool _threadsRunning;
|
||||
|
||||
bool _useMainThreadForRenderingTraversal;
|
||||
BarrierPosition _endBarrierPosition;
|
||||
bool _useMainThreadForRenderingTraversal;
|
||||
BarrierPosition _endBarrierPosition;
|
||||
|
||||
osg::ref_ptr<osg::BarrierOperation> _startRenderingBarrier;
|
||||
osg::ref_ptr<osg::BarrierOperation> _endRenderingDispatchBarrier;
|
||||
osg::ref_ptr<EndOfDynamicDrawBlock> _endDynamicDrawBlock;
|
||||
osg::ref_ptr<osg::BarrierOperation> _startRenderingBarrier;
|
||||
osg::ref_ptr<osg::BarrierOperation> _endRenderingDispatchBarrier;
|
||||
osg::ref_ptr<osg::EndOfDynamicDrawBlock> _endDynamicDrawBlock;
|
||||
|
||||
unsigned int _numWindowsOpenAtLastSetUpThreading;
|
||||
unsigned int _numWindowsOpenAtLastSetUpThreading;
|
||||
|
||||
osg::Timer_t _startTick;
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
osg::observer_ptr<osg::Camera> _cameraWithFocus;
|
||||
|
||||
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
|
||||
|
||||
osg::ref_ptr<osg::OperationQueue> _updateOperations;
|
||||
osg::ref_ptr<osgUtil::UpdateVisitor> _updateVisitor;
|
||||
|
||||
osg::ref_ptr<osg::Operation> _realizeOperation;
|
||||
|
||||
osg::observer_ptr<osg::Camera> _cameraWithFocus;
|
||||
|
||||
osg::ref_ptr<osgGA::EventVisitor> _eventVisitor;
|
||||
|
||||
osg::ref_ptr<osg::Operation> _realizeOperation;
|
||||
|
||||
osg::observer_ptr<osg::GraphicsContext> _currentContext;
|
||||
osg::observer_ptr<osg::GraphicsContext> _currentContext;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user