Skip to main content
Version: Phaser v4.0.0

ProgramManager

The ProgramManager is a utility class used to manage instantiated shader programs and a suite of associated data, such as a VAO. It maintains a shared pool of uniforms, so if a different shader program is used, the uniforms can be applied to the new program.

Constructor

new ProgramManager(renderer, attributeBufferLayouts, [indexBuffer])

Parameters

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe current WebGLRenderer instance.
attributeBufferLayoutsArray.<Phaser.Types.Renderer.WebGL.WebGLAttributeBufferLayout>NoThe attribute buffer layouts to use in the program.
indexBufferPhaser.Renderer.WebGL.Wrappers.WebGLBufferWrapperYesThe index buffer to use in the program, if any.

Scope: static

Source: src/renderer/webgl/ProgramManager.js#L10
Since: 4.0.0

Public Members

attributeBufferLayouts

attributeBufferLayouts: Array.<Phaser.Types.Renderer.WebGL.WebGLAttributeBufferLayout>

Description:

The attribute buffer layouts to use in the program. These are used to create a VAO.

Source: src/renderer/webgl/ProgramManager.js#L48
Since: 4.0.0


currentConfig

currentConfig: object

Description:

The configuration object currently being assembled.

Source: src/renderer/webgl/ProgramManager.js#L67
Since: 4.0.0


currentProgramKey

currentProgramKey: string

Description:

The key of the currently active shader program.

Source: src/renderer/webgl/ProgramManager.js#L58
Since: 4.0.0


indexBuffer

indexBuffer: Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper

Description:

The index buffer to use in the program, if any. This is used to create a VAO.

Source: src/renderer/webgl/ProgramManager.js#L38
Since: 4.0.0


programs

programs: object

Description:

A map of shader programs and associated data suite, identified by a unique key.

Each key corresponds to an object of the following shape:

  • program (WebGLProgramWrapper) - The compiled shader program.

  • vao (WebGLVAOWrapper) - The VAO associated with the program.

  • config (object) - The configuration object used to create the program.

Source: src/renderer/webgl/ProgramManager.js#L83
Since: 4.0.0


renderer

renderer: Phaser.Renderer.WebGL.WebGLRenderer

Description:

The current WebGLRenderer instance.

Source: src/renderer/webgl/ProgramManager.js#L29
Since: 4.0.0


uniforms

uniforms: object

Description:

A map of uniform values, identified by the shader uniform names. This allows uniforms to be kept between shader programs.

Source: src/renderer/webgl/ProgramManager.js#L99
Since: 4.0.0


Public Methods

addAddition

<instance> addAddition(addition, [index])

Description:

Add a shader addition to the current configuration.

Parameters:

nametypeoptionaldescription
additionPhaser.Types.Renderer.WebGL.ShaderAdditionConfigNoThe shader addition to add.
indexnumberYesThe index at which to insert the addition. If not specified, it will be added at the end.

Source: src/renderer/webgl/ProgramManager.js#L253
Since: 4.0.0


addFeature

<instance> addFeature(feature)

Description:

Add a feature to the current configuration.

Parameters:

nametypeoptionaldescription
featurestringNoThe feature to add.

Source: src/renderer/webgl/ProgramManager.js#L368
Since: 4.0.0


applyUniforms

<instance> applyUniforms(program)

Description:

Applies all stored uniform values to the given shader program. This is used to restore uniform state when switching between shader programs, ensuring the new program receives the same uniform values as the previous one.

Parameters:

nametypeoptionaldescription
programPhaser.Renderer.WebGL.Wrappers.WebGLProgramWrapperNoThe shader program to apply the uniforms to.

Source: src/renderer/webgl/ProgramManager.js#L216
Since: 4.0.0


clearFeatures

<instance> clearFeatures()

Description:

Clear all features from the current configuration.

Source: src/renderer/webgl/ProgramManager.js#L398
Since: 4.0.0


clearUniforms

<instance> clearUniforms()

Description:

Remove all uniforms.

Source: src/renderer/webgl/ProgramManager.js#L205
Since: 4.0.0


