diff --git a/include/osgShadow/ShadowedScene b/include/osgShadow/ShadowedScene index 9194131f8..e2b5cf2e5 100644 --- a/include/osgShadow/ShadowedScene +++ b/include/osgShadow/ShadowedScene @@ -52,7 +52,15 @@ class OSGSHADOW_EXPORT ShadowedScene : public osg::Group /** Dirty any cache data structures held in the attached ShadowTechnqiue.*/ void dirty(); - protected: + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + + /** If State is non-zero, this function releases any associated OpenGL objects for + * the specified graphics context. Otherwise, releases OpenGL objects + * for all graphics contexts. */ + virtual void releaseGLObjects(osg::State* = 0) const; + +protected: virtual ~ShadowedScene(); diff --git a/include/osgShadow/ViewDependentShadowMap b/include/osgShadow/ViewDependentShadowMap index 1855e65ec..e8285da0a 100644 --- a/include/osgShadow/ViewDependentShadowMap +++ b/include/osgShadow/ViewDependentShadowMap @@ -43,6 +43,14 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique /** run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/ virtual void cull(osgUtil::CullVisitor& cv); + /** Resize any per context GLObject buffers to specified size. */ + virtual void resizeGLObjectBuffers(unsigned int maxSize); + + /** If State is non-zero, this function releases any associated OpenGL objects for + * the specified graphics context. Otherwise, releases OpenGL objects + * for all graphics contexts. */ + virtual void releaseGLObjects(osg::State* = 0) const; + /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/ virtual void cleanSceneGraph(); @@ -100,6 +108,8 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique { ShadowData(ViewDependentData* vdd); + virtual void releaseGLObjects(osg::State* = 0) const; + ViewDependentData* _viewDependentData; unsigned int _textureUnit; @@ -124,6 +134,8 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique osg::StateSet* getStateSet() { return _stateset.get(); } + virtual void releaseGLObjects(osg::State* = 0) const; + protected: virtual ~ViewDependentData() {} @@ -156,8 +168,7 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; } ShadowMapProjectionHint getShadowMapProjectionHint() const { return _shadowMapProjectionHint; } - -virtual void createShaders(); + virtual void createShaders(); virtual bool selectActiveLights(osgUtil::CullVisitor* cv, ViewDependentData* vdd) const; @@ -184,8 +195,8 @@ protected: virtual ~ViewDependentShadowMap(); typedef std::map< osgUtil::CullVisitor*, osg::ref_ptr > ViewDependentDataMap; - OpenThreads::Mutex _viewDependentDataMapMutex; - ViewDependentDataMap _viewDependentDataMap; + mutable OpenThreads::Mutex _viewDependentDataMapMutex; + ViewDependentDataMap _viewDependentDataMap; unsigned int _baseShadowTextureUnit; diff --git a/src/osgShadow/ShadowedScene.cpp b/src/osgShadow/ShadowedScene.cpp index 23094438d..b874030cd 100644 --- a/src/osgShadow/ShadowedScene.cpp +++ b/src/osgShadow/ShadowedScene.cpp @@ -96,3 +96,15 @@ void ShadowedScene::dirty() _shadowTechnique->dirty(); } } + +void ShadowedScene::resizeGLObjectBuffers(unsigned int maxSize) +{ + if (_shadowTechnique.valid()) _shadowTechnique->resizeGLObjectBuffers(maxSize); + Group::resizeGLObjectBuffers(maxSize); +} + +void ShadowedScene::releaseGLObjects(osg::State* state) const +{ + if (_shadowTechnique.valid()) _shadowTechnique->releaseGLObjects(state); + Group::releaseGLObjects(state); +} diff --git a/src/osgShadow/ViewDependentShadowMap.cpp b/src/osgShadow/ViewDependentShadowMap.cpp index b4bc949da..bddaa6e0a 100644 --- a/src/osgShadow/ViewDependentShadowMap.cpp +++ b/src/osgShadow/ViewDependentShadowMap.cpp @@ -355,6 +355,13 @@ ViewDependentShadowMap::ShadowData::ShadowData(ViewDependentShadowMap::ViewDepen } } +void ViewDependentShadowMap::ShadowData::releaseGLObjects(osg::State* state) const +{ + OSG_INFO<<"ViewDependentShadowMap::ShadowData::releaseGLObjects"<releaseGLObjects(state); + _camera->releaseGLObjects(state); +} + /////////////////////////////////////////////////////////////////////////////////////////////// // // Frustum @@ -495,6 +502,15 @@ ViewDependentShadowMap::ViewDependentData::ViewDependentData(ViewDependentShadow _stateset = new osg::StateSet; } +void ViewDependentShadowMap::ViewDependentData::releaseGLObjects(osg::State* state) const +{ + for(ShadowDataList::const_iterator itr = _shadowDataList.begin(); + itr != _shadowDataList.end(); + ++itr) + { + (*itr)->releaseGLObjects(state); + } +} /////////////////////////////////////////////////////////////////////////////////////////////// // @@ -1769,3 +1785,23 @@ osg::StateSet* ViewDependentShadowMap::selectStateSetForRenderingShadow(ViewDepe return vdd.getStateSet(); } + +void ViewDependentShadowMap::resizeGLObjectBuffers(unsigned int maxSize) +{ + // the way that ViewDependentData is mapped shouldn't +} + +void ViewDependentShadowMap::releaseGLObjects(osg::State* state) const +{ + OpenThreads::ScopedLock lock(_viewDependentDataMapMutex); + for(ViewDependentDataMap::const_iterator itr = _viewDependentDataMap.begin(); + itr != _viewDependentDataMap.end(); + ++itr) + { + ViewDependentData* vdd = itr->second.get(); + if (vdd) + { + vdd->releaseGLObjects(state); + } + } +}