Rendering Engine 0.2.17
Modular Graphics Rendering Engine | v0.2.17
Loading...
Searching...
No Matches
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 <filesystem>
14#include "image_data.hpp"
16
17namespace rendering_engine
18{
19
20struct GlyphMetrics;
21
22/**
23 * @class TextureAtlasMaker
24 * @brief Builds texture atlases from collections of images.
25 *
26 * Arranges input images into a grid-based atlas, aiming for a compact,
27 * near-square layout. Supports generic image atlases and font glyph atlases.
28 */
30{
31public:
32 /**
33 * @brief Constructs an atlas maker from a collection of images.
34 * @param images Map of identifiers to image data.
35 */
36 TextureAtlasMaker(std::map<char, ImageData> images);
37 ~TextureAtlasMaker() = default;
38
39 /**
40 * @brief Creates a texture atlas from the stored image collection.
41 * @param texAtlasData Output map of image identifiers to atlas positions.
42 * @param texAtlasImage Output atlas image.
43 * @return True if the atlas was created successfully.
44 */
45 bool CreateTextureAtlas( std::map<char, std::pair<unsigned int, unsigned int>>& texAtlasData, ImageData& texAtlasImage );
46
47 /**
48 * @brief Creates a texture atlas from glyph images and updates glyph metrics.
49 *
50 * Modifies glyph metrics in-place to include atlas coordinates.
51 *
52 * @param ioFontAtlas Map of glyph identifiers to glyph metrics and images.
53 * @return Generated atlas image.
54 */
55 static ImageData CreateTextureAtlas(std::unordered_map<std::uint32_t, std::pair<GlyphMetrics, ImageData>>& ioFontAtlas);
56
57protected:
58 /**
59 * @brief Computes maximum cell dimensions for the stored images.
60 * @param outputWidth Output cell width in pixels.
61 * @param outputHeight Output cell height in pixels.
62 */
63 void FindCellDimensions(unsigned int& outputWidth, unsigned int& outputHeight);
64
65 /**
66 * @brief Computes maximum cell dimensions for glyph images.
67 * @param outputWidth Output cell width in pixels.
68 * @param outputHeight Output cell height in pixels.
69 * @param fontAtlas Glyph image collection.
70 */
71 static void FindCellDimensions(unsigned int& outputWidth, unsigned int& outputHeight, std::unordered_map<std::uint32_t, std::pair<GlyphMetrics, ImageData>>& fontAtlas);
72
73 /**
74 * @brief Calculates grid dimensions for the stored images.
75 * @param outputNumberOfColumns Output number of columns.
76 * @param outputNumberOfRows Output number of rows.
77 */
78 void CalculateGridDimensions(unsigned int& outputNumberOfColumns, unsigned int& outputNumberOfRows);
79
80 /**
81 * @brief Calculates grid dimensions for glyph images.
82 * @param outputNumberOfColumns Output number of columns.
83 * @param outputNumberOfRows Output number of rows.
84 * @param fontAtlas Glyph image collection.
85 */
86 static void CalculateGridDimensions(unsigned int& outputNumberOfColumns, unsigned int& outputNumberOfRows, std::unordered_map<std::uint32_t, std::pair<GlyphMetrics, ImageData>>& fontAtlas);
87
88private:
90 TextureAtlasMaker operator=(TextureAtlasMaker const&);
91
92protected:
93 //container of images
94 std::map<char, ImageData> mImageCollection;
95
97};
98
99} //namespace rendering_engine
Represents raw 2D image data stored in memory.
Builds texture atlases from collections of images.
std::map< char, ImageData > mImageCollection
#define RE_API
Represents a color with red, green, blue, and alpha channels.