Docs
API Reference

ResourcesWebGPU

Shared WebGPU resources for UI and engine UIs. Import from @uno.build/ui/ResourcesWebGPU. The types below describe signatures; this module exports only the class.

Properties

PropertyTypeDescription
canvasWebGPUCanvas | undefinedCanvas supplied at creation.
adapterGPUAdapter | null | undefinedSupplied or requested adapter.
deviceGPUDeviceGPU device.
contextWebGPUContextCanvas context.
formatGPUTextureFormatRendering format.
image_atlas_sizenumberImage atlas layer size in pixels.
font_atlas_sizenumberFont atlas layer size in pixels.
image_managerImageManagerImage atlas manager.
font_managerFontManagerFont atlas manager.
has_presentbooleanWhether the context supports present().
eventsEventEmitterEmits image and font resource changes.

Methods

MethodReturnsDescription
static create(options: ResourcesWebGPUOptions)Promise<ResourcesWebGPU>Creates and initializes the resource store.
registerImage(src: string, image: WebGPUImage)ManagedAtlasImageRegisters an image under a resource key.
disposeImage(src: string)voidRemoves a registered image.
getImageSize(src: string){ width: number; height: number } | undefinedGets the registered image dimensions.
registerFont(name: string, font: WebGPUFont)ManagedFontRegisters a font image and its metadata.
disposeFont(name: string)voidRemoves a registered font.
dispose()voidClears registered resources and releases atlas textures.
present()voidCalls the context's optional present() method.

Duplicate image or font keys throw. Disposing an unknown key does nothing. ui.destroy() does not dispose shared resources; resources.dispose() does not destroy the device or context.

Creation options

OptionTypeDefault
canvasWebGPUCanvasRequired when context is omitted
contextWebGPUContextObtained from canvas and configured
adapterGPUAdapter | nullRequested when neither adapter nor device is supplied
deviceGPUDeviceRequested from the adapter
formatGPUTextureFormatnavigator.gpu.getPreferredCanvasFormat()
image_atlas_sizenumber2048
font_atlas_sizenumber2048

A supplied context is used without reconfiguration.

type WebGPUCanvas = {
  getContext(context_id: 'webgpu'): WebGPUContext | null
}

type WebGPUContext = GPUCanvasContext & { present?(): void }

Image input

WebGPUImage fieldTypeDefault
imageGPUCopyExternalImageSourceRequired
widthnumberimage.width; required if unavailable
heightnumberimage.height; required if unavailable
preventBleedingbooleanfalse; copies edge pixels into atlas padding when enabled

See Images for usage.

Font input

WebGPUFont contains the image fields above plus a required data: FontData. See Texts and fonts for usage.

type FontData = {
  atlas: {
    size: number
    distanceRange: number
    effectDistanceRange?: number
    yOrigin: 'bottom' | 'top'
    width?: number
    height?: number
    type?: string
  }
  metrics: {
    emSize?: number
    lineHeight: number
    ascender: number
    descender: number
    underlineY?: number
    underlineThickness?: number
  }
  glyphs: Array<{
    unicode: number
    advance: number
    planeBounds?: GlyphBounds
    atlasBounds?: GlyphBounds
  }>
  kerning?: Array<{ unicode1: number; unicode2: number; advance: number }>
}

type GlyphBounds = { left: number; bottom: number; right: number; top: number }

On this page