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#L102
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#L88
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#L133
Since: 4.0.0
height
height: number
Description:
The height of the framebuffer.
Source: src/renderer/webgl/DrawingContext.js#L185
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#L165
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#L154
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.
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#L143
Since: 4.0.0
useCanvas
useCanvas: boolean
Description:
Whether to use the canvas as the framebuffer.
Source: src/renderer/webgl/DrawingContext.js#L123
Since: 4.0.0
width
width: number
Description:
The width of the framebuffer.
Source: src/renderer/webgl/DrawingContext.js#L176
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#L551
Since: 4.0.0
clear
<instance> clear()
Description:
Clear the framebuffer. This will bind the framebuffer.
Source: src/renderer/webgl/DrawingContext.js#L570
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#L274
Since: 4.0.0
destroy
<instance> destroy()
Description:
Destroys the DrawingContext and its resources.
Source: src/renderer/webgl/DrawingContext.js#L590
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#L316
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#L539
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#L496
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#L474
Since: 4.0.0
resize
<instance> resize(width, height)
Description:
Resize the DrawingContext.
Delete the framebuffer and texture, and create new ones with the new size. 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#L220
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#L341
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#L360
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#L391
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#L403
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#L427
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#L445
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#L516
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#L457
Since: 4.0.0