---
url: https://cri-middleware.github.io/SSPlayerForWeb/api/@spritestudio/ssplayer-webgl/classes/SSWebGLTextureCache.md
---
# Class: SSWebGLTextureCache

Defined in: [ssplayer-webgl/src/SSWebGLTextureCache.ts:31](https://github.com/cri-middleware/SSPlayerForWeb/blob/eb9d544908210befb40d3729ed6fde7adc44f61a/packages/ssplayer-webgl/src/SSWebGLTextureCache.ts#L31)

Surface-scoped texture cache: one GPU upload per URL, shared by every player
on the same [SSSurface](SSSurface.md).

A `WebGLTexture` belongs to the context that created it, so the cache is
per-context — exactly the scope a Surface owns. Two characters using the same
atlas on one surface then cost one upload instead of two, which for a cast of
the same character is most of the texture memory they would otherwise take.

**Keyed by URL, deliberately not by cell-map hash.** The hash the core passes
around comes from the cell-map *name*, so two unrelated `.ssab` files that both
contain a cell map of that name collide on it — and sharing on that key would
hand one character another character's atlas. That is not hypothetical at
surface scope: `ssplayer-tyranoscript` puts unrelated characters on one
surface, and an overlay puts unrelated *projects* on one. The URL is the real
identity, and the core builds it from the owning `.ssab`'s own directory.

Nothing is refcounted. Cached textures live until the Surface is destroyed, so
one player tearing down can never pull a texture out from under another — the
trap `ssplayer-pixi` hit by calling `Assets.unload()` from `destroy()`.
Embedded (`--embedded`) and caller-supplied textures never reach the cache;
they stay private to their player.

## Constructors

### Constructor

> **new SSWebGLTextureCache**(`gl`): `SSWebGLTextureCache`

Defined in: [ssplayer-webgl/src/SSWebGLTextureCache.ts:37](https://github.com/cri-middleware/SSPlayerForWeb/blob/eb9d544908210befb40d3729ed6fde7adc44f61a/packages/ssplayer-webgl/src/SSWebGLTextureCache.ts#L37)

#### Parameters

##### gl

`WebGLRenderingContext` | `WebGL2RenderingContext`

#### Returns

`SSWebGLTextureCache`

## Methods

### acquire()

> **acquire**(`url`, `upload`): `Promise`<[`SSTextureEntry`](../interfaces/SSTextureEntry.md)>

Defined in: [ssplayer-webgl/src/SSWebGLTextureCache.ts:40](https://github.com/cri-middleware/SSPlayerForWeb/blob/eb9d544908210befb40d3729ed6fde7adc44f61a/packages/ssplayer-webgl/src/SSWebGLTextureCache.ts#L40)

Upload `url` once via `upload`, and reuse it for every later request.

#### Parameters

##### url

`string`

##### upload

(`url`) => `Promise`<[`SSTextureEntry`](../interfaces/SSTextureEntry.md)>

#### Returns

`Promise`<[`SSTextureEntry`](../interfaces/SSTextureEntry.md)>

***

### destroy()

> **destroy**(): `void`

Defined in: [ssplayer-webgl/src/SSWebGLTextureCache.ts:75](https://github.com/cri-middleware/SSPlayerForWeb/blob/eb9d544908210befb40d3729ed6fde7adc44f61a/packages/ssplayer-webgl/src/SSWebGLTextureCache.ts#L75)

Delete every cached texture. Only the owning Surface may call this.

#### Returns

`void`

***

### invalidate()

> **invalidate**(): `void`

Defined in: [ssplayer-webgl/src/SSWebGLTextureCache.ts:69](https://github.com/cri-middleware/SSPlayerForWeb/blob/eb9d544908210befb40d3729ed6fde7adc44f61a/packages/ssplayer-webgl/src/SSWebGLTextureCache.ts#L69)

Forget everything after a context loss. The handles died with the context so
there is nothing to delete — players re-acquire during their own restore, and
whichever asks first re-uploads on behalf of the rest.

#### Returns

`void`
