Texture
이 페이지에서

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읽기 전용 object
format읽기 전용 string
width읽기 전용 number
height읽기 전용 number

인스턴스 메서드

resize (width: number, height: number): void

Replace 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 bgra8unorm texel is blue, green, red, alpha). Any uncompressed colour format is read, and depth32float; a compressed format and the other depth and stencil formats reject with a TypeError. 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() and rt.submit() hand the queue their commands before their own first await, 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 Float32Array of the texels’ channels in the order and with the packing read() gives, one number to each channel of each texel. A float format is decoded (a half float exactly), a unorm one gives 0 to 1, an snorm one -1 to 1, and depth32float its depth. An sRGB format gives the numbers it stores, as read()’s bytes hold them, not the linear values a shader reads. An integer format rejects with a TypeError that names read(), which gives its bytes.

It reads what read() reads, and when: the copy is recorded and submitted before readFloats() awaits anything.

destroy (): void

소스

src/runtime/resources.ts, 36행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고