2018-11-05 07:28:01 +00:00
|
|
|
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
|
|
|
|
// Ken Silverman's official web site: "http://www.advsys.net/ken"
|
|
|
|
// See the included license file "BUILDLIC.TXT" for license info.
|
|
|
|
//
|
|
|
|
// This file has been modified from Ken Silverman's original release
|
|
|
|
// by Jonathon Fowler (jf@jonof.id.au)
|
|
|
|
// by the EDuke32 team (development@voidpoint.com)
|
|
|
|
|
2016-06-21 00:33:06 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "build.h"
|
2016-09-17 19:57:58 +00:00
|
|
|
#include "engine_priv.h"
|
2016-09-16 21:55:21 +00:00
|
|
|
#include "baselayer.h"
|
2020-01-28 09:31:59 +00:00
|
|
|
#include "imagehelpers.h"
|
2019-12-17 22:25:07 +00:00
|
|
|
|
2016-06-21 00:33:06 +00:00
|
|
|
#include "palette.h"
|
2019-11-02 21:52:13 +00:00
|
|
|
#include "superfasthash.h"
|
2019-10-10 22:34:27 +00:00
|
|
|
#include "common.h"
|
2020-04-12 05:50:24 +00:00
|
|
|
#include "memarena.h"
|
|
|
|
#include "palettecontainer.h"
|
2020-04-12 05:51:11 +00:00
|
|
|
#include "palutil.h"
|
|
|
|
#include "colormatcher.h"
|
2020-05-23 12:40:54 +00:00
|
|
|
#include "m_swap.h"
|
2019-09-16 19:08:42 +00:00
|
|
|
#include "../../glbackend/glbackend.h"
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
// FString is a nice and convenient way to have automatically managed shared storage.
|
|
|
|
FString LookupTables[MAXPALOOKUPS];
|
2020-04-12 05:50:24 +00:00
|
|
|
|
2016-06-21 00:33:06 +00:00
|
|
|
uint8_t curbasepal;
|
|
|
|
int32_t globalblend;
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
PalEntry palfadergb;
|
2016-06-21 00:33:06 +00:00
|
|
|
|
|
|
|
#if defined(USE_OPENGL)
|
|
|
|
palette_t palookupfog[MAXPALOOKUPS];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For every pal number, whether tsprite pal should not be taken over from
|
|
|
|
// floor pal.
|
|
|
|
// NOTE: g_noFloorPal[0] is irrelevant as it's never checked.
|
|
|
|
int8_t g_noFloorPal[MAXPALOOKUPS];
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
FixedBitArray<256> FullbrightIndices;
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Adds a palette to the global list of base palettes
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2019-11-10 14:15:14 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
void paletteSetColorTable(int32_t id, uint8_t const* table, bool notransparency, bool twodonly)
|
2020-04-12 05:50:24 +00:00
|
|
|
{
|
|
|
|
if (id == 0)
|
|
|
|
{
|
|
|
|
GPalette.SetPalette(table, 255);
|
|
|
|
}
|
|
|
|
FRemapTable remap;
|
|
|
|
remap.AddColors(0, 256, table);
|
|
|
|
if (!notransparency)
|
|
|
|
{
|
|
|
|
remap.Palette[255] = 0;
|
|
|
|
remap.Remap[255] = 255;
|
|
|
|
}
|
2020-05-23 12:40:54 +00:00
|
|
|
remap.Inactive = twodonly; // use Inactive as a marker for the postprocessing so that for pure 2D palettes the creation of shade tables can be skipped.
|
2020-04-12 05:50:24 +00:00
|
|
|
GPalette.UpdateTranslation(TRANSLATION(Translation_BasePalettes, id), &remap);
|
|
|
|
|
|
|
|
// Todo: remove this once the texture code can use GPalette directly
|
|
|
|
#ifdef USE_OPENGL
|
|
|
|
uploadbasepalette(id);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
2016-06-21 00:33:06 +00:00
|
|
|
//
|
2020-05-23 12:40:54 +00:00
|
|
|
// loads the main palette file.
|
2016-06-21 00:33:06 +00:00
|
|
|
//
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
|
2018-04-12 21:03:12 +00:00
|
|
|
void paletteLoadFromDisk(void)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-04-12 05:50:24 +00:00
|
|
|
GPalette.Init(MAXPALOOKUPS + 1); // one slot for each translation, plus a separate one for the base palettes.
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2018-10-25 23:33:40 +00:00
|
|
|
for (auto & x : glblend)
|
|
|
|
x = defaultglblend;
|
2019-09-19 20:02:45 +00:00
|
|
|
|
2020-04-11 21:54:33 +00:00
|
|
|
auto fil = fileSystem.OpenFileReader("palette.dat");
|
2019-10-20 22:13:17 +00:00
|
|
|
if (!fil.isOpen())
|
2016-06-21 00:33:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// PALETTE_MAIN
|
|
|
|
|
2020-04-12 05:51:11 +00:00
|
|
|
uint8_t palette[768];
|
2019-10-20 22:13:17 +00:00
|
|
|
if (768 != fil.Read(palette, 768))
|
|
|
|
return;
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2018-10-25 23:33:40 +00:00
|
|
|
for (unsigned char & k : palette)
|
|
|
|
k <<= 2;
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
paletteSetColorTable(0, palette, false, false);
|
2016-06-21 00:33:06 +00:00
|
|
|
paletteloaded |= PALETTE_MAIN;
|
|
|
|
|
|
|
|
// PALETTE_SHADES
|
2020-05-23 12:40:54 +00:00
|
|
|
numshades = fil.ReadInt16();
|
2016-06-21 00:33:06 +00:00
|
|
|
|
|
|
|
if (numshades <= 1)
|
|
|
|
{
|
2020-04-11 21:45:45 +00:00
|
|
|
Printf("Warning: Invalid number of shades in \"palette.dat\"!\n");
|
2016-06-21 00:33:06 +00:00
|
|
|
numshades = 0;
|
2019-10-20 22:13:17 +00:00
|
|
|
return;
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
#if 0
|
|
|
|
// Reminder: Witchaven's shade table has no index and no easy means to autodetect.
|
|
|
|
if (numshades == 0 && (g_gameType & GAMEFLAG_WITCHAVEN))
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
numshades = 32;
|
|
|
|
fil.Seek(-2, FileReader::SeekCur);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
// LameDuke's is yet another variant.
|
|
|
|
if (numshades >= 256)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
uint16_t temp = fil.ReadUInt16();
|
|
|
|
if (temp == 770 || numshades > 256) // 02 03
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
fil.Seek(-4, FileReader::SeekCur);
|
|
|
|
numshades = 32;
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
2020-05-23 12:40:54 +00:00
|
|
|
else
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
fil.Seek(-2, FileReader::SeekCur);
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
|
2020-04-12 05:48:23 +00:00
|
|
|
// Read base shade table (lookuptables 0).
|
2020-05-23 12:40:54 +00:00
|
|
|
int length = numshades * 256;
|
|
|
|
auto p = LookupTables[0].LockNewBuffer(length);
|
|
|
|
auto count = fil.Read(p, length);
|
|
|
|
LookupTables->UnlockBuffer();
|
|
|
|
if (count != length)
|
2019-10-20 22:13:17 +00:00
|
|
|
return;
|
2016-06-21 00:33:06 +00:00
|
|
|
|
|
|
|
paletteloaded |= PALETTE_SHADE;
|
|
|
|
paletteloaded |= PALETTE_TRANSLUC;
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// postprocess the palette data after everything has been loaded
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2018-04-12 21:03:12 +00:00
|
|
|
void palettePostLoadTables(void)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
|
|
|
globalpal = 0;
|
2016-09-17 19:57:58 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
auto lookup = (const uint8_t*)LookupTables[0].GetChars();
|
2020-04-12 05:51:11 +00:00
|
|
|
ImageHelpers::SetPalette(GPalette.BaseColors);
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
for (int c = 0; c < 255; ++c) // skipping transparent color
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
uint8_t index = lookup[c];
|
2020-04-12 05:51:11 +00:00
|
|
|
PalEntry color = GPalette.BaseColors[index];
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
// don't consider black fullbright
|
|
|
|
if (color.isBlack()) continue;
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
bool isbright = true;
|
|
|
|
for (int i = 1; i < numshades; i++)
|
|
|
|
if (lookup[i * 256 + c] != index)
|
|
|
|
{
|
|
|
|
isbright = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
if (isbright) FullbrightIndices.Set(c);
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Ensure that all lookups map 255 to itself to preserve transparency.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-04-12 21:03:12 +00:00
|
|
|
void paletteFixTranslucencyMask(void)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
for (auto &thispalookup : LookupTables)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
if (thispalookup.IsEmpty())
|
2016-06-21 00:33:06 +00:00
|
|
|
continue;
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
for (int j = 0; j < numshades; j++)
|
|
|
|
{
|
|
|
|
auto p = thispalookup.LockBuffer();
|
|
|
|
p[(j << 8) + 255] = 255;
|
|
|
|
thispalookup.UnlockBuffer();
|
|
|
|
}
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
2016-06-21 00:33:06 +00:00
|
|
|
//
|
2020-05-23 12:40:54 +00:00
|
|
|
// load the lookup tables from lookup.dat
|
2016-06-21 00:33:06 +00:00
|
|
|
//
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
|
2019-10-20 20:26:53 +00:00
|
|
|
int32_t paletteLoadLookupTable(FileReader &fp)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
|
|
|
char remapbuf[256];
|
2020-05-23 12:40:54 +00:00
|
|
|
int numlookups = fp.ReadUInt8();
|
|
|
|
if (numlookups < 1)
|
2016-06-21 00:33:06 +00:00
|
|
|
return -1;
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
for (int j=0; j<numlookups; j++)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
int palnum = fp.ReadUInt8();
|
2016-06-21 00:33:06 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
if (256 != fp.Read(remapbuf, 256))
|
2016-06-21 00:33:06 +00:00
|
|
|
return -1;
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
if (palnum >= 256 - RESERVEDPALS)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-04-11 21:45:45 +00:00
|
|
|
Printf("ERROR: attempt to load lookup at reserved pal %d\n", palnum);
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
2020-05-23 12:40:54 +00:00
|
|
|
else
|
|
|
|
paletteMakeLookupTable(palnum, remapbuf, 0, 0, 0, 0);
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Find a gap of four consecutive unused pal numbers to generate fog shade tables.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-04-12 21:03:12 +00:00
|
|
|
void paletteSetupDefaultFog(void)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
for (int j = 1; j <= 255 - 3; j++)
|
|
|
|
{
|
|
|
|
if (!LookupTables[j].IsEmpty() && !LookupTables[j + 1].IsEmpty() && !LookupTables[j + 2].IsEmpty() && !LookupTables[j + 3].IsEmpty())
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2018-04-12 21:03:12 +00:00
|
|
|
paletteMakeLookupTable(j, NULL, 60, 60, 60, 1);
|
2020-05-23 12:40:54 +00:00
|
|
|
paletteMakeLookupTable(j + 1, NULL, 60, 0, 0, 1);
|
|
|
|
paletteMakeLookupTable(j + 2, NULL, 0, 60, 0, 1);
|
|
|
|
paletteMakeLookupTable(j + 3, NULL, 0, 0, 60, 1);
|
2016-06-21 00:33:06 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// post process the lookup tables once everything has been loaded
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-10-09 07:55:23 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
void palettePostLoadLookups(void)
|
2019-12-29 20:36:21 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
int numpalettes = GPalette.NumTranslations(Translation_BasePalettes);
|
|
|
|
if (numpalettes == 0) return;
|
|
|
|
auto basepalette = GPalette.GetTranslation(Translation_BasePalettes, 0);
|
2016-10-09 07:55:23 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
for (int l = 0; l < MAXPALOOKUPS; l++)
|
2019-12-29 20:36:21 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
if (!LookupTables[l].IsEmpty())
|
|
|
|
{
|
|
|
|
const uint8_t* lookup = (uint8_t*)LookupTables[l].GetChars();
|
|
|
|
FRemapTable remap;
|
|
|
|
for (int i = 0; i < numpalettes; i++)
|
|
|
|
{
|
|
|
|
auto palette = GPalette.GetTranslation(Translation_BasePalettes, i);
|
|
|
|
if (!palette) continue;
|
|
|
|
if (i == 0 || (palette != basepalette && !palette->Inactive))
|
|
|
|
{
|
|
|
|
memcpy(remap.Remap, lookup, 256);
|
|
|
|
for (int j = 0; j < 256; j++)
|
|
|
|
{
|
|
|
|
remap.Palette[j] = palette->Palette[remap.Remap[j]];
|
|
|
|
}
|
|
|
|
remap.NumEntries = 256;
|
|
|
|
GPalette.UpdateTranslation(TRANSLATION(i + 1, l), &remap);
|
|
|
|
}
|
|
|
|
if (palette != basepalette) palette->Inactive = false; // clear the marker flag
|
|
|
|
}
|
|
|
|
}
|
2019-12-29 20:36:21 +00:00
|
|
|
}
|
2020-05-23 12:40:54 +00:00
|
|
|
// todo: at this point we should swap colors 0 and 255 so that paletted images being created here have their transparent color at index 0.
|
2016-10-09 07:55:23 +00:00
|
|
|
}
|
2019-12-29 20:36:21 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// set a lookup table from external data
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-10-09 07:55:23 +00:00
|
|
|
|
2018-04-12 21:03:12 +00:00
|
|
|
int32_t paletteSetLookupTable(int32_t palnum, const uint8_t *shtab)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
|
|
|
if (shtab != NULL)
|
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
int length = numshades * 256;
|
|
|
|
auto p = LookupTables[palnum].LockNewBuffer(length);
|
|
|
|
memcpy(p, shtab, length);
|
|
|
|
LookupTables->UnlockBuffer();
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-04-12 21:03:12 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
2016-06-21 00:33:06 +00:00
|
|
|
//
|
2020-05-23 12:40:54 +00:00
|
|
|
// creates a lookup table from scratch
|
2016-06-21 00:33:06 +00:00
|
|
|
//
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
|
2018-04-12 21:03:12 +00:00
|
|
|
void paletteMakeLookupTable(int32_t palnum, const char *remapbuf, uint8_t r, uint8_t g, uint8_t b, char noFloorPal)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
char idmap[256];
|
2016-06-21 00:33:06 +00:00
|
|
|
|
|
|
|
// NOTE: palnum==0 is allowed
|
2020-05-23 12:40:54 +00:00
|
|
|
if (paletteloaded == 0 || (unsigned)palnum >= MAXPALOOKUPS)
|
2016-06-21 00:33:06 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_noFloorPal[palnum] = noFloorPal;
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
if (remapbuf == nullptr)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
if (r == 0 || g == 0 || b == 0)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
LookupTables[palnum] = ""; // clear this entry so that later it can be filled with the base remap.
|
2016-06-21 00:33:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
for (int i = 0; i < 256; i++) idmap[i] = i;
|
2016-06-21 00:33:06 +00:00
|
|
|
remapbuf = idmap;
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
int length = numshades * 256;
|
|
|
|
auto p = LookupTables[palnum].LockNewBuffer(length);
|
|
|
|
if (r == 0 || g == 0 || b == 0)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
|
|
|
// "black fog"/visibility case -- only remap color indices
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
auto src = (const uint8_t*)LookupTables[0].GetChars();
|
|
|
|
|
|
|
|
for (int j = 0; j < numshades; j++)
|
|
|
|
for (int i = 0; i < 256; i++)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
p[256 * j + i] = src[256 * j + remapbuf[i]];
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// colored fog case
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
for (int i = 0; i < numshades; i++)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
for (int j = 0; j < 256; j++)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-04-12 05:51:11 +00:00
|
|
|
PalEntry pe = GPalette.BaseColors[remapbuf[j]];
|
2020-05-23 12:40:54 +00:00
|
|
|
p[j] = ColorMatcher.Pick(
|
|
|
|
pe.r + Scale(r - pe.r, i, numshades - 1),
|
|
|
|
pe.g + Scale(g - pe.g, i, numshades - 1),
|
|
|
|
pe.b + Scale(b - pe.b, i, numshades - 1));
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(USE_OPENGL)
|
|
|
|
palookupfog[palnum].r = r;
|
|
|
|
palookupfog[palnum].g = g;
|
|
|
|
palookupfog[palnum].b = b;
|
2019-11-10 20:11:17 +00:00
|
|
|
palookupfog[palnum].f = 1;
|
2016-06-21 00:33:06 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
|
|
|
|
void videoSetPalette(int dabrightness, int palid, ESetPalFlags flags)
|
|
|
|
{
|
|
|
|
curbasepal = (GPalette.GetTranslation(Translation_BasePalettes, palid) == nullptr)? 0 : palid;
|
|
|
|
if ((flags & Pal_DontResetFade) == 0) palfadergb = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
2016-06-21 00:33:06 +00:00
|
|
|
//
|
2020-05-23 12:40:54 +00:00
|
|
|
// map Build blend definitions to actual render style / alpha combos.
|
2016-06-21 00:33:06 +00:00
|
|
|
//
|
2020-05-23 12:40:54 +00:00
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
glblend_t const nullglblend =
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
{
|
|
|
|
{ 1.f, STYLEALPHA_One, STYLEALPHA_Zero, 0 },
|
|
|
|
{ 1.f, STYLEALPHA_One, STYLEALPHA_Zero, 0 },
|
|
|
|
},
|
|
|
|
};
|
|
|
|
glblend_t const defaultglblend =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ 2.f / 3.f, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 },
|
|
|
|
{ 1.f / 3.f, STYLEALPHA_Src, STYLEALPHA_InvSrc, 0 },
|
|
|
|
},
|
|
|
|
};
|
2019-10-10 18:28:41 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
glblend_t glblend[MAXBLENDTABS];
|
2020-01-26 09:58:00 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
FRenderStyle GetRenderStyle(int blend, int def)
|
|
|
|
{
|
|
|
|
FRenderStyle rs;
|
|
|
|
rs.BlendOp = STYLEOP_Add;
|
|
|
|
auto glbdef = &glblend[blend].def[def];
|
|
|
|
rs.SrcAlpha = glbdef->src;
|
|
|
|
rs.DestAlpha = glbdef->dst;
|
|
|
|
rs.Flags = 0;
|
|
|
|
return rs;
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
void SetRenderStyleFromBlend(uint8_t enable, uint8_t blend, uint8_t def)
|
2016-06-21 00:33:06 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
if (!enable)
|
|
|
|
{
|
|
|
|
GLInterface.SetRenderStyle(LegacyRenderStyles[STYLE_Translucent]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto rs = GetRenderStyle(blend, def);
|
|
|
|
GLInterface.SetRenderStyle(rs);
|
2016-06-21 00:33:06 +00:00
|
|
|
}
|
2020-04-12 05:44:55 +00:00
|
|
|
|
2020-05-23 12:40:54 +00:00
|
|
|
float GetAlphaFromBlend(uint32_t method, uint32_t blend)
|
2020-04-12 05:44:55 +00:00
|
|
|
{
|
2020-05-23 12:40:54 +00:00
|
|
|
return method == DAMETH_TRANS1 || method == DAMETH_TRANS2 ? glblend[blend].def[method - DAMETH_TRANS1].alpha : 1.f;
|
|
|
|
}
|