From b1af1d16a79278a32ece8ee64acb2b193533828b Mon Sep 17 00:00:00 2001 From: luk3yx Date: Tue, 11 Apr 2023 08:35:50 +1200 Subject: [PATCH] Fix log2 on Lua 5.1 (closes !1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by appgurueu Co-authored-by: Lars Müller --- init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 5430495..00a40f6 100644 --- a/init.lua +++ b/init.lua @@ -74,6 +74,7 @@ function nodes.label(node, scale) return elem end +local log2_div = math.log(2) function nodes.image(node, scale, _, possibly_using_gles, client_hud_scale) -- The provided texture could be any size so this has to scale it first local w = floor(node.w * scale * client_hud_scale) @@ -92,8 +93,8 @@ function nodes.image(node, scale, _, possibly_using_gles, client_hud_scale) -- Hacks to work around textures being aligned to a power of 2 on some -- video drivers if possibly_using_gles then - local true_w = 2 ^ math.ceil(math.log(w, 2)) - local true_h = 2 ^ math.ceil(math.log(h, 2)) + local true_w = 2 ^ math.ceil(math.log(w) / log2_div) + local true_h = 2 ^ math.ceil(math.log(h) / log2_div) if true_w ~= w or true_h ~= h then texture = ("[combine:%sx%s:0,0=%s"):format( true_w, true_h,