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

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

One player's textures, keyed by the cell-map hash the core asks for.

URL-loaded atlases are delegated to the surface's [SSWebGLTextureCache](SSWebGLTextureCache.md)
when there is one, so several players showing the same character upload it
once. This manager still keeps its own hash → texture mapping, because the
hash is only unique within one `.ssab` while the cache is shared across all of
them (see the note on keying there).

Embedded (`--embedded`) and caller-supplied textures are never shared: they
came from *this* player's bytes, and two `.ssab` files can carry the same
cell-map name with completely different pixels.

## Implements

* [`IResourceManager`](../interfaces/IResourceManager.md)

## Constructors

### Constructor

> **new SSWebGLResourceManager**(`gl`, `shared?`): `SSWebGLResourceManager`

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

#### Parameters

##### gl

`WebGLRenderingContext` | `WebGL2RenderingContext`

##### shared?

[`SSWebGLTextureCache`](SSWebGLTextureCache.md)

#### Returns

`SSWebGLResourceManager`

## Methods

### bindTextureSource()

> **bindTextureSource**(`source`, `hash`, `width`, `height`): `void`

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

#### Parameters

##### source

`TexImageSource`

##### hash

`number`

##### width

`number`

##### height

`number`

#### Returns

`void`

***

### clearOverrideTexture()

> **clearOverrideTexture**(`hash`): `void`

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

Drop the override for `hash`, restoring the originally loaded texture.

#### Parameters

##### hash

`number`

#### Returns

`void`

#### Implementation of

[`IResourceManager`](../interfaces/IResourceManager.md).[`clearOverrideTexture`](../interfaces/IResourceManager.md#clearoverridetexture)

***

### destroy()

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

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

Delete the textures this player uploaded itself. Shared ones are left alone —
a sibling player is probably still drawing with them, and the surface deletes
the cache when it goes.

#### Returns

`void`

#### Implementation of

[`IResourceManager`](../interfaces/IResourceManager.md).[`destroy`](../interfaces/IResourceManager.md#destroy)

***

### getOverrideTexture()

> **getOverrideTexture**(`hash`): [`SSTextureEntry`](../interfaces/SSTextureEntry.md) | `undefined`

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

The current override for `hash` (never the original), or undefined.

#### Parameters

##### hash

`number`

#### Returns

[`SSTextureEntry`](../interfaces/SSTextureEntry.md) | `undefined`

#### Implementation of

[`IResourceManager`](../interfaces/IResourceManager.md).[`getOverrideTexture`](../interfaces/IResourceManager.md#getoverridetexture)

***

### getTexture()

> **getTexture**(`hash`): [`SSTextureEntry`](../interfaces/SSTextureEntry.md) | `undefined`

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

Gets a loaded texture by its hash.

#### Parameters

##### hash

`number`

The hash of the texture.

#### Returns

[`SSTextureEntry`](../interfaces/SSTextureEntry.md) | `undefined`

The engine-specific texture object (e.g. PIXI.Texture).

#### Implementation of

[`IResourceManager`](../interfaces/IResourceManager.md).[`getTexture`](../interfaces/IResourceManager.md#gettexture)

***

### loadTexture()

> **loadTexture**(`url`, `hash`): `Promise`<`void`>

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

Loads a texture from the given URL and associates it with the given hash.

#### Parameters

##### url

`string`

The URL of the texture to load.

##### hash

`number`

The cell-map name hash — a slot in one `.ssab`, not an image.

#### Returns

`Promise`<`void`>

#### Implementation of

[`IResourceManager`](../interfaces/IResourceManager.md).[`loadTexture`](../interfaces/IResourceManager.md#loadtexture)

***

### loadTextureFromBytes()

> **loadTextureFromBytes**(`bytes`, `hash`): `Promise`<`void`>

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

Decode raw (encoded) image bytes — e.g. a PNG embedded in the SSAB via the
converter's `--embedded` mode — and upload them as a texture under `hash`.

Never shared: these bytes belong to one `.ssab`, and a cell-map name is not
unique across files.

#### Parameters

##### bytes

`Uint8Array`

##### hash

`number`

#### Returns

`Promise`<`void`>

#### Implementation of

[`IResourceManager`](../interfaces/IResourceManager.md).[`loadTextureFromBytes`](../interfaces/IResourceManager.md#loadtexturefrombytes)

***

### reset()

> **reset**(): `void`

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

Optional: forget every texture bound for the previously bound pack, so the
next one loads its own from scratch. Called by the core from
`bindResource`; a manager that caches by hash must implement it. Must also
drop any runtime texture overrides — they belong to the previous pack's
hashes.

#### Returns

`void`

#### Implementation of

[`IResourceManager`](../interfaces/IResourceManager.md).[`reset`](../interfaces/IResourceManager.md#reset)

***

### restoreContext()

> **restoreContext**(): `Promise`<`void`>

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

Rebuild every texture after a GL context loss. The old WebGLTexture handles
died with the context, so drop them and re-create from the retained creation
info. URL / bytes sources re-decode asynchronously; caller-owned
TexImageSources re-upload synchronously (skipped if the caller let the source
go — e.g. a closed ImageBitmap — so one dead source can't abort the whole
restore).

The surface invalidates the shared cache before calling this, so the first
player to ask for a URL re-uploads it and the rest reuse that.

#### Returns

`Promise`<`void`>

***

### setOverrideTexture()

> **setOverrideTexture**(`hash`, `entry`): `void`

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

Runtime texture replacement: bind a ready [SSTextureEntry](../interfaces/SSTextureEntry.md) for `hash`,
shadowing the originally loaded texture. The entry's `WebGLTexture` is
caller-owned — this manager never deletes it. For the common case of
replacing from an image/canvas/video, prefer [setOverrideTextureFromSource](#setoverridetexturefromsource),
which uploads (and owns) the GL texture for you.

The entry's `width`/`height` are what the renderer normalizes UVs by, so a
replacement of a different size than the original samples a shifted region —
pass a same-size, same-layout atlas.

#### Parameters

##### hash

`number`

##### entry

[`SSTextureEntry`](../interfaces/SSTextureEntry.md)

#### Returns

`void`

#### Implementation of

[`IResourceManager`](../interfaces/IResourceManager.md).[`setOverrideTexture`](../interfaces/IResourceManager.md#setoverridetexture)

***

### setOverrideTextureFromSource()

> **setOverrideTextureFromSource**(`hash`, `source`, `width`, `height`): `void`

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

Runtime texture replacement from a raw image source (an `ImageBitmap`,
`HTMLImageElement`, `HTMLCanvasElement`, `HTMLVideoElement`, …). Uploads it
with the same premultiplied-alpha path as the initial textures and binds it
for `hash`. The uploaded GL texture is owned by this manager and freed on
[clearOverrideTexture](#clearoverridetexture), replacement, or reset/destroy.

#### Parameters

##### hash

`number`

##### source

`TexImageSource`

##### width

`number`

##### height

`number`

#### Returns

`void`
