Utility/GuillotineImageAtlas: Add max layer size

This commit is contained in:
Jérôme Leclercq
2022-02-23 23:48:58 +01:00
parent fe16584c8c
commit 86cc814f1b
3 changed files with 80 additions and 21 deletions

View File

@@ -15,7 +15,8 @@ namespace Nz
GuillotineImageAtlas::GuillotineImageAtlas() :
m_rectChoiceHeuristic(GuillotineBinPack::RectBestAreaFit),
m_rectSplitHeuristic(GuillotineBinPack::SplitMinimizeArea)
m_rectSplitHeuristic(GuillotineBinPack::SplitMinimizeArea),
m_maxLayerSize(16384)
{
}
@@ -42,6 +43,11 @@ namespace Nz
}
}
unsigned int GuillotineImageAtlas::GetMaxLayerSize() const
{
return m_maxLayerSize;
}
GuillotineBinPack::FreeRectChoiceHeuristic GuillotineImageAtlas::GetRectChoiceHeuristic() const
{
return m_rectChoiceHeuristic;
@@ -115,9 +121,10 @@ namespace Nz
if (newSize == Vector2ui::Zero())
newSize.Set(s_atlasStartSize);
if (ResizeLayer(layer, newSize))
// Limit image atlas size to prevent allocating too much contiguous memory blocks
if (newSize.x <= m_maxLayerSize && newSize.y <= m_maxLayerSize && ResizeLayer(layer, newSize))
{
// Oui on peut !
// Yes we can!
layer.binPack.Expand(newSize); // On ajuste l'atlas virtuel
// Et on relance la boucle sur la nouvelle dernière couche
@@ -149,6 +156,11 @@ namespace Nz
return false;
}
void GuillotineImageAtlas::SetMaxLayerSize(unsigned int maxLayerSize)
{
m_maxLayerSize = maxLayerSize;
}
void GuillotineImageAtlas::SetRectChoiceHeuristic(GuillotineBinPack::FreeRectChoiceHeuristic heuristic)
{
m_rectChoiceHeuristic = heuristic;