diff --git a/include/osgTerrain/Terrain b/include/osgTerrain/Terrain index 9186afd0c..c80ef46c3 100644 --- a/include/osgTerrain/Terrain +++ b/include/osgTerrain/Terrain @@ -63,6 +63,15 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group /** Get the const TerrainTile for a given TileID.*/ const TerrainTile* getTile(const TileID& tileID) const; + + /** Set the TerrainTechnique cprototype from which TerrainTiles can clone the techniques from..*/ + void setTerrainTechniquePrototype(TerrainTechnique* technique); + + /** Get the TerrainTechnique prototype */ + TerrainTechnique* getTerrainTechniquePrototype() { return _terrainTechnique.get(); } + + /** Get the const TerrainTechnique protype*/ + const TerrainTechnique* getTerrainTechniquePrototype() const { return _terrainTechnique.get(); } protected: @@ -85,7 +94,7 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group TerrainTileSet _terrainTileSet; TerrainTileMap _terrainTileMap; - + osg::ref_ptr _terrainTechnique; }; } diff --git a/include/osgTerrain/TerrainTile b/include/osgTerrain/TerrainTile index 217ab7cc1..616c69392 100644 --- a/include/osgTerrain/TerrainTile +++ b/include/osgTerrain/TerrainTile @@ -107,7 +107,7 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group /** Set the TerrainTechnique*/ - void setTerrainTechnique(TerrainTechnique* TerrainTechnique); + void setTerrainTechnique(TerrainTechnique* terrainTechnique); /** Get the TerrainTechnique*/ TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); } diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index c82a866c4..1646414bb 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -43,8 +43,13 @@ GeometryTechnique::GeometryTechnique(): } GeometryTechnique::GeometryTechnique(const GeometryTechnique& gt,const osg::CopyOp& copyop): - TerrainTechnique(gt,copyop) + TerrainTechnique(gt,copyop), + _currentReadOnlyBuffer(1), + _currentWriteBuffer(0) { + setFilterBias(gt._filterBias); + setFilterWidth(gt._filterWidth); + setFilterMatrix(gt._filterMatrix); } GeometryTechnique::~GeometryTechnique() diff --git a/src/osgTerrain/Terrain.cpp b/src/osgTerrain/Terrain.cpp index f5b5057c6..cf6d26675 100644 --- a/src/osgTerrain/Terrain.cpp +++ b/src/osgTerrain/Terrain.cpp @@ -12,6 +12,8 @@ */ #include +#include + #include using namespace osg; @@ -21,12 +23,14 @@ Terrain::Terrain(): _sampleRatio(1.0), _verticalScale(1.0) { + _terrainTechnique = new GeometryTechnique; } Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop): osg::Group(ts,copyop), _sampleRatio(ts._sampleRatio), - _verticalScale(ts._verticalScale) + _verticalScale(ts._verticalScale), + _terrainTechnique(ts._terrainTechnique) { } diff --git a/src/osgTerrain/TerrainTile.cpp b/src/osgTerrain/TerrainTile.cpp index 6a9bed43e..283d6eec7 100644 --- a/src/osgTerrain/TerrainTile.cpp +++ b/src/osgTerrain/TerrainTile.cpp @@ -13,6 +13,7 @@ #include #include +#include #include @@ -113,7 +114,9 @@ void TerrainTile::traverse(osg::NodeVisitor& nv) } } } - + + init(); + _hasBeenTraversal = true; } @@ -138,6 +141,19 @@ void TerrainTile::traverse(osg::NodeVisitor& nv) void TerrainTile::init() { + if (!_terrainTechnique) + { + if (_terrain && _terrain->getTerrainTechniquePrototype()) + { + osg::ref_ptr object = _terrain->getTerrainTechniquePrototype()->clone(osg::CopyOp::DEEP_COPY_ALL); + setTerrainTechnique(dynamic_cast(object.get())); + } + else + { + setTerrainTechnique(new GeometryTechnique); + } + } + if (_terrainTechnique.valid() && getDirty()) { _terrainTechnique->init();