Skip to content

Commit 599213d

Browse files
committed
New isPostFX property, listen to events and don't create projection matrix unless needed
1 parent 629eefb commit 599213d

1 file changed

Lines changed: 35 additions & 26 deletions

File tree

src/renderer/webgl/WebGLPipeline.js

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
var Class = require('../../utils/Class');
99
var DeepCopy = require('../../utils/object/DeepCopy');
10+
var Events = require('./events');
1011
var GetFastValue = require('../../utils/object/GetFastValue');
1112
var Matrix4 = require('../../math/Matrix4');
1213
var RenderTarget = require('./RenderTarget');
@@ -259,6 +260,16 @@ var WebGLPipeline = new Class({
259260
*/
260261
this.hasBooted = false;
261262

263+
/**
264+
* Indicates if this is a Post FX Pipeline, or not.
265+
*
266+
* @name Phaser.Renderer.WebGL.WebGLPipeline#isPostFX
267+
* @type {boolean}
268+
* @readonly
269+
* @since 3.50.0
270+
*/
271+
this.isPostFX = false;
272+
262273
/**
263274
* An array of RenderTarget instances that belong to this pipeline.
264275
*
@@ -311,7 +322,7 @@ var WebGLPipeline = new Class({
311322
* @type {Phaser.Math.Matrix4}
312323
* @since 3.50.0
313324
*/
314-
this.projectionMatrix = new Matrix4().identity();
325+
this.projectionMatrix;
315326

316327
/**
317328
* The configuration object that was used to create this pipeline.
@@ -343,6 +354,11 @@ var WebGLPipeline = new Class({
343354
var config = this.config;
344355
var renderer = this.renderer;
345356

357+
if (!this.isPostFX)
358+
{
359+
this.projectionMatrix = new Matrix4().identity();
360+
}
361+
346362
// Create the Render Targets
347363

348364
var renderTargets = this.renderTargets;
@@ -438,6 +454,11 @@ var WebGLPipeline = new Class({
438454

439455
this.hasBooted = true;
440456

457+
renderer.on(Events.RESIZE, this.resize, this);
458+
renderer.on(Events.PRE_RENDER, this.onPreRender, this);
459+
renderer.on(Events.RENDER, this.onRender, this);
460+
renderer.on(Events.POST_RENDER, this.onPostRender, this);
461+
441462
this.onBoot();
442463
},
443464

@@ -469,29 +490,6 @@ var WebGLPipeline = new Class({
469490
{
470491
},
471492

472-
/**
473-
* Creates a brand new WebGLPipeline instance based on the configuration object that
474-
* was used to create this one.
475-
*
476-
* The new instance is returned by this method. Note that the new instance is _not_
477-
* added to the Pipeline Manager. You will need to add it yourself should you require so.
478-
*
479-
* @method Phaser.Renderer.WebGL.WebGLPipeline#mvpInit
480-
* @since 3.50.0
481-
*
482-
* @param {string} name - The new name to give the cloned pipeline.
483-
*
484-
* @return {Phaser.Renderer.WebGL.WebGLPipeline} A clone of this WebGLPipeline instance.
485-
*/
486-
clone: function (name)
487-
{
488-
var clone = new WebGLPipeline(this.config);
489-
490-
clone.name = name;
491-
492-
return clone;
493-
},
494-
495493
/**
496494
* Sets the currently active shader within this pipeline.
497495
*
@@ -695,7 +693,11 @@ var WebGLPipeline = new Class({
695693

696694
var projectionMatrix = this.projectionMatrix;
697695

698-
projectionMatrix.ortho(0, width, height, 0, -1000, 1000);
696+
// Because Post FX Pipelines don't have them
697+
if (projectionMatrix)
698+
{
699+
projectionMatrix.ortho(0, width, height, 0, -1000, 1000);
700+
}
699701

700702
var i;
701703

@@ -1143,7 +1145,7 @@ var WebGLPipeline = new Class({
11431145
{
11441146
if (unit === undefined) { unit = this.currentUnit; }
11451147

1146-
var postPipeline = (gameObject && gameObject.postPipeline);
1148+
var postPipeline = (gameObject && gameObject.hasPostPipeline);
11471149

11481150
if (postPipeline)
11491151
{
@@ -1857,6 +1859,13 @@ var WebGLPipeline = new Class({
18571859

18581860
this.gl.deleteBuffer(this.vertexBuffer);
18591861

1862+
var renderer = this.renderer;
1863+
1864+
renderer.off(Events.RESIZE, this.resize, this);
1865+
renderer.off(Events.PRE_RENDER, this.onPreRender, this);
1866+
renderer.off(Events.RENDER, this.onRender, this);
1867+
renderer.off(Events.POST_RENDER, this.onPostRender, this);
1868+
18601869
this.game = null;
18611870
this.renderer = null;
18621871
this.gl = null;

0 commit comments

Comments
 (0)