Skip to content
Merged
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
34 changes: 22 additions & 12 deletions src/core/p5.Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ class Renderer {
this._clipInvert = false;

this._currentShape = undefined; // Lazily generate current shape

// Lazily cached by _individualTextureCoordinates(); initialized here
// (rather than computed) so subclasses can rely on their own
// constructor state when getSupportedIndividualVertexProperties()
// is first consulted.
this._supportsIndividualTextureCoordinates = undefined;
}

get currentShape() {
Expand Down Expand Up @@ -158,12 +164,22 @@ class Renderer {
}
}

bezierVertex(x, y, z = 0, u = 0, v = 0) {
const position = new Vector(x, y, z);
const textureCoordinates = this.getSupportedIndividualVertexProperties()
.textureCoordinates
// Builds the per-vertex texture-coordinates argument, caching whether
// the renderer supports them so the descriptor object isn't rebuilt on
// every vertex call.
_individualTextureCoordinates(u, v) {
if (this._supportsIndividualTextureCoordinates === undefined) {
this._supportsIndividualTextureCoordinates =
this.getSupportedIndividualVertexProperties().textureCoordinates;
}
return this._supportsIndividualTextureCoordinates
? new Vector(u, v)
: undefined;
}

bezierVertex(x, y, z = 0, u = 0, v = 0) {
const position = new Vector(x, y, z);
const textureCoordinates = this._individualTextureCoordinates(u, v);
this.currentShape.bezierVertex(position, textureCoordinates);
}

Expand All @@ -189,10 +205,7 @@ class Renderer {

splineVertex(x, y, z = 0, u = 0, v = 0) {
const position = new Vector(x, y, z);
const textureCoordinates = this.getSupportedIndividualVertexProperties()
.textureCoordinates
? new Vector(u, v)
: undefined;
const textureCoordinates = this._individualTextureCoordinates(u, v);
this.currentShape.splineVertex(position, textureCoordinates);
}

Expand Down Expand Up @@ -229,10 +242,7 @@ class Renderer {

vertex(x, y, z = 0, u = 0, v = 0) {
const position = new Vector(x, y, z);
const textureCoordinates = this.getSupportedIndividualVertexProperties()
.textureCoordinates
? new Vector(u, v)
: undefined;
const textureCoordinates = this._individualTextureCoordinates(u, v);
this.currentShape.vertex(position, textureCoordinates);
}

Expand Down
4 changes: 3 additions & 1 deletion src/core/p5.Renderer2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ class Renderer2D extends Renderer {

drawShape(shape) {
const visitor = new PrimitiveToPath2DConverter({
strokeWeight: this.states.strokeWeight
strokeWeight: this.states.strokeWeight,
hasFill: !this._clipping && !!this.states.fillColor,
hasStroke: !this._clipping && !!this.states.strokeColor
});
shape.accept(visitor);
if (this._clipping) {
Expand Down
Loading
Loading