- changed palswap management to handle the size of full lookup tables.

This commit is contained in:
Christoph Oelckers 2019-10-07 00:34:15 +02:00
parent 620897ecdd
commit c050a0c4c8
3 changed files with 24 additions and 10 deletions

View file

@ -376,7 +376,7 @@ void polymost_glinit()
palswapTextureID = 0;
for (int palookupnum = 0; palookupnum < MAXPALOOKUPS; ++palookupnum)
{
GLInterface.SetPalswapData(palookupnum, palookup[palookupnum]);
GLInterface.SetPalswapData(palookupnum, (uint8_t*)palookup[palookupnum], numshades+1);
}
GLInterface.UpdatePalswaps(256, numshades+1);
}
@ -708,7 +708,7 @@ void uploadpalswaps(int count, int32_t* swaps)
{
for (int i = 0; i < count; i++)
{
GLInterface.SetPalswapData(i, (uint8_t*)palookup[i]);
GLInterface.SetPalswapData(i, (uint8_t*)palookup[i], numshades + 1);
}
GLInterface.UpdatePalswaps(256, numshades + 1);
}

View file

@ -78,6 +78,10 @@ void PaletteManager::DeleteAll()
lastindex = -1;
memset(palettemap, 0, sizeof(palettemap));
memset(palswapmap, 0, sizeof(palswapmap));
memset(addshade, 0, sizeof(addshade));
memset(mulshade, 0, sizeof(mulshade));
numshades = 1;
}
@ -116,19 +120,19 @@ unsigned PaletteManager::FindPalette(const uint8_t *paldata)
unsigned PaletteManager::FindPalswap(const uint8_t* paldata)
{
auto crc32 = CalcCRC32(paldata, 256);
auto crc32 = CalcCRC32(paldata, 256 * numshades);
for (unsigned int i = 0; i < palswaps.Size(); i++)
{
if (crc32 == palswaps[i].crc32)
{
if (!memcmp(paldata, palswaps[i].swaps, 256))
if (!memcmp(paldata, palswaps[i].lookup, 256 * numshades))
{
return i;
}
}
}
PalswapData pd;
memcpy(pd.swaps, paldata, 256);
pd.lookup = paldata;
pd.crc32 = crc32;
return palswaps.Push(pd);
}
@ -208,16 +212,23 @@ void PaletteManager::BindPalette(int index)
//
//===========================================================================
void PaletteManager::SetPalswapData(int index, const uint8_t* data)
void PaletteManager::SetPalswapData(int index, const uint8_t* data, int numshades_)
{
// New palettes may only be added if declared transient or on startup.
// Otherwise this would require a renderer reset to flush out the textures affected by the change.
if (index < 0 || index > 255) return; // invalid index - ignore.
numshades = numshades_;
palswapmap[index] = FindPalswap(data);
}
//===========================================================================
//
//
//
//===========================================================================
void PaletteManager::UpdatePalswaps(int width, int height)
{
if (palswapTexture) delete palswapTexture;

View file

@ -34,7 +34,7 @@ struct PalShade
struct PalswapData
{
int32_t crc32;
uint8_t swaps[256];
const uint8_t *lookup; // points to the original data. This is static so no need to copy
};
enum
@ -47,7 +47,10 @@ class PaletteManager
// The current engine limit is 256 palettes and 256 palswaps.
uint32_t palettemap[256] = {};
uint32_t palswapmap[256] = {};
float addshade[256] = {};
float mulshade[256] = {};
uint32_t lastindex = ~0u;
int numshades = 1;
// Keep the short lived movie palettes out of the palette list for ease of maintenance.
// Since it is transient this doesn't need to be preserved if it changes, unlike the other palettes which need to be preserved as references for the texture management.
@ -70,7 +73,7 @@ public:
~PaletteManager();
void DeleteAll();
void SetPalette(int index, const uint8_t *data, bool transient);
void SetPalswapData(int index, const uint8_t* data);
void SetPalswapData(int index, const uint8_t* data, int numshades);
void UpdatePalswaps(int w, int h);
void BindPalette(int index);
@ -278,9 +281,9 @@ public:
palmanager.SetPalette(index, data, transient);
}
void SetPalswapData(int index, const uint8_t* data)
void SetPalswapData(int index, const uint8_t* data, int numshades)
{
palmanager.SetPalswapData(index, data);
palmanager.SetPalswapData(index, data, numshades);
}
void UpdatePalswaps(int w, int h)