Texture
인터페이스, 런타임 분류
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'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
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;}설명
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.
인스턴스 속성
texture읽기 전용objectformat읽기 전용stringwidth읽기 전용numberheight읽기 전용number
인스턴스 메서드
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
소스
src/runtime/resources.ts, 36행, 커밋 c66579bf 기준