fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / Base / OSGGeometry.h
blobcc1d7325c22750b2fe82866fe2dee0352e33620e
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGGEOMETRY_H_
40 #define _OSGGEOMETRY_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include <string>
47 #include "OSGGeometryBase.h"
49 #include "OSGGeoVectorProperty.h"
50 #include "OSGGeoIntegralProperty.h"
51 #include "OSGWindow.h"
53 #include "OSGShaderAttribute.h"
55 OSG_BEGIN_NAMESPACE
57 class GeoPumpGroup;
58 class GeoInstancer;
60 class TriangleIterator;
61 class PrimitiveIterator;
62 class FaceIterator;
63 class LineIterator;
64 class EdgeIterator;
65 class PointIterator;
67 class DrawEnv;
69 /*! \brief Geometry class. See \ref
70 PageDrawableGeometry for a description.
71 \ingroup GrpDrawablesGeometryObj
72 \ingroup GrpLibOSGDrawables
73 \includebasedoc
76 class OSG_DRAWABLE_DLLMAPPING Geometry : public GeometryBase
78 private:
80 /*========================== PUBLIC =================================*/
82 public:
84 typedef GeometryBase Inherited;
86 /*---------------------------------------------------------------------*/
87 /*! \name Simplification Constants */
88 /*! \{ */
90 // Maximum number of possible attributes
91 static const UInt16 MaxAttribs = 16;
93 /*! \} */
94 /*---------------------------------------------------------------------*/
95 /*! \name IndexMapping Constants
96 These are the constants used for mapping the excpliit get/set functions
97 to the generic attribute data buffers used by OpenGL.
99 /*! \{ */
101 static const UInt16 PositionsIndex = 0;
102 static const UInt16 NormalsIndex = 2;
103 static const UInt16 ColorsIndex = 3;
104 static const UInt16 SecondaryColorsIndex = 4;
105 static const UInt16 TexCoordsIndex = 8;
106 static const UInt16 TexCoords1Index = 9;
107 static const UInt16 TexCoords2Index = 10;
108 static const UInt16 TexCoords3Index = 11;
109 static const UInt16 TexCoords4Index = 12;
110 static const UInt16 TexCoords5Index = 13;
111 static const UInt16 TexCoords6Index = 14;
112 static const UInt16 TexCoords7Index = 15;
114 static const UInt16 Attribute0Index = ShaderConstants::Attribute0Index;
115 static const UInt16 Attribute1Index = ShaderConstants::Attribute1Index;
116 static const UInt16 Attribute2Index = ShaderConstants::Attribute2Index;
117 static const UInt16 Attribute3Index = ShaderConstants::Attribute3Index;
118 static const UInt16 Attribute4Index = ShaderConstants::Attribute4Index;
119 static const UInt16 Attribute5Index = ShaderConstants::Attribute5Index;
120 static const UInt16 Attribute6Index = ShaderConstants::Attribute6Index;
121 static const UInt16 Attribute7Index = ShaderConstants::Attribute7Index;
122 static const UInt16 Attribute8Index = ShaderConstants::Attribute8Index;
123 static const UInt16 Attribute9Index = ShaderConstants::Attribute9Index;
124 static const UInt16 Attribute10Index = ShaderConstants::Attribute10Index;
125 static const UInt16 Attribute11Index = ShaderConstants::Attribute11Index;
126 static const UInt16 Attribute12Index = ShaderConstants::Attribute12Index;
127 static const UInt16 Attribute13Index = ShaderConstants::Attribute13Index;
128 static const UInt16 Attribute14Index = ShaderConstants::Attribute14Index;
129 static const UInt16 Attribute15Index = ShaderConstants::Attribute15Index;
131 static const UInt16 LastIndex = 15;
133 /*! \} */
134 /*---------------------------------------------------------------------*/
135 /*! \name Property Access */
136 /*! \{ */
138 inline GeoIntegralProperty *getTypes (void) const;
139 inline GeoIntegralProperty *getLengths (void) const;
140 inline GeoVectorProperty *getPositions (void) const;
141 inline GeoVectorProperty *getNormals (void) const;
142 inline GeoVectorProperty *getColors (void) const;
143 inline GeoVectorProperty *getSecondaryColors(void) const;
144 inline GeoVectorProperty *getTexCoords (void) const;
145 inline GeoVectorProperty *getTexCoords1 (void) const;
146 inline GeoVectorProperty *getTexCoords2 (void) const;
147 inline GeoVectorProperty *getTexCoords3 (void) const;
148 inline GeoVectorProperty *getTexCoords4 (void) const;
149 inline GeoVectorProperty *getTexCoords5 (void) const;
150 inline GeoVectorProperty *getTexCoords6 (void) const;
151 inline GeoVectorProperty *getTexCoords7 (void) const;
154 inline void setPositions (GeoVectorProperty * const value);
155 inline void setNormals (GeoVectorProperty * const value);
156 inline void setColors (GeoVectorProperty * const value);
157 inline void setSecondaryColors(GeoVectorProperty * const value);
158 inline void setTexCoords (GeoVectorProperty * const value);
159 inline void setTexCoords1 (GeoVectorProperty * const value);
160 inline void setTexCoords2 (GeoVectorProperty * const value);
161 inline void setTexCoords3 (GeoVectorProperty * const value);
162 inline void setTexCoords4 (GeoVectorProperty * const value);
163 inline void setTexCoords5 (GeoVectorProperty * const value);
164 inline void setTexCoords6 (GeoVectorProperty * const value);
165 inline void setTexCoords7 (GeoVectorProperty * const value);
167 void setMaterial (Material * const value);
170 inline void setProperty (GeoVectorProperty * const value,
171 UInt16 index);
173 inline void setIndex (GeoIntegralProperty * const value,
174 UInt16 index);
176 Int32 getClassicGLId (void) const;
177 Int32 getAttGLId (void) const;
179 /*! \} */
180 /*---------------------------------------------------------------------*/
181 /*! \name Property/Index MField Changes */
182 /*! \{ */
184 inline GeoVectorProperty *getProperty(UInt16 index) const;
186 inline GeoIntegralProperty *getIndex (UInt16 index) const;
188 static const char *mapType (UInt8 type );
190 /*! \} */
191 /*---------------------------------------------------------------------*/
192 /*! \name Property/Index MField Changes */
193 /*! \{ */
195 inline void resizeProperties(size_t newsize);
196 inline void reserveProperties(size_t newsize);
198 inline void resizePropIndices(size_t newsize);
199 inline void reservePropIndices(size_t newsize);
202 /*! \} */
203 /*---------------------------------------------------------------------*/
204 /*! \name Backwards Compatibility Helpers */
205 /*! \{ */
207 inline void setIndices(GeoIntegralProperty * const value);
209 inline GeoIntegralProperty *getIndices(void);
211 /*! \} */
212 /*---------------------------------------------------------------------*/
213 /*! \name Backwards Compatibility Helpers */
214 /*! \{ */
216 UInt32 indexOccurrence(GeoIntegralProperty * const value) const;
217 bool isSingleIndex (void ) const;
219 /*! \} */
220 /*---------------------------------------------------------------------*/
221 /*! \name Iterator Access */
222 /*! \{ */
224 TriangleIterator beginTriangles (void) const;
225 TriangleIterator endTriangles (void) const;
227 PrimitiveIterator beginPrimitives (void) const;
228 PrimitiveIterator endPrimitives (void) const;
230 FaceIterator beginFaces (void) const;
231 FaceIterator endFaces (void) const;
233 LineIterator beginLines (void) const;
234 LineIterator endLines (void) const;
236 EdgeIterator beginEdges (void) const;
237 EdgeIterator endEdges (void) const;
239 PointIterator beginPoints (void) const;
240 PointIterator endPoints (void) const;
242 /*! \} */
243 /*---------------------------------------------------------------------*/
244 /*! \name Actions */
245 /*! \{ */
247 virtual void drawPrimitives (DrawEnv *pEnv );
249 Action::ResultE intersectEnter (Action *action);
251 void invalidateDlistCache(void);
253 /*! \} */
254 /*---------------------------------------------------------------------*/
255 /*! \name NodeCore Specific */
256 /*! \{ */
258 virtual void adjustVolume(Volume & volume);
260 /*! \} */
261 /*---------------------------------------------------------------------*/
262 /*! \name Sync */
263 /*! \{ */
265 virtual void changed(ConstFieldMaskArg whichField,
266 UInt32 origin,
267 BitVector detail);
269 /*! \} */
270 /*---------------------------------------------------------------------*/
271 /*! \name Output */
272 /*! \{ */
274 virtual void dump( UInt32 uiIndent = 0,
275 const BitVector bvFlags = 0) const;
277 /*! \} */
278 /*---------------------------------------------------------------------*/
279 /*! \name Pump Handling */
280 /*! \{ */
282 typedef std::vector<std::pair<GeoIntegralProperty *,
283 std::vector<UInt16> > > IndexBag;
285 IndexBag getUniqueIndexBag(void) const;
287 /*! \} */
288 /*---------------------------------------------------------------------*/
289 /*! \name Pump Handling */
290 /*! \{ */
292 // GeoPumpGroup::PropertyCharacteristics
293 // calcPropertyCharacteristics(void);
295 /*! \} */
296 /*---------------------------------------------------------------------*/
297 /*! \name Stats */
298 /*! \{ */
300 virtual void fill(DrawableStatsAttachment *pStat);
302 /*! \} */
303 /*---------------------------------------------------------------------*/
304 /*! \name Global Pump Group Handling */
305 /*! \{ */
307 static UInt32 getFuncIdDrawElementsInstanced(void);
308 static UInt32 getFuncIdDrawArraysInstanced (void);
310 /*! \} */
311 /*---------------------------------------------------------------------*/
312 /*! \name Global Pump Group Handling */
313 /*! \{ */
316 typedef std::vector<GeoPumpGroup*> PumpGroupStorage;
318 static PumpGroupStorage &getPumpGroupStorage(void);
320 /*! \} */
321 /*========================= PROTECTED ===============================*/
323 protected:
325 // Variables should all be in GeometryBase.
327 BoxVolume _volumeCache;
329 static UInt32 _arbVertexArrayObject;
330 static UInt32 _arbTessellationShader;
331 static UInt32 _arbDrawInstanced;
333 static UInt32 FuncIdBindVertexArray;
334 static UInt32 FuncIdDeleteVertexArrays;
335 static UInt32 FuncIdGenVertexArrays;
336 static UInt32 FuncPatchParameterI;
338 static UInt32 FuncIdDrawElementsInstanced;
339 static UInt32 FuncIdDrawArraysInstanced;
341 union GLHandlerOptions
343 UInt64 value;
345 struct
347 UInt32 uiOptions;
348 UInt32 uiNumInstances;
349 } s;
352 enum
354 ValidVAO = 0x00000001L
357 /*---------------------------------------------------------------------*/
358 /*! \name Constructors */
359 /*! \{ */
361 Geometry(void);
362 Geometry(const Geometry &source);
364 /*! \} */
365 /*---------------------------------------------------------------------*/
366 /*! \name Destructors */
367 /*! \{ */
369 virtual ~Geometry(void);
371 /*! \} */
372 /*---------------------------------------------------------------------*/
373 /*! \name Class Specific */
374 /*! \{ */
376 UInt32 handleClassicGL (DrawEnv *pEnv,
377 UInt32 id,
378 Window::GLObjectStatusE mode,
379 UInt64 uiOptions);
381 static void handleClassicDestroyGL(DrawEnv *pEnv,
382 UInt32 id,
383 Window::GLObjectStatusE mode );
385 UInt32 handleAttGL (DrawEnv *pEnv,
386 UInt32 id,
387 Window::GLObjectStatusE mode,
388 UInt64 uiOption);
389 static void handleAttDestroyGL (DrawEnv *pEnv,
390 UInt32 id,
391 Window::GLObjectStatusE mode );
393 UInt32 handleVAOGL (DrawEnv *pEnv,
394 UInt32 id,
395 Window::GLObjectStatusE mode,
396 UInt64 uiOption);
397 static void handleVAODestroyGL (DrawEnv *pEnv,
398 UInt32 id,
399 Window::GLObjectStatusE mode );
401 void onCreate(const Geometry *source = NULL);
402 void onDestroy(UInt32 id);
404 /*! \} */
405 /*---------------------------------------------------------------------*/
406 /*! \name Init */
407 /*! \{ */
409 virtual void drawPrimitives(DrawEnv *pEnv,
410 UInt32 uiNumInstances);
412 /*! \} */
413 /*---------------------------------------------------------------------*/
414 /*! \name Init */
415 /*! \{ */
417 static void initMethod(InitPhase ePhase);
419 /*! \} */
420 /*========================== PRIVATE ================================*/
422 private:
424 friend class FieldContainer;
425 friend class GeometryBase;
426 friend class GeoInstancer;
428 static PumpGroupStorage _pumps;
430 // prohibit default functions (move to 'public' if you need one)
431 void operator =(const Geometry &source);
434 typedef Geometry *GeometryP;
436 OSG_END_NAMESPACE
438 #include "OSGGeometryBase.inl"
439 #include "OSGGeometry.inl"
441 #endif /* _OSGGEOMETRY_H_ */