Engine: Move daskinloader into mdloadskin and clean up it and gloadtile_hi against one another.

git-svn-id: https://svn.eduke32.com/eduke32@5644 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2016-03-04 19:24:54 +00:00
parent f76c5177f4
commit 7011b30e50
5 changed files with 246 additions and 245 deletions

View File

@ -80,7 +80,7 @@ enum
HICR_NODOWNSIZE = 16, HICR_NODOWNSIZE = 16,
}; };
// hictinting[].f / gloadtile_hi() and daskinloader() <effect> arg bits // hictinting[].f / gloadtile_hi() and mdloadskin() <effect> arg bits
enum enum
{ {
HICTINT_GRAYSCALE = 1, HICTINT_GRAYSCALE = 1,

View File

@ -58,7 +58,7 @@ extern void texcache_init(void);
extern int32_t texcache_loadoffsets(void); extern int32_t texcache_loadoffsets(void);
extern int32_t texcache_readdata(void *dest, int32_t len); extern int32_t texcache_readdata(void *dest, int32_t len);
extern pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int32_t dameth); extern pthtyp *texcache_fetch(int32_t dapicnum, int32_t dapalnum, int32_t dashade, int32_t dameth);
extern int32_t texcache_loadskin(const texcacheheader *head, int32_t *doalloc, GLuint *glpic, int32_t *xsiz, int32_t *ysiz); extern int32_t texcache_loadskin(const texcacheheader *head, int32_t *doalloc, GLuint *glpic, vec2_t *siz);
extern int32_t texcache_loadtile(const texcacheheader *head, int32_t *doalloc, pthtyp *pth); extern int32_t texcache_loadtile(const texcacheheader *head, int32_t *doalloc, pthtyp *pth);
extern void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head); extern void texcache_writetex(const char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head);
extern int32_t texcache_readtexheader(const char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head, int32_t modelp); extern int32_t texcache_readtexheader(const char *fn, int32_t len, int32_t dameth, char effect, texcacheheader *head, int32_t modelp);

View File

