From 65f15e1147a07974b2bb79480616482d9b63424b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 11 Apr 2020 19:07:08 +0200 Subject: [PATCH] - moved the material class to 'common' as well. --- src/CMakeLists.txt | 2 +- .../textures/hw_material.cpp | 62 ++++--------------- .../textures/hw_material.h | 5 -- src/common/textures/texture.cpp | 19 ++++++ .../hwrenderer/textures/hw_precache.cpp | 17 ++++- src/rendering/swrenderer/r_renderer.h | 1 + src/rendering/v_video.cpp | 6 ++ 7 files changed, 53 insertions(+), 59 deletions(-) rename src/{rendering/hwrenderer => common}/textures/hw_material.cpp (88%) rename src/{rendering/hwrenderer => common}/textures/hw_material.h (96%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 106dffd7c..3ffec49fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -973,7 +973,6 @@ set (PCH_SOURCES rendering/hwrenderer/postprocessing/hw_postprocess.cpp rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp - rendering/hwrenderer/textures/hw_material.cpp rendering/hwrenderer/textures/hw_precache.cpp rendering/hwrenderer/utility/hw_clock.cpp rendering/hwrenderer/utility/hw_cvars.cpp @@ -1080,6 +1079,7 @@ set (PCH_SOURCES common/audio/music/music_config.cpp common/thirdparty/sfmt/SFMT.cpp common/textures/hw_ihwtexture.cpp + common/textures/hw_material.cpp common/textures/bitmap.cpp common/textures/m_png.cpp common/textures/texture.cpp diff --git a/src/rendering/hwrenderer/textures/hw_material.cpp b/src/common/textures/hw_material.cpp similarity index 88% rename from src/rendering/hwrenderer/textures/hw_material.cpp rename to src/common/textures/hw_material.cpp index 28f79fe47..33406ccd9 100644 --- a/src/rendering/hwrenderer/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -22,14 +22,14 @@ #include "filesystem.h" #include "m_png.h" -#include "sbar.h" -#include "stats.h" -#include "r_utility.h" #include "c_dispatch.h" -#include "v_video.h" #include "hw_ihwtexture.h" #include "hw_material.h" #include "texturemanager.h" +#include "c_cvars.h" + +EXTERN_CVAR(Bool, gl_texture_usehires) +IHardwareTexture* CreateHardwareTexture(); //=========================================================================== // @@ -302,7 +302,7 @@ IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) IHardwareTexture *hwtex = layer->SystemTextures.GetHardwareTexture(translation, mExpanded); if (hwtex == nullptr) { - hwtex = screen->CreateHardwareTexture(); + hwtex = CreateHardwareTexture(); layer->SystemTextures.AddHardwareTexture(translation, mExpanded, hwtex); } return hwtex; @@ -310,29 +310,6 @@ IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) return nullptr; } -//=========================================================================== -// -// -// -//=========================================================================== -void FMaterial::Precache() -{ - screen->PrecacheMaterial(this, 0); -} - -//=========================================================================== -// -// -// -//=========================================================================== -void FMaterial::PrecacheList(SpriteHits &translations) -{ - tex->SystemTextures.CleanUnused(translations, mExpanded); - SpriteHits::Iterator it(translations); - SpriteHits::Pair *pair; - while(it.NextPair(pair)) screen->PrecacheMaterial(this, pair->Key); -} - //=========================================================================== // // @@ -399,6 +376,12 @@ FMaterial * FMaterial::ValidateTexture(FTextureID no, bool expand, bool translat } +void DeleteMaterial(FMaterial* mat) +{ + delete mat; +} + + //----------------------------------------------------------------------------- // // Make sprite offset adjustment user-configurable per renderer. @@ -425,26 +408,3 @@ CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) } } - -//========================================================================== -// -// this must be copied back to textures.cpp later. -// -//========================================================================== - -FWrapperTexture::FWrapperTexture(int w, int h, int bits) -{ - Width = w; - Height = h; - Format = bits; - UseType = ETextureType::SWCanvas; - bNoCompress = true; - auto hwtex = screen->CreateHardwareTexture(); - // todo: Initialize here. - SystemTextures.AddHardwareTexture(0, false, hwtex); -} - -void DeleteMaterial(FMaterial* mat) -{ - delete mat; -} diff --git a/src/rendering/hwrenderer/textures/hw_material.h b/src/common/textures/hw_material.h similarity index 96% rename from src/rendering/hwrenderer/textures/hw_material.h rename to src/common/textures/hw_material.h index 9c19202e1..f6311c962 100644 --- a/src/rendering/hwrenderer/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -5,10 +5,7 @@ #include "m_fixed.h" #include "textures.h" -#include "r_defs.h" - struct FRemapTable; -class FTextureShader; class IHardwareTexture; enum @@ -56,8 +53,6 @@ public: FMaterial(FTexture *tex, bool forceexpand); ~FMaterial(); void SetSpriteRect(); - void Precache(); - void PrecacheList(SpriteHits &translations); int GetShaderIndex() const { return mShaderIndex; } void AddTextureLayer(FTexture *tex) { diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index ef2ad07bf..74ea3c37b 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -51,6 +51,7 @@ // Wrappers to keep the definitions of these classes out of here. void DeleteMaterial(FMaterial* mat); void DeleteSoftwareTexture(FSoftwareTexture *swtex); +IHardwareTexture* CreateHardwareTexture(); FTexture *CreateBrightmapTexture(FImageSource*); @@ -846,3 +847,21 @@ void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y, bool forcewo } +//========================================================================== +// +// this must be copied back to textures.cpp later. +// +//========================================================================== + +FWrapperTexture::FWrapperTexture(int w, int h, int bits) +{ + Width = w; + Height = h; + Format = bits; + UseType = ETextureType::SWCanvas; + bNoCompress = true; + auto hwtex = CreateHardwareTexture(); + // todo: Initialize here. + SystemTextures.AddHardwareTexture(0, false, hwtex); +} + diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index d8049dc03..8d1af7948 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -51,10 +51,23 @@ static void PrecacheTexture(FTexture *tex, int cache) if (cache & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { FMaterial * gltex = FMaterial::ValidateTexture(tex, false); - if (gltex) gltex->Precache(); + if (gltex) screen->PrecacheMaterial(gltex, 0); } } +//=========================================================================== +// +// +// +//=========================================================================== +static void PrecacheList(FMaterial *gltex, SpriteHits& translations) +{ + gltex->tex->SystemTextures.CleanUnused(translations, gltex->isExpanded()); + SpriteHits::Iterator it(translations); + SpriteHits::Pair* pair; + while (it.NextPair(pair)) screen->PrecacheMaterial(gltex, pair->Key); +} + //========================================================================== // // DFrameBuffer :: PrecacheSprite @@ -64,7 +77,7 @@ static void PrecacheTexture(FTexture *tex, int cache) static void PrecacheSprite(FTexture *tex, SpriteHits &hits) { FMaterial * gltex = FMaterial::ValidateTexture(tex, true); - if (gltex) gltex->PrecacheList(hits); + if (gltex) PrecacheList(gltex, hits); } //========================================================================== diff --git a/src/rendering/swrenderer/r_renderer.h b/src/rendering/swrenderer/r_renderer.h index 1f3dec145..a8c84c168 100644 --- a/src/rendering/swrenderer/r_renderer.h +++ b/src/rendering/swrenderer/r_renderer.h @@ -15,6 +15,7 @@ class FCanvasTexture; class FileWriter; class DCanvas; struct FLevelLocals; +class PClassActor; struct FRenderer { diff --git a/src/rendering/v_video.cpp b/src/rendering/v_video.cpp index e22cdc128..3a5fb797f 100644 --- a/src/rendering/v_video.cpp +++ b/src/rendering/v_video.cpp @@ -567,3 +567,9 @@ DEFINE_GLOBAL(CleanYfac_1) DEFINE_GLOBAL(CleanWidth_1) DEFINE_GLOBAL(CleanHeight_1) DEFINE_GLOBAL(generic_ui) + +IHardwareTexture* CreateHardwareTexture() +{ + return screen->CreateHardwareTexture(); +} +