- removed the conversion helper code and fixed a few places where FMaterial was only used to access the hardware textures in the FTexture class.

This commit is contained in:
Christoph Oelckers 2020-04-16 00:21:13 +02:00
parent 7bdef7fe9a
commit 662fa6e667
18 changed files with 68 additions and 56 deletions

View File

@ -425,8 +425,9 @@ void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height
tex->bWorldPanning = true; tex->bWorldPanning = true;
tex->bNoDecals = false; tex->bNoDecals = false;
tex->SourceLump = -1; // We do not really care. tex->SourceLump = -1; // We do not really care.
TexMan.AddGameTexture(MakeGameTexture(tex)); auto gtex = MakeGameTexture(tex);
charMap.Insert(int(position) + x + y * numtex_x, reinterpret_cast<FGameTexture*>(tex)); TexMan.AddGameTexture(gtex);
charMap.Insert(int(position) + x + y * numtex_x, gtex);
} }
} }
} }
@ -451,7 +452,7 @@ void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height
auto lump = charMap.CheckKey(FirstChar + i); auto lump = charMap.CheckKey(FirstChar + i);
if (lump != nullptr) if (lump != nullptr)
{ {
FTexture *pic = (*lump)->GetTexture(); auto pic = (*lump)->GetTexture();
auto b = pic->Get8BitPixels(false); auto b = pic->Get8BitPixels(false);

View File

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

View File

@ -41,6 +41,7 @@
#include "imagehelpers.h" #include "imagehelpers.h"
#include "image.h" #include "image.h"
#include "printf.h" #include "printf.h"
#include "texturemanager.h"
//========================================================================== //==========================================================================
// //
@ -608,7 +609,7 @@ FGameTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename)
// Reject anything that cannot be put into a savegame picture by GZDoom itself. // Reject anything that cannot be put into a savegame picture by GZDoom itself.
if (compression != 0 || filter != 0 || interlace > 0 || bitdepth != 8 || (colortype != 2 && colortype != 3)) return nullptr; if (compression != 0 || filter != 0 || interlace > 0 || bitdepth != 8 || (colortype != 2 && colortype != 3)) return nullptr;
else return reinterpret_cast<FGameTexture*>(new FPNGFileTexture (png->File, width, height, colortype)); else return MakeGameTexture(new FPNGFileTexture (png->File, width, height, colortype));
} }
//========================================================================== //==========================================================================

View File

@ -146,21 +146,12 @@ FMaterial::~FMaterial()
// //
//=========================================================================== //===========================================================================
IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) const
{ {
FTexture *layer = i == 0 ? imgtex : mTextureLayers[i - 1]; FTexture *layer = i == 0 ? imgtex : mTextureLayers[i - 1];
if (pLayer) *pLayer = layer; if (pLayer) *pLayer = layer;
if (layer && layer->UseType!=ETextureType::Null) if (layer) return layer->GetHardwareTexture(translation, mExpanded);
{
IHardwareTexture *hwtex = layer->SystemTextures.GetHardwareTexture(translation, mExpanded);
if (hwtex == nullptr)
{
hwtex = CreateHardwareTexture();
layer->SystemTextures.AddHardwareTexture(translation, mExpanded, hwtex);
}
return hwtex;
}
return nullptr; return nullptr;
} }

View File

@ -55,7 +55,7 @@ public:
return mTextureLayers.Size() + 1; return mTextureLayers.Size() + 1;
} }
IHardwareTexture *GetLayer(int i, int translation, FTexture **pLayer = nullptr); IHardwareTexture *GetLayer(int i, int translation, FTexture **pLayer = nullptr) const;
static FMaterial *ValidateTexture(FGameTexture * tex, bool expand, bool create = true); static FMaterial *ValidateTexture(FGameTexture * tex, bool expand, bool create = true);

View File

@ -990,6 +990,27 @@ void FTexture::SetSpriteRect()
} }
//===========================================================================
//
// Create a hardware texture for this texture image.
//
//===========================================================================
IHardwareTexture* FTexture::GetHardwareTexture(int translation, bool expanded)
{
if (UseType != ETextureType::Null)
{
IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, expanded);
if (hwtex == nullptr)
{
hwtex = CreateHardwareTexture();
SystemTextures.AddHardwareTexture(translation, expanded, hwtex);
}
return hwtex;
}
return nullptr;
}
//=========================================================================== //===========================================================================
// //
// Coordinate helper. // Coordinate helper.

View File