@ -23,14 +23,6 @@ static int32_t curextra=MAXTILES;
#define MIN_CACHETIME_PRINT 10 #define MIN_CACHETIME_PRINT 10
static void QuitOnFatalError(const char *msg)
{
if (msg)
initprintf("%s\n", msg);
uninitengine();
Bexit(1);
}
static int32_t addtileP(int32_t model,int32_t tile,int32_t pallet) static int32_t addtileP(int32_t model,int32_t tile,int32_t pallet)
{ {
@ -586,169 +578,35 @@ int32_t md_undefinemodel(int32_t modelid)
return 0; 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)
{
char *cptr,al=255;
coltype *pic;
int32_t xsiz, ysiz, tsizx = 0, tsizy = 0;
int32_t r, g, b;
int32_t j, y, x;
int32_t isart = 0;
int32_t const picfillen = kpzbufloadfil(filh);
// tsizx/y = replacement texture's natural size
// xsiz/y = 2^x size of replacement
#ifdef WITHKPLIB
kpgetdim(kpzbuf,picfillen,&tsizx,&tsizy);
#endif
if (tsizx == 0 || tsizy == 0)
{
if (E_CheckUnitArtFileHeader((uint8_t *)kpzbuf, picfillen))
return -2;
tsizx = B_LITTLE16(B_UNBUF16(&kpzbuf[16]));
tsizy = B_LITTLE16(B_UNBUF16(&kpzbuf[18]));
if (tsizx == 0 || tsizy == 0)
return -2;
isart = 1;
}
if (!glinfo.texnpot)
{
for (xsiz=1; xsiz<tsizx; xsiz+=xsiz) { }
for (ysiz=1; ysiz<tsizy; ysiz+=ysiz) { }
}
else
{
xsiz = tsizx;
ysiz = tsizy;
}
*osizx = tsizx; *osizy = tsizy;
if (isart)
{
if (tsizx * tsizy + ARTv1_UNITOFFSET > picfillen)
return -2;
}
int32_t const bytesperline = xsiz * sizeof(coltype);
pic = (coltype *)Xcalloc(ysiz, bytesperline);
if (isart)
{
E_RenderArtDataIntoBuffer((palette_t *)pic, (uint8_t *)&kpzbuf[ARTv1_UNITOFFSET], xsiz, tsizx, tsizy);
}
#ifdef WITHKPLIB
else
{
if (kprender(kpzbuf,picfillen,(intptr_t)pic,bytesperline,xsiz,ysiz))
{
Bfree(pic);
return -2;
}
}
#endif
cptr = &britable[gammabrightness ? 0 : curbrightness][0];
r=(glinfo.bgra)?hictinting[pal].b:hictinting[pal].r;
g=hictinting[pal].g;
b=(glinfo.bgra)?hictinting[pal].r:hictinting[pal].b;
for (y=0,j=0; y<tsizy; y++,j+=xsiz)
{
coltype *rpptr = &pic[j], tcol;
for (x=0; x<tsizx; x++)
{
tcol.b = cptr[rpptr[x].b];
tcol.g = cptr[rpptr[x].g];
tcol.r = cptr[rpptr[x].r];
if (effect & HICTINT_GRAYSCALE)
{
tcol.g = tcol.r = tcol.b = (uint8_t)((tcol.r * GRAYSCALE_COEFF_RED) + (tcol.g * GRAYSCALE_COEFF_GREEN) +
(tcol.b * GRAYSCALE_COEFF_BLUE));
}
if (effect & HICTINT_INVERT)
{
tcol.b = 255-tcol.b;
tcol.g = 255-tcol.g;
tcol.r = 255-tcol.r;
}
if (effect & HICTINT_COLORIZE)
{
tcol.b = min((int32_t)(tcol.b)*b/64,255);
tcol.g = min((int32_t)(tcol.g)*g/64,255);
tcol.r = min((int32_t)(tcol.r)*r/64,255);
}
switch (effect & HICTINT_BLENDMASK)
{
case HICTINT_BLEND_SCREEN:
tcol.b = 255 - (((255 - tcol.b) * (255 - b)) >> 8);
tcol.g = 255 - (((255 - tcol.g) * (255 - g)) >> 8);
tcol.r = 255 - (((255 - tcol.r) * (255 - r)) >> 8);
break;
case HICTINT_BLEND_OVERLAY:
tcol.b = tcol.b < 128 ? (tcol.b * b) >> 7 : 255 - (((255 - tcol.b) * (255 - b)) >> 7);
tcol.g = tcol.g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
tcol.r = tcol.r < 128 ? (tcol.r * r) >> 7 : 255 - (((255 - tcol.r) * (255 - r)) >> 7);
break;
case HICTINT_BLEND_HARDLIGHT:
tcol.b = b < 128 ? (tcol.b * b) >> 7 : 255 - (((255 - tcol.b) * (255 - b)) >> 7);
tcol.g = g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
tcol.r = r < 128 ? (tcol.r * r) >> 7 : 255 - (((255 - tcol.r) * (255 - r)) >> 7);
break;
}
rpptr[x].b = tcol.b;
rpptr[x].g = tcol.g;
rpptr[x].r = tcol.r;
al &= rpptr[x].a;
}
}
if (!glinfo.bgra)
{
for (j=xsiz*ysiz-1; j>=0; j--)
{
swapchar(&pic[j].r, &pic[j].b);
}
}
*sizx = xsiz;
*sizy = ysiz;
*bpl = xsiz;
*fptr = (intptr_t)pic;
*hasalpha = (al != 255);
return 0;
}
static inline int32_t hicfxmask(int32_t pal) static inline int32_t hicfxmask(int32_t pal)
{ {
return globalnoeffect ? 0 : (hictinting[pal].f & HICEFFECTMASK); return globalnoeffect ? 0 : (hictinting[pal].f & HICEFFECTMASK);
} }
static int32_t mdloadskin_notfound(char * const skinfile, char const * const fn)
{
OSD_Printf("Skin \"%s\" not found.\n", fn);
skinfile[0] = 0;
return 0;
}
static int32_t mdloadskin_failed(char * const skinfile, char const * const fn)
{
OSD_Printf("Failed loading skin file \"%s\".\n", fn);
skinfile[0] = 0;
return 0;
}
//Note: even though it says md2model, it works for both md2model&md3model //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 mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
{ {
int32_t i, bpl, osizx, osizy; int32_t i;
char *skinfile, hasalpha, fn[BMAX_PATH]; char *skinfile, fn[BMAX_PATH];
GLuint *texidx = NULL; GLuint *texidx = NULL;
mdskinmap_t *sk, *skzero = NULL; mdskinmap_t *sk, *skzero = NULL;
int32_t doalloc = 1, filh; int32_t doalloc = 1;
int32_t gotcache, picfillen;
texcacheheader cachead;
int32_t startticks, willprint=0;
vec2_t siz = { 0, 0 };
if (m->mdnum == 2) if (m->mdnum == 2)
surf = 0; surf = 0;
@ -831,55 +689,207 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
*texidx = 0; *texidx = 0;
int32_t filh;
if ((filh = kopen4load(fn, 0)) < 0) if ((filh = kopen4load(fn, 0)) < 0)
{ return mdloadskin_notfound(skinfile, fn);
OSD_Printf("Skin \"%s\" not found.\n",fn);
skinfile[0] = 0;
return 0;
}
picfillen = kfilelength(filh); int32_t picfillen = kfilelength(filh);
kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c
startticks = getticks(); int32_t startticks = getticks(), willprint = 0;
gotcache = texcache_readtexheader(fn, picfillen, pal<<8, hicfxmask(pal), &cachead, 1); char hasalpha;
texcacheheader cachead;
int32_t gotcache = texcache_readtexheader(fn, picfillen, pal<<8, hicfxmask(pal), &cachead, 1);
vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };
if (gotcache && !texcache_loadskin(&cachead, &doalloc, texidx, &siz.x, &siz.y)) if (gotcache && !texcache_loadskin(&cachead, &doalloc, texidx, &siz))
{ {
osizx = cachead.xdim; tsiz.x = cachead.xdim;
osizy = cachead.ydim; tsiz.y = cachead.ydim;
hasalpha = !!(cachead.flags & CACHEAD_HASALPHA); hasalpha = !!(cachead.flags & CACHEAD_HASALPHA);
if (pal < (MAXPALOOKUPS - RESERVEDPALS)) if (pal < (MAXPALOOKUPS - RESERVEDPALS))
m->usesalpha = hasalpha; m->usesalpha = hasalpha;
//kclose(filh); // FIXME: uncomment when cache1d.c is fixed
} }
else else
{ {
int32_t ret; char const effect = hicfxmask(pal);
intptr_t fptr=0;
// CODEDUP: gloadtile_hi
int32_t isart = 0;
gotcache = 0; // the compressed version will be saved to disk gotcache = 0; // the compressed version will be saved to disk
if ((filh = kopen4load(fn, 0)) < 0) int32_t const length = kpzbufload(fn);
return -1; if (length == 0)
return mdloadskin_notfound(skinfile, fn);
ret = daskinloader(filh,&fptr,&bpl,&siz.x,&siz.y,&osizx,&osizy,&hasalpha,pal,hicfxmask(pal)); // tsizx/y = replacement texture's natural size
// xsiz/y = 2^x size of replacement
if (ret) #ifdef WITHKPLIB
kpgetdim(kpzbuf,picfillen,&tsiz.x,&tsiz.y);
#endif
if (tsiz.x == 0 || tsiz.y == 0)
{ {
kclose(filh); if (E_CheckUnitArtFileHeader((uint8_t *)kpzbuf, picfillen))
OSD_Printf("Failed loading skin file \"%s\": error %d\n", fn, ret); return mdloadskin_failed(skinfile, fn);
if (ret==-1)
QuitOnFatalError("OUT OF MEMORY in daskinloader!");
skinfile[0] = 0; tsiz.x = B_LITTLE16(B_UNBUF16(&kpzbuf[16]));
return(0); tsiz.y = B_LITTLE16(B_UNBUF16(&kpzbuf[18]));
if (tsiz.x == 0 || tsiz.y == 0)
return mdloadskin_failed(skinfile, fn);
isart = 1;
} }
else kclose(filh);
willprint = 1; if (!glinfo.texnpot)
{
for (siz.x=1; siz.x<tsiz.x; siz.x+=siz.x) { }
for (siz.y=1; siz.y<tsiz.y; siz.y+=siz.y) { }
}
else
siz = tsiz;
if (isart)
{
if (tsiz.x * tsiz.y + ARTv1_UNITOFFSET > picfillen)
return mdloadskin_failed(skinfile, fn);
}
int32_t const bytesperline = siz.x * sizeof(coltype);
coltype *pic = (coltype *)Xcalloc(siz.y, bytesperline);
static coltype *lastpic = NULL;
static char *lastfn = NULL;
static int32_t lastsize = 0;
if (lastpic && lastfn && !Bstrcmp(lastfn,fn))
{
willprint=1;
Bmemcpy(pic, lastpic, siz.x*siz.y*sizeof(coltype));
}
else
{
if (isart)
{
E_RenderArtDataIntoBuffer((palette_t *)pic, (uint8_t *)&kpzbuf[ARTv1_UNITOFFSET], siz.x, tsiz.x, tsiz.y);
}
#ifdef WITHKPLIB
else
{
if (kprender(kpzbuf,picfillen,(intptr_t)pic,bytesperline,siz.x,siz.y))
{
Bfree(pic);
return mdloadskin_failed(skinfile, fn);
}
}
#endif
willprint=2;
if (hicprecaching)
{
lastfn = fn; // careful...
if (!lastpic)
{
lastpic = (coltype *)Bmalloc(siz.x*siz.y*sizeof(coltype));
lastsize = siz.x*siz.y;
}
else if (lastsize < siz.x*siz.y)
{
Bfree(lastpic);
lastpic = (coltype *)Bmalloc(siz.x*siz.y*sizeof(coltype));
}
if (lastpic)
Bmemcpy(lastpic, pic, siz.x*siz.y*sizeof(coltype));
}
else if (lastpic)
{
DO_FREE_AND_NULL(lastpic);
lastfn = NULL;
lastsize = 0;
}
}
char *cptr = britable[gammabrightness ? 0 : curbrightness];
int32_t r = (glinfo.bgra) ? hictinting[pal].r : hictinting[pal].b;
int32_t g = hictinting[pal].g;
int32_t b = (glinfo.bgra) ? hictinting[pal].b : hictinting[pal].r;
char al = 255;
for (int32_t y = 0, j = 0; y < tsiz.y; ++y, j += siz.x)
{
coltype tcol, *rpptr = &pic[j];
for (int32_t x = 0; x < tsiz.x; ++x)
{
tcol.b = cptr[rpptr[x].b];
tcol.g = cptr[rpptr[x].g];
tcol.r = cptr[rpptr[x].r];
tcol.a = rpptr[x].a;
al &= rpptr[x].a;
if (effect & HICTINT_GRAYSCALE)
{
tcol.g = tcol.r = tcol.b = (uint8_t) ((tcol.b * GRAYSCALE_COEFF_RED) +
(tcol.g * GRAYSCALE_COEFF_GREEN) +
(tcol.r * GRAYSCALE_COEFF_BLUE));
}
if (effect & HICTINT_INVERT)
{
tcol.b = 255 - tcol.b;
tcol.g = 255 - tcol.g;
tcol.r = 255 - tcol.r;
}
if (effect & HICTINT_COLORIZE)
{
tcol.b = min((int32_t)((tcol.b) * r) >> 6, 255);
tcol.g = min((int32_t)((tcol.g) * g) >> 6, 255);
tcol.r = min((int32_t)((tcol.r) * b) >> 6, 255);
}
switch (effect & HICTINT_BLENDMASK)
{
case HICTINT_BLEND_SCREEN:
tcol.b = 255 - (((255 - tcol.b) * (255 - r)) >> 8);
tcol.g = 255 - (((255 - tcol.g) * (255 - g)) >> 8);
tcol.r = 255 - (((255 - tcol.r) * (255 - b)) >> 8);
break;
case HICTINT_BLEND_OVERLAY:
tcol.b = tcol.b < 128 ? (tcol.b * r) >> 7 : 255 - (((255 - tcol.b) * (255 - r)) >> 7);
tcol.g = tcol.g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
tcol.r = tcol.r < 128 ? (tcol.r * b) >> 7 : 255 - (((255 - tcol.r) * (255 - b)) >> 7);
break;
case HICTINT_BLEND_HARDLIGHT:
tcol.b = r < 128 ? (tcol.b * r) >> 7 : 255 - (((255 - tcol.b) * (255 - r)) >> 7);
tcol.g = g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
tcol.r = b < 128 ? (tcol.r * b) >> 7 : 255 - (((255 - tcol.r) * (255 - b)) >> 7);
break;
}
rpptr[x] = tcol;
}
}
hasalpha = (al != 255);
// mdloadskin doesn't duplicate npow2 texture pixels
if (!glinfo.bgra)
{
for (int32_t j = siz.x*siz.y - 1; j >= 0; j--)
swapchar(&pic[j].r, &pic[j].b);
}
if (pal < (MAXPALOOKUPS - RESERVEDPALS)) if (pal < (MAXPALOOKUPS - RESERVEDPALS))
m->usesalpha = hasalpha; m->usesalpha = hasalpha;
@ -892,22 +902,22 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
int32_t const texfmt = glinfo.bgra ? GL_BGRA : GL_RGBA; int32_t const texfmt = glinfo.bgra ? GL_BGRA : GL_RGBA;
uploadtexture((doalloc&1), siz, texfmt, (coltype *)fptr, siz, uploadtexture((doalloc&1), siz, texfmt, pic, siz,
DAMETH_HI | DAMETH_HI |
TO_DAMETH_NODOWNSIZE(sk->flags) | TO_DAMETH_NODOWNSIZE(sk->flags) |
TO_DAMETH_NOTEXCOMPRESS(sk->flags) | TO_DAMETH_NOTEXCOMPRESS(sk->flags) |
(hasalpha ? DAMETH_HASALPHA : 0)); (hasalpha ? DAMETH_HASALPHA : 0));
Bfree((void *)fptr); Bfree(pic);
} }
if (!m->skinloaded) if (!m->skinloaded)
{ {
if (siz.x != osizx || siz.y != osizy) if (siz.x != tsiz.x || siz.y != tsiz.y)
{ {
float fx, fy; float fx, fy;
fx = ((float)osizx)/((float)siz.x); fx = ((float)tsiz.x)/((float)siz.x);
fy = ((float)osizy)/((float)siz.y); fy = ((float)tsiz.y)/((float)siz.y);
if (m->mdnum == 2) if (m->mdnum == 2)
{ {
int32_t *lptr; int32_t *lptr;
@ -955,8 +965,8 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
// save off the compressed version // save off the compressed version
cachead.quality = (sk->flags & HICR_NODOWNSIZE) ? 0 : r_downsize; cachead.quality = (sk->flags & HICR_NODOWNSIZE) ? 0 : r_downsize;
cachead.xdim = osizx>>cachead.quality; cachead.xdim = tsiz.x>>cachead.quality;
cachead.ydim = osizy>>cachead.quality; cachead.ydim = tsiz.y>>cachead.quality;
cachead.flags = nonpow2*CACHEAD_NONPOW2 | (hasalpha ? CACHEAD_HASALPHA : 0) | cachead.flags = nonpow2*CACHEAD_NONPOW2 | (hasalpha ? CACHEAD_HASALPHA : 0) |
(sk->flags & HICR_NODOWNSIZE ? CACHEAD_NODOWNSIZE : 0); (sk->flags & HICR_NODOWNSIZE ? CACHEAD_NODOWNSIZE : 0);

View File

@ -1036,12 +1036,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
{ {
if (!hicr) return -1; if (!hicr) return -1;
coltype *pic = NULL;
char *fn; char *fn;
int32_t picfillen, filh;
int32_t startticks=0, willprint=0;
if (facen > 0) if (facen > 0)
{ {
@ -1058,17 +1053,19 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
fn = hicr->filename; fn = hicr->filename;
} }
int32_t filh;
if (EDUKE32_PREDICT_FALSE((filh = kopen4load(fn, 0)) < 0)) if (EDUKE32_PREDICT_FALSE((filh = kopen4load(fn, 0)) < 0))
{ {
OSD_Printf("hightile: %s (pic %d) not found\n", fn, dapic); OSD_Printf("hightile: %s (pic %d) not found\n", fn, dapic);
return -2; return -2;
} }
picfillen = kfilelength(filh); int32_t picfillen = kfilelength(filh);
kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c
char hasalpha = 255; int32_t startticks = getticks(), willprint = 0;
char hasalpha;
texcacheheader cachead; texcacheheader cachead;
int32_t gotcache = texcache_readtexheader(fn, picfillen+(dapalnum<<8), dameth, effect, &cachead, 0); int32_t gotcache = texcache_readtexheader(fn, picfillen+(dapalnum<<8), dameth, effect, &cachead, 0);
vec2_t siz = { 0, 0 }, tsiz = { 0, 0 }; vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };
@ -1077,12 +1074,12 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
{ {
tsiz.x = cachead.xdim; tsiz.x = cachead.xdim;
tsiz.y = cachead.ydim; tsiz.y = cachead.ydim;
hasalpha = (cachead.flags & CACHEAD_HASALPHA) ? 0 : 255; hasalpha = !!(cachead.flags & CACHEAD_HASALPHA);
} }
else else
{ {
int32_t r, g, b; // CODEDUP: mdloadskin
int32_t j, y;
int32_t isart = 0; int32_t isart = 0;
gotcache = 0; // the compressed version will be saved to disk gotcache = 0; // the compressed version will be saved to disk
@ -1129,9 +1126,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
} }
int32_t const bytesperline = siz.x * sizeof(coltype); int32_t const bytesperline = siz.x * sizeof(coltype);
pic = (coltype *)Xcalloc(siz.y, bytesperline); coltype *pic = (coltype *)Xcalloc(siz.y, bytesperline);
startticks = getticks();
static coltype *lastpic = NULL; static coltype *lastpic = NULL;
static char *lastfn = NULL; static char *lastfn = NULL;
@ -1185,25 +1180,25 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
} }
} }
r = (glinfo.bgra) ? hictinting[dapalnum].r : hictinting[dapalnum].b; char *cptr = britable[gammabrightness ? 0 : curbrightness];
g = hictinting[dapalnum].g;
b = (glinfo.bgra) ? hictinting[dapalnum].b : hictinting[dapalnum].r;
for (y = 0, j = 0; y < tsiz.y; y++, j += siz.x) int32_t r = (glinfo.bgra) ? hictinting[dapalnum].r : hictinting[dapalnum].b;
int32_t g = hictinting[dapalnum].g;
int32_t b = (glinfo.bgra) ? hictinting[dapalnum].b : hictinting[dapalnum].r;
char al = 255;
for (int32_t y = 0, j = 0; y < tsiz.y; ++y, j += siz.x)
{ {
coltype tcol; coltype tcol, *rpptr = &pic[j];
char *cptr = britable[gammabrightness ? 0 : curbrightness];
coltype *rpptr = &pic[j];
int32_t x; for (int32_t x = 0; x < tsiz.x; ++x)
for (x=0; x<tsiz.x; x++)
{ {
tcol.b = cptr[rpptr[x].b]; tcol.b = cptr[rpptr[x].b];
tcol.g = cptr[rpptr[x].g]; tcol.g = cptr[rpptr[x].g];
tcol.r = cptr[rpptr[x].r]; tcol.r = cptr[rpptr[x].r];
tcol.a = rpptr[x].a; tcol.a = rpptr[x].a;
hasalpha &= rpptr[x].a; al &= rpptr[x].a;
if (effect & HICTINT_GRAYSCALE) if (effect & HICTINT_GRAYSCALE)
{ {
@ -1249,13 +1244,13 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
} }
} }
hasalpha = (al != 255);
if ((!(dameth & DAMETH_CLAMPED)) || facen) //Duplicate texture pixels (wrapping tricks for non power of 2 texture sizes) if ((!(dameth & DAMETH_CLAMPED)) || facen) //Duplicate texture pixels (wrapping tricks for non power of 2 texture sizes)
{ {
if (siz.x > tsiz.x) // Copy left to right if (siz.x > tsiz.x) // Copy left to right
{ {
int32_t *lptr = (int32_t *)pic; for (int32_t y = 0, *lptr = (int32_t *)pic; y < tsiz.y; y++, lptr += siz.x)
for (y = 0; y < tsiz.y; y++, lptr += siz.x)
Bmemcpy(&lptr[tsiz.x], lptr, (siz.x - tsiz.x) << 2); Bmemcpy(&lptr[tsiz.x], lptr, (siz.x - tsiz.x) << 2);
} }
@ -1263,16 +1258,13 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
Bmemcpy(&pic[siz.x * tsiz.y], pic, (siz.y - tsiz.y) * siz.x << 2); Bmemcpy(&pic[siz.x * tsiz.y], pic, (siz.y - tsiz.y) * siz.x << 2);
} }
int32_t texfmt;
if (!glinfo.bgra) if (!glinfo.bgra)
{ {
texfmt = GL_RGBA; for (int32_t j = siz.x*siz.y - 1; j >= 0; j--)
for (j=siz.x*siz.y-1; j>=0; j--)
swapchar(&pic[j].r, &pic[j].b); swapchar(&pic[j].r, &pic[j].b);
} }
else texfmt = GL_BGRA;
// end CODEDUP
if (tsiz.x>>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y) if (tsiz.x>>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y)
hicr->flags |= (HICR_NODOWNSIZE + HICR_NOTEXCOMPRESS); hicr->flags |= (HICR_NODOWNSIZE + HICR_NOTEXCOMPRESS);
@ -1283,11 +1275,15 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
fixtransparency(pic,tsiz,siz,dameth); fixtransparency(pic,tsiz,siz,dameth);
int32_t const texfmt = glinfo.bgra ? GL_BGRA : GL_RGBA;
uploadtexture(doalloc,siz,texfmt,pic,tsiz, uploadtexture(doalloc,siz,texfmt,pic,tsiz,
dameth | DAMETH_HI | DAMETH_NOFIX | dameth | DAMETH_HI | DAMETH_NOFIX |
TO_DAMETH_NODOWNSIZE(hicr->flags) | TO_DAMETH_NODOWNSIZE(hicr->flags) |
TO_DAMETH_NOTEXCOMPRESS(hicr->flags) | TO_DAMETH_NOTEXCOMPRESS(hicr->flags) |
(hasalpha != 255 ? DAMETH_HASALPHA : 0)); (hasalpha ? DAMETH_HASALPHA : 0));
Bfree(pic);
} }
// precalculate scaling parameters for replacement // precalculate scaling parameters for replacement
@ -1304,8 +1300,6 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
polymost_setuptexture(dameth, hicr->flags & HICR_FORCEFILTER ? TEXFILTER_ON : -1); polymost_setuptexture(dameth, hicr->flags & HICR_FORCEFILTER ? TEXFILTER_ON : -1);
DO_FREE_AND_NULL(pic);
if (tsiz.x>>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y) if (tsiz.x>>r_downsize <= tilesiz[dapic].x || tsiz.y>>r_downsize <= tilesiz[dapic].y)
hicr->flags |= HICR_NODOWNSIZE | HICR_NOTEXCOMPRESS; hicr->flags |= HICR_NODOWNSIZE | HICR_NOTEXCOMPRESS;
@ -1313,7 +1307,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
pth->effects = effect; pth->effects = effect;
pth->flags = TO_PTH_CLAMPED(dameth) | TO_PTH_NOTRANSFIX(dameth) | pth->flags = TO_PTH_CLAMPED(dameth) | TO_PTH_NOTRANSFIX(dameth) |
PTH_HIGHTILE | ((facen>0) * PTH_SKYBOX) | PTH_HIGHTILE | ((facen>0) * PTH_SKYBOX) |
((hasalpha != 255) ? PTH_HASALPHA : 0) | (hasalpha ? PTH_HASALPHA : 0) |
(hicr->flags & HICR_FORCEFILTER ? PTH_FORCEFILTER : 0); (hicr->flags & HICR_FORCEFILTER ? PTH_FORCEFILTER : 0);
pth->skyface = facen; pth->skyface = facen;
pth->hicr = hicr; pth->hicr = hicr;
@ -1328,7 +1322,7 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
cachead.ydim = tsiz.y >> cachead.quality; cachead.ydim = tsiz.y >> cachead.quality;
// handle nodownsize: // handle nodownsize:
cachead.flags = nonpow2 * CACHEAD_NONPOW2 | (hasalpha != 255 ? CACHEAD_HASALPHA : 0) | cachead.flags = nonpow2 * CACHEAD_NONPOW2 | (hasalpha ? CACHEAD_HASALPHA : 0) |
(hicr->flags & HICR_NODOWNSIZE ? CACHEAD_NODOWNSIZE : 0); (hicr->flags & HICR_NODOWNSIZE ? CACHEAD_NODOWNSIZE : 0);
/// OSD_Printf("Caching \"%s\"\n", fn); /// OSD_Printf("Caching \"%s\"\n", fn);

View File

@ -701,7 +701,7 @@ static void texcache_setuptexture(int32_t *doalloc, GLuint *glpic)
bglBindTexture(GL_TEXTURE_2D,*glpic); bglBindTexture(GL_TEXTURE_2D,*glpic);
} }
static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int32_t *xsiz, int32_t *ysiz) static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr)
{ {
int32_t level = 0; int32_t level = 0;
texcachepicture pict; texcachepicture pict;
@ -727,12 +727,6 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int3
pict.border = B_LITTLE32(pict.border); pict.border = B_LITTLE32(pict.border);
pict.depth = B_LITTLE32(pict.depth); pict.depth = B_LITTLE32(pict.depth);
if (level == 0)
{
if (xsiz) *xsiz = pict.xdim;
if (ysiz) *ysiz = pict.ydim;
}
if (alloclen < pict.size) if (alloclen < pict.size)
{ {
pic = (char *)Xrealloc(pic, pict.size); pic = (char *)Xrealloc(pic, pict.size);
@ -783,16 +777,19 @@ static int32_t texcache_loadmips(const texcacheheader *head, GLenum *glerr, int3
return 0; return 0;
} }
int32_t texcache_loadskin(const texcacheheader *head, int32_t *doalloc, GLuint *glpic, int32_t *xsiz, int32_t *ysiz) int32_t texcache_loadskin(const texcacheheader *head, int32_t *doalloc, GLuint *glpic, vec2_t *siz)
{ {
int32_t err=0; int32_t err=0;
GLenum glerr=GL_NO_ERROR; GLenum glerr=GL_NO_ERROR;
texcache_setuptexture(doalloc, glpic); texcache_setuptexture(doalloc, glpic);
siz->x = head->xdim;
siz->y = head->ydim;
CLEAR_GL_ERRORS(); CLEAR_GL_ERRORS();
if ((err = texcache_loadmips(head, &glerr, xsiz, ysiz))) if ((err = texcache_loadmips(head, &glerr)))
{ {
if (err > 0) if (err > 0)
initprintf("texcache_loadskin: %s (glerr=%x)\n", texcache_errorstr[err], glerr); initprintf("texcache_loadskin: %s (glerr=%x)\n", texcache_errorstr[err], glerr);
@ -815,7 +812,7 @@ int32_t texcache_loadtile(const texcacheheader *head, int32_t *doalloc, pthtyp *
CLEAR_GL_ERRORS(); CLEAR_GL_ERRORS();
if ((err = texcache_loadmips(head, &glerr, NULL, NULL))) if ((err = texcache_loadmips(head, &glerr)))
{ {
if (err > 0) if (err > 0)
initprintf("texcache_loadtile: %s (glerr=%x)\n", texcache_errorstr[err], glerr); initprintf("texcache_loadtile: %s (glerr=%x)\n", texcache_errorstr[err], glerr);