Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
rendering_engine::TextureAtlasMaker Class Reference

#include <texture_atlas_maker.hpp>

Public Member Functions

 TextureAtlasMaker (std::map< char, ImageData > images)
 ~TextureAtlasMaker ()=default
bool CreateTextureAtlas (std::map< char, std::pair< unsigned int, unsigned int > > &texAtlasData, ImageData &texAtlasImage)

Protected Member Functions

void FindCellDimensions (unsigned int &outputWidth, unsigned int &outputHeight)
void CalculateGridDimensions (unsigned int &outputNumberOfColumns, unsigned int &outputNumberOfRows)
void LogMetaData (const std::string &message)

Protected Attributes

std::map< char, ImageDatamImageCollection
std::ofstream mMetaDataOutputStream

Static Protected Attributes

static const char *const mMetaDataFileName = "MetaData.txt"
static const Color sDefaultPaletteBackgroundColor

Detailed Description

Definition at line 18 of file texture_atlas_maker.hpp.

Constructor & Destructor Documentation

◆ TextureAtlasMaker()

rendering_engine::TextureAtlasMaker::TextureAtlasMaker ( std::map< char, ImageData > images)

Definition at line 10 of file texture_atlas_maker.cpp.

11{
12 mImageCollection = images;
13}
std::map< char, ImageData > mImageCollection

◆ ~TextureAtlasMaker()

rendering_engine::TextureAtlasMaker::~TextureAtlasMaker ( )
default

Member Function Documentation

◆ CalculateGridDimensions()

void rendering_engine::TextureAtlasMaker::CalculateGridDimensions ( unsigned int & outputNumberOfColumns,
unsigned int & outputNumberOfRows )
protected

Definition at line 79 of file texture_atlas_maker.cpp.

80{
81 unsigned int cellWidth;
82 unsigned int cellHeight;
83 FindCellDimensions(cellWidth, cellHeight);
84
85 unsigned int cellsNum = mImageCollection.size();
86 int totalSquare = cellWidth * cellHeight * cellsNum;
87 float rootSq = sqrtf(totalSquare);
88
89 outputNumberOfColumns = std::ceil(rootSq / cellWidth);
90 outputNumberOfRows = std::ceil((float)(cellsNum) / (float)(outputNumberOfColumns));
91}
void FindCellDimensions(unsigned int &outputWidth, unsigned int &outputHeight)

◆ CreateTextureAtlas()

bool rendering_engine::TextureAtlasMaker::CreateTextureAtlas ( std::map< char, std::pair< unsigned int, unsigned int > > & texAtlasData,
ImageData & texAtlasImage )

Definition at line 15 of file texture_atlas_maker.cpp.

16{
17 if( mImageCollection.size() == 0 )
18 {
19 return false;
20 }
21
22 //Find palette specification
23
24 //Find dimension of each cell
25 unsigned int cellWidth;
26 unsigned int cellHeight;
27 FindCellDimensions(cellWidth, cellHeight);
28
29 //Find number of rows and columns
30 unsigned int numberOfColumns;
31 unsigned int numberOfRows;
32 CalculateGridDimensions(numberOfColumns, numberOfRows);
33
34 //Create palette
35 ImageData textureAtlasPalette(static_cast<unsigned int>(cellWidth * numberOfColumns), static_cast<unsigned int>(cellHeight * numberOfRows));
36 textureAtlasPalette.Fill(sDefaultPaletteBackgroundColor);
37
38 auto imageIterator = mImageCollection.begin();
39
40 for( int y = 0; y < numberOfRows; y++ )
41 {
42 for( int x = 0; x < numberOfColumns; x++ )
43 {
44 if( imageIterator != mImageCollection.end() )
45 {
46 ImageData::DrawImageOnImageAtPos(x * cellWidth, y * cellHeight, textureAtlasPalette, imageIterator->second);
47
48 texAtlasData.emplace(imageIterator->first, std::make_pair<unsigned int, unsigned int>(x * cellWidth, y * cellHeight));
49
50 imageIterator++;
51 }
52 }
53 }
54 texAtlasImage = textureAtlasPalette;
55
56 return true;
57}
static void DrawImageOnImageAtPos(unsigned int const x, unsigned int const y, ImageData &toImage, ImageData &fromImage)
Overlays one image on top of another at a given position.
void CalculateGridDimensions(unsigned int &outputNumberOfColumns, unsigned int &outputNumberOfRows)

◆ FindCellDimensions()

void rendering_engine::TextureAtlasMaker::FindCellDimensions ( unsigned int & outputWidth,
unsigned int & outputHeight )
protected

Definition at line 59 of file texture_atlas_maker.cpp.

60{
61 unsigned int height = 0U;
62 unsigned int width = 0U;
63 for( auto& it : mImageCollection )
64 {
65 if( it.second.GetHeight() >= height )
66 {
67 height = it.second.GetHeight();
68 }
69 if( it.second.GetWidth() >= width )
70 {
71 width = it.second.GetWidth();
72 }
73 }
74
75 outputWidth = width;
76 outputHeight = height;
77}

◆ LogMetaData()

void rendering_engine::TextureAtlasMaker::LogMetaData ( const std::string & message)
inlineprotected

Definition at line 32 of file texture_atlas_maker.hpp.

33 {
34 mMetaDataOutputStream << message << std::endl;
35 }

Member Data Documentation

◆ mImageCollection

std::map<char, ImageData> rendering_engine::TextureAtlasMaker::mImageCollection
protected

Definition at line 43 of file texture_atlas_maker.hpp.

◆ mMetaDataFileName

const char *const rendering_engine::TextureAtlasMaker::mMetaDataFileName = "MetaData.txt"
staticprotected

Definition at line 45 of file texture_atlas_maker.hpp.

◆ mMetaDataOutputStream

std::ofstream rendering_engine::TextureAtlasMaker::mMetaDataOutputStream
protected

Definition at line 46 of file texture_atlas_maker.hpp.

◆ sDefaultPaletteBackgroundColor

const Color rendering_engine::TextureAtlasMaker::sDefaultPaletteBackgroundColor
staticprotected

Definition at line 48 of file texture_atlas_maker.hpp.


The documentation for this class was generated from the following files: