OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Geometry.h
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 
27 namespace osg {
28 
29 
31 {
32  public:
33 
34  Geometry();
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 
54  void setNormalArray(Array* array, osg::Array::Binding binding);
55  Array* getNormalArray() { return _normalArray.get(); }
56  const Array* getNormalArray() const { return _normalArray.get(); }
57 
58 
59 
61  void setColorArray(Array* array, osg::Array::Binding binding);
62  Array* getColorArray() { return _colorArray.get(); }
63  const Array* getColorArray() const { return _colorArray.get(); }
64 
65 
66 
68  void setSecondaryColorArray(Array* array, osg::Array::Binding binding);
69  Array* getSecondaryColorArray() { return _secondaryColorArray.get(); }
70  const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); }
71 
72 
74  void setFogCoordArray(Array* array, osg::Array::Binding binding);
75  Array* getFogCoordArray() { return _fogCoordArray.get(); }
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);
86  ArrayList& getTexCoordArrayList() { return _texCoordList; }
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);
97  ArrayList& getVertexAttribArrayList() { return _vertexAttribList; }
98  const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; }
99 
100 
101 
102  typedef std::vector< ref_ptr<PrimitiveSet> > PrimitiveSetList;
103 
104  void setPrimitiveSetList(const PrimitiveSetList& primitives);
105 
106  PrimitiveSetList& getPrimitiveSetList() { return _primitives; }
107  const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; }
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 
133  bool containsSharedArrays() const;
134 
136  void duplicateSharedArrays();
137 
138 
141  virtual void setUseVertexBufferObjects(bool flag);
142 
144  virtual void dirtyDisplayList();
145 
146 
148  virtual void resizeGLObjectBuffers(unsigned int maxSize);
149 
153  virtual void releaseGLObjects(State* state=0) const;
154 
155  bool getArrayList(ArrayList& arrayList) const;
156 
157  typedef std::vector<osg::DrawElements*> DrawElementsList;
158  bool getDrawElementsList(DrawElementsList& drawElementsList) const;
159 
160  osg::VertexBufferObject* getOrCreateVertexBufferObject();
161  osg::ElementBufferObject* getOrCreateElementBufferObject();
162 
163 
166  virtual unsigned int getGLObjectSizeHint() const;
167 
171  virtual void compileGLObjects(RenderInfo& renderInfo) const;
172 
177  virtual void drawImplementation(RenderInfo& renderInfo) const;
178 
180  void drawVertexArraysImplementation(RenderInfo& renderInfo) const;
181 
183  void drawPrimitivesImplementation(RenderInfo& renderInfo) const;
184 
186  virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
187 
189  virtual void accept(Drawable::AttributeFunctor& af);
190 
192  virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
193 
195  virtual void accept(Drawable::ConstAttributeFunctor& af) const;
196 
198  virtual bool supports(const PrimitiveFunctor&) const { return true; }
199 
201  virtual void accept(PrimitiveFunctor& pf) const;
202 
204  virtual bool supports(const PrimitiveIndexFunctor&) const { return true; }
205 
207  virtual void accept(PrimitiveIndexFunctor& pf) const;
208 
209 
210  protected:
211 
212  Geometry& operator = (const Geometry&) { return *this;}
213 
214  virtual ~Geometry();
215 
216 
217  void addVertexBufferObjectIfRequired(osg::Array* array);
218  void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
219 
220 
221  PrimitiveSetList _primitives;
227  ArrayList _texCoordList;
228  ArrayList _vertexAttribList;
229 
231 
232  public:
233 
234 
236  bool containsDeprecatedData() const { return _containsDeprecatedData; }
237 
239  bool checkForDeprecatedData();
240 
242  void fixDeprecatedData();
243 
244 #if defined(OSG_DEPRECATED_GEOMETRY_BINDING)
245 
247  {
248  BIND_OFF=0,
249  BIND_OVERALL=1,
250  BIND_PER_PRIMITIVE_SET=2,
251  BIND_PER_VERTEX=4
252  };
253 
255  void setNormalBinding(AttributeBinding ab);
256  void setColorBinding(AttributeBinding ab);
257  void setSecondaryColorBinding(AttributeBinding ab);
258  void setFogCoordBinding(AttributeBinding ab);
259  void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
260 
262  AttributeBinding getNormalBinding() const;
263  AttributeBinding getColorBinding() const;
264  AttributeBinding getSecondaryColorBinding() const;
265  AttributeBinding getFogCoordBinding() const;
266  AttributeBinding getVertexAttribBinding(unsigned int index) const;
267 
269  void setVertexAttribNormalize(unsigned int index,GLboolean norm);
270 
272  GLboolean getVertexAttribNormalize(unsigned int index) const;
273 #endif
274 };
275 
279 extern OSG_EXPORT Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float l, float b, float r, float t);
280 
284 inline Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float s=1.0f, float t=1.0f)
285 {
286  return createTexturedQuadGeometry(corner,widthVec,heightVec, 0.0f, 0.0f, s, t);
287 }
288 
289 } // namespace osg
290 
291 
292 
294 namespace deprecated_osg {
295 
302 {
303  public:
305  Geometry(const Geometry& geometry,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Geometry(geometry, copyop) {}
306 
309  {
310  BIND_OFF=0,
311  BIND_OVERALL=1,
312  BIND_PER_PRIMITIVE_SET=2,
313  BIND_PER_PRIMITIVE=3,
314  BIND_PER_VERTEX=4
315  };
316 
317  void setNormalBinding(AttributeBinding ab);
318  AttributeBinding getNormalBinding() const;
319 
320  void setColorBinding(AttributeBinding ab);
321  AttributeBinding getColorBinding() const;
322 
323  void setSecondaryColorBinding(AttributeBinding ab);
324  AttributeBinding getSecondaryColorBinding() const;
325 
326  void setFogCoordBinding(AttributeBinding ab);
327  AttributeBinding getFogCoordBinding() const;
328 
329  void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
330  AttributeBinding getVertexAttribBinding(unsigned int index) const;
331 
332  void setVertexAttribNormalize(unsigned int index,GLboolean norm);
333  GLboolean getVertexAttribNormalize(unsigned int index) const;
334 
335  void setVertexIndices(osg::IndexArray* array);
336  const osg::IndexArray* getVertexIndices() const;
337 
338  void setNormalIndices(osg::IndexArray* array);
339  const osg::IndexArray* getNormalIndices() const;
340 
341  void setColorIndices(osg::IndexArray* array);
342  const osg::IndexArray* getColorIndices() const;
343 
344  void setSecondaryColorIndices(osg::IndexArray* array);
345  const osg::IndexArray* getSecondaryColorIndices() const;
346 
347  void setFogCoordIndices(osg::IndexArray* array);
348  const osg::IndexArray* getFogCoordIndices() const;
349 
350  void setTexCoordIndices(unsigned int unit,osg::IndexArray* array);
351  const osg::IndexArray* getTexCoordIndices(unsigned int unit) const;
352 
353  void setVertexAttribIndices(unsigned int index,osg::IndexArray* array);
354  const osg::IndexArray* getVertexAttribIndices(unsigned int index) const;
355 
356 };
357 
358 } // namespace deprecated_osg
359 
360 #endif
std::vector< ref_ptr< PrimitiveSet > > PrimitiveSetList
Definition: Geometry.h:102
#define OSG_EXPORT
Definition: Export.h:43
ArrayList & getTexCoordArrayList()
Definition: Geometry.h:86
OSG_EXPORT Geometry * createTexturedQuadGeometry(const Vec3 &corner, const Vec3 &widthVec, const Vec3 &heightVec, float l, float b, float r, float t)
virtual const Geometry * asGeometry() const
Definition: Geometry.h:42
unsigned int getNumTexCoordArrays() const
Definition: Geometry.h:84
osg::ref_ptr< Array > _fogCoordArray
Definition: Geometry.h:226
virtual bool supports(const Drawable::AttributeFunctor &) const
Definition: Geometry.h:186
const ArrayList & getVertexAttribArrayList() const
Definition: Geometry.h:98
Array * getSecondaryColorArray()
Definition: Geometry.h:69
void setFogCoordArray(Array *array)
Definition: Geometry.h:73
void setNormalArray(Array *array)
Definition: Geometry.h:53
PrimitiveSet * getPrimitiveSet(unsigned int pos)
Definition: Geometry.h:110
#define META_Node(library, name)
Definition: Node.h:59
virtual bool supports(const PrimitiveFunctor &) const
Definition: Geometry.h:198
osg::ref_ptr< Array > _vertexArray
Definition: Geometry.h:222
const Array * getNormalArray() const
Definition: Geometry.h:56
Array * getNormalArray()
Definition: Geometry.h:55
osg::ref_ptr< Array > _secondaryColorArray
Definition: Geometry.h:225
virtual bool supports(const Drawable::ConstAttributeFunctor &) const
Definition: Geometry.h:192
Geometry(const Geometry &geometry, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Geometry.h:305
const PrimitiveSetList & getPrimitiveSetList() const
Definition: Geometry.h:107
const Array * getVertexArray() const
Definition: Geometry.h:50
Array * getColorArray()
Definition: Geometry.h:62
osg::ref_ptr< Array > _normalArray
Definition: Geometry.h:223
Vec3f Vec3
Definition: Vec3.h:21
bool _containsDeprecatedData
Definition: Geometry.h:230
unsigned int getNumVertexAttribArrays() const
Definition: Geometry.h:95
void setSecondaryColorArray(Array *array)
Definition: Geometry.h:67
PrimitiveSetList & getPrimitiveSetList()
Definition: Geometry.h:106
const ArrayList & getTexCoordArrayList() const
Definition: Geometry.h:87
virtual Geometry * asGeometry()
Definition: Geometry.h:41
const Array * getFogCoordArray() const
Definition: Geometry.h:76
const Array * getSecondaryColorArray() const
Definition: Geometry.h:70
const PrimitiveSet * getPrimitiveSet(unsigned int pos) const
Definition: Geometry.h:111
ArrayList _texCoordList
Definition: Geometry.h:227
osg::ref_ptr< Array > _colorArray
Definition: Geometry.h:224
virtual bool supports(const PrimitiveIndexFunctor &) const
Definition: Geometry.h:204
unsigned int getNumPrimitiveSets() const
Definition: Geometry.h:109
const Array * getColorArray() const
Definition: Geometry.h:63
void setVertexAttribArray(unsigned int index, Array *array)
Definition: Geometry.h:89
void setColorArray(Array *array)
Definition: Geometry.h:60
Definition: AlphaFunc.h:19
ArrayList & getVertexAttribArrayList()
Definition: Geometry.h:97
std::vector< osg::DrawElements * > DrawElementsList
Definition: Geometry.h:157
PrimitiveSetList _primitives
Definition: Geometry.h:221
Array * getVertexArray()
Definition: Geometry.h:49
bool containsDeprecatedData() const
Definition: Geometry.h:236
void setTexCoordArray(unsigned int unit, Array *array)
Definition: Geometry.h:79
std::vector< osg::ref_ptr< osg::Array > > ArrayList
Definition: Geometry.h:46
Array * getFogCoordArray()
Definition: Geometry.h:75
ArrayList _vertexAttribList
Definition: Geometry.h:228