Class: RenderTarget

Phaser.Renderer.WebGL. RenderTarget

A Render Target encapsulates a WebGL framebuffer and the WebGL Texture that displays it.

Instances of this class are typically created by, and belong to WebGL Pipelines, however other Game Objects and classes can take advantage of Render Targets as well.


new RenderTarget(renderer, width, height [, scale] [, minFilter] [, autoClear] [, autoResize])

Parameters:
Name Type Argument Default Description
renderer Phaser.Renderer.WebGL.WebGLRenderer

A reference to the WebGLRenderer.

width number

The width of this Render Target.

height number

The height of this Render Target.

scale number <optional>
1

A value between 0 and 1. Controls the size of this Render Target in relation to the Renderer.

minFilter number <optional>
0

The minFilter mode of the texture when created. 0 is LINEAR, 1 is NEAREST.

autoClear boolean <optional>
true

Automatically clear this framebuffer when bound?

autoResize boolean <optional>
false

Automatically resize this Render Target if the WebGL Renderer resizes?

Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 10)

Members


autoClear :boolean

Controls if this Render Target is automatically cleared (via gl.COLOR_BUFFER_BIT) during the RenderTarget.bind method.

If you need more control over how, or if, the target is cleared, you can disable this via the config on creation, or even toggle it directly at runtime.

Type:
  • boolean
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 112)

<readonly> autoResize :boolean

Does this Render Target automatically resize when the WebGL Renderer does?

Modify this property via the setAutoResize method.

Type:
  • boolean
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 125)

destroy

Removes all external references from this class and deletes the WebGL framebuffer and texture instances.

Does not remove this Render Target from the parent pipeline.

Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 326)

framebuffer :WebGLFramebuffer

The WebGLFramebuffer of this Render Target.

This is created in the RenderTarget.resize method.

Type:
  • WebGLFramebuffer
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 50)

<readonly> height :number

The height of the texture.

Type:
  • number
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 82)

minFilter :number

The minFilter mode of the texture. 0 is LINEAR, 1 is NEAREST.

Type:
  • number
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 103)

renderer :Phaser.Renderer.WebGL.WebGLRenderer

A reference to the WebGLRenderer instance.

Type:
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 41)

scale :number

A value between 0 and 1. Controls the size of this Render Target in relation to the Renderer.

A value of 1 matches it. 0.5 makes the Render Target half the size of the renderer, etc.

Type:
  • number
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 92)

texture :WebGLTexture

The WebGLTexture of this Render Target.

This is created in the RenderTarget.resize method.

Type:
  • WebGLTexture
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 61)

unbind

Unbinds this Render Target and optionally flushes the WebGL Renderer first.

Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 302)

<readonly> width :number

The width of the texture.

Type:
  • number
Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 72)

Methods


adjustViewport()

Adjusts the GL viewport to match the width and height of this Render Target.

Also disables SCISSOR_TEST.

Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 261)

bind( [adjustViewport] [, width] [, height])

Pushes this Render Target as the current frame buffer of the renderer.

If autoClear is set, then clears the texture.

If adjustViewport is true then it will flush the renderer and then adjust the GL viewport.

Parameters:
Name Type Argument Default Description
adjustViewport boolean <optional>
false

Adjust the GL viewport by calling RenderTarget.adjustViewport ?

width number <optional>

Optional new width of this Render Target.

height number <optional>

Optional new height of this Render Target.

Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 216)

clear()

Clears this Render Target.

Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 278)

resize(width, height)

Resizes this Render Target.

Deletes both the frame buffer and texture, if they exist and then re-creates them using the new sizes.

This method is called automatically by the pipeline during its resize handler.

Parameters:
Name Type Description
width number

The new width of this Render Target.

height number

The new height of this Render Target.

Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 174)
Returns:

This RenderTarget instance.

Type
Phaser.Renderer.WebGL.RenderTarget

setAutoResize(autoResize)

Sets if this Render Target should automatically resize when the WebGL Renderer emits a resize event.

Parameters:
Name Type Description
autoResize boolean

Automatically resize this Render Target when the WebGL Renderer resizes?

Since: 3.50.0
Source: src/renderer/webgl/RenderTarget.js (Line 145)
Returns:

This RenderTarget instance.

Type
Phaser.Renderer.WebGL.RenderTarget