Only allocate space for tint flags combinations that require a pre-computed texture to be stored in memory, instead of space for every combination.

git-svn-id: https://svn.eduke32.com/eduke32@6214 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2017-06-21 13:46:36 +00:00
parent 05945c920b
commit 84c913d04c
6 changed files with 23 additions and 19 deletions

View file

@ -103,7 +103,7 @@ enum
HICTINT_PRECOMPUTED = HICTINT_COLORIZE | HICTINT_BLENDMASK, HICTINT_PRECOMPUTED = HICTINT_COLORIZE | HICTINT_BLENDMASK,
HICTINT_IN_MEMORY = HICTINT_PRECOMPUTED | HICTINT_GRAYSCALE | HICTINT_INVERT, HICTINT_IN_MEMORY = HICTINT_PRECOMPUTED | HICTINT_GRAYSCALE | HICTINT_INVERT,
HICEFFECTMASK = 255, // XXX: Xcalloc() based on this value, why? HICTINT_MEMORY_COMBINATIONS = 1<<5,
}; };
#define GRAYSCALE_COEFF_RED 0.3 #define GRAYSCALE_COEFF_RED 0.3

View file

@ -44,7 +44,7 @@ typedef struct _mdskinmap_t
uint8_t palette, flags, filler[2]; // Build palette number, flags the same as hicreplctyp uint8_t palette, flags, filler[2]; // Build palette number, flags the same as hicreplctyp
int32_t skinnum, surfnum; // Skin identifier, surface number int32_t skinnum, surfnum; // Skin identifier, surface number
char *fn; // Skin filename char *fn; // Skin filename
GLuint texid[HICEFFECTMASK+1]; // OpenGL texture numbers for effect variations GLuint texid[HICTINT_MEMORY_COMBINATIONS]; // OpenGL texture numbers for effect variations
struct _mdskinmap_t *next; struct _mdskinmap_t *next;
float param, specpower, specfactor; float param, specpower, specfactor;
} mdskinmap_t; } mdskinmap_t;

View file

@ -126,7 +126,7 @@ void hicsetpalettetint(int32_t palnum, char r, char g, char b, char effect)
hictinting[palnum].r = r; hictinting[palnum].r = r;
hictinting[palnum].g = g; hictinting[palnum].g = g;
hictinting[palnum].b = b; hictinting[palnum].b = b;
hictinting[palnum].f = effect & HICEFFECTMASK; hictinting[palnum].f = effect;
} }

View file

