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 34)
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 393)
-
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 138)
-
canvas :HTMLCanvasElement
-
The canvas which this WebGL Renderer draws to.
Type:
- HTMLCanvasElement
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 129)
-
compression :array
-
Stores the supported WebGL texture compression formats.
Type:
- array
- Since: 3.8.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 370)
-
config :object
-
The local configuration settings of this WebGL Renderer.
Type:
- object
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 70)
-
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 160)
-
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 310)
-
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 320)
-
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 205)
-
currentBlendMode :integer
-
Current blend mode in use
Type:
- integer
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 273)
-
currentCameraMask :any
-
Internal property that tracks the currently set camera mask.
Type:
- any
- Since: 3.17.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 480)
-
currentFramebuffer :WebGLFramebuffer
-
Current framebuffer in use
Type:
- WebGLFramebuffer
- Since: 3.0.0
- Default Value:
-
- null
- Source: src/renderer/webgl/WebGLRenderer.js (Line 223)
-
currentIndexBuffer :WebGLBuffer
-
Current WebGLBuffer (Index buffer) in use
Type:
- WebGLBuffer
- Since: 3.0.0
- Default Value:
-
- null
- Source: src/renderer/webgl/WebGLRenderer.js (Line 263)
-
currentMask :any
-
Internal property that tracks the currently set mask.
Type:
- any
- Since: 3.17.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 471)
-
currentPipeline :Phaser.Renderer.WebGL.WebGLPipeline
-
Current WebGLPipeline in use
Type:
- Since: 3.0.0
- Default Value:
-
- null
- Source: src/renderer/webgl/WebGLRenderer.js (Line 233)
-
currentProgram :WebGLProgram
-
Current WebGLProgram in use
Type:
- WebGLProgram
- Since: 3.0.0
- Default Value:
-
- null
- Source: src/renderer/webgl/WebGLRenderer.js (Line 243)
-
currentScissor :Uint32Array
-
Stores the current scissor data
Type:
- Uint32Array
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 292)
-
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 282)
-
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 214)
-
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 499)
-
currentVertexBuffer :WebGLBuffer
-
Current WebGLBuffer (Vertex buffer) in use
Type:
- WebGLBuffer
- Since: 3.0.0
- Default Value:
-
- null
- Source: src/renderer/webgl/WebGLRenderer.js (Line 253)
-
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 404)
-
<readonly> drawingBufferHeight :number
-
Cached drawing buffer height to reduce gl calls.
Type:
- number
- Since: 3.11.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 383)
-
extensions :object
-
Extensions loaded into the current context
Type:
- object
- Since: 3.0.0
- Default Value:
-
- {}
- Source: src/renderer/webgl/WebGLRenderer.js (Line 350)
-
game :Phaser.Game
-
The Game instance which owns this WebGL Renderer.
Type:
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 91)
-
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 330)
-
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 360)
-
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 489)
-
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 119)
-
maskCount :integer
-
The total number of masks currently stacked.
Type:
- integer
- Since: 3.17.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 453)
-
maskStack :Array.<Phaser.Display.Masks.GeometryMask>
-
The mask stack.
Type:
- Since: 3.17.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 462)
-
mipmapFilter :GLenum
-
The mipmap magFilter to be used when creating textures.
You can specify this as a string in the game config, i.e.:
renderer: { 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
Type:
- GLenum
- Since: 3.21.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 529)
-
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 150)
-
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 509)
-
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 519)
-
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 170)
-
scissorStack :Uint32Array
-
Stack of scissor data
Type:
- Uint32Array
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 301)
-
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 180)
-
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 340)
-
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 100)
-
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 109)
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 1203)
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 917)
Returns:
The pipeline instance that was passed.
-
canvasToTexture(srcCanvas [, dstTexture] [, noRepeat] [, flipY])
-
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 Argument Default Description srcCanvas
HTMLCanvasElement The Canvas to create the WebGL Texture from
dstTexture
WebGLTexture <optional>
The destination WebGL Texture 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
?- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2335)
Returns:
The newly created, or updated, 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 1137)
-
createCanvasTexture(srcCanvas [, noRepeat] [, flipY])
-
Creates a new WebGL Texture based on the given Canvas Element.
Parameters:
Name Type Argument 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
?- Since: 3.20.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2365)
Returns:
The newly created WebGL Texture.
- Type
- WebGLTexture
-
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 1589)
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 1713)
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 1644)
Returns:
Raw WebGLProgram
- Type
- WebGLProgram
-
createTexture2D(mipLevel, minFilter, magFilter, wrapT, wrapS, format, pixels, width, height [, pma] [, forceSize] [, flipY])
-
A wrapper for creating a WebGLTexture. If no pixel data is passed it will create an empty texture.
Parameters:
Name Type Argument Default 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 <nullable>
pixel data.
width
integer Width of the texture in pixels.
height
integer Height of the texture in 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.- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 1517)
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 1468)
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 1688)
Returns:
Raw vertex buffer
- Type
- WebGLBuffer
-
createVideoTexture(srcVideo [, noRepeat] [, flipY])
-
Creates a new WebGL Texture based on the given HTML Video Element.
Parameters:
Name Type Argument 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
?- Since: 3.20.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2445)
Returns:
The newly created WebGL Texture.
- Type
- WebGLTexture
-
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 1802)
Returns:
This WebGLRenderer instance.
-
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 1768)
Returns:
This WebGLRenderer instance.
-
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 1785)
Returns:
This WebGLRenderer instance.
-
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 1738)
Returns:
This WebGLRenderer instance.
-
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 2940)
-
flush()
-
Flushes the current pipeline if the pipeline is bound
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 856)
-
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 834)
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 2912)
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 2925)
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 885)
Returns:
The pipeline instance, or
null
if not found. -
hasActiveStencilMask()
-
Is there an active stencil mask?
- Since: 3.17.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 1069)
Returns:
true
if there is an active stencil mask, otherwisefalse
.- 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 819)
Returns:
true
if the extension is supported, otherwisefalse
.- 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 870)
Returns:
true
if the given pipeline is loaded, otherwisefalse
.- 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 558)
Returns:
This WebGLRenderer instance.
-
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 761)
-
popScissor()
-
Pops the last scissor state and sets it.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 1018)
-
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 2146)
-
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 1915)
-
preRender()
-
Clears the current vertex buffer and updates pipelines.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 1988)
-
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 1819)
-
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 946)
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
andSTENCIL_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 1085)
- Disable
-
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 1250)
Returns:
This WebGLRenderer instance.
-
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 900)
Returns:
This WebGLRenderer instance.
-
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
isfalse
, orCamera.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 2038)
-
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 781)
Returns:
This WebGLRenderer instance.
-
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 1158)
Returns:
true
if the blend mode was changed as a result of this call, forcing a flush, otherwisefalse
.- Type
- boolean
-
setFloat1(program, name, x)
-
Sets a 1f uniform value on the given shader.
If the shader is not currently active, it is made active first.
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 The 1f value to set on the named uniform.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2551)
Returns:
This WebGL Renderer instance.
-
setFloat1v(program, name, arr)
-
Sets the value of a 1fv uniform variable in the given WebGLProgram.
If the shader is not currently active, it is made active first.
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 2649)
Returns:
This WebGL Renderer instance.
-
setFloat2(program, name, x, y)
-
Sets the 2f uniform values on the given shader.
If the shader is not currently active, it is made active first.
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 The 2f x value to set on the named uniform.
y
number The 2f y value to set on the named uniform.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2574)
Returns:
This WebGL Renderer instance.
-
setFloat2v(program, name, arr)
-
Sets the value of a 2fv uniform variable in the given WebGLProgram.
If the shader is not currently active, it is made active first.
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 2672)
Returns:
This WebGL Renderer instance.
-
setFloat3(program, name, x, y, z)
-
Sets the 3f uniform values on the given shader.
If the shader is not currently active, it is made active first.
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 The 3f x value to set on the named uniform.
y
number The 3f y value to set on the named uniform.
z
number The 3f z value to set on the named uniform.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2598)
Returns:
This WebGL Renderer instance.
-
setFloat3v(program, name, arr)
-
Sets the value of a 3fv uniform variable in the given WebGLProgram.
If the shader is not currently active, it is made active first.
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 2695)
Returns:
This WebGL Renderer instance.
-
setFloat4(program, name, x, y, z, w)
-
Sets the 4f uniform values on the given shader.
If the shader is not currently active, it is made active first.
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 The 4f x value to set on the named uniform.
y
number The 4f y value to set on the named uniform.
z
number The 4f z value to set on the named uniform.
w
number The 4f w value to set on the named uniform.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2623)
Returns:
This WebGL Renderer instance.
-
setFloat4v(program, name, arr)
-
Sets the value of a 4fv uniform variable in the given WebGLProgram.
If the shader is not currently active, it is made active first.
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 2718)
Returns:
This WebGL Renderer instance.
-
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 1332)
Returns:
This WebGLRenderer instance.
-
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 1442)
Returns:
This WebGLRenderer instance.
-
setInt1(program, name, x)
-
Sets a 1i uniform value on the given shader.
If the shader is not currently active, it is made active first.
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 1i value to set on the named uniform.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2742)
Returns:
This WebGL Renderer instance.
-
setInt2(program, name, x, y)
-
Sets the 2i uniform values on the given shader.
If the shader is not currently active, it is made active first.
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 2i x value to set on the named uniform.
y
integer The 2i y value to set on the named uniform.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2765)
Returns:
This WebGL Renderer instance.
-
setInt3(program, name, x, y, z)
-
Sets the 3i uniform values on the given shader.
If the shader is not currently active, it is made active first.
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 3i x value to set on the named uniform.
y
integer The 3i y value to set on the named uniform.
z
integer The 3i z value to set on the named uniform.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2789)
Returns:
This WebGL Renderer instance.
-
setInt4(program, name, x, y, z, w)
-
Sets the 4i uniform values on the given shader.
If the shader is not currently active, it is made active first.
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 4i x value to set on the named uniform.
y
integer The 4i y value to set on the named uniform.
z
integer The 4i z value to set on the named uniform.
w
integer The 4i w value to set on the named uniform.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2814)
Returns:
This WebGL Renderer instance.
-
setMatrix2(program, name, transpose, matrix)
-
Sets the value of a matrix 2fv uniform variable in the given WebGLProgram.
If the shader is not currently active, it is made active first.
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 A Float32Array or sequence of 4 float values.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2840)
Returns:
This WebGL Renderer instance.
-
setMatrix3(program, name, transpose, matrix)
-
Sets the value of a matrix 3fv uniform variable in the given WebGLProgram.
If the shader is not currently active, it is made active first.
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 A Float32Array or sequence of 9 float values.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2864)
Returns:
This WebGL Renderer instance.
-
setMatrix4(program, name, transpose, matrix)
-
Sets the value of a matrix 4fv uniform variable in the given WebGLProgram.
If the shader is not currently active, it is made active first.
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 A Float32Array or sequence of 16 float values.
- Since: 3.0.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2888)
Returns:
This WebGL Renderer instance.
-
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 1042)
Returns:
The pipeline that was activated.
-
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 1390)
Returns:
This WebGLRenderer instance.
-
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 977)
-
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 1291)
Returns:
This WebGLRenderer instance.
-
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 2525)
Returns:
This WebGL Renderer instance.
-
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 1416)
Returns:
This WebGLRenderer instance.
-
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, seesnapshotPixel
.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
orimage/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 2177)
Returns:
This WebGL Renderer.
-
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, seesnapshotPixel
.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
orimage/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 2204)
Returns:
This WebGL Renderer.
-
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
orimage/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 2276)
Returns:
This WebGL Renderer.
-
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, seesnapshotArea
.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 2246)
Returns:
This WebGL Renderer.
-
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 1223)
Returns:
This WebGLRenderer instance.
-
updateCanvasTexture(srcCanvas, dstTexture [, flipY])
-
Updates a WebGL Texture based on the given Canvas Element.
Parameters:
Name Type Argument Default Description srcCanvas
HTMLCanvasElement The Canvas to update the WebGL Texture from.
dstTexture
WebGLTexture The destination WebGL Texture to update.
flipY
boolean <optional>
false Should the WebGL Texture set
UNPACK_MULTIPLY_FLIP_Y
?- Since: 3.20.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2407)
Returns:
The updated WebGL Texture.
- Type
- WebGLTexture
-
updateVideoTexture(srcVideo, dstTexture [, flipY])
-
Updates a WebGL Texture based on the given HTML Video Element.
Parameters:
Name Type Argument Default Description srcVideo
HTMLVideoElement The Video to update the WebGL Texture with.
dstTexture
WebGLTexture The destination WebGL Texture to update.
flipY
boolean <optional>
false Should the WebGL Texture set
UNPACK_MULTIPLY_FLIP_Y
?- Since: 3.20.0
- Source: src/renderer/webgl/WebGLRenderer.js (Line 2487)
Returns:
The updated WebGL Texture.
- Type
- WebGLTexture