Skip to content

Commit 70a16cb

Browse files
authored
Merge pull request #8185 from processing/fix/buildgeometry
Fix bugs in buildGeometry
2 parents 69536d8 + c978f11 commit 70a16cb

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/webgl/3d_primitives.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ function primitives3D(p5, fn){
17261726

17271727
this.states.setValue('uModelMatrix', mult);
17281728

1729-
this._drawGeometry(this.geometryBufferCache.getGeometryByID(gid));
1729+
this.model(this.geometryBufferCache.getGeometryByID(gid));
17301730
} finally {
17311731
this.states.setValue('uModelMatrix', uModelMatrix);
17321732
}
@@ -1858,7 +1858,7 @@ function primitives3D(p5, fn){
18581858
this.states.uModelMatrix.translate([x, y, 0]);
18591859
this.states.uModelMatrix.scale(width, height, 1);
18601860

1861-
this._drawGeometry(this.geometryBufferCache.getGeometryByID(gid));
1861+
this.model(this.geometryBufferCache.getGeometryByID(gid));
18621862
} finally {
18631863
this.states.setValue('uModelMatrix', uModelMatrix);
18641864
}
@@ -1919,7 +1919,7 @@ function primitives3D(p5, fn){
19191919
this.states.uModelMatrix.translate([x, y, 0]);
19201920
this.states.uModelMatrix.scale(width, height, 1);
19211921

1922-
this._drawGeometry(this.geometryBufferCache.getGeometryByID(gid));
1922+
this.model(this.geometryBufferCache.getGeometryByID(gid));
19231923
} finally {
19241924
this.states.setValue('uModelMatrix', uModelMatrix);
19251925
}
@@ -2069,7 +2069,7 @@ function primitives3D(p5, fn){
20692069
quadGeom.gid = gid;
20702070
this.geometryBufferCache.ensureCached(quadGeom);
20712071
}
2072-
this._drawGeometry(this.geometryBufferCache.getGeometryByID(gid));
2072+
this.model(this.geometryBufferCache.getGeometryByID(gid));
20732073
return this;
20742074
};
20752075

src/webgl/p5.RendererGL.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,11 @@ class RendererGL extends Renderer {
511511
);
512512
}
513513
const geometry = this.geometryBuilder.finish();
514-
this.fill(this.geometryBuilder.prevFillColor);
514+
if (this.geometryBuilder.prevFillColor) {
515+
this.fill(this.geometryBuilder.prevFillColor);
516+
} else {
517+
this.noFill();
518+
}
515519
this.geometryBuilder = undefined;
516520
return geometry;
517521
}

test/unit/webgl/p5.RendererGL.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,4 +2950,31 @@ suite('p5.RendererGL', function() {
29502950
myp5.checkPMatrix();
29512951
});
29522952
});
2953+
2954+
suite('buildGeometry', function() {
2955+
test('captures geometry without drawing', function() {
2956+
myp5.createCanvas(10, 10, myp5.WEBGL);
2957+
myp5.background(255, 0, 0);
2958+
const geom = myp5.buildGeometry(() => myp5.circle(0, 0, 5));
2959+
expect(geom.vertices.length).toBeGreaterThan(0);
2960+
expect(myp5.get(5, 5)).toEqual([255, 0, 0, 255]);
2961+
});
2962+
2963+
test('returns fill state back to a previous color', function() {
2964+
myp5.createCanvas(10, 10, myp5.WEBGL);
2965+
myp5.background(255, 0, 0);
2966+
myp5.fill(0, 255, 0);
2967+
const geom = myp5.buildGeometry(() => myp5.circle(0, 0, 10));
2968+
myp5.model(geom);
2969+
expect(myp5.get(5, 5)).toEqual([0, 255, 0, 255]);
2970+
});
2971+
test('returns fill state back to no fill', function() {
2972+
myp5.createCanvas(10, 10, myp5.WEBGL);
2973+
myp5.background(255, 0, 0);
2974+
myp5.noFill();
2975+
const geom = myp5.buildGeometry(() => myp5.circle(0, 0, 10));
2976+
myp5.model(geom);
2977+
expect(myp5.get(5, 5)).toEqual([255, 0, 0, 255]);
2978+
});
2979+
});
29532980
});

0 commit comments

Comments
 (0)