DrawingContext
DrawingContext
Constructor
new DrawingContext(renderer, [options])
Parameters
| name | type | optional | description |
|---|---|---|---|
| renderer | Phaser.Renderer.WebGL.WebGLRenderer | No | The renderer that owns this context. |
| options | Phaser.Types.Renderer.WebGL.RenderNodes.DrawingContextOptions | Yes | The options for this context. |
Scope: static
Source: src/renderer/webgl/DrawingContext.js#L35
Since: 4.0.0
Public Members
autoClear
autoClear: number
Description:
Which renderbuffers in the framebuffer to clear when the DrawingContext comes into use. This is the mask of buffers to clear: gl.COLOR_BUFFER_BIT, gl.DEPTH_BUFFER_BIT, gl.STENCIL_BUFFER_BIT.
Source: src/renderer/webgl/DrawingContext.js#L103
Since: 4.0.0
blendMode
blendMode: number
Description:
The blend mode to use when rendering. This is an index into the renderer's blendModes array. It is faster to check than the state object.
Source: src/renderer/webgl/DrawingContext.js#L89
Since: 4.0.0
camera
camera: Phaser.Cameras.Scene2D.Camera
Description:
The camera used by this context. Set this using setCamera to ensure the view matrix is updated. Ensure that this is not null before rendering.
Source: src/renderer/webgl/DrawingContext.js#L51
Since: 4.0.0
framebuffer
framebuffer: Phaser.Renderer.WebGL.Wrappers.WebGLFramebufferWrapper
Description:
The WebGLFramebufferWrapper which will hold the framebuffer output. This may contain the canvas.
Source: src/renderer/webgl/DrawingContext.js#L134
Since: 4.0.0
height
height: number
Description:
The height of the framebuffer.
Source: src/renderer/webgl/DrawingContext.js#L186
Since: 4.0.0
lastUsed
lastUsed: number
Description:
The last time the DrawingContext was used. This is used to determine whether the context is a candidate for reuse in a pool.
Source: src/renderer/webgl/DrawingContext.js#L166
Since: 4.0.0
pool
pool: Phaser.Renderer.WebGL.DrawingContextPool
Description:
The pool to return to when this context is no longer needed. Used only for temporary contexts.
Source: src/renderer/webgl/DrawingContext.js#L155
Since: 4.0.0
renderer
renderer: Phaser.Renderer.WebGL.WebGLRenderer
Description:
The renderer that owns this context.
Source: src/renderer/webgl/DrawingContext.js#L42
Since: 4.0.0
state
state: Phaser.Types.Renderer.WebGL.WebGLGlobalParameters
Description:
Relevant WebGL state for the DrawingContext. Contains the framebuffer, scissor box, and viewport.
Source: src/renderer/webgl/DrawingContext.js#L65
Since: 4.0.0
texture
texture: Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper
Description:
The WebGLTextureWrapper which will hold the framebuffer output. This is only used if useCanvas is false.
Source: src/renderer/webgl/DrawingContext.js#L144
Since: 4.0.0
useCanvas
useCanvas: boolean
Description:
Whether to use the canvas as the framebuffer.
Source: src/renderer/webgl/DrawingContext.js#L124
Since: 4.0.0
width
width: number
Description:
The width of the framebuffer.
Source: src/renderer/webgl/DrawingContext.js#L177
Since: 4.0.0
Public Methods
beginDraw
<instance> beginDraw()
Description:
Begin drawing with the DrawingContext.
This should be called before rendering to set up the framebuffer and other WebGL state.
Source: src/renderer/webgl/DrawingContext.js#L552
Since: 4.0.0
clear
<instance> clear([bits])
Description:
Clear the framebuffer. This will bind the framebuffer.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| bits | number | Yes | A bitmask of WebGL buffer bits to clear (e.g. gl.COLOR_BUFFER_BIT, gl.DEPTH_BUFFER_BIT, gl.STENCIL_BUFFER_BIT). Defaults to the autoClear value of this context. |
Source: src/renderer/webgl/DrawingContext.js#L571
Since: 4.0.0
copy
<instance> copy(source)
Description:
Copy the state of another DrawingContext.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| source | Phaser.Renderer.WebGL.DrawingContext | No | The DrawingContext to copy from. |
Source: src/renderer/webgl/DrawingContext.js#L275
Since: 4.0.0
destroy
<instance> destroy()
Description:
Destroys the DrawingContext and its resources.
Source: src/renderer/webgl/DrawingContext.js#L592
Since: 4.0.0
getClone
<instance> getClone([preserveAutoClear])
Description:
Create a clone of the DrawingContext. This is intended to be mutated for temporary use, and then thrown away.
The autoClear setting is set to false unless specified. This is because most clones reference an existing framebuffer, which is intended to accumulate drawing operations.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| preserveAutoClear | boolean | Yes | false | Whether to preserve the autoClear setting. |
Returns: Phaser.Renderer.WebGL.DrawingContext - The cloned DrawingContext.
Source: src/renderer/webgl/DrawingContext.js#L317
Since: 4.0.0
isLocked
<instance> isLocked()
Description:
Check whether the DrawingContext is locked.
Returns: boolean - Whether the DrawingContext is locked.
Source: src/renderer/webgl/DrawingContext.js#L540
Since: 4.0.0
lock
<instance> lock(key)
Description:
Lock the DrawingContext to be in use. This prevents release from returning it to its pool until unlock is called with the appropriate key. This is used for temporary DrawingContexts, which may be returned to a pool.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| key | any | No | The key to lock the DrawingContext with. |
Source: src/renderer/webgl/DrawingContext.js#L497
Since: 4.0.0
release
<instance> release()
Description:
End using the DrawingContext. This marks the context as not in use, so its framebuffer and texture are not needed any more and may be cleared at any time. This will finish any outstanding batches.
If there are no locks on the DrawingContext, and it comes from a pool, it will be returned to its pool.
Source: src/renderer/webgl/DrawingContext.js#L475
Since: 4.0.0
resize
<instance> resize(width, height)
Description:
Resize the DrawingContext.
If no framebuffer exists yet, a new texture and framebuffer are created at the given dimensions. If a framebuffer already exists, it is resized in place. The scissor box and viewport are reset to match the new size.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| width | number | No | The new width of the framebuffer. |
| height | number | No | The new height of the framebuffer. |
Source: src/renderer/webgl/DrawingContext.js#L221
Since: 4.0.0
setAutoClear
<instance> setAutoClear(color, depth, stencil)
Description:
Set the buffers to clear when the DrawingContext comes into use.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| color | boolean | No | Whether to clear the color buffer. |
| depth | boolean | No | Whether to clear the depth buffer. |
| stencil | boolean | No | Whether to clear the stencil buffer. |
Source: src/renderer/webgl/DrawingContext.js#L342
Since: 4.0.0
setBlendMode
<instance> setBlendMode(blendMode, [blendColor])
Description:
Set the blend mode for the DrawingContext.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| blendMode | number | No | The blend mode to set. |
| blendColor | Array.<number> | Yes | The blend color to set. This is an array of 4 values: red, green, blue, alpha. |
Source: src/renderer/webgl/DrawingContext.js#L361
Since: 4.0.0
setCamera
<instance> setCamera(camera)
Description:
Set the camera for the DrawingContext.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| camera | Phaser.Cameras.Scene2D.Camera | No | The camera to set. |
Source: src/renderer/webgl/DrawingContext.js#L392
Since: 4.0.0
setClearColor
<instance> setClearColor(r, g, b, a)
Description:
Set the clear color for the DrawingContext. No changes will be made if the color is the same as the current clear color.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| r | number | No | The red component of the color to clear with. |
| g | number | No | The green component of the color to clear with. |
| b | number | No | The blue component of the color to clear with. |
| a | number | No | The alpha component of the color to clear with. |
Source: src/renderer/webgl/DrawingContext.js#L404
Since: 4.0.0
setScissorBox
<instance> setScissorBox(x, y, width, height)
Description:
Set the scissor box for the DrawingContext.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| x | number | No | The x coordinate of the scissor box. |
| y | number | No | The y coordinate of the scissor box. |
| width | number | No | The width of the scissor box. |
| height | number | No | The height of the scissor box. |
Source: src/renderer/webgl/DrawingContext.js#L428
Since: 4.0.0
setScissorEnable
<instance> setScissorEnable(enable)
Description:
Enable or disable the scissor box for the DrawingContext.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| enable | boolean | No | Whether to enable the scissor box. |
Source: src/renderer/webgl/DrawingContext.js#L446
Since: 4.0.0
unlock
<instance> unlock(key, [release])
Description:
Unlock the DrawingContext. This allows release to return it to its pool.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| key | any | No | The key to unlock the DrawingContext with. This must be the same key used to lock it. |
| release | boolean | Yes | Whether to release the DrawingContext immediately. This will only happen if there are no other locks on it. |
Source: src/renderer/webgl/DrawingContext.js#L517
Since: 4.0.0
use
<instance> use()
Description:
Begin using the DrawingContext. This will finish any outstanding batches and run any autoClear.
Source: src/renderer/webgl/DrawingContext.js#L458
Since: 4.0.0