Skip to content

Commit 2e88c82

Browse files
committed
updated beginClip and pop
1 parent b42d2a1 commit 2e88c82

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,9 @@ class RendererGL extends Renderer {
429429
this.scratchMat3 = new Matrix(3);
430430

431431
this.isStencilTestOn = false; // Track stencil test state
432-
this._userEnabledStencil = false; // Track whether user enabled stencil
433-
// Override WebGL enable function
434432
const prevEnable = this.drawingContext.enable;
435433
this.drawingContext.enable = (key) => {
436434
if (key === this.drawingContext.STENCIL_TEST) {
437-
// When clip() calls enable(), don't mark as user-enabled
438-
if (!this._clipping) {
439-
this._userEnabledStencil = true;
440-
}
441435
this.isStencilTestOn = true;
442436
}
443437
return prevEnable.call(this.drawingContext, key);
@@ -449,12 +443,13 @@ class RendererGL extends Renderer {
449443
if (key === this.drawingContext.STENCIL_TEST) {
450444
// When pop() disables the stencil test after clip(),
451445
// restore the user's stencil test setting
452-
if (this._clipDepth === this._pushPopDepth) {
453-
this.isStencilTestOn = this._userEnabledStencil;
454-
} else {
455-
this.isStencilTestOn = false;
456-
this._userEnabledStencil = false;
457-
}
446+
// if (this._clipDepth === this._pushPopDepth) {
447+
// this.isStencilTestOn = this._userEnabledStencil;
448+
// } else {
449+
// this.isStencilTestOn = false;
450+
// this._userEnabledStencil = false;
451+
// }
452+
this.isStencilTestOn = false;
458453
}
459454
return prevDisable.call(this.drawingContext, key);
460455
};
@@ -1430,7 +1425,7 @@ class RendererGL extends Renderer {
14301425
this.drawTarget()._isClipApplied = true;
14311426

14321427
const gl = this.GL;
1433-
this._savedStencilTestState = this._userEnabledStencil;
1428+
this.isStencilTestOn = this.drawingContext.getEnabled(this.drawingContext.STENCIL_TEST);
14341429
gl.clearStencil(0);
14351430
gl.clear(gl.STENCIL_BUFFER_BIT);
14361431
gl.enable(gl.STENCIL_TEST);
@@ -1783,11 +1778,11 @@ class RendererGL extends Renderer {
17831778
this._pushPopDepth === this._clipDepths[this._clipDepths.length - 1]
17841779
) {
17851780
this._clearClip();
1786-
if (!this._savedStencilTestState) {
1787-
this.GL.disable(this.GL.STENCIL_TEST);
1781+
if (this.isStencilTestOn) {
1782+
this.GL.enable(this.GL.STENCIL_TEST);
1783+
} else {
1784+
this.GL.disable(this.GL.STENCIL_TEST);
17881785
}
1789-
1790-
this._userEnabledStencil = this._savedStencilTestState;
17911786
}
17921787
super.pop(...args);
17931788
this._applyStencilTestIfClipping();

0 commit comments

Comments
 (0)