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.
This commit is contained in:
Robert Osfield 2007-07-14 17:07:59 +00:00
parent af19e71024
commit 1f0edca631
3 changed files with 19 additions and 2 deletions

View File

@ -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<Camera*> Cameras;
ref_ptr<State> _state;
observer_ptr<View> _view;
Cameras _cameras;
ref_ptr<Referenced> _userData;
};

View File

@ -236,7 +236,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
double _clearDepth;
int _clearStencil;
bool _cameraRequiresSetUp;
bool _cameraRequiresSetUp;
osg::Camera* _camera;
osg::ref_ptr<osg::Texture> _texture;

View File

@ -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)