summaryrefslogtreecommitdiff
path: root/assetFactory/texturePacker.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-03-11 12:07:29 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-03-11 12:07:29 +0000
commitd7d5cd4265aab0b939b57ea7237b56f2f5840642 (patch)
treec7126217ea8a5f3b27bd0008301c4a3edc7f24e3 /assetFactory/texturePacker.h
parentCLOG includes line number (diff)
downloadilt-d7d5cd4265aab0b939b57ea7237b56f2f5840642.tar.bz2
ilt-d7d5cd4265aab0b939b57ea7237b56f2f5840642.tar.xz
ilt-d7d5cd4265aab0b939b57ea7237b56f2f5840642.zip
Initial version of texture packer
Determines where a collection of smaller textures can be tiled into a single bigger image. Probably non-optimal.
Diffstat (limited to 'assetFactory/texturePacker.h')
-rw-r--r--assetFactory/texturePacker.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/assetFactory/texturePacker.h b/assetFactory/texturePacker.h
new file mode 100644
index 0000000..8e2061b
--- /dev/null
+++ b/assetFactory/texturePacker.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <glm/vec2.hpp>
+#include <span>
+#include <vector>
+
+class TexturePacker {
+public:
+ using Position = glm::uvec2;
+ using Size = glm::uvec2;
+
+ struct Area {
+ Position position;
+ Size size;
+ bool
+ operator<(const Area & other) const
+ {
+ return area(size) < area(other.size);
+ }
+ };
+ using Image = Size;
+ using Space = Area;
+ using Positions = std::vector<Position>;
+ using Result = std::pair<Positions, Size>;
+
+ TexturePacker(std::vector<Image>);
+
+ Result pack(Size) const;
+ Result pack() const;
+
+ Size minSize() const;
+ static decltype(Size::x) area(const Size & size);
+
+private:
+ std::vector<Image> inputImages;
+};