Skip to content

Commit 40ed4a6

Browse files
committed
Fix noErase() breaking in WebGL
1 parent e03060a commit 40ed4a6

File tree

7 files changed

+37
-3
lines changed

7 files changed

+37
-3
lines changed

src/webgl/material.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3683,9 +3683,7 @@ function material(p5, fn){
36833683
);
36843684
break;
36853685
}
3686-
if (!this._isErasing) {
3687-
this._cachedBlendMode = this.states.curBlendMode;
3688-
}
3686+
this._cachedBlendMode = this.states.curBlendMode;
36893687
};
36903688

36913689
RendererGL.prototype.shader = function(s) {

src/webgl/p5.RendererGL.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ class RendererGL extends Renderer {
13291329
// Restore blend mode
13301330
this.states.curBlendMode = this.preEraseBlend;
13311331
this.blendMode(this.preEraseBlend);
1332+
console.log(this.preEraseBlend, this._cachedBlendMode)
13321333
// Ensure that _applyBlendMode() sets preEraseBlend back to the original blend mode
13331334
this._isErasing = false;
13341335
this._applyBlendMode();

test/unit/visual/cases/webgl.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,33 @@ visualSuite('WebGL', function() {
533533
screenshot();
534534
});
535535
});
536+
537+
visualSuite('erase()', () => {
538+
visualTest('on the main canvas', (p5, screenshot) => {
539+
p5.createCanvas(50, 50, p5.WEBGL);
540+
p5.background(0);
541+
p5.fill('red');
542+
p5.rect(-20, -20, 40, 40);
543+
p5.erase();
544+
p5.circle(0, 0, 10);
545+
p5.noErase();
546+
screenshot();
547+
});
548+
549+
visualTest('on a framebuffer', (p5, screenshot) => {
550+
p5.createCanvas(50, 50, p5.WEBGL);
551+
p5.background(0);
552+
const fbo = p5.createFramebuffer();
553+
fbo.begin();
554+
p5.fill('red');
555+
p5.rect(-20, -20, 40, 40);
556+
p5.erase();
557+
p5.circle(0, 0, 10);
558+
p5.noErase();
559+
fbo.end();
560+
p5.imageMode(p5.CENTER);
561+
p5.image(fbo, 0, 0);
562+
screenshot();
563+
});
564+
});
536565
});
319 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}
367 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)