Skip to content

@bloopjs/toodle


@bloopjs/toodle / backends/webgl2/WebGLBackend / WebGLBackend

Class: WebGLBackend ​

Defined in: backends/webgl2/WebGLBackend.ts:25

WebGL 2 implementation of the render backend.

Implements ​

Properties ​

atlasSize ​

readonly atlasSize: Size

Defined in: backends/webgl2/WebGLBackend.ts:28

Size of the default texture atlas

Implementation of ​

IRenderBackend.atlasSize


defaultAtlasId ​

readonly defaultAtlasId: "default" = "default"

Defined in: backends/webgl2/WebGLBackend.ts:29

Default atlas ID (always "default")

Implementation of ​

IRenderBackend.defaultAtlasId


limits ​

readonly limits: object

Defined in: backends/webgl2/WebGLBackend.ts:27

Engine limits (texture size, instance count, etc.)

instanceBufferFields ​

instanceBufferFields: number

Maximum number of instance buffer fields - 16 minus the vertex locations used by the engine

instanceBufferSize ​

instanceBufferSize: number

Maximum size of instance buffer

instanceCount ​

instanceCount: number

Maximum number of rendered instances in the scene per frame

maxTextLength ​

maxTextLength: number = 256

Maximum length of a single piece of text

shaderCount ​

shaderCount: number = 32

Maximum number of vfx shaders

textureArrayLayers ​

textureArrayLayers: number = 64

Maximum number of layers in a texture array

textureSize ​

textureSize: number

Maximum dimensions of a single texture

uniformBufferSize ​

uniformBufferSize: number

Maximum size of uniforms buffer

zIndex ​

zIndex: number = 32

Maximum number of unique z-indexes in the scene

Implementation of ​

IRenderBackend.limits


type ​

readonly type: "webgl2"

Defined in: backends/webgl2/WebGLBackend.ts:26

The type of backend ("webgpu" or "webgl2")

Implementation of ​

IRenderBackend.type

Accessors ​

gl ​

Get Signature ​

get gl(): WebGL2RenderingContext

Defined in: backends/webgl2/WebGLBackend.ts:246

Get the WebGL 2 rendering context.

Returns ​

WebGL2RenderingContext


presentationFormat ​

Get Signature ​

get presentationFormat(): TextureAtlasFormat

Defined in: backends/webgl2/WebGLBackend.ts:253

Get the presentation format (of the default atlas).

Returns ​

TextureAtlasFormat


textureArrayHandle ​

Get Signature ​

get textureArrayHandle(): WebGLTexture

Defined in: backends/webgl2/WebGLBackend.ts:226

Get the default texture atlas handle.

Deprecated ​

Use getTextureAtlas("default").handle instead

Returns ​

WebGLTexture

Methods ​

createQuadShader() ​

createQuadShader(opts): IBackendShader

Defined in: backends/webgl2/WebGLBackend.ts:160

Create a quad shader for instanced rendering.

Parameters ​

opts ​

QuadShaderCreationOpts

Returns ​

IBackendShader

Implementation of ​

IRenderBackend.createQuadShader


createTextureAtlas() ​

createTextureAtlas(id, options?): ITextureAtlas

Defined in: backends/webgl2/WebGLBackend.ts:170

Create a new texture atlas.

Parameters ​

id ​

string

Unique identifier for this atlas

options? ​

TextureAtlasOptions

Atlas configuration (format, layers, size)

Returns ​

ITextureAtlas

Implementation of ​

IRenderBackend.createTextureAtlas


destroy() ​

destroy(): void

Defined in: backends/webgl2/WebGLBackend.ts:234

Clean up GPU resources.

Returns ​

void

Implementation of ​

IRenderBackend.destroy


destroyTextureAtlas() ​

destroyTextureAtlas(id): void

Defined in: backends/webgl2/WebGLBackend.ts:214

Destroy a texture atlas and free GPU resources.

Parameters ​

id ​

string

Atlas identifier

Returns ​

void

Implementation of ​

IRenderBackend.destroyTextureAtlas


endFrame() ​

endFrame(): void

Defined in: backends/webgl2/WebGLBackend.ts:104

End the current frame and submit to GPU. WebGPU: Ends render pass and submits command buffer WebGL: Flushes pending operations

Returns ​

void

Implementation of ​

IRenderBackend.endFrame


getTextureAtlas() ​

getTextureAtlas(id): null | ITextureAtlas

Defined in: backends/webgl2/WebGLBackend.ts:210

Get a texture atlas by ID.

Parameters ​

id ​

string

Atlas identifier or defaults to "default"

Returns ​

null | ITextureAtlas

The atlas, or null if not found

Implementation of ​

IRenderBackend.getTextureAtlas


resize() ​

resize(_width, _height): void

Defined in: backends/webgl2/WebGLBackend.ts:230

Handle canvas resize.

Parameters ​

_width ​

number

_height ​

number

Returns ​

void

Implementation of ​

IRenderBackend.resize


startFrame() ​

startFrame(clearColor, loadOp): void

Defined in: backends/webgl2/WebGLBackend.ts:83

Begin a new frame. WebGPU: Creates command encoder and render pass WebGL: Clears the canvas if loadOp is "clear"

Parameters ​

clearColor ​

Color

loadOp ​

"load" | "clear"

Returns ​

void

Implementation of ​

IRenderBackend.startFrame


updateEngineUniform() ​

updateEngineUniform(_uniform): void

Defined in: backends/webgl2/WebGLBackend.ts:109

Update engine uniforms (view-projection matrix, resolution). Called once per frame before shader processing.

Parameters ​

_uniform ​

EngineUniform

Returns ​

void

Implementation of ​

IRenderBackend.updateEngineUniform


uploadAtlas() ​

uploadAtlas(atlas, layerIndex, atlasId?): Promise<void>

Defined in: backends/webgl2/WebGLBackend.ts:113

Upload a CPU texture atlas to a GPU texture array layer.

Parameters ​

atlas ​

CpuTextureAtlas

The CPU-side atlas data to upload

layerIndex ​

number

Which layer in the texture array to upload to

atlasId? ​

string

Which atlas to upload to (default: "default")

Returns ​

Promise<void>

Implementation of ​

IRenderBackend.uploadAtlas


create() ​

static create(canvas, options): Promise<WebGLBackend>

Defined in: backends/webgl2/WebGLBackend.ts:52

Create a WebGL 2 backend attached to a canvas.

Parameters ​

canvas ​

HTMLCanvasElement

options ​

WebGLBackendOptions = {}

Returns ​

Promise<WebGLBackend>