Make sure util::atlas size is power-of-two

This commit is contained in:
Nikita Lisitsa 2023-05-25 01:55:33 +03:00
parent eb55ad5644
commit 0791aa1096

View file

@ -53,14 +53,24 @@ namespace psemek::util
part.begin[1] = 0;
part.end[1] = part_height;
std::size_t new_width = std::max(array_.width(), free_start_ + part_width);
std::size_t new_height = std::max(array_.height(), part_height);
std::size_t new_width = array_.width();
std::size_t new_height = array_.height();
if (new_width > array_.width())
new_width = std::max(new_width, array_.width() * 2);
while (new_width < free_start_ + part_width)
{
if (new_width == 0)
new_width = 1;
else
new_width *= 2;
}
if (new_height > array_.height())
new_height = std::max(new_height, array_.height() * 2);
while (new_height < part_height)
{
if (new_height == 0)
new_height = 1;
else
new_height *= 2;
}
array_.resize({new_width, new_height}, default_value_);