All GPU texture resources in Rapid.js are managed throughDocumentation 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.
rapid.texture, an instance of TextureManager. It handles asynchronous loading, synchronous creation from existing DOM elements, reference-counted memory management, and a URL-keyed cache that prevents the same image from being uploaded to the GPU more than once.
Loading a Texture from a URL
rapid.texture.load() fetches an image by URL, uploads it to the GPU, stores it in the cache, and returns a Texture wrapped in a Promise. Subsequent calls with the same URL return a new Texture view backed by the already-cached BaseTexture — no extra network requests or GPU uploads occur.
ITextureOptions object as the second argument to control filtering, wrapping, and premultiplied alpha for that specific texture.
Creating a Texture from an Existing Source
rapid.texture.create() uploads any supported DOM element synchronously. This is useful for procedurally generated canvases, <img> elements already present in the DOM, or <video> frames.
HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageBitmap, and OffscreenCanvas.
Providing a
key in ITextureOptions causes create() to register the texture in the shared cache under that key. A subsequent call to rapid.texture.create(...) with the same key returns the cached BaseTexture without re-uploading.ITextureOptions Reference
Per-texture sampling filter.
TextureFilterMode.NEAREST preserves crisp pixel edges; TextureFilterMode.LINEAR blurs between texels. Overrides the renderer-level default set in IAppOptions.Controls how UV coordinates outside the
[0, 1] range are handled. See Wrap Modes below.Whether to upload this texture with premultiplied alpha. Defaults to the value set on the
Rapid instance. Override per-texture only when mixing assets with different alpha conventions.A custom cache key. When provided,
create() checks the cache first and stores the result for reuse. Has no effect on load(), which always uses the URL as the key.Texture Wrap Modes
TextureWrapMode is an enum with three values that control texture tiling behaviour.
| Value | WebGL equivalent | Behaviour |
|---|---|---|
TextureWrapMode.CLAMP | CLAMP_TO_EDGE | UV coordinates are clamped to [0, 1]. Pixels at the border stretch to the edge — no tiling. |
TextureWrapMode.REPEAT | REPEAT | UV coordinates wrap, producing seamless tiling. |
TextureWrapMode.MIRRORED_REPEAT | MIRRORED_REPEAT | Like REPEAT, but alternating tiles are mirrored. |
Texture Properties
Once you have aTexture, you can read these properties:
| Property | Type | Description |
|---|---|---|
width | number | Logical display width in pixels. Accounts for isRotated and scale. |
height | number | Logical display height in pixels. Accounts for isRotated and scale. |
rawWidth | number | The actual pixel width of the texture region, before any scale. |
rawHeight | number | The actual pixel height of the texture region, before any scale. |
offsetX | number | Horizontal draw offset applied automatically when the texture is drawn. |
offsetY | number | Vertical draw offset applied automatically when the texture is drawn. |
uvX | number | Left edge of the UV region within the base GPU texture (0–1). |
uvY | number | Top edge of the UV region within the base GPU texture (0–1). |
uvW | number | Right edge of the UV region within the base GPU texture (0–1). |
uvH | number | Bottom edge of the UV region within the base GPU texture (0–1). |
flipY | boolean | Whether the texture is flipped vertically. true for RenderTexture and TextTexture. |
isRotated | boolean | Set by atlas packers when a sprite has been rotated 90° to save space. |
Sprite Sheet Splitting
A common workflow is loading a single sprite sheet image and then splitting it into individual frame textures. Rapid provides two methods onTexture for this.
splitGrid(cellWidth, cellHeight)
Divides the texture into a uniform grid of cellWidth × cellHeight tiles and returns them as an array ordered left-to-right, top-to-bottom.
getSubTexture(x, y, width, height)
Extracts a single rectangular region from the texture at a specified pixel offset. Coordinates are relative to the top-left of the parent texture’s current region.
Destroying Textures
Rapid uses reference counting onBaseTexture. Each Texture view that wraps a BaseTexture increments its refCount; calling destroy() decrements it. The GPU resource is only freed when refCount reaches zero.
RenderTexture instances are not stored in the URL cache and must be destroyed manually by calling rapid.texture.destroy(rt, true) or rt.destroy() when no longer needed.Render Textures
RenderTexture is a Texture subclass backed by a WebGL framebuffer. Use it to render the scene (or part of it) into an off-screen buffer that can then be drawn as a normal sprite.
Text Textures
TextTexture renders text via an internal HTML <canvas> and uploads the result as a GPU texture. Update the text content or style at any time — the texture re-uploads automatically.