mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +00:00
- fixed texture layer management so that each material layer can decide for itself if it wants to allow upscaling.
- rewrote the hardware texture precacher to use the new texture management to properly track the data to delete.
This commit is contained in:
parent
cedc95c2a5
commit
b2281c38e1
20 changed files with 190 additions and 135 deletions
|
@ -145,7 +145,7 @@ public:
|
|||
bool isFullbrightDisabled() const { return !!(flags & GTexf_DisableFullbrightSprites); }
|
||||
bool isFullbright() const { return !!(flags & GTexf_RenderFullbright); }
|
||||
bool isFullNameTexture() const { return !!(flags & GTexf_FullNameTexture); }
|
||||
bool expandSprites() const { return !!expandSprite; }
|
||||
bool expandSprites() { return expandSprite == -1? ShouldExpandSprite() : !!expandSprite; }
|
||||
bool useWorldPanning() const { return !!(flags & GTexf_WorldPanning); }
|
||||
void SetWorldPanning(bool on) { if (on) flags |= GTexf_WorldPanning; else flags &= ~GTexf_WorldPanning; }
|
||||
bool allowNoDecals() const { return !!(flags & GTexf_NoDecals); }
|
||||
|
@ -269,6 +269,19 @@ public:
|
|||
|
||||
void CleanHardwareData(bool full = true);
|
||||
|
||||
void GetLayers(TArray<FTexture*>& layers)
|
||||
{
|
||||
layers.Clear();
|
||||
for (auto tex : { Base.get(), Brightmap.get(), Detailmap.get(), Glowmap.get(), Normal.get(), Specular.get(), Metallic.get(), Roughness.get(), AmbientOcclusion.get() })
|
||||
{
|
||||
if (tex != nullptr) layers.Push(tex);
|
||||
}
|
||||
for (auto& tex : CustomShaderTextures)
|
||||
{
|
||||
if (tex != nullptr) layers.Push(tex.get());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType)
|
||||
|
|
|
@ -41,7 +41,8 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
|||
{
|
||||
mShaderIndex = SHADER_Default;
|
||||
sourcetex = tx;
|
||||
imgtex = tx->GetTexture();
|
||||
auto imgtex = tx->GetTexture();
|
||||
mTextureLayers.Push({ imgtex, scaleflags });
|
||||
|
||||
if (tx->GetUseType() == ETextureType::SWCanvas && static_cast<FWrapperTexture*>(imgtex)->GetColorFormat() == 0)
|
||||
{
|
||||
|
@ -66,7 +67,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
|||
{
|
||||
for (auto &texture : { tx->Normal.get(), tx->Specular.get() })
|
||||
{
|
||||
mTextureLayers.Push(texture);
|
||||
mTextureLayers.Push({ texture, 0 });
|
||||
}
|
||||
mShaderIndex = SHADER_Specular;
|
||||
}
|
||||
|
@ -74,7 +75,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
|||
{
|
||||
for (auto &texture : { tx->Normal.get(), tx->Metallic.get(), tx->Roughness.get(), tx->AmbientOcclusion.get() })
|
||||
{
|
||||
mTextureLayers.Push(texture);
|
||||
mTextureLayers.Push({ texture, 0 });
|
||||
}
|
||||
mShaderIndex = SHADER_PBR;
|
||||
}
|
||||
|
@ -84,30 +85,30 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
|||
auto placeholder = TexMan.GameByIndex(1);
|
||||
if (tx->Brightmap.get())
|
||||
{
|
||||
mTextureLayers.Push(tx->Brightmap.get());
|
||||
mTextureLayers.Push({ tx->Brightmap.get(), scaleflags });
|
||||
mLayerFlags |= TEXF_Brightmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
mTextureLayers.Push(placeholder->GetTexture());
|
||||
mTextureLayers.Push({ placeholder->GetTexture(), 0 });
|
||||
}
|
||||
if (tx->Detailmap.get())
|
||||
{
|
||||
mTextureLayers.Push(tx->Detailmap.get());
|
||||
mTextureLayers.Push({ tx->Detailmap.get(), 0 });
|
||||
mLayerFlags |= TEXF_Detailmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
mTextureLayers.Push(placeholder->GetTexture());
|
||||
mTextureLayers.Push({ placeholder->GetTexture(), 0 });
|
||||
}
|
||||
if (tx->Glowmap.get())
|
||||
{
|
||||
mTextureLayers.Push(tx->Glowmap.get());
|
||||
mTextureLayers.Push({ tx->Glowmap.get(), scaleflags });
|
||||
mLayerFlags |= TEXF_Glowmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
mTextureLayers.Push(placeholder->GetTexture());
|
||||
mTextureLayers.Push({ placeholder->GetTexture(), 0 });
|
||||
}
|
||||
|
||||
auto index = tx->GetShaderIndex();
|
||||
|
@ -119,7 +120,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags)
|
|||
for (auto &texture : tx->CustomShaderTextures)
|
||||
{
|
||||
if (texture == nullptr) continue;
|
||||
mTextureLayers.Push(texture.get());
|
||||
mTextureLayers.Push({ texture.get(), 0 }); // scalability should be user-definable.
|
||||
}
|
||||
mShaderIndex = index;
|
||||
}
|
||||
|
@ -149,12 +150,12 @@ FMaterial::~FMaterial()
|
|||
//
|
||||
//===========================================================================
|
||||
|
||||
IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) const
|
||||
IHardwareTexture *FMaterial::GetLayer(int i, int translation, MaterialLayerInfo **pLayer) const
|
||||
{
|
||||
FTexture *layer = i == 0 ? imgtex : mTextureLayers[i - 1];
|
||||
if (pLayer) *pLayer = layer;
|
||||
auto &layer = mTextureLayers[i];
|
||||
if (pLayer) *pLayer = &layer;
|
||||
|
||||
if (layer) return layer->GetHardwareTexture(translation, mScaleFlags);
|
||||
if (layer.layerTexture) return layer.layerTexture->GetHardwareTexture(translation, layer.scaleFlags);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -169,7 +170,7 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool
|
|||
{
|
||||
if (gtex && gtex->isValid())
|
||||
{
|
||||
if (!gtex->ShouldExpandSprite()) scaleflags &= ~CTF_Expand;
|
||||
if (!gtex->expandSprites()) scaleflags &= ~CTF_Expand;
|
||||
|
||||
FMaterial *hwtex = gtex->Material[scaleflags];
|
||||
if (hwtex == NULL && create)
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
struct FRemapTable;
|
||||
class IHardwareTexture;
|
||||
|
||||
struct MaterialLayerInfo
|
||||
{
|
||||
FTexture* layerTexture;
|
||||
int scaleFlags;
|
||||
};
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// this is the material class for OpenGL.
|
||||
|
@ -17,14 +23,13 @@ class IHardwareTexture;
|
|||
class FMaterial
|
||||
{
|
||||
private:
|
||||
TArray<FTexture*> mTextureLayers;
|
||||
TArray<MaterialLayerInfo> mTextureLayers; // the only layers allowed to scale are the brightmap and the glowmap.
|
||||
int mShaderIndex;
|
||||
int mLayerFlags = 0;
|
||||
int mScaleFlags;
|
||||
|
||||
public:
|
||||
FGameTexture *sourcetex; // the owning texture.
|
||||
FTexture* imgtex; // the first layer's texture image - should be moved into the array
|
||||
|
||||
FMaterial(FGameTexture *tex, int scaleflags);
|
||||
virtual ~FMaterial();
|
||||
|
@ -37,27 +42,22 @@ public:
|
|||
{
|
||||
return sourcetex;
|
||||
}
|
||||
FTexture* BaseLayer() const
|
||||
|
||||
void AddTextureLayer(FTexture *tex, bool allowscale)
|
||||
{
|
||||
// Only for spftpoly!
|
||||
return imgtex;
|
||||
}
|
||||
void AddTextureLayer(FTexture *tex)
|
||||
{
|
||||
//ValidateTexture(tex, false);
|
||||
mTextureLayers.Push(tex);
|
||||
mTextureLayers.Push({ tex, allowscale });
|
||||
}
|
||||
|
||||
int GetLayers() const
|
||||
int NumLayers() const
|
||||
{
|
||||
return mTextureLayers.Size() + 1;
|
||||
return mTextureLayers.Size();
|
||||
}
|
||||
|
||||
IHardwareTexture *GetLayer(int i, int translation, FTexture **pLayer = nullptr) const;
|
||||
IHardwareTexture *GetLayer(int i, int translation, MaterialLayerInfo **pLayer = nullptr) const;
|
||||
|
||||
|
||||
static FMaterial *ValidateTexture(FGameTexture * tex, int scaleflags, bool create = true);
|
||||
const TArray<FTexture*> &GetLayerArray() const
|
||||
const TArray<MaterialLayerInfo> &GetLayerArray() const
|
||||
{
|
||||
return mTextureLayers;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ private:
|
|||
{
|
||||
IHardwareTexture *hwTexture = nullptr;
|
||||
int translation = 0;
|
||||
bool precacheMarker; // This is used to check whether a texture has been hit by the precacher, so that the cleanup code can delete the unneeded ones.
|
||||
|
||||
void Delete()
|
||||
{
|
||||
|
@ -40,6 +41,16 @@ private:
|
|||
{
|
||||
Delete();
|
||||
}
|
||||
|
||||
void MarkForPrecache(bool on)
|
||||
{
|
||||
precacheMarker = on;
|
||||
}
|
||||
|
||||
bool isMarkedForPreache() const
|
||||
{
|
||||
return precacheMarker;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -99,25 +110,44 @@ public:
|
|||
//===========================================================================
|
||||
//
|
||||
// Deletes all allocated resources and considers translations
|
||||
// This will only be called for sprites
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
void CleanUnused(SpriteHits &usedtranslations, int scaleflags)
|
||||
void CleanUnused()
|
||||
{
|
||||
if (usedtranslations.CheckKey(0) == nullptr)
|
||||
for (auto& tt : hwDefTex)
|
||||
{
|
||||
hwDefTex[scaleflags].Delete();
|
||||
if (!tt.isMarkedForPreache()) tt.Delete();
|
||||
}
|
||||
for (int i = hwTex_Translated.Size()-1; i>= 0; i--)
|
||||
{
|
||||
if (usedtranslations.CheckKey(hwTex_Translated[i].translation & 0xffffff) == nullptr)
|
||||
auto& tt = hwTex_Translated[i];
|
||||
if (!tt.isMarkedForPreache())
|
||||
{
|
||||
hwTex_Translated.Delete(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UnmarkAll()
|
||||
{
|
||||
for (auto& tt : hwDefTex)
|
||||
{
|
||||
if (!tt.isMarkedForPreache()) tt.MarkForPrecache(false);
|
||||
}
|
||||
for (auto& tt : hwTex_Translated)
|
||||
{
|
||||
if (!tt.isMarkedForPreache()) tt.MarkForPrecache(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MarkForPrecache(int translation, int scaleflags)
|
||||
{
|
||||
auto tt = GetTexID(translation, scaleflags);
|
||||
tt->MarkForPrecache(true);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Iterate(T callback)
|
||||
{
|
||||
|
|
|
@ -397,12 +397,6 @@ bool FTexture::DetermineTranslucency()
|
|||
return !!bTranslucent;
|
||||
}
|
||||
|
||||
|
||||
void FTexture::CleanHardwareTextures()
|
||||
{
|
||||
SystemTextures.Clean();
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// the default just returns an empty texture.
|
||||
|
|
|
@ -226,7 +226,26 @@ public:
|
|||
IHardwareTexture* GetHardwareTexture(int translation, int scaleflags);
|
||||
virtual FImageSource *GetImage() const { return nullptr; }
|
||||
void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly);
|
||||
void CleanHardwareTextures();
|
||||
|
||||
void CleanHardwareTextures()
|
||||
{
|
||||
SystemTextures.Clean();
|
||||
}
|
||||
|
||||
void CleanPrecacheMarker()
|
||||
{
|
||||
SystemTextures.UnmarkAll();
|
||||
}
|
||||
|
||||
void MarkForPrecache(int translation, int scaleflags)
|
||||
{
|
||||
SystemTextures.MarkForPrecache(translation, scaleflags);
|
||||
}
|
||||
|
||||
void CleanUnused()
|
||||
{
|
||||
SystemTextures.CleanUnused();
|
||||
}
|
||||
|
||||
int GetWidth() { return Width; }
|
||||
int GetHeight() { return Height; }
|
||||
|
|
|
@ -337,7 +337,7 @@ void Wiper_Burn::SetTextures(FGameTexture *startscreen, FGameTexture *endscreen)
|
|||
endScreen = endscreen;
|
||||
BurnTexture = new FBurnTexture(WIDTH, HEIGHT);
|
||||
auto mat = FMaterial::ValidateTexture(endScreen, false);
|
||||
mat->AddTextureLayer(BurnTexture);
|
||||
mat->AddTextureLayer(BurnTexture, false);
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -323,18 +323,17 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio
|
|||
int usebright = false;
|
||||
int maxbound = 0;
|
||||
|
||||
int flags = mat->GetScaleFlags();
|
||||
int numLayers = mat->GetLayers();
|
||||
int numLayers = mat->NumLayers();
|
||||
MaterialLayerInfo* layer;
|
||||
auto base = static_cast<FHardwareTexture*>(mat->GetLayer(0, translation));
|
||||
|
||||
if (base->BindOrCreate(tex->GetTexture(), 0, clampmode, translation, flags))
|
||||
if (base->BindOrCreate(tex->GetTexture(), 0, clampmode, translation, layer->scaleFlags))
|
||||
{
|
||||
for (int i = 1; i<numLayers; i++)
|
||||
{
|
||||
FTexture *layer;
|
||||
auto systex = static_cast<FHardwareTexture*>(mat->GetLayer(i, 0, &layer));
|
||||
// fixme: Upscale flags must be disabled for certain layers.
|
||||
systex->BindOrCreate(layer, i, clampmode, 0, flags);
|
||||
systex->BindOrCreate(layer->layerTexture, i, clampmode, 0, layer->scaleFlags);
|
||||
maxbound = i;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,16 +311,16 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
|
|||
if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return;
|
||||
|
||||
int flags = mat->GetScaleFlags();
|
||||
int numLayers = mat->GetLayers();
|
||||
FTexture* layer;
|
||||
int numLayers = mat->NumLayers();
|
||||
MaterialLayerInfo* layer;
|
||||
auto base = static_cast<FHardwareTexture*>(mat->GetLayer(0, translation, &layer));
|
||||
|
||||
if (base->BindOrCreate(layer, 0, CLAMP_NONE, translation, flags))
|
||||
if (base->BindOrCreate(layer->layerTexture, 0, CLAMP_NONE, translation, layer->scaleFlags))
|
||||
{
|
||||
for (int i = 1; i < numLayers; i++)
|
||||
{
|
||||
auto systex = static_cast<FHardwareTexture*>(mat->GetLayer(i, 0, &layer));
|
||||
systex->BindOrCreate(layer, i, CLAMP_NONE, 0, flags);
|
||||
systex->BindOrCreate(layer->layerTexture, i, CLAMP_NONE, 0, layer->scaleFlags);
|
||||
}
|
||||
}
|
||||
// unbind everything.
|
||||
|
|
|
@ -572,7 +572,6 @@ public:
|
|||
void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, int translation, int overrideshader)
|
||||
{
|
||||
if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale;
|
||||
if (!tex->expandSprites()) scaleflags &= ~CTF_Expand;
|
||||
SetMaterial(FMaterial::ValidateTexture(tex, scaleflags), clampmode, translation, overrideshader);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,10 @@ static void PrecacheTexture(FGameTexture *tex, int cache)
|
|||
{
|
||||
if (cache & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky))
|
||||
{
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(tex, false);
|
||||
int scaleflags = 0;
|
||||
if (shouldUpscale(tex, UF_Texture)) scaleflags |= CTF_Upscale;
|
||||
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(tex, scaleflags);
|
||||
if (gltex) screen->PrecacheMaterial(gltex, 0);
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +65,6 @@ static void PrecacheTexture(FGameTexture *tex, int cache)
|
|||
//===========================================================================
|
||||
static void PrecacheList(FMaterial *gltex, SpriteHits& translations)
|
||||
{
|
||||
//gltex->BaseLayer()->SystemTextures.CleanUnused(translations, gltex->GetScaleFlags()); this needs to be redone.
|
||||
SpriteHits::Iterator it(translations);
|
||||
SpriteHits::Pair* pair;
|
||||
while (it.NextPair(pair)) screen->PrecacheMaterial(gltex, pair->Key);
|
||||
|
@ -76,7 +78,10 @@ static void PrecacheList(FMaterial *gltex, SpriteHits& translations)
|
|||
|
||||
static void PrecacheSprite(FGameTexture *tex, SpriteHits &hits)
|
||||
{
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(tex, true);
|
||||
int scaleflags = CTF_Expand;
|
||||
if (shouldUpscale(tex, UF_Sprite)) scaleflags |= CTF_Upscale;
|
||||
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(tex, scaleflags);
|
||||
if (gltex) PrecacheList(gltex, hits);
|
||||
}
|
||||
|
||||
|
@ -88,26 +93,36 @@ static void PrecacheSprite(FGameTexture *tex, SpriteHits &hits)
|
|||
|
||||
void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitlist)
|
||||
{
|
||||
SpriteHits *spritelist = new SpriteHits[sprites.Size()];
|
||||
SpriteHits **spritehitlist = new SpriteHits*[TexMan.NumTextures()];
|
||||
TMap<PClassActor*, bool>::Iterator it(actorhitlist);
|
||||
TMap<PClassActor*, bool>::Pair *pair;
|
||||
uint8_t *modellist = new uint8_t[Models.Size()];
|
||||
memset(modellist, 0, Models.Size());
|
||||
memset(spritehitlist, 0, sizeof(SpriteHits**) * TexMan.NumTextures());
|
||||
TMap<FTexture*, bool> allTextures;
|
||||
TArray<FTexture*> layers;
|
||||
|
||||
// this isn't done by the main code so it needs to be done here first:
|
||||
// check skybox textures and mark the separate faces as used
|
||||
for (int i = 0; i<TexMan.NumTextures(); i++)
|
||||
// First collect the potential max. texture set
|
||||
for (unsigned i = 1; i < TexMan.NumTextures(); i++)
|
||||
{
|
||||
// HIT_Wall must be checked for MBF-style sky transfers.
|
||||
auto gametex = TexMan.GameByIndex(i);
|
||||
if (gametex &&
|
||||
gametex->GetTexture()->GetImage() && // only image textures are subject to precaching
|
||||
gametex->GetUseType() != ETextureType::FontChar && // We do not want to delete font characters here as they are very likely to be needed constantly.
|
||||
gametex->GetUseType() < ETextureType::Special) // Any texture marked as 'special' is also out.
|
||||
{
|
||||
gametex->GetLayers(layers);
|
||||
for (auto layer : layers)
|
||||
{
|
||||
allTextures.Insert(layer, true);
|
||||
layer->CleanPrecacheMarker();
|
||||
}
|
||||
}
|
||||
|
||||
// Mark the faces of a skybox as used.
|
||||
// This isn't done by the main code so it needs to be done here.
|
||||
// MBF sky transfers are being checked by the calling code to add HIT_Sky for them.
|
||||
if (texhitlist[i] & (FTextureManager::HIT_Sky))
|
||||
{
|
||||
auto tex = TexMan.GameByIndex(i);
|
||||
auto sb = dynamic_cast<FSkyBox*>(tex->GetTexture());
|
||||
if (sb)
|
||||
{
|
||||
for (int i = 0; i<6; i++)
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
if (sb->faces[i])
|
||||
{
|
||||
|
@ -119,6 +134,14 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
|
|||
}
|
||||
}
|
||||
|
||||
SpriteHits *spritelist = new SpriteHits[sprites.Size()];
|
||||
SpriteHits **spritehitlist = new SpriteHits*[TexMan.NumTextures()];
|
||||
TMap<PClassActor*, bool>::Iterator it(actorhitlist);
|
||||
TMap<PClassActor*, bool>::Pair *pair;
|
||||
uint8_t *modellist = new uint8_t[Models.Size()];
|
||||
memset(modellist, 0, Models.Size());
|
||||
memset(spritehitlist, 0, sizeof(SpriteHits**) * TexMan.NumTextures());
|
||||
|
||||
// Check all used actors.
|
||||
// 1. mark all sprites associated with its states
|
||||
// 2. mark all model data and skins associated with its states
|
||||
|
@ -190,7 +213,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
|
|||
screen->StartPrecaching();
|
||||
int cnt = TexMan.NumTextures();
|
||||
|
||||
// prepare the textures for precaching. First collect all used layer textures so that we know which ones should not be deleted.
|
||||
// prepare the textures for precaching. First mark all used layer textures so that we know which ones should not be deleted.
|
||||
for (int i = cnt - 1; i >= 0; i--)
|
||||
{
|
||||
auto tex = TexMan.GameByIndex(i);
|
||||
|
@ -198,44 +221,46 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
|
|||
{
|
||||
if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky))
|
||||
{
|
||||
FMaterial* mat = FMaterial::ValidateTexture(tex, false, false);
|
||||
int scaleflags = 0;
|
||||
if (shouldUpscale(tex, UF_Texture)) scaleflags |= CTF_Upscale;
|
||||
|
||||
FMaterial* mat = FMaterial::ValidateTexture(tex, scaleflags, true);
|
||||
if (mat != nullptr)
|
||||
{
|
||||
for (auto ftex : mat->GetLayerArray())
|
||||
for (auto &layer : mat->GetLayerArray())
|
||||
{
|
||||
usedTextures.Insert(ftex, true);
|
||||
if (layer.layerTexture) layer.layerTexture->MarkForPrecache(0, layer.scaleFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0)
|
||||
{
|
||||
FMaterial *mat = FMaterial::ValidateTexture(tex, true, false);
|
||||
int scaleflags = CTF_Expand;
|
||||
if (shouldUpscale(tex, UF_Sprite)) scaleflags |= CTF_Upscale;
|
||||
|
||||
FMaterial *mat = FMaterial::ValidateTexture(tex, true, true);
|
||||
if (mat != nullptr)
|
||||
{
|
||||
for (auto ftex : mat->GetLayerArray())
|
||||
SpriteHits::Iterator it(*spritehitlist[i]);
|
||||
SpriteHits::Pair* pair;
|
||||
while (it.NextPair(pair))
|
||||
{
|
||||
usedSprites.Insert(ftex, true);
|
||||
for (auto& layer : mat->GetLayerArray())
|
||||
{
|
||||
if (layer.layerTexture) layer.layerTexture->MarkForPrecache(pair->Key, layer.scaleFlags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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--)
|
||||
// delete unused hardware textures (i.e. those which didn't get referenced by any material in the cache list.)
|
||||
decltype(allTextures)::Iterator ita(allTextures);
|
||||
decltype(allTextures)::Pair* paira;
|
||||
while (it.NextPair(pair))
|
||||
{
|
||||
auto tex = TexMan.GameByIndex(i);
|
||||
if (tex != nullptr && tex->GetUseType() != ETextureType::FontChar)
|
||||
{
|
||||
// This is rather counterproductive in a system that can share hardware textures between game textures.
|
||||
// The precacher needs to be redone to account for that. For now, just skip the deletion, for any normal sized map this won't be a problem.
|
||||
#if 0
|
||||
if (usedTextures.CheckKey(tex->GetTexture()) == nullptr && usedSprites.CheckKey(tex->GetTexture()) == nullptr)
|
||||
{
|
||||
tex->CleanHardwareData();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
paira->Key->CleanUnused();
|
||||
}
|
||||
|
||||
if (gl_precache)
|
||||
|
@ -246,7 +271,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
|
|||
|
||||
FImageSource::BeginPrecaching();
|
||||
|
||||
// cache all used textures
|
||||
// cache all used images
|
||||
for (int i = cnt - 1; i >= 0; i--)
|
||||
{
|
||||
auto gtex = TexMan.GameByIndex(i);
|
||||
|
@ -262,7 +287,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
|
|||
}
|
||||
}
|
||||
|
||||
// Only register untranslated sprites. Translated ones are very unlikely to require data that can be reused.
|
||||
// Only register untranslated sprite images. Translated ones are very unlikely to require data that can be reused so they can just be created on demand.
|
||||
if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CheckKey(0))
|
||||
{
|
||||
FImageSource::RegisterForPrecache(tex->GetImage(), V_IsTrueColor());
|
||||
|
|
|
@ -535,16 +535,15 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
|
|||
{
|
||||
if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return;
|
||||
|
||||
int flags = mat->GetScaleFlags();
|
||||
FTexture* layer;
|
||||
MaterialLayerInfo* layer;
|
||||
auto systex = static_cast<PolyHardwareTexture*>(mat->GetLayer(0, translation, &layer));
|
||||
systex->GetImage(layer, translation, flags);
|
||||
systex->GetImage(layer->layerTexture, translation, layer->scaleFlags);
|
||||
|
||||
int numLayers = mat->GetLayers();
|
||||
int numLayers = mat->NumLayers();
|
||||
for (int i = 1; i < numLayers; i++)
|
||||
{
|
||||
auto systex = static_cast<PolyHardwareTexture*>(mat->GetLayer(i, 0, &layer));
|
||||
systex->GetImage(layer, 0, flags); // fixme: Upscale flags must be disabled for certain layers.
|
||||
systex->GetImage(layer->layerTexture, 0, layer->scaleFlags); // fixme: Upscale flags must be disabled for certain layers.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -585,10 +584,6 @@ void PolyFrameBuffer::TextureFilterChanged()
|
|||
{
|
||||
}
|
||||
|
||||
void PolyFrameBuffer::StartPrecaching()
|
||||
{
|
||||
}
|
||||
|
||||
void PolyFrameBuffer::BlurScene(float amount)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ public:
|
|||
sector_t *RenderView(player_t *player) override;
|
||||
void SetTextureFilterMode() override;
|
||||
void TextureFilterChanged() override;
|
||||
void StartPrecaching() override;
|
||||
void BeginFrame() override;
|
||||
void BlurScene(float amount) override;
|
||||
void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) override;
|
||||
|
|
|
@ -62,17 +62,6 @@ void PolyHardwareTexture::Reset()
|
|||
}
|
||||
}
|
||||
|
||||
DCanvas *PolyHardwareTexture::GetImage(FTexture *baselayer, const FMaterialState &state)
|
||||
{
|
||||
if (!mCanvas)
|
||||
{
|
||||
int flags = state.mMaterial->GetScaleFlags();
|
||||
return GetImage(baselayer, state.mTranslation, flags);
|
||||
}
|
||||
|
||||
return mCanvas.get();
|
||||
}
|
||||
|
||||
DCanvas *PolyHardwareTexture::GetImage(FTexture *tex, int translation, int flags)
|
||||
{
|
||||
if (!mCanvas)
|
||||
|
|
|
@ -23,7 +23,6 @@ public:
|
|||
static void ResetAll();
|
||||
void Reset();
|
||||
|
||||
DCanvas *GetImage(FTexture *tex, const FMaterialState &state);
|
||||
DCanvas *GetImage(FTexture *tex, int translation, int flags);
|
||||
PolyDepthStencil *GetDepthStencil(FTexture *tex);
|
||||
|
||||
|
|
|
@ -314,20 +314,19 @@ void PolyRenderState::ApplyMaterial()
|
|||
{
|
||||
mTempTM = mMaterial.mMaterial->Source()->isHardwareCanvas() ? TM_OPAQUE : TM_NORMAL;
|
||||
|
||||
FTexture* layer;
|
||||
MaterialLayerInfo* layer;
|
||||
auto base = static_cast<PolyHardwareTexture*>(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation, &layer));
|
||||
if (base)
|
||||
{
|
||||
DCanvas *texcanvas = base->GetImage(layer, mMaterial);
|
||||
DCanvas *texcanvas = base->GetImage(layer->layerTexture, mMaterial.mTranslation, layer->scaleFlags);
|
||||
mDrawCommands->SetTexture(0, texcanvas->GetPixels(), texcanvas->GetWidth(), texcanvas->GetHeight(), texcanvas->IsBgra());
|
||||
|
||||
int numLayers = mMaterial.mMaterial->GetLayers();
|
||||
int numLayers = mMaterial.mMaterial->NumLayers();
|
||||
for (int i = 1; i < numLayers; i++)
|
||||
{
|
||||
FTexture* layer;
|
||||
auto systex = static_cast<PolyHardwareTexture*>(mMaterial.mMaterial->GetLayer(i, 0, &layer));
|
||||
|
||||
texcanvas = systex->GetImage(layer, 0, mMaterial.mMaterial->GetScaleFlags());
|
||||
texcanvas = systex->GetImage(layer->layerTexture, 0, layer->scaleFlags);
|
||||
mDrawCommands->SetTexture(i, texcanvas->GetPixels(), texcanvas->GetWidth(), texcanvas->GetHeight(), texcanvas->IsBgra());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player)
|
|||
fbtex.reset(MakeGameTexture(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()), nullptr, ETextureType::SWCanvas));
|
||||
GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
|
||||
auto mat = FMaterial::ValidateTexture(fbtex.get(), false);
|
||||
mat->AddTextureLayer(PaletteTexture);
|
||||
mat->AddTextureLayer(PaletteTexture, false);
|
||||
|
||||
Canvas.reset();
|
||||
Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
|
||||
|
|
|
@ -228,7 +228,7 @@ void VkRenderState::ApplyRenderPass(int dt)
|
|||
pipelineKey.StencilPassOp = mStencilOp;
|
||||
pipelineKey.ColorMask = mColorMask;
|
||||
pipelineKey.CullMode = mCullMode;
|
||||
pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->GetLayers() : 0;
|
||||
pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->NumLayers() : 0;
|
||||
pipelineKey.NumTextureLayers = std::max(pipelineKey.NumTextureLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS);// Always force minimum 8 textures as the shader requires it
|
||||
if (mSpecialEffect > EFF_NONE)
|
||||
{
|
||||
|
|
|
@ -647,18 +647,16 @@ void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation)
|
|||
{
|
||||
if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return;
|
||||
|
||||
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
|
||||
int flags = mat->GetScaleFlags();
|
||||
FTexture* layer;
|
||||
MaterialLayerInfo* layer;
|
||||
|
||||
auto systex = static_cast<VkHardwareTexture*>(mat->GetLayer(0, translation, &layer));
|
||||
systex->GetImage(layer, translation, flags);
|
||||
systex->GetImage(layer->layerTexture, translation, layer->scaleFlags);
|
||||
|
||||
int numLayers = mat->GetLayers();
|
||||
int numLayers = mat->NumLayers();
|
||||
for (int i = 1; i < numLayers; i++)
|
||||
{
|
||||
auto systex = static_cast<VkHardwareTexture*>(mat->GetLayer(i, 0, &layer));
|
||||
systex->GetImage(layer, 0, flags); // fixme: Upscale flags must be disabled for certain layers.
|
||||
systex->GetImage(layer->layerTexture, 0, layer->scaleFlags);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -374,15 +374,12 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)
|
|||
|
||||
clampmode = base->GetClampMode(clampmode);
|
||||
|
||||
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
|
||||
int flags = GetScaleFlags();
|
||||
|
||||
for (auto& set : mDescriptorSets)
|
||||
{
|
||||
if (set.descriptor && set.clampmode == clampmode && set.flags == translation) return set.descriptor.get();
|
||||
}
|
||||
|
||||
int numLayers = GetLayers();
|
||||
int numLayers = NumLayers();
|
||||
|
||||
auto fb = GetVulkanFrameBuffer();
|
||||
auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(std::max(numLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS));
|
||||
|
@ -392,14 +389,13 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)
|
|||
VulkanSampler* sampler = fb->GetSamplerManager()->Get(clampmode);
|
||||
|
||||
WriteDescriptors update;
|
||||
FTexture* layer;
|
||||
MaterialLayerInfo *layer;
|
||||
auto systex = static_cast<VkHardwareTexture*>(GetLayer(0, translation, &layer));
|
||||
update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer, translation, flags)->View.get(), sampler, systex->mImage.Layout);
|
||||
update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, translation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout);
|
||||
for (int i = 1; i < numLayers; i++)
|
||||
{
|
||||
auto systex = static_cast<VkHardwareTexture*>(GetLayer(i, 0, &layer));
|
||||
// fixme: Upscale flags must be disabled for certain layers.
|
||||
update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer, 0, flags)->View.get(), sampler, systex->mImage.Layout);
|
||||
update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer->layerTexture, 0, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout);
|
||||
}
|
||||
|
||||
auto dummyImage = fb->GetRenderPassManager()->GetNullTextureView();
|
||||
|
|
Loading…
Reference in a new issue