Skip to content

Commit

Permalink
Added system limits to all current atlas types
Browse files Browse the repository at this point in the history
  • Loading branch information
EngineerSmith committed Oct 16, 2021
1 parent f8fd628 commit d1b9f6f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions baseAtlas.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local baseAtlas = {
_canvasSettings = {
dpiscale = 1,
},
_maxCanvasSize = love.graphics.getSystemLimits().texturesize -1
}
baseAtlas.__index = baseAtlas

Expand Down
6 changes: 2 additions & 4 deletions dynamicSize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
-- Under the MIT license, see license suppiled with this file
local path = select(1, ...):match("(.-)[^%.]+$")
local baseAtlas = require(path .. "baseAtlas")
local dynamicSizeTA = setmetatable({
_maxCanvas = love.graphics.getSystemLimits().texturesize -1
}, baseAtlas)
local dynamicSizeTA = setmetatable({}, baseAtlas)
dynamicSizeTA.__index = dynamicSizeTA

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

-- Calculate positions and size of canvas
local maxWidth, maxHeight = 0,0
local root = treeNode.new(self._maxCanvas, self._maxCanvas)
local root = treeNode.new(self._maxCanvasSize, self._maxCanvasSize)

for _, image in ipairs(shallowCopy) do
local img = image.image
Expand Down
24 changes: 20 additions & 4 deletions fixedSize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local fixedSizeTA = setmetatable({}, baseAtlas)
fixedSizeTA.__index = fixedSizeTA

local lg = love.graphics
local ceil, sqrt = math.ceil, math.sqrt
local ceil, floor, sqrt = math.ceil, math.sqrt, math.floor

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

fixedSizeTA.bake = function(self)
if self._dirty and not self._hardBake then
local columns = ceil(sqrt(#self.images))
local columns = ceil(sqrt(self.imagesSize))
local width, height = self.width, self.height
local widthPadded, heightPadded = width + self.padding, height + self.padding
local rows = ceil(#self.images / columns)
local widthCanvas, heightCanvas = columns * widthPadded, rows * heightPadded

local widthCanvas = columns * widthPadded
if widthCanvas > self._maxCanvasSize then
columns = floor(self._maxCanvasSize / width)
widthCanvas = columns * widthPadded
end

local rows = ceil(self.imagesSize / columns)
local heightCanvas = rows * heightPadded
if heightPadded > self._maxCanvasSize then
rows = floor(self._maxCanvasSize / height)
heightCanvas = rows * heightPadded
end

if columns * rows < self.imagesSize then
error("Cannot support "..tostring(self.imagesSize).." images, due to system limits of canvas size. Max allowed on this system: "..tostring(columns * rows))
end

local canvas = lg.newCanvas(widthCanvas, heightCanvas, self._canvasSettings)
local maxIndex = self.imagesSize
lg.push("all")
Expand Down

0 comments on commit d1b9f6f

Please sign in to comment.