TerrainTechnique 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_TERRAINTECHNIQUE
  14. #define OSGTERRAIN_TERRAINTECHNIQUE 1
  15. #include <osg/Object>
  16. #include <osgUtil/UpdateVisitor>
  17. #include <osgUtil/CullVisitor>
  18. #include <osgTerrain/Export>
  19. namespace osgTerrain {
  20. class TerrainTile;
  21. class OSGTERRAIN_EXPORT TerrainNeighbours
  22. {
  23. public:
  24. TerrainNeighbours();
  25. ~TerrainNeighbours();
  26. void clear();
  27. void addNeighbour(TerrainTile* tile);
  28. void removeNeighbour(TerrainTile* tile);
  29. bool containsNeighbour(TerrainTile* tile) const;
  30. protected:
  31. TerrainNeighbours(const TerrainNeighbours& /*tn*/) {}
  32. TerrainNeighbours& operator = (const TerrainNeighbours& /*rhs*/) { return *this; }
  33. typedef std::set<TerrainTile*> Neighbours;
  34. mutable OpenThreads::Mutex _neighboursMutex;
  35. Neighbours _neighbours;
  36. };
  37. class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object, public osg::Observer
  38. {
  39. public:
  40. TerrainTechnique();
  41. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  42. TerrainTechnique(const TerrainTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  43. META_Object(osgTerrain, TerrainTechnique);
  44. virtual void setTerrainTile(TerrainTile* tile);
  45. TerrainTile* getTerrainTile() { return _terrainTile; }
  46. const TerrainTile* getTerrainTile() const { return _terrainTile; }
  47. virtual void init(int dirtyMask, bool assumeMultiThreaded);
  48. virtual void update(osgUtil::UpdateVisitor* nv);
  49. virtual void cull(osgUtil::CullVisitor* nv);
  50. /** Clean scene graph from any terrain technique specific nodes.*/
  51. virtual void cleanSceneGraph();
  52. /** Traverse the terrain subgraph.*/
  53. virtual void traverse(osg::NodeVisitor& nv);
  54. /** If State is non-zero, this function releases any associated OpenGL objects for
  55. * the specified graphics context. Otherwise, releases OpenGL objects
  56. * for all graphics contexts. */
  57. virtual void releaseGLObjects(osg::State* = 0) const {}
  58. virtual void addNeighbour(TerrainTile* tile) { _neighbours.addNeighbour(tile); }
  59. virtual void removeNeighbour(TerrainTile* tile) { _neighbours.removeNeighbour(tile); }
  60. virtual bool containsNeighbour(TerrainTile* tile) { return _neighbours.containsNeighbour(tile); }
  61. protected:
  62. virtual ~TerrainTechnique();
  63. friend class osgTerrain::TerrainTile;
  64. TerrainTile* _terrainTile;
  65. TerrainNeighbours _neighbours;
  66. };
  67. }
  68. #endif