summaryrefslogtreecommitdiff
path: root/assetFactory/texturePacker.h
blob: 7e00f1ade0d7d198d3928ffdf04cf7054969a3ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#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::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;
};