- reworking some lower level texture code.

This commit is contained in:
Christoph Oelckers 2020-04-14 20:45:26 +02:00
parent 72835c5462
commit 9099bc8420
21 changed files with 76 additions and 61 deletions

View file

@ -1081,16 +1081,17 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FTextureID &value, FTe
}
FTextureID chk = value;
if (chk.GetIndex() >= TexMan.NumTextures()) chk.SetNull();
FTexture *pic = TexMan.GetTexture(chk);
auto pic = TexMan.GetGameTexture(chk);
const char *name;
auto lump = pic->GetSourceLump();
if (fileSystem.GetLinkedTexture(pic->SourceLump) == pic)
if (fileSystem.GetLinkedTexture(lump) == pic)
{
name = fileSystem.GetFileFullName(pic->SourceLump);
name = fileSystem.GetFileFullName(lump);
}
else
{
name = pic->Name;
name = pic->GetName();
}
arc.WriteKey(key);
arc.w->StartArray();

View file

@ -57,7 +57,7 @@ extern FILE* hashfile;
struct FileSystem::LumpRecord
{
FResourceLump *lump;
FTexture* linkedTexture;
FGameTexture* linkedTexture;
LumpShortName shortName;
FString longName;
int rfnum;
@ -725,7 +725,7 @@ int FileSystem::GetResource (int resid, const char *type, int filenum) const
//
//==========================================================================
void FileSystem::SetLinkedTexture(int lump, FTexture *tex)
void FileSystem::SetLinkedTexture(int lump, FGameTexture *tex)
{
if ((size_t)lump < NumEntries)
{
@ -739,7 +739,7 @@ void FileSystem::SetLinkedTexture(int lump, FTexture *tex)
//
//==========================================================================
FTexture *FileSystem::GetLinkedTexture(int lump)
FGameTexture *FileSystem::GetLinkedTexture(int lump)
{
if ((size_t)lump < NumEntries)
{

View file

@ -16,7 +16,7 @@
class FResourceFile;
struct FResourceLump;
class FTexture;
class FGameTexture;
union LumpShortName
{
@ -124,8 +124,8 @@ public:
inline int CheckNumForFullName (const FString &name, int wadfile) { return CheckNumForFullName(name.GetChars(), wadfile); }
inline int GetNumForFullName (const FString &name) { return GetNumForFullName(name.GetChars()); }
void SetLinkedTexture(int lump, FTexture *tex);
FTexture *GetLinkedTexture(int lump);
void SetLinkedTexture(int lump, FGameTexture *tex);
FGameTexture *GetLinkedTexture(int lump);
void ReadFile (int lump, void *dest);

View file

@ -19,7 +19,6 @@ struct LumpFilterInfo
};
class FResourceFile;
class FTexture;
// [RH] Namespaces from BOOM.
// These are needed here in the low level part so that WAD files can be properly set up.

View file

@ -39,6 +39,7 @@
#include "name.h"
class DCanvas;
class FTexture;
class FGameTexture;
struct FRemapTable;

View file

@ -53,7 +53,7 @@ static void CastCo2S(FString *a, int b) { PalEntry c(b); a->Format("%02x %02x %0
static int CastS2So(FString *b) { return FSoundID(*b); }
static void CastSo2S(FString* a, int b) { *a = soundEngine->GetSoundName(b); }
static void CastSID2S(FString* a, unsigned int b) { VM_CastSpriteIDToString(a, b); }
static void CastTID2S(FString *a, int b) { auto tex = TexMan.GetTexture(*(FTextureID*)&b); *a = (tex == nullptr) ? "(null)" : tex->GetName().GetChars(); }
static void CastTID2S(FString *a, int b) { auto tex = TexMan.GetGameTexture(*(FTextureID*)&b); *a = (tex == nullptr) ? "(null)" : tex->GetName().GetChars(); }
void JitCompiler::EmitCAST()
{

View file

@ -1848,7 +1848,7 @@ static void DoCast(const VMRegisters &reg, const VMFrame *f, int a, int b, int c
case CAST_TID2S:
{
ASSERTS(a); ASSERTD(b);
auto tex = TexMan.GetTexture(*(FTextureID*)&(reg.d[b]));
auto tex = TexMan.GetGameTexture(*(FTextureID*)&(reg.d[b]));
reg.s[a] = tex == nullptr ? "(null)" : tex->GetName().GetChars();
break;
}

View file

@ -356,7 +356,7 @@ void FMultipatchTextureBuilder::AddTexturesLump(const void *lumpdata, int lumpsi
// It still needs to be created in case someone uses it by name.
offset = LittleLong(directory[1]);
const maptexture_t *tex = (const maptexture_t *)((const uint8_t *)maptex + offset);
FTexture *tex0 = TexMan.ByIndex(0);
auto tex0 = TexMan.GameByIndex(0);
tex0->SetSize(SAFESHORT(tex->width), SAFESHORT(tex->height));
}
@ -373,7 +373,7 @@ void FMultipatchTextureBuilder::AddTexturesLump(const void *lumpdata, int lumpsi
int j;
for (j = (int)TexMan.NumTextures() - 1; j >= firstdup; --j)
{
if (strnicmp(TexMan.ByIndex(j)->GetName(), (const char *)maptex + offset, 8) == 0)
if (strnicmp(TexMan.GameByIndex(j)->GetName(), (const char *)maptex + offset, 8) == 0)
break;
}
if (j + 1 == firstdup)
@ -780,7 +780,7 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo)
TexMan.ListTextures(buildinfo.Inits[i].TexName, list, true);
for (int i = list.Size() - 1; i >= 0; i--)
{
if (list[i] != buildinfo.tex->id && !TexMan.GetTexture(list[i])->bMultiPatch)
if (list[i] != buildinfo.tex->id && !TexMan.GetGameTexture(list[i])->isMultiPatch() )
{
texno = list[i];
break;

View file

@ -148,8 +148,8 @@ FTexture::FTexture (const char *name, int lumpnum)
FTexture::~FTexture ()
{
FTexture *link = fileSystem.GetLinkedTexture(SourceLump);
if (link == this) fileSystem.SetLinkedTexture(SourceLump, nullptr);
FGameTexture *link = fileSystem.GetLinkedTexture(SourceLump);
if (link->GetTexture() == this) fileSystem.SetLinkedTexture(SourceLump, nullptr);
if (areas != nullptr) delete[] areas;
areas = nullptr;

View file

@ -220,20 +220,20 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset
// Any graphic being placed in the zip's root directory can not be found by this.
if (strchr(name, '/'))
{
FTexture *const NO_TEXTURE = (FTexture*)-1;
FGameTexture *const NO_TEXTURE = (FGameTexture*)-1;
int lump = fileSystem.CheckNumForFullName(name);
if (lump >= 0)
{
FTexture *tex = fileSystem.GetLinkedTexture(lump);
FGameTexture *tex = fileSystem.GetLinkedTexture(lump);
if (tex == NO_TEXTURE) return FTextureID(-1);
if (tex != NULL) return tex->id;
if (tex != NULL) return tex->GetID();
if (flags & TEXMAN_DontCreate) return FTextureID(-1); // we only want to check, there's no need to create a texture if we don't have one yet.
tex = FTexture::CreateTexture("", lump, ETextureType::Override);
tex = reinterpret_cast<FGameTexture*>(FTexture::CreateTexture("", lump, ETextureType::Override));
if (tex != NULL)
{
tex->AddAutoMaterials();
fileSystem.SetLinkedTexture(lump, tex);
return AddTexture(tex);
return AddTexture(tex->GetTexture());
}
else
{

View file

@ -618,11 +618,13 @@ public:
bool isHardwareCanvas() const { return wrapped.isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later.
bool isSoftwareCanvas() const { return wrapped.isCanvas(); }
bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not.
bool isMultiPatch() const { return wrapped.bMultiPatch; }
bool isFullbrightDisabled() const { return wrapped.isFullbrightDisabled(); }
bool useWorldPanning() const { return wrapped.UseWorldPanning(); }
bool allowNoDecals() const { return wrapped.allowNoDecals(); }
void SetTranslucent(bool on) { wrapped.bTranslucent = on; }
ETextureType GetUseType() const { return wrapped.GetUseType(); }
void SetUseType(ETextureType type) { wrapped.SetUseType(type); }
float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); }
uint16_t GetRotations() const { return wrapped.GetRotations(); }
void SetRotations(int index) { wrapped.SetRotations(index); }
@ -651,6 +653,10 @@ public:
}
}
void CopySize(FGameTexture* BaseTexture)
{
wrapped.CopySize(&BaseTexture->wrapped);
}
// These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place.
FGameTexture* GetPalVersion() { return reinterpret_cast<FGameTexture*>(wrapped.GetPalVersion()); }
@ -669,6 +675,11 @@ public:
void SetGlowing(PalEntry color) { auto tex = GetTexture(); tex->bAutoGlowing = false; tex->bGlowing = true; tex->GlowColor = color; }
bool isUserContent() const;
void AddAutoMaterials() { wrapped.AddAutoMaterials(); }
int CheckRealHeight() { return wrapped.CheckRealHeight(); }
bool isSkybox() const { return wrapped.isSkybox(); }
void SetSize(int x, int y) { wrapped.SetSize(x, y); }
};

View file

@ -2642,7 +2642,7 @@ static void PatchTextures()
FTextureID tex = TexMan.CheckForTexture("BLANK", ETextureType::Wall, false);
if (tex.Exists())
{
auto texture = TexMan.GetTexture(tex, false);
auto texture = TexMan.GetGameTexture(tex, false);
texture->SetUseType(ETextureType::Null);
}
}

View file

@ -513,7 +513,7 @@ double FindShortestTextureAround (sector_t *sec)
CheckShortestTex (sec->Level, check->sidedef[1]->GetTexture(side_t::bottom), minsize);
}
}
return minsize < FLT_MAX ? minsize : TexMan.ByIndex(0)->GetDisplayHeight();
return minsize < FLT_MAX ? minsize : TexMan.GameByIndex(0)->GetDisplayHeight();
}
//
@ -538,7 +538,7 @@ double FindShortestUpperAround (sector_t *sec)
CheckShortestTex (sec->Level, check->sidedef[1]->GetTexture(side_t::top), minsize);
}
}
return minsize < FLT_MAX ? minsize : TexMan.ByIndex(0)->GetDisplayHeight();
return minsize < FLT_MAX ? minsize : TexMan.GameByIndex(0)->GetDisplayHeight();
}
//

View file

@ -1000,14 +1000,15 @@ void PPCustomShaderInstance::SetTextures(PPRenderState *renderstate)
while (it.NextPair(pair))
{
FString name = pair->Value;
FTexture *tex = TexMan.GetTexture(TexMan.CheckForTexture(name, ETextureType::Any), true);
if (tex && tex->isValid())
auto gtex = TexMan.GetGameTexture(TexMan.CheckForTexture(name, ETextureType::Any), true);
if (gtex && gtex->isValid())
{
// Why does this completely circumvent the normal way of handling textures?
// This absolutely needs fixing because it will also circumvent any potential caching system that may get implemented.
//
// To do: fix the above problem by adding PPRenderState::SetInput(FTexture *tex)
auto tex = gtex->GetTexture();
auto &pptex = Textures[tex];
if (!pptex)
{

View file

@ -289,7 +289,7 @@ void HWDrawInfo::AddLine (seg_t *seg, bool portalclip)
{
if (!seg->linedef->isVisualPortal())
{
FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::mid), true);
auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::mid), true);
if (!tex || !tex->isValid())
{
// nothing to do here!

View file

@ -351,7 +351,7 @@ bool HWDrawInfo::DoOneSectorUpper(subsector_t * subsec, float Planez, area_t in_
if (sec->GetPlaneTexZ(sector_t::ceiling) == Planez)
{
// If there's a texture abort
FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::top));
auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::top));
if (!tex || !tex->isValid()) continue;
else return false;
}
@ -409,7 +409,7 @@ bool HWDrawInfo::DoOneSectorLower(subsector_t * subsec, float Planez, area_t in_
if (sec->GetPlaneTexZ(sector_t::floor) == Planez)
{
// If there's a texture abort
FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::bottom));
auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::bottom));
if (!tex || !tex->isValid()) continue;
else return false;
}

