Skip to content

Commit ba9b837

Browse files
committed
You can now pass a pipeline instance to the GameObject.setPipeline method, as well as a string.
1 parent d670edd commit ba9b837

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

src/gameobjects/components/Pipeline.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var Pipeline = {
1919
/**
2020
* The initial WebGL pipeline of this Game Object.
2121
*
22+
* If you call `resetPipeline` on this Game Object, the pipeline is reset to this default.
23+
*
2224
* @name Phaser.GameObjects.Components.Pipeline#defaultPipeline
2325
* @type {Phaser.Renderer.WebGL.WebGLPipeline}
2426
* @default null
@@ -41,29 +43,34 @@ var Pipeline = {
4143
/**
4244
* Sets the initial WebGL Pipeline of this Game Object.
4345
*
44-
* This should only be called during the instantiation of the Game Object.
46+
* This should only be called during the instantiation of the Game Object. After that, use `setPipeline`.
4547
*
4648
* @method Phaser.GameObjects.Components.Pipeline#initPipeline
4749
* @webglOnly
4850
* @since 3.0.0
4951
*
50-
* @param {string} [name=MultiPipeline] - The name of the pipeline to set on this Game Object. Defaults to the Multi Pipeline.
52+
* @param {(string|Phaser.Renderer.WebGL.WebGLPipeline)} pipeline - Either the string-based name of the pipeline, or a pipeline instance to set.
5153
*
5254
* @return {boolean} `true` if the pipeline was set successfully, otherwise `false`.
5355
*/
54-
initPipeline: function (name)
56+
initPipeline: function (pipeline)
5557
{
56-
if (name === undefined) { name = PIPELINE_CONST.MULTI_PIPELINE; }
58+
if (pipeline === undefined) { pipeline = PIPELINE_CONST.MULTI_PIPELINE; }
5759

58-
var renderer = this.scene.sys.game.renderer;
60+
var renderer = this.scene.sys.renderer;
5961
var pipelines = renderer.pipelines;
6062

61-
if (pipelines && pipelines.has(name))
63+
if (pipelines)
6264
{
63-
this.defaultPipeline = pipelines.get(name);
64-
this.pipeline = this.defaultPipeline;
65+
var instance = pipelines.get(pipeline);
66+
67+
if (instance)
68+
{
69+
this.defaultPipeline = instance;
70+
this.pipeline = instance;
6571

66-
return true;
72+
return true;
73+
}
6774
}
6875

6976
return false;
@@ -76,18 +83,23 @@ var Pipeline = {
7683
* @webglOnly
7784
* @since 3.0.0
7885
*
79-
* @param {string} name - The name of the pipeline to set on this Game Object.
86+
* @param {(string|Phaser.Renderer.WebGL.WebGLPipeline)} pipeline - Either the string-based name of the pipeline, or a pipeline instance to set.
8087
*
8188
* @return {this} This Game Object instance.
8289
*/
83-
setPipeline: function (name)
90+
setPipeline: function (pipeline)
8491
{
85-
var renderer = this.scene.sys.game.renderer;
92+
var renderer = this.scene.sys.renderer;
8693
var pipelines = renderer.pipelines;
8794

88-
if (pipelines && pipelines.has(name))
95+
if (pipelines)
8996
{
90-
this.pipeline = pipelines.get(name);
97+
var instance = pipelines.get(pipeline);
98+
99+
if (instance)
100+
{
101+
this.pipeline = instance;
102+
}
91103
}
92104

93105
return this;

0 commit comments

Comments
 (0)