- minor cleanup on the texture layer data in FTexture.

This commit is contained in:
Christoph Oelckers 2018-03-31 12:27:41 +02:00
parent 6d6196388e
commit 410d6817b2
4 changed files with 48 additions and 56 deletions

View file

@ -481,18 +481,18 @@ FMaterial::FMaterial(FTexture * tx, bool expanded)
}
else
{
if (tx->gl_info.Normal && tx->gl_info.Specular)
if (tx->Normal && tx->Specular)
{
for (auto &texture : { tx->gl_info.Normal, tx->gl_info.Specular })
for (auto &texture : { tx->Normal, tx->Specular })
{
ValidateSysTexture(texture, expanded);
mTextureLayers.Push({ texture, false });
}
mShaderIndex = SHADER_Specular;
}
else if (tx->gl_info.Normal && tx->gl_info.Metallic && tx->gl_info.Roughness && tx->gl_info.AmbientOcclusion)
else if (tx->Normal && tx->Metallic && tx->Roughness && tx->AmbientOcclusion)
{
for (auto &texture : { tx->gl_info.Normal, tx->gl_info.Metallic, tx->gl_info.Roughness, tx->gl_info.AmbientOcclusion })
for (auto &texture : { tx->Normal, tx->Metallic, tx->Roughness, tx->AmbientOcclusion })
{
ValidateSysTexture(texture, expanded);
mTextureLayers.Push({ texture, false });
@ -501,10 +501,10 @@ FMaterial::FMaterial(FTexture * tx, bool expanded)
}
tx->CreateDefaultBrightmap();
if (tx->gl_info.Brightmap != NULL)
if (tx->Brightmap != NULL)
{
ValidateSysTexture(tx->gl_info.Brightmap, expanded);
FTextureLayer layer = {tx->gl_info.Brightmap, false};
ValidateSysTexture(tx->Brightmap, expanded);
FTextureLayer layer = {tx->Brightmap, false};
mTextureLayers.Push(layer);
if (mShaderIndex == SHADER_Specular)
mShaderIndex = SHADER_SpecularBrightmap;
@ -915,9 +915,9 @@ again:
tex->gl_info.bNoExpand = true;
goto again;
}
if (tex->gl_info.Brightmap != NULL &&
(tex->GetWidth() != tex->gl_info.Brightmap->GetWidth() ||
tex->GetHeight() != tex->gl_info.Brightmap->GetHeight())
if (tex->Brightmap != NULL &&
(tex->GetWidth() != tex->Brightmap->GetWidth() ||
tex->GetHeight() != tex->Brightmap->GetHeight())
)
{
// do not expand if the brightmap's size differs.

View file

@ -108,6 +108,9 @@ class FMaterial
bool animated;
};
// This array is needed because not all textures are managed by the texture manager
// but some code needs to discard all hardware dependent data attached to any created texture.
// Font characters are not, for example.
static TArray<FMaterial *> mMaterials;
static int mMaxBound;

View file

@ -196,12 +196,6 @@ FTexture::MiscGLInfo::MiscGLInfo() throw()
Material[1] = Material[0] = NULL;
SystemTexture[1] = SystemTexture[0] = NULL;
Brightmap = NULL;
Normal = NULL;
Specular = NULL;
Metallic = NULL;
Roughness = NULL;
AmbientOcclusion = NULL;
}
FTexture::MiscGLInfo::~MiscGLInfo()
@ -215,9 +209,6 @@ FTexture::MiscGLInfo::~MiscGLInfo()
SystemTexture[i] = NULL;
}
// this is just a reference to another texture in the texture manager.
Brightmap = NULL;
if (areas != NULL) delete [] areas;
areas = NULL;
}
@ -234,7 +225,7 @@ void FTexture::CreateDefaultBrightmap()
// Check for brightmaps
if (UseBasePalette() && HasGlobalBrightmap &&
UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar &&
gl_info.Brightmap == NULL && bWarped == 0
Brightmap == NULL && bWarped == 0
)
{
// May have one - let's check when we use this texture
@ -248,9 +239,9 @@ void FTexture::CreateDefaultBrightmap()
{
// Create a brightmap
DPrintf(DMSG_NOTIFY, "brightmap created for texture '%s'\n", Name.GetChars());
gl_info.Brightmap = new FBrightmapTexture(this);
Brightmap = new FBrightmapTexture(this);
gl_info.bBrightmapChecked = 1;
TexMan.AddTexture(gl_info.Brightmap);
TexMan.AddTexture(Brightmap);
return;
}
}
@ -650,12 +641,12 @@ void gl_ParseMaterial(FScanner &sc, int deflump)
FTexture **bindings[6] =
{
&tex->gl_info.Brightmap,
&tex->gl_info.Normal,
&tex->gl_info.Specular,
&tex->gl_info.Metallic,
&tex->gl_info.Roughness,
&tex->gl_info.AmbientOcclusion
&tex->Brightmap,
&tex->Normal,
&tex->Specular,
&tex->Metallic,
&tex->Roughness,
&tex->AmbientOcclusion
};
for (int i = 0; keywords[i] != nullptr; i++)
{
@ -758,7 +749,7 @@ void gl_ParseBrightmap(FScanner &sc, int deflump)
*/
bmtex->bMasked = false;
tex->gl_info.Brightmap = bmtex;
tex->Brightmap = bmtex;
}
tex->gl_info.bDisableFullbright = disable_fullbright;
}
@ -772,27 +763,23 @@ void gl_ParseBrightmap(FScanner &sc, int deflump)
struct AutoTextureSearchPath
{
const char *path;
ptrdiff_t offset;
void SetTexture(FTexture *material, FTexture *texture) const
{
*reinterpret_cast<FTexture**>(reinterpret_cast<uint8_t*>(&material->gl_info) + offset) = texture;
}
FTexture *FTexture::*pointer;
};
static AutoTextureSearchPath autosearchpaths[] =
{
{ "brightmaps/auto/", offsetof(FTexture::MiscGLInfo, Brightmap) }, // For backwards compatibility
{ "materials/brightmaps/auto/", offsetof(FTexture::MiscGLInfo, Brightmap) },
{ "materials/normalmaps/auto/", offsetof(FTexture::MiscGLInfo, Normal) },
{ "materials/specular/auto/", offsetof(FTexture::MiscGLInfo, Specular) },
{ "materials/metallic/auto/", offsetof(FTexture::MiscGLInfo, Metallic) },
{ "materials/roughness/auto/", offsetof(FTexture::MiscGLInfo, Roughness) },
{ "materials/ao/auto/", offsetof(FTexture::MiscGLInfo, AmbientOcclusion) }
{ "brightmaps/auto/", &FTexture::Brightmap }, // For backwards compatibility
{ "materials/brightmaps/auto/", &FTexture::Brightmap },
{ "materials/normalmaps/auto/", &FTexture::Normal },
{ "materials/specular/auto/", &FTexture::Specular },
{ "materials/metallic/auto/", &FTexture::Metallic },
{ "materials/roughness/auto/", &FTexture::Roughness },
{ "materials/ao/auto/", &FTexture::AmbientOcclusion }
};
void AddAutoMaterials()
{
// Fixme: let this be driven by the texture manager, not the renderer.
int num = Wads.GetNumLumps();
for (int i = 0; i < num; i++)
{
@ -804,11 +791,12 @@ void AddAutoMaterials()
TArray<FTextureID> list;
FString texname = ExtractFileBase(name, false);
TexMan.ListTextures(texname, list);
auto bmtex = TexMan.FindTexture(name, ETextureType::Any, FTextureManager::TEXMAN_TryAny);
auto bmtex = TexMan.FindTexture(name, ETextureType::Any, FTextureManager::TEXMAN_TryAny || FTextureManager::TEXMAN_DontCreate || FTextureManager::TEXMAN_ShortNameOnly );
for (auto texid : list)
{
bmtex->bMasked = false;
searchpath.SetTexture(TexMan[texid], bmtex);
auto tex = TexMan[texid];
if (tex != nullptr) tex->*(searchpath.pointer) = bmtex;
}
}
}

