Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/webgl/3d_primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ function primitives3D(p5, fn){

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

this._drawGeometry(this.geometryBufferCache.getGeometryByID(gid));
this.model(this.geometryBufferCache.getGeometryByID(gid));
} finally {
this.states.setValue('uModelMatrix', uModelMatrix);
}
Expand Down Expand Up @@ -1858,7 +1858,7 @@ function primitives3D(p5, fn){
this.states.uModelMatrix.translate([x, y, 0]);
this.states.uModelMatrix.scale(width, height, 1);

this._drawGeometry(this.geometryBufferCache.getGeometryByID(gid));
this.model(this.geometryBufferCache.getGeometryByID(gid));
} finally {
this.states.setValue('uModelMatrix', uModelMatrix);
}
Expand Down Expand Up @@ -1919,7 +1919,7 @@ function primitives3D(p5, fn){
this.states.uModelMatrix.translate([x, y, 0]);
this.states.uModelMatrix.scale(width, height, 1);

this._drawGeometry(this.geometryBufferCache.getGeometryByID(gid));
this.model(this.geometryBufferCache.getGeometryByID(gid));
} finally {
this.states.setValue('uModelMatrix', uModelMatrix);
}
Expand Down Expand Up @@ -2069,7 +2069,7 @@ function primitives3D(p5, fn){
quadGeom.gid = gid;
this.geometryBufferCache.ensureCached(quadGeom);
}
this._drawGeometry(this.geometryBufferCache.getGeometryByID(gid));
this.model(this.geometryBufferCache.getGeometryByID(gid));
return this;
};

Expand Down
6 changes: 5 additions & 1 deletion src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,11 @@ class RendererGL extends Renderer {
);
}
const geometry = this.geometryBuilder.finish();
this.fill(this.geometryBuilder.prevFillColor);
if (this.geometryBuilder.prevFillColor) {
this.fill(this.geometryBuilder.prevFillColor);
} else {
this.noFill();
}
this.geometryBuilder = undefined;
return geometry;
}
Expand Down
27 changes: 27 additions & 0 deletions test/unit/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -2950,4 +2950,31 @@ suite('p5.RendererGL', function() {
myp5.checkPMatrix();
});
});

suite('buildGeometry', function() {
test('captures geometry without drawing', function() {
myp5.createCanvas(10, 10, myp5.WEBGL);
myp5.background(255, 0, 0);
const geom = myp5.buildGeometry(() => myp5.circle(0, 0, 5));
expect(geom.vertices.length).toBeGreaterThan(0);
expect(myp5.get(5, 5)).toEqual([255, 0, 0, 255]);
});

test('returns fill state back to a previous color', function() {
myp5.createCanvas(10, 10, myp5.WEBGL);
myp5.background(255, 0, 0);
myp5.fill(0, 255, 0);
const geom = myp5.buildGeometry(() => myp5.circle(0, 0, 10));
myp5.model(geom);
expect(myp5.get(5, 5)).toEqual([0, 255, 0, 255]);
});
test('returns fill state back to no fill', function() {
myp5.createCanvas(10, 10, myp5.WEBGL);
myp5.background(255, 0, 0);
myp5.noFill();
const geom = myp5.buildGeometry(() => myp5.circle(0, 0, 10));
myp5.model(geom);
expect(myp5.get(5, 5)).toEqual([255, 0, 0, 255]);
});
});
});
Loading