diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index a1135f89a..5fb4641be 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -425,8 +425,9 @@ void FFont::ReadSheetFont(TArray &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(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 &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); diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 536b07ba3..4e78da08f 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -39,7 +39,6 @@ #include "name.h" class DCanvas; -class FTexture; class FGameTexture; struct FRemapTable; diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index 36ce398d3..75e578b68 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -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(new FPNGFileTexture (png->File, width, height, colortype)); + else return MakeGameTexture(new FPNGFileTexture (png->File, width, height, colortype)); } //========================================================================== diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 7ab3f1321..3a97d5a23 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -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; } diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index a9d1812d3..0f8fd8dad 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -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); diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 0636822d2..a5e6e138e 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -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. diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index f35a8af2b..32d66d1b0 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) hash = -1; } - TextureHash hasher = { reinterpret_cast(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(newtexture); + Textures[index].Texture = newtexture; newtexture->GetTexture()->id = oldtexture->GetID(); oldtexture->GetTexture()->Name = ""; AddGameTexture(oldtexture); diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 774ad3a27..641b97c47 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -9,6 +9,7 @@ class FxAddSub; struct BuildInfo; +class FMultipatchTextureBuilder; int PalCheck(int tex); // Texture manager diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 6322d91ab..6753d8ed1 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -49,6 +49,7 @@ typedef TMap 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(isSkybox() ? static_cast(&wrapped)->faces[num] : nullptr); + return (isSkybox() ? static_cast(&wrapped)->faces[num] : nullptr); } bool GetSkyFlip() { return isSkybox() ? static_cast(&wrapped)->fliptop : false; } diff --git a/src/d_main.cpp b/src/d_main.cpp index b6c048149..98f0a884e 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -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(wipe), reinterpret_cast(wipend)); + wiper->SetTextures(wipe, wipend); wipestart = I_msTime(); NetUpdate(); // send out any new accumulation diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index 464f93427..80e425718 100644 --- a/src/rendering/2d/f_wipe.cpp +++ b/src/rendering/2d/f_wipe.cpp @@ -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(endScreen->GetTexture()), false); + auto mat = FMaterial::ValidateTexture(endScreen, false); mat->AddTextureLayer(BurnTexture); } diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index d3b80ad34..ee5fbb09a 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -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(mat->GetLayer(0, 0, &layer)); + auto BaseLayer = static_cast(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(tex), false); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); StartOffscreen(); - BindToFrameBuffer(gltex); + BindToFrameBuffer(tex); IntRect bounds; bounds.left = bounds.top = 0; diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index 91ac325d5..bf59a5532 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -101,7 +101,7 @@ public: void EndOffscreen(); void UpdateShadowMap(); - void BindToFrameBuffer(FMaterial *mat); + void BindToFrameBuffer(FTexture *mat); private: diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 7f52a5393..fa695f925 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -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(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(tex), true); + FMaterial * gltex = FMaterial::ValidateTexture(tex, true); if (gltex) PrecacheList(gltex, hits); } @@ -273,13 +273,12 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &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]); } } } diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 827291f9c..e8b1c5c87 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -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(tex), false); - auto BaseLayer = static_cast(mat->GetLayer(0, 0)); + auto BaseLayer = static_cast(tex->GetHardwareTexture(0, false)); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); DCanvas *image = BaseLayer->GetImage(tex, 0, 0); diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index f3ed9b296..ac5c382a9 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -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(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(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(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, [&]() { diff --git a/src/rendering/swrenderer/r_swscene.h b/src/rendering/swrenderer/r_swscene.h index 7dc12488d..ad6b6d450 100644 --- a/src/rendering/swrenderer/r_swscene.h +++ b/src/rendering/swrenderer/r_swscene.h @@ -13,7 +13,7 @@ class FWrapperTexture; class SWSceneDrawer { FTexture *PaletteTexture; - std::unique_ptr FBTexture[2]; + std::unique_ptr FBTexture[2]; int FBTextureIndex = 0; bool FBIsTruecolor = false; std::unique_ptr Canvas; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 24c5075eb..dd4ef1d79 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -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(tex), false); - auto BaseLayer = static_cast(mat->GetLayer(0, 0)); + auto BaseLayer = static_cast(tex->GetHardwareTexture(0, false)); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0);