Class: WebGLRenderer

Phaser.Renderer.WebGL. WebGLRenderer

WebGLRenderer is a class that contains the needed functionality to keep the WebGLRenderingContext state clean. The main idea of the WebGLRenderer is to keep track of any context change that happens for WebGL rendering inside of Phaser. This means if raw webgl functions are called outside the WebGLRenderer of the Phaser WebGL rendering ecosystem they might pollute the current WebGLRenderingContext state producing unexpected behavior. It's recommended that WebGL interaction is done through WebGLRenderer and/or WebGLPipeline.


new WebGLRenderer(game)

Parameters:
Name Type Description
game Phaser.Game

The Game instance which owns this WebGL Renderer.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 33)

Members


<readonly> blankTexture :WebGLTexture

A blank 32x32 transparent texture, as used by the Graphics system where needed. This is set in the boot method.

Type:
  • WebGLTexture
Since: 3.12.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 391)

blendModes :array

An array of blend modes supported by the WebGL Renderer.

This array includes the default blend modes as well as any custom blend modes added through #addBlendMode.

Type:
  • array
Since: 3.0.0
Default Value:
  • []
Source: src/renderer/webgl/WebGLRenderer.js (Line 136)

canvas :HTMLCanvasElement

The canvas which this WebGL Renderer draws to.

Type:
  • HTMLCanvasElement
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 127)

compression :array

Stores the supported WebGL texture compression formats.

Type:
  • array
Since: 3.8.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 368)

config :object

The local configuration settings of this WebGL Renderer.

Type:
  • object
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 69)

contextLost :boolean

This property is set to true if the WebGL context of the renderer is lost.

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/renderer/webgl/WebGLRenderer.js (Line 158)

contextLostHandler :function

The handler to invoke when the context is lost. This should not be changed and is set in the boot method.

Type:
  • function
Since: 3.19.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 308)

contextRestoredHandler :function

The handler to invoke when the context is restored. This should not be changed and is set in the boot method.

Type:
  • function
Since: 3.19.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 318)

currentActiveTextureUnit :integer

Cached value for the last texture unit that was used

Type:
  • integer
Since: 3.1.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 203)

currentBlendMode :integer

Current blend mode in use

Type:
  • integer
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 271)

currentCameraMask :any

Internal property that tracks the currently set camera mask.

Type:
  • any
Since: 3.17.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 478)

currentFramebuffer :WebGLFramebuffer

Current framebuffer in use

Type:
  • WebGLFramebuffer
Since: 3.0.0
Default Value:
  • null
Source: src/renderer/webgl/WebGLRenderer.js (Line 221)

currentIndexBuffer :WebGLBuffer

Current WebGLBuffer (Index buffer) in use

Type:
  • WebGLBuffer
Since: 3.0.0
Default Value:
  • null
Source: src/renderer/webgl/WebGLRenderer.js (Line 261)

currentMask :any

Internal property that tracks the currently set mask.

Type:
  • any
Since: 3.17.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 469)

currentPipeline :Phaser.Renderer.WebGL.WebGLPipeline

Current WebGLPipeline in use

Type:
Since: 3.0.0
Default Value:
  • null
Source: src/renderer/webgl/WebGLRenderer.js (Line 231)

currentProgram :WebGLProgram

Current WebGLProgram in use

Type:
  • WebGLProgram
Since: 3.0.0
Default Value:
  • null
Source: src/renderer/webgl/WebGLRenderer.js (Line 241)

currentScissor :Uint32Array

Stores the current scissor data

Type:
  • Uint32Array
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 290)

currentScissorEnabled :boolean

Indicates if the the scissor state is enabled in WebGLRenderingContext

Type:
  • boolean
Since: 3.0.0
Default Value:
  • false
Source: src/renderer/webgl/WebGLRenderer.js (Line 280)

currentTextures :array

An array of the last texture handles that were bound to the WebGLRenderingContext

Type:
  • array
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 212)

currentType :string

The type of the Game Object being currently rendered. This can be used by advanced render functions for batching look-ahead.

Type:
  • string
Since: 3.19.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 497)

currentVertexBuffer :WebGLBuffer

