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