Texture
Interface in Runtime
A texture the runtime binds by name and renders into: a sampled texture, a render target, a depth or shadow map.
import type { Texture } from 'typeshade/runtime'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
interface Texture { readonly texture: object; readonly format: string; readonly width: number; readonly height: number; resize(width: number, height: number): void; read(): Promise<Uint8Array>; readFloats(): Promise<Float32Array>; destroy(): void;}Description
A texture the runtime binds by name and renders into: a sampled texture, a render target, a
depth or shadow map. It lives until destroy(), and resize() gives it a new size, keeping
its format. texture is the GPUTexture itself, for the host’s own WebGPU.
Instance properties
textureread onlyobjectformatread onlystringwidthread onlynumberheightread onlynumber
Instance methods
resize(width: number, height: number): voidReplace the texture with one of this size. What it held is gone.
read(): Promise<Uint8Array>Read every texel back as bytes: rows tightly packed, as many bytes to a texel as the format has, its channels in the format’s order (a
bgra8unormtexel is blue, green, red, alpha). Any uncompressed colour format is read, anddepth32float; a compressed format and the other depth and stencil formats reject with aTypeError. An array or a 3D texture gives its first layer or slice.A read reads what was submitted before the call. Its copy is recorded and submitted before
read()awaits anything, so the queue runs it after every submit made before the call and before every one made after: a frame submitted while the read is pending draws after the copy, and the bytes are the texture as it was.frame.submit()andrt.submit()hand the queue their commands before their own firstawait, so a frame counts as submitted from that call and not from the moment its promise resolves; a frame recorded and not yet submitted is not read.readFloats(): Promise<Float32Array>Read every texel back as numbers: a
Float32Arrayof the texels’ channels in the order and with the packingread()gives, one number to each channel of each texel. A float format is decoded (a half float exactly), aunormone gives 0 to 1, ansnormone -1 to 1, anddepth32floatits depth. An sRGB format gives the numbers it stores, asread()’s bytes hold them, not the linear values a shader reads. An integer format rejects with aTypeErrorthat namesread(), which gives its bytes.It reads what
read()reads, and when: the copy is recorded and submitted beforereadFloats()awaits anything.destroy(): void
Source
src/runtime/resources.ts, line 36, at commit 26de7be8