@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture)
hash = -1; hash = -1;
} }
TextureHash hasher = { reinterpret_cast<FGameTexture*>(texture), hash }; TextureHash hasher = { texture, hash };
int trans = Textures.Push (hasher); int trans = Textures.Push (hasher);
Translation.Push (trans); Translation.Push (trans);
if (bucket >= 0) HashFirst[bucket] = trans; if (bucket >= 0) HashFirst[bucket] = trans;
@ -445,7 +445,7 @@ void FTextureManager::ReplaceTexture (FTextureID picnum, FGameTexture *newtextur
newtexture->GetTexture()->Name = oldtexture->GetName(); newtexture->GetTexture()->Name = oldtexture->GetName();
newtexture->SetUseType(oldtexture->GetUseType()); newtexture->SetUseType(oldtexture->GetUseType());
Textures[index].Texture = reinterpret_cast<FGameTexture*>(newtexture); Textures[index].Texture = newtexture;
newtexture->GetTexture()->id = oldtexture->GetID(); newtexture->GetTexture()->id = oldtexture->GetID();
oldtexture->GetTexture()->Name = ""; oldtexture->GetTexture()->Name = "";
AddGameTexture(oldtexture); AddGameTexture(oldtexture);

View File

@ -9,6 +9,7 @@
class FxAddSub; class FxAddSub;
struct BuildInfo; struct BuildInfo;
class FMultipatchTextureBuilder;
int PalCheck(int tex); int PalCheck(int tex);
// Texture manager // Texture manager

View File

@ -49,6 +49,7 @@
typedef TMap<int, bool> SpriteHits; typedef TMap<int, bool> SpriteHits;
class FImageSource; class FImageSource;
class FGameTexture; class FGameTexture;
class IHardwareTexture;
enum MaterialShaderIndex enum MaterialShaderIndex
{ {
@ -257,6 +258,7 @@ public:
SpritePositioningInfo spi; SpritePositioningInfo spi;
int8_t mTrimResult = -1; int8_t mTrimResult = -1;
IHardwareTexture* GetHardwareTexture(int translation, bool expanded);
static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType usetype); static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType usetype);
virtual ~FTexture (); virtual ~FTexture ();
virtual FImageSource *GetImage() const { return nullptr; } virtual FImageSource *GetImage() const { return nullptr; }
@ -757,7 +759,7 @@ public:
// Since these properties will later piggyback on existing members of FGameTexture, the accessors need to be here. // Since these properties will later piggyback on existing members of FGameTexture, the accessors need to be here.
FGameTexture *GetSkyFace(int num) FGameTexture *GetSkyFace(int num)
{ {
return reinterpret_cast<FGameTexture*>(isSkybox() ? static_cast<FSkyBox*>(&wrapped)->faces[num] : nullptr); return (isSkybox() ? static_cast<FSkyBox*>(&wrapped)->faces[num] : nullptr);
} }
bool GetSkyFlip() { return isSkybox() ? static_cast<FSkyBox*>(&wrapped)->fliptop : false; } bool GetSkyFlip() { return isSkybox() ? static_cast<FSkyBox*>(&wrapped)->fliptop : false; }

View File

@ -805,7 +805,7 @@ CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
void D_Display () void D_Display ()
{ {
FTexture *wipe = nullptr; FGameTexture *wipe = nullptr;
int wipe_type; int wipe_type;
sector_t *viewsec; sector_t *viewsec;
@ -880,7 +880,7 @@ void D_Display ()
if (vr_mode == 0 || vid_rendermode != 4) if (vr_mode == 0 || vid_rendermode != 4)
{ {
// save the current screen if about to wipe // save the current screen if about to wipe
wipe = screen->WipeStartScreen (); wipe = MakeGameTexture(screen->WipeStartScreen ());
switch (wipegamestate) switch (wipegamestate)
{ {
@ -1063,9 +1063,9 @@ void D_Display ()
GSnd->SetSfxPaused(true, 1); GSnd->SetSfxPaused(true, 1);
I_FreezeTime(true); I_FreezeTime(true);
screen->End2D(); screen->End2D();
auto wipend = screen->WipeEndScreen (); auto wipend = MakeGameTexture(screen->WipeEndScreen ());
auto wiper = Wiper::Create(wipe_type); auto wiper = Wiper::Create(wipe_type);
wiper->SetTextures(reinterpret_cast<FGameTexture*>(wipe), reinterpret_cast<FGameTexture*>(wipend)); wiper->SetTextures(wipe, wipend);
wipestart = I_msTime(); wipestart = I_msTime();
NetUpdate(); // send out any new accumulation NetUpdate(); // send out any new accumulation

View File

@ -336,7 +336,7 @@ void Wiper_Burn::SetTextures(FGameTexture *startscreen, FGameTexture *endscreen)
startScreen = startscreen; startScreen = startscreen;
endScreen = endscreen; endScreen = endscreen;
BurnTexture = new FBurnTexture(WIDTH, HEIGHT); BurnTexture = new FBurnTexture(WIDTH, HEIGHT);
auto mat = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(endScreen->GetTexture()), false); auto mat = FMaterial::ValidateTexture(endScreen, false);
mat->AddTextureLayer(BurnTexture); mat->AddTextureLayer(BurnTexture);
} }

View File

@ -295,19 +295,18 @@ sector_t *FGLRenderer::RenderView(player_t* player)
// //
//=========================================================================== //===========================================================================
void FGLRenderer::BindToFrameBuffer(FMaterial *mat) void FGLRenderer::BindToFrameBuffer(FTexture *tex)
{ {
FTexture* layer; auto BaseLayer = static_cast<FHardwareTexture*>(tex->GetHardwareTexture(0, false));
auto BaseLayer = static_cast<FHardwareTexture*>(mat->GetLayer(0, 0, &layer));
if (BaseLayer == nullptr) if (BaseLayer == nullptr)
{ {
// must create the hardware texture first // must create the hardware texture first
BaseLayer->BindOrCreate(layer, 0, 0, 0, 0); BaseLayer->BindOrCreate(tex, 0, 0, 0, 0);
FHardwareTexture::Unbind(0); FHardwareTexture::Unbind(0);
gl_RenderState.ClearLastMaterial(); gl_RenderState.ClearLastMaterial();
} }
BaseLayer->BindToFrameBuffer(mat->Source()->GetTexelWidth(), mat->Source()->GetTexelHeight()); BaseLayer->BindToFrameBuffer(tex->GetTexelWidth(), tex->GetTexelHeight());
} }
//=========================================================================== //===========================================================================
@ -319,12 +318,11 @@ void FGLRenderer::BindToFrameBuffer(FMaterial *mat)
void FGLRenderer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) void FGLRenderer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV)
{ {
// This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene.
FMaterial * gltex = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(tex), false);
float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble();
StartOffscreen(); StartOffscreen();
BindToFrameBuffer(gltex); BindToFrameBuffer(tex);
IntRect bounds; IntRect bounds;
bounds.left = bounds.top = 0; bounds.left = bounds.top = 0;

View File

@ -101,7 +101,7 @@ public:
void EndOffscreen(); void EndOffscreen();
void UpdateShadowMap(); void UpdateShadowMap();
void BindToFrameBuffer(FMaterial *mat); void BindToFrameBuffer(FTexture *mat);
private: private:

View File

@ -46,11 +46,11 @@ EXTERN_CVAR(Bool, gl_precache)
// //
//========================================================================== //==========================================================================
static void PrecacheTexture(FTexture *tex, int cache) static void PrecacheTexture(FGameTexture *tex, int cache)
{ {
if (cache & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) if (cache & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky))
{ {
FMaterial * gltex = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(tex), false); FMaterial * gltex = FMaterial::ValidateTexture(tex, false);
if (gltex) screen->PrecacheMaterial(gltex, 0); if (gltex) screen->PrecacheMaterial(gltex, 0);
} }
} }
@ -74,9 +74,9 @@ static void PrecacheList(FMaterial *gltex, SpriteHits& translations)
// //
//========================================================================== //==========================================================================
static void PrecacheSprite(FTexture *tex, SpriteHits &hits) static void PrecacheSprite(FGameTexture *tex, SpriteHits &hits)
{ {
FMaterial * gltex = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(tex), true); FMaterial * gltex = FMaterial::ValidateTexture(tex, true);
if (gltex) PrecacheList(gltex, hits); if (gltex) PrecacheList(gltex, hits);
} }
@ -273,13 +273,12 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
for (int i = cnt - 1; i >= 0; i--) for (int i = cnt - 1; i >= 0; i--)
{ {
auto gtex = TexMan.GameByIndex(i); auto gtex = TexMan.GameByIndex(i);
auto tex = gtex->GetTexture(); if (gtex != nullptr)
if (tex != nullptr)
{ {
PrecacheTexture(tex, texhitlist[i]); PrecacheTexture(gtex, texhitlist[i]);
if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0) if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0)
{ {
PrecacheSprite(tex, *spritehitlist[i]); PrecacheSprite(gtex, *spritehitlist[i]);
} }
} }
} }

