Phaser API Documentation

  Version: 
Filter
This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Renderer . WebGL . PipelineManager

This is a beta release of our new docs system. Found an issue?
Please tell us about it in the #📖-newdocs-feedback channel on the Phaser Discord

Phaser . Renderer . WebGL . PipelineManager

The Pipeline Manager is responsible for the creation, activation, running and destruction of WebGL Pipelines and Post FX Pipelines in Phaser 3.

The WebGLRenderer owns a single instance of the Pipeline Manager, which you can access via the WebGLRenderer.pipelines property.

By default, there are 8 pipelines installed into the Pipeline Manager when Phaser boots:

  1. The Multi Pipeline. Responsible for all multi-texture rendering, i.e. Sprites and Tilemaps.
  2. The Graphics Pipeline. Responsible for rendering Graphics and Shape objects.
  3. The Rope Pipeline. Responsible for rendering the Rope Game Object.
  4. The Light Pipeline. Responsible for rendering the Light Game Object.
  5. The Point Light Pipeline. Responsible for rendering the Point Light Game Object.
  6. The Single Pipeline. Responsible for rendering Game Objects that explicitly require one bound texture.
  7. The Bitmap Mask Pipeline. Responsible for Bitmap Mask rendering.
  8. The Utility Pipeline. Responsible for providing lots of handy texture manipulation functions.

You can add your own custom pipeline via the PipelineManager.add method. Pipelines are identified by unique string-based keys.

Constructor:

new PipelineManager(renderer)

Parameters:

name type description
renderer Phaser.Renderer.WebGL.WebGLRenderer

A reference to the WebGL Renderer that owns this Pipeline Manager.

Since: 3.50.0

Members

Description:

A constant-style reference to the Bitmap Mask Pipeline Instance.

This is the default Phaser 3 mask pipeline and is used Game Objects using a Bitmap Mask. This property is set during the boot method.

Type:
Default: null
Since: 3.50.0
Focus
Focus

Description:

A constant-style reference to the Multi Pipeline Instance.

This is the default Phaser 3 pipeline and is used by the WebGL Renderer to manage camera effects and more. This property is set during the boot method.

Type:
Default: null
Since: 3.50.0
Focus
Focus

Description:

A constant-style reference to the Utility Pipeline Instance.

Type:
Default: null
Since: 3.50.0
Focus
Focus
classes: Phaser.Structs.Map.<string, Class>
Focus
Focus

Description:

This map stores all pipeline classes available in this manager.

The Utility Class must always come first.

Type:
Phaser.Structs.Map.<string, Class>
Since: 3.50.0
Focus
Focus

Description:

Current pipeline in use by the WebGLRenderer.

Type:
Default: null
Since: 3.50.0
Focus
Focus

Description:

A reference to the Full Frame 1 Render Target that belongs to the Utility Pipeline. This property is set during the boot method.

This Render Target is the full size of the renderer.

You can use this directly in Post FX Pipelines for multi-target effects. However, be aware that these targets are shared between all post fx pipelines.

Type:
Default: null
Since: 3.50.0
Focus
Focus

Description:

A reference to the Full Frame 2 Render Target that belongs to the Utility Pipeline. This property is set during the boot method.

This Render Target is the full size of the renderer.

You can use this directly in Post FX Pipelines for multi-target effects. However, be aware that these targets are shared between all post fx pipelines.

Type:
Default: null
Since: 3.50.0
Focus
Focus
game: Phaser.Game
Focus
Focus

Description:

A reference to the Game instance.

Type:
Since: 3.50.0
Focus
Focus

Description:

A reference to the Half Frame 1 Render Target that belongs to the Utility Pipeline. This property is set during the boot method.

This Render Target is half the size of the renderer.

You can use this directly in Post FX Pipelines for multi-target effects. However, be aware that these targets are shared between all post fx pipelines.

Type:
Default: null
Since: 3.50.0
Focus
Focus

Description:

A reference to the Half Frame 2 Render Target that belongs to the Utility Pipeline. This property is set during the boot method.

This Render Target is half the size of the renderer.

You can use this directly in Post FX Pipelines for multi-target effects. However, be aware that these targets are shared between all post fx pipelines.

