From a7200809159c82f603c2baa6636ed70830dc5d24 Mon Sep 17 00:00:00 2001 From: Alejandro <121937906+acamposuribe@users.noreply.github.com> Date: Fri, 3 Nov 2023 18:10:22 +0100 Subject: [PATCH 1/4] Update p5.RendererGL.js Fix erase() and noErase() --- src/webgl/p5.RendererGL.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index 5e95a83088..1ed8f0f08d 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1180,7 +1180,9 @@ p5.RendererGL = class RendererGL extends p5.Renderer { erase(opacityFill, opacityStroke) { if (!this._isErasing) { - this._applyBlendMode(constants.REMOVE); + this.currentBlendMode = this._cachedBlendMode; + this.blendMode(constants.REMOVE); + this._applyBlendMode(); this._isErasing = true; this._cachedFillStyle = this.curFillColor.slice(); @@ -1196,7 +1198,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer { this._isErasing = false; this.curFillColor = this._cachedFillStyle.slice(); this.curStrokeColor = this._cachedStrokeStyle.slice(); - this.blendMode(this._cachedBlendMode); + this.blendMode(this.currentBlendMode); } } From 8f3fea91cea241e16aac462b8de312a36e32179e Mon Sep 17 00:00:00 2001 From: Alejandro Date: Fri, 3 Nov 2023 20:21:05 +0100 Subject: [PATCH 2/4] Fix erase() and noErase() in webgl --- src/webgl/p5.RendererGL.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index 1ed8f0f08d..97b174e580 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1180,14 +1180,12 @@ p5.RendererGL = class RendererGL extends p5.Renderer { erase(opacityFill, opacityStroke) { if (!this._isErasing) { - this.currentBlendMode = this._cachedBlendMode; + this._cachedBlendMode = this.curBlendMode; + this._isErasing = true; this.blendMode(constants.REMOVE); this._applyBlendMode(); - this._isErasing = true; - this._cachedFillStyle = this.curFillColor.slice(); this.curFillColor = [1, 1, 1, opacityFill / 255]; - this._cachedStrokeStyle = this.curStrokeColor.slice(); this.curStrokeColor = [1, 1, 1, opacityStroke / 255]; } @@ -1195,10 +1193,14 @@ p5.RendererGL = class RendererGL extends p5.Renderer { noErase() { if (this._isErasing) { - this._isErasing = false; this.curFillColor = this._cachedFillStyle.slice(); this.curStrokeColor = this._cachedStrokeStyle.slice(); - this.blendMode(this.currentBlendMode); + // It's necessary to restore post-erase state. Needs rework + let temp = this.curBlendMode; + this.blendMode(this._cachedBlendMode); + this._cachedBlendMode = temp; // If we don't do this, appleBlendMode() returns null + this._isErasing = false; + this._applyBlendMode(); // This sets _cachedBlendMode back to the original blendmode } } From 0df9212b08872538f3b474a9954e890361c75644 Mon Sep 17 00:00:00 2001 From: Alejandro Date: Fri, 3 Nov 2023 20:22:20 +0100 Subject: [PATCH 3/4] Fix erase and noErase in webgl --- src/webgl/p5.RendererGL.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index 97b174e580..9b6d3fbded 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1198,7 +1198,7 @@ p5.RendererGL = class RendererGL extends p5.Renderer { // It's necessary to restore post-erase state. Needs rework let temp = this.curBlendMode; this.blendMode(this._cachedBlendMode); - this._cachedBlendMode = temp; // If we don't do this, appleBlendMode() returns null + this._cachedBlendMode = temp; // If we don't do this, applyBlendMode() returns null this._isErasing = false; this._applyBlendMode(); // This sets _cachedBlendMode back to the original blendmode } From ee2c13dd34cf0b1302d3d5d956209091e3e5bbfb Mon Sep 17 00:00:00 2001 From: Alejandro Date: Fri, 3 Nov 2023 20:25:08 +0100 Subject: [PATCH 4/4] Fix erase() and noErase() in webgl --- src/webgl/p5.RendererGL.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index 9b6d3fbded..2eaa885c11 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1183,7 +1183,6 @@ p5.RendererGL = class RendererGL extends p5.Renderer { this._cachedBlendMode = this.curBlendMode; this._isErasing = true; this.blendMode(constants.REMOVE); - this._applyBlendMode(); this._cachedFillStyle = this.curFillColor.slice(); this.curFillColor = [1, 1, 1, opacityFill / 255]; this._cachedStrokeStyle = this.curStrokeColor.slice();