| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 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. |
|---|
| 7 | * |
|---|
| 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. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGTerrain |
|---|
| 15 | #define OSGTerrain 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/CoordinateSystemNode> |
|---|
| 18 | #include <OpenThreads/ReentrantMutex> |
|---|
| 19 | |
|---|
| 20 | #include <osgTerrain/TerrainTile> |
|---|
| 21 | |
|---|
| 22 | namespace osgTerrain { |
|---|
| 23 | |
|---|
| 24 | /** Terrain provides a framework for loosely coupling height field data with height rendering algorithms. |
|---|
| 25 | * This allows TerrainTechniques to be plugged in at runtime.*/ |
|---|
| 26 | class OSGTERRAIN_EXPORT Terrain : public osg::CoordinateSystemNode |
|---|
| 27 | { |
|---|
| 28 | public: |
|---|
| 29 | |
|---|
| 30 | Terrain(); |
|---|
| 31 | |
|---|
| 32 | /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ |
|---|
| 33 | Terrain(const Terrain&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 34 | |
|---|
| 35 | META_Node(osgTerrain, Terrain); |
|---|
| 36 | |
|---|
| 37 | virtual void traverse(osg::NodeVisitor& nv); |
|---|
| 38 | |
|---|
| 39 | virtual osgTerrain::Terrain* asTerrain() { return this; } |
|---|
| 40 | virtual const osgTerrain::Terrain* asTerrain() const { return this; } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | /** Set the sample ratio hint that TerrainTile should use when building geometry. |
|---|
| 44 | * Defaults to 1.0, which means use all original sample points.*/ |
|---|
| 45 | void setSampleRatio(float ratio); |
|---|
| 46 | |
|---|
| 47 | /** Get the sample ratio hint.*/ |
|---|
| 48 | float getSampleRatio() const { return _sampleRatio; } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | /** Set the vertical scale hint.*/ |
|---|
| 52 | void setVerticalScale(float scale); |
|---|
| 53 | |
|---|
| 54 | /** Get the vertical scale hint.*/ |
|---|
| 55 | float getVerticalScale() const { return _verticalScale; } |
|---|
| 56 | |
|---|
| 57 | /** If set to true the boundaries between adjacent tiles should be equalized. |
|---|
| 58 | * Note, it is only possible to equalizae boundaries when the TerrainTile's contain properly assigned TileID's, |
|---|
| 59 | * databases built with VirtualPlanetBuilder-0.9.11 and older do not set the TileID, so databases must be |
|---|
| 60 | * built with later versions of VirtualPlanetBuilder to take advantage of boundary equalization. */ |
|---|
| 61 | void setEqualizeBoundaries(bool equalizeBoundaries); |
|---|
| 62 | |
|---|
| 63 | /** If true the boundaries between adjacent tiles will be equalized. */ |
|---|
| 64 | bool getEqualizeBoundaries() const { return _equalizeBoundaries; } |
|---|
| 65 | |
|---|
| 66 | /** Set the default policy to use when deciding whether to enable/disable blending and use of transparent bin. |
|---|
| 67 | * Note, the Terrain::BlendingPolicy value only sets the value for the TerrainTiles it encloses for the |
|---|
| 68 | * TerrainTile's that have their policy set to INHERIT. INHERIT is the default BlendingPolicy for both |
|---|
| 69 | * Terrain and TerrainTile, and if both are left to INERHIT then the policy used is ENABLE_BLENDING_WHEN_ALPHA_PRESENT. */ |
|---|
| 70 | void setBlendingPolicy(TerrainTile::BlendingPolicy policy); |
|---|
| 71 | |
|---|
| 72 | /** Get the default policy to use when deciding whether to enable/disable blending and use of transparent bin.*/ |
|---|
| 73 | TerrainTile::BlendingPolicy getBlendingPolicy() const { return _blendingPolicy; } |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | /** Get the TerrainTile for a given TileID.*/ |
|---|
| 77 | TerrainTile* getTile(const TileID& tileID); |
|---|
| 78 | |
|---|
| 79 | /** Get the const TerrainTile for a given TileID.*/ |
|---|
| 80 | const TerrainTile* getTile(const TileID& tileID) const; |
|---|
| 81 | |
|---|
| 82 | /** Set the TerrainTechnique prototype from which TerrainTiles can clone the techniques from.*/ |
|---|
| 83 | void setTerrainTechniquePrototype(TerrainTechnique* technique) { _terrainTechnique = technique; } |
|---|
| 84 | |
|---|
| 85 | /** Get the TerrainTechnique prototype */ |
|---|
| 86 | TerrainTechnique* getTerrainTechniquePrototype() { return _terrainTechnique.get(); } |
|---|
| 87 | |
|---|
| 88 | /** Get the const TerrainTechnique protype*/ |
|---|
| 89 | const TerrainTechnique* getTerrainTechniquePrototype() const { return _terrainTechnique.get(); } |
|---|
| 90 | |
|---|
| 91 | /** Tell the Terrain node to call the terrainTile's TerrainTechnique on the next update traversal.*/ |
|---|
| 92 | void updateTerrainTileOnNextFrame(TerrainTile* terrainTile); |
|---|
| 93 | |
|---|
| 94 | protected: |
|---|
| 95 | |
|---|
| 96 | virtual ~Terrain(); |
|---|
| 97 | |
|---|
| 98 | friend class TerrainTile; |
|---|
| 99 | |
|---|
| 100 | void dirtyRegisteredTiles(int dirtyMask = TerrainTile::ALL_DIRTY); |
|---|
| 101 | |
|---|
| 102 | void registerTerrainTile(TerrainTile* tile); |
|---|
| 103 | void unregisterTerrainTile(TerrainTile* tile); |
|---|
| 104 | |
|---|
| 105 | typedef std::map< TileID, TerrainTile* > TerrainTileMap; |
|---|
| 106 | typedef std::set< TerrainTile* > TerrainTileSet; |
|---|
| 107 | |
|---|
| 108 | float _sampleRatio; |
|---|
| 109 | float _verticalScale; |
|---|
| 110 | TerrainTile::BlendingPolicy _blendingPolicy; |
|---|
| 111 | bool _equalizeBoundaries; |
|---|
| 112 | |
|---|
| 113 | mutable OpenThreads::ReentrantMutex _mutex; |
|---|
| 114 | TerrainTileSet _terrainTileSet; |
|---|
| 115 | TerrainTileMap _terrainTileMap; |
|---|
| 116 | TerrainTileSet _updateTerrainTileSet; |
|---|
| 117 | |
|---|
| 118 | osg::ref_ptr<TerrainTechnique> _terrainTechnique; |
|---|
| 119 | }; |
|---|
| 120 | |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | #endif |
|---|