Class: BatchRenderer
renderer/batchRenderer.BatchRenderer
Batch renders instances of shapes and entities.
A texture atlas must be used with the batch renderer.
Hierarchy
โณ
BatchRenderer
Constructors
constructor
โข new BatchRenderer()
Inherited from
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
Defined in
src/renderer/renderer.ts:58
circleProgramInfo
โช Static
circleProgramInfo: ShaderProgramInfo
Inherited from
Defined in
src/renderer/renderer.ts:59
indexBuffer
โช Static
indexBuffer: WebGLBuffer
Inherited from
Defined in
src/renderer/renderer.ts:51
metaballProgram
โช Static
metaballProgram: WebGLProgram
Inherited from
Defined in
src/renderer/renderer.ts:64
metaballProgramInfo
โช Static
metaballProgramInfo: ShaderProgramInfo
Inherited from
Defined in
src/renderer/renderer.ts:65
opacityBuffer
โช Static
opacityBuffer: WebGLBuffer
Inherited from
Defined in
src/renderer/renderer.ts:52
positionBuffer
โช Static
positionBuffer: WebGLBuffer
Inherited from
Defined in
src/renderer/renderer.ts:48
queue
โช Static
Protected
queue: ZMap
<RenderQueueItem
[]> = {}
Inherited from
Defined in
src/renderer/renderer.ts:45
rectProgram
โช Static
rectProgram: WebGLProgram
Inherited from
Defined in
src/renderer/renderer.ts:55
rectProgramInfo
โช Static
rectProgramInfo: ShaderProgramInfo
Inherited from
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
Defined in
src/renderer/renderer.ts:43
texBuffer
โช Static
texBuffer: WebGLBuffer
Inherited from
Defined in
src/renderer/renderer.ts:49
triangleProgram
โช Static
triangleProgram: WebGLProgram
Inherited from
Defined in
src/renderer/renderer.ts:61
triangleProgramInfo
โช Static
triangleProgramInfo: ShaderProgramInfo
Inherited from
Defined in
src/renderer/renderer.ts:62
uvBuffer
โช Static
uvBuffer: WebGLBuffer
Inherited from
Defined in
src/renderer/renderer.ts:50
Methods
addRenderablesToQueue
โธ Static
Private
addRenderablesToQueue(renderables
, zIndex
, type
): void
Parameters
Name | Type |
---|---|
renderables | Renderable <Shape >[] |
zIndex | number |
type | string |
Returns
void
Defined in
src/renderer/batchRenderer.ts:159
clear
โธ Static
clear(clearColor
): void
Parameters
Name | Type |
---|---|
clearColor | Color |
Returns
void
Inherited from
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
Name | Type |
---|---|
z | number |
Returns
void
Overrides
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
The camera that is currently being used for rendering
Inherited from
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
Defined in
src/renderer/renderer.ts:330
getGeometryFromRenderables
โธ Static
Private
getGeometryFromRenderables(renderable
): Geometry
Generates geometry data for an array of {@link Renderable} shapes.
Parameters
Name | Type |
---|---|
renderable | Renderable <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
Defined in
src/renderer/renderer.ts:377
getQueue
โธ Static
getQueue(): ZMap
<RenderQueueItem
[]>
Gets the render queue.
Returns
ZMap
<RenderQueueItem
[]>
the render queue
Inherited from
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
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
Defined in
src/renderer/batchRenderer.ts:442
getRenderableCirclesFromCircles
โธ Static
Private
getRenderableCirclesFromCircles(circles
): Renderable
<Circle
>[]
Parameters
Name | Type |
---|---|
circles | Circle [] |
Returns
Renderable
<Circle
>[]
Defined in
src/renderer/batchRenderer.ts:353
getRenderableRectsFromRects
โธ Static
Private
getRenderableRectsFromRects(rects
): Renderable
<Rect
>[]
Parameters
Name | Type |
---|---|
rects | Rect [] |
Returns
Renderable
<Rect
>[]
Defined in
src/renderer/batchRenderer.ts:339
getRenderableShapesFromEntites
โธ Static
Private
getRenderableShapesFromEntites(entities
): Object
Parameters
Name | Type |
---|---|
entities | Entity [] |
Returns
Object
Name | Type |
---|---|
circles | Renderable <Circle >[] |
rects | Renderable <Rect >[] |
triangles | Renderable <Triangle >[] |
Defined in
src/renderer/batchRenderer.ts:381
getRenderableTrianglesfromTriangles
โธ Static
Private
getRenderableTrianglesfromTriangles(triangles
): Renderable
<Triangle
>[]
Parameters
Name | Type |
---|---|
triangles | Triangle [] |
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
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
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
Name | Type | Description |
---|---|---|
canvas | HTMLCanvasElement | The canvas to grab webgl context from |
opts? | WebGLContextAttributes | {@link WebGLContextAttributes} to pass to the getContext call |
Returns
void
Inherited from
Defined in
src/renderer/renderer.ts:77
queueCircles
โธ Static
queueCircles(circles
, zIndex?
): void
Queue a group of circle to be batch rendered.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
circles | (Circle | Renderable <Circle >)[] | undefined | The circles to queue |
zIndex | number | 0 | The 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
Name | Type | Default value | Description |
---|---|---|---|
entities | Entity [] | undefined | The entities to render |
zIndex | number | 0 | The 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
Name | Type | Default value | Description |
---|---|---|---|
entity | Entity | undefined | The entity to render |
zIndex | number | 0 | The 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
Name | Type | Default value | Description |
---|---|---|---|
rects | (Rect | Renderable <Rect >)[] | undefined | The rects to queue |
zIndex | number | 0 | The 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
Name | Type | Default value | Description |
---|---|---|---|
shape | Shape | undefined | The shape to queue |
position | vec2 | undefined | The x and y position to render the rectangle at |
rotation | number | 0 | The rotation to apply to the shape |
zIndex | number | 0 | The z position of the rendered rectangle |
Returns
void
Inherited from
Defined in
src/renderer/renderer.ts:238
queueTriangles
โธ Static
queueTriangles(triangles
, zIndex?
): void
Queue a group of triangle to be batch rendered.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
triangles | (Triangle | Renderable <Triangle >)[] | undefined | The triangles to queue |
zIndex | number | 0 | The 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
Name | Type | Default value | Description |
---|---|---|---|
circles | (Circle | Renderable <Circle >)[] | undefined | The circles to render |
zIndex | number | 0 | The 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
Name | Type | Default value | Description |
---|---|---|---|
geometry | Geometry | undefined | The geometry to render |
type | "rect" | "circle" | "triangle" | undefined | The type of shape shader to use |
zIndex | number | 0 | The 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
Name | Type | Default value | Description |
---|---|---|---|
rects | (Rect | Renderable <Rect >)[] | undefined | The rects to render |
zIndex | number | 0 | The 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
Name | Type | Default value | Description |
---|---|---|---|
triangles | (Triangle | Renderable <Triangle >)[] | undefined | The triangles to render |
zIndex | number | 0 | The 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
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
Name | Type | Description |
---|---|---|
mode | "TRIANGLES" | "LINES" | "POINTS" | The mode to use |
Returns
void
Inherited from
Defined in
src/renderer/renderer.ts:364
setQueueMax
โธ Static
setQueueMax(max
): void
Sets the maximum zIndex used by the queue.
Parameters
Name | Type | Description |
---|---|---|
max | number | The max zIndex of the queue |
Returns
void
Overrides
Defined in
src/renderer/batchRenderer.ts:451
setQueueMin
โธ Static
setQueueMin(min
): void
Sets the minimum zIndex used by the queue.
Parameters
Name | Type | Description |
---|---|---|
min | number | The min zIndex of the queue |
Returns
void
Overrides
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
Name | Type | Description |
---|---|---|
resolutionScale | number | The new resolution scale to use |
Returns
void
Inherited from
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
Name | Type | Description |
---|---|---|
scale | vec2 | The scaling vector |
Returns
void
Inherited from
Defined in
src/renderer/renderer.ts:404
useCamera
โธ Static
useCamera(camera
): void
Sets the camera to use for rendering.
Parameters
Name | Type | Description |
---|---|---|
camera | Camera | The camera to use for rendering |
Returns
void
Inherited from
Defined in
src/renderer/renderer.ts:386