Skip to content

Commit 080677f

Browse files
committed
Set on creation, not in the component
1 parent 9cf6772 commit 080677f

2 files changed

Lines changed: 82 additions & 38 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ var Camera = new Class({
6969
{
7070
BaseCamera.call(this, x, y, width, height);
7171

72+
this.postPipelines = [];
73+
this.pipelineData = {};
74+
7275
/**
7376
* Does this Camera allow the Game Objects it renders to receive input events?
7477
*

src/gameobjects/components/Pipeline.js

Lines changed: 79 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,29 @@ var Pipeline = {
4242
pipeline: null,
4343

4444
/**
45-
* The WebGL Pipeline this Game Object uses for post-render effects.
45+
* Does this Game Object have any Post Pipelines set?
46+
*
47+
* @name Phaser.GameObjects.Components.Pipeline#hasPostPipeline
48+
* @type {boolean}
49+
* @webglOnly
50+
* @since 3.50.0
51+
*/
52+
hasPostPipeline: false,
53+
54+
/**
55+
* The WebGL Post FX Pipelines this Game Object uses for post-render effects.
56+
*
57+
* The pipelines are processed in the order in which they appear in this array.
58+
*
59+
* If you modify this array directly, be sure to set the
60+
* `hasPostPipeline` property accordingly.
4661
*
4762
* @name Phaser.GameObjects.Components.Pipeline#postPipeline
48-
* @type {Phaser.Renderer.WebGL.WebGLPipeline}
49-
* @default null
63+
* @type {Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[]}
5064
* @webglOnly
5165
* @since 3.50.0
5266
*/
53-
postPipeline: null,
67+
postPipelines: null,
5468

5569
/**
5670
* An object to store pipeline specific data in, to be read by the pipelines this Game Object uses.
@@ -60,7 +74,7 @@ var Pipeline = {
6074
* @webglOnly
6175
* @since 3.50.0
6276
*/
63-
pipelineData: {},
77+
pipelineData: null,
6478

6579
/**
6680
* Sets the initial WebGL Pipeline of this Game Object.
@@ -82,6 +96,9 @@ var Pipeline = {
8296
var renderer = this.scene.sys.renderer;
8397
var pipelines = renderer.pipelines;
8498

99+
this.postPipelines = [];
100+
this.pipelineData = {};
101+
85102
if (pipelines)
86103
{
87104
var instance = pipelines.get(pipeline);
@@ -99,11 +116,11 @@ var Pipeline = {
99116
},
100117

101118
/**
102-
* Sets the main WebGL Pipeline of this Game Object, and optionally the post-render pipeline as well.
119+
* Sets the main WebGL Pipeline of this Game Object.
103120
*
104121
* Also sets the `pipelineData` property, if the parameter is given.
105122
*
106-
* Both the pipeline and post pipeline share the pipeline data object together.
123+
* Both the pipeline and post pipelines share the same pipeline data object.
107124
*
108125
* @method Phaser.GameObjects.Components.Pipeline#setPipeline
109126
* @webglOnly
@@ -139,41 +156,54 @@ var Pipeline = {
139156
},
140157

141158
/**
142-
* Sets the post-render WebGL Pipeline of this Game Object.
159+
* Sets one, or more, Post Pipelines on this Game Object.
143160
*
144161
* Post Pipelines are invoked after this Game Object has rendered to its target and
145162
* are commonly used for post-fx.
146163
*
147-
* Also sets the `pipelineData` property, if the parameter is given and the pipeline is successfully set.
164+
* The post pipelines instances are appended to the `postPipelines` array belonging to this
165+
* Game Object. When the renderer processes this Game Object, it iterates through the post
166+
* pipelines in the order in which they appear in the array. If you are stacking together
167+
* multiple effects, be aware that the order is important.
148168
*
149-
* Both the pipeline and post pipeline share the pipeline data object together.
169+
* If you call this method multiple times, the new pipelines will be appended to any existing
170+
* post pipelines already set. Use the `resetPostPipeline` method to clear them first, if required.
171+
*
172+
* You can optionally also sets the `pipelineData` property, if the parameter is given
173+
* and the pipeline is successfully set.
174+
*
175+
* Both the pipeline and post pipelines share the pipeline data object together.
150176
*
151177
* @method Phaser.GameObjects.Components.Pipeline#setPostPipeline
152178
* @webglOnly
153179
* @since 3.50.0
154180
*
155-
* @param {(string|Phaser.Renderer.WebGL.WebGLPipeline)} pipeline - Either the string-based name of the pipeline, or a pipeline instance to set.
181+
* @param {(string|string[]|Phaser.Renderer.WebGL.Pipelines.PostFXPipeline|Phaser.Renderer.WebGL.Pipelines.PostFXPipeline[])} pipelines - Either the string-based name of the pipeline, or a pipeline instance, or an array of them.
156182
* @param {object} [pipelineData] - Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object.
157183
* @param {boolean} [copyData=true] - Should the pipeline data object be _deep copied_ into the `pipelineData` property of this Game Object? If `false` it will be set by reference instead.
158184
*
159185
* @return {this} This Game Object instance.
160186
*/
161-
setPostPipeline: function (pipeline, pipelineData, copyData)
187+
setPostPipeline: function (pipelines, pipelineData, copyData)
162188
{
163189
var renderer = this.scene.sys.renderer;
164-
var pipelines = renderer.pipelines;
190+
var pipelineManager = renderer.pipelines;
165191

166-
if (pipelines)
192+
if (pipelineManager)
167193
{
168-
var instance = pipelines.get(pipeline);
169-
170-
if (instance)
194+
if (!Array.isArray(pipelines))
171195
{
172-
this.postPipeline = instance;
196+
pipelines = [ pipelines ];
173197
}
174-
else
198+
199+
for (var i = 0; i < pipelines.length; i++)
175200
{
176-
this.postPipeline = null;
201+
var instance = pipelineManager.getPostPipeline(pipelines[i]);
202+
203+
if (instance)
204+
{
205+
this.postPipelines.push(instance);
206+
}
177207
}
178208

179209
if (pipelineData)
@@ -182,6 +212,8 @@ var Pipeline = {
182212
}
183213
}
184214

215+
this.hasPostPipeline = (this.postPipelines.length > 0);
216+
185217
return this;
186218
},
187219

@@ -192,7 +224,7 @@ var Pipeline = {
192224
*
193225
* If `value` is undefined, and `key` exists, `key` is removed from the data object.
194226
*
195-
* Both the pipeline and post pipeline share the pipeline data object together.
227+
* Both the pipeline and post pipelines share the pipeline data object together.
196228
*
197229
* @method Phaser.GameObjects.Components.Pipeline#setPipelineData
198230
* @webglOnly
@@ -226,21 +258,22 @@ var Pipeline = {
226258
* @webglOnly
227259
* @since 3.0.0
228260
*
229-
* @param {boolean} [resetPostPipeline=false] - Reset the `postPipeline`?
261+
* @param {boolean} [resetPostPipelines=false] - Reset all of the post pipelines?
230262
* @param {boolean} [resetData=false] - Reset the `pipelineData` object to being an empty object?
231263
*
232264
* @return {boolean} `true` if the pipeline was reset successfully, otherwise `false`.
233265
*/
234-
resetPipeline: function (resetPostPipeline, resetData)
266+
resetPipeline: function (resetPostPipelines, resetData)
235267
{
236-
if (resetPostPipeline === undefined) { resetPostPipeline = false; }
268+
if (resetPostPipelines === undefined) { resetPostPipelines = false; }
237269
if (resetData === undefined) { resetData = false; }
238270

239271
this.pipeline = this.defaultPipeline;
240272

241-
if (resetPostPipeline)
273+
if (resetPostPipelines)
242274
{
243-
this.postPipeline = null;
275+
this.postPipelines = [];
276+
this.hasPostPipeline = false;
244277
}
245278

246279
if (resetData)
@@ -252,31 +285,39 @@ var Pipeline = {
252285
},
253286

254287
/**
255-
* Gets the name of the WebGL Pipeline this Game Object is currently using.
288+
* Resets the WebGL Post Pipelines of this Game Object.
256289
*
257-
* @method Phaser.GameObjects.Components.Pipeline#getPipelineName
290+
* @method Phaser.GameObjects.Components.Pipeline#resetPostPipeline
258291
* @webglOnly
259-
* @since 3.0.0
292+
* @since 3.50.0
260293
*
261-
* @return {string} The string-based name of the pipeline being used by this Game Object.
294+
* @param {boolean} [resetData=false] - Reset the `pipelineData` object to being an empty object?
262295
*/
263-
getPipelineName: function ()
296+
resetPostPipeline: function (resetData)
264297
{
265-
return this.pipeline.name;
298+
if (resetData === undefined) { resetData = false; }
299+
300+
this.postPipelines = [];
301+
this.hasPostPipeline = false;
302+
303+
if (resetData)
304+
{
305+
this.pipelineData = {};
306+
}
266307
},
267308

268309
/**
269-
* Gets the name of the Post Pipeline this Game Object is currently using, if any.
310+
* Gets the name of the WebGL Pipeline this Game Object is currently using.
270311
*
271-
* @method Phaser.GameObjects.Components.Pipeline#getPostPipelineName
312+
* @method Phaser.GameObjects.Components.Pipeline#getPipelineName
272313
* @webglOnly
273-
* @since 3.50.0
314+
* @since 3.0.0
274315
*
275-
* @return {string} The string-based name of the post pipeline being used by this Game Object.
316+
* @return {string} The string-based name of the pipeline being used by this Game Object.
276317
*/
277-
getPostPipelineName: function ()
318+
getPipelineName: function ()
278319
{
279-
return (this.postPipeline) ? this.postPipeline.name : '';
320+
return this.pipeline.name;
280321
}
281322

282323
};

0 commit comments

Comments
 (0)