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
The most replaceable texture unit
Defined in
src/texture/loader.ts:154
getFreeTextureUnit
โธ Static
getFreeTextureUnit(): TextureUnit
Finds a free texture unit.
Returns
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
Name | Type | Description |
---|---|---|
texture | Texture | The texture to find |
Returns
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
Name | Type | Description |
---|---|---|
gl | WebGL2RenderingContext | The 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
Name | Type | Description |
---|---|---|
texture | Texture | The 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
Name | Type | Description |
---|---|---|
texture | Texture | The 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
Name | Type | Description |
---|---|---|
texture | Texture | The 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
Name | Type | Description |
---|---|---|
texture | Texture | The texture to unload |
unit? | TextureUnit | The 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
Name | Type | Description |
---|---|---|
unit | number | The WebGL texture unit number |
Returns
boolean
Wether or not the TextureUnit was updated
Defined in
src/texture/loader.ts:176