TextureAllocator

class TextureAllocator

The texture allocator dynamically manages space on base-texture slabs. It can be used to generate atlases on demand, which improve batching efficiency.

Constructor


new TextureAllocator(slabWidth: number, slabHeight: number) → {}
Parameters:
Name Type Default Description
slabWidth number 2048

The width of base-texture slabs. This should be at most 2048.

slabHeight number 2048

The height of base-texture slabs. This should be at most 2048.

Summary


Properties from TextureAllocator

number
slabHeight

The height of texture slabs.

number
slabWidth

The width of texture slabs.

TextureSlab[]
protected textureSlabs

The list of base-textures that are used to allocate texture space.

Methods from TextureAllocator

T
allocate(width: number, height: number, padding)

Allocates a texture from this allocator.

void
free(texture: T)
TextureSlab
protected createSlab()
T
protected createTexture(baseTexture: PIXI.BaseTexture, frame: PIXI.Rectangle)

Creates a texture on the given base-texture at frame.

T
protected issueTexture(slab: TextureSlab, width: number, height: number, padding: number)

Issues a texture from the given texture slab, if possible.

Public Properties


slabHeight TextureAllocator.ts:22
slabHeight: number

The height of texture slabs.

slabWidth TextureAllocator.ts:17
slabWidth: number

The width of texture slabs.

Protected Properties


textureSlabs TextureAllocator.ts:27
protected textureSlabs: TextureSlab[]

The list of base-textures that are used to allocate texture space.

Public Methods


allocate TextureAllocator.ts:52
allocate(width: number, height: number, padding) → {T}

Allocates a texture from this allocator.

If its existing slab pool has enough space, the texture is issued from one. Otherwise, a new slab is created and the texture is issued from it. However, if the requested dimensions are larger than slabs themselves, then null is always returned.

To upload a texture source, you will have to create an atlas-managing Resource yourself on the base-texture. The AtlasAllocator does this for you, while the CanvasTextureAllocator can be used to draw on a canvas-based atlas.

Parameters:
Name Type Description
width number

The width of the requested texture.

height number

The height of the requested texture.

padding

The padding requested around the texture, to prevent bleeding.

Returns:
Type Description
T

The allocated texture, if successful; otherwise, null.

free TextureAllocator.ts:101
free(texture: T) → {void}

Frees the texture and reclaims its space. It is assumed you will not use it again, and have destroyed any resource uploading its data.

Parameters:
Name Type Description
texture T
Returns:
Type Description
void

Protected Methods


createSlab TextureAllocator.ts:156
protected createSlab() → {TextureSlab}

Creates a texture slab. The slab's base-texture is not backed by any resource. You will have to manage that yourself. See AtlasAllocator or CanvasTextureAllocator for better resource semantics.

Returns:
Type Description
TextureSlab
createTexture TextureAllocator.ts:174
protected createTexture(baseTexture: PIXI.BaseTexture, frame: PIXI.Rectangle) → {T}

Creates a texture on the given base-texture at frame.

Parameters:
Name Type Description
baseTexture PIXI.BaseTexture

The base texture that will hold the texture's space.

frame PIXI.Rectangle

The frame in which the texture will be stored.

Returns:
Type Description
T
issueTexture TextureAllocator.ts:186
protected issueTexture(slab: TextureSlab, width: number, height: number, padding: number) → {T}

Issues a texture from the given texture slab, if possible.

Parameters:
Name Type Default Description
slab TextureSlab

The texture slab to allocate frame.

width number

The width of the requested texture.

height number

The height of the requested texture.

padding number 0

Padding required around the texture.

Returns:
Type Description
T

The issued texture, if successful; otherwise, null.


Powered by webdoc!