getAddition

<instance> getAddition(name)

Description:

Returns the addition with the given name.

Parameters:

nametypeoptionaldescription
namestringNoThe name to find.

Returns: Phaser.Types.Renderer.WebGL.ShaderAdditionConfig - The addition, or null if it was not found.

Source: src/renderer/webgl/ProgramManager.js#L273
Since: 4.0.0


getAdditionIndex

<instance> getAdditionIndex(name)

Description:

Returns the index of a shader addition with the given name.

Parameters:

nametypeoptionaldescription
namestringNoThe name to find.

Returns: number - The index of the addition, or -1 if it was not found.

Source: src/renderer/webgl/ProgramManager.js#L316
Since: 4.0.0


getAdditionsByTag

<instance> getAdditionsByTag(tag)

Description:

Returns a list of shader additions in the current config that have a specific tag.

Parameters:

nametypeoptionaldescription
tagstringNoThe tag to filter by.

Returns: Array.<Phaser.Types.Renderer.WebGL.ShaderAdditionConfig> - The shader additions with the tag.

Source: src/renderer/webgl/ProgramManager.js#L295
Since: 4.0.0


getCurrentProgramSuite

<instance> getCurrentProgramSuite()

Description:

Returns a program suite based on the current configuration. If the program does not exist, it is created.

The suite contains the following properties:

  • program (WebGLProgramWrapper) - The compiled shader program.

  • vao (WebGLVAOWrapper) - The VAO associated with the program.

  • config (object) - The configuration object used to create the program.

If parallel shader compilation is enabled, the program may not be available immediately. In this case, null is returned.

Returns: Object - The program suite, or null if the program is not available.

Source: src/renderer/webgl/ProgramManager.js#L110
Since: 4.0.0


removeAddition

<instance> removeAddition(name)

Description:

Remove a shader addition from the current configuration.

Parameters:

nametypeoptionaldescription
namestringNoThe name of the shader addition to remove.

Source: src/renderer/webgl/ProgramManager.js#L332
Since: 4.0.0


removeFeature

<instance> removeFeature(feature)

Description:

Remove a feature from the current configuration.

Parameters:

nametypeoptionaldescription
featurestringNoThe feature to remove.

Source: src/renderer/webgl/ProgramManager.js#L383
Since: 4.0.0


removeUniform

<instance> removeUniform(name)

Description:

Delete a uniform value. While unused uniforms are not harmful, they do take time to process and can be a source of confusion.

Parameters:

nametypeoptionaldescription
namestringNoThe name of the uniform.

Source: src/renderer/webgl/ProgramManager.js#L192
Since: 4.0.0


replaceAddition

<instance> replaceAddition(name, addition)

Description:

Replace a shader addition in the current configuration.

Parameters:

nametypeoptionaldescription
namestringNoThe name of the shader addition to replace.
additionPhaser.Types.Renderer.WebGL.ShaderAdditionConfigNoThe new shader addition.

Source: src/renderer/webgl/ProgramManager.js#L347
Since: 4.0.0


resetCurrentConfig

<instance> resetCurrentConfig()

Description:

Resets the current configuration object to its default empty state, clearing the base vertex and fragment shaders, all shader additions, and all features.

Source: src/renderer/webgl/ProgramManager.js#L162
Since: 4.0.0


setBaseShader

<instance> setBaseShader(name, vertexShader, fragmentShader)

Description:

Set the base shader for the current configuration.

Parameters:

nametypeoptionaldescription
namestringNoThe name of the shader program.
vertexShaderstringNoThe vertex shader source code.
fragmentShaderstringNoThe fragment shader source code.

Source: src/renderer/webgl/ProgramManager.js#L236
Since: 4.0.0


setUniform

<instance> setUniform(name, value)

Description:

Set the value of a uniform, available for all shader programs in this manager.

Parameters:

nametypeoptionaldescription
namestringNoThe name of the uniform.
valueanyNoThe value of the uniform.

Source: src/renderer/webgl/ProgramManager.js#L178
Since: 4.0.0