#include #include #include #include using namespace osg; using namespace osgUtil; /* Win32 calling conventions. (or a least thats what the GLUT example tess.c uses.)*/ #ifndef CALLBACK #define CALLBACK #endif static Tesselator* s_tesselator = NULL; void CALLBACK beginCallback(GLenum which) { s_tesselator->beginPrimitive(which); } void CALLBACK errorCallback(GLenum errorCode) { s_tesselator->_errorCode = errorCode; } void CALLBACK endCallback() { s_tesselator->endPrimitive(); } void CALLBACK vertexCallback(GLvoid *data) { Tesselator::VertexIndexSet* vip = (Tesselator::VertexIndexSet*)data; vip->accumulate(); } Tesselator::Tesselator() { } Tesselator::~Tesselator() { } void Tesselator::tesselate(osg::Vec3* coords,int numIndices, int* indices,InputBoundaryDirection ibd) { init(); _coordVec.reserve(numIndices); if (ibd==COUNTER_CLOCK_WISE) { for(int i=0;i=0;--i) { _coordVec.push_back(VertexIndexSet(this,coords[indices[i]],indices[i])); } } do_it(); } void Tesselator::tesselate(osg::Vec3* coords,int numIndices, osg::ushort* indices,InputBoundaryDirection ibd) { init(); _coordVec.reserve(numIndices); if (ibd==COUNTER_CLOCK_WISE) { for(int i=0;i=0;--i) { _coordVec.push_back(VertexIndexSet(this,coords[indices[i]],indices[i])); } } do_it(); } void Tesselator::tesselate(osg::Vec3* coords,int numIndices, osg::uint* indices,InputBoundaryDirection ibd) { init(); _coordVec.reserve(numIndices); if (ibd==COUNTER_CLOCK_WISE) { for(int i=0;i=0;--i) { _coordVec.push_back(VertexIndexSet(this,coords[indices[i]],indices[i])); } } do_it(); } void Tesselator::init() { _errorCode = 0; _coordVec.clear(); _acummulated_indices.clear(); _tesselated_indices.clear(); _currentPrimtiveType=0; } #ifdef GLU_VERSION_1_2 void Tesselator::do_it() { GLUtesselator *tobj = gluNewTess(); gluTessCallback(tobj, (GLenum)GLU_TESS_VERTEX, (GLvoid (CALLBACK*) ()) (&vertexCallback)); gluTessCallback(tobj, (GLenum)GLU_TESS_BEGIN, (GLvoid (CALLBACK*) ()) (&beginCallback)); gluTessCallback(tobj, (GLenum)GLU_TESS_END, (GLvoid (CALLBACK*) ()) (&endCallback)); gluTessCallback(tobj, (GLenum)GLU_TESS_ERROR, (GLvoid (CALLBACK*) ()) (&errorCallback)); s_tesselator = this; gluTessBeginPolygon(tobj,NULL); gluTessBeginContour(tobj); for(CoordVec::iterator itr=_coordVec.begin(); itr!=_coordVec.end(); ++itr) { gluTessVertex(tobj,itr->_vertex,itr->_vertex); } gluTessEndContour(tobj); gluTessEndPolygon(tobj); gluDeleteTess(tobj); if (_errorCode!=0) { const GLubyte *estring = gluErrorString((GLenum)_errorCode); osg::notify(osg::WARN)<<"Tessellation Error: "<