- Discovered that Shader Model 1.4 clamps my constants, so I can't use

palettes smaller than 256 entries with the shader I wrote for it. Is there
  a list of gotchas like this listed some where? I'd really like to see it.
  
  Well, when compiled with SM2.0, the PalTex shader seems to be every-so-
  slightly faster on my GF7950GT than the SM1.4 version, so I guess it's a
  minor win for cards that support it.
- Fixed: ST_Endoom() failed to free the bitmap it used.
- Added the DTA_ColorOverlay attribute to blend a color with the texture
  being drawn. For software, this (currently) only works with black. For
  hardware, it works with any color. The motiviation for this was so I could
  rewrite the status bar calls that passed DIM_MAP to DTA_Translation to
  draw darker icons into something that didn't require making a whole new
  remap table.
- After having an "OMG! How could I have been so stupid?" moment, I have
  removed the off-by-one check from D3DFB. I had thought the off-by-one error
  was caused by rounding errors by the shader hardware. Not so. Rather, I
  wasn't sampling what I thought I was sampling. A texture that uses palette
  index 255 passes the value 1.0 to the shader. The shader needs to adjust the
  range of its palette indexes, or it will end up trying to read color 256
  from the palette texture when it should be reading color 255. Doh!
- The TranslationToTable() function has been added to map from translation
  numbers used by actors to the tables those numbers represent. This function
  performs validation for the input and returns NULL if the input value
  is invalid.
- Major changes to the way translation tables work: No longer are they each a
  256-byte array. Instead, the FRemapTable structure is used to represent each
  one. It includes a remap array for the software renderer, a palette array
  for a hardware renderer, and a native texture pointer for D3DFB. The
  translationtables array itself is now an array of TArrays that point to the
  real tables. The DTA_Translation attribute must also be passed a pointer
  to a FRemapTable, not a byte array as previously.
- Modified DFrameBuffer::DrawRateStuff() so that it can do its thing properly
  for D3DFB's 2D mode. Before, any fullscreen graphics (like help images)
  covered it up.


SVN r640 (trunk)
This commit is contained in:
Randy Heit 2007-12-26 04:42:15 +00:00
commit 1acc3d00c4
35 changed files with 1101 additions and 738 deletions

View file

