diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 01:06:31 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 01:06:31 +0100 |
commit | 2b3df2889369aa22b6a1c782bb7fed658720c341 (patch) | |
tree | d915537080b26d2dea1de2e0330445f5075e652e /assetFactory/texturePacker.cpp | |
parent | Reduce texture size determined by packer if non-pot sizes are supported (diff) | |
download | ilt-2b3df2889369aa22b6a1c782bb7fed658720c341.tar.bz2 ilt-2b3df2889369aa22b6a1c782bb7fed658720c341.tar.xz ilt-2b3df2889369aa22b6a1c782bb7fed658720c341.zip |
Have texture packer search harder for a solution, stopping at the reported texture size limit
Diffstat (limited to 'assetFactory/texturePacker.cpp')
-rw-r--r-- | assetFactory/texturePacker.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/assetFactory/texturePacker.cpp b/assetFactory/texturePacker.cpp index 30f1c37..fcc935f 100644 --- a/assetFactory/texturePacker.cpp +++ b/assetFactory/texturePacker.cpp @@ -14,6 +14,9 @@ TexturePacker::TexturePacker(std::span<const Image> in) : std::sort(sortedIndexes.rbegin(), sortedIndexes.rend(), [this](const auto a, const auto b) { return area(inputImages[a]) < area(inputImages[b]); }); + int mts; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mts); + maxTextureSize = static_cast<unsigned int>(mts); } TexturePacker::Result @@ -25,6 +28,9 @@ TexturePacker::pack() const TexturePacker::Result TexturePacker::pack(Size size) const { + if (size.x > maxTextureSize || size.y > maxTextureSize) { + return {}; + } using Spaces = std::set<Space>; Spaces spaces {{{}, size}}; @@ -49,12 +55,14 @@ TexturePacker::pack(Size size) const } } else { - if (size.x < size.y) { - return pack({size.x * 2, size.y}); + const auto x = pack({size.x * 2, size.y}), y = pack({size.x, size.y * 2}); + if (!x.first.empty() && (y.first.empty() || area(x.second) < area(y.second))) { + return x; } - else { - return pack({size.x, size.y * 2}); + else if (!y.first.empty()) { + return y; } + return {}; } } if (GLEW_ARB_texture_non_power_of_two) { |