diff --git a/source/build/include/palette.h b/source/build/include/palette.h index ae3557f5e..c9d0db980 100644 --- a/source/build/include/palette.h +++ b/source/build/include/palette.h @@ -54,7 +54,6 @@ enum }; extern uint8_t curbasepal; -extern FixedBitArray<256> FullbrightIndices; extern int32_t r_scenebrightness; struct palette_t diff --git a/source/build/src/palette.cpp b/source/build/src/palette.cpp index 6ba85fbfc..1c255d888 100644 --- a/source/build/src/palette.cpp +++ b/source/build/src/palette.cpp @@ -39,8 +39,6 @@ palette_t palookupfog[MAXPALOOKUPS]; // NOTE: g_noFloorPal[0] is irrelevant as it's never checked. int8_t g_noFloorPal[MAXPALOOKUPS]; -FixedBitArray<256> FullbrightIndices; - //========================================================================== // // Adds a palette to the global list of base palettes @@ -155,28 +153,7 @@ void paletteLoadFromDisk(void) void palettePostLoadTables(void) { globalpal = 0; - - auto lookup = paletteGetLookupTable(0); - ImageHelpers::SetPalette(GPalette.BaseColors); - - for (int c = 0; c < 255; ++c) // skipping transparent color - { - uint8_t index = lookup[c]; - PalEntry color = GPalette.BaseColors[index]; - - // don't consider black fullbright - if (color.isBlack()) continue; - - bool isbright = true; - for (int i = 1; i < numshades; i++) - if (lookup[i * 256 + c] != index) - { - isbright = false; - break; - } - - if (isbright) FullbrightIndices.Set(c); - } + GPalette.GenerateGlobalBrightmapFromColormap(paletteGetLookupTable(0), numshades); } //========================================================================== diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 50e3795fd..07e558365 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -290,7 +290,7 @@ void uploadbasepalette(int32_t basepalnum) basepalWFullBrightInfo[i*4+0] = remap->Palette[i].b; basepalWFullBrightInfo[i*4+1] = remap->Palette[i].g; basepalWFullBrightInfo[i*4+2] = remap->Palette[i].r; - basepalWFullBrightInfo[i*4+3] = 0-(FullbrightIndices[i] != 0); + basepalWFullBrightInfo[i * 4 + 3] = GPalette.GlobalBrightmap.Palette[i].r; // todo: get rid of this. } GLInterface.SetPaletteData(basepalnum, basepalWFullBrightInfo); diff --git a/source/common/engine/palettecontainer.cpp b/source/common/engine/palettecontainer.cpp index 41e9a01ba..8d36af246 100644 --- a/source/common/engine/palettecontainer.cpp +++ b/source/common/engine/palettecontainer.cpp @@ -53,6 +53,7 @@ FColorMatcher ColorMatcher; void PaletteContainer::Init(int numslots) // This cannot be a constructor!!! { Clear(); + HasGlobalBrightmap = false; // Make sure that index 0 is always the identity translation. FRemapTable remap; remap.MakeIdentity(); @@ -64,15 +65,17 @@ void PaletteContainer::Init(int numslots) // This cannot be a constructor!!! void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index) { + // Initialize all tables to the original palette. // At this point we do not care about the transparent index yet. for (int i = 0; i < 256; i++, colors += 3) { - BaseColors[i] = PalEntry(255, colors[0], colors[1], colors[2]); + uniqueRemaps[0]->Palette[i] = BaseColors[i] = RawColors[i] = PalEntry(255, colors[0], colors[1], colors[2]); Remap[i] = i; } uniqueRemaps[0]->MakeIdentity(); // update the identity remap. + // If the palette already has a transparent index, clear that color now if (transparent_index >= 0 && transparent_index <= 255) { BaseColors[transparent_index] = 0; @@ -85,8 +88,8 @@ void PaletteContainer::SetPalette(const uint8_t* colors, int transparent_index) // Find white and black from the original palette so that they can be // used to make an educated guess of the translucency % for a // translucency map. - WhiteIndex = BestColor((uint32_t*)BaseColors, 255, 255, 255, 0, 255); - BlackIndex = BestColor((uint32_t*)BaseColors, 0, 0, 0, 0, 255); + WhiteIndex = BestColor((uint32_t*)RawColors, 255, 255, 255, 0, 255); + BlackIndex = BestColor((uint32_t*)RawColors, 0, 0, 0, 0, 255); } @@ -240,6 +243,41 @@ int PaletteContainer::StoreTranslation(int slot, FRemapTable *remap) return AddTranslation(slot, remap); } +//=========================================================================== +// +// Examines the colormap to see if some of the colors have to be +// considered fullbright all the time. +// +//=========================================================================== + +void PaletteContainer::GenerateGlobalBrightmapFromColormap(const uint8_t *cmapdata, int numlevels) +{ + GlobalBrightmap.MakeIdentity(); + memset(GlobalBrightmap.Remap, WhiteIndex, 256); + for (int i = 0; i < 256; i++) GlobalBrightmap.Palette[i] = PalEntry(255, 255, 255, 255); + for (int j = 0; j < numlevels; j++) + { + for (int i = 0; i < 256; i++) + { + // the palette comparison should be for ==0 but that gives false positives with Heretic + // and Hexen. + uint8_t mappedcolor = cmapdata[i]; // consider colormaps which already remap the base level. + if (cmapdata[i + j * 256] != mappedcolor || (RawColors[mappedcolor].r < 10 && RawColors[mappedcolor].g < 10 && RawColors[mappedcolor].b < 10)) + { + GlobalBrightmap.Remap[i] = BlackIndex; + GlobalBrightmap.Palette[i] = PalEntry(255, 0, 0, 0); + } + } + } + for (int i = 0; i < 256; i++) + { + HasGlobalBrightmap |= GlobalBrightmap.Remap[i] == WhiteIndex; + if (GlobalBrightmap.Remap[i] == WhiteIndex) DPrintf(DMSG_NOTIFY, "Marked color %d as fullbright\n", i); + } +} + + + //---------------------------------------------------------------------------- // // diff --git a/source/common/engine/palettecontainer.h b/source/common/engine/palettecontainer.h index 7b7143bae..0abc00e26 100644 --- a/source/common/engine/palettecontainer.h +++ b/source/common/engine/palettecontainer.h @@ -71,10 +71,15 @@ class PaletteContainer { public: PalEntry BaseColors[256]; // non-gamma corrected palette + PalEntry RawColors[256]; // colors as read from the game data without the transparancy remap applied uint8_t Remap[256]; // remap original palette indices to in-game indices uint8_t WhiteIndex; // white in original palette index uint8_t BlackIndex; // black in original palette index + + bool HasGlobalBrightmap; + FRemapTable GlobalBrightmap; + private: FMemArena remapArena; TArray uniqueRemaps; @@ -90,6 +95,7 @@ public: void CopyTranslation(int dest, int src); int StoreTranslation(int slot, FRemapTable* remap); FRemapTable* TranslationToTable(int translation); + void GenerateGlobalBrightmapFromColormap(const uint8_t* cmapdata, int numlevels); void PushIdentityTable(int slot) { diff --git a/source/common/utility/basics.h b/source/common/utility/basics.h index 503d3ea7b..42ee9f414 100644 --- a/source/common/utility/basics.h +++ b/source/common/utility/basics.h @@ -57,6 +57,13 @@ using INTBOOL = int; using BITFIELD = uint32_t; +#if defined(_MSC_VER) +#define NOVTABLE __declspec(novtable) +#else +#define NOVTABLE +#endif + + #if defined(_MSC_VER) #define NOVTABLE __declspec(novtable) #else