Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since we only want triangles we can use the EDGE_FLAG callback to force the tessellator to return triangles #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 6 additions & 93 deletions src/opengl/glPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ namespace MonkVG {


_fillTesseleator = gluNewTess();
gluTessCallback( _fillTesseleator, GLU_TESS_BEGIN_DATA, (GLvoid (APIENTRY *) ( )) &OpenGLPath::tessBegin );
gluTessCallback( _fillTesseleator, GLU_TESS_END_DATA, (GLvoid (APIENTRY *) ( )) &OpenGLPath::tessEnd );
gluTessCallback( _fillTesseleator, GLU_TESS_EDGE_FLAG_DATA, (GLvoid (APIENTRY *) ( )) &OpenGLPath::tessEdgeFlag );
gluTessCallback( _fillTesseleator, GLU_TESS_VERTEX_DATA, (GLvoid (APIENTRY *) ( )) &OpenGLPath::tessVertex );
gluTessCallback( _fillTesseleator, GLU_TESS_COMBINE_DATA, (GLvoid (APIENTRY *) ( )) &OpenGLPath::tessCombine );
gluTessCallback( _fillTesseleator, GLU_TESS_ERROR, (GLvoid (APIENTRY *)())&OpenGLPath::tessError );
Expand Down Expand Up @@ -931,101 +930,12 @@ namespace MonkVG {
_strokeVertices.clear();
}

static GLdouble startVertex_[2];
static GLdouble lastVertex_[2];
static int vertexCount_ = 0;

void OpenGLPath::tessBegin( GLenum type, GLvoid* user ) {
OpenGLPath* me = (OpenGLPath*)user;
me->setPrimType( type );
vertexCount_ = 0;

switch( type )
{
case GL_TRIANGLES:
//printf( "begin(GL_TRIANGLES)\n" );
break;
case GL_TRIANGLE_FAN:
//printf( "begin(GL_TRIANGLE_FAN)\n" );
break;
case GL_TRIANGLE_STRIP:
//printf( "begin(GL_TRIANGLE_STRIP)\n" );
break;
case GL_LINE_LOOP:
//printf( "begin(GL_LINE_LOOP)\n" );
break;
default:
break;
}

}


void OpenGLPath::tessEnd( GLvoid* user ) {
// OpenGLPath* me = (OpenGLPath*)user;
// me->endOfTesselation();

//printf("end\n");
}


void OpenGLPath::tessVertex( GLvoid* vertex, GLvoid* user ) {
OpenGLPath* me = (OpenGLPath*)user;
GLdouble* v = (GLdouble*)vertex;

if ( me->primType() == GL_TRIANGLE_FAN ) {
// break up fans and strips into triangles
switch ( vertexCount_ ) {
case 0:
startVertex_[0] = v[0];
startVertex_[1] = v[1];
break;
case 1:
lastVertex_[0] = v[0];
lastVertex_[1] = v[1];
break;

default:
me->addVertex( startVertex_ );
me->addVertex( lastVertex_ );
me->addVertex( v );
lastVertex_[0] = v[0];
lastVertex_[1] = v[1];
break;
}
} else if ( me->primType() == GL_TRIANGLES ) {
me->addVertex( v );
} else if ( me->primType() == GL_TRIANGLE_STRIP ) {
switch ( vertexCount_ ) {
case 0:
me->addVertex( v );
break;
case 1:
startVertex_[0] = v[0];
startVertex_[1] = v[1];
me->addVertex( v );
break;
case 2:
lastVertex_[0] = v[0];
lastVertex_[1] = v[1];
me->addVertex( v );
break;

default:
me->addVertex( startVertex_ );
me->addVertex( lastVertex_ );
me->addVertex( v );
startVertex_[0] = lastVertex_[0];
startVertex_[1] = lastVertex_[1];
lastVertex_[0] = v[0];
lastVertex_[1] = v[1];
break;
}
}
vertexCount_++;

//printf("\tvert[%d]: %f, %f, %f\n", vertexCount_, v[0], v[1], v[2] );
me->addVertex( v );
}

void OpenGLPath::tessCombine( GLdouble coords[3], void *data[4],
GLfloat weight[4], void **outData,
void *polygonData ) {
Expand All @@ -1038,6 +948,9 @@ namespace MonkVG {
void OpenGLPath::tessError( GLenum errorCode ) {
printf("tesselator error: [%d] %s\n", errorCode, gluErrorString( errorCode) );
}

void OpenGLPath::tessEdgeFlag( GLboolean f, void * data ) { }


OpenGLPath::~OpenGLPath() {
if ( _fillTesseleator ) {
Expand Down
9 changes: 1 addition & 8 deletions src/opengl/glPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ namespace MonkVG {
vector<GLfloat> _vertices;
vector<v2_t> _strokeVertices;
list<v3_t> _tessVertices;
GLenum _primType;
GLuint _fillVBO;
GLuint _strokeVBO;
int _numberFillVertices;
Expand All @@ -81,18 +80,12 @@ namespace MonkVG {
static void tessCombine( GLdouble coords[3], void *data[4],
GLfloat weight[4], void **outData,
void *polygonData );
static void tessEdgeFlag( GLboolean f, void * data );
static void tessError( GLenum errorCode );
void endOfTesselation( VGbitfield paintModes );

private: // utility methods

GLenum primType() {
return _primType;
}
void setPrimType( GLenum t ) {
_primType = t;
}

GLdouble* tessVerticesBackPtr() {
return &(_tessVertices.back().x);
}
Expand Down