Current WebGLBuffer (Vertex buffer) in use

Type:
  • WebGLBuffer
Since: 3.0.0
Default Value:
  • null
Source: src/renderer/webgl/WebGLRenderer.js (Line 251)

defaultCamera :Phaser.Cameras.Scene2D.BaseCamera

A default Camera used in calls when no other camera has been provided.

Type:
Since: 3.12.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 402)

<readonly> drawingBufferHeight :number

Cached drawing buffer height to reduce gl calls.

Type:
  • number
Since: 3.11.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 381)

extensions :object

Extensions loaded into the current context

Type:
  • object
Since: 3.0.0
Default Value:
  • {}
Source: src/renderer/webgl/WebGLRenderer.js (Line 348)

game :Phaser.Game

The Game instance which owns this WebGL Renderer.

Type:
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 89)

gl :WebGLRenderingContext

The underlying WebGL context of the renderer.

Type:
  • WebGLRenderingContext
Since: 3.0.0
Default Value:
  • null
Source: src/renderer/webgl/WebGLRenderer.js (Line 328)

glFormats :array

Stores the current WebGL component formats for further use

Type:
  • array
Since: 3.2.0
Default Value:
  • []
Source: src/renderer/webgl/WebGLRenderer.js (Line 358)

glFuncMap :any

Internal gl function mapping for uniform look-up. https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/uniform

Type:
  • any
Since: 3.17.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 487)

height :integer

The height of the canvas being rendered to. This is populated in the onResize event handler.

Type:
  • integer
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 117)

maskCount :integer

The total number of masks currently stacked.

Type:
  • integer
Since: 3.17.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 451)

maskStack :Array.<Phaser.Display.Masks.GeometryMask>

The mask stack.

Type:
Since: 3.17.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 460)

nativeTextures :array

Keeps track of any WebGLTexture created with the current WebGLRenderingContext

Type:
  • array
Since: 3.0.0
Default Value:
  • []
Source: src/renderer/webgl/WebGLRenderer.js (Line 148)

newType :boolean

Is the type of the Game Object being currently rendered different than the type of the object before it in the display list? I.e. it's a 'new' type.

Type:
  • boolean
Since: 3.19.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 507)

nextTypeMatch :boolean

Does the type of the next Game Object in the display list match that of the object being currently rendered?

Type:
  • boolean
Since: 3.19.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 517)

pipelines :object

This object will store all pipelines created through addPipeline

Type:
  • object
Since: 3.0.0
Default Value:
  • null
Source: src/renderer/webgl/WebGLRenderer.js (Line 168)

scissorStack :Uint32Array

Stack of scissor data

Type:
  • Uint32Array
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 299)

snapshotState :Phaser.Types.Renderer.Snapshot.SnapshotState

Details about the currently scheduled snapshot.

If a non-null callback is set in this object, a snapshot of the canvas will be taken after the current frame is fully rendered.

Type:
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 178)

supportedExtensions :object

Array of strings that indicate which WebGL extensions are supported by the browser

Type:
  • object
Since: 3.0.0
Default Value:
  • null
Source: src/renderer/webgl/WebGLRenderer.js (Line 338)

type :integer

A constant which allows the renderer to be easily identified as a WebGL Renderer.

Type:
  • integer
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 98)

width :integer

The width of the canvas being rendered to. This is populated in the onResize event handler.

Type:
  • integer
Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 107)

Methods


addBlendMode(func, equation)

Creates a new custom blend mode for the renderer.

See https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#Blending_modes

Parameters:
Name Type Description
func Array.<GLenum>

An array containing the WebGL functions to use for the source and the destination blending factors, respectively. See the possible constants for WebGLRenderingContext#blendFunc().

equation GLenum

The equation to use for combining the RGB and alpha components of a new pixel with a rendered one. See the possible constants for WebGLRenderingContext#blendEquation().

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1171)
Returns:

The index of the new blend mode, used for referencing it in the future.

Type
integer

addPipeline(pipelineName, pipelineInstance)

Adds a pipeline instance into the collection of pipelines

Parameters:
Name Type Description
pipelineName string

A unique string-based key for the pipeline.

