2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSGUTIL_Tesselator
|
|
|
|
#define OSGUTIL_Tesselator
|
|
|
|
|
2002-06-29 06:42:02 +08:00
|
|
|
#include <osg/Geometry>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
|
2002-06-29 06:42:02 +08:00
|
|
|
#include <osg/GLU>
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2002-06-29 06:42:02 +08:00
|
|
|
/* Win32 calling conventions. (or a least thats what the GLUT example tess.c uses.)*/
|
|
|
|
#ifndef CALLBACK
|
|
|
|
#define CALLBACK
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
namespace osgUtil {
|
|
|
|
|
2001-09-28 20:36:40 +08:00
|
|
|
/** A simple class for tessellating a single polygon boundary.
|
|
|
|
* Currently uses old style glu tessellation functions for portability.
|
|
|
|
* It be nice to use the modern glu tessellation functions or to find
|
2001-09-20 05:19:47 +08:00
|
|
|
* a small set of code for doing this job better.*/
|
|
|
|
class OSGUTIL_EXPORT Tesselator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Tesselator();
|
|
|
|
~Tesselator();
|
|
|
|
|
|
|
|
enum InputBoundaryDirection
|
|
|
|
{
|
|
|
|
CLOCK_WISE,
|
|
|
|
COUNTER_CLOCK_WISE
|
|
|
|
};
|
|
|
|
|
2002-06-29 06:42:02 +08:00
|
|
|
typedef std::vector<osg::Vec3*> VertexPointList;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-06-29 06:42:02 +08:00
|
|
|
struct Prim : public osg::Referenced
|
|
|
|
{
|
|
|
|
Prim(GLenum mode):_mode(mode) {}
|
|
|
|
|
|
|
|
typedef std::vector<osg::Vec3*> VecList;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-06-29 06:42:02 +08:00
|
|
|
GLenum _mode;
|
|
|
|
VecList _vertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
void beginTesselation();
|
|
|
|
|
|
|
|
void beginContour();
|
|
|
|
void addVertex(osg::Vec3* vertex);
|
|
|
|
void endContour();
|
|
|
|
|
|
|
|
void endTesselation();
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-06-29 06:42:02 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<Prim> > PrimList;
|
|
|
|
|
|
|
|
PrimList& getPrimList() { return _primList; }
|
|
|
|
|
|
|
|
void retesselatePolygons(osg::Geometry& geom);
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void begin(GLenum mode);
|
|
|
|
void vertex(osg::Vec3* vertex);
|
2002-07-16 06:23:57 +08:00
|
|
|
void combine(osg::Vec3* vertex,void* vertex_data[4],GLfloat weight[4]);
|
2002-06-29 06:42:02 +08:00
|
|
|
void end();
|
|
|
|
void error(GLenum errorCode);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
|
2002-07-03 03:53:18 +08:00
|
|
|
static void CALLBACK beginCallback(GLenum which, void* userData);
|
|
|
|
static void CALLBACK vertexCallback(GLvoid *data, void* userData);
|
|
|
|
static void CALLBACK combineCallback(GLdouble coords[3], void* vertex_data[4],
|
2002-06-29 06:42:02 +08:00
|
|
|
GLfloat weight[4], void** outData,
|
|
|
|
void* useData);
|
2002-07-03 03:53:18 +08:00
|
|
|
static void CALLBACK endCallback(void* userData);
|
|
|
|
static void CALLBACK errorCallback(GLenum errorCode, void* userData);
|
2002-06-29 06:42:02 +08:00
|
|
|
|
|
|
|
|
|
|
|
struct Vec3d
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
2002-06-29 06:42:02 +08:00
|
|
|
double _v[3];
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-07-16 06:23:57 +08:00
|
|
|
struct NewVertex
|
|
|
|
{
|
|
|
|
|
|
|
|
NewVertex():
|
|
|
|
_f1(0),
|
|
|
|
_v1(0),
|
|
|
|
_f2(0),
|
|
|
|
_v2(0),
|
|
|
|
_f3(0),
|
|
|
|
_v3(0),
|
|
|
|
_f4(0),
|
|
|
|
_v4(0) {}
|
|
|
|
|
|
|
|
NewVertex(const NewVertex& nv):
|
|
|
|
_f1(nv._f1),
|
|
|
|
_v1(nv._v1),
|
|
|
|
_f2(nv._f2),
|
|
|
|
_v2(nv._v2),
|
|
|
|
_f3(nv._f3),
|
|
|
|
_v3(nv._v3),
|
|
|
|
_f4(nv._f4),
|
|
|
|
_v4(nv._v4) {}
|
|
|
|
|
|
|
|
NewVertex(float f1,osg::Vec3* v1,
|
|
|
|
float f2,osg::Vec3* v2,
|
|
|
|
float f3,osg::Vec3* v3,
|
|
|
|
float f4,osg::Vec3* v4):
|
|
|
|
_f1(f1),
|
|
|
|
_v1(v1),
|
|
|
|
_f2(f2),
|
|
|
|
_v2(v2),
|
|
|
|
_f3(f3),
|
|
|
|
_v3(v3),
|
|
|
|
_f4(f4),
|
|
|
|
_v4(v4) {}
|
|
|
|
|
|
|
|
float _f1;
|
|
|
|
osg::Vec3* _v1;
|
|
|
|
|
|
|
|
float _f2;
|
|
|
|
osg::Vec3* _v2;
|
|
|
|
|
|
|
|
float _f3;
|
|
|
|
osg::Vec3* _v3;
|
|
|
|
|
|
|
|
float _f4;
|
|
|
|
osg::Vec3* _v4;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<osg::Vec3*,NewVertex> NewVertexList;
|
2002-06-29 06:42:02 +08:00
|
|
|
typedef std::vector<Vec3d*> Vec3dList;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-06-29 06:42:02 +08:00
|
|
|
GLUtesselator* _tobj;
|
|
|
|
PrimList _primList;
|
|
|
|
Vec3dList _coordData;
|
2002-07-16 06:23:57 +08:00
|
|
|
NewVertexList _newVertexList;
|
2002-06-29 06:42:02 +08:00
|
|
|
GLenum _errorCode;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|