1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
17#include <osg/CoordinateSystemNode>
18#include <OpenThreads/ReentrantMutex>
20#include <osgTerrain/TerrainTile>
21#include <osgTerrain/GeometryPool>
25/** Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
26 * This allows TerrainTechniques to be plugged in at runtime.*/
27class OSGTERRAIN_EXPORT Terrain : public osg::CoordinateSystemNode
33 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
34 Terrain(const Terrain&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
36 META_Node(osgTerrain, Terrain);
38 virtual void traverse(osg::NodeVisitor& nv);
40 virtual osgTerrain::Terrain* asTerrain() { return this; }
41 virtual const osgTerrain::Terrain* asTerrain() const { return this; }
44 /** Set the sample ratio hint that TerrainTile should use when building geometry.
45 * Defaults to 1.0, which means use all original sample points.*/
46 void setSampleRatio(float ratio);
48 /** Get the sample ratio hint.*/
49 float getSampleRatio() const { return _sampleRatio; }
52 /** Set the vertical scale hint.*/
53 void setVerticalScale(float scale);
55 /** Get the vertical scale hint.*/
56 float getVerticalScale() const { return _verticalScale; }
59 /** Set the default policy to use when deciding whether to enable/disable blending and use of transparent bin.
60 * Note, the Terrain::BlendingPolicy value only sets the value for the TerrainTiles it encloses for the
61 * TerrainTile's that have their policy set to INHERIT. INHERIT is the default BlendingPolicy for both
62 * Terrain and TerrainTile, and if both are left to INERHIT then the policy used is ENABLE_BLENDING_WHEN_ALPHA_PRESENT. */
63 void setBlendingPolicy(TerrainTile::BlendingPolicy policy);
65 /** Get the default policy to use when deciding whether to enable/disable blending and use of transparent bin.*/
66 TerrainTile::BlendingPolicy getBlendingPolicy() const { return _blendingPolicy; }
68 /** If set to true the boundaries between adjacent tiles should be equalized.
69 * Note, it is only possible to equalizae boundaries when the TerrainTile's contain properly assigned TileID's,
70 * databases built with VirtualPlanetBuilder-0.9.11 and older do not set the TileID, so databases must be
71 * built with later versions of VirtualPlanetBuilder to take advantage of boundary equalization. */
72 void setEqualizeBoundaries(bool equalizeBoundaries);
74 /** If true the boundaries between adjacent tiles will be equalized. */
75 bool getEqualizeBoundaries() const { return _equalizeBoundaries; }
78 /** Set a custom GeometryPool to be used by TerrainTechniques that share geometry.*/
79 void setGeometryPool(GeometryPool* gp) { _geometryPool = gp; }
81 /** Get the GeometryPool.*/
82 GeometryPool* getGeometryPool() { return _geometryPool.get(); }
84 /** Get the const GeometryPool.*/
85 const GeometryPool* getGeometryPool() const { return _geometryPool.get(); }
89 /** Get the TerrainTile for a given TileID.*/
90 TerrainTile* getTile(const TileID& tileID);
92 /** Get the const TerrainTile for a given TileID.*/
93 const TerrainTile* getTile(const TileID& tileID) const;
95 /** Set the TerrainTechnique prototype from which TerrainTiles can clone the techniques from.*/
96 void setTerrainTechniquePrototype(TerrainTechnique* technique) { _terrainTechnique = technique; }
98 /** Get the TerrainTechnique prototype */
99 TerrainTechnique* getTerrainTechniquePrototype() { return _terrainTechnique.get(); }
101 /** Get the const TerrainTechnique protype*/
102 const TerrainTechnique* getTerrainTechniquePrototype() const { return _terrainTechnique.get(); }
104 /** Tell the Terrain node to call the terrainTile's TerrainTechnique on the next update traversal.*/
105 void updateTerrainTileOnNextFrame(TerrainTile* terrainTile);
111 friend class TerrainTile;
113 void dirtyRegisteredTiles(int dirtyMask = TerrainTile::ALL_DIRTY);
115 void registerTerrainTile(TerrainTile* tile);
116 void unregisterTerrainTile(TerrainTile* tile);
118 typedef std::map< TileID, TerrainTile* > TerrainTileMap;
119 typedef std::set< TerrainTile* > TerrainTileSet;
122 float _verticalScale;
123 TerrainTile::BlendingPolicy _blendingPolicy;
124 bool _equalizeBoundaries;
125 osg::ref_ptr<GeometryPool> _geometryPool;
127 mutable OpenThreads::ReentrantMutex _mutex;
128 TerrainTileSet _terrainTileSet;
129 TerrainTileMap _terrainTileMap;
130 TerrainTileSet _updateTerrainTileSet;
132 osg::ref_ptr<TerrainTechnique> _terrainTechnique;