@mocanvas/editor · class
declare class TextureManagerOwns the host's GPU textures: allocates ids, refcounts them by key, loads
their pixels asynchronously and uploads them through the current
RenderBackend.
acquire hands back the id straight away so a shape can be written to the
engine in the same tick; the texture only appears once the load resolves, so
callers keep a DOM fallback until isReady(key). A key whose load rejected
resolves to 0 (no texture — the shape falls back to its plain fill).
Callers that re-derive their textures on every write (a ShapeUtil in
getRenderStyle) should acquire inside withOwner, which reconciles the
keys an owner holds instead of piling up references.
Methods · 15
acquire(key: string, load: TextureLoader, opts?: TextureOptions): numberReference the texture for key, starting load the first time. Returns
the host texture id, or 0 when the key previously failed to load.
constructor(options?: TextureManagerOptions)dispose(): voidgetAllOwners(): readonly string[]Every owner holding at least one texture.
getBackend(): RenderBackend | nullgetId(key: string): numberCurrent id for key: 0 when unknown or failed.
getInfo(key: string): TextureInfo | undefinedgetOwners(key: string): readonly string[]Owners (shape ids) currently holding key.
getState(key: string): TextureState | undefinedisReady(key: string): booleanWhether the texture for key is uploaded and safe to draw.
release(key: string): voidDrop one reference. The texture is deleted when the last one goes.
releaseOwner(owner: string): voidRelease every key an owner holds (the shape was deleted).
setBackend(backend: RenderBackend | null): voidPoint the manager at the backend that owns the GPU textures. Everything already decoded is uploaded again; anything still loading uploads when it resolves. The previous backend keeps (and frees) its own GL objects.
get size(): numberNumber of live texture entries.
withOwner<T>(owner: string, fn: () => T): TRun fn with every acquire inside it attributed to owner. Keys the
owner held before but did not acquire again are released, so re-deriving a
shape's style neither leaks references nor keeps a stale texture alive.
Mentioned here
mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.