Skip to main content

Class: BatchRenderer

renderer/batchRenderer.BatchRenderer

Batch renders instances of shapes and entities.

A texture atlas must be used with the batch renderer.

Hierarchy

Constructors

constructor

โ€ข new BatchRenderer()

Inherited from

Renderer.constructor

Properties

atlas

โ–ช Static atlas: TextureAtlas

Defined in

src/renderer/batchRenderer.ts:47


batchQueue

โ–ช Static batchQueue: ZMap<Object> = {}

Defined in

src/renderer/batchRenderer.ts:49


circleProgram

โ–ช Static circleProgram: WebGLProgram

Inherited from

Renderer.circleProgram

Defined in

src/renderer/renderer.ts:58


circleProgramInfo

โ–ช Static circleProgramInfo: ShaderProgramInfo

Inherited from

Renderer.circleProgramInfo

Defined in

src/renderer/renderer.ts:59


indexBuffer

โ–ช Static indexBuffer: WebGLBuffer

Inherited from

Renderer.indexBuffer

Defined in

src/renderer/renderer.ts:51


metaballProgram

โ–ช Static metaballProgram: WebGLProgram

Inherited from

Renderer.metaballProgram

Defined in

src/renderer/renderer.ts:64


metaballProgramInfo

โ–ช Static metaballProgramInfo: ShaderProgramInfo

Inherited from

Renderer.metaballProgramInfo

Defined in

src/renderer/renderer.ts:65


opacityBuffer

โ–ช Static opacityBuffer: WebGLBuffer

Inherited from

Renderer.opacityBuffer

Defined in

src/renderer/renderer.ts:52


positionBuffer

โ–ช Static positionBuffer: WebGLBuffer

Inherited from

Renderer.positionBuffer

Defined in

src/renderer/renderer.ts:48


queue

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

Inherited from

Renderer.queue

Defined in

src/renderer/renderer.ts:45


rectProgram

โ–ช Static rectProgram: WebGLProgram

Inherited from

Renderer.rectProgram

Defined in

src/renderer/renderer.ts:55


rectProgramInfo

โ–ช Static rectProgramInfo: ShaderProgramInfo

Inherited from

Renderer.rectProgramInfo

Defined in

src/renderer/renderer.ts:56


scale

โ–ช Static Protected scale: vec2

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

Inherited from

Renderer.scale

Defined in

src/renderer/renderer.ts:43


texBuffer

โ–ช Static texBuffer: WebGLBuffer

Inherited from

Renderer.texBuffer

Defined in

src/renderer/renderer.ts:49


triangleProgram

โ–ช Static triangleProgram: WebGLProgram

Inherited from

Renderer.triangleProgram

Defined in

src/renderer/renderer.ts:61


triangleProgramInfo

โ–ช Static triangleProgramInfo: ShaderProgramInfo

Inherited from

Renderer.triangleProgramInfo

Defined in

src/renderer/renderer.ts:62


uvBuffer

โ–ช Static uvBuffer: WebGLBuffer

Inherited from

Renderer.uvBuffer

Defined in

src/renderer/renderer.ts:50

Methods

addRenderablesToQueue

โ–ธ Static Private addRenderablesToQueue(renderables, zIndex, type): void

Parameters

NameType
renderablesRenderable<Shape>[]
zIndexnumber
typestring

Returns

void

Defined in

src/renderer/batchRenderer.ts:159


clear

โ–ธ Static clear(clearColor): void

Parameters

NameType
clearColorColor

Returns

void

Inherited from

Renderer.clear

Defined in

src/renderer/renderer.ts:203


flush

โ–ธ Static flush(z): void

Renders all items currently in the batch 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

Overrides

Renderer.flush

Defined in

src/renderer/batchRenderer.ts:58


getBatchQueue

โ–ธ Static getBatchQueue(): ZMap<Object>

Gets the batch render queue.

Returns

ZMap<Object>

the batch render queue

Defined in

src/renderer/batchRenderer.ts:424


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

Inherited from

Renderer.getCamera

Defined in

src/renderer/renderer.ts:395


getGL

โ–ธ Static getGL(): WebGL2RenderingContext

Gets the renderer's webgl context.

Returns

WebGL2RenderingContext

The renderer's webgl context

Inherited from

Renderer.getGL

Defined in

src/renderer/renderer.ts:330


getGeometryFromRenderables

โ–ธ Static Private getGeometryFromRenderables(renderable): Geometry

Generates geometry data for an array of {@link Renderable} shapes.

Parameters

NameType
renderableRenderable<Shape>[]

Returns

Geometry

Defined in

src/renderer/batchRenderer.ts:291


getMode

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

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

Returns

"TRIANGLES" | "LINES" | "POINTS"

The rendering mode

Inherited from

Renderer.getMode

Defined in

src/renderer/renderer.ts:377


getQueue

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

Gets the render queue.

Returns

ZMap<RenderQueueItem[]>

the render queue

Inherited from

Renderer.getQueue

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

Overrides

Renderer.getQueueMax

Defined in

src/renderer/batchRenderer.ts:433


getQueueMin

โ–ธ Static getQueueMin(): number

Gets the minimum zIndex used by the queue.

Returns

number

The min zIndex of the queue

Overrides

Renderer.getQueueMin

Defined in

src/renderer/batchRenderer.ts:442


getRenderableCirclesFromCircles

โ–ธ Static Private getRenderableCirclesFromCircles(circles): Renderable<Circle>[]

