From a0ec86ce0159dd6a59921ddb7de6814b0e61ade4 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Thu, 12 Sep 2019 14:32:31 -0300 Subject: [PATCH] Fix powers-of-two checks --- src/r_plane.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 51a69336e..db5fb0f24 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -652,12 +652,18 @@ static void R_DrawSkyPlane(visplane_t *pl) boolean R_CheckPowersOfTwo(void) { - if (ds_flatwidth & (ds_flatwidth - 1)) - ds_powersoftwo = false; - else if (ds_flatheight & (ds_flatheight - 1)) - ds_powersoftwo = false; - else if (ds_flatwidth == ds_flatheight) + boolean wpow2 = (!(ds_flatwidth & (ds_flatwidth - 1))); + boolean hpow2 = (!(ds_flatheight & (ds_flatheight - 1))); + + // Initially, the flat isn't powers-of-two-sized. + ds_powersoftwo = false; + + // But if the width and height are powers of two, + // and are EQUAL, then it's okay :] + if ((ds_flatwidth == ds_flatheight) && (wpow2 && hpow2)) ds_powersoftwo = true; + + // Just return ds_powersoftwo. return ds_powersoftwo; } @@ -806,6 +812,7 @@ void R_DrawSinglePlane(visplane_t *pl) size_t size; ffloor_t *rover; levelflat_t *levelflat; + boolean rawflat = false; if (!(pl->minx <= pl->maxx)) return; @@ -968,6 +975,7 @@ void R_DrawSinglePlane(visplane_t *pl) // It's a raw flat. else { + rawflat = true; R_CheckFlatLength(size); flat = ds_source; } @@ -978,8 +986,11 @@ void R_DrawSinglePlane(visplane_t *pl) if (ds_source == NULL) return; - // Check if the flat has dimensions that are powers-of-two numbers. - if (R_CheckPowersOfTwo()) + // Raw flats always have dimensions that are powers-of-two numbers. + if (rawflat) + ds_powersoftwo = true; + // Otherwise, check if this texture or patch has such dimensions. + else if (R_CheckPowersOfTwo()) { R_CheckFlatLength(ds_flatwidth * ds_flatheight); if (spanfunc == basespanfunc) @@ -1116,26 +1127,27 @@ void R_DrawSinglePlane(visplane_t *pl) ds_sz.z *= focallengthf; // Premultiply the texture vectors with the scale factors +#define SFMULT 65536.f if (ds_powersoftwo) { -#define SFMULT 65536.f*(1<