diff --git a/include/osgTerrain/GeometryTechnique b/include/osgTerrain/GeometryTechnique index 70cb90df0..5f9829759 100644 --- a/include/osgTerrain/GeometryTechnique +++ b/include/osgTerrain/GeometryTechnique @@ -76,6 +76,11 @@ class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique void setFilterMatrixAs(FilterType filterType); + /** 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; + private: diff --git a/include/osgTerrain/TerrainTechnique b/include/osgTerrain/TerrainTechnique index e7f47854e..1922cddbd 100644 --- a/include/osgTerrain/TerrainTechnique +++ b/include/osgTerrain/TerrainTechnique @@ -51,6 +51,11 @@ class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object /** Traverse the terrain subgraph.*/ virtual void traverse(osg::NodeVisitor& nv); + /** 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: void setDirty(bool dirty); diff --git a/include/osgTerrain/TerrainTile b/include/osgTerrain/TerrainTile index 42b7ece3a..6e49527d0 100644 --- a/include/osgTerrain/TerrainTile +++ b/include/osgTerrain/TerrainTile @@ -175,6 +175,12 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group static void setTileLoadedCallback(TileLoadedCallback* lc); static osg::ref_ptr& getTileLoadedCallback(); + /** 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 ~TerrainTile(); diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index 9f51e374e..602e5ce4c 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -898,3 +898,9 @@ void GeometryTechnique::cleanSceneGraph() { } +void GeometryTechnique::releaseGLObjects(osg::State* state) const +{ + if (_bufferData[0]._transform.valid()) _bufferData[0]._transform->releaseGLObjects(state); + if (_bufferData[1]._transform.valid()) _bufferData[1]._transform->releaseGLObjects(state); +} + diff --git a/src/osgTerrain/TerrainTile.cpp b/src/osgTerrain/TerrainTile.cpp index 55b213cbf..21b0c3675 100644 --- a/src/osgTerrain/TerrainTile.cpp +++ b/src/osgTerrain/TerrainTile.cpp @@ -463,3 +463,14 @@ void WhiteListTileLoadedCallback::loaded(osgTerrain::TerrainTile* tile, const os } } + +void TerrainTile::releaseGLObjects(osg::State* state) const +{ + Group::releaseGLObjects(state); + + if (_terrainTechnique.valid()) + { + _terrainTechnique->releaseGLObjects( state ); + } +} +