mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Improving support for child masking
This commit is contained in:
parent
216bf3d904
commit
f69cec7975
1 changed files with 63 additions and 19 deletions
|
@ -470,6 +470,15 @@ var WebGLRenderer = new Class({
|
||||||
*/
|
*/
|
||||||
this._tempMatrix4 = new TransformMatrix();
|
this._tempMatrix4 = new TransformMatrix();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reference to the mask the current camera is using, if any.
|
||||||
|
*
|
||||||
|
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentMask
|
||||||
|
* @type {(Phaser.Display.Masks.BitmapMask|Phaser.Display.Masks.GeometryMask)}
|
||||||
|
* @since 3.17.0
|
||||||
|
*/
|
||||||
|
this.currentMask = null;
|
||||||
|
|
||||||
this.init(this.config);
|
this.init(this.config);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1688,12 +1697,22 @@ var WebGLRenderer = new Class({
|
||||||
|
|
||||||
var color = camera.backgroundColor;
|
var color = camera.backgroundColor;
|
||||||
|
|
||||||
|
// Clear the current mask, if set
|
||||||
|
this.currentMask = null;
|
||||||
|
|
||||||
if (camera.renderToTexture)
|
if (camera.renderToTexture)
|
||||||
{
|
{
|
||||||
this.flush();
|
this.flush();
|
||||||
|
|
||||||
this.pushScissor(cx, cy, cw, -ch);
|
this.pushScissor(cx, cy, cw, -ch);
|
||||||
|
|
||||||
|
this.currentStencil = 0;
|
||||||
|
|
||||||
|
if (camera.mask)
|
||||||
|
{
|
||||||
|
this.setCameraMask(camera);
|
||||||
|
}
|
||||||
|
|
||||||
this.setFramebuffer(camera.framebuffer);
|
this.setFramebuffer(camera.framebuffer);
|
||||||
|
|
||||||
var gl = this.gl;
|
var gl = this.gl;
|
||||||
|
@ -1719,11 +1738,9 @@ var WebGLRenderer = new Class({
|
||||||
{
|
{
|
||||||
this.pushScissor(cx, cy, cw, ch);
|
this.pushScissor(cx, cy, cw, ch);
|
||||||
|
|
||||||
var mask = camera.mask;
|
if (camera.mask)
|
||||||
|
|
||||||
if (mask)
|
|
||||||
{
|
{
|
||||||
mask.preRenderWebGL(this, null, camera._maskCamera);
|
this.setCameraMask(camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (color.alphaGL > 0)
|
if (color.alphaGL > 0)
|
||||||
|
@ -1755,13 +1772,6 @@ var WebGLRenderer = new Class({
|
||||||
|
|
||||||
camera.dirty = false;
|
camera.dirty = false;
|
||||||
|
|
||||||
var mask = camera.mask;
|
|
||||||
|
|
||||||
if (mask)
|
|
||||||
{
|
|
||||||
mask.postRenderWebGL(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.popScissor();
|
this.popScissor();
|
||||||
|
|
||||||
if (camera.renderToTexture)
|
if (camera.renderToTexture)
|
||||||
|
@ -1803,6 +1813,11 @@ var WebGLRenderer = new Class({
|
||||||
// Force clear the current texture so that items next in the batch (like Graphics) don't try and use it
|
// Force clear the current texture so that items next in the batch (like Graphics) don't try and use it
|
||||||
this.setBlankTexture(true);
|
this.setBlankTexture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (camera.mask)
|
||||||
|
{
|
||||||
|
this.clearCameraMask(camera);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1899,15 +1914,9 @@ var WebGLRenderer = new Class({
|
||||||
this.setBlendMode(child.blendMode);
|
this.setBlendMode(child.blendMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
var mask = child.mask;
|
if (child.mask)
|
||||||
|
|
||||||
if (mask)
|
|
||||||
{
|
{
|
||||||
mask.preRenderWebGL(this, child, camera);
|
this.setChildMask(this, child, interpolationPercentage, camera);
|
||||||
|
|
||||||
child.renderWebGL(this, child, interpolationPercentage, camera);
|
|
||||||
|
|
||||||
mask.postRenderWebGL(this, child);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1952,6 +1961,41 @@ var WebGLRenderer = new Class({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setCameraMask: function (camera)
|
||||||
|
{
|
||||||
|
var mask = camera.mask;
|
||||||
|
|
||||||
|
// Cameras cannot have child cameras, so each one can clear the mask stack
|
||||||
|
this.currentMask = mask;
|
||||||
|
|
||||||
|
mask.preRenderWebGL(this, null, camera._maskCamera);
|
||||||
|
},
|
||||||
|
|
||||||
|
clearCameraMask: function (camera)
|
||||||
|
{
|
||||||
|
camera.mask.postRenderWebGL(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
setChildMask: function (renderer, child, interpolationPercentage, camera)
|
||||||
|
{
|
||||||
|
var mask = child.mask;
|
||||||
|
|
||||||
|
if (mask !== this.currentMask)
|
||||||
|
{
|
||||||
|
mask.preRenderWebGL(renderer, child, camera);
|
||||||
|
|
||||||
|
child.renderWebGL(renderer, child, interpolationPercentage, camera);
|
||||||
|
|
||||||
|
mask.postRenderWebGL(renderer);
|
||||||
|
|
||||||
|
// Restore camera mask
|
||||||
|
if (this.currentMask)
|
||||||
|
{
|
||||||
|
this.setCameraMask(camera);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedules a snapshot of the entire game viewport to be taken after the current frame is rendered.
|
* Schedules a snapshot of the entire game viewport to be taken after the current frame is rendered.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue