Skip to content

Commit 84e898f

Browse files
committed
Fixed nested bitmap mask issue
1 parent 80a0bf3 commit 84e898f

3 files changed

Lines changed: 25 additions & 17 deletions

File tree

src/display/mask/GeometryMask.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var GeometryMask = new Class({
135135

136136
if (renderer.currentCameraMask.mask !== this)
137137
{
138-
renderer.currentMask = this;
138+
renderer.currentMask.mask = this;
139139
}
140140

141141
renderer.maskStack.push({ mask: this, camera: camera });
@@ -214,7 +214,7 @@ var GeometryMask = new Class({
214214
// If this is the only mask in the stack, flush and disable
215215
renderer.flush();
216216

217-
renderer.currentMask = null;
217+
renderer.currentMask.mask = null;
218218

219219
gl.disable(gl.STENCIL_TEST);
220220
}
@@ -229,11 +229,12 @@ var GeometryMask = new Class({
229229

230230
if (renderer.currentCameraMask.mask !== prev.mask)
231231
{
232-
renderer.currentMask = prev.mask;
232+
renderer.currentMask.mask = prev.mask;
233+
renderer.currentMask.camera = prev.camera;
233234
}
234235
else
235236
{
236-
renderer.currentMask = null;
237+
renderer.currentMask.mask = null;
237238
}
238239
}
239240
},

src/renderer/webgl/WebGLRenderer.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,16 @@ var WebGLRenderer = new Class({
492492
* Internal property that tracks the currently set mask.
493493
*
494494
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentMask
495-
* @type {Phaser.Display.Masks.GeometryMask}
495+
* @type {any}
496496
* @since 3.17.0
497497
*/
498-
this.currentMask = null;
498+
this.currentMask = { mask: null, camera: null };
499499

500500
/**
501501
* Internal property that tracks the currently set camera mask.
502502
*
503503
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentCameraMask
504-
* @type {Phaser.Display.Masks.GeometryMask}
504+
* @type {any}
505505
* @since 3.17.0
506506
*/
507507
this.currentCameraMask = { mask: null, camera: null };
@@ -1008,7 +1008,7 @@ var WebGLRenderer = new Class({
10081008
*/
10091009
hasActiveStencilMask: function ()
10101010
{
1011-
var mask = this.currentMask;
1011+
var mask = this.currentMask.mask;
10121012
var camMask = this.currentCameraMask.mask;
10131013

10141014
return ((mask && mask.isStencil) || (camMask && camMask.isStencil));
@@ -1935,7 +1935,7 @@ var WebGLRenderer = new Class({
19351935
gl.scissor(0, (this.drawingBufferHeight - this.height), this.width, this.height);
19361936
}
19371937

1938-
this.currentMask = null;
1938+
this.currentMask.mask = null;
19391939
this.currentCameraMask.mask = null;
19401940
this.maskStack.length = 0;
19411941

@@ -1976,6 +1976,8 @@ var WebGLRenderer = new Class({
19761976
// Apply scissor for cam region + render background color, if not transparent
19771977
this.preRenderCamera(camera);
19781978

1979+
var current = this.currentMask;
1980+
19791981
for (var i = 0; i < childCount; i++)
19801982
{
19811983
var child = list[i];
@@ -1992,24 +1994,28 @@ var WebGLRenderer = new Class({
19921994

19931995
var mask = child.mask;
19941996

1995-
if (this.currentMask && this.currentMask !== mask)
1997+
current = this.currentMask;
1998+
1999+
if (current.mask && current.mask !== mask)
19962000
{
19972001
// Render out the previously set mask
1998-
this.currentMask.postRenderWebGL(this, camera);
2002+
current.mask.postRenderWebGL(this, current.camera);
19992003
}
20002004

2001-
if (mask && this.currentMask !== mask)
2005+
if (mask && current.mask !== mask)
20022006
{
20032007
mask.preRenderWebGL(this, child, camera);
20042008
}
20052009

20062010
child.renderWebGL(this, child, interpolationPercentage, camera);
20072011
}
20082012

2009-
if (this.currentMask)
2013+
current = this.currentMask;
2014+
2015+
if (current.mask)
20102016
{
20112017
// Render out the previously set mask, if it was the last item in the display list
2012-
this.currentMask.postRenderWebGL(this, camera);
2018+
current.mask.postRenderWebGL(this, current.camera);
20132019
}
20142020

20152021
this.setBlendMode(CONST.BlendModes.NORMAL);

src/renderer/webgl/pipelines/BitmapMaskPipeline.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ var BitmapMaskPipeline = new Class({
177177

178178
gl.clear(gl.COLOR_BUFFER_BIT);
179179

180-
if (renderer.currentCameraMask !== mask)
180+
if (renderer.currentCameraMask.mask !== mask)
181181
{
182-
renderer.currentMask = mask;
182+
renderer.currentMask.mask = mask;
183+
renderer.currentMask.camera = camera;
183184
}
184185
}
185186
},
@@ -230,7 +231,7 @@ var BitmapMaskPipeline = new Class({
230231
}
231232
else
232233
{
233-
renderer.currentMask = null;
234+
renderer.currentMask.mask = null;
234235
}
235236

236237
// Bind bitmap mask pipeline and draw

0 commit comments

Comments
 (0)