From cfd851e98ab3775ccb29cfdfce0917c16ebd66ab Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 27 Oct 2023 13:31:28 -0700 Subject: [PATCH] fix max lod level computation in IBLPrefilter FIXES=[308012116] --- filament/src/details/Texture.h | 2 +- libs/iblprefilter/src/IBLPrefilterContext.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/filament/src/details/Texture.h b/filament/src/details/Texture.h index cbf02e30424..bf8d7e435db 100644 --- a/filament/src/details/Texture.h +++ b/filament/src/details/Texture.h @@ -104,7 +104,7 @@ class FTexture : public Texture { // Returns the max number of levels for a texture of given dimensions static inline uint8_t maxLevelCount(uint32_t width, uint32_t height) noexcept { - uint32_t maxDimension = std::max(width, height); + uint32_t const maxDimension = std::max(width, height); return maxLevelCount(maxDimension); } diff --git a/libs/iblprefilter/src/IBLPrefilterContext.cpp b/libs/iblprefilter/src/IBLPrefilterContext.cpp index d4020206ea6..fc66e250eb9 100644 --- a/libs/iblprefilter/src/IBLPrefilterContext.cpp +++ b/libs/iblprefilter/src/IBLPrefilterContext.cpp @@ -217,7 +217,7 @@ Texture* IBLPrefilterContext::EquirectangularToCubemap::operator()( "equirect must be a 2D texture."); UTILS_UNUSED_IN_RELEASE - const uint8_t maxLevelCount = uint8_t(std::log2(equirect->getWidth()) + 0.5f) + 1u; + const uint8_t maxLevelCount = std::max(1, std::ilogbf(float(equirect->getWidth())) + 1); ASSERT_PRECONDITION(equirect->getLevels() == maxLevelCount, "equirect must have %u mipmap levels allocated.", +maxLevelCount);