@ -165,12 +165,12 @@ static void nullskintexids(GLuint texid)
mdskinmap_t *sk; mdskinmap_t *sk;
md2model_t *m2 = (md2model_t *)m; md2model_t *m2 = (md2model_t *)m;
for (j=0; j<m2->numskins*(HICEFFECTMASK+1); j++) for (j=0; j < m2->numskins * HICTINT_MEMORY_COMBINATIONS; j++)
if (m2->texid[j] == texid) if (m2->texid[j] == texid)
m2->texid[j] = 0; m2->texid[j] = 0;
for (sk=m2->skinmap; sk; sk=sk->next) for (sk=m2->skinmap; sk; sk=sk->next)
for (j=0; j<(HICEFFECTMASK+1); j++) for (j=0; j < HICTINT_MEMORY_COMBINATIONS; j++)
if (sk->texid[j] == texid) if (sk->texid[j] == texid)
sk->texid[j] = 0; sk->texid[j] = 0;
} }
@ -201,7 +201,7 @@ void clearskins(int32_t type)
mdskinmap_t *sk; mdskinmap_t *sk;
md2model_t *m2 = (md2model_t *)m; md2model_t *m2 = (md2model_t *)m;
for (j=0; j<m2->numskins*(HICEFFECTMASK+1); j++) for (j=0; j < m2->numskins * HICTINT_MEMORY_COMBINATIONS; j++)
if (m2->texid[j]) if (m2->texid[j])
{ {
GLuint otexid = m2->texid[j]; GLuint otexid = m2->texid[j];
@ -213,7 +213,7 @@ void clearskins(int32_t type)
} }
for (sk=m2->skinmap; sk; sk=sk->next) for (sk=m2->skinmap; sk; sk=sk->next)
for (j=0; j<(HICEFFECTMASK+1); j++) for (j=0; j < HICTINT_MEMORY_COMBINATIONS; j++)
if (sk->texid[j]) if (sk->texid[j])
{ {
GLuint otexid = sk->texid[j]; GLuint otexid = sk->texid[j];
@ -576,9 +576,13 @@ int32_t md_undefinemodel(int32_t modelid)
return 0; return 0;
} }
static inline int32_t hicfxmask(int32_t pal) static inline int32_t hicfxmask(size_t pal)
{ {
return globalnoeffect ? 0 : (hictinting[pal].f & HICEFFECTMASK); return globalnoeffect ? 0 : (hictinting[pal].f & HICTINT_IN_MEMORY);
}
static inline int32_t hicfxid(size_t pal)
{
return globalnoeffect ? 0 : ((hictinting[pal].f & (HICTINT_GRAYSCALE|HICTINT_INVERT|HICTINT_COLORIZE)) | ((hictinting[pal].f & HICTINT_BLENDMASK)<<3));
} }
static int32_t mdloadskin_notfound(char * const skinfile, char const * const fn) static int32_t mdloadskin_notfound(char * const skinfile, char const * const fn)
@ -618,7 +622,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
if (sk->palette == pal && sk->skinnum == number && sk->surfnum == surf) if (sk->palette == pal && sk->skinnum == number && sk->surfnum == surf)
{ {
skinfile = sk->fn; skinfile = sk->fn;
texidx = &sk->texid[hicfxmask(pal)]; texidx = &sk->texid[hicfxid(pal)];
Bstrncpyz(fn, skinfile, BMAX_PATH); Bstrncpyz(fn, skinfile, BMAX_PATH);
//OSD_Printf("Using exact match skin (pal=%d,skinnum=%d,surfnum=%d) %s\n",pal,number,surf,skinfile); //OSD_Printf("Using exact match skin (pal=%d,skinnum=%d,surfnum=%d) %s\n",pal,number,surf,skinfile);
break; break;
@ -640,7 +644,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
if (skzero) if (skzero)
{ {
skinfile = skzero->fn; skinfile = skzero->fn;
texidx = &skzero->texid[hicfxmask(pal)]; texidx = &skzero->texid[hicfxid(pal)];
Bstrncpyz(fn, skinfile, BMAX_PATH); Bstrncpyz(fn, skinfile, BMAX_PATH);
//OSD_Printf("Using def skin 0,0 as fallback, pal=%d\n", pal); //OSD_Printf("Using def skin 0,0 as fallback, pal=%d\n", pal);
} }
@ -654,7 +658,7 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
// m->skinfn is undefined when md3model_t is cast to md2model_t --> crash // m->skinfn is undefined when md3model_t is cast to md2model_t --> crash
skinfile = m->skinfn + number*64; skinfile = m->skinfn + number*64;
texidx = &m->texid[number*(HICEFFECTMASK+1) + hicfxmask(pal)]; texidx = &m->texid[number * HICTINT_MEMORY_COMBINATIONS + hicfxid(pal)];
Bstrncpyz(fn, m->basepath, BMAX_PATH); Bstrncpyz(fn, m->basepath, BMAX_PATH);
if ((Bstrlen(fn) + Bstrlen(skinfile)) < BMAX_PATH) if ((Bstrlen(fn) + Bstrlen(skinfile)) < BMAX_PATH)
Bstrcat(fn,skinfile); Bstrcat(fn,skinfile);
@ -673,9 +677,9 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
if (pal >= (MAXPALOOKUPS - RESERVEDPALS)) if (pal >= (MAXPALOOKUPS - RESERVEDPALS))
for (i=0; i<nextmodelid; i++) for (i=0; i<nextmodelid; i++)
for (skzero = ((md2model_t *)models[i])->skinmap; skzero; skzero = skzero->next) for (skzero = ((md2model_t *)models[i])->skinmap; skzero; skzero = skzero->next)
if (!Bstrcasecmp(skzero->fn, sk->fn) && skzero->texid[hicfxmask(pal)]) if (!Bstrcasecmp(skzero->fn, sk->fn) && skzero->texid[hicfxid(pal)])
{ {
int32_t f = hicfxmask(pal); size_t f = hicfxid(pal);
sk->texid[f] = skzero->texid[f]; sk->texid[f] = skzero->texid[f];
return sk->texid[f]; return sk->texid[f];
@ -1306,7 +1310,7 @@ static md2model_t *md2load(int32_t fil, const char *filnam)
{ Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return 0; } { Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return 0; }
} }
m->texid = (GLuint *)Xcalloc(ournumskins, sizeof(GLuint) * (HICEFFECTMASK+1)); m->texid = (GLuint *)Xcalloc(ournumskins, sizeof(GLuint) * HICTINT_MEMORY_COMBINATIONS);
maxmodelverts = max(maxmodelverts, m->numverts); maxmodelverts = max(maxmodelverts, m->numverts);
maxmodeltris = max(maxmodeltris, head.numtris); maxmodeltris = max(maxmodeltris, head.numtris);

View file

@ -253,7 +253,7 @@ void gltexapplyprops(void)
if (m->mdnum < 2) if (m->mdnum < 2)
continue; continue;
for (bssize_t j = 0; j < m->numskins * (HICEFFECTMASK + 1); j++) for (bssize_t j = 0; j < m->numskins * HICTINT_MEMORY_COMBINATIONS; j++)
{ {
if (!m->texid[j]) if (!m->texid[j])
continue; continue;
@ -261,7 +261,7 @@ void gltexapplyprops(void)
} }
for (mdskinmap_t *sk = m->skinmap; sk; sk = sk->next) for (mdskinmap_t *sk = m->skinmap; sk; sk = sk->next)
for (bssize_t j = 0; j < (HICEFFECTMASK + 1); j++) for (bssize_t j = 0; j < HICTINT_MEMORY_COMBINATIONS; j++)
{ {
if (!sk->texid[j]) if (!sk->texid[j])
continue; continue;
@ -1257,7 +1257,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
char hasalpha; char hasalpha;
texcacheheader cachead; texcacheheader cachead;
char texcacheid[BMAX_PATH]; char texcacheid[BMAX_PATH];
texcache_calcid(texcacheid, fn, picfillen+(dapalnum<<8), DAMETH_NARROW_MASKPROPS(dameth), effect); texcache_calcid(texcacheid, fn, picfillen+(dapalnum<<8), DAMETH_NARROW_MASKPROPS(dameth), effect & HICTINT_IN_MEMORY);
int32_t gotcache = texcache_readtexheader(texcacheid, &cachead, 0); int32_t gotcache = texcache_readtexheader(texcacheid, &cachead, 0);
vec2_t siz = { 0, 0 }, tsiz = { 0, 0 }; vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };

View file

@ -8907,7 +8907,7 @@ static int32_t osdcmd_tint(const osdfuncparm_t *parm)
p->r = atoi_safe(parm->parms[1]); p->r = atoi_safe(parm->parms[1]);
p->g = (parm->numparms>=3) ? atoi_safe(parm->parms[2]) : 255; p->g = (parm->numparms>=3) ? atoi_safe(parm->parms[2]) : 255;
p->b = (parm->numparms>=4) ? atoi_safe(parm->parms[3]) : 255; p->b = (parm->numparms>=4) ? atoi_safe(parm->parms[3]) : 255;
p->f = (parm->numparms>=5) ? atoi_safe(parm->parms[4])&HICEFFECTMASK : 0; p->f = (parm->numparms>=5) ? atoi_safe(parm->parms[4]) : 0;
} }
return OSDCMD_OK; return OSDCMD_OK;
} }