Skip to content

Commit 52c2312

Browse files
committed
Update PipelineManager.js
1 parent 2d3edc9 commit 52c2312

1 file changed

Lines changed: 109 additions & 22 deletions

File tree

src/renderer/webgl/PipelineManager.js

Lines changed: 109 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ var SinglePipeline = require('./pipelines/SinglePipeline');
2424
* @constructor
2525
* @since 3.50.0
2626
*
27-
* @param {} config - The pipeline configuration object.
27+
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the WebGL Renderer that owns this Pipeline Manager.
2828
*/
2929
var PipelineManager = new Class({
3030

3131
initialize:
3232

33-
function PipelineManager (game)
33+
function PipelineManager (renderer)
3434
{
35-
// var gameConfig = game.config;
36-
3735
/**
3836
* A reference to the Game instance.
3937
*
4038
* @name Phaser.Renderer.WebGL.PipelineManager#game
4139
* @type {Phaser.Game}
4240
* @since 3.50.0
4341
*/
44-
this.game = game;
42+
this.game = renderer.game;
4543

4644
/**
4745
* A reference to the WebGL Renderer instance.
@@ -50,7 +48,7 @@ var PipelineManager = new Class({
5048
* @type {Phaser.Renderer.WebGL.WebGLRenderer}
5149
* @since 3.50.0
5250
*/
53-
this.renderer = game.renderer;
51+
this.renderer = renderer;
5452

5553
/**
5654
* The underlying WebGL context of the renderer.
@@ -78,24 +76,50 @@ var PipelineManager = new Class({
7876
/**
7977
* Current pipeline in use by the WebGLRenderer.
8078
*
81-
* @name Phaser.Renderer.WebGL.PipelineManager#currentPipeline
79+
* @name Phaser.Renderer.WebGL.PipelineManager#current
8280
* @type {Phaser.Renderer.WebGL.WebGLPipeline}
8381
* @default null
8482
* @since 3.50.0
8583
*/
86-
this.currentPipeline = null;
84+
this.current = null;
8785

8886
/**
8987
* The previous WebGLPipeline that was in use.
9088
*
9189
* This is set when `clearPipeline` is called and restored in `rebindPipeline` if none is given.
9290
*
93-
* @name Phaser.Renderer.WebGL.PipelineManager#previousPipeline
91+
* @name Phaser.Renderer.WebGL.PipelineManager#previous
9492
* @type {Phaser.Renderer.WebGL.WebGLPipeline}
9593
* @default null
9694
* @since 3.50.0
9795
*/
98-
this.previousPipeline = null;
96+
this.previous = null;
97+
98+
/**
99+
* A constant-style reference to the Multi Pipeline Instance.
100+
*
101+
* This is the default Phaser 3 pipeline and is used by the WebGL Renderer to manage
102+
* camera effects and more. This property is set during the `boot` method.
103+
*
104+
* @name Phaser.Renderer.WebGL.PipelineManager#MULTI_PIPELINE
105+
* @type {Phaser.Renderer.WebGL.Pipelines.MultiPipeline}
106+
* @default null
107+
* @since 3.50.0
108+
*/
109+
this.MULTI_PIPELINE = null;
110+
111+
/**
112+
* A constant-style reference to the Bitmap Mask Pipeline Instance.
113+
*
114+
* This is the default Phaser 3 mask pipeline and is used Game Objects using
115+
* a Bitmap Mask. This property is set during the `boot` method.
116+
*
117+
* @name Phaser.Renderer.WebGL.PipelineManager#BITMAPMASK_PIPELINE
118+
* @type {Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline}
119+
* @default null
120+
* @since 3.50.0
121+
*/
122+
this.BITMAPMASK_PIPELINE = null;
99123
},
100124

101125
/**
@@ -113,14 +137,14 @@ var PipelineManager = new Class({
113137
{
114138
var game = this.game;
115139

116-
var multi = this.add(CONST.MULTI_PIPELINE, new MultiPipeline({ game: game }));
140+
this.MULTI_PIPELINE = this.add(CONST.MULTI_PIPELINE, new MultiPipeline({ game: game }));
141+
this.BITMAPMASK_PIPELINE = this.add(CONST.BITMAPMASK_PIPELINE, new BitmapMaskPipeline({ game: game }));
117142

118143
this.add(CONST.SINGLE_PIPELINE, new SinglePipeline({ game: game }));
119144
this.add(CONST.ROPE_PIPELINE, new RopePipeline({ game: game }));
120-
this.add(CONST.BITMAPMASK_PIPELINE, new BitmapMaskPipeline({ game: game }));
121145
this.add(CONST.LIGHT_PIPELINE, new LightPipeline({ game: game }));
122146

123-
this.set(multi);
147+
this.set(this.MULTI_PIPELINE);
124148
},
125149

126150
/**
@@ -190,6 +214,63 @@ var PipelineManager = new Class({
190214
});
191215
},
192216

217+
/**
218+
* Calls the `onPreRender` method on each pipeline in this manager.
219+
*
220+
* This is called automatically by the `WebGLRenderer.preRender` method.
221+
*
222+
* @method Phaser.Renderer.WebGL.PipelineManager#preRender
223+
* @since 3.50.0
224+
*/
225+
preRender: function ()
226+
{
227+
var pipelines = this.pipelines;
228+
229+
pipelines.each(function (pipelineName, pipelineInstance)
230+
{
231+
pipelineInstance.onPreRender();
232+
});
233+
},
234+
235+
/**
236+
* Calls the `onRender` method on each pipeline in this manager.
237+
*
238+
* This is called automatically by the `WebGLRenderer.render` method.
239+
*
240+
* @method Phaser.Renderer.WebGL.PipelineManager#render
241+
* @since 3.50.0
242+
*
243+
* @param {Phaser.Scene} scene - The Scene to render.
244+
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Scene Camera to render with.
245+
*/
246+
render: function (scene, camera)
247+
{
248+
var pipelines = this.pipelines;
249+
250+
pipelines.each(function (pipelineName, pipelineInstance)
251+
{
252+
pipelineInstance.onRender(scene, camera);
253+
});
254+
},
255+
256+
/**
257+
* Calls the `onPostRender` method on each pipeline in this manager.
258+
*
259+
* This is called automatically by the `WebGLRenderer.postRender` method.
260+
*
261+
* @method Phaser.Renderer.WebGL.PipelineManager#postRender
262+
* @since 3.50.0
263+
*/
264+
postRender: function ()
265+
{
266+
var pipelines = this.pipelines;
267+
268+
pipelines.each(function (pipelineName, pipelineInstance)
269+
{
270+
pipelineInstance.onPostRender();
271+
});
272+
},
273+
193274
/**
194275
* Flushes the current pipeline, if one is bound.
195276
*
@@ -273,7 +354,7 @@ var PipelineManager = new Class({
273354
set: function (pipeline, gameObject)
274355
{
275356
var renderer = this.renderer;
276-
var current = this.currentPipeline;
357+
var current = this.current;
277358

278359
if (
279360
current !== pipeline ||
@@ -283,7 +364,7 @@ var PipelineManager = new Class({
283364
{
284365
renderer.resetTextures();
285366

286-
this.currentPipeline = pipeline;
367+
this.current = pipeline;
287368

288369
pipeline.bind();
289370
}
@@ -293,6 +374,11 @@ var PipelineManager = new Class({
293374
return pipeline;
294375
},
295376

377+
setMulti: function ()
378+
{
379+
return this.set(this.MULTI_PIPELINE);
380+
},
381+
296382
/**
297383
* Use this to reset the gl context to the state that Phaser requires to continue rendering.
298384
*
@@ -315,9 +401,9 @@ var PipelineManager = new Class({
315401
*/
316402
rebind: function (pipeline)
317403
{
318-
if (pipeline === undefined && this.previousPipeline)
404+
if (pipeline === undefined && this.previous)
319405
{
320-
pipeline = this.previousPipeline;
406+
pipeline = this.previous;
321407
}
322408

323409
if (!pipeline)
@@ -352,7 +438,7 @@ var PipelineManager = new Class({
352438

353439
renderer.resetTextures();
354440

355-
this.currentPipeline = pipeline;
441+
this.current = pipeline;
356442

357443
pipeline.bind(true);
358444
pipeline.onBind();
@@ -370,15 +456,14 @@ var PipelineManager = new Class({
370456
* @method Phaser.Renderer.WebGL.PipelineManager#clear
371457
* @since 3.50.0
372458
*/
373-
clearPipeline: function ()
459+
clear: function ()
374460
{
375461
var renderer = this.renderer;
376462

377463
this.flush();
378464

379-
this.previousPipeline = this.currentPipeline;
380-
381-
this.currentPipeline = null;
465+
this.previous = this.current;
466+
this.current = null;
382467

383468
renderer.currentProgram = null;
384469
renderer.currentVertexBuffer = null;
@@ -403,6 +488,8 @@ var PipelineManager = new Class({
403488
this.renderer = null;
404489
this.game = null;
405490
this.pipelines = null;
491+
this.current = null;
492+
this.previous = null;
406493
}
407494

408495
});

0 commit comments

Comments
 (0)