Parameters

NameType
circlesCircle[]

Returns

Renderable<Circle>[]

Defined in

src/renderer/batchRenderer.ts:353


getRenderableRectsFromRects

โ–ธ Static Private getRenderableRectsFromRects(rects): Renderable<Rect>[]

Parameters

NameType
rectsRect[]

Returns

Renderable<Rect>[]

Defined in

src/renderer/batchRenderer.ts:339


getRenderableShapesFromEntites

โ–ธ Static Private getRenderableShapesFromEntites(entities): Object

Parameters

NameType
entitiesEntity[]

Returns

Object

NameType
circlesRenderable<Circle>[]
rectsRenderable<Rect>[]
trianglesRenderable<Triangle>[]

Defined in

src/renderer/batchRenderer.ts:381


getRenderableTrianglesfromTriangles

โ–ธ Static Private getRenderableTrianglesfromTriangles(triangles): Renderable<Triangle>[]

Parameters

NameType
trianglesTriangle[]

Returns

Renderable<Triangle>[]

Defined in

src/renderer/batchRenderer.ts:367


getResolutionScale

โ–ธ Static getResolutionScale(): number

Gets the renderer's current resolution scale.

Returns

number

The renderer's current resolution scale

Inherited from

Renderer.getResolutionScale

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

Inherited from

Renderer.getScale

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

Inherited from

Renderer.init

Defined in

src/renderer/renderer.ts:77


queueCircles

โ–ธ Static queueCircles(circles, zIndex?): void

Queue a group of circle to be batch rendered.

Parameters

NameTypeDefault valueDescription
circles(Circle | Renderable<Circle>)[]undefinedThe circles to queue
zIndexnumber0The z index of the circles

Returns

void

Defined in

src/renderer/batchRenderer.ts:135


queueEntities

โ–ธ Static queueEntities(entities, zIndex?): void

Batch render an array of entities.

Parameters

NameTypeDefault valueDescription
entitiesEntity[]undefinedThe entities to render
zIndexnumber0The z position of the rendered rectangle

Returns

void

Defined in

src/renderer/batchRenderer.ts:108


queueEntity

โ–ธ Static queueEntity(entity, zIndex?): void

Queue an entity to be batch rendered.

Parameters

NameTypeDefault valueDescription
entityEntityundefinedThe entity to render
zIndexnumber0The z index of the entity

Returns

void

Defined in

src/renderer/batchRenderer.ts:94


queueRects

โ–ธ Static queueRects(rects, zIndex?): void

Queue a group of rectangles to be batch rendered.

Parameters

NameTypeDefault valueDescription
rects(Rect | Renderable<Rect>)[]undefinedThe rects to queue
zIndexnumber0The z index of the rectangles

Returns

void

Defined in

src/renderer/batchRenderer.ts:122


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

Inherited from

Renderer.queueShape

Defined in

src/renderer/renderer.ts:238


queueTriangles

โ–ธ Static queueTriangles(triangles, zIndex?): void

Queue a group of triangle to be batch rendered.

Parameters

NameTypeDefault valueDescription
triangles(Triangle | Renderable<Triangle>)[]undefinedThe triangles to queue
zIndexnumber0The z index of the triangles

Returns

void

Defined in

src/renderer/batchRenderer.ts:150


renderCircles

โ–ธ Static Private renderCircles(circles, zIndex?): void

Batch render an array of circles.

Parameters

NameTypeDefault valueDescription
circles(Circle | Renderable<Circle>)[]undefinedThe circles to render
zIndexnumber0The z index of the rendered circles

Returns

void

Defined in

src/renderer/batchRenderer.ts:190


renderGeometry

โ–ธ Static Private renderGeometry(geometry, type, zIndex?): void

Renders geometry using a shape shader.

Parameters

NameTypeDefault valueDescription
geometryGeometryundefinedThe geometry to render
type"rect" | "circle" | "triangle"undefinedThe type of shape shader to use
zIndexnumber0The z position of the rendered rectangle

Returns

void

Defined in

src/renderer/batchRenderer.ts:225


renderRects

โ–ธ Static Private renderRects(rects, zIndex?): void

Batch render an array of rectangles.

Parameters

NameTypeDefault valueDescription
rects(Rect | Renderable<Rect>)[]undefinedThe rects to render
zIndexnumber0The z index of the rendered rectangles

Returns

void

Defined in

src/renderer/batchRenderer.ts:175


renderTriangles

โ–ธ Static Private renderTriangles(triangles, zIndex?): void

Batch render an array of triangles.

Parameters

NameTypeDefault valueDescription
triangles(Triangle | Renderable<Triangle>)[]undefinedThe triangles to render
zIndexnumber0The z index of the rendered triangles

Returns

void

Defined in

src/renderer/batchRenderer.ts:207


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

Inherited from

Renderer.resizeToCanvas

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

Inherited from

Renderer.setMode

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

Overrides

Renderer.setQueueMax

Defined in

src/renderer/batchRenderer.ts:451


setQueueMin

โ–ธ Static setQueueMin(min): void

Sets the minimum zIndex used by the queue.

Parameters

NameTypeDescription
minnumberThe min zIndex of the queue

Returns

void

Overrides

Renderer.setQueueMin

Defined in

src/renderer/batchRenderer.ts:460


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

Inherited from

Renderer.setResolutionScale

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

Inherited from

Renderer.setScale

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

Inherited from

Renderer.useCamera

Defined in

src/renderer/renderer.ts:386