diff --git a/include/osg/Camera b/include/osg/Camera index 3a2219a57..b9e115636 100644 --- a/include/osg/Camera +++ b/include/osg/Camera @@ -416,6 +416,16 @@ class OSG_EXPORT Camera : public Transform, public CullSettings const BufferAttachmentMap& getBufferAttachmentMap() const { return _bufferAttachmentMap; } + /** Increment the _attachementMapModifiedCount so that the rendering backend will know that it needs to be updated to handle any new settings (such as format change/resizes.).*/ + void dirtyAttachmentMap() { ++_attachmentMapModifiedCount; } + + /** Set the AttachmentMapModifiedCount to a specific value. Note, normal usage you would simply call dirtyAttachmentMap(). */ + void setAttachmentMapModifiedCount(unsigned int v) { _attachmentMapModifiedCount = v; } + + /** Get the AttachmentMapModifiedCount. */ + unsigned int getAttachmentMapModifiedCount() const { return _attachmentMapModifiedCount; } + + /** Explicit control over implicit allocation of buffers when using FBO. Implicit buffers are automatically substituted when user have not attached such buffer. @@ -667,6 +677,8 @@ class OSG_EXPORT Camera : public Transform, public CullSettings ImplicitBufferAttachmentMask _implicitBufferAttachmentRenderMask; ImplicitBufferAttachmentMask _implicitBufferAttachmentResolveMask; + unsigned int _attachmentMapModifiedCount; + ref_ptr _cameraThread; ref_ptr _graphicsContext; diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index eda5f24b3..6c2a3c15c 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -143,6 +143,10 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin void setCameraRequiresSetUp(bool flag) { _cameraRequiresSetUp = flag; } bool getCameraRequiresSetUp() const { return _cameraRequiresSetUp; } + void setCameraAttachmentMapCount(unsigned int v) { _cameraAttachmentMapModifiedCount = v; } + unsigned int getCameraAttachmentMapCount() { return _cameraAttachmentMapModifiedCount; } + + /** Attempt the set the RenderStage from the Camera settings.*/ void runCameraSetUp(osg::RenderInfo& renderInfo); @@ -288,6 +292,7 @@ protected: int _clearStencil; bool _cameraRequiresSetUp; + unsigned int _cameraAttachmentMapModifiedCount; osg::observer_ptr _camera; osg::ref_ptr _texture; diff --git a/src/osg/Camera.cpp b/src/osg/Camera.cpp index ccef7f8bd..823b63aad 100644 --- a/src/osg/Camera.cpp +++ b/src/osg/Camera.cpp @@ -35,7 +35,8 @@ Camera::Camera(): _renderTargetImplementation(FRAME_BUFFER), _renderTargetFallback(FRAME_BUFFER), _implicitBufferAttachmentRenderMask( USE_DISPLAY_SETTINGS_MASK ), - _implicitBufferAttachmentResolveMask( USE_DISPLAY_SETTINGS_MASK ) + _implicitBufferAttachmentResolveMask( USE_DISPLAY_SETTINGS_MASK ), + _attachmentMapModifiedCount(0) { setStateSet(new StateSet); } @@ -66,6 +67,7 @@ Camera::Camera(const Camera& camera,const CopyOp& copyop): _bufferAttachmentMap(camera._bufferAttachmentMap), _implicitBufferAttachmentRenderMask(camera._implicitBufferAttachmentRenderMask), _implicitBufferAttachmentResolveMask(camera._implicitBufferAttachmentResolveMask), + _attachmentMapModifiedCount(camera._attachmentMapModifiedCount), _initialDrawCallback(camera._initialDrawCallback), _preDrawCallback(camera._preDrawCallback), _postDrawCallback(camera._postDrawCallback), diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index d9f6526ff..c686bc89c 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -53,6 +53,7 @@ RenderStage::RenderStage(): _clearStencil = 0; _cameraRequiresSetUp = false; + _cameraAttachmentMapModifiedCount = 0; _camera = 0; _level = 0; @@ -83,6 +84,7 @@ RenderStage::RenderStage(SortMode mode): _clearStencil = 0; _cameraRequiresSetUp = false; + _cameraAttachmentMapModifiedCount = 0; _camera = 0; _level = 0; @@ -109,6 +111,7 @@ RenderStage::RenderStage(const RenderStage& rhs,const osg::CopyOp& copyop): _clearDepth(rhs._clearDepth), _clearStencil(rhs._clearStencil), _cameraRequiresSetUp(rhs._cameraRequiresSetUp), + _cameraAttachmentMapModifiedCount(rhs._cameraAttachmentMapModifiedCount), _camera(rhs._camera), _level(rhs._level), _face(rhs._face), @@ -227,6 +230,10 @@ void RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) if (!_camera) return; + OSG_INFO<<"RenderStage::runCameraSetUp(osg::RenderInfo& renderInfo) "<getAttachmentMapModifiedCount(); + osg::State& state = *renderInfo.getState(); osg::Camera::RenderTargetImplementation renderTargetImplementation = _camera->getRenderTargetImplementation(); @@ -1160,7 +1167,7 @@ void RenderStage::draw(osg::RenderInfo& renderInfo,RenderLeaf*& previous) // so there is no need to call it here. drawPreRenderStages(renderInfo,previous); - if (_cameraRequiresSetUp) + if (_cameraRequiresSetUp || (_cameraAttachmentMapModifiedCount!=_camera->getAttachmentMapModifiedCount())) { runCameraSetUp(renderInfo); }