From 5027e4481ea71c454a278e76571c71e2a8a71a03 Mon Sep 17 00:00:00 2001 From: Bigfoot71 Date: Fri, 24 Oct 2025 16:42:44 +0200 Subject: [PATCH] review of `sw_texture_sample_linear` --- src/external/rlsw.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/external/rlsw.h b/src/external/rlsw.h index c1e781b22..94042a952 100644 --- a/src/external/rlsw.h +++ b/src/external/rlsw.h @@ -1942,18 +1942,20 @@ static inline void sw_texture_sample_linear(float *color, const sw_texture_t *te // TODO: With a bit more cleverness we could clearly reduce the // number of operations here, but for now it works fine. - float xf = u*tex->width - 0.5f; - float yf = v*tex->height - 0.5f; + float xf = (u * tex->width) - 0.5f; + float yf = (v * tex->height) - 0.5f; - int x0 = (int)floorf(xf); - int y0 = (int)floorf(yf); + float fx = sw_fract(xf); + float fy = sw_fract(yf); - float fx = xf - x0; - float fy = yf - y0; + int x0 = (int)xf; + int y0 = (int)yf; int x1 = x0 + 1; int y1 = y0 + 1; + // NOTE: If the textures are POT we could avoid the division for SW_REPEAT + if (tex->sWrap == SW_CLAMP) { x0 = (x0 > tex->wMinus1)? tex->wMinus1 : x0;