- moved a large portion of gl_textures.cpp into the main files for the implementing classes.

The old organization made sense when ZDoom still was a thing but now it'd be better if all pure data with no dependence on renderer implementation details was moved out.
A separation between GL2 and GL3+4 renderers looks to be inevitable and the more data is out of the renderer when that happens, the better.
This commit is contained in:
Christoph Oelckers 2018-03-31 19:20:59 +02:00
commit bc485a7f2c
22 changed files with 681 additions and 533 deletions

View file

@ -163,14 +163,19 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset
{
return FTextureID(0);
}
i = HashFirst[MakeKey (name) % HASH_SIZE];
while (i != HASH_END)
for(i = HashFirst[MakeKey(name) % HASH_SIZE]; i != HASH_END; i = Textures[i].HashNext)
{
const FTexture *tex = Textures[i].Texture;
if (stricmp (tex->Name, name) == 0)
if (stricmp (tex->Name, name) == 0 )
{
// If we look for short names, we must ignore any long name texture.
if ((flags & TEXMAN_ShortNameOnly) && !tex->bFullNameTexture)
{
continue;
}
// The name matches, so check the texture type
if (usetype == ETextureType::Any)
{
@ -210,7 +215,6 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset
}
}
}
i = Textures[i].HashNext;
}
if ((flags & TEXMAN_TryAny) && usetype != ETextureType::Any)
@ -242,6 +246,7 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset
tex = FTexture::CreateTexture("", lump, ETextureType::Override);
if (tex != NULL)
{
tex->AddAutoMaterials();
Wads.SetLinkedTexture(lump, tex);
return AddTexture(tex);
}
@ -981,6 +986,7 @@ FTexture *CreateShaderTexture(bool, bool);
void FTextureManager::Init()
{
DeleteAll();
GenerateGlobalBrightmapFromColormap();
SpriteFrames.Clear();
//if (BuildTileFiles.Size() == 0) CountBuildTiles ();
FTexture::InitGrayMap();
@ -1045,6 +1051,11 @@ void FTextureManager::Init()
InitSwitchList();
InitPalettedVersions();
AdjustSpriteOffsets();
// Add auto materials to each texture after everything has been set up.
for (auto &tex : Textures)
{
tex.Texture->AddAutoMaterials();
}
}
//==========================================================================
@ -1057,7 +1068,6 @@ void FTextureManager::InitPalettedVersions()
{
int lump, lastlump = 0;
PalettedVersions.Clear();
while ((lump = Wads.FindLump("PALVERS", &lastlump)) != -1)
{
FScanner sc(lump);
@ -1077,7 +1087,10 @@ void FTextureManager::InitPalettedVersions()
}
if (pic1.isValid() && pic2.isValid())
{
PalettedVersions[pic1.GetIndex()] = pic2.GetIndex();
FTexture *owner = TexMan[pic1];
FTexture *owned = TexMan[pic2];
if (owner && owned) owner->PalVersion = owned;
}
}
}
@ -1089,12 +1102,13 @@ void FTextureManager::InitPalettedVersions()
//
//==========================================================================
// fixme: The way this is used, it is mostly useless.
FTextureID FTextureManager::PalCheck(FTextureID tex)
{
if (vid_nopalsubstitutions) return tex;
int *newtex = PalettedVersions.CheckKey(tex.GetIndex());
if (newtex == NULL || *newtex == 0) return tex;
return *newtex;
auto ftex = operator[](tex);
if (ftex != nullptr && ftex->PalVersion != nullptr) return ftex->PalVersion->id;
return tex;
}
//===========================================================================
@ -1292,6 +1306,55 @@ void FTextureManager::SpriteAdjustChanged()
}
}
//===========================================================================
//
// Examines the colormap to see if some of the colors have to be
// considered fullbright all the time.
//
//===========================================================================
void FTextureManager::GenerateGlobalBrightmapFromColormap()
{
Wads.CheckNumForFullName("textures/tgapal", false, 0, true);
HasGlobalBrightmap = false;
int lump = Wads.CheckNumForName("COLORMAP");
if (lump == -1) lump = Wads.CheckNumForName("COLORMAP", ns_colormaps);
if (lump == -1) return;
FMemLump cmap = Wads.ReadLump(lump);
uint8_t palbuffer[768];
ReadPalette(Wads.CheckNumForName("PLAYPAL"), palbuffer);
const unsigned char *cmapdata = (const unsigned char *)cmap.GetMem();
const uint8_t *paldata = palbuffer;
const int black = 0;
const int white = ColorMatcher.Pick(255, 255, 255);
GlobalBrightmap.MakeIdentity();
memset(GlobalBrightmap.Remap, white, 256);
for (int i = 0; i<256; i++) GlobalBrightmap.Palette[i] = PalEntry(255, 255, 255, 255);
for (int j = 0; j<32; j++)
{
for (int i = 0; i<256; i++)
{
// the palette comparison should be for ==0 but that gives false positives with Heretic
// and Hexen.
if (cmapdata[i + j * 256] != i || (paldata[3 * i]<10 && paldata[3 * i + 1]<10 && paldata[3 * i + 2]<10))
{
GlobalBrightmap.Remap[i] = black;
GlobalBrightmap.Palette[i] = PalEntry(255, 0, 0, 0);
}
}
}
for (int i = 0; i<256; i++)
{
HasGlobalBrightmap |= GlobalBrightmap.Remap[i] == white;
if (GlobalBrightmap.Remap[i] == white) DPrintf(DMSG_NOTIFY, "Marked color %d as fullbright\n", i);
}
}
//==========================================================================
//
//