View file

@ -793,7 +793,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
if (isPicnumOverride)
{
// Animate picnum overrides.
auto tex = TexMan.GetTexture(thing->picnum, true);
auto tex = TexMan.GetGameTexture(thing->picnum, true);
if (tex == nullptr) return;
patch = tex->GetID();
mirror = false;

View file

@ -1238,7 +1238,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary,
// Set up the top
//
//
FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::top), true);
auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::top), true);
if (!tex || !tex->isValid())
{
if (front->GetTexture(sector_t::ceiling) == skyflatnum &&
@ -1274,7 +1274,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary,
// Set up the bottom
//
//
tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::bottom), true);
tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::bottom), true);
if (!tex || !tex->isValid())
{
// texture is missing - use the lower plane
@ -1543,7 +1543,7 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover,
if (rover->flags&FF_UPPERTEXTURE)
{
gltexture = FMaterial::ValidateTexture(seg->sidedef->GetTexture(side_t::top), false, true);
if (!gltexture) return;
if (!gltexture) return;
GetTexCoordInfo(gltexture, &tci, seg->sidedef, side_t::top);
}
else if (rover->flags&FF_LOWERTEXTURE)
@ -2073,14 +2073,14 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_
sector_t *backsec = isportal? seg->linedef->getPortalDestination()->frontsector : backsector;
bool drawfogboundary = !di->isFullbrightScene() && di->CheckFog(frontsector, backsec);
FTexture *tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::mid), true);
auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::mid), true);
if (tex != NULL)
{
if (di->Level->i_compatflags & COMPATF_MASKEDMIDTEX)
{
tex = tex->GetRawTexture();
}
gltexture = FMaterial::ValidateTexture(tex, false);
gltexture = FMaterial::ValidateTexture(tex->GetTexture(), false);
}
else gltexture = NULL;

