Skip to main content
Version: Phaser v4.0.0-rc.6

DrawingContext

DrawingContext

Constructor

new DrawingContext(renderer, [options])

Parameters

nametypeoptionaldescription
rendererPhaser.Renderer.WebGL.WebGLRendererNoThe renderer that owns this context.
optionsPhaser.Types.Renderer.WebGL.RenderNodes.DrawingContextOptionsYesThe 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.

Source: src/renderer/webgl/DrawingContext.js#L65


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:

nametypeoptionaldescription
sourcePhaser.Renderer.WebGL.DrawingContextNoThe 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:

nametypeoptionaldefaultdescription
preserveAutoClearbooleanYesfalseWhether 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:

nametypeoptionaldescription
keyanyNoThe 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:

nametypeoptionaldescription
widthnumberNoThe new width of the framebuffer.
heightnumberNoThe 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:

nametypeoptionaldescription
colorbooleanNoWhether to clear the color buffer.
depthbooleanNoWhether to clear the depth buffer.
stencilbooleanNoWhether 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:

nametypeoptionaldescription
blendModenumberNoThe blend mode to set.
blendColorArray.<number>YesThe 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:

nametypeoptionaldescription
cameraPhaser.Cameras.Scene2D.CameraNoThe 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:

nametypeoptionaldescription
rnumberNoThe red component of the color to clear with.
gnumberNoThe green component of the color to clear with.
bnumberNoThe blue component of the color to clear with.
anumberNoThe 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:

nametypeoptionaldescription
xnumberNoThe x coordinate of the scissor box.
ynumberNoThe y coordinate of the scissor box.
widthnumberNoThe width of the scissor box.
heightnumberNoThe 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:

nametypeoptionaldescription
enablebooleanNoWhether 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:

nametypeoptionaldescription
keyanyNoThe key to unlock the DrawingContext with. This must be the same key used to lock it.
releasebooleanYesWhether 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