@@ -504,7 +504,7 @@ var WebGLRenderer = new Class({
504504 * @type {Phaser.Display.Masks.GeometryMask }
505505 * @since 3.17.0
506506 */
507- this . currentCameraMask = null ;
507+ this . currentCameraMask = { mask : null , camera : null } ;
508508
509509 this . init ( this . config ) ;
510510 } ,
@@ -1009,7 +1009,7 @@ var WebGLRenderer = new Class({
10091009 hasActiveStencilMask : function ( )
10101010 {
10111011 var mask = this . currentMask ;
1012- var camMask = this . currentCameraMask ;
1012+ var camMask = this . currentCameraMask . mask ;
10131013
10141014 return ( ( mask && mask . isStencil ) || ( camMask && camMask . isStencil ) ) ;
10151015 } ,
@@ -1754,13 +1754,6 @@ var WebGLRenderer = new Class({
17541754
17551755 this . pushScissor ( cx , cy , cw , - ch ) ;
17561756
1757- this . currentStencil = 0 ;
1758-
1759- if ( camera . mask )
1760- {
1761- camera . mask . preRenderWebGL ( this , camera , camera . _maskCamera ) ;
1762- }
1763-
17641757 this . setFramebuffer ( camera . framebuffer ) ;
17651758
17661759 var gl = this . gl ;
@@ -1771,6 +1764,14 @@ var WebGLRenderer = new Class({
17711764
17721765 TextureTintPipeline . projOrtho ( cx , cw + cx , cy , ch + cy , - 1000 , 1000 ) ;
17731766
1767+ if ( camera . mask )
1768+ {
1769+ this . currentCameraMask . mask = camera . mask ;
1770+ this . currentCameraMask . camera = camera . _maskCamera ;
1771+
1772+ camera . mask . preRenderWebGL ( this , camera , camera . _maskCamera ) ;
1773+ }
1774+
17741775 if ( color . alphaGL > 0 )
17751776 {
17761777 TextureTintPipeline . drawFillRect (
@@ -1788,7 +1789,8 @@ var WebGLRenderer = new Class({
17881789
17891790 if ( camera . mask )
17901791 {
1791- this . currentCameraMask = camera . mask ;
1792+ this . currentCameraMask . mask = camera . mask ;
1793+ this . currentCameraMask . camera = camera . _maskCamera ;
17921794
17931795 camera . mask . preRenderWebGL ( this , camera , camera . _maskCamera ) ;
17941796 }
@@ -1804,6 +1806,24 @@ var WebGLRenderer = new Class({
18041806 }
18051807 } ,
18061808
1809+ getCurrentStencilMask : function ( )
1810+ {
1811+ var prev = null ;
1812+ var stack = this . maskStack ;
1813+ var cameraMask = this . currentCameraMask ;
1814+
1815+ if ( stack . length > 0 )
1816+ {
1817+ prev = stack [ stack . length - 1 ] ;
1818+ }
1819+ else if ( cameraMask . mask && cameraMask . mask . isStencil )
1820+ {
1821+ prev = cameraMask ;
1822+ }
1823+
1824+ return prev ;
1825+ } ,
1826+
18071827 /**
18081828 * Controls the post-render operations for the given camera.
18091829 * Renders the foreground camera effects like flash and fading. It resets the current scissor state.
@@ -1866,7 +1886,7 @@ var WebGLRenderer = new Class({
18661886
18671887 if ( camera . mask )
18681888 {
1869- this . currentCameraMask = null ;
1889+ this . currentCameraMask . mask = null ;
18701890
18711891 camera . mask . postRenderWebGL ( this , camera . _maskCamera ) ;
18721892 }
@@ -1916,7 +1936,7 @@ var WebGLRenderer = new Class({
19161936 }
19171937
19181938 this . currentMask = null ;
1919- this . currentCameraMask = null ;
1939+ this . currentCameraMask . mask = null ;
19201940 this . maskStack . length = 0 ;
19211941
19221942 this . setPipeline ( this . pipelines . TextureTintPipeline ) ;
@@ -1972,19 +1992,15 @@ var WebGLRenderer = new Class({
19721992
19731993 var mask = child . mask ;
19741994
1975- if ( mask !== this . currentMask )
1995+ if ( this . currentMask && this . currentMask !== mask )
19761996 {
1977- if ( this . currentMask )
1978- {
1979- // Render out the previously set mask
1980- this . currentMask . postRenderWebGL ( this , camera ) ;
1981- }
1982-
1983- if ( mask )
1984- {
1985- // Set-up the new mask
1986- mask . preRenderWebGL ( this , child , camera ) ;
1987- }
1997+ // Render out the previously set mask
1998+ this . currentMask . postRenderWebGL ( this , camera ) ;
1999+ }
2000+
2001+ if ( mask && this . currentMask !== mask )
2002+ {
2003+ mask . preRenderWebGL ( this , child , camera ) ;
19882004 }
19892005
19902006 child . renderWebGL ( this , child , interpolationPercentage , camera ) ;
0 commit comments