Terrain 5.7 KB

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