Skip to content

@blooper.gg/toodle


@blooper.gg/toodle / textures/AssetManager / AssetManager

Class: AssetManager

Defined in: textures/AssetManager.ts:31

Constructors

Constructor

new AssetManager(device, presentationFormat, limits): AssetManager

Defined in: textures/AssetManager.ts:43

Parameters

device

GPUDevice

presentationFormat

GPUTextureFormat

limits
instanceBufferFields

number = ...

Maximum number of instance buffer fields - 16 minus the vertex locations used by the engine

instanceBufferSize

number = ...

Maximum size of instance buffer

instanceCount

number = ...

Maximum number of rendered instances in the scene per frame

maxTextLength

number = 256

Maximum length of a single piece of text

shaderCount

number = 32

Maximum number of vfx shaders

textureArrayLayers

number = 64

Maximum number of layers in a texture array

textureSize

number = ...

Maximum dimensions of a single texture

uniformBufferSize

number = ...

Maximum size of uniforms buffer

zIndex

number = 32

Maximum number of unique z-indexes in the scene

Returns

AssetManager

Properties

extra

extra: object

Defined in: textures/AssetManager.ts:499

Advanced and niche features

getAtlasCoords()

getAtlasCoords: (id) => AtlasCoords[]

Get the atlas coordinates for a texture.

Parameters
id

string

The id of the texture to get the atlas coordinates for

Returns

AtlasCoords[]

An array of the atlas coordinates for the texture

getAtlasUsage()

getAtlasUsage: () => object

Get diagnostics on texture atlas usage

Returns

Usage stats for texture atlases

available

available: number

The number of texture atlases that are currently unused and available to load textures into.

total

total: number

The total number of texture atlases that can be loaded.

used

used: number

The number of texture atlases that are currently in use.

getLoadedBundleIds()

getLoadedBundleIds: () => string[]

Returns

string[]

getRegisteredBundleIds()

getRegisteredBundleIds: () => string[]

Returns

string[]

getTextureOffset()

getTextureOffset: (id) => Vec2

Get the texture default offset

Parameters
id

string

The id of the texture to get the atlas coordinates for

Returns

Vec2

Point of the texture's associated X,Y offset

loadAtlas()

loadAtlas: (atlas) => Promise<number>

Load a texture atlas from a CpuTextureAtlas.

Parameters
atlas

CpuTextureAtlas

The texture atlas to load

Returns

Promise<number>

The index of the atlas

nextAvailableAtlasIndex()

nextAvailableAtlasIndex: () => number

Consume the next available atlas index.

Returns

number

setAtlasCoords()

setAtlasCoords: (id, coords) => void

Set the atlas coordinates for a texture.

This should not be necessary for most use cases. This allows for UV precision

Parameters
id

string

The id of the texture to set the atlas coordinates for

coords

AtlasCoords

The atlas coordinates to set

Returns

void

unloadAtlas()

unloadAtlas: (atlasIndex) => Promise<void>

Unload an atlas from the texture atlas.

Parameters
atlasIndex

number

The index of the atlas to unload

Returns

Promise<void>


textureAtlas

readonly textureAtlas: GPUTexture

Defined in: textures/AssetManager.ts:32

Accessors

textureIds

Get Signature

get textureIds(): string[]

Defined in: textures/AssetManager.ts:128

A read-only array of all currently loaded texture ids.

Returns

string[]


textures

Get Signature

get textures(): Map<string, AtlasCoords[]>

Defined in: textures/AssetManager.ts:121

A read-only map of all currently loaded textures.

Returns

Map<string, AtlasCoords[]>

Methods

destroy()

destroy(): void

Defined in: textures/AssetManager.ts:684

Destroy the texture atlas. This should free up ~4gb of gpu memory (and make all draw calls fail)

Returns

void


getCroppedSize()

getCroppedSize(id): Size

Defined in: textures/AssetManager.ts:91

Dimensions of a loaded texture, cropped to a minimal bounding box.

Parameters

id

string

The id of the texture to get the size of

Returns

Size

The size of the texture


getFont()

getFont(id): TextShader

Defined in: textures/AssetManager.ts:310

Parameters

id

string

Returns

TextShader


getSize()

getSize(id): Size

Defined in: textures/AssetManager.ts:76

True dimensions of a loaded texture, prior to any transparent pixel cropping.

Parameters

id

string

The id of the texture to get the size of

Returns

Size

The size of the texture


isCropped()

isCropped(id): boolean

Defined in: textures/AssetManager.ts:108

Whether the texture has been cropped for extra transparency.

Parameters

id

string

The id of the texture to be checked

Returns

boolean

Whether the image has been cropped (i.e. if it has uvScaledCropped)


loadBundle()

loadBundle(bundleId): Promise<void>

Defined in: textures/AssetManager.ts:236

Load a bundle of textures to the gpu

See: https://toodle.gg/f849595b3ed13fc956fc1459a5cb5f0228f9d259/examples/texture-bundles.html

Parameters

bundleId

string

Returns

Promise<void>


loadFont()

loadFont(id, url, fallbackCharacter): Promise<string>

Defined in: textures/AssetManager.ts:289

Load a font to the gpu

Parameters

id

string

The id of the font to load

url

URL

The url of the font to load

fallbackCharacter

string = "_"

The character to use as a fallback if the font does not contain a character to be rendererd

Returns

Promise<string>


loadTexture()

loadTexture(id, url, options?): Promise<{ coords: AtlasCoords; id: string; }>

Defined in: textures/AssetManager.ts:163

Debug method to load a single texture.

Parameters

id

string

ID used to name the texture

url

URL or ImageBitmap target for the image

ImageBitmap | URL

options?

Partial<TextureBundleOpts>

LoadingOptions used to modify the loading process

Note: this will consume one texture atlas per texture. For more efficient loading of multiple textures, consider loadBundle

Returns

Promise<{ coords: AtlasCoords; id: string; }>


loadTextures()

loadTextures(opts): Promise<void>

Defined in: textures/AssetManager.ts:147

Debug method to load a set of textures from a record of URLS.

Parameters

opts

Record<string, URL>

Returns

Promise<void>

Example

ts
await toodle.assets.loadTextures({
  "myImage": new URL("assets/image.png", "https://mywebsite.com"),
});

registerBundle()

registerBundle(bundleId, opts): Promise<string>

Defined in: textures/AssetManager.ts:215

Register a bundle of textures.

Parameters

bundleId

string

ID used to name the bundle

opts

TextureBundleOpts | AtlasBundleOpts

Returns

Promise<string>


unloadBundle()

unloadBundle(bundleId): Promise<void>

Defined in: textures/AssetManager.ts:261

Unload a bundle of textures from the gpu - this marks the gpu-side texture atlas as available for future texture loading.

Parameters

bundleId

string

The id of the bundle to unload

Returns

Promise<void>


validateTextureReference()

validateTextureReference(node): void

Defined in: textures/AssetManager.ts:319

Parameters

node

SceneNode | QuadNode

Returns

void