Skip to main content
Version: Phaser v4.2.0

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#L40
Since: 4.0.0

Public Members​

alphaStrategy​

alphaStrategy: Phaser.Types.Renderer.WebGL.AlphaStrategy​

Description:

The alpha strategy to use when rendering. Shaders can opt in to alpha strategies via this value. Typically, this is used to switch from floating-point alpha to a fragment discard strategy for use in stencil rendering.

Source: src/renderer/webgl/DrawingContext.js#L110
Since: 4.2.0


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#L123
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#L96
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#L56
Since: 4.0.0


enableMipmap​

enableMipmap: boolean​

Description:

Whether to enable mipmaps on the framebuffer texture, if it exists. The game must still be set to use mipmaps for this to work.

Source: src/renderer/webgl/DrawingContext.js#L175
Since: 4.1.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#L154
Since: 4.0.0


height​

height: number​

Description:

The height of the framebuffer.

Source: src/renderer/webgl/DrawingContext.js#L217
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#L197
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#L186
Since: 4.0.0


renderer​

renderer: Phaser.Renderer.WebGL.WebGLRenderer​

Description:

The renderer that owns this context.

Source: src/renderer/webgl/DrawingContext.js#L47
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#L70
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#L164
Since: 4.0.0


useCanvas​

useCanvas: boolean​

Description:

Whether to use the canvas as the framebuffer.

Source: src/renderer/webgl/DrawingContext.js#L144
Since: 4.0.0


width​

width: number​

Description:

The width of the framebuffer.

Source: src/renderer/webgl/DrawingContext.js#L208
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#L699
Since: 4.0.0


clear​

<instance> clear([bits])​

Description:

Clear the framebuffer. This will bind the framebuffer.

Parameters:

nametypeoptionaldescription
bitsnumberYesA 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#L718
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#L333
Since: 4.0.0


destroy​

<instance> destroy()​

Description:

Destroys the DrawingContext and its resources.

Source: src/renderer/webgl/DrawingContext.js#L739
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#L393
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#L687
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#L644
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#L622
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:

nametypeoptionaldescription
widthnumberNoThe new width of the framebuffer.
heightnumberNoThe new height of the framebuffer.

Source: src/renderer/webgl/DrawingContext.js#L252
Since: 4.0.0


setAlphaStrategy​

<instance> setAlphaStrategy(alphaStrategy)​

Description:

Set the alpha strategy for the DrawingContext.

Parameters:

nametypeoptionaldescription
alphaStrategyPhaser.Types.Renderer.WebGL.AlphaStrategyNoThe alpha strategy to use when rendering.

Source: src/renderer/webgl/DrawingContext.js#L418
Since: 4.2.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#L430
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#L449
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#L480
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#L492
Since: 4.0.0


setColorWritemask​

<instance> setColorWritemask(r, g, b, a)​

Description:

Set the color writemask for the DrawingContext.

Parameters:

nametypeoptionaldescription
rbooleanNoWhether to write the red channel.
gbooleanNoWhether to write the green channel.
bbooleanNoWhether to write the blue channel.
abooleanNoWhether to write the alpha channel.

Source: src/renderer/webgl/DrawingContext.js#L516
Since: 4.2.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#L531
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#L549
Since: 4.0.0


setStencil​

<instance> setStencil([enabled], [func], [funcRef], [funcMask], [opFail], [opZfail], [opZpass], [clear], [writeMask])​

Description:

Set the stencil parameters for the DrawingContext.

Parameters:

nametypeoptionaldefaultdescription
enabledGLbooleanYestrueWhether the stencil test is enabled.
funcGLenumYes"GL_EQUAL"The stencil comparison function used to compare the reference value against the current stencil buffer value.
funcRefGLintYes0The reference value against which the stencil buffer value is compared during the stencil test.
funcMaskGLuintYes"0xFF"The bitwise mask applied to both the reference value and the stencil buffer value before they are compared.
opFailGLenumYes"GL_KEEP"The operation to perform if the stencil test fails.
opZfailGLenumYes"GL_KEEP"The operation to perform if the stencil test passes but the depth test fails.
opZpassGLenumYes"GL_KEEP"The operation to perform if the stencil test passes and the depth test passes or is disabled.
clearGLintYes0The value to clear the stencil buffer to.
writeMaskGLuintYes"0x00"The mask applied to the stencil buffer value when it is written. Set to 0 to prevent writing. Set to 0xFF to allow full writing.

Source: src/renderer/webgl/DrawingContext.js#L561
Since: 4.2.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#L664
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#L605
Since: 4.0.0