API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classPixelReader

@codexo/exojs / rendering / stable

A standing, non-blocking readback of one rectangle of one render texture, for callers who read repeatedly: a picker, an analysis pass, a shader that produces data rather than pixels. ```ts const probe = app.rendering.createPixelReader(app.frameTexture, { region: cursorRect }); let pending: PixelRead | null = null; update() { if (clicked) pending = probe.request(); if (pending?.ready) { pick(pending.data!); pending.release(); pending = null; } } ``` Nothing blocks and nothing is allocated per read: each of the reader's slots owns a staging buffer and a destination array for the reader's lifetime, and a read copies into the slot it was given. The price is latency, the pixels arrive a frame or more after the request, on both backends alike. A caller that needs the pixels within the frame that drew them should keep that data CPU-side instead; for a screenshot or any other single read, RenderingContext.readPixels is the simpler call. `request()` refuses with `null` when every slot is held, rather than queueing or stalling, so a consumer that reads faster than the GPU delivers sees that as it happens instead of as growing latency. # Ownership The reader owns its slots and their arrays and nothing else; the source is the caller's. Destroy the reader when the reads stop. A read whose consumer went away still completes into its slot, so the worst case is the reader's own fixed footprint, never a leak. Context loss fails the reads in flight and the reader recovers on its own; resizing the source fails them too, and a whole-texture reader follows the new size.

6
props
2
methods
0
events
Import
import { PixelReader } from '@codexo/exojs'

A standing, non-blocking readback of one rectangle of one render texture, for callers who read repeatedly: a picker, an analysis pass, a shader that produces data rather than pixels.

```ts const probe = app.rendering.createPixelReader(app.frameTexture, { region: cursorRect }); let pending: PixelRead | null = null;

update() { if (clicked) pending = probe.request();

if (pending?.ready) { pick(pending.data!); pending.release(); pending = null; } } ```

Nothing blocks and nothing is allocated per read: each of the reader's slots owns a staging buffer and a destination array for the reader's lifetime, and a read copies into the slot it was given. The price is latency, the pixels arrive a frame or more after the request, on both backends alike. A caller that needs the pixels within the frame that drew them should keep that data CPU-side instead; for a screenshot or any other single read, RenderingContext.readPixels is the simpler call.

`request()` refuses with `null` when every slot is held, rather than queueing or stalling, so a consumer that reads faster than the GPU delivers sees that as it happens instead of as growing latency.

# Ownership

The reader owns its slots and their arrays and nothing else; the source is the caller's. Destroy the reader when the reads stop. A read whose consumer went away still completes into its slot, so the worst case is the reader's own fixed footprint, never a leak. Context loss fails the reads in flight and the reader recovers on its own; resizing the source fails them too, and a whole-texture reader follows the new size.

Constructors1
Prefer RenderingContext.createPixelReader, which resolves the backend. Constructing one directly is for code that already holds a RenderBackend, such as an extension package.
Methods2
destroy(): void
Release every slot's GPU memory. Reads in flight fail. Idempotent.
Copy the rectangle as drawn so far and hand back the read to poll, or null when every slot is still held. Everything drawn into the source before this call is included; pending work is submitted first. Throws once the reader or its source is destroyed, and when a region reader's rectangle no longer fits a resized source.
Properties6
slots: number
Number of staging slots.
height: number
Height of the rectangle each read describes.
inFlight: number
Reads handed out and not yet released, pending or finished. Equal to slots when the next request would be refused.
isDestroyed: boolean
width: number
Width of the rectangle each read describes.
Source