class StaticTextureAtlasLayout

Organizes a set of textures into a single larger texture (an atlas) by minimizing empty space.

Does not allow modifications after initial construction.

Public

Constructors

StaticTextureAtlasLayout

StaticTextureAtlasLayout() = default

StaticTextureAtlasLayout

StaticTextureAtlasLayout(u32 width, u32 height, u32 maxWidth, u32 maxHeight, bool pow2 = false)

Constructs a new texture atlas layout with the provided parameters.

width
Initial width of the atlas texture.
height
Initial height of the atlas texture.
maxWidth
Maximum width the atlas texture is allowed to grow to, when elements don't fit.
maxHeight
Maximum height the atlas texture is allowed to grow to, when elements don't fit.
pow2
When true the resulting atlas size will always be a power of two.

Methods

AddElement

bool AddElement(u32 width, u32 height, u32 &outX, u32 &outY)

Attempts to add a new element in the layout.

Elements should be added to the atlas from largest to smallest, otherwise a non-optimal layout is likely to be generated.

width
Width of the new element, in pixels.
height
Height of the new element, in pixels.
outX
Horizontal position of the new element within the atlas. Only valid if method returns true.
outY
Vertical position of the new element within the atlas. Only valid if method returns true.

Returns: True if the element was added to the atlas, false if the element doesn't fit.

Clear

void Clear()

Removes all entries from the layout.

IsEmpty

bool IsEmpty() const

Checks have any elements been added to the layout.

GetWidth

u32 GetWidth() const

Returns the width of the atlas texture, in pixels.

GetHeight

u32 GetHeight() const

Returns the height of the atlas texture, in pixels.

Private

Methods

AddToNode

bool AddToNode(u32 nodeIndex, u32 width, u32 height, u32 &outX, u32 &outY, bool allowGrowth)

Fields

mInitialWidth

u32 mInitialWidth

mInitialHeight

u32 mInitialHeight

mWidth

u32 mWidth

mHeight

u32 mHeight

mPow2

bool mPow2

mNodes

Vector<TexAtlasNode> mNodes