---
title: "textureStore / imageStore: shader function guide"
description: "A texture store replaces the value of one integer-addressed texel. Use it to write a compute result into an image."
url: https://typeshade.dev/reference/functions/textureStore/
language: en
---

# `textureStore`

Function

A texture store replaces the value of one integer-addressed texel.

**Related names in other languages**

These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.

- GLSL: `imageStore`

[Targets](https://typeshade.dev/reference/functions/textureStore/#targets)

## Compare examples

Only the selected texel changes to the input value. The call returns no value; the display shows the texel before and after the store.

**Model assumptions**`texture_storage_2d<"r32float", "write">; value = vec4(0.5, 0, 0, 1)`

**Example 1`textureStore(tex, vec2i(0, 0), value)`**

`0.75` `1` `0.5` `0.25`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Stored value before**

`0`

**Returned value**

`void`

**Stored value after**

`0.5`

**Example 2`textureStore(tex, vec2i(1, 0), value)`**

`0.75` `1` `0` `0.5`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Stored value before**

`0.25`

**Returned value**

`void`

**Stored value after**

`0.5`

**Example 3`textureStore(tex, vec2i(1, 1), value)`**

`0.75` `0.5` `0` `0.25`

Texel grid. The upper row has the higher vertical texture coordinate. Values describe one channel; comparison grids show pass or fail.

**Stored value before**

`1`

**Returned value**

`void`

**Stored value after**

`0.5`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use it to write a compute result into an image.

## Inputs and limits

Use a writable storage texture and a value matching its format. This model shows separate writes; overlapping writes need an explicit race-free design.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`textureSample`](https://typeshade.dev/reference/functions/textureSample/)
- [`textureLoad`](https://typeshade.dev/reference/functions/textureLoad/)
- [`textureSampleLevel`](https://typeshade.dev/reference/functions/textureSampleLevel/)
- [`textureSampleBias`](https://typeshade.dev/reference/functions/textureSampleBias/)
- [`textureSampleGrad`](https://typeshade.dev/reference/functions/textureSampleGrad/)

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Writes one texel to a storage texture at the integer `coord`, on a binding declared `"write"` or `"read_write"`; returns nothing.

## Syntax

```ts
declare function textureStore<F extends StorageFormat, A extends 'write' | 'read_write'>(
  tex: texture_storage_2d<F, A>,
  coord: TexelCoord2,
  value: StorageTexel<F>,
): void
declare function textureStore<F extends StorageFormat, A extends 'write' | 'read_write'>(
  tex: texture_storage_2d_array<F, A>,
  coord: TexelCoord2,
  layer: number,
  value: StorageTexel<F>,
): void
```

A `number` in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

`type f32 = number & { readonly [f32Tag]?: true }`

A `number` you write as a type is inferred from its uses, and `f32`, `i32` and `u32` fix a width; [the TypeScript constructs page](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

A signature may name a type the ambient file declares for its own use. These are those declarations.

**`TexelCoord2`**

`type TexelCoord2 = vec2i | vec2u`

**`StorageFormat`**

`type StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm'`

**`StorageTexel`**

``type StorageTexel<F extends StorageFormat> = F extends `${string}uint` ? vec4u : F extends `${string}sint` ? vec4i : vec4``

## Parameters

- `tex` `texture_storage_2d<F, A>``texture_storage_2d_array<F, A>`
- `coord` `TexelCoord2`
- `value` `StorageTexel<F>`
- `layer` optional `number`

## Return value

`void`

## Description

The value is the texel the format decides: a `"…uint"` format stores a `vec4u`, a `"…sint"` one a `vec4i`, and every other one a `vec4`. Compiles to `textureStore` on WGSL; in a render entry its GLSL lowering is not supported yet ([Rule 10.5](https://typeshade.dev/reference/rules/10-5/)), so a module using it emits WGSL alone, and on the CPU tier a store into a `CpuTexture` converts the value as the format decides while a store outside it, or into a texture not in that memory, is dropped ([Rule 11.7](https://typeshade.dev/reference/rules/11-7/)).

The CPU oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with `{ gpuStubs: true }`, which returns a placeholder.

## Targets

**WGSL**

`textureStore(a, b, c)`

**GLSL ES 3.00**

`textureStore` is not supported yet on the WebGL2 tier (Rule 10.5)

## Examples

- [`gallery/kernel-image-invert/kernel-image-invert.shade.ts`](https://typeshade.dev/guide/examples/kernel-image-invert/)
- [`gallery/storage-texture/storage-texture.shade.ts`](https://typeshade.dev/guide/examples/storage-texture/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#textures)
