diff options
author | Aaron Suen <warr1024@gmail.com> | 2015-03-09 09:32:11 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2015-04-01 00:01:05 -0400 |
commit | 6d61375cc72bad5c569d25c253adca4e3701dd27 (patch) | |
tree | 790accab0443ebcff77790da83a306d713045b01 /src/util | |
parent | b4247dff2e003dd8c5ea5a1f3ae349d0bfab90bc (diff) | |
download | minetest-6d61375cc72bad5c569d25c253adca4e3701dd27.tar.gz minetest-6d61375cc72bad5c569d25c253adca4e3701dd27.tar.bz2 minetest-6d61375cc72bad5c569d25c253adca4e3701dd27.zip |
Clean scaling pre-filter for formspec/HUD.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/numeric.cpp | 1 | ||||
-rw-r--r-- | src/util/numeric.h | 13 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index 2306976ec..4ddfede92 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -245,4 +245,3 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, return true; } - diff --git a/src/util/numeric.h b/src/util/numeric.h index a158a2eae..b4b841918 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -411,5 +411,16 @@ inline bool is_power_of_two(u32 n) return n != 0 && (n & (n-1)) == 0; } -#endif +// Compute next-higher power of 2 efficiently, e.g. for power-of-2 texture sizes. +// Public Domain: https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 +inline u32 npot2(u32 orig) { + orig--; + orig |= orig >> 1; + orig |= orig >> 2; + orig |= orig >> 4; + orig |= orig >> 8; + orig |= orig >> 16; + return orig + 1; +} +#endif |