OpenSceneGraph 3.6.5
Geometry
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 OSG_GEOMETRY
15#define OSG_GEOMETRY 1
16
17#include <osg/Drawable>
18#include <osg/Vec2>
19#include <osg/Vec3>
20#include <osg/Vec4>
21#include <osg/Array>
22#include <osg/PrimitiveSet>
23
24// leave defined for OpenSceneGraph-3.2 release, post 3.2 associated methods will be only be available in deprecated_osg::Geometry
25#define OSG_DEPRECATED_GEOMETRY_BINDING 1
26
27namespace osg {
28
29
31{
32 public:
33
35
37 Geometry(const Geometry& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
38
40
41 virtual Geometry* asGeometry() { return this; }
42 virtual const Geometry* asGeometry() const { return this; }
43
44 bool empty() const;
45
46 typedef std::vector< osg::ref_ptr<osg::Array> > ArrayList;
47
48 void setVertexArray(Array* array);
49 Array* getVertexArray() { return _vertexArray.get(); }
50 const Array* getVertexArray() const { return _vertexArray.get(); }
51
52
55 Array* getNormalArray() { return _normalArray.get(); }
56 const Array* getNormalArray() const { return _normalArray.get(); }
57
58
59
62 Array* getColorArray() { return _colorArray.get(); }
63 const Array* getColorArray() const { return _colorArray.get(); }
64
65
66
70 const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); }
71
72
76 const Array* getFogCoordArray() const { return _fogCoordArray.get(); }
77
78
79 void setTexCoordArray(unsigned int unit, Array* array) { setTexCoordArray(unit, array, osg::Array::BIND_UNDEFINED); }
80 void setTexCoordArray(unsigned int unit, Array* array, osg::Array::Binding binding);
81 Array* getTexCoordArray(unsigned int unit);
82 const Array* getTexCoordArray(unsigned int unit) const;
83
84 unsigned int getNumTexCoordArrays() const { return static_cast<unsigned int>(_texCoordList.size()); }
85 void setTexCoordArrayList(const ArrayList& arrrayList);
87 const ArrayList& getTexCoordArrayList() const { return _texCoordList; }
88
89 void setVertexAttribArray(unsigned int index, Array* array) { setVertexAttribArray(index, array, osg::Array::BIND_UNDEFINED); }
90 void setVertexAttribArray(unsigned int index, Array* array, osg::Array::Binding binding);
91 Array *getVertexAttribArray(unsigned int index);
92 const Array *getVertexAttribArray(unsigned int index) const;
93
94
95 unsigned int getNumVertexAttribArrays() const { return static_cast<unsigned int>(_vertexAttribList.size()); }
96 void setVertexAttribArrayList(const ArrayList& arrayList);
99
100
101
102 typedef std::vector< ref_ptr<PrimitiveSet> > PrimitiveSetList;
103
104 void setPrimitiveSetList(const PrimitiveSetList& primitives);
105
108
109 unsigned int getNumPrimitiveSets() const { return static_cast<unsigned int>(_primitives.size()); }
110 PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); }
111 const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); }
112
114 bool addPrimitiveSet(PrimitiveSet* primitiveset);
115
117 bool setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
118
120 bool insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
121
123 bool removePrimitiveSet(unsigned int i,unsigned int numElementsToRemove=1);
124
129 unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const;
130
131
134
137
140
141
144 virtual void setUseVertexBufferObjects(bool flag);
145
147 virtual void dirtyGLObjects();
148
149
151 virtual void resizeGLObjectBuffers(unsigned int maxSize);
152
156 virtual void releaseGLObjects(State* state=0) const;
157
158 bool getArrayList(ArrayList& arrayList) const;
159
160 typedef std::vector<osg::DrawElements*> DrawElementsList;
161 bool getDrawElementsList(DrawElementsList& drawElementsList) const;
162
165
166
169 virtual unsigned int getGLObjectSizeHint() const;
170
174 virtual void compileGLObjects(RenderInfo& renderInfo) const;
175
180 virtual void drawImplementation(RenderInfo& renderInfo) const;
181
182
185
188
189
191 virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
192
195
197 virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
198
201
203 virtual bool supports(const PrimitiveFunctor&) const { return true; }
204
206 virtual void accept(PrimitiveFunctor& pf) const;
207
209 virtual bool supports(const PrimitiveIndexFunctor&) const { return true; }
210
212 virtual void accept(PrimitiveIndexFunctor& pf) const;
213
214
215 protected:
216
217 Geometry& operator = (const Geometry&) { return *this;}
218
219 virtual ~Geometry();
220
221
224
233
235
237
238 public:
239
240
243
246
249
250#if defined(OSG_DEPRECATED_GEOMETRY_BINDING)
259
265 void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
266
272 AttributeBinding getVertexAttribBinding(unsigned int index) const;
273
275 void setVertexAttribNormalize(unsigned int index,GLboolean norm);
276
278 GLboolean getVertexAttribNormalize(unsigned int index) const;
279#endif
280};
281
294
295
296
300extern OSG_EXPORT Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float l, float b, float r, float t);
301
305inline Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float s=1.0f, float t=1.0f)
306{
307 return createTexturedQuadGeometry(corner,widthVec,heightVec, 0.0f, 0.0f, s, t);
308}
309
310} // namespace osg
311
312#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec3f Vec3
Definition Vec3:21
OSG_EXPORT Geometry * createTexturedQuadGeometry(const Vec3 &corner, const Vec3 &widthVec, const Vec3 &heightVec, float l, float b, float r, float t)
Convenience function to be used for creating quad geometry with texture coords.
Definition Array:61
Binding
The scope of applicability of the values in this array.
Definition Array:130
@ BIND_UNDEFINED
Definition Array:131
Definition BufferObject:599
Definition BufferObject:622
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
Definition Drawable:426
Definition Geometry:31
osg::ref_ptr< Array > _fogCoordArray
Definition Geometry:230
META_Node(osg, Geometry)
Array * getVertexArray()
Definition Geometry:49
virtual void accept(Drawable::AttributeFunctor &af)
Accept an Drawable::AttributeFunctor and call its methods to tell it about the internal attributes th...
const PrimitiveSet * getPrimitiveSet(unsigned int pos) const
Definition Geometry:111
const PrimitiveSetList & getPrimitiveSetList() const
Definition Geometry:107
Array * getSecondaryColorArray()
Definition Geometry:69
virtual unsigned int getGLObjectSizeHint() const
Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with...
virtual const Geometry * asGeometry() const
convert 'const this' into a const Geometry pointer if Node is a Geometry, otherwise return 0.
Definition Geometry:42
const Array * getTexCoordArray(unsigned int unit) const
void setNormalArray(Array *array)
Definition Geometry:53
PrimitiveSetList _primitives
Definition Geometry:225
void setTexCoordArray(unsigned int unit, Array *array, osg::Array::Binding binding)
void setVertexAttribArray(unsigned int index, Array *array, osg::Array::Binding binding)
void setFogCoordArray(Array *array)
Definition Geometry:73
unsigned int getPrimitiveSetIndex(const PrimitiveSet *primitiveset) const
Get the index number of a primitive set, return a value between 0 and getNumPrimitiveSet()-1 if found...
osg::ref_ptr< Array > _normalArray
Definition Geometry:227
virtual void dirtyGLObjects()
Force a recompile on next draw() of any OpenGL objects associated with this geoset.
bool _containsDeprecatedData
Definition Geometry:234
PrimitiveSet * getPrimitiveSet(unsigned int pos)
Definition Geometry:110
void setPrimitiveSetList(const PrimitiveSetList &primitives)
void setColorArray(Array *array)
Definition Geometry:60
void setTexCoordArray(unsigned int unit, Array *array)
Definition Geometry:79
void drawVertexArraysImplementation(RenderInfo &renderInfo) const
Set up the vertex arrays for the purpose of rendering, called by drawImplemtation() prior to it calli...
osg::ref_ptr< Array > _vertexArray
Definition Geometry:226
const Array * getColorArray() const
Definition Geometry:63
unsigned int getNumTexCoordArrays() const
Definition Geometry:84
virtual Geometry * asGeometry()
convert 'this' into a Geometry pointer if Node is a Geometry, otherwise return 0.
Definition Geometry:41
const Array * getFogCoordArray() const
Definition Geometry:76
virtual void drawImplementation(RenderInfo &renderInfo) const
Draw Geometry directly ignoring an OpenGL display list which could be attached.
Array * getVertexAttribArray(unsigned int index)
std::vector< osg::DrawElements * > DrawElementsList
Definition Geometry:160
void setSecondaryColorArray(Array *array)
Definition Geometry:67
virtual void releaseGLObjects(State *state=0) const
If State is non-zero, this function releases OpenGL objects for the specified graphics context.
void setVertexAttribNormalize(unsigned int index, GLboolean norm)
deprecated, use array->set*Normalize(..).
void setColorArray(Array *array, osg::Array::Binding binding)
osg::VertexBufferObject * getOrCreateVertexBufferObject()
const ArrayList & getVertexAttribArrayList() const
Definition Geometry:98
void setNormalBinding(AttributeBinding ab)
deprecated, use array->set*Binding(..).
void addElementBufferObjectIfRequired(osg::PrimitiveSet *primitiveSet)
PrimitiveSetList & getPrimitiveSetList()
Definition Geometry:106
virtual bool supports(const PrimitiveFunctor &) const
Return true, osg::Geometry does support accept(PrimitiveFunctor&).
Definition Geometry:203
void setVertexAttribArray(unsigned int index, Array *array)
Definition Geometry:89
const Array * getVertexArray() const
Definition Geometry:50
ArrayList & getTexCoordArrayList()
Definition Geometry:86
bool addPrimitiveSet(PrimitiveSet *primitiveset)
Add a primitive set to the geometry.
ArrayList _vertexAttribList
Definition Geometry:232
void setTexCoordArrayList(const ArrayList &arrrayList)
const Array * getSecondaryColorArray() const
Definition Geometry:70
bool getDrawElementsList(DrawElementsList &drawElementsList) const
AttributeBinding getFogCoordBinding() const
AttributeBinding getColorBinding() const
GLboolean getVertexAttribNormalize(unsigned int index) const
deprecated, use array->get*Normalize(..).
AttributeBinding
deprecated, Same values as Array::Binding.
Definition Geometry:253
@ BIND_PER_VERTEX
Definition Geometry:257
@ BIND_PER_PRIMITIVE_SET
Definition Geometry:256
@ BIND_OFF
Definition Geometry:254
@ BIND_OVERALL
Definition Geometry:255
Array * getNormalArray()
Definition Geometry:55
void setFogCoordBinding(AttributeBinding ab)
virtual void accept(PrimitiveIndexFunctor &pf) const
Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Dra...
bool getArrayList(ArrayList &arrayList) const
virtual void compileGLObjects(RenderInfo &renderInfo) const
Immediately compile this Drawable into an OpenGL Display List/VertexBufferObjects.
std::vector< ref_ptr< PrimitiveSet > > PrimitiveSetList
Definition Geometry:102
virtual void accept(PrimitiveFunctor &pf) const
Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Dra...
AttributeBinding getNormalBinding() const
deprecated, use array->get*Binding(..).
unsigned int getNumPrimitiveSets() const
Definition Geometry:109
bool checkForDeprecatedData()
fallback for deprecated functionality.
void duplicateSharedArrays()
duplicate any shared arrays.
virtual bool supports(const Drawable::AttributeFunctor &) const
Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&).
Definition Geometry:191
Array * getFogCoordArray()
Definition Geometry:75
bool insertPrimitiveSet(unsigned int i, PrimitiveSet *primitiveset)
Insert a primitive set to the specified position in geometry's primitive set list.
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
void configureBufferObjects()
Convenience method that checks all the vertex arrays to make sure that the buffer objects are all ass...
osg::ref_ptr< Array > _colorArray
Definition Geometry:228
virtual ~Geometry()
bool empty() const
void setVertexAttribArrayList(const ArrayList &arrayList)
unsigned int getNumVertexAttribArrays() const
Definition Geometry:95
bool containsDeprecatedData() const
Return true if the deprecated use array indices or BIND_PER_PRIMITIVE binding has been assigned to ar...
Definition Geometry:242
virtual void accept(Drawable::ConstAttributeFunctor &af) const
Accept a Drawable::ConstAttributeFunctor and call its methods to tell it about the internal attribute...
ArrayList _texCoordList
Definition Geometry:231
Array * getTexCoordArray(unsigned int unit)
void fixDeprecatedData()
fallback for deprecated functionality.
virtual void setUseVertexBufferObjects(bool flag)
When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation method...
Geometry(const Geometry &geometry, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
Copy constructor using CopyOp to manage deep vs shallow copy.
ArrayList & getVertexAttribArrayList()
Definition Geometry:97
void setVertexAttribBinding(unsigned int index, AttributeBinding ab)
bool removePrimitiveSet(unsigned int i, unsigned int numElementsToRemove=1)
Remove primitive set(s) from the specified position in geometry's primitive set list.
void setVertexArray(Array *array)
const Array * getVertexAttribArray(unsigned int index) const
void setFogCoordArray(Array *array, osg::Array::Binding binding)
void drawPrimitivesImplementation(RenderInfo &renderInfo) const
dispatch the primitives to OpenGL, called by drawImplemtation() after calling drawVertexArraysImpleme...
Array * getColorArray()
Definition Geometry:62
std::vector< osg::ref_ptr< osg::Array > > ArrayList
Definition Geometry:46
void setSecondaryColorArray(Array *array, osg::Array::Binding binding)
void setNormalArray(Array *array, osg::Array::Binding binding)
const ArrayList & getTexCoordArrayList() const
Definition Geometry:87
osg::ElementBufferObject * getOrCreateElementBufferObject()
osg::ref_ptr< Array > _secondaryColorArray
Definition Geometry:229
void addVertexBufferObjectIfRequired(osg::Array *array)
AttributeBinding getVertexAttribBinding(unsigned int index) const
bool containsSharedArrays() const
return true if any arrays are shared.
bool setPrimitiveSet(unsigned int i, PrimitiveSet *primitiveset)
Set a primitive set to the specified position in geometry's primitive set list.
virtual bool supports(const PrimitiveIndexFunctor &) const
Return true, osg::Geometry does support accept(PrimitiveIndexFunctor&).
Definition Geometry:209
virtual bool supports(const Drawable::ConstAttributeFunctor &) const
Return true, osg::Geometry does support accept(Drawable::ConstAttributeFunctor&).
Definition Geometry:197
void setSecondaryColorBinding(AttributeBinding ab)
AttributeBinding getSecondaryColorBinding() const
virtual VertexArrayState * createVertexArrayStateImplementation(RenderInfo &renderInfo) const
Implementation of Create the VertexArrayState object.
const Array * getNormalArray() const
Definition Geometry:56
void setColorBinding(AttributeBinding ab)
ConfigureBufferObjectsVisitor()
Definition Geometry:286
void apply(osg::Geometry &geometry)
Definition Geometry:289
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
@ TRAVERSE_ALL_CHILDREN
Definition NodeVisitor:89
NodeVisitor(TraversalMode tm=TRAVERSE_NONE)
A PrimitiveFunctor is used (in conjunction with osg::Drawable::accept (PrimitiveFunctor&)) to get acc...
Definition PrimitiveSet:54
Definition PrimitiveSet:103
Definition PrimitiveSet:125
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Definition RenderInfo:28
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Definition VertexArrayState:25
#define OSG_EXPORT
Definition Export:39

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