From cbf7d23623b5bb2d2092cb6c86bc965138b4ea75 Mon Sep 17 00:00:00 2001 From: vimene Date: Tue, 3 Feb 2026 20:26:01 +0100 Subject: added mipmaps for the hw renderer, improvements This commit add mipmaps, but for now, mipmaps are generated on the gpu at runtime. We should generate them in advance. - added mipmaps for the hardware renderer - renamed stb_image.c to stb_image.cpp - add compiler flag to stb_image.cpp to prevent warning - added pipe notation for various objects to have all clipping functions be left to right. We need this for the time being because dot notation would considerably complicate the current implementation - small improvements --- src/math/utils.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/math') diff --git a/src/math/utils.hpp b/src/math/utils.hpp index 5c8c62d..ac19ddc 100644 --- a/src/math/utils.hpp +++ b/src/math/utils.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "math/vector.hpp" namespace engine::math { @@ -35,6 +36,28 @@ constexpr float map(float x, float from1, float from2, float to1, float to2) { return to1 + (x - from1) * (to2 - to1) / (from2 - from1); } +template +constexpr UInt log2_floored(UInt n) noexcept +requires std::same_as || std::same_as || std::same_as +{ +#ifdef __GNUG__ + if constexpr (std::is_same_v) { + return static_cast(sizeof(UInt) * 8 - 1) - __builtin_clz(n); + } else if constexpr (std::is_same_v) { + return static_cast(sizeof(UInt) * 8 - 1) - __builtin_clzl(n); + } else { // unsigned long long + return static_cast(sizeof(UInt) * 8 - 1) - __builtin_clzll(n); + } +#else + UInt ret = 0; + while (n & 1) { + n >>= 1; + ret++; + } + return ret; +#endif +} + } #endif // MATH_UTILS_HPP -- cgit v1.2.3