From c934737d9e58e15bd48933ac9d08d29d88600c51 Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Fri, 25 Apr 2008 02:11:29 -0800 Subject: [PATCH] Add a function to combine vertices while tesselating the polygon, so that OpenGL can fill self-intersecting polygons. [git-p4: depot-paths = "//depot/solvespace/": change = 1688] --- expr.h | 3 +++ glhelper.cpp | 11 +++++++++++ solvespace.cpp | 2 +- solvespace.h | 4 ++-- win32/w32main.cpp | 13 ++++++------- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/expr.h b/expr.h index 80a3bee..8916f44 100644 --- a/expr.h +++ b/expr.h @@ -53,6 +53,9 @@ public: char c; } x; + static inline Expr *AllocExpr(void) + { return (Expr *)AllocTemporary(sizeof(Expr)); } + static Expr *FromParam(hParam p); static Expr *FromConstant(double v); diff --git a/glhelper.cpp b/glhelper.cpp index 57fd568..3078310 100644 --- a/glhelper.cpp +++ b/glhelper.cpp @@ -82,6 +82,16 @@ void glxColor4d(double r, double g, double b, double a) static void __stdcall Vertex(Vector *p) { glxVertex3v(*p); } +static void __stdcall Combine(double coords[3], void *vertexData[4], + float weight[4], void **outData) +{ + Vector *n = (Vector *)AllocTemporary(sizeof(Vector)); + n->x = coords[0]; + n->y = coords[1]; + n->z = coords[2]; + + *outData = n; +} void glxFillPolygon(SPolygon *p) { int i, j; @@ -91,6 +101,7 @@ void glxFillPolygon(SPolygon *p) gluTessCallback(gt, GLU_TESS_BEGIN, (cf *)glBegin); gluTessCallback(gt, GLU_TESS_END, (cf *)glEnd); gluTessCallback(gt, GLU_TESS_VERTEX, (cf *)Vertex); + gluTessCallback(gt, GLU_TESS_COMBINE, (cf *)Combine); gluTessProperty(gt, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); gluTessBeginPolygon(gt, NULL); diff --git a/solvespace.cpp b/solvespace.cpp index 1967113..60b8d71 100644 --- a/solvespace.cpp +++ b/solvespace.cpp @@ -102,7 +102,7 @@ bool SolveSpace::SolveGroup(hGroup hg) { } bool r = sys.Solve(); - FreeAllExprs(); + FreeAllTemporary(); return r; } diff --git a/solvespace.h b/solvespace.h index cd3f0d3..d43e89e 100644 --- a/solvespace.h +++ b/solvespace.h @@ -48,8 +48,8 @@ void PaintGraphics(void); void dbp(char *str, ...); void Error(char *str, ...); -Expr *AllocExpr(void); -void FreeAllExprs(void); +void *AllocTemporary(int n); +void FreeAllTemporary(void); void *MemRealloc(void *p, int n); void *MemAlloc(int n); void MemFree(void *p); diff --git a/win32/w32main.cpp b/win32/w32main.cpp index 6295407..80c6bba 100644 --- a/win32/w32main.cpp +++ b/win32/w32main.cpp @@ -69,15 +69,14 @@ void Error(char *str, ...) // at the end. //----------------------------------------------------------------------------- static HANDLE Heap; -Expr *AllocExpr(void) +void *AllocTemporary(int n) { - Expr *v = (Expr *)HeapAlloc(Heap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, - sizeof(Expr)); + Expr *v = (Expr *)HeapAlloc(Heap, HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY, n); if(!v) oops(); - memset(v, 0, sizeof(*v)); + memset(v, 0, n); return v; } -void FreeAllExprs(void) +void FreeAllTemporary(void) { if(Heap) HeapDestroy(Heap); Heap = HeapCreate(HEAP_NO_SERIALIZE, 1024*1024*20, 0); @@ -735,8 +734,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, ThawWindowPos(TextWnd); ThawWindowPos(GraphicsWnd); - // Create the heap that we use to store Exprs. - FreeAllExprs(); + // Create the heap that we use to store Exprs and other temp stuff. + FreeAllTemporary(); // Call in to the platform-independent code, and let them do their init SS.Init(lpCmdLine);