Skip to content

Commit 0be8f2c

Browse files
Isaac Garzonruevs
authored andcommitted
render: remove a call to AllocTemporary() from the OpenGL 1 renderer
This needlessly uses the global temporary arena, when the lifetime can be managed by replacing `GLU_TESS_COMBINE` with `GLU_TESS_COMBINE_DATA` instead. While the use of the global temporary arena is mostly harmless, having it around needlessly prevents restricting the arena's scope to the sketch in a possible future where the global sketch is removed. Additionally, it means that calls to `FreeAllTemporary()` must synchronise with the renderer, which is a needless restriction on the users of the arena given the fact that none of the other renderers use it.
1 parent bd7b627 commit 0be8f2c

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/render/rendergl1.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,34 +557,39 @@ void OpenGl1Renderer::DrawPoint(const Vector &o, Canvas::hStroke hcs) {
557557
#endif
558558
typedef void(SSGL_CALLBACK *GLUCallback)();
559559

560+
using CombineVec = std::vector<std::unique_ptr<Vector>>;
561+
560562
static void SSGL_CALLBACK Vertex(Vector *p) {
561563
ssglVertex3v(*p);
562564
}
563565
static void SSGL_CALLBACK Combine(double coords[3], void *vertexData[4],
564-
float weight[4], void **outData) {
565-
Vector *n = (Vector *)AllocTemporary(sizeof(Vector));
566+
float weight[4], void **outData, void *inData) {
567+
Vector *n = new Vector;
566568
n->x = coords[0];
567569
n->y = coords[1];
568570
n->z = coords[2];
569571

570572
*outData = n;
573+
CombineVec *vec = static_cast<CombineVec *>(inData);
574+
vec->emplace_back(n);
571575
}
572576
void OpenGl1Renderer::DrawPolygon(const SPolygon &p, hFill hcf) {
573577
UnSelectPrimitive();
574578
SelectFill(hcf);
575579

576580
GLUtesselator *gt = gluNewTess();
577-
gluTessCallback(gt, GLU_TESS_BEGIN, (GLUCallback) glBegin);
578-
gluTessCallback(gt, GLU_TESS_VERTEX, (GLUCallback) Vertex);
579-
gluTessCallback(gt, GLU_TESS_END, (GLUCallback) glEnd);
580-
gluTessCallback(gt, GLU_TESS_COMBINE, (GLUCallback) Combine);
581+
gluTessCallback(gt, GLU_TESS_BEGIN, (GLUCallback) glBegin);
582+
gluTessCallback(gt, GLU_TESS_VERTEX, (GLUCallback) Vertex);
583+
gluTessCallback(gt, GLU_TESS_END, (GLUCallback) glEnd);
584+
gluTessCallback(gt, GLU_TESS_COMBINE_DATA, (GLUCallback) Combine);
581585

582586
gluTessProperty(gt, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
583587

584588
ssglNormal3v(p.normal);
585589
gluTessNormal(gt, p.normal.x, p.normal.y, p.normal.z);
586590

587-
gluTessBeginPolygon(gt, NULL);
591+
CombineVec vecs;
592+
gluTessBeginPolygon(gt, &vecs);
588593
for(const SContour &sc : p.l) {
589594
gluTessBeginContour(gt);
590595
for(const SPoint &sp : sc.l) {

0 commit comments

Comments
 (0)