Skip to content
This repository was archived by the owner on Mar 15, 2025. It is now read-only.

Commit 5b264c0

Browse files
committed
Added MipmapLevels to a few tests.
1 parent cda89bc commit 5b264c0

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

dang-gl/tests/Texturing/test-TextureAtlasTiles.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ struct StringMaker<TextureAtlasTiles::TileHandle> {
7979

8080
auto tileData(TileData::Padding padding = {}) { return TileData(TileData::Size(4), padding); }
8181

82-
auto mipmappedTileData(TileData::Padding padding = {})
83-
{
84-
auto mipmapper = [](const TileData& tile_data) { return TileData(dgl::nextMipmapSize(tile_data.size())); };
85-
return MipmapLevels(tileData(padding), mipmapper);
86-
}
87-
8882
auto atlasTiles() { return TextureAtlasTiles({16, 4}); }
8983

9084
auto atlasTilesWithTileHandle(const TileData::Padding& padding = {})
@@ -109,6 +103,12 @@ auto frozenTilesWithTileHandle()
109103
return std::pair{freeze(std::move(atlas_tiles)), tile_handle};
110104
}
111105

106+
auto applyMipmap(const TileData& tile_data)
107+
{
108+
auto mipmapper = [](const TileData& tile_data) { return TileData(dgl::nextMipmapSize(tile_data.size())); };
109+
return MipmapLevels(tile_data, mipmapper);
110+
}
111+
112112
TEST_CASE("TextureAtlasTiles can be constructed and moved.", "[texturing][texture-atlas-tiles]")
113113
{
114114
SECTION("Constructing TextureAtlasTiles.")
@@ -279,6 +279,7 @@ TEST_CASE("TextureAtlasTiles can be filled with tiles of the same size, spanning
279279
auto tile_height = GENERATE(range<std::size_t>(1, 5));
280280

281281
auto tile_size = TileData::Size(tile_width, tile_height);
282+
auto tile_data = GENERATE_COPY(MipmapLevels(TileData(tile_size)), applyMipmap(TileData(tile_size)));
282283

283284
// Tiles are aligned on powers of two:
284285
auto tile_width_log2 = dutils::ilog2ceil(tile_width);
@@ -297,7 +298,7 @@ TEST_CASE("TextureAtlasTiles can be filled with tiles of the same size, spanning
297298
DYNAMIC_SECTION("Atlas of size " << max_texture_size << " cannot fit any tile of size " << tile_size
298299
<< ".\nAdding a single tile should throw an invalid_argument exception.")
299300
{
300-
CHECK_THROWS_AS(atlas_tiles.add(TileData(tile_size)), std::invalid_argument);
301+
CHECK_THROWS_AS(atlas_tiles.add(tile_data), std::invalid_argument);
301302
}
302303
}
303304
else {
@@ -309,7 +310,7 @@ TEST_CASE("TextureAtlasTiles can be filled with tiles of the same size, spanning
309310
for (std::size_t layer = 0; layer < max_layer_count; layer++) {
310311
std::set<dmath::svec2> tile_positions;
311312
for (std::size_t i = 0; i < tiles_per_layer; i++) {
312-
auto tile = atlas_tiles.add(TileData(tile_size));
313+
auto tile = atlas_tiles.add(tile_data);
313314
auto tile_pos = tile.pixelPos();
314315
auto [_, position_is_unique] = tile_positions.insert(tile_pos);
315316

@@ -327,7 +328,7 @@ TEST_CASE("TextureAtlasTiles can be filled with tiles of the same size, spanning
327328

328329
SECTION("Adding one more tile should throw a length_error exception.")
329330
{
330-
CHECK_THROWS_AS(atlas_tiles.add(TileData(tile_size)), std::length_error);
331+
CHECK_THROWS_AS(atlas_tiles.add(tile_data), std::length_error);
331332
}
332333
}
333334
}
@@ -345,12 +346,13 @@ TEST_CASE("TextureAtlasTiles can be used to update a texture.", "[texturing]")
345346
auto mipmap_levels = dgl::maxMipmapLevels(size);
346347
auto tile_size = GENERATE(as<std::size_t>{}, 1, 2, 4);
347348
auto layers = GENERATE(as<std::size_t>{}, 1, 2, 4);
349+
auto tile_data = GENERATE_COPY(MipmapLevels(TileData(tile_size)), applyMipmap(TileData(tile_size)));
348350

349351
auto tile_count = dutils::sqr(size) / dutils::sqr(tile_size) * layers;
350352

351353
auto atlas_tiles = TextureAtlasTiles({size, layers});
352354
for (std::size_t i = 0; i < tile_count; i++)
353-
(void)atlas_tiles.add(TileData(TileData::Size(tile_size)));
355+
(void)atlas_tiles.add(tile_data);
354356

355357
SECTION("Using the updateTexture method, which allows further modifications.")
356358
{
@@ -362,7 +364,7 @@ TEST_CASE("TextureAtlasTiles can be used to update a texture.", "[texturing]")
362364
}
363365

364366
CHECK_THAT(resize, CalledWith(resize, size, layers, mipmap_levels));
365-
CHECK_THAT(modify, Called(modify, tile_count));
367+
CHECK_THAT(modify, Called(modify, tile_count * tile_data.count()));
366368

367369
std::set<std::pair<dmath::svec3, std::size_t>> positions_and_mipmap_levels;
368370
for (const auto& [tile_data, offset, mipmap_level] : modify.invocations()) {

0 commit comments

Comments
 (0)