fix to loading maps/models with fullbrights (sw)
fix a rare crash with HLBSP textures git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1660 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
87bf121760
commit
283c7f8454
7 changed files with 64 additions and 15 deletions
|
@ -344,6 +344,7 @@ void R_RestartRenderer_f (void);//this goes here so we can save some stack when
|
|||
|
||||
//used to live in glquake.h
|
||||
qbyte GetPalette(int red, int green, int blue);
|
||||
qbyte GetPaletteNoFB(int red, int green, int blue);
|
||||
extern cvar_t r_norefresh;
|
||||
extern cvar_t r_drawentities;
|
||||
extern cvar_t r_drawworld;
|
||||
|
|
|
@ -220,6 +220,7 @@ qbyte *Skin_Cache8 (skin_t *skin)
|
|||
if (out)
|
||||
return out;
|
||||
|
||||
// TODO: we build a fullbright remap.. can we get rid of this?
|
||||
#ifdef SWQUAKE
|
||||
if (qrenderer == QR_SOFTWARE && r_pixbytes == 1 && cls.allow_fbskins<0.2) //only time FB has to exist... (gl can be disabled)
|
||||
{
|
||||
|
|
|
@ -450,6 +450,12 @@ qbyte *W_GetTexture(char *name, int *width, int *height, qboolean *usesalpha)//r
|
|||
tex->height = LittleLong(tex->height);
|
||||
for (j = 0;j < MIPLEVELS;j++)
|
||||
tex->offsets[j] = LittleLong(tex->offsets[j]);
|
||||
|
||||
if (!strcmp(texname, "bn_painting3"))
|
||||
{
|
||||
int k = 0;
|
||||
}
|
||||
|
||||
data = W_ConvertWAD3Texture(tex, width, height, usesalpha); //this will add to the temp
|
||||
BZ_Free(tex);
|
||||
return data;
|
||||
|
|
|
@ -1063,7 +1063,7 @@ void *Mod_LoadWall(char *name)
|
|||
{
|
||||
for (i=0; i < tex->width*tex->height; i++) //downgrade colour
|
||||
{
|
||||
*out++ = GetPalette(in[0], in[1], in[2]);
|
||||
*out++ = GetPaletteNoFB(in[0], in[1], in[2]);
|
||||
in+=4;
|
||||
}
|
||||
|
||||
|
@ -1151,7 +1151,7 @@ void *Mod_LoadWall(char *name)
|
|||
{
|
||||
for (i=0; i < tex->width*tex->height; i++) //downgrade colour
|
||||
{
|
||||
*out++ = GetPalette(d_q28to24table[*in*3+0], d_q28to24table[*in*3+1], d_q28to24table[*in*3+2]);
|
||||
*out++ = GetPaletteNoFB(d_q28to24table[*in*3+0], d_q28to24table[*in*3+1], d_q28to24table[*in*3+2]);
|
||||
in++;
|
||||
}
|
||||
in = (qbyte *)tex+tex->offsets[0]; //shrink mips.
|
||||
|
|
|
@ -7,12 +7,14 @@
|
|||
|
||||
void MakeVideoPalette(void);
|
||||
void MakeSwizzledPalette(void);
|
||||
void MakeFullbrightRemap(void);
|
||||
|
||||
int *srctable;
|
||||
int *dsttable;
|
||||
qbyte *pal555to8;
|
||||
|
||||
int swzpal[TRANS_LEVELS][256];
|
||||
qbyte nofbremap[256];
|
||||
|
||||
#define palette host_basepal
|
||||
#define _abs(x) ((x)*(x))
|
||||
|
@ -22,6 +24,7 @@ void D_InitTrans(void)
|
|||
// create pal555to8 and swizzled palette
|
||||
MakeVideoPalette();
|
||||
MakeSwizzledPalette();
|
||||
MakeFullbrightRemap();
|
||||
|
||||
srctable = swzpal[0];
|
||||
dsttable = swzpal[TRANS_MAX];
|
||||
|
@ -105,6 +108,28 @@ qbyte FindIndexFromRGB(int red, int green, int blue)
|
|||
return best;
|
||||
}
|
||||
|
||||
qbyte FindIndexFromRGBNoFB(int red, int green, int blue)
|
||||
{
|
||||
int i, best=15;
|
||||
int bestdif=256*256*256, curdif;
|
||||
extern qbyte *host_basepal;
|
||||
qbyte *pa;
|
||||
|
||||
pa = host_basepal;
|
||||
for (i = 0; i < 256 - vid.fullbright; i++, pa+=3)
|
||||
{
|
||||
curdif = _abs(red - pa[0]) + _abs(green - pa[1]) + _abs(blue - pa[2]);
|
||||
if (curdif < bestdif)
|
||||
{
|
||||
if (curdif<1)
|
||||
return i;
|
||||
bestdif = curdif;
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
#define FindPalette(r,g,b) pal555to8[((r&0xF8)>>3)|((g&0xF8)<<2)|((b&0xF8)<<7)]
|
||||
qbyte GetPalette(int red, int green, int blue)
|
||||
{
|
||||
|
@ -114,6 +139,14 @@ qbyte GetPalette(int red, int green, int blue)
|
|||
return FindIndexFromRGB(red, green, blue);
|
||||
}
|
||||
|
||||
qbyte GetPaletteNoFB(int red, int green, int blue)
|
||||
{
|
||||
if (pal555to8) //fast precalculated (but ugly) method
|
||||
return nofbremap[FindPalette(red,green,blue)];
|
||||
else //slow, horrible (but accurate) method.
|
||||
return FindIndexFromRGBNoFB(red, green, blue);
|
||||
}
|
||||
|
||||
void MakeVideoPalette(void)
|
||||
{
|
||||
FILE *f;
|
||||
|
@ -168,6 +201,16 @@ void MakeSwizzledPalette(void)
|
|||
}
|
||||
}
|
||||
|
||||
void MakeFullbrightRemap(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256 - vid.fullbright; i++)
|
||||
nofbremap[i] = i;
|
||||
for (i = 256 - vid.fullbright; i < 256; i++)
|
||||
nofbremap[i] = FindIndexFromRGBNoFB(host_basepal[i*3], host_basepal[i*3+1], host_basepal[i*3+2]);
|
||||
}
|
||||
|
||||
void MediaSW_ShowFrame8bit(qbyte *framedata, int inwidth, int inheight, qbyte *palette)
|
||||
{
|
||||
int y, x;
|
||||
|
|
|
@ -125,7 +125,7 @@ mpic_t *SWDraw_SafeCachePic (char *extpath)
|
|||
dat->data[i] = 255;
|
||||
}
|
||||
else
|
||||
dat->data[i] = GetPalette(image[i*4], image[i*4+1], image[i*4+2]);
|
||||
dat->data[i] = GetPaletteNoFB(image[i*4], image[i*4+1], image[i*4+2]);
|
||||
}
|
||||
|
||||
BZ_Free(image);
|
||||
|
@ -160,7 +160,7 @@ mpic_t *SWDraw_SafeCachePic (char *extpath)
|
|||
dat->data[i] = 255;
|
||||
}
|
||||
else
|
||||
dat->data[i] = GetPalette(image[i*4], image[i*4+1], image[i*4+2]);
|
||||
dat->data[i] = GetPaletteNoFB(image[i*4], image[i*4+1], image[i*4+2]);
|
||||
}
|
||||
|
||||
BZ_Free(image);
|
||||
|
@ -195,7 +195,7 @@ mpic_t *SWDraw_SafeCachePic (char *extpath)
|
|||
dat->data[i] = 255;
|
||||
}
|
||||
else
|
||||
dat->data[i] = GetPalette(image[i*4], image[i*4+1], image[i*4+2]);
|
||||
dat->data[i] = GetPaletteNoFB(image[i*4], image[i*4+1], image[i*4+2]);
|
||||
}
|
||||
|
||||
BZ_Free(image);
|
||||
|
@ -325,7 +325,7 @@ mpic_t *SWDraw_MallocPic (char *path)
|
|||
((mpic_t*)dat)->height = height;
|
||||
((mpic_t*)dat)->flags = 0;
|
||||
for (i = 0; i < width*height; i++)
|
||||
dat->data[i] = GetPalette(image[i*4], image[i*4+1], image[i*4+2]);
|
||||
dat->data[i] = GetPaletteNoFB(image[i*4], image[i*4+1], image[i*4+2]);
|
||||
|
||||
BZ_Free(image);
|
||||
|
||||
|
|
|
@ -549,7 +549,7 @@ void SWMod_LoadTextures (lump_t *l)
|
|||
if (in[3] == 0)
|
||||
*out++ = 255;
|
||||
else
|
||||
*out++ = GetPalette(in[0], in[1], in[2]);
|
||||
*out++ = GetPaletteNoFB(in[0], in[1], in[2]);
|
||||
}
|
||||
|
||||
in = out-mt->width*mt->height; //shrink mips.
|
||||
|
@ -705,15 +705,13 @@ void SWMod_NowLoadExternal(void)
|
|||
qbyte *out;
|
||||
qboolean alphaed;
|
||||
unsigned int *out32;
|
||||
int width;
|
||||
int height;
|
||||
int t;
|
||||
for (t=0 ; t<loadmodel->numtextures ; t++)
|
||||
{
|
||||
tx = loadmodel->textures[t];
|
||||
if (tx && !tx->offsets[0])
|
||||
{
|
||||
in = W_GetTexture(tx->name, &width, &height, &alphaed);
|
||||
in = W_GetTexture(tx->name, &(tx->width), &(tx->height), &alphaed);
|
||||
i=0;
|
||||
tx->offsets[0] = sizeof(texture_t);
|
||||
tx->offsets[1] = tx->offsets[0] + tx->width*tx->pixbytes*tx->height;
|
||||
|
@ -774,7 +772,7 @@ void SWMod_NowLoadExternal(void)
|
|||
if (in[3] == 0)
|
||||
*out++ = 255;
|
||||
else
|
||||
*out++ = GetPalette(in[0], in[1], in[2]);
|
||||
*out++ = GetPaletteNoFB(in[0], in[1], in[2]);
|
||||
in += 4;
|
||||
}
|
||||
in = (qbyte *)tx+tx->offsets[0]; //shrink mips.
|
||||
|
@ -2781,7 +2779,7 @@ void SWMod_LoadAlias2Model (model_t *mod, void *buffer)
|
|||
{
|
||||
for (j = 0; j < skinsize; j++) //you know when you've been palettized.
|
||||
{
|
||||
skin[j+0] = GetPalette(texture[j*4+0], texture[j*4+1], texture[j*4+2]);
|
||||
skin[j+0] = GetPaletteNoFB(texture[j*4+0], texture[j*4+1], texture[j*4+2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3106,7 +3104,7 @@ void SWMod_LoadAlias3Model (model_t *mod, void *buffer)
|
|||
{
|
||||
for (j = 0; j < skinsize; j++) //you know when you've been palettized.
|
||||
{
|
||||
skin[j+0] = GetPalette(texture[j*4+0], texture[j*4+1], texture[j*4+2]);
|
||||
skin[j+0] = GetPaletteNoFB(texture[j*4+0], texture[j*4+1], texture[j*4+2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3293,7 +3291,7 @@ void * SWMod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int version)
|
|||
if (ppixin[i*4+3] < 128)
|
||||
ppixout[i] = 255; //transparent.
|
||||
else
|
||||
ppixout[i] = GetPalette(ppixin[i*4], ppixin[i*4+1], ppixin[i*4+2]);
|
||||
ppixout[i] = GetPaletteNoFB(ppixin[i*4], ppixin[i*4+1], ppixin[i*4+2]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -3593,7 +3591,7 @@ void SWMod_LoadSprite2Model (model_t *mod, void *buffer)
|
|||
if (!framedata[j*4+3]) //make sure
|
||||
frame->pixels[j] = 255;
|
||||
else
|
||||
frame->pixels[j] = GetPalette(framedata[j*4+0], framedata[j*4+1], framedata[j*4+2]);
|
||||
frame->pixels[j] = GetPaletteNoFB(framedata[j*4+0], framedata[j*4+1], framedata[j*4+2]);
|
||||
}
|
||||
}
|
||||
BZ_Free(framedata);
|
||||
|
|
Loading…
Reference in a new issue