Skip to main content

Class: RenderContext

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

The rendering context.

Implements​

Constructors​

Constructor​

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

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

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:28

The canvas element associated with the render context.


clearStrategy​

clearStrategy: CLEAR_STRATEGY_KEYS

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

The strategy for clearing the render context.


gl​

readonly gl: WebGL2RenderingContext

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

The WebGL2 rendering context.


height​

height: number

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

The current height, in pixels.

Implementation of​

Resizable.height


imageCache​

readonly imageCache: ImageCache

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

The image cache containing loaded images.


instanceBuffer​

instanceBuffer: WebGLBuffer

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


shaderCache​

readonly shaderCache: ShaderCache

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

The shader store containing compiled shaders.


width​

width: number

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

The current width, in pixels.

Implementation of​

Resizable.width

Methods​

bindRenderTarget()​

bindRenderTarget(target): void

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

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:115

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:128

Parameters​

name​

string

Returns​

UniformValue


resize()​

resize(width, height): void

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

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

Implementation of​

Resizable.resize


setGlobalUniformValue()​

setGlobalUniformValue(name, value): void

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

Parameters​

name​

string

value​

UniformValue

Returns​

void