@@ -429,15 +429,9 @@ class RendererGL extends Renderer {
429
429
this . scratchMat3 = new Matrix ( 3 ) ;
430
430
431
431
this . isStencilTestOn = false ; // Track stencil test state
432
- this . _userEnabledStencil = false ; // Track whether user enabled stencil
433
- // Override WebGL enable function
434
432
const prevEnable = this . drawingContext . enable ;
435
433
this . drawingContext . enable = ( key ) => {
436
434
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
- }
441
435
this . isStencilTestOn = true ;
442
436
}
443
437
return prevEnable . call ( this . drawingContext , key ) ;
@@ -449,12 +443,13 @@ class RendererGL extends Renderer {
449
443
if ( key === this . drawingContext . STENCIL_TEST ) {
450
444
// When pop() disables the stencil test after clip(),
451
445
// 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 ;
458
453
}
459
454
return prevDisable . call ( this . drawingContext , key ) ;
460
455
} ;
@@ -1430,7 +1425,7 @@ class RendererGL extends Renderer {
1430
1425
this . drawTarget ( ) . _isClipApplied = true ;
1431
1426
1432
1427
const gl = this . GL ;
1433
- this . _savedStencilTestState = this . _userEnabledStencil ;
1428
+ this . isStencilTestOn = this . drawingContext . getEnabled ( this . drawingContext . STENCIL_TEST ) ;
1434
1429
gl . clearStencil ( 0 ) ;
1435
1430
gl . clear ( gl . STENCIL_BUFFER_BIT ) ;
1436
1431
gl . enable ( gl . STENCIL_TEST ) ;
@@ -1783,11 +1778,11 @@ class RendererGL extends Renderer {
1783
1778
this . _pushPopDepth === this . _clipDepths [ this . _clipDepths . length - 1 ]
1784
1779
) {
1785
1780
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 ) ;
1788
1785
}
1789
-
1790
- this . _userEnabledStencil = this . _savedStencilTestState ;
1791
1786
}
1792
1787
super . pop ( ...args ) ;
1793
1788
this . _applyStencilTestIfClipping ( ) ;
0 commit comments