- remove colormap from texture generation parameters. The one remaining special case, alpha texture on old hardware is now handled by the currently set texture mode at the time of use.

- use the cleaned up decal lighting code from the first GLEW branch.
This commit is contained in:
Christoph Oelckers 2014-05-11 19:44:19 +02:00
commit 887d35d559
14 changed files with 131 additions and 289 deletions

View file

@ -50,12 +50,11 @@
//
//===========================================================================
template<class T>
void iCopyColors(unsigned char * pout, const unsigned char * pin, int cm, int count, int step)
void iCopyColors(unsigned char * pout, const unsigned char * pin, bool alphatex, int count, int step)
{
int i;
int fac;
if (cm == CM_DEFAULT)
if (!alphatex)
{
for(i=0;i<count;i++)
{
@ -70,7 +69,7 @@ void iCopyColors(unsigned char * pout, const unsigned char * pin, int cm, int co
pin+=step;
}
}
else if (cm == CM_SHADE)
else
{
// Alpha shade uses the red channel for true color pics
for(i=0;i<count;i++)
@ -84,40 +83,9 @@ void iCopyColors(unsigned char * pout, const unsigned char * pin, int cm, int co
pin+=step;
}
}
else if (cm >= CM_FIRSTSPECIALCOLORMAP && cm < CM_FIRSTSPECIALCOLORMAP + int(SpecialColormaps.Size()))
{
for(i=0;i<count;i++)
{
if (T::A(pin) != 0)
{
PalEntry pe = SpecialColormaps[cm - CM_FIRSTSPECIALCOLORMAP].GrayscaleToColor[T::Gray(pin)];
pout[0] = pe.r;
pout[1] = pe.g;
pout[2] = pe.b;
pout[3] = T::A(pin);
}
pout+=4;
pin+=step;
}
}
else if (cm<=CM_DESAT31)
{
// Desaturated light settings.
fac=cm-CM_DESAT0;
for(i=0;i<count;i++)
{
if (T::A(pin) != 0)
{
gl_Desaturate(T::Gray(pin), T::R(pin), T::G(pin), T::B(pin), pout[0], pout[1], pout[2], fac);
pout[3] = T::A(pin);
}
pout+=4;
pin+=step;
}
}
}
typedef void (*CopyFunc)(unsigned char * pout, const unsigned char * pin, int cm, int count, int step);
typedef void (*CopyFunc)(unsigned char * pout, const unsigned char * pin, bool alphatex, int count, int step);
static CopyFunc copyfuncs[]={
iCopyColors<cRGB>,
@ -147,57 +115,11 @@ void FGLBitmap::CopyPixelDataRGB(int originx, int originy,
BYTE *buffer = GetPixels() + 4*originx + Pitch*originy;
for (int y=0;y<srcheight;y++)
{
copyfuncs[ct](&buffer[y*Pitch], &patch[y*step_y], cm, srcwidth, step_x);
copyfuncs[ct](&buffer[y*Pitch], &patch[y*step_y], alphatex, srcwidth, step_x);
}
}
}
//===========================================================================
//
// Creates one of the special palette translations for the given palette
//
//===========================================================================
void ModifyPalette(PalEntry * pout, PalEntry * pin, int cm, int count)
{
int i;
int fac;
if (cm == CM_DEFAULT)
{
if (pin != pout)
memcpy(pout, pin, count * sizeof(PalEntry));
}
else if (cm >= CM_FIRSTSPECIALCOLORMAP && cm < CM_FIRSTSPECIALCOLORMAP + int(SpecialColormaps.Size()))
{
for(i=0;i<count;i++)
{
int gray = (pin[i].r*77 + pin[i].g*143 + pin[i].b*37) >> 8;
// This can be done in place so we cannot copy the color directly.
PalEntry pe = SpecialColormaps[cm - CM_FIRSTSPECIALCOLORMAP].GrayscaleToColor[gray];
pout[i].r = pe.r;
pout[i].g = pe.g;
pout[i].b = pe.b;
pout[i].a = pin[i].a;
}
}
else if (cm<=CM_DESAT31)
{
// Desaturated light settings.
fac=cm-CM_DESAT0;
for(i=0;i<count;i++)
{
int gray=(pin[i].r*77 + pin[i].g*143 + pin[i].b*36)>>8;
gl_Desaturate(gray, pin[i].r, pin[i].g, pin[i].b, pout[i].r, pout[i].g, pout[i].b, fac);
pout[i].a = pin[i].a;
}
}
else if (pin!=pout)
{
memcpy(pout, pin, count * sizeof(PalEntry));
}
}
//===========================================================================
//
// Paletted to True Color texture copy function
@ -215,7 +137,7 @@ void FGLBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int
BYTE *buffer = GetPixels() + 4*originx + Pitch*originy;
// CM_SHADE is an alpha map with 0==transparent and 1==opaque
if (cm == CM_SHADE)
if (alphatex)
{
for(int i=0;i<256;i++)
{
@ -225,37 +147,21 @@ void FGLBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int
penew[i]=PalEntry(0,255,255,255); // If the palette contains transparent colors keep them.
}
}
else
else if (translation > 0)
{
// apply any translation.
// The ice and blood color translations are done directly
// because that yields better results.
switch(translation)
PalEntry *ptrans = GLTranslationPalette::GetPalette(translation);
if (ptrans)
{
default:
{
PalEntry *ptrans = GLTranslationPalette::GetPalette(translation);
if (ptrans)
for (i = 0; i < 256; i++)
{
for(i = 0; i < 256; i++)
{
penew[i] = (ptrans[i]&0xffffff) | (palette[i]&0xff000000);
}
break;
penew[i] = (ptrans[i] & 0xffffff) | (palette[i] & 0xff000000);
}
}
case 0:
memcpy(penew, palette, 256*sizeof(PalEntry));
break;
}
if (cm!=0)
{
// Apply color modifications like invulnerability, desaturation and Boom colormaps
ModifyPalette(penew, penew, cm, 256);
}
}
// Now penew contains the actual palette that is to be used for creating the image.
else
{
memcpy(penew, palette, 256*sizeof(PalEntry));
}
// convert the image according to the translated palette.
for (y=0;y<srcheight;y++)
@ -271,15 +177,6 @@ void FGLBitmap::CopyPixelData(int originx, int originy, const BYTE * patch, int
buffer[pos+2] = penew[v].b;
buffer[pos+3] = penew[v].a;
}
/*
else if (penew[v].a!=255)
{
buffer[pos ] = (buffer[pos ] * penew[v].a + penew[v].r * (1-penew[v].a)) / 255;
buffer[pos+1] = (buffer[pos+1] * penew[v].a + penew[v].g * (1-penew[v].a)) / 255;
buffer[pos+2] = (buffer[pos+2] * penew[v].a + penew[v].b * (1-penew[v].a)) / 255;
buffer[pos+3] = clamp<int>(buffer[pos+3] + (( 255-buffer[pos+3]) * (255-penew[v].a))/255, 0, 255);
}
*/
}
}
}