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
| name | type | optional | description |
|---|---|---|---|
| renderer | Phaser.Renderer.WebGL.WebGLRenderer | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| name | string | No | The unique key of the shader program. |
| base | BaseShaderConfig | No | The base shader configuration. |
| additions | Array.<Phaser.Types.Renderer.WebGL.ShaderAdditionConfig> | Yes | An array of shader addition configurations. |
| features | Array.<string> | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| base | BaseShaderConfig | No | The base shader configuration. |
| additions | Array.<Phaser.Types.Renderer.WebGL.ShaderAdditionConfig> | Yes | An array of shader addition configurations. |
| features | Array.<string> | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| base | BaseShaderConfig | No | The base shader configuration. |
| additions | Array.<Phaser.Types.Renderer.WebGL.ShaderAdditionConfig> | Yes | An array of shader addition configurations. |
| features | Array.<string> | Yes | An 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:
| name | type | optional | description |
|---|---|---|---|
| key | string | No | The 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