1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGGEOMETRY_H_
40 #define _OSGGEOMETRY_H_
47 #include "OSGGeometryBase.h"
49 #include "OSGGeoVectorProperty.h"
50 #include "OSGGeoIntegralProperty.h"
51 #include "OSGWindow.h"
53 #include "OSGShaderAttribute.h"
60 class TriangleIterator
;
61 class PrimitiveIterator
;
69 /*! \brief Geometry class. See \ref
70 PageDrawableGeometry for a description.
71 \ingroup GrpDrawablesGeometryObj
72 \ingroup GrpLibOSGDrawables
76 class OSG_DRAWABLE_DLLMAPPING Geometry
: public GeometryBase
80 /*========================== PUBLIC =================================*/
84 typedef GeometryBase Inherited
;
86 /*---------------------------------------------------------------------*/
87 /*! \name Simplification Constants */
90 // Maximum number of possible attributes
91 static const UInt16 MaxAttribs
= 16;
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.
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;
134 /*---------------------------------------------------------------------*/
135 /*! \name Property Access */
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
,
173 inline void setIndex (GeoIntegralProperty
* const value
,
176 Int32
getClassicGLId (void) const;
177 Int32
getAttGLId (void) const;
180 /*---------------------------------------------------------------------*/
181 /*! \name Property/Index MField Changes */
184 inline GeoVectorProperty
*getProperty(UInt16 index
) const;
186 inline GeoIntegralProperty
*getIndex (UInt16 index
) const;
188 static const char *mapType (UInt8 type
);
191 /*---------------------------------------------------------------------*/
192 /*! \name Property/Index MField Changes */
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
);
203 /*---------------------------------------------------------------------*/
204 /*! \name Backwards Compatibility Helpers */
207 inline void setIndices(GeoIntegralProperty
* const value
);
209 inline GeoIntegralProperty
*getIndices(void);
212 /*---------------------------------------------------------------------*/
213 /*! \name Backwards Compatibility Helpers */
216 UInt32
indexOccurrence(GeoIntegralProperty
* const value
) const;
217 bool isSingleIndex (void ) const;
220 /*---------------------------------------------------------------------*/
221 /*! \name Iterator Access */
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;
243 /*---------------------------------------------------------------------*/
247 virtual void drawPrimitives (DrawEnv
*pEnv
);
249 Action::ResultE
intersectEnter (Action
*action
);
251 void invalidateDlistCache(void);
254 /*---------------------------------------------------------------------*/
255 /*! \name NodeCore Specific */
258 virtual void adjustVolume(Volume
& volume
);
261 /*---------------------------------------------------------------------*/
265 virtual void changed(ConstFieldMaskArg whichField
,
270 /*---------------------------------------------------------------------*/
274 virtual void dump( UInt32 uiIndent
= 0,
275 const BitVector bvFlags
= 0) const;
278 /*---------------------------------------------------------------------*/
279 /*! \name Pump Handling */
282 typedef std::vector
<std::pair
<GeoIntegralProperty
*,
283 std::vector
<UInt16
> > > IndexBag
;
285 IndexBag
getUniqueIndexBag(void) const;
288 /*---------------------------------------------------------------------*/
289 /*! \name Pump Handling */
292 // GeoPumpGroup::PropertyCharacteristics
293 // calcPropertyCharacteristics(void);
296 /*---------------------------------------------------------------------*/
300 virtual void fill(DrawableStatsAttachment
*pStat
);
303 /*---------------------------------------------------------------------*/
304 /*! \name Global Pump Group Handling */
307 static UInt32
getFuncIdDrawElementsInstanced(void);
308 static UInt32
getFuncIdDrawArraysInstanced (void);
311 /*---------------------------------------------------------------------*/
312 /*! \name Global Pump Group Handling */
316 typedef std::vector
<GeoPumpGroup
*> PumpGroupStorage
;
318 static PumpGroupStorage
&getPumpGroupStorage(void);
321 /*========================= 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
348 UInt32 uiNumInstances
;
354 ValidVAO
= 0x00000001L
357 /*---------------------------------------------------------------------*/
358 /*! \name Constructors */
362 Geometry(const Geometry
&source
);
365 /*---------------------------------------------------------------------*/
366 /*! \name Destructors */
369 virtual ~Geometry(void);
372 /*---------------------------------------------------------------------*/
373 /*! \name Class Specific */
376 UInt32
handleClassicGL (DrawEnv
*pEnv
,
378 Window::GLObjectStatusE mode
,
381 static void handleClassicDestroyGL(DrawEnv
*pEnv
,
383 Window::GLObjectStatusE mode
);
385 UInt32
handleAttGL (DrawEnv
*pEnv
,
387 Window::GLObjectStatusE mode
,
389 static void handleAttDestroyGL (DrawEnv
*pEnv
,
391 Window::GLObjectStatusE mode
);
393 UInt32
handleVAOGL (DrawEnv
*pEnv
,
395 Window::GLObjectStatusE mode
,
397 static void handleVAODestroyGL (DrawEnv
*pEnv
,
399 Window::GLObjectStatusE mode
);
401 void onCreate(const Geometry
*source
= NULL
);
402 void onDestroy(UInt32 id
);
405 /*---------------------------------------------------------------------*/
409 virtual void drawPrimitives(DrawEnv
*pEnv
,
410 UInt32 uiNumInstances
);
413 /*---------------------------------------------------------------------*/
417 static void initMethod(InitPhase ePhase
);
420 /*========================== 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
;
438 #include "OSGGeometryBase.inl"
439 #include "OSGGeometry.inl"
441 #endif /* _OSGGEOMETRY_H_ */