From 93dabaa34ee86299a1af5efbe6abe26d068fdb3a Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Fri, 26 Apr 2019 19:13:55 +0100 Subject: [PATCH] Store and restore previous framebuffer --- src/display/mask/BitmapMask.js | 58 ++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/display/mask/BitmapMask.js b/src/display/mask/BitmapMask.js index e644854a4..4ba11fc87 100644 --- a/src/display/mask/BitmapMask.js +++ b/src/display/mask/BitmapMask.js @@ -115,6 +115,15 @@ var BitmapMask = new Class({ */ this.maskFramebuffer = null; + /** + * The previous framebuffer set in the renderer before this one was enabled. + * + * @name Phaser.Display.Masks.BitmapMask#prevFramebuffer + * @type {WebGLFramebuffer} + * @since 3.17.0 + */ + this.prevFramebuffer = null; + /** * Whether to invert the mask's alpha. * @@ -126,6 +135,8 @@ var BitmapMask = new Class({ */ this.invertAlpha = false; + this.isStencil = false; + if (renderer && renderer.gl) { var width = renderer.width; @@ -185,7 +196,21 @@ var BitmapMask = new Class({ */ preRenderWebGL: function (renderer, maskedObject, camera) { + // if (renderer.maskStack.length === 0) + // { + // renderer.maskCount = 0; + // } + + // if (renderer.currentCameraMask !== this) + // { + // renderer.currentMask = this; + // } + + // renderer.maskStack.push({ mask: this, camera: camera }); + renderer.pipelines.BitmapMaskPipeline.beginMask(this, maskedObject, camera); + + // renderer.maskCount++; }, /** @@ -198,9 +223,37 @@ var BitmapMask = new Class({ * * @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The WebGL Renderer to clean up. */ - postRenderWebGL: function (renderer) + postRenderWebGL: function (renderer, camera) { - renderer.pipelines.BitmapMaskPipeline.endMask(this); + renderer.pipelines.BitmapMaskPipeline.endMask(this, camera); + + /* + renderer.maskStack.pop(); + + renderer.maskCount--; + + if (renderer.maskStack.length === 0) + { + renderer.pipelines.BitmapMaskPipeline.endMask(this); + + renderer.currentMask = null; + } + else + { + // Get the mask previous to this one + var prev = renderer.maskStack[renderer.maskStack.length - 1]; + var bitmapMask = prev.mask; + + // var camera = prev.camera; + + if (renderer.currentCameraMask !== bitmapMask) + { + renderer.currentMask = bitmapMask; + } + + renderer.setFramebuffer(bitmapMask.mainFramebuffer); + } + */ }, /** @@ -258,6 +311,7 @@ var BitmapMask = new Class({ this.maskTexture = null; this.mainFramebuffer = null; this.maskFramebuffer = null; + this.prevFramebuffer = null; this.renderer = null; }