View file

@ -141,7 +141,7 @@ static bool isBright(DPSprite *psp)
FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr);
if (lump.isValid())
{
FTexture * tex = TexMan.GetTexture(lump, true);
auto tex = TexMan.GetGameTexture(lump, true);
if (tex) disablefullbright = tex->isFullbrightDisabled();
}
return psp->GetState()->GetFullbright() && !disablefullbright;

View file

@ -103,10 +103,10 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
// HIT_Wall must be checked for MBF-style sky transfers.
if (texhitlist[i] & (FTextureManager::HIT_Sky | FTextureManager::HIT_Wall))
{
FTexture *tex = TexMan.ByIndex(i);
auto tex = TexMan.GameByIndex(i);
if (tex->isSkybox())
{
FSkyBox *sb = static_cast<FSkyBox*>(tex);
FSkyBox *sb = static_cast<FSkyBox*>(tex->GetTexture());
for (int i = 0; i<6; i++)
{
if (sb->faces[i])
@ -193,12 +193,12 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
// prepare the textures for precaching. First collect all used layer textures so that we know which ones should not be deleted.
for (int i = cnt - 1; i >= 0; i--)
{
FTexture *tex = TexMan.ByIndex(i);
auto tex = TexMan.GameByIndex(i);
if (tex != nullptr)
{
if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky))
{
FMaterial* mat = FMaterial::ValidateTexture(tex, false, false);
FMaterial* mat = FMaterial::ValidateTexture(tex->GetTexture(), false, false);
if (mat != nullptr)
{
for (auto ftex : mat->GetLayerArray())
@ -209,7 +209,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
}
if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0)
{
FMaterial *mat = FMaterial::ValidateTexture(tex, true, false);
FMaterial *mat = FMaterial::ValidateTexture(tex->GetTexture(), true, false);
if (mat != nullptr)
{
for (auto ftex : mat->GetLayerArray())
@ -224,16 +224,16 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
// delete unused textures (i.e. those which didn't get referenced by any material in the cache list.
for (int i = cnt - 1; i >= 0; i--)
{
FTexture *tex = TexMan.ByIndex(i);
auto tex = TexMan.GameByIndex(i);
if (tex != nullptr && tex->GetUseType() != ETextureType::FontChar)
{
if (usedTextures.CheckKey(tex) == nullptr)
if (usedTextures.CheckKey(tex->GetTexture()) == nullptr)
{
tex->CleanHardwareTextures(true, false);
tex->GetTexture()->CleanHardwareTextures(true, false);
}
if (usedSprites.CheckKey(tex) == nullptr)
if (usedSprites.CheckKey(tex->GetTexture()) == nullptr)
{
tex->CleanHardwareTextures(false, true);
tex->GetTexture()->CleanHardwareTextures(false, true);
}
}
}
@ -249,7 +249,8 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
// cache all used textures
for (int i = cnt - 1; i >= 0; i--)
{
FTexture *tex = TexMan.ByIndex(i);
auto gtex = TexMan.GameByIndex(i);
auto tex = gtex->GetTexture();
if (tex != nullptr && tex->GetImage() != nullptr)
{
if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky))
@ -271,7 +272,8 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
// cache all used textures
for (int i = cnt - 1; i >= 0; i--)
{
FTexture *tex = TexMan.ByIndex(i);
auto gtex = TexMan.GameByIndex(i);
auto tex = gtex->GetTexture();
if (tex != nullptr)
{
PrecacheTexture(tex, texhitlist[i]);

View file

@ -1630,7 +1630,7 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetName)
{
PARAM_PROLOGUE;
PARAM_INT(texid);
auto tex = TexMan.ByIndex(texid);
auto tex = TexMan.GameByIndex(texid);
FString retval;
if (tex != nullptr)
@ -1655,12 +1655,12 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetName)
static int GetTextureSize(int texid, int* py)
{
auto tex = TexMan.ByIndex(texid);
auto tex = TexMan.GameByIndex(texid);
int x, y;
if (tex != nullptr)
{
x = tex->GetDisplayWidth();
y = tex->GetDisplayHeight();
x = int(0.5 + tex->GetDisplayWidth());
y = int(0.5 + tex->GetDisplayHeight());
}
else x = y = -1;
if (py) *py = y;
@ -1685,12 +1685,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetSize, GetTextureSize)
//==========================================================================
static void GetScaledSize(int texid, DVector2* pvec)
{
auto tex = TexMan.ByIndex(texid);
auto tex = TexMan.GameByIndex(texid);
double x, y;
if (tex != nullptr)
{
x = tex->GetDisplayWidthDouble();
y = tex->GetDisplayHeightDouble();
x = tex->GetDisplayWidth();
y = tex->GetDisplayHeight();
}
else x = y = -1;
if (pvec)
@ -1716,12 +1716,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledSize, GetScaledSize)
//==========================================================================
static void GetScaledOffset(int texid, DVector2* pvec)
{
auto tex = TexMan.ByIndex(texid);
auto tex = TexMan.GameByIndex(texid);
double x, y;
if (tex != nullptr)
{
x = tex->GetDisplayLeftOffsetDouble();
y = tex->GetDisplayTopOffsetDouble();
x = tex->GetDisplayLeftOffset();
y = tex->GetDisplayTopOffset();
}
else x = y = -1;
if (pvec)
@ -1748,7 +1748,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledOffset, GetScaledOffset)
static int CheckRealHeight(int texid)
{
auto tex = TexMan.ByIndex(texid);
auto tex = TexMan.GameByIndex(texid);
if (tex != nullptr) return tex->CheckRealHeight();
else return -1;
}