Phaser API Documentation

  Version: 
Filter

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.

Constructor:

new WebGLRenderer(game)

Parameters:

name type description
game Phaser.Game

The Game instance which owns this WebGL Renderer.

Since: 3.0.0

Extends


Members

<private> _debugCapture: boolean
Focus
Focus

Description:

Is Spector currently capturing a WebGL frame?

Type:
boolean
Since: 3.60.0
Focus
Focus

Description:

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

Type:
Since: 3.12.0
Focus
Focus
blendModes: array
Focus
Focus

Description:

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
Default: []
Since: 3.0.0
Focus
Focus
canvas: HTMLCanvasElement
Focus
Focus

Description:

The canvas which this WebGL Renderer draws to.

Type:
HTMLCanvasElement
Since: 3.0.0
Focus
Focus

Description:

Stores the WebGL texture compression formats that this device and browser supports.

Support for using compressed texture formats was added in Phaser version 3.60.

Type:
Since: 3.8.0
Focus
Focus
config: object
Focus
Focus

Description:

The local configuration settings of this WebGL Renderer.

Type:
object
Since: 3.0.0
Focus
Focus
contextLost: boolean
Focus
Focus

Description:

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

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
contextLostHandler: function
Focus
Focus

Description:

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

Type:
function
Since: 3.19.0
Focus
Focus
contextRestoredHandler: function
Focus
Focus

Description:

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

Type:
function
Since: 3.19.0
Focus
Focus
currentBlendMode: number
Focus
Focus

Description:

Current blend mode in use

Type:
number
Since: 3.0.0
Focus
Focus
currentCameraMask: any
Focus
Focus

Description:

Internal property that tracks the currently set camera mask.

Type:
any
Since: 3.17.0
Focus
Focus

Description:

The currently bound framebuffer in use.

Type:
Default: null
Since: 3.0.0
Focus
Focus
currentMask: any
Focus
Focus

Description:

Internal property that tracks the currently set mask.

Type:
any
Since: 3.17.0
Focus
Focus

Description:

Current WebGLProgram in use.

Type:
Default: null
Since: 3.0.0
Focus
Focus
currentScissor: Uint32Array
Focus
Focus

Description:

Stores the current scissor data

Type:
Uint32Array
Since: 3.0.0
Focus
Focus
currentScissorEnabled: boolean
Focus
Focus

Description:

Indicates if the the scissor state is enabled in WebGLRenderingContext

Type:
boolean
Default: false
Since: 3.0.0
Focus
Focus
currentType: string
Focus
Focus

Description:

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
Focus
Focus
<private> defaultScissor: Array.<number>
Focus
Focus

Description:

The default scissor, set during preRender and modified during resize.

Type:
Array.<number>
Since: 3.50.0
Focus
Focus
<readonly> drawingBufferHeight: number
Focus
Focus

Description:

Cached drawing buffer height to reduce gl calls.

Type:
number
Since: 3.11.0
Focus
Focus
extensions: object
Focus
Focus

Description:

The WebGL Extensions loaded into the current context.

Type:
object
Default: {}
Since: 3.0.0
Focus
Focus

Description:

A stack into which the frame buffer objects are pushed and popped.

Type:
Since: 3.50.0
Focus
Focus
finalType: boolean
Focus
Focus

Description:

Is the Game Object being currently rendered the final one in the list?

Type:
boolean
Since: 3.50.0
Focus
Focus
game: Phaser.Game
Focus
Focus

Description:

The Game instance which owns this WebGL Renderer.

Type:
Since: 3.0.0
Focus
Focus
gl: WebGLRenderingContext
Focus
Focus

Description:

The underlying WebGL context of the renderer.

Type:
WebGLRenderingContext
Default: null
Since: 3.0.0
Focus
Focus

Description:

A list of all WebGLAttribLocationWrappers that have been created by this renderer.

Type:
Since: 3.80.0
Focus
Focus

Description:

A list of all WebGLBufferWrappers that have been created by this renderer.

Type:
Since: 3.80.0
Focus
Focus
glFormats: array
Focus
Focus

Description:

Stores the current WebGL component formats for further use.

This array is populated in the init method.

Type:
array
Since: 3.2.0
Focus
Focus

Description:

A list of all WebGLFramebufferWrappers that have been created by this renderer.

Type:
Since: 3.80.0
Focus
Focus
glFuncMap: any
Focus
Focus

Description:

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
Focus
Focus

Description:

A list of all WebGLProgramWrappers that have been created by this renderer.

Type:
Since: 3.80.0
Focus
Focus

Description:

A list of all WebGLTextureWrappers that have been created by this renderer.

Type:
Since: 3.80.0
Focus
Focus

Description:

A list of all WebGLUniformLocationWrappers that have been created by this renderer.

Type:
Since: 3.80.0
Focus
Focus
height: number
Focus
Focus

Description:

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

Type:
number
Since: 3.0.0
Focus
Focus
instancedArraysExtension: ANGLE_instanced_arrays
Focus
Focus

Description:

If the browser supports the ANGLE_instanced_arrays extension, this property will hold a reference to the glExtension for it.

This is populated in the setExtensions method.

Type:
ANGLE_instanced_arrays
Default: null
Since: 3.50.0
Focus
Focus
isBooted: boolean
Focus
Focus

Description:

Has this renderer fully booted yet?

Type:
boolean
Since: 3.50.0
Focus
Focus
maskCount: number
Focus
Focus

Description:

The total number of masks currently stacked.

Type:
number
Since: 3.17.0
Focus
Focus

Description:

A RenderTarget used by the BitmapMask Pipeline.

This is the source, i.e. the masked Game Object itself.