View file

@ -181,6 +181,13 @@ public:
int SourceLump;
FTextureID id;
FTexture *Brightmap = nullptr;
FTexture *Normal = nullptr; // Normal map texture
FTexture *Specular = nullptr; // Specular light texture for the diffuse+normal+specular light model
FTexture *Metallic = nullptr; // Metalness texture for the physically based rendering (PBR) light model
FTexture *Roughness = nullptr; // Roughness texture for PBR
FTexture *AmbientOcclusion = nullptr; // Ambient occlusion texture for PBR
FString Name;
ETextureType UseType; // This texture's primary purpose
@ -366,12 +373,12 @@ protected:
bNoDecals = other->bNoDecals;
Rotations = other->Rotations;
gl_info = other->gl_info;
gl_info.Brightmap = NULL;
gl_info.Normal = NULL;
gl_info.Specular = NULL;
gl_info.Metallic = NULL;
gl_info.Roughness = NULL;
gl_info.AmbientOcclusion = NULL;
Brightmap = NULL;
Normal = NULL;
Specular = NULL;
Metallic = NULL;
Roughness = NULL;
AmbientOcclusion = NULL;
gl_info.areas = NULL;
}
@ -402,12 +409,6 @@ public:
{
FMaterial *Material[2];
FGLTexture *SystemTexture[2];
FTexture *Brightmap;
FTexture *Normal; // Normal map texture
FTexture *Specular; // Specular light texture for the diffuse+normal+specular light model
FTexture *Metallic; // Metalness texture for the physically based rendering (PBR) light model
FTexture *Roughness; // Roughness texture for PBR
FTexture *AmbientOcclusion; // Ambient occlusion texture for PBR
float Glossiness;
float SpecularLevel;
PalEntry GlowColor;