From fb6ee5046c5aba89d1321fa59acf21d20b0ee4af Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 12 Dec 2018 02:28:42 +0100 Subject: [PATCH] - add the hardware texture container to FTexture. Currently it does not use the translated entries yet. # Conflicts: # src/hwrenderer/textures/hw_material.cpp --- src/gl/system/gl_framebuffer.cpp | 8 ++++---- src/hwrenderer/textures/hw_texcontainer.h | 14 ++++++++++---- src/swrenderer/r_swscene.cpp | 8 ++++---- src/textures/texture.cpp | 5 +---- src/textures/textures.h | 8 +++++--- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index ca2616cfd..fda8ae9df 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -515,9 +515,9 @@ FTexture *OpenGLFrameBuffer::WipeStartScreen() const auto &viewport = screen->mScreenViewport; auto tex = new FWrapperTexture(viewport.width, viewport.height, 1); - tex->GetSystemTexture(0)->CreateTexture(nullptr, viewport.width, viewport.height, 0, false, 0, "WipeStartScreen"); + tex->GetSystemTexture()->CreateTexture(nullptr, viewport.width, viewport.height, 0, false, 0, "WipeStartScreen"); glFinish(); - static_cast(tex->GetSystemTexture(0))->Bind(0, false, false); + static_cast(tex->GetSystemTexture())->Bind(0, false, false); GLRenderer->mBuffers->BindCurrentFB(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height); @@ -537,9 +537,9 @@ FTexture *OpenGLFrameBuffer::WipeEndScreen() GLRenderer->Flush(); const auto &viewport = screen->mScreenViewport; auto tex = new FWrapperTexture(viewport.width, viewport.height, 1); - tex->GetSystemTexture(0)->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0, "WipeEndScreen"); + tex->GetSystemTexture()->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0, "WipeEndScreen"); glFinish(); - static_cast(tex->GetSystemTexture(0))->Bind(0, false, false); + static_cast(tex->GetSystemTexture())->Bind(0, false, false); GLRenderer->mBuffers->BindCurrentFB(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height); return tex; diff --git a/src/hwrenderer/textures/hw_texcontainer.h b/src/hwrenderer/textures/hw_texcontainer.h index d5836d82b..96cd8fa3c 100644 --- a/src/hwrenderer/textures/hw_texcontainer.h +++ b/src/hwrenderer/textures/hw_texcontainer.h @@ -1,8 +1,10 @@ #pragma once #include "tarray.h" +#include "hwrenderer/textures/hw_ihwtexture.h" struct FTextureBuffer; +class IHardwareTexture; class FHardwareTextureContainer { @@ -49,10 +51,10 @@ private: unsigned index = hwTex_Translated.FindEx([=](auto &element) { return element.translation == translation; - } + }); if (index < hwTex_Translated.Size()) { - return &hwTex_Translated[i]; + return &hwTex_Translated[index]; } int add = hwTex_Translated.Reserve(1); @@ -65,7 +67,11 @@ public: void Clean(bool all) { - if (all) hwDefTex.Delete(); + if (all) + { + hwDefTex[0].Delete(); + hwDefTex[1].Delete(); + } hwTex_Translated.Clear(); } @@ -90,7 +96,7 @@ public: // //=========================================================================== - void FHardwareTexture::CleanUnused(SpriteHits &usedtranslations, bool expanded) + void CleanUnused(SpriteHits &usedtranslations, bool expanded) { if (usedtranslations.CheckKey(0) == nullptr) { diff --git a/src/swrenderer/r_swscene.cpp b/src/swrenderer/r_swscene.cpp index 88a5417b6..807a3126e 100644 --- a/src/swrenderer/r_swscene.cpp +++ b/src/swrenderer/r_swscene.cpp @@ -91,7 +91,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) FBTextureIndex = (FBTextureIndex + 1) % 2; auto &fbtex = FBTexture[FBTextureIndex]; - if (fbtex == nullptr || fbtex->GetSystemTexture(0) == nullptr || + if (fbtex == nullptr || fbtex->GetSystemTexture() == nullptr || fbtex->GetDisplayWidth() != screen->GetWidth() || fbtex->GetDisplayHeight() != screen->GetHeight() || (V_IsTrueColor() ? 1:0) != fbtex->GetColorFormat()) @@ -99,7 +99,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) // This manually constructs its own material here. fbtex.reset(); fbtex.reset(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); - fbtex->GetSystemTexture(0)->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1); + fbtex->GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1); auto mat = FMaterial::ValidateTexture(fbtex.get(), false); mat->AddTextureLayer(PaletteTexture); @@ -107,10 +107,10 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); } - auto buf = fbtex->GetSystemTexture(0)->MapBuffer(); + auto buf = fbtex->GetSystemTexture()->MapBuffer(); if (!buf) I_FatalError("Unable to map buffer for software rendering"); SWRenderer->RenderView(player, Canvas.get(), buf); - fbtex->GetSystemTexture(0)->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer"); + fbtex->GetSystemTexture()->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, 0, "swbuffer"); auto map = swrenderer::CameraLight::Instance()->ShaderColormap(); screen->DrawTexture(fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index d760296ec..7dfd00484 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -178,9 +178,6 @@ FTexture::~FTexture () { if (Material[i] != nullptr) delete Material[i]; Material[i] = nullptr; - - if (SystemTexture[i] != nullptr) delete SystemTexture[i]; - SystemTexture[i] = nullptr; } if (SoftwareTexture != nullptr) { @@ -793,7 +790,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) Format = bits; UseType = ETextureType::SWCanvas; bNoCompress = true; - SystemTexture[0] = screen->CreateHardwareTexture(); + SystemTextures.AddHardwareTexture(0, false, screen->CreateHardwareTexture()); } //=========================================================================== diff --git a/src/textures/textures.h b/src/textures/textures.h index 366e3ecc3..199ce0be8 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -42,6 +42,7 @@ #include "colormatcher.h" #include "r_data/renderstyle.h" #include "r_data/r_translate.h" +#include "hwrenderer/textures/hw_texcontainer.h" #include // 15 because 0th texture is our texture @@ -344,7 +345,8 @@ protected: FTextureID id; FMaterial *Material[2] = { nullptr, nullptr }; - IHardwareTexture *SystemTexture[2] = { nullptr, nullptr }; + FHardwareTextureContainer SystemTextures; + //IHardwareTexture *SystemTexture[2] = { nullptr, nullptr }; FSoftwareTexture *SoftwareTexture = nullptr; // None of the following pointers are owned by this texture, they are all controlled by the texture manager. @@ -710,9 +712,9 @@ class FWrapperTexture : public FTexture int Format; public: FWrapperTexture(int w, int h, int bits = 1); - IHardwareTexture *GetSystemTexture(int slot) + IHardwareTexture *GetSystemTexture() { - return SystemTexture[slot]; + return SystemTextures.GetHardwareTexture(0, false); } int GetColorFormat() const