WebGLRenderer is a class that contains the needed functionality to keep the WebGLRenderingContext state clean. The main idea of the WebGLRenderer is to keep track of any context change that happens for WebGL rendering inside of Phaser. This means if raw webgl functions are called outside the WebGLRenderer of the Phaser WebGL rendering ecosystem they might pollute the current WebGLRenderingContext state producing unexpected behavior. It's recommended that WebGL interaction is done through WebGLRenderer and/or WebGLPipeline.
new WebGLRenderer(game)
name | type | description |
---|---|---|
game | Phaser.Game |
The Game instance which owns this WebGL Renderer. |
A blank 32x32 transparent texture, as used by the Graphics system where needed.
This is set in the boot
method.
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.
The canvas which this WebGL Renderer draws to.
Stores the supported WebGL texture compression formats.
The local configuration settings of this WebGL Renderer.
This property is set to true
if the WebGL context of the renderer is lost.
The handler to invoke when the context is lost. This should not be changed and is set in the boot method.
The handler to invoke when the context is restored. This should not be changed and is set in the boot method.
Cached value for the last texture unit that was used.
Current blend mode in use
Internal property that tracks the currently set camera mask.
The currently bound framebuffer in use.
Internal property that tracks the currently set mask.
Current WebGLProgram in use.
Stores the current scissor data
Indicates if the the scissor state is enabled in WebGLRenderingContext
The type
of the Game Object being currently rendered.
This can be used by advanced render functions for batching look-ahead.
Cached drawing buffer height to reduce gl calls.
The WebGL Extensions loaded into the current context.
A stack into which the frame buffer objects are pushed and popped.
Is the Game Object being currently rendered the final one in the list?
The underlying WebGL context of the renderer.
Stores the current WebGL component formats for further use.
Internal gl function mapping for uniform look-up. https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/uniform
The height of the canvas being rendered to. This is populated in the onResize event handler.
If the browser supports the ANGLE_instanced_arrays
extension, this property will hold
a reference to the glExtension for it.
Has this renderer fully booted yet?
Are the WebGL Textures in their default state?
Used to avoid constant gl binds.
The total number of masks currently stacked.
The mask stack.
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.
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
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.
Does the type
of the next Game Object in the display list match that
of the object being currently rendered?
The currently bound normal map texture at texture unit one, if any.
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.
The cached height of the Projection matrix.
The global game Projection matrix, used by shaders as 'uProjectionMatrix' uniform.
The cached width of the Projection matrix.
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.
Stack of scissor data
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.
Contains the current starting active texture unit. This value is constantly updated and should be treated as read-only by your code.
Array of strings that indicate which WebGL extensions are supported by the browser.
This is populated in the boot
method.
An array of default temporary WebGL Textures.
This array is populated during the init phase and should never be changed after boot.
The number of times the renderer had to flush this frame, due to running out of texture units.
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.
The currently bound texture at texture unit zero, if any.
A constant which allows the renderer to be easily identified as a WebGL Renderer.
If the browser supports the OES_vertex_array_object
extension, this property will hold
a reference to the glExtension for it.
A pure white 4x4 texture, as used by the Graphics system where needed.
This is set in the boot
method.
The width of the canvas being rendered to. This is populated in the onResize event handler.
Creates a new custom blend mode for the renderer.
See https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants#Blending_modes
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()}. |
The index of the new blend mode, used for referencing it in the future.
Add a listener for a given event.
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. |
this
.
Binds the WebGL Renderers Render Target, so all drawn content is now redirected to it.
Make sure to call endCapture
when you are finished.
name | type | arguments | description |
---|---|---|---|
width | number | <optional> |
Optional new width of the Render Target. |
height | number | <optional> |
Optional new height of the Render Target. |
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.
name | type | arguments | 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 |
flipY | boolean | <optional> | false |
Should the WebGL Texture set |
The newly created, or updated, WebGL Texture.
Clears the texture that was directly bound to texture unit one and increases the start active texture counter.
Clears the texture that was directly bound to texture unit zero.
Creates a new WebGL Texture based on the given Canvas Element.
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 |
flipY | boolean | <optional> | false |
Should the WebGL Texture set |
The newly created WebGL Texture.
Creates a WebGL Framebuffer object and optionally binds a depth stencil render buffer.
name | type | arguments | Default | description |
---|---|---|---|---|
width | number |
If |
||
height | number |
If |
||
renderTexture | WebGLTexture |
The color texture where the color pixels are written. |
||
addDepthStencilBuffer | boolean | <optional> | false |
Create a Renderbuffer for the depth stencil? |
Raw WebGLFramebuffer
Wrapper for creating a vertex buffer.
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. |
Raw index buffer
Creates a WebGLProgram instance based on the given vertex and fragment shader source.
Then compiles, attaches and links the program before returning it.
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. |
The linked WebGLProgram created from the given shader source.
A wrapper for creating a WebGLTexture. If no pixel data is passed it will create an empty texture.
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. |
||
height | number |
Height of the texture in pixels. |
||
pma | boolean | <optional> | true |
Does the texture have premultiplied alpha? |
forceSize | boolean | <optional> | false |
If |
flipY | boolean | <optional> | false |
Sets the |
The WebGLTexture that was created.
Creates a texture from an image source. If the source is not valid it creates an empty texture.
name | type | 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. |
The WebGL Texture that was created, or null
if it couldn't be created.
Wrapper for creating a vertex buffer.
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 |
Raw vertex buffer
Creates a new WebGL Texture based on the given HTML Video Element.
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 |
flipY | boolean | <optional> | false |
Should the WebGL Texture set |
The newly created WebGL Texture.
Deletes a WebGLBuffer from the GL instance.
name | type | description |
---|---|---|
vertexBuffer | WebGLBuffer |
The WebGLBuffer to be deleted. |
This WebGLRenderer instance.
Deletes a WebGLFramebuffer from the GL instance.
name | type | description |
---|---|---|
framebuffer | WebGLFramebuffer |
The Framebuffer to be deleted. |
This WebGLRenderer instance.
Deletes a WebGLProgram from the GL instance.
name | type | description |
---|---|---|
program | WebGLProgram |
The shader program to be deleted. |
This WebGLRenderer instance.
Calls GL.deleteTexture
on the given WebGLTexture and also optionally
resets the currently defined textures.
name | type | arguments | Default | description |
---|---|---|---|---|
texture | WebGLTexture |
The WebGL Texture to be deleted. |
||
reset | boolean | <optional> | false |
Call the |
This WebGLRenderer instance.
Destroy this WebGLRenderer, cleaning up all related resources such as pipelines, native textures, etc.
Calls each of the listeners registered for a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
args | * | <optional> |
Additional arguments that will be passed to the event handler. |
true
if the event had listeners, else false
.
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.
A reference to the WebGL Renderer Render Target.
Return an array listing the events for which the emitter has registered listeners.
Flushes the current pipeline if the pipeline is bound
Gets the aspect ratio of the WebGLRenderer dimensions.
The aspect ratio of the WebGLRenderer dimensions.
Loads a WebGL extension
name | type | description |
---|---|---|
extensionName | string |
The name of the extension to load. |
WebGL extension if the extension is supported
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.
The maximum supported texture size.
Is there an active stencil mask?
true
if there is an active stencil mask, otherwise false
.
Checks if a WebGL extension is supported
name | type | description |
---|---|---|
extensionName | string |
Name of the WebGL extension |
true
if the extension is supported, otherwise false
.
Creates a new WebGLRenderingContext and initializes all internal state.
name | type | description |
---|---|---|
config | object |
The configuration object for the renderer. |
This WebGLRenderer instance.
Checks to see if the given diffuse and normal map textures are already bound, or not.
name | type | description |
---|---|---|
texture | WebGLTexture |
The WebGL diffuse texture. |
normalMap | WebGLTexture |
The WebGL normal map texture. |
Returns false
if this combination is already set, or true
if it's a new combination.
Return the number of listeners listening to a given event.
name | type | description |
---|---|---|
event | string | symbol |
The event name. |
The number of listeners.
Return the listeners registered for a given event.
name | type | description |
---|---|---|
event | string | symbol |
The event name. |
The registered listeners.
Remove the listeners of a given event.
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. |
this
.
Add a listener for a given event.
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. |
this
.
The event handler that manages the resize
event dispatched by the Scale Manager.
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. |
Add a one-time listener for a given event.
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. |
this
.
Pops the previous framebuffer from the fbo stack and sets it.
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 |
resetTextures | boolean | <optional> | false |
Should the WebGL Textures be reset after the new framebuffer is bound? |
setViewport | boolean | <optional> | true |
Should the WebGL viewport be set? |
The Framebuffer that was set, or null
if there aren't any more in the stack.
Pops the last scissor state and sets it.
The post-render step happens after all Cameras in all Scenes have been rendered.
Controls the post-render operations for the given camera.
Renders the foreground camera effects like flash and fading, then resets the current scissor state.
name | type | description |
---|---|---|
camera | Phaser.Cameras.Scene2D.Camera |
The Camera to post-render. |
Clears the current vertex buffer and updates pipelines.
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.
name | type | description |
---|---|---|
camera | Phaser.Cameras.Scene2D.Camera |
The Camera to pre-render. |
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.
name | type | arguments | Default | description |
---|---|---|---|---|
framebuffer | WebGLFramebuffer |
The framebuffer that needs to be bound. |
||
updateScissor | boolean | <optional> | false |
Set the gl scissor to match the frame buffer size? Or, if |
resetTextures | boolean | <optional> | false |
Should the WebGL Textures be reset after the new framebuffer is bound? |
setViewport | boolean | <optional> | true |
Should the WebGL viewport be set? |
This WebGLRenderer instance.
Pushes a new scissor state. This is used to set nested scissor states.
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. |
An array containing the scissor values.
Remove all listeners, or those of the specified event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol | <optional> |
The event name. |
this
.
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.
name | type | description |
---|---|---|
index | number |
The index of the custom blend mode to be removed. |
This WebGLRenderer instance.
Remove the listeners of a given event.
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. |
this
.
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.
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. |
Rebinds whatever program WebGLRenderer.currentProgram
is set as, without
changing anything, or flushing.
This WebGLRenderer instance.
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.
Resets the gl scissor state to be whatever the current scissor is, if there is one, without modifying the scissor stack.
Flushes the current pipeline, then resets the first two textures back to the default temporary textures, resets the start active counter and sets texture unit 1 as being active.
name | type | arguments | Default | description |
---|---|---|---|---|
all | boolean | <optional> | false |
Reset all textures, or just the first two? |
Resets the gl viewport to the current renderer dimensions.
Resizes the drawing buffer to match that required by the Scale Manager.
name | type | arguments | description |
---|---|---|---|
width | number | <optional> |
The new width of the renderer. |
height | number | <optional> |
The new height of the renderer. |
This WebGLRenderer instance.
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.
name | type | arguments | Default | description |
---|---|---|---|---|
blendModeId | number |
The blend mode to be set. Can be a |
||
force | boolean | <optional> | false |
Force the blend mode to be set, regardless of the currently set blend mode. |
true
if the blend mode was changed as a result of this call, forcing a flush, otherwise false
.
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.
name | type | arguments | 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 |
resetTextures | boolean | <optional> | false |
Should the WebGL Textures be reset after the new framebuffer is bound? |
setViewport | boolean | <optional> | true |
Should the WebGL viewport be set? |
This WebGLRenderer instance.
Binds a texture directly to texture unit one then activates it.
If the texture is already at unit one, it skips the bind.
Make sure to call clearNormalMap
after using this method.
name | type | description |
---|---|---|
texture | WebGLTexture |
The WebGL texture that needs to be bound. |
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
.
name | type | description |
---|---|---|
program | WebGLProgram |
The program that needs to be bound. |
true
if the given program was bound, otherwise false
.
Sets the Projection Matrix of this renderer to the given dimensions.
name | type | description |
---|---|---|
width | number |
The new width of the Projection Matrix. |
height | number |
The new height of the Projection Matrix. |
This WebGLRenderer instance.
Sets the current scissor state.
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. |
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.
name | type | description |
---|---|---|
texture | WebGLTexture |
The WebGL texture that needs to be bound. |
The texture unit that was assigned to the Texture Source.
Sets the minification and magnification filter for a texture.
name | type | description |
---|---|---|
texture | number |
The texture to set the filter for. |
filter | number |
The filter to set. 0 for linear filtering, 1 for nearest neighbor (blocky) filtering. |
This WebGL Renderer instance.
Activates the Texture Source and assigns it the next available texture unit. If none are available, it will flush the current pipeline first.
name | type | description |
---|---|---|
textureSource | Phaser.Textures.TextureSource |
The Texture Source to be assigned the texture unit. |
The texture unit that was assigned to the Texture Source.
Binds a texture directly to texture unit zero then activates it.
If the texture is already at unit zero, it skips the bind.
Make sure to call clearTextureZero
after using this method.
name | type | arguments | Default | description |
---|---|---|---|---|
texture | WebGLTexture |
The WebGL texture that needs to be bound. |
||
flush | boolean | <optional> | false |
Flush the pipeline if the texture is different? |
Removes all listeners.
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.
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 |
encoderOptions | number | <optional> | 0.92 |
The image quality, between 0 and 1. Used for image formats with lossy compression, such as |
This WebGL Renderer.
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.
name | type | arguments | Default | description |
---|---|---|---|---|
x | number |
The x coordinate to grab from. |
||
y | number |
The y coordinate to grab from. |
||
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 |
encoderOptions | number | <optional> | 0.92 |
The image quality, between 0 and 1. Used for image formats with lossy compression, such as |
This WebGL Renderer.
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.
name | type | arguments | Default | description |
---|---|---|---|---|
framebuffer | WebGLFramebuffer |
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. |
y | number | <optional> | 0 |
The y coordinate to grab from. |
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 |
encoderOptions | number | <optional> | 0.92 |
The image quality, between 0 and 1. Used for image formats with lossy compression, such as |
This WebGL Renderer.
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.
name | type | description |
---|---|---|
x | number |
The x coordinate of the pixel to get. |
y | number |
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. |
This WebGL Renderer.
Activates each texture, in turn, then binds them all to null
.
name | type | arguments | Default | description |
---|---|---|---|---|
all | boolean | <optional> | false |
Reset all textures, or just the first two? |
Updates the function bound to a given custom blend mode.
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. |
This WebGLRenderer instance.
Updates a WebGL Texture based on the given Canvas Element.
name | type | arguments | 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 |
The updated WebGL Texture.
Updates a WebGL Texture based on the given HTML Video Element.
name | type | arguments | 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 |
The updated WebGL Texture.