Type:
Default: null
Since: 3.50.0
Focus
Focus

Description:

This map stores all pipeline instances in this manager.

This is populated with the default pipelines in the boot method.

Type:
Since: 3.50.0
Focus
Focus
postPipelineClasses: Phaser.Structs.Map.<string, Class>
Focus
Focus

Description:

This map stores all Post FX Pipeline classes available in this manager.

Type:
Phaser.Structs.Map.<string, Class>
Since: 3.50.0
Focus
Focus

Description:

A reference to the WebGL Renderer instance.

Type:
Since: 3.50.0
Focus
Focus

Methods

add(name, pipeline)
Focus
Focus

Description:

Adds a pipeline instance to this Pipeline Manager.

The name of the instance must be unique within this manager.

Make sure to pass an instance to this method, not a base class.

For example, you should pass it like this:

this.add('yourName', new CustomPipeline());`

and not like this:

this.add('yourName', CustomPipeline);`

To add a Post Pipeline, see addPostPipeline instead.

Parameters:

name type description
name string

A unique string-based key for the pipeline within the manager.

pipeline Phaser.Renderer.WebGL.WebGLPipeline

A pipeline instance which must extend WebGLPipeline.

Returns:
Description:

The pipeline instance that was passed.

Examples:
Since: 3.50.0
Focus
Focus
addPostPipeline(name, pipeline)
Focus
Focus

Description:

Adds a Post Pipeline to this Pipeline Manager.

Make sure to pass a base class to this method, not an instance.

For example, you should pass it like this:

this.addPostPipeline('yourName', CustomPipeline);`

and not like this:

this.addPostPipeline('yourName', new CustomPipeline());`

To add a regular pipeline, see the add method instead.

Parameters:

name type description
name string

A unique string-based key for the pipeline within the manager.

pipeline function

A pipeline class which must extend PostFXPipeline.

Returns:
Description:

This Pipeline Manager.

Examples:
Since: 3.50.0
Focus
Focus
blendFrames(source1, source2, [target], [strength], [clearAlpha])
Focus
Focus

Description:

Draws the source1 and source2 Render Targets to the target Render Target using a linear blend effect, which is controlled by the strength parameter.

The draw itself is handled by the Utility Pipeline.

Parameters:

name type arguments Default description
source1 Phaser.Renderer.WebGL.RenderTarget

The first source Render Target.

source2 Phaser.Renderer.WebGL.RenderTarget

The second source Render Target.

target Phaser.Renderer.WebGL.RenderTarget <optional>

The target Render Target.

strength number <optional> 1

The strength of the blend.

clearAlpha boolean <optional> true

Clear the alpha channel when running gl.clear on the target?

Returns:
Description:

This Pipeline Manager instance.

Examples:
Since: 3.50.0
Focus
Focus
blendFramesAdditive(source1, source2, [target], [strength], [clearAlpha])
Focus
Focus

Description:

Draws the source1 and source2 Render Targets to the target Render Target using an additive blend effect, which is controlled by the strength parameter.

The draw itself is handled by the Utility Pipeline.

Parameters:

name type arguments Default description
source1 Phaser.Renderer.WebGL.RenderTarget

The first source Render Target.

source2 Phaser.Renderer.WebGL.RenderTarget

The second source Render Target.

target Phaser.Renderer.WebGL.RenderTarget <optional>

The target Render Target.

strength number <optional> 1

The strength of the blend.

clearAlpha boolean <optional> true

Clear the alpha channel when running gl.clear on the target?

Returns:
Description:

This Pipeline Manager instance.

Examples:
Since: 3.50.0
Focus
Focus
blitFrame(source, target, [brightness], [clear], [clearAlpha], [eraseMode])
Focus
Focus

Description:

Copy the source Render Target to the target Render Target.

The difference with this copy is that no resizing takes place. If the source Render Target is larger than the target then only a portion the same size as the target dimensions is copied across.

You can optionally set the brightness factor of the copy.

Parameters:

name type arguments Default description
source Phaser.Renderer.WebGL.RenderTarget

The source Render Target.

target Phaser.Renderer.WebGL.RenderTarget

The target Render Target.

brightness number <optional> 1