@ -3,7 +3,7 @@
** Font management
**
**---------------------------------------------------------------------------
** Copyright 1998-2006 Randy Heit
** Copyright 1998-2008 Randy Heit
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
@ -52,6 +52,7 @@
#include "cmdlib.h"
#include "sc_man.h"
#include "hu_stuff.h"
#include "r_draw.h"
// MACROS ------------------------------------------------------------------
@ -263,8 +264,6 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
Chars = new CharData[count];
charlumps = new int[count];
PatchRemap = new BYTE[256];
Ranges = NULL;
PalRanges = NULL;
FirstChar = first;
LastChar = first + count - 1;
FontHeight = 0;
@ -334,7 +333,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
{
SpaceWidth = 4;
}
BuildTranslations (luminosity, identity, &TranslationParms[0][0]);
BuildTranslations (luminosity, identity, &TranslationParms[0][0], ActiveColors);
delete[] luminosity;
delete[] charlumps;
@ -362,16 +361,6 @@ FFont::~FFont ()
delete[] Chars;
Chars = NULL;
}
if (Ranges)
{
delete[] Ranges;
Ranges = NULL;
}
if (PalRanges)
{
delete[] PalRanges;
PalRanges = NULL;
}
if (PatchRemap)
{
delete[] PatchRemap;
@ -552,42 +541,40 @@ int FFont::SimpleTranslation (BYTE *colorsused, BYTE *translation, BYTE *reverse
//
//==========================================================================
void FFont::BuildTranslations (const double *luminosity, const BYTE *identity, const void *ranges)
void FFont::BuildTranslations (const double *luminosity, const BYTE *identity,
const void *ranges, int total_colors)
{
int i, j;
const TranslationParm *parmstart = (const TranslationParm *)ranges;
BYTE *range;
PalEntry *prange;
range = Ranges = new BYTE[NumTextColors * ActiveColors];
// this is padded so that each palette can be treated as if it had 256 colors
prange = PalRanges = new PalEntry[NumTextColors * ActiveColors + 256];
FRemapTable remap(total_colors);
// Create different translations for different color ranges
Ranges.Clear();
for (i = 0; i < NumTextColors; i++)
{
if (i == CR_UNTRANSLATED)
{
if (identity != NULL)
{
memcpy (range, identity, ActiveColors);
memcpy (remap.Remap, identity, ActiveColors);
for (j = 0; j < ActiveColors; ++j)
{
remap.Palette[j] = GPalette.BaseColors[identity[j]];
}
}
else
{
memcpy (range, Ranges, ActiveColors);
remap = Ranges[0];
}
for (j = 0; j < ActiveColors; j++)
{
*prange++ = GPalette.BaseColors[range[j]];
}
range += ActiveColors;
Ranges.Push(remap);
continue;
}
assert(parmstart->RangeStart >= 0);
*range++ = 0;
*prange++ = PalEntry(0);
remap.Remap[0] = 0;
remap.Palette[0] = 0;
for (j = 1; j < ActiveColors; j++)
{
@ -608,12 +595,13 @@ void FFont::BuildTranslations (const double *luminosity, const BYTE *identity, c
int r = ((parms->Start[0] << 8) + rangev * (parms->End[0] - parms->Start[0])) >> 8; // red
int g = ((parms->Start[1] << 8) + rangev * (parms->End[1] - parms->Start[1])) >> 8; // green
int b = ((parms->Start[2] << 8) + rangev * (parms->End[2] - parms->Start[2])) >> 8; // blue
r=clamp(r, 0, 255);
g=clamp(g, 0, 255);
b=clamp(b, 0, 255);
*range++ = ColorMatcher.Pick (r, g, b);
*prange++ = PalEntry(r, g, b);
r = clamp(r, 0, 255);
g = clamp(g, 0, 255);
b = clamp(b, 0, 255);
remap.Remap[j] = ColorMatcher.Pick(r, g, b);
remap.Palette[j] = PalEntry(255,r,g,b);
}
Ranges.Push(remap);
// Advance to the next color range.
while (parmstart[1].RangeStart > parmstart[0].RangeEnd)
@ -630,25 +618,15 @@ void FFont::BuildTranslations (const double *luminosity, const BYTE *identity, c
//
//==========================================================================
BYTE *FFont::GetColorTranslation (EColorRange range) const
FRemapTable *FFont::GetColorTranslation (EColorRange range) const
{
if (ActiveColors == 0)
return NULL;
else if (range >= NumTextColors)
range = CR_UNTRANSLATED;
return Ranges + ActiveColors * range;
return &Ranges[range];
}
PalEntry *FFont::GetTranslatedPalette (EColorRange range) const
{
if (ActiveColors == 0)
return NULL;
else if (range >= NumTextColors)
range = CR_UNTRANSLATED;
return PalRanges + ActiveColors * range;
}
//==========================================================================
//
// FFont :: GetChar
@ -725,8 +703,6 @@ int FFont::GetCharWidth (int code) const
FFont::FFont ()
{
Chars = NULL;
Ranges = NULL;
PalRanges = NULL;
PatchRemap = NULL;
Name = NULL;
}
@ -836,7 +812,7 @@ void FSingleLumpFont::LoadFON1 (int lump, const BYTE *data)
PatchRemap = new BYTE[256];
CheckFON1Chars (lump, data, luminosity);
BuildTranslations (luminosity, NULL, &TranslationParms[1][0]);
BuildTranslations (luminosity, NULL, &TranslationParms[1][0], ActiveColors);
}
//==========================================================================
@ -862,7 +838,6 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data)
FirstChar = data[6];
LastChar = data[7];
ActiveColors = data[10];
Ranges = NULL;
count = LastChar - FirstChar + 1;
Chars = new CharData[count];
@ -948,7 +923,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const BYTE *data)
}
}
BuildTranslations (luminosity, identity, &TranslationParms[0][0]);
BuildTranslations (luminosity, identity, &TranslationParms[0][0], ActiveColors);
delete[] widths2;
}
@ -1382,7 +1357,6 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, int *lumplis
Chars = new CharData[count];
charlumps = new int[count];
PatchRemap = new BYTE[256];
Ranges = NULL;
FirstChar = first;
LastChar = first + count - 1;
FontHeight = 0;
@ -1463,31 +1437,20 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, int *lumplis
SpaceWidth = 4;
}
BuildTranslations (luminosity, identity, &TranslationParms[0][0]);
BuildTranslations (luminosity, identity, &TranslationParms[0][0], TotalColors);
// add the untranslated colors to the Ranges table
// add the untranslated colors to the Ranges tables
if (ActiveColors < TotalColors)
{
int factor = 1;
BYTE *oldranges = Ranges;
PalEntry *oldpranges = PalRanges;
Ranges = new BYTE[NumTextColors * TotalColors]; // palette map + true color map + padding
PalRanges = new PalEntry[NumTextColors * TotalColors + 256]; // padded so that each palette can be treated as if it had 256 colors
for (i = 0; i < NumTextColors; i++)
{
memcpy(&Ranges [i * TotalColors], &oldranges [i * ActiveColors], ActiveColors);
memcpy(&PalRanges[i * TotalColors], &oldpranges[i * ActiveColors], ActiveColors*sizeof(PalEntry));
for(j=ActiveColors;j<TotalColors;j++)
FRemapTable *remap = &Ranges[i];
for (j = ActiveColors; j < TotalColors; ++j)
{
Ranges[TotalColors*i + j] = identity[j];
PalRanges[TotalColors*i + j] = GPalette.BaseColors[identity[j]];
remap->Remap[j] = identity[j];
remap->Palette[j] = GPalette.BaseColors[j];
}
}
delete[] oldranges;
delete[] oldpranges;
}
ActiveColors = TotalColors;