Replace RectPacker with a version that can do dynamic allocations

This commit is contained in:
Magnus Norddahl 2025-03-16 18:42:49 +01:00
commit f34cce5614
8 changed files with 393 additions and 697 deletions

View file

@ -121,7 +121,7 @@ void VkLightmapper::SelectTiles(const TArray<LightmapTile*>& tiles)
selectedTiles.Clear();
// We use a 3 texel spacing between rectangles so that the blur pass will not pick up anything from a neighbour tile.
RectPacker packer(bakeImageSize, bakeImageSize, RectPacker::Spacing(3), RectPacker::Padding(3));
RectPacker packer(bakeImageSize, bakeImageSize, 3);
for (int i = 0, count = tiles.Size(); i < count; i++)
{
@ -131,17 +131,17 @@ void VkLightmapper::SelectTiles(const TArray<LightmapTile*>& tiles)
continue;
// Only grab surfaces until our bake texture is full
auto result = packer.insert(tile->AtlasLocation.Width, tile->AtlasLocation.Height);
if (result.pageIndex == 0)
auto result = packer.Alloc(tile->AtlasLocation.Width, tile->AtlasLocation.Height);
if (result->PageIndex == 0)
{
SelectedTile selected;
selected.Tile = tile;
selected.X = result.pos.x;
selected.Y = result.pos.y;
selected.X = result->X;
selected.Y = result->Y;
selectedTiles.Push(selected);
bakeImage.maxX = std::max<uint16_t>(bakeImage.maxX, uint16_t(result.pos.x + tile->AtlasLocation.Width));
bakeImage.maxY = std::max<uint16_t>(bakeImage.maxY, uint16_t(result.pos.y + tile->AtlasLocation.Height));
bakeImage.maxX = std::max<uint16_t>(bakeImage.maxX, uint16_t(result->X + tile->AtlasLocation.Width));
bakeImage.maxY = std::max<uint16_t>(bakeImage.maxY, uint16_t(result->Y + tile->AtlasLocation.Height));
tile->NeedsUpdate = false;
}