Skip to main content

Class: Renderer

renderer/renderer.Renderer

Renders single instances of shapes at a time.

Hierarchy

Constructors

constructor

โ€ข new Renderer()

Properties

camera

โ–ช Static Private camera: Camera

Defined in

src/renderer/renderer.ts:38


circleProgram

โ–ช Static circleProgram: WebGLProgram

Defined in

src/renderer/renderer.ts:58


circleProgramInfo

โ–ช Static circleProgramInfo: ShaderProgramInfo

Defined in

src/renderer/renderer.ts:59


gl

โ–ช Static Private gl: WebGL2RenderingContext

Defined in

src/renderer/renderer.ts:35


indexBuffer

โ–ช Static indexBuffer: WebGLBuffer

Defined in

src/renderer/renderer.ts:51


metaballProgram

โ–ช Static metaballProgram: WebGLProgram

Defined in

src/renderer/renderer.ts:64


metaballProgramInfo

โ–ช Static metaballProgramInfo: ShaderProgramInfo

Defined in

src/renderer/renderer.ts:65


mode

โ–ช Static Private mode: "TRIANGLES" | "LINES" | "POINTS" = "TRIANGLES"

Defined in

src/renderer/renderer.ts:37


opacityBuffer

โ–ช Static opacityBuffer: WebGLBuffer

Defined in

src/renderer/renderer.ts:52


positionBuffer

โ–ช Static positionBuffer: WebGLBuffer

Defined in

src/renderer/renderer.ts:48


queue

โ–ช Static Protected queue: ZMap<RenderQueueItem[]> = {}

Defined in

src/renderer/renderer.ts:45


rectProgram

โ–ช Static rectProgram: WebGLProgram

Defined in

src/renderer/renderer.ts:55


rectProgramInfo

โ–ช Static rectProgramInfo: ShaderProgramInfo

Defined in

src/renderer/renderer.ts:56


resolutionScale

โ–ช Static Private resolutionScale: number = 1

Defined in

src/renderer/renderer.ts:36


scale

โ–ช Static Protected scale: vec2

The scale applied to shape vertices to obtain their clip space vertices.

Defined in

src/renderer/renderer.ts:43


texBuffer

โ–ช Static texBuffer: WebGLBuffer

Defined in

src/renderer/renderer.ts:49


triangleProgram

โ–ช Static triangleProgram: WebGLProgram

Defined in

src/renderer/renderer.ts:61


triangleProgramInfo

โ–ช Static triangleProgramInfo: ShaderProgramInfo

Defined in

src/renderer/renderer.ts:62


uvBuffer

โ–ช Static uvBuffer: WebGLBuffer

Defined in

src/renderer/renderer.ts:50

Methods

clear

โ–ธ Static clear(clearColor): void

Parameters

NameType
clearColorColor

Returns

void

Defined in

src/renderer/renderer.ts:203


flush

โ–ธ Static flush(z): void

Renders all items currently in the render queue and clears the queue.

Should be called at the end of each frame.

If there is no camera specified in Renderer then nothing will be rendered.

Parameters

NameType
znumber

Returns

void

Defined in

src/renderer/renderer.ts:214


getCamera

โ–ธ Static getCamera(): Camera

Gets the camera that is currently being used for rendering.

Returns

Camera

The camera that is currently being used for rendering

Defined in

src/renderer/renderer.ts:395


getGL

โ–ธ Static getGL(): WebGL2RenderingContext

Gets the renderer's webgl context.

Returns

WebGL2RenderingContext

The renderer's webgl context

Defined in

src/renderer/renderer.ts:330


getMode

โ–ธ Static getMode(): "TRIANGLES" | "LINES" | "POINTS"

Gets the current webgl rendering mode being used by the renderer.

Returns

"TRIANGLES" | "LINES" | "POINTS"

The rendering mode

Defined in

src/renderer/renderer.ts:377


getQueue

โ–ธ Static getQueue(): ZMap<RenderQueueItem[]>

Gets the render queue.

Returns

ZMap<RenderQueueItem[]>

the render queue

Defined in

src/renderer/renderer.ts:422


getQueueMax

โ–ธ Static getQueueMax(): number

Gets the maximum zIndex used by the queue.

