CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
TextureAtlasLayout.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
13
14namespace CeresEngine {
15
20 struct Node {
21 UInt32 x = 0;
22 UInt32 y = 0;
25 UInt32 children[2]{std::numeric_limits<UInt32>::max(), std::numeric_limits<UInt32>::max()};
26 bool nodeFull = false;
27
28 constexpr Node() = default;
29 constexpr Node(const UInt32 x, const UInt32 y, const UInt32 width, const UInt32 height) : x(x), y(y), width(width), height(height) {}
30 };
31
36 bool mPow2 = false;
37
39
40 public:
41 TextureAtlasLayout() = default;
42
46 TextureAtlasLayout(const UInt32 width, const UInt32 height) : mInitialWidth(width), mInitialHeight(height), mWidth(width), mHeight(height), mPow2(false) {
47 mNodes.push_back(Node(0, 0, width, height));
48 }
49
59 TextureAtlasLayout(const UInt32 width, const UInt32 height, const UInt32 maxWidth, const UInt32 maxHeight, const bool pow2 = false)
60 : mInitialWidth(width), mInitialHeight(height), mWidth(width), mHeight(height), mPow2(pow2) {
61 mNodes.push_back(Node(0, 0, maxWidth, maxHeight));
62 }
63
75 [[nodiscard]] bool addElement(UInt32 width, UInt32 height, UInt32& x, UInt32& y);
76
78 void clear();
79
81 [[nodiscard]] bool isEmpty() const { return mNodes.size() == 1; }
82
84 [[nodiscard]] UInt32 getWidth() const { return mWidth; }
85
87 [[nodiscard]] UInt32 getHeight() const { return mHeight; }
88
89 private:
102 bool addToNode(UInt32 nodeIdx, UInt32 width, UInt32 height, UInt32& x, UInt32& y, bool allowGrowth);
103 };
104
107 public:
112 struct Element {
113 struct {
116
117 struct {
122 };
123
125 struct Page {
127 };
128
148 bool pow2 = false);
149 };
150
151} // namespace CeresEngine
Organizes a set of textures into a single larger texture (an atlas) by minimizing empty space.
Definition TextureAtlasLayout.hpp:18
bool mPow2
Definition TextureAtlasLayout.hpp:36
bool addToNode(UInt32 nodeIdx, UInt32 width, UInt32 height, UInt32 &x, UInt32 &y, bool allowGrowth)
Attempts to add a new element to the specified layout node.
UInt32 mInitialHeight
Definition TextureAtlasLayout.hpp:33
UInt32 mHeight
Definition TextureAtlasLayout.hpp:35
bool isEmpty() const
Checks have any elements been added to the layout.
Definition TextureAtlasLayout.hpp:81
UInt32 getWidth() const
Returns the width of the atlas texture, in pixels.
Definition TextureAtlasLayout.hpp:84
UInt32 mInitialWidth
Definition TextureAtlasLayout.hpp:32
UInt32 getHeight() const
Returns the height of the atlas texture, in pixels.
Definition TextureAtlasLayout.hpp:87
TextureAtlasLayout(const UInt32 width, const UInt32 height)
Constructs a new texture atlas layout with the provided parameters.
Definition TextureAtlasLayout.hpp:46
UInt32 mWidth
Definition TextureAtlasLayout.hpp:34
bool addElement(UInt32 width, UInt32 height, UInt32 &x, UInt32 &y)
Attempts to add a new element in the layout.
void clear()
Removes all entries from the layout.
TextureAtlasLayout(const UInt32 width, const UInt32 height, const UInt32 maxWidth, const UInt32 maxHeight, const bool pow2=false)
Constructs a new texture atlas layout with the provided parameters.
Definition TextureAtlasLayout.hpp:59
Vector< Node > mNodes
Definition TextureAtlasLayout.hpp:38
Utility class used for texture atlas layouts.
Definition TextureAtlasLayout.hpp:106
static Vector< Page > createAtlasLayout(Vector< Element > &elements, UInt32 width, UInt32 height, UInt32 maxWidth, UInt32 maxHeight, bool pow2=false)
Creates an optimal texture layout by packing texture elements in order to end up with as little empty...
Definition Application.hpp:19
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::int32_t Int32
Definition DataTypes.hpp:21
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Represent a single node in the texture atlas binary tree.
Definition TextureAtlasLayout.hpp:20
UInt32 height
Definition TextureAtlasLayout.hpp:24
constexpr Node(const UInt32 x, const UInt32 y, const UInt32 width, const UInt32 height)
Definition TextureAtlasLayout.hpp:29
UInt32 width
Definition TextureAtlasLayout.hpp:23
UInt32 y
Definition TextureAtlasLayout.hpp:22
UInt32 x
Definition TextureAtlasLayout.hpp:21
bool nodeFull
Definition TextureAtlasLayout.hpp:26
UInt32 children[2]
Definition TextureAtlasLayout.hpp:25
Represents a single element used as in input to TextureAtlasUtility.
Definition TextureAtlasLayout.hpp:112
UInt32 width
Definition TextureAtlasLayout.hpp:114
Int32 page
Definition TextureAtlasLayout.hpp:120
UInt32 height
Definition TextureAtlasLayout.hpp:114
UInt32 y
Definition TextureAtlasLayout.hpp:118
UInt32 idx
Definition TextureAtlasLayout.hpp:119
struct CeresEngine::TextureAtlasUtility::Element::@60 input
struct CeresEngine::TextureAtlasUtility::Element::@61 output
UInt32 x
Definition TextureAtlasLayout.hpp:118
Describes a single page of the texture atlas.
Definition TextureAtlasLayout.hpp:125
UInt32 width
Definition TextureAtlasLayout.hpp:126
UInt32 height
Definition TextureAtlasLayout.hpp:126