Skip to content

Commit d1b9f6f

Browse files
committed
Added system limits to all current atlas types
1 parent f8fd628 commit d1b9f6f

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

baseAtlas.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local baseAtlas = {
55
_canvasSettings = {
66
dpiscale = 1,
77
},
8+
_maxCanvasSize = love.graphics.getSystemLimits().texturesize -1
89
}
910
baseAtlas.__index = baseAtlas
1011

dynamicSize.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
-- Under the MIT license, see license suppiled with this file
33
local path = select(1, ...):match("(.-)[^%.]+$")
44
local baseAtlas = require(path .. "baseAtlas")
5-
local dynamicSizeTA = setmetatable({
6-
_maxCanvas = love.graphics.getSystemLimits().texturesize -1
7-
}, baseAtlas)
5+
local dynamicSizeTA = setmetatable({}, baseAtlas)
86
dynamicSizeTA.__index = dynamicSizeTA
97

108
-- Based on BlackPawn's lightmap packing: https://blackpawn.com/texts/lightmaps/default.html
@@ -49,7 +47,7 @@ dynamicSizeTA.bake = function(self, sortBy)
4947

5048
-- Calculate positions and size of canvas
5149
local maxWidth, maxHeight = 0,0
52-
local root = treeNode.new(self._maxCanvas, self._maxCanvas)
50+
local root = treeNode.new(self._maxCanvasSize, self._maxCanvasSize)
5351

5452
for _, image in ipairs(shallowCopy) do
5553
local img = image.image

fixedSize.lua

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local fixedSizeTA = setmetatable({}, baseAtlas)
77
fixedSizeTA.__index = fixedSizeTA
88

99
local lg = love.graphics
10-
local ceil, sqrt = math.ceil, math.sqrt
10+
local ceil, floor, sqrt = math.ceil, math.sqrt, math.floor
1111

1212
fixedSizeTA.new = function(width, height, padding)
1313
local self = setmetatable(baseAtlas.new(padding), fixedSizeTA)
@@ -26,11 +26,27 @@ end
2626

2727
fixedSizeTA.bake = function(self)
2828
if self._dirty and not self._hardBake then
29-
local columns = ceil(sqrt(#self.images))
29+
local columns = ceil(sqrt(self.imagesSize))
3030
local width, height = self.width, self.height
3131
local widthPadded, heightPadded = width + self.padding, height + self.padding
32-
local rows = ceil(#self.images / columns)
33-
local widthCanvas, heightCanvas = columns * widthPadded, rows * heightPadded
32+
33+
local widthCanvas = columns * widthPadded
34+
if widthCanvas > self._maxCanvasSize then
35+
columns = floor(self._maxCanvasSize / width)
36+
widthCanvas = columns * widthPadded
37+
end
38+
39+
local rows = ceil(self.imagesSize / columns)
40+
local heightCanvas = rows * heightPadded
41+
if heightPadded > self._maxCanvasSize then
42+
rows = floor(self._maxCanvasSize / height)
43+
heightCanvas = rows * heightPadded
44+
end
45+
46+
if columns * rows < self.imagesSize then
47+
error("Cannot support "..tostring(self.imagesSize).." images, due to system limits of canvas size. Max allowed on this system: "..tostring(columns * rows))
48+
end
49+
3450
local canvas = lg.newCanvas(widthCanvas, heightCanvas, self._canvasSettings)
3551
local maxIndex = self.imagesSize
3652
lg.push("all")

0 commit comments

Comments
 (0)