aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorvimene <vincent.menegaux@gmail.com>2026-02-03 20:26:01 +0100
committervimene <vincent.menegaux@gmail.com>2026-02-03 20:26:01 +0100
commitcbf7d23623b5bb2d2092cb6c86bc965138b4ea75 (patch)
tree7234b255b871cecca24aadc03c8d0857202f48e4 /src/math
parent0d10b77f77459333c5549711334f417623ab1f3e (diff)
downloadengine-main.tar.gz
added mipmaps for the hw renderer, improvementsHEADmain
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
Diffstat (limited to 'src/math')
-rw-r--r--src/math/utils.hpp23
1 files changed, 23 insertions, 0 deletions
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 <array>
#include <utility>
+#include <concepts>
#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<typename UInt>
+constexpr UInt log2_floored(UInt n) noexcept
+requires std::same_as<UInt, unsigned> || std::same_as<UInt, unsigned long> || std::same_as<UInt, unsigned long long>
+{
+#ifdef __GNUG__
+ if constexpr (std::is_same_v<UInt, unsigned>) {
+ return static_cast<UInt>(sizeof(UInt) * 8 - 1) - __builtin_clz(n);
+ } else if constexpr (std::is_same_v<UInt, unsigned long>) {
+ return static_cast<UInt>(sizeof(UInt) * 8 - 1) - __builtin_clzl(n);
+ } else { // unsigned long long
+ return static_cast<UInt>(sizeof(UInt) * 8 - 1) - __builtin_clzll(n);
+ }
+#else
+ UInt ret = 0;
+ while (n & 1) {
+ n >>= 1;
+ ret++;
+ }
+ return ret;
+#endif
+}
+
}
#endif // MATH_UTILS_HPP