Skip to content

Texture resources

Read as Markdown

defineTexture from @pibbl/core creates a recipe factory. Recipes contain data; useTexture(recipe, options) creates one persistent, mount-owned source that can be passed directly to style.fill or style.stroke. Its send(message) method queues typed, structured-cloneable data for the next Pibbl update. It may not run during rendering. A static texture without a receiver accepts no messages.

TextureDefinition<Config, State, Message> supplies synchronous create, rasterize, and optional update, receive, advance, and dispose callbacks. TextureContext supplies the resource-owned canvas, optional palette, invalidate() for changed output, and requestFrame() for continuing work. TextureFrame supplies delta and time in milliseconds. No additional loop is needed. Configurations and messages must be structured-cloneable data.

TextureOptions controls resolution and optional palette. Resolution defaults to 256 by 160; dimensions are integers from 8 through 1024 with at most 262144 cells. Resizing resets implementation state. Palette changes preserve state.

Texture<Message> is a TexturePaint with send and paint(placement). TexturePlacement chooses repeat or stretch, logical tileWidth/tileHeight, offsetX/offsetY, and rotation in degrees. Paint views share their owner’s pixels and lifetime. Sharing is supported within the owner’s Pibbl tree. Disposal releases the canvas and queued work; later sends are inert, and rendering a disposed resource is an error. Owners must outlive consumers.

TextureRecipe<Message> is the opaque result of the recipe factory. Recreating recipes with the same definition preserves the mounted resource. Changing the definition requires a new keyed owner. Custom implementations receive changed configuration through update and decide whether output needs regeneration.

Creates the immutable recipe factory for a custom implementation.

The typed resource handle accepted by fills and strokes.

The owned raster and invalidation capabilities.

The custom implementation lifecycle described above.

Pibbl-supplied time and delta in milliseconds.

Resource resolution and presentation palette.

An opaque resource-backed paint, optionally with per-use placement.

Per-consumer repeat/stretch, tile size, offset, and rotation.

A pure definition/configuration value consumed by the hook.

Owns one recipe instance at the current mounted hook slot.

Owns one persistent texture resource for the current mounted hook slot.

useTexture: <Message>(input: TextureRecipe<Message>, options?: TextureOptions) => Texture<Message>

Related API: useTexture, TextureRecipe, TextureOptions, Texture.

  • input — Texture recipe to mount or update. See TextureRecipe.

  • options — Resolution and lifecycle options for the mounted texture. See TextureOptions .

A mount-owned texture handle for sending messages and creating paint placements. See Texture .

TextureRecipe

TextureOptions

Texture

View source — packages/core/src/lib/textures/texture.ts:565

Defines a pure recipe factory; resource allocation starts at useTexture.

defineTexture: <Config, State, Message = never>(definition: TextureDefinition<Config, State, Message>) => (config: Config) => TextureRecipe<Message>

Related API: defineTexture, TextureDefinition, TextureRecipe.

  • definition — State creation, update, simulation, rasterization, and disposal callbacks. See TextureDefinition .

A configuration-to-recipe factory; resources are allocated when a recipe is mounted. See TextureRecipe .

TextureDefinition

TextureRecipe

View source — packages/core/src/lib/textures/texture.ts:179

A mount-owned texture handle that provides paint and accepts recipe messages.

interface Texture<Message = never> extends TexturePaint

Related API: Texture, TexturePaint.

TexturePaint

TexturePlacement

useTexture

View source — packages/core/src/lib/textures/texture.ts:27

send
send: (message: Message) => void

Delivers a typed message to the mounted recipe instance. See Texture.

  • message — Message delivered to the texture definition’s receive callback.

View source — packages/core/src/lib/textures/texture.ts:32

paint
paint: (placement: TexturePlacement) => TexturePaint

Related API: TexturePlacement, TexturePaint.

Returns a paint view with the requested placement while retaining the same texture ownership. See TexturePaint.

  • placement — Destination bounds and texture placement policy. See TexturePlacement .

A paint descriptor referencing this mounted texture. See TexturePaint.

View source — packages/core/src/lib/textures/texture.ts:40

Opaque paint value produced by a mounted texture owner.

interface TexturePaint

Related API: TexturePaint.

FillStyle

StrokeStyle

Texture

View source — packages/core/src/lib/textures/texture-protocol.ts:35

A reusable texture definition together with the options used to instantiate it.

interface TextureRecipe<Message = never>

Related API: TextureRecipe.

defineTexture

useTexture

View source — packages/core/src/lib/textures/texture.ts:158

Lifecycle callbacks for creating, updating, painting, and disposing texture resources.

interface TextureDefinition<Config, State, Message = never>

Related API: TextureDefinition.

TexturePlacement

TextureContext

TextureFrame

defineTexture

View source — packages/core/src/lib/textures/texture.ts:98

defaultPlacement (optional)
readonly defaultPlacement?: TexturePlacement | undefined

Related API: TexturePlacement.

Texture placement used when no paint-specific override is supplied. See TexturePlacement.

View source — packages/core/src/lib/textures/texture.ts:103

create
create: (context: TextureContext, config: Readonly<Config>) => State

Related API: TextureContext.

Allocates state for a mounted texture recipe. See TextureDefinition.

  • context — Texture-owned drawing surface and scheduling services. See TextureContext .

  • config — Initial recipe configuration.

State retained for this mounted texture lifetime.

View source — packages/core/src/lib/textures/texture.ts:111

