summaryrefslogtreecommitdiff
path: root/assetFactory/texturePacker.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-09 23:29:00 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-09 23:29:00 +0100
commitb6b3944e9507f337f77a72ea44b5c0ccba7a2c01 (patch)
treea487df54853522f973ed987006e787117804b9eb /assetFactory/texturePacker.h
parentSwap messy glmvec wrapper for OpenMesh Point/Normal with real glm::vec and a ... (diff)
parentMove remaining split/plane functions to use library (diff)
downloadilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.tar.bz2
ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.tar.xz
ilt-b6b3944e9507f337f77a72ea44b5c0ccba7a2c01.zip
Merge branch 'model-factory-textures'
Diffstat (limited to 'assetFactory/texturePacker.h')
-rw-r--r--assetFactory/texturePacker.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/assetFactory/texturePacker.h b/assetFactory/texturePacker.h
new file mode 100644
index 0000000..ca0d67a
--- /dev/null
+++ b/assetFactory/texturePacker.h
@@ -0,0 +1,41 @@
+#pragma once
+
+#include <glm/vec2.hpp>
+#include <span>
+#include <vector>
+
+class TexturePacker {
+public:
+ using Position = glm::uvec2;
+ using Size = glm::uvec2;
+
+ struct Area {
+#ifndef __cpp_aggregate_paren_init
+ constexpr Area(Position p, Size s) : position {std::move(p)}, size {std::move(s)} { }
+#endif
+
+ 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::span<const Image>);
+
+ Result pack(Size) const;
+ Result pack() const;
+
+ Size minSize() const;
+ static decltype(Size::x) area(const Size & size);
+
+private:
+ std::span<const Image> inputImages;
+ std::vector<size_t> sortedIndexes;
+};