The brightness value applied to the frame copy.

clear boolean <optional> true

Clear the target before copying?

clearAlpha boolean <optional> true

Clear the alpha channel when running gl.clear on the target?

eraseMode boolean <optional> false

Erase source from target using ERASE Blend Mode?

Returns:
Description:

This Pipeline Manager instance.

Examples:
Since: 3.50.0
Focus
Focus
boot([pipelineConfig])
Focus
Focus

Description:

Internal boot handler, called by the WebGLRenderer durings its boot process.

Adds all of the default pipelines, based on the game config, and then calls the boot method on each one of them.

Finally, the default pipeline is set.

Parameters:

name type arguments description
pipelineConfig Phaser.Types.Core.PipelineConfig <optional>

The pipeline configuration object as set in the Game Config.

Examples:
Since: 3.50.0
Focus
Focus
clear()
Focus
Focus

Description:

Flushes the current pipeline being used and then clears it, along with the the current shader program and vertex buffer from the WebGLRenderer.

Then resets the blend mode to NORMAL.

Call this before jumping to your own gl context handler, and then call rebind when you wish to return control to Phaser again.

Examples:
Since: 3.50.0
Focus
Focus
clearFrame(target, [clearAlpha])
Focus
Focus

Description:

Clears the given Render Target.

Parameters:

name type arguments Default description
target Phaser.Renderer.WebGL.RenderTarget

The Render Target to clear.

clearAlpha boolean <optional> true

Clear the alpha channel when running gl.clear on the target?

Returns:
Description:

This Pipeline Manager instance.

Examples:
Since: 3.50.0
Focus
Focus
copyFrame(source, [target], [brightness], [clear], [clearAlpha])
Focus
Focus

Description:

Copy the source Render Target to the target Render Target.

You can optionally set the brightness factor of the copy.

The difference between this method and drawFrame is that this method uses a faster copy shader, where only the brightness can be modified. If you need color level manipulation, see drawFrame instead.

The copy itself is handled by the Utility Pipeline.

Parameters:

name type arguments Default description
source Phaser.Renderer.WebGL.RenderTarget

The source Render Target.

target Phaser.Renderer.WebGL.RenderTarget <optional>

The target Render Target.

brightness number <optional> 1

The brightness value applied to the frame copy.

clear boolean <optional> true

Clear the target before copying?

clearAlpha boolean <optional> true

Clear the alpha channel when running gl.clear on the target?

Returns:
Description:

This Pipeline Manager instance.

Examples:
Since: 3.50.0
Focus
Focus
copyFrameRect(source, target, x, y, width, height, [clear], [clearAlpha])
Focus
Focus

Description:

Binds the source Render Target and then copies a section of it to the target Render Target.

This method is extremely fast because it uses gl.copyTexSubImage2D and doesn't require the use of any shaders. Remember the coordinates are given in standard WebGL format, where x and y specify the lower-left corner of the section, not the top-left. Also, the copy entirely replaces the contents of the target texture, no 'merging' or 'blending' takes place.

Parameters:

name type arguments Default description
source Phaser.Renderer.WebGL.RenderTarget

The source Render Target.

target Phaser.Renderer.WebGL.RenderTarget

The target Render Target.

x number

The x coordinate of the lower left corner where to start copying.

y number

The y coordinate of the lower left corner where to start copying.

width number

The width of the texture.

height number

The height of the texture.

clear boolean <optional> true

Clear the target before copying?

clearAlpha boolean <optional> true

Clear the alpha channel when running gl.clear on the target?

Returns:
Description:

This Pipeline Manager instance.

Examples:
Since: 3.50.0
Focus
Focus
copyToGame(source)
Focus
Focus

Description:

Pops the framebuffer from the renderers FBO stack and sets that as the active target, then draws the source Render Target to it. It then resets the renderer textures.

This should be done when you need to draw the final results of a pipeline to the game canvas, or the next framebuffer in line on the FBO stack. You should only call this once in the onDraw handler and it should be the final thing called. Be careful not to call this if you need to actually use the pipeline shader, instead of the copy shader. In those cases, use the bindAndDraw method.

Parameters:

name type description
source Phaser.Renderer.WebGL.RenderTarget