update (optional)
update?: ((state: State, config: Readonly<Config>, context: TextureContext) => void) | undefined

Related API: TextureContext.

Updates existing state when the recipe configuration changes. See TextureDefinition.

  • state — State returned by create.

  • config — Latest recipe configuration.

  • context — Texture-owned drawing surface and scheduling services. See TextureContext .

View source — packages/core/src/lib/textures/texture.ts:119

receive (optional)
receive?: ((state: State, message: Message, context: TextureContext) => void) | undefined

Related API: TextureContext.

Handles a typed application message for this recipe instance. See TextureDefinition.

  • state — State returned by create.

  • message — Message sent through the mounted texture handle.

  • context — Texture-owned drawing surface and scheduling services. See TextureContext .

View source — packages/core/src/lib/textures/texture.ts:127

advance (optional)
advance?: ((state: State, frame: TextureFrame, context: TextureContext) => void) | undefined

Related API: TextureFrame, TextureContext.

Advances simulation using the shared Pibbl frame timing. See TextureDefinition.

  • state — State returned by create.

  • frame — Shared animation time and delta. See TextureFrame.

  • context — Texture-owned drawing surface and scheduling services. See TextureContext .

View source — packages/core/src/lib/textures/texture.ts:135

rasterize
rasterize: (state: State, context: TextureContext) => void

Related API: TextureContext.

Draws current texture pixels into the owned offscreen surface. See TextureDefinition.

  • state — State returned by create.

  • context — Texture-owned drawing surface and scheduling services. See TextureContext .

View source — packages/core/src/lib/textures/texture.ts:142

dispose (optional)
dispose?: ((state: State, context: TextureContext) => void) | undefined

Related API: TextureContext.

Releases state and resources when the mounted texture is disposed. See TextureDefinition.

  • state — State returned by create.

  • context — Texture-owned drawing surface and scheduling services. See TextureContext .

View source — packages/core/src/lib/textures/texture.ts:150

Resolution and runtime configuration for a mounted texture recipe.

interface TextureOptions

Related API: TextureOptions.

useTexture

View source — packages/core/src/lib/textures/texture.ts:47

resolution (optional)
readonly resolution?: { readonly width: number; readonly height: number; } | undefined

Dimensions of the simulation or raster grid. See TextureOptions.

View source — packages/core/src/lib/textures/texture.ts:49

palette (optional)
readonly palette?: readonly string[] | undefined

Ordered colors used to present texture intensity. See TextureOptions.

View source — packages/core/src/lib/textures/texture.ts:62

How a texture raster is positioned and scaled when used as paint.

interface TexturePlacement

Related API: TexturePlacement.

Texture

TextureDefinition

View source — packages/core/src/lib/textures/texture-protocol.ts:13

mode (optional)
readonly mode?: "repeat" | "stretch" | undefined

Related API: repeat.

Selects the supported mapping, placement, or result policy. See TexturePlacement.

View source — packages/core/src/lib/textures/texture-protocol.ts:15

tileWidth (optional)
readonly tileWidth?: number | undefined

Width of one texture tile in logical paint coordinates. See TexturePlacement.

View source — packages/core/src/lib/textures/texture-protocol.ts:17

tileHeight (optional)
readonly tileHeight?: number | undefined

Height of one texture tile in logical paint coordinates. See TexturePlacement.

View source — packages/core/src/lib/textures/texture-protocol.ts:19

offsetX (optional)
readonly offsetX?: number | undefined

Horizontal offset applied to the texture or shadow. See TexturePlacement.

View source — packages/core/src/lib/textures/texture-protocol.ts:21

offsetY (optional)
readonly offsetY?: number | undefined

Vertical offset applied to the texture or shadow. See TexturePlacement.

View source — packages/core/src/lib/textures/texture-protocol.ts:23

rotation (optional)
readonly rotation?: number | undefined

Rotation applied to the containing geometry. See TexturePlacement.

View source — packages/core/src/lib/textures/texture-protocol.ts:25

Surface and invalidation facilities supplied to texture lifecycle callbacks.

interface TextureContext

Related API: TextureContext.

TextureDefinition

View source — packages/core/src/lib/textures/texture.ts:69

canvas
readonly canvas: OffscreenCanvas

Canvas surface associated with this resource or mount. See TextureContext.

View source — packages/core/src/lib/textures/texture.ts:71

palette
readonly palette: readonly string[] | undefined

Ordered colors used to present texture intensity. See TextureContext.

View source — packages/core/src/lib/textures/texture.ts:73

invalidate
invalidate: () => void

Marks the source pixels dirty and requests a Pibbl update.

View source — packages/core/src/lib/textures/texture.ts:75

requestFrame
requestFrame: () => void

Requests another Pibbl frame; implementations stop by not requesting again.

View source — packages/core/src/lib/textures/texture.ts:77

Shared logical time and elapsed milliseconds supplied while advancing a texture.

interface TextureFrame

Related API: TextureFrame.

TextureDefinition

View source — packages/core/src/lib/textures/texture.ts:84

delta
readonly delta: number

Elapsed time since the preceding texture frame, in milliseconds. See TextureFrame.

View source — packages/core/src/lib/textures/texture.ts:86

time
readonly time: number

Current shared logical time, in milliseconds. See TextureFrame.

View source — packages/core/src/lib/textures/texture.ts:88

Read the Textures and reaction-diffusion companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

Documentation built with @pibbl/core 0.0.2, revision 380919b. ALPHA — NOT FOR PRODUCTION USE.