From 1f0edca631802471074ebae4cf5d232aaf88a3ec Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 14 Jul 2007 17:07:59 +0000 Subject: [PATCH] Added support into osg::RenderInfo for a stack of Cameras that allow querries of which camera is currently active to be querried from within the draw traversal. --- include/osg/RenderInfo | 10 ++++++++++ include/osgUtil/RenderStage | 2 +- src/osgUtil/RenderStage.cpp | 9 ++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/osg/RenderInfo b/include/osg/RenderInfo index c8b35bbdf..3ba9a45c2 100644 --- a/include/osg/RenderInfo +++ b/include/osg/RenderInfo @@ -30,6 +30,7 @@ public: RenderInfo(const RenderInfo& rhs): _state(rhs._state), _view(rhs._view), + _cameras(rhs._cameras), _userData(rhs._userData) {} RenderInfo(State* state, View* view): @@ -40,6 +41,7 @@ public: { _state = rhs._state; _view = rhs._view; + _cameras = rhs._cameras; _userData = rhs._userData; return *this; } @@ -53,6 +55,11 @@ public: void setView(View* view) { _view = view; } View* getView() { return _view.get(); } const View* getView() const { return _view.get(); } + + void pushCamera(Camera* camera) { _cameras.push_back(camera); } + void popCamera() { if (_cameras.empty()) _cameras.pop_back(); } + + Camera* getCurrentCamera() { return _cameras.empty() ? 0 : _cameras.back(); } void setUserData(Referenced* userData) { _userData = userData; } Referenced* getUserData() { return _userData.get(); } @@ -60,8 +67,11 @@ public: protected: + typedef std::vector Cameras; + ref_ptr _state; observer_ptr _view; + Cameras _cameras; ref_ptr _userData; }; diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 6716b574e..a0c772f5e 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -236,7 +236,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin double _clearDepth; int _clearStencil; - bool _cameraRequiresSetUp; + bool _cameraRequiresSetUp; osg::Camera* _camera; osg::ref_ptr _texture; diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index 0054348b3..b3b6c7705 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -988,7 +988,10 @@ void RenderStage::drawImplementation(osg::RenderInfo& renderInfo,RenderLeaf*& pr notify(FATAL) << "Error: cannot draw stage due to undefined viewport."<< std::endl; return; } - + + // push the stages camera so that drawing code can querry it + if (_camera) renderInfo.pushCamera(_camera); + // set up the back buffer. state.applyAttribute(_viewport.get()); @@ -1048,6 +1051,10 @@ void RenderStage::drawImplementation(osg::RenderInfo& renderInfo,RenderLeaf*& pr RenderBin::drawImplementation(renderInfo,previous); state.apply(); + + // pop the render stages camera. + if (_camera) renderInfo.popCamera(); + } void RenderStage::drawPostRenderStages(osg::RenderInfo& renderInfo,RenderLeaf*& previous)