Rendering Engine 0.2.17
Modular Graphics Rendering Engine | v0.2.17
Loading...
Searching...
No Matches
texture_atlas_maker_tests.cpp File Reference
#include "texture_atlas_maker.hpp"
#include <gtest/gtest.h>

Go to the source code of this file.

Functions

 TEST (TextureAtlasMaker, EmptyCollectionReportsFailure)
 
 TEST (TextureAtlasMaker, SingleImagePreservesPixelsAndRecordsOrigin)
 
 TEST (TextureAtlasMaker, UniformImagesUseGridAndLeaveUnusedCellBlack)
 
 TEST (TextureAtlasMaker, MixedSizesUseMaximumCellDimensionsAndBlackPadding)
 

Function Documentation

◆ TEST() [1/4]

TEST ( TextureAtlasMaker  ,
EmptyCollectionReportsFailure   
)

Definition at line 54 of file texture_atlas_maker_tests.cpp.

55{
56 TextureAtlasMaker maker({});
57 Positions positions;
58 ImageData atlas;
59 EXPECT_FALSE(maker.CreateTextureAtlas(positions, atlas));
60 EXPECT_TRUE(positions.empty());
61 EXPECT_EQ(atlas.GetWidth(), 0U);
62 EXPECT_EQ(atlas.GetHeight(), 0U);
63 EXPECT_TRUE(atlas.GetImageDataRGBA().empty());
64}
Represents raw 2D image data stored in memory.
unsigned int GetWidth() const
Returns the image width.
std::vector< uint8_t > GetImageDataRGBA() const
Gets raw image data in RGBA format.
unsigned int GetHeight() const
Returns the image height.
Builds texture atlases from collections of images.

◆ TEST() [2/4]

TEST ( TextureAtlasMaker  ,
MixedSizesUseMaximumCellDimensionsAndBlackPadding   
)

Definition at line 101 of file texture_atlas_maker_tests.cpp.

102{
103 const std::map<char, ImageData> images{
104 {'A', SolidImage(2, 3, Color(255, 0, 0))},
105 {'B', SolidImage(4, 1, Color(0, 255, 0))},
106 {'C', SolidImage(1, 2, Color(0, 0, 255))}
107 };
108 TextureAtlasMaker maker(images);
109 Positions positions;
110 ImageData atlas;
111 ASSERT_TRUE(maker.CreateTextureAtlas(positions, atlas));
112 // 4x3 cells, two columns and two rows for these three images.
113 ASSERT_EQ(atlas.GetWidth(), 8U);
114 ASSERT_EQ(atlas.GetHeight(), 6U);
115 const Positions expected{{'A', {0, 0}}, {'B', {4, 0}}, {'C', {0, 3}}};
116 EXPECT_EQ(positions, expected);
117 ExpectAtlasPixels(atlas, images, positions);
118}
Represents a color with red, green, blue, and alpha channels.

◆ TEST() [3/4]

TEST ( TextureAtlasMaker  ,
SingleImagePreservesPixelsAndRecordsOrigin   
)

Definition at line 66 of file texture_atlas_maker_tests.cpp.

67{
68 ImageData source(2, 2, std::vector<std::uint8_t>{
69 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
70 const std::map<char, ImageData> images{{'A', source}};
71 TextureAtlasMaker maker(images);
72 Positions positions;
73 ImageData atlas;
74 ASSERT_TRUE(maker.CreateTextureAtlas(positions, atlas));
75 EXPECT_EQ(atlas.GetWidth(), 2U);
76 EXPECT_EQ(atlas.GetHeight(), 2U);
77 const Positions expected{{'A', {0, 0}}};
78 EXPECT_EQ(positions, expected);
79 EXPECT_EQ(atlas.GetImageDataRGBA(), source.GetImageDataRGBA());
80}

◆ TEST() [4/4]

TEST ( TextureAtlasMaker  ,
UniformImagesUseGridAndLeaveUnusedCellBlack   
)

Definition at line 82 of file texture_atlas_maker_tests.cpp.

83{
84 const std::map<char, ImageData> images{
85 {'C', SolidImage(2, 2, Color(0, 0, 255, 64))},
86 {'A', SolidImage(2, 2, Color(255, 0, 0, 128))},
87 {'B', SolidImage(2, 2, Color(0, 255, 0, 192))}
88 };
89 TextureAtlasMaker maker(images);
90 Positions positions;
91 ImageData atlas;
92 ASSERT_TRUE(maker.CreateTextureAtlas(positions, atlas));
93 ASSERT_EQ(atlas.GetWidth(), 4U);
94 ASSERT_EQ(atlas.GetHeight(), 4U);
95 // This overload uses an ordered map, unlike the optional glyph overload.
96 const Positions expected{{'A', {0, 0}}, {'B', {2, 0}}, {'C', {0, 2}}};
97 EXPECT_EQ(positions, expected);
98 ExpectAtlasPixels(atlas, images, positions);
99}