The Render Target to draw from.

Examples:
Since: 3.50.0
Focus
Focus
destroy()
Focus
Focus

Description:

Destroy the Pipeline Manager, cleaning up all related resources and references.

Examples:
Since: 3.50.0
Focus
Focus
drawFrame(source, [target], [clearAlpha], [colorMatrix])
Focus
Focus

Description:

Copy the source Render Target to the target Render Target, using the given Color Matrix.

The difference between this method and copyFrame is that this method uses a color matrix shader, where you have full control over the luminance values used during the copy. If you don't need this, you can use the faster copyFrame method instead.

The copy itself is handled by the Utility Pipeline.

Parameters:

name type arguments Default description
source Phaser.Renderer.WebGL.RenderTarget

The source Render Target.

target Phaser.Renderer.WebGL.RenderTarget <optional>

The target Render Target.

clearAlpha boolean <optional> true

Clear the alpha channel when running gl.clear on the target?

colorMatrix Phaser.Display.ColorMatrix <optional>

The Color Matrix to use when performing the draw.

Returns:
Description:

This Pipeline Manager instance.

Examples:
Since: 3.50.0
Focus
Focus
flush()
Focus
Focus

Description:

Flushes the current pipeline, if one is bound.

Examples:
Since: 3.50.0
Focus
Focus
forceZero()
Focus
Focus

Description:

Returns true if the current pipeline is forced to use texture unit zero.

Returns:
Description:

true if the current pipeline is forced to use texture unit zero.

Type:
  • boolean
Examples:
Since: 3.50.0
Focus
Focus
get(pipeline)
Focus
Focus

Description:

Returns the pipeline instance based on the given name, or instance.

If no instance, or matching name, exists in this manager, it returns undefined.

Parameters:

name type description
pipeline string | Phaser.Renderer.WebGL.WebGLPipeline

Either the string-based name of the pipeline to get, or a pipeline instance to look-up.

Returns:
Description:

The pipeline instance, or undefined if not found.

Examples:
Since: 3.50.0
Focus
Focus
getPostPipeline(pipeline, [gameObject])
Focus
Focus

Description:

Returns a new instance of the post pipeline based on the given name, or class.

If no instance, or matching name, exists in this manager, it returns undefined.

Parameters:

name type arguments description
pipeline string | function | Phaser.Renderer.WebGL.Pipelines.PostFXPipeline

Either the string-based name of the pipeline to get, or a pipeline instance, or class to look-up.

gameObject Phaser.GameObjects.GameObject <optional>

If this post pipeline is being installed into a Game Object or Camera, this is a reference to it.

Returns:
Description:

The pipeline instance, or undefined if not found.

Examples:
Since: 3.50.0
Focus
Focus
has(pipeline)
Focus
Focus

Description:

Checks if a pipeline is present in this Pipeline Manager.

Parameters:

name type description
pipeline string | Phaser.Renderer.WebGL.WebGLPipeline

Either the string-based name of the pipeline to get, or a pipeline instance to look-up.

Returns:
Description:

true if the given pipeline is loaded, otherwise false.

Type:
  • boolean
Examples:
Since: 3.50.0
Focus
Focus
isCurrent(pipeline, [currentShader])
Focus
Focus

Description:

Checks to see if the given pipeline is already the active pipeline, both within this Pipeline Manager and also has the same shader set in the Renderer.

Parameters:

name type arguments description
pipeline Phaser.Renderer.WebGL.WebGLPipeline

The pipeline instance to be checked.

currentShader Phaser.Renderer.WebGL.WebGLShader <optional>

The shader to set as being current.

Returns:
Description:

true if the given pipeline is already the current pipeline, otherwise false.

Type:
  • boolean
Examples:
Since: 3.50.0
Focus
Focus
postBatch(gameObject)
Focus
Focus

Description:

This method is called by the WebGLPipeline.batchQuad method, right after a quad belonging to a Game Object has been added to the batch. It causes a batch flush, then calls the postBatch method on the post-fx pipelines belonging to the Game Object.

Parameters:

name type description
gameObject Phaser.GameObjects.GameObject

The Game Object that was just added to the batch.

