Skip to content

Commit

Permalink
Merge pull request #6524 from acamposuribe/fix_webgl_erase
Browse files Browse the repository at this point in the history
Fix webgl erase. Resolves #6523
  • Loading branch information
davepagurek committed Nov 3, 2023
2 parents 39b50ec + ee2c13d commit c0af525
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/webgl/p5.RendererGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,23 +1180,26 @@ p5.RendererGL = class RendererGL extends p5.Renderer {

erase(opacityFill, opacityStroke) {
if (!this._isErasing) {
this._applyBlendMode(constants.REMOVE);
this._cachedBlendMode = this.curBlendMode;
this._isErasing = true;

this.blendMode(constants.REMOVE);
this._cachedFillStyle = this.curFillColor.slice();
this.curFillColor = [1, 1, 1, opacityFill / 255];

this._cachedStrokeStyle = this.curStrokeColor.slice();
this.curStrokeColor = [1, 1, 1, opacityStroke / 255];
}
}

noErase() {
if (this._isErasing) {
this._isErasing = false;
this.curFillColor = this._cachedFillStyle.slice();
this.curStrokeColor = this._cachedStrokeStyle.slice();
// 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, applyBlendMode() returns null
this._isErasing = false;
this._applyBlendMode(); // This sets _cachedBlendMode back to the original blendmode
}
}

Expand Down

0 comments on commit c0af525

Please sign in to comment.