fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / Base / OSGGeoBuilder.h
blob7d01aa6d5bd604b460186dd45b9b99191e44f4a9
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 _OSGGEOBUILDER_H_
40 #define _OSGGEOBUILDER_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGGeoProperties.h"
46 #include "OSGGeometry.h"
48 OSG_BEGIN_NAMESPACE
50 /*! \brief A helper class to simplify building geometry.
51 \ingroup GrpDrawablesGeometryUtils
52 \nohierarchy
55 class OSG_DRAWABLE_DLLMAPPING GeoBuilder
57 /*========================== PUBLIC =================================*/
58 public:
59 /*---------------------------------------------------------------------*/
60 /*! \name Con/Destructors */
61 /*! \{ */
63 GeoBuilder(void);
65 ~GeoBuilder();
67 void reset(void);
69 /*! \} */
70 /*---------------------------------------------------------------------*/
71 /*! \name Property Access */
72 /*! \{ */
74 template <class Type>
75 UInt32 vertex(Type data)
77 getProperty(Geometry::PositionsIndex)->addValue(data);
79 return finishVertex();
82 template <class Type>
83 void normal(Type data)
85 getProperty(Geometry::NormalsIndex)->addValue(data);
88 template <class Type>
89 void color(Type data)
91 getProperty(Geometry::ColorsIndex)->addValue(data);
94 template <class Type>
95 void texcoord(UInt16 unit, Type data)
97 getProperty(Geometry::TexCoordsIndex + unit)->addValue(data);
100 template <class Type>
101 UInt32 prop(UInt16 propIndex, Type data)
103 getProperty(propIndex)->addValue(data);
105 if(propIndex == 0)
106 return finishVertex();
107 else
108 return 0;
111 template <class VType, class NType>
112 UInt32 fullVertex(VType vert, NType norm)
114 normal(norm);
115 return vertex(vert);
118 template <class VType, class NType, class CType>
119 UInt32 fullVertex(VType vert, NType norm, CType col)
121 color(col);
122 normal(norm);
123 return vertex(vert);
126 template <class VType, class NType, class CType, class TType>
127 UInt32 fullVertex(VType vert, NType norm, CType col, TType tc)
129 color(col);
130 normal(norm);
131 texcoord(0, tc);
132 return vertex(vert);
135 /*! \} */
136 /*---------------------------------------------------------------------*/
137 /*! \name Face Creation */
138 /*! \{ */
140 void begin(UInt32 type);
142 void index(UInt32 newIndex);
144 void end(void);
146 void line(UInt32 start );
147 void line(UInt32 i1, UInt32 i2);
149 void tri(UInt32 start );
150 void tri(UInt32 i1, UInt32 i2, UInt32 i3);
152 void quad(UInt32 start );
153 void quad(UInt32 i1, UInt32 i2, UInt32 i3, UInt32 i4);
155 /*! \} */
156 /*---------------------------------------------------------------------*/
157 /*! \name Object Access */
158 /*! \{ */
160 Geometry *getGeometry(void);
162 /*! \} */
163 /*========================= PROTECTED ===============================*/
164 protected:
165 /*---------------------------------------------------------------------*/
166 /*! \name Property Helper */
167 /*! \{ */
169 GeoVectorProperty *getProperty(UInt32 index);
171 UInt32 finishVertex(void);
173 void addType(Int32 type);
174 void addLength(UInt32 length);
176 /*! \} */
177 /*========================== PRIVATE ================================*/
178 private:
180 GeometryUnrecPtr _geo;
182 UInt32 _actLen;
183 Int32 _actType;
185 static const char* _defaultPropTypes[Geometry::MaxAttribs];
188 OSG_END_NAMESPACE
190 #include "OSGGeoBuilder.inl"
192 #endif /* _OSGGEOBUILDER_H_ */