Type:
Since: 3.60.0
Focus
Focus

Description:

The mask stack.

Type:
Since: 3.17.0
Focus
Focus

Description:

A RenderTarget used by the BitmapMask Pipeline.

This is the target, i.e. the framebuffer the masked objects are drawn to.

Type:
Since: 3.60.0
Focus
Focus
maxTextures: number
Focus
Focus

Description:

The maximum number of textures the GPU can handle. The minimum under the WebGL1 spec is 8. This is set via the Game Config maxTextures property and should never be changed after boot.

Type:
number
Since: 3.50.0
Focus
Focus
mipmapFilter: GLenum
Focus
Focus

Description:

The mipmap magFilter to be used when creating textures.

You can specify this as a string in the game config, i.e.:

render: { mipmapFilter: 'NEAREST_MIPMAP_LINEAR' }

The 6 options for WebGL1 are, in order from least to most computationally expensive:

NEAREST (for pixel art) LINEAR (the default) NEAREST_MIPMAP_NEAREST LINEAR_MIPMAP_NEAREST NEAREST_MIPMAP_LINEAR LINEAR_MIPMAP_LINEAR

Mipmaps only work with textures that are fully power-of-two in size.

For more details see https://webglfundamentals.org/webgl/lessons/webgl-3d-textures.html

As of v3.60 no mipmaps will be generated unless a string is given in the game config. This saves on VRAM use when it may not be required. To obtain the previous result set the property to LINEAR in the config.

Type:
GLenum
Since: 3.21.0
Focus
Focus
newType: boolean
Focus
Focus

Description:

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
Focus
Focus
nextTypeMatch: boolean
Focus
Focus

Description:

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
Focus
Focus

Description:

A blank 1x1 #7f7fff texture, a flat normal map, as used by the Graphics system where needed. This is set in the boot method.

Type:
Since: 3.80.0
Focus
Focus

Description:

An instance of the Pipeline Manager class, that handles all WebGL Pipelines.

Use this to manage all of your interactions with pipelines, such as adding, getting, setting and rendering them.

The Pipeline Manager class is created in the init method and then populated with pipelines during the boot method.

Prior to Phaser v3.50.0 this was just a plain JavaScript object, not a class.

Type:
Since: 3.50.0
Focus
Focus
previousContextLostHandler: function
Focus
Focus

Description:

The previous contextLostHandler that was in use. This is set when setContextHandlers is called.

Type:
function
Since: 3.19.0
Focus
Focus
previousContextRestoredHandler: function
Focus
Focus

Description:

The previous contextRestoredHandler that was in use. This is set when setContextHandlers is called.

Type:
function
Since: 3.19.0
Focus
Focus
projectionHeight: number
Focus
Focus

Description:

The cached height of the Projection matrix.

Type:
number
Since: 3.50.0
Focus
Focus
projectionMatrix: Phaser.Math.Matrix4
Focus
Focus

Description:

The global game Projection matrix, used by shaders as 'uProjectionMatrix' uniform.

Type:
Since: 3.50.0
Focus
Focus
projectionWidth: number
Focus
Focus

Description:

The cached width of the Projection matrix.

Type:
number
Since: 3.50.0
Focus
Focus

Description:

A Render Target you can use to capture the current state of the Renderer.

A Render Target encapsulates a framebuffer and texture for the WebGL Renderer.

Type:
Since: 3.50.0
Focus
Focus
scissorStack: Uint32Array
Focus
Focus

Description:

Stack of scissor data

Type:
Uint32Array
Since: 3.0.0
Focus
Focus

Description:

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
Focus
Focus
spector: function
Focus
Focus

Description:

An instance of SpectorJS used for WebGL Debugging.

Only available in the Phaser Debug build.

Type:
function
Since: 3.60.0
Focus
Focus
supportedExtensions: Array.<string>
Focus
Focus

Description:

Array of strings that indicate which WebGL extensions are supported by the browser. This is populated in the setExtensions method.

Type:
Array.<string>
Default: null
Since: 3.0.0
Focus
Focus
textureIndexes: array
Focus
Focus

Description:

An array of the available WebGL texture units, used to populate the uSampler uniforms.

This array is populated during the init phase and should never be changed after boot.

Type:
array
Since: 3.50.0
Focus
Focus
type: number
Focus
Focus

Description:

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

Type:
number
Since: 3.0.0
Focus
Focus
vaoExtension: OES_vertex_array_object
Focus
Focus

Description:

If the browser supports the OES_vertex_array_object extension, this property will hold a reference to the glExtension for it.

This is populated in the setExtensions method.

Type:
OES_vertex_array_object
Default: null
Since: 3.50.0
Focus
Focus

Description:

A pure white 4x4 texture, as used by the Graphics system where needed. This is set in the boot method.

Type:
Since: 3.50.0
Focus
Focus
width: number
Focus
Focus

Description:

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

Type:
number
Since: 3.0.0
Focus
Focus

Methods

addBlendMode(func, equation)
Focus
Focus

