Skip to main content

Class: RenderContext

Defined in: rendering/render-context.ts:12

The rendering context.

Constructors

Constructor

new RenderContext(shaderCache, imageCache, canvas, clearStrategy?, preserveDrawingBuffer?): RenderContext

Defined in: rendering/render-context.ts:48

Constructs a new instance of the RenderContext class.

Parameters

shaderCache

ShaderCache

The shader cache.

imageCache

ImageCache

The image cache.

canvas

HTMLCanvasElement

The canvas element.

clearStrategy?

CLEAR_STRATEGY_KEYS = CLEAR_STRATEGY.blank

The strategy for clearing the render context (default: CLEAR_STRATEGY.blank).

preserveDrawingBuffer?

boolean = false

Whether to retain the drawing buffer after presentation instead of letting the browser clear it, required for reading back the canvas's pixels (e.g. toDataURL, drawImage) after a frame has already been presented (default: false, since most consumers never read the canvas back and the retained buffer costs GPU memory bandwidth).

Returns

RenderContext

Properties

canvas

readonly canvas: HTMLCanvasElement

Defined in: rendering/render-context.ts:27

The canvas element associated with the render context.


clearStrategy

clearStrategy: CLEAR_STRATEGY_KEYS

Defined in: rendering/render-context.ts:14

The strategy for clearing the render context.


gl

readonly gl: WebGL2RenderingContext

Defined in: rendering/render-context.ts:30

The WebGL2 rendering context.


height

height: number

Defined in: rendering/render-context.ts:36


imageCache

readonly imageCache: ImageCache

Defined in: rendering/render-context.ts:24

The image cache containing loaded images.


instanceBuffer

instanceBuffer: WebGLBuffer

Defined in: rendering/render-context.ts:32


shaderCache

readonly shaderCache: ShaderCache

Defined in: rendering/render-context.ts:19

The shader store containing compiled shaders.


width

width: number

Defined in: rendering/render-context.ts:34

Methods

bindRenderTarget()

bindRenderTarget(target): void

Defined in: rendering/render-context.ts:101

Binds a render target as the current draw destination, or the default framebuffer (the canvas) if null is passed. Updates the viewport to match the bound target's dimensions.

Parameters

target

RenderTarget | null

The render target to bind, or null to bind the canvas.

Returns

void


clear()

clear(color?): void

Defined in: rendering/render-context.ts:114

Clears the currently bound framebuffer's color buffer, according to clearStrategy.

Parameters

color?

Color = Color.transparent

Returns

void


getGlobalUniformValue()

getGlobalUniformValue(name): UniformValue

Defined in: rendering/render-context.ts:127

Parameters

name

string

Returns

UniformValue


resize()

resize(width, height): void

Defined in: rendering/render-context.ts:81

Resizes the render context canvas and updates the WebGL viewport.

Parameters

width

number

The new canvas width in pixels.

height

number

The new canvas height in pixels.

Returns

void


setGlobalUniformValue()

setGlobalUniformValue(name, value): void

Defined in: rendering/render-context.ts:123

Parameters

name

string

value

UniformValue

Returns

void