Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Nightre/Rapid.js/llms.txt

Use this file to discover all available pages before exploring further.

TextureManager is the central hub for all texture operations in Rapid.js. It is accessed through rapid.texture and takes care of loading images from the network, creating textures from in-memory sources, and tracking every GPU resource through reference counting so nothing leaks and nothing is destroyed too early.
URLs loaded via .load() are cached by URL string. Calling .load() again with the same URL skips the network request and returns a new Texture view that shares the same underlying BaseTexture — no duplicate GPU uploads.

Methods

load(url, options?)

Asynchronously fetches an image from a URL, uploads it to the GPU, caches the result, and returns a Texture wrapping the full image.
const tex = await rapid.texture.load("/assets/hero.png");
Parameters
url
string
required
The URL of the image to load. Used as the cache key.
options
ITextureOptions
Optional texture configuration. See ITextureOptions below.
Returns: Promise<Texture>

create(source, options?)

Synchronously creates a Texture from an existing browser media element or bitmap. Useful when you already have an image decoded in memory — for example a procedurally drawn HTMLCanvasElement or a decoded ImageBitmap.
const canvas = document.getElementById("myCanvas") as HTMLCanvasElement;
const tex = rapid.texture.create(canvas, { key: "myCanvas" });
Parameters
source
Images
required
The pixel source. Accepted types: HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageBitmap, OffscreenCanvas.
options
ITextureOptions
Optional texture configuration. If options.key is provided and a cached texture with that key already exists, the existing BaseTexture is reused.
Returns: Texture

createRenderTexture(options)

Creates a RenderTexture — a texture backed by a WebGL framebuffer that you can draw into. See the RenderTexture reference for full details on drawing and pixel readback.
const rt = rapid.texture.createRenderTexture({
  width: 512,
  height: 512,
  clearColor: Color.Transparent,
});
Parameters
options
IRenderTextureOptions
required
Configuration for the offscreen framebuffer. See the RenderTexture page for all fields.
Returns: RenderTexture

createTextTexture(options?)

Creates a TextTexture — a texture that renders styled text via an internal HTML5 canvas and uploads the result to the GPU. See the TextTexture reference for styling and live-update details.
const label = rapid.texture.createTextTexture({
  text: "Hello, World!",
  fontSize: 28,
  fill: "#ffffff",
});
Parameters
options
ITextOptions
Optional text content and style configuration. See the TextTexture page for all fields.
Returns: TextTexture

destroy(textureOrUrl, force?)

Destroys a texture and, if the underlying BaseTexture reference count drops to zero (or force is true), removes the WebGL texture from the GPU and evicts it from the cache.
// By URL
rapid.texture.destroy("/assets/hero.png");

// By Texture instance
rapid.texture.destroy(myTexture);

// Force-destroy immediately regardless of other references
rapid.texture.destroy(myTexture, true);
Parameters
textureOrUrl
Texture | BaseTexture | string
required
The resource to destroy. Accepts a Texture instance, a BaseTexture instance, or the URL string that was used to load the texture.
force
boolean
default:"false"
When true, the underlying BaseTexture is destroyed immediately regardless of its current refCount. Use with caution — other Texture views sharing the same BaseTexture will be left with dangling GPU references.
Returns: void

destroyAll()

Destroys every cached BaseTexture and clears the internal cache. Reference counts are ignored. Call this during a full scene teardown or when shutting down the renderer.
rapid.texture.destroyAll();
Returns: void

ITextureOptions

Options accepted by load(), create(), and the RenderTexture/TextTexture factory methods.
textureFilter
TextureFilterMode
Controls how the texture is sampled when scaled.
ValueDescription
TextureFilterMode.NEARESTPixel-perfect, no blending. Default.
TextureFilterMode.LINEARBilinear interpolation — smoother at scale.
wrap
TextureWrapMode
Controls how UV coordinates outside the [0, 1] range are handled.
ValueDescription
TextureWrapMode.CLAMPClamps to the edge pixel.
TextureWrapMode.REPEATTiles the texture.
TextureWrapMode.MIRRORED_REPEATTiles with alternating mirror flips.
premultipliedAlpha
boolean
Whether the texture data uses premultiplied alpha. When set, the WebGL UNPACK_PREMULTIPLY_ALPHA_WEBGL pixel store flag is toggled accordingly.
key
string
An explicit cache key. If provided, the resulting BaseTexture is stored in the cache under this key and reused on subsequent create() calls with the same key. Has no effect on load() (which always uses the URL as key).

Build docs developers (and LLMs) love