8#ifndef GALAXY_GRAPHICS_TEXTUREATLAS_HPP_
9#define GALAXY_GRAPHICS_TEXTUREATLAS_HPP_
14#include <robin_hood.h>
18#include "galaxy/graphics/TexelRegion.hpp"
19#include "galaxy/graphics/VertexArray.hpp"
99 void add(
const std::string& file);
125 [[nodiscard]]
bool contains(
const std::string& key);
134 [[nodiscard]] meta::optional_ref<Info>
query(
const std::string& key);
146 template<meta::is_arithmetic Type>
147 [[nodiscard]]
static float map_x_texel(
const Type x,
const Type width);
159 template<meta::is_arithmetic Type>
160 [[nodiscard]]
static float map_y_texel(
const Type y,
const Type height);
167 [[nodiscard]] meta::vector<std::string>
keys();
214 robin_hood::unordered_flat_map<std::string, Info>
m_data;
227 template<meta::is_arithmetic Type>
230 if constexpr (std::is_floating_point<Type>::value)
236 return static_cast<float>(x) /
static_cast<float>(width);
240 template<meta::is_arithmetic Type>
243 if constexpr (std::is_floating_point<Type>::value)
249 return static_cast<float>(y) /
static_cast<float>(height);
Draw to an opengl texture instead of the screen.
Abstraction for OpenGL vertex array objects.
Parses raw texture files and stiches them into a large altas.
virtual ~TextureAtlas()
Destructor.
robin_hood::unordered_flat_map< std::string, Info > m_data
Index'd list of textures on a sheet.
void init()
Initialize atlas.
TextureAtlas(const TextureAtlas &)=delete
Copy constructor.
int m_size
Maxinum size of an atlas texture.
TextureAtlas(TextureAtlas &&)=delete
Move constructor.
components::Transform m_transform
Default transform to use when building an atlas.
graphics::VertexArray m_vao
Default vertex array to use when building an atlas.
meta::vector< std::string > keys()
Get a list of keys in the cache.
TextureAtlas()
Constructor.
void add_from_vfs()
Loads all atlas textures in the vfs.
void clear()
Clear all data.
int m_max_bindings
Max number of active textures allowed.
void save()
Save all created atlas' to disk.
meta::vector< std::unique_ptr< Sheet > > m_sheets
Texture atlas sheets.
meta::optional_ref< Info > query(const std::string &key)
Get data about texture in atlas.
static float map_y_texel(const Type y, const Type height)
Takes in a y positon texture coord and maps it to a texel.
void add(const std::string &file)
Add a single file.
TextureAtlas & operator=(const TextureAtlas &)=delete
Copy assignment operator.
static float map_x_texel(const Type x, const Type width)
Takes in a x positon texture coord and maps it to a texel.
bool contains(const std::string &key)
Check if atlas contains a texture.
TextureAtlas & operator=(TextureAtlas &&)=delete
Move assignment operator.
Information about textures stored in atlas.
int m_sheet_width
Texture sheet width.
math::iRect m_region
Region of the texture in the atlas.
int m_handle
Texture handle this texture belongs to.
int m_sheet_height
Texture sheet height.
graphics::TexelRegion m_texel_region
Texture region in OpenGL texels.
int m_index
Index of which atlas this sprite belongs to.
A sheet of textures in the atlas.
graphics::RenderTexture m_render_texture
Texture to combine to.
math::RectPack m_packer
Rectangle packing algorithm structure.