OpenSceneGraph 3.6.5
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; }
42 const osg::Array* getVertexArray() const { return _vertexArray.get(); }
43
44 void setNormalArray(osg::Array* array) { _normalArray = array; }
46 const osg::Array* getNormalArray() const { return _normalArray.get(); }
47
48 void setColorArray(osg::Array* array) { _colorArray = array; }
50 const osg::Array* getColorArray() const { return _colorArray.get(); }
51
52 void setTexCoordArray(osg::Array* array) { _texcoordArray = array; }
54 const osg::Array* getTexCoordArray() const { return _texcoordArray.get(); }
55
58 const osg::DrawElements* getDrawElements() const { return _drawElements.get(); }
59
60
61 typedef std::vector<unsigned int> VertexToHeightFieldMapping;
62
64
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
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
164 OpenThreads::Mutex _geometryMapMutex;
166
167 OpenThreads::Mutex _programMapMutex;
169
172};
173
174
176{
177 public:
179
181
183
186 const osg::HeightField* getHeightField() const { return _heightField.get(); }
187
188 void setGeometry(SharedGeometry* geom) { _geometry = geom; }
190 const SharedGeometry* getGeometry() const { return _geometry.get(); }
191
192 void setVertices(osg::Vec3Array* vertices) { _vertices = vertices; }
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
TemplateArray< Vec3, Array::Vec3ArrayType, 3, GL_FLOAT > Vec3Array
Definition Array:449
The osgTerrain library is a NodeKit that provides geospecifc terrain rendering support.
Definition Node:29
OSGTERRAIN_EXPORT const osgTerrain::Locator * computeMasterLocator(const osgTerrain::TerrainTile *tile)
Definition Array:61
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Pure virtual base class for drawable geometry.
Definition Drawable:89
Definition Drawable:426
A PrimitiveFunctor is used (in conjunction with osg::Drawable::accept (PrimitiveFunctor&)) to get acc...
Definition PrimitiveSet:54
Definition PrimitiveSet:103
Definition PrimitiveSet:337
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
Definition RenderInfo:28
Definition Shape:483
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
Definition VertexArrayState:25
Definition GeometryPool:32
osg::Array * getColorArray()
Definition GeometryPool:49
virtual bool supports(const osg::PrimitiveIndexFunctor &) const
Return true if the Drawable subclass supports accept(PrimitiveIndexFunctor&).
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
Accept an AttributeFunctor and call its methods to tell it about the internal attributes that this Dr...
void setColorArray(osg::Array *array)
Definition GeometryPool:48
osg::VertexArrayState * createVertexArrayStateImplementation(osg::RenderInfo &renderInfo) const
Implementation of Create the VertexArrayState object.
std::vector< unsigned int > VertexToHeightFieldMapping
Definition GeometryPool:61
void releaseGLObjects(osg::State *state) const
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
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)
Resize any per context GLObject buffers to specified size.
virtual bool supports(const osg::PrimitiveFunctor &) const
Return true if the Drawable subclass supports accept(PrimitiveFunctor&).
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
drawImplementation(RenderInfo&) is a pure virtual method for the actual implementation of OpenGL draw...
void setDrawElements(osg::DrawElements *array)
Definition GeometryPool:56
virtual bool supports(const osg::Drawable::ConstAttributeFunctor &) const
Return true if the Drawable subclass supports accept(ConstAttributeFunctor&).
Definition GeometryPool:81
META_Node(osgTerrain, SharedGeometry)
virtual void accept(osg::PrimitiveIndexFunctor &) const
Accept a PrimitiveIndexFunctor and call its methods to tell it about the internal primitives that thi...
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
Return true if the Drawable subclass supports accept(AttributeFunctor&).
Definition GeometryPool:78
virtual void accept(osg::PrimitiveFunctor &) const
Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Dra...
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 &)
accept an AttributeFunctor and call its methods to tell it about the internal attributes that this Dr...
osg::DrawElements * getDrawElements()
Definition GeometryPool:57
void compileGLObjects(osg::RenderInfo &renderInfo) const
Immediately compile this Drawable into an OpenGL Display List/VertexBufferObjects.
VertexToHeightFieldMapping & getVertexToHeightFieldMapping()
Definition GeometryPool:65
osg::ref_ptr< osg::Array > _texcoordArray
Definition GeometryPool:97
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
@ CONTOUR_LAYER
Definition GeometryPool:145
OpenThreads::Mutex _programMapMutex
Definition GeometryPool:167
GeometryMap _geometryMap
Definition GeometryPool:165
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
virtual void accept(osg::Drawable::ConstAttributeFunctor &) const
Accept an AttributeFunctor and call its methods to tell it about the internal attributes that this Dr...
SharedGeometry * getGeometry()
Definition GeometryPool:189
virtual void accept(osg::PrimitiveFunctor &) const
Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Dra...
void setHeightField(osg::HeightField *hf)
Definition GeometryPool:184
const osg::Vec3Array * getVertices() const
Definition GeometryPool:194
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
drawImplementation(RenderInfo&) is a pure virtual method for the actual implementation of OpenGL draw...
osg::ref_ptr< osg::Vec3Array > _vertices
Definition GeometryPool:220
osg::Vec3Array * getVertices()
Definition GeometryPool:193
virtual bool supports(const osg::Drawable::ConstAttributeFunctor &) const
Return true if the Drawable subclass supports accept(ConstAttributeFunctor&).
Definition GeometryPool:205
const SharedGeometry * getGeometry() const
Definition GeometryPool:190
META_Node(osgTerrain, HeightFieldDrawable)
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
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
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
osg::HeightField * getHeightField()
Definition GeometryPool:185
virtual bool supports(const osg::PrimitiveIndexFunctor &) const
Return true if the Drawable subclass supports accept(PrimitiveIndexFunctor&).
Definition GeometryPool:211
osg::ref_ptr< SharedGeometry > _geometry
Definition GeometryPool:219
virtual bool supports(const osg::PrimitiveFunctor &) const
Return true if the Drawable subclass supports accept(PrimitiveFunctor&).
Definition GeometryPool:208
virtual bool supports(const osg::Drawable::AttributeFunctor &) const
Return true if the Drawable subclass supports accept(AttributeFunctor&).
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
Immediately compile this Drawable into an OpenGL Display List/VertexBufferObjects.
virtual void accept(osg::Drawable::AttributeFunctor &)
accept an AttributeFunctor and call its methods to tell it about the internal attributes that this Dr...
virtual void accept(osg::PrimitiveIndexFunctor &) const
Accept a PrimitiveIndexFunctor and call its methods to tell it about the internal primitives that thi...
void setGeometry(SharedGeometry *geom)
Definition GeometryPool:188
Definition Locator:26
Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
Definition Terrain:28
Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
Definition TerrainTile:68
#define OSGTERRAIN_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.