From 89bbfcbdea903563defbfe93f30a1818a344f537 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 28 May 2014 22:40:19 +0000 Subject: [PATCH] Miscellaneous cleanup, still with the same suspects... - in mdloadskin() and gloadtile_hi(), use new function check_nonpow2() (bit-twiddling) instead of loop - Replace a couple of missed literals with CACHEAD_* enum labels git-svn-id: https://svn.eduke32.com/eduke32@4488 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/hightile.h | 1 + polymer/eduke32/build/include/polymost.h | 6 ++++ polymer/eduke32/build/src/mdsprite.c | 21 ++++++-------- polymer/eduke32/build/src/polymost.c | 16 ++++------- polymer/eduke32/build/src/texcache.c | 35 +++++++++++++++--------- 5 files changed, 43 insertions(+), 36 deletions(-) diff --git a/polymer/eduke32/build/include/hightile.h b/polymer/eduke32/build/include/hightile.h index cb69dcf35..c04c06d0a 100644 --- a/polymer/eduke32/build/include/hightile.h +++ b/polymer/eduke32/build/include/hightile.h @@ -63,6 +63,7 @@ enum CACHEAD_NONPOW2 = 1, CACHEAD_HASALPHA = 2, CACHEAD_COMPRESSED = 4, + CACHEAD_NOCOMPRESS = 8, }; // hicreplctyp hicr->flags bits diff --git a/polymer/eduke32/build/include/polymost.h b/polymer/eduke32/build/include/polymost.h index 2cbfd3604..15b1a3ac1 100644 --- a/polymer/eduke32/build/include/polymost.h +++ b/polymer/eduke32/build/include/polymost.h @@ -94,6 +94,12 @@ static inline int32_t fogpal_shade(const sectortype *sec, int32_t shade) return sec->fogpal ? 0 : shade; } +static inline int check_nonpow2(int32_t xsiz, int32_t ysiz) +{ + return (xsiz > 1 && (xsiz&(xsiz-1))) + || (ysiz > 1 && (ysiz&(ysiz-1))); +} + // Flags of the argument of various functions enum { DAMETH_CLAMPED = 4, diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 2bc6f4799..852fd608b 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -573,7 +573,8 @@ int32_t md_undefinemodel(int32_t modelid) return 0; } -static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t *sizx, int32_t *sizy, int32_t *osizx, int32_t *osizy, char *hasalpha, int32_t pal, char effect) +static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t *sizx, int32_t *sizy, + int32_t *osizx, int32_t *osizy, char *hasalpha, int32_t pal, char effect) { int32_t picfillen, j,y,x; char *picfil,*cptr,al=255; @@ -670,13 +671,13 @@ static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t static inline int32_t hicfxmask(int32_t pal) { - return (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK); + return globalnoeffect ? 0 : (hictinting[pal].f & HICEFFECTMASK); } //Note: even though it says md2model, it works for both md2model&md3model int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf) { - int32_t i,j, bpl, xsiz=0, ysiz=0, osizx, osizy, texfmt = GL_RGBA, intexfmt = GL_RGBA; + int32_t i, bpl, xsiz=0, ysiz=0, osizx, osizy, texfmt = GL_RGBA, intexfmt = GL_RGBA; char *skinfile, hasalpha, fn[BMAX_PATH]; GLuint *texidx = NULL; mdskinmap_t *sk, *skzero = NULL; @@ -829,7 +830,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf) if (glinfo.bgra) texfmt = GL_BGRA; - uploadtexture((doalloc&1), xsiz, ysiz, intexfmt, texfmt, (coltype *)fptr, xsiz, ysiz, 0|8192); + uploadtexture((doalloc&1), xsiz, ysiz, intexfmt, texfmt, (coltype *)fptr, xsiz, ysiz, DAMETH_HI); Bfree((void *)fptr); } @@ -879,18 +880,14 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf) if (glinfo.texcompr && glusetexcompr && glusetexcache) if (!gotcache) { + const int32_t nonpow2 = check_nonpow2(xsiz, ysiz); + // save off the compressed version cachead.quality = r_downsize; cachead.xdim = osizx>>cachead.quality; cachead.ydim = osizy>>cachead.quality; - i = 0; - for (j=0; j<31; j++) - { - if (xsiz == pow2long[j]) { i |= 1; } - if (ysiz == pow2long[j]) { i |= 2; } - } - cachead.flags = (i!=3)*CACHEAD_NONPOW2 | (hasalpha ? CACHEAD_HASALPHA : 0); + cachead.flags = nonpow2*CACHEAD_NONPOW2 | (hasalpha ? CACHEAD_HASALPHA : 0); /// OSD_Printf("Caching \"%s\"\n",fn); texcache_writetex(fn, picfillen, pal<<8, hicfxmask(pal), &cachead); @@ -2040,7 +2037,7 @@ static int32_t md3draw(md3model_t *m, const spritetype *tspr) int32_t i, surfi; float f, g, k0, k1, k2=0, k3=0, mat[16]; // inits: compiler-happy GLfloat pc[4]; - int32_t texunits = GL_TEXTURE0_ARB; + int32_t texunits = GL_TEXTURE0_ARB; const int32_t owner = tspr->owner; // PK: XXX: These owner bound checks are redundant because sext is diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 06d50749b..8dba21e83 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -754,7 +754,8 @@ static void fixtransparency(int32_t dapicnum, coltype *dapic, int32_t daxsiz, in } } -void uploadtexture(int32_t doalloc, int32_t xsiz, int32_t ysiz, int32_t intexfmt, int32_t texfmt, coltype *pic, int32_t tsizx, int32_t tsizy, int32_t dameth) +void uploadtexture(int32_t doalloc, int32_t xsiz, int32_t ysiz, int32_t intexfmt, int32_t texfmt, + coltype *pic, int32_t tsizx, int32_t tsizy, int32_t dameth) { int32_t x2, y2, j, js=0; const int32_t hi = (dameth & DAMETH_HI) ? 1 : 0; @@ -1281,7 +1282,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp if (glinfo.texcompr && glusetexcompr && glusetexcache && !(hicr->flags & HICR_NOSAVE)) if (!gotcache) { - int32_t j, x; + const int32_t nonpow2 = check_nonpow2(xsiz, ysiz); // save off the compressed version if (hicr->flags & HICR_NOCOMPRESS) cachead.quality = 0; @@ -1289,17 +1290,10 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp cachead.xdim = tsizx>>cachead.quality; cachead.ydim = tsizy>>cachead.quality; - x = 0; - for (j=0; j<31; j++) - { - if (xsiz == pow2long[j]) { x |= 1; } - if (ysiz == pow2long[j]) { x |= 2; } - } - // handle nocompress: - cachead.flags = (x!=3)*CACHEAD_NONPOW2 | + cachead.flags = nonpow2*CACHEAD_NONPOW2 | (hasalpha != 255 ? CACHEAD_HASALPHA : 0) | - (hicr->flags & HICR_NOCOMPRESS ? 8 : 0); + (hicr->flags & HICR_NOCOMPRESS ? CACHEAD_NOCOMPRESS : 0); /// OSD_Printf("Caching \"%s\"\n", fn); texcache_writetex(fn, picfillen+(dapalnum<<8), dameth, effect, &cachead); diff --git a/polymer/eduke32/build/src/texcache.c b/polymer/eduke32/build/src/texcache.c index 569bc738b..775bee718 100644 --- a/polymer/eduke32/build/src/texcache.c +++ b/polymer/eduke32/build/src/texcache.c @@ -437,7 +437,8 @@ int32_t texcache_readtexheader(const char *fn, int32_t len, int32_t dameth, char int32_t i, err = 0; char cachefn[BMAX_PATH]; - if (!texcache_enabled()) return 0; + if (!texcache_enabled()) + return 0; i = hash_find(&texcache.hashes, texcache_calcid(cachefn, fn, len, dameth, effect)); @@ -445,12 +446,13 @@ int32_t texcache_readtexheader(const char *fn, int32_t len, int32_t dameth, char return 0; // didn't find it texcache.filepos = texcache.ptrs[i]->offset; - // initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, cachefn,offset); +// initprintf("%s %d got a match for %s offset %d\n",__FILE__, __LINE__, cachefn,offset); + if (texcache_readdata(head, sizeof(texcacheheader))) + READTEXHEADER_FAILURE(0); - if (texcache_readdata(head, sizeof(texcacheheader))) READTEXHEADER_FAILURE(0); - - if (Bmemcmp(head->magic, TEXCACHEMAGIC, 4)) READTEXHEADER_FAILURE(1); + if (Bmemcmp(head->magic, TEXCACHEMAGIC, 4)) + READTEXHEADER_FAILURE(1); // native (little-endian) -> internal head->xdim = B_LITTLE32(head->xdim); @@ -458,16 +460,21 @@ int32_t texcache_readtexheader(const char *fn, int32_t len, int32_t dameth, char head->flags = B_LITTLE32(head->flags); head->quality = B_LITTLE32(head->quality); - if (modelp && head->quality != r_downsize) READTEXHEADER_FAILURE(2); - if ((head->flags & 4) && glusetexcache != 2) READTEXHEADER_FAILURE(3); - if (!(head->flags & 4) && glusetexcache == 2) READTEXHEADER_FAILURE(4); + if (modelp && head->quality != r_downsize) + READTEXHEADER_FAILURE(2); + if ((head->flags & CACHEAD_COMPRESSED) && glusetexcache != 2) + READTEXHEADER_FAILURE(3); + if (!(head->flags & CACHEAD_COMPRESSED) && glusetexcache == 2) + READTEXHEADER_FAILURE(4); // handle nocompress - if (!modelp && !(head->flags & 8) && head->quality != r_downsize) + if (!modelp && !(head->flags & CACHEAD_NOCOMPRESS) && head->quality != r_downsize) return 0; - if (gltexmaxsize && (head->xdim > (1<ydim > (1<flags & 1)) READTEXHEADER_FAILURE(6); + if (gltexmaxsize && (head->xdim > (1<ydim > (1<flags & CACHEAD_NONPOW2)) + READTEXHEADER_FAILURE(6); return 1; @@ -519,7 +526,8 @@ void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect, Bmemcpy(head->magic, TEXCACHEMAGIC, 4); // sizes are set by caller - if (glusetexcache == 2) head->flags |= 4; + if (glusetexcache == 2) + head->flags |= CACHEAD_COMPRESSED; // native -> external (little-endian) head->xdim = B_LITTLE32(head->xdim); @@ -665,7 +673,8 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int3 REALLOC_OR_FAIL(midbuf, pict.size, void); } - if (dedxtfilter(texcache.filehandle, &pict, pic, midbuf, packbuf, (head->flags&4)==4)) + if (dedxtfilter(texcache.filehandle, &pict, pic, midbuf, packbuf, + (head->flags & CACHEAD_COMPRESSED)!=0)) { TEXCACHE_FREEBUFS(); return TEXCACHERR_DEDXT;