Fixed nested bitmap mask issue

This commit is contained in:
Richard Davey 2019-04-29 14:45:54 +01:00
parent 80a0bf3f1a
commit 84e898fd90
3 changed files with 25 additions and 17 deletions

View file

@ -135,7 +135,7 @@ var GeometryMask = new Class({
if (renderer.currentCameraMask.mask !== this)
{
renderer.currentMask = this;
renderer.currentMask.mask = this;
}
renderer.maskStack.push({ mask: this, camera: camera });
@ -214,7 +214,7 @@ var GeometryMask = new Class({
// If this is the only mask in the stack, flush and disable
renderer.flush();
renderer.currentMask = null;
renderer.currentMask.mask = null;
gl.disable(gl.STENCIL_TEST);
}
@ -229,11 +229,12 @@ var GeometryMask = new Class({
if (renderer.currentCameraMask.mask !== prev.mask)
{
renderer.currentMask = prev.mask;
renderer.currentMask.mask = prev.mask;
renderer.currentMask.camera = prev.camera;
}
else
{
renderer.currentMask = null;
renderer.currentMask.mask = null;
}
}
},

View file

@ -492,16 +492,16 @@ var WebGLRenderer = new Class({
* Internal property that tracks the currently set mask.
*
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentMask
* @type {Phaser.Display.Masks.GeometryMask}
* @type {any}
* @since 3.17.0
*/
this.currentMask = null;
this.currentMask = { mask: null, camera: null };
/**
* Internal property that tracks the currently set camera mask.
*
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentCameraMask
* @type {Phaser.Display.Masks.GeometryMask}
* @type {any}
* @since 3.17.0
*/
this.currentCameraMask = { mask: null, camera: null };
@ -1008,7 +1008,7 @@ var WebGLRenderer = new Class({
*/
hasActiveStencilMask: function ()
{
var mask = this.currentMask;
var mask = this.currentMask.mask;
var camMask = this.currentCameraMask.mask;
return ((mask && mask.isStencil) || (camMask && camMask.isStencil));
@ -1935,7 +1935,7 @@ var WebGLRenderer = new Class({
gl.scissor(0, (this.drawingBufferHeight - this.height), this.width, this.height);
}
this.currentMask = null;
this.currentMask.mask = null;
this.currentCameraMask.mask = null;
this.maskStack.length = 0;
@ -1976,6 +1976,8 @@ var WebGLRenderer = new Class({
// Apply scissor for cam region + render background color, if not transparent
this.preRenderCamera(camera);
var current = this.currentMask;
for (var i = 0; i < childCount; i++)
{
var child = list[i];
@ -1992,13 +1994,15 @@ var WebGLRenderer = new Class({
var mask = child.mask;
if (this.currentMask && this.currentMask !== mask)
current = this.currentMask;
if (current.mask && current.mask !== mask)
{
// Render out the previously set mask
this.currentMask.postRenderWebGL(this, camera);
current.mask.postRenderWebGL(this, current.camera);
}
if (mask && this.currentMask !== mask)
if (mask && current.mask !== mask)
{
mask.preRenderWebGL(this, child, camera);
}
@ -2006,10 +2010,12 @@ var WebGLRenderer = new Class({
child.renderWebGL(this, child, interpolationPercentage, camera);
}
if (this.currentMask)
current = this.currentMask;
if (current.mask)
{
// Render out the previously set mask, if it was the last item in the display list
this.currentMask.postRenderWebGL(this, camera);
current.mask.postRenderWebGL(this, current.camera);
}
this.setBlendMode(CONST.BlendModes.NORMAL);

View file

@ -177,9 +177,10 @@ var BitmapMaskPipeline = new Class({
gl.clear(gl.COLOR_BUFFER_BIT);
if (renderer.currentCameraMask !== mask)
if (renderer.currentCameraMask.mask !== mask)
{
renderer.currentMask = mask;
renderer.currentMask.mask = mask;
renderer.currentMask.camera = camera;
}
}
},
@ -230,7 +231,7 @@ var BitmapMaskPipeline = new Class({
}
else
{
renderer.currentMask = null;
renderer.currentMask.mask = null;
}
// Bind bitmap mask pipeline and draw