---
title: "Texture: interface in Runtime, TypeShade API reference"
description: "Texture, an interface in Runtime. A texture the runtime binds by name and renders into: a sampled texture, a render target, a depth or shadow map."
url: https://typeshade.dev/api/texture-interface/
language: en
---

# `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 af54ddad5.

## Syntax

```ts
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

**`texture` read only `object`**

Escape hatch ([Rule 11.17](https://typeshade.dev/reference/rules/11-17/)): the `GPUTexture` or `WebGLTexture` the texture holds.

**`format` read only `string`**

**`width` read only `number`**

**`height` read only `number`**

## Instance methods

**`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`**

## Source

[`src/runtime/resources.ts`, line 35](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/resources.ts#L35), at commit af54ddad5