pipelineInstance Phaser.Renderer.WebGL.WebGLPipeline

A pipeline instance which must extend WebGLPipeline.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 885)
Returns:

The pipeline instance that was passed.

Type
Phaser.Renderer.WebGL.WebGLPipeline

canvasToTexture(srcCanvas [, dstTexture] [, noRepeat])

Creates a WebGL Texture based on the given canvas element.

Parameters:
Name Type Argument Default Description
srcCanvas HTMLCanvasElement

The Canvas element that will be used to populate the texture.

dstTexture WebGLTexture <optional>

Is this going to replace an existing texture? If so, pass it here.

noRepeat boolean <optional>
false

Should this canvas never be allowed to set REPEAT? (such as for Text objects)

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2280)
Returns:

The newly created WebGL Texture.

Type
WebGLTexture

clearPipeline()

Flushes the current WebGLPipeline being used and then clears it, along with the the current shader program and vertex buffer. Then resets the blend mode to NORMAL. Call this before jumping to your own gl context handler, and then call rebindPipeline when you wish to return control to Phaser again.

Since: 3.16.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1105)

createFramebuffer(width, height, renderTexture, addDepthStencilBuffer)

Wrapper for creating WebGLFramebuffer.

Parameters:
Name Type Description
width integer

Width in pixels of the framebuffer

height integer

Height in pixels of the framebuffer

renderTexture WebGLTexture

The color texture to where the color pixels are written

addDepthStencilBuffer boolean

Indicates if the current framebuffer support depth and stencil buffers

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1539)
Returns:

Raw WebGLFramebuffer

Type
WebGLFramebuffer

createIndexBuffer(initialDataOrSize, bufferUsage)

Wrapper for creating a vertex buffer.

Parameters:
Name Type Description
initialDataOrSize ArrayBuffer

Either ArrayBuffer or an integer indicating the size of the vbo.

bufferUsage integer

How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1663)
Returns:

Raw index buffer

Type
WebGLBuffer

createProgram(vertexShader, fragmentShader)

Wrapper for creating a WebGLProgram

Parameters:
Name Type Description
vertexShader string

Source to the vertex shader

fragmentShader string

Source to the fragment shader

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1594)
Returns:

Raw WebGLProgram

Type
WebGLProgram

createTexture2D(mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, pma)

A wrapper for creating a WebGLTexture. If no pixel data is passed it will create an empty texture.

Parameters:
Name Type Description
mipLevel integer

Mip level of the texture.

minFilter integer

Filtering of the texture.

magFilter integer

Filtering of the texture.

wrapT integer

Wrapping mode of the texture.

wrapS integer

Wrapping mode of the texture.

format integer

Which format does the texture use.

pixels object

pixel data.

width integer

Width of the texture in pixels.

height integer

Height of the texture in pixels.

pma boolean

Does the texture have premultiplied alpha?

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1481)
Returns:

The WebGLTexture that was created.

Type
WebGLTexture

createTextureFromSource(source, width, height, scaleMode)

Creates a texture from an image source. If the source is not valid it creates an empty texture.

Parameters:
Name Type Description
source object

The source of the texture.

width integer

The width of the texture.

height integer

The height of the texture.

scaleMode integer

The scale mode to be used by the texture.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1436)
Returns:

The WebGL Texture that was created, or null if it couldn't be created.

Type
WebGLTexture

createVertexBuffer(initialDataOrSize, bufferUsage)

Wrapper for creating a vertex buffer.

Parameters:
Name Type Description
initialDataOrSize ArrayBuffer

It's either ArrayBuffer or an integer indicating the size of the vbo

bufferUsage integer

How the buffer is used. gl.DYNAMIC_DRAW, gl.STATIC_DRAW or gl.STREAM_DRAW

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1638)
Returns:

Raw vertex buffer

Type
WebGLBuffer

deleteBuffer(vertexBuffer)

Deletes a WebGLBuffer from the GL instance.

Parameters:
Name Type Description
vertexBuffer WebGLBuffer

The WebGLBuffer to be deleted.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1752)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

deleteFramebuffer(framebuffer)

Deletes a WebGLFramebuffer from the GL instance.

