Added BlendingPolicy support into osgTerrain::Terrain.

This commit is contained in:
Robert Osfield 2010-03-16 18:43:59 +00:00
parent 1537af6235
commit c4e82f0221
5 changed files with 48 additions and 10 deletions

View File

@ -40,6 +40,7 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
* Defaults to 1.0, which means use all original sample points.*/
void setSampleRatio(float ratio)
{
if (_sampleRatio == ratio) return;
_sampleRatio = ratio;
dirtyRegisteredTiles();
}
@ -51,6 +52,7 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
/** Set the vertical scale hint.*/
void setVerticalScale(float scale)
{
if (_verticalScale == scale) return;
_verticalScale = scale;
dirtyRegisteredTiles();
}
@ -58,6 +60,22 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
/** 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;

View File

@ -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.*/

View File

@ -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"<<std::endl;
blendingPolicy = _terrainTile->getTerrain()->getBlendingPolicy();
}
if (blendingPolicy == TerrainTile::INHERIT)
{
OSG_INFO<<"GeometryTechnique::applyTransparency() policy is INHERIT, defaulting to ENABLE_BLENDING_WHEN_ALPHA_PRESENT"<<std::endl;
blendingPolicy = TerrainTile::ENABLE_BLENDING_WHEN_ALPHA_PRESENT;
}
if (blendingPolicy == TerrainTile::DO_NOT_SET_BLENDING)
{
OSG_INFO<<"blendingPolicy == TerrainTile::DO_NOT_SET_BLENDING"<<std::endl;
return;
}
bool enableBlending = false;
if (_terrainTile->getBlendingPolicy()==TerrainTile::ENABLE_BLENDING)
if (blendingPolicy == TerrainTile::ENABLE_BLENDING)
{
OSG_INFO<<"blendingPolicy == TerrainTile::ENABLE_BLENDING"<<std::endl;
enableBlending = true;
}
else if (_terrainTile->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"<<std::endl;
for(unsigned int i=0; i<_terrainTile->getNumColorLayers(); ++i)
{
osg::Image* image = (_terrainTile->getColorLayer(i)!=0) ? _terrainTile->getColorLayer(i)->getImage() : 0;

View File

@ -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)
{
}

View File

@ -62,7 +62,7 @@ TerrainTile::TerrainTile():
_hasBeenTraversal(false),
_requiresNormals(true),
_treatBoundariesToValidDataAsDefaultValue(false),
_blendingPolicy(ENABLE_BLENDING_WHEN_ALPHA_PRESENT)
_blendingPolicy(INHERIT)
{
setThreadSafeRefUnref(true);
}