Skip to content

Texture2D

Wrapper around a GPUTexture with convenient factory methods.

Load a texture from a URL (async).

const tex = await Texture2D.fromUrl(surface, '/sprites/hero.png')

From an HTMLImageElement, ImageBitmap, HTMLCanvasElement, or OffscreenCanvas.

const tex = Texture2D.fromImageSource(surface, myImageBitmap)

Create a 1x1 solid-color texture.

const white = Texture2D.fromColor(surface, 1, 1, 1)
MemberTypeDescription
widthnumberTexture width in pixels
heightnumberTexture height in pixels
viewGPUTextureViewThe GPU texture view

Release the GPU texture.

tex.destroy()