Parameters:
Name Type Description
framebuffer WebGLFramebuffer

The Framebuffer to be deleted.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1718)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

deleteProgram(program)

Deletes a WebGLProgram from the GL instance.

Parameters:
Name Type Description
program WebGLProgram

The shader program to be deleted.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1735)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

deleteTexture(texture)

Removes the given texture from the nativeTextures array and then deletes it from the GPU.

Parameters:
Name Type Description
texture WebGLTexture

The WebGL Texture to be deleted.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1688)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

destroy()

Destroy this WebGLRenderer, cleaning up all related resources such as pipelines, native textures, etc.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2711)

flush()

Flushes the current pipeline if the pipeline is bound

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 824)

getExtension(extensionName)

Loads a WebGL extension

Parameters:
Name Type Description
extensionName string

The name of the extension to load.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 802)
Returns:

WebGL extension if the extension is supported

Type
object

getMaxTextures()

Returns the maximum number of texture units that can be used in a fragment shader.

Since: 3.8.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2683)
Returns:

The maximum number of textures WebGL supports.

Type
integer

getMaxTextureSize()

Returns the largest texture size (either width or height) that can be created. Note that VRAM may not allow a texture of any given size, it just expresses hardware / driver support for a given size.

Since: 3.8.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2696)
Returns:

The maximum supported texture size.

Type
integer

getPipeline(pipelineName)

Returns the pipeline by name if the pipeline exists

Parameters:
Name Type Description
pipelineName string

The name of the pipeline.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 853)
Returns:

The pipeline instance, or null if not found.

Type
Phaser.Renderer.WebGL.WebGLPipeline

hasActiveStencilMask()

Is there an active stencil mask?

Since: 3.17.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1037)
Returns:

true if there is an active stencil mask, otherwise false.

Type
boolean

hasExtension(extensionName)

Checks if a WebGL extension is supported

Parameters:
Name Type Description
extensionName string

Name of the WebGL extension

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 787)
Returns:

true if the extension is supported, otherwise false.

Type
boolean

hasPipeline(pipelineName)

Checks if a pipeline is present in the current WebGLRenderer

Parameters:
Name Type Description
pipelineName string

The name of the pipeline.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 838)
Returns:

true if the given pipeline is loaded, otherwise false.

Type
boolean

init(config)

Creates a new WebGLRenderingContext and initializes all internal state.

Parameters:
Name Type Description
config object

The configuration object for the renderer.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 530)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

onResize(gameSize, baseSize, displaySize [, resolution])

The event handler that manages the resize event dispatched by the Scale Manager.

Parameters:
Name Type Argument Description
gameSize Phaser.Structs.Size

The default Game Size object. This is the un-modified game dimensions.

baseSize Phaser.Structs.Size

The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this.

displaySize Phaser.Structs.Size

The display Size object. The size of the canvas style width / height attributes.

resolution number <optional>

The Scale Manager resolution setting.

Since: 3.16.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 729)

popScissor()

Pops the last scissor state and sets it.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 986)

postRender()

The post-render step happens after all Cameras in all Scenes have been rendered.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2091)

postRenderCamera(camera)

Controls the post-render operations for the given camera. Renders the foreground camera effects like flash and fading. It resets the current scissor state.

Parameters:
Name Type Description
camera Phaser.Cameras.Scene2D.Camera

The Camera to post-render.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1865)

preRender()

Clears the current vertex buffer and updates pipelines.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1933)

preRenderCamera(camera)

Controls the pre-render operations for the given camera. Handles any clipping needed by the camera and renders the background color if a color is visible.

Parameters:
Name Type Description
camera Phaser.Cameras.Scene2D.Camera

The Camera to pre-render.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1769)

pushScissor(x, y, width, height [, drawingBufferHeight])

Pushes a new scissor state. This is used to set nested scissor states.

Parameters:
Name Type Argument Description
x integer

The x position of the scissor.

y integer

The y position of the scissor.

width integer

The width of the scissor.

height integer

The height of the scissor.

drawingBufferHeight integer <optional>

Optional drawingBufferHeight override value.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 914)
Returns:

An array containing the scissor values.

Type
Array.<integer>

