diff --git a/include/osgTerrain/Terrain b/include/osgTerrain/Terrain index 9c1b49f98..abe6b3b53 100644 --- a/include/osgTerrain/Terrain +++ b/include/osgTerrain/Terrain @@ -39,7 +39,8 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group /** Set the sample ratio hint that TerrainTile should use when building geometry. * Defaults to 1.0, which means use all original sample points.*/ void setSampleRatio(float ratio) - { + { + if (_sampleRatio == ratio) return; _sampleRatio = ratio; dirtyRegisteredTiles(); } @@ -50,14 +51,31 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group /** Set the vertical scale hint.*/ void setVerticalScale(float scale) - { + { + if (_verticalScale == scale) return; _verticalScale = scale; dirtyRegisteredTiles(); } - + /** Get the vertical scale hint.*/ float getVerticalScale() const { return _verticalScale; } - + + + /** Set the default policy to use when deciding whether to enable/disable blending and use of transparent bin. + * Note, the Terrain::BlendingPolicy value only sets the value for the TerrainTiles it encloses for the + * TerrainTile's that have their policy set to INHERIT. INHERIT is the default BlendingPolicy for both + * Terrain and TerrainTile, and if both are left to INERHIT then the policy used is ENABLE_BLENDING_WHEN_ALPHA_PRESENT. */ + void setBlendingPolicy(TerrainTile::BlendingPolicy policy) + { + if (_blendingPolicy == policy) return; + _blendingPolicy = policy; + dirtyRegisteredTiles(); + } + + /** Get the default policy to use when deciding whether to enable/disable blending and use of transparent bin.*/ + TerrainTile::BlendingPolicy getBlendingPolicy() const { return _blendingPolicy; } + + /** Get the TerrainTile for a given TileID.*/ TerrainTile* getTile(const TileID& tileID); @@ -89,6 +107,7 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group float _sampleRatio; float _verticalScale; + TerrainTile::BlendingPolicy _blendingPolicy; mutable OpenThreads::Mutex _mutex; TerrainTileSet _terrainTileSet; diff --git a/include/osgTerrain/TerrainTile b/include/osgTerrain/TerrainTile index 811aa3827..2ac187474 100644 --- a/include/osgTerrain/TerrainTile +++ b/include/osgTerrain/TerrainTile @@ -159,9 +159,10 @@ class OSGTERRAIN_EXPORT TerrainTile : public osg::Group enum BlendingPolicy { + INHERIT, /** Default - check for the any BlendingPolicy set on the enclosing osgTerrain::Terrain node, and if it's also INHERIT then assume ENABLE_BLENDING_WHEN_ALPHA_PRESENT. */ DO_NOT_SET_BLENDING, ENABLE_BLENDING, - ENABLE_BLENDING_WHEN_ALPHA_PRESENT /** Default - check colour layers for alpha value and if present enable blending. */ + ENABLE_BLENDING_WHEN_ALPHA_PRESENT /** check colour layers for alpha value and if present enable blending. */ }; /** Set the policy to use when deciding whether to enable/disable blending and use of transparent bin.*/ diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index 09090134a..0dea263c0 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -802,19 +802,35 @@ void GeometryTechnique::applyColorLayers() void GeometryTechnique::applyTransparency() { - if (_terrainTile->getBlendingPolicy()==TerrainTile::DO_NOT_SET_BLENDING) + TerrainTile::BlendingPolicy blendingPolicy = _terrainTile->getBlendingPolicy(); + if (blendingPolicy == TerrainTile::INHERIT && _terrainTile->getTerrain()) { + OSG_INFO<<"GeometryTechnique::applyTransparency() inheriting policy from Terrain"<getTerrain()->getBlendingPolicy(); + } + + if (blendingPolicy == TerrainTile::INHERIT) + { + OSG_INFO<<"GeometryTechnique::applyTransparency() policy is INHERIT, defaulting to ENABLE_BLENDING_WHEN_ALPHA_PRESENT"<getBlendingPolicy()==TerrainTile::ENABLE_BLENDING) + if (blendingPolicy == TerrainTile::ENABLE_BLENDING) { + OSG_INFO<<"blendingPolicy == TerrainTile::ENABLE_BLENDING"<getBlendingPolicy()==TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT) + else if (blendingPolicy == TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT) { + OSG_INFO<<"blendingPolicy == TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT"<getNumColorLayers(); ++i) { osg::Image* image = (_terrainTile->getColorLayer(i)!=0) ? _terrainTile->getColorLayer(i)->getImage() : 0; diff --git a/src/osgTerrain/Terrain.cpp b/src/osgTerrain/Terrain.cpp index cf6d26675..79417bec6 100644 --- a/src/osgTerrain/Terrain.cpp +++ b/src/osgTerrain/Terrain.cpp @@ -21,7 +21,8 @@ using namespace osgTerrain; Terrain::Terrain(): _sampleRatio(1.0), - _verticalScale(1.0) + _verticalScale(1.0), + _blendingPolicy(TerrainTile::INHERIT) { _terrainTechnique = new GeometryTechnique; } @@ -30,6 +31,7 @@ Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop): osg::Group(ts,copyop), _sampleRatio(ts._sampleRatio), _verticalScale(ts._verticalScale), + _blendingPolicy(ts._blendingPolicy), _terrainTechnique(ts._terrainTechnique) { } diff --git a/src/osgTerrain/TerrainTile.cpp b/src/osgTerrain/TerrainTile.cpp index bd8b95094..334afc767 100644 --- a/src/osgTerrain/TerrainTile.cpp +++ b/src/osgTerrain/TerrainTile.cpp @@ -62,7 +62,7 @@ TerrainTile::TerrainTile(): _hasBeenTraversal(false), _requiresNormals(true), _treatBoundariesToValidDataAsDefaultValue(false), - _blendingPolicy(ENABLE_BLENDING_WHEN_ALPHA_PRESENT) + _blendingPolicy(INHERIT) { setThreadSafeRefUnref(true); }