Skip to content

Commit 38abe63

Browse files
committed
fixed breaking the tests
1 parent 2e88c82 commit 38abe63

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/webgl/p5.RendererGL.js

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -429,27 +429,29 @@ 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
432434
const prevEnable = this.drawingContext.enable;
433435
this.drawingContext.enable = (key) => {
434-
if (key === this.drawingContext.STENCIL_TEST) {
435-
this.isStencilTestOn = true;
436-
}
437-
return prevEnable.call(this.drawingContext, key);
436+
if (key === this.drawingContext.STENCIL_TEST) {
437+
if (!this._clipping) {
438+
this._userEnabledStencil = true;
439+
}
440+
this.isStencilTestOn = true;
441+
}
442+
return prevEnable.call(this.drawingContext, key);
438443
};
439444

440445
// Override WebGL disable function
441446
const prevDisable = this.drawingContext.disable;
442447
this.drawingContext.disable = (key) => {
443448
if (key === this.drawingContext.STENCIL_TEST) {
444-
// When pop() disables the stencil test after clip(),
445-
// restore the user's stencil test setting
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;
449+
if (this._clipDepth === this._pushPopDepth) {
450+
this.isStencilTestOn = this._userEnabledStencil;
451+
} else {
452+
this.isStencilTestOn = false;
453+
this._userEnabledStencil = false;
454+
}
453455
}
454456
return prevDisable.call(this.drawingContext, key);
455457
};
@@ -1425,7 +1427,9 @@ class RendererGL extends Renderer {
14251427
this.drawTarget()._isClipApplied = true;
14261428

14271429
const gl = this.GL;
1428-
this.isStencilTestOn = this.drawingContext.getEnabled(this.drawingContext.STENCIL_TEST);
1430+
this._savedStencilTestState = this._userEnabledStencil;
1431+
this._preClipStencilState = this.drawingContext.getEnabled(this.drawingContext.STENCIL_TEST);
1432+
// this.isStencilTestOn = this.drawingContext.getEnabled(this.drawingContext.STENCIL_TEST);
14291433
gl.clearStencil(0);
14301434
gl.clear(gl.STENCIL_BUFFER_BIT);
14311435
gl.enable(gl.STENCIL_TEST);
@@ -1778,11 +1782,22 @@ class RendererGL extends Renderer {
17781782
this._pushPopDepth === this._clipDepths[this._clipDepths.length - 1]
17791783
) {
17801784
this._clearClip();
1781-
if (this.isStencilTestOn) {
1785+
// if (this.isStencilTestOn) {
1786+
// this.GL.enable(this.GL.STENCIL_TEST);
1787+
// } else {
1788+
// this.GL.disable(this.GL.STENCIL_TEST);
1789+
// }
1790+
// if (!this._savedStencilTestState) {
1791+
// this.GL.disable(this.GL.STENCIL_TEST);
1792+
// }
1793+
if (this._preClipStencilState) {
17821794
this.GL.enable(this.GL.STENCIL_TEST);
17831795
} else {
17841796
this.GL.disable(this.GL.STENCIL_TEST);
17851797
}
1798+
1799+
// Reset saved state
1800+
this._userEnabledStencil = this._savedStencilTestState;
17861801
}
17871802
super.pop(...args);
17881803
this._applyStencilTestIfClipping();

0 commit comments

Comments
 (0)