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

Commit ad72938

Browse files
committed
Added MipmapLevels to a few tests.
1 parent 7e94340 commit ad72938

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
@@ -81,12 +81,6 @@ struct StringMaker<TextureAtlasTiles::TileHandle> {
8181

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

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

9286
auto atlasTilesWithTileHandle(const TileData::Padding& padding = {})
@@ -111,6 +105,12 @@ auto frozenTilesWithTileHandle()
111105
return std::pair{freeze(std::move(atlas_tiles)), tile_handle};
112106
}
113107

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

283283
auto tile_size = TileData::Size(tile_width, tile_height);
284+
auto tile_data = GENERATE_COPY(MipmapLevels(TileData(tile_size)), applyMipmap(TileData(tile_size)));
284285

285286
// Tiles are aligned on powers of two:
286287
auto tile_width_log2 = dutils::ilog2ceil(tile_width);
@@ -299,7 +300,7 @@ TEST_CASE("TextureAtlasTiles can be filled with tiles of the same size, spanning
299300
DYNAMIC_SECTION("Atlas of size " << max_texture_size << " cannot fit any tile of size " << tile_size
300301
<< ".\nAdding a single tile should throw an invalid_argument exception.")
301302
{
302-
CHECK_THROWS_AS(atlas_tiles.add(TileData(tile_size)), std::invalid_argument);
303+
CHECK_THROWS_AS(atlas_tiles.add(tile_data), std::invalid_argument);
303304
}
304305
}
305306
else {
@@ -311,7 +312,7 @@ TEST_CASE("TextureAtlasTiles can be filled with tiles of the same size, spanning
311312
for (std::size_t layer = 0; layer < max_layer_count; layer++) {
312313
std::set<dmath::svec2> tile_positions;
313314
for (std::size_t i = 0; i < tiles_per_layer; i++) {
314-
auto tile = atlas_tiles.add(TileData(tile_size));
315+
auto tile = atlas_tiles.add(tile_data);
315316
auto tile_pos = tile.pixelPos();
316317
auto [_, position_is_unique] = tile_positions.insert(tile_pos);
317318

@@ -329,7 +330,7 @@ TEST_CASE("TextureAtlasTiles can be filled with tiles of the same size, spanning
329330

330331
SECTION("Adding one more tile should throw a length_error exception.")
331332
{
332-
CHECK_THROWS_AS(atlas_tiles.add(TileData(tile_size)), std::length_error);
333+
CHECK_THROWS_AS(atlas_tiles.add(tile_data), std::length_error);
333334
}
334335
}
335336
}
@@ -347,12 +348,13 @@ TEST_CASE("TextureAtlasTiles can be used to update a texture.", "[texturing]")
347348
auto mipmap_levels = dgl::maxMipmapLevels(size);
348349
auto tile_size = GENERATE(as<std::size_t>{}, 1, 2, 4);
349350
auto layers = GENERATE(as<std::size_t>{}, 1, 2, 4);
351+
auto tile_data = GENERATE_COPY(MipmapLevels(TileData(tile_size)), applyMipmap(TileData(tile_size)));
350352

351353
auto tile_count = dutils::sqr(size) / dutils::sqr(tile_size) * layers;
352354

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

357359
SECTION("Using the updateTexture method, which allows further modifications.")
358360
{
@@ -364,7 +366,7 @@ TEST_CASE("TextureAtlasTiles can be used to update a texture.", "[texturing]")
364366
}
365367

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

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

0 commit comments

Comments
 (0)