Skip to content

@bloopjs/toodle


@bloopjs/toodle / backends/webgpu/WebGPUBackend / WebGPUBackend

Class: WebGPUBackend

Defined in: backends/webgpu/WebGPUBackend.ts:26

WebGPU implementation of the render backend.

Implements

Properties

atlasSize

readonly atlasSize: Size

Defined in: backends/webgpu/WebGPUBackend.ts:29

Size of the default texture atlas

Implementation of

IRenderBackend.atlasSize


defaultAtlasId

readonly defaultAtlasId: "default" = "default"

Defined in: backends/webgpu/WebGPUBackend.ts:30

Default atlas ID (always "default")

Implementation of

IRenderBackend.defaultAtlasId


limits

readonly limits: object

Defined in: backends/webgpu/WebGPUBackend.ts:28

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: "webgpu"

Defined in: backends/webgpu/WebGPUBackend.ts:27

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

Implementation of

IRenderBackend.type

Accessors

context

Get Signature

get context(): GPUCanvasContext

Defined in: backends/webgpu/WebGPUBackend.ts:328

Get the canvas context.

Returns

GPUCanvasContext


device

Get Signature

get device(): GPUDevice

Defined in: backends/webgpu/WebGPUBackend.ts:321

Get the GPU device for advanced operations.

Returns

GPUDevice


presentationFormat

Get Signature

get presentationFormat(): GPUTextureFormat

Defined in: backends/webgpu/WebGPUBackend.ts:335

Get the presentation format.

Returns

GPUTextureFormat


renderPass

Get Signature

get renderPass(): GPURenderPassEncoder

Defined in: backends/webgpu/WebGPUBackend.ts:343

Get the current render pass encoder. Only available between startFrame() and endFrame().

Returns

GPURenderPassEncoder

Methods

createQuadShader()

createQuadShader(opts): IBackendShader

Defined in: backends/webgpu/WebGPUBackend.ts:199

Create a quad shader for instanced rendering.

Parameters

opts

QuadShaderCreationOpts

Returns

IBackendShader

Implementation of

IRenderBackend.createQuadShader


createTextureAtlas()

createTextureAtlas(id, options?): ITextureAtlas

Defined in: backends/webgpu/WebGPUBackend.ts:210

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/webgpu/WebGPUBackend.ts:257

Clean up GPU resources.

Returns

void

Implementation of

IRenderBackend.destroy


destroyTextureAtlas()

destroyTextureAtlas(id): void

Defined in: backends/webgpu/WebGPUBackend.ts:238

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/webgpu/WebGPUBackend.ts:132

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


getPostprocess()

getPostprocess(): null | PostProcess

Defined in: backends/webgpu/WebGPUBackend.ts:285

Get the current post-processor.

Returns

null | PostProcess


getTextureAtlas()

getTextureAtlas(id?): null | ITextureAtlas

Defined in: backends/webgpu/WebGPUBackend.ts:234

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/webgpu/WebGPUBackend.ts:246

Handle canvas resize.

Parameters

_width

number

_height

number

Returns

void

Implementation of

IRenderBackend.resize


setPostprocess()

setPostprocess(processor): void

Defined in: backends/webgpu/WebGPUBackend.ts:273

Set a post-processor for screen effects. Setting a post-processor will cause the main render to go to an offscreen texture. Note: Ping-pong textures are not destroyed when setting to null to avoid race conditions with in-flight command buffers. They are cleaned up on destroy().

Parameters

processor

null | PostProcess

Returns

void


startFrame()

startFrame(clearColor, loadOp): void

Defined in: backends/webgpu/WebGPUBackend.ts:111

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/webgpu/WebGPUBackend.ts:154

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/webgpu/WebGPUBackend.ts:159

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<WebGPUBackend>

Defined in: backends/webgpu/WebGPUBackend.ts:64

Create a WebGPU backend attached to a canvas.

Parameters

canvas

HTMLCanvasElement

options

WebGPUBackendOptions = {}

Returns

Promise<WebGPUBackend>