openscenegraph
GeometryPool
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2014 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_GEOMETRYPOOL
15#define OSGTERRAIN_GEOMETRYPOOL 1
16
17#include <osg/Geometry>
18#include <osg/MatrixTransform>
19#include <osg/Program>
20
21#include <OpenThreads/Mutex>
22
24
25
26namespace osgTerrain {
27
29
30
32{
33 public:
35
37
39
40 void setVertexArray(osg::Array* array) { _vertexArray = array; }
41 osg::Array* getVertexArray() { return _vertexArray.get(); }
42 const osg::Array* getVertexArray() const { return _vertexArray.get(); }
43
44 void setNormalArray(osg::Array* array) { _normalArray = array; }
45 osg::Array* getNormalArray() { return _normalArray.get(); }
46 const osg::Array* getNormalArray() const { return _normalArray.get(); }
47
48 void setColorArray(osg::Array* array) { _colorArray = array; }
49 osg::Array* getColorArray() { return _colorArray.get(); }
50 const osg::Array* getColorArray() const { return _colorArray.get(); }
51
52 void setTexCoordArray(osg::Array* array) { _texcoordArray = array; }
53 osg::Array* getTexCoordArray() { return _texcoordArray.get(); }
54 const osg::Array* getTexCoordArray() const { return _texcoordArray.get(); }
55
56 void setDrawElements(osg::DrawElements* array) { _drawElements = array; }
57 osg::DrawElements* getDrawElements() { return _drawElements.get(); }
58 const osg::DrawElements* getDrawElements() const { return _drawElements.get(); }
59
60
61 typedef std::vector<unsigned int> VertexToHeightFieldMapping;
62
63 void setVertexToHeightFieldMapping(const VertexToHeightFieldMapping& vthfm) { _vertexToHeightFieldMapping = vthfm; }
64
65 VertexToHeightFieldMapping& getVertexToHeightFieldMapping() { return _vertexToHeightFieldMapping; }
66 const VertexToHeightFieldMapping& getVertexToHeightFieldMapping() const { return _vertexToHeightFieldMapping; }
67
68
70
71 void compileGLObjects(osg::RenderInfo& renderInfo) const;
72
73 void drawImplementation(osg::RenderInfo& renderInfo) const;
74
75 void resizeGLObjectBuffers(unsigned int maxSize);
76 void releaseGLObjects(osg::State* state) const;
77
78 virtual bool supports(const osg::Drawable::AttributeFunctor&) const { return true; }
80
81 virtual bool supports(const osg::Drawable::ConstAttributeFunctor&) const { return true; }
83
84 virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
85 virtual void accept(osg::PrimitiveFunctor&) const;
86
87 virtual bool supports(const osg::PrimitiveIndexFunctor&) const { return true; }
88 virtual void accept(osg::PrimitiveIndexFunctor&) const;
89
90protected:
91
92 virtual ~SharedGeometry();
93
99
101};
102
104{
105 public:
107
109 {
110 GeometryKey(): sx(0.0), sy(0.0), y(0.0), nx(0), ny(0) {}
111
112 bool operator < (const GeometryKey& rhs) const
113 {
114 if (sx<rhs.sx) return true;
115 if (sx>rhs.sx) return false;
116
117 if (sx<rhs.sx) return true;
118 if (sx>rhs.sx) return false;
119
120 if (y<rhs.y) return true;
121 if (y>rhs.y) return false;
122
123 if (nx<rhs.nx) return true;
124 if (nx>rhs.nx) return false;
125
126 return (ny<rhs.ny);
127 }
128
129 double sx;
130 double sy;
131 double y;
132
133 int nx;
134 int ny;
135 };
136
137 typedef std::map< GeometryKey, osg::ref_ptr<SharedGeometry> > GeometryMap;
138
139 virtual bool createKeyForTile(TerrainTile* tile, GeometryKey& key);
140
142 {
145 CONTOUR_LAYER
146 };
147
148 typedef std::vector<LayerType> LayerTypes;
149 typedef std::map<LayerTypes, osg::ref_ptr<osg::Program> > ProgramMap;
150
152
154
156
158
159 virtual void applyLayers(osgTerrain::TerrainTile* tile, osg::StateSet* stateset);
160
161 protected:
162 virtual ~GeometryPool();
163
166
169
172};
173
174
176{
177 public:
179
181
183
184 void setHeightField(osg::HeightField* hf) { _heightField = hf; }
185 osg::HeightField* getHeightField() { return _heightField.get(); }
186 const osg::HeightField* getHeightField() const { return _heightField.get(); }
187
188 void setGeometry(SharedGeometry* geom) { _geometry = geom; }
189 SharedGeometry* getGeometry() { return _geometry.get(); }
190 const SharedGeometry* getGeometry() const { return _geometry.get(); }
191
192 void setVertices(osg::Vec3Array* vertices) { _vertices = vertices; }
193 osg::Vec3Array* getVertices() { return _vertices.get(); }
194 const osg::Vec3Array* getVertices() const { return _vertices.get(); }
195
196 virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
197 virtual void compileGLObjects(osg::RenderInfo& renderInfo) const;
198 virtual void resizeGLObjectBuffers(unsigned int maxSize);
199 virtual void releaseGLObjects(osg::State* state=0) const;
200
201
202 virtual bool supports(const osg::Drawable::AttributeFunctor&) const { return true; }
204
205 virtual bool supports(const osg::Drawable::ConstAttributeFunctor&) const { return true; }
207
208 virtual bool supports(const osg::PrimitiveFunctor&) const { return true; }
209 virtual void accept(osg::PrimitiveFunctor&) const;
210
211 virtual bool supports(const osg::PrimitiveIndexFunctor&) const { return true; }
212 virtual void accept(osg::PrimitiveIndexFunctor&) const;
213
214protected:
215
217
221};
222
223
224
225}
226
227#endif
This class provides an object-oriented thread mutex interface.
Definition Mutex:31
Definition GeometryPool:104
ProgramMap _programMap
Definition GeometryPool:168
osg::StateSet * getRootStateSetForTerrain(Terrain *terrain)
std::map< GeometryKey, osg::ref_ptr< SharedGeometry > > GeometryMap
Definition GeometryPool:137
osg::ref_ptr< osg::StateSet > _rootStateSet
Definition GeometryPool:170
std::map< LayerTypes, osg::ref_ptr< osg::Program > > ProgramMap
Definition GeometryPool:149
OpenThreads::Mutex _geometryMapMutex
Definition GeometryPool:164
virtual osg::ref_ptr< osg::MatrixTransform > getTileSubgraph(osgTerrain::TerrainTile *tile)
bool _rootStateSetAssigned
Definition GeometryPool:171
std::vector< LayerType > LayerTypes
Definition GeometryPool:148
virtual bool createKeyForTile(TerrainTile *tile, GeometryKey &key)
virtual osg::ref_ptr< SharedGeometry > getOrCreateGeometry(osgTerrain::TerrainTile *tile)
virtual void applyLayers(osgTerrain::TerrainTile *tile, osg::StateSet *stateset)
virtual osg::ref_ptr< osg::Program > getOrCreateProgram(LayerTypes &layerTypes)
LayerType
Definition GeometryPool:142
@ HEIGHTFIELD_LAYER
Definition GeometryPool:143
@ COLOR_LAYER
Definition GeometryPool:144
OpenThreads::Mutex _programMapMutex
Definition GeometryPool:167
GeometryMap _geometryMap
Definition GeometryPool:165
Definition GeometryPool:176
virtual void accept(osg::Drawable::ConstAttributeFunctor &) const
SharedGeometry * getGeometry()
Definition GeometryPool:189
virtual void accept(osg::PrimitiveFunctor &) const
void setHeightField(osg::HeightField *hf)
Definition GeometryPool:184
const osg::Vec3Array * getVertices() const
Definition GeometryPool:194
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
osg::ref_ptr< osg::Vec3Array > _vertices
Definition GeometryPool:220
osg::Vec3Array * getVertices()
Definition GeometryPool:193
virtual bool supports(const osg::Drawable::ConstAttributeFunctor &) const
Definition GeometryPool:205
const SharedGeometry * getGeometry() const
Definition GeometryPool:190
META_Node(osgTerrain, HeightFieldDrawable)
virtual void resizeGLObjectBuffers(unsigned int maxSize)
const osg::HeightField * getHeightField() const
Definition GeometryPool:186
HeightFieldDrawable(const HeightFieldDrawable &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual void releaseGLObjects(osg::State *state=0) const
osg::HeightField * getHeightField()
Definition GeometryPool:185
virtual bool supports(const osg::PrimitiveIndexFunctor &) const
Definition GeometryPool:211
osg::ref_ptr< SharedGeometry > _geometry
Definition GeometryPool:219
virtual bool supports(const osg::PrimitiveFunctor &) const
Definition GeometryPool:208
virtual bool supports(const osg::Drawable::AttributeFunctor &) const
Definition GeometryPool:202
void setVertices(osg::Vec3Array *vertices)
Definition GeometryPool:192
osg::ref_ptr< osg::HeightField > _heightField
Definition GeometryPool:218
virtual void compileGLObjects(osg::RenderInfo &renderInfo) const
virtual void accept(osg::Drawable::AttributeFunctor &)
virtual void accept(osg::PrimitiveIndexFunctor &) const
void setGeometry(SharedGeometry *geom)
Definition GeometryPool:188
Definition osgTerrain/Locator:26
Definition GeometryPool:32
osg::Array * getColorArray()
Definition GeometryPool:49
virtual bool supports(const osg::PrimitiveIndexFunctor &) const
Definition GeometryPool:87
osg::ref_ptr< osg::Array > _vertexArray
Definition GeometryPool:94
const osg::Array * getTexCoordArray() const
Definition GeometryPool:54
virtual void accept(osg::Drawable::ConstAttributeFunctor &) const
void setColorArray(osg::Array *array)
Definition GeometryPool:48
osg::VertexArrayState * createVertexArrayStateImplementation(osg::RenderInfo &renderInfo) const
std::vector< unsigned int > VertexToHeightFieldMapping
Definition GeometryPool:61
void releaseGLObjects(osg::State *state) const
osg::ref_ptr< osg::Array > _normalArray
Definition GeometryPool:95
void setNormalArray(osg::Array *array)
Definition GeometryPool:44
SharedGeometry(const SharedGeometry &, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
VertexToHeightFieldMapping _vertexToHeightFieldMapping
Definition GeometryPool:100
void resizeGLObjectBuffers(unsigned int maxSize)
virtual bool supports(const osg::PrimitiveFunctor &) const
Definition GeometryPool:84
osg::Array * getVertexArray()
Definition GeometryPool:41
const osg::Array * getColorArray() const
Definition GeometryPool:50
const osg::Array * getVertexArray() const
Definition GeometryPool:42
void setVertexToHeightFieldMapping(const VertexToHeightFieldMapping &vthfm)
Definition GeometryPool:63
void drawImplementation(osg::RenderInfo &renderInfo) const
void setDrawElements(osg::DrawElements *array)
Definition GeometryPool:56
virtual bool supports(const osg::Drawable::ConstAttributeFunctor &) const
Definition GeometryPool:81
META_Node(osgTerrain, SharedGeometry)
virtual void accept(osg::PrimitiveIndexFunctor &) const
osg::Array * getNormalArray()
Definition GeometryPool:45
osg::ref_ptr< osg::DrawElements > _drawElements
Definition GeometryPool:98
void setTexCoordArray(osg::Array *array)
Definition GeometryPool:52
const VertexToHeightFieldMapping & getVertexToHeightFieldMapping() const
Definition GeometryPool:66
osg::ref_ptr< osg::Array > _colorArray
Definition GeometryPool:96
virtual bool supports(const osg::Drawable::AttributeFunctor &) const
Definition GeometryPool:78
virtual void accept(osg::PrimitiveFunctor &) const
void setVertexArray(osg::Array *array)
Definition GeometryPool:40
const osg::Array * getNormalArray() const
Definition GeometryPool:46
osg::Array * getTexCoordArray()
Definition GeometryPool:53
const osg::DrawElements * getDrawElements() const
Definition GeometryPool:58
virtual void accept(osg::Drawable::AttributeFunctor &)
osg::DrawElements * getDrawElements()
Definition GeometryPool:57
void compileGLObjects(osg::RenderInfo &renderInfo) const
VertexToHeightFieldMapping & getVertexToHeightFieldMapping()
Definition GeometryPool:65
osg::ref_ptr< osg::Array > _texcoordArray
Definition GeometryPool:97
Definition TerrainTile:68
Definition Terrain:28
Definition Array:61
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition PrimitiveSet:337
Definition Drawable:426
Definition Drawable:89
Definition Shape:483
Definition PrimitiveSet:54
Definition PrimitiveSet:103
Definition Referenced:44
Definition RenderInfo:28
Definition StateSet:46
Definition State:80
A concrete array holding elements of type T.
Definition Array:243
Definition VertexArrayState:25
Definition ref_ptr:32
Definition Node:29
OSGTERRAIN_EXPORT const osgTerrain::Locator * computeMasterLocator(const osgTerrain::TerrainTile *tile)
#define OSGTERRAIN_EXPORT
Definition osgTerrain/Export:39
Definition GeometryPool:109
double sy
Definition GeometryPool:130
double y
Definition GeometryPool:131
double sx
Definition GeometryPool:129
int ny
Definition GeometryPool:134
int nx
Definition GeometryPool:133
GeometryKey()
Definition GeometryPool:110