static int EmptyCache( fastuidraw_GLUtesselator *tess ) { CachedVertex *v = tess->cache; CachedVertex *vLast; tess->mesh = glu_fastuidraw_gl_meshNewMesh(); if (tess->mesh == NULL) return 0; for( vLast = v + tess->cacheCount; v < vLast; ++v ) { if ( !AddVertex( tess, v->s, v->t, v->client_id ) ) return 0; } tess->cacheCount = 0; tess->emptyCache = FALSE; return 1; }
GLUmesh *glu_fastuidraw_gl_copyMesh(GLUmesh *mesh) { /* copy the mesh which means get all the pointer copying correct */ GLUmesh *return_value; std::vector<GLUface*> tmp_faces; std::vector<GLUvertex*> tmp_verts; std::vector<EdgePair*> tmp_edges; return_value = glu_fastuidraw_gl_meshNewMesh(); mesh->vHead.unique_id = 0; return_value->vHead = mesh->vHead; tmp_verts.push_back(&return_value->vHead); mesh->fHead.unique_id = 0; return_value->fHead = mesh->fHead; tmp_faces.push_back(&return_value->fHead); mesh->eHead.unique_id = 0; mesh->eHeadSym.unique_id = 0; return_value->eHead = mesh->eHead; return_value->eHeadSym = mesh->eHeadSym; tmp_edges.push_back((EdgePair*)(&return_value->eHead)); /* assign each element a unique id and copy each element */ for( GLUface *f = mesh->fHead.next; f != &mesh->fHead; f = f->next ) { f->unique_id = tmp_faces.size(); tmp_faces.push_back(copy_mesh_element(f)); } for( GLUvertex *v = mesh->vHead.next; v != &mesh->vHead; v = v->next ) { v->unique_id = tmp_verts.size(); tmp_verts.push_back(copy_mesh_element(v)); } for( GLUhalfEdge *e = mesh->eHead.next; e != &mesh->eHead; e = e->next ) { EdgePair E; e->unique_id = tmp_edges.size(); e->Sym->unique_id = tmp_edges.size(); E.e = *e; E.eSym = *e->Sym; tmp_edges.push_back(copy_mesh_element(&E)); } /* now walk through all the elements and set the pointers correctly */ for (GLUface *f : tmp_faces) { f->next = select_mesh_element(f->next, tmp_faces); f->prev = select_mesh_element(f->prev, tmp_faces); f->anEdge = select_half_edge(f->anEdge, tmp_edges); f->trail = select_mesh_element(f->trail, tmp_faces); } for (GLUvertex *v : tmp_verts) { v->next = select_mesh_element(v->next, tmp_verts); v->prev = select_mesh_element(v->prev, tmp_verts); v->anEdge = select_half_edge(v->anEdge, tmp_edges); } for (EdgePair *E : tmp_edges) { GLUhalfEdge *e; e = &E->e; e->next = select_half_edge(e->next, tmp_edges); e->Sym = select_half_edge(e->Sym, tmp_edges); e->Onext = select_half_edge(e->Onext, tmp_edges); e->Lnext = select_half_edge(e->Lnext, tmp_edges); e->Org = select_mesh_element(e->Org, tmp_verts); e->Lface = select_mesh_element(e->Lface, tmp_faces); e->activeRegion = nullptr; e = &E->eSym; e->next = select_half_edge(e->next, tmp_edges); e->Sym = select_half_edge(e->Sym, tmp_edges); e->Onext = select_half_edge(e->Onext, tmp_edges); e->Lnext = select_half_edge(e->Lnext, tmp_edges); e->Org = select_mesh_element(e->Org, tmp_verts); e->Lface = select_mesh_element(e->Lface, tmp_faces); e->activeRegion = nullptr; } return return_value; }