Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
texture_atlas_maker.hpp
Go to the documentation of this file.
1// This file is part of the Rendering Engine project.
2// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3// Copyright (c) 2026 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5#pragma once
6
7#include <iostream>
8#include <unordered_map>
9#include <map>
10#include <memory>
11#include <fstream>
12#include <sstream>
13#include <boost/filesystem.hpp>
14#include "image_data.hpp"
15
16namespace rendering_engine
17{
18
19struct GlyphMetrics;
20
21/**
22 * @class TextureAtlasMaker
23 * @brief Builds texture atlases from collections of images.
24 *
25 * Arranges input images into a grid-based atlas, aiming for a compact,
26 * near-square layout. Supports generic image atlases and font glyph atlases.
27 */
29{
30public:
31 /**
32 * @brief Constructs an atlas maker from a collection of images.
33 * @param images Map of identifiers to image data.
34 */
35 TextureAtlasMaker(std::map<char, ImageData> images);
36 ~TextureAtlasMaker() = default;
37
38 /**
39 * @brief Creates a texture atlas from the stored image collection.
40 * @param texAtlasData Output map of image identifiers to atlas positions.
41 * @param texAtlasImage Output atlas image.
42 * @return True if the atlas was created successfully.
43 */
44 bool CreateTextureAtlas( std::map<char, std::pair<unsigned int, unsigned int>>& texAtlasData, ImageData& texAtlasImage );
45
46 /**
47 * @brief Creates a texture atlas from glyph images and updates glyph metrics.
48 *
49 * Modifies glyph metrics in-place to include atlas coordinates.
50 *
51 * @param ioFontAtlas Map of glyph identifiers to glyph metrics and images.
52 * @return Generated atlas image.
53 */
54 static ImageData CreateTextureAtlas(std::unordered_map<std::uint32_t, std::pair<GlyphMetrics, ImageData>>& ioFontAtlas);
55
56protected:
57 /**
58 * @brief Computes maximum cell dimensions for the stored images.
59 * @param outputWidth Output cell width in pixels.
60 * @param outputHeight Output cell height in pixels.
61 */
62 void FindCellDimensions(unsigned int& outputWidth, unsigned int& outputHeight);
63
64 /**
65 * @brief Computes maximum cell dimensions for glyph images.
66 * @param outputWidth Output cell width in pixels.
67 * @param outputHeight Output cell height in pixels.
68 * @param fontAtlas Glyph image collection.
69 */
70 static void FindCellDimensions(unsigned int& outputWidth, unsigned int& outputHeight, std::unordered_map<std::uint32_t, std::pair<GlyphMetrics, ImageData>>& fontAtlas);
71
72 /**
73 * @brief Calculates grid dimensions for the stored images.
74 * @param outputNumberOfColumns Output number of columns.
75 * @param outputNumberOfRows Output number of rows.
76 */
77 void CalculateGridDimensions(unsigned int& outputNumberOfColumns, unsigned int& outputNumberOfRows);
78
79 /**
80 * @brief Calculates grid dimensions for glyph images.
81 * @param outputNumberOfColumns Output number of columns.
82 * @param outputNumberOfRows Output number of rows.
83 * @param fontAtlas Glyph image collection.
84 */
85 static void CalculateGridDimensions(unsigned int& outputNumberOfColumns, unsigned int& outputNumberOfRows, std::unordered_map<std::uint32_t, std::pair<GlyphMetrics, ImageData>>& fontAtlas);
86
87private:
89 TextureAtlasMaker operator=(TextureAtlasMaker const&);
90
91protected:
92 //container of images
93 std::map<char, ImageData> mImageCollection;
94
96};
97
98} //namespace rendering_engine
Represents raw 2D image data stored in memory.
Definition: image_data.hpp:80
Builds texture atlases from collections of images.
void FindCellDimensions(unsigned int &outputWidth, unsigned int &outputHeight)
Computes maximum cell dimensions for the stored images.
bool CreateTextureAtlas(std::map< char, std::pair< unsigned int, unsigned int > > &texAtlasData, ImageData &texAtlasImage)
Creates a texture atlas from the stored image collection.
TextureAtlasMaker(std::map< char, ImageData > images)
Constructs an atlas maker from a collection of images.
std::map< char, ImageData > mImageCollection
void CalculateGridDimensions(unsigned int &outputNumberOfColumns, unsigned int &outputNumberOfRows)
Calculates grid dimensions for the stored images.
Represents a color with red, green, blue, and alpha channels.
Definition: image_data.hpp:23