From c050a0c4c896974e030e829499bd8a79aa56528a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 7 Oct 2019 00:34:15 +0200 Subject: [PATCH] - changed palswap management to handle the size of full lookup tables. --- source/build/src/polymost.cpp | 4 ++-- source/glbackend/gl_palmanager.cpp | 19 +++++++++++++++---- source/glbackend/glbackend.h | 11 +++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 6a71913bd..f22790fd6 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -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); } diff --git a/source/glbackend/gl_palmanager.cpp b/source/glbackend/gl_palmanager.cpp index 6d3003a36..997314e9b 100644 --- a/source/glbackend/gl_palmanager.cpp +++ b/source/glbackend/gl_palmanager.cpp @@ -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; diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 13dae1864..c18f5ca19 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -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)