openscenegraph
Tessellator
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 OSGUTIL_Tessellator
15#define OSGUTIL_Tessellator
16
17#include <osg/Geometry>
18
19#include <osgUtil/Export>
20
21#include <osg/GLU>
22
23#include <vector>
24
25#ifndef CALLBACK
26 /* Win32 calling conventions. (or a least that's what the GLUT example tess.c uses.)*/
27 #define CALLBACK
28#endif
29
30namespace osgUtil {
31
37{
38 public:
39
42
45 TESS_WINDING_ODD = GLU_TESS_WINDING_ODD,
46 TESS_WINDING_NONZERO = GLU_TESS_WINDING_NONZERO,
47 TESS_WINDING_POSITIVE = GLU_TESS_WINDING_POSITIVE,
48 TESS_WINDING_NEGATIVE = GLU_TESS_WINDING_NEGATIVE,
49 TESS_WINDING_ABS_GEQ_TWO = GLU_TESS_WINDING_ABS_GEQ_TWO
50 } ;
51
55 TESS_TYPE_GEOMETRY, // tessellate everything in the geometry object
56 TESS_TYPE_DRAWABLE, // tessellate each polygon, triangles & quads drawables in geometry separately
57 TESS_TYPE_POLYGONS // tessellate ONLY polygon drawables in geometry separately
58 };
59
61 void setBoundaryOnly (const bool tt) { _boundaryOnly=tt;}
62 inline bool getBoundaryOnly ( ) { return _boundaryOnly;}
63
65 void setWindingType (const WindingType wt) { _wtype=wt;}
66 inline WindingType getWindingType ( ) { return _wtype;}
67
69 void setTessellationType (const TessellationType tt) { _ttype=tt;}
70 inline TessellationType getTessellationType ( ) { return _ttype;}
71
78
85 void setTessellationNormal(const osg::Vec3 norm) { tessNormal=norm;}
86
88
89 struct Prim : public osg::Referenced
90 {
91 Prim(GLenum mode):_mode(mode) {}
92
93 typedef std::vector<osg::Vec3*> VecList;
94
95 GLenum _mode;
97 };
98
99 virtual void beginTessellation();
100
102
108 void addVertex(osg::Vec3* vertex);
109
111
113
114 typedef std::vector< osg::ref_ptr<Prim> > PrimList;
115
116 PrimList& getPrimList() { return _primList; }
117
118 void reset();
119
120 protected:
121
125 void reduceArray(osg::Array * cold, const unsigned int nnu);
126
127 void collectTessellation(osg::Geometry &cxgeom, unsigned int originalIndex);
128
129 typedef std::map<osg::Vec3*,unsigned int> VertexPtrToIndexMap;
130 void addContour(GLenum mode, unsigned int first, unsigned int last, osg::Vec3Array* vertices);
131 void addContour(osg::PrimitiveSet* primitive, osg::Vec3Array* vertices);
132 void handleNewVertices(osg::Geometry& geom,VertexPtrToIndexMap &vertexPtrToIndexMap);
133
134 void begin(GLenum mode);
135 void vertex(osg::Vec3* vertex);
136 void combine(osg::Vec3* vertex,void* vertex_data[4],GLfloat weight[4]);
137 void end();
138 void error(GLenum errorCode);
139
140
141 static void CALLBACK beginCallback(GLenum which, void* userData);
142 static void CALLBACK vertexCallback(GLvoid *data, void* userData);
143 static void CALLBACK combineCallback(GLdouble coords[3], void* vertex_data[4],
144 GLfloat weight[4], void** outData,
145 void* useData);
146 static void CALLBACK endCallback(void* userData);
147 static void CALLBACK errorCallback(GLenum errorCode, void* userData);
148
149
150 struct Vec3d
151 {
152 double _v[3];
153 };
154
155
157 {
158
160 _vpos(0),
161 _f1(0),
162 _v1(0),
163 _f2(0),
164 _v2(0),
165 _f3(0),
166 _v3(0),
167 _f4(0),
168 _v4(0) {}
169
171 _vpos(nv._vpos),
172 _f1(nv._f1),
173 _v1(nv._v1),
174 _f2(nv._f2),
175 _v2(nv._v2),
176 _f3(nv._f3),
177 _v3(nv._v3),
178 _f4(nv._f4),
179 _v4(nv._v4) {}
180
182 float f1,osg::Vec3* v1,
183 float f2,osg::Vec3* v2,
184 float f3,osg::Vec3* v3,
185 float f4,osg::Vec3* v4):
186 _vpos(vx),
187 _f1(f1),
188 _v1(v1),
189 _f2(f2),
190 _v2(v2),
191 _f3(f3),
192 _v3(v3),
193 _f4(f4),
194 _v4(v4) {}
195
196 osg::Vec3 *_vpos; // added gwm Jan 2004 the vertex coords s.t. NewVertex can be used in a std::vector
197
198 float _f1;
200
201 float _f2;
203
204 float _f3;
206
207 float _f4;
209
210 };
211
212 //change NewVertexList from std::map<osg::Vec3*,NewVertex> NewVertexList;
213 // because this has undefined order of insertion for new vertices.
214 // which occasionally corrupted the texture mapping.
215 typedef std::vector<NewVertex> NewVertexList;
216 typedef std::vector<Vec3d*> Vec3dList;
217
218 osg::GLUtesselator* _tobj;
219
224
227
230
231 bool _boundaryOnly; // see gluTessProperty - if true: make the boundary edges only.
232
234 unsigned int _numberVerts;
235
238
240 unsigned int _index;
241
244
246 unsigned int _extraPrimitives;
247};
248
249}
250
251#endif
#define GLU_TESS_WINDING_NONZERO
Definition GLU:156
#define GLU_TESS_WINDING_POSITIVE
Definition GLU:157
#define GLU_TESS_WINDING_NEGATIVE
Definition GLU:158
#define GLU_TESS_WINDING_ODD
Definition GLU:155
#define GLU_TESS_WINDING_ABS_GEQ_TWO
Definition GLU:159
#define CALLBACK
Definition Tessellator:27
Definition Tessellator:37
TessellationType _ttype
Definition Tessellator:229
std::vector< Vec3d * > Vec3dList
Definition Tessellator:216
osg::Vec3 tessNormal
Definition Tessellator:243
osg::Geometry::PrimitiveSetList _Contours
Definition Tessellator:237
TessellationType getTessellationType()
Definition Tessellator:70
bool getBoundaryOnly()
Definition Tessellator:62
void error(GLenum errorCode)
WindingType getWindingType()
Definition Tessellator:66
void setTessellationNormal(const osg::Vec3 norm)
Definition Tessellator:85
osg::Geometry::PrimitiveSetList getContours()
Definition Tessellator:87
unsigned int _numberVerts
Definition Tessellator:234
virtual void beginTessellation()
Vec3dList _coordData
Definition Tessellator:221
void combine(osg::Vec3 *vertex, void *vertex_data[4], GLfloat weight[4])
void reduceArray(osg::Array *cold, const unsigned int nnu)
void setWindingType(const WindingType wt)
Definition Tessellator:65
unsigned int _extraPrimitives
Definition Tessellator:246
static void CALLBACK endCallback(void *userData)
void begin(GLenum mode)
void handleNewVertices(osg::Geometry &geom, VertexPtrToIndexMap &vertexPtrToIndexMap)
static void CALLBACK errorCallback(GLenum errorCode, void *userData)
TessellationType
Definition Tessellator:54
@ TESS_TYPE_GEOMETRY
Definition Tessellator:55
@ TESS_TYPE_DRAWABLE
Definition Tessellator:56
void addVertex(osg::Vec3 *vertex)
PrimList _primList
Definition Tessellator:220
void vertex(osg::Vec3 *vertex)
static void CALLBACK beginCallback(GLenum which, void *userData)
static void CALLBACK combineCallback(GLdouble coords[3], void *vertex_data[4], GLfloat weight[4], void **outData, void *useData)
void setTessellationType(const TessellationType tt)
Definition Tessellator:69
void collectTessellation(osg::Geometry &cxgeom, unsigned int originalIndex)
NewVertexList _newVertexList
Definition Tessellator:222
void retessellatePolygons(osg::Geometry &cxgeom)
unsigned int _index
Definition Tessellator:240
GLenum _errorCode
Definition Tessellator:223
void addContour(osg::PrimitiveSet *primitive, osg::Vec3Array *vertices)
static void CALLBACK vertexCallback(GLvoid *data, void *userData)
PrimList & getPrimList()
Definition Tessellator:116
std::vector< osg::ref_ptr< Prim > > PrimList
Definition Tessellator:114
std::map< osg::Vec3 *, unsigned int > VertexPtrToIndexMap
Definition Tessellator:129
std::vector< NewVertex > NewVertexList
Definition Tessellator:215
bool _boundaryOnly
Definition Tessellator:231
osg::GLUtesselator * _tobj
Definition Tessellator:218
WindingType
Definition Tessellator:44
void addContour(GLenum mode, unsigned int first, unsigned int last, osg::Vec3Array *vertices)
void setBoundaryOnly(const bool tt)
Definition Tessellator:61
WindingType _wtype
Definition Tessellator:226
Definition Array:61
Definition Geometry:31
std::vector< ref_ptr< PrimitiveSet > > PrimitiveSetList
Definition Geometry:102
Definition PrimitiveSet:125
Definition Referenced:44
A concrete array holding elements of type T.
Definition Array:243
Definition Vec3f:29
Shader generator framework.
Definition NodeVisitor:25
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40
Definition Tessellator:157
float _f1
Definition Tessellator:198
osg::Vec3 * _vpos
Definition Tessellator:196
float _f2
Definition Tessellator:201
NewVertex(const NewVertex &nv)
Definition Tessellator:170
osg::Vec3 * _v1
Definition Tessellator:199
osg::Vec3 * _v2
Definition Tessellator:202
NewVertex(osg::Vec3 *vx, float f1, osg::Vec3 *v1, float f2, osg::Vec3 *v2, float f3, osg::Vec3 *v3, float f4, osg::Vec3 *v4)
Definition Tessellator:181
osg::Vec3 * _v3
Definition Tessellator:205
float _f4
Definition Tessellator:207
osg::Vec3 * _v4
Definition Tessellator:208
float _f3
Definition Tessellator:204
NewVertex()
Definition Tessellator:159
Definition Tessellator:90
std::vector< osg::Vec3 * > VecList
Definition Tessellator:93
VecList _vertices
Definition Tessellator:96
Prim(GLenum mode)
Definition Tessellator:91
GLenum _mode
Definition Tessellator:95
Definition Tessellator:151