Skip to main content
Version: Phaser v4.0.0-rc.6

WebGLTextureUnitsWrapper

A wrapper for the WebGLRenderingContext's texture units.

It tracks which textures are bound to which units, and provides

binding utilities.

Constructor

new WebGLTextureUnitsWrapper(renderer)

Parameters

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe WebGLRenderer instance that owns this wrapper.

Scope: static

Source: src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js#L9
Since: 4.0.0

Public Members

renderer

renderer: Phaser.Renderer.WebGL.WebGLRenderer

Description:

The WebGLRenderer instance that owns this wrapper.

Source: src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js#L27
Since: 4.0.0


unitIndices

unitIndices: Array.<number>

Description:

List of the indexes of available texture units.

Used in setting uniforms.

Source: src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js#L45
Since: 4.0.0


units

units: Array.<(Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper | null)>

Description:

The list of texture units available to the WebGLRenderingContext.

Source: src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js#L36
Since: 4.0.0


Public Methods

bind

<instance> bind(texture, unit, [force], [forceActive])

Description:

Binds a texture to a texture unit.

This will change the active texture unit to the given unit,

unless forceActive is false.

This should be the only way to bind a texture to a unit.

Parameters:

nametypeoptionaldefaultdescription
texturePhaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper | nullNoThe texture to bind, or null to unbind the unit.
unitnumberNoThe texture unit to bind the texture to.
forcebooleanYesfalseIf true, it will bind the texture even if it is already bound.
forceActivebooleanYestrueIf true, it will change the active texture unit to the given unit even if it is already active. Otherwise, it will only change the active texture unit if it is not already active.

Source: src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js#L97
Since: 4.0.0


bindUnits

<instance> bindUnits(textures, [force])

Description:

Set specific texture units to specific textures.

The active texture unit may change to accommodate the bindings.

Parameters:

nametypeoptionaldefaultdescription
texturesArray.<(Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper | nullundefined)>No
forcebooleanYesfalseIf true, it will bind all textures, even if they are already bound.

Source: src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js#L131
Since: 4.0.0


init

<instance> init()

Description:

Initializes the texture units to null. The active texture unit

will be 0 after this runs.

This populates every texture unit with a 1x1 texture.

This stops WebGL errors on MacOS.

These textures are not wrapped, and are not intended to be used,

so the texture units are recorded as null.

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


unbindAllUnits

<instance> unbindAllUnits()

Description:

Unbinds all textures from all texture units.

This will change the active texture unit to 0.

Source: src/renderer/webgl/wrappers/WebGLTextureUnitsWrapper.js#L164
Since: 4.0.0