Examples:
Since: 3.50.0
Focus
Focus
postBatchCamera(camera)
Focus
Focus

Description:

Called at the end of the WebGLRenderer.postRenderCamera method.

If the Camera has post pipelines set, it will flush the batch and then call the postBatch method on the post-fx pipelines belonging to the Camera.

Parameters:

name type description
camera Phaser.Cameras.Scene2D.Camera

The Camera that was just rendered.

Examples:
Since: 3.50.0
Focus
Focus
preBatch(gameObject)
Focus
Focus

Description:

This method is called by the WebGLPipeline.batchQuad method, right before a quad belonging to a Game Object is about to be added to the batch. It causes a batch flush, then calls the preBatch method on the post-fx pipelines belonging to the Game Object.

Parameters:

name type description
gameObject Phaser.GameObjects.GameObject

The Game Object about to be batched.

Examples:
Since: 3.50.0
Focus
Focus
preBatchCamera(camera)
Focus
Focus

Description:

Called at the start of the WebGLRenderer.preRenderCamera method.

If the Camera has post pipelines set, it will flush the batch and then call the preBatch method on the post-fx pipelines belonging to the Camera.

Parameters:

name type description
camera Phaser.Cameras.Scene2D.Camera

The Camera about to be rendered.

Examples:
Since: 3.50.0
Focus
Focus
rebind([pipeline])
Focus
Focus

Description:

Use this to reset the gl context to the state that Phaser requires to continue rendering.

Calling this will:

  • Disable DEPTH_TEST, CULL_FACE and STENCIL_TEST.
  • Clear the depth buffer and stencil buffers.
  • Reset the viewport size.
  • Reset the blend mode.
  • Bind a blank texture as the active texture on texture unit zero.
  • Rebinds the given pipeline instance.

You should call this if you have previously called clear, and then wish to return rendering control to Phaser again.

Parameters:

name type arguments description
pipeline Phaser.Renderer.WebGL.WebGLPipeline <optional>

The pipeline instance to be rebound. If not given, the previous pipeline will be bound.

Examples:
Since: 3.50.0
Focus
Focus
remove(name, [removeClass], [removePostPipelineClass])
Focus
Focus

Description:

Removes a pipeline instance based on the given name.

If no pipeline matches the name, this method does nothing.

Note that the pipeline will not be flushed or destroyed, it's simply removed from this manager.

Parameters:

name type arguments Default description
name string

The name of the pipeline to be removed.

removeClass boolean <optional> true

Remove the pipeline class as well as the instance?

removePostPipelineClass boolean <optional> true

Remove the post pipeline class as well as the instance?

Examples:
Since: 3.50.0
Focus
Focus
set(pipeline, [gameObject], [currentShader])
Focus
Focus

Description:

Sets the current pipeline to be used by the WebGLRenderer.

This method accepts a pipeline instance as its parameter, not the name.

If the pipeline isn't already the current one it will call WebGLPipeline.bind and then onBind.

You cannot set Post FX Pipelines using this method. To use a Post FX Pipeline, you should apply it to either a Camera, Container or other supporting Game Object.

Parameters:

name type arguments description
pipeline Phaser.Renderer.WebGL.WebGLPipeline

The pipeline instance to be set as current.

gameObject Phaser.GameObjects.GameObject <optional>

The Game Object that invoked this pipeline, if any.

currentShader Phaser.Renderer.WebGL.WebGLShader <optional>

The shader to set as being current.

Returns:
Description:

The pipeline that was set, or undefined if it couldn't be set.

Examples:
Since: 3.50.0
Focus
Focus
setMulti()
Focus
Focus

Description:

Sets the Multi Pipeline to be the currently bound pipeline.

This is the default Phaser 3 rendering pipeline.

Returns:
Description:

The Multi Pipeline instance.

Examples:
Since: 3.50.0
Focus
Focus
setUtility([currentShader])
Focus
Focus

Description:

Sets the Utility Pipeline to be the currently bound pipeline.

Parameters:

name type arguments description
currentShader Phaser.Renderer.WebGL.WebGLShader <optional>

The shader to set as being current.

Returns:
Description:

The Utility Pipeline instance.

Examples:
Since: 3.50.0
Focus
Focus