From 40ed4a6c75a46f3a0fa895ee554a5bd86cfd5af9 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Sat, 21 Dec 2024 17:19:49 -0500 Subject: [PATCH 1/2] Fix noErase() breaking in WebGL --- src/webgl/material.js | 4 +-- src/webgl/p5.RendererGL.js | 1 + test/unit/visual/cases/webgl.js | 29 ++++++++++++++++++ .../WebGL/erase()/on a framebuffer/000.png | Bin 0 -> 319 bytes .../erase()/on a framebuffer/metadata.json | 3 ++ .../WebGL/erase()/on the main canvas/000.png | Bin 0 -> 367 bytes .../erase()/on the main canvas/metadata.json | 3 ++ 7 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 test/unit/visual/screenshots/WebGL/erase()/on a framebuffer/000.png create mode 100644 test/unit/visual/screenshots/WebGL/erase()/on a framebuffer/metadata.json create mode 100644 test/unit/visual/screenshots/WebGL/erase()/on the main canvas/000.png create mode 100644 test/unit/visual/screenshots/WebGL/erase()/on the main canvas/metadata.json diff --git a/src/webgl/material.js b/src/webgl/material.js index 3fdb3733cd..28d6174a79 100644 --- a/src/webgl/material.js +++ b/src/webgl/material.js @@ -3683,9 +3683,7 @@ function material(p5, fn){ ); break; } - if (!this._isErasing) { - this._cachedBlendMode = this.states.curBlendMode; - } + this._cachedBlendMode = this.states.curBlendMode; }; RendererGL.prototype.shader = function(s) { diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index b6b90984af..33b72bb464 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1329,6 +1329,7 @@ class RendererGL extends Renderer { // Restore blend mode this.states.curBlendMode = this.preEraseBlend; this.blendMode(this.preEraseBlend); + console.log(this.preEraseBlend, this._cachedBlendMode) // Ensure that _applyBlendMode() sets preEraseBlend back to the original blend mode this._isErasing = false; this._applyBlendMode(); diff --git a/test/unit/visual/cases/webgl.js b/test/unit/visual/cases/webgl.js index e503f80981..14d354d500 100644 --- a/test/unit/visual/cases/webgl.js +++ b/test/unit/visual/cases/webgl.js @@ -533,4 +533,33 @@ visualSuite('WebGL', function() { screenshot(); }); }); + + visualSuite('erase()', () => { + visualTest('on the main canvas', (p5, screenshot) => { + p5.createCanvas(50, 50, p5.WEBGL); + p5.background(0); + p5.fill('red'); + p5.rect(-20, -20, 40, 40); + p5.erase(); + p5.circle(0, 0, 10); + p5.noErase(); + screenshot(); + }); + + visualTest('on a framebuffer', (p5, screenshot) => { + p5.createCanvas(50, 50, p5.WEBGL); + p5.background(0); + const fbo = p5.createFramebuffer(); + fbo.begin(); + p5.fill('red'); + p5.rect(-20, -20, 40, 40); + p5.erase(); + p5.circle(0, 0, 10); + p5.noErase(); + fbo.end(); + p5.imageMode(p5.CENTER); + p5.image(fbo, 0, 0); + screenshot(); + }); + }); }); diff --git a/test/unit/visual/screenshots/WebGL/erase()/on a framebuffer/000.png b/test/unit/visual/screenshots/WebGL/erase()/on a framebuffer/000.png new file mode 100644 index 0000000000000000000000000000000000000000..39c1f8259713e95cb48cb17a26918874c16fd7cf GIT binary patch literal 319 zcmV-F0l@x=P)Px#`AI}URA@u(nn4l*Aq)iBm#Z&Vb4V2jD4DPfks8jC(9@u}dX-Y%<$!SsB$-7S zNhYK;jXblhvRY4XZC#K@Qkd6wT`d@a>=Gs;yOQtql@S?Plz_I@qF}?*%1Ai6MK6?* znP4qFA9r0ssYV>2bxWOnKtKcOHLA_dz@!2(s3;5tWWIR?bePvi|CosrZawr%XY z^T;>`B=s3_6ThrPZP@&jGg5D<7L0#DMh>~pO$VtP-+4{h1~PK+ks5&@X)$VLgpo4R zLq?Fa7_~CONEzuNBS>0|S{Y%ajP!tv*u?+#6Se;NfNTdwt&A{IMtU4$Px$DM>^@RA@u(nqdxtFbsv?PNtkpIhlB}xhf=zi*&`6WqD2bH`w0$YD0?wKtu-- zD5NopB+?iVWQm*s$kk#@>1=YXBP-;ZD!`>h6#&L`E;%2Cv;v4kS|PEVgG5NAk^@Yw zO2(QWOCo0LD&0sTJB<|smpJ|7rP`aw6o6rELVR@x@?vf75SuGc}?VQdoYwNi7-6$Ux&~%w Date: Sat, 21 Dec 2024 17:25:02 -0500 Subject: [PATCH 2/2] Remove log --- 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 33b72bb464..b6b90984af 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1329,7 +1329,6 @@ class RendererGL extends Renderer { // Restore blend mode this.states.curBlendMode = this.preEraseBlend; this.blendMode(this.preEraseBlend); - console.log(this.preEraseBlend, this._cachedBlendMode) // Ensure that _applyBlendMode() sets preEraseBlend back to the original blend mode this._isErasing = false; this._applyBlendMode();