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]
This commit is contained in:
Jonathan Westhues 2008-04-25 02:11:29 -08:00
parent ebdef1818c
commit c934737d9e
5 changed files with 23 additions and 10 deletions

3
expr.h
View File

@ -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);

View File

@ -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);

View File

@ -102,7 +102,7 @@ bool SolveSpace::SolveGroup(hGroup hg) {
}
bool r = sys.Solve();
FreeAllExprs();
FreeAllTemporary();
return r;
}

View File

@ -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);

View File

@ -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);