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;