Skip to content

Commit 02bde43

Browse files
committed
Added fboStack, pushFramebuffer, popFramebuffer and resetTextures parameter
1 parent 416ae58 commit 02bde43

1 file changed

Lines changed: 74 additions & 4 deletions

File tree

src/renderer/webgl/WebGLRenderer.js

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
* @license {@link https://opensource.org/licenses/MIT|MIT License}
66
*/
77

8+
var ArrayRemove = require('../../utils/array/Remove');
89
var BaseCamera = require('../../cameras/2d/BaseCamera');
910
var CameraEvents = require('../../cameras/2d/events');
1011
var Class = require('../../utils/Class');
1112
var CONST = require('../../const');
1213
var GameEvents = require('../../core/events');
1314
var IsSizePowerOfTwo = require('../../math/pow2/IsSizePowerOfTwo');
1415
var NOOP = require('../../utils/NOOP');
15-
var PIPELINE_CONST = require('./pipelines/const');
1616
var PipelineManager = require('./PipelineManager');
1717
var ScaleEvents = require('../../scale/events');
1818
var TextureEvents = require('../../textures/events');
19-
var TransformMatrix = require('../../gameobjects/components/TransformMatrix');
2019
var Utils = require('./Utils');
2120
var WebGLSnapshot = require('../snapshot/WebGLSnapshot');
2221

@@ -1508,19 +1507,53 @@ var WebGLRenderer = new Class({
15081507
},
15091508

15101509
/**
1511-
* Binds a framebuffer. If there was another framebuffer already bound it will force a pipeline flush.
1510+
* Pushes a new framebuffer onto the FBO stack and makes it the currently bound framebuffer.
1511+
*
1512+
* If there was another framebuffer already bound it will force a pipeline flush.
1513+
*
1514+
* Call `popFramebuffer` to remove it again.
1515+
*
1516+
* @method Phaser.Renderer.WebGL.WebGLRenderer#pushFramebuffer
1517+
* @since 3.50.0
1518+
*
1519+
* @param {WebGLFramebuffer} framebuffer - The framebuffer that needs to be bound.
1520+
* @param {boolean} [updateScissor=false] - Set the gl scissor to match the frame buffer size? Or, if `null` given, pop the scissor from the stack.
1521+
* @param {boolean} [resetTextures=true] - Should the WebGL Textures be reset after the new framebuffer is bound?
1522+
*
1523+
* @return {this} This WebGLRenderer instance.
1524+
*/
1525+
pushFramebuffer: function (framebuffer, updateScissor, resetTextures)
1526+
{
1527+
if (framebuffer === this.currentFramebuffer)
1528+
{
1529+
return this;
1530+
}
1531+
1532+
this.fboStack.push(framebuffer);
1533+
1534+
return this.setFramebuffer(framebuffer, updateScissor, resetTextures);
1535+
},
1536+
1537+
/**
1538+
* Sets the given framebuffer as the active and currently bound framebuffer.
1539+
*
1540+
* If there was another framebuffer already bound it will force a pipeline flush.
1541+
*
1542+
* Typically, you should call `pushFramebuffer` instead of this method.
15121543
*
15131544
* @method Phaser.Renderer.WebGL.WebGLRenderer#setFramebuffer
15141545
* @since 3.0.0
15151546
*
15161547
* @param {WebGLFramebuffer} framebuffer - The framebuffer that needs to be bound.
15171548
* @param {boolean} [updateScissor=false] - If a framebuffer is given, set the gl scissor to match the frame buffer size? Or, if `null` given, pop the scissor from the stack.
1549+
* @param {boolean} [resetTextures=true] - Should the WebGL Textures be reset after the new framebuffer is bound?
15181550
*
15191551
* @return {this} This WebGLRenderer instance.
15201552
*/
1521-
setFramebuffer: function (framebuffer, updateScissor)
1553+
setFramebuffer: function (framebuffer, updateScissor, resetTextures)
15221554
{
15231555
if (updateScissor === undefined) { updateScissor = false; }
1556+
if (resetTextures === undefined) { resetTextures = true; }
15241557

15251558
if (framebuffer === this.currentFramebuffer)
15261559
{
@@ -1564,9 +1597,38 @@ var WebGLRenderer = new Class({
15641597

15651598
this.currentFramebuffer = framebuffer;
15661599

1600+
if (resetTextures)
1601+
{
1602+
this.resetTextures();
1603+
}
1604+
15671605
return this;
15681606
},
15691607

1608+
/**
1609+
* Pops the previous framebuffer from the fbo stack and sets it.
1610+
*
1611+
* @method Phaser.Renderer.WebGL.WebGLRenderer#popFramebuffer
1612+
* @since 3.50.0
1613+
*/
1614+
popFramebuffer: function ()
1615+
{
1616+
var fboStack = this.fboStack;
1617+
1618+
// Remove the current fbo
1619+
fboStack.pop();
1620+
1621+
// Reset the previous framebuffer
1622+
var framebuffer = fboStack[fboStack.length - 1];
1623+
1624+
if (!framebuffer)
1625+
{
1626+
framebuffer = null;
1627+
}
1628+
1629+
this.setFramebuffer(framebuffer);
1630+
},
1631+
15701632
/**
15711633
* Binds a shader program.
15721634
*
@@ -1995,6 +2057,13 @@ var WebGLRenderer = new Class({
19952057
if (framebuffer)
19962058
{
19972059
this.gl.deleteFramebuffer(framebuffer);
2060+
2061+
ArrayRemove(this.fboStack, framebuffer);
2062+
2063+
if (this.currentFramebuffer === framebuffer)
2064+
{
2065+
this.currentFramebuffer = null;
2066+
}
19982067
}
19992068

20002069
return this;
@@ -2847,6 +2916,7 @@ var WebGLRenderer = new Class({
28472916
this.pipelines.destroy();
28482917
this.defaultCamera.destroy();
28492918

2919+
this.fboStack = [];
28502920
this.maskStack = [];
28512921
this.extensions = {};
28522922
this.textureIndexes = [];

0 commit comments

Comments
 (0)