Skip to content

Commit 38f56a9

Browse files
committed
fix: make mipmaps for RGBA textures if allowed
Unless explicitly prohibited via `TF_NOMIPMAP` we should build mipmaps for textures destined for the GPU. This currently excludes single-mip block-compressed textures as we would need to decompress them or use the GPU to do so.
1 parent 9ac5ffa commit 38f56a9

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

engine/render/r_texture.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ std::unique_ptr<image_c> r_tex_c::BuildMipSet(std::unique_ptr<image_c> img)
389389
const bool blockCompressed = is_compressed(format);
390390
const bool isAsync = !!(flags & TF_ASYNC);
391391
const bool hasExistingMips = img->tex.layers() > 1;
392-
const bool generateMips = !blockCompressed && !(flags & TF_NOMIPMAP);
393392

394393
auto extent = img->tex.extent();
395394
const auto maxDim = (int)renderer->texMaxDim;
@@ -430,12 +429,22 @@ std::unique_ptr<image_c> r_tex_c::BuildMipSet(std::unique_ptr<image_c> img)
430429
}
431430
}
432431

432+
const bool generateMips = !blockCompressed && img->tex.levels() == 1 && !(flags & TF_NOMIPMAP);
433+
433434
if (generateMips) {
434435
if (blockCompressed) {
435436
// TODO(LV): Mipmap generation requested for a block-compressed texture. This requires decompression.
436437
}
437438
else {
438-
img->tex = gli::generate_mipmaps(img->tex, gli::FILTER_LINEAR);
439+
const auto format = img->tex.format();
440+
const auto extent = img->tex.extent();
441+
const auto layers = img->tex.layers();
442+
const auto swizzles = img->tex.swizzles();
443+
auto newTex = gli::texture2d_array(format, extent, layers, swizzles);
444+
for (size_t layer = 0; layer < layers; ++layer)
445+
newTex.copy(img->tex, layer, 0, 0, layer, 0, 0);
446+
newTex = gli::generate_mipmaps(newTex, gli::FILTER_LINEAR);
447+
img->tex = newTex;
439448
}
440449
}
441450
return img;

0 commit comments

Comments
 (0)