Returns

number

The max zIndex of the queue

Defined in

src/renderer/renderer.ts:431


getQueueMin

โ–ธ Static getQueueMin(): number

Gets the minimum zIndex used by the queue.

Returns

number

The min zIndex of the queue

Defined in

src/renderer/renderer.ts:440


getResolutionScale

โ–ธ Static getResolutionScale(): number

Gets the renderer's current resolution scale.

Returns

number

The renderer's current resolution scale

Defined in

src/renderer/renderer.ts:353


getScale

โ–ธ Static getScale(): vec2

Gets the scale that is applied to vertices to obtain the vertices in clip space.

Returns

vec2

The scaling vector

Defined in

src/renderer/renderer.ts:413


init

โ–ธ Static init(canvas, opts?): void

Sets up the renderer to be used for rendering.

Creates the webgl2 rendering context for the canvas and clears the webgl buffer.

throws When browser does not support webgl 2.0

Parameters

NameTypeDescription
canvasHTMLCanvasElementThe canvas to grab webgl context from
opts?WebGLContextAttributes{@link WebGLContextAttributes} to pass to the getContext call

Returns

void

Defined in

src/renderer/renderer.ts:77


initShaders

โ–ธ Static Private initShaders(gl): void

Parameters

NameType
glWebGL2RenderingContext

Returns

void

Defined in

src/renderer/renderer.ts:114


queueShape

โ–ธ Static queueShape(shape, position?, rotation?, zIndex?): void

Adds a shape to the render queue.

Parameters

NameTypeDefault valueDescription
shapeShapeundefinedThe shape to queue
positionvec2undefinedThe x and y position to render the rectangle at
rotationnumber0The rotation to apply to the shape
zIndexnumber0The z position of the rendered rectangle

Returns

void

Defined in

src/renderer/renderer.ts:238


renderQueueItem

โ–ธ Static Private renderQueueItem(item, zIndex): void

Renders a shape from a {@link RenderQueueItem} object.

Parameters

NameTypeDescription
itemRenderQueueItemThe {@link RenderQueueItem} to render
zIndexnumberThe z index to render the shape at

Returns

void

Defined in

src/renderer/renderer.ts:258


resizeToCanvas

โ–ธ Static resizeToCanvas(): void

Resizes the width and height of the canvas attached to gl to the canvas' clientWidth and clientHeight multiplied by the resolutionScale or 1.

Returns

void

Defined in

src/renderer/renderer.ts:191


setMode

โ–ธ Static setMode(mode): void

Sets the mode the renderer will use for drawing.

throws When the provided mode is not TRIANGLES, LINES or POINTS

Parameters

NameTypeDescription
mode"TRIANGLES" | "LINES" | "POINTS"The mode to use

Returns

void

Defined in

src/renderer/renderer.ts:364


setQueueMax

โ–ธ Static setQueueMax(max): void

Sets the maximum zIndex used by the queue.

Parameters

NameTypeDescription
maxnumberThe max zIndex of the queue

Returns

void

Defined in

src/renderer/renderer.ts:449


setQueueMin

โ–ธ Static setQueueMin(min): void

Sets the minimum zIndex used by the queue.

Parameters

NameTypeDescription
minnumberThe min zIndex of the queue

Returns

void

Defined in

src/renderer/renderer.ts:458


setResolutionScale

โ–ธ Static setResolutionScale(resolutionScale): void

Sets the resolution scale to use when rendering.

The width and height of the renderer canvas are set to clientWidth * resolutionScale and clientHeight * resolutionScale respectively.

Parameters

NameTypeDescription
resolutionScalenumberThe new resolution scale to use

Returns

void

Defined in

src/renderer/renderer.ts:341


setScale

โ–ธ Static setScale(scale): void

Set the scale that is applied to vertices to obtain the vertices in clip space.

Parameters

NameTypeDescription
scalevec2The scaling vector

Returns

void

Defined in

src/renderer/renderer.ts:404


useCamera

โ–ธ Static useCamera(camera): void

Sets the camera to use for rendering.

Parameters

NameTypeDescription
cameraCameraThe camera to use for rendering

Returns

void

Defined in

src/renderer/renderer.ts:386