mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +00:00
- 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:
parent
7bdef7fe9a
commit
662fa6e667
18 changed files with 68 additions and 56 deletions
|
@ -425,8 +425,9 @@ void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height
|
|||
tex->bWorldPanning = true;
|
||||
tex->bNoDecals = false;
|
||||
tex->SourceLump = -1; // We do not really care.
|
||||
TexMan.AddGameTexture(MakeGameTexture(tex));
|
||||
charMap.Insert(int(position) + x + y * numtex_x, reinterpret_cast<FGameTexture*>(tex));
|
||||
auto gtex = MakeGameTexture(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);
|
||||
if (lump != nullptr)
|
||||
{
|
||||
FTexture *pic = (*lump)->GetTexture();
|
||||
auto pic = (*lump)->GetTexture();
|
||||
|
||||
auto b = pic->Get8BitPixels(false);
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include "name.h"
|
||||
|
||||
class DCanvas;
|
||||
class FTexture;
|
||||
class FGameTexture;
|
||||
struct FRemapTable;
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "imagehelpers.h"
|
||||
#include "image.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.
|
||||
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));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
|
@ -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];
|
||||
if (pLayer) *pLayer = layer;
|
||||
|
||||
if (layer && layer->UseType!=ETextureType::Null)
|
||||
{
|
||||
IHardwareTexture *hwtex = layer->SystemTextures.GetHardwareTexture(translation, mExpanded);
|
||||
if (hwtex == nullptr)
|
||||
{
|
||||
hwtex = CreateHardwareTexture();
|
||||
layer->SystemTextures.AddHardwareTexture(translation, mExpanded, hwtex);
|
||||
}
|
||||
return hwtex;
|
||||
}
|
||||
if (layer) return layer->GetHardwareTexture(translation, mExpanded);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture)
|
|||
hash = -1;
|
||||
}
|
||||
|
||||
TextureHash hasher = { reinterpret_cast<FGameTexture*>(texture), hash };
|
||||
TextureHash hasher = { texture, hash };
|
||||
int trans = Textures.Push (hasher);
|
||||
Translation.Push (trans);
|
||||
if (bucket >= 0) HashFirst[bucket] = trans;
|
||||
|
@ -445,7 +445,7 @@ void FTextureManager::ReplaceTexture (FTextureID picnum, FGameTexture *newtextur
|
|||
|
||||
newtexture->GetTexture()->Name = oldtexture->GetName();
|
||||
newtexture->SetUseType(oldtexture->GetUseType());
|
||||
Textures[index].Texture = reinterpret_cast<FGameTexture*>(newtexture);
|
||||
Textures[index].Texture = newtexture;
|
||||
newtexture->GetTexture()->id = oldtexture->GetID();
|
||||
oldtexture->GetTexture()->Name = "";
|
||||
AddGameTexture(oldtexture);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
class FxAddSub;
|
||||
struct BuildInfo;
|
||||
class FMultipatchTextureBuilder;
|
||||
int PalCheck(int tex);
|
||||
|
||||
// Texture manager
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
typedef TMap<int, bool> SpriteHits;
|
||||
class FImageSource;
|
||||
class FGameTexture;
|
||||
class IHardwareTexture;
|
||||
|
||||
enum MaterialShaderIndex
|
||||
{
|
||||
|
@ -257,6 +258,7 @@ public:
|
|||
SpritePositioningInfo spi;
|
||||
int8_t mTrimResult = -1;
|
||||
|
||||
IHardwareTexture* GetHardwareTexture(int translation, bool expanded);
|
||||
static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType usetype);
|
||||
virtual ~FTexture ();
|
||||
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.
|
||||
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; }
|
||||
|
||||
|
|
|
@ -805,7 +805,7 @@ CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
|||
|
||||
void D_Display ()
|
||||
{
|
||||
FTexture *wipe = nullptr;
|
||||
FGameTexture *wipe = nullptr;
|
||||
int wipe_type;
|
||||
sector_t *viewsec;
|
||||
|
||||
|
@ -880,7 +880,7 @@ void D_Display ()
|
|||
if (vr_mode == 0 || vid_rendermode != 4)
|
||||
{
|
||||
// save the current screen if about to wipe
|
||||
wipe = screen->WipeStartScreen ();
|
||||
wipe = MakeGameTexture(screen->WipeStartScreen ());
|
||||
|
||||
switch (wipegamestate)
|
||||
{
|
||||
|
@ -1063,9 +1063,9 @@ void D_Display ()
|
|||
GSnd->SetSfxPaused(true, 1);
|
||||
I_FreezeTime(true);
|
||||
screen->End2D();
|
||||
auto wipend = screen->WipeEndScreen ();
|
||||
auto wipend = MakeGameTexture(screen->WipeEndScreen ());
|
||||
auto wiper = Wiper::Create(wipe_type);
|
||||
wiper->SetTextures(reinterpret_cast<FGameTexture*>(wipe), reinterpret_cast<FGameTexture*>(wipend));
|
||||
wiper->SetTextures(wipe, wipend);
|
||||
|
||||
wipestart = I_msTime();
|
||||
NetUpdate(); // send out any new accumulation
|
||||
|
|
|
@ -336,7 +336,7 @@ void Wiper_Burn::SetTextures(FGameTexture *startscreen, FGameTexture *endscreen)
|
|||
startScreen = startscreen;
|
||||
endScreen = endscreen;
|
||||
BurnTexture = new FBurnTexture(WIDTH, HEIGHT);
|
||||
auto mat = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(endScreen->GetTexture()), false);
|
||||
auto mat = FMaterial::ValidateTexture(endScreen, false);
|
||||
mat->AddTextureLayer(BurnTexture);
|
||||
}
|
||||
|
||||
|
|
|
@ -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*>(mat->GetLayer(0, 0, &layer));
|
||||
auto BaseLayer = static_cast<FHardwareTexture*>(tex->GetHardwareTexture(0, false));
|
||||
|
||||
if (BaseLayer == nullptr)
|
||||
{
|
||||
// must create the hardware texture first
|
||||
BaseLayer->BindOrCreate(layer, 0, 0, 0, 0);
|
||||
BaseLayer->BindOrCreate(tex, 0, 0, 0, 0);
|
||||
FHardwareTexture::Unbind(0);
|
||||
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)
|
||||
{
|
||||
// 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();
|
||||
|
||||
StartOffscreen();
|
||||
BindToFrameBuffer(gltex);
|
||||
BindToFrameBuffer(tex);
|
||||
|
||||
IntRect bounds;
|
||||
bounds.left = bounds.top = 0;
|
||||
|
|
|
@ -101,7 +101,7 @@ public:
|
|||
void EndOffscreen();
|
||||
void UpdateShadowMap();
|
||||
|
||||
void BindToFrameBuffer(FMaterial *mat);
|
||||
void BindToFrameBuffer(FTexture *mat);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(tex), false);
|
||||
FMaterial * gltex = FMaterial::ValidateTexture(tex, false);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -273,13 +273,12 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
|
|||
for (int i = cnt - 1; i >= 0; i--)
|
||||
{
|
||||
auto gtex = TexMan.GameByIndex(i);
|
||||
auto tex = gtex->GetTexture();
|
||||
if (tex != nullptr)
|
||||
if (gtex != nullptr)
|
||||
{
|
||||
PrecacheTexture(tex, texhitlist[i]);
|
||||
PrecacheTexture(gtex, texhitlist[i]);
|
||||
if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0)
|
||||
{
|
||||
PrecacheSprite(tex, *spritehitlist[i]);
|
||||
PrecacheSprite(gtex, *spritehitlist[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -377,8 +377,7 @@ sector_t *PolyFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * ca
|
|||
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.
|
||||
FMaterial *mat = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(tex), false);
|
||||
auto BaseLayer = static_cast<PolyHardwareTexture*>(mat->GetLayer(0, 0));
|
||||
auto BaseLayer = static_cast<PolyHardwareTexture*>(tex->GetHardwareTexture(0, false));
|
||||
|
||||
float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble();
|
||||
DCanvas *image = BaseLayer->GetImage(tex, 0, 0);
|
||||
|
|
|
@ -94,30 +94,32 @@ sector_t *SWSceneDrawer::RenderView(player_t *player)
|
|||
FBTextureIndex = (FBTextureIndex + 1) % 2;
|
||||
auto &fbtex = FBTexture[FBTextureIndex];
|
||||
|
||||
if (fbtex == nullptr || fbtex->GetSystemTexture() == nullptr ||
|
||||
fbtex->GetDisplayWidth() != screen->GetWidth() ||
|
||||
fbtex->GetDisplayHeight() != screen->GetHeight() ||
|
||||
(V_IsTrueColor() ? 1:0) != fbtex->GetColorFormat())
|
||||
auto GetSystemTexture = [&]() { return fbtex->GetTexture()->SystemTextures.GetHardwareTexture(0, false); };
|
||||
|
||||
if (fbtex == nullptr || GetSystemTexture() == nullptr ||
|
||||
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.
|
||||
fbtex.reset();
|
||||
fbtex.reset(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
|
||||
fbtex->GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
|
||||
auto mat = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(fbtex.get()), false);
|
||||
fbtex.reset(MakeGameTexture(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())));
|
||||
GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1);
|
||||
auto mat = FMaterial::ValidateTexture(fbtex.get(), false);
|
||||
mat->AddTextureLayer(PaletteTexture);
|
||||
|
||||
Canvas.reset();
|
||||
Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()));
|
||||
}
|
||||
|
||||
IHardwareTexture *systemTexture = fbtex->GetSystemTexture();
|
||||
IHardwareTexture *systemTexture = GetSystemTexture();
|
||||
auto buf = systemTexture->MapBuffer();
|
||||
if (!buf) I_FatalError("Unable to map buffer for software rendering");
|
||||
SWRenderer->RenderView(player, Canvas.get(), buf, systemTexture->GetBufferPitch());
|
||||
systemTexture->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, "swbuffer");
|
||||
|
||||
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->Clear2D();
|
||||
screen->PostProcessScene(CM_DEFAULT, [&]() {
|
||||
|
|
|
@ -13,7 +13,7 @@ class FWrapperTexture;
|
|||
class SWSceneDrawer
|
||||
{
|
||||
FTexture *PaletteTexture;
|
||||
std::unique_ptr<FWrapperTexture> FBTexture[2];
|
||||
std::unique_ptr<FGameTexture> FBTexture[2];
|
||||
int FBTextureIndex = 0;
|
||||
bool FBIsTruecolor = false;
|
||||
std::unique_ptr<DCanvas> Canvas;
|
||||
|
|
|
@ -515,9 +515,7 @@ sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor *
|
|||
|
||||
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.
|
||||
FMaterial *mat = FMaterial::ValidateTexture(reinterpret_cast<FGameTexture*>(tex), false);
|
||||
auto BaseLayer = static_cast<VkHardwareTexture*>(mat->GetLayer(0, 0));
|
||||
auto BaseLayer = static_cast<VkHardwareTexture*>(tex->GetHardwareTexture(0, false));
|
||||
|
||||
float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble();
|
||||
VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0);
|
||||
|
|
Loading…
Reference in a new issue