rebindPipeline(pipelineInstance)

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 having previously called clearPipeline and then wishing to return control to Phaser again.

Parameters:
Name Type Description
pipelineInstance Phaser.Renderer.WebGL.WebGLPipeline

The pipeline instance to be activated.

Since: 3.16.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1053)

removeBlendMode(index)

Removes a custom blend mode from the renderer. Any Game Objects still using this blend mode will error, so be sure to clear them first.

Parameters:
Name Type Description
index integer

The index of the custom blend mode to be removed.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1218)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

removePipeline(pipelineName)

Removes a pipeline by name.

Parameters:
Name Type Description
pipelineName string

The name of the pipeline to be removed.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 868)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

render(scene, children, interpolationPercentage, camera)

The core render step for a Scene Camera.

Iterates through the given Game Object's array and renders them with the given Camera.

This is called by the CameraManager.render method. The Camera Manager instance belongs to a Scene, and is invoked by the Scene Systems.render method.

This method is not called if Camera.visible is false, or Camera.alpha is zero.

Parameters:
Name Type Description
scene Phaser.Scene

The Scene to render.

children Phaser.GameObjects.GameObject

The Game Object's within the Scene to be rendered.

interpolationPercentage number

The interpolation percentage to apply. Currently un-used.

camera Phaser.Cameras.Scene2D.Camera

The Scene Camera to render with.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1983)

resize( [width] [, height] [, resolution])

Resizes the drawing buffer to match that required by the Scale Manager.

Parameters:
Name Type Argument Description
width number <optional>

The new width of the renderer.

height number <optional>

The new height of the renderer.

resolution number <optional>

The new resolution of the renderer.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 749)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setBlendMode(blendModeId [, force])

Sets the blend mode to the value given.

If the current blend mode is different from the one given, the pipeline is flushed and the new blend mode is enabled.

Parameters:
Name Type Argument Default Description
blendModeId integer

The blend mode to be set. Can be a BlendModes const or an integer value.

force boolean <optional>
false

Force the blend mode to be set, regardless of the currently set blend mode.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1126)
Returns:

true if the blend mode was changed as a result of this call, forcing a flush, otherwise false.

Type
boolean

setFloat1(program, name, x)

[description]

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

x number

[description]

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2352)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setFloat1v(program, name, arr)

Sets the value of a uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

arr Float32Array

The new value to be used for the uniform variable.

Since: 3.13.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2442)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setFloat2(program, name, x, y)

[description]

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

x number

[description]

y number

[description]

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2373)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setFloat2v(program, name, arr)

Sets the value of a uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

arr Float32Array

The new value to be used for the uniform variable.

Since: 3.13.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2463)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setFloat3(program, name, x, y, z)

[description]

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

x number

[description]

y number

[description]

z number

[description]

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2395)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setFloat3v(program, name, arr)

Sets the value of a uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

arr Float32Array

The new value to be used for the uniform variable.

Since: 3.13.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2484)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setFloat4(program, name, x, y, z, w)

Sets uniform of a WebGLProgram

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

x number

X component

y number

Y component

z number

Z component

w number

W component

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2418)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setFloat4v(program, name, arr)

Sets the value of a uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

arr Float32Array

The new value to be used for the uniform variable.

Since: 3.13.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2505)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setFramebuffer(framebuffer [, updateScissor])

Binds a framebuffer. If there was another framebuffer already bound it will force a pipeline flush.

Parameters:
Name Type Argument Default Description
framebuffer WebGLFramebuffer

The framebuffer that needs to be bound.

updateScissor boolean <optional>
false

If a framebuffer is given, set the gl scissor to match the frame buffer size? Or, if null given, pop the scissor from the stack.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1300)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setIndexBuffer(indexBuffer)

Bounds a index buffer. If there is a index buffer already bound it'll force a pipeline flush.

Parameters:
Name Type Description
indexBuffer WebGLBuffer

The buffer the needs to be bound.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1410)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setInt1(program, name, x)

Sets the value of a uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

x integer

[description]

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2527)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setInt2(program, name, x, y)

Sets the value of a uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

x integer

The new X component

y integer

The new Y component

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2548)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setInt3(program, name, x, y, z)

