Skip to main content
Version: Phaser v4.0.0

ShaderProgramFactory

The ShaderProgramFactory is a utility class used to create and cache Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper objects for the WebGL renderer. It assembles compiled shader programs from a base shader combined with optional additions and feature flags, then stores the result under a unique key so that the same combination is never compiled more than once. Use this class when you need to obtain a shader program that may vary at runtime based on renderer capabilities or pipeline configuration.

Constructor

new ShaderProgramFactory(renderer)

Parameters

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe WebGLRenderer that owns this ShaderProgramFactory.

Scope: static

Source: src/renderer/webgl/ShaderProgramFactory.js#L16
Since: 4.0.0

Public Members

programs

programs: object

Description:

A map of shader programs, identified by a unique key.

The key of each shader program is made up of the following components:

  • The key of the base shader program.

  • The key of each shader addition, in addition order.

  • The key of each enabled shader feature, sorted alphabetically.

Source: src/renderer/webgl/ShaderProgramFactory.js#L44
Since: 4.0.0


renderer

renderer: Phaser.Renderer.WebGL.WebGLRenderer

Description:

The WebGLRenderer that owns this ShaderProgramFactory.

Source: src/renderer/webgl/ShaderProgramFactory.js#L35
Since: 4.0.0


Public Methods

createShaderProgram

<instance> createShaderProgram(name, base, [additions], [features])

Description:

Creates a shader program based on the given configuration settings.

Parameters:

nametypeoptionaldescription
namestringNoThe unique key of the shader program.
baseBaseShaderConfigNoThe base shader configuration.
additionsArray.<Phaser.Types.Renderer.WebGL.ShaderAdditionConfig>YesAn array of shader addition configurations.
featuresArray.<string>YesAn array of enabled shader feature keys.

Returns: Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper - The newly compiled and cached shader program wrapper.

Source: src/renderer/webgl/ShaderProgramFactory.js#L143
Since: 4.0.0


getKey

<instance> getKey(base, [additions], [features])

Description:

Returns a unique key for a shader program based on the given configuration settings.

The key is made up of the following components:

  • The key of the base shader program.

  • The key of each shader addition, in addition order.

  • The key of each enabled shader feature, sorted alphabetically.

Parameters:

nametypeoptionaldescription
baseBaseShaderConfigNoThe base shader configuration.
additionsArray.<Phaser.Types.Renderer.WebGL.ShaderAdditionConfig>YesAn array of shader addition configurations.
featuresArray.<string>YesAn array of enabled shader feature keys.

Returns: string - The unique cache key for this shader configuration.

Source: src/renderer/webgl/ShaderProgramFactory.js#L101
Since: 4.0.0


getShaderProgram

<instance> getShaderProgram(base, [additions], [features])

Description:

Returns a compiled shader program for the given configuration. If a program matching the derived key already exists in the cache it is returned immediately; otherwise a new program is compiled, stored in the cache, and returned.

Parameters:

nametypeoptionaldescription
baseBaseShaderConfigNoThe base shader configuration.
additionsArray.<Phaser.Types.Renderer.WebGL.ShaderAdditionConfig>YesAn array of shader addition configurations.
featuresArray.<string>YesAn array of enabled shader feature keys.

Returns: Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper - The compiled shader program wrapper.

Source: src/renderer/webgl/ShaderProgramFactory.js#L74
Since: 4.0.0


has

<instance> has(key)

Description:

Checks whether a compiled shader program with the given key already exists in the internal cache.

Parameters:

nametypeoptionaldescription
keystringNoThe unique key of the shader program.

Returns: boolean - true if a shader program with this key exists in the cache, otherwise false.

Source: src/renderer/webgl/ShaderProgramFactory.js#L60
Since: 4.0.0