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.
Texture is a lightweight view over a BaseTexture. Multiple Texture objects can reference the same GPU resource simultaneously, each describing a different rectangular UV region within it. This makes Texture the natural building block for sprite sheets, atlases, and any use-case where you want to pack many images onto a single GPU upload.
Texture instances track their BaseTexture through reference counting.
Always call destroy() when you are done with a texture you own so the GPU
memory can be reclaimed when no other views remain.Public Properties
The underlying GPU resource shared by this view.
undefined after
destroy() has been called.Left edge of the UV clipping region, in the
[0, 1] range.Top edge of the UV clipping region, in the
[0, 1] range.Right edge of the UV clipping region (i.e.
uvX + uvWidth), in the [0, 1]
range.Bottom edge of the UV clipping region (i.e.
uvY + uvHeight), in the
[0, 1] range.Width of the region in source pixels, before
scale is applied.Height of the region in source pixels, before
scale is applied.Read-only computed display width. Equals
rawWidth × scale normally, or
rawHeight × scale when isRotated is true (the axes are swapped for
rotated atlas packing).Read-only computed display height. Equals
rawHeight × scale normally, or
rawWidth × scale when isRotated is true.Draw offset applied along the X axis at render time. Used by
TextTexture to
implement text alignment without moving the draw position.Draw offset applied along the Y axis at render time. Used by
TextTexture to
implement baseline alignment.Display scale factor applied to
rawWidth/rawHeight when computing width
and height. Defaults to 1. TextTexture sets this to 1 / dpr so that
the high-DPR canvas pixels render at logical size.When
true, the texture is rendered vertically flipped. RenderTexture and
TextTexture both set this to true to compensate for WebGL’s bottom-left
origin and canvas coordinate differences.When
true, the UV region is stored 90° rotated in the atlas. The width
and height getters swap rawWidth/rawHeight accordingly so that sprite
dimensions remain correct.true if this Texture represents a sub-region of a larger BaseTexture
(i.e. the region does not cover the full GPU texture). Set automatically by
setRegion().Direct reference to the underlying WebGL texture handle, mirrored from
base.glTexture for quick access by the renderer. null after destroy()
or before a BaseTexture has been assigned.Methods
setBase(base)
Assigns a new BaseTexture to this view, incrementing the new texture’s
refCount and decrementing the previous one’s. Also resets the UV region to
cover the full new texture.
The new underlying GPU resource to attach.
this — for method chaining.
setRegion(x, y, w, h)
Defines the visible rectangular clip region within the BaseTexture, expressed
in source pixels. UV coordinates are computed automatically.
Left edge of the region in pixels, relative to the
BaseTexture origin.Top edge of the region in pixels, relative to the
BaseTexture origin.Width of the region in pixels.
Height of the region in pixels.
this — for method chaining.
getSubTexture(x, y, width, height)
Returns a new Texture that describes a rectangle relative to this texture’s
current region. The coordinates are local to the current view, not to the
underlying BaseTexture.
X offset in pixels, relative to this texture’s top-left corner.
Y offset in pixels, relative to this texture’s top-left corner.
Width of the sub-region in pixels.
Height of the sub-region in pixels.
Texture
splitGrid(cellWidth, cellHeight, cols?, rows?)
Splits this texture into a uniform grid of equally-sized cells and returns them
as a flat array in row-major order (left-to-right, top-to-bottom). Great for
slicing sprite sheets and tile sets.
Width of each cell in pixels.
Height of each cell in pixels.
Number of columns to extract. Defaults to
Math.floor(rawWidth / cellWidth).Number of rows to extract. Defaults to
Math.floor(rawHeight / cellHeight).Texture[]
clone(target?)
Creates a shallow copy of this Texture. The copy shares the same BaseTexture
(incrementing its refCount) and inherits all UV, scale, offset, and flag
properties. Useful for producing per-instance copies that can have their region
mutated independently.
Optional existing
Texture to copy into. If omitted, a new instance is
allocated.Texture
destroy()
Decrements the BaseTexture reference count and clears the internal reference.
The GPU resource is not deleted here — that happens inside TextureManager (or
BaseTexture.destroy()) once the refCount reaches zero.
void
static fromImageSource(render, source, options?)
Creates a Texture (and an implicit BaseTexture) directly from a browser
media source, bypassing TextureManager entirely. Use this when you need a
one-off texture and do not want it cached.
The active
Rapid renderer instance.The pixel source (
HTMLImageElement, HTMLCanvasElement, HTMLVideoElement,
ImageBitmap, or OffscreenCanvas).Optional texture configuration (filter mode, wrap mode, premultiplied alpha).
Texture
BaseTexture
BaseTexture owns the actual WebGL texture object and implements reference
counting. You rarely need to interact with it directly, but the API is available
for advanced use-cases such as dynamically updating video frame textures.
Properties
The raw WebGL texture handle.
null after destroy().Width of the GPU-allocated texture in pixels.
Height of the GPU-allocated texture in pixels.
Optional identifier string.
TextureManager sets this to the load URL so it
can evict the entry from its cache on destruction.Number of
Texture views currently referencing this BaseTexture. The GPU
resource should only be freed when this reaches zero.static fromSource(render, source, options?)
Uploads a browser media element to the GPU and returns a new BaseTexture.
Returns: BaseTexture
updateSource(gl, source, options?)
Re-uploads pixel data from source into the existing GPU texture. When the
source dimensions match the current allocation, uses texSubImage2D for a
cheaper update path; otherwise re-allocates with texImage2D and updates
width/height.
Handy for live-updating a video texture every frame:
setFilterMode(gl, filterMode)
Changes the texture’s minification/magnification filter at any time after
creation.
setWrapMode(gl, wrapMode)
Changes the texture’s UV wrap mode at any time after creation.
destroy(gl)
Calls gl.deleteTexture() and nulls the internal handle. Should only be called
when refCount is zero.