From 868306abef1c5a362be25b224058119a3c0d69c4 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Wed, 4 May 2016 00:25:17 +0000 Subject: [PATCH] Polymost: Allow compressed ART tiles (r_texcompr 2) to be cached. git-svn-id: https://svn.eduke32.com/eduke32@5713 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/hightile.h | 2 ++ polymer/eduke32/build/include/polymost.h | 7 +++- polymer/eduke32/build/src/polymost.c | 43 ++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/polymer/eduke32/build/include/hightile.h b/polymer/eduke32/build/include/hightile.h index 917ac58ca..2df12dd41 100644 --- a/polymer/eduke32/build/include/hightile.h +++ b/polymer/eduke32/build/include/hightile.h @@ -69,6 +69,8 @@ enum CACHEAD_HASALPHA = 2, CACHEAD_COMPRESSED = 4, CACHEAD_NODOWNSIZE = 8, + CACHEAD_HASFULLBRIGHT = 16, + CACHEAD_NPOTWALL = 32, }; // hicreplctyp hicr->flags bits diff --git a/polymer/eduke32/build/include/polymost.h b/polymer/eduke32/build/include/polymost.h index bf2e5269a..4bfb8ca38 100644 --- a/polymer/eduke32/build/include/polymost.h +++ b/polymer/eduke32/build/include/polymost.h @@ -162,6 +162,9 @@ enum { DAMETH_ONEBITALPHA = 131072, DAMETH_ARTIMMUNITY = 262144, + DAMETH_HASFULLBRIGHT = 524288, + DAMETH_NPOTWALL = 1048576, + DAMETH_UPLOADTEXTURE_MASK = DAMETH_HI | DAMETH_NODOWNSIZE | @@ -169,7 +172,9 @@ enum { DAMETH_NOTEXCOMPRESS | DAMETH_HASALPHA | DAMETH_ONEBITALPHA | - DAMETH_ARTIMMUNITY, + DAMETH_ARTIMMUNITY | + DAMETH_HASFULLBRIGHT | + DAMETH_NPOTWALL, }; #define DAMETH_NARROW_MASKPROPS(dameth) (((dameth)&(~DAMETH_TRANS1))|(((dameth)&DAMETH_TRANS1)>>1)) diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 2a0a35ae5..8ad64ea4e 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -1031,9 +1031,29 @@ void gloadtile_art(int32_t dapic, int32_t dapal, int32_t tintpalnum, int32_t das { static int32_t fullbrightloadingpass = 0; vec2_t siz = { 0, 0 }, tsiz = tilesiz[dapic]; + size_t const picdim = tsiz.x*tsiz.y; char hasalpha = 0, hasfullbright = 0; - int32_t npoty = 0; + char npoty = 0; + texcacheheader cachead; + char texcacheid[BMAX_PATH]; + { + // Absolutely disgusting. + uint32_t firstint = 0; + if (waloff[dapic]) + Bmemcpy(&firstint, (void *)waloff[dapic], min(4, picdim)); + sprintf(texcacheid, "%08x", firstint); + } + texcache_calcid(texcacheid, texcacheid, picdim | ((unsigned)dapal<<24u), DAMETH_NARROW_MASKPROPS(dameth) | ((unsigned)dapic<<8u) | ((unsigned)dashade<<24u), tintpalnum); + int32_t gotcache = texcache_readtexheader(texcacheid, &cachead, 0); + + if (gotcache && !texcache_loadtile(&cachead, &doalloc, pth)) + { + hasalpha = !!(cachead.flags & CACHEAD_HASALPHA); + hasfullbright = !!(cachead.flags & CACHEAD_HASFULLBRIGHT); + npoty = !!(cachead.flags & CACHEAD_NPOTWALL); + } + else { if (!glinfo.texnpot) { @@ -1180,12 +1200,14 @@ void gloadtile_art(int32_t dapic, int32_t dapal, int32_t tintpalnum, int32_t das Bmemcpy(&pic[siz.x * siz.y], pic, siz.x * ydif * sizeof(coltype)); siz.y = tsiz.y = nextpoty; - npoty = PTH_NPOTWALL; + npoty = 1; } uploadtexture(doalloc, siz, GL_RGBA, pic, tsiz, dameth | DAMETH_ARTIMMUNITY | (dapic >= MAXUSERTILES ? (DAMETH_NOTEXCOMPRESS|DAMETH_NODOWNSIZE) : 0) | /* never process these short-lived tiles */ + (hasfullbright ? DAMETH_HASFULLBRIGHT : 0) | + (npoty ? DAMETH_NPOTWALL : 0) | (hasalpha ? (DAMETH_HASALPHA|DAMETH_ONEBITALPHA) : 0)); Bfree(pic); @@ -1197,9 +1219,24 @@ void gloadtile_art(int32_t dapic, int32_t dapal, int32_t tintpalnum, int32_t das pth->palnum = dapal; pth->shade = dashade; pth->effects = 0; - pth->flags = TO_PTH_CLAMPED(dameth) | TO_PTH_NOTRANSFIX(dameth) | (hasalpha*PTH_HASALPHA) | npoty; + pth->flags = TO_PTH_CLAMPED(dameth) | TO_PTH_NOTRANSFIX(dameth) | (hasalpha*PTH_HASALPHA) | (npoty*PTH_NPOTWALL); pth->hicr = NULL; +#if defined USE_GLEXT && !defined EDUKE32_GLES + if (!gotcache && glinfo.texcompr && glusetexcache && glusetexcompr == 2 && dapic < MAXUSERTILES) + { + cachead.quality = 0; + cachead.xdim = tsiz.x; + cachead.ydim = tsiz.y; + + cachead.flags = (check_nonpow2(siz.x) || check_nonpow2(siz.y)) * CACHEAD_NONPOW2 | + npoty * CACHEAD_NPOTWALL | + hasalpha * CACHEAD_HASALPHA | hasfullbright * CACHEAD_HASFULLBRIGHT | CACHEAD_NODOWNSIZE; + + texcache_writetex_fromdriver(texcacheid, &cachead); + } +#endif + if (hasfullbright && !fullbrightloadingpass) { // Load the ONLY texture that'll be assembled with the regular one to