Description:

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 {@link 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 {@link WebGLRenderingContext#blendEquation()}.

Returns:
Description:

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

Type:
  • number
Since: 3.0.0
Focus
Focus
addListener(event, fn, [context])
Focus
Focus

Description:

Add a listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#addListener
Since: 3.0.0
Focus
Focus
beginBitmapMask(mask, camera)
Focus
Focus

Description:

Binds necessary resources and renders the mask to a separated framebuffer. The framebuffer for the masked object is also bound for further use.

Parameters:

name type description
mask Phaser.Display.Masks.BitmapMask

The BitmapMask instance that called beginMask.

camera Phaser.Cameras.Scene2D.Camera

The camera rendering the current mask.

Since: 3.60.0
Focus
Focus
beginCapture([width], [height])
Focus
Focus

Description:

Binds the WebGL Renderers Render Target, so all drawn content is now redirected to it.

Make sure to call endCapture when you are finished.

Parameters:

name type arguments description
width number <optional>

Optional new width of the Render Target.

height number <optional>

Optional new height of the Render Target.

Since: 3.50.0
Focus
Focus
<private> boot()
Focus
Focus

Description:

Internal boot handler. Calls 'boot' on each pipeline.

Since: 3.11.0
Focus
Focus
canvasToTexture(srcCanvas, [dstTexture], [noRepeat], [flipY])
Focus
Focus

Description:

Creates a new WebGL Texture based on the given Canvas Element.

If the dstTexture parameter is given, the WebGL Texture is updated, rather than created fresh.

Parameters:

name type arguments Default description
srcCanvas HTMLCanvasElement

The Canvas to create the WebGL Texture from

dstTexture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper <optional>

The destination WebGLTextureWrapper to set.

noRepeat boolean <optional> false

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

flipY boolean <optional> false

Should the WebGL Texture set UNPACK_MULTIPLY_FLIP_Y?

Returns:
Description:

The newly created, or updated, WebGLTextureWrapper.

Since: 3.0.0
Focus
Focus
captureFrame([quickCapture], [fullCapture])
Focus
Focus

Description:

This method is only available in the Debug Build of Phaser, or a build with the WEBGL_DEBUG flag set in the Webpack Config.

Phaser v3.60 Debug has a build of Spector.js embedded in it, which is a WebGL inspector that allows for live inspection of your WebGL calls. Although it's easy to add the Spector extension to a desktop browsr, by embedding it in Phaser we can make it available in mobile browsers too, making it a powerful tool for debugging WebGL games on mobile devices where extensions are not permitted.

See https://github.com/BabylonJS/Spector.js for more details.

This method will capture the current WebGL frame and send it to the Spector.js tool for inspection.

Parameters:

name type arguments Default description
quickCapture boolean <optional> false

If true thumbnails are not captured in order to speed up the capture.

fullCapture boolean <optional> false

If true all details are captured.

Since: 3.60.0
Focus
Focus
captureNextFrame()
Focus
Focus

Description:

This method is only available in the Debug Build of Phaser, or a build with the WEBGL_DEBUG flag set in the Webpack Config.

Phaser v3.60 Debug has a build of Spector.js embedded in it, which is a WebGL inspector that allows for live inspection of your WebGL calls. Although it's easy to add the Spector extension to a desktop browsr, by embedding it in Phaser we can make it available in mobile browsers too, making it a powerful tool for debugging WebGL games on mobile devices where extensions are not permitted.

See https://github.com/BabylonJS/Spector.js for more details.

This method will capture the next WebGL frame and send it to the Spector.js tool for inspection.

Since: 3.60.0
Focus
Focus
clearStencilMask()
Focus
Focus

Description:

Disables the STENCIL_TEST but does not change the status of the current stencil mask.

Since: 3.60.0
Focus
Focus
createAttribLocation(program, name)
Focus
Focus

Description:

Creates a WebGLAttribLocationWrapper instance based on the given WebGLProgramWrapper and attribute name.

Parameters:

name type description
program Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper

The WebGLProgramWrapper instance.

name string

The name of the attribute.

Since: 3.80.0
Focus
Focus
createCanvasTexture(srcCanvas, [noRepeat], [flipY])
Focus
Focus

Description:

Creates a new WebGL Texture based on the given Canvas Element.

Parameters:

name type arguments Default description
srcCanvas HTMLCanvasElement

The Canvas to create the WebGL Texture from.

noRepeat boolean <optional> false

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

flipY boolean <optional> false

Should the WebGL Texture set UNPACK_MULTIPLY_FLIP_Y?

Returns:
Description:

The newly created WebGLTextureWrapper.

Since: 3.20.0
Focus
Focus
createFramebuffer(width, height, renderTexture, [addDepthStencilBuffer])
Focus
Focus

Description:

Creates a WebGL Framebuffer object and optionally binds a depth stencil render buffer.

This will unbind any currently bound framebuffer.

Parameters:

name type arguments Default description
width number

If addDepthStencilBuffer is true, this controls the width of the depth stencil.

height number

If addDepthStencilBuffer is true, this controls the height of the depth stencil.

renderTexture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

The color texture where the color pixels are written.

addDepthStencilBuffer boolean <optional> false

Create a Renderbuffer for the depth stencil?

Returns:
Description:

Wrapped framebuffer which is safe to use with the renderer.

Since: 3.0.0
Focus
Focus
createIndexBuffer(initialDataOrSize, bufferUsage)
Focus
Focus

Description:

Wrapper for creating a vertex buffer.

Parameters:

name type description
initialDataOrSize ArrayBuffer

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

bufferUsage number

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

Returns:
Description:

Wrapped index buffer

Since: 3.0.0
Focus
Focus
createProgram(vertexShader, fragmentShader)
Focus
Focus

Description:

Creates a WebGLProgram instance based on the given vertex and fragment shader source.

Then compiles, attaches and links the program before wrapping and returning it.

Parameters:

name type description
vertexShader string

The vertex shader source code as a single string.

fragmentShader string

The fragment shader source code as a single string.

Returns:
Description:

The wrapped, linked WebGLProgram created from the given shader source.

Since: 3.0.0
Focus
Focus
createTemporaryTextures()
Focus
Focus

Description:

Create temporary WebGL textures to stop WebGL errors on macOS.

Since: 3.60.0
Focus
Focus
createTexture2D(mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height, [pma], [forceSize], [flipY])
Focus
Focus

Description:

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

Parameters:

name type arguments Default description
mipLevel number

Mip level of the texture.

minFilter number

Filtering of the texture.

magFilter number

Filtering of the texture.

wrapT number

Wrapping mode of the texture.

wrapS number

Wrapping mode of the texture.

format number

Which format does the texture use.

pixels object

pixel data.

width number

Width of the texture in pixels. If not supplied, it must be derived from pixels.

height number

Height of the texture in pixels. If not supplied, it must be derived from pixels.

pma boolean <optional> true

Does the texture have premultiplied alpha?

forceSize boolean <optional> false

If true it will use the width and height passed to this method, regardless of the pixels dimension.

flipY boolean <optional> false

Sets the UNPACK_FLIP_Y_WEBGL flag the WebGL Texture uses during upload.

Returns:
Description:

The WebGLTextureWrapper that was created.

Since: 3.0.0
Focus
Focus
createTextureFromSource(source, width, height, scaleMode, [forceClamp])
Focus
Focus

Description:

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

Parameters:

name type arguments Default description
source object

The source of the texture.

width number

The width of the texture.

height number

The height of the texture.

scaleMode number

The scale mode to be used by the texture.

forceClamp boolean <optional> false

Force the texture to use the CLAMP_TO_EDGE wrap mode, even if a power of two?

Returns:
Description:

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

Since: 3.0.0
Focus
Focus
createUint8ArrayTexture(data, width, height)
Focus
Focus

Description:

Create a WebGLTexture from a Uint8Array.

The Uint8Array is assumed to be RGBA values, one byte per color component.

The texture will be filtered with gl.NEAREST and will not be mipped.

Parameters:

name type description
data Uint8Array

The Uint8Array to create the texture from.

width number

The width of the texture.

height number

The height of the texture.

Returns:
Description:

The newly created WebGLTextureWrapper.

Since: 3.80.0
Focus
Focus
createUniformLocation(program, name)
Focus
Focus

Description:

Creates a WebGLUniformLocationWrapper instance based on the given WebGLProgramWrapper and uniform name.

Parameters:

name type description
program Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper

The WebGLProgramWrapper instance.

name string

The name of the uniform.

Since: 3.80.0
Focus
Focus
createVertexBuffer(initialDataOrSize, bufferUsage)
Focus
Focus

Description:

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 number

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

Returns:
Description:

Wrapped vertex buffer

Since: 3.0.0
Focus
Focus
createVideoTexture(srcVideo, [noRepeat], [flipY])
Focus
Focus

Description:

Creates a new WebGL Texture based on the given HTML Video Element.

Parameters:

name type arguments Default description
srcVideo HTMLVideoElement

The Video to create the WebGL Texture from

noRepeat boolean <optional> false

Should this canvas be allowed to set REPEAT?

flipY boolean <optional> false

Should the WebGL Texture set UNPACK_MULTIPLY_FLIP_Y?

Returns:
Description:

The newly created WebGLTextureWrapper.

Since: 3.20.0
Focus
Focus
deleteAttribLocation(attrib)
Focus
Focus

Description:

Deletes a WebGLAttribLocation from the GL instance.

Parameters:

name type description
attrib Phaser.Renderer.WebGL.Wrappers.WebGLAttribLocationWrapper

The attrib location to be deleted.

Since: 3.80.0
Focus
Focus
deleteBuffer(vertexBuffer)
Focus
Focus

Description:

Deletes a WebGLBuffer from the GL instance.

Parameters:

name type description
vertexBuffer Phaser.Renderer.WebGL.Wrappers.WebGLBufferWrapper

The WebGLBuffer to be deleted.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
deleteFramebuffer(framebuffer)
Focus
Focus

Description:

Deletes a Framebuffer from the GL instance.

Parameters:

name type description
framebuffer null | Phaser.Renderer.WebGL.Wrappers.WebGLFramebufferWrapper

The Framebuffer to be deleted.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
deleteProgram(program)
Focus
Focus

Description:

Deletes a WebGLProgram from the GL instance.

Parameters:

name type description
program Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper

The shader program to be deleted.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
deleteTexture(texture)
Focus
Focus

Description:

Removes a texture from the GPU.

Parameters:

name type description
texture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

The WebGL Texture to be deleted.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
deleteUniformLocation(uniform)
Focus
Focus

Description:

Deletes a WebGLUniformLocation from the GL instance.

Parameters:

name type description
uniform Phaser.Renderer.WebGL.Wrappers.WebGLUniformLocationWrapper

The uniform location to be deleted.

Since: 3.80.0
Focus
Focus
destroy()
Focus
Focus

Description:

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

Overrides: Phaser.Events.EventEmitter#destroy
Since: 3.0.0
Focus
Focus
dispatchContextLost(event)
Focus
Focus

Description:

This method is called when the WebGL context is lost. By default this is bound to the property WebGLRenderer.contextLostHandler. If you override the context loss handler via the setContextHandlers method then be sure to invoke this method in due course.

Parameters:

name type description
event WebGLContextEvent

The WebGL context lost Event.

Since: 3.85.0
Focus
Focus
dispatchContextRestored(event)
Focus
Focus

Description:

This method is called when the WebGL context is restored. By default this is bound to the property WebGLRenderer.contextRestoredHandler. If you override the context restored handler via the setContextHandlers method then be sure to invoke this method in due course.

Parameters:

name type description
event WebGLContextEvent

The WebGL context restored Event.

Since: 3.85.0
Focus
Focus
drawBitmapMask(mask, camera, bitmapMaskPipeline)
Focus
Focus

Description:

Binds necessary resources and renders the mask to a separated framebuffer. The framebuffer for the masked object is also bound for further use.

Parameters:

name type description
mask Phaser.Display.Masks.BitmapMask

The BitmapMask instance that called beginMask.

camera Phaser.Cameras.Scene2D.Camera

The camera rendering the current mask.

bitmapMaskPipeline Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline

The BitmapMask Pipeline instance that is requesting the draw.

Since: 3.60.0
Focus
Focus
emit(event, [args])
Focus
Focus

Description:

Calls each of the listeners registered for a given event.

Parameters:

name type arguments description
event string | symbol

The event name.

args * <optional>

Additional arguments that will be passed to the event handler.

Returns:
Description:

true if the event had listeners, else false.

Type:
  • boolean
Inherited from: Phaser.Events.EventEmitter#emit
Since: 3.0.0
Focus
Focus
endCapture()
Focus
Focus

Description:

Unbinds the WebGL Renderers Render Target and returns it, stopping any further content being drawn to it.

If the viewport or scissors were modified during the capture, you should reset them by calling resetViewport and resetScissor accordingly.

Returns:
Description:

A reference to the WebGL Renderer Render Target.

Since: 3.50.0
Focus
Focus
eventNames()
Focus
Focus

Description:

Return an array listing the events for which the emitter has registered listeners.

Type:
  • Array.<(string
  • symbol)>
Inherited from: Phaser.Events.EventEmitter#eventNames
Since: 3.0.0
Focus
Focus
flush()
Focus
Focus

Description:

Flushes the current pipeline if the pipeline is bound

Since: 3.0.0
Focus
Focus
getAspectRatio()
Focus
Focus

Description:

Gets the aspect ratio of the WebGLRenderer dimensions.

Returns:
Description:

The aspect ratio of the WebGLRenderer dimensions.

Type:
  • number
Since: 3.50.0
Focus
Focus
getCompressedTextureName(baseFormat, [format])
Focus
Focus

Description:

Returns a compressed texture format GLenum name based on the given format.

Parameters:

name type arguments description
baseFormat string

The Base Format to check.

format GLenum <optional>

An optional GLenum format to check within the base format.

Returns:
Description:

The compressed texture format name, as a string.

Type:
  • string
Since: 3.60.0
Focus
Focus
getCompressedTextures()
Focus
Focus

Description:

Determines which compressed texture formats this browser and device supports.

Called automatically as part of the WebGL Renderer init process. If you need to investigate which formats it supports, see the Phaser.Renderer.WebGL.WebGLRenderer#compression property instead.

Returns:
Description:

The compression object.

Since: 3.60.0
Focus
Focus
<private> getCurrentStencilMask()
Focus
Focus

Description:

Return the current stencil mask.

Since: 3.50.0
Focus
Focus
getExtension(extensionName)
Focus
Focus

Description:

Loads a WebGL extension

Parameters:

name type description
extensionName string

The name of the extension to load.

Returns:
Description:

WebGL extension if the extension is supported

Type:
  • object
Since: 3.0.0
Focus
Focus
getFps()
Focus
Focus

Description:

This method is only available in the Debug Build of Phaser, or a build with the WEBGL_DEBUG flag set in the Webpack Config.

Phaser v3.60 Debug has a build of Spector.js embedded in it, which is a WebGL inspector that allows for live inspection of your WebGL calls. Although it's easy to add the Spector extension to a desktop browsr, by embedding it in Phaser we can make it available in mobile browsers too, making it a powerful tool for debugging WebGL games on mobile devices where extensions are not permitted.

See https://github.com/BabylonJS/Spector.js for more details.

This method will return the current FPS of the WebGL canvas.

Returns:
Description:

The current FPS of the WebGL canvas.

Type:
  • number
Since: 3.60.0
Focus
Focus
getMaxTextureSize()
Focus
Focus

Description:

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.

Returns:
Description:

The maximum supported texture size.

Type:
  • number
Since: 3.8.0
Focus
Focus
hasActiveStencilMask()
Focus
Focus

Description:

Is there an active stencil mask?

Returns:
Description:

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

Type:
  • boolean
Since: 3.17.0
Focus
Focus
hasExtension(extensionName)
Focus
Focus

Description:

Checks if a WebGL extension is supported

Parameters:

name type description
extensionName string

Name of the WebGL extension

Returns:
Description:

true if the extension is supported, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
init(config)
Focus
Focus

Description:

Creates a new WebGLRenderingContext and initializes all internal state.

Parameters:

name type description
config object

The configuration object for the renderer.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
isNewNormalMap(texture, normalMap)
Focus
Focus

Description:

Checks to see if the given diffuse and normal map textures are already bound, or not.

Parameters:

name type description
texture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

The diffuse texture.

normalMap Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

The normal map texture.

Returns:
Description:

Returns false if this combination is already set, or true if it's a new combination.

Type:
  • boolean
Since: 3.50.0
Focus
Focus
listenerCount(event)
Focus
Focus

Description:

Return the number of listeners listening to a given event.

Parameters:

name type description
event string | symbol

The event name.

Returns:
Description:

The number of listeners.

Type:
  • number
Inherited from: Phaser.Events.EventEmitter#listenerCount
Since: 3.0.0
Focus
Focus
listeners(event)
Focus
Focus

Description:

Return the listeners registered for a given event.

Parameters:

name type description
event string | symbol

The event name.

Returns:
Description:

The registered listeners.

Type:
  • Array.<function()>
Inherited from: Phaser.Events.EventEmitter#listeners
Since: 3.0.0
Focus
Focus
log(arguments)
Focus
Focus

Description:

This method is only available in the Debug Build of Phaser, or a build with the WEBGL_DEBUG flag set in the Webpack Config.

Phaser v3.60 Debug has a build of Spector.js embedded in it, which is a WebGL inspector that allows for live inspection of your WebGL calls. Although it's easy to add the Spector extension to a desktop browsr, by embedding it in Phaser we can make it available in mobile browsers too, making it a powerful tool for debugging WebGL games on mobile devices where extensions are not permitted.

See https://github.com/BabylonJS/Spector.js for more details.

This method adds a command with the name value in the list. This can be filtered in the search. All logs can be filtered searching for "LOG".

Parameters:

name type description
arguments *

The arguments to log to Spector.

Returns:
Description:

The current log.

Type:
  • string
Since: 3.60.0
Focus
Focus
off(event, [fn], [context], [once])
Focus
Focus

Description:

Remove the listeners of a given event.

Parameters:

name type arguments description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#off
Since: 3.0.0
Focus
Focus
on(event, fn, [context])
Focus
Focus

Description:

Add a listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#on
Since: 3.0.0
Focus
Focus
<private> onCapture(capture)
Focus
Focus

Description:

This method is only available in the Debug Build of Phaser, or a build with the WEBGL_DEBUG flag set in the Webpack Config.

Internal onCapture handler.

Parameters:

name type description
capture object

The capture data.

Since: 3.60.0
Focus
Focus
onResize(gameSize, baseSize)
Focus
Focus

Description:

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

Parameters:

name type 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. The canvas width / height values match this.

Since: 3.16.0
Focus
Focus
once(event, fn, [context])
Focus
Focus

Description:

Add a one-time listener for a given event.

Parameters:

name type arguments Default description
event string | symbol

The event name.

fn function

The listener function.

context * <optional> this

The context to invoke the listener with.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#once
Since: 3.0.0
Focus
Focus
popFramebuffer([updateScissor], [setViewport])
Focus
Focus

Description:

Pops the previous framebuffer from the fbo stack and sets it.

Parameters:

name type arguments Default description
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.

setViewport boolean <optional> true

Should the WebGL viewport be set?

Returns:
Description:

The Framebuffer that was set, or null if there aren't any more in the stack.

Since: 3.50.0
Focus
Focus
popScissor()
Focus
Focus

Description:

Pops the last scissor state and sets it.

Since: 3.0.0
Focus
Focus
postRender()
Focus
Focus

Description:

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

Since: 3.0.0
Focus
Focus
postRenderCamera(camera)
Focus
Focus

Description:

Controls the post-render operations for the given camera.

Renders the foreground camera effects like flash and fading, then resets the current scissor state.

Parameters:

name type description
camera Phaser.Cameras.Scene2D.Camera

The Camera to post-render.

Since: 3.0.0
Focus
Focus
preRender()
Focus
Focus

Description:

Clears the current vertex buffer and updates pipelines.

Since: 3.0.0
Focus
Focus
preRenderCamera(camera)
Focus
Focus

Description:

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
Focus
Focus
pushFramebuffer(framebuffer, [updateScissor], [setViewport], [texture], [clear])
Focus
Focus

Description:

Pushes a new framebuffer onto the FBO stack and makes it the currently bound framebuffer.

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

Call popFramebuffer to remove it again.

Parameters:

name type arguments Default description
framebuffer Phaser.Renderer.WebGL.Wrappers.WebGLFramebufferWrapper

The framebuffer that needs to be bound.

updateScissor boolean <optional> false

Set the gl scissor to match the frame buffer size? Or, if null given, pop the scissor from the stack.

setViewport boolean <optional> true

Should the WebGL viewport be set?

texture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper <optional> null

Bind the given frame buffer texture?

clear boolean <optional> false

Clear the frame buffer after binding?

Returns:
Description:

This WebGLRenderer instance.

Since: 3.50.0
Focus
Focus
pushScissor(x, y, width, height, [drawingBufferHeight])
Focus
Focus

Description:

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

Parameters:

name type arguments description
x number

The x position of the scissor.

y number

The y position of the scissor.

width number

The width of the scissor.

height number

The height of the scissor.

drawingBufferHeight number <optional>

Optional drawingBufferHeight override value.

Returns:
Description:

An array containing the scissor values.

Type:
  • Array.<number>
Since: 3.0.0
Focus
Focus
removeAllListeners([event])
Focus
Focus

Description:

Remove all listeners, or those of the specified event.

Parameters:

name type arguments description
event string | symbol <optional>

The event name.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#removeAllListeners
Since: 3.0.0
Focus
Focus
removeBlendMode(index)
Focus
Focus

Description:

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 number

The index of the custom blend mode to be removed.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
removeListener(event, [fn], [context], [once])
Focus
Focus

Description:

Remove the listeners of a given event.

Parameters:

name type arguments description
event string | symbol

The event name.

fn function <optional>

Only remove the listeners that match this function.

context * <optional>

Only remove the listeners that have this context.

once boolean <optional>

Only remove one-time listeners.

Returns:
Description:

this.

Inherited from: Phaser.Events.EventEmitter#removeListener
Since: 3.0.0
Focus
Focus
render(scene, children, camera)
Focus
Focus

Description:

The core render step for a Scene Camera.

Iterates through the given array of Game Objects 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 Array.<Phaser.GameObjects.GameObject>

An array of filtered Game Objects that can be rendered by the given Camera.

camera Phaser.Cameras.Scene2D.Camera

The Scene Camera to render with.

Since: 3.0.0
Focus
Focus
resetProgram()
Focus
Focus

Description:

Rebinds whatever program WebGLRenderer.currentProgram is set as, without changing anything, or flushing.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.50.0
Focus
Focus
resetProjectionMatrix()
Focus
Focus

Description:

Resets the Projection Matrix back to this renderers width and height.

This is called during endCapture, should the matrix have been changed as a result of the capture process.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.50.0
Focus
Focus
resetScissor()
Focus
Focus

Description:

Resets the gl scissor state to be whatever the current scissor is, if there is one, without modifying the scissor stack.

Since: 3.50.0
Focus
Focus
resetViewport()
Focus
Focus

Description:

Resets the gl viewport to the current renderer dimensions.

Since: 3.50.0
Focus
Focus
resize([width], [height])
Focus
Focus

Description:

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

Parameters:

name type arguments description
width number <optional>

The new width of the renderer.

height number <optional>

The new height of the renderer.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
restoreFramebuffer([updateScissor], [setViewport])
Focus
Focus

Description:

Restores the previous framebuffer from the fbo stack and sets it.

Parameters:

name type arguments Default description
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.

setViewport boolean <optional> true

Should the WebGL viewport be set?

Since: 3.60.0
Focus
Focus
restoreStencilMask()
Focus
Focus

Description:

Restores the current stencil function to the one that was in place before clearStencilMask was called.

Since: 3.60.0
Focus
Focus
setBlendMode(blendModeId, [force])
Focus
Focus

Description:

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 arguments Default description
blendModeId number

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.

Returns:
Description:

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

Type:
  • boolean
Since: 3.0.0
Focus
Focus
setContextHandlers([contextLost], [contextRestored])
Focus
Focus

Description:

Sets the handlers that are called when WebGL context is lost or restored by the browser.

The default handlers are referenced via the properties WebGLRenderer.contextLostHandler and WebGLRenderer.contextRestoredHandler. By default, these map to the methods WebGLRenderer.dispatchContextLost and WebGLRenderer.dispatchContextRestored.

You can override these handlers with your own via this method.

If you do override them, make sure that your handlers invoke the methods WebGLRenderer.dispatchContextLost and WebGLRenderer.dispatchContextRestored in due course, otherwise the renderer will not be able to restore itself fully.

Parameters:

name type arguments description
contextLost function <optional>

Custom handler for responding to the WebGL context lost event. Set as undefined to use the default handler.

contextRestored function <optional>

Custom handler for responding to the WebGL context restored event. Set as undefined to use the default handler.

Since: 3.85.0
Focus
Focus
setExtensions()
Focus
Focus

Description:

Queries the GL context to get the supported extensions.

Then sets them into the supportedExtensions, instancedArraysExtension and vaoExtension properties.

Called automatically during the init method.

Since: 3.85.2
Focus
Focus
setFramebuffer(framebuffer, [updateScissor], [setViewport], [texture], [clear])
Focus
Focus

Description:

Sets the given framebuffer as the active and currently bound framebuffer.

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

Typically, you should call pushFramebuffer instead of this method.

Parameters:

name type arguments Default description
framebuffer null | Phaser.Renderer.WebGL.Wrappers.WebGLFramebufferWrapper

The framebuffer that needs to be bound, or null to bind back to the default framebuffer.

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.

setViewport boolean <optional> true

Should the WebGL viewport be set?

texture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper <optional> null

Bind the given frame buffer texture?

clear boolean <optional> false

Clear the frame buffer after binding?

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
setProgram(program)
Focus
Focus

Description:

Binds a shader program.

If there was a different program already bound it will force a pipeline flush first.

If the same program given to this method is already set as the current program, no change will take place and this method will return false.

Parameters:

name type description
program Phaser.Renderer.WebGL.Wrappers.WebGLProgramWrapper

The program that needs to be bound.

Returns:
Description:

true if the given program was bound, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
setProjectionMatrix(width, height)
Focus
Focus

Description:

Sets the Projection Matrix of this renderer to the given dimensions.

Parameters:

name type description
width number

The new width of the Projection Matrix.

height number

The new height of the Projection Matrix.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.50.0
Focus
Focus
setScissor(x, y, width, height, [drawingBufferHeight])
Focus
Focus

Description:

Sets the current scissor state.

Parameters:

name type arguments description
x number

The x position of the scissor.

y number

The y position of the scissor.

width number

The width of the scissor.

height number

The height of the scissor.

drawingBufferHeight number <optional>

Optional drawingBufferHeight override value.

Since: 3.0.0
Focus
Focus
setTextureFilter(texture, filter)
Focus
Focus

Description:

Sets the minification and magnification filter for a texture.

Parameters:

name type description
texture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

The texture to set the filter for.

filter number

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

Returns:
Description:

This WebGL Renderer instance.

Since: 3.0.0
Focus
Focus
shutdown()
Focus
Focus

Description:

Removes all listeners.

Inherited from: Phaser.Events.EventEmitter#shutdown
Since: 3.0.0
Focus
Focus
snapshot(callback, [type], [encoderOptions])
Focus
Focus

Description:

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 arguments 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.

Returns:
Description:

This WebGL Renderer.

Since: 3.0.0
Focus
Focus
snapshotArea(x, y, width, height, callback, [type], [encoderOptions])
Focus
Focus

Description:

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 arguments Default description
x number

The x coordinate to grab from. This is based on the game viewport, not the world.

y number

The y coordinate to grab from. This is based on the game viewport, not the world.

width number

The width of the area to grab.

height number

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.

Returns:
Description:

This WebGL Renderer.

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

Description:

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 arguments Default description
framebuffer Phaser.Renderer.WebGL.Wrappers.WebGLFramebufferWrapper

The framebuffer to grab from.

bufferWidth number

The width of the framebuffer.

bufferHeight number

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 number <optional> 0

The x coordinate to grab from. This is based on the framebuffer, not the world.

y number <optional> 0

The y coordinate to grab from. This is based on the framebuffer, not the world.

width number <optional> bufferWidth

The width of the area to grab.

height number <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.

Returns:
Description:

This WebGL Renderer.

Since: 3.19.0
Focus
Focus
snapshotPixel(x, y, callback)
Focus
Focus

Description:

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 number

The x coordinate of the pixel to get. This is based on the game viewport, not the world.

y number

The y coordinate of the pixel to get. This is based on the game viewport, not the world.

callback Phaser.Types.Renderer.Snapshot.SnapshotCallback

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

Returns:
Description:

This WebGL Renderer.

Since: 3.16.0
Focus
Focus
startCapture([commandCount], [quickCapture], [fullCapture])
Focus
Focus

Description:

This method is only available in the Debug Build of Phaser, or a build with the WEBGL_DEBUG flag set in the Webpack Config.

Phaser v3.60 Debug has a build of Spector.js embedded in it, which is a WebGL inspector that allows for live inspection of your WebGL calls. Although it's easy to add the Spector extension to a desktop browsr, by embedding it in Phaser we can make it available in mobile browsers too, making it a powerful tool for debugging WebGL games on mobile devices where extensions are not permitted.

See https://github.com/BabylonJS/Spector.js for more details.

This method will start a capture on the Phaser canvas. The capture will stop once it reaches the number of commands specified as a parameter, or after 10 seconds. If quick capture is true, the thumbnails are not captured in order to speed up the capture.

Parameters:

name type arguments Default description
commandCount number <optional> 0

The number of commands to capture. If zero it will capture for 10 seconds.

quickCapture boolean <optional> false

If true thumbnails are not captured in order to speed up the capture.

fullCapture boolean <optional> false

If true all details are captured.

Since: 3.60.0
Focus
Focus
stopCapture()
Focus
Focus

Description:

This method is only available in the Debug Build of Phaser, or a build with the WEBGL_DEBUG flag set in the Webpack Config.

Phaser v3.60 Debug has a build of Spector.js embedded in it, which is a WebGL inspector that allows for live inspection of your WebGL calls. Although it's easy to add the Spector extension to a desktop browsr, by embedding it in Phaser we can make it available in mobile browsers too, making it a powerful tool for debugging WebGL games on mobile devices where extensions are not permitted.

See https://github.com/BabylonJS/Spector.js for more details.

This method will stop the current capture and returns the result in JSON. It displays the result if the UI has been displayed. This returns undefined if the capture has not been completed or did not find any commands.

Returns:
Description:

The current capture.

Type:
  • object
Since: 3.60.0
Focus
Focus
supportsCompressedTexture(baseFormat, [format])
Focus
Focus

Description:

Checks if the given compressed texture format is supported, or not.

Parameters:

name type arguments description
baseFormat string

The Base Format to check.

format GLenum <optional>

An optional GLenum format to check within the base format.

Returns:
Description:

True if the format is supported, otherwise false.

Type:
  • boolean
Since: 3.60.0
Focus
Focus
updateBlendMode(index, func, equation)
Focus
Focus

Description:

Updates the function bound to a given custom blend mode.

Parameters:

name type description
index number

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.

Returns:
Description:

This WebGLRenderer instance.

Since: 3.0.0
Focus
Focus
updateCanvasTexture(srcCanvas, dstTexture, [flipY], [noRepeat])
Focus
Focus

Description:

Updates a WebGL Texture based on the given Canvas Element.

Parameters:

name type arguments Default description
srcCanvas HTMLCanvasElement

The Canvas to update the WebGL Texture from.

dstTexture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

The destination WebGLTextureWrapper to update.

flipY boolean <optional> false

Should the WebGL Texture set UNPACK_MULTIPLY_FLIP_Y?

noRepeat boolean <optional> false

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

Returns:
Description:

The updated WebGLTextureWrapper. This is the same wrapper object as dstTexture.

Since: 3.20.0
Focus
Focus
updateVideoTexture(srcVideo, dstTexture, [flipY], [noRepeat])
Focus
Focus

Description:

Updates a WebGL Texture based on the given HTML Video Element.

Parameters:

name type arguments Default description
srcVideo HTMLVideoElement

The Video to update the WebGL Texture with.

dstTexture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper

The destination WebGLTextureWrapper to update.

flipY boolean <optional> false

Should the WebGL Texture set UNPACK_MULTIPLY_FLIP_Y?

noRepeat boolean <optional> false

Should this canvas be allowed to set REPEAT?

Returns:
Description:

The updated WebGLTextureWrapper. This is the same wrapper object as dstTexture.

Since: 3.20.0
Focus
Focus
videoToTexture(srcVideo, [dstTexture], [noRepeat], [flipY])
Focus
Focus

Description:

Creates or updates a WebGL Texture based on the given HTML Video Element.

If the dstTexture parameter is given, the WebGL Texture is updated, rather than created fresh.

Parameters:

name type arguments Default description
srcVideo HTMLVideoElement

The Video to create the WebGL Texture from

dstTexture Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper <optional>

The destination WebGLTextureWrapper to set.

noRepeat boolean <optional> false

Should this canvas be allowed to set REPEAT?

flipY boolean <optional> false

Should the WebGL Texture set UNPACK_MULTIPLY_FLIP_Y?

Returns:
Description:

The newly created, or updated, WebGLTextureWrapper.

Since: 3.85.0
Focus
Focus