|
16 | 16 | namespace Siege::Vulkan
|
17 | 17 | {
|
18 | 18 |
|
| 19 | +/** |
| 20 | + * A vulkan-based texture atlas class. This class contains a single texture made out of many |
| 21 | + * sub-textures. Texture Atlases are a way to store multiple textures in a single space within the |
| 22 | + * same memory space. Currently, the TextureAtlas supports fixed size sub-textures |
| 23 | + * |
| 24 | + * NOTE: Currently only supports fixed size texture atlases |
| 25 | + * |
| 26 | + * TODO(Aryeh): Add the ability to add sub-textures from png files |
| 27 | + * TODO(Aryeh): Add the ability to manually specify the sub-texture extents |
| 28 | + */ |
19 | 29 | class TextureAtlas
|
20 | 30 | {
|
21 | 31 | public:
|
22 | 32 |
|
23 |
| - class TextureRef |
| 33 | + /** |
| 34 | + * A subTextureRef is a reference to a sub-texture. These are textures which are contained |
| 35 | + * within a texture atlas. These can be accessed from the TextureAtlas via indexing |
| 36 | + */ |
| 37 | + class SubTextureRef |
24 | 38 | {
|
25 | 39 | public:
|
26 | 40 |
|
27 | 41 | // 'Structors
|
28 |
| - TextureRef(TextureAtlas* parent, float minX, float minY, float width, float height) : |
| 42 | + |
| 43 | + /** |
| 44 | + * The SubTextureRef constructor |
| 45 | + * @param parent the parent texture atlas this sub-texture belongs to |
| 46 | + * @param minX the leftmost normalised x coordinate within the parent texture |
| 47 | + * @param minY the top-most normalised y coordinate within the parent texture |
| 48 | + * @param width the width of the texture |
| 49 | + * @param height the height of the texture |
| 50 | + */ |
| 51 | + inline SubTextureRef(TextureAtlas* parent, |
| 52 | + float minX, |
| 53 | + float minY, |
| 54 | + float width, |
| 55 | + float height) : |
29 | 56 | parentAtlas {parent},
|
30 | 57 | minX {minX},
|
31 | 58 | width {width},
|
32 | 59 | minY {minY},
|
33 | 60 | height {height}
|
34 | 61 | {}
|
35 | 62 |
|
| 63 | + /** |
| 64 | + * The SubTextureRef move constructor |
| 65 | + * @param other the SubTextureRef to move information from |
| 66 | + */ |
| 67 | + inline SubTextureRef(SubTextureRef&& other) |
| 68 | + { |
| 69 | + Swap(other); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * The SubTextureRef copy constructor |
| 74 | + * @param other the SubTextureRef to copy information from |
| 75 | + */ |
| 76 | + inline SubTextureRef(SubTextureRef& other) : |
| 77 | + parentAtlas {other.parentAtlas}, |
| 78 | + minX {other.minX}, |
| 79 | + width {other.width}, |
| 80 | + minY {other.minY}, |
| 81 | + height {other.height} |
| 82 | + {} |
| 83 | + |
36 | 84 | // Operator Overloads
|
37 | 85 |
|
| 86 | + /** |
| 87 | + * The SubTextureRef copy assignment operator |
| 88 | + * @param other the SubTextureRef to copy information from |
| 89 | + * @return a reference to the SubTextureRef |
| 90 | + */ |
| 91 | + SubTextureRef& operator=(SubTextureRef& other); |
| 92 | + |
| 93 | + /** |
| 94 | + * The SubTextureRef move assignment operator |
| 95 | + * @param other the SubTextureRef to move information from |
| 96 | + * @return a reference to the SubTextureRef |
| 97 | + */ |
| 98 | + inline SubTextureRef& operator=(SubTextureRef&& other) |
| 99 | + { |
| 100 | + Swap(other); |
| 101 | + return *this; |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * The dereference operator |
| 106 | + * @return returns a reference to the stored Texture2D within the parent texture |
| 107 | + */ |
38 | 108 | Texture2D& operator*();
|
39 | 109 |
|
| 110 | + /** |
| 111 | + * The pointer arrow operator |
| 112 | + * @return returns the pointer to the parentTexture for member access |
| 113 | + */ |
40 | 114 | TextureAtlas* operator->();
|
41 | 115 |
|
| 116 | + /** |
| 117 | + * A boolean operator for the SubTextureRef |
| 118 | + * @return A boolean specifying if the parentAtlas exists (is not a nullptr) |
| 119 | + */ |
42 | 120 | operator bool() const;
|
43 | 121 |
|
44 | 122 | // Getters and setters
|
45 | 123 |
|
| 124 | + /** |
| 125 | + * Returns the leftmost coordinate of the sub-texture |
| 126 | + * @return a float specifying the leftmost extent of the sub-texture |
| 127 | + */ |
46 | 128 | inline float GetMinX() const
|
47 | 129 | {
|
48 | 130 | return minX;
|
49 | 131 | }
|
| 132 | + /** |
| 133 | + * Returns the topmost coordinate of the sub-texture |
| 134 | + * @return a float specifying the topmost coordinate of the sub-texture |
| 135 | + */ |
50 | 136 | inline float GetMinY() const
|
51 | 137 | {
|
52 | 138 | return minY;
|
53 | 139 | }
|
| 140 | + /** |
| 141 | + * Returns the width of the sub-texture |
| 142 | + * @return the width of the sub-texture |
| 143 | + */ |
54 | 144 | inline float GetWidth() const
|
55 | 145 | {
|
56 | 146 | return width;
|
57 | 147 | }
|
| 148 | + /** |
| 149 | + * Returns the height of the sub-texture |
| 150 | + * @return the height of the sub-texture |
| 151 | + */ |
58 | 152 | inline float GetHeight() const
|
59 | 153 | {
|
60 | 154 | return height;
|
61 | 155 | }
|
62 | 156 |
|
63 | 157 | private:
|
64 | 158 |
|
65 |
| - // NOTE(Aryeh): Can we always guarantee that the atlas will exist? |
| 159 | + // Private methods |
| 160 | + |
| 161 | + /** |
| 162 | + * Swaps the contents of two SubTextureRefs |
| 163 | + * @param other the SubTextureRef to swap contents with |
| 164 | + */ |
| 165 | + void Swap(SubTextureRef& other); |
| 166 | + |
| 167 | + // Private member variables |
| 168 | + |
66 | 169 | TextureAtlas* parentAtlas {nullptr};
|
67 | 170 | float minX, width, minY, height {0.f};
|
68 | 171 | };
|
69 | 172 |
|
70 | 173 | // 'Structors
|
71 | 174 |
|
| 175 | + /** |
| 176 | + * The default TextureAtlas constructor (empty constructor) |
| 177 | + */ |
72 | 178 | TextureAtlas() = default;
|
| 179 | + |
| 180 | + /** |
| 181 | + * The file upload TextureAtlas constructor. Loads texture data from disk and stores it in the |
| 182 | + * memory |
| 183 | + * @param name the name of the texture |
| 184 | + * @param filePath the path to the texture file |
| 185 | + * @param imageExtents the width and height of the texture |
| 186 | + * @param filter the scaling filter used for the texture |
| 187 | + */ |
73 | 188 | TextureAtlas(const char* name,
|
74 | 189 | const char* filePath,
|
75 | 190 | Utils::Extent2DF imageExtents,
|
76 | 191 | Utils::TextureFilter filter = Utils::TEXTURE_FILTER_LINEAR);
|
| 192 | + |
| 193 | + /** |
| 194 | + * The TextureAtlas move constructor. Moves the contents of one TextureAtlas to another |
| 195 | + * @param other the TextureAtlas to move information from |
| 196 | + */ |
77 | 197 | TextureAtlas(TextureAtlas&& other);
|
| 198 | + |
| 199 | + /** |
| 200 | + * The TextureAtlas Destructor. Destroys all memory stored by the TextureAtlas |
| 201 | + */ |
78 | 202 | ~TextureAtlas();
|
79 | 203 |
|
80 | 204 | // Operator Overloads
|
81 | 205 |
|
82 |
| - TextureRef operator[](size_t index); |
| 206 | + /** |
| 207 | + * The TextureAtlas subscript operator. Indexes into a texture atlas and returns the SubTexture |
| 208 | + * stored in that position. |
| 209 | + * NOTE: So far TextureAtlases only support fixed-size textures |
| 210 | + * @param index the index of the SubTexture |
| 211 | + * @return the SubTextureRef stored in the specified location |
| 212 | + */ |
| 213 | + SubTextureRef operator[](size_t index); |
| 214 | + |
| 215 | + /** |
| 216 | + * The TextureAtlas move assignment operator |
| 217 | + * @param other the TextureAtlas to move information from |
| 218 | + * @return a reference to the TextureAtlas |
| 219 | + */ |
| 220 | + TextureAtlas& operator=(TextureAtlas&& other); |
83 | 221 |
|
84 | 222 | // Getters & Setters
|
85 | 223 |
|
| 224 | + // TODO(Aryeh): Need a way to add new textures to the Atlas in future |
| 225 | + // TODO(Aryeh): Need a way to manually specify each texture coordinate when not using fixed |
| 226 | + // textures |
| 227 | + |
| 228 | + /** |
| 229 | + * Gets the Texture2D stored within the Atlas |
| 230 | + * @return the atlas' texture |
| 231 | + */ |
86 | 232 | inline Texture2D& GetTexture()
|
87 | 233 | {
|
88 | 234 | return texture;
|
89 | 235 | }
|
90 |
| - inline const Texture2D& GetTexture() const |
91 |
| - { |
92 |
| - return texture; |
93 |
| - } |
94 | 236 |
|
95 | 237 | private:
|
96 | 238 |
|
97 | 239 | // Private functions
|
98 | 240 |
|
| 241 | + /** |
| 242 | + * Swaps the contents of two TextureAtlases |
| 243 | + * @param other the TextureAtlas to swap contents with |
| 244 | + */ |
99 | 245 | void Swap(TextureAtlas& other);
|
100 | 246 |
|
101 | 247 | // Private member variables
|
|
0 commit comments