Skip to content

Commit a00e169

Browse files
committed
Added all the handlers needed for the post pipeline feature
1 parent 4747d20 commit a00e169

1 file changed

Lines changed: 139 additions & 7 deletions

File tree

src/gameobjects/components/Pipeline.js

Lines changed: 139 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @license {@link https://opensource.org/licenses/MIT|MIT License}
55
*/
66

7+
var DeepCopy = require('../../utils/object/DeepCopy');
78
var PIPELINE_CONST = require('../../renderer/webgl/pipelines/const');
89

910
/**
@@ -41,7 +42,18 @@ var Pipeline = {
4142
pipeline: null,
4243

4344
/**
44-
* An object to store pipeline specific data in, to be read by the pipeline this Game Object uses.
45+
* The WebGL Pipeline this Game Object uses for post-render effects.
46+
*
47+
* @name Phaser.GameObjects.Components.Pipeline#postPipeline
48+
* @type {Phaser.Renderer.WebGL.WebGLPipeline}
49+
* @default null
50+
* @webglOnly
51+
* @since 3.50.0
52+
*/
53+
postPipeline: null,
54+
55+
/**
56+
* An object to store pipeline specific data in, to be read by the pipelines this Game Object uses.
4557
*
4658
* @name Phaser.GameObjects.Components.Pipeline#pipelineData
4759
* @type {object}
@@ -87,17 +99,24 @@ var Pipeline = {
8799
},
88100

89101
/**
90-
* Sets the active WebGL Pipeline of this Game Object.
102+
* Sets the main WebGL Pipeline of this Game Object, and optionally the post-render pipeline as well.
103+
*
104+
* Also sets the `pipelineData` property, if the parameter is given.
105+
*
106+
* Both the pipeline and post pipeline share the pipeline data object together.
91107
*
92108
* @method Phaser.GameObjects.Components.Pipeline#setPipeline
93109
* @webglOnly
94110
* @since 3.0.0
95111
*
96112
* @param {(string|Phaser.Renderer.WebGL.WebGLPipeline)} pipeline - Either the string-based name of the pipeline, or a pipeline instance to set.
113+
* @param {(string|Phaser.Renderer.WebGL.WebGLPipeline)} [postPipeline] - The post-render pipeline. Set to `null` to skip if you need to set `pipelineData`. Can be either the string-based name of the pipeline, or a pipeline instance to set.
114+
* @param {object} [pipelineData] - Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object.
115+
* @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.
97116
*
98117
* @return {this} This Game Object instance.
99118
*/
100-
setPipeline: function (pipeline, pipelineData)
119+
setPipeline: function (pipeline, postPipeline, pipelineData, copyData)
101120
{
102121
var renderer = this.scene.sys.renderer;
103122
var pipelines = renderer.pipelines;
@@ -109,16 +128,99 @@ var Pipeline = {
109128
if (instance)
110129
{
111130
this.pipeline = instance;
112-
this.pipelineData = pipelineData;
131+
}
132+
133+
if (postPipeline)
134+
{
135+
instance = pipelines.get(postPipeline);
136+
137+
if (instance)
138+
{
139+
this.postPipeline = instance;
140+
}
141+
}
142+
143+
if (pipelineData)
144+
{
145+
this.pipelineData = (copyData) ? DeepCopy(pipelineData) : pipelineData;
146+
}
147+
}
148+
149+
return this;
150+
},
151+
152+
/**
153+
* Sets the post-render WebGL Pipeline of this Game Object.
154+
*
155+
* Post Pipelines are invoked after this Game Object has rendered to its target and
156+
* are commonly used for post-fx.
157+
*
158+
* Also sets the `pipelineData` property, if the parameter is given and the pipeline is successfully set.
159+
*
160+
* Both the pipeline and post pipeline share the pipeline data object together.
161+
*
162+
* @method Phaser.GameObjects.Components.Pipeline#setPostPipeline
163+
* @webglOnly
164+
* @since 3.50.0
165+
*
166+
* @param {(string|Phaser.Renderer.WebGL.WebGLPipeline)} pipeline - Either the string-based name of the pipeline, or a pipeline instance to set.
167+
* @param {object} [pipelineData] - Optional pipeline data object that is _deep copied_ into the `pipelineData` property of this Game Object.
168+
*
169+
* @return {this} This Game Object instance.
170+
*/
171+
setPostPipeline: function (pipeline, pipelineData)
172+
{
173+
var renderer = this.scene.sys.renderer;
174+
var pipelines = renderer.pipelines;
175+
176+
if (pipelines)
177+
{
178+
var instance = pipelines.get(pipeline);
179+
180+
if (instance)
181+
{
182+
this.postPipeline = instance;
183+
184+
if (pipelineData)
185+
{
186+
this.pipelineData = DeepCopy(pipelineData);
187+
}
113188
}
114189
}
115190

116191
return this;
117192
},
118193

194+
/**
195+
* Adds an entry to the `pipelineData` object belonging to this Game Object.
196+
*
197+
* If the 'key' already exists, its value is updated. If it doesn't exist, it is created.
198+
*
199+
* If `value` is undefined, and `key` exists, `key` is removed from the data object.
200+
*
201+
* Both the pipeline and post pipeline share the pipeline data object together.
202+
*
203+
* @method Phaser.GameObjects.Components.Pipeline#setPipelineData
204+
* @webglOnly
205+
* @since 3.50.0
206+
*
207+
* @param {string} key - The key of the pipeline data to set, update, or delete.
208+
* @param {any} [value] - The value to be set with the key. If `undefined` then `key` will be deleted from the object.
209+
*
210+
* @return {this} This Game Object instance.
211+
*/
119212
setPipelineData: function (key, value)
120213
{
121-
this.pipelineData[key] = value;
214+
var data = this.pipelineData;
215+
216+
if (value === undefined)
217+
{
218+
delete data[key];
219+
}
220+
else
221+
{
222+
data[key] = value;
223+
}
122224

123225
return this;
124226
},
@@ -130,12 +232,28 @@ var Pipeline = {
130232
* @webglOnly
131233
* @since 3.0.0
132234
*
133-
* @return {boolean} `true` if the pipeline was set successfully, otherwise `false`.
235+
* @param {boolean} [resetPostPipeline=false] - Reset the `postPipeline`?
236+
* @param {boolean} [resetData=false] - Reset the `pipelineData` object to being an empty object?
237+
*
238+
* @return {boolean} `true` if the pipeline was reset successfully, otherwise `false`.
134239
*/
135-
resetPipeline: function ()
240+
resetPipeline: function (resetPostPipeline, resetData)
136241
{
242+
if (resetPostPipeline === undefined) { resetPostPipeline = false; }
243+
if (resetData === undefined) { resetData = false; }
244+
137245
this.pipeline = this.defaultPipeline;
138246

247+
if (resetPostPipeline)
248+
{
249+
this.postPipeline = null;
250+
}
251+
252+
if (resetData)
253+
{
254+
this.pipelineData = {};
255+
}
256+
139257
return (this.pipeline !== null);
140258
},
141259

@@ -151,6 +269,20 @@ var Pipeline = {
151269
getPipelineName: function ()
152270
{
153271
return this.pipeline.name;
272+
},
273+
274+
/**
275+
* Gets the name of the Post Pipeline this Game Object is currently using, if any.
276+
*
277+
* @method Phaser.GameObjects.Components.Pipeline#getPostPipelineName
278+
* @webglOnly
279+
* @since 3.50.0
280+
*
281+
* @return {string} The string-based name of the post pipeline being used by this Game Object.
282+
*/
283+
getPostPipelineName: function ()
284+
{
285+
return (this.postPipeline) ? this.postPipeline.name : '';
154286
}
155287

156288
};

0 commit comments

Comments
 (0)