View File

@ -377,8 +377,7 @@ sector_t *PolyFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * ca
void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV)
{ {
// This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene.
FMaterial *mat = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(tex), false); auto BaseLayer = static_cast<PolyHardwareTexture*>(tex->GetHardwareTexture(0, false));
auto BaseLayer = static_cast<PolyHardwareTexture*>(mat->GetLayer(0, 0));
float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble();
DCanvas *image = BaseLayer->GetImage(tex, 0, 0); DCanvas *image = BaseLayer->GetImage(tex, 0, 0);

View File

@ -94,30 +94,32 @@ sector_t *SWSceneDrawer::RenderView(player_t *player)
FBTextureIndex = (FBTextureIndex + 1) % 2; FBTextureIndex = (FBTextureIndex + 1) % 2;
auto &fbtex = FBTexture[FBTextureIndex]; auto &fbtex = FBTexture[FBTextureIndex];
if (fbtex == nullptr || fbtex->GetSystemTexture() == nullptr || auto GetSystemTexture = [&]() { return fbtex->GetTexture()->SystemTextures.GetHardwareTexture(0, false); };
fbtex->GetDisplayWidth() != screen->GetWidth() ||
fbtex->GetDisplayHeight() != screen->GetHeight() || if (fbtex == nullptr || GetSystemTexture() == nullptr ||
(V_IsTrueColor() ? 1:0) != fbtex->GetColorFormat()) fbtex->GetTexelWidth() != screen->GetWidth() ||
fbtex->GetTexelHeight() != screen->GetHeight() ||
(V_IsTrueColor() ? 1:0) != static_cast<FWrapperTexture*>(fbtex->GetTexture())->GetColorFormat())
{ {
// This manually constructs its own material here. // This manually constructs its own material here.
fbtex.reset(); fbtex.reset();
fbtex.reset(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); fbtex.reset(MakeGameTexture(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())));
fbtex->GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1); GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
auto mat = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(fbtex.get()), false); auto mat = FMaterial::ValidateTexture(fbtex.get(), false);
mat->AddTextureLayer(PaletteTexture); mat->AddTextureLayer(PaletteTexture);
Canvas.reset(); Canvas.reset();
Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
} }
IHardwareTexture *systemTexture = fbtex->GetSystemTexture(); IHardwareTexture *systemTexture = GetSystemTexture();
auto buf = systemTexture->MapBuffer(); auto buf = systemTexture->MapBuffer();
if (!buf) I_FatalError("Unable to map buffer for software rendering"); if (!buf) I_FatalError("Unable to map buffer for software rendering");
SWRenderer->RenderView(player, Canvas.get(), buf, systemTexture->GetBufferPitch()); SWRenderer->RenderView(player, Canvas.get(), buf, systemTexture->GetBufferPitch());
systemTexture->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, "swbuffer"); systemTexture->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, "swbuffer");
auto map = swrenderer::CameraLight::Instance()->ShaderColormap(); auto map = swrenderer::CameraLight::Instance()->ShaderColormap();
DrawTexture(twod, reinterpret_cast<FGameTexture*>(fbtex.get()), 0, 0, DTA_SpecialColormap, map, TAG_DONE); DrawTexture(twod, fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE);
screen->Draw2D(); screen->Draw2D();
screen->Clear2D(); screen->Clear2D();
screen->PostProcessScene(CM_DEFAULT, [&]() { screen->PostProcessScene(CM_DEFAULT, [&]() {

View File

@ -13,7 +13,7 @@ class FWrapperTexture;
class SWSceneDrawer class SWSceneDrawer
{ {
FTexture *PaletteTexture; FTexture *PaletteTexture;
std::unique_ptr<FWrapperTexture> FBTexture[2]; std::unique_ptr<FGameTexture> FBTexture[2];
int FBTextureIndex = 0; int FBTextureIndex = 0;
bool FBIsTruecolor = false; bool FBIsTruecolor = false;
std::unique_ptr<DCanvas> Canvas; std::unique_ptr<DCanvas> Canvas;

View File

@ -515,9 +515,7 @@ sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor *
void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV)
{ {
// This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. auto BaseLayer = static_cast<VkHardwareTexture*>(tex->GetHardwareTexture(0, false));
FMaterial *mat = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(tex), false);
auto BaseLayer = static_cast<VkHardwareTexture*>(mat->GetLayer(0, 0));
float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble();
VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0); VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0);