Sets the value of a uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

x integer

The new X component

y integer

The new Y component

z integer

The new Z component

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2570)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setInt4(program, name, x, y, z, w)

Sets the value of a uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

x integer

X component

y integer

Y component

z integer

Z component

w integer

W component

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2593)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setMatrix2(program, name, transpose, matrix)

Sets the value of a 2x2 matrix uniform variable in the given WebGLProgram.

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

transpose boolean

The value indicating whether to transpose the matrix. Must be false.

matrix Float32Array

The new matrix value.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2617)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setMatrix3(program, name, transpose, matrix)

[description]

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

transpose boolean

[description]

matrix Float32Array

[description]

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2639)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setMatrix4(program, name, transpose, matrix)

Sets uniform of a WebGLProgram

Parameters:
Name Type Description
program WebGLProgram

The target WebGLProgram from which the uniform location will be looked-up.

name string

The name of the uniform to look-up and modify.

transpose boolean

Is the matrix transposed

matrix Float32Array

Matrix data

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2661)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setPipeline(pipelineInstance [, gameObject])

Binds a WebGLPipeline and sets it as the current pipeline to be used.

Parameters:
Name Type Argument Description
pipelineInstance Phaser.Renderer.WebGL.WebGLPipeline

The pipeline instance to be activated.

gameObject Phaser.GameObjects.GameObject <optional>

The Game Object that invoked this pipeline, if any.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1010)
Returns:

The pipeline that was activated.

Type
Phaser.Renderer.WebGL.WebGLPipeline

setProgram(program)

Binds a program. If there was another program already bound it will force a pipeline flush.

Parameters:
Name Type Description
program WebGLProgram

The program that needs to be bound.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1358)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setScissor(x, y, width, height [, drawingBufferHeight])

Sets the current scissor state.

Parameters:
Name Type Argument Description
x integer

The x position of the scissor.

y integer

The y position of the scissor.

width integer

The width of the scissor.

height integer

The height of the scissor.

drawingBufferHeight integer <optional>

Optional drawingBufferHeight override value.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 945)

setTexture2D(texture, textureUnit [, flush])

Binds a texture at a texture unit. If a texture is already bound to that unit it will force a flush on the current pipeline.

Parameters:
Name Type Argument Default Description
texture WebGLTexture

The WebGL texture that needs to be bound.

textureUnit integer

The texture unit to which the texture will be bound.

flush boolean <optional>
true

Will the current pipeline be flushed if this is a new texture, or not?

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1259)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setTextureFilter(texture, filter)

Sets the minification and magnification filter for a texture.

Parameters:
Name Type Description
texture integer

The texture to set the filter for.

filter integer

The filter to set. 0 for linear filtering, 1 for nearest neighbor (blocky) filtering.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2326)
Returns:

This WebGL Renderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

setVertexBuffer(vertexBuffer)

Bounds a vertex buffer. If there is a vertex buffer already bound it'll force a pipeline flush.

Parameters:
Name Type Description
vertexBuffer WebGLBuffer

The buffer that needs to be bound.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1384)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer

snapshot(callback [, type] [, encoderOptions])

Schedules a snapshot of the entire game viewport to be taken after the current frame is rendered.

To capture a specific area see the snapshotArea method. To capture a specific pixel, see snapshotPixel.

Only one snapshot can be active per frame. If you have already called snapshotPixel, for example, then calling this method will override it.

Snapshots work by using the WebGL readPixels feature to grab every pixel from the frame buffer into an ArrayBufferView. It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it, which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process, which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game.

Parameters:
Name Type Argument Default Description
callback Phaser.Types.Renderer.Snapshot.SnapshotCallback

The Function to invoke after the snapshot image is created.

type string <optional>
'image/png'

The format of the image to create, usually image/png or image/jpeg.

encoderOptions number <optional>
0.92

The image quality, between 0 and 1. Used for image formats with lossy compression, such as image/jpeg.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2122)
Returns:

This WebGL Renderer.

Type
Phaser.Renderer.WebGL.WebGLRenderer

snapshotArea(x, y, width, height, callback [, type] [, encoderOptions])

