Skip to main content

Class: TextureLoader

texture/loader.TextureLoader

Handles loading and unloading of textures on the GPU as needed.

Constructors

constructor

โ€ข new TextureLoader()

Properties

gl

โ–ช Static Private gl: WebGL2RenderingContext

Defined in

src/texture/loader.ts:12


loaded

โ–ช Static Private loaded: Map<Texture, number>

Defined in

src/texture/loader.ts:13


ready

โ–ช Static Private ready: boolean = false

Defined in

src/texture/loader.ts:10


textureUnits

โ–ช Static Private textureUnits: TextureUnit[] = []

Defined in

src/texture/loader.ts:14

Methods

checkReady

โ–ธ Static Private checkReady(): void

Checks if the loader is ready to be used for texture loading/unloading.

throws When TextureLoader.init has not yet been called

Returns

void

Defined in

src/texture/loader.ts:42


findReplaceableTextureUnit

โ–ธ Static findReplaceableTextureUnit(): TextureUnit

Finds the best texture unit to replace.

First looks for free texture units and if none are available then it will return the texture unit with the oldest last used time.

Texture units that have a TextureAtlas in them will be ignored.

Returns

TextureUnit

The most replaceable texture unit

Defined in

src/texture/loader.ts:154


getFreeTextureUnit

โ–ธ Static getFreeTextureUnit(): TextureUnit

Finds a free texture unit.

Returns

TextureUnit

A free texture unit or undefined when no units are free

Defined in

src/texture/loader.ts:137


getUnitOfTexture

โ–ธ Static getUnitOfTexture(texture): TextureUnit

Finds the texture unit the given texture is loaded in.

Parameters

NameTypeDescription
textureTextureThe texture to find

Returns

TextureUnit

The unit the texture is loaded in or undefined

Defined in

src/texture/loader.ts:122


init

โ–ธ Static init(gl): void

Sets up the texture loader for use, should only be called once.

Parameters

NameTypeDescription
glWebGL2RenderingContextThe WebGL context to use for texture loading

Returns

void

Defined in

src/texture/loader.ts:21


isLoaded

โ–ธ Static isLoaded(texture): boolean

Checks if a texture is loaded, ie the texture's image is loaded in a texture unit on the GPU.

Parameters

NameTypeDescription
textureTextureThe texture to check

Returns

boolean

Wether or not the texture is loaded

Defined in

src/texture/loader.ts:111


loadTexture

โ–ธ Static loadTexture(texture): boolean

Loads a texture into any available texture unit on the GPU, if no unit is available then the unit with the longest time since it was last used is overwritten.

Parameters

NameTypeDescription
textureTextureThe texture to load

Returns

boolean

Wether or not the texture was loaded

Defined in

src/texture/loader.ts:53


reloadTexture

โ–ธ Static reloadTexture(texture): boolean

Unloads and then reloads the provided texture.

Parameters

NameTypeDescription
textureTextureThe texture to reload

Returns

boolean

Wether or not the texture was reloaded

Defined in

src/texture/loader.ts:100


unloadTexture

โ–ธ Static unloadTexture(texture, unit?): boolean

Unloads the texture from the GPU.

Parameters

NameTypeDescription
textureTextureThe texture to unload
unit?TextureUnitThe texture unit the texture belongs to, improves performance as the unit does not need to be searched for.

Returns

boolean

Wether or not the texture was unloaded

Defined in

src/texture/loader.ts:79


updateLastUsed

โ–ธ Static updateLastUsed(unit): boolean

Finds a TextureUnit by its WebGL texture unit number and updates its lastUsed time to the current time from performance.now()

Parameters

NameTypeDescription
unitnumberThe WebGL texture unit number

Returns

boolean

Wether or not the TextureUnit was updated

Defined in

src/texture/loader.ts:176