CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::TextureAtlasLayout Class Reference

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

#include <CeresEngine/Texture/TextureAtlasLayout.hpp>

Classes

struct  Node
 Represent a single node in the texture atlas binary tree. More...
 

Public Member Functions

 TextureAtlasLayout ()=default
 
 TextureAtlasLayout (const UInt32 width, const UInt32 height)
 Constructs a new texture atlas layout with the provided parameters.
 
 TextureAtlasLayout (const UInt32 width, const UInt32 height, const UInt32 maxWidth, const UInt32 maxHeight, const bool pow2=false)
 Constructs a new texture atlas layout with the provided parameters.
 
bool addElement (UInt32 width, UInt32 height, UInt32 &x, UInt32 &y)
 Attempts to add a new element in the layout.
 
void clear ()
 Removes all entries from the layout.
 
bool isEmpty () const
 Checks have any elements been added to the layout.
 
UInt32 getWidth () const
 Returns the width of the atlas texture, in pixels.
 
UInt32 getHeight () const
 Returns the height of the atlas texture, in pixels.
 

Private Member Functions

bool addToNode (UInt32 nodeIdx, UInt32 width, UInt32 height, UInt32 &x, UInt32 &y, bool allowGrowth)
 Attempts to add a new element to the specified layout node.
 

Private Attributes

UInt32 mInitialWidth = 0
 
UInt32 mInitialHeight = 0
 
UInt32 mWidth = 0
 
UInt32 mHeight = 0
 
bool mPow2 = false
 
Vector< NodemNodes
 

Detailed Description

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

Constructor & Destructor Documentation

◆ TextureAtlasLayout() [1/3]

CeresEngine::TextureAtlasLayout::TextureAtlasLayout ( )
default

◆ TextureAtlasLayout() [2/3]

CeresEngine::TextureAtlasLayout::TextureAtlasLayout ( const UInt32  width,
const UInt32  height 
)
inline

Constructs a new texture atlas layout with the provided parameters.

Parameters
widthInitial width of the atlas texture.
heightInitial height of the atlas texture.

◆ TextureAtlasLayout() [3/3]

CeresEngine::TextureAtlasLayout::TextureAtlasLayout ( const UInt32  width,
const UInt32  height,
const UInt32  maxWidth,
const UInt32  maxHeight,
const bool  pow2 = false 
)
inline

Constructs a new texture atlas layout with the provided parameters.

Parameters
widthInitial width of the atlas texture.
heightInitial height of the atlas texture.
maxWidthMaximum width the atlas texture is allowed to grow to, when elements don't fit.
maxHeightMaximum height the atlas texture is allowed to grow to, when elements don't fit.
pow2When true the resulting atlas size will always be a power of two.

Member Function Documentation

◆ addElement()

bool CeresEngine::TextureAtlasLayout::addElement ( UInt32  width,
UInt32  height,
UInt32 x,
UInt32 y 
)

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.

Parameters
widthWidth of the new element, in pixels.
heightHeight of the new element, in pixels.
xHorizontal position of the new element within the atlas. Only valid if method returns true.
yVertical 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.

◆ addToNode()

bool CeresEngine::TextureAtlasLayout::addToNode ( UInt32  nodeIdx,
UInt32  width,
UInt32  height,
UInt32 x,
UInt32 y,
bool  allowGrowth 
)
private

Attempts to add a new element to the specified layout node.

Parameters
nodeIdxIndex of the node to which to add the element.
widthWidth of the new element, in pixels.
heightHeight of the new element, in pixels.
xHorizontal position of the new element within the atlas. Only valid if method returns true.
yVertical position of the new element within the atlas. Only valid if method returns true.
allowGrowthWhen true, the width/height of the atlas will be allowed to grow to fit the element.
Returns
true if the element was added to the atlas, false if the element doesn't fit.

◆ clear()

void CeresEngine::TextureAtlasLayout::clear ( )

Removes all entries from the layout.

◆ getHeight()

UInt32 CeresEngine::TextureAtlasLayout::getHeight ( ) const
inline

Returns the height of the atlas texture, in pixels.

◆ getWidth()

UInt32 CeresEngine::TextureAtlasLayout::getWidth ( ) const
inline

Returns the width of the atlas texture, in pixels.

◆ isEmpty()

bool CeresEngine::TextureAtlasLayout::isEmpty ( ) const
inline

Checks have any elements been added to the layout.

Member Data Documentation

◆ mHeight

UInt32 CeresEngine::TextureAtlasLayout::mHeight = 0
private

◆ mInitialHeight

UInt32 CeresEngine::TextureAtlasLayout::mInitialHeight = 0
private

◆ mInitialWidth

UInt32 CeresEngine::TextureAtlasLayout::mInitialWidth = 0
private

◆ mNodes

Vector<Node> CeresEngine::TextureAtlasLayout::mNodes
private

◆ mPow2

bool CeresEngine::TextureAtlasLayout::mPow2 = false
private

◆ mWidth

UInt32 CeresEngine::TextureAtlasLayout::mWidth = 0
private

The documentation for this class was generated from the following file: