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) → {}
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 |
The height of texture slabs. |
number |
The width of texture slabs. |
TextureSlab[] |
The list of base-textures that are used to allocate texture space. |
Methods from TextureAllocator
T |
Allocates a texture from this allocator. |
void |
|
TextureSlab |
|
T |
Creates a texture on the given base-texture at |
T |
Issues a texture from the given texture slab, if possible. |
Public Properties
Protected Properties
protected textureSlabs: TextureSlab[]
The list of base-textures that are used to allocate texture space.
Public Methods
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.
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. |
Type | Description |
---|---|
T |
The allocated texture, if successful; otherwise, |
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.
Name | Type | Description |
---|---|---|
texture | T |
Type | Description |
---|---|
void |
Protected Methods
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.
Type | Description |
---|---|
TextureSlab |
protected createTexture(baseTexture: PIXI.BaseTexture, frame: PIXI.Rectangle) → {T}
Creates a texture on the given base-texture at frame
.
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. |
Type | Description |
---|---|
T |
protected issueTexture(slab: TextureSlab, width: number, height: number, padding: number) → {T}
Issues a texture from the given texture slab, if possible.
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. |
Type | Description |
---|---|
T |
The issued texture, if successful; otherwise, |