Schedules a snapshot of the given area of the game viewport to be taken after the current frame is rendered.

To capture the whole game viewport see the snapshot method. To capture a specific pixel, see snapshotPixel.

Only one snapshot can be active per frame. If you have already called snapshotPixel, for example, then calling this method will override it.

Snapshots work by using the WebGL readPixels feature to grab every pixel from the frame buffer into an ArrayBufferView. It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it, which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process, which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game.

Parameters:
Name Type Argument Default Description
x integer

The x coordinate to grab from.

y integer

The y coordinate to grab from.

width integer

The width of the area to grab.

height integer

The height of the area to grab.

callback Phaser.Types.Renderer.Snapshot.SnapshotCallback

The Function to invoke after the snapshot image is created.

type string <optional>
'image/png'

The format of the image to create, usually image/png or image/jpeg.

encoderOptions number <optional>
0.92

The image quality, between 0 and 1. Used for image formats with lossy compression, such as image/jpeg.

Since: 3.16.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2149)
Returns:

This WebGL Renderer.

Type
Phaser.Renderer.WebGL.WebGLRenderer

snapshotFramebuffer(framebuffer, bufferWidth, bufferHeight, callback [, getPixel] [, x] [, y] [, width] [, height] [, type] [, encoderOptions])

Takes a snapshot of the given area of the given frame buffer.

Unlike the other snapshot methods, this one is processed immediately and doesn't wait for the next render.

Snapshots work by using the WebGL readPixels feature to grab every pixel from the frame buffer into an ArrayBufferView. It then parses this, copying the contents to a temporary Canvas and finally creating an Image object from it, which is the image returned to the callback provided. All in all, this is a computationally expensive and blocking process, which gets more expensive the larger the canvas size gets, so please be careful how you employ this in your game.

Parameters:
Name Type Argument Default Description
framebuffer WebGLFramebuffer

The framebuffer to grab from.

bufferWidth integer

The width of the framebuffer.

bufferHeight integer

The height of the framebuffer.

callback Phaser.Types.Renderer.Snapshot.SnapshotCallback

The Function to invoke after the snapshot image is created.

getPixel boolean <optional>
false

Grab a single pixel as a Color object, or an area as an Image object?

x integer <optional>
0

The x coordinate to grab from.

y integer <optional>
0

The y coordinate to grab from.

width integer <optional>
bufferWidth

The width of the area to grab.

height integer <optional>
bufferHeight

The height of the area to grab.

type string <optional>
'image/png'

The format of the image to create, usually image/png or image/jpeg.

encoderOptions number <optional>
0.92

The image quality, between 0 and 1. Used for image formats with lossy compression, such as image/jpeg.

Since: 3.19.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2221)
Returns:

This WebGL Renderer.

Type
Phaser.Renderer.WebGL.WebGLRenderer

snapshotPixel(x, y, callback)

Schedules a snapshot of the given pixel from the game viewport to be taken after the current frame is rendered.

To capture the whole game viewport see the snapshot method. To capture a specific area, see snapshotArea.

Only one snapshot can be active per frame. If you have already called snapshotArea, for example, then calling this method will override it.

Unlike the other two snapshot methods, this one will return a Color object containing the color data for the requested pixel. It doesn't need to create an internal Canvas or Image object, so is a lot faster to execute, using less memory.

Parameters:
Name Type Description
x integer

The x coordinate of the pixel to get.

y integer

The y coordinate of the pixel to get.

callback Phaser.Types.Renderer.Snapshot.SnapshotCallback

The Function to invoke after the snapshot pixel data is extracted.

Since: 3.16.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 2191)
Returns:

This WebGL Renderer.

Type
Phaser.Renderer.WebGL.WebGLRenderer

updateBlendMode(index, func, equation)

Updates the function bound to a given custom blend mode.

Parameters:
Name Type Description
index integer

The index of the custom blend mode.

func function

The function to use for the blend mode.

equation function

The equation to use for the blend mode.

Since: 3.0.0
Source: src/renderer/webgl/WebGLRenderer.js (Line 1191)
Returns:

This WebGLRenderer instance.

Type
Phaser.Renderer.WebGL.WebGLRenderer