From 8381092cce992d2ea369065162a8d162908f3bff Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 12 Apr 2020 22:10:15 +0200 Subject: [PATCH 001/220] - major shader rework * handle brightmaps in the main shader instead of keeping separate instances around. * added detail and glow layers from Raze. * fixed material setup which could not guarantee that everything was initialized correctly. * for warped textures, warp all layers. With this brightmaps finally work on warped textures. Note: Vulkan reports a "device lost" error with this which still needs to be investigated. --- src/CMakeLists.txt | 4 +- src/common/2d/v_2ddrawer.cpp | 2 +- src/common/2d/v_2ddrawer.h | 2 +- src/common/filesystem/filesystem.h | 2 +- src/common/textures/formats/emptytexture.cpp | 5 ++ src/common/textures/hw_material.cpp | 42 +++++++---- src/common/textures/hw_material.h | 2 + src/common/textures/texture.cpp | 4 +- src/common/textures/texturemanager.cpp | 5 ++ src/common/textures/textures.h | 23 +++++- src/r_data/gldefs.cpp | 27 ++++--- src/rendering/gl/renderer/gl_renderstate.cpp | 7 +- src/rendering/gl/shaders/gl_shader.cpp | 50 ++++++++++--- src/rendering/gl/shaders/gl_shader.h | 5 +- .../hwrenderer/scene/hw_renderstate.h | 21 ++++-- .../hwrenderer/utility/hw_shaderpatcher.cpp | 3 - .../polyrenderer/backend/poly_renderstate.cpp | 2 +- .../vulkan/renderer/vk_renderstate.cpp | 4 +- src/rendering/vulkan/shaders/vk_shader.cpp | 43 ++++++++--- wadsrc/static/shaders/glsl/func_brightmap.fp | 9 --- .../static/shaders/glsl/func_defaultlight.fp | 12 ---- wadsrc/static/shaders/glsl/func_defaultmat.fp | 6 +- .../static/shaders/glsl/func_defaultmat2.fp | 6 ++ wadsrc/static/shaders/glsl/func_normal.fp | 7 +- wadsrc/static/shaders/glsl/func_pbr.fp | 10 +-- wadsrc/static/shaders/glsl/func_spec.fp | 10 +-- wadsrc/static/shaders/glsl/func_warp1.fp | 11 +-- wadsrc/static/shaders/glsl/func_warp2.fp | 12 ++-- wadsrc/static/shaders/glsl/func_warp3.fp | 12 ++-- wadsrc/static/shaders/glsl/func_wavex.fp | 9 ++- wadsrc/static/shaders/glsl/main.fp | 72 +++++++++++++++++-- 31 files changed, 294 insertions(+), 135 deletions(-) delete mode 100644 wadsrc/static/shaders/glsl/func_brightmap.fp create mode 100644 wadsrc/static/shaders/glsl/func_defaultmat2.fp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d39eca9dde..95c07ac7df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1465,8 +1465,8 @@ source_group("Common\\Scripting\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_S source_group("Common\\Scripting\\Core" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/core/.+") source_group("Common\\Scripting\\JIT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/jit/.+") source_group("Common\\Scripting\\VM" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/vm/.+") -source_group("Common\\Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/.+") -source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl_load/.+") +source_group("Common\\Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/.+") +source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+") source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+") source_group("Common\\Textures\\Hires" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/.+") source_group("Common\\Textures\\Hires\\HQ Resize" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/hqnx/.+") diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 39398b8007..4cee865ab3 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -755,7 +755,7 @@ void F2DDrawer::ClearScreen(PalEntry color) // //========================================================================== -void F2DDrawer::AddLine(float x1, float y1, float x2, float y2, int clipx1, int clipy1, int clipx2, int clipy2, uint32_t color, uint8_t alpha) +void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, int clipx1, int clipy1, int clipx2, int clipy2, uint32_t color, uint8_t alpha) { PalEntry p = (PalEntry)color; p.a = alpha; diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index ed4c1ee94d..7c759b1954 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -190,7 +190,7 @@ public: void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color); - void AddLine(float x1, float y1, float x2, float y2, int cx, int cy, int cx2, int cy2, uint32_t color, uint8_t alpha = 255); + void AddLine(double x1, double y1, double x2, double y2, int cx, int cy, int cx2, int cy2, uint32_t color, uint8_t alpha = 255); void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha = 255); void AddPixel(int x1, int y1, uint32_t color); diff --git a/src/common/filesystem/filesystem.h b/src/common/filesystem/filesystem.h index f71aefb85d..dd5cc8234f 100644 --- a/src/common/filesystem/filesystem.h +++ b/src/common/filesystem/filesystem.h @@ -38,7 +38,7 @@ public: ~FileData (); void *GetMem () { return Block.Len() == 0 ? NULL : (void *)Block.GetChars(); } size_t GetSize () { return Block.Len(); } - FString GetString () { return Block; } + const FString &GetString () const { return Block; } private: FileData (const FString &source); diff --git a/src/common/textures/formats/emptytexture.cpp b/src/common/textures/formats/emptytexture.cpp index ab4703e4ee..bcbd682e0c 100644 --- a/src/common/textures/formats/emptytexture.cpp +++ b/src/common/textures/formats/emptytexture.cpp @@ -69,6 +69,11 @@ FImageSource *EmptyImage_TryCreate(FileReader & file, int lumpnum) return new FEmptyTexture(lumpnum); } +FImageSource* CreateEmptyTexture() +{ + return new FEmptyTexture(0); +} + //========================================================================== // // diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 803cd34e42..8c0bc06ef8 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -45,10 +45,6 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) { mShaderIndex = SHADER_Paletted; } - else if (tx->isWarped()) - { - mShaderIndex = tx->isWarped(); // This picks SHADER_Warp1 or SHADER_Warp2 - } else if (tx->isHardwareCanvas()) { if (tx->shaderindex >= FIRST_USER_SHADER) @@ -59,7 +55,11 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) } else { - if (tx->Normal && tx->Specular) + if (tx->isWarped()) + { + mShaderIndex = tx->isWarped(); // This picks SHADER_Warp1 or SHADER_Warp2 + } + else if (tx->Normal && tx->Specular) { for (auto &texture : { tx->Normal, tx->Specular }) { @@ -76,16 +76,34 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) mShaderIndex = SHADER_PBR; } + // Note that these layers must present a valid texture even if not used, because empty TMUs in the shader are an undefined condition. tx->CreateDefaultBrightmap(); if (tx->Brightmap) { mTextureLayers.Push(tx->Brightmap); - if (mShaderIndex == SHADER_Specular) - mShaderIndex = SHADER_SpecularBrightmap; - else if (mShaderIndex == SHADER_PBR) - mShaderIndex = SHADER_PBRBrightmap; - else - mShaderIndex = SHADER_Brightmap; + mLayerFlags |= TEXF_Brightmap; + } + else + { + mTextureLayers.Push(TexMan.ByIndex(1)); + } + if (tx->Detailmap) + { + mTextureLayers.Push(tx->Detailmap); + mLayerFlags |= TEXF_Detailmap; + } + else + { + mTextureLayers.Push(TexMan.ByIndex(1)); + } + if (tx->Glowmap) + { + mTextureLayers.Push(tx->Glowmap); + mLayerFlags |= TEXF_Glowmap; + } + else + { + mTextureLayers.Push(TexMan.ByIndex(1)); } if (tx->shaderindex >= FIRST_USER_SHADER) @@ -347,7 +365,7 @@ again: { if (expand) { - if (tex->isWarped() || tex->isHardwareCanvas() || tex->shaderindex >= FIRST_USER_SHADER || (tex->shaderindex >= SHADER_Specular && tex->shaderindex <= SHADER_PBRBrightmap)) + if (tex->isWarped() || tex->isHardwareCanvas() || tex->shaderindex >= FIRST_USER_SHADER || tex->shaderindex == SHADER_Specular || tex->shaderindex == SHADER_PBR) { tex->bNoExpand = true; goto again; diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index f6311c9628..0265573768 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -30,6 +30,7 @@ class FMaterial { TArray mTextureLayers; int mShaderIndex; + int mLayerFlags = 0; short mLeftOffset; short mTopOffset; @@ -52,6 +53,7 @@ public: FMaterial(FTexture *tex, bool forceexpand); ~FMaterial(); + int GetLayerFlags() const { return mLayerFlags; } void SetSpriteRect(); int GetShaderIndex() const { return mShaderIndex; } void AddTextureLayer(FTexture *tex) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 401b61b13f..be2b730e79 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -116,7 +116,7 @@ FTexture::FTexture (const char *name, int lumpnum) : Scale(1,1), SourceLump(lumpnum), UseType(ETextureType::Any), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), - bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bFullNameTexture(false), + bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(1), bComplex(false), bMultiPatch(false), bFullNameTexture(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { bBrightmapChecked = false; @@ -384,7 +384,7 @@ void FTexture::CreateDefaultBrightmap() // Check for brightmaps if (GetImage() && GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap && UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar && - Brightmap == NULL && bWarped == 0) + Brightmap == NULL) { // May have one - let's check when we use this texture auto texbuf = Get8BitPixels(false); diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 66a196a310..76024b4ecd 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -1083,6 +1083,7 @@ void FTextureManager::AddLocalizedVariants() //========================================================================== FTexture *CreateShaderTexture(bool, bool); void InitBuildTiles(); +FImageSource* CreateEmptyTexture(); void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildInfo&)) { @@ -1094,6 +1095,10 @@ void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildI auto nulltex = new FImageTexture(nullptr, ""); nulltex->SetUseType(ETextureType::Null); AddTexture (nulltex); + // This is for binding to unused texture units, because accessing an unbound texture unit is undefined. It's a one pixel empty texture. + auto emptytex = new FImageTexture(CreateEmptyTexture(), ""); + emptytex->SetSize(1, 1); + AddTexture(emptytex); // some special textures used in the game. AddTexture(CreateShaderTexture(false, false)); AddTexture(CreateShaderTexture(false, true)); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index e1fa263fde..cefb39114b 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -54,11 +54,8 @@ enum MaterialShaderIndex SHADER_Default, SHADER_Warp1, SHADER_Warp2, - SHADER_Brightmap, SHADER_Specular, - SHADER_SpecularBrightmap, SHADER_PBR, - SHADER_PBRBrightmap, SHADER_Paletted, SHADER_NoTexture, SHADER_BasicFuzz, @@ -72,12 +69,30 @@ enum MaterialShaderIndex FIRST_USER_SHADER }; +enum texflags +{ + // These get Or'ed into uTextureMode because it only uses its 3 lowermost bits. + TEXF_Brightmap = 0x10000, + TEXF_Detailmap = 0x20000, + TEXF_Glowmap = 0x40000, +}; + + + +enum +{ + SFlag_Brightmap = 1, + SFlag_Detailmap = 2, + SFlag_Glowmap = 4, +}; + struct UserShaderDesc { FString shader; MaterialShaderIndex shaderType; FString defines; bool disablealphatest = false; + uint8_t shaderFlags = 0; }; extern TArray usershaders; @@ -341,6 +356,8 @@ protected: FTexture *PalVersion = nullptr; // Material layers FTexture *Brightmap = nullptr; + FTexture* Detailmap = nullptr; + FTexture* Glowmap = nullptr; FTexture *Normal = nullptr; // Normal map texture FTexture *Specular = nullptr; // Specular light texture for the diffuse+normal+specular light model FTexture *Metallic = nullptr; // Metalness texture for the physically based rendering (PBR) light model diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index a8f68d5f18..40f32f306b 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -1372,18 +1372,18 @@ class GLDefsParser int firstUserTexture; if (tex->Normal && tex->Specular) { - usershader.shaderType = tex->Brightmap ? SHADER_SpecularBrightmap : SHADER_Specular; - firstUserTexture = tex->Brightmap ? 5 : 4; + usershader.shaderType = SHADER_Specular; + firstUserTexture = 7; } else if (tex->Normal && tex->Metallic && tex->Roughness && tex->AmbientOcclusion) { - usershader.shaderType = tex->Brightmap ? SHADER_PBRBrightmap : SHADER_PBR; - firstUserTexture = tex->Brightmap ? 7 : 6; + usershader.shaderType = SHADER_PBR; + firstUserTexture = 9; } else { - usershader.shaderType = tex->Brightmap ? SHADER_Brightmap : SHADER_Default; - firstUserTexture = tex->Brightmap ? 3 : 2; + usershader.shaderType = SHADER_Default; + firstUserTexture = 5; } for (unsigned int i = 0; i < texNameList.Size(); i++) @@ -1537,14 +1537,16 @@ class GLDefsParser else if (sc.Compare("material")) { sc.MustGetString(); - MaterialShaderIndex typeIndex[6] = { SHADER_Default, SHADER_Brightmap, SHADER_Specular, SHADER_SpecularBrightmap, SHADER_PBR, SHADER_PBRBrightmap }; - const char *typeName[6] = { "normal", "brightmap", "specular", "specularbrightmap", "pbr", "pbrbrightmap" }; + static MaterialShaderIndex typeIndex[6] = { SHADER_Default, SHADER_Default, SHADER_Specular, SHADER_Specular, SHADER_PBR, SHADER_PBR }; + static bool usesBrightmap[6] = { false, true, false, true, false, true }; + static const char *typeName[6] = { "normal", "brightmap", "specular", "specularbrightmap", "pbr", "pbrbrightmap" }; bool found = false; for (int i = 0; i < 6; i++) { if (sc.Compare(typeName[i])) { desc.shaderType = typeIndex[i]; + if (usesBrightmap[i]) desc.shaderFlags |= SFlag_Brightmap; found = true; break; } @@ -1617,12 +1619,9 @@ class GLDefsParser switch (desc.shaderType) { default: - case SHADER_Default: firstUserTexture = 2; break; - case SHADER_Brightmap: firstUserTexture = 3; break; - case SHADER_Specular: firstUserTexture = 4; break; - case SHADER_SpecularBrightmap: firstUserTexture = 5; break; - case SHADER_PBR: firstUserTexture = 6; break; - case SHADER_PBRBrightmap: firstUserTexture = 7; break; + case SHADER_Default: firstUserTexture = 5; break; + case SHADER_Specular: firstUserTexture = 7; break; + case SHADER_PBR: firstUserTexture = 9; break; } for (unsigned int i = 0; i < texNameList.Size(); i++) diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index fdaebfcd37..8bb637ca4d 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -126,7 +126,10 @@ bool FGLRenderState::ApplyShader() activeShader->muDesaturation.Set(mStreamData.uDesaturationFactor); activeShader->muFogEnabled.Set(fogset); - activeShader->muTextureMode.Set(mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode); + + int f = mTextureModeFlags; + if (!mBrightmapEnabled) f &= TEXF_Detailmap; + activeShader->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f); activeShader->muLightParms.Set(mLightParms); activeShader->muFogColor.Set(mStreamData.uFogColor); activeShader->muObjectColor.Set(mStreamData.uObjectColor); @@ -141,6 +144,7 @@ bool FGLRenderState::ApplyShader() activeShader->muTextureAddColor.Set(mStreamData.uTextureAddColor); activeShader->muTextureModulateColor.Set(mStreamData.uTextureModulateColor); activeShader->muTextureBlendColor.Set(mStreamData.uTextureBlendColor); + activeShader->muDetailParms.Set(&mStreamData.uDetailParms.X); if (mGlowEnabled || activeShader->currentglowstate) { @@ -166,6 +170,7 @@ bool FGLRenderState::ApplyShader() activeShader->currentsplitstate = mSplitEnabled; } + if (mTextureMatrixEnabled) { matrixToGL(mTextureMatrix, activeShader->texturematrix_index); diff --git a/src/rendering/gl/shaders/gl_shader.cpp b/src/rendering/gl/shaders/gl_shader.cpp index 1aa23bcbd7..8487c29818 100644 --- a/src/rendering/gl/shaders/gl_shader.cpp +++ b/src/rendering/gl/shaders/gl_shader.cpp @@ -262,6 +262,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * i_data += "uniform vec4 uSplitTopPlane;\n"; i_data += "uniform vec4 uSplitBottomPlane;\n"; + i_data += "uniform vec4 uDetailParms;\n"; + // Lighting + Fog i_data += "uniform vec4 uLightAttr;\n"; i_data += "#define uLightLevel uLightAttr.a\n"; @@ -302,6 +304,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * i_data += "uniform sampler2D texture4;\n"; i_data += "uniform sampler2D texture5;\n"; i_data += "uniform sampler2D texture6;\n"; + i_data += "uniform sampler2D texture7;\n"; + i_data += "uniform sampler2D texture8;\n"; // timer data i_data += "uniform float timer;\n"; @@ -311,14 +315,20 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * i_data += "#define normaltexture texture2\n"; i_data += "#define speculartexture texture3\n"; i_data += "#define brighttexture texture4\n"; + i_data += "#define detailtexture texture5\n"; + i_data += "#define glowtexture texture6\n"; i_data += "#elif defined(PBR)\n"; i_data += "#define normaltexture texture2\n"; i_data += "#define metallictexture texture3\n"; i_data += "#define roughnesstexture texture4\n"; i_data += "#define aotexture texture5\n"; i_data += "#define brighttexture texture6\n"; + i_data += "#define detailtexture texture7\n"; + i_data += "#define glowtexture texture8\n"; i_data += "#else\n"; i_data += "#define brighttexture texture2\n"; + i_data += "#define detailtexture texture3\n"; + i_data += "#define glowtexture texture4\n"; i_data += "#endif\n"; #ifdef __APPLE__ @@ -387,22 +397,31 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * if (pp_lump == -1) I_Error("Unable to load '%s'", proc_prog_lump); FileData pp_data = fileSystem.ReadFile(pp_lump); - if (pp_data.GetString().IndexOf("ProcessMaterial") < 0) + if (pp_data.GetString().IndexOf("ProcessMaterial") < 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0) { // this looks like an old custom hardware shader. - // add ProcessMaterial function that calls the older ProcessTexel function - int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat.fp", 0); - if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat.fp"); - FileData pl_data = fileSystem.ReadFile(pl_lump); - fp_comb << "\n" << pl_data.GetString().GetChars(); - - if (pp_data.GetString().IndexOf("ProcessTexel") < 0) + if (pp_data.GetString().IndexOf("GetTexCoord") >= 0) { - // this looks like an even older custom hardware shader. - // We need to replace the ProcessTexel call to make it work. + int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat2.fp", 0); + if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat2.fp"); + FileData pl_data = fileSystem.ReadFile(pl_lump); + fp_comb << "\n" << pl_data.GetString().GetChars(); + } + else + { + int pl_lump = fileSystem.CheckNumForFullName("shaders/glsl/func_defaultmat.fp", 0); + if (pl_lump == -1) I_Error("Unable to load '%s'", "shaders/glsl/func_defaultmat.fp"); + FileData pl_data = fileSystem.ReadFile(pl_lump); + fp_comb << "\n" << pl_data.GetString().GetChars(); - fp_comb.Substitute("material.Base = ProcessTexel();", "material.Base = Process(vec4(1.0));"); + if (pp_data.GetString().IndexOf("ProcessTexel") < 0) + { + // this looks like an even older custom hardware shader. + // We need to replace the ProcessTexel call to make it work. + + fp_comb.Substitute("material.Base = ProcessTexel();", "material.Base = Process(vec4(1.0));"); + } } if (pp_data.GetString().IndexOf("ProcessLight") >= 0) @@ -423,6 +442,14 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * FileData pl_data = fileSystem.ReadFile(pl_lump); fp_comb << "\n" << pl_data.GetString().GetChars(); } + + // ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about. + if (pp_data.GetString().IndexOf("ProcessMaterial") >= 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0) + { + // This reactivates the old logic and disables all features that cannot be supported with that method. + fp_comb.Insert(0, "#define LEGACY_USER_SHADER\n"); + } + } else { @@ -546,6 +573,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muGradientTopPlane.Init(hShader, "uGradientTopPlane"); muSplitBottomPlane.Init(hShader, "uSplitBottomPlane"); muSplitTopPlane.Init(hShader, "uSplitTopPlane"); + muDetailParms.Init(hShader, "uDetailParms"); muInterpolationFactor.Init(hShader, "uInterpolationFactor"); muAlphaThreshold.Init(hShader, "uAlphaThreshold"); muSpecularMaterial.Init(hShader, "uSpecularMaterial"); diff --git a/src/rendering/gl/shaders/gl_shader.h b/src/rendering/gl/shaders/gl_shader.h index e9d638446b..c5068f5a23 100644 --- a/src/rendering/gl/shaders/gl_shader.h +++ b/src/rendering/gl/shaders/gl_shader.h @@ -257,6 +257,7 @@ class FShader FUniform4f muGradientTopPlane; FUniform4f muSplitBottomPlane; FUniform4f muSplitTopPlane; + FUniform4f muDetailParms; FBufferedUniform1f muInterpolationFactor; FBufferedUniform1f muAlphaThreshold; FBufferedUniform2f muSpecularMaterial; @@ -331,8 +332,8 @@ public: FShader *Get(unsigned int eff, bool alphateston) { - // indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom - if (!alphateston && eff <= 3) + // indices 0-2 match the warping modes, 3 no texture, the following are custom + if (!alphateston && eff <= 2) { return mMaterialShadersNAT[eff]; // Non-alphatest shaders are only created for default, warp1+2 and brightmap. The rest won't get used anyway } diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index 6ec91b6c35..7791dbc287 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -199,6 +199,8 @@ struct StreamData FVector4 uSplitTopPlane; FVector4 uSplitBottomPlane; + + FVector4 uDetailParms; }; class FRenderState @@ -208,14 +210,15 @@ protected: uint8_t mTextureEnabled:1; uint8_t mGlowEnabled : 1; uint8_t mGradientEnabled : 1; - uint8_t mBrightmapEnabled : 1; uint8_t mModelMatrixEnabled : 1; uint8_t mTextureMatrixEnabled : 1; uint8_t mSplitEnabled : 1; + uint8_t mBrightmapEnabled : 1; int mLightIndex; int mSpecialEffect; int mTextureMode; + int mTextureModeFlags; int mSoftLight; float mLightParms[4]; @@ -247,10 +250,11 @@ public: void Reset() { mTextureEnabled = true; - mGradientEnabled = mBrightmapEnabled = mFogEnabled = mGlowEnabled = false; + mBrightmapEnabled = mGradientEnabled = mFogEnabled = mGlowEnabled = false; mFogColor = 0xffffffff; mStreamData.uFogColor = mFogColor; mTextureMode = -1; + mTextureModeFlags = 0; mStreamData.uDesaturationFactor = 0.0f; mAlphaThreshold = 0.5f; mModelMatrixEnabled = false; @@ -287,6 +291,7 @@ public: mStreamData.uSplitTopPlane = { 0.0f, 0.0f, 0.0f, 0.0f }; mStreamData.uSplitBottomPlane = { 0.0f, 0.0f, 0.0f, 0.0f }; mStreamData.uDynLightColor = { 0.0f, 0.0f, 0.0f, 0.0f }; + mStreamData.uDetailParms = { 0.0f, 0.0f, 0.0f, 0.0f }; mModelMatrix.loadIdentity(); mTextureMatrix.loadIdentity(); @@ -338,15 +343,15 @@ public: { if (style.Flags & STYLEF_RedIsAlpha) { - mTextureMode = TM_ALPHATEXTURE; + SetTextureMode(TM_ALPHATEXTURE); } else if (style.Flags & STYLEF_ColorIsFixed) { - mTextureMode = TM_STENCIL; + SetTextureMode(TM_STENCIL); } else if (style.Flags & STYLEF_InvertSource) { - mTextureMode = TM_INVERSE; + SetTextureMode(TM_INVERSE); } } @@ -451,6 +456,11 @@ public: mStreamData.uSplitBottomPlane = { (float)bn.X, (float)bn.Y, (float)bottom.negiC, (float)bottom.fD() }; } + void SetDetailParms(float xscale, float yscale, float bias) + { + mStreamData.uDetailParms = { xscale, yscale, bias, 0 }; + } + void SetDynLight(float r, float g, float b) { mStreamData.uDynLightColor = { r, g, b, 0.0f }; @@ -556,6 +566,7 @@ public: mMaterial.mTranslation = translation; mMaterial.mOverrideShader = overrideshader; mMaterial.mChanged = true; + mTextureModeFlags = mat->GetLayerFlags(); } void SetClipSplit(float bottom, float top) diff --git a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp index bdbaa50b4a..cfe2b754c4 100644 --- a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp +++ b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp @@ -268,11 +268,8 @@ const FDefaultShader defaultshaders[] = {"Default", "shaders/glsl/func_normal.fp", "shaders/glsl/material_normal.fp", ""}, {"Warp 1", "shaders/glsl/func_warp1.fp", "shaders/glsl/material_normal.fp", ""}, {"Warp 2", "shaders/glsl/func_warp2.fp", "shaders/glsl/material_normal.fp", ""}, - {"Brightmap","shaders/glsl/func_brightmap.fp", "shaders/glsl/material_normal.fp", "#define BRIGHTMAP\n"}, {"Specular", "shaders/glsl/func_spec.fp", "shaders/glsl/material_specular.fp", "#define SPECULAR\n#define NORMALMAP\n"}, - {"SpecularBrightmap", "shaders/glsl/func_spec.fp", "shaders/glsl/material_specular.fp", "#define SPECULAR\n#define NORMALMAP\n#define BRIGHTMAP\n"}, {"PBR","shaders/glsl/func_pbr.fp", "shaders/glsl/material_pbr.fp", "#define PBR\n#define NORMALMAP\n"}, - {"PBRBrightmap","shaders/glsl/func_pbr.fp", "shaders/glsl/material_pbr.fp", "#define PBR\n#define NORMALMAP\n#define BRIGHTMAP\n"}, {"Paletted", "shaders/glsl/func_paletted.fp", "shaders/glsl/material_nolight.fp", ""}, {"No Texture", "shaders/glsl/func_notexture.fp", "shaders/glsl/material_normal.fp", ""}, {"Basic Fuzz", "shaders/glsl/fuzz_standard.fp", "shaders/glsl/material_normal.fp", ""}, diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 1d19460ec6..cc763b89a1 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -287,7 +287,7 @@ void PolyRenderState::Apply() PolyPushConstants constants; constants.uFogEnabled = fogset; - constants.uTextureMode = mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode; + constants.uTextureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode); constants.uLightDist = mLightParms[0]; constants.uLightFactor = mLightParms[1]; constants.uFogDensity = mLightParms[2]; diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index abf2ba12a6..11f0403205 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -372,7 +372,9 @@ void VkRenderState::ApplyPushConstants() tempTM = TM_OPAQUE; mPushConstants.uFogEnabled = fogset; - mPushConstants.uTextureMode = mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode; + int f = mTextureModeFlags; + if (!mBrightmapEnabled) f &= TEXF_Detailmap; + mPushConstants.uTextureMode = (mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f; mPushConstants.uLightDist = mLightParms[0]; mPushConstants.uLightFactor = mLightParms[1]; mPushConstants.uFogDensity = mLightParms[2]; diff --git a/src/rendering/vulkan/shaders/vk_shader.cpp b/src/rendering/vulkan/shaders/vk_shader.cpp index 6432abc50e..d7b461cf10 100644 --- a/src/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/rendering/vulkan/shaders/vk_shader.cpp @@ -90,10 +90,10 @@ VkShaderProgram *VkShaderManager::GetEffect(int effect, EPassType passType) VkShaderProgram *VkShaderManager::Get(unsigned int eff, bool alphateston, EPassType passType) { - // indices 0-2 match the warping modes, 3 is brightmap, 4 no texture, the following are custom - if (!alphateston && eff <= 3) + // indices 0-2 match the warping modes, 3 no texture, the following are custom + if (!alphateston && eff <= 2) { - return &mMaterialShadersNAT[passType][eff]; // Non-alphatest shaders are only created for default, warp1+2 and brightmap. The rest won't get used anyway + return &mMaterialShadersNAT[passType][eff]; // Non-alphatest shaders are only created for default, warp1+2. The rest won't get used anyway } else if (eff < (unsigned int)mMaterialShaders[passType].size()) { @@ -160,6 +160,8 @@ static const char *shaderBindings = R"( vec4 uSplitTopPlane; vec4 uSplitBottomPlane; + + vec4 uDetailParms; }; layout(set = 0, binding = 3, std140) uniform StreamUBO { @@ -175,6 +177,8 @@ static const char *shaderBindings = R"( layout(set = 1, binding = 3) uniform sampler2D texture4; layout(set = 1, binding = 4) uniform sampler2D texture5; layout(set = 1, binding = 5) uniform sampler2D texture6; + layout(set = 1, binding = 6) uniform sampler2D texture7; + layout(set = 1, binding = 7) uniform sampler2D texture8; // This must match the PushConstants struct layout(push_constant) uniform PushConstants @@ -205,14 +209,20 @@ static const char *shaderBindings = R"( #define normaltexture texture2 #define speculartexture texture3 #define brighttexture texture4 + #define detailtexture texture5 + #define glowtexture texture6 #elif defined(PBR) #define normaltexture texture2 #define metallictexture texture3 #define roughnesstexture texture4 #define aotexture texture5 #define brighttexture texture6 + #define detailtexture texture7 + #define glowtexture texture8 #else #define brighttexture texture2 + #define detailtexture texture3 + #define glowtexture texture4 #endif #define uObjectColor data[uDataIndex].uObjectColor @@ -237,6 +247,7 @@ static const char *shaderBindings = R"( #define uGradientBottomPlane data[uDataIndex].uGradientBottomPlane #define uSplitTopPlane data[uDataIndex].uSplitTopPlane #define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane + #define uDetailParms data[uDataIndex].uDetailParms #define SUPPORTS_SHADOWMAPS #define VULKAN_COORDINATE_SYSTEM @@ -289,18 +300,25 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername { FString pp_code = LoadPublicShaderLump(material_lump); - if (pp_code.IndexOf("ProcessMaterial") < 0) + if (pp_code.IndexOf("ProcessMaterial") < 0 && pp_code.IndexOf("SetupMaterial") < 0) { // this looks like an old custom hardware shader. // add ProcessMaterial function that calls the older ProcessTexel function - code << "\n" << LoadPrivateShaderLump("shaders/glsl/func_defaultmat.fp").GetChars() << "\n"; - if (pp_code.IndexOf("ProcessTexel") < 0) + if (pp_code.IndexOf("GetTexCoord") >= 0) { - // this looks like an even older custom hardware shader. - // We need to replace the ProcessTexel call to make it work. + code << "\n" << LoadPrivateShaderLump("shaders/glsl/func_defaultmat2.fp").GetChars() << "\n"; + } + else + { + code << "\n" << LoadPrivateShaderLump("shaders/glsl/func_defaultmat.fp").GetChars() << "\n"; + if (pp_code.IndexOf("ProcessTexel") < 0) + { + // this looks like an even older custom hardware shader. + // We need to replace the ProcessTexel call to make it work. - code.Substitute("material.Base = ProcessTexel();", "material.Base = Process(vec4(1.0));"); + code.Substitute("material.Base = ProcessTexel();", "material.Base = Process(vec4(1.0));"); + } } if (pp_code.IndexOf("ProcessLight") >= 0) @@ -319,6 +337,13 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername { code << "\n" << LoadPrivateShaderLump("shaders/glsl/func_defaultlight.fp").GetChars() << "\n"; } + + // ProcessMaterial must be considered broken because it requires the user to fill in data they possibly cannot know all about. + if (pp_code.IndexOf("ProcessMaterial") >= 0 && pp_code.IndexOf("SetupMaterial") < 0) + { + // This reactivates the old logic and disables all features that cannot be supported with that method. + code.Insert(0, "#define LEGACY_USER_SHADER\n"); + } } else { diff --git a/wadsrc/static/shaders/glsl/func_brightmap.fp b/wadsrc/static/shaders/glsl/func_brightmap.fp deleted file mode 100644 index 30c2a737b8..0000000000 --- a/wadsrc/static/shaders/glsl/func_brightmap.fp +++ /dev/null @@ -1,9 +0,0 @@ - -Material ProcessMaterial() -{ - Material material; - material.Base = getTexel(vTexCoord.st); - material.Normal = ApplyNormalMap(vTexCoord.st); - material.Bright = texture(brighttexture, vTexCoord.st); - return material; -} diff --git a/wadsrc/static/shaders/glsl/func_defaultlight.fp b/wadsrc/static/shaders/glsl/func_defaultlight.fp index 7463528fd2..6738af8f5f 100644 --- a/wadsrc/static/shaders/glsl/func_defaultlight.fp +++ b/wadsrc/static/shaders/glsl/func_defaultlight.fp @@ -1,17 +1,5 @@ -#if defined(BRIGHTMAP) - -vec4 ProcessLight(Material material, vec4 color) -{ - vec4 brightpix = desaturate(material.Bright); - return vec4(min(color.rgb + brightpix.rgb, 1.0), color.a); -} - -#else - vec4 ProcessLight(Material material, vec4 color) { return color; } - -#endif diff --git a/wadsrc/static/shaders/glsl/func_defaultmat.fp b/wadsrc/static/shaders/glsl/func_defaultmat.fp index 0535b8750a..d4c3c99f78 100644 --- a/wadsrc/static/shaders/glsl/func_defaultmat.fp +++ b/wadsrc/static/shaders/glsl/func_defaultmat.fp @@ -1,11 +1,7 @@ -Material ProcessMaterial() +void SetupMaterial(inout Material material) { - Material material; material.Base = ProcessTexel(); material.Normal = ApplyNormalMap(vTexCoord.st); -#if defined(BRIGHTMAP) material.Bright = texture(brighttexture, vTexCoord.st); -#endif - return material; } diff --git a/wadsrc/static/shaders/glsl/func_defaultmat2.fp b/wadsrc/static/shaders/glsl/func_defaultmat2.fp new file mode 100644 index 0000000000..b2beb254e6 --- /dev/null +++ b/wadsrc/static/shaders/glsl/func_defaultmat2.fp @@ -0,0 +1,6 @@ + +void SetupMaterial(inout Material material) +{ + vec2 texCoord = GetTexCoord(); + SetMaterialProps(material, texCoord); +} diff --git a/wadsrc/static/shaders/glsl/func_normal.fp b/wadsrc/static/shaders/glsl/func_normal.fp index fbf40113f9..49dfadd9aa 100644 --- a/wadsrc/static/shaders/glsl/func_normal.fp +++ b/wadsrc/static/shaders/glsl/func_normal.fp @@ -1,8 +1,5 @@ -Material ProcessMaterial() +void SetupMaterial(inout Material material) { - Material material; - material.Base = getTexel(vTexCoord.st); - material.Normal = ApplyNormalMap(vTexCoord.st); - return material; + SetMaterialProps(material, vTexCoord.st); } diff --git a/wadsrc/static/shaders/glsl/func_pbr.fp b/wadsrc/static/shaders/glsl/func_pbr.fp index b0e61d1014..79de3bb857 100644 --- a/wadsrc/static/shaders/glsl/func_pbr.fp +++ b/wadsrc/static/shaders/glsl/func_pbr.fp @@ -1,14 +1,8 @@ -Material ProcessMaterial() +void SetupMaterial(inout Material material) { - Material material; - material.Base = getTexel(vTexCoord.st); - material.Normal = ApplyNormalMap(vTexCoord.st); + SetMaterialProps(material, vTexCoord.st); material.Metallic = texture(metallictexture, vTexCoord.st).r; material.Roughness = texture(roughnesstexture, vTexCoord.st).r; material.AO = texture(aotexture, vTexCoord.st).r; -#if defined(BRIGHTMAP) - material.Bright = texture(brighttexture, vTexCoord.st); -#endif - return material; } diff --git a/wadsrc/static/shaders/glsl/func_spec.fp b/wadsrc/static/shaders/glsl/func_spec.fp index afa1af8435..7de5b1d4ea 100644 --- a/wadsrc/static/shaders/glsl/func_spec.fp +++ b/wadsrc/static/shaders/glsl/func_spec.fp @@ -1,14 +1,8 @@ -Material ProcessMaterial() +void SetupMaterial(inout Material material) { - Material material; - material.Base = getTexel(vTexCoord.st); - material.Normal = ApplyNormalMap(vTexCoord.st); + SetMaterialProps(material, vTexCoord.st); material.Specular = texture(speculartexture, vTexCoord.st).rgb; material.Glossiness = uSpecularMaterial.x; material.SpecularLevel = uSpecularMaterial.y; -#if defined(BRIGHTMAP) - material.Bright = texture(brighttexture, vTexCoord.st); -#endif - return material; } diff --git a/wadsrc/static/shaders/glsl/func_warp1.fp b/wadsrc/static/shaders/glsl/func_warp1.fp index 4214f771f2..dfadf8ada8 100644 --- a/wadsrc/static/shaders/glsl/func_warp1.fp +++ b/wadsrc/static/shaders/glsl/func_warp1.fp @@ -1,5 +1,5 @@ -vec4 ProcessTexel() +vec2 GetTexCoord() { vec2 texCoord = vTexCoord.st; @@ -9,8 +9,11 @@ vec4 ProcessTexel() offset.y = sin(pi * 2.0 * (texCoord.x + timer * 0.125)) * 0.1; offset.x = sin(pi * 2.0 * (texCoord.y + timer * 0.125)) * 0.1; - texCoord += offset; - - return getTexel(texCoord); + return texCoord + offset; +} + +vec4 ProcessTexel() +{ + return getTexel(GetTexCoord()); } diff --git a/wadsrc/static/shaders/glsl/func_warp2.fp b/wadsrc/static/shaders/glsl/func_warp2.fp index 389fad9df7..1ee0f7fd02 100644 --- a/wadsrc/static/shaders/glsl/func_warp2.fp +++ b/wadsrc/static/shaders/glsl/func_warp2.fp @@ -1,5 +1,6 @@ -vec4 ProcessTexel() + +vec2 GetTexCoord() { vec2 texCoord = vTexCoord.st; @@ -9,8 +10,11 @@ vec4 ProcessTexel() offset.y = 0.5 + sin(pi * 2.0 * (texCoord.y + timer * 0.61 + 900.0/8192.0)) + sin(pi * 2.0 * (texCoord.x * 2.0 + timer * 0.36 + 300.0/8192.0)); offset.x = 0.5 + sin(pi * 2.0 * (texCoord.y + timer * 0.49 + 700.0/8192.0)) + sin(pi * 2.0 * (texCoord.x * 2.0 + timer * 0.49 + 1200.0/8192.0)); - texCoord += offset * 0.025; - - return getTexel(texCoord); + return texCoord + offset * 0.025; +} + +vec4 ProcessTexel() +{ + return getTexel(GetTexCoord()); } diff --git a/wadsrc/static/shaders/glsl/func_warp3.fp b/wadsrc/static/shaders/glsl/func_warp3.fp index dceca24773..9edea0004e 100644 --- a/wadsrc/static/shaders/glsl/func_warp3.fp +++ b/wadsrc/static/shaders/glsl/func_warp3.fp @@ -1,5 +1,6 @@ -vec4 ProcessTexel() + +vec2 GetTexCoord() { vec2 texCoord = vTexCoord.st; @@ -10,8 +11,11 @@ vec4 ProcessTexel() offset.y = siny + sin(pi * 2.0 * (texCoord.x + timer * 0.75)) * 0.03; offset.x = siny + sin(pi * 2.0 * (texCoord.x + timer * 0.45)) * 0.02; - texCoord += offset; - - return getTexel(texCoord); + return texCoord + offset; +} + +vec4 ProcessTexel() +{ + return getTexel(GetTexCoord()); } diff --git a/wadsrc/static/shaders/glsl/func_wavex.fp b/wadsrc/static/shaders/glsl/func_wavex.fp index 05ab530284..3b892da9d7 100644 --- a/wadsrc/static/shaders/glsl/func_wavex.fp +++ b/wadsrc/static/shaders/glsl/func_wavex.fp @@ -1,5 +1,5 @@ -vec4 ProcessTexel() +vec2 GetTexCoord() { vec2 texCoord = vTexCoord.st; @@ -7,6 +7,11 @@ vec4 ProcessTexel() texCoord.x += sin(pi * 2.0 * (texCoord.y + timer * 0.125)) * 0.1; - return getTexel(texCoord); + return texCoord; +} + +vec4 ProcessTexel() +{ + return getTexel(GetTexCoord()); } diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 095c16a35f..06011501be 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -22,6 +22,7 @@ struct Material { vec4 Base; vec4 Bright; + vec4 Glow; vec3 Normal; vec3 Specular; float Glossiness; @@ -33,9 +34,16 @@ struct Material vec4 Process(vec4 color); vec4 ProcessTexel(); -Material ProcessMaterial(); +Material ProcessMaterial(); // note that this is deprecated. Use SetupMaterial! +void SetupMaterial(inout Material mat); vec4 ProcessLight(Material mat, vec4 color); vec3 ProcessMaterialLight(Material material, vec3 color); +vec2 GetTexCoord(); + +// These get Or'ed into uTextureMode because it only uses its 3 lowermost bits. +const int TEXF_Brightmap = 0x10000; +const int TEXF_Detailmap = 0x20000; +const int TEXF_Glowmap = 0x40000; //=========================================================================== // @@ -157,7 +165,7 @@ vec4 getTexel(vec2 st) // // Apply texture modes // - switch (uTextureMode) + switch (uTextureMode & 0xffff) { case 1: // TM_STENCIL texel.rgb = vec3(1.0,1.0,1.0); @@ -524,6 +532,30 @@ vec3 ApplyNormalMap(vec2 texcoord) } #endif +//=========================================================================== +// +// Sets the common material properties. +// +//=========================================================================== + +void SetMaterialProps(inout Material material, vec2 texCoord) +{ + material.Base = getTexel(texCoord.st); + material.Normal = ApplyNormalMap(texCoord.st); + + if ((uTextureMode & TEXF_Brightmap) != 0) + material.Bright = texture(brighttexture, texCoord.st); + + if ((uTextureMode & TEXF_Detailmap) != 0) + { + vec4 Detail = texture(detailtexture, texCoord.st * uDetailParms.xy) * uDetailParms.z; + material.Base *= Detail; + } + + if ((uTextureMode & TEXF_Glowmap) != 0) + material.Glow = texture(glowtexture, texCoord.st); +} + //=========================================================================== // // Calculate light @@ -574,8 +606,21 @@ vec4 getLightColor(Material material, float fogdist, float fogfactor) } color = min(color, 1.0); + // these cannot be safely applied by the legacy format where the implementation cannot guarantee that the values are set. +#ifndef LEGACY_USER_SHADER // - // apply brightmaps (or other light manipulation by custom shaders. + // apply glow + // + color.rgb = mix(color.rgb, material.Glow.rgb, material.Glow.a); + + // + // apply brightmaps + // + color.rgb = min(color.rgb + material.Bright.rgb, 1.0); +#endif + + // + // apply other light manipulation by custom shaders, default is a NOP. // color = ProcessLight(material, color); @@ -635,7 +680,23 @@ void main() if (ClipDistanceA.x < 0 || ClipDistanceA.y < 0 || ClipDistanceA.z < 0 || ClipDistanceA.w < 0 || ClipDistanceB.x < 0) discard; #endif +#ifndef LEGACY_USER_SHADER + Material material; + + material.Base = vec4(0.0); + material.Bright = vec4(0.0); + material.Glow = vec4(0.0); + material.Normal = vec3(0.0); + material.Specular = vec3(0.0); + material.Glossiness = 0.0; + material.SpecularLevel = 0.0; + material.Metallic = 0.0; + material.Roughness = 0.0; + material.AO = 0.0; + SetupMaterial(material); +#else Material material = ProcessMaterial(); +#endif vec4 frag = material.Base; #ifndef NO_ALPHATEST @@ -663,9 +724,10 @@ void main() fogfactor = exp2 (uFogDensity * fogdist); } - if (uTextureMode != 7) + if ((uTextureMode & 0xffff) != 7) { frag = getLightColor(material, fogdist, fogfactor); + // // colored fog // @@ -681,7 +743,7 @@ void main() } else // simple 2D (uses the fog color to add a color overlay) { - if (uTextureMode == 7) + if ((uTextureMode & 0xffff) == 7) { float gray = grayscale(frag); vec4 cm = (uObjectColor + gray * (uAddColor - uObjectColor)) * 2; From dd5de4ce51a4317337c5b308a433177adfefd177 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 12 Apr 2020 22:13:15 +0200 Subject: [PATCH 002/220] - removed test code that forced all textures being warped. --- src/common/textures/texture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index be2b730e79..cdaa29d55f 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -116,7 +116,7 @@ FTexture::FTexture (const char *name, int lumpnum) : Scale(1,1), SourceLump(lumpnum), UseType(ETextureType::Any), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), - bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(1), bComplex(false), bMultiPatch(false), bFullNameTexture(false), + bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bFullNameTexture(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { bBrightmapChecked = false; From 7c46dace031f067e77a615d7f727ec35d9bef5d7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 12 Apr 2020 22:42:00 +0200 Subject: [PATCH 003/220] - this still doesn't work on Vulkan. :( --- src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp | 4 ++-- src/rendering/vulkan/renderer/vk_renderstate.cpp | 4 ++-- wadsrc/static/shaders/glsl/main.fp | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp index cfe2b754c4..626d53494f 100644 --- a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp +++ b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp @@ -59,7 +59,7 @@ static FString NextGlslToken(const char *chars, long len, long &pos) pos = tokenEnd; return FString(chars + tokenStart, tokenEnd - tokenStart); -} +} static bool isShaderType(const char *name) { @@ -271,7 +271,7 @@ const FDefaultShader defaultshaders[] = {"Specular", "shaders/glsl/func_spec.fp", "shaders/glsl/material_specular.fp", "#define SPECULAR\n#define NORMALMAP\n"}, {"PBR","shaders/glsl/func_pbr.fp", "shaders/glsl/material_pbr.fp", "#define PBR\n#define NORMALMAP\n"}, {"Paletted", "shaders/glsl/func_paletted.fp", "shaders/glsl/material_nolight.fp", ""}, - {"No Texture", "shaders/glsl/func_notexture.fp", "shaders/glsl/material_normal.fp", ""}, + {"No Texture", "shaders/glsl/func_notexture.fp", "shaders/glsl/material_normal.fp", "#define NO_LAYERS\n"}, {"Basic Fuzz", "shaders/glsl/fuzz_standard.fp", "shaders/glsl/material_normal.fp", ""}, {"Smooth Fuzz", "shaders/glsl/fuzz_smooth.fp", "shaders/glsl/material_normal.fp", ""}, {"Swirly Fuzz", "shaders/glsl/fuzz_swirly.fp", "shaders/glsl/material_normal.fp", ""}, diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 11f0403205..b0851f1176 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -228,7 +228,7 @@ void VkRenderState::ApplyRenderPass(int dt) pipelineKey.StencilPassOp = mStencilOp; pipelineKey.ColorMask = mColorMask; pipelineKey.CullMode = mCullMode; - pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->GetLayers() : 1; // Always force minimum 1 texture as the shader requires it + pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->GetLayers() : 4; // Always force minimum 1 texture as the shader requires it if (mSpecialEffect > EFF_NONE) { pipelineKey.SpecialEffect = mSpecialEffect; @@ -373,7 +373,7 @@ void VkRenderState::ApplyPushConstants() mPushConstants.uFogEnabled = fogset; int f = mTextureModeFlags; - if (!mBrightmapEnabled) f &= TEXF_Detailmap; + if (!mBrightmapEnabled) mPushConstants.uTextureMode = (mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f; mPushConstants.uLightDist = mLightParms[0]; mPushConstants.uLightFactor = mLightParms[1]; diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index 06011501be..8960103bf8 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -543,6 +543,8 @@ void SetMaterialProps(inout Material material, vec2 texCoord) material.Base = getTexel(texCoord.st); material.Normal = ApplyNormalMap(texCoord.st); +// OpenGL doesn't care, but Vulkan pukes all over the place if these texture samplings are included in no-texture shaders, even though never called. +#ifndef NO_LAYERS if ((uTextureMode & TEXF_Brightmap) != 0) material.Bright = texture(brighttexture, texCoord.st); @@ -554,6 +556,7 @@ void SetMaterialProps(inout Material material, vec2 texCoord) if ((uTextureMode & TEXF_Glowmap) != 0) material.Glow = texture(glowtexture, texCoord.st); +#endif } //=========================================================================== From 9ef6d8fd53eab1027b2f82e01bd3814679a681f7 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 13 Apr 2020 00:42:22 +0200 Subject: [PATCH 004/220] Always null textures for all slots because the vulkan target is an OpenGL emulator ;) --- src/rendering/vulkan/renderer/vk_renderpass.cpp | 12 ++++++++++-- src/rendering/vulkan/renderer/vk_renderpass.h | 1 + src/rendering/vulkan/renderer/vk_renderstate.cpp | 3 ++- src/rendering/vulkan/shaders/vk_shader.h | 2 ++ src/rendering/vulkan/textures/vk_hwtexture.cpp | 10 +++++++++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/rendering/vulkan/renderer/vk_renderpass.cpp index a90c825e81..7567ee90fa 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/rendering/vulkan/renderer/vk_renderpass.cpp @@ -215,17 +215,25 @@ VulkanDescriptorSet* VkRenderPassManager::GetNullTextureDescriptorSet() { if (!NullTextureDescriptorSet) { - NullTextureDescriptorSet = AllocateTextureDescriptorSet(1); + NullTextureDescriptorSet = AllocateTextureDescriptorSet(SHADER_MIN_REQUIRED_TEXTURE_LAYERS); auto fb = GetVulkanFrameBuffer(); WriteDescriptors update; - update.addCombinedImageSampler(NullTextureDescriptorSet.get(), 0, NullTextureView.get(), fb->GetSamplerManager()->Get(CLAMP_XY_NOMIP), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + for (int i = 0; i < SHADER_MIN_REQUIRED_TEXTURE_LAYERS; i++) + { + update.addCombinedImageSampler(NullTextureDescriptorSet.get(), i, NullTextureView.get(), fb->GetSamplerManager()->Get(CLAMP_XY_NOMIP), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + } update.updateSets(fb->device); } return NullTextureDescriptorSet.get(); } +VulkanImageView* VkRenderPassManager::GetNullTextureView() +{ + return NullTextureView.get(); +} + void VkRenderPassManager::UpdateDynamicSet() { auto fb = GetVulkanFrameBuffer(); diff --git a/src/rendering/vulkan/renderer/vk_renderpass.h b/src/rendering/vulkan/renderer/vk_renderpass.h index 37fd05ed66..c2c3b3e8e1 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.h +++ b/src/rendering/vulkan/renderer/vk_renderpass.h @@ -94,6 +94,7 @@ public: VulkanPipelineLayout* GetPipelineLayout(int numLayers); VulkanDescriptorSet* GetNullTextureDescriptorSet(); + VulkanImageView* GetNullTextureView(); std::unique_ptr DynamicSetLayout; std::map> RenderPassSetup; diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index b0851f1176..f5cc42e76a 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -228,7 +228,8 @@ void VkRenderState::ApplyRenderPass(int dt) pipelineKey.StencilPassOp = mStencilOp; pipelineKey.ColorMask = mColorMask; pipelineKey.CullMode = mCullMode; - pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->GetLayers() : 4; // Always force minimum 1 texture as the shader requires it + pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->GetLayers() : 0; + pipelineKey.NumTextureLayers = std::max(pipelineKey.NumTextureLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS);// Always force minimum 8 textures as the shader requires it if (mSpecialEffect > EFF_NONE) { pipelineKey.SpecialEffect = mSpecialEffect; diff --git a/src/rendering/vulkan/shaders/vk_shader.h b/src/rendering/vulkan/shaders/vk_shader.h index feb897ef00..a9936293c0 100644 --- a/src/rendering/vulkan/shaders/vk_shader.h +++ b/src/rendering/vulkan/shaders/vk_shader.h @@ -8,6 +8,8 @@ #include "name.h" #include "hwrenderer/scene/hw_renderstate.h" +#define SHADER_MIN_REQUIRED_TEXTURE_LAYERS 8 + class VulkanDevice; class VulkanShader; diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index d91807206b..c8784b6c5b 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -33,6 +33,7 @@ #include "vulkan/renderer/vk_renderpass.h" #include "vulkan/renderer/vk_postprocess.h" #include "vulkan/renderer/vk_renderbuffers.h" +#include "vulkan/shaders/vk_shader.h" #include "vk_hwtexture.h" VkHardwareTexture *VkHardwareTexture::First = nullptr; @@ -144,7 +145,7 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s int numLayers = mat->GetLayers(); auto fb = GetVulkanFrameBuffer(); - auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(numLayers); + auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(std::max(numLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS)); descriptor->SetDebugName("VkHardwareTexture.mDescriptorSets"); @@ -158,6 +159,13 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s auto systex = static_cast(mat->GetLayer(i, 0, &layer)); update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0)->View.get(), sampler, systex->mImage.Layout); } + + auto dummyImage = fb->GetRenderPassManager()->GetNullTextureView(); + for (int i = numLayers; i < SHADER_MIN_REQUIRED_TEXTURE_LAYERS; i++) + { + update.addCombinedImageSampler(descriptor.get(), i, dummyImage, sampler, mImage.Layout); + } + update.updateSets(fb->device); mDescriptorSets.emplace_back(clampmode, flags, std::move(descriptor)); return mDescriptorSets.back().descriptor.get(); From 3a47c5c7f773b43dc33cb2c23b440cbc70f7c60c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 13 Apr 2020 08:54:45 +0200 Subject: [PATCH 005/220] - fixed Vulkan's uTextureMode setup. Also only mask out the flags we really do not want to avoid surprises in the future. --- src/rendering/gl/renderer/gl_renderstate.cpp | 2 +- src/rendering/vulkan/renderer/vk_renderstate.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index 8bb637ca4d..4eb25647bc 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -128,7 +128,7 @@ bool FGLRenderState::ApplyShader() activeShader->muFogEnabled.Set(fogset); int f = mTextureModeFlags; - if (!mBrightmapEnabled) f &= TEXF_Detailmap; + if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap | TEXF_Glowmap); activeShader->muTextureMode.Set((mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f); activeShader->muLightParms.Set(mLightParms); activeShader->muFogColor.Set(mStreamData.uFogColor); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index f5cc42e76a..ca08b4134e 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -374,7 +374,7 @@ void VkRenderState::ApplyPushConstants() mPushConstants.uFogEnabled = fogset; int f = mTextureModeFlags; - if (!mBrightmapEnabled) + if (!mBrightmapEnabled) f &= ~(TEXF_Brightmap|TEXF_Glowmap); mPushConstants.uTextureMode = (mTextureMode == TM_NORMAL && tempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) | f; mPushConstants.uLightDist = mLightParms[0]; mPushConstants.uLightFactor = mLightParms[1]; From aeba30471571765c523513b948937bb78f2162e4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 13 Apr 2020 17:05:49 +0200 Subject: [PATCH 006/220] - texture code refactoring to consolidate multiple textures referencing the same backing image. --- src/common/textures/animtexture.cpp | 2 +- src/common/textures/hw_ihwtexture.h | 4 +- src/common/textures/hw_material.cpp | 40 +++++++++++++------ src/common/textures/hw_material.h | 32 +++++++++++++-- src/common/textures/texture.cpp | 6 +++ src/common/textures/texturemanager.cpp | 2 +- src/common/textures/textures.h | 1 + src/rendering/2d/f_wipe.cpp | 4 +- src/rendering/gl/renderer/gl_renderstate.cpp | 8 ++-- src/rendering/gl/system/gl_framebuffer.cpp | 9 ++--- .../hwrenderer/scene/hw_drawlistadd.cpp | 2 +- src/rendering/hwrenderer/scene/hw_flats.cpp | 4 +- src/rendering/hwrenderer/scene/hw_portal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sky.cpp | 5 ++- src/rendering/hwrenderer/scene/hw_skydome.cpp | 7 ++-- .../hwrenderer/scene/hw_skyportal.cpp | 9 +++-- src/rendering/hwrenderer/scene/hw_sprites.cpp | 8 ++-- src/rendering/hwrenderer/scene/hw_walls.cpp | 14 +++---- src/rendering/hwrenderer/scene/hw_weapon.cpp | 2 +- .../hwrenderer/textures/hw_precache.cpp | 17 ++++---- .../polyrenderer/backend/poly_framebuffer.cpp | 14 +++++-- .../polyrenderer/backend/poly_hwtexture.cpp | 27 ++----------- .../polyrenderer/backend/poly_hwtexture.h | 4 +- .../polyrenderer/backend/poly_renderstate.cpp | 11 ++--- .../vulkan/renderer/vk_renderstate.cpp | 13 +++--- .../vulkan/system/vk_framebuffer.cpp | 15 +++++-- .../vulkan/textures/vk_hwtexture.cpp | 24 +++-------- src/rendering/vulkan/textures/vk_hwtexture.h | 2 - 28 files changed, 160 insertions(+), 128 deletions(-) diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp index 4dbf2d111a..b09c5cd185 100644 --- a/src/common/textures/animtexture.cpp +++ b/src/common/textures/animtexture.cpp @@ -50,7 +50,7 @@ void AnimTexture::SetFrame(const uint8_t *palette, const void *data_) { memcpy(Palette, palette, 768); memcpy(Image.Data(), data_, Width * Height); - SystemTextures.Clean(true, true); + CleanHardwareTextures(true, true); } //=========================================================================== diff --git a/src/common/textures/hw_ihwtexture.h b/src/common/textures/hw_ihwtexture.h index 24b92c9262..73023014cd 100644 --- a/src/common/textures/hw_ihwtexture.h +++ b/src/common/textures/hw_ihwtexture.h @@ -14,8 +14,8 @@ public: MAX_TEXTURES = 16 }; - IHardwareTexture() {} - virtual ~IHardwareTexture() {} + IHardwareTexture() = default; + virtual ~IHardwareTexture() = default; virtual void DeleteDescriptors() { } diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 8c0bc06ef8..bb39cef7be 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -30,6 +30,21 @@ IHardwareTexture* CreateHardwareTexture(); +// We really do not need to create more than one hardware texture per image source. +// However, the internal handling depends on FTexture for everything so this array maps each all textures sharing the same master texture that gets used in the layer array. +static TMap imageToMasterTexture; + +static FTexture* GetMasterTexture(FTexture* tx) +{ + if (tx->GetUseType() == ETextureType::Null) return tx; // Null textures never get redirected + auto img = tx->GetImage(); + if (!img) return tx; // this is not an image texture and represents itself. + auto find = imageToMasterTexture.CheckKey(img); + if (find) return *find; // already got a master texture for this. Return it. + imageToMasterTexture.Insert(img, tx); + return tx; // this is a newly added master texture. +} + //=========================================================================== // // Constructor @@ -39,7 +54,8 @@ IHardwareTexture* CreateHardwareTexture(); FMaterial::FMaterial(FTexture * tx, bool expanded) { mShaderIndex = SHADER_Default; - sourcetex = tex = tx; + sourcetex = tx; + imgtex = GetMasterTexture(tx); if (tx->UseType == ETextureType::SWCanvas && static_cast(tx)->GetColorFormat() == 0) { @@ -63,7 +79,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) { for (auto &texture : { tx->Normal, tx->Specular }) { - mTextureLayers.Push(texture); + mTextureLayers.Push(GetMasterTexture(texture)); } mShaderIndex = SHADER_Specular; } @@ -71,7 +87,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) { for (auto &texture : { tx->Normal, tx->Metallic, tx->Roughness, tx->AmbientOcclusion }) { - mTextureLayers.Push(texture); + mTextureLayers.Push(GetMasterTexture(texture)); } mShaderIndex = SHADER_PBR; } @@ -80,7 +96,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) tx->CreateDefaultBrightmap(); if (tx->Brightmap) { - mTextureLayers.Push(tx->Brightmap); + mTextureLayers.Push(GetMasterTexture(tx->Brightmap)); mLayerFlags |= TEXF_Brightmap; } else @@ -89,7 +105,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) } if (tx->Detailmap) { - mTextureLayers.Push(tx->Detailmap); + mTextureLayers.Push(GetMasterTexture(tx->Detailmap)); mLayerFlags |= TEXF_Detailmap; } else @@ -98,7 +114,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) } if (tx->Glowmap) { - mTextureLayers.Push(tx->Glowmap); + mTextureLayers.Push(GetMasterTexture(tx->Glowmap)); mLayerFlags |= TEXF_Glowmap; } else @@ -114,7 +130,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) for (auto &texture : tx->CustomShaderTextures) { if (texture == nullptr) continue; - mTextureLayers.Push(texture); + mTextureLayers.Push(GetMasterTexture(texture)); } mShaderIndex = tx->shaderindex; } @@ -167,11 +183,11 @@ FMaterial::~FMaterial() void FMaterial::SetSpriteRect() { - auto leftOffset = tex->GetLeftOffsetHW(); - auto topOffset = tex->GetTopOffsetHW(); + auto leftOffset = sourcetex->GetLeftOffsetHW(); + auto topOffset = sourcetex->GetTopOffsetHW(); - float fxScale = (float)tex->Scale.X; - float fyScale = (float)tex->Scale.Y; + float fxScale = (float)sourcetex->Scale.X; + float fyScale = (float)sourcetex->Scale.Y; // mSpriteRect is for positioning the sprite in the scene. mSpriteRect.left = -leftOffset / fxScale; @@ -311,7 +327,7 @@ outl: IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) { - FTexture *layer = i == 0 ? tex : mTextureLayers[i - 1]; + FTexture *layer = i == 0 ? imgtex : mTextureLayers[i - 1]; if (pLayer) *pLayer = layer; if (layer && layer->UseType!=ETextureType::Null) diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index 0265573768..11cbc58b4c 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -28,6 +28,7 @@ enum class FMaterial { + private: TArray mTextureLayers; int mShaderIndex; int mLayerFlags = 0; @@ -48,14 +49,37 @@ class FMaterial bool TrimBorders(uint16_t *rect); public: - FTexture *tex; - FTexture *sourcetex; // in case of redirection this is different from tex. - + FTexture *sourcetex; // the owning texture. + FTexture* imgtex; // the master texture for the backing image. Can be different from sourcetex and should not be in the layer array because that'd confuse the precacher. + FMaterial(FTexture *tex, bool forceexpand); ~FMaterial(); int GetLayerFlags() const { return mLayerFlags; } void SetSpriteRect(); int GetShaderIndex() const { return mShaderIndex; } + + FTexture* Source() const + { + return sourcetex; + } + FTexture* BaseLayer() const + { + // Only for spftpoly! + return imgtex; + } + bool isFullbright() const + { + return sourcetex->isFullbright(); + } + bool isHardwareCanvas() const + { + return sourcetex->isHardwareCanvas(); + } + bool GetTranslucency() + { + // This queries the master texture to reduce recalculations. + return imgtex->GetTranslucency(); + } void AddTextureLayer(FTexture *tex) { ValidateTexture(tex, false); @@ -77,7 +101,7 @@ public: bool hasCanvas() { - return tex->isHardwareCanvas(); + return sourcetex->isHardwareCanvas(); } IHardwareTexture *GetLayer(int i, int translation, FTexture **pLayer = nullptr); diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index cdaa29d55f..a2f02e3eb0 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -733,6 +733,12 @@ bool FTexture::DetermineTranslucency() return !!bTranslucent; } + +void FTexture::CleanHardwareTextures(bool cleannormal, bool cleanexpanded) +{ + SystemTextures.Clean(cleannormal, cleanexpanded); +} + //=========================================================================== // // the default just returns an empty texture. diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 76024b4ecd..4e87a893ee 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -119,7 +119,7 @@ void FTextureManager::FlushAll() { for (int j = 0; j < 2; j++) { - Textures[i].Texture->SystemTextures.Clean(true, true); + Textures[i].Texture->CleanHardwareTextures(true, true); DeleteSoftwareTexture(Textures[i].Texture->SoftwareTexture); Textures[i].Texture->SoftwareTexture = nullptr; } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index cefb39114b..35487c7727 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -248,6 +248,7 @@ public: virtual FImageSource *GetImage() const { return nullptr; } void AddAutoMaterials(); void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); + void CleanHardwareTextures(bool cleannormal, bool cleanextended); // These are mainly meant for 2D code which only needs logical information about the texture to position it properly. int GetDisplayWidth() { int foo = int((Width * 2) / Scale.X); return (foo >> 1) + (foo & 1); } diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index 6b66b7dd6c..f255774918 100644 --- a/src/rendering/2d/f_wipe.cpp +++ b/src/rendering/2d/f_wipe.cpp @@ -373,8 +373,8 @@ bool Wiper_Burn::Run(int ticks) done = (Density < 0); } - BurnTexture->SystemTextures.Clean(true, true); - endScreen->SystemTextures.Clean(false, false); + BurnTexture->CleanHardwareTextures(true, true); + endScreen->CleanHardwareTextures(false, false); const uint8_t *src = BurnArray; uint32_t *dest = (uint32_t *)BurnTexture->GetBuffer(); diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index 4eb25647bc..8da456248d 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -298,7 +298,7 @@ void FGLRenderState::Apply() void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader) { - if (mat->tex->isHardwareCanvas()) + if (mat->isHardwareCanvas()) { mTempTM = TM_OPAQUE; } @@ -306,11 +306,11 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio { mTempTM = TM_NORMAL; } + auto tex = mat->Source(); mEffectState = overrideshader >= 0 ? overrideshader : mat->GetShaderIndex(); - mShaderTimer = mat->tex->shaderspeed; - SetSpecular(mat->tex->Glossiness, mat->tex->SpecularLevel); + mShaderTimer = tex->shaderspeed; + SetSpecular(tex->Glossiness, tex->SpecularLevel); - auto tex = mat->tex; if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index f025a4e867..4b90118352 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -308,18 +308,17 @@ IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture() void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { - auto tex = mat->tex; - if (tex->isSWCanvas()) return; + if (mat->Source()->isSWCanvas()) return; int flags = mat->isExpanded() ? CTF_Expand : 0; int numLayers = mat->GetLayers(); - auto base = static_cast(mat->GetLayer(0, translation)); + FTexture* layer; + auto base = static_cast(mat->GetLayer(0, translation, &layer)); - if (base->BindOrCreate(tex, 0, CLAMP_NONE, translation, flags)) + if (base->BindOrCreate(layer, 0, CLAMP_NONE, translation, flags)) { for (int i = 1; i < numLayers; i++) { - FTexture *layer; auto systex = static_cast(mat->GetLayer(i, 0, &layer)); systex->BindOrCreate(layer, i, CLAMP_NONE, 0, mat->isExpanded() ? CTF_Expand : 0); } diff --git a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp index eb81a31703..851c2e1488 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -101,7 +101,7 @@ void HWDrawInfo::AddFlat(HWFlat *flat, bool fog) // translucent 3D floors go into the regular translucent list, translucent portals go into the translucent border list. list = (flat->renderflags&SSRF_RENDER3DPLANES) ? GLDL_TRANSLUCENT : GLDL_TRANSLUCENTBORDER; } - else if (flat->gltexture->tex->GetTranslucency()) + else if (flat->gltexture->GetTranslucency()) { if (flat->stack) { diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 204a1e5303..9f592bf057 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -349,7 +349,7 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) } else { - if (!gltexture->tex->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); + if (!gltexture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); else state.AlphaFunc(Alpha_GEqual, 0.f); state.SetMaterial(gltexture, CLAMP_NONE, 0, -1); state.SetPlaneTextureRotation(&plane, gltexture); @@ -407,7 +407,7 @@ void HWFlat::Process(HWDrawInfo *di, sector_t * model, int whichplane, bool fog) { gltexture=FMaterial::ValidateTexture(plane.texture, false, true); if (!gltexture) return; - if (gltexture->tex->isFullbright()) + if (gltexture->isFullbright()) { Colormap.MakeWhite(); lightlevel=255; diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index d68a9fa3ab..f9953051dc 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -960,7 +960,7 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state) di->SetCameraPos(vp.Pos); - if (gltexture && gltexture->tex->isFullbright()) + if (gltexture && gltexture->isFullbright()) { // glowing textures are always drawn full bright without color di->SetColor(state, 255, 0, false, origin->colormap, 1.f); diff --git a/src/rendering/hwrenderer/scene/hw_sky.cpp b/src/rendering/hwrenderer/scene/hw_sky.cpp index 6bdb8f8420..1461028281 100644 --- a/src/rendering/hwrenderer/scene/hw_sky.cpp +++ b/src/rendering/hwrenderer/scene/hw_sky.cpp @@ -61,8 +61,9 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) } FTextureID texno = s->GetTexture(pos); - texture[0] = FMaterial::ValidateTexture(texno, false, true); - if (!texture[0] || !texture[0]->tex->isValid()) goto normalsky; + FTexture* tex = TexMan.GetTexture(texno, true); + if (!tex || !tex->isValid()) goto normalsky; + texture[0] = FMaterial::ValidateTexture(tex, false); skytexno1 = texno; x_offset[0] = s->GetTextureXOffset(pos) * (360.f/65536.f); y_offset = s->GetTextureYOffset(pos); diff --git a/src/rendering/hwrenderer/scene/hw_skydome.cpp b/src/rendering/hwrenderer/scene/hw_skydome.cpp index 9b79423838..968b79fbb2 100644 --- a/src/rendering/hwrenderer/scene/hw_skydome.cpp +++ b/src/rendering/hwrenderer/scene/hw_skydome.cpp @@ -292,9 +292,10 @@ void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FMaterial *tex, float x_off float xscale = texw < 1024.f ? floor(1024.f / float(texw)) : 1.f; float yscale = 1.f; + auto texskyoffset = tex->Source()->GetSkyOffset() + skyoffset; if (texh <= 128 && (di->Level->flags & LEVEL_FORCETILEDSKY)) { - modelMatrix.translate(0.f, (-40 + tex->tex->GetSkyOffset() + skyoffset)*skyoffsetfactor, 0.f); + modelMatrix.translate(0.f, (-40 + texskyoffset)*skyoffsetfactor, 0.f); modelMatrix.scale(1.f, 1.2f * 1.17f, 1.f); yscale = 240.f / texh; } @@ -312,12 +313,12 @@ void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FMaterial *tex, float x_off } else if (texh <= 240) { - modelMatrix.translate(0.f, (200 - texh + tex->tex->GetSkyOffset() + skyoffset)*skyoffsetfactor, 0.f); + modelMatrix.translate(0.f, (200 - texh + texskyoffset)*skyoffsetfactor, 0.f); modelMatrix.scale(1.f, 1.f + ((texh - 200.f) / 200.f) * 1.17f, 1.f); } else { - modelMatrix.translate(0.f, (-40 + tex->tex->GetSkyOffset() + skyoffset)*skyoffsetfactor, 0.f); + modelMatrix.translate(0.f, (-40 + texskyoffset)*skyoffsetfactor, 0.f); modelMatrix.scale(1.f, 1.2f * 1.17f, 1.f); yscale = 240.f / texh; } diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index 98811286e4..d4c4f11a74 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -66,12 +66,13 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * te // The caps only get drawn for the main layer but not for the overlay. if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL) { - PalEntry pe = tex->tex->GetSkyCapColor(false); + auto base = tex->Source(); + PalEntry pe = base->GetSkyCapColor(false); state.SetObjectColor(pe); state.EnableTexture(false); RenderRow(di, state, DT_TriangleFan, 0); - pe = tex->tex->GetSkyCapColor(true); + pe = base->GetSkyCapColor(true); state.SetObjectColor(pe); RenderRow(di, state, DT_TriangleFan, rc); state.EnableTexture(true); @@ -96,7 +97,7 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * te void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FMaterial * gltex, float x_offset, bool sky2) { - FSkyBox * sb = static_cast(gltex->tex); + FSkyBox * sb = static_cast(gltex->Source()); int faces; FMaterial * tex; @@ -181,7 +182,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) di->SetupView(state, 0, 0, 0, !!(mState->MirrorFlag & 1), !!(mState->PlaneMirrorFlag & 1)); state.SetVertexBuffer(vertexBuffer); - if (origin->texture[0] && origin->texture[0]->tex->isSkybox()) + if (origin->texture[0] && origin->texture[0]->Source()->isSkybox()) { RenderBox(di, state, origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->sky2); } diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 1516159355..fb96034ed0 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -94,7 +94,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) // Optionally use STYLE_ColorBlend in place of STYLE_Add for fullbright items. if (RenderStyle == LegacyRenderStyles[STYLE_Add] && trans > 1.f - FLT_EPSILON && gl_usecolorblending && !di->isFullbrightScene() && actor && - fullbright && gltexture && !gltexture->tex->GetTranslucency()) + fullbright && gltexture && !gltexture->GetTranslucency()) { RenderStyle = LegacyRenderStyles[STYLE_ColorAdd]; } @@ -106,7 +106,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) { state.AlphaFunc(Alpha_GEqual, 0.f); } - else if (!gltexture || !gltexture->tex->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold); + else if (!gltexture || !gltexture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold); else state.AlphaFunc(Alpha_Greater, 0.f); if (RenderStyle.BlendOp == STYLEOP_Shadow) @@ -914,7 +914,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // allow disabling of the fullbright flag by a brightmap definition // (e.g. to do the gun flashes of Doom's zombies correctly. fullbright = (thing->flags5 & MF5_BRIGHT) || - ((thing->renderflags & RF_FULLBRIGHT) && (!gltexture || !gltexture->tex->isFullbrightDisabled())); + ((thing->renderflags & RF_FULLBRIGHT) && (!gltexture || !gltexture->Source()->isFullbrightDisabled())); lightlevel = fullbright ? 255 : hw_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ? @@ -1033,7 +1033,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t RenderStyle.DestAlpha = STYLEALPHA_InvSrc; } } - if ((gltexture && gltexture->tex->GetTranslucency()) || (RenderStyle.Flags & STYLEF_RedIsAlpha) || (modelframe && thing->RenderStyle != DefaultRenderStyle())) + if ((gltexture && gltexture->GetTranslucency()) || (RenderStyle.Flags & STYLEF_RedIsAlpha) || (modelframe && thing->RenderStyle != DefaultRenderStyle())) { if (hw_styleflags == STYLEHW_Solid) { diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 5c527304bd..1249a13cec 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -264,7 +264,7 @@ void HWWall::RenderTranslucentWall(HWDrawInfo *di, FRenderState &state) state.SetRenderStyle(RenderStyle); if (gltexture) { - if (!gltexture->tex->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); + if (!gltexture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); else state.AlphaFunc(Alpha_GEqual, 0.f); RenderTexturedWall(di, state, HWWall::RWF_TEXTURED | HWWall::RWF_NOSPLIT); } @@ -442,7 +442,7 @@ const char HWWall::passflag[] = { //========================================================================== void HWWall::PutWall(HWDrawInfo *di, bool translucent) { - if (gltexture && gltexture->tex->GetTranslucency() && passflag[type] == 2) + if (gltexture && gltexture->GetTranslucency() && passflag[type] == 2) { translucent = true; } @@ -1010,7 +1010,7 @@ bool HWWall::SetWallCoordinates(seg_t * seg, FTexCoordInfo *tci, float textureto if (gltexture != NULL) { bool normalize = false; - if (gltexture->tex->isHardwareCanvas()) normalize = true; + if (gltexture->isHardwareCanvas()) normalize = true; else if (flags & HWF_CLAMPY) { // for negative scales we can get negative coordinates here. @@ -1039,7 +1039,7 @@ void HWWall::CheckTexturePosition(FTexCoordInfo *tci) { float sub; - if (gltexture->tex->isHardwareCanvas()) return; + if (gltexture->isHardwareCanvas()) return; // clamp texture coordinates to a reasonable range. // Extremely large values can cause visual problems @@ -1106,7 +1106,7 @@ void HWWall::CheckTexturePosition(FTexCoordInfo *tci) static void GetTexCoordInfo(FMaterial *tex, FTexCoordInfo *tci, side_t *side, int texpos) { - tci->GetFromTexture(tex->tex, (float)side->GetTextureXScale(texpos), (float)side->GetTextureYScale(texpos), !!(side->GetLevel()->flags3 & LEVEL3_FORCEWORLDPANNING)); + tci->GetFromTexture(tex->Source(), (float)side->GetTextureXScale(texpos), (float)side->GetTextureYScale(texpos), !!(side->GetLevel()->flags3 & LEVEL3_FORCEWORLDPANNING)); } //========================================================================== @@ -1412,7 +1412,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, case 0: RenderStyle=STYLE_Translucent; alpha = seg->linedef->alpha; - translucent =alpha < 1. || (gltexture && gltexture->tex->GetTranslucency()); + translucent =alpha < 1. || (gltexture && gltexture->GetTranslucency()); break; case ML_ADDTRANS: @@ -2209,7 +2209,7 @@ void HWWall::ProcessLowerMiniseg(HWDrawInfo *di, seg_t *seg, sector_t * frontsec { FTexCoordInfo tci; type = RENDERWALL_BOTTOM; - tci.GetFromTexture(gltexture->tex, 1, 1, false); + tci.GetFromTexture(gltexture->Source(), 1, 1, false); SetWallCoordinates(seg, &tci, bfh, bfh, bfh, ffh, ffh, 0); PutWall(di, false); } diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index d0de4e0585..09881c1006 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -94,7 +94,7 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) } else { - float thresh = (huds->tex->tex->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; + float thresh = (huds->tex->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; state.AlphaFunc(Alpha_GEqual, thresh); state.SetMaterial(huds->tex, CLAMP_XY_NOMIP, (huds->weapon->Flags & PSPF_PLAYERTRANSLATED) ? huds->owner->Translation : 0, huds->OverrideShader); state.Draw(DT_TriangleStrip, huds->mx, 4); diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index fd42db857b..9711fe74a3 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -62,7 +62,7 @@ static void PrecacheTexture(FTexture *tex, int cache) //=========================================================================== static void PrecacheList(FMaterial *gltex, SpriteHits& translations) { - gltex->tex->SystemTextures.CleanUnused(translations, gltex->isExpanded()); + gltex->BaseLayer()->SystemTextures.CleanUnused(translations, gltex->isExpanded()); SpriteHits::Iterator it(translations); SpriteHits::Pair* pair; while (it.NextPair(pair)) screen->PrecacheMaterial(gltex, pair->Key); @@ -196,12 +196,15 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl FTexture *tex = TexMan.ByIndex(i); if (tex != nullptr) { - FMaterial *mat = FMaterial::ValidateTexture(tex, false, false); - if (mat != nullptr) + if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { - for (auto ftex : mat->GetLayerArray()) + FMaterial* mat = FMaterial::ValidateTexture(tex, false, false); + if (mat != nullptr) { - usedTextures.Insert(ftex, true); + for (auto ftex : mat->GetLayerArray()) + { + usedTextures.Insert(ftex, true); + } } } if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0) @@ -226,11 +229,11 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl { if (usedTextures.CheckKey(tex) == nullptr) { - tex->SystemTextures.Clean(true, false); + tex->CleanHardwareTextures(true, false); } if (usedSprites.CheckKey(tex) == nullptr) { - tex->SystemTextures.Clean(false, true); + tex->CleanHardwareTextures(false, true); } } } diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 4131061443..0e12a82754 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -535,13 +535,19 @@ void PolyFrameBuffer::CleanForRestart() void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { - auto tex = mat->tex; - if (tex->isSWCanvas()) return; + if (mat->Source()->isSWCanvas()) return; int flags = mat->isExpanded() ? CTF_Expand : 0; - auto base = static_cast(mat->GetLayer(0, translation)); + FTexture* layer; + auto systex = static_cast(mat->GetLayer(0, translation, &layer)); + systex->GetImage(layer, translation, flags); - base->Precache(mat, translation, flags); + int numLayers = mat->GetLayers(); + for (int i = 1; i < numLayers; i++) + { + auto systex = static_cast(mat->GetLayer(i, 0, &layer)); + systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0); + } } IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture() diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index 73c063e957..b5d4d3e88e 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -62,36 +62,15 @@ void PolyHardwareTexture::Reset() } } -void PolyHardwareTexture::Precache(FMaterial *mat, int translation, int flags) +DCanvas *PolyHardwareTexture::GetImage(FTexture *baselayer, const FMaterialState &state) { - int numLayers = mat->GetLayers(); - GetImage(mat->tex, translation, flags); - for (int i = 1; i < numLayers; i++) - { - FTexture *layer; - auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0); - } -} - -DCanvas *PolyHardwareTexture::GetImage(const FMaterialState &state) -{ - FTexture *tex = state.mMaterial->tex; + FTexture *tex = state.mMaterial->Source(); if (tex->isHardwareCanvas()) static_cast(tex)->NeedUpdate(); if (!mCanvas) { - FMaterial *mat = state.mMaterial; - int clampmode = state.mClampMode; - int translation = state.mTranslation; - - if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; - if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; - int flags = state.mMaterial->isExpanded() ? CTF_Expand : 0; - - return GetImage(tex, translation, flags); + return GetImage(baselayer, state.mTranslation, flags); } return mCanvas.get(); diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.h b/src/rendering/polyrenderer/backend/poly_hwtexture.h index 3d7565b581..26d9beb5bc 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.h +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.h @@ -23,9 +23,7 @@ public: static void ResetAll(); void Reset(); - void Precache(FMaterial *mat, int translation, int flags); - - DCanvas *GetImage(const FMaterialState &state); + DCanvas *GetImage(FTexture *tex, const FMaterialState &state); DCanvas *GetImage(FTexture *tex, int translation, int flags); PolyDepthStencil *GetDepthStencil(FTexture *tex); diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index cc763b89a1..6a36105b56 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -280,8 +280,8 @@ void PolyRenderState::Apply() mDrawCommands->SetShader(EFF_NONE, mTextureEnabled ? effectState : SHADER_NoTexture, mAlphaThreshold >= 0.f, false); } - if (mMaterial.mMaterial && mMaterial.mMaterial->tex) - mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->tex->shaderspeed / 1000.); + if (mMaterial.mMaterial && mMaterial.mMaterial->Source()) + mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->Source()->shaderspeed / 1000.); else mStreamData.timer = 0.0f; @@ -312,12 +312,13 @@ void PolyRenderState::ApplyMaterial() { if (mMaterial.mChanged && mMaterial.mMaterial) { - mTempTM = mMaterial.mMaterial->tex->isHardwareCanvas() ? TM_OPAQUE : TM_NORMAL; + mTempTM = mMaterial.mMaterial->isHardwareCanvas() ? TM_OPAQUE : TM_NORMAL; - auto base = static_cast(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation)); + FTexture* layer; + auto base = static_cast(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation, &layer)); if (base) { - DCanvas *texcanvas = base->GetImage(mMaterial); + DCanvas *texcanvas = base->GetImage(layer, mMaterial); mDrawCommands->SetTexture(0, texcanvas->GetPixels(), texcanvas->GetWidth(), texcanvas->GetHeight(), texcanvas->IsBgra()); int numLayers = mMaterial.mMaterial->GetLayers(); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index ca08b4134e..b1d2b3e0c8 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -337,8 +337,8 @@ void VkRenderState::ApplyStreamData() mStreamData.useVertexData = passManager->GetVertexFormat(static_cast(mVertexBuffer)->VertexFormat)->UseVertexData; - if (mMaterial.mMaterial && mMaterial.mMaterial->tex) - mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->tex->shaderspeed / 1000.); + if (mMaterial.mMaterial && mMaterial.mMaterial->Source()) + mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->Source()->shaderspeed / 1000.); else mStreamData.timer = 0.0f; @@ -369,7 +369,7 @@ void VkRenderState::ApplyPushConstants() } int tempTM = TM_NORMAL; - if (mMaterial.mMaterial && mMaterial.mMaterial->tex && mMaterial.mMaterial->tex->isHardwareCanvas()) + if (mMaterial.mMaterial && mMaterial.mMaterial->isHardwareCanvas()) tempTM = TM_OPAQUE; mPushConstants.uFogEnabled = fogset; @@ -383,8 +383,11 @@ void VkRenderState::ApplyPushConstants() mPushConstants.uAlphaThreshold = mAlphaThreshold; mPushConstants.uClipSplit = { mClipSplit[0], mClipSplit[1] }; - if (mMaterial.mMaterial && mMaterial.mMaterial->tex) - mPushConstants.uSpecularMaterial = { mMaterial.mMaterial->tex->Glossiness, mMaterial.mMaterial->tex->SpecularLevel }; + if (mMaterial.mMaterial) + { + auto source = mMaterial.mMaterial->Source(); + mPushConstants.uSpecularMaterial = { source->Glossiness, source->SpecularLevel }; + } mPushConstants.uLightIndex = mLightIndex; mPushConstants.uDataIndex = mStreamBufferWriter.DataIndex(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 1c0ea5e6de..796526b7e2 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -648,14 +648,21 @@ void VulkanFrameBuffer::CleanForRestart() void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { - auto tex = mat->tex; - if (tex->isSWCanvas()) return; + if (mat->Source()->isSWCanvas()) return; // Textures that are already scaled in the texture lump will not get replaced by hires textures. int flags = mat->isExpanded() ? CTF_Expand : 0; - auto base = static_cast(mat->GetLayer(0, translation)); + FTexture* layer; - base->Precache(mat, translation, flags); + auto systex = static_cast(mat->GetLayer(0, translation, &layer)); + systex->GetImage(layer, translation, mat->isExpanded() ? CTF_Expand : 0); + + int numLayers = mat->GetLayers(); + for (int i = 1; i < numLayers; i++) + { + auto systex = static_cast(mat->GetLayer(i, 0, &layer)); + systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0); + } } IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture() diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index c8784b6c5b..ccd7c804d3 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -109,33 +109,21 @@ void VkHardwareTexture::ResetAllDescriptors() fb->GetRenderPassManager()->TextureSetPoolReset(); } -void VkHardwareTexture::Precache(FMaterial *mat, int translation, int flags) -{ - int numLayers = mat->GetLayers(); - GetImage(mat->tex, translation, flags); - for (int i = 1; i < numLayers; i++) - { - FTexture *layer; - auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0); - } -} - VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state) { FMaterial *mat = state.mMaterial; - FTexture *tex = state.mMaterial->tex; + FTexture *base = state.mMaterial->Source(); int clampmode = state.mClampMode; int translation = state.mTranslation; - if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; - if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + if (base->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; + if (base->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; + else if ((base->isWarped() || base->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; // Textures that are already scaled in the texture lump will not get replaced by hires textures. int flags = state.mMaterial->isExpanded() ? CTF_Expand : 0; - if (tex->isHardwareCanvas()) static_cast(tex)->NeedUpdate(); + if (base->isHardwareCanvas()) static_cast(base)->NeedUpdate(); for (auto &set : mDescriptorSets) { @@ -152,7 +140,7 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s VulkanSampler *sampler = fb->GetSamplerManager()->Get(clampmode); WriteDescriptors update; - update.addCombinedImageSampler(descriptor.get(), 0, GetImage(tex, translation, flags)->View.get(), sampler, mImage.Layout); + update.addCombinedImageSampler(descriptor.get(), 0, GetImage(mat->BaseLayer(), translation, flags)->View.get(), sampler, mImage.Layout); for (int i = 1; i < numLayers; i++) { FTexture *layer; diff --git a/src/rendering/vulkan/textures/vk_hwtexture.h b/src/rendering/vulkan/textures/vk_hwtexture.h index 6dd2f8ea9a..b7bd02979a 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.h +++ b/src/rendering/vulkan/textures/vk_hwtexture.h @@ -27,8 +27,6 @@ public: static void ResetAll(); void Reset(); - void Precache(FMaterial *mat, int translation, int flags); - VulkanDescriptorSet *GetDescriptorSet(const FMaterialState &state); // Software renderer stuff From 73b4fbe861b4da7d4957539c8791c1fe8ddec442 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 00:25:08 +0200 Subject: [PATCH 007/220] - FGameTexture conversion in am_map.cpp --- src/am_map.cpp | 26 +++++++++++++------------- src/common/2d/v_draw.h | 6 ++++++ src/common/textures/texturemanager.h | 7 ++++++- src/common/textures/textures.h | 14 ++++++++++++++ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 3648381fd9..fd195ea700 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -988,7 +988,7 @@ class DAutomap :public DAutomapBase void calcMinMaxMtoF(); - void DrawMarker(FTexture *tex, double x, double y, int yadjust, + void DrawMarker(FGameTexture *tex, double x, double y, int yadjust, INTBOOL flip, double xscale, double yscale, int translation, double alpha, uint32_t fillcolor, FRenderStyle renderstyle); void rotatePoint(double *x, double *y); @@ -1235,7 +1235,7 @@ void DAutomap::ScrollParchment (double dmapx, double dmapy) if (mapback.isValid()) { - FTexture *backtex = TexMan.GetTexture(mapback); + auto backtex = TexMan.GetGameTexture(mapback); if (backtex != nullptr) { @@ -1588,7 +1588,7 @@ void DAutomap::clearFB (const AMColor &color) } else { - FTexture *backtex = TexMan.GetTexture(mapback); + auto backtex = TexMan.GetGameTexture(mapback); if (backtex != nullptr) { int pwidth = backtex->GetDisplayWidth(); @@ -2908,7 +2908,7 @@ void DAutomap::drawThings () if (am_showthingsprites > 0 && t->sprite > 0) { - FTexture *texture = nullptr; + FGameTexture *texture = nullptr; spriteframe_t *frame; int rotation = 0; @@ -2928,7 +2928,7 @@ void DAutomap::drawThings () rotation = int((angle.Normalized360() * (16. / 360.)).Degrees); const FTextureID textureID = frame->Texture[show > 2 ? rotation : 0]; - texture = TexMan.GetTexture(textureID, true); + texture = TexMan.GetGameTexture(textureID, true); } if (texture == nullptr) goto drawTriangle; // fall back to standard display if no sprite can be found. @@ -3023,7 +3023,7 @@ void DAutomap::drawThings () // //============================================================================= -void DAutomap::DrawMarker (FTexture *tex, double x, double y, int yadjust, +void DAutomap::DrawMarker (FGameTexture *tex, double x, double y, int yadjust, INTBOOL flip, double xscale, double yscale, int translation, double alpha, uint32_t fillcolor, FRenderStyle renderstyle) { if (tex == nullptr || !tex->isValid()) @@ -3035,8 +3035,8 @@ void DAutomap::DrawMarker (FTexture *tex, double x, double y, int yadjust, rotatePoint (&x, &y); } DrawTexture(twod, tex, CXMTOF(x) + f_x, CYMTOF(y) + yadjust + f_y, - DTA_DestWidthF, tex->GetDisplayWidthDouble() * CleanXfac * xscale, - DTA_DestHeightF, tex->GetDisplayHeightDouble() * CleanYfac * yscale, + DTA_DestWidth, tex->GetDisplayWidth() * CleanXfac * xscale, + DTA_DestHeight, tex->GetDisplayHeight() * CleanYfac * yscale, DTA_ClipTop, f_y, DTA_ClipBottom, f_y + f_h, DTA_ClipLeft, f_x, @@ -3072,7 +3072,7 @@ void DAutomap::drawMarks () if (font == nullptr) { - DrawMarker(TexMan.GetTexture(marknums[i], true), markpoints[i].x, markpoints[i].y, -3, 0, + DrawMarker(TexMan.GetGameTexture(marknums[i], true), markpoints[i].x, markpoints[i].y, -3, 0, 1, 1, 0, 1, 0, LegacyRenderStyles[STYLE_Normal]); } else @@ -3114,18 +3114,18 @@ void DAutomap::drawAuthorMarkers () } FTextureID picnum; - FTexture *tex; + FGameTexture *tex; uint16_t flip = 0; if (mark->picnum.isValid()) { - tex = TexMan.GetTexture(mark->picnum, true); + tex = TexMan.GetGameTexture(mark->picnum, true); if (tex->GetRotations() != 0xFFFF) { spriteframe_t *sprframe = &SpriteFrames[tex->GetRotations()]; picnum = sprframe->Texture[0]; flip = sprframe->Flip & 1; - tex = TexMan.GetTexture(picnum); + tex = TexMan.GetGameTexture(picnum); } } else @@ -3140,7 +3140,7 @@ void DAutomap::drawAuthorMarkers () spriteframe_t *sprframe = &SpriteFrames[sprdef->spriteframes + mark->frame]; picnum = sprframe->Texture[0]; flip = sprframe->Flip & 1; - tex = TexMan.GetTexture(picnum); + tex = TexMan.GetGameTexture(picnum); } } auto it = Level->GetActorIterator(mark->args[0]); diff --git a/src/common/2d/v_draw.h b/src/common/2d/v_draw.h index a3e6b747ca..5aebfd8332 100644 --- a/src/common/2d/v_draw.h +++ b/src/common/2d/v_draw.h @@ -214,6 +214,12 @@ void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double void DrawChar(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, int character, int tag_first, ...); void DrawTexture(F2DDrawer* drawer, FTexture* img, double x, double y, int tags_first, ...); +template +void DrawTexture(F2DDrawer* drawer, FGameTexture* img, double x, double y, int tags_first, Params&&... params) +{ + DrawTexture(drawer, img->GetTexture(), x, y, tags_first, std::forward(params)...); +} + void DoDim(F2DDrawer* drawer, PalEntry color, float amount, int x1, int y1, int w, int h, FRenderStyle* style = nullptr); void Dim(F2DDrawer* drawer, PalEntry color, float damount, int x1, int y1, int w, int h, FRenderStyle* style = nullptr); void FillBorder(F2DDrawer *drawer, FTexture* img); // Fills the border around a 4:3 part of the screen on non-4:3 displays diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index ac47b170bc..ed239c8bab 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -44,7 +44,12 @@ public: { return InternalGetTexture(texnum.GetIndex(), animate, true, false); } - + + FGameTexture* GetGameTexture(FTextureID texnum, bool animate = false) + { + return reinterpret_cast(GetTexture(texnum, animate)); + } + // This is the only access function that should be used inside the software renderer. FTexture *GetPalettedTexture(FTextureID texnum, bool animate) { diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 35487c7727..74d3bed192 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -559,6 +559,20 @@ struct FTexCoordInfo void GetFromTexture(FTexture *tex, float x, float y, bool forceworldpanning); }; +// Refactoring helper to allow piece by piece adjustment of the API +class FGameTexture +{ + FTexture wrapped; +public: + FTexture* GetTexture() { return &wrapped; } + + int GetDisplayWidth() /*const*/ { return wrapped.GetDisplayWidth(); } + int GetDisplayHeight() /*const*/ { return wrapped.GetDisplayHeight(); } + + bool isValid() { return wrapped.isValid(); } + uint16_t GetRotations() { return wrapped.GetRotations(); } +}; + #endif From 9593cb56aebbf61393e866b6bbd7db3cfe2741c6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 00:42:13 +0200 Subject: [PATCH 008/220] - decoupled the software renderer entirely from FTexture - it will only look at FSoftwareTexture now, all access to the texture manager has been wrapped. --- src/common/textures/texture.cpp | 3 +- src/common/textures/texturemanager.cpp | 3 +- src/common/textures/texturemanager.h | 7 ++- src/common/textures/textures.h | 37 +++++++++++-- src/rendering/swrenderer/line/r_line.cpp | 24 ++++----- .../swrenderer/line/r_renderdrawsegment.cpp | 42 +++++---------- src/rendering/swrenderer/line/r_walldraw.cpp | 2 +- src/rendering/swrenderer/plane/r_skyplane.cpp | 19 +++---- .../swrenderer/plane/r_visibleplane.cpp | 8 +-- src/rendering/swrenderer/r_swrenderer.cpp | 18 +++---- src/rendering/swrenderer/r_swrenderer.h | 4 +- .../swrenderer/scene/r_opaque_pass.cpp | 17 +++--- .../swrenderer/scene/r_opaque_pass.h | 2 +- .../swrenderer/textures/r_swtexture.cpp | 54 ++++++++++++------- .../swrenderer/textures/r_swtexture.h | 51 +++++++++--------- .../swrenderer/textures/swcanvastexture.cpp | 6 +-- .../swrenderer/textures/warptexture.cpp | 6 +-- src/rendering/swrenderer/things/r_decal.cpp | 6 +-- .../swrenderer/things/r_playersprite.cpp | 8 +-- src/rendering/swrenderer/things/r_sprite.cpp | 8 ++- src/rendering/swrenderer/things/r_sprite.h | 2 +- .../swrenderer/things/r_wallsprite.cpp | 3 +- .../swrenderer/things/r_wallsprite.h | 2 +- 23 files changed, 170 insertions(+), 162 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index a2f02e3eb0..05ae74221f 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -50,7 +50,6 @@ // Wrappers to keep the definitions of these classes out of here. void DeleteMaterial(FMaterial* mat); -void DeleteSoftwareTexture(FSoftwareTexture *swtex); IHardwareTexture* CreateHardwareTexture(); @@ -161,7 +160,7 @@ FTexture::~FTexture () } if (SoftwareTexture != nullptr) { - DeleteSoftwareTexture(SoftwareTexture); + delete SoftwareTexture; SoftwareTexture = nullptr; } } diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 4e87a893ee..834f9de48f 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -111,7 +111,6 @@ void FTextureManager::DeleteAll() // main reason to call this outside of the destruction code. // //========================================================================== -void DeleteSoftwareTexture(FSoftwareTexture* swtex); void FTextureManager::FlushAll() { @@ -120,7 +119,7 @@ void FTextureManager::FlushAll() for (int j = 0; j < 2; j++) { Textures[i].Texture->CleanHardwareTextures(true, true); - DeleteSoftwareTexture(Textures[i].Texture->SoftwareTexture); + delete Textures[i].Texture->SoftwareTexture; Textures[i].Texture->SoftwareTexture = nullptr; } } diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index ed239c8bab..b5a7aa4e75 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -60,7 +60,12 @@ public: { return InternalGetTexture(i, animate, true, false); } - + + FGameTexture* GameByIndex(int i, bool animate = false) + { + return reinterpret_cast(ByIndex(i, animate)); + } + FTexture *FindTexture(const char *texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny); bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 74d3bed192..839607cd30 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -156,7 +156,12 @@ enum FTextureFormat : uint32_t TEX_Count }; -class FSoftwareTexture; +class ISoftwareTexture +{ +public: + virtual ~ISoftwareTexture() = default; +}; + class FGLRenderState; struct spriteframewithrotate; @@ -226,7 +231,6 @@ class FTexture friend FSerializer &Serialize(FSerializer &arc, const char *key, FTextureID &value, FTextureID *defval); // For now only give access to classes which cannot be reworked yet. None of these should remain here when all is done. - friend class FSoftwareTexture; friend class FWarpTexture; friend class FMaterial; friend class OpenGLRenderer::FGLRenderState; // For now this needs access to some fields in ApplyMaterial. This should be rerouted through the Material class @@ -275,6 +279,7 @@ public: bool isMiscPatch() const { return UseType == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. int isWarped() const { return bWarped; } int GetRotations() const { return Rotations; } + float GetShaderSpeed() const { return shaderspeed; } void SetRotations(int rot) { Rotations = int16_t(rot); } bool isSprite() const { return UseType == ETextureType::Sprite || UseType == ETextureType::SkinSprite || UseType == ETextureType::Decal; } @@ -301,6 +306,7 @@ public: int GetSourceLump() const { return SourceLump; } ETextureType GetUseType() const { return UseType; } void SetSpeed(float fac) { shaderspeed = fac; } + bool UseWorldPanning() const { return bWorldPanning; } void SetWorldPanning(bool on) { bWorldPanning = on; } void SetDisplaySize(int fitwidth, int fitheight); void SetFrontSkyLayer(bool on = true) { bNoRemap0 = on; } @@ -334,7 +340,14 @@ public: static PalEntry averageColor(const uint32_t *data, int size, int maxout); - FSoftwareTexture *GetSoftwareTexture(); + ISoftwareTexture* GetSoftwareTexture() + { + return SoftwareTexture; + } + void SetSoftwareTextue(ISoftwareTexture* swtex) + { + SoftwareTexture = swtex; + } protected: @@ -347,7 +360,7 @@ protected: public: FHardwareTextureContainer SystemTextures; protected: - FSoftwareTexture *SoftwareTexture = nullptr; + ISoftwareTexture *SoftwareTexture = nullptr; // None of the following pointers are owned by this texture, they are all controlled by the texture manager. @@ -568,9 +581,23 @@ public: int GetDisplayWidth() /*const*/ { return wrapped.GetDisplayWidth(); } int GetDisplayHeight() /*const*/ { return wrapped.GetDisplayHeight(); } + int GetTexelWidth() /*const*/ { return wrapped.GetTexelWidth(); } + int GetTexelHeight() /*const*/ { return wrapped.GetTexelHeight(); } + int GetTexelLeftOffset(int adjusted) /*const*/ { return wrapped.GetTexelLeftOffset(adjusted); } + int GetTexelTopOffset(int adjusted) /*const*/ { return wrapped.GetTexelTopOffset(adjusted); } + double GetDisplayLeftOffset(int adjusted) /*const*/ { return wrapped.GetDisplayLeftOffsetDouble(adjusted); } + double GetDisplayTopOffset(int adjusted) /*const*/ { return wrapped.GetDisplayTopOffsetDouble(adjusted); } bool isValid() { return wrapped.isValid(); } - uint16_t GetRotations() { return wrapped.GetRotations(); } + bool isWarped() { return wrapped.isWarped(); } + bool useWorldPanning() { return wrapped.UseWorldPanning(); } + float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } + uint16_t GetRotations() const { return wrapped.GetRotations(); } + int GetSkyOffset() const { return wrapped.GetSkyOffset(); } + FTextureID GetID() const { return wrapped.GetID(); } + ISoftwareTexture* GetSoftwareTexture() { return wrapped.GetSoftwareTexture(); } + void SetSoftwareTexture(ISoftwareTexture* swtex) { wrapped.SetSoftwareTextue(swtex); } + }; diff --git a/src/rendering/swrenderer/line/r_line.cpp b/src/rendering/swrenderer/line/r_line.cpp index d18c2d9a55..d6fb813214 100644 --- a/src/rendering/swrenderer/line/r_line.cpp +++ b/src/rendering/swrenderer/line/r_line.cpp @@ -389,8 +389,7 @@ namespace swrenderer if (mLineSegment->linedef->alpha > 0.0f && sidedef->GetTexture(side_t::mid).isValid()) { - FTexture* tex = TexMan.GetPalettedTexture(sidedef->GetTexture(side_t::mid), true); - FSoftwareTexture* pic = tex && tex->isValid() ? tex->GetSoftwareTexture() : nullptr; + auto pic = GetPalettedSWTexture(sidedef->GetTexture(side_t::mid), true); if (pic) { draw_segment->SetHasTranslucentMidTexture(); @@ -687,10 +686,9 @@ namespace swrenderer // No top texture for skyhack lines if (mFrontSector->GetTexture(sector_t::ceiling) == skyflatnum && mBackSector->GetTexture(sector_t::ceiling) == skyflatnum) return; - FTexture *tex = TexMan.GetPalettedTexture(sidedef->GetTexture(side_t::top), true); - if (!tex || !tex->isValid()) return; - - mTopTexture = tex->GetSoftwareTexture(); + auto tex = GetPalettedSWTexture(sidedef->GetTexture(side_t::top), true); + if (!tex) return; + mTopTexture = tex; } void SWRenderLine::SetMiddleTexture() @@ -702,10 +700,9 @@ namespace swrenderer if (linedef->isVisualPortal()) return; if (linedef->special == Line_Horizon) return; - auto tex = TexMan.GetPalettedTexture(sidedef->GetTexture(side_t::mid), true); - if (!tex || !tex->isValid()) return; - - mMiddleTexture = tex->GetSoftwareTexture(); + auto tex = GetPalettedSWTexture(sidedef->GetTexture(side_t::mid), true); + if (!tex) return; + mMiddleTexture = tex; } void SWRenderLine::SetBottomTexture() @@ -713,10 +710,9 @@ namespace swrenderer side_t *sidedef = mLineSegment->sidedef; line_t *linedef = mLineSegment->linedef; - FTexture *tex = TexMan.GetPalettedTexture(sidedef->GetTexture(side_t::bottom), true); - if (!tex || !tex->isValid()) return; - - mBottomTexture = tex->GetSoftwareTexture(); + auto tex = GetPalettedSWTexture(sidedef->GetTexture(side_t::bottom), true); + if (!tex) return; + mBottomTexture = tex; } bool SWRenderLine::IsFogBoundary(sector_t *front, sector_t *back) const diff --git a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp index fc5a2cbb0b..4d203ec4a0 100644 --- a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp @@ -91,13 +91,7 @@ namespace swrenderer auto viewport = Thread->Viewport.get(); Clip3DFloors *clip3d = Thread->Clip3D.get(); - FTexture *ttex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::mid), true); - if (curline->GetLevel()->i_compatflags & COMPATF_MASKEDMIDTEX) - { - ttex = ttex->GetRawTexture(); - } - FSoftwareTexture *tex = ttex->GetSoftwareTexture(); - + auto tex = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::mid), true, curline->GetLevel()); const short *mfloorclip = ds->drawsegclip.sprbottomclip; const short *mceilingclip = ds->drawsegclip.sprtopclip; @@ -333,20 +327,18 @@ namespace swrenderer } else { - FTexture *rw_tex = nullptr; if (fover->flags & FF_UPPERTEXTURE) { - rw_tex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::top), true); + rw_pic = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::top), true); } else if (fover->flags & FF_LOWERTEXTURE) { - rw_tex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::bottom), true); + rw_pic = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::bottom), true); } else { - rw_tex = TexMan.GetPalettedTexture(fover->master->sidedef[0]->GetTexture(side_t::mid), true); + rw_pic = GetPalettedSWTexture(fover->master->sidedef[0]->GetTexture(side_t::mid), true); } - rw_pic = rw_tex && rw_tex->isValid() ? rw_tex->GetSoftwareTexture() : nullptr; } } else if (frontsector->e->XFloor.ffloors.Size()) @@ -395,20 +387,18 @@ namespace swrenderer if (!rw_pic && !swimmable_found) { fover = nullptr; - FTexture *rw_tex; if (rover->flags & FF_UPPERTEXTURE) { - rw_tex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::top), true); + rw_pic = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::top), true); } else if (rover->flags & FF_LOWERTEXTURE) { - rw_tex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::bottom), true); + rw_pic = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::bottom), true); } else { - rw_tex = TexMan.GetPalettedTexture(rover->master->sidedef[0]->GetTexture(side_t::mid), true); + rw_pic = GetPalettedSWTexture(rover->master->sidedef[0]->GetTexture(side_t::mid), true); } - rw_pic = rw_tex && rw_tex->isValid() ? rw_tex->GetSoftwareTexture() : nullptr; } if (rw_pic && !swimmable_found) @@ -487,20 +477,18 @@ namespace swrenderer } else { - FTexture *rw_tex; if (fover->flags & FF_UPPERTEXTURE) { - rw_tex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::top), true); + rw_pic = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::top), true); } else if (fover->flags & FF_LOWERTEXTURE) { - rw_tex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::bottom), true); + rw_pic = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::bottom), true); } else { - rw_tex = TexMan.GetPalettedTexture(fover->master->sidedef[0]->GetTexture(side_t::mid), true); + rw_pic = GetPalettedSWTexture(fover->master->sidedef[0]->GetTexture(side_t::mid), true); } - rw_pic = rw_tex && rw_tex->isValid() ? rw_tex->GetSoftwareTexture() : nullptr; } } else if (frontsector->e->XFloor.ffloors.Size()) @@ -546,20 +534,18 @@ namespace swrenderer if (!rw_pic && !swimmable_found) { fover = nullptr; - FTexture *rw_tex; if (rover->flags & FF_UPPERTEXTURE) { - rw_tex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::top), true); + rw_pic = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::top), true); } else if (rover->flags & FF_LOWERTEXTURE) { - rw_tex = TexMan.GetPalettedTexture(curline->sidedef->GetTexture(side_t::bottom), true); + rw_pic = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::bottom), true); } else { - rw_tex = TexMan.GetPalettedTexture(rover->master->sidedef[0]->GetTexture(side_t::mid), true); + rw_pic = GetPalettedSWTexture(rover->master->sidedef[0]->GetTexture(side_t::mid), true); } - rw_pic = rw_tex && rw_tex->isValid() ? rw_tex->GetSoftwareTexture() : nullptr; } if (rw_pic && !swimmable_found) @@ -643,7 +629,7 @@ namespace swrenderer void RenderDrawSegment::GetNoWrapMidTextureZ(DrawSegment* ds, FSoftwareTexture* tex, double& ceilZ, double& floorZ) { - double texheight = tex->GetScaledHeightDouble() / fabs(curline->sidedef->GetTextureYScale(side_t::mid)); + double texheight = tex->GetScaledHeight() / fabs(curline->sidedef->GetTextureYScale(side_t::mid)); double texturemid; if (curline->linedef->flags & ML_DONTPEGBOTTOM) texturemid = MAX(frontsector->GetPlaneTexZ(sector_t::floor), backsector->GetPlaneTexZ(sector_t::floor)) + texheight; diff --git a/src/rendering/swrenderer/line/r_walldraw.cpp b/src/rendering/swrenderer/line/r_walldraw.cpp index 022854ddd6..35f3403606 100644 --- a/src/rendering/swrenderer/line/r_walldraw.cpp +++ b/src/rendering/swrenderer/line/r_walldraw.cpp @@ -130,7 +130,7 @@ namespace swrenderer WallDrawerArgs drawerargs; // Textures that aren't masked can use the faster opaque drawer - if (!pic->GetTexture()->isMasked() && mask && alpha >= OPAQUE && !additive) + if (!pic->isMasked() && mask && alpha >= OPAQUE && !additive) { drawerargs.SetStyle(true, false, OPAQUE, light_list); } diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 13361e3973..5b9b60c4cc 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -63,10 +63,7 @@ namespace swrenderer { static FSoftwareTexture *GetSWTex(FTextureID texid, bool allownull = true) { - auto tex = TexMan.GetPalettedTexture(texid, true); - if (tex == nullptr) return nullptr; - if (!allownull && !tex->isValid()) return nullptr; - return tex->GetSoftwareTexture(); + return GetPalettedSWTexture(texid, true, nullptr, true); } RenderSkyPlane::RenderSkyPlane(RenderThread *thread) @@ -74,16 +71,14 @@ namespace swrenderer Thread = thread; auto Level = Thread->Viewport->Level(); - auto skytex1 = TexMan.GetPalettedTexture(Level->skytexture1, true); - auto skytex2 = TexMan.GetPalettedTexture(Level->skytexture2, true); + auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true); + auto sskytex2 = GetPalettedSWTexture(Level->skytexture2, true, nullptr, true); - if (skytex1 == nullptr) + if (sskytex1 == nullptr) return; - FSoftwareTexture *sskytex1 = skytex1->GetSoftwareTexture(); - FSoftwareTexture *sskytex2 = skytex2->GetSoftwareTexture(); skytexturemid = 0; - int skyheight = skytex1->GetDisplayHeight(); + int skyheight = sskytex1->GetScaledHeight(); skyoffset = cl_oldfreelooklimit? 0 : skyheight == 256? 166 : skyheight >= 240? 150 : skyheight >= 200? 110 : 138; if (skyheight >= 128 && skyheight < 200) { @@ -91,7 +86,7 @@ namespace swrenderer } else if (skyheight >= 200) { - skytexturemid = (200 - skyheight) * sskytex1->GetScale().Y + ((r_skymode == 2 && !(Level->flags & LEVEL_FORCETILEDSKY)) ? skytex1->GetSkyOffset() : 0); + skytexturemid = (200 - skyheight) * sskytex1->GetScale().Y + ((r_skymode == 2 && !(Level->flags & LEVEL_FORCETILEDSKY)) ? sskytex1->GetSkyOffset() : 0); } if (viewwidth != 0 && viewheight != 0) @@ -207,7 +202,7 @@ namespace swrenderer frontcyl = MAX(frontskytex->GetWidth(), frontxscale); if (Level->skystretch) { - skymid = skymid * frontskytex->GetScaledHeightDouble() / (SKYSTRETCH_HEIGHT + skyoffset); + skymid = skymid * frontskytex->GetScaledHeight() / (SKYSTRETCH_HEIGHT + skyoffset); } } } diff --git a/src/rendering/swrenderer/plane/r_visibleplane.cpp b/src/rendering/swrenderer/plane/r_visibleplane.cpp index 00f76a8f34..889d2f0be0 100644 --- a/src/rendering/swrenderer/plane/r_visibleplane.cpp +++ b/src/rendering/swrenderer/plane/r_visibleplane.cpp @@ -114,13 +114,7 @@ namespace swrenderer } else // regular flat { - FTexture *ttex = TexMan.GetPalettedTexture(picnum, true); - - if (!ttex->isValid()) - { - return; - } - FSoftwareTexture *tex = ttex->GetSoftwareTexture(); + auto tex = GetPalettedSWTexture(picnum, true); if (!masked && !additive) { // If we're not supposed to see through this plane, draw it opaque. diff --git a/src/rendering/swrenderer/r_swrenderer.cpp b/src/rendering/swrenderer/r_swrenderer.cpp index c099b4b16b..4f91447cef 100644 --- a/src/rendering/swrenderer/r_swrenderer.cpp +++ b/src/rendering/swrenderer/r_swrenderer.cpp @@ -82,13 +82,13 @@ FRenderer *CreateSWRenderer() return new FSoftwareRenderer; } -void FSoftwareRenderer::PreparePrecache(FTexture *ttex, int cache) +void FSoftwareRenderer::PreparePrecache(FGameTexture *ttex, int cache) { bool isbgra = V_IsTrueColor(); - if (ttex != nullptr && ttex->isValid() && !ttex->isCanvas()) + if (ttex != nullptr && ttex->isValid() && !ttex->GetTexture()->isCanvas()) { - FSoftwareTexture *tex = ttex->GetSoftwareTexture(); + FSoftwareTexture *tex = GetSoftwareTexture(ttex); if (tex->CheckPixels()) { @@ -96,18 +96,18 @@ void FSoftwareRenderer::PreparePrecache(FTexture *ttex, int cache) } else if (cache != 0) { - FImageSource::RegisterForPrecache(ttex->GetImage(), V_IsTrueColor()); + FImageSource::RegisterForPrecache(ttex->GetTexture()->GetImage(), V_IsTrueColor()); } } } -void FSoftwareRenderer::PrecacheTexture(FTexture *ttex, int cache) +void FSoftwareRenderer::PrecacheTexture(FGameTexture *ttex, int cache) { bool isbgra = V_IsTrueColor(); - if (ttex != nullptr && ttex->isValid() && !ttex->isCanvas()) + if (ttex != nullptr && ttex->isValid() && !ttex->GetTexture()->isCanvas()) { - FSoftwareTexture *tex = ttex->GetSoftwareTexture(); + FSoftwareTexture *tex = GetSoftwareTexture(ttex); if (cache & FTextureManager::HIT_Columnmode) { const FSoftwareTextureSpan *spanp; @@ -173,12 +173,12 @@ void FSoftwareRenderer::Precache(uint8_t *texhitlist, TMap & FImageSource::BeginPrecaching(); for (int i = cnt - 1; i >= 0; i--) { - PreparePrecache(TexMan.ByIndex(i), texhitlist[i]); + PreparePrecache(TexMan.GameByIndex(i), texhitlist[i]); } for (int i = cnt - 1; i >= 0; i--) { - PrecacheTexture(TexMan.ByIndex(i), texhitlist[i]); + PrecacheTexture(TexMan.GameByIndex(i), texhitlist[i]); } FImageSource::EndPrecaching(); } diff --git a/src/rendering/swrenderer/r_swrenderer.h b/src/rendering/swrenderer/r_swrenderer.h index 7ab3c05080..1e26a6a060 100644 --- a/src/rendering/swrenderer/r_swrenderer.h +++ b/src/rendering/swrenderer/r_swrenderer.h @@ -27,8 +27,8 @@ struct FSoftwareRenderer : public FRenderer void Init() override; private: - void PreparePrecache(FTexture *tex, int cache); - void PrecacheTexture(FTexture *tex, int cache); + void PreparePrecache(FGameTexture *tex, int cache); + void PrecacheTexture(FGameTexture *tex, int cache); swrenderer::RenderScene mScene; }; diff --git a/src/rendering/swrenderer/scene/r_opaque_pass.cpp b/src/rendering/swrenderer/scene/r_opaque_pass.cpp index c8158e8cf6..6f6ef6bd1e 100644 --- a/src/rendering/swrenderer/scene/r_opaque_pass.cpp +++ b/src/rendering/swrenderer/scene/r_opaque_pass.cpp @@ -951,7 +951,8 @@ namespace swrenderer { thinglightlevel = thing->Sector->GetTexture(sector_t::ceiling) == skyflatnum ? thing->Sector->GetCeilingLight() : thing->Sector->GetFloorLight(); auto nc = !!(thing->Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING); - thingColormap = GetSpriteColorTable(thing->Sector->Colormap, thing->Sector->SpecialColors[sector_t::sprites], nc); } + thingColormap = GetSpriteColorTable(thing->Sector->Colormap, thing->Sector->SpecialColors[sector_t::sprites], nc); + } if ((sprite.renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE) { @@ -1021,11 +1022,8 @@ namespace swrenderer { sprite.picnum = thing->picnum; - sprite.tex = TexMan.GetPalettedTexture(sprite.picnum, true); - if (!sprite.tex->isValid()) - { - return false; - } + sprite.tex = GetPalettedSWTexture(sprite.picnum, true); + if (!sprite.tex) return false; if (sprite.tex->GetRotations() != 0xFFFF) { @@ -1052,7 +1050,8 @@ namespace swrenderer { sprite.renderflags ^= RF_XFLIP; } - sprite.tex = TexMan.GetPalettedTexture(sprite.picnum, false); // Do not animate the rotation + sprite.tex = GetPalettedSWTexture(sprite.picnum, false); // Do not animate the rotation + if (!sprite.tex) return false; } } else @@ -1082,7 +1081,7 @@ namespace swrenderer { sprite.renderflags ^= RF_XFLIP; } - sprite.tex = TexMan.GetPalettedTexture(tex, false); // Do not animate the rotation + sprite.tex = GetPalettedSWTexture(tex, false); // Do not animate the rotation } if (r_drawvoxels) @@ -1094,7 +1093,7 @@ namespace swrenderer return false; } - if (sprite.voxel == nullptr && (sprite.tex == nullptr || !sprite.tex->isValid())) + if (sprite.voxel == nullptr && sprite.tex == nullptr) { return false; } diff --git a/src/rendering/swrenderer/scene/r_opaque_pass.h b/src/rendering/swrenderer/scene/r_opaque_pass.h index d834327d56..d9d20c972c 100644 --- a/src/rendering/swrenderer/scene/r_opaque_pass.h +++ b/src/rendering/swrenderer/scene/r_opaque_pass.h @@ -51,7 +51,7 @@ namespace swrenderer { DVector3 pos; int spritenum; - FTexture *tex; + FSoftwareTexture *tex; FVoxelDef *voxel; FTextureID picnum; DVector2 spriteScale; diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index 37695fa7d5..676ed73138 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -38,18 +38,9 @@ #include "bitmap.h" #include "m_alloc.h" #include "imagehelpers.h" +#include "texturemanager.h" -FSoftwareTexture *FTexture::GetSoftwareTexture() -{ - if (!SoftwareTexture) - { - if (bHasCanvas) SoftwareTexture = new FSWCanvasTexture(this); - else if (bWarped) SoftwareTexture = new FWarpTexture(this, bWarped); - else SoftwareTexture = new FSoftwareTexture(this); - } - return SoftwareTexture; -} //========================================================================== // @@ -57,16 +48,19 @@ FSoftwareTexture *FTexture::GetSoftwareTexture() // //========================================================================== -FSoftwareTexture::FSoftwareTexture(FTexture *tex) +FSoftwareTexture::FSoftwareTexture(FGameTexture *tex) { mTexture = tex; - mSource = tex; + mSource = tex->GetTexture(); mBufferFlags = CTF_ProcessData; - auto info = tex->CreateTexBuffer(0, CTF_CheckOnly| mBufferFlags); + // calculate the real size after running the scaler. + auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| mBufferFlags); mPhysicalWidth = info.mWidth; mPhysicalHeight = info.mHeight; - mPhysicalScale = tex->Width > 0? mPhysicalWidth / tex->Width : mPhysicalWidth; + mPhysicalScale = tex->GetTexelWidth() > 0 ? mPhysicalWidth / tex->GetTexelWidth() : mPhysicalWidth; + Scale.X = (double)tex->GetTexelWidth() / tex->GetDisplayWidth(); + Scale.Y = (double)tex->GetTexelHeight() / tex->GetDisplayHeight(); CalcBitSize(); } @@ -119,7 +113,7 @@ const uint8_t *FSoftwareTexture::GetPixels(int style) } else { - auto tempbuffer = mTexture->CreateTexBuffer(0, mBufferFlags); + auto tempbuffer = mSource->CreateTexBuffer(0, mBufferFlags); Pixels.Resize(GetPhysicalWidth()*GetPhysicalHeight()); PalEntry *pe = (PalEntry*)tempbuffer.mBuffer; if (!style) @@ -159,12 +153,12 @@ const uint32_t *FSoftwareTexture::GetPixelsBgra() { if (mPhysicalScale == 1) { - FBitmap bitmap = mTexture->GetBgraBitmap(nullptr); + FBitmap bitmap = mSource->GetBgraBitmap(nullptr); GenerateBgraFromBitmap(bitmap); } else { - auto tempbuffer = mTexture->CreateTexBuffer(0, mBufferFlags); + auto tempbuffer = mSource->CreateTexBuffer(0, mBufferFlags); CreatePixelsBgraWithMipmaps(); PalEntry *pe = (PalEntry*)tempbuffer.mBuffer; for (int y = 0; y < GetPhysicalHeight(); y++) @@ -263,7 +257,7 @@ FSoftwareTextureSpan **FSoftwareTexture::CreateSpans (const T *pixels) { FSoftwareTextureSpan **spans, *span; - if (!mTexture->isMasked()) + if (!mSource->isMasked()) { // Texture does not have holes, so it can use a simpler span structure spans = (FSoftwareTextureSpan **)M_Malloc (sizeof(FSoftwareTextureSpan*)*GetPhysicalWidth() + sizeof(FSoftwareTextureSpan)*2); span = (FSoftwareTextureSpan *)&spans[GetPhysicalWidth()]; @@ -598,8 +592,28 @@ void FSoftwareTexture::FreeAllSpans() } } -void DeleteSoftwareTexture(FSoftwareTexture* swtex) +FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex) { - delete swtex; + FSoftwareTexture* SoftwareTexture = static_cast(tex->GetSoftwareTexture()); + if (!SoftwareTexture) + { + auto source = tex->GetTexture(); + if (source->isCanvas()) SoftwareTexture = new FSWCanvasTexture(tex); + else if (tex->isWarped()) SoftwareTexture = new FWarpTexture(tex, tex->isWarped()); + else SoftwareTexture = new FSoftwareTexture(tex); + tex->SetSoftwareTexture(SoftwareTexture); + } + return SoftwareTexture; +} + +FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull) +{ + auto tex = TexMan.GetPalettedTexture(texid, true); + if (checkcompat && tex && tex->isValid() && checkcompat->i_compatflags & COMPATF_MASKEDMIDTEX) + { + tex = tex->GetRawTexture(); + } + FSoftwareTexture* pic = tex && (allownull || tex->isValid()) ? GetSoftwareTexture(reinterpret_cast(tex)) : nullptr; + return pic; } diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index ce6438aafb..a6b89c8c99 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -12,14 +12,15 @@ struct FSoftwareTextureSpan // For now this is just a minimal wrapper around FTexture. Once the software renderer no longer accesses FTexture directly, it is time for cleaning up. -class FSoftwareTexture +class FSoftwareTexture : public ISoftwareTexture { protected: - FTexture *mTexture; + FGameTexture *mTexture; FTexture *mSource; TArray Pixels; TArray PixelsBgra; FSoftwareTextureSpan **Spandata[3] = { }; + DVector2 Scale; uint8_t WidthBits = 0, HeightBits = 0; uint16_t WidthMask = 0; int mPhysicalWidth, mPhysicalHeight; @@ -32,14 +33,14 @@ protected: void CalcBitSize(); public: - FSoftwareTexture(FTexture *tex); + FSoftwareTexture(FGameTexture *tex); virtual ~FSoftwareTexture() { FreeAllSpans(); } - FTexture *GetTexture() const + FGameTexture *GetTexture() const { return mTexture; } @@ -47,32 +48,33 @@ public: // The feature from hell... :( bool useWorldPanning(FLevelLocals *Level) const { - return mTexture->bWorldPanning || (Level->flags3 & LEVEL3_FORCEWORLDPANNING); + return mTexture->useWorldPanning() || (Level->flags3 & LEVEL3_FORCEWORLDPANNING); } bool isMasked() { - return mTexture->bMasked; + return mSource->isMasked(); + } + + uint16_t GetRotations() const + { + return mTexture->GetRotations(); } int GetSkyOffset() const { return mTexture->GetSkyOffset(); } - PalEntry GetSkyCapColor(bool bottom) const { return mTexture->GetSkyCapColor(bottom); } + PalEntry GetSkyCapColor(bool bottom) const { return mSource->GetSkyCapColor(bottom); } int GetWidth () { return mTexture->GetTexelWidth(); } int GetHeight () { return mTexture->GetTexelHeight(); } int GetWidthBits() { return WidthBits; } int GetHeightBits() { return HeightBits; } - int GetScaledWidth () { return mTexture->GetScaledWidth(); } - int GetScaledHeight () { return mTexture->GetScaledHeight(); } - double GetScaledWidthDouble () { return mTexture->GetScaledWidthDouble(); } - double GetScaledHeightDouble () { return mTexture->GetScaledHeightDouble(); } + int GetScaledWidth () { return mTexture->GetDisplayWidth(); } + int GetScaledHeight () { return mTexture->GetDisplayHeight(); } // Now with improved offset adjustment. - int GetLeftOffset(int adjusted) { return mTexture->GetLeftOffset(adjusted); } - int GetTopOffset(int adjusted) { return mTexture->GetTopOffset(adjusted); } - int GetScaledLeftOffset (int adjusted) { return mTexture->GetScaledLeftOffset(adjusted); } - int GetScaledTopOffset (int adjusted) { return mTexture->GetScaledTopOffset(adjusted); } + int GetLeftOffset(int adjusted) { return mTexture->GetTexelLeftOffset(adjusted); } + int GetTopOffset(int adjusted) { return mTexture->GetTexelTopOffset(adjusted); } // Interfaces for the different renderers. Everything that needs to check renderer-dependent offsets // should use these, so that if changes are needed, this is the only place to edit. @@ -80,16 +82,10 @@ public: // For the original software renderer int GetLeftOffsetSW() { return GetLeftOffset(r_spriteadjustSW); } int GetTopOffsetSW() { return GetTopOffset(r_spriteadjustSW); } - int GetScaledLeftOffsetSW() { return GetScaledLeftOffset(r_spriteadjustSW); } - int GetScaledTopOffsetSW() { return GetScaledTopOffset(r_spriteadjustSW); } + double GetScaledLeftOffsetSW() { return mTexture->GetDisplayLeftOffset(r_spriteadjustSW); } + double GetScaledTopOffsetSW() { return mTexture->GetDisplayTopOffset(r_spriteadjustSW); } - // For the softpoly renderer, in case it wants adjustment - int GetLeftOffsetPo() { return GetLeftOffset(r_spriteadjustSW); } - int GetTopOffsetPo() { return GetTopOffset(r_spriteadjustSW); } - int GetScaledLeftOffsetPo() { return GetScaledLeftOffset(r_spriteadjustSW); } - int GetScaledTopOffsetPo() { return GetScaledTopOffset(r_spriteadjustSW); } - - DVector2 GetScale() const { return mTexture->Scale; } + DVector2 GetScale() const { return Scale; } int GetPhysicalWidth() { return mPhysicalWidth; } int GetPhysicalHeight() { return mPhysicalHeight; } int GetPhysicalScale() const { return mPhysicalScale; } @@ -157,7 +153,7 @@ class FWarpTexture : public FSoftwareTexture int WidthOffsetMultiplier, HeightOffsetMultiplier; // [mxd] public: - FWarpTexture (FTexture *source, int warptype); + FWarpTexture (FGameTexture *source, int warptype); const uint32_t *GetPixelsBgra() override; const uint8_t *GetPixels(int style) override; @@ -180,7 +176,7 @@ class FSWCanvasTexture : public FSoftwareTexture public: - FSWCanvasTexture(FTexture *source) : FSoftwareTexture(source) {} + FSWCanvasTexture(FGameTexture *source) : FSoftwareTexture(source) {} ~FSWCanvasTexture(); // Returns the whole texture, stored in column-major order @@ -195,3 +191,6 @@ public: bool Mipmapped() override { return false; } }; + +FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex); +FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat = nullptr, bool allownull = false); diff --git a/src/rendering/swrenderer/textures/swcanvastexture.cpp b/src/rendering/swrenderer/textures/swcanvastexture.cpp index c3d12e33ee..a9a946fce9 100644 --- a/src/rendering/swrenderer/textures/swcanvastexture.cpp +++ b/src/rendering/swrenderer/textures/swcanvastexture.cpp @@ -64,7 +64,7 @@ FSWCanvasTexture::~FSWCanvasTexture() const uint8_t *FSWCanvasTexture::GetPixels(int style) { - static_cast(mTexture)->NeedUpdate(); + static_cast(mSource)->NeedUpdate(); if (Canvas == nullptr) { MakeTexture(); @@ -81,7 +81,7 @@ const uint8_t *FSWCanvasTexture::GetPixels(int style) const uint32_t *FSWCanvasTexture::GetPixelsBgra() { - static_cast(mTexture)->NeedUpdate(); + static_cast(mSource)->NeedUpdate(); if (CanvasBgra == nullptr) { MakeTextureBgra(); @@ -181,5 +181,5 @@ void FSWCanvasTexture::UpdatePixels(bool truecolor) ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), Canvas->GetPixels(), GetWidth(), GetHeight(), Canvas->GetPitch(), GPalette.Remap); } - static_cast(mTexture)->SetUpdated(false); + static_cast(mSource)->SetUpdated(false); } \ No newline at end of file diff --git a/src/rendering/swrenderer/textures/warptexture.cpp b/src/rendering/swrenderer/textures/warptexture.cpp index 23a15529af..49869f8d6d 100644 --- a/src/rendering/swrenderer/textures/warptexture.cpp +++ b/src/rendering/swrenderer/textures/warptexture.cpp @@ -44,7 +44,7 @@ EXTERN_CVAR(Int, gl_texture_hqresizemult) EXTERN_CVAR(Int, gl_texture_hqresizemode) EXTERN_CVAR(Int, gl_texture_hqresize_targets) -FWarpTexture::FWarpTexture (FTexture *source, int warptype) +FWarpTexture::FWarpTexture (FGameTexture *source, int warptype) : FSoftwareTexture (source) { if (warptype == 2) SetupMultipliers(256, 128); @@ -69,7 +69,7 @@ const uint32_t *FWarpTexture::GetPixelsBgra() auto otherpix = FSoftwareTexture::GetPixelsBgra(); WarpedPixelsRgba.Resize(unsigned(GetWidth() * GetHeight() * resizeMult * resizeMult * 4 / 3 + 1)); - WarpBuffer(WarpedPixelsRgba.Data(), otherpix, int(GetWidth() * resizeMult), int(GetHeight() * resizeMult), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->shaderspeed, bWarped); + WarpBuffer(WarpedPixelsRgba.Data(), otherpix, int(GetWidth() * resizeMult), int(GetHeight() * resizeMult), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->GetShaderSpeed(), bWarped); GenerateBgraMipmapsFast(); FreeAllSpans(); GenTime[2] = time; @@ -90,7 +90,7 @@ const uint8_t *FWarpTexture::GetPixels(int index) const uint8_t *otherpix = FSoftwareTexture::GetPixels(index); WarpedPixels[index].Resize(unsigned(GetWidth() * GetHeight() * resizeMult * resizeMult)); - WarpBuffer(WarpedPixels[index].Data(), otherpix, int(GetWidth() * resizeMult), int(GetHeight() * resizeMult), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->shaderspeed, bWarped); + WarpBuffer(WarpedPixels[index].Data(), otherpix, int(GetWidth() * resizeMult), int(GetHeight() * resizeMult), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->GetShaderSpeed(), bWarped); FreeAllSpans(); GenTime[index] = time; } diff --git a/src/rendering/swrenderer/things/r_decal.cpp b/src/rendering/swrenderer/things/r_decal.cpp index 7ede9a5742..fcc3055f43 100644 --- a/src/rendering/swrenderer/things/r_decal.cpp +++ b/src/rendering/swrenderer/things/r_decal.cpp @@ -123,13 +123,11 @@ namespace swrenderer } } - FTexture *tex = TexMan.GetPalettedTexture(decal->PicNum, true); - - if (tex == NULL || !tex->isValid()) + FSoftwareTexture *WallSpriteTile = GetPalettedSWTexture(decal->PicNum, true); + if (WallSpriteTile == NULL) { return; } - FSoftwareTexture *WallSpriteTile = tex->GetSoftwareTexture(); // Determine left and right edges of sprite. Since this sprite is bound // to a wall, we use the wall's angle instead of the decal's. This is diff --git a/src/rendering/swrenderer/things/r_playersprite.cpp b/src/rendering/swrenderer/things/r_playersprite.cpp index d4459c8802..d59f0a64c7 100644 --- a/src/rendering/swrenderer/things/r_playersprite.cpp +++ b/src/rendering/swrenderer/things/r_playersprite.cpp @@ -208,7 +208,7 @@ namespace swrenderer spriteframe_t* sprframe; FTextureID picnum; uint16_t flip; - FTexture* tex; + FGameTexture* tex; bool noaccel; double alpha = owner->Alpha; @@ -228,7 +228,7 @@ namespace swrenderer picnum = sprframe->Texture[0]; flip = sprframe->Flip & 1; - tex = TexMan.GetTexture(picnum); + tex = TexMan.GetGameTexture(picnum); if (!tex->isValid()) return; @@ -267,7 +267,7 @@ namespace swrenderer double pspriteyscale = pspritexscale * viewport->BaseYaspectMul * ((double)SCREENHEIGHT / SCREENWIDTH) * r_viewwindow.WidescreenRatio; double pspritexiscale = 1 / pspritexscale; - int tleft = tex->GetDisplayLeftOffset(); + int tleft = tex->GetDisplayLeftOffset(0); int twidth = tex->GetDisplayWidth(); // calculate edges of the shape @@ -290,7 +290,7 @@ namespace swrenderer vis.renderflags = owner->renderflags; - FSoftwareTexture *stex = tex->GetSoftwareTexture(); + FSoftwareTexture* stex = GetSoftwareTexture(tex); vis.texturemid = (BASEYCENTER - sy) * stex->GetScale().Y + stex->GetTopOffset(0); // Force it to use software rendering when drawing to a canvas texture. diff --git a/src/rendering/swrenderer/things/r_sprite.cpp b/src/rendering/swrenderer/things/r_sprite.cpp index 348cc1bf42..c0ebeae756 100644 --- a/src/rendering/swrenderer/things/r_sprite.cpp +++ b/src/rendering/swrenderer/things/r_sprite.cpp @@ -74,10 +74,8 @@ EXTERN_CVAR(Int, gl_texture_hqresize_targets) namespace swrenderer { - void RenderSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FTexture *ttex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int lightlevel, bool foggy, FDynamicColormap *basecolormap) + void RenderSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FSoftwareTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int lightlevel, bool foggy, FDynamicColormap *basecolormap) { - FSoftwareTexture *tex = ttex->GetSoftwareTexture(); - auto viewport = thread->Viewport.get(); const double thingxscalemul = spriteScale.X / tex->GetScale().X; @@ -92,8 +90,8 @@ namespace swrenderer return; // [RH] Added scaling - int scaled_to = tex->GetScaledTopOffsetSW(); - int scaled_bo = scaled_to - tex->GetScaledHeight(); + double scaled_to = tex->GetScaledTopOffsetSW(); + double scaled_bo = scaled_to - tex->GetScaledHeight(); double gzt = pos.Z + spriteScale.Y * scaled_to; double gzb = pos.Z + spriteScale.Y * scaled_bo; diff --git a/src/rendering/swrenderer/things/r_sprite.h b/src/rendering/swrenderer/things/r_sprite.h index 0e7d97bcbc..d41504fc8d 100644 --- a/src/rendering/swrenderer/things/r_sprite.h +++ b/src/rendering/swrenderer/things/r_sprite.h @@ -7,7 +7,7 @@ namespace swrenderer class RenderSprite : public VisibleSprite { public: - static void Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int lightlevel, bool foggy, FDynamicColormap *basecolormap); + static void Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FSoftwareTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int lightlevel, bool foggy, FDynamicColormap *basecolormap); protected: void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override; diff --git a/src/rendering/swrenderer/things/r_wallsprite.cpp b/src/rendering/swrenderer/things/r_wallsprite.cpp index 4663f6f367..909c723953 100644 --- a/src/rendering/swrenderer/things/r_wallsprite.cpp +++ b/src/rendering/swrenderer/things/r_wallsprite.cpp @@ -69,9 +69,8 @@ namespace swrenderer { - void RenderWallSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FTexture *ppic, const DVector2 &scale, int renderflags, int lightlevel, bool foggy, FDynamicColormap *basecolormap) + void RenderWallSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FSoftwareTexture *pic, const DVector2 &scale, int renderflags, int lightlevel, bool foggy, FDynamicColormap *basecolormap) { - FSoftwareTexture *pic = ppic->GetSoftwareTexture(); FWallCoords wallc; double x1, x2; DVector2 left, right; diff --git a/src/rendering/swrenderer/things/r_wallsprite.h b/src/rendering/swrenderer/things/r_wallsprite.h index 2851ec2b56..b512ec960b 100644 --- a/src/rendering/swrenderer/things/r_wallsprite.h +++ b/src/rendering/swrenderer/things/r_wallsprite.h @@ -10,7 +10,7 @@ namespace swrenderer class RenderWallSprite : public VisibleSprite { public: - static void Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FTexture *pic, const DVector2 &scale, int renderflags, int lightlevel, bool foggy, FDynamicColormap *basecolormap); + static void Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FSoftwareTexture *pic, const DVector2 &scale, int renderflags, int lightlevel, bool foggy, FDynamicColormap *basecolormap); protected: bool IsWallSprite() const override { return true; } From 5d8adb90c472e2e2d8f2585fdc649cdbe720383b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 00:43:27 +0200 Subject: [PATCH 009/220] - made 'supportRemap0' an image property so that later the handling for this can be taken out of the actual texture class by just providing a replacement texture for the skies. --- .../textures/formats/multipatchtexture.cpp | 26 +++++++++++++++---- .../textures/formats/multipatchtexture.h | 1 + src/common/textures/formats/patchtexture.cpp | 1 + src/common/textures/image.h | 1 + 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/common/textures/formats/multipatchtexture.cpp b/src/common/textures/formats/multipatchtexture.cpp index 86c9f8d77a..dfd63ea387 100644 --- a/src/common/textures/formats/multipatchtexture.cpp +++ b/src/common/textures/formats/multipatchtexture.cpp @@ -67,6 +67,27 @@ FMultiPatchTexture::FMultiPatchTexture(int w, int h, const TArray &part } } +//========================================================================== +// +// sky remapping will only happen if +// - the texture was defined through a TEXTUREx lump (this implies only trivial copies) +// - all patches use the base palette. +// - all patches are in a format that allows the remap. +// All other cases would not be able to properly deal with this special case. +// For textual definitions this hack isn't necessary. +// +//========================================================================== + +bool FMultiPatchTexture::SupportRemap0() +{ + if (bTextual || UseGamePalette()) return false; + for (int i = 0; i < NumParts; i++) + { + if (!Parts[i].Image->SupportRemap0()) return false; + } + return true; +} + //========================================================================== // // GetBlendMap @@ -203,11 +224,6 @@ TArray FMultiPatchTexture::CreatePalettedPixels(int conversion) } if (conversion == noremap0) { - // sky remapping will only happen if - // - the texture was defined through a TEXTUREx lump (this implies only trivial copies) - // - all patches use the base palette. - // All other cases would not be able to properly deal with this special case. - // For textual definitions this hack isn't necessary. if (bTextual || !UseGamePalette()) conversion = normal; } diff --git a/src/common/textures/formats/multipatchtexture.h b/src/common/textures/formats/multipatchtexture.h index 190cd49b75..3b8c6db752 100644 --- a/src/common/textures/formats/multipatchtexture.h +++ b/src/common/textures/formats/multipatchtexture.h @@ -40,6 +40,7 @@ class FMultiPatchTexture : public FImageSource friend class FTexture; public: FMultiPatchTexture(int w, int h, const TArray &parts, bool complex, bool textual); + bool SupportRemap0() override; protected: int NumParts; diff --git a/src/common/textures/formats/patchtexture.cpp b/src/common/textures/formats/patchtexture.cpp index 960994b5c2..0a93adf50a 100644 --- a/src/common/textures/formats/patchtexture.cpp +++ b/src/common/textures/formats/patchtexture.cpp @@ -63,6 +63,7 @@ public: FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex); TArray CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; + bool SupportRemap0() override { return !badflag; } void DetectBadPatches(); }; diff --git a/src/common/textures/image.h b/src/common/textures/image.h index 1f6fcb5fa6..a72c82eb31 100644 --- a/src/common/textures/image.h +++ b/src/common/textures/image.h @@ -57,6 +57,7 @@ protected: public: + virtual bool SupportRemap0() { return false; } // Unfortunate hackery that's needed for Hexen's skies. void CopySize(FImageSource &other) { From c7db5b932ef40e207ea3f60653f17a07317d2694 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 00:55:16 +0200 Subject: [PATCH 010/220] - switched the entire status bar code to use FGameTexture. - scale the automap parchment to clean 320x200 dimensions. --- src/am_map.cpp | 10 +-- src/common/2d/v_2ddrawer.h | 5 ++ src/common/textures/texture.cpp | 6 ++ src/common/textures/texturemanager.h | 13 +++- src/common/textures/textures.h | 14 ++-- src/console/c_console.cpp | 2 +- src/g_level.cpp | 10 +-- src/g_statusbar/sbar.h | 11 +-- src/g_statusbar/sbar_mugshot.cpp | 8 +-- src/g_statusbar/sbarinfo.cpp | 40 +++++------ src/g_statusbar/sbarinfo_commands.cpp | 68 ++++++++++--------- src/g_statusbar/shared_sbar.cpp | 29 ++++---- .../swrenderer/textures/r_swtexture.h | 6 +- .../swrenderer/things/r_wallsprite.cpp | 4 +- src/utility/v_collection.cpp | 4 +- src/utility/v_collection.h | 4 +- 16 files changed, 129 insertions(+), 105 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index fd195ea700..40de0a01dd 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -1239,8 +1239,8 @@ void DAutomap::ScrollParchment (double dmapx, double dmapy) if (backtex != nullptr) { - int pwidth = backtex->GetDisplayWidth(); - int pheight = backtex->GetDisplayHeight(); + int pwidth = int(backtex->GetDisplayWidth() * CleanXfac); + int pheight = int(backtex->GetDisplayHeight() * CleanYfac); while(mapxstart > 0) mapxstart -= pwidth; @@ -1591,8 +1591,8 @@ void DAutomap::clearFB (const AMColor &color) auto backtex = TexMan.GetGameTexture(mapback); if (backtex != nullptr) { - int pwidth = backtex->GetDisplayWidth(); - int pheight = backtex->GetDisplayHeight(); + int pwidth = int(backtex->GetDisplayWidth() * CleanXfac); + int pheight = int(backtex->GetDisplayHeight() * CleanYfac); int x, y; //blit the automap background to the screen. @@ -1600,7 +1600,7 @@ void DAutomap::clearFB (const AMColor &color) { for (x = int(mapxstart); x < f_w; x += pwidth) { - DrawTexture(twod, backtex, x, y, DTA_ClipBottom, f_h, DTA_TopOffset, 0, DTA_LeftOffset, 0, TAG_DONE); + DrawTexture(twod, backtex, x, y, DTA_ClipBottom, f_h, DTA_TopOffset, 0, DTA_LeftOffset, 0, DTA_DestWidth, pwidth, DTA_DestHeight, pheight, TAG_DONE); } } } diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index 7c759b1954..6442b3526f 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -183,6 +183,11 @@ public: void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex, int clipx1, int clipy1, int clipx2, int clipy2); void AddFlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin = false); + void AddFlatFill(int left, int top, int right, int bottom, FGameTexture* src, bool local_origin = false) + { + AddFlatFill(left, top, right, bottom, src->GetTexture(), local_origin); + } + void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style = nullptr); void ClearScreen(PalEntry color = 0xff000000); diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 05ae74221f..74cd685306 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -868,3 +868,9 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) SystemTextures.AddHardwareTexture(0, false, hwtex); } + +bool FGameTexture::isUserContent() const +{ + int filenum = fileSystem.GetFileContainer(wrapped.GetSourceLump()); + return (filenum > fileSystem.GetMaxIwadNum()); +} diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index b5a7aa4e75..70717bb880 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -39,7 +39,12 @@ public: FTextureID texnum = GetTextureID (name, ETextureType::MiscPatch); return InternalGetTexture(texnum.GetIndex(), animate, true, false); } - + + FGameTexture* GetGameTextureByName(const char *name, bool animate = false) + { + return reinterpret_cast(GetTextureByName(name, animate)); + } + FTexture *GetTexture(FTextureID texnum, bool animate = false) { return InternalGetTexture(texnum.GetIndex(), animate, true, false); @@ -67,6 +72,12 @@ public: } FTexture *FindTexture(const char *texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny); + + FGameTexture* FindGameTexture(const char* texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny) + { + return reinterpret_cast(FindTexture(texname, usetype, flags)); + } + bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum); void FlushAll(); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 839607cd30..6d32360d09 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -579,14 +579,14 @@ class FGameTexture public: FTexture* GetTexture() { return &wrapped; } - int GetDisplayWidth() /*const*/ { return wrapped.GetDisplayWidth(); } - int GetDisplayHeight() /*const*/ { return wrapped.GetDisplayHeight(); } + double GetDisplayWidth() /*const*/ { return wrapped.GetDisplayWidthDouble(); } + double GetDisplayHeight() /*const*/ { return wrapped.GetDisplayHeightDouble(); } int GetTexelWidth() /*const*/ { return wrapped.GetTexelWidth(); } int GetTexelHeight() /*const*/ { return wrapped.GetTexelHeight(); } - int GetTexelLeftOffset(int adjusted) /*const*/ { return wrapped.GetTexelLeftOffset(adjusted); } - int GetTexelTopOffset(int adjusted) /*const*/ { return wrapped.GetTexelTopOffset(adjusted); } - double GetDisplayLeftOffset(int adjusted) /*const*/ { return wrapped.GetDisplayLeftOffsetDouble(adjusted); } - double GetDisplayTopOffset(int adjusted) /*const*/ { return wrapped.GetDisplayTopOffsetDouble(adjusted); } + int GetTexelLeftOffset(int adjusted = 0) /*const*/ { return wrapped.GetTexelLeftOffset(adjusted); } + int GetTexelTopOffset(int adjusted = 0) /*const*/ { return wrapped.GetTexelTopOffset(adjusted); } + double GetDisplayLeftOffset(int adjusted = 0) /*const*/ { return wrapped.GetDisplayLeftOffsetDouble(adjusted); } + double GetDisplayTopOffset(int adjusted = 0) /*const*/ { return wrapped.GetDisplayTopOffsetDouble(adjusted); } bool isValid() { return wrapped.isValid(); } bool isWarped() { return wrapped.isWarped(); } @@ -598,6 +598,8 @@ public: ISoftwareTexture* GetSoftwareTexture() { return wrapped.GetSoftwareTexture(); } void SetSoftwareTexture(ISoftwareTexture* swtex) { wrapped.SetSoftwareTextue(swtex); } + bool isUserContent() const; + }; diff --git a/src/console/c_console.cpp b/src/console/c_console.cpp index 182e8886d5..1204b2c7a2 100644 --- a/src/console/c_console.cpp +++ b/src/console/c_console.cpp @@ -1170,7 +1170,7 @@ void C_DrawConsole () else if (ConBottom) { int visheight; - FTexture *conpic = TexMan.GetTexture(conback); + FGameTexture *conpic = TexMan.GetGameTexture(conback); visheight = ConBottom; diff --git a/src/g_level.cpp b/src/g_level.cpp index bd3d86855b..ac0d2bad9b 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -894,14 +894,10 @@ bool FLevelLocals::DoCompleted (FString nextlevel, wbstartstruct_t &wminfo) { if (texids[i]->isValid() && langtable[i] != FStringTable::default_table) { - FTexture *tex = TexMan.GetTexture(*texids[i]); - if (tex != nullptr) + FGameTexture *tex = TexMan.GetGameTexture(*texids[i]); + if (tex != nullptr && !tex->isUserContent()) { - int filenum = fileSystem.GetFileContainer(tex->GetSourceLump()); - if (filenum >= 0 && filenum <= fileSystem.GetMaxIwadNum()) - { - texids[i]->SetInvalid(); - } + texids[i]->SetInvalid(); } } } diff --git a/src/g_statusbar/sbar.h b/src/g_statusbar/sbar.h index ee96bdd112..8a1ad1bc7e 100644 --- a/src/g_statusbar/sbar.h +++ b/src/g_statusbar/sbar.h @@ -42,6 +42,7 @@ class player_t; struct FRemapTable; +class FGameTexture; enum EHudState { @@ -233,7 +234,7 @@ struct FMugShotFrame FMugShotFrame(); ~FMugShotFrame(); - FTexture *GetTexture(const char *default_face, const char *skin_face, int random, int level=0, + FGameTexture *GetTexture(const char *default_face, const char *skin_face, int random, int level=0, int direction=0, bool usesLevels=false, bool health2=false, bool healthspecial=false, bool directional=false); }; @@ -256,7 +257,7 @@ struct FMugShotState void Tick(); void Reset(); FMugShotFrame &GetCurrentFrame() { return Frames[Position]; } - FTexture *GetCurrentFrameTexture(const char *default_face, const char *skin_face, int level=0, int direction=0) + FGameTexture *GetCurrentFrameTexture(const char *default_face, const char *skin_face, int level=0, int direction=0) { return GetCurrentFrame().GetTexture(default_face, skin_face, Random, level, direction, bUsesLevels, bHealth2, bHealthSpecial, bDirectional); } @@ -287,7 +288,7 @@ class FMugShot void Tick(player_t *player); bool SetState(const char *state_name, bool wait_till_done=false, bool reset=false); int UpdateState(player_t *player, StateFlags stateflags=STANDARD); - FTexture *GetFace(player_t *player, const char *default_face, int accuracy, StateFlags stateflags=STANDARD); + FGameTexture *GetFace(player_t *player, const char *default_face, int accuracy, StateFlags stateflags=STANDARD); private: FMugShotState *CurrentState; @@ -308,7 +309,7 @@ int FindMugShotStateIndex(FName state); // Base Status Bar ---------------------------------------------------------- -class FTexture; +class FGameTexture; enum { @@ -525,7 +526,7 @@ DBaseStatusBar *CreateCustomStatusBar(int script=0); void ST_LoadCrosshair(bool alwaysload=false); void ST_Clear(); void ST_CreateStatusBar(bool bTitleLevel); -extern FTexture *CrosshairImage; +extern FGameTexture *CrosshairImage; int GetInventoryIcon(AActor *item, uint32_t flags, int *applyscale = nullptr); diff --git a/src/g_statusbar/sbar_mugshot.cpp b/src/g_statusbar/sbar_mugshot.cpp index 09e483ef8b..2fe24fae2a 100644 --- a/src/g_statusbar/sbar_mugshot.cpp +++ b/src/g_statusbar/sbar_mugshot.cpp @@ -71,11 +71,11 @@ FMugShotFrame::~FMugShotFrame() // // FMugShotFrame :: GetTexture // -// Assemble a graphic name with the specified prefix and return the FTexture. +// Assemble a graphic name with the specified prefix and return the FGameTexture. // //=========================================================================== -FTexture *FMugShotFrame::GetTexture(const char *default_face, const char *skin_face, int random, int level, +FGameTexture *FMugShotFrame::GetTexture(const char *default_face, const char *skin_face, int random, int level, int direction, bool uses_levels, bool health2, bool healthspecial, bool directional) { int index = !directional ? random % Graphic.Size() : direction; @@ -97,7 +97,7 @@ FTexture *FMugShotFrame::GetTexture(const char *default_face, const char *skin_f } sprite.UnlockBuffer(); } - return TexMan.GetTexture(TexMan.CheckForTexture(sprite, ETextureType::Any, FTextureManager::TEXMAN_TryAny|FTextureManager::TEXMAN_AllowSkins)); + return TexMan.GetGameTexture(TexMan.CheckForTexture(sprite, ETextureType::Any, FTextureManager::TEXMAN_TryAny|FTextureManager::TEXMAN_AllowSkins)); } //=========================================================================== @@ -459,7 +459,7 @@ int FMugShot::UpdateState(player_t *player, StateFlags stateflags) // //=========================================================================== -FTexture *FMugShot::GetFace(player_t *player, const char *default_face, int accuracy, StateFlags stateflags) +FGameTexture *FMugShot::GetFace(player_t *player, const char *default_face, int accuracy, StateFlags stateflags) { int angle = UpdateState(player, stateflags); int level = 0; diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index 98ca01b450..1c380184aa 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1191,7 +1191,7 @@ public: } //draws an image with the specified flags - void DrawGraphic(FTexture* texture, SBarInfoCoordinate x, SBarInfoCoordinate y, int xOffset, int yOffset, double Alpha, bool fullScreenOffsets, bool translate=false, bool dim=false, int offsetflags=0, bool alphaMap=false, int forceWidth=-1, int forceHeight=-1, const double *clip = nulclip, bool clearDontDraw=false) const + void DrawGraphic(FGameTexture* texture, SBarInfoCoordinate x, SBarInfoCoordinate y, int xOffset, int yOffset, double Alpha, bool fullScreenOffsets, bool translate=false, bool dim=false, int offsetflags=0, bool alphaMap=false, int forceWidth=-1, int forceHeight=-1, const double *clip = nulclip, bool clearDontDraw=false) const { if (texture == NULL) return; @@ -1201,11 +1201,11 @@ public: if((offsetflags & SBarInfoCommand::CENTER) == SBarInfoCommand::CENTER) { - if (forceWidth < 0) dx -= (texture->GetDisplayWidthDouble()/2.0)-texture->GetDisplayLeftOffsetDouble(); - else dx -= forceWidth*(0.5-(texture->GetDisplayLeftOffsetDouble()/texture->GetDisplayWidthDouble())); + if (forceWidth < 0) dx -= (texture->GetDisplayWidth()/2.0)-texture->GetDisplayLeftOffset(); + else dx -= forceWidth*(0.5-(texture->GetDisplayLeftOffset()/texture->GetDisplayWidth())); - if (forceHeight < 0) dy -= (texture->GetDisplayHeightDouble()/2.0)-texture->GetDisplayTopOffsetDouble(); - else dy -= forceHeight*(0.5-(texture->GetDisplayTopOffsetDouble()/texture->GetDisplayHeightDouble())); + if (forceHeight < 0) dy -= (texture->GetDisplayHeight()/2.0)-texture->GetDisplayTopOffset(); + else dy -= forceHeight*(0.5-(texture->GetDisplayTopOffset()/texture->GetDisplayHeight())); } dx += xOffset; @@ -1214,12 +1214,12 @@ public: if(!fullScreenOffsets) { double tmp = 0; - w = forceWidth < 0 ? texture->GetDisplayWidthDouble() : forceWidth; - h = forceHeight < 0 ? texture->GetDisplayHeightDouble() : forceHeight; - double dcx = clip[0] == 0 ? 0 : dx + clip[0] - texture->GetDisplayLeftOffsetDouble(); - double dcy = clip[1] == 0 ? 0 : dy + clip[1] - texture->GetDisplayTopOffsetDouble(); - double dcr = clip[2] == 0 ? INT_MAX : dx + w - clip[2] - texture->GetDisplayLeftOffsetDouble(); - double dcb = clip[3] == 0 ? INT_MAX : dy + h - clip[3] - texture->GetDisplayTopOffsetDouble(); + w = forceWidth < 0 ? texture->GetDisplayWidth() : forceWidth; + h = forceHeight < 0 ? texture->GetDisplayHeight() : forceHeight; + double dcx = clip[0] == 0 ? 0 : dx + clip[0] - texture->GetDisplayLeftOffset(); + double dcy = clip[1] == 0 ? 0 : dy + clip[1] - texture->GetDisplayTopOffset(); + double dcr = clip[2] == 0 ? INT_MAX : dx + w - clip[2] - texture->GetDisplayLeftOffset(); + double dcb = clip[3] == 0 ? INT_MAX : dy + h - clip[3] - texture->GetDisplayTopOffset(); if(clip[0] != 0 || clip[1] != 0) { @@ -1283,8 +1283,8 @@ public: bool xright = *x < 0 && !x.RelCenter(); bool ybot = *y < 0 && !y.RelCenter(); - w = (forceWidth < 0 ? texture->GetDisplayWidthDouble() : forceWidth); - h = (forceHeight < 0 ? texture->GetDisplayHeightDouble() : forceHeight); + w = (forceWidth < 0 ? texture->GetDisplayWidth() : forceWidth); + h = (forceHeight < 0 ? texture->GetDisplayHeight() : forceHeight); if(vid_fps && rx < 0 && ry >= 0) ry += 10; @@ -1301,10 +1301,10 @@ public: // Check for clipping if(clip[0] != 0 || clip[1] != 0 || clip[2] != 0 || clip[3] != 0) { - rcx = clip[0] == 0 ? 0 : rx+((clip[0] - texture->GetDisplayLeftOffsetDouble())*Scale.X); - rcy = clip[1] == 0 ? 0 : ry+((clip[1] - texture->GetDisplayTopOffsetDouble())*Scale.Y); - rcr = clip[2] == 0 ? INT_MAX : rx+w-((clip[2] + texture->GetDisplayLeftOffsetDouble())*Scale.X); - rcb = clip[3] == 0 ? INT_MAX : ry+h-((clip[3] + texture->GetDisplayTopOffsetDouble())*Scale.Y); + rcx = clip[0] == 0 ? 0 : rx+((clip[0] - texture->GetDisplayLeftOffset())*Scale.X); + rcy = clip[1] == 0 ? 0 : ry+((clip[1] - texture->GetDisplayTopOffset())*Scale.Y); + rcr = clip[2] == 0 ? INT_MAX : rx+w-((clip[2] + texture->GetDisplayLeftOffset())*Scale.X); + rcb = clip[3] == 0 ? INT_MAX : ry+h-((clip[3] + texture->GetDisplayTopOffset())*Scale.Y); } if(clearDontDraw) @@ -1393,7 +1393,7 @@ public: else width = font->GetCharWidth((unsigned char) script->spacingCharacter); bool redirected = false; - FTexture* c = font->GetChar(ch, fontcolor, &width); + auto c = font->GetChar(ch, fontcolor, &width); if(c == NULL) //missing character. { continue; @@ -1405,8 +1405,8 @@ public: double rx, ry, rw, rh; rx = ax + xOffset; ry = ay + yOffset; - rw = c->GetDisplayWidthDouble(); - rh = c->GetDisplayHeightDouble(); + rw = c->GetDisplayWidth(); + rh = c->GetDisplayHeight(); if(script->spacingCharacter != '\0') { diff --git a/src/g_statusbar/sbarinfo_commands.cpp b/src/g_statusbar/sbarinfo_commands.cpp index a2286734a9..287b395135 100644 --- a/src/g_statusbar/sbarinfo_commands.cpp +++ b/src/g_statusbar/sbarinfo_commands.cpp @@ -69,8 +69,8 @@ class CommandDrawImage : public SBarInfoCommandFlowControl { double scale1, scale2; scale1 = scale2 = 1.0f; - double texwidth = (int) (texture->GetDisplayWidthDouble()*spawnScaleX); - double texheight = (int) (texture->GetDisplayHeightDouble()*spawnScaleY); + double texwidth = (int) (texture->GetDisplayWidth()*spawnScaleX); + double texheight = (int) (texture->GetDisplayHeight()*spawnScaleY); if (w != -1 && (wGetDisplayWidthDouble()*spawnScaleX); - h=(int) (texture->GetDisplayHeightDouble()*spawnScaleY); + w=(int) (texture->GetDisplayWidth()*spawnScaleX); + h=(int) (texture->GetDisplayHeight()*spawnScaleY); } statusBar->DrawGraphic(texture, imgx, imgy, block->XOffset(), block->YOffset(), frameAlpha, block->FullScreenOffsets(), translatable, false, offset, false, w, h); @@ -241,7 +241,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl applyscale = false; } if(type == PLAYERICON) - texture = TexMan.ByIndex(statusBar->CPlayer->mo->IntVar(NAME_ScoreIcon), true); + texture = TexMan.GameByIndex(statusBar->CPlayer->mo->IntVar(NAME_ScoreIcon), true); else if(type == AMMO1) { auto ammo = statusBar->ammo1; @@ -270,7 +270,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl { auto item = statusBar->CPlayer->mo->FindInventory(NAME_Sigil); if (item != NULL) - texture = TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true); + texture = TexMan.GetGameTexture(item->TextureIDVar(NAME_Icon), true); } else if(type == HEXENARMOR_ARMOR || type == HEXENARMOR_SHIELD || type == HEXENARMOR_HELM || type == HEXENARMOR_AMULET) { @@ -292,9 +292,9 @@ class CommandDrawImage : public SBarInfoCommandFlowControl } } else if(type == INVENTORYICON) - texture = TexMan.GetTexture(sprite, true); + texture = TexMan.GetGameTexture(sprite, true); else if(type == SELECTEDINVENTORYICON && statusBar->CPlayer->mo->PointerVar(NAME_InvSel) != NULL) - texture = TexMan.GetTexture(statusBar->CPlayer->mo->PointerVar(NAME_InvSel)->TextureIDVar(NAME_Icon), true); + texture = TexMan.GetGameTexture(statusBar->CPlayer->mo->PointerVar(NAME_InvSel)->TextureIDVar(NAME_Icon), true); else if(image >= 0) texture = statusBar->Images[image]; @@ -316,7 +316,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl spawnScaleY = item->Scale.Y; } - texture = TexMan.GetTexture(icon, true); + texture = TexMan.GetGameTexture(icon, true); } enum ImageType @@ -353,7 +353,7 @@ class CommandDrawImage : public SBarInfoCommandFlowControl SBarInfoCoordinate imgy; Offset offset; - FTexture *texture; + FGameTexture *texture; double alpha; }; @@ -1618,7 +1618,7 @@ class CommandDrawMugShot : public SBarInfoCommand void Draw(const SBarInfoMainBlock *block, const DSBarInfo *statusBar) { - FTexture *face = statusBar->wrapper->mugshot.GetFace(statusBar->CPlayer, defaultFace, accuracy, stateFlags); + FGameTexture *face = statusBar->wrapper->mugshot.GetFace(statusBar->CPlayer, defaultFace, accuracy, stateFlags); if (face != NULL) statusBar->DrawGraphic(face, x, y, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); } @@ -2045,10 +2045,10 @@ class CommandDrawShader : public SBarInfoCommand } GetCoordinates(sc, fullScreenOffsets, x, y); sc.MustGetToken(';'); - shaders[0] = TexMan.FindTexture("BarShaderHF"); - shaders[1] = TexMan.FindTexture("BarShaderHR"); - shaders[2] = TexMan.FindTexture("BarShaderVF"); - shaders[3] = TexMan.FindTexture("BarShaderVR"); + shaders[0] = TexMan.FindGameTexture("BarShaderHF"); + shaders[1] = TexMan.FindGameTexture("BarShaderHR"); + shaders[2] = TexMan.FindGameTexture("BarShaderVF"); + shaders[3] = TexMan.FindGameTexture("BarShaderVR"); } protected: bool vertical; @@ -2059,7 +2059,7 @@ class CommandDrawShader : public SBarInfoCommand SBarInfoCoordinate y; private: - FTexture *shaders[4]; + FGameTexture *shaders[4]; }; //////////////////////////////////////////////////////////////////////////////// @@ -2132,7 +2132,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand statusBar->DrawGraphic(statusBar->Images[statusBar->invBarOffset + imgARTIBOX], rx, ry, block->XOffset(), block->YOffset(), bgalpha, block->FullScreenOffsets()); if(style != STYLE_Strife) //Strife draws the cursor before the icons - statusBar->DrawGraphic(TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true), rx - (style == STYLE_HexenStrict ? 2 : 0), ry - (style == STYLE_HexenStrict ? 1 : 0), block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0); + statusBar->DrawGraphic(TexMan.GetGameTexture(item->TextureIDVar(NAME_Icon), true), rx - (style == STYLE_HexenStrict ? 2 : 0), ry - (style == STYLE_HexenStrict ? 1 : 0), block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0); if(item == statusBar->CPlayer->mo->PointerVar(NAME_InvSel)) { if(style == STYLE_Heretic) @@ -2147,7 +2147,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand statusBar->DrawGraphic(statusBar->Images[statusBar->invBarOffset + imgSELECTBOX], rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); } if(style == STYLE_Strife) - statusBar->DrawGraphic(TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true), rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0); + statusBar->DrawGraphic(TexMan.GetGameTexture(item->TextureIDVar(NAME_Icon), true), rx, ry, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets(), false, item->IntVar(NAME_Amount) <= 0); if(counters != NULL && (alwaysShowCounter || item->IntVar(NAME_Amount) != 1)) { counters[i]->valueArgument = item->IntVar(NAME_Amount); @@ -2255,7 +2255,7 @@ class CommandDrawInventoryBar : public SBarInfoCommand } int GetCounterSpacing(const DSBarInfo *statusBar) const { - FTexture *box = (style != STYLE_Strife) + FGameTexture *box = (style != STYLE_Strife) ? statusBar->Images[statusBar->invBarOffset + imgARTIBOX] : statusBar->Images[statusBar->invBarOffset + imgCURSOR]; if (box == NULL) @@ -2265,13 +2265,14 @@ class CommandDrawInventoryBar : public SBarInfoCommand else { int spacing; + // Intentionally rounded down. if (!vertical) { - spacing = box->GetDisplayWidth(); + spacing = (int)box->GetDisplayWidth(); } else { - spacing = box->GetDisplayHeight(); + spacing = (int)box->GetDisplayHeight(); } return spacing + ((style != STYLE_Strife) ? 1 : -1); } @@ -2368,24 +2369,25 @@ class CommandDrawKeyBar : public SBarInfoCommand } if(i >= keyOffset) //Should we start drawing? { + auto tex = TexMan.GetGameTexture(item->TextureIDVar(NAME_Icon), true); if(!vertical) { - statusBar->DrawGraphic(TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true), x+slotOffset, y+rowOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); - rowWidth = rowIconSize == -1 ? TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true)->GetDisplayHeight()+2 : rowIconSize; + statusBar->DrawGraphic(tex, x+slotOffset, y+rowOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); + rowWidth = rowIconSize == -1 ? (int)tex->GetDisplayHeight()+2 : rowIconSize; } else { - statusBar->DrawGraphic(TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true), x+rowOffset, y+slotOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); - rowWidth = rowIconSize == -1 ? TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true)->GetDisplayWidth()+2 : rowIconSize; + statusBar->DrawGraphic(tex, x+rowOffset, y+slotOffset, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); + rowWidth = rowIconSize == -1 ? (int)tex->GetDisplayWidth()+2 : rowIconSize; } // If cmd.special is -1 then the slot size is auto detected if(iconSize == -1) { if(!vertical) - slotOffset += (reverse ? -1 : 1) * (TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true)->GetDisplayWidth() + 2); + slotOffset += (reverse ? -1 : 1) * ((int)tex->GetDisplayWidth() + 2); else - slotOffset += (reverse ? -1 : 1) * (TexMan.GetTexture(item->TextureIDVar(NAME_Icon), true)->GetDisplayHeight() + 2); + slotOffset += (reverse ? -1 : 1) * ((int)tex->GetDisplayHeight() + 2); } else slotOffset += (reverse ? -iconSize : iconSize); @@ -2491,8 +2493,8 @@ class CommandDrawBar : public SBarInfoCommand return; //don't draw anything. assert(statusBar->Images[foreground] != NULL); - FTexture *fg = statusBar->Images[foreground]; - FTexture *bg = (background != -1) ? statusBar->Images[background] : NULL; + FGameTexture *fg = statusBar->Images[foreground]; + FGameTexture *bg = (background != -1) ? statusBar->Images[background] : NULL; double value = drawValue; if(border != 0) @@ -2514,7 +2516,7 @@ class CommandDrawBar : public SBarInfoCommand // {cx, cy, cr, cb} double Clip[4] = {0, 0, 0, 0}; - int sizeOfImage = (horizontal ? fg->GetDisplayWidth()-border*2 : fg->GetDisplayHeight()-border*2); + double sizeOfImage = (horizontal ? fg->GetDisplayWidth()-border*2 : fg->GetDisplayHeight()-border*2); Clip[(!horizontal)|((horizontal ? !reverse : reverse)<<1)] = sizeOfImage - sizeOfImage *value; // Draw background if(border != 0) @@ -3108,15 +3110,15 @@ class CommandDrawGem : public SBarInfoCommand void Draw(const SBarInfoMainBlock *block, const DSBarInfo *statusBar) { - FTexture *chainImg = statusBar->Images[chain]; - FTexture *gemImg = statusBar->Images[gem]; + FGameTexture *chainImg = statusBar->Images[chain]; + FGameTexture *gemImg = statusBar->Images[gem]; if(chainImg == NULL) return; SBarInfoCoordinate drawY = y; if(wiggle && drawValue != goalValue) // Should only wiggle when the value doesn't equal what is being drawn. drawY += chainWiggle; - int chainWidth = chainImg->GetDisplayWidth(); + double chainWidth = chainImg->GetDisplayWidth(); int offset = (int) (((double) (chainWidth-leftPadding-rightPadding)/100)*drawValue); statusBar->DrawGraphic(chainImg, x+(offset%chainSize), drawY, block->XOffset(), block->YOffset(), block->Alpha(), block->FullScreenOffsets()); if(gemImg != NULL) diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index e9282b72aa..be653faba0 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -95,7 +95,7 @@ DBaseStatusBar *StatusBar; extern int setblocks; -FTexture *CrosshairImage; +FGameTexture *CrosshairImage; static int CrosshairNum; CVAR (Int, paletteflash, 0, CVAR_ARCHIVE) @@ -192,7 +192,7 @@ void ST_LoadCrosshair(bool alwaysload) } } CrosshairNum = num; - CrosshairImage = TexMan.GetTexture(texid); + CrosshairImage = TexMan.GetGameTexture(texid); } //--------------------------------------------------------------------------- @@ -1015,11 +1015,12 @@ void DBaseStatusBar::RefreshBackground () const if (setblocks >= 10) { - FTexture *p = TexMan.GetTextureByName(gameinfo.Border.b); + FGameTexture *p = TexMan.GetGameTextureByName(gameinfo.Border.b); if (p != NULL) { - twod->AddFlatFill(0, y, x, y + p->GetDisplayHeight(), p, true); - twod->AddFlatFill(x2, y, twod->GetWidth(), y + p->GetDisplayHeight(), p, true); + int h = int(0.5 + p->GetDisplayHeight()); + twod->AddFlatFill(0, y, x, y + h, p, true); + twod->AddFlatFill(x2, y, twod->GetWidth(), y + h, p, true); } } } @@ -1546,10 +1547,10 @@ void DBaseStatusBar::DrawGraphic(FTextureID texture, double x, double y, int fla if (!texture.isValid()) return; - FTexture *tex = TexMan.GetTexture(texture, !(flags & DI_DONTANIMATE)); + FGameTexture *tex = TexMan.GetGameTexture(texture, !(flags & DI_DONTANIMATE)); - double texwidth = tex->GetDisplayWidthDouble() * scaleX; - double texheight = tex->GetDisplayHeightDouble() * scaleY; + double texwidth = tex->GetDisplayWidth() * scaleX; + double texheight = tex->GetDisplayHeight() * scaleY; if (boxwidth > 0 || boxheight > 0) { @@ -1601,14 +1602,14 @@ void DBaseStatusBar::DrawGraphic(FTextureID texture, double x, double y, int fla { case DI_ITEM_HCENTER: x -= boxwidth / 2; break; case DI_ITEM_RIGHT: x -= boxwidth; break; - case DI_ITEM_HOFFSET: x -= tex->GetDisplayLeftOffsetDouble() * boxwidth / texwidth; break; + case DI_ITEM_HOFFSET: x -= tex->GetDisplayLeftOffset() * boxwidth / texwidth; break; } switch (flags & DI_ITEM_VMASK) { case DI_ITEM_VCENTER: y -= boxheight / 2; break; case DI_ITEM_BOTTOM: y -= boxheight; break; - case DI_ITEM_VOFFSET: y -= tex->GetDisplayTopOffsetDouble() * boxheight / texheight; break; + case DI_ITEM_VOFFSET: y -= tex->GetDisplayTopOffset() * boxheight / texheight; break; } if (!fullscreenOffsets) @@ -1737,20 +1738,20 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d } int width; - FTexture* c = font->GetChar(ch, fontcolor, &width); + auto c = font->GetChar(ch, fontcolor, &width); if (c == NULL) //missing character. { continue; } if (!monospaced) //If we are monospaced lets use the offset - x += (c->GetDisplayLeftOffsetDouble() + 1); //ignore x offsets since we adapt to character size + x += (c->GetDisplayLeftOffset() + 1); //ignore x offsets since we adapt to character size double rx, ry, rw, rh; rx = x + drawOffset.X; ry = y + drawOffset.Y; - rw = c->GetDisplayWidthDouble(); - rh = c->GetDisplayHeightDouble(); + rw = c->GetDisplayWidth(); + rh = c->GetDisplayHeight(); if (monospacing == EMonospacing::CellCenter) rx += (spacing - rw) / 2; diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index a6b89c8c99..7ea9ba34fd 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -69,9 +69,9 @@ public: int GetWidthBits() { return WidthBits; } int GetHeightBits() { return HeightBits; } - int GetScaledWidth () { return mTexture->GetDisplayWidth(); } - int GetScaledHeight () { return mTexture->GetDisplayHeight(); } - + double GetScaledWidth () { return mTexture->GetDisplayWidth(); } + double GetScaledHeight () { return mTexture->GetDisplayHeight(); } + // Now with improved offset adjustment. int GetLeftOffset(int adjusted) { return mTexture->GetTexelLeftOffset(adjusted); } int GetTopOffset(int adjusted) { return mTexture->GetTexelTopOffset(adjusted); } diff --git a/src/rendering/swrenderer/things/r_wallsprite.cpp b/src/rendering/swrenderer/things/r_wallsprite.cpp index 909c723953..a3a526e2c7 100644 --- a/src/rendering/swrenderer/things/r_wallsprite.cpp +++ b/src/rendering/swrenderer/things/r_wallsprite.cpp @@ -105,8 +105,8 @@ namespace swrenderer // but right now, I just want to get them drawing. tz = (pos.X - thread->Viewport->viewpoint.Pos.X) * thread->Viewport->viewpoint.TanCos + (pos.Y - thread->Viewport->viewpoint.Pos.Y) * thread->Viewport->viewpoint.TanSin; - int scaled_to = pic->GetScaledTopOffsetSW(); - int scaled_bo = scaled_to - pic->GetScaledHeight(); + double scaled_to = pic->GetScaledTopOffsetSW(); + double scaled_bo = scaled_to - pic->GetScaledHeight(); gzt = pos.Z + scale.Y * scaled_to; gzb = pos.Z + scale.Y * scaled_bo; diff --git a/src/utility/v_collection.cpp b/src/utility/v_collection.cpp index 9bb11a1629..2b51885bf0 100644 --- a/src/utility/v_collection.cpp +++ b/src/utility/v_collection.cpp @@ -72,11 +72,11 @@ void FImageCollection::Uninit () ImageMap.Clear(); } -FTexture *FImageCollection::operator[] (int index) const +FGameTexture *FImageCollection::operator[] (int index) const { if ((unsigned int)index >= ImageMap.Size()) { return NULL; } - return ImageMap[index].Exists()? TexMan.GetPalettedTexture(ImageMap[index], true) : NULL; + return ImageMap[index].Exists()? TexMan.GetGameTexture(ImageMap[index], true) : NULL; } diff --git a/src/utility/v_collection.h b/src/utility/v_collection.h index 697e6bb078..f5df863bf4 100644 --- a/src/utility/v_collection.h +++ b/src/utility/v_collection.h @@ -37,7 +37,7 @@ #include "doomtype.h" #include "r_defs.h" -class FTexture; +class FGameTexture; class FImageCollection { @@ -49,7 +49,7 @@ public: void Add(const char **patchnames, int numPatches, ETextureType namespc = ETextureType::Any); void Uninit(); - FTexture *operator[] (int index) const; + FGameTexture *operator[] (int index) const; protected: TArray ImageMap; From d9928b51a8b86722c1ec856117ff4e94d792cc07 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 01:01:29 +0200 Subject: [PATCH 011/220] - eliminated all cases of calling DrawTexture with an FTexture. Everything uses FGameTexture now. --- src/common/2d/v_draw.h | 3 +- src/common/textures/formats/pngtexture.cpp | 4 +-- src/common/textures/m_png.h | 4 +-- src/common/textures/textures.h | 2 +- src/d_main.cpp | 17 +++++------ src/hu_scores.cpp | 4 +-- src/intermission/intermission.cpp | 25 ++++++++-------- src/menu/menu.h | 2 +- src/rendering/2d/f_wipe.cpp | 12 ++++---- src/rendering/2d/f_wipe.h | 4 +-- src/rendering/swrenderer/r_swscene.cpp | 2 +- src/rendering/v_video.cpp | 26 ++++++++--------- src/wi_stuff.cpp | 34 +++++++++++----------- 13 files changed, 68 insertions(+), 71 deletions(-) diff --git a/src/common/2d/v_draw.h b/src/common/2d/v_draw.h index 5aebfd8332..bd0a27df61 100644 --- a/src/common/2d/v_draw.h +++ b/src/common/2d/v_draw.h @@ -212,11 +212,12 @@ bool SetTextureParms(F2DDrawer *drawer, DrawParms* parms, FTexture* img, double void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, const char* string, int tag_first, ...); void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, const char32_t* string, int tag_first, ...); void DrawChar(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, int character, int tag_first, ...); -void DrawTexture(F2DDrawer* drawer, FTexture* img, double x, double y, int tags_first, ...); template void DrawTexture(F2DDrawer* drawer, FGameTexture* img, double x, double y, int tags_first, Params&&... params) { + void DrawTexture(F2DDrawer * drawer, FTexture * img, double x, double y, int tags_first, ...); + DrawTexture(drawer, img->GetTexture(), x, y, tags_first, std::forward(params)...); } diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index 794892c6c7..36ce398d35 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -589,7 +589,7 @@ protected: // //========================================================================== -FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) +FGameTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) { if (M_FindPNGChunk(png, MAKE_ID('I','H','D','R')) == 0) { @@ -608,7 +608,7 @@ FTexture *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 new FPNGFileTexture (png->File, width, height, colortype); + else return reinterpret_cast(new FPNGFileTexture (png->File, width, height, colortype)); } //========================================================================== diff --git a/src/common/textures/m_png.h b/src/common/textures/m_png.h index 12e6d5adf5..2f52a1fcf5 100644 --- a/src/common/textures/m_png.h +++ b/src/common/textures/m_png.h @@ -119,8 +119,8 @@ bool M_ReadIDAT (FileReader &file, uint8_t *buffer, int width, int height, int p uint8_t bitdepth, uint8_t colortype, uint8_t interlace, unsigned int idatlen); -class FTexture; +class FGameTexture; -FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename); +FGameTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename); #endif diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 6d32360d09..d889f97e13 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -276,7 +276,6 @@ public: bool isFullbrightDisabled() const { return bDisableFullbright; } bool isHardwareCanvas() const { return bHasCanvas; } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isCanvas() const { return bHasCanvas; } - bool isMiscPatch() const { return UseType == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. int isWarped() const { return bWarped; } int GetRotations() const { return Rotations; } float GetShaderSpeed() const { return shaderspeed; } @@ -590,6 +589,7 @@ public: bool isValid() { return wrapped.isValid(); } bool isWarped() { return wrapped.isWarped(); } + bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. bool useWorldPanning() { return wrapped.UseWorldPanning(); } float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped.GetRotations(); } diff --git a/src/d_main.cpp b/src/d_main.cpp index 70a95aa05f..0e9f269d1a 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -271,7 +271,7 @@ int eventhead; int eventtail; gamestate_t wipegamestate = GS_DEMOSCREEN; // can be -1 to force a wipe bool PageBlank; -FTexture *Advisory; +FGameTexture *Advisory; FTextureID Page; const char *Subtitle; bool nospriterename; @@ -1005,11 +1005,8 @@ void D_Display () // draw pause pic if ((paused || pauseext) && menuactive == MENU_Off) { - FTexture *tex; - int x; - - tex = TexMan.GetTextureByName(gameinfo.PauseSign, true); - x = (SCREENWIDTH - tex->GetDisplayWidth() * CleanXfac)/2 + + auto tex = TexMan.GetGameTextureByName(gameinfo.PauseSign, true); + double x = (SCREENWIDTH - tex->GetDisplayWidth() * CleanXfac)/2 + tex->GetDisplayLeftOffset() * CleanXfac; DrawTexture(twod, tex, x, 4, DTA_CleanNoMove, true, TAG_DONE); if (paused && multiplayer) @@ -1031,7 +1028,7 @@ void D_Display () D_DrawIcon = NULL; if (picnum.isValid()) { - FTexture *tex = TexMan.GetTexture(picnum); + auto tex = TexMan.GetGameTexture(picnum); DrawTexture(twod, tex, 160 - tex->GetDisplayWidth()/2, 100 - tex->GetDisplayHeight()/2, DTA_320x200, true, TAG_DONE); } @@ -1068,7 +1065,7 @@ void D_Display () screen->End2D(); auto wipend = screen->WipeEndScreen (); auto wiper = Wiper::Create(wipe_type); - wiper->SetTextures(wipe, wipend); + wiper->SetTextures(reinterpret_cast(wipe), reinterpret_cast(wipend)); wipestart = I_msTime(); NetUpdate(); // send out any new accumulation @@ -1232,7 +1229,7 @@ void D_PageDrawer (void) ClearRect(twod, 0, 0, SCREENWIDTH, SCREENHEIGHT, 0, 0); if (Page.Exists()) { - DrawTexture(twod, TexMan.GetTexture(Page, true), 0, 0, + DrawTexture(twod, TexMan.GetGameTexture(Page, true), 0, 0, DTA_Fullscreen, true, DTA_Masked, false, DTA_BilinearFilter, true, @@ -1433,7 +1430,7 @@ void D_DoAdvanceDemo (void) case 3: if (gameinfo.advisoryTime) { - Advisory = TexMan.GetTextureByName("ADVISOR"); + Advisory = TexMan.GetGameTextureByName("ADVISOR"); demosequence = 1; pagetic = (int)(gameinfo.advisoryTime * TICRATE); break; diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index d8dce6a455..d393cfb4d2 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -429,7 +429,7 @@ static void HU_DrawPlayer (player_t *player, bool highlight, int col1, int col2, auto icon = FSetTextureID(player->mo->IntVar(NAME_ScoreIcon)); if (icon.isValid()) { - FTexture *pic = TexMan.GetTexture(icon); + auto pic = TexMan.GetGameTexture(icon); DrawTexture(twod, pic, col3, y, DTA_CleanNoMove, true, TAG_DONE); @@ -450,7 +450,7 @@ static void HU_DrawPlayer (player_t *player, bool highlight, int col1, int col2, if (teamplay && Teams[player->userinfo.GetTeam()].GetLogo().IsNotEmpty ()) { - FTexture *pic = TexMan.GetTextureByName(Teams[player->userinfo.GetTeam()].GetLogo().GetChars ()); + auto pic = TexMan.GetGameTextureByName(Teams[player->userinfo.GetTeam()].GetLogo().GetChars ()); DrawTexture(twod, pic, col1 - (pic->GetDisplayWidth() + 2) * CleanXfac, y, DTA_CleanNoMove, true, TAG_DONE); } diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index a06feac8f9..b2ce4a5b27 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -216,7 +216,7 @@ void DIntermissionScreen::Drawer () { if (!mFlatfill) { - DrawTexture(twod, TexMan.GetTexture(mBackground), 0, 0, DTA_Fullscreen, true, TAG_DONE); + DrawTexture(twod, TexMan.GetGameTexture(mBackground), 0, 0, DTA_Fullscreen, true, TAG_DONE); } else { @@ -230,7 +230,7 @@ void DIntermissionScreen::Drawer () for (unsigned i=0; i < mOverlays.Size(); i++) { if (CheckOverlay(i)) - DrawTexture(twod, TexMan.GetTexture(mOverlays[i].mPic), mOverlays[i].x, mOverlays[i].y, DTA_320x200, true, TAG_DONE); + DrawTexture(twod, TexMan.GetGameTexture(mOverlays[i].mPic), mOverlays[i].x, mOverlays[i].y, DTA_320x200, true, TAG_DONE); } if (mSubtitle) { @@ -287,11 +287,11 @@ void DIntermissionScreenFader::Drawer () if (mType == FADE_In) factor = 1.0 - factor; int color = MAKEARGB(int(factor*255), 0,0,0); - DrawTexture(twod, TexMan.GetTexture(mBackground), 0, 0, DTA_Fullscreen, true, DTA_ColorOverlay, color, TAG_DONE); + DrawTexture(twod, TexMan.GetGameTexture(mBackground), 0, 0, DTA_Fullscreen, true, DTA_ColorOverlay, color, TAG_DONE); for (unsigned i=0; i < mOverlays.Size(); i++) { if (CheckOverlay(i)) - DrawTexture(twod, TexMan.GetTexture(mOverlays[i].mPic), mOverlays[i].x, mOverlays[i].y, DTA_320x200, true, DTA_ColorOverlay, color, TAG_DONE); + DrawTexture(twod, TexMan.GetGameTexture(mOverlays[i].mPic), mOverlays[i].x, mOverlays[i].y, DTA_320x200, true, DTA_ColorOverlay, color, TAG_DONE); } } } @@ -620,7 +620,6 @@ int DIntermissionScreenCast::Ticker () void DIntermissionScreenCast::Drawer () { spriteframe_t* sprframe; - FTexture* pic; Super::Drawer(); @@ -667,13 +666,13 @@ void DIntermissionScreenCast::Drawer () } sprframe = &SpriteFrames[sprites[castsprite].spriteframes + caststate->GetFrame()]; - pic = TexMan.GetTexture(sprframe->Texture[0], true); + auto pic = TexMan.GetGameTexture(sprframe->Texture[0], true); DrawTexture(twod, pic, 160, 170, DTA_320x200, true, DTA_FlipX, sprframe->Flip & 1, - DTA_DestHeightF, pic->GetDisplayHeightDouble() * castscale.Y, - DTA_DestWidthF, pic->GetDisplayWidthDouble() * castscale.X, + DTA_DestHeightF, pic->GetDisplayHeight() * castscale.Y, + DTA_DestWidthF, pic->GetDisplayWidth() * castscale.X, DTA_RenderStyle, mDefaults->RenderStyle, DTA_Alpha, mDefaults->Alpha, DTA_TranslationIndex, casttranslation, @@ -710,13 +709,13 @@ int DIntermissionScreenScroller::Responder (event_t *ev) void DIntermissionScreenScroller::Drawer () { - FTexture *tex = TexMan.GetTexture(mFirstPic); - FTexture *tex2 = TexMan.GetTexture(mSecondPic); + auto tex = TexMan.GetGameTexture(mFirstPic); + auto tex2 = TexMan.GetGameTexture(mSecondPic); if (mTicker >= mScrollDelay && mTicker < mScrollDelay + mScrollTime && tex != NULL && tex2 != NULL) { - - int fwidth = tex->GetDisplayWidth(); - int fheight = tex->GetDisplayHeight(); + // These must round down to the nearest full pixel to cover seams between the two textures. + int fwidth = (int)tex->GetDisplayWidth(); + int fheight = (int)tex->GetDisplayHeight(); double xpos1 = 0, ypos1 = 0, xpos2 = 0, ypos2 = 0; diff --git a/src/menu/menu.h b/src/menu/menu.h index 98fd2addbb..ed224e9608 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -73,7 +73,7 @@ private: int LastSaved = -1; int LastAccessed = -1; TArray SavePicData; - FTexture *SavePic = nullptr; + FGameTexture *SavePic = nullptr; public: int WindowSize = 0; diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index f255774918..6fe106646d 100644 --- a/src/rendering/2d/f_wipe.cpp +++ b/src/rendering/2d/f_wipe.cpp @@ -168,7 +168,7 @@ class Wiper_Burn : public Wiper public: ~Wiper_Burn(); bool Run(int ticks) override; - void SetTextures(FTexture *startscreen, FTexture *endscreen) override; + void SetTextures(FGameTexture *startscreen, FGameTexture *endscreen) override; private: static const int WIDTH = 64, HEIGHT = 64; @@ -307,8 +307,8 @@ bool Wiper_Melt::Run(int ticks) // Only draw for the final tick. // No need for optimization. Wipes won't ever be drawn with anything else. - int w = startScreen->GetDisplayWidth(); - int h = startScreen->GetDisplayHeight(); + int w = startScreen->GetTexelWidth(); + int h = startScreen->GetTexelHeight(); dpt.x = i * w / WIDTH; dpt.y = MAX(0, y[i] * h / HEIGHT); rect.left = dpt.x; @@ -331,12 +331,12 @@ bool Wiper_Melt::Run(int ticks) // //========================================================================== -void Wiper_Burn::SetTextures(FTexture *startscreen, FTexture *endscreen) +void Wiper_Burn::SetTextures(FGameTexture *startscreen, FGameTexture *endscreen) { startScreen = startscreen; endScreen = endscreen; BurnTexture = new FBurnTexture(WIDTH, HEIGHT); - auto mat = FMaterial::ValidateTexture(endScreen, false); + auto mat = FMaterial::ValidateTexture(endScreen->GetTexture(), false); mat->AddTextureLayer(BurnTexture); } @@ -374,7 +374,7 @@ bool Wiper_Burn::Run(int ticks) } BurnTexture->CleanHardwareTextures(true, true); - endScreen->CleanHardwareTextures(false, false); + endScreen->GetTexture()->CleanHardwareTextures(false, false); const uint8_t *src = BurnArray; uint32_t *dest = (uint32_t *)BurnTexture->GetBuffer(); diff --git a/src/rendering/2d/f_wipe.h b/src/rendering/2d/f_wipe.h index c639307aa6..9b16b4d38d 100644 --- a/src/rendering/2d/f_wipe.h +++ b/src/rendering/2d/f_wipe.h @@ -43,11 +43,11 @@ enum class Wiper { protected: - FTexture *startScreen = nullptr, *endScreen = nullptr; + FGameTexture *startScreen = nullptr, *endScreen = nullptr; public: virtual ~Wiper(); virtual bool Run(int ticks) = 0; - virtual void SetTextures(FTexture *startscreen, FTexture *endscreen) + virtual void SetTextures(FGameTexture *startscreen, FGameTexture *endscreen) { startScreen = startscreen; endScreen = endscreen; diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index aea5501036..dc7dcad8ba 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -116,7 +116,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) systemTexture->CreateTexture(nullptr, screen->GetWidth(), screen->GetHeight(), 0, false, "swbuffer"); auto map = swrenderer::CameraLight::Instance()->ShaderColormap(); - DrawTexture(twod, fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE); + DrawTexture(twod, reinterpret_cast(fbtex.get()), 0, 0, DTA_SpecialColormap, map, TAG_DONE); screen->Draw2D(); screen->Clear2D(); screen->PostProcessScene(CM_DEFAULT, [&]() { diff --git a/src/rendering/v_video.cpp b/src/rendering/v_video.cpp index 3c75aa73cb..a4c59283e2 100644 --- a/src/rendering/v_video.cpp +++ b/src/rendering/v_video.cpp @@ -522,7 +522,7 @@ IHardwareTexture* CreateHardwareTexture() void DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height) { - FTexture* p; + FGameTexture* p; const gameborder_t* border = &gameinfo.Border; // Sanity check for incomplete gameinfo if (border == NULL) @@ -532,22 +532,22 @@ void DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height) int bottom = top + height; // Draw top and bottom sides. - p = TexMan.GetTextureByName(border->t); - drawer->AddFlatFill(left, top - p->GetDisplayHeight(), right, top, p, true); - p = TexMan.GetTextureByName(border->b); - drawer->AddFlatFill(left, bottom, right, bottom + p->GetDisplayHeight(), p, true); + p = TexMan.GetGameTextureByName(border->t); + drawer->AddFlatFill(left, top - (int)p->GetDisplayHeight(), right, top, p, true); + p = TexMan.GetGameTextureByName(border->b); + drawer->AddFlatFill(left, bottom, right, bottom + (int)p->GetDisplayHeight(), p, true); // Draw left and right sides. - p = TexMan.GetTextureByName(border->l); - drawer->AddFlatFill(left - p->GetDisplayWidth(), top, left, bottom, p, true); - p = TexMan.GetTextureByName(border->r); - drawer->AddFlatFill(right, top, right + p->GetDisplayWidth(), bottom, p, true); + p = TexMan.GetGameTextureByName(border->l); + drawer->AddFlatFill(left - (int)p->GetDisplayWidth(), top, left, bottom, p, true); + p = TexMan.GetGameTextureByName(border->r); + drawer->AddFlatFill(right, top, right + (int)p->GetDisplayWidth(), bottom, p, true); // Draw beveled corners. - DrawTexture(drawer, TexMan.GetTextureByName(border->tl), left - offset, top - offset, TAG_DONE); - DrawTexture(drawer, TexMan.GetTextureByName(border->tr), left + width, top - offset, TAG_DONE); - DrawTexture(drawer, TexMan.GetTextureByName(border->bl), left - offset, top + height, TAG_DONE); - DrawTexture(drawer, TexMan.GetTextureByName(border->br), left + width, top + height, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->tl), left - offset, top - offset, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->tr), left + width, top - offset, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->bl), left - offset, top + height, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->br), left + width, top + height, TAG_DONE); } DEFINE_ACTION_FUNCTION(_Screen, DrawFrame) diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index 5e65cd292b..4334d170d9 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -138,7 +138,7 @@ class DInterBackground : public DObject int period; // period in tics between animations yahpt_t loc; // location of animation int data; // ALWAYS: n/a, RANDOM: period deviation (<256) - TArray frames; // actual graphics for frames of animations + TArray frames; // actual graphics for frames of animations // following must be initialized to zero before use! int nexttic; // next value of bcnt (used in conjunction with period) @@ -161,9 +161,9 @@ private: TArray lnodes; TArray anims; int bcnt = 0; // used for timing of background animation - TArray yah; // You Are Here graphic - FTexture* splat = nullptr; // splat - FTexture *background = nullptr; + TArray yah; // You Are Here graphic + FGameTexture* splat = nullptr; // splat + FGameTexture *background = nullptr; wbstartstruct_t *wbs; level_info_t *exitlevel; @@ -208,15 +208,15 @@ private: // //==================================================================== - void drawOnLnode(int n, FTexture * c[], int numc) + void drawOnLnode(int n, FGameTexture * c[], int numc) { int i; for (i = 0; iGetDisplayWidth(); @@ -387,13 +387,13 @@ bool DInterBackground::LoadBackground(bool isenterpic) case 1: // Splat sc.MustGetString(); - splat = TexMan.GetTextureByName(sc.String); + splat = TexMan.GetGameTextureByName(sc.String); break; case 2: // Pointers while (sc.GetString() && !sc.Crossed) { - yah.Push(TexMan.GetTextureByName(sc.String)); + yah.Push(TexMan.GetGameTextureByName(sc.String)); } if (sc.Crossed) sc.UnGet(); @@ -485,14 +485,14 @@ bool DInterBackground::LoadBackground(bool isenterpic) if (!sc.CheckString("{")) { sc.MustGetString(); - an.frames.Push(TexMan.GetTextureByName(sc.String)); + an.frames.Push(TexMan.GetGameTextureByName(sc.String)); } else { while (!sc.CheckString("}")) { sc.MustGetString(); - an.frames.Push(TexMan.GetTextureByName(sc.String)); + an.frames.Push(TexMan.GetGameTextureByName(sc.String)); } } an.ctr = -1; @@ -507,7 +507,7 @@ bool DInterBackground::LoadBackground(bool isenterpic) an.loc.y = sc.Number; sc.MustGetString(); an.frames.Reserve(1); // allocate exactly one element - an.frames[0] = TexMan.GetTextureByName(sc.String); + an.frames[0] = TexMan.GetGameTextureByName(sc.String); anims.Push(an); break; @@ -523,7 +523,7 @@ bool DInterBackground::LoadBackground(bool isenterpic) texture = TexMan.GetTextureID("INTERPIC", ETextureType::MiscPatch); } } - background = TexMan.GetTexture(texture); + background = TexMan.GetGameTexture(texture); return noautostartmap; } @@ -598,8 +598,8 @@ void DInterBackground::drawBackground(int state, bool drawsplat, bool snl_pointe // scale all animations below to fit the size of the base pic // The base pic is always scaled to fit the screen so this allows // placing the animations precisely where they belong on the base pic - animwidth = background->GetDisplayWidthDouble(); - animheight = background->GetDisplayHeightDouble(); + animwidth = background->GetDisplayWidth(); + animheight = background->GetDisplayHeight(); DrawTexture(twod, background, 0, 0, DTA_Fullscreen, true, TAG_DONE); } else From 9e7094848c3943632773d056ff40d16ed4d04ba8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 01:23:37 +0200 Subject: [PATCH 012/220] - transitioned the 2D drawer to FGameTexture. --- src/am_map.cpp | 2 +- src/common/2d/v_2ddrawer.cpp | 25 ++++---- src/common/2d/v_2ddrawer.h | 19 +++--- src/common/2d/v_draw.cpp | 60 +++++++++--------- src/common/2d/v_draw.h | 14 ++--- src/common/2d/v_drawtext.cpp | 10 +-- src/common/fonts/font.cpp | 63 +++++++++---------- src/common/fonts/singlepicfont.cpp | 6 +- src/common/fonts/v_font.h | 6 +- src/common/textures/texture.cpp | 1 + src/common/textures/texturemanager.h | 15 ++--- src/common/textures/textures.h | 10 ++- src/d_main.cpp | 18 +----- src/g_statusbar/sbarinfo.cpp | 2 +- src/g_statusbar/shared_sbar.cpp | 2 +- src/intermission/intermission.cpp | 4 +- .../hwrenderer/utility/hw_draw2d.cpp | 2 +- src/rendering/swrenderer/line/r_walldraw.h | 1 - src/rendering/swrenderer/r_renderer.h | 1 - src/rendering/swrenderer/r_swrenderer.cpp | 4 +- .../swrenderer/textures/r_swtexture.cpp | 23 +++++-- 21 files changed, 135 insertions(+), 153 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 40de0a01dd..d86da9506b 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -2150,7 +2150,7 @@ void DAutomap::drawSubsectors() fadelevel = 1. - clamp(floorlight, 0, 255) / 255.f; } - twod->AddPoly(TexMan.GetTexture(maptex, true), + twod->AddPoly(TexMan.GetGameTexture(maptex, true), &points[0], points.Size(), originx, originy, scale / scalex, diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 4cee865ab3..704d2e1cf7 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -234,7 +234,7 @@ void F2DDrawer::AddIndices(int firstvert, TArray &v) // //========================================================================== -bool F2DDrawer::SetStyle(FTexture *tex, DrawParms &parms, PalEntry &vertexcolor, RenderCommand &quad) +bool F2DDrawer::SetStyle(FGameTexture *tex, DrawParms &parms, PalEntry &vertexcolor, RenderCommand &quad) { FRenderStyle style = parms.style; float alpha; @@ -390,7 +390,7 @@ void F2DDrawer::SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcol // //========================================================================== -void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms) +void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms) { if (parms.style.BlendOp == STYLEOP_None) return; // not supposed to be drawn. @@ -472,7 +472,7 @@ void F2DDrawer::AddTexture(FTexture *img, DrawParms &parms) // //========================================================================== -void F2DDrawer::AddShape( FTexture *img, DShape2D *shape, DrawParms &parms ) +void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms) { // [MK] bail out if vertex/coord array sizes are mismatched if ( shape->mVertices.Size() != shape->mCoords.Size() ) @@ -550,12 +550,11 @@ void F2DDrawer::AddShape( FTexture *img, DShape2D *shape, DrawParms &parms ) // //========================================================================== -void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints, +void F2DDrawer::AddPoly(FGameTexture *texture, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, DAngle rotation, const FColormap &colormap, PalEntry flatcolor, double fadelevel, uint32_t *indices, size_t indexcount) { - RenderCommand poly; poly.mType = DrawTypeTriangles; @@ -630,7 +629,7 @@ void F2DDrawer::AddPoly(FTexture *texture, FVector2 *points, int npoints, // //========================================================================== -void F2DDrawer::AddPoly(FTexture* img, FVector4* vt, size_t vtcount, unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2) +void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, unsigned int* ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2) { RenderCommand dg = {}; int method = 0; @@ -677,7 +676,7 @@ void F2DDrawer::AddPoly(FTexture* img, FVector4* vt, size_t vtcount, unsigned in // //========================================================================== -void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin) +void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, bool local_origin) { float fU1, fU2, fV1, fV2; @@ -693,17 +692,17 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FTexture * // scaling is not used here. if (!local_origin) { - fU1 = float(left) / src->GetDisplayWidth(); - fV1 = float(top) / src->GetDisplayHeight(); - fU2 = float(right) / src->GetDisplayWidth(); - fV2 = float(bottom) / src->GetDisplayHeight(); + fU1 = float(left) / (float)src->GetDisplayWidth(); + fV1 = float(top) / (float)src->GetDisplayHeight(); + fU2 = float(right) / (float)src->GetDisplayWidth(); + fV2 = float(bottom) / (float)src->GetDisplayHeight(); } else { fU1 = 0; fV1 = 0; - fU2 = float(right - left) / src->GetDisplayWidth(); - fV2 = float(bottom - top) / src->GetDisplayHeight(); + fU2 = float(right - left) / (float)src->GetDisplayWidth(); + fV2 = float(bottom - top) / (float)src->GetDisplayHeight(); } dg.mVertIndex = (int)mVertices.Reserve(4); auto ptr = &mVertices[dg.mVertIndex]; diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index 6442b3526f..07115f0f92 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -124,7 +124,7 @@ public: int mIndexIndex; int mIndexCount; - FTexture *mTexture; + FGameTexture *mTexture; int mTranslationId; PalEntry mSpecialColormap[2]; int mScissor[4]; @@ -170,24 +170,19 @@ public: void AddIndices(int firstvert, int count, ...); private: void AddIndices(int firstvert, TArray &v); - bool SetStyle(FTexture *tex, DrawParms &parms, PalEntry &color0, RenderCommand &quad); + bool SetStyle(FGameTexture *tex, DrawParms &parms, PalEntry &color0, RenderCommand &quad); void SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcolor, PalEntry &overlaycolor); public: - void AddTexture(FTexture *img, DrawParms &parms); - void AddShape(FTexture *img, DShape2D *shape, DrawParms &parms); - void AddPoly(FTexture *texture, FVector2 *points, int npoints, + void AddTexture(FGameTexture* img, DrawParms& parms); + void AddShape(FGameTexture *img, DShape2D *shape, DrawParms &parms); + void AddPoly(FGameTexture *texture, FVector2 *points, int npoints, double originx, double originy, double scalex, double scaley, DAngle rotation, const FColormap &colormap, PalEntry flatcolor, double lightlevel, uint32_t *indices, size_t indexcount); - void AddPoly(FTexture* img, FVector4 *vt, size_t vtcount, unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2); + void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2); void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex, int clipx1, int clipy1, int clipx2, int clipy2); - void AddFlatFill(int left, int top, int right, int bottom, FTexture *src, bool local_origin = false); - void AddFlatFill(int left, int top, int right, int bottom, FGameTexture* src, bool local_origin = false) - { - AddFlatFill(left, top, right, bottom, src->GetTexture(), local_origin); - } - + void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, bool local_origin = false); void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style = nullptr); void ClearScreen(PalEntry color = 0xff000000); diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index a70d47e5fc..fc1708ef42 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -180,7 +180,7 @@ int CleanXfac_1, CleanYfac_1, CleanWidth_1, CleanHeight_1; // //========================================================================== -void DrawTexture(F2DDrawer *drawer, FTexture* img, double x, double y, int tags_first, ...) +void DrawTexture(F2DDrawer *drawer, FGameTexture* img, double x, double y, int tags_first, ...) { Va_List tags; va_start(tags.list, tags_first); @@ -203,7 +203,7 @@ void DrawTexture(F2DDrawer *drawer, FTexture* img, double x, double y, int tags_ int ListGetInt(VMVa_List &tags); -static void DrawTexture(F2DDrawer *drawer, FTexture *img, double x, double y, VMVa_List &args) +static void DrawTexture(F2DDrawer *drawer, FGameTexture *img, double x, double y, VMVa_List &args) { DrawParms parms; uint32_t tag = ListGetInt(args); @@ -224,7 +224,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawTexture) if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - FTexture *tex = TexMan.ByIndex(texid, animate); + auto tex = TexMan.GameByIndex(texid, animate); VMVa_List args = { param + 4, 0, numparam - 5, va_reginfo + 4 }; DrawTexture(twod, tex, x, y, args); return 0; @@ -236,7 +236,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawTexture) // //========================================================================== -void DrawShape(F2DDrawer *drawer, FTexture *img, DShape2D *shape, int tags_first, ...) +void DrawShape(F2DDrawer *drawer, FGameTexture *img, DShape2D *shape, int tags_first, ...) { Va_List tags; va_start(tags.list, tags_first); @@ -248,7 +248,7 @@ void DrawShape(F2DDrawer *drawer, FTexture *img, DShape2D *shape, int tags_first drawer->AddShape(img, shape, parms); } -void DrawShape(F2DDrawer *drawer, FTexture *img, DShape2D *shape, VMVa_List &args) +void DrawShape(F2DDrawer *drawer, FGameTexture *img, DShape2D *shape, VMVa_List &args) { DrawParms parms; uint32_t tag = ListGetInt(args); @@ -269,7 +269,7 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawShape) if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - FTexture *tex = TexMan.ByIndex(texid, animate); + auto tex = TexMan.GameByIndex(texid, animate); VMVa_List args = { param + 3, 0, numparam - 4, va_reginfo + 3 }; DrawShape(twod, tex, shape, args); @@ -334,7 +334,7 @@ DEFINE_ACTION_FUNCTION(_Screen, GetClipRect) // //========================================================================== -bool SetTextureParms(F2DDrawer * drawer, DrawParms *parms, FTexture *img, double xx, double yy) +bool SetTextureParms(F2DDrawer * drawer, DrawParms *parms, FGameTexture *img, double xx, double yy) { auto GetWidth = [=]() { return drawer->GetWidth(); }; auto GetHeight = [=]() {return drawer->GetHeight(); }; @@ -342,8 +342,8 @@ bool SetTextureParms(F2DDrawer * drawer, DrawParms *parms, FTexture *img, double { parms->x = xx; parms->y = yy; - parms->texwidth = img->GetDisplayWidthDouble(); - parms->texheight = img->GetDisplayHeightDouble(); + parms->texwidth = img->GetDisplayWidth(); + parms->texheight = img->GetDisplayHeight(); if (parms->top == INT_MAX || parms->fortext) { parms->top = img->GetDisplayTopOffset(); @@ -354,11 +354,11 @@ bool SetTextureParms(F2DDrawer * drawer, DrawParms *parms, FTexture *img, double } if (parms->destwidth == INT_MAX || parms->fortext) { - parms->destwidth = img->GetDisplayWidthDouble(); + parms->destwidth = img->GetDisplayWidth(); } if (parms->destheight == INT_MAX || parms->fortext) { - parms->destheight = img->GetDisplayHeightDouble(); + parms->destheight = img->GetDisplayHeight(); } switch (parms->cleanmode) @@ -387,8 +387,8 @@ bool SetTextureParms(F2DDrawer * drawer, DrawParms *parms, FTexture *img, double case DTA_FullscreenEx: { double aspect; - double srcwidth = img->GetDisplayWidthDouble(); - double srcheight = img->GetDisplayHeightDouble(); + double srcwidth = img->GetDisplayWidth(); + double srcheight = img->GetDisplayHeight(); int autoaspect = parms->fsscalemode; aspect = autoaspect == 0 || (srcwidth == 320 && srcheight == 200) || (srcwidth == 640 && srcheight == 400)? 1.333 : srcwidth / srcheight; parms->x = parms->y = 0; @@ -531,7 +531,7 @@ static inline FSpecialColormap * ListGetSpecialColormap(VMVa_List &tags) //========================================================================== template -bool ParseDrawTextureTags(F2DDrawer *drawer, FTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, bool fortext) +bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, bool fortext) { INTBOOL boolval; int intval; @@ -724,8 +724,8 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FTexture *img, double x, double y, if (img == NULL) return false; parms->cleanmode = DTA_Fullscreen; parms->fsscalemode = (uint8_t)twod->fullscreenautoaspect; - parms->virtWidth = img->GetDisplayWidthDouble(); - parms->virtHeight = img->GetDisplayHeightDouble(); + parms->virtWidth = img->GetDisplayWidth(); + parms->virtHeight = img->GetDisplayHeight(); } break; @@ -738,8 +738,8 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FTexture *img, double x, double y, if (img == NULL) return false; parms->cleanmode = DTA_Fullscreen; parms->fsscalemode = (uint8_t)intval; - parms->virtWidth = img->GetDisplayWidthDouble(); - parms->virtHeight = img->GetDisplayHeightDouble(); + parms->virtWidth = img->GetDisplayWidth(); + parms->virtHeight = img->GetDisplayHeight(); } break; @@ -785,19 +785,19 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FTexture *img, double x, double y, break; case DTA_SrcX: - parms->srcx = ListGetDouble(tags) / img->GetDisplayWidthDouble(); + parms->srcx = ListGetDouble(tags) / img->GetDisplayWidth(); break; case DTA_SrcY: - parms->srcy = ListGetDouble(tags) / img->GetDisplayHeightDouble(); + parms->srcy = ListGetDouble(tags) / img->GetDisplayHeight(); break; case DTA_SrcWidth: - parms->srcwidth = ListGetDouble(tags) / img->GetDisplayWidthDouble(); + parms->srcwidth = ListGetDouble(tags) / img->GetDisplayWidth(); break; case DTA_SrcHeight: - parms->srcheight = ListGetDouble(tags) / img->GetDisplayHeightDouble(); + parms->srcheight = ListGetDouble(tags) / img->GetDisplayHeight(); break; case DTA_TopOffset: @@ -829,8 +829,8 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FTexture *img, double x, double y, if (fortext) return false; if (ListGetInt(tags)) { - parms->left = img->GetDisplayWidthDouble() * 0.5; - parms->top = img->GetDisplayHeightDouble() * 0.5; + parms->left = img->GetDisplayWidth() * 0.5; + parms->top = img->GetDisplayHeight() * 0.5; } break; @@ -839,8 +839,8 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FTexture *img, double x, double y, if (fortext) return false; if (ListGetInt(tags)) { - parms->left = img->GetDisplayWidthDouble() * 0.5; - parms->top = img->GetDisplayHeightDouble(); + parms->left = img->GetDisplayWidth() * 0.5; + parms->top = img->GetDisplayHeight(); } break; @@ -1038,8 +1038,8 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FTexture *img, double x, double y, } // explicitly instantiate both versions for v_text.cpp. -template bool ParseDrawTextureTags(F2DDrawer* drawer, FTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, bool fortext); -template bool ParseDrawTextureTags(F2DDrawer* drawer, FTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, bool fortext); +template bool ParseDrawTextureTags(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, bool fortext); +template bool ParseDrawTextureTags(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, bool fortext); //========================================================================== // @@ -1131,7 +1131,7 @@ void VirtualToRealCoordsInt(F2DDrawer *drawer, int &x, int &y, int &w, int &h, // //========================================================================== -void FillBorder (F2DDrawer *drawer, FTexture *img) +void FillBorder (F2DDrawer *drawer, FGameTexture *img) { auto Width = drawer->GetWidth(); auto Height = drawer->GetHeight(); @@ -1351,7 +1351,7 @@ void DrawBorder (F2DDrawer *drawer, FTextureID picnum, int x1, int y1, int x2, i { if (picnum.isValid()) { - drawer->AddFlatFill (x1, y1, x2, y2, TexMan.GetTexture(picnum, false)); + drawer->AddFlatFill (x1, y1, x2, y2, TexMan.GetGameTexture(picnum, false)); } else { diff --git a/src/common/2d/v_draw.h b/src/common/2d/v_draw.h index bd0a27df61..e42b6f3067 100644 --- a/src/common/2d/v_draw.h +++ b/src/common/2d/v_draw.h @@ -203,27 +203,21 @@ inline int active_con_scale(F2DDrawer *drawer) #endif template -bool ParseDrawTextureTags(F2DDrawer *drawer, FTexture* img, double x, double y, uint32_t tag, T& tags, DrawParms* parms, bool fortext); +bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture* img, double x, double y, uint32_t tag, T& tags, DrawParms* parms, bool fortext); template void DrawTextCommon(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, const T* string, DrawParms& parms); -bool SetTextureParms(F2DDrawer *drawer, DrawParms* parms, FTexture* img, double x, double y); +bool SetTextureParms(F2DDrawer *drawer, DrawParms* parms, FGameTexture* img, double x, double y); void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, const char* string, int tag_first, ...); void DrawText(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, const char32_t* string, int tag_first, ...); void DrawChar(F2DDrawer* drawer, FFont* font, int normalcolor, double x, double y, int character, int tag_first, ...); -template -void DrawTexture(F2DDrawer* drawer, FGameTexture* img, double x, double y, int tags_first, Params&&... params) -{ - void DrawTexture(F2DDrawer * drawer, FTexture * img, double x, double y, int tags_first, ...); - - DrawTexture(drawer, img->GetTexture(), x, y, tags_first, std::forward(params)...); -} +void DrawTexture(F2DDrawer* drawer, FGameTexture* img, double x, double y, int tags_first, ...); void DoDim(F2DDrawer* drawer, PalEntry color, float amount, int x1, int y1, int w, int h, FRenderStyle* style = nullptr); void Dim(F2DDrawer* drawer, PalEntry color, float damount, int x1, int y1, int w, int h, FRenderStyle* style = nullptr); -void FillBorder(F2DDrawer *drawer, FTexture* img); // Fills the border around a 4:3 part of the screen on non-4:3 displays +void FillBorder(F2DDrawer *drawer, FGameTexture* img); // Fills the border around a 4:3 part of the screen on non-4:3 displays void DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height); void DrawBorder(F2DDrawer* drawer, FTextureID, int x1, int y1, int x2, int y2); diff --git a/src/common/2d/v_drawtext.cpp b/src/common/2d/v_drawtext.cpp index a475e9e9a1..ac99e3178b 100644 --- a/src/common/2d/v_drawtext.cpp +++ b/src/common/2d/v_drawtext.cpp @@ -53,7 +53,7 @@ int ListGetInt(VMVa_List &tags); // //========================================================================== #if 0 -FTexture * BuildTextTexture(FFont *font, const char *string, int textcolor) +FGameTexture * BuildTextTexture(FFont *font, const char *string, int textcolor) { int w; const uint8_t *ch; @@ -61,7 +61,7 @@ FTexture * BuildTextTexture(FFont *font, const char *string, int textcolor) int cy; int trans = -1; int kerning; - FTexture *pic; + FGameTexture *pic; kerning = font->GetDefaultKerning(); @@ -170,7 +170,7 @@ void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double if (normalcolor >= NumTextColors) normalcolor = CR_UNTRANSLATED; - FTexture* pic; + FGameTexture* pic; int dummy; bool redirected; @@ -200,7 +200,7 @@ void DrawChar(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double if (normalcolor >= NumTextColors) normalcolor = CR_UNTRANSLATED; - FTexture *pic; + FGameTexture *pic; int dummy; bool redirected; @@ -256,7 +256,7 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d int boldcolor; int trans = -1; int kerning; - FTexture *pic; + FGameTexture *pic; if (parms.celly == 0) parms.celly = font->GetHeight() + 1; parms.celly *= parms.scaley; diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 148631670f..f670d5af84 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -73,7 +73,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla int i; FTextureID lump; char buffer[12]; - int maxyoffs; DVector2 Scale = { 1, 1 }; noTranslate = notranslate; @@ -91,9 +90,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla translateUntranslated = false; int FixedWidth = 0; - maxyoffs = 0; - - TMap charMap; + TMap charMap; int minchar = INT_MAX; int maxchar = INT_MIN; @@ -231,13 +228,13 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla Type = Multilump; if (position < minchar) minchar = position; if (position > maxchar) maxchar = position; - charMap.Insert(position, TexMan.GetTexture(lump)); + charMap.Insert(position, TexMan.GetGameTexture(lump)); } } } else { - FTexture *texs[256] = {}; + FGameTexture *texs[256] = {}; if (lcount > 256 - start) lcount = 256 - start; for (i = 0; i < lcount; i++) { @@ -247,8 +244,8 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla TexMan.ListTextures(buffer, array, true); for (auto entry : array) { - FTexture *tex = TexMan.GetTexture(entry, false); - if (tex && tex->GetSourceLump() >= 0 && fileSystem.GetFileContainer(tex->GetSourceLump()) <= fileSystem.GetMaxIwadNum() && tex->GetUseType() == ETextureType::MiscPatch) + auto tex = TexMan.GetGameTexture(entry, false); + if (tex && !tex->isUserContent() && tex->GetUseType() == ETextureType::MiscPatch) { texs[i] = tex; } @@ -292,7 +289,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla { if ((int)position < minchar) minchar = (int)position; if ((int)position > maxchar) maxchar = (int)position; - auto tex = TexMan.GetTexture(lump); + auto tex = TexMan.GetGameTexture(lump); tex->SetScale(Scale); charMap.Insert((int)position, tex); Type = Folder; @@ -312,17 +309,13 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla auto lump = charMap.CheckKey(FirstChar + i); if (lump != nullptr) { - FTexture *pic = *lump; + auto pic = *lump; if (pic != nullptr) { - int height = pic->GetDisplayHeight(); - int yoffs = pic->GetDisplayTopOffset(); + double fheight = pic->GetDisplayHeight(); + double yoffs = pic->GetDisplayTopOffset(); - if (yoffs > maxyoffs) - { - maxyoffs = yoffs; - } - height += abs(yoffs); + int height = int(fheight + abs(yoffs) + 0.5); if (height > fontheight) { fontheight = height; @@ -333,21 +326,23 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla } } - Chars[i].OriginalPic = new FImageTexture(pic->GetImage(), ""); - Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); - Chars[i].OriginalPic->CopySize(pic); - TexMan.AddTexture(Chars[i].OriginalPic); + auto orig = pic->GetTexture(); + auto tex = new FImageTexture(orig->GetImage(), ""); + tex->SetUseType(ETextureType::FontChar); + tex->CopySize(orig); + TexMan.AddTexture(tex); + Chars[i].OriginalPic = tex; if (!noTranslate) { - Chars[i].TranslatedPic = new FImageTexture(new FFontChar1(pic->GetImage()), ""); - Chars[i].TranslatedPic->CopySize(pic); + Chars[i].TranslatedPic = new FImageTexture(new FFontChar1(orig->GetImage()), ""); + Chars[i].TranslatedPic->CopySize(orig); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); TexMan.AddTexture(Chars[i].TranslatedPic); } else { - Chars[i].TranslatedPic = Chars[i].OriginalPic; + Chars[i].TranslatedPic = tex; } Chars[i].XMove = Chars[i].TranslatedPic->GetDisplayWidth(); @@ -389,7 +384,7 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height { // all valid lumps must be named with a hex number that represents the Unicode character index for its first character, TArray part(1, true); - TMap charMap; + TMap charMap; int minchar = INT_MAX; int maxchar = INT_MIN; for (auto &entry : folderdata) @@ -433,7 +428,7 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height tex->bNoDecals = false; tex->SourceLump = -1; // We do not really care. TexMan.AddTexture(tex); - charMap.Insert(int(position) + x + y * numtex_x, tex); + charMap.Insert(int(position) + x + y * numtex_x, reinterpret_cast(tex)); } } } @@ -458,7 +453,7 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height auto lump = charMap.CheckKey(FirstChar + i); if (lump != nullptr) { - FTexture *pic = *lump; + FTexture *pic = (*lump)->GetTexture(); auto b = pic->Get8BitPixels(false); @@ -982,7 +977,7 @@ int FFont::GetCharCode(int code, bool needpic) const // //========================================================================== -FTexture *FFont::GetChar (int code, int translation, int *const width, bool *redirected) const +FGameTexture *FFont::GetChar (int code, int translation, int *const width, bool *redirected) const { code = GetCharCode(code, true); int xmove = SpaceWidth; @@ -1007,12 +1002,12 @@ FTexture *FFont::GetChar (int code, int translation, int *const width, bool *red if (redirect) { assert(Chars[code].OriginalPic->UseType == ETextureType::FontChar); - return Chars[code].OriginalPic; + return reinterpret_cast(Chars[code].OriginalPic); } } if (redirected) *redirected = false; assert(Chars[code].TranslatedPic->UseType == ETextureType::FontChar); - return Chars[code].TranslatedPic; + return reinterpret_cast(Chars[code].TranslatedPic); } //========================================================================== @@ -1037,11 +1032,11 @@ int FFont::GetCharWidth (int code) const double GetBottomAlignOffset(FFont *font, int c) { int w; - FTexture *tex_zero = font->GetChar('0', CR_UNDEFINED, &w); - FTexture *texc = font->GetChar(c, CR_UNDEFINED, &w); + auto tex_zero = font->GetChar('0', CR_UNDEFINED, &w); + auto texc = font->GetChar(c, CR_UNDEFINED, &w); double offset = 0; - if (texc) offset += texc->GetDisplayTopOffsetDouble(); - if (tex_zero) offset += -tex_zero->GetDisplayTopOffsetDouble() + tex_zero->GetDisplayHeightDouble(); + if (texc) offset += texc->GetDisplayTopOffset(); + if (tex_zero) offset += -tex_zero->GetDisplayTopOffset() + tex_zero->GetDisplayHeight(); return offset; } diff --git a/src/common/fonts/singlepicfont.cpp b/src/common/fonts/singlepicfont.cpp index 8d289944db..f54c3117ee 100644 --- a/src/common/fonts/singlepicfont.cpp +++ b/src/common/fonts/singlepicfont.cpp @@ -45,7 +45,7 @@ public: FSinglePicFont(const char *picname); // FFont interface - FTexture *GetChar(int code, int translation, int *const width, bool *redirected = nullptr) const override; + FGameTexture *GetChar(int code, int translation, int *const width, bool *redirected = nullptr) const override; int GetCharWidth (int code) const; protected: @@ -94,13 +94,13 @@ FSinglePicFont::FSinglePicFont(const char *picname) : // //========================================================================== -FTexture *FSinglePicFont::GetChar (int code, int translation, int *const width, bool *redirected) const +FGameTexture *FSinglePicFont::GetChar (int code, int translation, int *const width, bool *redirected) const { *width = SpaceWidth; if (redirected) *redirected = false; if (code == 'a' || code == 'A') { - return TexMan.GetPalettedTexture(PicNum, true); + return TexMan.GetGameTexture(PicNum, true); } else { diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 71ba99ed75..b4d2c753b8 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -39,7 +39,7 @@ #include "name.h" class DCanvas; -class FTexture; +class FGameTexture; struct FRemapTable; enum EColorRange : int @@ -77,7 +77,7 @@ enum EColorRange : int extern int NumTextColors; -using GlyphSet = TMap; +using GlyphSet = TMap; class FFont { @@ -97,7 +97,7 @@ public: FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false, GlyphSet *baseGlpyphs = nullptr); virtual ~FFont (); - virtual FTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const; + virtual FGameTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const; virtual int GetCharWidth (int code) const; int GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const; int GetLump() const { return Lump; } diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 74cd685306..e9bbdf9daa 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -874,3 +874,4 @@ bool FGameTexture::isUserContent() const int filenum = fileSystem.GetFileContainer(wrapped.GetSourceLump()); return (filenum > fileSystem.GetMaxIwadNum()); } + diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 70717bb880..51ff8af04e 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -24,12 +24,11 @@ public: private: int ResolveLocalizedTexture(int texnum); - FTexture *InternalGetTexture(int texnum, bool animate, bool localize, bool palettesubst) + FTexture *InternalGetTexture(int texnum, bool animate, bool localize) { if ((unsigned)texnum >= Textures.Size()) return nullptr; if (animate) texnum = Translation[texnum]; if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum); - if (palettesubst) texnum = PalCheck(texnum); return Textures[texnum].Texture; } public: @@ -37,7 +36,7 @@ public: FTexture *GetTextureByName(const char *name, bool animate = false) { FTextureID texnum = GetTextureID (name, ETextureType::MiscPatch); - return InternalGetTexture(texnum.GetIndex(), animate, true, false); + return InternalGetTexture(texnum.GetIndex(), animate, true); } FGameTexture* GetGameTextureByName(const char *name, bool animate = false) @@ -47,23 +46,17 @@ public: FTexture *GetTexture(FTextureID texnum, bool animate = false) { - return InternalGetTexture(texnum.GetIndex(), animate, true, false); + return InternalGetTexture(texnum.GetIndex(), animate, true); } FGameTexture* GetGameTexture(FTextureID texnum, bool animate = false) { return reinterpret_cast(GetTexture(texnum, animate)); } - - // This is the only access function that should be used inside the software renderer. - FTexture *GetPalettedTexture(FTextureID texnum, bool animate) - { - return InternalGetTexture(texnum.GetIndex(), animate, true, true); - } FTexture *ByIndex(int i, bool animate = false) { - return InternalGetTexture(i, animate, true, false); + return InternalGetTexture(i, animate, true); } FGameTexture* GameByIndex(int i, bool animate = false) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index d889f97e13..d6b4a4eb62 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -438,6 +438,7 @@ protected: virtual void ResolvePatches() {} +public: void SetScale(const DVector2 &scale) { Scale = scale; @@ -589,17 +590,24 @@ public: bool isValid() { return wrapped.isValid(); } bool isWarped() { return wrapped.isWarped(); } + bool isHardwareCanvas() const { return wrapped.isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. + bool isSoftwareCanvas() const { return wrapped.isCanvas(); } bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. bool useWorldPanning() { return wrapped.UseWorldPanning(); } + ETextureType GetUseType() const { return wrapped.GetUseType(); } float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped.GetRotations(); } int GetSkyOffset() const { return wrapped.GetSkyOffset(); } FTextureID GetID() const { return wrapped.GetID(); } ISoftwareTexture* GetSoftwareTexture() { return wrapped.GetSoftwareTexture(); } void SetSoftwareTexture(ISoftwareTexture* swtex) { wrapped.SetSoftwareTextue(swtex); } + void SetScale(DVector2 vec) { wrapped.SetScale(vec); } + + // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. + FGameTexture* GetPalVersion() { return reinterpret_cast(wrapped.GetPalVersion()); } + FGameTexture* GetRawTexture() { return reinterpret_cast(wrapped.GetRawTexture()); } bool isUserContent() const; - }; diff --git a/src/d_main.cpp b/src/d_main.cpp index 0e9f269d1a..5d7b5f6122 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2724,28 +2724,12 @@ static void CheckForHacks(BuildInfo& buildinfo) } } -CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL) -{ - // This is in case the sky texture has been substituted. - R_InitSkyMap(); -} - //========================================================================== // -// FTextureManager :: PalCheck taken out of the texture manager because it ties it to other subsystems -// todo: move elsewhere +// // //========================================================================== -int PalCheck(int tex) -{ - // In any true color mode this shouldn't do anything. - if (vid_nopalsubstitutions || V_IsTrueColor()) return tex; - FTexture *ftex = TexMan.ByIndex(tex); - if (ftex != nullptr && ftex->GetPalVersion() != nullptr) return ftex->GetPalVersion()->GetID().GetIndex(); - return tex; -} - static void Doom_CastSpriteIDToString(FString* a, unsigned int b) { *a = (b >= sprites.Size()) ? "TNT1" : sprites[b].name; diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index 1c380184aa..06427abd62 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -1464,7 +1464,7 @@ public: DTA_Alpha, Alpha, TAG_DONE); if (script->spacingCharacter == '\0') - ax += width + spacing - (c->GetDisplayLeftOffsetDouble() + 1); + ax += width + spacing - (c->GetDisplayLeftOffset() + 1); else //width gets changed at the call to GetChar() ax += font->GetCharWidth((unsigned char) script->spacingCharacter) + spacing; } diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index be653faba0..20d1148db4 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1796,7 +1796,7 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d dx = monospaced ? spacing - : width + spacing - (c->GetDisplayLeftOffsetDouble() + 1); + : width + spacing - (c->GetDisplayLeftOffset() + 1); // Take text scale into account x += dx * scaleX; diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index b2ce4a5b27..be331a3a14 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -220,7 +220,7 @@ void DIntermissionScreen::Drawer () } else { - twod->AddFlatFill(0,0, twod->GetWidth(), twod->GetHeight(), TexMan.GetTexture(mBackground)); + twod->AddFlatFill(0,0, twod->GetWidth(), twod->GetHeight(), TexMan.GetGameTexture(mBackground)); } } else @@ -365,7 +365,7 @@ void DIntermissionScreenText::Drawer () Super::Drawer(); if (mTicker >= mTextDelay) { - FTexture *pic; + FGameTexture *pic; int w; size_t count; int c; diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index 5a5b18c295..ea07419bfc 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -164,7 +164,7 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) if (cmd.mTexture != nullptr) { - auto mat = FMaterial::ValidateTexture(cmd.mTexture, false); + auto mat = FMaterial::ValidateTexture(cmd.mTexture->GetTexture(), false); if (mat == nullptr) continue; state.SetMaterial(mat, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); diff --git a/src/rendering/swrenderer/line/r_walldraw.h b/src/rendering/swrenderer/line/r_walldraw.h index 250f0de27c..3db272807a 100644 --- a/src/rendering/swrenderer/line/r_walldraw.h +++ b/src/rendering/swrenderer/line/r_walldraw.h @@ -25,7 +25,6 @@ #include "swrenderer/viewport/r_walldrawer.h" #include "r_line.h" -class FTexture; struct FLightNode; struct seg_t; struct FLightNode; diff --git a/src/rendering/swrenderer/r_renderer.h b/src/rendering/swrenderer/r_renderer.h index a8c84c1684..2ad6c79004 100644 --- a/src/rendering/swrenderer/r_renderer.h +++ b/src/rendering/swrenderer/r_renderer.h @@ -7,7 +7,6 @@ struct FRenderer; extern FRenderer *SWRenderer; class FSerializer; -class FTexture; class AActor; class player_t; struct sector_t; diff --git a/src/rendering/swrenderer/r_swrenderer.cpp b/src/rendering/swrenderer/r_swrenderer.cpp index 4f91447cef..d01d89242d 100644 --- a/src/rendering/swrenderer/r_swrenderer.cpp +++ b/src/rendering/swrenderer/r_swrenderer.cpp @@ -86,7 +86,7 @@ void FSoftwareRenderer::PreparePrecache(FGameTexture *ttex, int cache) { bool isbgra = V_IsTrueColor(); - if (ttex != nullptr && ttex->isValid() && !ttex->GetTexture()->isCanvas()) + if (ttex != nullptr && ttex->isValid() && !ttex->isSoftwareCanvas()) { FSoftwareTexture *tex = GetSoftwareTexture(ttex); @@ -105,7 +105,7 @@ void FSoftwareRenderer::PrecacheTexture(FGameTexture *ttex, int cache) { bool isbgra = V_IsTrueColor(); - if (ttex != nullptr && ttex->isValid() && !ttex->GetTexture()->isCanvas()) + if (ttex != nullptr && ttex->isValid() && !ttex->isSoftwareCanvas()) { FSoftwareTexture *tex = GetSoftwareTexture(ttex); if (cache & FTextureManager::HIT_Columnmode) diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index 676ed73138..a71015c45d 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -597,8 +597,7 @@ FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex) FSoftwareTexture* SoftwareTexture = static_cast(tex->GetSoftwareTexture()); if (!SoftwareTexture) { - auto source = tex->GetTexture(); - if (source->isCanvas()) SoftwareTexture = new FSWCanvasTexture(tex); + if (tex->isSoftwareCanvas()) SoftwareTexture = new FSWCanvasTexture(tex); else if (tex->isWarped()) SoftwareTexture = new FWarpTexture(tex, tex->isWarped()); else SoftwareTexture = new FSoftwareTexture(tex); tex->SetSoftwareTexture(SoftwareTexture); @@ -606,14 +605,30 @@ FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex) return SoftwareTexture; } + +CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL) +{ + // This is in case the sky texture has been substituted. + R_InitSkyMap(); +} + +static FGameTexture* PalCheck(FGameTexture* tex) +{ + // In any true color mode this shouldn't do anything. + if (vid_nopalsubstitutions || V_IsTrueColor() || tex == nullptr) return tex; + auto palvers = tex->GetPalVersion(); + if (palvers) return palvers; + return tex; +} + FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull) { - auto tex = TexMan.GetPalettedTexture(texid, true); + auto tex = PalCheck(TexMan.GetGameTexture(texid, true)); if (checkcompat && tex && tex->isValid() && checkcompat->i_compatflags & COMPATF_MASKEDMIDTEX) { tex = tex->GetRawTexture(); } - FSoftwareTexture* pic = tex && (allownull || tex->isValid()) ? GetSoftwareTexture(reinterpret_cast(tex)) : nullptr; + FSoftwareTexture* pic = tex && (allownull || tex->isValid()) ? GetSoftwareTexture(tex) : nullptr; return pic; } From b9b6a354c78bcdf038f8e84ce6b6fdeec958977e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 18:01:51 +0200 Subject: [PATCH 013/220] - changed all texture access in the play code to use FGameTexture and redid Hexen's front sky layer by adding a new texture instead of hacking the existing one. --- src/common/textures/texture.cpp | 29 +++++++++++++++++++ src/common/textures/textures.h | 20 ++++++++++--- src/d_main.cpp | 16 ---------- src/g_dumpinfo.cpp | 2 +- src/gamedata/textures/animations.cpp | 20 +------------ src/hu_scores.cpp | 6 ++-- src/playsim/a_decals.cpp | 8 ++--- src/playsim/fragglescript/t_func.cpp | 4 +-- src/playsim/mapthinkers/a_doors.cpp | 4 +-- src/playsim/p_3dmidtex.cpp | 2 +- src/playsim/p_acs.cpp | 2 +- src/playsim/p_sectors.cpp | 14 ++++----- src/r_data/sprites.cpp | 4 +-- src/rendering/hwrenderer/scene/hw_sky.cpp | 4 ++- src/rendering/r_sky.cpp | 14 +++++---- src/rendering/swrenderer/plane/r_skyplane.cpp | 2 +- .../swrenderer/textures/r_swtexture.cpp | 12 +++++--- .../swrenderer/textures/r_swtexture.h | 2 +- src/rendering/v_video.h | 2 -- src/wi_stuff.h | 1 - 20 files changed, 91 insertions(+), 77 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index e9bbdf9daa..eeed137ea6 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -214,6 +214,31 @@ FTexture *FTexture::GetRawTexture() return OffsetLess; } +//========================================================================== +// +// Same shit for a different hack, this time Hexen's front sky layers. +// +//========================================================================== + +FTexture* FTexture::GetFrontSkyLayer() +{ + if (FrontSkyLayer) return FrontSkyLayer; + // Reject anything that cannot have been a front layer for the sky in Hexen. + auto image = GetImage(); + if (image == nullptr || !image->SupportRemap0() || UseType != ETextureType::Wall || Scale.X != 1 || Scale.Y != 1 || bWorldPanning || _TopOffset[0] != 0 || + image->GetWidth() != GetTexelWidth() || image->GetHeight() != GetTexelHeight()) + { + FrontSkyLayer = this; + return this; + } + + FrontSkyLayer = new FImageTexture(image, ""); + TexMan.AddTexture(FrontSkyLayer); + FrontSkyLayer->bNoRemap0 = true; + return FrontSkyLayer; +} + + void FTexture::SetDisplaySize(int fitwidth, int fitheight) { Scale.X = double(Width) / fitwidth; @@ -849,6 +874,10 @@ void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y, bool forcewo mWidth = tex->GetTexelWidth(); } +void FTexCoordInfo::GetFromTexture(FGameTexture* tex, float x, float y, bool forceworldpanning) +{ + GetFromTexture(tex->GetTexture(), x, y, forceworldpanning); +} //========================================================================== // diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index d6b4a4eb62..43ec16da19 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -48,6 +48,7 @@ typedef TMap SpriteHits; class FImageSource; +class FGameTexture; enum MaterialShaderIndex { @@ -263,7 +264,8 @@ public: int GetDisplayTopOffset() { return GetScaledTopOffset(0); } double GetDisplayLeftOffsetDouble(int adjusted = 0) { return _LeftOffset[adjusted] / Scale.X; } double GetDisplayTopOffsetDouble(int adjusted = 0) { return _TopOffset[adjusted] / Scale.Y; } - + FTexture* GetFrontSkyLayer(); + int GetTexelWidth() { return Width; } int GetTexelHeight() { return Height; } int GetTexelLeftOffset(int adjusted) { return _LeftOffset[adjusted]; } @@ -308,8 +310,6 @@ public: bool UseWorldPanning() const { return bWorldPanning; } void SetWorldPanning(bool on) { bWorldPanning = on; } void SetDisplaySize(int fitwidth, int fitheight); - void SetFrontSkyLayer(bool on = true) { bNoRemap0 = on; } - bool IsFrontSkyLayer() { return bNoRemap0; } void CopySize(FTexture* BaseTexture) @@ -365,6 +365,8 @@ protected: // Offset-less version for COMPATF_MASKEDMIDTEX FTexture *OffsetLess = nullptr; + // Front sky layer variant where color 0 is transparent + FTexture* FrontSkyLayer = nullptr; // Paletted variant FTexture *PalVersion = nullptr; // Material layers @@ -570,6 +572,7 @@ struct FTexCoordInfo float TextureOffset(float ofs) const; float TextureAdjustWidth() const; void GetFromTexture(FTexture *tex, float x, float y, bool forceworldpanning); + void GetFromTexture(FGameTexture* tex, float x, float y, bool forceworldpanning); }; // Refactoring helper to allow piece by piece adjustment of the API @@ -593,7 +596,8 @@ public: bool isHardwareCanvas() const { return wrapped.isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isSoftwareCanvas() const { return wrapped.isCanvas(); } bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. - bool useWorldPanning() { return wrapped.UseWorldPanning(); } + bool useWorldPanning() const { return wrapped.UseWorldPanning(); } + bool allowNoDecals() const { return wrapped.allowNoDecals(); } ETextureType GetUseType() const { return wrapped.GetUseType(); } float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped.GetRotations(); } @@ -602,10 +606,18 @@ public: ISoftwareTexture* GetSoftwareTexture() { return wrapped.GetSoftwareTexture(); } void SetSoftwareTexture(ISoftwareTexture* swtex) { wrapped.SetSoftwareTextue(swtex); } void SetScale(DVector2 vec) { wrapped.SetScale(vec); } + const FString& GetName() const { return wrapped.GetName(); } // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. FGameTexture* GetPalVersion() { return reinterpret_cast(wrapped.GetPalVersion()); } FGameTexture* GetRawTexture() { return reinterpret_cast(wrapped.GetRawTexture()); } + FGameTexture* GetFrontSkyLayer() { return reinterpret_cast(wrapped.GetFrontSkyLayer()); } + + // Glowing is a pure material property that should not filter down to the actual texture objects. + void GetGlowColor(float* data) { wrapped.GetGlowColor(data); } + bool isGlowing() const { return wrapped.isGlowing(); } + bool isAutoGlowing() const { return wrapped.isAutoGlowing(); } + int GetGlowHeight() const { return wrapped.GetGlowHeight(); } bool isUserContent() const; }; diff --git a/src/d_main.cpp b/src/d_main.cpp index 5d7b5f6122..554ad1a8e3 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2646,22 +2646,6 @@ static void PatchTextures() texture->SetUseType(ETextureType::Null); } } - - // Hexen parallax skies use color 0 to indicate transparency on the front - // layer, so we must not remap color 0 on these textures. Unfortunately, - // the only way to identify these textures is to check the MAPINFO. - for (unsigned int i = 0; i < wadlevelinfos.Size(); ++i) - { - if (wadlevelinfos[i].flags & LEVEL_DOUBLESKY) - { - FTextureID picnum = TexMan.CheckForTexture(wadlevelinfos[i].SkyPic1, ETextureType::Wall, false); - if (picnum.isValid()) - { - TexMan.GetTexture(picnum)->SetFrontSkyLayer(); - } - } - } - } //========================================================================== diff --git a/src/g_dumpinfo.cpp b/src/g_dumpinfo.cpp index 01f19b46bb..358593583a 100644 --- a/src/g_dumpinfo.cpp +++ b/src/g_dumpinfo.cpp @@ -75,7 +75,7 @@ CCMD(listlights) if (dl->target) { FTextureID spr = sprites[dl->target->sprite].GetSpriteFrame(dl->target->frame, 0, 0., nullptr); - Printf(", frame = %s ", TexMan.GetTexture(spr)->GetName().GetChars()); + Printf(", frame = %s ", TexMan.GetGameTexture(spr)->GetName().GetChars()); } diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index 9fb56efc6a..e45a594e1b 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -772,17 +772,7 @@ void FTextureAnimator::FixAnimations () for (i = 0; i < mAnimations.Size(); ++i) { FAnimDef *anim = mAnimations[i]; - if (anim->bDiscrete) - { - if (TexMan.Texture(anim->BasePic)->IsFrontSkyLayer()) - { - for (j = 0; j < anim->NumFrames; ++j) - { - TexMan.Texture(anim->Frames[j].FramePic)->SetFrontSkyLayer (); - } - } - } - else + if (!anim->bDiscrete) { bool nodecals; bool noremap = false; @@ -793,16 +783,8 @@ void FTextureAnimator::FixAnimations () for (j = 0; j < anim->NumFrames; ++j) { FTexture *tex = TexMan.Texture(anim->BasePic + j); - noremap |= tex->IsFrontSkyLayer(); tex->SetNoDecals(nodecals); } - if (noremap) - { - for (j = 0; j < anim->NumFrames; ++j) - { - TexMan.Texture(anim->BasePic + j)->SetFrontSkyLayer (); - } - } } } } diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index d393cfb4d2..5305440ef0 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -219,15 +219,15 @@ void HU_GetPlayerWidths(int &maxnamewidth, int &maxscorewidth, int &maxiconheigh auto icon = FSetTextureID(players[i].mo->IntVar(NAME_ScoreIcon)); if (icon.isValid()) { - FTexture *pic = TexMan.GetTexture(icon); - width = pic->GetDisplayWidth() - pic->GetDisplayLeftOffset() + 2; + auto pic = TexMan.GetGameTexture(icon); + width = int(pic->GetDisplayWidth() - pic->GetDisplayLeftOffset() + 2.5); if (width > maxscorewidth) { maxscorewidth = width; } // The icon's top offset does not count toward its height, because // zdoom.pk3's standard Hexen class icons are designed that way. - int height = pic->GetDisplayHeight() - pic->GetDisplayTopOffset(); + int height = int(pic->GetDisplayHeight() - pic->GetDisplayTopOffset() + 0.5); if (height > maxiconheight) { maxiconheight = height; diff --git a/src/playsim/a_decals.cpp b/src/playsim/a_decals.cpp index fc712a5d85..f3faa488f8 100644 --- a/src/playsim/a_decals.cpp +++ b/src/playsim/a_decals.cpp @@ -341,7 +341,7 @@ FTextureID DBaseDecal::StickToWall (side_t *wall, double x, double y, F3DFloor * else return FNullTextureID(); CalcFracPos (wall, x, y); - FTexture *texture = TexMan.GetTexture(tex); + auto texture = TexMan.GetGameTexture(tex); if (texture == NULL || texture->allowNoDecals()) { @@ -613,19 +613,19 @@ void DBaseDecal::SpreadRight (double r, side_t *feelwall, double wallsize, F3DFl void DBaseDecal::Spread (const FDecalTemplate *tpl, side_t *wall, double x, double y, double z, F3DFloor * ffloor) { SpreadInfo spread; - FTexture *tex; + FGameTexture *tex; vertex_t *v1; double rorg, ldx, ldy; GetWallStuff (wall, v1, ldx, ldy); rorg = Length (x - v1->fX(), y - v1->fY()); - if ((tex = TexMan.GetTexture(PicNum)) == NULL) + if ((tex = TexMan.GetGameTexture(PicNum)) == NULL) { return; } - int dwidth = tex->GetDisplayWidth (); + double dwidth = tex->GetDisplayWidth (); spread.DecalWidth = dwidth * ScaleX; spread.DecalLeft = tex->GetDisplayLeftOffset() * ScaleX; diff --git a/src/playsim/fragglescript/t_func.cpp b/src/playsim/fragglescript/t_func.cpp index 277263854c..c2df2c6595 100644 --- a/src/playsim/fragglescript/t_func.cpp +++ b/src/playsim/fragglescript/t_func.cpp @@ -1878,7 +1878,7 @@ void FParser::SF_FloorTexture(void) } t_return.type = svt_string; - FTexture * tex = TexMan.GetTexture(sector->GetTexture(sector_t::floor)); + auto tex = TexMan.GetGameTexture(sector->GetTexture(sector_t::floor)); t_return.string = tex? tex->GetName() : ""; } } @@ -1968,7 +1968,7 @@ void FParser::SF_CeilingTexture(void) } t_return.type = svt_string; - FTexture * tex = TexMan.GetTexture(sector->GetTexture(sector_t::ceiling)); + auto tex = TexMan.GetGameTexture(sector->GetTexture(sector_t::ceiling)); t_return.string = tex? tex->GetName() : ""; } } diff --git a/src/playsim/mapthinkers/a_doors.cpp b/src/playsim/mapthinkers/a_doors.cpp index 4f57770ce8..fda4178f73 100644 --- a/src/playsim/mapthinkers/a_doors.cpp +++ b/src/playsim/mapthinkers/a_doors.cpp @@ -291,7 +291,7 @@ void DDoor::DoorSound(bool raise, DSeqNode *curseq) const if (line->backsector == NULL) continue; - FTexture *tex = TexMan.GetTexture(line->sidedef[0]->GetTexture(side_t::top)); + auto tex = TexMan.GetGameTexture(line->sidedef[0]->GetTexture(side_t::top)); texname = tex ? tex->GetName().GetChars() : NULL; if (texname != NULL && texname[0] == 'D' && texname[1] == 'O' && texname[2] == 'R') { @@ -716,7 +716,7 @@ void DAnimatedDoor::Construct(sector_t *sec, line_t *line, int speed, int delay, picnum = tex1[side_t::top].texture; - FTexture *tex = TexMan.GetTexture(picnum); + auto tex = TexMan.GetGameTexture(picnum); topdist = tex ? tex->GetDisplayHeight() : 64; topdist = m_Sector->ceilingplane.fD() - topdist * m_Sector->ceilingplane.fC(); diff --git a/src/playsim/p_3dmidtex.cpp b/src/playsim/p_3dmidtex.cpp index bf46a5ed93..5d764d4e0c 100644 --- a/src/playsim/p_3dmidtex.cpp +++ b/src/playsim/p_3dmidtex.cpp @@ -231,7 +231,7 @@ bool P_GetMidTexturePosition(const line_t *line, int sideno, double *ptextop, do side_t *side = line->sidedef[sideno]; FTextureID texnum = side->GetTexture(side_t::mid); if (!texnum.isValid()) return false; - FTexture * tex= TexMan.GetTexture(texnum, true); + FGameTexture * tex= TexMan.GetGameTexture(texnum, true); if (!tex) return false; FTexCoordInfo tci; diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index b3f0646dcf..b33a397b2f 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -6597,7 +6597,7 @@ doplaysound: if (funcIndex == ACSF_PlayActorSound) auto a = Level->SingleActorFromTID(args[0], activator); if (a != nullptr) { - return GlobalACSStrings.AddString(TexMan.GetTexture(a->floorpic)->GetName()); + return GlobalACSStrings.AddString(TexMan.GetGameTexture(a->floorpic)->GetName()); } else { diff --git a/src/playsim/p_sectors.cpp b/src/playsim/p_sectors.cpp index d7a1a12bd9..ae967d2c06 100644 --- a/src/playsim/p_sectors.cpp +++ b/src/playsim/p_sectors.cpp @@ -489,7 +489,7 @@ static inline void CheckShortestTex (FLevelLocals *Level, FTextureID texnum, dou { if (texnum.isValid() || (texnum.isNull() && (Level->i_compatflags & COMPATF_SHORTTEX))) { - FTexture *tex = TexMan.GetTexture(texnum); + auto tex = TexMan.GetGameTexture(texnum); if (tex != NULL) { double h = tex->GetDisplayHeight(); @@ -1156,10 +1156,10 @@ double GetFriction(const sector_t *self, int plane, double *pMoveFac) auto c = planes[sector_t::floor].GlowColor; if (c == 0) { - FTexture *tex = TexMan.GetTexture(GetTexture(sector_t::floor)); + auto tex = TexMan.GetGameTexture(GetTexture(sector_t::floor)); if (tex != NULL && tex->isGlowing()) { - if (!tex->isAutoGlowing()) tex = TexMan.GetTexture(GetTexture(sector_t::floor), true); + if (!tex->isAutoGlowing()) tex = TexMan.GetGameTexture(GetTexture(sector_t::floor), true); if (tex->isGlowing()) // recheck the current animation frame. { tex->GetGlowColor(bottomglowcolor); @@ -1201,10 +1201,10 @@ double GetFriction(const sector_t *self, int plane, double *pMoveFac) auto c = planes[sector_t::ceiling].GlowColor; if (c == 0) { - FTexture *tex = TexMan.GetTexture(GetTexture(sector_t::ceiling)); + auto tex = TexMan.GetGameTexture(GetTexture(sector_t::ceiling)); if (tex != NULL && tex->isGlowing()) { - if (!tex->isAutoGlowing()) tex = TexMan.GetTexture(GetTexture(sector_t::ceiling), true); + if (!tex->isAutoGlowing()) tex = TexMan.GetGameTexture(GetTexture(sector_t::ceiling), true); if (tex->isGlowing()) // recheck the current animation frame. { ret = true; @@ -1225,10 +1225,10 @@ double GetFriction(const sector_t *self, int plane, double *pMoveFac) c = planes[sector_t::floor].GlowColor; if (c == 0) { - FTexture *tex = TexMan.GetTexture(GetTexture(sector_t::floor)); + auto tex = TexMan.GetGameTexture(GetTexture(sector_t::floor)); if (tex != NULL && tex->isGlowing()) { - if (!tex->isAutoGlowing()) tex = TexMan.GetTexture(GetTexture(sector_t::floor), true); + if (!tex->isAutoGlowing()) tex = TexMan.GetGameTexture(GetTexture(sector_t::floor), true); if (tex->isGlowing()) // recheck the current animation frame. { ret = true; diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index 4318660512..dc06498fed 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -333,7 +333,7 @@ void R_InitSpriteDefs () memset(hashes.Data(), -1, sizeof(Hasher)*smax); for (i = 0; i < smax; ++i) { - FTexture *tex = TexMan.ByIndex(i); + auto tex = TexMan.GameByIndex(i); if (tex->GetUseType() == ETextureType::Sprite && strlen(tex->GetName()) >= 6) { size_t bucket = TEX_DWNAME(tex) % smax; @@ -415,7 +415,7 @@ void R_InitSpriteDefs () int hash = hashes[intname % smax].Head; while (hash != -1) { - FTexture *tex = TexMan.GetTexture(hash); + auto tex = TexMan.GetGameTexture(hash); if (TEX_DWNAME(tex) == intname) { bool res = R_InstallSpriteLump (FTextureID(hash), tex->GetName()[4] - 'A', tex->GetName()[5], false, sprtemp, maxframe); diff --git a/src/rendering/hwrenderer/scene/hw_sky.cpp b/src/rendering/hwrenderer/scene/hw_sky.cpp index 1461028281..91218d0b74 100644 --- a/src/rendering/hwrenderer/scene/hw_sky.cpp +++ b/src/rendering/hwrenderer/scene/hw_sky.cpp @@ -74,7 +74,9 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) normalsky: if (di->Level->flags&LEVEL_DOUBLESKY) { - texture[1] = FMaterial::ValidateTexture(di->Level->skytexture1, false, true); + auto tex1 = TexMan.GetTexture(di->Level->skytexture1, true); + if (tex1) tex1 = tex1->GetFrontSkyLayer(); + texture[1] = FMaterial::ValidateTexture(tex1, false); x_offset[1] = di->Level->hw_sky1pos; doublesky = true; } diff --git a/src/rendering/r_sky.cpp b/src/rendering/r_sky.cpp index b3813e3244..b51a447837 100644 --- a/src/rendering/r_sky.cpp +++ b/src/rendering/r_sky.cpp @@ -64,8 +64,7 @@ CVAR(Float, skyoffset, 0, 0) // for testing void InitSkyMap(FLevelLocals *Level) { - int skyheight; - FTexture *skytex1, *skytex2; + FGameTexture *skytex1, *skytex2; // Do not allow the null texture which has no bitmap and will crash. if (Level->skytexture1.isNull()) @@ -77,12 +76,17 @@ void InitSkyMap(FLevelLocals *Level) Level->skytexture2 = TexMan.CheckForTexture("-noflat-", ETextureType::Any); } - skytex1 = TexMan.GetTexture(Level->skytexture1, false); - skytex2 = TexMan.GetTexture(Level->skytexture2, false); + skytex1 = TexMan.GetGameTexture(Level->skytexture1, false); + skytex2 = TexMan.GetGameTexture(Level->skytexture2, false); if (skytex1 == nullptr) return; + if (Level->flags & LEVEL_DOUBLESKY) + { + skytex1 = skytex1->GetFrontSkyLayer(); + } + if ((Level->flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight()) { Printf(TEXTCOLOR_BOLD "Both sky textures must be the same height." TEXTCOLOR_NORMAL "\n"); @@ -103,7 +107,7 @@ void InitSkyMap(FLevelLocals *Level) // the screen when looking fully up. // h > 200: Unstretched, but the baseline is shifted down so that the top // of the texture is at the top of the screen when looking fully up. - skyheight = skytex1->GetDisplayHeight(); + auto skyheight = skytex1->GetDisplayHeight(); Level->skystretch = (r_skymode == 1 && skyheight >= 128 && skyheight <= 256 diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 5b9b60c4cc..7276aa6047 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -71,7 +71,7 @@ namespace swrenderer Thread = thread; auto Level = Thread->Viewport->Level(); - auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true); + auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true, !!(Level->flags & LEVEL_DOUBLESKY)); auto sskytex2 = GetPalettedSWTexture(Level->skytexture2, true, nullptr, true); if (sskytex1 == nullptr) diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index a71015c45d..c501f4df00 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -621,14 +621,18 @@ static FGameTexture* PalCheck(FGameTexture* tex) return tex; } -FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull) +FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull, bool frontsky) { auto tex = PalCheck(TexMan.GetGameTexture(texid, true)); - if (checkcompat && tex && tex->isValid() && checkcompat->i_compatflags & COMPATF_MASKEDMIDTEX) + if (tex == nullptr || (!allownull && !tex->isValid())) return nullptr; + if (frontsky) + { + tex = tex->GetFrontSkyLayer(); + } + else if (checkcompat && checkcompat->i_compatflags & COMPATF_MASKEDMIDTEX) { tex = tex->GetRawTexture(); } - FSoftwareTexture* pic = tex && (allownull || tex->isValid()) ? GetSoftwareTexture(tex) : nullptr; - return pic; + return GetSoftwareTexture(tex); } diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index 7ea9ba34fd..595acbd773 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -193,4 +193,4 @@ public: }; FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex); -FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat = nullptr, bool allownull = false); +FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat = nullptr, bool allownull = false, bool frontsky = false); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index bcd81d405a..080aed555a 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -56,7 +56,6 @@ static const int VID_MIN_UI_HEIGHT = 400; class player_t; struct sector_t; -class FTexture; struct FPortalSceneState; class FSkyVertexBuffer; class IIndexBuffer; @@ -148,7 +147,6 @@ inline bool V_IsTrueColor() } -class FTexture; struct FColormap; class FileWriter; enum FTextureFormat : uint32_t; diff --git a/src/wi_stuff.h b/src/wi_stuff.h index d9f089c857..78b591d282 100644 --- a/src/wi_stuff.h +++ b/src/wi_stuff.h @@ -29,7 +29,6 @@ #include "doomdef.h" -class FTexture; struct FLevelLocals; // From 54f4267597a0a3628e7d5020491ddb1169890a9b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 18:02:48 +0200 Subject: [PATCH 014/220] - use FGameTexture in the model rendering code. --- src/common/textures/textures.h | 1 + src/r_data/models/models.cpp | 2 +- src/r_data/models/models.h | 10 +++++----- src/r_data/models/models_md2.cpp | 4 ++-- src/r_data/models/models_md3.cpp | 8 ++++---- src/r_data/models/models_obj.cpp | 8 ++++---- src/r_data/models/models_obj.h | 2 +- src/r_data/models/models_ue1.cpp | 6 +++--- src/r_data/models/models_ue1.h | 2 +- src/r_data/models/models_voxel.cpp | 2 +- src/r_data/sprites.cpp | 4 ++-- src/rendering/hwrenderer/models/hw_models.cpp | 4 ++-- src/rendering/hwrenderer/models/hw_models.h | 2 +- 13 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 43ec16da19..d12f5582bc 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -601,6 +601,7 @@ public: ETextureType GetUseType() const { return wrapped.GetUseType(); } float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped.GetRotations(); } + void SetRotations(int index) { wrapped.SetRotations(index); } int GetSkyOffset() const { return wrapped.GetSkyOffset(); } FTextureID GetID() const { return wrapped.GetID(); } ISoftwareTexture* GetSoftwareTexture() { return wrapped.GetSoftwareTexture(); } diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 21eaec7aea..92a5ad34e3 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -269,7 +269,7 @@ void FModelRenderer::RenderFrameModels(FLevelLocals *Level, const FSpriteModelFr if (smf->modelIDs[i] != -1) { FModel * mdl = Models[smf->modelIDs[i]]; - FTexture *tex = smf->skinIDs[i].isValid() ? TexMan.GetTexture(smf->skinIDs[i], true) : nullptr; + auto tex = smf->skinIDs[i].isValid() ? TexMan.GetGameTexture(smf->skinIDs[i], true) : nullptr; mdl->BuildVertexBuffer(this); mdl->PushSpriteMDLFrame(smf, i); diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index b9a41039c0..e6c30323fb 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -77,7 +77,7 @@ public: virtual void EndDrawHUDModel(AActor *actor) = 0; virtual void SetInterpolation(double interpolation) = 0; - virtual void SetMaterial(FTexture *skin, bool clampNoFilter, int translation) = 0; + virtual void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) = 0; virtual void DrawArrays(int start, int count) = 0; virtual void DrawElements(int numIndices, size_t offset) = 0; @@ -136,7 +136,7 @@ public: virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0; virtual int FindFrame(const char * name) = 0; - virtual void RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0; virtual void AddSkins(uint8_t *hitlist) = 0; virtual float getAspectFactor(FLevelLocals *) { return 1.f; } @@ -263,7 +263,7 @@ public: virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame, int frame2, double inter, int translation=0); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); virtual void LoadGeometry(); virtual void AddSkins(uint8_t *hitlist); @@ -349,7 +349,7 @@ public: virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame, int frame2, double inter, int translation=0); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); void LoadGeometry(); void BuildVertexBuffer(FModelRenderer *renderer); virtual void AddSkins(uint8_t *hitlist); @@ -404,7 +404,7 @@ public: bool Load(const char * fn, int lumpnum, const char * buffer, int length); void Initialize(); virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame, int frame2, double inter, int translation=0); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); virtual void AddSkins(uint8_t *hitlist); FTextureID GetPaletteTexture() const { return mPalette; } void BuildVertexBuffer(FModelRenderer *renderer); diff --git a/src/r_data/models/models_md2.cpp b/src/r_data/models/models_md2.cpp index a27d079e40..31387f000a 100644 --- a/src/r_data/models/models_md2.cpp +++ b/src/r_data/models/models_md2.cpp @@ -358,14 +358,14 @@ int FDMDModel::FindFrame(const char * name) // //=========================================================================== -void FDMDModel::RenderFrame(FModelRenderer *renderer, FTexture * skin, int frameno, int frameno2, double inter, int translation) +void FDMDModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation) { if (frameno >= info.numFrames || frameno2 >= info.numFrames) return; if (!skin) { if (info.numSkins == 0 || !skins[0].isValid()) return; - skin = TexMan.GetTexture(skins[0], true); + skin = TexMan.GetGameTexture(skins[0], true); if (!skin) return; } diff --git a/src/r_data/models/models_md3.cpp b/src/r_data/models/models_md3.cpp index e5e91463a3..b37b3df36f 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/r_data/models/models_md3.cpp @@ -342,7 +342,7 @@ int FMD3Model::FindFrame(const char * name) // //=========================================================================== -void FMD3Model::RenderFrame(FModelRenderer *renderer, FTexture * skin, int frameno, int frameno2, double inter, int translation) +void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation) { if ((unsigned)frameno >= Frames.Size() || (unsigned)frameno2 >= Frames.Size()) return; @@ -353,16 +353,16 @@ void FMD3Model::RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame // [BB] In case no skin is specified via MODELDEF, check if the MD3 has a skin for the current surface. // Note: Each surface may have a different skin. - FTexture *surfaceSkin = skin; + FGameTexture *surfaceSkin = skin; if (!surfaceSkin) { if (curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) { - surfaceSkin = TexMan.GetTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i], true); + surfaceSkin = TexMan.GetGameTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i], true); } else if (surf->numSkins > 0 && surf->Skins[0].isValid()) { - surfaceSkin = TexMan.GetTexture(surf->Skins[0], true); + surfaceSkin = TexMan.GetGameTexture(surf->Skins[0], true); } if (!surfaceSkin) diff --git a/src/r_data/models/models_obj.cpp b/src/r_data/models/models_obj.cpp index 0c59b6875d..67c1106357 100644 --- a/src/r_data/models/models_obj.cpp +++ b/src/r_data/models/models_obj.cpp @@ -626,22 +626,22 @@ int FOBJModel::FindFrame(const char* name) * @param inter Unused * @param translation The translation for the skin */ -void FOBJModel::RenderFrame(FModelRenderer *renderer, FTexture * skin, int frameno, int frameno2, double inter, int translation) +void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frameno, int frameno2, double inter, int translation) { for (unsigned int i = 0; i < surfaces.Size(); i++) { OBJSurface *surf = &surfaces[i]; - FTexture *userSkin = skin; + FGameTexture *userSkin = skin; if (!userSkin) { if (i < MD3_MAX_SURFACES && curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i].isValid()) { - userSkin = TexMan.GetTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i], true); + userSkin = TexMan.GetGameTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][i], true); } else if (surf->skin.isValid()) { - userSkin = TexMan.GetTexture(surf->skin, true); + userSkin = TexMan.GetGameTexture(surf->skin, true); } } diff --git a/src/r_data/models/models_obj.h b/src/r_data/models/models_obj.h index 01a6e03cf2..c58c30a5ae 100644 --- a/src/r_data/models/models_obj.h +++ b/src/r_data/models/models_obj.h @@ -96,7 +96,7 @@ public: ~FOBJModel(); bool Load(const char* fn, int lumpnum, const char* buffer, int length) override; int FindFrame(const char* name) override; - void RenderFrame(FModelRenderer* renderer, FTexture* skin, int frame, int frame2, double inter, int translation=0) override; + void RenderFrame(FModelRenderer* renderer, FGameTexture* skin, int frame, int frame2, double inter, int translation=0) override; void BuildVertexBuffer(FModelRenderer* renderer) override; void AddSkins(uint8_t* hitlist) override; }; diff --git a/src/r_data/models/models_ue1.cpp b/src/r_data/models/models_ue1.cpp index e32aacdf2e..7d53798916 100644 --- a/src/r_data/models/models_ue1.cpp +++ b/src/r_data/models/models_ue1.cpp @@ -216,7 +216,7 @@ int FUE1Model::FindFrame( const char *name ) return -1; } -void FUE1Model::RenderFrame( FModelRenderer *renderer, FTexture *skin, int frame, int frame2, double inter, int translation ) +void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int frame, int frame2, double inter, int translation ) { // the moment of magic if ( (frame >= numFrames) || (frame2 >= numFrames) ) return; @@ -232,11 +232,11 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FTexture *skin, int frame vofs += vsize; continue; } - FTexture *sskin = skin; + FGameTexture *sskin = skin; if ( !sskin ) { if ( curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][groups[i].texNum].isValid() ) - sskin = TexMan.GetTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][groups[i].texNum], true); + sskin = TexMan.GetGameTexture(curSpriteMDLFrame->surfaceskinIDs[curMDLIndex][groups[i].texNum], true); if ( !sskin ) { vofs += vsize; diff --git a/src/r_data/models/models_ue1.h b/src/r_data/models/models_ue1.h index be9f57a10b..fb3c85483d 100644 --- a/src/r_data/models/models_ue1.h +++ b/src/r_data/models/models_ue1.h @@ -24,7 +24,7 @@ public: bool Load(const char * fn, int lumpnum, const char * buffer, int length) override; int FindFrame(const char * name) override; - void RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame, int frame2, double inter, int translation=0) override; + void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0) override; void BuildVertexBuffer(FModelRenderer *renderer) override; void AddSkins(uint8_t *hitlist) override; void LoadGeometry(); diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index e279c6c1bc..be123b3376 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -395,7 +395,7 @@ float FVoxelModel::getAspectFactor(FLevelLocals *Level) // //=========================================================================== -void FVoxelModel::RenderFrame(FModelRenderer *renderer, FTexture * skin, int frame, int frame2, double inter, int translation) +void FVoxelModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation) { renderer->SetMaterial(skin, true, translation); GetVertexBuffer(renderer)->SetupFrame(renderer, 0, 0, 0); diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index dc06498fed..6dfc34d969 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -123,7 +123,7 @@ static bool R_InstallSpriteLump (FTextureID lump, unsigned frame, char rot, bool if (frame >= MAX_SPRITE_FRAMES || rotation > 16) { - Printf (TEXTCOLOR_RED "R_InstallSpriteLump: Bad frame characters in lump %s\n", TexMan.GetTexture(lump)->GetName().GetChars()); + Printf (TEXTCOLOR_RED "R_InstallSpriteLump: Bad frame characters in lump %s\n", TexMan.GetGameTexture(lump)->GetName().GetChars()); return false; } @@ -287,7 +287,7 @@ void R_InstallSprite (int num, spriteframewithrotate *sprtemp, int &maxframe) { for (int rot = 0; rot < 16; ++rot) { - TexMan.GetTexture(sprtemp[frame].Texture[rot])->SetRotations(framestart + frame); + TexMan.GetGameTexture(sprtemp[frame].Texture[rot])->SetRotations(framestart + frame); } } } diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 286ffe1e0e..4b2786df5d 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -112,9 +112,9 @@ void FHWModelRenderer::SetInterpolation(double inter) state.SetInterpolationFactor((float)inter); } -void FHWModelRenderer::SetMaterial(FTexture *skin, bool clampNoFilter, int translation) +void FHWModelRenderer::SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) { - FMaterial * tex = FMaterial::ValidateTexture(skin, false); + FMaterial * tex = FMaterial::ValidateTexture(skin->GetTexture(), false); state.SetMaterial(tex, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1); state.SetLightIndex(modellightindex); } diff --git a/src/rendering/hwrenderer/models/hw_models.h b/src/rendering/hwrenderer/models/hw_models.h index a3de32e600..efe1e18698 100644 --- a/src/rendering/hwrenderer/models/hw_models.h +++ b/src/rendering/hwrenderer/models/hw_models.h @@ -68,7 +68,7 @@ public: void BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) override; void EndDrawHUDModel(AActor *actor) override; void SetInterpolation(double interpolation) override; - void SetMaterial(FTexture *skin, bool clampNoFilter, int translation) override; + void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) override; void DrawArrays(int start, int count) override; void DrawElements(int numIndices, size_t offset) override; }; From 72835c54624fd33d2450d4a81700b67108f0aa8c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 19:05:37 +0200 Subject: [PATCH 015/220] - transitioned the GLDEFS parser to FGameTexture. --- src/common/textures/textures.h | 50 +++++++- src/r_data/gldefs.cpp | 113 +++++++++--------- src/rendering/hwrenderer/scene/hw_decal.cpp | 13 +- .../hwrenderer/scene/hw_fakeflat.cpp | 8 +- src/rendering/hwrenderer/scene/hw_sky.cpp | 16 +-- src/rendering/swrenderer/things/r_model.cpp | 2 +- 6 files changed, 125 insertions(+), 77 deletions(-) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index d12f5582bc..0127e9effb 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -225,6 +225,7 @@ struct FTextureBuffer // Base texture class class FTexture { + friend class FGameTexture; // only for the porting work friend class GLDefsParser; friend class FMultipatchTextureBuilder; @@ -367,6 +368,7 @@ protected: FTexture *OffsetLess = nullptr; // Front sky layer variant where color 0 is transparent FTexture* FrontSkyLayer = nullptr; + public: // Paletted variant FTexture *PalVersion = nullptr; // Material layers @@ -381,6 +383,8 @@ protected: FTexture *CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES] = { nullptr }; // Custom texture maps for custom hardware shaders + protected: + FString Name; ETextureType UseType; // This texture's primary purpose @@ -397,10 +401,12 @@ protected: uint8_t bMultiPatch:2; // This is a multipatch texture (we really could use real type info for textures...) uint8_t bFullNameTexture : 1; uint8_t bBrightmapChecked : 1; // Set to 1 if brightmap has been checked + public: uint8_t bGlowing : 1; // Texture glow color uint8_t bAutoGlowing : 1; // Glow info is determined from texture image. uint8_t bFullbright : 1; // always draw fullbright uint8_t bDisableFullbright : 1; // This texture will not be displayed as fullbright sprite + protected: uint8_t bSkybox : 1; // is a cubic skybox uint8_t bNoCompress : 1; uint8_t bNoExpand : 1; @@ -411,9 +417,10 @@ protected: int16_t SkyOffset; FloatRect *areas = nullptr; int areacount = 0; + public: int GlowHeight = 128; PalEntry GlowColor = 0; - int HiresLump = -1; // For external hires textures. + private: float Glossiness = 10.f; float SpecularLevel = 0.1f; float shaderspeed = 1.f; @@ -557,6 +564,19 @@ public: }; +struct MaterialLayers +{ + float Glossiness; + float SpecularLevel; + FGameTexture* Brightmap; + FGameTexture* Normal; + FGameTexture* Specular; + FGameTexture* Metallic; + FGameTexture* Roughness; + FGameTexture* AmbientOcclusion; + FGameTexture* CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES]; +}; + struct FTexCoordInfo { int mRenderWidth; @@ -581,6 +601,8 @@ class FGameTexture FTexture wrapped; public: FTexture* GetTexture() { return &wrapped; } + int GetSourceLump() const { return wrapped.GetSourceLump(); } + void SetBrightmap(FGameTexture* tex) { wrapped.Brightmap = tex->GetTexture(); } double GetDisplayWidth() /*const*/ { return wrapped.GetDisplayWidthDouble(); } double GetDisplayHeight() /*const*/ { return wrapped.GetDisplayHeightDouble(); } @@ -596,8 +618,10 @@ public: bool isHardwareCanvas() const { return wrapped.isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isSoftwareCanvas() const { return wrapped.isCanvas(); } bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. + bool isFullbrightDisabled() const { return wrapped.isFullbrightDisabled(); } bool useWorldPanning() const { return wrapped.UseWorldPanning(); } bool allowNoDecals() const { return wrapped.allowNoDecals(); } + void SetTranslucent(bool on) { wrapped.bTranslucent = on; } ETextureType GetUseType() const { return wrapped.GetUseType(); } float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped.GetRotations(); } @@ -608,6 +632,25 @@ public: void SetSoftwareTexture(ISoftwareTexture* swtex) { wrapped.SetSoftwareTextue(swtex); } void SetScale(DVector2 vec) { wrapped.SetScale(vec); } const FString& GetName() const { return wrapped.GetName(); } + void SetShaderSpeed(float speed) { wrapped.shaderspeed = speed; } + void SetShaderIndex(int index) { wrapped.shaderindex = index; } + void SetShaderLayers(MaterialLayers& lay) + { + // Only update layers that have something defind. + if (lay.Glossiness > -1000) wrapped.Glossiness = lay.Glossiness; + if (lay.SpecularLevel > -1000) wrapped.SpecularLevel = lay.SpecularLevel; + if (lay.Brightmap) wrapped.Brightmap = lay.Brightmap->GetTexture(); + if (lay.Normal) wrapped.Normal = lay.Normal->GetTexture(); + if (lay.Specular) wrapped.Specular = lay.Specular->GetTexture(); + if (lay.Metallic) wrapped.Metallic = lay.Metallic->GetTexture(); + if (lay.Roughness) wrapped.Roughness = lay.Roughness->GetTexture(); + if (lay.AmbientOcclusion) wrapped.AmbientOcclusion = lay.AmbientOcclusion->GetTexture(); + for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) + { + if (lay.CustomShaderTextures[i]) wrapped.CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); + } + } + // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. FGameTexture* GetPalVersion() { return reinterpret_cast(wrapped.GetPalVersion()); } @@ -619,6 +662,11 @@ public: bool isGlowing() const { return wrapped.isGlowing(); } bool isAutoGlowing() const { return wrapped.isAutoGlowing(); } int GetGlowHeight() const { return wrapped.GetGlowHeight(); } + void SetAutoGlowing() { auto tex = GetTexture(); tex->bAutoGlowing = tex->bGlowing = tex->bFullbright = true; } + void SetGlowHeight(int v) { wrapped.GlowHeight = v; } + void SetFullbright() { wrapped.bFullbright = true; } + void SetDisableFullbright(bool on) { wrapped.bDisableFullbright = on; } + void SetGlowing(PalEntry color) { auto tex = GetTexture(); tex->bAutoGlowing = false; tex->bGlowing = true; tex->GlowColor = color; } bool isUserContent() const; }; diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 40f32f306b..b3aa050561 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -1034,8 +1034,8 @@ class GLDefsParser { sc.MustGetString(); FTextureID flump=TexMan.CheckForTexture(sc.String, ETextureType::Flat,FTextureManager::TEXMAN_TryAny); - FTexture *tex = TexMan.GetTexture(flump); - if (tex) tex->bAutoGlowing = tex->bGlowing = tex->bFullbright = true; + auto tex = TexMan.GetGameTexture(flump); + if (tex) tex->SetAutoGlowing(); } } else if (sc.Compare("WALLS")) @@ -1045,8 +1045,8 @@ class GLDefsParser { sc.MustGetString(); FTextureID flump=TexMan.CheckForTexture(sc.String, ETextureType::Wall,FTextureManager::TEXMAN_TryAny); - FTexture *tex = TexMan.GetTexture(flump); - if (tex) tex->bAutoGlowing = tex->bGlowing = tex->bFullbright = true; + auto tex = TexMan.GetGameTexture(flump); + if (tex) tex->SetAutoGlowing(); } } else if (sc.Compare("TEXTURE")) @@ -1054,7 +1054,7 @@ class GLDefsParser sc.SetCMode(true); sc.MustGetString(); FTextureID flump=TexMan.CheckForTexture(sc.String, ETextureType::Flat,FTextureManager::TEXMAN_TryAny); - FTexture *tex = TexMan.GetTexture(flump); + auto tex = TexMan.GetGameTexture(flump); sc.MustGetStringName(","); sc.MustGetString(); PalEntry color = V_GetColor(NULL, sc.String); @@ -1064,21 +1064,19 @@ class GLDefsParser { if (sc.CheckNumber()) { - if (tex) tex->GlowHeight = sc.Number; + if (tex) tex->SetGlowHeight(sc.Number); if (!sc.CheckString(",")) goto skip_fb; } sc.MustGetStringName("fullbright"); - if (tex) tex->bFullbright = true; + if (tex) tex->SetFullbright(); } skip_fb: sc.SetCMode(false); if (tex && color != 0) { - tex->bAutoGlowing = false; - tex->bGlowing = true; - tex->GlowColor = color; + tex->SetGlowing(color); } } } @@ -1097,7 +1095,7 @@ class GLDefsParser bool disable_fullbright=false; bool thiswad = false; bool iwad = false; - FTexture *bmtex = NULL; + FGameTexture *bmtex = NULL; sc.MustGetString(); if (sc.Compare("texture")) type = ETextureType::Wall; @@ -1107,7 +1105,7 @@ class GLDefsParser sc.MustGetString(); FTextureID no = TexMan.CheckForTexture(sc.String, type, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_Overridable); - FTexture *tex = TexMan.GetTexture(no); + auto tex = TexMan.GetGameTexture(no); sc.MustGetToken('{'); while (!sc.CheckToken('}')) @@ -1136,13 +1134,13 @@ class GLDefsParser if (bmtex != NULL) { - Printf("Multiple brightmap definitions in texture %s\n", tex? tex->Name.GetChars() : "(null)"); + Printf("Multiple brightmap definitions in texture %s\n", tex? tex->GetName().GetChars() : "(null)"); } - bmtex = TexMan.FindTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); + bmtex = TexMan.FindGameTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); if (bmtex == NULL) - Printf("Brightmap '%s' not found in texture '%s'\n", sc.String, tex? tex->Name.GetChars() : "(null)"); + Printf("Brightmap '%s' not found in texture '%s'\n", sc.String, tex? tex->GetName().GetChars() : "(null)"); } } if (!tex) @@ -1164,20 +1162,19 @@ class GLDefsParser if (bmtex != NULL) { - bmtex->bMasked = false; - tex->Brightmap = bmtex; + tex->SetBrightmap(bmtex); } - tex->bDisableFullbright = disable_fullbright; + tex->SetDisableFullbright(disable_fullbright); } - void SetShaderIndex(FTexture *tex, unsigned index) + void SetShaderIndex(FGameTexture *tex, unsigned index) { auto desc = usershaders[index - FIRST_USER_SHADER]; if (desc.disablealphatest) { - tex->bTranslucent = true; + tex->SetTranslucent(true); } - tex->shaderindex = index; + tex->SetShaderIndex(index); } //========================================================================== @@ -1199,10 +1196,10 @@ class GLDefsParser TArray texNameIndex; float speed = 1.f; - FTexture *textures[6]; + MaterialLayers mlay = { -1000, -1000 }; + FGameTexture* textures[6] = {}; const char *keywords[7] = { "brightmap", "normal", "specular", "metallic", "roughness", "ao", nullptr }; const char *notFound[6] = { "Brightmap", "Normalmap", "Specular texture", "Metallic texture", "Roughness texture", "Ambient occlusion texture" }; - memset(textures, 0, sizeof(textures)); sc.MustGetString(); if (sc.Compare("texture")) type = ETextureType::Wall; @@ -1212,7 +1209,7 @@ class GLDefsParser sc.MustGetString(); FTextureID no = TexMan.CheckForTexture(sc.String, type, FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_Overridable); - FTexture *tex = TexMan.GetTexture(no); + auto tex = TexMan.GetGameTexture(no); if (tex == nullptr) { @@ -1245,13 +1242,13 @@ class GLDefsParser { sc.MustGetFloat(); if (tex) - tex->Glossiness = (float)sc.Float; + mlay.Glossiness = (float)sc.Float; } else if (sc.Compare("specularlevel")) { sc.MustGetFloat(); if (tex) - tex->SpecularLevel = (float)sc.Float; + mlay.SpecularLevel = (float)sc.Float; } else if (sc.Compare("speed")) { @@ -1271,7 +1268,7 @@ class GLDefsParser { if (!texName.Compare(textureName)) { - sc.ScriptError("Trying to redefine custom hardware shader texture '%s' in texture '%s'\n", textureName.GetChars(), tex ? tex->Name.GetChars() : "(null)"); + sc.ScriptError("Trying to redefine custom hardware shader texture '%s' in texture '%s'\n", textureName.GetChars(), tex ? tex->GetName().GetChars() : "(null)"); } } sc.MustGetString(); @@ -1280,12 +1277,12 @@ class GLDefsParser bool okay = false; for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) { - if (!tex->CustomShaderTextures[i]) + if (!mlay.CustomShaderTextures[i]) { - tex->CustomShaderTextures[i] = TexMan.FindTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); - if (!tex->CustomShaderTextures[i]) + mlay.CustomShaderTextures[i] = TexMan.FindGameTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); + if (!mlay.CustomShaderTextures[i]) { - sc.ScriptError("Custom hardware shader texture '%s' not found in texture '%s'\n", sc.String, tex->Name.GetChars()); + sc.ScriptError("Custom hardware shader texture '%s' not found in texture '%s'\n", sc.String, tex->GetName().GetChars()); } texNameList.Push(textureName); @@ -1296,7 +1293,7 @@ class GLDefsParser } if (!okay) { - sc.ScriptError("Error: out of texture units in texture '%s'", tex->Name.GetChars()); + sc.ScriptError("Error: out of texture units in texture '%s'", tex->GetName().GetChars()); } } } @@ -1320,10 +1317,10 @@ class GLDefsParser { sc.MustGetString(); if (textures[i]) - Printf("Multiple %s definitions in texture %s\n", keywords[i], tex? tex->Name.GetChars() : "(null)"); - textures[i] = TexMan.FindTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); + Printf("Multiple %s definitions in texture %s\n", keywords[i], tex? tex->GetName().GetChars() : "(null)"); + textures[i] = TexMan.FindGameTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); if (!textures[i]) - Printf("%s '%s' not found in texture '%s'\n", notFound[i], sc.String, tex? tex->Name.GetChars() : "(null)"); + Printf("%s '%s' not found in texture '%s'\n", notFound[i], sc.String, tex? tex->GetName().GetChars() : "(null)"); break; } } @@ -1346,36 +1343,35 @@ class GLDefsParser if (!useme) return; } - FTexture **bindings[6] = + FGameTexture **bindings[6] = { - &tex->Brightmap, - &tex->Normal, - &tex->Specular, - &tex->Metallic, - &tex->Roughness, - &tex->AmbientOcclusion + &mlay.Brightmap, + &mlay.Normal, + &mlay.Specular, + &mlay.Metallic, + &mlay.Roughness, + &mlay.AmbientOcclusion }; for (int i = 0; keywords[i] != nullptr; i++) { if (textures[i]) { - textures[i]->bMasked = false; *bindings[i] = textures[i]; } } if (disable_fullbright_specified) - tex->bDisableFullbright = disable_fullbright; + tex->SetDisableFullbright(disable_fullbright); if (usershader.shader.IsNotEmpty()) { int firstUserTexture; - if (tex->Normal && tex->Specular) + if (mlay.Normal && mlay.Specular) { usershader.shaderType = SHADER_Specular; firstUserTexture = 7; } - else if (tex->Normal && tex->Metallic && tex->Roughness && tex->AmbientOcclusion) + else if (mlay.Normal && mlay.Metallic && mlay.Roughness && mlay.AmbientOcclusion) { usershader.shaderType = SHADER_PBR; firstUserTexture = 9; @@ -1393,10 +1389,10 @@ class GLDefsParser if (tex->isWarped() != 0) { - Printf("Cannot combine warping with hardware shader on texture '%s'\n", tex->Name.GetChars()); + Printf("Cannot combine warping with hardware shader on texture '%s'\n", tex->GetName().GetChars()); return; } - tex->shaderspeed = speed; + tex->SetShaderSpeed(speed); for (unsigned i = 0; i < usershaders.Size(); i++) { if (!usershaders[i].shader.CompareNoCase(usershader.shader) && @@ -1409,6 +1405,7 @@ class GLDefsParser } SetShaderIndex(tex, usershaders.Push(usershader) + FIRST_USER_SHADER); } + tex->SetShaderLayers(mlay); } @@ -1523,7 +1520,8 @@ class GLDefsParser sc.MustGetString(); FTextureID no = TexMan.CheckForTexture(sc.String, type); - FTexture *tex = TexMan.GetTexture(no); + auto tex = TexMan.GetGameTexture(no); + MaterialLayers mlay = { -1000, -1000 }; sc.MustGetToken('{'); while (!sc.CheckToken('}')) @@ -1567,19 +1565,19 @@ class GLDefsParser { if(!texName.Compare(textureName)) { - sc.ScriptError("Trying to redefine custom hardware shader texture '%s' in texture '%s'\n", textureName.GetChars(), tex? tex->Name.GetChars() : "(null)"); + sc.ScriptError("Trying to redefine custom hardware shader texture '%s' in texture '%s'\n", textureName.GetChars(), tex? tex->GetName().GetChars() : "(null)"); } } sc.MustGetString(); bool okay = false; for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) { - if (!tex->CustomShaderTextures[i]) + if (!mlay.CustomShaderTextures[i]) { - tex->CustomShaderTextures[i] = TexMan.FindTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); - if (!tex->CustomShaderTextures[i]) + mlay.CustomShaderTextures[i] = TexMan.FindGameTexture(sc.String, ETextureType::Any, FTextureManager::TEXMAN_TryAny); + if (!mlay.CustomShaderTextures[i]) { - sc.ScriptError("Custom hardware shader texture '%s' not found in texture '%s'\n", sc.String, tex? tex->Name.GetChars() : "(null)"); + sc.ScriptError("Custom hardware shader texture '%s' not found in texture '%s'\n", sc.String, tex? tex->GetName().GetChars() : "(null)"); } texNameList.Push(textureName); @@ -1590,7 +1588,7 @@ class GLDefsParser } if(!okay) { - sc.ScriptError("Error: out of texture units in texture '%s'", tex? tex->Name.GetChars() : "(null)"); + sc.ScriptError("Error: out of texture units in texture '%s'", tex? tex->GetName().GetChars() : "(null)"); } } else if(sc.Compare("define")) @@ -1633,10 +1631,10 @@ class GLDefsParser { if (tex->isWarped() != 0) { - Printf("Cannot combine warping with hardware shader on texture '%s'\n", tex->Name.GetChars()); + Printf("Cannot combine warping with hardware shader on texture '%s'\n", tex->GetName().GetChars()); return; } - tex->shaderspeed = speed; + tex->SetShaderSpeed(speed); for (unsigned i = 0; i < usershaders.Size(); i++) { if (!usershaders[i].shader.CompareNoCase(desc.shader) && @@ -1649,6 +1647,7 @@ class GLDefsParser } SetShaderIndex(tex, usershaders.Push(desc) + FIRST_USER_SHADER); } + tex->SetShaderLayers(mlay); } } diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index 52f0662069..a505894aed 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -209,7 +209,7 @@ void HWWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor flipy = !!(decal->RenderFlags & RF_YFLIP); - FTexture *texture = TexMan.GetTexture(decalTile); + auto texture = TexMan.GetGameTexture(decalTile); if (texture == NULL) return; @@ -265,14 +265,13 @@ void HWWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling); } } - FMaterial *tex = FMaterial::ValidateTexture(texture, false); // now clip the decal to the actual polygon - float decalwidth = tex->TextureWidth() * decal->ScaleX; - float decalheight = tex->TextureHeight() * decal->ScaleY; - float decallefto = tex->GetLeftOffset() * decal->ScaleX; - float decaltopo = tex->GetTopOffset() * decal->ScaleY; + float decalwidth = texture->GetDisplayWidth() * decal->ScaleX; + float decalheight = texture->GetDisplayHeight() * decal->ScaleY; + float decallefto = texture->GetDisplayLeftOffset() * decal->ScaleX; + float decaltopo = texture->GetDisplayTopOffset() * decal->ScaleY; float leftedge = glseg.fracleft * side->TexelLength; float linelength = glseg.fracright * side->TexelLength - leftedge; @@ -314,6 +313,8 @@ void HWWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor float vx = (glseg.x2 - glseg.x1) / linelength; float vy = (glseg.y2 - glseg.y1) / linelength; + FMaterial* tex = FMaterial::ValidateTexture(texture->GetTexture(), false); + DecalVertex dv[4]; enum { diff --git a/src/rendering/hwrenderer/scene/hw_fakeflat.cpp b/src/rendering/hwrenderer/scene/hw_fakeflat.cpp index f1d7d4d9b1..a5431bc3b8 100644 --- a/src/rendering/hwrenderer/scene/hw_fakeflat.cpp +++ b/src/rendering/hwrenderer/scene/hw_fakeflat.cpp @@ -118,7 +118,7 @@ bool hw_CheckClip(side_t * sidedef, sector_t * frontsector, sector_t * backsecto // now check for closed sectors! if (bs_ceilingheight1 <= fs_floorheight1 && bs_ceilingheight2 <= fs_floorheight2) { - FTexture * tex = TexMan.GetTexture(sidedef->GetTexture(side_t::top), true); + auto tex = TexMan.GetGameTexture(sidedef->GetTexture(side_t::top), true); if (!tex || !tex->isValid()) return false; if (backsector->GetTexture(sector_t::ceiling) == skyflatnum && frontsector->GetTexture(sector_t::ceiling) == skyflatnum) return false; @@ -127,7 +127,7 @@ bool hw_CheckClip(side_t * sidedef, sector_t * frontsector, sector_t * backsecto if (fs_ceilingheight1 <= bs_floorheight1 && fs_ceilingheight2 <= bs_floorheight2) { - FTexture * tex = TexMan.GetTexture(sidedef->GetTexture(side_t::bottom), true); + auto tex = TexMan.GetGameTexture(sidedef->GetTexture(side_t::bottom), true); if (!tex || !tex->isValid()) return false; // properly render skies (consider door "open" if both floors are sky): @@ -141,12 +141,12 @@ bool hw_CheckClip(side_t * sidedef, sector_t * frontsector, sector_t * backsecto // preserve a kind of transparent door/lift special effect: if (bs_ceilingheight1 < fs_ceilingheight1 || bs_ceilingheight2 < fs_ceilingheight2) { - FTexture * tex = TexMan.GetTexture(sidedef->GetTexture(side_t::top), true); + auto tex = TexMan.GetGameTexture(sidedef->GetTexture(side_t::top), true); if (!tex || !tex->isValid()) return false; } if (bs_floorheight1 > fs_floorheight1 || bs_floorheight2 > fs_floorheight2) { - FTexture * tex = TexMan.GetTexture(sidedef->GetTexture(side_t::bottom), true); + auto tex = TexMan.GetGameTexture(sidedef->GetTexture(side_t::bottom), true); if (!tex || !tex->isValid()) return false; } if (backsector->GetTexture(sector_t::ceiling) == skyflatnum && diff --git a/src/rendering/hwrenderer/scene/hw_sky.cpp b/src/rendering/hwrenderer/scene/hw_sky.cpp index 91218d0b74..ce48d94376 100644 --- a/src/rendering/hwrenderer/scene/hw_sky.cpp +++ b/src/rendering/hwrenderer/scene/hw_sky.cpp @@ -61,9 +61,9 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) } FTextureID texno = s->GetTexture(pos); - FTexture* tex = TexMan.GetTexture(texno, true); + auto tex = TexMan.GetGameTexture(texno, true); if (!tex || !tex->isValid()) goto normalsky; - texture[0] = FMaterial::ValidateTexture(tex, false); + texture[0] = FMaterial::ValidateTexture(tex->GetTexture(), false); skytexno1 = texno; x_offset[0] = s->GetTextureXOffset(pos) * (360.f/65536.f); y_offset = s->GetTextureYOffset(pos); @@ -74,9 +74,9 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) normalsky: if (di->Level->flags&LEVEL_DOUBLESKY) { - auto tex1 = TexMan.GetTexture(di->Level->skytexture1, true); + auto tex1 = TexMan.GetGameTexture(di->Level->skytexture1, true); if (tex1) tex1 = tex1->GetFrontSkyLayer(); - texture[1] = FMaterial::ValidateTexture(tex1, false); + texture[1] = FMaterial::ValidateTexture(tex1->GetTexture(), false); x_offset[1] = di->Level->hw_sky1pos; doublesky = true; } @@ -247,13 +247,13 @@ void HWWall::SkyTop(HWDrawInfo *di, seg_t * seg,sector_t * fs,sector_t * bs,vert { if (bs->GetPlaneTexZ(sector_t::floor)==fs->GetPlaneTexZ(sector_t::floor)+1.) { - FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::bottom), true); + auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::bottom), true); if (!tex || !tex->isValid()) return; // very, very, very ugly special case (See Icarus MAP14) // It is VERY important that this is only done for a floor height difference of 1 // or it will cause glitches elsewhere. - tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::mid), true); + tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::mid), true); if (tex != NULL && !(seg->linedef->flags & ML_DONTPEGTOP) && seg->sidedef->GetTextureYOffset(side_t::mid) > 0) { @@ -269,7 +269,7 @@ void HWWall::SkyTop(HWDrawInfo *di, seg_t * seg,sector_t * fs,sector_t * bs,vert ztop[0]=ztop[1]=32768.0f; - FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::top), true); + auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::top), true); if (bs->GetTexture(sector_t::ceiling) != skyflatnum) { @@ -329,7 +329,7 @@ void HWWall::SkyBottom(HWDrawInfo *di, seg_t * seg,sector_t * fs,sector_t * bs,v if (fs->GetTexture(sector_t::floor)==skyflatnum) { if (bs->special == GLSector_NoSkyDraw || (bs->MoreFlags & SECMF_NOSKYWALLS) != 0 || (seg->linedef->flags & ML_NOSKYWALLS) != 0) return; - FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::bottom), true); + auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::bottom), true); // For lower skies the normal logic only applies to walls with no lower texture. if (!tex->isValid()) diff --git a/src/rendering/swrenderer/things/r_model.cpp b/src/rendering/swrenderer/things/r_model.cpp index 43f52ccfab..bb8c66d5e3 100644 --- a/src/rendering/swrenderer/things/r_model.cpp +++ b/src/rendering/swrenderer/things/r_model.cpp @@ -109,7 +109,7 @@ namespace swrenderer FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr); if (lump.isValid()) { - FTexture * tex = TexMan.GetTexture(lump, true); + auto tex = TexMan.GetGameTexture(lump, true); if (tex) disablefullbright = tex->isFullbrightDisabled(); } return psp->GetState()->GetFullbright() && !disablefullbright; From 9099bc842075f312f8b5c84603a6703e63e73aff Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 20:45:26 +0200 Subject: [PATCH 016/220] - reworking some lower level texture code. --- src/common/engine/serializer.cpp | 9 ++++--- src/common/filesystem/filesystem.cpp | 6 ++--- src/common/filesystem/filesystem.h | 6 ++--- src/common/filesystem/resourcefile.h | 1 - src/common/fonts/v_font.h | 1 + src/common/scripting/jit/jit_move.cpp | 2 +- src/common/scripting/vm/vmexec.h | 2 +- .../textures/multipatchtexturebuilder.cpp | 6 ++--- src/common/textures/texture.cpp | 4 +-- src/common/textures/texturemanager.cpp | 10 +++---- src/common/textures/textures.h | 11 ++++++++ src/d_main.cpp | 2 +- src/playsim/p_sectors.cpp | 4 +-- .../postprocessing/hw_postprocess.cpp | 5 ++-- src/rendering/hwrenderer/scene/hw_bsp.cpp | 2 +- .../hwrenderer/scene/hw_renderhacks.cpp | 4 +-- src/rendering/hwrenderer/scene/hw_sprites.cpp | 2 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 10 +++---- src/rendering/hwrenderer/scene/hw_weapon.cpp | 2 +- .../hwrenderer/textures/hw_precache.cpp | 26 ++++++++++--------- src/scripting/vmthunks.cpp | 22 ++++++++-------- 21 files changed, 76 insertions(+), 61 deletions(-) diff --git a/src/common/engine/serializer.cpp b/src/common/engine/serializer.cpp index ae2f872f91..d500826ed6 100644 --- a/src/common/engine/serializer.cpp +++ b/src/common/engine/serializer.cpp @@ -1081,16 +1081,17 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FTextureID &value, FTe } FTextureID chk = value; if (chk.GetIndex() >= TexMan.NumTextures()) chk.SetNull(); - FTexture *pic = TexMan.GetTexture(chk); + auto pic = TexMan.GetGameTexture(chk); const char *name; + auto lump = pic->GetSourceLump(); - if (fileSystem.GetLinkedTexture(pic->SourceLump) == pic) + if (fileSystem.GetLinkedTexture(lump) == pic) { - name = fileSystem.GetFileFullName(pic->SourceLump); + name = fileSystem.GetFileFullName(lump); } else { - name = pic->Name; + name = pic->GetName(); } arc.WriteKey(key); arc.w->StartArray(); diff --git a/src/common/filesystem/filesystem.cpp b/src/common/filesystem/filesystem.cpp index 2bced84292..12b1d197a2 100644 --- a/src/common/filesystem/filesystem.cpp +++ b/src/common/filesystem/filesystem.cpp @@ -57,7 +57,7 @@ extern FILE* hashfile; struct FileSystem::LumpRecord { FResourceLump *lump; - FTexture* linkedTexture; + FGameTexture* linkedTexture; LumpShortName shortName; FString longName; int rfnum; @@ -725,7 +725,7 @@ int FileSystem::GetResource (int resid, const char *type, int filenum) const // //========================================================================== -void FileSystem::SetLinkedTexture(int lump, FTexture *tex) +void FileSystem::SetLinkedTexture(int lump, FGameTexture *tex) { if ((size_t)lump < NumEntries) { @@ -739,7 +739,7 @@ void FileSystem::SetLinkedTexture(int lump, FTexture *tex) // //========================================================================== -FTexture *FileSystem::GetLinkedTexture(int lump) +FGameTexture *FileSystem::GetLinkedTexture(int lump) { if ((size_t)lump < NumEntries) { diff --git a/src/common/filesystem/filesystem.h b/src/common/filesystem/filesystem.h index dd5cc8234f..a7c38683f9 100644 --- a/src/common/filesystem/filesystem.h +++ b/src/common/filesystem/filesystem.h @@ -16,7 +16,7 @@ class FResourceFile; struct FResourceLump; -class FTexture; +class FGameTexture; union LumpShortName { @@ -124,8 +124,8 @@ public: inline int CheckNumForFullName (const FString &name, int wadfile) { return CheckNumForFullName(name.GetChars(), wadfile); } inline int GetNumForFullName (const FString &name) { return GetNumForFullName(name.GetChars()); } - void SetLinkedTexture(int lump, FTexture *tex); - FTexture *GetLinkedTexture(int lump); + void SetLinkedTexture(int lump, FGameTexture *tex); + FGameTexture *GetLinkedTexture(int lump); void ReadFile (int lump, void *dest); diff --git a/src/common/filesystem/resourcefile.h b/src/common/filesystem/resourcefile.h index 224f208110..4d90f3e2fd 100644 --- a/src/common/filesystem/resourcefile.h +++ b/src/common/filesystem/resourcefile.h @@ -19,7 +19,6 @@ struct LumpFilterInfo }; class FResourceFile; -class FTexture; // [RH] Namespaces from BOOM. // These are needed here in the low level part so that WAD files can be properly set up. diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index b4d2c753b8..ab20edf766 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -39,6 +39,7 @@ #include "name.h" class DCanvas; +class FTexture; class FGameTexture; struct FRemapTable; diff --git a/src/common/scripting/jit/jit_move.cpp b/src/common/scripting/jit/jit_move.cpp index 584de35a11..a02898ac06 100644 --- a/src/common/scripting/jit/jit_move.cpp +++ b/src/common/scripting/jit/jit_move.cpp @@ -53,7 +53,7 @@ static void CastCo2S(FString *a, int b) { PalEntry c(b); a->Format("%02x %02x %0 static int CastS2So(FString *b) { return FSoundID(*b); } static void CastSo2S(FString* a, int b) { *a = soundEngine->GetSoundName(b); } static void CastSID2S(FString* a, unsigned int b) { VM_CastSpriteIDToString(a, b); } -static void CastTID2S(FString *a, int b) { auto tex = TexMan.GetTexture(*(FTextureID*)&b); *a = (tex == nullptr) ? "(null)" : tex->GetName().GetChars(); } +static void CastTID2S(FString *a, int b) { auto tex = TexMan.GetGameTexture(*(FTextureID*)&b); *a = (tex == nullptr) ? "(null)" : tex->GetName().GetChars(); } void JitCompiler::EmitCAST() { diff --git a/src/common/scripting/vm/vmexec.h b/src/common/scripting/vm/vmexec.h index 72e0d0199e..d88945a446 100644 --- a/src/common/scripting/vm/vmexec.h +++ b/src/common/scripting/vm/vmexec.h @@ -1848,7 +1848,7 @@ static void DoCast(const VMRegisters ®, const VMFrame *f, int a, int b, int c case CAST_TID2S: { ASSERTS(a); ASSERTD(b); - auto tex = TexMan.GetTexture(*(FTextureID*)&(reg.d[b])); + auto tex = TexMan.GetGameTexture(*(FTextureID*)&(reg.d[b])); reg.s[a] = tex == nullptr ? "(null)" : tex->GetName().GetChars(); break; } diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 3380968b02..b627bacacb 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -356,7 +356,7 @@ void FMultipatchTextureBuilder::AddTexturesLump(const void *lumpdata, int lumpsi // It still needs to be created in case someone uses it by name. offset = LittleLong(directory[1]); const maptexture_t *tex = (const maptexture_t *)((const uint8_t *)maptex + offset); - FTexture *tex0 = TexMan.ByIndex(0); + auto tex0 = TexMan.GameByIndex(0); tex0->SetSize(SAFESHORT(tex->width), SAFESHORT(tex->height)); } @@ -373,7 +373,7 @@ void FMultipatchTextureBuilder::AddTexturesLump(const void *lumpdata, int lumpsi int j; for (j = (int)TexMan.NumTextures() - 1; j >= firstdup; --j) { - if (strnicmp(TexMan.ByIndex(j)->GetName(), (const char *)maptex + offset, 8) == 0) + if (strnicmp(TexMan.GameByIndex(j)->GetName(), (const char *)maptex + offset, 8) == 0) break; } if (j + 1 == firstdup) @@ -780,7 +780,7 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) TexMan.ListTextures(buildinfo.Inits[i].TexName, list, true); for (int i = list.Size() - 1; i >= 0; i--) { - if (list[i] != buildinfo.tex->id && !TexMan.GetTexture(list[i])->bMultiPatch) + if (list[i] != buildinfo.tex->id && !TexMan.GetGameTexture(list[i])->isMultiPatch() ) { texno = list[i]; break; diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index eeed137ea6..57ee44c57e 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -148,8 +148,8 @@ FTexture::FTexture (const char *name, int lumpnum) FTexture::~FTexture () { - FTexture *link = fileSystem.GetLinkedTexture(SourceLump); - if (link == this) fileSystem.SetLinkedTexture(SourceLump, nullptr); + FGameTexture *link = fileSystem.GetLinkedTexture(SourceLump); + if (link->GetTexture() == this) fileSystem.SetLinkedTexture(SourceLump, nullptr); if (areas != nullptr) delete[] areas; areas = nullptr; diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 834f9de48f..62eac65c2f 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -220,20 +220,20 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset // Any graphic being placed in the zip's root directory can not be found by this. if (strchr(name, '/')) { - FTexture *const NO_TEXTURE = (FTexture*)-1; + FGameTexture *const NO_TEXTURE = (FGameTexture*)-1; int lump = fileSystem.CheckNumForFullName(name); if (lump >= 0) { - FTexture *tex = fileSystem.GetLinkedTexture(lump); + FGameTexture *tex = fileSystem.GetLinkedTexture(lump); if (tex == NO_TEXTURE) return FTextureID(-1); - if (tex != NULL) return tex->id; + if (tex != NULL) return tex->GetID(); if (flags & TEXMAN_DontCreate) return FTextureID(-1); // we only want to check, there's no need to create a texture if we don't have one yet. - tex = FTexture::CreateTexture("", lump, ETextureType::Override); + tex = reinterpret_cast(FTexture::CreateTexture("", lump, ETextureType::Override)); if (tex != NULL) { tex->AddAutoMaterials(); fileSystem.SetLinkedTexture(lump, tex); - return AddTexture(tex); + return AddTexture(tex->GetTexture()); } else { diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 0127e9effb..efa45ec753 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -618,11 +618,13 @@ public: bool isHardwareCanvas() const { return wrapped.isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isSoftwareCanvas() const { return wrapped.isCanvas(); } bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. + bool isMultiPatch() const { return wrapped.bMultiPatch; } bool isFullbrightDisabled() const { return wrapped.isFullbrightDisabled(); } bool useWorldPanning() const { return wrapped.UseWorldPanning(); } bool allowNoDecals() const { return wrapped.allowNoDecals(); } void SetTranslucent(bool on) { wrapped.bTranslucent = on; } ETextureType GetUseType() const { return wrapped.GetUseType(); } + void SetUseType(ETextureType type) { wrapped.SetUseType(type); } float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped.GetRotations(); } void SetRotations(int index) { wrapped.SetRotations(index); } @@ -651,6 +653,10 @@ public: } } + void CopySize(FGameTexture* BaseTexture) + { + wrapped.CopySize(&BaseTexture->wrapped); + } // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. FGameTexture* GetPalVersion() { return reinterpret_cast(wrapped.GetPalVersion()); } @@ -669,6 +675,11 @@ public: void SetGlowing(PalEntry color) { auto tex = GetTexture(); tex->bAutoGlowing = false; tex->bGlowing = true; tex->GlowColor = color; } bool isUserContent() const; + void AddAutoMaterials() { wrapped.AddAutoMaterials(); } + int CheckRealHeight() { return wrapped.CheckRealHeight(); } + bool isSkybox() const { return wrapped.isSkybox(); } + void SetSize(int x, int y) { wrapped.SetSize(x, y); } + }; diff --git a/src/d_main.cpp b/src/d_main.cpp index 554ad1a8e3..90b94f7700 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2642,7 +2642,7 @@ static void PatchTextures() FTextureID tex = TexMan.CheckForTexture("BLANK", ETextureType::Wall, false); if (tex.Exists()) { - auto texture = TexMan.GetTexture(tex, false); + auto texture = TexMan.GetGameTexture(tex, false); texture->SetUseType(ETextureType::Null); } } diff --git a/src/playsim/p_sectors.cpp b/src/playsim/p_sectors.cpp index ae967d2c06..448808265a 100644 --- a/src/playsim/p_sectors.cpp +++ b/src/playsim/p_sectors.cpp @@ -513,7 +513,7 @@ double FindShortestTextureAround (sector_t *sec) CheckShortestTex (sec->Level, check->sidedef[1]->GetTexture(side_t::bottom), minsize); } } - return minsize < FLT_MAX ? minsize : TexMan.ByIndex(0)->GetDisplayHeight(); + return minsize < FLT_MAX ? minsize : TexMan.GameByIndex(0)->GetDisplayHeight(); } // @@ -538,7 +538,7 @@ double FindShortestUpperAround (sector_t *sec) CheckShortestTex (sec->Level, check->sidedef[1]->GetTexture(side_t::top), minsize); } } - return minsize < FLT_MAX ? minsize : TexMan.ByIndex(0)->GetDisplayHeight(); + return minsize < FLT_MAX ? minsize : TexMan.GameByIndex(0)->GetDisplayHeight(); } // diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp index 9d80fc46cb..c8a32f30fe 100644 --- a/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -1000,14 +1000,15 @@ void PPCustomShaderInstance::SetTextures(PPRenderState *renderstate) while (it.NextPair(pair)) { FString name = pair->Value; - FTexture *tex = TexMan.GetTexture(TexMan.CheckForTexture(name, ETextureType::Any), true); - if (tex && tex->isValid()) + auto gtex = TexMan.GetGameTexture(TexMan.CheckForTexture(name, ETextureType::Any), true); + if (gtex && gtex->isValid()) { // Why does this completely circumvent the normal way of handling textures? // This absolutely needs fixing because it will also circumvent any potential caching system that may get implemented. // // To do: fix the above problem by adding PPRenderState::SetInput(FTexture *tex) + auto tex = gtex->GetTexture(); auto &pptex = Textures[tex]; if (!pptex) { diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index 9c89689b60..d2ce57e4dc 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -289,7 +289,7 @@ void HWDrawInfo::AddLine (seg_t *seg, bool portalclip) { if (!seg->linedef->isVisualPortal()) { - FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::mid), true); + auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::mid), true); if (!tex || !tex->isValid()) { // nothing to do here! diff --git a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp index 45f48bf0f1..6ebdab3f8a 100644 --- a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp @@ -351,7 +351,7 @@ bool HWDrawInfo::DoOneSectorUpper(subsector_t * subsec, float Planez, area_t in_ if (sec->GetPlaneTexZ(sector_t::ceiling) == Planez) { // If there's a texture abort - FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::top)); + auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::top)); if (!tex || !tex->isValid()) continue; else return false; } @@ -409,7 +409,7 @@ bool HWDrawInfo::DoOneSectorLower(subsector_t * subsec, float Planez, area_t in_ if (sec->GetPlaneTexZ(sector_t::floor) == Planez) { // If there's a texture abort - FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::bottom)); + auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::bottom)); if (!tex || !tex->isValid()) continue; else return false; } diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index fb96034ed0..4d6a2bc1ec 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -793,7 +793,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t if (isPicnumOverride) { // Animate picnum overrides. - auto tex = TexMan.GetTexture(thing->picnum, true); + auto tex = TexMan.GetGameTexture(thing->picnum, true); if (tex == nullptr) return; patch = tex->GetID(); mirror = false; diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 1249a13cec..9b0a5f1779 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -1238,7 +1238,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, // Set up the top // // - FTexture * tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::top), true); + auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::top), true); if (!tex || !tex->isValid()) { if (front->GetTexture(sector_t::ceiling) == skyflatnum && @@ -1274,7 +1274,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, // Set up the bottom // // - tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::bottom), true); + tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::bottom), true); if (!tex || !tex->isValid()) { // texture is missing - use the lower plane @@ -1543,7 +1543,7 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, if (rover->flags&FF_UPPERTEXTURE) { gltexture = FMaterial::ValidateTexture(seg->sidedef->GetTexture(side_t::top), false, true); - if (!gltexture) return; + if (!gltexture) return; GetTexCoordInfo(gltexture, &tci, seg->sidedef, side_t::top); } else if (rover->flags&FF_LOWERTEXTURE) @@ -2073,14 +2073,14 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ sector_t *backsec = isportal? seg->linedef->getPortalDestination()->frontsector : backsector; bool drawfogboundary = !di->isFullbrightScene() && di->CheckFog(frontsector, backsec); - FTexture *tex = TexMan.GetTexture(seg->sidedef->GetTexture(side_t::mid), true); + auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::mid), true); if (tex != NULL) { if (di->Level->i_compatflags & COMPATF_MASKEDMIDTEX) { tex = tex->GetRawTexture(); } - gltexture = FMaterial::ValidateTexture(tex, false); + gltexture = FMaterial::ValidateTexture(tex->GetTexture(), false); } else gltexture = NULL; diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index 09881c1006..d8cabda51b 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -141,7 +141,7 @@ static bool isBright(DPSprite *psp) FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., nullptr); if (lump.isValid()) { - FTexture * tex = TexMan.GetTexture(lump, true); + auto tex = TexMan.GetGameTexture(lump, true); if (tex) disablefullbright = tex->isFullbrightDisabled(); } return psp->GetState()->GetFullbright() && !disablefullbright; diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 9711fe74a3..2c442e894c 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -103,10 +103,10 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl // HIT_Wall must be checked for MBF-style sky transfers. if (texhitlist[i] & (FTextureManager::HIT_Sky | FTextureManager::HIT_Wall)) { - FTexture *tex = TexMan.ByIndex(i); + auto tex = TexMan.GameByIndex(i); if (tex->isSkybox()) { - FSkyBox *sb = static_cast(tex); + FSkyBox *sb = static_cast(tex->GetTexture()); for (int i = 0; i<6; i++) { if (sb->faces[i]) @@ -193,12 +193,12 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl // prepare the textures for precaching. First collect all used layer textures so that we know which ones should not be deleted. for (int i = cnt - 1; i >= 0; i--) { - FTexture *tex = TexMan.ByIndex(i); + auto tex = TexMan.GameByIndex(i); if (tex != nullptr) { if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { - FMaterial* mat = FMaterial::ValidateTexture(tex, false, false); + FMaterial* mat = FMaterial::ValidateTexture(tex->GetTexture(), false, false); if (mat != nullptr) { for (auto ftex : mat->GetLayerArray()) @@ -209,7 +209,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl } if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0) { - FMaterial *mat = FMaterial::ValidateTexture(tex, true, false); + FMaterial *mat = FMaterial::ValidateTexture(tex->GetTexture(), true, false); if (mat != nullptr) { for (auto ftex : mat->GetLayerArray()) @@ -224,16 +224,16 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl // delete unused textures (i.e. those which didn't get referenced by any material in the cache list. for (int i = cnt - 1; i >= 0; i--) { - FTexture *tex = TexMan.ByIndex(i); + auto tex = TexMan.GameByIndex(i); if (tex != nullptr && tex->GetUseType() != ETextureType::FontChar) { - if (usedTextures.CheckKey(tex) == nullptr) + if (usedTextures.CheckKey(tex->GetTexture()) == nullptr) { - tex->CleanHardwareTextures(true, false); + tex->GetTexture()->CleanHardwareTextures(true, false); } - if (usedSprites.CheckKey(tex) == nullptr) + if (usedSprites.CheckKey(tex->GetTexture()) == nullptr) { - tex->CleanHardwareTextures(false, true); + tex->GetTexture()->CleanHardwareTextures(false, true); } } } @@ -249,7 +249,8 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl // cache all used textures for (int i = cnt - 1; i >= 0; i--) { - FTexture *tex = TexMan.ByIndex(i); + auto gtex = TexMan.GameByIndex(i); + auto tex = gtex->GetTexture(); if (tex != nullptr && tex->GetImage() != nullptr) { if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) @@ -271,7 +272,8 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl // cache all used textures for (int i = cnt - 1; i >= 0; i--) { - FTexture *tex = TexMan.ByIndex(i); + auto gtex = TexMan.GameByIndex(i); + auto tex = gtex->GetTexture(); if (tex != nullptr) { PrecacheTexture(tex, texhitlist[i]); diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 02394188f2..497feba3e8 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -1630,7 +1630,7 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetName) { PARAM_PROLOGUE; PARAM_INT(texid); - auto tex = TexMan.ByIndex(texid); + auto tex = TexMan.GameByIndex(texid); FString retval; if (tex != nullptr) @@ -1655,12 +1655,12 @@ DEFINE_ACTION_FUNCTION(_TexMan, GetName) static int GetTextureSize(int texid, int* py) { - auto tex = TexMan.ByIndex(texid); + auto tex = TexMan.GameByIndex(texid); int x, y; if (tex != nullptr) { - x = tex->GetDisplayWidth(); - y = tex->GetDisplayHeight(); + x = int(0.5 + tex->GetDisplayWidth()); + y = int(0.5 + tex->GetDisplayHeight()); } else x = y = -1; if (py) *py = y; @@ -1685,12 +1685,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetSize, GetTextureSize) //========================================================================== static void GetScaledSize(int texid, DVector2* pvec) { - auto tex = TexMan.ByIndex(texid); + auto tex = TexMan.GameByIndex(texid); double x, y; if (tex != nullptr) { - x = tex->GetDisplayWidthDouble(); - y = tex->GetDisplayHeightDouble(); + x = tex->GetDisplayWidth(); + y = tex->GetDisplayHeight(); } else x = y = -1; if (pvec) @@ -1716,12 +1716,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledSize, GetScaledSize) //========================================================================== static void GetScaledOffset(int texid, DVector2* pvec) { - auto tex = TexMan.ByIndex(texid); + auto tex = TexMan.GameByIndex(texid); double x, y; if (tex != nullptr) { - x = tex->GetDisplayLeftOffsetDouble(); - y = tex->GetDisplayTopOffsetDouble(); + x = tex->GetDisplayLeftOffset(); + y = tex->GetDisplayTopOffset(); } else x = y = -1; if (pvec) @@ -1748,7 +1748,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, GetScaledOffset, GetScaledOffset) static int CheckRealHeight(int texid) { - auto tex = TexMan.ByIndex(texid); + auto tex = TexMan.GameByIndex(texid); if (tex != nullptr) return tex->CheckRealHeight(); else return -1; } From 0ce0099e29d8de6f546ff68563531ebaabe5f37c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 23:19:11 +0200 Subject: [PATCH 017/220] - moved the sprite positioning info out of FMaterial back into FTexture. This cleans out half of FMaterial and brings it closer to being a texture binding descriptor, which is all it really should be. --- src/common/textures/hw_material.cpp | 252 +----------------- src/common/textures/hw_material.h | 20 -- src/common/textures/texture.cpp | 232 +++++++++++++++- src/common/textures/textures.h | 35 ++- src/rendering/hwrenderer/scene/hw_sprites.cpp | 39 +-- src/rendering/hwrenderer/scene/hw_walls.cpp | 2 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 29 +- 7 files changed, 309 insertions(+), 300 deletions(-) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index bb39cef7be..34f60af794 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -30,21 +30,6 @@ IHardwareTexture* CreateHardwareTexture(); -// We really do not need to create more than one hardware texture per image source. -// However, the internal handling depends on FTexture for everything so this array maps each all textures sharing the same master texture that gets used in the layer array. -static TMap imageToMasterTexture; - -static FTexture* GetMasterTexture(FTexture* tx) -{ - if (tx->GetUseType() == ETextureType::Null) return tx; // Null textures never get redirected - auto img = tx->GetImage(); - if (!img) return tx; // this is not an image texture and represents itself. - auto find = imageToMasterTexture.CheckKey(img); - if (find) return *find; // already got a master texture for this. Return it. - imageToMasterTexture.Insert(img, tx); - return tx; // this is a newly added master texture. -} - //=========================================================================== // // Constructor @@ -55,7 +40,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) { mShaderIndex = SHADER_Default; sourcetex = tx; - imgtex = GetMasterTexture(tx); + imgtex = tx; if (tx->UseType == ETextureType::SWCanvas && static_cast(tx)->GetColorFormat() == 0) { @@ -79,7 +64,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) { for (auto &texture : { tx->Normal, tx->Specular }) { - mTextureLayers.Push(GetMasterTexture(texture)); + mTextureLayers.Push(texture); } mShaderIndex = SHADER_Specular; } @@ -87,7 +72,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) { for (auto &texture : { tx->Normal, tx->Metallic, tx->Roughness, tx->AmbientOcclusion }) { - mTextureLayers.Push(GetMasterTexture(texture)); + mTextureLayers.Push(texture); } mShaderIndex = SHADER_PBR; } @@ -96,7 +81,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) tx->CreateDefaultBrightmap(); if (tx->Brightmap) { - mTextureLayers.Push(GetMasterTexture(tx->Brightmap)); + mTextureLayers.Push(tx->Brightmap); mLayerFlags |= TEXF_Brightmap; } else @@ -105,7 +90,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) } if (tx->Detailmap) { - mTextureLayers.Push(GetMasterTexture(tx->Detailmap)); + mTextureLayers.Push(tx->Detailmap); mLayerFlags |= TEXF_Detailmap; } else @@ -114,7 +99,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) } if (tx->Glowmap) { - mTextureLayers.Push(GetMasterTexture(tx->Glowmap)); + mTextureLayers.Push(tx->Glowmap); mLayerFlags |= TEXF_Glowmap; } else @@ -130,7 +115,7 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) for (auto &texture : tx->CustomShaderTextures) { if (texture == nullptr) continue; - mTextureLayers.Push(GetMasterTexture(texture)); + mTextureLayers.Push(texture); } mShaderIndex = tx->shaderindex; } @@ -142,23 +127,8 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) mTopOffset = tx->GetTopOffset(0); mRenderWidth = tx->GetScaledWidth(); mRenderHeight = tx->GetScaledHeight(); - mSpriteU[0] = mSpriteV[0] = 0.f; - mSpriteU[1] = mSpriteV[1] = 1.f; mExpanded = expanded; - if (expanded) - { - int oldwidth = mWidth; - int oldheight = mHeight; - - mTrimResult = TrimBorders(trim); // get the trim size before adding the empty frame - mWidth += 2; - mHeight += 2; - mRenderWidth = mRenderWidth * mWidth / oldwidth; - mRenderHeight = mRenderHeight * mHeight / oldheight; - - } - SetSpriteRect(); mTextureLayers.ShrinkToFit(); tx->Material[expanded] = this; @@ -175,149 +145,6 @@ FMaterial::~FMaterial() { } -//=========================================================================== -// -// Set the sprite rectangle -// -//=========================================================================== - -void FMaterial::SetSpriteRect() -{ - auto leftOffset = sourcetex->GetLeftOffsetHW(); - auto topOffset = sourcetex->GetTopOffsetHW(); - - float fxScale = (float)sourcetex->Scale.X; - float fyScale = (float)sourcetex->Scale.Y; - - // mSpriteRect is for positioning the sprite in the scene. - mSpriteRect.left = -leftOffset / fxScale; - mSpriteRect.top = -topOffset / fyScale; - mSpriteRect.width = mWidth / fxScale; - mSpriteRect.height = mHeight / fyScale; - - if (mExpanded) - { - // a little adjustment to make sprites look better with texture filtering: - // create a 1 pixel wide empty frame around them. - - int oldwidth = mWidth - 2; - int oldheight = mHeight - 2; - - leftOffset += 1; - topOffset += 1; - - // Reposition the sprite with the frame considered - mSpriteRect.left = -leftOffset / fxScale; - mSpriteRect.top = -topOffset / fyScale; - mSpriteRect.width = mWidth / fxScale; - mSpriteRect.height = mHeight / fyScale; - - if (mTrimResult) - { - mSpriteRect.left += trim[0] / fxScale; - mSpriteRect.top += trim[1] / fyScale; - - mSpriteRect.width -= (oldwidth - trim[2]) / fxScale; - mSpriteRect.height -= (oldheight - trim[3]) / fyScale; - - mSpriteU[0] = trim[0] / (float)mWidth; - mSpriteV[0] = trim[1] / (float)mHeight; - mSpriteU[1] -= (oldwidth - trim[0] - trim[2]) / (float)mWidth; - mSpriteV[1] -= (oldheight - trim[1] - trim[3]) / (float)mHeight; - } - } -} - - -//=========================================================================== -// -// Finds empty space around the texture. -// Used for sprites that got placed into a huge empty frame. -// -//=========================================================================== - -bool FMaterial::TrimBorders(uint16_t *rect) -{ - - auto texbuffer = sourcetex->CreateTexBuffer(0); - int w = texbuffer.mWidth; - int h = texbuffer.mHeight; - auto Buffer = texbuffer.mBuffer; - - if (texbuffer.mBuffer == nullptr) - { - return false; - } - if (w != mWidth || h != mHeight) - { - // external Hires replacements cannot be trimmed. - return false; - } - - int size = w*h; - if (size == 1) - { - // nothing to be done here. - rect[0] = 0; - rect[1] = 0; - rect[2] = 1; - rect[3] = 1; - return true; - } - int first, last; - - for(first = 0; first < size; first++) - { - if (Buffer[first*4+3] != 0) break; - } - if (first >= size) - { - // completely empty - rect[0] = 0; - rect[1] = 0; - rect[2] = 1; - rect[3] = 1; - return true; - } - - for(last = size-1; last >= first; last--) - { - if (Buffer[last*4+3] != 0) break; - } - - rect[1] = first / w; - rect[3] = 1 + last/w - rect[1]; - - rect[0] = 0; - rect[2] = w; - - unsigned char *bufferoff = Buffer + (rect[1] * w * 4); - h = rect[3]; - - for(int x = 0; x < w; x++) - { - for(int y = 0; y < h; y++) - { - if (bufferoff[(x+y*w)*4+3] != 0) goto outl; - } - rect[0]++; - } -outl: - rect[2] -= rect[0]; - - for(int x = w-1; rect[2] > 1; x--) - { - for(int y = 0; y < h; y++) - { - if (bufferoff[(x+y*w)*4+3] != 0) - { - return true; - } - } - rect[2]--; - } - return true; -} //=========================================================================== // @@ -343,25 +170,6 @@ IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) return nullptr; } -//=========================================================================== -// -// -// -//=========================================================================== - -int FMaterial::GetAreas(FloatRect **pAreas) const -{ - if (mShaderIndex == SHADER_Default) // texture splitting can only be done if there's no attached effects - { - *pAreas = sourcetex->areas; - return sourcetex->areacount; - } - else - { - return 0; - } -} - //========================================================================== // // Gets a texture from the texture manager and checks its validity for @@ -371,31 +179,13 @@ int FMaterial::GetAreas(FloatRect **pAreas) const FMaterial * FMaterial::ValidateTexture(FTexture * tex, bool expand, bool create) { -again: if (tex && tex->isValid()) { - if (tex->bNoExpand) expand = false; + if (!tex->ShouldExpandSprite()) expand = false; FMaterial *hwtex = tex->Material[expand]; if (hwtex == NULL && create) { - if (expand) - { - if (tex->isWarped() || tex->isHardwareCanvas() || tex->shaderindex >= FIRST_USER_SHADER || tex->shaderindex == SHADER_Specular || tex->shaderindex == SHADER_PBR) - { - tex->bNoExpand = true; - goto again; - } - if (tex->Brightmap != NULL && - (tex->GetTexelWidth() != tex->Brightmap->GetTexelWidth() || - tex->GetTexelHeight() != tex->Brightmap->GetTexelHeight()) - ) - { - // do not expand if the brightmap's size differs. - tex->bNoExpand = true; - goto again; - } - } hwtex = new FMaterial(tex, expand); } return hwtex; @@ -415,29 +205,3 @@ void DeleteMaterial(FMaterial* mat) } -//----------------------------------------------------------------------------- -// -// Make sprite offset adjustment user-configurable per renderer. -// -//----------------------------------------------------------------------------- - -extern int r_spriteadjustSW, r_spriteadjustHW; - -CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - r_spriteadjustHW = !!(self & 2); - r_spriteadjustSW = !!(self & 1); - for (int i = 0; i < TexMan.NumTextures(); i++) - { - auto tex = TexMan.GetTexture(FSetTextureID(i)); - if (tex->GetTexelLeftOffset(0) != tex->GetTexelLeftOffset(1) || tex->GetTexelTopOffset(0) != tex->GetTexelTopOffset(1)) - { - for (int i = 0; i < 2; i++) - { - auto mat = tex->GetMaterial(i); - if (mat != nullptr) mat->SetSpriteRect(); - } - } - - } -} diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index 11cbc58b4c..a280ac6fb1 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -40,13 +40,6 @@ class FMaterial short mRenderWidth; short mRenderHeight; bool mExpanded; - bool mTrimResult; - uint16_t trim[4]; - - float mSpriteU[2], mSpriteV[2]; - FloatRect mSpriteRect; - - bool TrimBorders(uint16_t *rect); public: FTexture *sourcetex; // the owning texture. @@ -108,17 +101,10 @@ public: // Patch drawing utilities - void GetSpriteRect(FloatRect * r) const - { - *r = mSpriteRect; - } - // This is scaled size in integer units as needed by walls and flats int TextureHeight() const { return mRenderHeight; } int TextureWidth() const { return mRenderWidth; } - int GetAreas(FloatRect **pAreas) const; - int GetWidth() const { return mWidth; @@ -147,12 +133,6 @@ public: float GetU(float upix) const { return upix/(float)mWidth; } float GetV(float vpix) const { return vpix/(float)mHeight; } - float GetSpriteUL() const { return mSpriteU[0]; } - float GetSpriteVT() const { return mSpriteV[0]; } - float GetSpriteUR() const { return mSpriteU[1]; } - float GetSpriteVB() const { return mSpriteV[1]; } - - static FMaterial *ValidateTexture(FTexture * tex, bool expand, bool create = true); static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans, bool create = true); const TArray &GetLayerArray() const diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 57ee44c57e..bd97b23505 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -47,6 +47,7 @@ #include "image.h" #include "formats/multipatchtexture.h" #include "texturemanager.h" +#include "c_cvars.h" // Wrappers to keep the definitions of these classes out of here. void DeleteMaterial(FMaterial* mat); @@ -125,7 +126,6 @@ FTexture::FTexture (const char *name, int lumpnum) bDisableFullbright = false; bSkybox = false; bNoCompress = false; - bNoExpand = false; bTranslucent = -1; @@ -461,6 +461,25 @@ void FTexture::GetGlowColor(float *data) data[2] = GlowColor.b / 255.0f; } +//=========================================================================== +// +// +// +//=========================================================================== + +int FTexture::GetAreas(FloatRect** pAreas) const +{ + if (shaderindex == SHADER_Default) // texture splitting can only be done if there's no attached effects + { + *pAreas = areas; + return areacount; + } + else + { + return 0; + } +} + //=========================================================================== // // Finds gaps in the texture which can be skipped by the renderer @@ -776,6 +795,197 @@ TArray FTexture::Get8BitPixels(bool alphatex) return Pixels; } +//=========================================================================== +// +// Sets up the sprite positioning data for this texture +// +//=========================================================================== + +void FTexture::SetupSpriteData() +{ + spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f; + spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f; + spi.spriteWidth = GetTexelWidth(); + spi.spriteHeight = GetTexelHeight(); + + if (ShouldExpandSprite()) + { + if (mTrimResult == -1) mTrimResult = !!TrimBorders(spi.trim); // get the trim size before adding the empty frame + spi.spriteWidth += 2; + spi.spriteHeight += 2; + } + else mTrimResult = 0; + SetSpriteRect(); +} + +//=========================================================================== +// +// Checks if a sprite may be expanded with an empty frame +// +//=========================================================================== + +bool FTexture::ShouldExpandSprite() +{ + if (bExpandSprite != -1) return bExpandSprite; + if (isWarped() || isHardwareCanvas() || shaderindex != SHADER_Default) + { + bExpandSprite = false; + return false; + } + if (Brightmap != NULL && (GetTexelWidth() != Brightmap->GetTexelWidth() || GetTexelHeight() != Brightmap->GetTexelHeight())) + { + // do not expand if the brightmap's size differs. + bExpandSprite = false; + return false; + } + bExpandSprite = true; + return true; +} + +//=========================================================================== +// +// Finds empty space around the texture. +// Used for sprites that got placed into a huge empty frame. +// +//=========================================================================== + +bool FTexture::TrimBorders(uint16_t* rect) +{ + + auto texbuffer = CreateTexBuffer(0); + int w = texbuffer.mWidth; + int h = texbuffer.mHeight; + auto Buffer = texbuffer.mBuffer; + + if (texbuffer.mBuffer == nullptr) + { + return false; + } + if (w != Width || h != Height) + { + // external Hires replacements cannot be trimmed. + return false; + } + + int size = w * h; + if (size == 1) + { + // nothing to be done here. + rect[0] = 0; + rect[1] = 0; + rect[2] = 1; + rect[3] = 1; + return true; + } + int first, last; + + for (first = 0; first < size; first++) + { + if (Buffer[first * 4 + 3] != 0) break; + } + if (first >= size) + { + // completely empty + rect[0] = 0; + rect[1] = 0; + rect[2] = 1; + rect[3] = 1; + return true; + } + + for (last = size - 1; last >= first; last--) + { + if (Buffer[last * 4 + 3] != 0) break; + } + + rect[1] = first / w; + rect[3] = 1 + last / w - rect[1]; + + rect[0] = 0; + rect[2] = w; + + unsigned char* bufferoff = Buffer + (rect[1] * w * 4); + h = rect[3]; + + for (int x = 0; x < w; x++) + { + for (int y = 0; y < h; y++) + { + if (bufferoff[(x + y * w) * 4 + 3] != 0) goto outl; + } + rect[0]++; + } +outl: + rect[2] -= rect[0]; + + for (int x = w - 1; rect[2] > 1; x--) + { + for (int y = 0; y < h; y++) + { + if (bufferoff[(x + y * w) * 4 + 3] != 0) + { + return true; + } + } + rect[2]--; + } + return true; +} + +//=========================================================================== +// +// Set the sprite rectangle +// +//=========================================================================== + +void FTexture::SetSpriteRect() +{ + auto leftOffset = GetLeftOffsetHW(); + auto topOffset = GetTopOffsetHW(); + + float fxScale = (float)Scale.X; + float fyScale = (float)Scale.Y; + + // mSpriteRect is for positioning the sprite in the scene. + spi.mSpriteRect.left = -leftOffset / fxScale; + spi.mSpriteRect.top = -topOffset / fyScale; + spi.mSpriteRect.width = spi.spriteWidth / fxScale; + spi.mSpriteRect.height = spi.spriteHeight / fyScale; + + if (bExpandSprite) + { + // a little adjustment to make sprites look better with texture filtering: + // create a 1 pixel wide empty frame around them. + + int oldwidth = spi.spriteWidth - 2; + int oldheight = spi.spriteHeight - 2; + + leftOffset += 1; + topOffset += 1; + + // Reposition the sprite with the frame considered + spi.mSpriteRect.left = -leftOffset / fxScale; + spi.mSpriteRect.top = -topOffset / fyScale; + spi.mSpriteRect.width = spi.spriteWidth / fxScale; + spi.mSpriteRect.height = spi.spriteHeight / fyScale; + + if (mTrimResult > 0) + { + spi.mSpriteRect.left += spi.trim[0] / fxScale; + spi.mSpriteRect.top += spi.trim[1] / fyScale; + + spi.mSpriteRect.width -= (oldwidth - spi.trim[2]) / fxScale; + spi.mSpriteRect.height -= (oldheight - spi.trim[3]) / fyScale; + + spi.mSpriteU[0] = spi.trim[0] / spi.spriteWidth; + spi.mSpriteV[0] = spi.trim[1] / spi.spriteHeight; + spi.mSpriteU[1] -= (oldwidth - spi.trim[0] - spi.trim[2]) / spi.spriteWidth; + spi.mSpriteV[1] -= (oldheight - spi.trim[1] - spi.trim[3]) / spi.spriteHeight; + } + } +} + + //=========================================================================== // // Coordinate helper. @@ -904,3 +1114,23 @@ bool FGameTexture::isUserContent() const return (filenum > fileSystem.GetMaxIwadNum()); } + +//----------------------------------------------------------------------------- +// +// Make sprite offset adjustment user-configurable per renderer. +// +//----------------------------------------------------------------------------- + +CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + r_spriteadjustHW = !!(self & 2); + r_spriteadjustSW = !!(self & 1); + for (int i = 0; i < TexMan.NumTextures(); i++) + { + auto tex = TexMan.GetGameTexture(FSetTextureID(i)); + if (tex->GetTexelLeftOffset(0) != tex->GetTexelLeftOffset(1) || tex->GetTexelTopOffset(0) != tex->GetTexelTopOffset(1)) + { + tex->SetSpriteRect(); + } + } +} diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index efa45ec753..487d041d01 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -222,6 +222,25 @@ struct FTextureBuffer }; +struct SpritePositioningInfo +{ + uint16_t trim[4]; + int spriteWidth, spriteHeight; + float mSpriteU[2], mSpriteV[2]; + FloatRect mSpriteRect; + + float GetSpriteUL() const { return mSpriteU[0]; } + float GetSpriteVT() const { return mSpriteV[0]; } + float GetSpriteUR() const { return mSpriteU[1]; } + float GetSpriteVB() const { return mSpriteV[1]; } + + const FloatRect &GetSpriteRect() const + { + return mSpriteRect; + } + +}; + // Base texture class class FTexture { @@ -249,6 +268,10 @@ class FTexture public: + + SpritePositioningInfo spi; + int8_t mTrimResult = -1; + static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType usetype); virtual ~FTexture (); virtual FImageSource *GetImage() const { return nullptr; } @@ -331,6 +354,11 @@ public: Height = h; } + bool TrimBorders(uint16_t* rect); + void SetSpriteRect(); + bool ShouldExpandSprite(); + void SetupSpriteData(); + int GetAreas(FloatRect** pAreas) const; // Returns the whole texture, stored in column-major order virtual TArray Get8BitPixels(bool alphatex); @@ -409,8 +437,8 @@ protected: protected: uint8_t bSkybox : 1; // is a cubic skybox uint8_t bNoCompress : 1; - uint8_t bNoExpand : 1; int8_t bTranslucent : 2; + int8_t bExpandSprite = -1; bool bHiresHasColorKey = false; // Support for old color-keyed Doomsday textures uint16_t Rotations; @@ -507,7 +535,7 @@ public: bMasked = false; bHasCanvas = true; bTranslucent = false; - bNoExpand = true; + bExpandSprite = false; UseType = ETextureType::Wall; } @@ -680,6 +708,9 @@ public: bool isSkybox() const { return wrapped.isSkybox(); } void SetSize(int x, int y) { wrapped.SetSize(x, y); } + void SetSpriteRect() { wrapped.SetSpriteRect(); } + const SpritePositioningInfo& GetSpritePositioning() { if (wrapped.mTrimResult == -1) wrapped.SetupSpriteData(); return wrapped.spi; } + }; diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 4d6a2bc1ec..035b031f69 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -755,8 +755,6 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t else Angles = thing->Angles; - FloatRect r; - if (sector->sectornum != thing->Sector->sectornum && !thruportal) { // This cannot create a copy in the fake sector cache because it'd interfere with the main thread, so provide a local buffer for the copy. @@ -818,15 +816,15 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t if (!patch.isValid()) return; int type = thing->renderflags & RF_SPRITETYPEMASK; - gltexture = FMaterial::ValidateTexture(patch, (type == RF_FACESPRITE), false); - if (!gltexture) - return; + auto tex = TexMan.GetGameTexture(patch, false); + if (!tex || !tex->isValid()) return; + auto& spi = tex->GetSpritePositioning(); - vt = gltexture->GetSpriteVT(); - vb = gltexture->GetSpriteVB(); + vt = spi.GetSpriteVT(); + vb = spi.GetSpriteVB(); if (thing->renderflags & RF_YFLIP) std::swap(vt, vb); - gltexture->GetSpriteRect(&r); + auto r = spi.GetSpriteRect(); // [SP] SpriteFlip if (thing->renderflags & RF_SPRITEFLIP) @@ -835,15 +833,19 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t if (mirror ^ !!(thing->renderflags & RF_XFLIP)) { r.left = -r.width - r.left; // mirror the sprite's x-offset - ul = gltexture->GetSpriteUL(); - ur = gltexture->GetSpriteUR(); + ul = spi.GetSpriteUL(); + ur = spi.GetSpriteUR(); } else { - ul = gltexture->GetSpriteUR(); - ur = gltexture->GetSpriteUL(); + ul = spi.GetSpriteUR(); + ur = spi.GetSpriteUL(); } + gltexture = FMaterial::ValidateTexture(patch, (type == RF_FACESPRITE), false); + if (!gltexture) + return; + if (thing->renderflags & RF_SPRITEFLIP) // [SP] Flip back thing->renderflags ^= RF_XFLIP; @@ -1182,15 +1184,14 @@ void HWSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * if (lump.isValid()) { - gltexture = FMaterial::ValidateTexture(lump, true, false); translation = 0; + //auto tex = TexMan.GetGameTexture(lump, false); - ul = gltexture->GetUL(); - ur = gltexture->GetUR(); - vt = gltexture->GetVT(); - vb = gltexture->GetVB(); - FloatRect r; - gltexture->GetSpriteRect(&r); + ul = 0; + ur = 1; + vt = 0; + vb = 1; + gltexture = FMaterial::ValidateTexture(lump, true, false); } } diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 9b0a5f1779..cab8ca6ef7 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -1431,7 +1431,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, // // FloatRect *splitrect; - int v = gltexture->GetAreas(&splitrect); + int v = gltexture->sourcetex->GetAreas(&splitrect); if (seg->frontsector == seg->backsector) flags |= HWF_NOSPLIT; // we don't need to do vertex splits if a line has both sides in the same sector if (v>0 && !drawfogboundary && !(seg->linedef->flags&ML_WRAP_MIDTEX)) { diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index d8cabda51b..6cd2313764 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -417,14 +417,14 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, FTextureID lump = sprites[psp->GetSprite()].GetSpriteFrame(psp->GetFrame(), 0, 0., &mirror); if (!lump.isValid()) return false; - FMaterial * tex = FMaterial::ValidateTexture(lump, true, false); - if (!tex) return false; + auto tex = TexMan.GetGameTexture(lump, false); + if (!tex || !tex->isValid()) return false; + auto& spi = tex->GetSpritePositioning(); float vw = (float)viewwidth; float vh = (float)viewheight; - FloatRect r; - tex->GetSpriteRect(&r); + FloatRect r = spi.GetSpriteRect(); // calculate edges of the shape scalex = (320.0f / (240.0f * r_viewwindow.WidescreenRatio)) * vw / 320; @@ -452,17 +452,17 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, if (!(mirror) != !(psp->Flags & (PSPF_FLIP))) { - u2 = tex->GetSpriteUL(); - v1 = tex->GetSpriteVT(); - u1 = tex->GetSpriteUR(); - v2 = tex->GetSpriteVB(); + u2 = spi.GetSpriteUL(); + v1 = spi.GetSpriteVT(); + u1 = spi.GetSpriteUR(); + v2 = spi.GetSpriteVB(); } else { - u1 = tex->GetSpriteUL(); - v1 = tex->GetSpriteVT(); - u2 = tex->GetSpriteUR(); - v2 = tex->GetSpriteVB(); + u1 = spi.GetSpriteUL(); + v1 = spi.GetSpriteVT(); + u2 = spi.GetSpriteUR(); + v2 = spi.GetSpriteVB(); } auto verts = screen->mVertexData->AllocVertices(4); @@ -473,7 +473,10 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, verts.first[2].Set(x2, y1, 0, u2, v1); verts.first[3].Set(x2, y2, 0, u2, v2); - this->tex = tex; + FMaterial* mat = FMaterial::ValidateTexture(lump, true, false); + if (!mat) return false; + + this->tex = mat; return true; } From 1146cf9e08b52517f9a344c299058b74bbcfaf13 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 14 Apr 2020 23:50:57 +0200 Subject: [PATCH 018/220] - use FGameTexture instead of FMaterial for texture tracking in HWWall. The FMaterial object is only needed when finally binding the texture to the render state. --- src/common/textures/texture.cpp | 24 ++-- src/common/textures/textures.h | 7 ++ src/rendering/hwrenderer/scene/hw_decal.cpp | 2 +- .../hwrenderer/scene/hw_drawlist.cpp | 2 +- .../hwrenderer/scene/hw_drawlistadd.cpp | 2 +- .../hwrenderer/scene/hw_drawstructs.h | 2 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 105 +++++++++--------- 7 files changed, 76 insertions(+), 68 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index bd97b23505..a1a3c7056e 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -964,23 +964,23 @@ void FTexture::SetSpriteRect() topOffset += 1; // Reposition the sprite with the frame considered - spi.mSpriteRect.left = -leftOffset / fxScale; - spi.mSpriteRect.top = -topOffset / fyScale; - spi.mSpriteRect.width = spi.spriteWidth / fxScale; - spi.mSpriteRect.height = spi.spriteHeight / fyScale; + spi.mSpriteRect.left = -(float)leftOffset / fxScale; + spi.mSpriteRect.top = -(float)topOffset / fyScale; + spi.mSpriteRect.width = (float)spi.spriteWidth / fxScale; + spi.mSpriteRect.height = (float)spi.spriteHeight / fyScale; if (mTrimResult > 0) { - spi.mSpriteRect.left += spi.trim[0] / fxScale; - spi.mSpriteRect.top += spi.trim[1] / fyScale; + spi.mSpriteRect.left += (float)spi.trim[0] / fxScale; + spi.mSpriteRect.top += (float)spi.trim[1] / fyScale; - spi.mSpriteRect.width -= (oldwidth - spi.trim[2]) / fxScale; - spi.mSpriteRect.height -= (oldheight - spi.trim[3]) / fyScale; + spi.mSpriteRect.width -= float(oldwidth - spi.trim[2]) / fxScale; + spi.mSpriteRect.height -= float(oldheight - spi.trim[3]) / fyScale; - spi.mSpriteU[0] = spi.trim[0] / spi.spriteWidth; - spi.mSpriteV[0] = spi.trim[1] / spi.spriteHeight; - spi.mSpriteU[1] -= (oldwidth - spi.trim[0] - spi.trim[2]) / spi.spriteWidth; - spi.mSpriteV[1] -= (oldheight - spi.trim[1] - spi.trim[3]) / spi.spriteHeight; + spi.mSpriteU[0] = (float)spi.trim[0] / (float)spi.spriteWidth; + spi.mSpriteV[0] = (float)spi.trim[1] / (float)spi.spriteHeight; + spi.mSpriteU[1] -= float(oldwidth - spi.trim[0] - spi.trim[2]) / (float)spi.spriteWidth; + spi.mSpriteV[1] -= float(oldheight - spi.trim[1] - spi.trim[3]) / (float)spi.spriteHeight; } } } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 487d041d01..90de86eae0 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -643,6 +643,7 @@ public: bool isValid() { return wrapped.isValid(); } bool isWarped() { return wrapped.isWarped(); } + bool isMasked() { return wrapped.isMasked(); } bool isHardwareCanvas() const { return wrapped.isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isSoftwareCanvas() const { return wrapped.isCanvas(); } bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. @@ -710,6 +711,12 @@ public: void SetSpriteRect() { wrapped.SetSpriteRect(); } const SpritePositioningInfo& GetSpritePositioning() { if (wrapped.mTrimResult == -1) wrapped.SetupSpriteData(); return wrapped.spi; } + int GetAreas(FloatRect** pAreas) const { return wrapped.GetAreas(pAreas); } + + bool GetTranslucency() + { + return wrapped.GetTranslucency(); + } }; diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index a505894aed..d112d5aeec 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -200,7 +200,7 @@ void HWWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor if (decal->RenderFlags & RF_INVISIBLE) return; - if (type == RENDERWALL_FFBLOCK && gltexture->isMasked()) return; // No decals on 3D floors with transparent textures. + if (type == RENDERWALL_FFBLOCK && texture->isMasked()) return; // No decals on 3D floors with transparent textures. if (seg == nullptr) return; diff --git a/src/rendering/hwrenderer/scene/hw_drawlist.cpp b/src/rendering/hwrenderer/scene/hw_drawlist.cpp index 37ff4006be..54f5db6a56 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlist.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlist.cpp @@ -722,7 +722,7 @@ void HWDrawList::SortWalls() HWWall * w1 = walls[a.index]; HWWall * w2 = walls[b.index]; - if (w1->gltexture != w2->gltexture) return w1->gltexture < w2->gltexture; + if (w1->texture != w2->texture) return w1->texture < w2->texture; return (w1->flags & 3) < (w2->flags & 3); }); diff --git a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp index 851c2e1488..646f52279b 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -44,7 +44,7 @@ void HWDrawInfo::AddWall(HWWall *wall) } else { - bool masked = HWWall::passflag[wall->type] == 1 ? false : (wall->gltexture && wall->gltexture->isMasked()); + bool masked = HWWall::passflag[wall->type] == 1 ? false : (wall->texture && wall->texture->isMasked()); int list; if ((wall->flags & HWWall::HWF_SKYHACK && wall->type == RENDERWALL_M2S)) diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 036811fa09..236d45332a 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -151,7 +151,7 @@ public: friend class HWPortal; vertex_t * vertexes[2]; // required for polygon splitting - FMaterial *gltexture; + FGameTexture *texture; TArray *lightlist; HWSeg glseg; diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index cab8ca6ef7..b96634c7bf 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -156,7 +156,8 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) state.SetGlowParams(topglowcolor, bottomglowcolor); state.SetGlowPlanes(frontsector->ceilingplane, frontsector->floorplane); } - state.SetMaterial(gltexture, flags & 3, 0, -1); + auto mat = FMaterial::ValidateTexture(texture->GetTexture(), false, true); + state.SetMaterial(mat, flags & 3, 0, -1); if (type == RENDERWALL_M2SNF) { @@ -262,9 +263,9 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) void HWWall::RenderTranslucentWall(HWDrawInfo *di, FRenderState &state) { state.SetRenderStyle(RenderStyle); - if (gltexture) + if (texture) { - if (!gltexture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); + if (!texture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); else state.AlphaFunc(Alpha_GEqual, 0.f); RenderTexturedWall(di, state, HWWall::RWF_TEXTURED | HWWall::RWF_NOSPLIT); } @@ -289,7 +290,7 @@ void HWWall::DrawWall(HWDrawInfo *di, FRenderState &state, bool translucent) { if (screen->BuffersArePersistent()) { - if (di->Level->HasDynamicLights && !di->isFullbrightScene() && gltexture != nullptr) + if (di->Level->HasDynamicLights && !di->isFullbrightScene() && texture != nullptr) { SetupLights(di, lightdata); } @@ -442,7 +443,7 @@ const char HWWall::passflag[] = { //========================================================================== void HWWall::PutWall(HWDrawInfo *di, bool translucent) { - if (gltexture && gltexture->GetTranslucency() && passflag[type] == 2) + if (texture && texture->GetTranslucency() && passflag[type] == 2) { translucent = true; } @@ -455,7 +456,7 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent) if (di->isFullbrightScene()) { // light planes don't get drawn with fullbright rendering - if (gltexture == NULL) return; + if (texture == NULL) return; Colormap.Clear(); } @@ -464,7 +465,7 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent) if (!screen->BuffersArePersistent()) { - if (di->Level->HasDynamicLights && !di->isFullbrightScene() && gltexture != nullptr) + if (di->Level->HasDynamicLights && !di->isFullbrightScene() && texture != nullptr) { SetupLights(di, lightdata); } @@ -474,7 +475,7 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent) bool solid; if (passflag[type] == 1) solid = true; - else if (type == RENDERWALL_FFBLOCK) solid = gltexture && !gltexture->isMasked(); + else if (type == RENDERWALL_FFBLOCK) solid = texture && !texture->isMasked(); else solid = false; if (solid) ProcessDecals(di); @@ -914,7 +915,7 @@ bool HWWall::SetWallCoordinates(seg_t * seg, FTexCoordInfo *tci, float textureto float l_ul; float texlength; - if (gltexture) + if (texture) { float length = seg->sidedef ? seg->sidedef->TexelLength : Dist2(glseg.x1, glseg.y1, glseg.x2, glseg.y2); @@ -1007,10 +1008,10 @@ bool HWWall::SetWallCoordinates(seg_t * seg, FTexCoordInfo *tci, float textureto tcs[UPLFT].u = tcs[LOLFT].u = l_ul + texlength * glseg.fracleft; tcs[UPRGT].u = tcs[LORGT].u = l_ul + texlength * glseg.fracright; - if (gltexture != NULL) + if (texture != NULL) { bool normalize = false; - if (gltexture->isHardwareCanvas()) normalize = true; + if (texture->isHardwareCanvas()) normalize = true; else if (flags & HWF_CLAMPY) { // for negative scales we can get negative coordinates here. @@ -1039,7 +1040,7 @@ void HWWall::CheckTexturePosition(FTexCoordInfo *tci) { float sub; - if (gltexture->isHardwareCanvas()) return; + if (texture->isHardwareCanvas()) return; // clamp texture coordinates to a reasonable range. // Extremely large values can cause visual problems @@ -1104,9 +1105,9 @@ void HWWall::CheckTexturePosition(FTexCoordInfo *tci) } -static void GetTexCoordInfo(FMaterial *tex, FTexCoordInfo *tci, side_t *side, int texpos) +static void GetTexCoordInfo(FGameTexture *tex, FTexCoordInfo *tci, side_t *side, int texpos) { - tci->GetFromTexture(tex->Source(), (float)side->GetTextureXScale(texpos), (float)side->GetTextureYScale(texpos), !!(side->GetLevel()->flags3 & LEVEL3_FORCEWORLDPANNING)); + tci->GetFromTexture(tex, (float)side->GetTextureXScale(texpos), (float)side->GetTextureYScale(texpos), !!(side->GetLevel()->flags3 & LEVEL3_FORCEWORLDPANNING)); } //========================================================================== @@ -1143,7 +1144,7 @@ void HWWall::DoTexture(HWDrawInfo *di, int _type,seg_t * seg, int peg, FTexCoordInfo tci; - GetTexCoordInfo(gltexture, &tci, seg->sidedef, texpos); + GetTexCoordInfo(texture, &tci, seg->sidedef, texpos); type = _type; @@ -1199,12 +1200,12 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, // Get the base coordinates for the texture // // - if (gltexture) + if (texture) { // Align the texture to the ORIGINAL sector's height!! // At this point slopes don't matter because they don't affect the texture's z-position - GetTexCoordInfo(gltexture, &tci, seg->sidedef, side_t::mid); + GetTexCoordInfo(texture, &tci, seg->sidedef, side_t::mid); if (tci.mRenderHeight < 0) { mirrory = true; @@ -1331,7 +1332,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, // float t_ofs = seg->sidedef->GetTextureXOffset(side_t::mid); - if (gltexture) + if (texture) { // First adjust the texture offset so that the left edge of the linedef is inside the range [0..1]. float texwidth = tci.TextureAdjustWidth(); @@ -1385,15 +1386,15 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, { flags |= HWF_NOSPLITUPPER|HWF_NOSPLITLOWER; type=RENDERWALL_FOGBOUNDARY; - FMaterial *savetex = gltexture; - gltexture = NULL; + auto savetex = texture; + texture = NULL; PutWall(di, true); if (!savetex) { flags &= ~(HWF_NOSPLITUPPER|HWF_NOSPLITLOWER); return; } - gltexture = savetex; + texture = savetex; type=RENDERWALL_M2SNF; } else type=RENDERWALL_M2S; @@ -1412,7 +1413,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, case 0: RenderStyle=STYLE_Translucent; alpha = seg->linedef->alpha; - translucent =alpha < 1. || (gltexture && gltexture->GetTranslucency()); + translucent =alpha < 1. || (texture && texture->GetTranslucency()); break; case ML_ADDTRANS: @@ -1431,7 +1432,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, // // FloatRect *splitrect; - int v = gltexture->sourcetex->GetAreas(&splitrect); + int v = texture->GetAreas(&splitrect); if (seg->frontsector == seg->backsector) flags |= HWF_NOSPLIT; // we don't need to do vertex splits if a line has both sides in the same sector if (v>0 && !drawfogboundary && !(seg->linedef->flags&ML_WRAP_MIDTEX)) { @@ -1532,7 +1533,7 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, Colormap.LightColor = light->extra_colormap.FadeColor; // the fog plane defines the light di->Level->, not the front sector lightlevel = hw_ClampLight(*light->p_lightlevel); - gltexture = NULL; + texture = NULL; type = RENDERWALL_FFBLOCK; } else return; @@ -1542,21 +1543,21 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, if (rover->flags&FF_UPPERTEXTURE) { - gltexture = FMaterial::ValidateTexture(seg->sidedef->GetTexture(side_t::top), false, true); - if (!gltexture) return; - GetTexCoordInfo(gltexture, &tci, seg->sidedef, side_t::top); + texture = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::top), true); + if (!texture || !texture->isValid()) return; + GetTexCoordInfo(texture, &tci, seg->sidedef, side_t::top); } else if (rover->flags&FF_LOWERTEXTURE) { - gltexture = FMaterial::ValidateTexture(seg->sidedef->GetTexture(side_t::bottom), false, true); - if (!gltexture) return; - GetTexCoordInfo(gltexture, &tci, seg->sidedef, side_t::bottom); + texture = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::bottom), true); + if (!texture || !texture->isValid()) return; + GetTexCoordInfo(texture, &tci, seg->sidedef, side_t::bottom); } else { - gltexture = FMaterial::ValidateTexture(mastersd->GetTexture(side_t::mid), false, true); - if (!gltexture) return; - GetTexCoordInfo(gltexture, &tci, mastersd, side_t::mid); + texture = TexMan.GetGameTexture(mastersd->GetTexture(side_t::mid), true); + if (!texture || !texture->isValid()) return; + GetTexCoordInfo(texture, &tci, mastersd, side_t::mid); } to = (rover->flags&(FF_UPPERTEXTURE | FF_LOWERTEXTURE)) ? 0 : tci.TextureOffset(mastersd->GetTextureXOffset(side_t::mid)); @@ -1592,7 +1593,7 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, alpha = rover->alpha / 255.0f; RenderStyle = (rover->flags&FF_ADDITIVETRANS) ? STYLE_Add : STYLE_Translucent; translucent = true; - type = gltexture ? RENDERWALL_M2S : RENDERWALL_COLOR; + type = texture ? RENDERWALL_M2S : RENDERWALL_COLOR; } else { @@ -1959,7 +1960,7 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ alpha = 1.0f; RenderStyle = STYLE_Normal; - gltexture = NULL; + texture = NULL; if (frontsector->GetWallGlow(topglowcolor, bottomglowcolor)) flags |= HWF_GLOW; @@ -1999,8 +2000,8 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ else { // normal texture - gltexture = FMaterial::ValidateTexture(seg->sidedef->GetTexture(side_t::mid), false, true); - if (gltexture) + texture = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::mid), true); + if (texture && texture->isValid()) { DoTexture(di, RENDERWALL_M1S, seg, (seg->linedef->flags & ML_DONTPEGBOTTOM) > 0, crefz, frefz, // must come from the original! @@ -2034,8 +2035,8 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ if (bch1a < fch1 || bch2a < fch2) { - gltexture = FMaterial::ValidateTexture(seg->sidedef->GetTexture(side_t::top), false, true); - if (gltexture) + texture = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::top), true); + if (texture && texture->isValid()) { DoTexture(di, RENDERWALL_TOP, seg, (seg->linedef->flags & (ML_DONTPEGTOP)) == 0, crefz, realback->GetPlaneTexZ(sector_t::ceiling), @@ -2047,8 +2048,8 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ frontsector->GetTexture(sector_t::ceiling) != skyflatnum && backsector->GetTexture(sector_t::ceiling) != skyflatnum) { - gltexture = FMaterial::ValidateTexture(frontsector->GetTexture(sector_t::ceiling), false, true); - if (gltexture) + texture = TexMan.GetGameTexture(frontsector->GetTexture(sector_t::ceiling), true); + if (texture && texture->isValid()) { DoTexture(di, RENDERWALL_TOP, seg, (seg->linedef->flags & (ML_DONTPEGTOP)) == 0, crefz, realback->GetPlaneTexZ(sector_t::ceiling), @@ -2074,17 +2075,17 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ bool drawfogboundary = !di->isFullbrightScene() && di->CheckFog(frontsector, backsec); auto tex = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::mid), true); - if (tex != NULL) + if (tex != NULL && tex->isValid()) { if (di->Level->i_compatflags & COMPATF_MASKEDMIDTEX) { tex = tex->GetRawTexture(); } - gltexture = FMaterial::ValidateTexture(tex->GetTexture(), false); + texture = tex; } - else gltexture = NULL; + else texture = nullptr; - if (gltexture || drawfogboundary) + if (texture || drawfogboundary) { DoMidTexture(di, seg, drawfogboundary, frontsector, backsector, realfront, realback, fch1, fch2, ffh1, ffh2, bch1, bch2, bfh1, bfh2); @@ -2114,8 +2115,8 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ if (bfh1 > ffh1 || bfh2 > ffh2) { - gltexture = FMaterial::ValidateTexture(seg->sidedef->GetTexture(side_t::bottom), false, true); - if (gltexture) + texture = TexMan.GetGameTexture(seg->sidedef->GetTexture(side_t::bottom), true); + if (texture && texture->isValid()) { DoTexture(di, RENDERWALL_BOTTOM, seg, (seg->linedef->flags & ML_DONTPEGBOTTOM) > 0, realback->GetPlaneTexZ(sector_t::floor), frefz, @@ -2133,8 +2134,8 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ // render it anyway with the sector's floor texture. With a background sky // there are ugly holes otherwise and slopes are simply not precise enough // to mach in any case. - gltexture = FMaterial::ValidateTexture(frontsector->GetTexture(sector_t::floor), false, true); - if (gltexture) + texture = TexMan.GetGameTexture(frontsector->GetTexture(sector_t::floor), true); + if (texture && texture->isValid()) { DoTexture(di, RENDERWALL_BOTTOM, seg, (seg->linedef->flags & ML_DONTPEGBOTTOM) > 0, realback->GetPlaneTexZ(sector_t::floor), frefz, @@ -2203,13 +2204,13 @@ void HWWall::ProcessLowerMiniseg(HWDrawInfo *di, seg_t *seg, sector_t * frontsec zfloor[0] = zfloor[1] = ffh; - gltexture = FMaterial::ValidateTexture(frontsector->GetTexture(sector_t::floor), false, true); + texture = TexMan.GetGameTexture(frontsector->GetTexture(sector_t::floor), true); - if (gltexture) + if (texture && texture->isValid()) { FTexCoordInfo tci; type = RENDERWALL_BOTTOM; - tci.GetFromTexture(gltexture->Source(), 1, 1, false); + tci.GetFromTexture(texture, 1, 1, false); SetWallCoordinates(seg, &tci, bfh, bfh, bfh, ffh, ffh, 0); PutWall(di, false); } From cca3f878f5b3aa68682595d622b84492819d18ac Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 00:29:23 +0200 Subject: [PATCH 019/220] - removed FMaterial references from other high level renderer data like HWFlat and HWSprite. --- src/common/textures/textures.h | 4 +- .../hwrenderer/scene/hw_drawlist.cpp | 2 +- .../hwrenderer/scene/hw_drawlistadd.cpp | 6 +-- .../hwrenderer/scene/hw_drawstructs.h | 6 +-- src/rendering/hwrenderer/scene/hw_flats.cpp | 45 ++++++++++--------- src/rendering/hwrenderer/scene/hw_portal.cpp | 13 +++--- .../hwrenderer/scene/hw_renderstate.h | 8 +++- src/rendering/hwrenderer/scene/hw_sprites.cpp | 23 +++++----- src/rendering/hwrenderer/scene/hw_walls.cpp | 7 ++- src/rendering/hwrenderer/scene/hw_weapon.cpp | 11 ++--- src/rendering/hwrenderer/scene/hw_weapon.h | 4 +- 11 files changed, 68 insertions(+), 61 deletions(-) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 90de86eae0..a88bed179a 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -649,6 +649,8 @@ public: bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. bool isMultiPatch() const { return wrapped.bMultiPatch; } bool isFullbrightDisabled() const { return wrapped.isFullbrightDisabled(); } + bool isFullbright() const { return wrapped.isFullbright(); } + bool expandSprites() const { return wrapped.bExpandSprite; } bool useWorldPanning() const { return wrapped.UseWorldPanning(); } bool allowNoDecals() const { return wrapped.allowNoDecals(); } void SetTranslucent(bool on) { wrapped.bTranslucent = on; } @@ -710,7 +712,7 @@ public: void SetSize(int x, int y) { wrapped.SetSize(x, y); } void SetSpriteRect() { wrapped.SetSpriteRect(); } - const SpritePositioningInfo& GetSpritePositioning() { if (wrapped.mTrimResult == -1) wrapped.SetupSpriteData(); return wrapped.spi; } + const SpritePositioningInfo& GetSpritePositioning(int which) { /* todo: keep two sets of positioning infd*/ if (wrapped.mTrimResult == -1) wrapped.SetupSpriteData(); return wrapped.spi; } int GetAreas(FloatRect** pAreas) const { return wrapped.GetAreas(pAreas); } bool GetTranslucency() diff --git a/src/rendering/hwrenderer/scene/hw_drawlist.cpp b/src/rendering/hwrenderer/scene/hw_drawlist.cpp index 54f5db6a56..ae3a83e78f 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlist.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlist.cpp @@ -737,7 +737,7 @@ void HWDrawList::SortFlats() { HWFlat * w1 = flats[a.index]; HWFlat* w2 = flats[b.index]; - return w1->gltexture < w2->gltexture; + return w1->texture < w2->texture; }); } } diff --git a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp index 646f52279b..7224824d35 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -96,12 +96,12 @@ void HWDrawInfo::AddFlat(HWFlat *flat, bool fog) { int list; - if (flat->renderstyle != STYLE_Translucent || flat->alpha < 1.f - FLT_EPSILON || fog || flat->gltexture == nullptr) + if (flat->renderstyle != STYLE_Translucent || flat->alpha < 1.f - FLT_EPSILON || fog || flat->texture == nullptr) { // translucent 3D floors go into the regular translucent list, translucent portals go into the translucent border list. list = (flat->renderflags&SSRF_RENDER3DPLANES) ? GLDL_TRANSLUCENT : GLDL_TRANSLUCENTBORDER; } - else if (flat->gltexture->GetTranslucency()) + else if (flat->texture->GetTranslucency()) { if (flat->stack) { @@ -118,7 +118,7 @@ void HWDrawInfo::AddFlat(HWFlat *flat, bool fog) } else //if (flat->hacktype != SSRF_FLOODHACK) // The flood hack may later need different treatment but with the current setup can go into the existing render list. { - bool masked = flat->gltexture->isMasked() && ((flat->renderflags&SSRF_RENDER3DPLANES) || flat->stack); + bool masked = flat->texture->isMasked() && ((flat->renderflags&SSRF_RENDER3DPLANES) || flat->stack); list = masked ? GLDL_MASKEDFLATS : GLDL_PLAINFLATS; } auto newflat = drawlists[list].NewFlat(); diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 236d45332a..347f96aad2 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -295,7 +295,7 @@ class HWFlat public: sector_t * sector; FSection *section; - FMaterial *gltexture; + FGameTexture *texture; TextureManipulation* TextureFx; float z; // the z position of the flat (only valid for non-sloped planes) @@ -369,7 +369,7 @@ public: float trans; int dynlightindex; - FMaterial *gltexture; + FGameTexture *texture; AActor * actor; particle_t * particle; TArray *lightlist; @@ -426,7 +426,7 @@ inline float Dist2(float x1,float y1,float x2,float y2) return sqrtf((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } -bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FMaterial * gltexture, VSMatrix &mat); +bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FGameTexture * gltexture, VSMatrix &mat); void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata); extern const float LARGE_VALUE; diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 9f592bf057..a4e8d1eee0 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -45,6 +45,7 @@ #include "hwrenderer/dynlights/hw_lightbuffer.h" #include "hw_drawstructs.h" #include "hw_renderstate.h" +#include "texturemanager.h" #ifdef _DEBUG CVAR(Int, gl_breaksec, -1, 0) @@ -56,28 +57,28 @@ CVAR(Int, gl_breaksec, -1, 0) // //========================================================================== -bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FMaterial * gltexture, VSMatrix &dest) +bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FGameTexture * gltexture, VSMatrix &dest) { // only manipulate the texture matrix if needed. if (!secplane->Offs.isZero() || secplane->Scale.X != 1. || secplane->Scale.Y != 1 || secplane->Angle != 0 || - gltexture->TextureWidth() != 64 || - gltexture->TextureHeight() != 64) + gltexture->GetDisplayWidth() != 64 || + gltexture->GetDisplayHeight() != 64) { - float uoffs = secplane->Offs.X / gltexture->TextureWidth(); - float voffs = secplane->Offs.Y / gltexture->TextureHeight(); + float uoffs = secplane->Offs.X / gltexture->GetDisplayWidth(); + float voffs = secplane->Offs.Y / gltexture->GetDisplayHeight(); float xscale1 = secplane->Scale.X; float yscale1 = secplane->Scale.Y; - if (gltexture->hasCanvas()) + if (gltexture->isHardwareCanvas()) { yscale1 = 0 - yscale1; } float angle = -secplane->Angle; - float xscale2 = 64.f / gltexture->TextureWidth(); - float yscale2 = 64.f / gltexture->TextureHeight(); + float xscale2 = 64.f / gltexture->GetDisplayWidth(); + float yscale2 = 64.f / gltexture->GetDisplayHeight(); dest.loadIdentity(); dest.scale(xscale1, yscale1, 1.0f); @@ -203,7 +204,7 @@ void HWFlat::DrawSubsectors(HWDrawInfo *di, FRenderState &state) void HWFlat::DrawOtherPlanes(HWDrawInfo *di, FRenderState &state) { - state.SetMaterial(gltexture, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); // Draw the subsectors assigned to it due to missing textures auto pNode = (renderflags&SSRF_RENDERFLOOR) ? @@ -235,7 +236,7 @@ void HWFlat::DrawFloodPlanes(HWDrawInfo *di, FRenderState &state) // This requires a stencil because the projected plane interferes with // the depth buffer - state.SetMaterial(gltexture, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); // Draw the subsectors assigned to it due to missing textures auto pNode = (renderflags&SSRF_RENDERFLOOR) ? @@ -323,14 +324,14 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) { if (sector->special != GLSector_Skybox) { - state.SetMaterial(gltexture, CLAMP_NONE, 0, -1); - state.SetPlaneTextureRotation(&plane, gltexture); + state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); + state.SetPlaneTextureRotation(&plane, texture); DrawSubsectors(di, state); state.EnableTextureMatrix(false); } else if (!hacktype) { - state.SetMaterial(gltexture, CLAMP_XY, 0, -1); + state.SetMaterial(texture, false, CLAMP_XY, 0, -1); state.SetLightIndex(dynlightindex); state.Draw(DT_TriangleStrip,iboindex, 4); flatvertices += 4; @@ -340,7 +341,7 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) else { state.SetRenderStyle(renderstyle); - if (!gltexture) + if (!texture || !texture->isValid()) { state.AlphaFunc(Alpha_GEqual, 0.f); state.EnableTexture(false); @@ -349,10 +350,10 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) } else { - if (!gltexture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); + if (!texture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); else state.AlphaFunc(Alpha_GEqual, 0.f); - state.SetMaterial(gltexture, CLAMP_NONE, 0, -1); - state.SetPlaneTextureRotation(&plane, gltexture); + state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); + state.SetPlaneTextureRotation(&plane, texture); DrawSubsectors(di, state); state.EnableTextureMatrix(false); } @@ -379,7 +380,7 @@ inline void HWFlat::PutFlat(HWDrawInfo *di, bool fog) } else if (!screen->BuffersArePersistent()) { - if (di->Level->HasDynamicLights && gltexture != nullptr && !di->isFullbrightScene() && !(hacktype & (SSRF_PLANEHACK|SSRF_FLOODHACK)) ) + if (di->Level->HasDynamicLights && texture != nullptr && !di->isFullbrightScene() && !(hacktype & (SSRF_PLANEHACK|SSRF_FLOODHACK)) ) { SetupLights(di, section->lighthead, lightdata, sector->PortalGroup); } @@ -405,9 +406,9 @@ void HWFlat::Process(HWDrawInfo *di, sector_t * model, int whichplane, bool fog) if (!fog) { - gltexture=FMaterial::ValidateTexture(plane.texture, false, true); - if (!gltexture) return; - if (gltexture->isFullbright()) + texture = TexMan.GetGameTexture(plane.texture, true); + if (!texture || !texture->isValid()) return; + if (texture->isFullbright()) { Colormap.MakeWhite(); lightlevel=255; @@ -415,7 +416,7 @@ void HWFlat::Process(HWDrawInfo *di, sector_t * model, int whichplane, bool fog) } else { - gltexture = NULL; + texture = NULL; lightlevel = abs(lightlevel); } diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index f9953051dc..f3915096f1 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -36,6 +36,7 @@ #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" +#include "texturemanager.h" EXTERN_CVAR(Int, r_mirror_recursions) EXTERN_CVAR(Bool, gl_portals) @@ -947,12 +948,12 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state) { Clocker c(PortalAll); - FMaterial * gltexture; HWSectorPlane * sp = &origin->plane; auto &vp = di->Viewpoint; - gltexture = FMaterial::ValidateTexture(sp->texture, false, true); - if (!gltexture) + auto texture = TexMan.GetGameTexture(sp->texture, true); + + if (!texture || !texture->isValid()) { state.ClearScreen(); return; @@ -960,7 +961,7 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state) di->SetCameraPos(vp.Pos); - if (gltexture && gltexture->isFullbright()) + if (texture->isFullbright()) { // glowing textures are always drawn full bright without color di->SetColor(state, 255, 0, false, origin->colormap, 1.f); @@ -974,10 +975,10 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state) } - state.SetMaterial(gltexture, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); state.SetObjectColor(origin->specialcolor); - state.SetPlaneTextureRotation(sp, gltexture); + state.SetPlaneTextureRotation(sp, texture); state.AlphaFunc(Alpha_GEqual, 0.f); state.SetRenderStyle(STYLE_Source); diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index 7791dbc287..44cce14dce 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -522,7 +522,7 @@ public: else mAlphaThreshold = thresh - 0.001f; } - void SetPlaneTextureRotation(HWSectorPlane *plane, FMaterial *texture) + void SetPlaneTextureRotation(HWSectorPlane *plane, FGameTexture *texture) { if (hw_SetPlaneTextureRotation(plane, texture, mTextureMatrix)) { @@ -569,6 +569,12 @@ public: mTextureModeFlags = mat->GetLayerFlags(); } + void SetMaterial(FGameTexture* tex, bool expandmode, int clampmode, int translation, int overrideshader) + { + expandmode &= tex->expandSprites(); + SetMaterial(FMaterial::ValidateTexture(tex->GetTexture(), expandmode), clampmode, translation, overrideshader); + } + void SetClipSplit(float bottom, float top) { mClipSplit[0] = bottom; diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 035b031f69..392d1caadc 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -94,7 +94,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) // Optionally use STYLE_ColorBlend in place of STYLE_Add for fullbright items. if (RenderStyle == LegacyRenderStyles[STYLE_Add] && trans > 1.f - FLT_EPSILON && gl_usecolorblending && !di->isFullbrightScene() && actor && - fullbright && gltexture && !gltexture->GetTranslucency()) + fullbright && texture && !texture->GetTranslucency()) { RenderStyle = LegacyRenderStyles[STYLE_ColorAdd]; } @@ -106,7 +106,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) { state.AlphaFunc(Alpha_GEqual, 0.f); } - else if (!gltexture || !gltexture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold); + else if (!texture || !texture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_sprite_threshold); else state.AlphaFunc(Alpha_Greater, 0.f); if (RenderStyle.BlendOp == STYLEOP_Shadow) @@ -197,7 +197,8 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) state.SetFog(0, 0); } - if (gltexture) state.SetMaterial(gltexture, CLAMP_XY, translation, OverrideShader); + uint32_t spritetype = (actor->renderflags & RF_SPRITETYPEMASK); + if (texture) state.SetMaterial(texture, spritetype == RF_FACESPRITE, CLAMP_XY, translation, OverrideShader); else if (!modelframe) state.EnableTexture(false); //SetColor(lightlevel, rel, Colormap, trans); @@ -818,7 +819,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t int type = thing->renderflags & RF_SPRITETYPEMASK; auto tex = TexMan.GetGameTexture(patch, false); if (!tex || !tex->isValid()) return; - auto& spi = tex->GetSpritePositioning(); + auto& spi = tex->GetSpritePositioning(type == RF_FACESPRITE); vt = spi.GetSpriteVT(); vb = spi.GetSpriteVB(); @@ -842,8 +843,8 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t ur = spi.GetSpriteUL(); } - gltexture = FMaterial::ValidateTexture(patch, (type == RF_FACESPRITE), false); - if (!gltexture) + texture = TexMan.GetGameTexture(patch, false); + if (!texture || !texture->isValid()) return; if (thing->renderflags & RF_SPRITEFLIP) // [SP] Flip back @@ -904,7 +905,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t x1 = x2 = x; y1 = y2 = y; z1 = z2 = z; - gltexture = nullptr; + texture = nullptr; } depth = (float)((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin); @@ -916,7 +917,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // allow disabling of the fullbright flag by a brightmap definition // (e.g. to do the gun flashes of Doom's zombies correctly. fullbright = (thing->flags5 & MF5_BRIGHT) || - ((thing->renderflags & RF_FULLBRIGHT) && (!gltexture || !gltexture->Source()->isFullbrightDisabled())); + ((thing->renderflags & RF_FULLBRIGHT) && (!texture || !texture->isFullbrightDisabled())); lightlevel = fullbright ? 255 : hw_ClampLight(rendersector->GetTexture(sector_t::ceiling) == skyflatnum ? @@ -1035,7 +1036,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t RenderStyle.DestAlpha = STYLEALPHA_InvSrc; } } - if ((gltexture && gltexture->GetTranslucency()) || (RenderStyle.Flags & STYLEF_RedIsAlpha) || (modelframe && thing->RenderStyle != DefaultRenderStyle())) + if ((texture && texture->GetTranslucency()) || (RenderStyle.Flags & STYLEF_RedIsAlpha) || (modelframe && thing->RenderStyle != DefaultRenderStyle())) { if (hw_styleflags == STYLEHW_Solid) { @@ -1163,7 +1164,7 @@ void HWSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * ThingColor.a = 255; modelframe=nullptr; - gltexture=nullptr; + texture=nullptr; topclip = LARGE_VALUE; bottomclip = -LARGE_VALUE; index = 0; @@ -1191,7 +1192,7 @@ void HWSprite::ProcessParticle (HWDrawInfo *di, particle_t *particle, sector_t * ur = 1; vt = 0; vb = 1; - gltexture = FMaterial::ValidateTexture(lump, true, false); + texture = TexMan.GetGameTexture(lump, false); } } diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index b96634c7bf..68ecbae3ab 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -103,8 +103,8 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state) state.SetRenderStyle(STYLE_Add); state.AlphaFunc(Alpha_Greater, 0); - FMaterial * pat = FMaterial::ValidateTexture(TexMan.mirrorTexture, false, false); - state.SetMaterial(pat, CLAMP_NONE, 0, -1); + auto tex = TexMan.GetGameTexture(TexMan.mirrorTexture, false); + state.SetMaterial(tex, false, CLAMP_NONE, 0, -1); flags &= ~HWWall::HWF_GLOW; RenderWall(di, state, HWWall::RWF_BLANK); @@ -156,8 +156,7 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) state.SetGlowParams(topglowcolor, bottomglowcolor); state.SetGlowPlanes(frontsector->ceilingplane, frontsector->floorplane); } - auto mat = FMaterial::ValidateTexture(texture->GetTexture(), false, true); - state.SetMaterial(mat, flags & 3, 0, -1); + state.SetMaterial(texture, false, flags & 3, 0, -1); if (type == RENDERWALL_M2SNF) { diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index 6cd2313764..f07c667f30 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -94,9 +94,9 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) } else { - float thresh = (huds->tex->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; + float thresh = (huds->texture->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; state.AlphaFunc(Alpha_GEqual, thresh); - state.SetMaterial(huds->tex, CLAMP_XY_NOMIP, (huds->weapon->Flags & PSPF_PLAYERTRANSLATED) ? huds->owner->Translation : 0, huds->OverrideShader); + state.SetMaterial(huds->texture, true, CLAMP_XY_NOMIP, (huds->weapon->Flags & PSPF_PLAYERTRANSLATED) ? huds->owner->Translation : 0, huds->OverrideShader); state.Draw(DT_TriangleStrip, huds->mx, 4); } @@ -419,7 +419,7 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, auto tex = TexMan.GetGameTexture(lump, false); if (!tex || !tex->isValid()) return false; - auto& spi = tex->GetSpritePositioning(); + auto& spi = tex->GetSpritePositioning(1); float vw = (float)viewwidth; float vh = (float)viewheight; @@ -473,10 +473,7 @@ bool HUDSprite::GetWeaponRect(HWDrawInfo *di, DPSprite *psp, float sx, float sy, verts.first[2].Set(x2, y1, 0, u2, v1); verts.first[3].Set(x2, y2, 0, u2, v2); - FMaterial* mat = FMaterial::ValidateTexture(lump, true, false); - if (!mat) return false; - - this->tex = mat; + texture = tex; return true; } diff --git a/src/rendering/hwrenderer/scene/hw_weapon.h b/src/rendering/hwrenderer/scene/hw_weapon.h index 62c5a70a04..d77337e427 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.h +++ b/src/rendering/hwrenderer/scene/hw_weapon.h @@ -8,7 +8,7 @@ class AActor; enum area_t : int; struct FSpriteModelFrame; struct HWDrawInfo; -class FMaterial; +class FGameTexture; struct WeaponPosition @@ -29,7 +29,7 @@ struct HUDSprite { AActor *owner; DPSprite *weapon; - FMaterial *tex; + FGameTexture *texture; FSpriteModelFrame *mframe; FColormap cm; From 4cbd20e82226ceffcb30dc825a79b533033f711b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 00:35:09 +0200 Subject: [PATCH 020/220] - transitioned sky and decal code away from FMaterial. --- src/common/textures/hw_material.h | 8 ----- src/common/textures/skyboxtexture.h | 28 --------------- src/common/textures/textures.h | 35 +++++++++++++++++++ src/rendering/hwrenderer/scene/hw_decal.cpp | 23 +++++------- .../hwrenderer/scene/hw_drawstructs.h | 2 +- src/rendering/hwrenderer/scene/hw_portal.h | 6 ++-- src/rendering/hwrenderer/scene/hw_sky.cpp | 8 ++--- src/rendering/hwrenderer/scene/hw_skydome.cpp | 8 ++--- src/rendering/hwrenderer/scene/hw_skydome.h | 4 +-- .../hwrenderer/scene/hw_skyportal.cpp | 15 ++++---- 10 files changed, 65 insertions(+), 72 deletions(-) diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index a280ac6fb1..9e9428759b 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -125,14 +125,6 @@ public: return mTopOffset; } - // Get right/bottom UV coordinates for patch drawing - float GetUL() const { return 0; } - float GetVT() const { return 0; } - float GetUR() const { return 1; } - float GetVB() const { return 1; } - float GetU(float upix) const { return upix/(float)mWidth; } - float GetV(float vpix) const { return vpix/(float)mHeight; } - static FMaterial *ValidateTexture(FTexture * tex, bool expand, bool create = true); static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans, bool create = true); const TArray &GetLayerArray() const diff --git a/src/common/textures/skyboxtexture.h b/src/common/textures/skyboxtexture.h index 1c7a6ad2b6..14ada8b4ae 100644 --- a/src/common/textures/skyboxtexture.h +++ b/src/common/textures/skyboxtexture.h @@ -1,31 +1,3 @@ #pragma once #include "textures.h" -//----------------------------------------------------------------------------- -// -// This is not a real texture but will be added to the texture manager -// so that it can be handled like any other sky. -// -//----------------------------------------------------------------------------- - -class FSkyBox : public FImageTexture -{ -public: - - FTexture *previous; - FTexture * faces[6]; - bool fliptop; - - FSkyBox(const char *name); - void SetSize(); - - bool Is3Face() const - { - return faces[5] == nullptr; - } - - bool IsFlipped() const - { - return fliptop; - } -}; diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index a88bed179a..f288214cc4 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -623,6 +623,35 @@ struct FTexCoordInfo void GetFromTexture(FGameTexture* tex, float x, float y, bool forceworldpanning); }; +//----------------------------------------------------------------------------- +// +// Todo: Get rid of this +// The faces can easily be stored in the material layer array +// +//----------------------------------------------------------------------------- + +class FSkyBox : public FImageTexture +{ +public: + + FTexture* previous; + FTexture* faces[6]; + bool fliptop; + + FSkyBox(const char* name); + void SetSize(); + + bool Is3Face() const + { + return faces[5] == nullptr; + } + + bool IsFlipped() const + { + return fliptop; + } +}; + // Refactoring helper to allow piece by piece adjustment of the API class FGameTexture { @@ -714,12 +743,18 @@ public: void SetSpriteRect() { wrapped.SetSpriteRect(); } const SpritePositioningInfo& GetSpritePositioning(int which) { /* todo: keep two sets of positioning infd*/ if (wrapped.mTrimResult == -1) wrapped.SetupSpriteData(); return wrapped.spi; } int GetAreas(FloatRect** pAreas) const { return wrapped.GetAreas(pAreas); } + PalEntry GetSkyCapColor(bool bottom) { return wrapped.GetSkyCapColor(bottom); } bool GetTranslucency() { return wrapped.GetTranslucency(); } + FGameTexture *GetSkyFace(int num) + { + return reinterpret_cast(isSkybox() ? static_cast(&wrapped)->faces[num] : nullptr); + } + }; diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index d112d5aeec..e92a6c80ee 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -47,8 +47,6 @@ void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) { - auto tex = gltexture; - // calculate dynamic light effect. if (di->Level->HasDynamicLights && !di->isFullbrightScene() && gl_light_sprites) { @@ -68,7 +66,7 @@ void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) state.SetTextureMode(decal->RenderStyle); state.SetRenderStyle(decal->RenderStyle); - state.SetMaterial(tex, CLAMP_XY, decal->Translation, -1); + state.SetMaterial(texture, false, CLAMP_XY, decal->Translation, -1); // If srcalpha is one it looks better with a higher alpha threshold @@ -313,8 +311,6 @@ void HWWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor float vx = (glseg.x2 - glseg.x1) / linelength; float vy = (glseg.y2 - glseg.y1) / linelength; - FMaterial* tex = FMaterial::ValidateTexture(texture->GetTexture(), false); - DecalVertex dv[4]; enum { @@ -330,11 +326,12 @@ void HWWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor dv[UL].z = dv[UR].z = zpos; dv[LL].z = dv[LR].z = dv[UL].z - decalheight; - dv[UL].v = dv[UR].v = tex->GetVT(); + dv[UL].v = dv[UR].v = 0.f; - dv[UL].u = dv[LL].u = tex->GetU(lefttex / decal->ScaleX); - dv[LR].u = dv[UR].u = tex->GetU(righttex / decal->ScaleX); - dv[LL].v = dv[LR].v = tex->GetVB(); + float decalscale = float(decal->ScaleX * texture->GetDisplayWidth()); + dv[UL].u = dv[LL].u = lefttex / decalscale; + dv[LR].u = dv[UR].u = righttex / decalscale; + dv[LL].v = dv[LR].v = 1.f; // now clip to the top plane float vzt = (ztop[UL] - ztop[LL]) / linelength; @@ -377,17 +374,15 @@ void HWWall::ProcessDecal(HWDrawInfo *di, DBaseDecal *decal, const FVector3 &nor if (flipx) { - float ur = tex->GetUR(); - for (i = 0; i < 4; i++) dv[i].u = ur - dv[i].u; + for (i = 0; i < 4; i++) dv[i].u = 1.f - dv[i].u; } if (flipy) { - float vb = tex->GetVB(); - for (i = 0; i < 4; i++) dv[i].v = vb - dv[i].v; + for (i = 0; i < 4; i++) dv[i].v = 1.f - dv[i].v; } HWDecal *gldecal = di->AddDecal(type == RENDERWALL_MIRRORSURFACE); - gldecal->gltexture = tex; + gldecal->texture = texture; gldecal->decal = decal; if (decal->RenderFlags & RF_FULLBRIGHT) diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 347f96aad2..e8a244562d 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -401,7 +401,7 @@ struct DecalVertex struct HWDecal { - FMaterial *gltexture; + FGameTexture *texture; TArray *lightlist; DBaseDecal *decal; DecalVertex dv[4]; diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index 63a2f55181..10fd90d7db 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -13,7 +13,7 @@ struct HWSkyInfo { float x_offset[2]; float y_offset; // doubleskies don't have a y-offset - FMaterial * texture[2]; + FGameTexture * texture[2]; FTextureID skytexno1; bool mirrored; bool doublesky; @@ -358,8 +358,8 @@ struct HWSkyPortal : public HWPortal friend struct HWEEHorizonPortal; void RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply = true); - void RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FMaterial * gltex, float x_offset, bool sky2); - void RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * tex, float x_offset, float y_offset, bool mirror, int mode); + void RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FGameTexture * gltex, float x_offset, bool sky2); + void RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode); protected: virtual void DrawContents(HWDrawInfo *di, FRenderState &state); diff --git a/src/rendering/hwrenderer/scene/hw_sky.cpp b/src/rendering/hwrenderer/scene/hw_sky.cpp index ce48d94376..af2328bbc0 100644 --- a/src/rendering/hwrenderer/scene/hw_sky.cpp +++ b/src/rendering/hwrenderer/scene/hw_sky.cpp @@ -63,7 +63,7 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) FTextureID texno = s->GetTexture(pos); auto tex = TexMan.GetGameTexture(texno, true); if (!tex || !tex->isValid()) goto normalsky; - texture[0] = FMaterial::ValidateTexture(tex->GetTexture(), false); + texture[0] = tex; skytexno1 = texno; x_offset[0] = s->GetTextureXOffset(pos) * (360.f/65536.f); y_offset = s->GetTextureYOffset(pos); @@ -76,7 +76,7 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) { auto tex1 = TexMan.GetGameTexture(di->Level->skytexture1, true); if (tex1) tex1 = tex1->GetFrontSkyLayer(); - texture[1] = FMaterial::ValidateTexture(tex1->GetTexture(), false); + texture[1] = tex1; x_offset[1] = di->Level->hw_sky1pos; doublesky = true; } @@ -84,14 +84,14 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) if ((di->Level->flags&LEVEL_SWAPSKIES || (sky1 == PL_SKYFLAT) || (di->Level->flags&LEVEL_DOUBLESKY)) && di->Level->skytexture2 != di->Level->skytexture1) // If both skies are equal use the scroll offset of the first! { - texture[0] = FMaterial::ValidateTexture(di->Level->skytexture2, false, true); + texture[0] = TexMan.GetGameTexture(di->Level->skytexture2, true); skytexno1 = di->Level->skytexture2; sky2 = true; x_offset[0] = di->Level->hw_sky2pos; } else if (!doublesky) { - texture[0] = FMaterial::ValidateTexture(di->Level->skytexture1, false, true); + texture[0] = TexMan.GetGameTexture(di->Level->skytexture1, true); skytexno1 = di->Level->skytexture1; x_offset[0] = di->Level->hw_sky1pos; } diff --git a/src/rendering/hwrenderer/scene/hw_skydome.cpp b/src/rendering/hwrenderer/scene/hw_skydome.cpp index 968b79fbb2..58f25f5329 100644 --- a/src/rendering/hwrenderer/scene/hw_skydome.cpp +++ b/src/rendering/hwrenderer/scene/hw_skydome.cpp @@ -282,17 +282,17 @@ void FSkyVertexBuffer::CreateDome() // //----------------------------------------------------------------------------- -void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix) +void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix) { - int texw = tex->TextureWidth(); - int texh = tex->TextureHeight(); + int texw = tex->GetDisplayWidth(); + int texh = tex->GetDisplayHeight(); modelMatrix.loadIdentity(); modelMatrix.rotate(-180.0f + x_offset, 0.f, 1.f, 0.f); float xscale = texw < 1024.f ? floor(1024.f / float(texw)) : 1.f; float yscale = 1.f; - auto texskyoffset = tex->Source()->GetSkyOffset() + skyoffset; + auto texskyoffset = tex->GetSkyOffset() + skyoffset; if (texh <= 128 && (di->Level->flags & LEVEL_FORCETILEDSKY)) { modelMatrix.translate(0.f, (-40 + texskyoffset)*skyoffsetfactor, 0.f); diff --git a/src/rendering/hwrenderer/scene/hw_skydome.h b/src/rendering/hwrenderer/scene/hw_skydome.h index 4084ef96f3..e4865f3308 100644 --- a/src/rendering/hwrenderer/scene/hw_skydome.h +++ b/src/rendering/hwrenderer/scene/hw_skydome.h @@ -4,7 +4,7 @@ #include "matrix.h" #include "hwrenderer/data/buffers.h" -class FMaterial; +class FGameTexture; class FRenderState; class IVertexBuffer; struct HWSkyPortal; @@ -70,7 +70,7 @@ public: FSkyVertexBuffer(); ~FSkyVertexBuffer(); - void SetupMatrices(HWDrawInfo *di, FMaterial *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix); + void SetupMatrices(HWDrawInfo *di, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix); std::pair GetBufferObjects() const { return std::make_pair(mVertexBuffer, nullptr); diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index d4c4f11a74..e1eb942d86 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -50,11 +50,11 @@ void HWSkyPortal::RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, // //----------------------------------------------------------------------------- -void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * tex, float x_offset, float y_offset, bool mirror, int mode) +void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode) { if (tex) { - state.SetMaterial(tex, CLAMP_NONE, 0, -1); + state.SetMaterial(tex, false, CLAMP_NONE, 0, -1); state.EnableModelMatrix(true); state.EnableTextureMatrix(true); @@ -66,13 +66,12 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * te // The caps only get drawn for the main layer but not for the overlay. if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL) { - auto base = tex->Source(); - PalEntry pe = base->GetSkyCapColor(false); + PalEntry pe = tex->GetSkyCapColor(false); state.SetObjectColor(pe); state.EnableTexture(false); RenderRow(di, state, DT_TriangleFan, 0); - pe = base->GetSkyCapColor(true); + pe = tex->GetSkyCapColor(true); state.SetObjectColor(pe); RenderRow(di, state, DT_TriangleFan, rc); state.EnableTexture(true); @@ -95,9 +94,9 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FMaterial * te // //----------------------------------------------------------------------------- -void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FMaterial * gltex, float x_offset, bool sky2) +void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FGameTexture * gltex, float x_offset, bool sky2) { - FSkyBox * sb = static_cast(gltex->Source()); + FSkyBox * sb = static_cast(gltex->GetTexture()); int faces; FMaterial * tex; @@ -182,7 +181,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) di->SetupView(state, 0, 0, 0, !!(mState->MirrorFlag & 1), !!(mState->PlaneMirrorFlag & 1)); state.SetVertexBuffer(vertexBuffer); - if (origin->texture[0] && origin->texture[0]->Source()->isSkybox()) + if (origin->texture[0] && origin->texture[0]->isSkybox()) { RenderBox(di, state, origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->sky2); } From c178313da5b8ec3e5054adedf3a49ac5ed907967 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 00:36:08 +0200 Subject: [PATCH 021/220] - got rid of the last remaining FMaterial references in the high level renderer. --- src/common/textures/textures.h | 2 ++ src/rendering/hwrenderer/models/hw_models.cpp | 3 +- .../hwrenderer/scene/hw_skyportal.cpp | 29 +++++++------------ .../hwrenderer/utility/hw_draw2d.cpp | 7 ++--- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index f288214cc4..c93207968e 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -750,10 +750,12 @@ public: return wrapped.GetTranslucency(); } + // 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); } + bool GetSkyFlip() { return isSkybox() ? static_cast(&wrapped)->fliptop : false; } }; diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 4b2786df5d..6c76126e51 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -114,8 +114,7 @@ void FHWModelRenderer::SetInterpolation(double inter) void FHWModelRenderer::SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) { - FMaterial * tex = FMaterial::ValidateTexture(skin->GetTexture(), false); - state.SetMaterial(tex, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1); + state.SetMaterial(skin, false, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1); state.SetLightIndex(modellightindex); } diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index e1eb942d86..5b13f73712 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -94,11 +94,9 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * // //----------------------------------------------------------------------------- -void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FGameTexture * gltex, float x_offset, bool sky2) +void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FGameTexture * tex, float x_offset, bool sky2) { - FSkyBox * sb = static_cast(gltex->GetTexture()); int faces; - FMaterial * tex; state.EnableModelMatrix(true); state.mModelMatrix.loadIdentity(); @@ -108,46 +106,39 @@ void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texn else state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector2.X, di->Level->info->skyrotatevector2.Z, di->Level->info->skyrotatevector2.Y); - if (sb->faces[5]) + if (tex->GetSkyFace(5)) { faces=4; // north - tex = FMaterial::ValidateTexture(sb->faces[0], false); - state.SetMaterial(tex, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(0), false, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(0), 4); // east - tex = FMaterial::ValidateTexture(sb->faces[1], false); - state.SetMaterial(tex, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(1), false, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(1), 4); // south - tex = FMaterial::ValidateTexture(sb->faces[2], false); - state.SetMaterial(tex, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(2), false, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(2), 4); // west - tex = FMaterial::ValidateTexture(sb->faces[3], false); - state.SetMaterial(tex, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(3), false, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(3), 4); } else { faces=1; - tex = FMaterial::ValidateTexture(sb->faces[0], false); - state.SetMaterial(tex, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(0), false, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(-1), 10); } // top - tex = FMaterial::ValidateTexture(sb->faces[faces], false); - state.SetMaterial(tex, CLAMP_XY, 0, -1); - state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(sb->fliptop ? 6 : 5), 4); + state.SetMaterial(tex->GetSkyFace(faces), false, CLAMP_XY, 0, -1); + state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(tex->GetSkyFlip() ? 6 : 5), 4); // bottom - tex = FMaterial::ValidateTexture(sb->faces[faces+1], false); - state.SetMaterial(tex, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(faces+1), false, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(4), 4); state.EnableModelMatrix(false); diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index ea07419bfc..9ea18891e0 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -162,12 +162,9 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) state.AlphaFunc(Alpha_GEqual, 0.f); - if (cmd.mTexture != nullptr) + if (cmd.mTexture != nullptr && cmd.mTexture->isValid()) { - auto mat = FMaterial::ValidateTexture(cmd.mTexture->GetTexture(), false); - if (mat == nullptr) continue; - - state.SetMaterial(mat, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); + state.SetMaterial(cmd.mTexture, false, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); state.EnableTexture(true); // Canvas textures are stored upside down From 31035a6cea16d5051e3290deafd3242415fdfeba Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 00:48:04 +0200 Subject: [PATCH 022/220] - cleaned out the coordinate code in FMaterial. --- src/common/textures/hw_material.cpp | 7 --- src/common/textures/hw_material.h | 55 ------------------- src/rendering/gl/renderer/gl_renderer.cpp | 11 ++-- src/rendering/gl/renderer/gl_renderstate.cpp | 2 +- .../polyrenderer/backend/poly_framebuffer.cpp | 9 ++- .../polyrenderer/backend/poly_renderstate.cpp | 2 +- .../vulkan/renderer/vk_renderstate.cpp | 2 +- .../vulkan/system/vk_framebuffer.cpp | 9 ++- 8 files changed, 16 insertions(+), 81 deletions(-) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 34f60af794..37fa8441a4 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -121,13 +121,6 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) } } } - mWidth = tx->GetTexelWidth(); - mHeight = tx->GetTexelHeight(); - mLeftOffset = tx->GetLeftOffset(0); // These only get used by decals and decals should not use renderer-specific offsets. - mTopOffset = tx->GetTopOffset(0); - mRenderWidth = tx->GetScaledWidth(); - mRenderHeight = tx->GetScaledHeight(); - mExpanded = expanded; mTextureLayers.ShrinkToFit(); diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index 9e9428759b..e211585bab 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -32,13 +32,6 @@ class FMaterial TArray mTextureLayers; int mShaderIndex; int mLayerFlags = 0; - - short mLeftOffset; - short mTopOffset; - short mWidth; - short mHeight; - short mRenderWidth; - short mRenderHeight; bool mExpanded; public: @@ -48,7 +41,6 @@ public: FMaterial(FTexture *tex, bool forceexpand); ~FMaterial(); int GetLayerFlags() const { return mLayerFlags; } - void SetSpriteRect(); int GetShaderIndex() const { return mShaderIndex; } FTexture* Source() const @@ -60,28 +52,11 @@ public: // Only for spftpoly! return imgtex; } - bool isFullbright() const - { - return sourcetex->isFullbright(); - } - bool isHardwareCanvas() const - { - return sourcetex->isHardwareCanvas(); - } - bool GetTranslucency() - { - // This queries the master texture to reduce recalculations. - return imgtex->GetTranslucency(); - } void AddTextureLayer(FTexture *tex) { ValidateTexture(tex, false); mTextureLayers.Push(tex); } - bool isMasked() const - { - return sourcetex->bMasked; - } bool isExpanded() const { return mExpanded; @@ -91,39 +66,9 @@ public: { return mTextureLayers.Size() + 1; } - - bool hasCanvas() - { - return sourcetex->isHardwareCanvas(); - } IHardwareTexture *GetLayer(int i, int translation, FTexture **pLayer = nullptr); - // Patch drawing utilities - - // This is scaled size in integer units as needed by walls and flats - int TextureHeight() const { return mRenderHeight; } - int TextureWidth() const { return mRenderWidth; } - - int GetWidth() const - { - return mWidth; - } - - int GetHeight() const - { - return mHeight; - } - - int GetLeftOffset() const - { - return mLeftOffset; - } - - int GetTopOffset() const - { - return mTopOffset; - } static FMaterial *ValidateTexture(FTexture * tex, bool expand, bool create = true); static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans, bool create = true); diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 06fc5d27b8..08c7caae9d 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -306,7 +306,7 @@ void FGLRenderer::BindToFrameBuffer(FMaterial *mat) FHardwareTexture::Unbind(0); gl_RenderState.ClearLastMaterial(); } - BaseLayer->BindToFrameBuffer(mat->GetWidth(), mat->GetHeight()); + BaseLayer->BindToFrameBuffer(mat->Source()->GetTexelWidth(), mat->Source()->GetTexelHeight()); } //=========================================================================== @@ -320,19 +320,18 @@ void FGLRenderer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, doub // 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(tex, false); - int width = gltex->TextureWidth(); - int height = gltex->TextureHeight(); + float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); StartOffscreen(); BindToFrameBuffer(gltex); IntRect bounds; bounds.left = bounds.top = 0; - bounds.width = FHardwareTexture::GetTexDimension(gltex->GetWidth()); - bounds.height = FHardwareTexture::GetTexDimension(gltex->GetHeight()); + bounds.width = FHardwareTexture::GetTexDimension(tex->GetTexelWidth()); + bounds.height = FHardwareTexture::GetTexDimension(tex->GetTexelHeight()); FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, (float)width / height, (float)width / height, false, false); + RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); EndOffscreen(); diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index 8da456248d..a537d7050a 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -298,7 +298,7 @@ void FGLRenderState::Apply() void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translation, int overrideshader) { - if (mat->isHardwareCanvas()) + if (mat->Source()->isHardwareCanvas()) { mTempTM = TM_OPAQUE; } diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 0e12a82754..6c0e7b1fcd 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -380,19 +380,18 @@ void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, FMaterial *mat = FMaterial::ValidateTexture(tex, false); auto BaseLayer = static_cast(mat->GetLayer(0, 0)); - int width = mat->TextureWidth(); - int height = mat->TextureHeight(); + float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); DCanvas *image = BaseLayer->GetImage(tex, 0, 0); PolyDepthStencil *depthStencil = BaseLayer->GetDepthStencil(tex); mRenderState->SetRenderTarget(image, depthStencil, false); IntRect bounds; bounds.left = bounds.top = 0; - bounds.width = MIN(mat->GetWidth(), image->GetWidth()); - bounds.height = MIN(mat->GetHeight(), image->GetHeight()); + bounds.width = std::min(tex->GetTexelWidth(), image->GetWidth()); + bounds.height = std::min(tex->GetTexelHeight(), image->GetHeight()); FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, (float)width / height, (float)width / height, false, false); + RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); FlushDrawCommands(); DrawerThreads::WaitForWorkers(); diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 6a36105b56..5538fbf371 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -312,7 +312,7 @@ void PolyRenderState::ApplyMaterial() { if (mMaterial.mChanged && mMaterial.mMaterial) { - mTempTM = mMaterial.mMaterial->isHardwareCanvas() ? TM_OPAQUE : TM_NORMAL; + mTempTM = mMaterial.mMaterial->Source()->isHardwareCanvas() ? TM_OPAQUE : TM_NORMAL; FTexture* layer; auto base = static_cast(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation, &layer)); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index b1d2b3e0c8..d647594b1f 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -369,7 +369,7 @@ void VkRenderState::ApplyPushConstants() } int tempTM = TM_NORMAL; - if (mMaterial.mMaterial && mMaterial.mMaterial->isHardwareCanvas()) + if (mMaterial.mMaterial && mMaterial.mMaterial->Source()->isHardwareCanvas()) tempTM = TM_OPAQUE; mPushConstants.uFogEnabled = fogset; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 796526b7e2..6153a574d6 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -519,8 +519,7 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint FMaterial *mat = FMaterial::ValidateTexture(tex, false); auto BaseLayer = static_cast(mat->GetLayer(0, 0)); - int width = mat->TextureWidth(); - int height = mat->TextureHeight(); + float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0); VkTextureImage *depthStencil = BaseLayer->GetDepthStencil(tex); @@ -534,11 +533,11 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint IntRect bounds; bounds.left = bounds.top = 0; - bounds.width = MIN(mat->GetWidth(), image->Image->width); - bounds.height = MIN(mat->GetHeight(), image->Image->height); + bounds.width = std::min(tex->GetTexelWidth(), image->Image->width); + bounds.height = std::min(tex->GetTexelHeight(), image->Image->height); FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, (float)width / height, (float)width / height, false, false); + RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); mRenderState->EndRenderPass(); From 83817080bbfbfd30d0db53923cf796fb74c07a75 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 18:59:14 +0200 Subject: [PATCH 023/220] - more texture cleanup. It is now in a state where FTexture really needs to be separated from FGameTexture. --- src/common/fonts/font.cpp | 2 - src/common/textures/hw_material.cpp | 53 ++++++++++--------- src/common/textures/hw_material.h | 24 +++------ .../textures/multipatchtexturebuilder.cpp | 3 +- src/common/textures/texture.cpp | 4 +- src/common/textures/textures.h | 43 ++++++++------- src/r_data/gldefs.cpp | 7 +-- src/rendering/2d/f_wipe.cpp | 2 +- src/rendering/gl/renderer/gl_renderer.cpp | 7 +-- src/rendering/gl/renderer/gl_renderstate.cpp | 11 ++-- src/rendering/gl/system/gl_framebuffer.cpp | 2 +- src/rendering/gl/textures/gl_hwtexture.cpp | 1 - .../hwrenderer/scene/hw_renderstate.h | 2 +- .../hwrenderer/textures/hw_precache.cpp | 8 +-- .../polyrenderer/backend/poly_framebuffer.cpp | 4 +- .../polyrenderer/backend/poly_hwtexture.cpp | 3 +- .../polyrenderer/backend/poly_renderstate.cpp | 2 +- src/rendering/swrenderer/r_swscene.cpp | 2 +- .../vulkan/renderer/vk_renderstate.cpp | 4 +- .../vulkan/system/vk_framebuffer.cpp | 4 +- .../vulkan/textures/vk_hwtexture.cpp | 8 +-- 21 files changed, 92 insertions(+), 104 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index f670d5af84..3fd264f768 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -415,8 +415,6 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height FImageTexture *tex = new FImageTexture(image, ""); tex->SetUseType(ETextureType::FontChar); tex->bMultiPatch = true; - tex->Width = width; - tex->Height = height; tex->_LeftOffset[0] = tex->_LeftOffset[1] = tex->_TopOffset[0] = diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 37fa8441a4..57c88099e8 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -36,21 +36,21 @@ IHardwareTexture* CreateHardwareTexture(); // //=========================================================================== -FMaterial::FMaterial(FTexture * tx, bool expanded) +FMaterial::FMaterial(FGameTexture * tx, bool expanded) { mShaderIndex = SHADER_Default; sourcetex = tx; - imgtex = tx; + imgtex = tx->GetTexture(); - if (tx->UseType == ETextureType::SWCanvas && static_cast(tx)->GetColorFormat() == 0) + if (tx->GetUseType() == ETextureType::SWCanvas && static_cast(imgtex)->GetColorFormat() == 0) { mShaderIndex = SHADER_Paletted; } else if (tx->isHardwareCanvas()) { - if (tx->shaderindex >= FIRST_USER_SHADER) + if (tx->GetShaderIndex() >= FIRST_USER_SHADER) { - mShaderIndex = tx->shaderindex; + mShaderIndex = tx->GetShaderIndex(); } // no brightmap for cameratexture } @@ -60,17 +60,17 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) { mShaderIndex = tx->isWarped(); // This picks SHADER_Warp1 or SHADER_Warp2 } - else if (tx->Normal && tx->Specular) + else if (imgtex->Normal && imgtex->Specular) { - for (auto &texture : { tx->Normal, tx->Specular }) + for (auto &texture : { imgtex->Normal, imgtex->Specular }) { mTextureLayers.Push(texture); } mShaderIndex = SHADER_Specular; } - else if (tx->Normal && tx->Metallic && tx->Roughness && tx->AmbientOcclusion) + else if (imgtex->Normal && imgtex->Metallic && imgtex->Roughness && imgtex->AmbientOcclusion) { - for (auto &texture : { tx->Normal, tx->Metallic, tx->Roughness, tx->AmbientOcclusion }) + for (auto &texture : { imgtex->Normal, imgtex->Metallic, imgtex->Roughness, imgtex->AmbientOcclusion }) { mTextureLayers.Push(texture); } @@ -78,28 +78,28 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) } // Note that these layers must present a valid texture even if not used, because empty TMUs in the shader are an undefined condition. - tx->CreateDefaultBrightmap(); - if (tx->Brightmap) + imgtex->CreateDefaultBrightmap(); + if (imgtex->Brightmap) { - mTextureLayers.Push(tx->Brightmap); + mTextureLayers.Push(imgtex->Brightmap); mLayerFlags |= TEXF_Brightmap; } else { mTextureLayers.Push(TexMan.ByIndex(1)); } - if (tx->Detailmap) + if (imgtex->Detailmap) { - mTextureLayers.Push(tx->Detailmap); + mTextureLayers.Push(imgtex->Detailmap); mLayerFlags |= TEXF_Detailmap; } else { mTextureLayers.Push(TexMan.ByIndex(1)); } - if (tx->Glowmap) + if (imgtex->Glowmap) { - mTextureLayers.Push(tx->Glowmap); + mTextureLayers.Push(imgtex->Glowmap); mLayerFlags |= TEXF_Glowmap; } else @@ -107,25 +107,25 @@ FMaterial::FMaterial(FTexture * tx, bool expanded) mTextureLayers.Push(TexMan.ByIndex(1)); } - if (tx->shaderindex >= FIRST_USER_SHADER) + if (imgtex->shaderindex >= FIRST_USER_SHADER) { - const UserShaderDesc &usershader = usershaders[tx->shaderindex - FIRST_USER_SHADER]; + const UserShaderDesc &usershader = usershaders[imgtex->shaderindex - FIRST_USER_SHADER]; if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material { - for (auto &texture : tx->CustomShaderTextures) + for (auto &texture : imgtex->CustomShaderTextures) { if (texture == nullptr) continue; mTextureLayers.Push(texture); } - mShaderIndex = tx->shaderindex; + mShaderIndex = tx->GetShaderIndex(); } } } mExpanded = expanded; mTextureLayers.ShrinkToFit(); - tx->Material[expanded] = this; - if (tx->isHardwareCanvas()) tx->bTranslucent = 0; + imgtex->Material[expanded] = this; + if (tx->isHardwareCanvas()) tx->SetTranslucent(false); } //=========================================================================== @@ -170,16 +170,17 @@ IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) // //========================================================================== -FMaterial * FMaterial::ValidateTexture(FTexture * tex, bool expand, bool create) +FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, bool expand, bool create) { - if (tex && tex->isValid()) + if (gtex && gtex->isValid()) { + auto tex = gtex->GetTexture(); if (!tex->ShouldExpandSprite()) expand = false; FMaterial *hwtex = tex->Material[expand]; if (hwtex == NULL && create) { - hwtex = new FMaterial(tex, expand); + hwtex = new FMaterial(gtex, expand); } return hwtex; } @@ -188,7 +189,7 @@ FMaterial * FMaterial::ValidateTexture(FTexture * tex, bool expand, bool create) FMaterial * FMaterial::ValidateTexture(FTextureID no, bool expand, bool translate, bool create) { - return ValidateTexture(TexMan.GetTexture(no, translate), expand, create); + return ValidateTexture(TexMan.GetGameTexture(no, translate), expand, create); } diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index e211585bab..a9d1812d37 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -8,18 +8,6 @@ struct FRemapTable; class IHardwareTexture; -enum -{ - CLAMP_NONE = 0, - CLAMP_X = 1, - CLAMP_Y = 2, - CLAMP_XY = 3, - CLAMP_XY_NOMIP = 4, - CLAMP_NOFILTER = 5, - CLAMP_CAMTEX = 6, -}; - - //=========================================================================== // // this is the material class for OpenGL. @@ -35,15 +23,15 @@ class FMaterial bool mExpanded; public: - FTexture *sourcetex; // the owning texture. - FTexture* imgtex; // the master texture for the backing image. Can be different from sourcetex and should not be in the layer array because that'd confuse the precacher. + FGameTexture *sourcetex; // the owning texture. + FTexture* imgtex; // the first layer's texture image - should be moved into the array - FMaterial(FTexture *tex, bool forceexpand); + FMaterial(FGameTexture *tex, bool forceexpand); ~FMaterial(); int GetLayerFlags() const { return mLayerFlags; } int GetShaderIndex() const { return mShaderIndex; } - FTexture* Source() const + FGameTexture* Source() const { return sourcetex; } @@ -54,7 +42,7 @@ public: } void AddTextureLayer(FTexture *tex) { - ValidateTexture(tex, false); + //ValidateTexture(tex, false); mTextureLayers.Push(tex); } bool isExpanded() const @@ -70,7 +58,7 @@ public: IHardwareTexture *GetLayer(int i, int translation, FTexture **pLayer = nullptr); - static FMaterial *ValidateTexture(FTexture * tex, bool expand, bool create = true); + static FMaterial *ValidateTexture(FGameTexture * tex, bool expand, bool create = true); static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans, bool create = true); const TArray &GetLayerArray() const { diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index b627bacacb..87b008f08d 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -140,8 +140,7 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u FImageTexture *tex = new FImageTexture(nullptr, buildinfo.Name); tex->SetUseType(usetype); tex->bMultiPatch = true; - tex->Width = buildinfo.Width; - tex->Height = buildinfo.Height; + tex->SetSize(buildinfo.Width, buildinfo.Height); tex->_LeftOffset[0] = buildinfo.LeftOffset[0]; tex->_LeftOffset[1] = buildinfo.LeftOffset[1]; tex->_TopOffset[0] = buildinfo.TopOffset[0]; diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index a1a3c7056e..4fadb318d0 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -1050,7 +1050,7 @@ void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y, bool forcewo { if (x == 1.f) { - mRenderWidth = tex->GetScaledWidth(); + mRenderWidth = tex->GetDisplayWidth(); mScale.X = (float)tex->Scale.X; mTempScale.X = 1.f; } @@ -1064,7 +1064,7 @@ void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y, bool forcewo if (y == 1.f) { - mRenderHeight = tex->GetScaledHeight(); + mRenderHeight = tex->GetDisplayHeight(); mScale.Y = (float)tex->Scale.Y; mTempScale.Y = 1.f; } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index c93207968e..d95e5ac6c4 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -245,25 +245,10 @@ struct SpritePositioningInfo class FTexture { friend class FGameTexture; // only for the porting work - friend class GLDefsParser; - friend class FMultipatchTextureBuilder; - - // The serializer also needs access to more specific info that shouldn't be accessible through the interface. - friend FSerializer &Serialize(FSerializer &arc, const char *key, FTextureID &value, FTextureID *defval); - - // For now only give access to classes which cannot be reworked yet. None of these should remain here when all is done. - friend class FWarpTexture; - friend class FMaterial; - friend class OpenGLRenderer::FGLRenderState; // For now this needs access to some fields in ApplyMaterial. This should be rerouted through the Material class - friend class VkRenderState; - friend class PolyRenderState; + friend class FTexture; friend struct FTexCoordInfo; - friend class OpenGLRenderer::FHardwareTexture; - friend class VkHardwareTexture; - friend class PolyHardwareTexture; - friend class FMultiPatchTexture; - friend class FSkyBox; - friend class FBrightmapTexture; + friend class FMultipatchTextureBuilder; + friend class FMaterial; friend class FFont; @@ -623,6 +608,18 @@ struct FTexCoordInfo void GetFromTexture(FGameTexture* tex, float x, float y, bool forceworldpanning); }; +enum +{ + CLAMP_NONE = 0, + CLAMP_X = 1, + CLAMP_Y = 2, + CLAMP_XY = 3, + CLAMP_XY_NOMIP = 4, + CLAMP_NOFILTER = 5, + CLAMP_CAMTEX = 6, +}; + + //----------------------------------------------------------------------------- // // Todo: Get rid of this @@ -685,6 +682,7 @@ public: void SetTranslucent(bool on) { wrapped.bTranslucent = on; } ETextureType GetUseType() const { return wrapped.GetUseType(); } void SetUseType(ETextureType type) { wrapped.SetUseType(type); } + int GetShaderIndex() const { return wrapped.shaderindex; } float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped.GetRotations(); } void SetRotations(int index) { wrapped.SetRotations(index); } @@ -712,6 +710,8 @@ public: if (lay.CustomShaderTextures[i]) wrapped.CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); } } + float GetGlossiness() const { return wrapped.Glossiness; } + float GetSpecularLevel() const { return wrapped.SpecularLevel; } void CopySize(FGameTexture* BaseTexture) { @@ -757,6 +757,13 @@ public: } bool GetSkyFlip() { return isSkybox() ? static_cast(&wrapped)->fliptop : false; } + int GetClampMode(int clampmode) + { + if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; + else if (isHardwareCanvas()) clampmode = CLAMP_CAMTEX; + else if ((isWarped() || wrapped.shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + return clampmode; + } }; diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index b3aa050561..d89be2019e 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -991,8 +991,9 @@ class GLDefsParser sc.MustGetString(); - FSkyBox * sb = new FSkyBox(sc.String); - sb->Name.ToUpper(); + FString s = sc.String; + s.ToUpper(); + FSkyBox * sb = new FSkyBox(s); if (sc.CheckString("fliptop")) { sb->fliptop = true; @@ -1009,7 +1010,7 @@ class GLDefsParser } if (facecount != 3 && facecount != 6) { - sc.ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->Name.GetChars()); + sc.ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->GetName().GetChars()); } sb->SetSize(); TexMan.AddTexture(sb); diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index 6fe106646d..464f93427a 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(endScreen->GetTexture(), false); + auto mat = FMaterial::ValidateTexture(reinterpret_cast(endScreen->GetTexture()), false); mat->AddTextureLayer(BurnTexture); } diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 08c7caae9d..d3b80ad34c 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -297,12 +297,13 @@ sector_t *FGLRenderer::RenderView(player_t* player) void FGLRenderer::BindToFrameBuffer(FMaterial *mat) { - auto BaseLayer = static_cast(mat->GetLayer(0, 0)); + FTexture* layer; + auto BaseLayer = static_cast(mat->GetLayer(0, 0, &layer)); if (BaseLayer == nullptr) { // must create the hardware texture first - BaseLayer->BindOrCreate(mat->sourcetex, 0, 0, 0, 0); + BaseLayer->BindOrCreate(layer, 0, 0, 0, 0); FHardwareTexture::Unbind(0); gl_RenderState.ClearLastMaterial(); } @@ -318,7 +319,7 @@ 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(tex, false); + FMaterial * gltex = FMaterial::ValidateTexture(reinterpret_cast(tex), false); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index a537d7050a..73386ee106 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -308,12 +308,11 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio } auto tex = mat->Source(); mEffectState = overrideshader >= 0 ? overrideshader : mat->GetShaderIndex(); - mShaderTimer = tex->shaderspeed; - SetSpecular(tex->Glossiness, tex->SpecularLevel); + mShaderTimer = tex->GetShaderSpeed(); + SetSpecular(tex->GetGlossiness(), tex->GetSpecularLevel()); + if (tex->isHardwareCanvas()) static_cast(tex->GetTexture())->NeedUpdate(); - if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; - if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + clampmode = tex->GetClampMode(clampmode); // avoid rebinding the same texture multiple times. if (mat == lastMaterial && lastClamp == clampmode && translation == lastTranslation) return; @@ -328,7 +327,7 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio int numLayers = mat->GetLayers(); auto base = static_cast(mat->GetLayer(0, translation)); - if (base->BindOrCreate(tex, 0, clampmode, translation, flags)) + if (base->BindOrCreate(tex->GetTexture(), 0, clampmode, translation, flags)) { for (int i = 1; iSource()->isSWCanvas()) return; + if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; int flags = mat->isExpanded() ? CTF_Expand : 0; int numLayers = mat->GetLayers(); diff --git a/src/rendering/gl/textures/gl_hwtexture.cpp b/src/rendering/gl/textures/gl_hwtexture.cpp index c849aea39c..f3743571eb 100644 --- a/src/rendering/gl/textures/gl_hwtexture.cpp +++ b/src/rendering/gl/textures/gl_hwtexture.cpp @@ -346,7 +346,6 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i return false; } } - if (tex->isHardwareCanvas()) static_cast(tex)->NeedUpdate(); GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255); return true; } diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index 44cce14dce..e0800172c7 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -572,7 +572,7 @@ public: void SetMaterial(FGameTexture* tex, bool expandmode, int clampmode, int translation, int overrideshader) { expandmode &= tex->expandSprites(); - SetMaterial(FMaterial::ValidateTexture(tex->GetTexture(), expandmode), clampmode, translation, overrideshader); + SetMaterial(FMaterial::ValidateTexture(tex, expandmode), clampmode, translation, overrideshader); } void SetClipSplit(float bottom, float top) diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 2c442e894c..7f52a53935 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -50,7 +50,7 @@ static void PrecacheTexture(FTexture *tex, int cache) { if (cache & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { - FMaterial * gltex = FMaterial::ValidateTexture(tex, false); + FMaterial * gltex = FMaterial::ValidateTexture(reinterpret_cast(tex), false); if (gltex) screen->PrecacheMaterial(gltex, 0); } } @@ -76,7 +76,7 @@ static void PrecacheList(FMaterial *gltex, SpriteHits& translations) static void PrecacheSprite(FTexture *tex, SpriteHits &hits) { - FMaterial * gltex = FMaterial::ValidateTexture(tex, true); + FMaterial * gltex = FMaterial::ValidateTexture(reinterpret_cast(tex), true); if (gltex) PrecacheList(gltex, hits); } @@ -198,7 +198,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl { if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { - FMaterial* mat = FMaterial::ValidateTexture(tex->GetTexture(), false, false); + FMaterial* mat = FMaterial::ValidateTexture(tex, false, false); if (mat != nullptr) { for (auto ftex : mat->GetLayerArray()) @@ -209,7 +209,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl } if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0) { - FMaterial *mat = FMaterial::ValidateTexture(tex->GetTexture(), true, false); + FMaterial *mat = FMaterial::ValidateTexture(tex, true, false); if (mat != nullptr) { for (auto ftex : mat->GetLayerArray()) diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 6c0e7b1fcd..827291f9c7 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -377,7 +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(tex, false); + FMaterial *mat = FMaterial::ValidateTexture(reinterpret_cast(tex), false); auto BaseLayer = static_cast(mat->GetLayer(0, 0)); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); @@ -534,7 +534,7 @@ void PolyFrameBuffer::CleanForRestart() void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { - if (mat->Source()->isSWCanvas()) return; + if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; int flags = mat->isExpanded() ? CTF_Expand : 0; FTexture* layer; diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index b5d4d3e88e..51a7886604 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -64,8 +64,7 @@ void PolyHardwareTexture::Reset() DCanvas *PolyHardwareTexture::GetImage(FTexture *baselayer, const FMaterialState &state) { - FTexture *tex = state.mMaterial->Source(); - if (tex->isHardwareCanvas()) static_cast(tex)->NeedUpdate(); + FGameTexture *tex = state.mMaterial->Source(); if (!mCanvas) { diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 5538fbf371..41e2aeb4e1 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -281,7 +281,7 @@ void PolyRenderState::Apply() } if (mMaterial.mMaterial && mMaterial.mMaterial->Source()) - mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->Source()->shaderspeed / 1000.); + mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->Source()->GetShaderSpeed() / 1000.); else mStreamData.timer = 0.0f; diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index dc7dcad8ba..81264e6f2a 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -102,7 +102,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) 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(fbtex.get(), false); + auto mat = FMaterial::ValidateTexture(reinterpret_cast(fbtex.get()), false); mat->AddTextureLayer(PaletteTexture); Canvas.reset(); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index d647594b1f..bb0270fba4 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -338,7 +338,7 @@ void VkRenderState::ApplyStreamData() mStreamData.useVertexData = passManager->GetVertexFormat(static_cast(mVertexBuffer)->VertexFormat)->UseVertexData; if (mMaterial.mMaterial && mMaterial.mMaterial->Source()) - mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->Source()->shaderspeed / 1000.); + mStreamData.timer = static_cast((double)(screen->FrameTime - firstFrame) * (double)mMaterial.mMaterial->Source()->GetShaderSpeed() / 1000.); else mStreamData.timer = 0.0f; @@ -386,7 +386,7 @@ void VkRenderState::ApplyPushConstants() if (mMaterial.mMaterial) { auto source = mMaterial.mMaterial->Source(); - mPushConstants.uSpecularMaterial = { source->Glossiness, source->SpecularLevel }; + mPushConstants.uSpecularMaterial = { source->GetGlossiness(), source->GetSpecularLevel() }; } mPushConstants.uLightIndex = mLightIndex; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 6153a574d6..24c5075eb0 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -516,7 +516,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(tex, false); + FMaterial *mat = FMaterial::ValidateTexture(reinterpret_cast(tex), false); auto BaseLayer = static_cast(mat->GetLayer(0, 0)); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); @@ -647,7 +647,7 @@ void VulkanFrameBuffer::CleanForRestart() void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { - if (mat->Source()->isSWCanvas()) return; + if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; // Textures that are already scaled in the texture lump will not get replaced by hires textures. int flags = mat->isExpanded() ? CTF_Expand : 0; diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index ccd7c804d3..1868331fa2 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -112,19 +112,15 @@ void VkHardwareTexture::ResetAllDescriptors() VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state) { FMaterial *mat = state.mMaterial; - FTexture *base = state.mMaterial->Source(); + auto base = state.mMaterial->Source(); int clampmode = state.mClampMode; int translation = state.mTranslation; - if (base->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; - if (base->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - else if ((base->isWarped() || base->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + clampmode = base->GetClampMode(clampmode); // Textures that are already scaled in the texture lump will not get replaced by hires textures. int flags = state.mMaterial->isExpanded() ? CTF_Expand : 0; - if (base->isHardwareCanvas()) static_cast(base)->NeedUpdate(); - for (auto &set : mDescriptorSets) { if (set.descriptor && set.clampmode == clampmode && set.flags == flags) return set.descriptor.get(); From c605359b0e7fe2c729a917eeacd6ac20fc3a1d71 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 19:41:15 +0200 Subject: [PATCH 024/220] - animator transitioned. --- src/common/textures/texturemanager.h | 1 + src/common/textures/textures.h | 7 ++++- src/gamedata/textures/animations.cpp | 46 ++++++++++++++-------------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 51ff8af04e..304d771c9f 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -158,6 +158,7 @@ public: } FTexture* Texture(FTextureID id) { return Textures[id.GetIndex()].Texture; } + FGameTexture* GameTexture(FTextureID id) { return reinterpret_cast(Textures[id.GetIndex()].Texture); } void SetTranslation(FTextureID fromtexnum, FTextureID totexnum); private: diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index d95e5ac6c4..17047050d6 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -668,7 +668,8 @@ public: double GetDisplayTopOffset(int adjusted = 0) /*const*/ { return wrapped.GetDisplayTopOffsetDouble(adjusted); } bool isValid() { return wrapped.isValid(); } - bool isWarped() { return wrapped.isWarped(); } + int isWarped() { return wrapped.isWarped(); } + void SetWarpStyle(int style) { wrapped.bWarped = style; } bool isMasked() { return wrapped.isMasked(); } bool isHardwareCanvas() const { return wrapped.isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isSoftwareCanvas() const { return wrapped.isCanvas(); } @@ -678,7 +679,9 @@ public: bool isFullbright() const { return wrapped.isFullbright(); } bool expandSprites() const { return wrapped.bExpandSprite; } bool useWorldPanning() const { return wrapped.UseWorldPanning(); } + void SetWorldPanning(bool on) { wrapped.SetWorldPanning(on); } bool allowNoDecals() const { return wrapped.allowNoDecals(); } + void SetNoDecals(bool on) { wrapped.bNoDecals = on; } void SetTranslucent(bool on) { wrapped.bTranslucent = on; } ETextureType GetUseType() const { return wrapped.GetUseType(); } void SetUseType(ETextureType type) { wrapped.SetUseType(type); } @@ -686,6 +689,7 @@ public: float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped.GetRotations(); } void SetRotations(int index) { wrapped.SetRotations(index); } + void SetSkyOffset(int ofs) { wrapped.SetSkyOffset(ofs); } int GetSkyOffset() const { return wrapped.GetSkyOffset(); } FTextureID GetID() const { return wrapped.GetID(); } ISoftwareTexture* GetSoftwareTexture() { return wrapped.GetSoftwareTexture(); } @@ -739,6 +743,7 @@ public: int CheckRealHeight() { return wrapped.CheckRealHeight(); } bool isSkybox() const { return wrapped.isSkybox(); } void SetSize(int x, int y) { wrapped.SetSize(x, y); } + void SetDisplaySize(float w, float h) { wrapped.SetSize((int)w, (int)h); } void SetSpriteRect() { wrapped.SetSpriteRect(); } const SpritePositioningInfo& GetSpritePositioning(int which) { /* todo: keep two sets of positioning infd*/ if (wrapped.mTrimResult == -1) wrapped.SetupSpriteData(); return wrapped.spi; } diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index e45a594e1b..ab4a5d2a8c 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -245,8 +245,8 @@ void FTextureAnimator::InitAnimated (void) // [RH] Bit 1 set means allow decals on walls with this texture bool nodecals = !(*anim_p & 2); - TexMan.Texture(pic2)->SetNoDecals(nodecals); - TexMan.Texture(pic1)->SetNoDecals(nodecals); + TexMan.GameTexture(pic2)->SetNoDecals(nodecals); + TexMan.GameTexture(pic1)->SetNoDecals(nodecals); } else { @@ -255,8 +255,8 @@ void FTextureAnimator::InitAnimated (void) continue; } - FTexture *tex1 = TexMan.Texture(pic1); - FTexture *tex2 = TexMan.Texture(pic2); + auto tex1 = TexMan.GameTexture(pic1); + auto tex2 = TexMan.GameTexture(pic2); animspeed = (anim_p[19] << 0) | (anim_p[20] << 8) | (anim_p[21] << 16) | (anim_p[22] << 24); @@ -355,7 +355,7 @@ void FTextureAnimator::InitAnimDefs () sc.MustGetNumber(); if (picnum.Exists()) { - TexMan.Texture(picnum)->SetSkyOffset(sc.Number); + TexMan.GameTexture(picnum)->SetSkyOffset(sc.Number); } } else @@ -408,7 +408,7 @@ void FTextureAnimator::ParseAnim (FScanner &sc, ETextureType usetype) // no decals on animating textures, by default if (picnum.isValid()) { - TexMan.Texture(picnum)->SetNoDecals(true); + TexMan.GameTexture(picnum)->SetNoDecals(true); } while (sc.GetString ()) @@ -417,7 +417,7 @@ void FTextureAnimator::ParseAnim (FScanner &sc, ETextureType usetype) { if (picnum.isValid()) { - TexMan.Texture(picnum)->SetNoDecals(false); + TexMan.GameTexture(picnum)->SetNoDecals(false); } continue; } @@ -439,7 +439,7 @@ void FTextureAnimator::ParseAnim (FScanner &sc, ETextureType usetype) } else if (sc.Compare ("range")) { - if (picnum.Exists() && TexMan.Texture(picnum)->GetName().IsEmpty()) + if (picnum.Exists() && TexMan.GameTexture(picnum)->GetName().IsEmpty()) { // long texture name: We cannot do ranged anims on these because they have no defined order sc.ScriptError ("You cannot use \"range\" for long texture names."); @@ -513,7 +513,7 @@ FAnimDef *FTextureAnimator::ParseRangeAnim (FScanner &sc, FTextureID picnum, ETe return NULL; // Animation is only one frame or does not exist } - if (TexMan.Texture(framenum)->GetName().IsEmpty()) + if (TexMan.GameTexture(framenum)->GetName().IsEmpty()) { // long texture name: We cannot do ranged anims on these because they have no defined order sc.ScriptError ("You cannot use \"range\" for long texture names."); @@ -522,7 +522,7 @@ FAnimDef *FTextureAnimator::ParseRangeAnim (FScanner &sc, FTextureID picnum, ETe if (framenum < picnum) { type = FAnimDef::ANIM_Backward; - TexMan.Texture(framenum)->SetNoDecals(TexMan.Texture(picnum)->allowNoDecals()); + TexMan.GameTexture(framenum)->SetNoDecals(TexMan.GameTexture(picnum)->allowNoDecals()); std::swap (framenum, picnum); } FAnimDef *ani = AddSimpleAnim (picnum, framenum - picnum + 1, min, max - min); @@ -649,7 +649,7 @@ void FTextureAnimator::ParseWarp(FScanner &sc) if (picnum.isValid()) { - FTexture *warper = TexMan.Texture(picnum); + auto warper = TexMan.GameTexture(picnum); if (warper->GetName().IsEmpty()) { @@ -666,7 +666,7 @@ void FTextureAnimator::ParseWarp(FScanner &sc) if (sc.CheckFloat()) { - warper->SetSpeed(float(sc.Float)); + warper->SetShaderSpeed(float(sc.Float)); } // No decals on warping textures, by default. @@ -699,7 +699,7 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) { const BITFIELD texflags = FTextureManager::TEXMAN_Overridable | FTextureManager::TEXMAN_TryAny | FTextureManager::TEXMAN_ShortNameOnly; int width, height; - int fitwidth, fitheight; + double fitwidth, fitheight; FString picname; sc.MustGetString (); @@ -709,14 +709,14 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) sc.MustGetNumber (); height = sc.Number; FTextureID picnum = TexMan.CheckForTexture (picname, ETextureType::Flat, texflags); - FTexture *viewer = new FCanvasTexture (picname, width, height); + FGameTexture *viewer = reinterpret_cast(new FCanvasTexture (picname, width, height)); if (picnum.Exists()) { - FTexture *oldtex = TexMan.Texture(picnum); + auto oldtex = TexMan.GameTexture(picnum); fitwidth = oldtex->GetDisplayWidth (); fitheight = oldtex->GetDisplayHeight (); viewer->SetUseType(oldtex->GetUseType()); - TexMan.ReplaceTexture (picnum, viewer, true); + TexMan.ReplaceTexture (picnum, viewer->GetTexture(), true); } else { @@ -724,7 +724,7 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) fitheight = height; // [GRB] No need for oldtex viewer->SetUseType(ETextureType::Wall); - TexMan.AddTexture (viewer); + TexMan.AddTexture (viewer->GetTexture()); } if (sc.GetString()) { @@ -751,7 +751,7 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) sc.UnGet(); } } - viewer->SetDisplaySize(fitwidth, fitheight); + viewer->SetDisplaySize((float)fitwidth, (float)fitheight); } //========================================================================== @@ -778,11 +778,11 @@ void FTextureAnimator::FixAnimations () bool noremap = false; const char *name; - name = TexMan.Texture(anim->BasePic)->GetName(); - nodecals = TexMan.Texture(anim->BasePic)->allowNoDecals(); + name = TexMan.GameTexture(anim->BasePic)->GetName(); + nodecals = TexMan.GameTexture(anim->BasePic)->allowNoDecals(); for (j = 0; j < anim->NumFrames; ++j) { - FTexture *tex = TexMan.Texture(anim->BasePic + j); + auto tex = TexMan.GameTexture(anim->BasePic + j); tex->SetNoDecals(nodecals); } } @@ -815,7 +815,7 @@ void FTextureAnimator::ParseAnimatedDoor(FScanner &sc) } else { - TexMan.Texture(anim.BaseTexture)->SetNoDecals(true); + TexMan.GameTexture(anim.BaseTexture)->SetNoDecals(true); } while (sc.GetString()) { @@ -848,7 +848,7 @@ void FTextureAnimator::ParseAnimatedDoor(FScanner &sc) } else if (sc.Compare("allowdecals")) { - if (anim.BaseTexture.Exists()) TexMan.Texture(anim.BaseTexture)->SetNoDecals(false); + if (anim.BaseTexture.Exists()) TexMan.GameTexture(anim.BaseTexture)->SetNoDecals(false); } else { From 397b1520bcc6660a6350dc9b73374ecd8367f04c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 19:49:06 +0200 Subject: [PATCH 025/220] - deal with I_SetCursor --- src/d_main.cpp | 6 +++--- src/posix/cocoa/i_video.mm | 4 ++-- src/posix/i_system.h | 4 ++-- src/posix/sdl/i_gui.cpp | 4 ++-- src/win32/i_system.cpp | 4 ++-- src/win32/i_system.h | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 90b94f7700..b6c0481494 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -235,15 +235,15 @@ CUSTOM_CVAR (String, vid_cursor, "None", CVAR_ARCHIVE | CVAR_NOINITCALL) if (!stricmp(self, "None" ) && gameinfo.CursorPic.IsNotEmpty()) { - res = I_SetCursor(TexMan.GetTextureByName(gameinfo.CursorPic)); + res = I_SetCursor(TexMan.GetGameTextureByName(gameinfo.CursorPic)); } else { - res = I_SetCursor(TexMan.GetTextureByName(self)); + res = I_SetCursor(TexMan.GetGameTextureByName(self)); } if (!res) { - I_SetCursor(TexMan.GetTextureByName("cursor")); + I_SetCursor(TexMan.GetGameTextureByName("cursor")); } } diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 704dbaf916..824b429041 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -798,7 +798,7 @@ CUSTOM_CVAR(Bool, vid_hidpi, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINI // --------------------------------------------------------------------------- -bool I_SetCursor(FTexture *cursorpic) +bool I_SetCursor(FGameTexture *cursorpic) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSCursor* cursor = nil; @@ -807,7 +807,7 @@ bool I_SetCursor(FTexture *cursorpic) { // Create bitmap image representation - auto sbuffer = cursorpic->CreateTexBuffer(0); + auto sbuffer = cursorpic->GetTexture()->CreateTexBuffer(0); const NSInteger imageWidth = sbuffer.mWidth; const NSInteger imageHeight = sbuffer.mHeight; diff --git a/src/posix/i_system.h b/src/posix/i_system.h index 61bc8356bf..09473091e2 100644 --- a/src/posix/i_system.h +++ b/src/posix/i_system.h @@ -97,8 +97,8 @@ TArray I_GetGogPaths(); // The ini could not be saved at exit bool I_WriteIniFailed (); -class FTexture; -bool I_SetCursor(FTexture *); +class FGameTexture; +bool I_SetCursor(FGameTexture *); static inline char *strlwr(char *str) diff --git a/src/posix/sdl/i_gui.cpp b/src/posix/sdl/i_gui.cpp index 8ad9c8b926..27c429f5c9 100644 --- a/src/posix/sdl/i_gui.cpp +++ b/src/posix/sdl/i_gui.cpp @@ -39,14 +39,14 @@ #include "v_palette.h" #include "textures.h" -bool I_SetCursor(FTexture *cursorpic) +bool I_SetCursor(FGameTexture *cursorpic) { static SDL_Cursor *cursor; static SDL_Surface *cursorSurface; if (cursorpic != NULL && cursorpic->isValid()) { - auto src = cursorpic->GetBgraBitmap(nullptr); + auto src = cursorpic->GetTexture()->GetBgraBitmap(nullptr); // Must be no larger than 32x32. if (src.GetWidth() > 32 || src.GetHeight() > 32) { diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 960ddbf1d4..9b8073ef3a 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -638,13 +638,13 @@ int I_PickIWad(WadStuff *wads, int numwads, bool showwin, int defaultiwad) // //========================================================================== -bool I_SetCursor(FTexture *cursorpic) +bool I_SetCursor(FGameTexture *cursorpic) { HCURSOR cursor; if (cursorpic != NULL && cursorpic->isValid()) { - auto image = cursorpic->GetBgraBitmap(nullptr); + auto image = cursorpic->GetTexture()->GetBgraBitmap(nullptr); // Must be no larger than 32x32. (is this still necessary? if (image.GetWidth() > 32 || image.GetHeight() > 32) { diff --git a/src/win32/i_system.h b/src/win32/i_system.h index fb5a490141..18cc68aac2 100644 --- a/src/win32/i_system.h +++ b/src/win32/i_system.h @@ -79,8 +79,8 @@ void I_Quit (void); // Set the mouse cursor. The texture must be 32x32. -class FTexture; -bool I_SetCursor(FTexture *cursor); +class FGameTexture; +bool I_SetCursor(FGameTexture *cursor); // Repaint the pre-game console void I_PaintConsole (void); From 437d4f8af04e2b82bf09f4479ba1e6da2cf751c6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 21:34:33 +0200 Subject: [PATCH 026/220] - changed storage in texture manager to FGameTexture. --- src/common/textures/texturemanager.cpp | 102 +++++++++++++------------ src/common/textures/texturemanager.h | 8 +- src/common/textures/textures.h | 1 + 3 files changed, 57 insertions(+), 54 deletions(-) diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 62eac65c2f..e8762431b4 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -118,9 +118,9 @@ void FTextureManager::FlushAll() { for (int j = 0; j < 2; j++) { - Textures[i].Texture->CleanHardwareTextures(true, true); - delete Textures[i].Texture->SoftwareTexture; - Textures[i].Texture->SoftwareTexture = nullptr; + Textures[i].Texture->GetTexture()->CleanHardwareTextures(true, true); + delete Textures[i].Texture->GetTexture()->SoftwareTexture; + Textures[i].Texture->GetTexture()->SoftwareTexture = nullptr; } } } @@ -151,38 +151,39 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset for(i = HashFirst[MakeKey(name) % HASH_SIZE]; i != HASH_END; i = Textures[i].HashNext) { - const FTexture *tex = Textures[i].Texture; + auto tex = Textures[i].Texture; - if (stricmp (tex->Name, name) == 0 ) + if (stricmp (tex->GetName(), name) == 0 ) { // If we look for short names, we must ignore any long name texture. - if ((flags & TEXMAN_ShortNameOnly) && tex->bFullNameTexture) + if ((flags & TEXMAN_ShortNameOnly) && tex->isFullNameTexture()) { continue; } + auto texUseType = tex->GetUseType(); // The name matches, so check the texture type if (usetype == ETextureType::Any) { // All NULL textures should actually return 0 - if (tex->UseType == ETextureType::FirstDefined && !(flags & TEXMAN_ReturnFirst)) return 0; - if (tex->UseType == ETextureType::SkinGraphic && !(flags & TEXMAN_AllowSkins)) return 0; - return FTextureID(tex->UseType==ETextureType::Null ? 0 : i); + if (texUseType == ETextureType::FirstDefined && !(flags & TEXMAN_ReturnFirst)) return 0; + if (texUseType == ETextureType::SkinGraphic && !(flags & TEXMAN_AllowSkins)) return 0; + return FTextureID(texUseType==ETextureType::Null ? 0 : i); } - else if ((flags & TEXMAN_Overridable) && tex->UseType == ETextureType::Override) + else if ((flags & TEXMAN_Overridable) && texUseType == ETextureType::Override) { return FTextureID(i); } - else if (tex->UseType == usetype) + else if (texUseType == usetype) { return FTextureID(i); } - else if (tex->UseType == ETextureType::FirstDefined && usetype == ETextureType::Wall) + else if (texUseType == ETextureType::FirstDefined && usetype == ETextureType::Wall) { if (!(flags & TEXMAN_ReturnFirst)) return FTextureID(0); else return FTextureID(i); } - else if (tex->UseType == ETextureType::Null && usetype == ETextureType::Wall) + else if (texUseType == ETextureType::Null && usetype == ETextureType::Wall) { // We found a NULL texture on a wall -> return 0 return FTextureID(0); @@ -191,12 +192,12 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset { if (firsttype == ETextureType::Null || (firsttype == ETextureType::MiscPatch && - tex->UseType != firsttype && - tex->UseType != ETextureType::Null) + texUseType != firsttype && + texUseType != ETextureType::Null) ) { firstfound = i; - firsttype = tex->UseType; + firsttype = texUseType; } } } @@ -272,12 +273,13 @@ int FTextureManager::ListTextures (const char *name, TArray &list, b while (i != HASH_END) { - const FTexture *tex = Textures[i].Texture; + auto tex = Textures[i].Texture; - if (stricmp (tex->Name, name) == 0) + if (stricmp (tex->GetName(), name) == 0) { + auto texUseType = tex->GetUseType(); // NULL textures must be ignored. - if (tex->UseType!=ETextureType::Null) + if (texUseType!=ETextureType::Null) { unsigned int j = list.Size(); if (!listall) @@ -285,7 +287,7 @@ int FTextureManager::ListTextures (const char *name, TArray &list, b for (j = 0; j < list.Size(); j++) { // Check for overriding definitions from newer WADs - if (Textures[list[j].GetIndex()].Texture->UseType == tex->UseType) break; + if (Textures[list[j].GetIndex()].Texture->GetUseType() == texUseType) break; } } if (j==list.Size()) list.Push(FTextureID(i)); @@ -361,7 +363,7 @@ bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitut if (locmode == 2) return false; // Mode 3 must also reject substitutions for non-IWAD content. - int file = fileSystem.GetFileContainer(Textures[texnum.GetIndex()].Texture->SourceLump); + int file = fileSystem.GetFileContainer(Textures[texnum.GetIndex()].Texture->GetSourceLump()); if (file > fileSystem.GetMaxIwadNum()) return true; return false; @@ -394,7 +396,7 @@ FTextureID FTextureManager::AddTexture (FTexture *texture) hash = -1; } - TextureHash hasher = { texture, hash }; + TextureHash hasher = { reinterpret_cast(texture), hash }; int trans = Textures.Push (hasher); Translation.Push (trans); if (bucket >= 0) HashFirst[bucket] = trans; @@ -439,14 +441,14 @@ void FTextureManager::ReplaceTexture (FTextureID picnum, FTexture *newtexture, b if (unsigned(index) >= Textures.Size()) return; - FTexture *oldtexture = Textures[index].Texture; + auto oldtexture = Textures[index].Texture; - newtexture->Name = oldtexture->Name; - newtexture->UseType = oldtexture->UseType; - Textures[index].Texture = newtexture; - newtexture->id = oldtexture->id; - oldtexture->Name = ""; - AddTexture(oldtexture); + newtexture->Name = oldtexture->GetName(); + newtexture->UseType = oldtexture->GetUseType(); + Textures[index].Texture = reinterpret_cast(newtexture); + newtexture->id = oldtexture->GetID(); + oldtexture->GetTexture()->Name = ""; + AddTexture(oldtexture->GetTexture()); } //========================================================================== @@ -464,11 +466,11 @@ bool FTextureManager::AreTexturesCompatible (FTextureID picnum1, FTextureID picn if (unsigned(index1) >= Textures.Size() || unsigned(index2) >= Textures.Size()) return false; - FTexture *texture1 = Textures[index1].Texture; - FTexture *texture2 = Textures[index2].Texture; + auto texture1 = Textures[index1].Texture; + auto texture2 = Textures[index2].Texture; // both textures must be the same type. - if (texture1 == NULL || texture2 == NULL || texture1->UseType != texture2->UseType) + if (texture1 == NULL || texture2 == NULL || texture1->GetUseType() != texture2->GetUseType()) return false; // both textures must be from the same file @@ -569,15 +571,15 @@ void FTextureManager::AddHiresTextures (int wadnum) FTexture * newtex = FTexture::CreateTexture ("", firsttx, ETextureType::Any); if (newtex != NULL) { - FTexture * oldtex = Textures[tlist[i].GetIndex()].Texture; + auto oldtex = Textures[tlist[i].GetIndex()].Texture; // Replace the entire texture and adjust the scaling and offset factors. newtex->bWorldPanning = true; newtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); - newtex->_LeftOffset[0] = int(oldtex->GetScaledLeftOffset(0) * newtex->Scale.X); - newtex->_LeftOffset[1] = int(oldtex->GetScaledLeftOffset(1) * newtex->Scale.X); - newtex->_TopOffset[0] = int(oldtex->GetScaledTopOffset(0) * newtex->Scale.Y); - newtex->_TopOffset[1] = int(oldtex->GetScaledTopOffset(1) * newtex->Scale.Y); + newtex->_LeftOffset[0] = int(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X); + newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); + newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); + newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); ReplaceTexture(tlist[i], newtex, true); } } @@ -654,14 +656,14 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build { for(unsigned int i = 0; i < tlist.Size(); i++) { - FTexture * oldtex = Textures[tlist[i].GetIndex()].Texture; + auto oldtex = Textures[tlist[i].GetIndex()].Texture; int sl; // only replace matching types. For sprites also replace any MiscPatches // based on the same lump. These can be created for icons. - if (oldtex->UseType == type || type == ETextureType::Any || - (mode == TEXMAN_Overridable && oldtex->UseType == ETextureType::Override) || - (type == ETextureType::Sprite && oldtex->UseType == ETextureType::MiscPatch && + if (oldtex->GetUseType() == type || type == ETextureType::Any || + (mode == TEXMAN_Overridable && oldtex->GetUseType() == ETextureType::Override) || + (type == ETextureType::Sprite && oldtex->GetUseType() == ETextureType::MiscPatch && (sl=oldtex->GetSourceLump()) >= 0 && fileSystem.GetFileNamespace(sl) == ns_sprites) ) { @@ -671,10 +673,10 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build // Replace the entire texture and adjust the scaling and offset factors. newtex->bWorldPanning = true; newtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); - newtex->_LeftOffset[0] = int(oldtex->GetScaledLeftOffset(0) * newtex->Scale.X); - newtex->_LeftOffset[1] = int(oldtex->GetScaledLeftOffset(1) * newtex->Scale.X); - newtex->_TopOffset[0] = int(oldtex->GetScaledTopOffset(0) * newtex->Scale.Y); - newtex->_TopOffset[1] = int(oldtex->GetScaledTopOffset(1) * newtex->Scale.Y); + newtex->_LeftOffset[0] = int(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X); + newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); + newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); + newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); ReplaceTexture(tlist[i], newtex, true); } } @@ -952,7 +954,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b void FTextureManager::SortTexturesByType(int start, int end) { - TArray newtextures; + TArray newtextures; // First unlink all newly added textures from the hash chain for (int i = 0; i < HASH_SIZE; i++) @@ -980,9 +982,9 @@ void FTextureManager::SortTexturesByType(int start, int end) { for(unsigned j = 0; jUseType == texturetypes[i]) + if (newtextures[j] != NULL && newtextures[j]->GetUseType() == texturetypes[i]) { - AddTexture(newtextures[j]); + AddTexture(newtextures[j]->GetTexture()); newtextures[j] = NULL; } } @@ -992,8 +994,8 @@ void FTextureManager::SortTexturesByType(int start, int end) { if (newtextures[j] != NULL) { - Printf("Texture %s has unknown type!\n", newtextures[j]->Name.GetChars()); - AddTexture(newtextures[j]); + Printf("Texture %s has unknown type!\n", newtextures[j]->GetName().GetChars()); + AddTexture(newtextures[j]->GetTexture()); } } } diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 304d771c9f..5629639906 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -29,7 +29,7 @@ private: if ((unsigned)texnum >= Textures.Size()) return nullptr; if (animate) texnum = Translation[texnum]; if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum); - return Textures[texnum].Texture; + return Textures[texnum].Texture->GetTexture(); } public: // This only gets used in UI code so we do not need PALVERS handling. @@ -157,8 +157,8 @@ public: return BuildTileData.Last(); } - FTexture* Texture(FTextureID id) { return Textures[id.GetIndex()].Texture; } - FGameTexture* GameTexture(FTextureID id) { return reinterpret_cast(Textures[id.GetIndex()].Texture); } + FTexture* Texture(FTextureID id) { return Textures[id.GetIndex()].Texture->GetTexture(); } + FGameTexture* GameTexture(FTextureID id) { return Textures[id.GetIndex()].Texture; } void SetTranslation(FTextureID fromtexnum, FTextureID totexnum); private: @@ -169,7 +169,7 @@ private: struct TextureHash { - FTexture *Texture; + FGameTexture *Texture; int HashNext; bool HasLocalization; }; diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 17047050d6..93f0bed958 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -677,6 +677,7 @@ public: bool isMultiPatch() const { return wrapped.bMultiPatch; } bool isFullbrightDisabled() const { return wrapped.isFullbrightDisabled(); } bool isFullbright() const { return wrapped.isFullbright(); } + bool isFullNameTexture() const { return wrapped.bFullNameTexture; } bool expandSprites() const { return wrapped.bExpandSprite; } bool useWorldPanning() const { return wrapped.UseWorldPanning(); } void SetWorldPanning(bool on) { wrapped.SetWorldPanning(on); } From f5d5888c22a1d7081120725304376a06380d0982 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 22:03:51 +0200 Subject: [PATCH 027/220] - thinned out the Texturemanager interface. --- src/common/textures/hw_material.cpp | 7 +++--- src/common/textures/texture.cpp | 7 +++--- src/common/textures/texturemanager.cpp | 4 ++-- src/common/textures/texturemanager.h | 31 +++++++------------------- src/r_data/gldefs.cpp | 4 ++-- 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 57c88099e8..7ab3f1321f 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -79,6 +79,7 @@ FMaterial::FMaterial(FGameTexture * tx, bool expanded) // Note that these layers must present a valid texture even if not used, because empty TMUs in the shader are an undefined condition. imgtex->CreateDefaultBrightmap(); + auto placeholder = TexMan.GameByIndex(1); if (imgtex->Brightmap) { mTextureLayers.Push(imgtex->Brightmap); @@ -86,7 +87,7 @@ FMaterial::FMaterial(FGameTexture * tx, bool expanded) } else { - mTextureLayers.Push(TexMan.ByIndex(1)); + mTextureLayers.Push(placeholder->GetTexture()); } if (imgtex->Detailmap) { @@ -95,7 +96,7 @@ FMaterial::FMaterial(FGameTexture * tx, bool expanded) } else { - mTextureLayers.Push(TexMan.ByIndex(1)); + mTextureLayers.Push(placeholder->GetTexture()); } if (imgtex->Glowmap) { @@ -104,7 +105,7 @@ FMaterial::FMaterial(FGameTexture * tx, bool expanded) } else { - mTextureLayers.Push(TexMan.ByIndex(1)); + mTextureLayers.Push(placeholder->GetTexture()); } if (imgtex->shaderindex >= FIRST_USER_SHADER) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 4fadb318d0..72b57190d5 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -119,6 +119,7 @@ FTexture::FTexture (const char *name, int lumpnum) bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bFullNameTexture(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { + tempGameTexture = reinterpret_cast(this); bBrightmapChecked = false; bGlowing = false; bAutoGlowing = false; @@ -385,11 +386,11 @@ void FTexture::AddAutoMaterials() auto lump = fileSystem.CheckNumForFullName(lookup, false, ns_global, true); if (lump != -1) { - auto bmtex = TexMan.FindTexture(fileSystem.GetFileFullName(lump), ETextureType::Any, FTextureManager::TEXMAN_TryAny); + auto bmtex = TexMan.FindGameTexture(fileSystem.GetFileFullName(lump), ETextureType::Any, FTextureManager::TEXMAN_TryAny); if (bmtex != nullptr) { - bmtex->bMasked = false; - this->*(layer.pointer) = bmtex; + bmtex->GetTexture()->bMasked = false; + this->*(layer.pointer) = bmtex->GetTexture(); } } } diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index e8762431b4..6c870006a5 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -332,10 +332,10 @@ FTextureID FTextureManager::GetTextureID (const char *name, ETextureType usetype // //========================================================================== -FTexture *FTextureManager::FindTexture(const char *texname, ETextureType usetype, BITFIELD flags) +FGameTexture *FTextureManager::FindGameTexture(const char *texname, ETextureType usetype, BITFIELD flags) { FTextureID texnum = CheckForTexture (texname, usetype, flags); - return GetTexture(texnum.GetIndex()); + return GetGameTexture(texnum.GetIndex()); } //========================================================================== diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 5629639906..71edb533d9 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -24,52 +24,37 @@ public: private: int ResolveLocalizedTexture(int texnum); - FTexture *InternalGetTexture(int texnum, bool animate, bool localize) + FGameTexture *InternalGetTexture(int texnum, bool animate, bool localize) { if ((unsigned)texnum >= Textures.Size()) return nullptr; if (animate) texnum = Translation[texnum]; if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum); - return Textures[texnum].Texture->GetTexture(); + return Textures[texnum].Texture; } public: // This only gets used in UI code so we do not need PALVERS handling. - FTexture *GetTextureByName(const char *name, bool animate = false) - { - FTextureID texnum = GetTextureID (name, ETextureType::MiscPatch); - return InternalGetTexture(texnum.GetIndex(), animate, true); - } - FGameTexture* GetGameTextureByName(const char *name, bool animate = false) { - return reinterpret_cast(GetTextureByName(name, animate)); + FTextureID texnum = GetTextureID(name, ETextureType::MiscPatch); + return InternalGetTexture(texnum.GetIndex(), animate, true); } FTexture *GetTexture(FTextureID texnum, bool animate = false) { - return InternalGetTexture(texnum.GetIndex(), animate, true); + return InternalGetTexture(texnum.GetIndex(), animate, true)->GetTexture(); } FGameTexture* GetGameTexture(FTextureID texnum, bool animate = false) { - return reinterpret_cast(GetTexture(texnum, animate)); + return InternalGetTexture(texnum.GetIndex(), animate, true); } - FTexture *ByIndex(int i, bool animate = false) + FGameTexture* GameByIndex(int i, bool animate = false) { return InternalGetTexture(i, animate, true); } - FGameTexture* GameByIndex(int i, bool animate = false) - { - return reinterpret_cast(ByIndex(i, animate)); - } - - FTexture *FindTexture(const char *texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny); - - FGameTexture* FindGameTexture(const char* texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny) - { - return reinterpret_cast(FindTexture(texname, usetype, flags)); - } + FGameTexture* FindGameTexture(const char* texname, ETextureType usetype = ETextureType::MiscPatch, BITFIELD flags = TEXMAN_TryAny); bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum); diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index d89be2019e..d8e04dcd83 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -90,13 +90,13 @@ static void ParseVavoomSkybox() maplump = fileSystem.CheckNumForFullName(sc.String, true); - FTexture *tex = TexMan.FindTexture(sc.String, ETextureType::Wall, FTextureManager::TEXMAN_TryAny); + auto tex = TexMan.FindGameTexture(sc.String, ETextureType::Wall, FTextureManager::TEXMAN_TryAny); if (tex == NULL) { sc.ScriptMessage("Texture '%s' not found in Vavoom skybox '%s'\n", sc.String, sb->GetName().GetChars()); error = true; } - sb->faces[facecount] = tex; + sb->faces[facecount] = tex->GetTexture(); sc.MustGetStringName("}"); } facecount++; From 7bdef7fe9a9ce315056916a0a40902c58c3f08e8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 15 Apr 2020 23:36:43 +0200 Subject: [PATCH 028/220] - cleaned the texture manager's method interface from FTexture references. --- src/common/fonts/font.cpp | 48 +++++----- src/common/fonts/hexfont.cpp | 8 +- src/common/fonts/singlelumpfont.cpp | 22 ++--- src/common/fonts/singlepicfont.cpp | 6 +- src/common/fonts/specialfont.cpp | 28 +++--- src/common/fonts/v_font.cpp | 10 +- src/common/fonts/v_font.h | 4 +- .../textures/formats/multipatchtexture.h | 2 + .../textures/multipatchtexturebuilder.cpp | 14 +-- src/common/textures/skyboxtexture.cpp | 6 +- src/common/textures/texture.cpp | 45 ++++----- src/common/textures/texturemanager.cpp | 94 +++++++++---------- src/common/textures/texturemanager.h | 16 ++-- src/common/textures/textures.h | 20 ++-- src/gamedata/textures/animations.cpp | 6 +- src/gamedata/textures/buildloader.cpp | 5 +- src/r_data/gldefs.cpp | 8 +- src/r_data/models/models_voxel.cpp | 2 +- src/r_data/r_canvastexture.cpp | 6 +- src/rendering/swrenderer/r_swscene.cpp | 7 +- 20 files changed, 179 insertions(+), 178 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 3fd264f768..a1135f89a8 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -327,25 +327,25 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla } auto orig = pic->GetTexture(); - auto tex = new FImageTexture(orig->GetImage(), ""); + auto tex = MakeGameTexture(new FImageTexture(orig->GetImage(), "")); // todo - can reuse orig directly later. tex->SetUseType(ETextureType::FontChar); - tex->CopySize(orig); - TexMan.AddTexture(tex); + tex->CopySize(pic); + TexMan.AddGameTexture(tex); Chars[i].OriginalPic = tex; if (!noTranslate) { - Chars[i].TranslatedPic = new FImageTexture(new FFontChar1(orig->GetImage()), ""); - Chars[i].TranslatedPic->CopySize(orig); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(orig->GetImage()), "")); + Chars[i].TranslatedPic->CopySize(pic); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); - TexMan.AddTexture(Chars[i].TranslatedPic); + TexMan.AddGameTexture(Chars[i].TranslatedPic); } else { Chars[i].TranslatedPic = tex; } - Chars[i].XMove = Chars[i].TranslatedPic->GetDisplayWidth(); + Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth(); } else { @@ -397,7 +397,7 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height auto lump = TexMan.CheckForTexture(entry.name, ETextureType::MiscPatch); if (lump.isValid()) { - auto tex = TexMan.GetTexture(lump); + auto tex = TexMan.GetGameTexture(lump); int numtex_x = tex->GetTexelWidth() / width; int numtex_y = tex->GetTexelHeight() / height; int maxinsheet = int(position) + numtex_x * numtex_y - 1; @@ -410,7 +410,7 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height { part[0].OriginX = -width * x; part[0].OriginY = -height * y; - part[0].Image = tex->GetImage(); + part[0].Image = tex->GetTexture()->GetImage(); FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false); FImageTexture *tex = new FImageTexture(image, ""); tex->SetUseType(ETextureType::FontChar); @@ -425,7 +425,7 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height tex->bWorldPanning = true; tex->bNoDecals = false; tex->SourceLump = -1; // We do not really care. - TexMan.AddTexture(tex); + TexMan.AddGameTexture(MakeGameTexture(tex)); charMap.Insert(int(position) + x + y * numtex_x, reinterpret_cast(tex)); } } @@ -455,14 +455,14 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height auto b = pic->Get8BitPixels(false); - Chars[i].OriginalPic = new FImageTexture(pic->GetImage(), ""); + Chars[i].OriginalPic = MakeGameTexture(new FImageTexture(pic->GetImage(), "")); Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); - Chars[i].OriginalPic->CopySize(pic); - Chars[i].TranslatedPic = new FImageTexture(new FFontChar1(pic->GetImage()), ""); - Chars[i].TranslatedPic->CopySize(pic); + Chars[i].OriginalPic->CopySize(*lump); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage()), "")); + Chars[i].TranslatedPic->CopySize(*lump); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); - TexMan.AddTexture(Chars[i].OriginalPic); - TexMan.AddTexture(Chars[i].TranslatedPic); + TexMan.AddGameTexture(Chars[i].OriginalPic); + TexMan.AddGameTexture(Chars[i].TranslatedPic); } Chars[i].XMove = width; } @@ -612,7 +612,7 @@ void FFont::RecordAllTextureColors(uint32_t *usedcolors) { if (Chars[i].TranslatedPic) { - FFontChar1 *pic = static_cast(Chars[i].TranslatedPic->GetImage()); + FFontChar1 *pic = static_cast(Chars[i].TranslatedPic->GetTexture()->GetImage()); if (pic) { // The remap must be temporarily reset here because this can be called on an initialized font. @@ -999,13 +999,13 @@ FGameTexture *FFont::GetChar (int code, int translation, int *const width, bool if (redirected) *redirected = redirect; if (redirect) { - assert(Chars[code].OriginalPic->UseType == ETextureType::FontChar); - return reinterpret_cast(Chars[code].OriginalPic); + assert(Chars[code].OriginalPic->GetUseType() == ETextureType::FontChar); + return Chars[code].OriginalPic; } } if (redirected) *redirected = false; - assert(Chars[code].TranslatedPic->UseType == ETextureType::FontChar); - return reinterpret_cast(Chars[code].TranslatedPic); + assert(Chars[code].TranslatedPic->GetUseType() == ETextureType::FontChar); + return Chars[code].TranslatedPic; } //========================================================================== @@ -1193,7 +1193,7 @@ void FFont::LoadTranslations() { if (Chars[i].TranslatedPic) { - FFontChar1 *pic = static_cast(Chars[i].TranslatedPic->GetImage()); + FFontChar1 *pic = static_cast(Chars[i].TranslatedPic->GetTexture()->GetImage()); if (pic) { pic->SetSourceRemap(nullptr); // Force the FFontChar1 to return the same pixels as the base texture @@ -1207,7 +1207,7 @@ void FFont::LoadTranslations() for (unsigned int i = 0; i < count; i++) { if(Chars[i].TranslatedPic) - static_cast(Chars[i].TranslatedPic->GetImage())->SetSourceRemap(PatchRemap); + static_cast(Chars[i].TranslatedPic->GetTexture()->GetImage())->SetSourceRemap(PatchRemap); } BuildTranslations (Luminosity.Data(), identity, &TranslationParms[TranslationType][0], ActiveColors, nullptr); @@ -1283,7 +1283,7 @@ void FFont::FixXMoves() } if (Chars[i].OriginalPic) { - int ofs = Chars[i].OriginalPic->GetDisplayTopOffset(); + int ofs = (int)Chars[i].OriginalPic->GetDisplayTopOffset(); if (ofs > Displacement) Displacement = ofs; } } diff --git a/src/common/fonts/hexfont.cpp b/src/common/fonts/hexfont.cpp index 1b3bca2e41..b1ac21e8a6 100644 --- a/src/common/fonts/hexfont.cpp +++ b/src/common/fonts/hexfont.cpp @@ -289,10 +289,10 @@ public: { auto offset = hexdata.glyphmap[i]; int size = hexdata.glyphdata[offset] / 16; - Chars[i - FirstChar].TranslatedPic = new FImageTexture(new FHexFontChar (&hexdata.glyphdata[offset+1], size, size * 9, 16)); + Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar (&hexdata.glyphdata[offset+1], size, size * 9, 16))); Chars[i - FirstChar].TranslatedPic->SetUseType(ETextureType::FontChar); Chars[i - FirstChar].XMove = size * spacing; - TexMan.AddTexture(Chars[i - FirstChar].TranslatedPic); + TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); } else Chars[i - FirstChar].XMove = spacing; @@ -362,10 +362,10 @@ public: { auto offset = hexdata.glyphmap[i]; int size = hexdata.glyphdata[offset] / 16; - Chars[i - FirstChar].TranslatedPic = new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)); + Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18))); Chars[i - FirstChar].TranslatedPic->SetUseType(ETextureType::FontChar); Chars[i - FirstChar].XMove = size * spacing; - TexMan.AddTexture(Chars[i - FirstChar].TranslatedPic); + TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); } else Chars[i - FirstChar].XMove = spacing; diff --git a/src/common/fonts/singlelumpfont.cpp b/src/common/fonts/singlelumpfont.cpp index 4b4fc3d9ab..3d71f6fb78 100644 --- a/src/common/fonts/singlelumpfont.cpp +++ b/src/common/fonts/singlelumpfont.cpp @@ -167,10 +167,10 @@ FSingleLumpFont::FSingleLumpFont (const char *name, int lump) : FFont(lump) void FSingleLumpFont::CreateFontFromPic (FTextureID picnum) { - FTexture *pic = TexMan.GetTexture(picnum); + auto pic = TexMan.GetGameTexture(picnum); - FontHeight = pic->GetDisplayHeight (); - SpaceWidth = pic->GetDisplayWidth (); + FontHeight = (int)pic->GetDisplayHeight (); + SpaceWidth = (int)pic->GetDisplayWidth (); GlobalKerning = 0; FirstChar = LastChar = 'A'; @@ -222,7 +222,7 @@ void FSingleLumpFont::LoadTranslations() for(unsigned int i = 0;i < count;++i) { if(Chars[i].TranslatedPic) - static_cast(Chars[i].TranslatedPic->GetImage())->SetSourceRemap(PatchRemap); + static_cast(Chars[i].TranslatedPic->GetTexture()->GetImage())->SetSourceRemap(PatchRemap); } BuildTranslations (luminosity, useidentity ? identity : nullptr, ranges, ActiveColors, usepalette ? local_palette : nullptr); @@ -353,9 +353,9 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data) } else { - Chars[i].TranslatedPic = new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight))); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); - TexMan.AddTexture(Chars[i].TranslatedPic); + TexMan.AddGameTexture(Chars[i].TranslatedPic); do { int8_t code = *data_p++; @@ -483,15 +483,15 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data) { // Empty character: skip it. continue; } - auto tex = new FImageTexture(new FFontChar2(lump, int(chardata + chari + 6 - data), + auto tex = MakeGameTexture(new FImageTexture(new FFontChar2(lump, int(chardata + chari + 6 - data), chardata[chari+1], // width chardata[chari+2], // height -(int8_t)chardata[chari+3], // x offset -(int8_t)chardata[chari+4] // y offset - )); + ))); tex->SetUseType(ETextureType::FontChar); Chars[chardata[chari] - FirstChar].TranslatedPic = tex; - TexMan.AddTexture(tex); + TexMan.AddGameTexture(tex); } // If the font did not define a space character, determine a suitable space width now. @@ -556,10 +556,10 @@ void FSingleLumpFont::CheckFON1Chars (double *luminosity) if(!Chars[i].TranslatedPic) { - Chars[i].TranslatedPic = new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight)); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight))); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); Chars[i].XMove = SpaceWidth; - TexMan.AddTexture(Chars[i].TranslatedPic); + TexMan.AddGameTexture(Chars[i].TranslatedPic); } // Advance to next char's data and count the used colors. diff --git a/src/common/fonts/singlepicfont.cpp b/src/common/fonts/singlepicfont.cpp index f54c3117ee..46a723bd1a 100644 --- a/src/common/fonts/singlepicfont.cpp +++ b/src/common/fonts/singlepicfont.cpp @@ -72,11 +72,11 @@ FSinglePicFont::FSinglePicFont(const char *picname) : I_FatalError ("%s is not a font or texture", picname); } - FTexture *pic = TexMan.GetTexture(picnum); + auto pic = TexMan.GetGameTexture(picnum); FontName = picname; - FontHeight = pic->GetDisplayHeight(); - SpaceWidth = pic->GetDisplayWidth(); + FontHeight = (int)pic->GetDisplayHeight(); + SpaceWidth = (int)pic->GetDisplayWidth(); GlobalKerning = 0; FirstChar = LastChar = 'A'; ActiveColors = 0; diff --git a/src/common/fonts/specialfont.cpp b/src/common/fonts/specialfont.cpp index 519ccf8dda..f7389f8345 100644 --- a/src/common/fonts/specialfont.cpp +++ b/src/common/fonts/specialfont.cpp @@ -45,7 +45,7 @@ class FSpecialFont : public FFont { public: - FSpecialFont (const char *name, int first, int count, FTexture **lumplist, const bool *notranslate, int lump, bool donttranslate); + FSpecialFont (const char *name, int first, int count, FGameTexture **lumplist, const bool *notranslate, int lump, bool donttranslate); void LoadTranslations(); @@ -60,13 +60,13 @@ protected: // //========================================================================== -FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **lumplist, const bool *notranslate, int lump, bool donttranslate) +FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture **lumplist, const bool *notranslate, int lump, bool donttranslate) : FFont(lump) { int i; - TArray charlumps(count, true); + TArray charlumps(count, true); int maxyoffs; - FTexture *pic; + FGameTexture *pic; memcpy(this->notranslate, notranslate, 256*sizeof(bool)); @@ -87,8 +87,8 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l pic = charlumps[i] = lumplist[i]; if (pic != nullptr) { - int height = pic->GetDisplayHeight(); - int yoffs = pic->GetDisplayTopOffset(); + int height = (int)pic->GetDisplayHeight(); + int yoffs = (int)pic->GetDisplayTopOffset(); if (yoffs > maxyoffs) { @@ -104,20 +104,20 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l if (charlumps[i] != nullptr) { auto pic = charlumps[i]; - Chars[i].OriginalPic = new FImageTexture(pic->GetImage(), ""); + Chars[i].OriginalPic = MakeGameTexture(new FImageTexture(pic->GetTexture()->GetImage(), "")); Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); Chars[i].OriginalPic->CopySize(pic); - TexMan.AddTexture(Chars[i].OriginalPic); + TexMan.AddGameTexture(Chars[i].OriginalPic); if (!noTranslate) { - Chars[i].TranslatedPic = new FImageTexture(new FFontChar1 (charlumps[i]->GetImage()), ""); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1 (charlumps[i]->GetTexture()->GetImage()), "")); Chars[i].TranslatedPic->CopySize(charlumps[i]); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); - TexMan.AddTexture(Chars[i].TranslatedPic); + TexMan.AddGameTexture(Chars[i].TranslatedPic); } else Chars[i].TranslatedPic = Chars[i].OriginalPic; - Chars[i].XMove = Chars[i].TranslatedPic->GetDisplayWidth(); + Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth(); } else { @@ -167,7 +167,7 @@ void FSpecialFont::LoadTranslations() { if (Chars[i].TranslatedPic) { - FFontChar1 *pic = static_cast(Chars[i].TranslatedPic->GetImage()); + FFontChar1 *pic = static_cast(Chars[i].TranslatedPic->GetTexture()->GetImage()); if (pic) { pic->SetSourceRemap(nullptr); // Force the FFontChar1 to return the same pixels as the base texture @@ -197,7 +197,7 @@ void FSpecialFont::LoadTranslations() for (i = 0; i < count; i++) { if(Chars[i].TranslatedPic) - static_cast(Chars[i].TranslatedPic->GetImage())->SetSourceRemap(PatchRemap); + static_cast(Chars[i].TranslatedPic->GetTexture()->GetImage())->SetSourceRemap(PatchRemap); } BuildTranslations(Luminosity.Data(), identity, &TranslationParms[0][0], TotalColors, nullptr, [=](FRemapTable* remap) @@ -217,7 +217,7 @@ void FSpecialFont::LoadTranslations() ActiveColors = TotalColors; } -FFont *CreateSpecialFont (const char *name, int first, int count, FTexture **lumplist, const bool *notranslate, int lump, bool donttranslate) +FFont *CreateSpecialFont (const char *name, int first, int count, FGameTexture **lumplist, const bool *notranslate, int lump, bool donttranslate) { return new FSpecialFont(name, first, count, lumplist, notranslate, lump, donttranslate); } diff --git a/src/common/fonts/v_font.cpp b/src/common/fonts/v_font.cpp index 8fe004f7f1..4057bc8788 100644 --- a/src/common/fonts/v_font.cpp +++ b/src/common/fonts/v_font.cpp @@ -144,7 +144,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname) FTextureID picnum = TexMan.CheckForTexture (name, ETextureType::Any); if (picnum.isValid()) { - FTexture *tex = TexMan.GetTexture(picnum); + auto tex = TexMan.GetGameTexture(picnum); if (tex && tex->GetSourceLump() >= folderfile) { FFont *CreateSinglePicFont(const char *name); @@ -170,7 +170,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname) void V_InitCustomFonts() { FScanner sc; - FTexture *lumplist[256]; + FGameTexture *lumplist[256]; bool notranslate[256]; bool donttranslate; FString namebuffer, templatebuf; @@ -266,12 +266,12 @@ void V_InitCustomFonts() else { if (format == 1) goto wrong; - FTexture **p = &lumplist[*(unsigned char*)sc.String]; + FGameTexture **p = &lumplist[*(unsigned char*)sc.String]; sc.MustGetString(); FTextureID texid = TexMan.CheckForTexture(sc.String, ETextureType::MiscPatch); if (texid.Exists()) { - *p = TexMan.GetTexture(texid); + *p = TexMan.GetGameTexture(texid); } else if (fileSystem.GetFileContainer(sc.LumpNum) >= fileSystem.GetIwadNum()) { @@ -307,7 +307,7 @@ void V_InitCustomFonts() } if (count > 0) { - FFont *CreateSpecialFont (const char *name, int first, int count, FTexture **lumplist, const bool *notranslate, int lump, bool donttranslate); + FFont *CreateSpecialFont (const char *name, int first, int count, FGameTexture **lumplist, const bool *notranslate, int lump, bool donttranslate); FFont *fnt = CreateSpecialFont (namebuffer, first, count, &lumplist[first], notranslate, llump, donttranslate); fnt->SetCursor(cursor); fnt->SetKerning(kerning); diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index ab20edf766..536b07ba3a 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -162,8 +162,8 @@ protected: bool forceremap = false; struct CharData { - FTexture *TranslatedPic = nullptr; // Texture for use with font translations. - FTexture *OriginalPic = nullptr; // Texture for use with CR_UNTRANSLATED or font colorization. + FGameTexture *TranslatedPic = nullptr; // Texture for use with font translations. + FGameTexture *OriginalPic = nullptr; // Texture for use with CR_UNTRANSLATED or font colorization. int XMove = INT_MIN; }; TArray Chars; diff --git a/src/common/textures/formats/multipatchtexture.h b/src/common/textures/formats/multipatchtexture.h index 3b8c6db752..5c15e8aa06 100644 --- a/src/common/textures/formats/multipatchtexture.h +++ b/src/common/textures/formats/multipatchtexture.h @@ -38,9 +38,11 @@ struct TexPart class FMultiPatchTexture : public FImageSource { friend class FTexture; + friend class FGameTexture; public: FMultiPatchTexture(int w, int h, const TArray &parts, bool complex, bool textual); bool SupportRemap0() override; + int GetNumParts() const { return NumParts; } protected: int NumParts; diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 87b008f08d..dcaefcec2a 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -152,7 +152,7 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u tex->bNoDecals = buildinfo.bNoDecals; tex->SourceLump = buildinfo.DefinitionLump; buildinfo.tex = tex; - TexMan.AddTexture(tex); + TexMan.AddGameTexture(MakeGameTexture(tex)); } //========================================================================== @@ -808,18 +808,18 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) } else { - FTexture *tex = TexMan.GetTexture(texno); + FGameTexture *tex = TexMan.GetGameTexture(texno); if (tex != nullptr && tex->isValid()) { //We cannot set the image source yet. First all textures need to be resolved. - buildinfo.Inits[i].Texture = tex; - buildinfo.tex->bComplex |= tex->bComplex; - buildinfo.bComplex |= tex->bComplex; + buildinfo.Inits[i].Texture = tex->GetTexture(); + buildinfo.tex->bComplex |= tex->GetTexture()->bComplex; // this one's NOT a material property! It must remain on the texture image. + buildinfo.bComplex |= tex->GetTexture()->bComplex; if (buildinfo.Inits[i].UseOffsets) { - buildinfo.Parts[i].OriginX -= tex->GetLeftOffset(0); - buildinfo.Parts[i].OriginY -= tex->GetTopOffset(0); + buildinfo.Parts[i].OriginX -= tex->GetTexelLeftOffset(0); + buildinfo.Parts[i].OriginY -= tex->GetTexelTopOffset(0); } } else diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index 64eb11e6fd..48520cafde 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -40,7 +40,7 @@ FSkyBox::FSkyBox(const char *name) FTextureID texid = TexMan.CheckForTexture(name, ETextureType::Wall); if (texid.isValid()) { - previous = TexMan.GetTexture(texid); + previous = TexMan.GetGameTexture(texid); } else previous = nullptr; faces[0]=faces[1]=faces[2]=faces[3]=faces[4]=faces[5] = nullptr; @@ -58,9 +58,9 @@ FSkyBox::FSkyBox(const char *name) void FSkyBox::SetSize() { if (!previous && faces[0]) previous = faces[0]; - if (previous && previous->GetImage()) + if (previous && previous->GetTexture()->GetImage()) { - SetImage(previous->GetImage()); + SetImage(previous->GetTexture()->GetImage()); SetFromImage(); } } diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 72b57190d5..0636822d21 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -119,7 +119,6 @@ FTexture::FTexture (const char *name, int lumpnum) bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bFullNameTexture(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { - tempGameTexture = reinterpret_cast(this); bBrightmapChecked = false; bGlowing = false; bAutoGlowing = false; @@ -188,14 +187,16 @@ FBitmap FTexture::GetBgraBitmap(const PalEntry *remap, int *ptrans) // //========================================================================== -FTexture *FTexture::GetRawTexture() +FGameTexture *FGameTexture::GetRawTexture() { - if (OffsetLess) return OffsetLess; + auto tex = GetTexture(); + if (tex->OffsetLess) return tex->OffsetLess; // Reject anything that cannot have been a single-patch multipatch texture in vanilla. - auto image = static_cast(GetImage()); - if (bMultiPatch != 1 || UseType != ETextureType::Wall || Scale.X != 1 || Scale.Y != 1 || bWorldPanning || image == nullptr || image->NumParts != 1 || _TopOffset[0] == 0) + auto image = static_cast(tex->GetImage()); + if (tex->bMultiPatch != 1 || GetUseType() != ETextureType::Wall || tex->Scale.X != 1 || tex->Scale.Y != 1 || + useWorldPanning() || image == nullptr || image->GetNumParts() != 1 || tex->_TopOffset[0] == 0) { - OffsetLess = this; + tex->OffsetLess = this; return this; } // Set up a new texture that directly references the underlying patch. @@ -203,16 +204,17 @@ FTexture *FTexture::GetRawTexture() FImageSource *source = image->Parts[0].Image; // Size must match for this to work as intended - if (source->GetWidth() != Width || source->GetHeight() != Height) + if (source->GetWidth() != GetTexelWidth() || source->GetHeight() != GetTexelHeight()) { - OffsetLess = this; + tex->OffsetLess = this; return this; } - OffsetLess = new FImageTexture(source, ""); - TexMan.AddTexture(OffsetLess); - return OffsetLess; + tex->OffsetLess = MakeGameTexture(new FImageTexture(source, "")); + // todo: This must also copy all layers from the base texture. + TexMan.AddGameTexture(tex->OffsetLess); + return tex->OffsetLess; } //========================================================================== @@ -221,22 +223,23 @@ FTexture *FTexture::GetRawTexture() // //========================================================================== -FTexture* FTexture::GetFrontSkyLayer() +FGameTexture* FGameTexture::GetFrontSkyLayer() { - if (FrontSkyLayer) return FrontSkyLayer; + auto tex = GetTexture(); + if (tex->FrontSkyLayer) return tex->FrontSkyLayer; // Reject anything that cannot have been a front layer for the sky in Hexen. - auto image = GetImage(); - if (image == nullptr || !image->SupportRemap0() || UseType != ETextureType::Wall || Scale.X != 1 || Scale.Y != 1 || bWorldPanning || _TopOffset[0] != 0 || + auto image = tex->GetImage(); + if (image == nullptr || !image->SupportRemap0() || GetUseType() != ETextureType::Wall || tex->Scale.X != 1 || tex->Scale.Y != 1 || useWorldPanning() || tex->_TopOffset[0] != 0 || image->GetWidth() != GetTexelWidth() || image->GetHeight() != GetTexelHeight()) { - FrontSkyLayer = this; + tex->FrontSkyLayer = this; return this; } - FrontSkyLayer = new FImageTexture(image, ""); - TexMan.AddTexture(FrontSkyLayer); - FrontSkyLayer->bNoRemap0 = true; - return FrontSkyLayer; + tex->FrontSkyLayer = MakeGameTexture(new FImageTexture(image, "")); + TexMan.AddGameTexture(tex->FrontSkyLayer); + tex->FrontSkyLayer->GetTexture()->bNoRemap0 = true; + return tex->FrontSkyLayer; } @@ -424,7 +427,7 @@ void FTexture::CreateDefaultBrightmap() DPrintf(DMSG_NOTIFY, "brightmap created for texture '%s'\n", Name.GetChars()); Brightmap = CreateBrightmapTexture(static_cast(this)->GetImage()); bBrightmapChecked = true; - TexMan.AddTexture(Brightmap); + TexMan.AddGameTexture(MakeGameTexture(Brightmap)); return; } } diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 6c870006a5..f35a8af2b6 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -229,12 +229,12 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset if (tex == NO_TEXTURE) return FTextureID(-1); if (tex != NULL) return tex->GetID(); if (flags & TEXMAN_DontCreate) return FTextureID(-1); // we only want to check, there's no need to create a texture if we don't have one yet. - tex = reinterpret_cast(FTexture::CreateTexture("", lump, ETextureType::Override)); + tex = MakeGameTexture(FTexture::CreateTexture("", lump, ETextureType::Override)); if (tex != NULL) { tex->AddAutoMaterials(); fileSystem.SetLinkedTexture(lump, tex); - return AddTexture(tex->GetTexture()); + return AddGameTexture(tex); } else { @@ -375,7 +375,7 @@ bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitut // //========================================================================== -FTextureID FTextureManager::AddTexture (FTexture *texture) +FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) { int bucket; int hash; @@ -385,9 +385,9 @@ FTextureID FTextureManager::AddTexture (FTexture *texture) // Later textures take precedence over earlier ones // Textures without name can't be looked for - if (texture->Name[0] != '\0') + if (texture->GetName().IsNotEmpty()) { - bucket = int(MakeKey (texture->Name) % HASH_SIZE); + bucket = int(MakeKey (texture->GetName()) % HASH_SIZE); hash = HashFirst[bucket]; } else @@ -400,7 +400,7 @@ FTextureID FTextureManager::AddTexture (FTexture *texture) int trans = Textures.Push (hasher); Translation.Push (trans); if (bucket >= 0) HashFirst[bucket] = trans; - return (texture->id = FTextureID(trans)); + return (texture->GetTexture()->id = FTextureID(trans)); } //========================================================================== @@ -417,9 +417,9 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype) { FString str; fileSystem.GetFileShortName(str, lumpnum); - FTexture *out = FTexture::CreateTexture(str, lumpnum, usetype); + auto out = MakeGameTexture(FTexture::CreateTexture(str, lumpnum, usetype)); - if (out != NULL) return AddTexture (out); + if (out != NULL) return AddGameTexture (out); else { Printf (TEXTCOLOR_ORANGE "Invalid data encountered for texture %s\n", fileSystem.GetFileFullPath(lumpnum).GetChars()); @@ -435,7 +435,7 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype) // //========================================================================== -void FTextureManager::ReplaceTexture (FTextureID picnum, FTexture *newtexture, bool free) +void FTextureManager::ReplaceTexture (FTextureID picnum, FGameTexture *newtexture, bool free) { int index = picnum.GetIndex(); if (unsigned(index) >= Textures.Size()) @@ -443,12 +443,12 @@ void FTextureManager::ReplaceTexture (FTextureID picnum, FTexture *newtexture, b auto oldtexture = Textures[index].Texture; - newtexture->Name = oldtexture->GetName(); - newtexture->UseType = oldtexture->GetUseType(); + newtexture->GetTexture()->Name = oldtexture->GetName(); + newtexture->SetUseType(oldtexture->GetUseType()); Textures[index].Texture = reinterpret_cast(newtexture); - newtexture->id = oldtexture->GetID(); + newtexture->GetTexture()->id = oldtexture->GetID(); oldtexture->GetTexture()->Name = ""; - AddTexture(oldtexture->GetTexture()); + AddGameTexture(oldtexture); } //========================================================================== @@ -557,11 +557,11 @@ void FTextureManager::AddHiresTextures (int wadnum) if (amount == 0) { // A texture with this name does not yet exist - FTexture * newtex = FTexture::CreateTexture (Name, firsttx, ETextureType::Any); + auto newtex = MakeGameTexture(FTexture::CreateTexture (Name, firsttx, ETextureType::Any)); if (newtex != NULL) { - newtex->UseType=ETextureType::Override; - AddTexture(newtex); + newtex->SetUseType(ETextureType::Override); + AddGameTexture(newtex); } } else @@ -575,12 +575,12 @@ void FTextureManager::AddHiresTextures (int wadnum) // Replace the entire texture and adjust the scaling and offset factors. newtex->bWorldPanning = true; - newtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); + newtex->SetDisplaySize((int)oldtex->GetDisplayWidth(), (int)oldtex->GetDisplayHeight()); newtex->_LeftOffset[0] = int(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X); newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); - ReplaceTexture(tlist[i], newtex, true); + ReplaceTexture(tlist[i], MakeGameTexture(newtex), true); } } } @@ -672,12 +672,12 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build { // Replace the entire texture and adjust the scaling and offset factors. newtex->bWorldPanning = true; - newtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); + newtex->SetDisplaySize((int)oldtex->GetDisplayWidth(), (int)oldtex->GetDisplayHeight()); newtex->_LeftOffset[0] = int(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X); newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); - ReplaceTexture(tlist[i], newtex, true); + ReplaceTexture(tlist[i], MakeGameTexture(newtex), true); } } } @@ -706,21 +706,21 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build if (lumpnum>=0) { - FTexture *newtex = FTexture::CreateTexture(src, lumpnum, ETextureType::Override); + auto newtex = MakeGameTexture(FTexture::CreateTexture(src, lumpnum, ETextureType::Override)); if (newtex != NULL) { // Replace the entire texture and adjust the scaling and offset factors. - newtex->bWorldPanning = true; - newtex->SetDisplaySize(width, height); + newtex->SetWorldPanning(true); + newtex->SetDisplaySize((float)width, (float)height); FTextureID oldtex = TexMan.CheckForTexture(src, ETextureType::MiscPatch); if (oldtex.isValid()) { ReplaceTexture(oldtex, newtex, true); - newtex->UseType = ETextureType::Override; + newtex->SetUseType(ETextureType::Override); } - else AddTexture(newtex); + else AddGameTexture(newtex); } } } @@ -926,11 +926,11 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b // Try to create a texture from this lump and add it. // Unfortunately we have to look at everything that comes through here... - FTexture *out = FTexture::CreateTexture(Name, i, skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch); + auto out = MakeGameTexture(FTexture::CreateTexture(Name, i, skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch)); if (out != NULL) { - AddTexture (out); + AddGameTexture (out); } } @@ -984,7 +984,7 @@ void FTextureManager::SortTexturesByType(int start, int end) { if (newtextures[j] != NULL && newtextures[j]->GetUseType() == texturetypes[i]) { - AddTexture(newtextures[j]->GetTexture()); + AddGameTexture(newtextures[j]); newtextures[j] = NULL; } } @@ -995,7 +995,7 @@ void FTextureManager::SortTexturesByType(int start, int end) if (newtextures[j] != NULL) { Printf("Texture %s has unknown type!\n", newtextures[j]->GetName().GetChars()); - AddTexture(newtextures[j]->GetTexture()); + AddGameTexture(newtextures[j]); } } } @@ -1033,8 +1033,8 @@ void FTextureManager::AddLocalizedVariants() FTextureID tex = CheckForTexture(entry.name, ETextureType::MiscPatch); if (tex.isValid()) { - FTexture *otex = GetTexture(origTex); - FTexture *ntex = GetTexture(tex); + auto otex = GetGameTexture(origTex); + auto ntex = GetGameTexture(tex); if (otex->GetDisplayWidth() != ntex->GetDisplayWidth() || otex->GetDisplayHeight() != ntex->GetDisplayHeight()) { Printf("Localized texture %s must be the same size as the one it replaces\n", entry.name); @@ -1093,18 +1093,18 @@ void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildI //if (BuildTileFiles.Size() == 0) CountBuildTiles (); // Texture 0 is a dummy texture used to indicate "no texture" - auto nulltex = new FImageTexture(nullptr, ""); + auto nulltex = MakeGameTexture(new FImageTexture(nullptr, "")); nulltex->SetUseType(ETextureType::Null); - AddTexture (nulltex); + AddGameTexture (nulltex); // This is for binding to unused texture units, because accessing an unbound texture unit is undefined. It's a one pixel empty texture. - auto emptytex = new FImageTexture(CreateEmptyTexture(), ""); + auto emptytex = MakeGameTexture(new FImageTexture(CreateEmptyTexture(), "")); emptytex->SetSize(1, 1); - AddTexture(emptytex); + AddGameTexture(emptytex); // some special textures used in the game. - AddTexture(CreateShaderTexture(false, false)); - AddTexture(CreateShaderTexture(false, true)); - AddTexture(CreateShaderTexture(true, false)); - AddTexture(CreateShaderTexture(true, true)); + AddGameTexture(MakeGameTexture(CreateShaderTexture(false, false))); + AddGameTexture(MakeGameTexture(CreateShaderTexture(false, true))); + AddGameTexture(MakeGameTexture(CreateShaderTexture(true, false))); + AddGameTexture(MakeGameTexture(CreateShaderTexture(true, true))); int wadcnt = fileSystem.GetNumWads(); @@ -1170,10 +1170,10 @@ void FTextureManager::InitPalettedVersions() } if (pic1.isValid() && pic2.isValid()) { - FTexture *owner = GetTexture(pic1); - FTexture *owned = GetTexture(pic2); + auto owner = GetGameTexture(pic1); + auto owned = GetGameTexture(pic2); - if (owner && owned) owner->PalVersion = owned; + if (owner && owned) owner->GetTexture()->PalVersion = owned; } } } @@ -1320,7 +1320,7 @@ void FTextureManager::AdjustSpriteOffsets() fileSystem.GetFileShortName(str, i); str[8] = 0; FTextureID texid = TexMan.CheckForTexture(str, ETextureType::Sprite, 0); - if (texid.isValid() && fileSystem.GetFileContainer(GetTexture(texid)->SourceLump) > fileSystem.GetMaxIwadNum()) + if (texid.isValid() && fileSystem.GetFileContainer(GetGameTexture(texid)->GetSourceLump()) > fileSystem.GetMaxIwadNum()) { // This texture has been replaced by some PWAD. memcpy(&sprid, str, 4); @@ -1355,7 +1355,7 @@ void FTextureManager::AdjustSpriteOffsets() } if (texno.isValid()) { - FTexture * tex = GetTexture(texno); + auto tex = GetGameTexture(texno); int lumpnum = tex->GetSourceLump(); // We only want to change texture offsets for sprites in the IWAD or the file this lump originated from. @@ -1366,11 +1366,11 @@ void FTextureManager::AdjustSpriteOffsets() { if (wadno >= fileSystem.GetIwadNum() && wadno <= fileSystem.GetMaxIwadNum() && !forced && iwadonly) { - memcpy(&sprid, &tex->Name[0], 4); + memcpy(&sprid, tex->GetName().GetChars(), 4); if (donotprocess.CheckKey(sprid)) continue; // do not alter sprites that only get partially replaced. } - tex->_LeftOffset[1] = x; - tex->_TopOffset[1] = y; + tex->GetTexture()->_LeftOffset[1] = x; + tex->GetTexture()->_TopOffset[1] = y; } } } diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 71edb533d9..774ad3a271 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -8,7 +8,6 @@ #include "name.h" class FxAddSub; -class FTexture; struct BuildInfo; int PalCheck(int tex); @@ -39,11 +38,6 @@ public: return InternalGetTexture(texnum.GetIndex(), animate, true); } - FTexture *GetTexture(FTextureID texnum, bool animate = false) - { - return InternalGetTexture(texnum.GetIndex(), animate, true)->GetTexture(); - } - FGameTexture* GetGameTexture(FTextureID texnum, bool animate = false) { return InternalGetTexture(texnum.GetIndex(), animate, true); @@ -97,7 +91,7 @@ public: void AddLocalizedVariants(); FTextureID CreateTexture (int lumpnum, ETextureType usetype=ETextureType::Any); // Also calls AddTexture - FTextureID AddTexture (FTexture *texture); + FTextureID AddGameTexture(FGameTexture* texture); FTextureID GetDefaultTexture() const { return DefaultTexture; } void LoadTextureX(int wadnum, FMultipatchTextureBuilder &build); @@ -105,7 +99,7 @@ public: void Init(void (*progressFunc_)(), void (*checkForHacks)(BuildInfo &)); void DeleteAll(); - void ReplaceTexture (FTextureID picnum, FTexture *newtexture, bool free); + void ReplaceTexture (FTextureID picnum, FGameTexture *newtexture, bool free); int NumTextures () const { return (int)Textures.Size(); } @@ -142,7 +136,6 @@ public: return BuildTileData.Last(); } - FTexture* Texture(FTextureID id) { return Textures[id.GetIndex()].Texture->GetTexture(); } FGameTexture* GameTexture(FTextureID id) { return Textures[id.GetIndex()].Texture; } void SetTranslation(FTextureID fromtexnum, FTextureID totexnum); @@ -184,3 +177,8 @@ public: }; extern FTextureManager TexMan; + +inline FGameTexture* MakeGameTexture(FTexture* tex) +{ + return reinterpret_cast(tex); +} \ No newline at end of file diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 93f0bed958..6322d91ab5 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -273,7 +273,6 @@ public: int GetDisplayTopOffset() { return GetScaledTopOffset(0); } double GetDisplayLeftOffsetDouble(int adjusted = 0) { return _LeftOffset[adjusted] / Scale.X; } double GetDisplayTopOffsetDouble(int adjusted = 0) { return _TopOffset[adjusted] / Scale.Y; } - FTexture* GetFrontSkyLayer(); int GetTexelWidth() { return Width; } int GetTexelHeight() { return Height; } @@ -303,7 +302,6 @@ public: int GetSkyOffset() const { return SkyOffset; } FTextureID GetID() const { return id; } PalEntry GetSkyCapColor(bool bottom); - FTexture *GetRawTexture(); virtual int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. void GetGlowColor(float *data); bool isGlowing() const { return bGlowing; } @@ -378,12 +376,12 @@ protected: // None of the following pointers are owned by this texture, they are all controlled by the texture manager. // Offset-less version for COMPATF_MASKEDMIDTEX - FTexture *OffsetLess = nullptr; + FGameTexture *OffsetLess = nullptr; // Front sky layer variant where color 0 is transparent - FTexture* FrontSkyLayer = nullptr; + FGameTexture* FrontSkyLayer = nullptr; public: // Paletted variant - FTexture *PalVersion = nullptr; + FGameTexture *PalVersion = nullptr; // Material layers FTexture *Brightmap = nullptr; FTexture* Detailmap = nullptr; @@ -483,7 +481,7 @@ public: { return Material[num]; } - FTexture* GetPalVersion() + FGameTexture* GetPalVersion() { return PalVersion; } @@ -631,8 +629,8 @@ class FSkyBox : public FImageTexture { public: - FTexture* previous; - FTexture* faces[6]; + FGameTexture* previous; + FGameTexture* faces[6]; // the faces need to be full materials as they can have all supported effects. bool fliptop; FSkyBox(const char* name); @@ -724,9 +722,9 @@ public: } // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. - FGameTexture* GetPalVersion() { return reinterpret_cast(wrapped.GetPalVersion()); } - FGameTexture* GetRawTexture() { return reinterpret_cast(wrapped.GetRawTexture()); } - FGameTexture* GetFrontSkyLayer() { return reinterpret_cast(wrapped.GetFrontSkyLayer()); } + FGameTexture* GetPalVersion() { return wrapped.GetPalVersion(); } + FGameTexture* GetRawTexture(); + FGameTexture* GetFrontSkyLayer(); // Glowing is a pure material property that should not filter down to the actual texture objects. void GetGlowColor(float* data) { wrapped.GetGlowColor(data); } diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index ab4a5d2a8c..f409b25311 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -709,14 +709,14 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) sc.MustGetNumber (); height = sc.Number; FTextureID picnum = TexMan.CheckForTexture (picname, ETextureType::Flat, texflags); - FGameTexture *viewer = reinterpret_cast(new FCanvasTexture (picname, width, height)); + FGameTexture *viewer = MakeGameTexture(new FCanvasTexture (picname, width, height)); if (picnum.Exists()) { auto oldtex = TexMan.GameTexture(picnum); fitwidth = oldtex->GetDisplayWidth (); fitheight = oldtex->GetDisplayHeight (); viewer->SetUseType(oldtex->GetUseType()); - TexMan.ReplaceTexture (picnum, viewer->GetTexture(), true); + TexMan.ReplaceTexture (picnum, viewer, true); } else { @@ -724,7 +724,7 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) fitheight = height; // [GRB] No need for oldtex viewer->SetUseType(ETextureType::Wall); - TexMan.AddTexture (viewer->GetTexture()); + TexMan.AddGameTexture (viewer); } if (sc.GetString()) { diff --git a/src/gamedata/textures/buildloader.cpp b/src/gamedata/textures/buildloader.cpp index 9faaab186c..e2f73e1469 100644 --- a/src/gamedata/textures/buildloader.cpp +++ b/src/gamedata/textures/buildloader.cpp @@ -153,13 +153,12 @@ void AddTiles(const FString& pathprefix, const void* tiles, FRemapTable *remap) int yoffs = (int8_t)((anm >> 16) & 255) + height / 2; int size = width * height; FTextureID texnum; - FTexture* tex; if (width <= 0 || height <= 0) continue; FStringf name("%sBTIL%04d", pathprefix.GetChars(), i); - tex = new FImageTexture(new FBuildTexture(pathprefix, i, tiledata, remap, width, height, xoffs, yoffs), name); - texnum = TexMan.AddTexture(tex); + auto tex = MakeGameTexture(new FImageTexture(new FBuildTexture(pathprefix, i, tiledata, remap, width, height, xoffs, yoffs), name)); + texnum = TexMan.AddGameTexture(tex); tiledata += size; tex->SetUseType(ETextureType::Override); diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index d8e04dcd83..893b35cffb 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -96,7 +96,7 @@ static void ParseVavoomSkybox() sc.ScriptMessage("Texture '%s' not found in Vavoom skybox '%s'\n", sc.String, sb->GetName().GetChars()); error = true; } - sb->faces[facecount] = tex->GetTexture(); + sb->faces[facecount] = tex; sc.MustGetStringName("}"); } facecount++; @@ -108,7 +108,7 @@ static void ParseVavoomSkybox() sb->SetSize(); if (!error) { - TexMan.AddTexture(sb); + TexMan.AddGameTexture(MakeGameTexture(sb)); } } } @@ -1004,7 +1004,7 @@ class GLDefsParser sc.MustGetString(); if (facecount<6) { - sb->faces[facecount] = TexMan.GetTexture(TexMan.GetTextureID(sc.String, ETextureType::Wall, FTextureManager::TEXMAN_TryAny|FTextureManager::TEXMAN_Overridable)); + sb->faces[facecount] = TexMan.GetGameTexture(TexMan.GetTextureID(sc.String, ETextureType::Wall, FTextureManager::TEXMAN_TryAny|FTextureManager::TEXMAN_Overridable)); } facecount++; } @@ -1013,7 +1013,7 @@ class GLDefsParser sc.ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->GetName().GetChars()); } sb->SetSize(); - TexMan.AddTexture(sb); + TexMan.AddGameTexture(MakeGameTexture(sb)); } //=========================================================================== diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index be123b3376..1418e6e2e2 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -157,7 +157,7 @@ FVoxelModel::FVoxelModel(FVoxel *voxel, bool owned) { mVoxel = voxel; mOwningVoxel = owned; - mPalette = TexMan.AddTexture(new FImageTexture(new FVoxelTexture(voxel))); + mPalette = TexMan.AddGameTexture(MakeGameTexture(new FImageTexture(new FVoxelTexture(voxel)))); } //=========================================================================== diff --git a/src/r_data/r_canvastexture.cpp b/src/r_data/r_canvastexture.cpp index 4e7e4a107d..dd8b91d5a2 100644 --- a/src/r_data/r_canvastexture.cpp +++ b/src/r_data/r_canvastexture.cpp @@ -57,7 +57,7 @@ void FCanvasTextureInfo::Add (AActor *viewpoint, FTextureID picnum, double fov) { return; } - texture = static_cast(TexMan.GetTexture(picnum)); + texture = static_cast(TexMan.GetGameTexture(picnum)->GetTexture()); if (!texture->bHasCanvas) { Printf ("%s is not a valid target for a camera\n", texture->Name.GetChars()); @@ -101,8 +101,8 @@ void SetCameraToTexture(AActor *viewpoint, const FString &texturename, double fo if (textureid.isValid()) { // Only proceed if the texture actually has a canvas. - FTexture *tex = TexMan.GetTexture(textureid); - if (tex && tex->isCanvas()) + auto tex = TexMan.GetGameTexture(textureid); + if (tex && tex->isHardwareCanvas()) // Q: how to deal with the software renderer here? { viewpoint->Level->canvasTextureInfo.Add(viewpoint, textureid, fov); } diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index 81264e6f2a..f3ed9b2964 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -75,10 +75,11 @@ SWSceneDrawer::SWSceneDrawer() auto texid = TexMan.CheckForTexture("@@palette@@", ETextureType::Any); if (!texid.Exists()) { - auto tex = new FImageTexture(new FSWPaletteTexture, "@@palette@@"); - texid = TexMan.AddTexture(tex); + // We need to wrap this in a game texture object to have it managed by the texture manager, even though it will never be used as a material. + auto tex = MakeGameTexture(new FImageTexture(new FSWPaletteTexture, "@@palette@@")); + texid = TexMan.AddGameTexture(tex); } - PaletteTexture = TexMan.GetTexture(texid); + PaletteTexture = TexMan.GetGameTexture(texid)->GetTexture(); } SWSceneDrawer::~SWSceneDrawer() From 662fa6e667a6ca3200f8d8bc2c82be069a79bbb2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 00:21:13 +0200 Subject: [PATCH 029/220] - removed the conversion helper code and fixed a few places where FMaterial was only used to access the hardware textures in the FTexture class. --- src/common/fonts/font.cpp | 7 ++++--- src/common/fonts/v_font.h | 1 - src/common/textures/formats/pngtexture.cpp | 3 ++- src/common/textures/hw_material.cpp | 13 ++---------- src/common/textures/hw_material.h | 2 +- src/common/textures/texture.cpp | 21 +++++++++++++++++++ src/common/textures/texturemanager.cpp | 4 ++-- src/common/textures/texturemanager.h | 1 + src/common/textures/textures.h | 4 +++- src/d_main.cpp | 8 +++---- src/rendering/2d/f_wipe.cpp | 2 +- src/rendering/gl/renderer/gl_renderer.cpp | 12 +++++------ src/rendering/gl/renderer/gl_renderer.h | 2 +- .../hwrenderer/textures/hw_precache.cpp | 15 +++++++------ .../polyrenderer/backend/poly_framebuffer.cpp | 3 +-- src/rendering/swrenderer/r_swscene.cpp | 20 ++++++++++-------- src/rendering/swrenderer/r_swscene.h | 2 +- .../vulkan/system/vk_framebuffer.cpp | 4 +--- 18 files changed, 68 insertions(+), 56 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index a1135f89a8..5fb4641be1 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 536b07ba3a..4e78da08f8 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 36ce398d35..75e578b684 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 7ab3f1321f..3a97d5a239 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 a9d1812d37..0f8fd8dad9 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 0636822d21..a5e6e138e6 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 f35a8af2b6..32d66d1b0d 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 774ad3a271..641b97c476 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 6322d91ab5..6753d8ed15 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 b6c0481494..98f0a884ee 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 464f93427a..80e425718f 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 d3b80ad34c..ee5fbb09a4 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 91ac325d5e..bf59a55326 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 7f52a53935..fa695f925a 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 827291f9c7..e8b1c5c87f 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 f3ed9b2964..ac5c382a9f 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 7dc12488d0..ad6b6d450c 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 24c5075eb0..dd4ef1d79c 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); From 18760d662269af80ec302873f197008ee9eeac17 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 00:23:40 +0200 Subject: [PATCH 030/220] - deleted unused function. --- src/common/textures/hw_material.cpp | 6 ------ src/common/textures/hw_material.h | 1 - 2 files changed, 7 deletions(-) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 3a97d5a239..2aa81199ff 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -179,12 +179,6 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, bool expand, bool cr return NULL; } -FMaterial * FMaterial::ValidateTexture(FTextureID no, bool expand, bool translate, bool create) -{ - return ValidateTexture(TexMan.GetGameTexture(no, translate), expand, create); -} - - void DeleteMaterial(FMaterial* mat) { delete mat; diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index 0f8fd8dad9..e1e27e3db8 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -59,7 +59,6 @@ public: static FMaterial *ValidateTexture(FGameTexture * tex, bool expand, bool create = true); - static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans, bool create = true); const TArray &GetLayerArray() const { return mTextureLayers; From da873ca8d111c5fd298a5901798ce7114d7f1e5f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 00:27:12 +0200 Subject: [PATCH 031/220] - moved the handling for paletted replacements into the texture manager. This is something the texture should not concern itself with. --- src/common/textures/texturemanager.cpp | 9 ++---- src/common/textures/texturemanager.h | 30 ++++++++++++++++--- src/common/textures/textures.h | 7 ----- .../swrenderer/textures/r_swtexture.cpp | 12 ++------ 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 32d66d1b0d..410a2c9a48 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 = { texture, hash }; + TextureHash hasher = { texture, -1, hash }; int trans = Textures.Push (hasher); Translation.Push (trans); if (bucket >= 0) HashFirst[bucket] = trans; @@ -1166,14 +1166,11 @@ void FTextureManager::InitPalettedVersions() FTextureID pic2 = CheckForTexture(sc.String, ETextureType::Any); if (!pic2.isValid()) { - sc.ScriptMessage("Unknown texture %s to use as replacement", sc.String); + sc.ScriptMessage("Unknown texture %s to use as paletted replacement", sc.String); } if (pic1.isValid() && pic2.isValid()) { - auto owner = GetGameTexture(pic1); - auto owned = GetGameTexture(pic2); - - if (owner && owned) owner->GetTexture()->PalVersion = owned; + Textures[pic1.GetIndex()].Paletted = pic2.GetIndex(); } } } diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 641b97c476..9fdb22a8da 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -24,14 +24,27 @@ public: private: int ResolveLocalizedTexture(int texnum); - FGameTexture *InternalGetTexture(int texnum, bool animate, bool localize) + int ResolveTextureIndex(int texnum, bool animate, bool localize) { - if ((unsigned)texnum >= Textures.Size()) return nullptr; + if ((unsigned)texnum >= Textures.Size()) return -1; if (animate) texnum = Translation[texnum]; if (localize && Textures[texnum].HasLocalization) texnum = ResolveLocalizedTexture(texnum); + return texnum; + } + + FGameTexture *InternalGetTexture(int texnum, bool animate, bool localize) + { + texnum = ResolveTextureIndex(texnum, animate, localize); + if (texnum == -1) return nullptr; return Textures[texnum].Texture; } + public: + FTextureID ResolveTextureIndex(FTextureID texid, bool animate, bool localize) + { + return FSetTextureID(ResolveTextureIndex(texid.GetIndex(), animate, localize)); + } + // This only gets used in UI code so we do not need PALVERS handling. FGameTexture* GetGameTextureByName(const char *name, bool animate = false) { @@ -44,6 +57,14 @@ public: return InternalGetTexture(texnum.GetIndex(), animate, true); } + FGameTexture* GetPalettedTexture(FTextureID texnum, bool animate = false, bool allowsubstitute = true) + { + auto texid = ResolveTextureIndex(texnum.GetIndex(), animate, true); + if (texid == -1) return nullptr; + if (allowsubstitute && Textures[texid].Paletted > 0) texid = Textures[texid].Paletted; + return Textures[texid].Texture; + } + FGameTexture* GameByIndex(int i, bool animate = false) { return InternalGetTexture(i, animate, true); @@ -148,7 +169,8 @@ private: struct TextureHash { - FGameTexture *Texture; + FGameTexture* Texture; + int Paletted; // redirection to paletted variant int HashNext; bool HasLocalization; }; @@ -182,4 +204,4 @@ extern FTextureManager TexMan; inline FGameTexture* MakeGameTexture(FTexture* tex) { return reinterpret_cast(tex); -} \ No newline at end of file +} diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 6753d8ed15..abfabd3863 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -382,8 +382,6 @@ protected: // Front sky layer variant where color 0 is transparent FGameTexture* FrontSkyLayer = nullptr; public: - // Paletted variant - FGameTexture *PalVersion = nullptr; // Material layers FTexture *Brightmap = nullptr; FTexture* Detailmap = nullptr; @@ -483,10 +481,6 @@ public: { return Material[num]; } - FGameTexture* GetPalVersion() - { - return PalVersion; - } private: int CheckDDPK3(); @@ -724,7 +718,6 @@ public: } // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. - FGameTexture* GetPalVersion() { return wrapped.GetPalVersion(); } FGameTexture* GetRawTexture(); FGameTexture* GetFrontSkyLayer(); diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index c501f4df00..ef7d3decb3 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -612,18 +612,10 @@ CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL) R_InitSkyMap(); } -static FGameTexture* PalCheck(FGameTexture* tex) -{ - // In any true color mode this shouldn't do anything. - if (vid_nopalsubstitutions || V_IsTrueColor() || tex == nullptr) return tex; - auto palvers = tex->GetPalVersion(); - if (palvers) return palvers; - return tex; -} - FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull, bool frontsky) { - auto tex = PalCheck(TexMan.GetGameTexture(texid, true)); + bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor(); + auto tex = TexMan.GetPalettedTexture(texid, true, needpal); if (tex == nullptr || (!allownull && !tex->isValid())) return nullptr; if (frontsky) { From 5352682697cffd237cc43a163c417777d9e60b5d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 00:33:12 +0200 Subject: [PATCH 032/220] - moved the front layer hack for Hexen's skies to the texture manager. --- src/common/textures/texture.cpp | 26 ------------- src/common/textures/texturemanager.cpp | 38 +++++++++++++++++-- src/common/textures/texturemanager.h | 4 +- src/common/textures/textures.h | 1 - src/rendering/hwrenderer/scene/hw_sky.cpp | 1 - src/rendering/r_sky.cpp | 9 +++-- .../swrenderer/line/r_renderdrawsegment.cpp | 2 +- src/rendering/swrenderer/plane/r_skyplane.cpp | 2 +- .../swrenderer/textures/r_swtexture.cpp | 11 +----- .../swrenderer/textures/r_swtexture.h | 2 +- 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index a5e6e138e6..6d19723f58 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -217,32 +217,6 @@ FGameTexture *FGameTexture::GetRawTexture() return tex->OffsetLess; } -//========================================================================== -// -// Same shit for a different hack, this time Hexen's front sky layers. -// -//========================================================================== - -FGameTexture* FGameTexture::GetFrontSkyLayer() -{ - auto tex = GetTexture(); - if (tex->FrontSkyLayer) return tex->FrontSkyLayer; - // Reject anything that cannot have been a front layer for the sky in Hexen. - auto image = tex->GetImage(); - if (image == nullptr || !image->SupportRemap0() || GetUseType() != ETextureType::Wall || tex->Scale.X != 1 || tex->Scale.Y != 1 || useWorldPanning() || tex->_TopOffset[0] != 0 || - image->GetWidth() != GetTexelWidth() || image->GetHeight() != GetTexelHeight()) - { - tex->FrontSkyLayer = this; - return this; - } - - tex->FrontSkyLayer = MakeGameTexture(new FImageTexture(image, "")); - TexMan.AddGameTexture(tex->FrontSkyLayer); - tex->FrontSkyLayer->GetTexture()->bNoRemap0 = true; - return tex->FrontSkyLayer; -} - - void FTexture::SetDisplaySize(int fitwidth, int fitheight) { Scale.X = double(Width) / fitwidth; diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 410a2c9a48..3a25f0a0b2 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -375,7 +375,7 @@ bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitut // //========================================================================== -FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) +FTextureID FTextureManager::AddGameTexture (FGameTexture *texture, bool addtohash) { int bucket; int hash; @@ -385,7 +385,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) // Later textures take precedence over earlier ones // Textures without name can't be looked for - if (texture->GetName().IsNotEmpty()) + if (addtohash && texture->GetName().IsNotEmpty()) { bucket = int(MakeKey (texture->GetName()) % HASH_SIZE); hash = HashFirst[bucket]; @@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture) hash = -1; } - TextureHash hasher = { texture, -1, hash }; + TextureHash hasher = { texture, -1, -1, hash }; int trans = Textures.Push (hasher); Translation.Push (trans); if (bucket >= 0) HashFirst[bucket] = trans; @@ -1176,6 +1176,38 @@ void FTextureManager::InitPalettedVersions() } } +//========================================================================== +// +// Same shit for a different hack, this time Hexen's front sky layers. +// +//========================================================================== + +FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid) +{ + int texidx = texid.GetIndex(); + if (texidx >= Textures.Size()) return texid; + if (Textures[texidx].FrontSkyLayer != -1) return FSetTextureID(Textures[texidx].FrontSkyLayer); + + // Reject anything that cannot have been a front layer for the sky in original Hexen, i.e. it needs to be an unscaled wall texture only using Doom patches. + auto tex = Textures[texidx].Texture; + auto image = tex->GetTexture()->GetImage(); + if (image == nullptr || !image->SupportRemap0() || tex->GetUseType() != ETextureType::Wall || tex->useWorldPanning() || tex->GetTexelTopOffset() != 0 || + tex->GetTexelWidth() != tex->GetDisplayWidth() || tex->GetTexelHeight() != tex->GetDisplayHeight()) + { + Textures[texidx].FrontSkyLayer = texidx; + return texid; + } + + // Set this up so that it serializes to the same info as the base texture - this is needed to restore it on load. + auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image, tex->GetName())); + FrontSkyLayer->SetUseType(tex->GetUseType()); + FrontSkyLayer->GetTexture()->bNoRemap0 = true; + texid = TexMan.AddGameTexture(FrontSkyLayer); + Textures[texidx].FrontSkyLayer = texid.GetIndex(); + Textures[texid.GetIndex()].FrontSkyLayer = texid.GetIndex(); // also let it refer to itself as its front sky layer, in case for repeated InitSkyMap calls. + return texid; +} + //========================================================================== // // diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 9fdb22a8da..2b3bb08298 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -75,6 +75,7 @@ public: bool OkForLocalization(FTextureID texnum, const char *substitute, int locnum); void FlushAll(); + FTextureID GetFrontSkyLayer(FTextureID); enum @@ -113,7 +114,7 @@ public: void AddLocalizedVariants(); FTextureID CreateTexture (int lumpnum, ETextureType usetype=ETextureType::Any); // Also calls AddTexture - FTextureID AddGameTexture(FGameTexture* texture); + FTextureID AddGameTexture(FGameTexture* texture, bool addtohash = true); FTextureID GetDefaultTexture() const { return DefaultTexture; } void LoadTextureX(int wadnum, FMultipatchTextureBuilder &build); @@ -171,6 +172,7 @@ private: { FGameTexture* Texture; int Paletted; // redirection to paletted variant + int FrontSkyLayer; int HashNext; bool HasLocalization; }; diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index abfabd3863..ed438e36a3 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -719,7 +719,6 @@ public: // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. FGameTexture* GetRawTexture(); - FGameTexture* GetFrontSkyLayer(); // Glowing is a pure material property that should not filter down to the actual texture objects. void GetGlowColor(float* data) { wrapped.GetGlowColor(data); } diff --git a/src/rendering/hwrenderer/scene/hw_sky.cpp b/src/rendering/hwrenderer/scene/hw_sky.cpp index af2328bbc0..5a0c4f139d 100644 --- a/src/rendering/hwrenderer/scene/hw_sky.cpp +++ b/src/rendering/hwrenderer/scene/hw_sky.cpp @@ -75,7 +75,6 @@ void HWSkyInfo::init(HWDrawInfo *di, int sky1, PalEntry FadeColor) if (di->Level->flags&LEVEL_DOUBLESKY) { auto tex1 = TexMan.GetGameTexture(di->Level->skytexture1, true); - if (tex1) tex1 = tex1->GetFrontSkyLayer(); texture[1] = tex1; x_offset[1] = di->Level->hw_sky1pos; doublesky = true; diff --git a/src/rendering/r_sky.cpp b/src/rendering/r_sky.cpp index b51a447837..0510681626 100644 --- a/src/rendering/r_sky.cpp +++ b/src/rendering/r_sky.cpp @@ -75,6 +75,11 @@ void InitSkyMap(FLevelLocals *Level) { Level->skytexture2 = TexMan.CheckForTexture("-noflat-", ETextureType::Any); } + if (Level->flags & LEVEL_DOUBLESKY) + { + Level->skytexture1 = TexMan.GetFrontSkyLayer(Level->skytexture1); + } + skytex1 = TexMan.GetGameTexture(Level->skytexture1, false); skytex2 = TexMan.GetGameTexture(Level->skytexture2, false); @@ -82,10 +87,6 @@ void InitSkyMap(FLevelLocals *Level) if (skytex1 == nullptr) return; - if (Level->flags & LEVEL_DOUBLESKY) - { - skytex1 = skytex1->GetFrontSkyLayer(); - } if ((Level->flags & LEVEL_DOUBLESKY) && skytex1->GetDisplayHeight() != skytex2->GetDisplayHeight()) { diff --git a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp index 4d203ec4a0..041e96b181 100644 --- a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp @@ -91,7 +91,7 @@ namespace swrenderer auto viewport = Thread->Viewport.get(); Clip3DFloors *clip3d = Thread->Clip3D.get(); - auto tex = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::mid), true, curline->GetLevel()); + auto tex = GetPalettedSWTexture(curline->sidedef->GetTexture(side_t::mid), true, !!(curline->GetLevel()->i_compatflags & COMPATF_MASKEDMIDTEX)); const short *mfloorclip = ds->drawsegclip.sprbottomclip; const short *mceilingclip = ds->drawsegclip.sprtopclip; diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 7276aa6047..5b9b60c4cc 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -71,7 +71,7 @@ namespace swrenderer Thread = thread; auto Level = Thread->Viewport->Level(); - auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true, !!(Level->flags & LEVEL_DOUBLESKY)); + auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true); auto sskytex2 = GetPalettedSWTexture(Level->skytexture2, true, nullptr, true); if (sskytex1 == nullptr) diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index ef7d3decb3..5094aa3555 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -612,19 +612,12 @@ CUSTOM_CVAR(Bool, vid_nopalsubstitutions, false, CVAR_ARCHIVE | CVAR_NOINITCALL) R_InitSkyMap(); } -FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat, bool allownull, bool frontsky) +FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat, bool allownull) { bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor(); auto tex = TexMan.GetPalettedTexture(texid, true, needpal); if (tex == nullptr || (!allownull && !tex->isValid())) return nullptr; - if (frontsky) - { - tex = tex->GetFrontSkyLayer(); - } - else if (checkcompat && checkcompat->i_compatflags & COMPATF_MASKEDMIDTEX) - { - tex = tex->GetRawTexture(); - } + if (checkcompat) tex = tex->GetRawTexture(); return GetSoftwareTexture(tex); } diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index 595acbd773..bf9a83c5a6 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -193,4 +193,4 @@ public: }; FSoftwareTexture* GetSoftwareTexture(FGameTexture* tex); -FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, FLevelLocals *checkcompat = nullptr, bool allownull = false, bool frontsky = false); +FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool checkcompat = false, bool allownull = false); From c5e81c54a24c30f628a51c70fee54bd19dadf6b6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 00:45:14 +0200 Subject: [PATCH 033/220] - Moved the raw texture handling into the texture manager as well. --- .../textures/formats/multipatchtexture.h | 12 +++- src/common/textures/image.h | 3 +- src/common/textures/texture.cpp | 36 ------------ src/common/textures/texturemanager.cpp | 57 ++++++++++++++++++- src/common/textures/texturemanager.h | 6 +- src/common/textures/textures.h | 3 - src/rendering/hwrenderer/scene/hw_walls.cpp | 4 +- .../swrenderer/textures/r_swtexture.cpp | 7 ++- 8 files changed, 80 insertions(+), 48 deletions(-) diff --git a/src/common/textures/formats/multipatchtexture.h b/src/common/textures/formats/multipatchtexture.h index 5c15e8aa06..2f1421a8a1 100644 --- a/src/common/textures/formats/multipatchtexture.h +++ b/src/common/textures/formats/multipatchtexture.h @@ -41,8 +41,18 @@ class FMultiPatchTexture : public FImageSource friend class FGameTexture; public: FMultiPatchTexture(int w, int h, const TArray &parts, bool complex, bool textual); - bool SupportRemap0() override; int GetNumParts() const { return NumParts; } + // Query some needed info for texture hack support. + bool SupportRemap0() override; + bool IsRawCompatible() override + { + return NumParts != 1 || Parts[0].OriginY == 0 || bTextual; + } + FImageSource* GetImageForPart(int num) + { + if (num >= 0 && num < NumParts) return Parts[num].Image; + return nullptr; + } protected: int NumParts; diff --git a/src/common/textures/image.h b/src/common/textures/image.h index a72c82eb31..00b5414119 100644 --- a/src/common/textures/image.h +++ b/src/common/textures/image.h @@ -57,7 +57,8 @@ protected: public: - virtual bool SupportRemap0() { return false; } // Unfortunate hackery that's needed for Hexen's skies. + virtual bool SupportRemap0() { return false; } // Unfortunate hackery that's needed for Hexen's skies. Only the image can know about the needed parameters + virtual bool IsRawCompatible() { return true; } // Same thing for mid texture compatibility handling. Can only be determined by looking at the composition data which is private to the image. void CopySize(FImageSource &other) { diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 6d19723f58..adb2b60e4e 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -181,42 +181,6 @@ FBitmap FTexture::GetBgraBitmap(const PalEntry *remap, int *ptrans) return bmp; } -//========================================================================== -// -// -// -//========================================================================== - -FGameTexture *FGameTexture::GetRawTexture() -{ - auto tex = GetTexture(); - if (tex->OffsetLess) return tex->OffsetLess; - // Reject anything that cannot have been a single-patch multipatch texture in vanilla. - auto image = static_cast(tex->GetImage()); - if (tex->bMultiPatch != 1 || GetUseType() != ETextureType::Wall || tex->Scale.X != 1 || tex->Scale.Y != 1 || - useWorldPanning() || image == nullptr || image->GetNumParts() != 1 || tex->_TopOffset[0] == 0) - { - tex->OffsetLess = this; - return this; - } - // Set up a new texture that directly references the underlying patch. - // From here we cannot retrieve the original texture made for it, so just create a new one. - FImageSource *source = image->Parts[0].Image; - - // Size must match for this to work as intended - if (source->GetWidth() != GetTexelWidth() || source->GetHeight() != GetTexelHeight()) - { - tex->OffsetLess = this; - return this; - } - - - tex->OffsetLess = MakeGameTexture(new FImageTexture(source, "")); - // todo: This must also copy all layers from the base texture. - TexMan.AddGameTexture(tex->OffsetLess); - return tex->OffsetLess; -} - void FTexture::SetDisplaySize(int fitwidth, int fitheight) { Scale.X = double(Width) / fitwidth; diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 3a25f0a0b2..5ffac6fc8d 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -396,7 +396,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture, bool addtohas hash = -1; } - TextureHash hasher = { texture, -1, -1, hash }; + TextureHash hasher = { texture, -1, -1, -1, hash }; int trans = Textures.Push (hasher); Translation.Push (trans); if (bucket >= 0) HashFirst[bucket] = trans; @@ -1176,6 +1176,50 @@ void FTextureManager::InitPalettedVersions() } } +//========================================================================== +// +// +// +//========================================================================== + +FTextureID FTextureManager::GetRawTexture(FTextureID texid) +{ + int texidx = texid.GetIndex(); + if ((unsigned)texidx >= Textures.Size()) return texid; + if (Textures[texidx].FrontSkyLayer != -1) return FSetTextureID(Textures[texidx].FrontSkyLayer); + + // Reject anything that cannot have been a front layer for the sky in original Hexen, i.e. it needs to be an unscaled wall texture only using Doom patches. + auto tex = Textures[texidx].Texture; + auto ttex = tex->GetTexture(); + auto image = tex->GetTexture()->GetImage(); + // Reject anything that cannot have been a single-patch multipatch texture in vanilla. + if (image == nullptr || image->IsRawCompatible() || tex->GetUseType() != ETextureType::Wall || tex->GetTexelWidth() != tex->GetDisplayWidth() || + tex->GetTexelHeight() != tex->GetDisplayHeight()) + { + Textures[texidx].RawTexture = texidx; + return texid; + } + + // Let the hackery begin + auto mptimage = static_cast(image); + auto source = mptimage->GetImageForPart(0); + + // Size must match for this to work as intended + if (source->GetWidth() != tex->GetTexelWidth() || source->GetHeight() != tex->GetTexelHeight()) + { + Textures[texidx].RawTexture = texidx; + return texid; + } + + // Todo: later this can just link to the already existing texture for this source graphic, once it can be retrieved through the image's SourceLump index + auto RawTexture = MakeGameTexture(new FImageTexture(source, "")); + texid = TexMan.AddGameTexture(RawTexture); + Textures[texidx].RawTexture = texid.GetIndex(); + Textures[texid.GetIndex()].RawTexture = texid.GetIndex(); + return texid; +} + + //========================================================================== // // Same shit for a different hack, this time Hexen's front sky layers. @@ -1185,7 +1229,7 @@ void FTextureManager::InitPalettedVersions() FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid) { int texidx = texid.GetIndex(); - if (texidx >= Textures.Size()) return texid; + if ((unsigned)texidx >= Textures.Size()) return texid; if (Textures[texidx].FrontSkyLayer != -1) return FSetTextureID(Textures[texidx].FrontSkyLayer); // Reject anything that cannot have been a front layer for the sky in original Hexen, i.e. it needs to be an unscaled wall texture only using Doom patches. @@ -1199,10 +1243,11 @@ FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid) } // Set this up so that it serializes to the same info as the base texture - this is needed to restore it on load. + // But do not link the new texture into the hash chain! auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image, tex->GetName())); FrontSkyLayer->SetUseType(tex->GetUseType()); FrontSkyLayer->GetTexture()->bNoRemap0 = true; - texid = TexMan.AddGameTexture(FrontSkyLayer); + texid = TexMan.AddGameTexture(FrontSkyLayer, false); Textures[texidx].FrontSkyLayer = texid.GetIndex(); Textures[texid.GetIndex()].FrontSkyLayer = texid.GetIndex(); // also let it refer to itself as its front sky layer, in case for repeated InitSkyMap calls. return texid; @@ -1443,3 +1488,9 @@ FTextureID FTextureID::operator +(int offset) throw() if (texnum + offset >= TexMan.NumTextures()) return FTextureID(-1); return FTextureID(texnum + offset); } + + +CCMD(texinfo) +{ + Printf("Sizeof texture = %d\n", sizeof(FTexture)); +} diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 2b3bb08298..994772edc9 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -76,6 +76,7 @@ public: void FlushAll(); FTextureID GetFrontSkyLayer(FTextureID); + FTextureID GetRawTexture(FTextureID); enum @@ -171,8 +172,9 @@ private: struct TextureHash { FGameTexture* Texture; - int Paletted; // redirection to paletted variant - int FrontSkyLayer; + int Paletted; // redirection to paletted variant + int FrontSkyLayer; // and front sky layer, + int RawTexture; int HashNext; bool HasLocalization; }; diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index ed438e36a3..c4841cb814 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -717,9 +717,6 @@ public: wrapped.CopySize(&BaseTexture->wrapped); } - // These substitutions must be done on the material level because their sizes can differ. Substitution must happen before any coordinate calculations take place. - FGameTexture* GetRawTexture(); - // Glowing is a pure material property that should not filter down to the actual texture objects. void GetGlowColor(float* data) { wrapped.GetGlowColor(data); } bool isGlowing() const { return wrapped.isGlowing(); } diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 68ecbae3ab..73c19f8041 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -2078,7 +2078,9 @@ void HWWall::Process(HWDrawInfo *di, seg_t *seg, sector_t * frontsector, sector_ { if (di->Level->i_compatflags & COMPATF_MASKEDMIDTEX) { - tex = tex->GetRawTexture(); + auto rawtexid = TexMan.GetRawTexture(tex->GetID()); + auto rawtex = TexMan.GetGameTexture(rawtexid); + if (rawtex) tex = rawtex; } texture = tex; } diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index 5094aa3555..4f3a94bc9f 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -617,7 +617,12 @@ FSoftwareTexture* GetPalettedSWTexture(FTextureID texid, bool animate, bool chec bool needpal = !vid_nopalsubstitutions && !V_IsTrueColor(); auto tex = TexMan.GetPalettedTexture(texid, true, needpal); if (tex == nullptr || (!allownull && !tex->isValid())) return nullptr; - if (checkcompat) tex = tex->GetRawTexture(); + if (checkcompat) + { + auto rawtexid = TexMan.GetRawTexture(tex->GetID()); + auto rawtex = TexMan.GetGameTexture(rawtexid); + if (rawtex) tex = rawtex; + } return GetSoftwareTexture(tex); } From 095a5e2c0a73dbd71c4bb29bc030c094dff29179 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 18:46:31 +0200 Subject: [PATCH 034/220] - allocate the sprite positioning info on demand only. For most textures this is never needed and it can easily be put in the memory arena being used for image sources. --- src/common/textures/image.cpp | 2 +- src/common/textures/image.h | 2 +- src/common/textures/texture.cpp | 119 ++++++++++++++----------- src/common/textures/texturemanager.cpp | 6 -- src/common/textures/textures.h | 12 +-- 5 files changed, 71 insertions(+), 70 deletions(-) diff --git a/src/common/textures/image.cpp b/src/common/textures/image.cpp index ef40efd19a..d68db329d0 100644 --- a/src/common/textures/image.cpp +++ b/src/common/textures/image.cpp @@ -41,7 +41,7 @@ #include "cmdlib.h" #include "palettecontainer.h" -FMemArena FImageSource::ImageArena(32768); +FMemArena ImageArena(32768); TArrayFImageSource::ImageForLump; int FImageSource::NextID; static PrecacheInfo precacheInfo; diff --git a/src/common/textures/image.h b/src/common/textures/image.h index 00b5414119..38e5a2ee17 100644 --- a/src/common/textures/image.h +++ b/src/common/textures/image.h @@ -7,6 +7,7 @@ class FImageSource; using PrecacheInfo = TMap>; +extern FMemArena ImageArena; // Doom patch format header struct patch_t @@ -38,7 +39,6 @@ class FImageSource friend class FBrightmapTexture; protected: - static FMemArena ImageArena; static TArrayImageForLump; static int NextID; diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index adb2b60e4e..c41637430d 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -737,29 +737,6 @@ TArray FTexture::Get8BitPixels(bool alphatex) return Pixels; } -//=========================================================================== -// -// Sets up the sprite positioning data for this texture -// -//=========================================================================== - -void FTexture::SetupSpriteData() -{ - spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f; - spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f; - spi.spriteWidth = GetTexelWidth(); - spi.spriteHeight = GetTexelHeight(); - - if (ShouldExpandSprite()) - { - if (mTrimResult == -1) mTrimResult = !!TrimBorders(spi.trim); // get the trim size before adding the empty frame - spi.spriteWidth += 2; - spi.spriteHeight += 2; - } - else mTrimResult = 0; - SetSpriteRect(); -} - //=========================================================================== // // Checks if a sprite may be expanded with an empty frame @@ -875,54 +852,90 @@ outl: } //=========================================================================== +// +// Sets up the sprite positioning data for this texture // -// Set the sprite rectangle +//=========================================================================== + +void FTexture::SetupSpriteData() +{ + // Since this is only needed for real sprites it gets allocated on demand. + // It also allocates from the image memory arena because it has the same lifetime and to reduce maintenance. + if (spi == nullptr) spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo)); + for (int i = 0; i < 2; i++) + { + auto& spi = this->spi[i]; + spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f; + spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f; + spi.spriteWidth = GetTexelWidth(); + spi.spriteHeight = GetTexelHeight(); + + if (i == 1 && ShouldExpandSprite()) + { + spi.mTrimResult = TrimBorders(spi.trim); // get the trim size before adding the empty frame + spi.spriteWidth += 2; + spi.spriteHeight += 2; + } + } + SetSpriteRect(); +} + +//=========================================================================== +// +// Set the sprite rectangle. This is separate because it may be called by a CVAR, too. // //=========================================================================== void FTexture::SetSpriteRect() { + + if (!spi) return; auto leftOffset = GetLeftOffsetHW(); auto topOffset = GetTopOffsetHW(); float fxScale = (float)Scale.X; float fyScale = (float)Scale.Y; - // mSpriteRect is for positioning the sprite in the scene. - spi.mSpriteRect.left = -leftOffset / fxScale; - spi.mSpriteRect.top = -topOffset / fyScale; - spi.mSpriteRect.width = spi.spriteWidth / fxScale; - spi.mSpriteRect.height = spi.spriteHeight / fyScale; - - if (bExpandSprite) + for (int i = 0; i < 2; i++) { - // a little adjustment to make sprites look better with texture filtering: - // create a 1 pixel wide empty frame around them. + auto& spi = this->spi[i]; - int oldwidth = spi.spriteWidth - 2; - int oldheight = spi.spriteHeight - 2; + // mSpriteRect is for positioning the sprite in the scene. + spi.mSpriteRect.left = -leftOffset / fxScale; + spi.mSpriteRect.top = -topOffset / fyScale; + spi.mSpriteRect.width = spi.spriteWidth / fxScale; + spi.mSpriteRect.height = spi.spriteHeight / fyScale; - leftOffset += 1; - topOffset += 1; - - // Reposition the sprite with the frame considered - spi.mSpriteRect.left = -(float)leftOffset / fxScale; - spi.mSpriteRect.top = -(float)topOffset / fyScale; - spi.mSpriteRect.width = (float)spi.spriteWidth / fxScale; - spi.mSpriteRect.height = (float)spi.spriteHeight / fyScale; - - if (mTrimResult > 0) + if (i == 1 && ShouldExpandSprite()) { - spi.mSpriteRect.left += (float)spi.trim[0] / fxScale; - spi.mSpriteRect.top += (float)spi.trim[1] / fyScale; + // a little adjustment to make sprites look better with texture filtering: + // create a 1 pixel wide empty frame around them. - spi.mSpriteRect.width -= float(oldwidth - spi.trim[2]) / fxScale; - spi.mSpriteRect.height -= float(oldheight - spi.trim[3]) / fyScale; + int oldwidth = spi.spriteWidth - 2; + int oldheight = spi.spriteHeight - 2; - spi.mSpriteU[0] = (float)spi.trim[0] / (float)spi.spriteWidth; - spi.mSpriteV[0] = (float)spi.trim[1] / (float)spi.spriteHeight; - spi.mSpriteU[1] -= float(oldwidth - spi.trim[0] - spi.trim[2]) / (float)spi.spriteWidth; - spi.mSpriteV[1] -= float(oldheight - spi.trim[1] - spi.trim[3]) / (float)spi.spriteHeight; + leftOffset += 1; + topOffset += 1; + + // Reposition the sprite with the frame considered + spi.mSpriteRect.left = -(float)leftOffset / fxScale; + spi.mSpriteRect.top = -(float)topOffset / fyScale; + spi.mSpriteRect.width = (float)spi.spriteWidth / fxScale; + spi.mSpriteRect.height = (float)spi.spriteHeight / fyScale; + + if (spi.mTrimResult > 0) + { + spi.mSpriteRect.left += (float)spi.trim[0] / fxScale; + spi.mSpriteRect.top += (float)spi.trim[1] / fyScale; + + spi.mSpriteRect.width -= float(oldwidth - spi.trim[2]) / fxScale; + spi.mSpriteRect.height -= float(oldheight - spi.trim[3]) / fyScale; + + spi.mSpriteU[0] = (float)spi.trim[0] / (float)spi.spriteWidth; + spi.mSpriteV[0] = (float)spi.trim[1] / (float)spi.spriteHeight; + spi.mSpriteU[1] -= float(oldwidth - spi.trim[0] - spi.trim[2]) / (float)spi.spriteWidth; + spi.mSpriteV[1] -= float(oldheight - spi.trim[1] - spi.trim[3]) / (float)spi.spriteHeight; + } } } } diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 5ffac6fc8d..ca370dda6a 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -1488,9 +1488,3 @@ FTextureID FTextureID::operator +(int offset) throw() if (texnum + offset >= TexMan.NumTextures()) return FTextureID(-1); return FTextureID(texnum + offset); } - - -CCMD(texinfo) -{ - Printf("Sizeof texture = %d\n", sizeof(FTexture)); -} diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index c4841cb814..76af078f1c 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -229,6 +229,7 @@ struct SpritePositioningInfo int spriteWidth, spriteHeight; float mSpriteU[2], mSpriteV[2]; FloatRect mSpriteRect; + uint8_t mTrimResult; float GetSpriteUL() const { return mSpriteU[0]; } float GetSpriteVT() const { return mSpriteV[0]; } @@ -255,8 +256,7 @@ class FTexture public: - SpritePositioningInfo spi; - int8_t mTrimResult = -1; + SpritePositioningInfo *spi = nullptr; IHardwareTexture* GetHardwareTexture(int translation, bool expanded); static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType usetype); @@ -375,12 +375,6 @@ public: protected: ISoftwareTexture *SoftwareTexture = nullptr; - // None of the following pointers are owned by this texture, they are all controlled by the texture manager. - - // Offset-less version for COMPATF_MASKEDMIDTEX - FGameTexture *OffsetLess = nullptr; - // Front sky layer variant where color 0 is transparent - FGameTexture* FrontSkyLayer = nullptr; public: // Material layers FTexture *Brightmap = nullptr; @@ -736,7 +730,7 @@ public: void SetDisplaySize(float w, float h) { wrapped.SetSize((int)w, (int)h); } void SetSpriteRect() { wrapped.SetSpriteRect(); } - const SpritePositioningInfo& GetSpritePositioning(int which) { /* todo: keep two sets of positioning infd*/ if (wrapped.mTrimResult == -1) wrapped.SetupSpriteData(); return wrapped.spi; } + const SpritePositioningInfo& GetSpritePositioning(int which) { if (wrapped.spi == nullptr) wrapped.SetupSpriteData(); return wrapped.spi[which]; } int GetAreas(FloatRect** pAreas) const { return wrapped.GetAreas(pAreas); } PalEntry GetSkyCapColor(bool bottom) { return wrapped.GetSkyCapColor(bottom); } From a81bb2a136c19eb7c0b12420366b98a5a8b6347b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 19:34:56 +0200 Subject: [PATCH 035/220] - make FGameTexture a separate object owning an FTexture instead of merely using a type cast to access it. --- src/common/textures/texture.cpp | 11 +- src/common/textures/texturemanager.h | 4 - src/common/textures/textures.h | 161 ++++++++++++++------------- 3 files changed, 93 insertions(+), 83 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index c41637430d..9e7ad3aae1 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -148,8 +148,6 @@ FTexture::FTexture (const char *name, int lumpnum) FTexture::~FTexture () { - FGameTexture *link = fileSystem.GetLinkedTexture(SourceLump); - if (link->GetTexture() == this) fileSystem.SetLinkedTexture(SourceLump, nullptr); if (areas != nullptr) delete[] areas; areas = nullptr; @@ -1084,9 +1082,16 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) } +FGameTexture::~FGameTexture() +{ + FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump()); + if (link == this) fileSystem.SetLinkedTexture(GetSourceLump(), nullptr); + delete wrapped; +} + bool FGameTexture::isUserContent() const { - int filenum = fileSystem.GetFileContainer(wrapped.GetSourceLump()); + int filenum = fileSystem.GetFileContainer(wrapped->GetSourceLump()); return (filenum > fileSystem.GetMaxIwadNum()); } diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 994772edc9..9cdfa58b47 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -205,7 +205,3 @@ public: extern FTextureManager TexMan; -inline FGameTexture* MakeGameTexture(FTexture* tex) -{ - return reinterpret_cast(tex); -} diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 76af078f1c..1b5bac4101 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -640,121 +640,130 @@ public: // Refactoring helper to allow piece by piece adjustment of the API class FGameTexture { - FTexture wrapped; + FTexture *wrapped; public: - FTexture* GetTexture() { return &wrapped; } - int GetSourceLump() const { return wrapped.GetSourceLump(); } - void SetBrightmap(FGameTexture* tex) { wrapped.Brightmap = tex->GetTexture(); } + FGameTexture(FTexture* wrap) : wrapped(wrap) {} + ~FGameTexture(); - double GetDisplayWidth() /*const*/ { return wrapped.GetDisplayWidthDouble(); } - double GetDisplayHeight() /*const*/ { return wrapped.GetDisplayHeightDouble(); } - int GetTexelWidth() /*const*/ { return wrapped.GetTexelWidth(); } - int GetTexelHeight() /*const*/ { return wrapped.GetTexelHeight(); } - int GetTexelLeftOffset(int adjusted = 0) /*const*/ { return wrapped.GetTexelLeftOffset(adjusted); } - int GetTexelTopOffset(int adjusted = 0) /*const*/ { return wrapped.GetTexelTopOffset(adjusted); } - double GetDisplayLeftOffset(int adjusted = 0) /*const*/ { return wrapped.GetDisplayLeftOffsetDouble(adjusted); } - double GetDisplayTopOffset(int adjusted = 0) /*const*/ { return wrapped.GetDisplayTopOffsetDouble(adjusted); } + FTexture* GetTexture() { return wrapped; } + int GetSourceLump() const { return wrapped->GetSourceLump(); } + void SetBrightmap(FGameTexture* tex) { wrapped->Brightmap = tex->GetTexture(); } - bool isValid() { return wrapped.isValid(); } - int isWarped() { return wrapped.isWarped(); } - void SetWarpStyle(int style) { wrapped.bWarped = style; } - bool isMasked() { return wrapped.isMasked(); } - bool isHardwareCanvas() const { return wrapped.isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. - bool isSoftwareCanvas() const { return wrapped.isCanvas(); } - bool isMiscPatch() const { return wrapped.GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. - bool isMultiPatch() const { return wrapped.bMultiPatch; } - bool isFullbrightDisabled() const { return wrapped.isFullbrightDisabled(); } - bool isFullbright() const { return wrapped.isFullbright(); } - bool isFullNameTexture() const { return wrapped.bFullNameTexture; } - bool expandSprites() const { return wrapped.bExpandSprite; } - bool useWorldPanning() const { return wrapped.UseWorldPanning(); } - void SetWorldPanning(bool on) { wrapped.SetWorldPanning(on); } - bool allowNoDecals() const { return wrapped.allowNoDecals(); } - void SetNoDecals(bool on) { wrapped.bNoDecals = on; } - void SetTranslucent(bool on) { wrapped.bTranslucent = on; } - ETextureType GetUseType() const { return wrapped.GetUseType(); } - void SetUseType(ETextureType type) { wrapped.SetUseType(type); } - int GetShaderIndex() const { return wrapped.shaderindex; } - float GetShaderSpeed() const { return wrapped.GetShaderSpeed(); } - uint16_t GetRotations() const { return wrapped.GetRotations(); } - void SetRotations(int index) { wrapped.SetRotations(index); } - void SetSkyOffset(int ofs) { wrapped.SetSkyOffset(ofs); } - int GetSkyOffset() const { return wrapped.GetSkyOffset(); } - FTextureID GetID() const { return wrapped.GetID(); } - ISoftwareTexture* GetSoftwareTexture() { return wrapped.GetSoftwareTexture(); } - void SetSoftwareTexture(ISoftwareTexture* swtex) { wrapped.SetSoftwareTextue(swtex); } - void SetScale(DVector2 vec) { wrapped.SetScale(vec); } - const FString& GetName() const { return wrapped.GetName(); } - void SetShaderSpeed(float speed) { wrapped.shaderspeed = speed; } - void SetShaderIndex(int index) { wrapped.shaderindex = index; } + double GetDisplayWidth() /*const*/ { return wrapped->GetDisplayWidthDouble(); } + double GetDisplayHeight() /*const*/ { return wrapped->GetDisplayHeightDouble(); } + int GetTexelWidth() /*const*/ { return wrapped->GetTexelWidth(); } + int GetTexelHeight() /*const*/ { return wrapped->GetTexelHeight(); } + int GetTexelLeftOffset(int adjusted = 0) /*const*/ { return wrapped->GetTexelLeftOffset(adjusted); } + int GetTexelTopOffset(int adjusted = 0) /*const*/ { return wrapped->GetTexelTopOffset(adjusted); } + double GetDisplayLeftOffset(int adjusted = 0) /*const*/ { return wrapped->GetDisplayLeftOffsetDouble(adjusted); } + double GetDisplayTopOffset(int adjusted = 0) /*const*/ { return wrapped->GetDisplayTopOffsetDouble(adjusted); } + + bool isValid() { return wrapped->isValid(); } + int isWarped() { return wrapped->isWarped(); } + void SetWarpStyle(int style) { wrapped->bWarped = style; } + bool isMasked() { return wrapped->isMasked(); } + bool isHardwareCanvas() const { return wrapped->isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. + bool isSoftwareCanvas() const { return wrapped->isCanvas(); } + bool isMiscPatch() const { return wrapped->GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. + bool isMultiPatch() const { return wrapped->bMultiPatch; } + bool isFullbrightDisabled() const { return wrapped->isFullbrightDisabled(); } + bool isFullbright() const { return wrapped->isFullbright(); } + bool isFullNameTexture() const { return wrapped->bFullNameTexture; } + bool expandSprites() const { return wrapped->bExpandSprite; } + bool useWorldPanning() const { return wrapped->UseWorldPanning(); } + void SetWorldPanning(bool on) { wrapped->SetWorldPanning(on); } + bool allowNoDecals() const { return wrapped->allowNoDecals(); } + void SetNoDecals(bool on) { wrapped->bNoDecals = on; } + void SetTranslucent(bool on) { wrapped->bTranslucent = on; } + ETextureType GetUseType() const { return wrapped->GetUseType(); } + void SetUseType(ETextureType type) { wrapped->SetUseType(type); } + int GetShaderIndex() const { return wrapped->shaderindex; } + float GetShaderSpeed() const { return wrapped->GetShaderSpeed(); } + uint16_t GetRotations() const { return wrapped->GetRotations(); } + void SetRotations(int index) { wrapped->SetRotations(index); } + void SetSkyOffset(int ofs) { wrapped->SetSkyOffset(ofs); } + int GetSkyOffset() const { return wrapped->GetSkyOffset(); } + FTextureID GetID() const { return wrapped->GetID(); } + ISoftwareTexture* GetSoftwareTexture() { return wrapped->GetSoftwareTexture(); } + void SetSoftwareTexture(ISoftwareTexture* swtex) { wrapped->SetSoftwareTextue(swtex); } + void SetScale(DVector2 vec) { wrapped->SetScale(vec); } + const FString& GetName() const { return wrapped->GetName(); } + void SetShaderSpeed(float speed) { wrapped->shaderspeed = speed; } + void SetShaderIndex(int index) { wrapped->shaderindex = index; } void SetShaderLayers(MaterialLayers& lay) { // Only update layers that have something defind. - if (lay.Glossiness > -1000) wrapped.Glossiness = lay.Glossiness; - if (lay.SpecularLevel > -1000) wrapped.SpecularLevel = lay.SpecularLevel; - if (lay.Brightmap) wrapped.Brightmap = lay.Brightmap->GetTexture(); - if (lay.Normal) wrapped.Normal = lay.Normal->GetTexture(); - if (lay.Specular) wrapped.Specular = lay.Specular->GetTexture(); - if (lay.Metallic) wrapped.Metallic = lay.Metallic->GetTexture(); - if (lay.Roughness) wrapped.Roughness = lay.Roughness->GetTexture(); - if (lay.AmbientOcclusion) wrapped.AmbientOcclusion = lay.AmbientOcclusion->GetTexture(); + if (lay.Glossiness > -1000) wrapped->Glossiness = lay.Glossiness; + if (lay.SpecularLevel > -1000) wrapped->SpecularLevel = lay.SpecularLevel; + if (lay.Brightmap) wrapped->Brightmap = lay.Brightmap->GetTexture(); + if (lay.Normal) wrapped->Normal = lay.Normal->GetTexture(); + if (lay.Specular) wrapped->Specular = lay.Specular->GetTexture(); + if (lay.Metallic) wrapped->Metallic = lay.Metallic->GetTexture(); + if (lay.Roughness) wrapped->Roughness = lay.Roughness->GetTexture(); + if (lay.AmbientOcclusion) wrapped->AmbientOcclusion = lay.AmbientOcclusion->GetTexture(); for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) { - if (lay.CustomShaderTextures[i]) wrapped.CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); + if (lay.CustomShaderTextures[i]) wrapped->CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); } } - float GetGlossiness() const { return wrapped.Glossiness; } - float GetSpecularLevel() const { return wrapped.SpecularLevel; } + float GetGlossiness() const { return wrapped->Glossiness; } + float GetSpecularLevel() const { return wrapped->SpecularLevel; } void CopySize(FGameTexture* BaseTexture) { - wrapped.CopySize(&BaseTexture->wrapped); + wrapped->CopySize(BaseTexture->wrapped); } // Glowing is a pure material property that should not filter down to the actual texture objects. - void GetGlowColor(float* data) { wrapped.GetGlowColor(data); } - bool isGlowing() const { return wrapped.isGlowing(); } - bool isAutoGlowing() const { return wrapped.isAutoGlowing(); } - int GetGlowHeight() const { return wrapped.GetGlowHeight(); } + void GetGlowColor(float* data) { wrapped->GetGlowColor(data); } + bool isGlowing() const { return wrapped->isGlowing(); } + bool isAutoGlowing() const { return wrapped->isAutoGlowing(); } + int GetGlowHeight() const { return wrapped->GetGlowHeight(); } void SetAutoGlowing() { auto tex = GetTexture(); tex->bAutoGlowing = tex->bGlowing = tex->bFullbright = true; } - void SetGlowHeight(int v) { wrapped.GlowHeight = v; } - void SetFullbright() { wrapped.bFullbright = true; } - void SetDisableFullbright(bool on) { wrapped.bDisableFullbright = on; } + void SetGlowHeight(int v) { wrapped->GlowHeight = v; } + void SetFullbright() { wrapped->bFullbright = true; } + void SetDisableFullbright(bool on) { wrapped->bDisableFullbright = on; } void SetGlowing(PalEntry color) { auto tex = GetTexture(); tex->bAutoGlowing = false; tex->bGlowing = true; tex->GlowColor = color; } bool isUserContent() const; - void AddAutoMaterials() { wrapped.AddAutoMaterials(); } - int CheckRealHeight() { return wrapped.CheckRealHeight(); } - bool isSkybox() const { return wrapped.isSkybox(); } - void SetSize(int x, int y) { wrapped.SetSize(x, y); } - void SetDisplaySize(float w, float h) { wrapped.SetSize((int)w, (int)h); } + void AddAutoMaterials() { wrapped->AddAutoMaterials(); } + int CheckRealHeight() { return wrapped->CheckRealHeight(); } + bool isSkybox() const { return wrapped->isSkybox(); } + void SetSize(int x, int y) { wrapped->SetSize(x, y); } + void SetDisplaySize(float w, float h) { wrapped->SetSize((int)w, (int)h); } - void SetSpriteRect() { wrapped.SetSpriteRect(); } - const SpritePositioningInfo& GetSpritePositioning(int which) { if (wrapped.spi == nullptr) wrapped.SetupSpriteData(); return wrapped.spi[which]; } - int GetAreas(FloatRect** pAreas) const { return wrapped.GetAreas(pAreas); } - PalEntry GetSkyCapColor(bool bottom) { return wrapped.GetSkyCapColor(bottom); } + void SetSpriteRect() { wrapped->SetSpriteRect(); } + const SpritePositioningInfo& GetSpritePositioning(int which) { if (wrapped->spi == nullptr) wrapped->SetupSpriteData(); return wrapped->spi[which]; } + int GetAreas(FloatRect** pAreas) const { return wrapped->GetAreas(pAreas); } + PalEntry GetSkyCapColor(bool bottom) { return wrapped->GetSkyCapColor(bottom); } bool GetTranslucency() { - return wrapped.GetTranslucency(); + return wrapped->GetTranslucency(); } // Since these properties will later piggyback on existing members of FGameTexture, the accessors need to be here. FGameTexture *GetSkyFace(int num) { - return (isSkybox() ? static_cast(&wrapped)->faces[num] : nullptr); + return (isSkybox() ? static_cast(wrapped)->faces[num] : nullptr); } - bool GetSkyFlip() { return isSkybox() ? static_cast(&wrapped)->fliptop : false; } + bool GetSkyFlip() { return isSkybox() ? static_cast(wrapped)->fliptop : false; } int GetClampMode(int clampmode) { if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; else if (isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - else if ((isWarped() || wrapped.shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + else if ((isWarped() || wrapped->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; return clampmode; } }; +inline FGameTexture* MakeGameTexture(FTexture* tex) +{ + if (!tex) return nullptr; + return new FGameTexture(tex); +} + #endif From 0b990f0dcb8f830a7fc1aecc45c950eb6c76bb64 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 21:36:14 +0200 Subject: [PATCH 036/220] - moved the decision whether to upscale textures up one level in the function chain. Still not the perfect place, this should be decided before creating the texture, not in the middle of the process. - disabled the selective texture cleaning in the precacher. The logic here turned out to be a serious blocker and needs to be rethought. --- src/common/textures/animtexture.cpp | 2 +- src/common/textures/hires/hqresize.cpp | 16 ------------ src/common/textures/texture.cpp | 25 ++++++++++++++++--- src/common/textures/texturemanager.cpp | 4 +-- src/common/textures/textures.h | 2 +- src/rendering/2d/f_wipe.cpp | 4 +-- .../hwrenderer/textures/hw_precache.cpp | 9 +++---- .../swrenderer/textures/r_swtexture.cpp | 2 +- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp index b09c5cd185..7ec249025a 100644 --- a/src/common/textures/animtexture.cpp +++ b/src/common/textures/animtexture.cpp @@ -50,7 +50,7 @@ void AnimTexture::SetFrame(const uint8_t *palette, const void *data_) { memcpy(Palette, palette, 768); memcpy(Image.Data(), data_, Width * Height); - CleanHardwareTextures(true, true); + CleanHardwareTextures(true); } //=========================================================================== diff --git a/src/common/textures/hires/hqresize.cpp b/src/common/textures/hires/hqresize.cpp index e04be8262b..9a4fd8b45f 100644 --- a/src/common/textures/hires/hqresize.cpp +++ b/src/common/textures/hires/hqresize.cpp @@ -425,22 +425,6 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA if (Scale.X >= 2 && Scale.Y >= 2) return; - switch (UseType) - { - case ETextureType::Sprite: - case ETextureType::SkinSprite: - if (!(gl_texture_hqresize_targets & 2)) return; - break; - - case ETextureType::FontChar: - if (!(gl_texture_hqresize_targets & 4)) return; - break; - - default: - if (!(gl_texture_hqresize_targets & 1)) return; - break; - } - int type = gl_texture_hqresizemode; int mult = gl_texture_hqresizemult; #ifdef HAVE_MMX diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 9e7ad3aae1..d51d060430 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -49,6 +49,8 @@ #include "texturemanager.h" #include "c_cvars.h" +EXTERN_CVAR(Int, gl_texture_hqresize_targets) + // Wrappers to keep the definitions of these classes out of here. void DeleteMaterial(FMaterial* mat); IHardwareTexture* CreateHardwareTexture(); @@ -686,10 +688,27 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags) result.mWidth = W; result.mHeight = H; + bool upscale = true; + switch (UseType) + { + case ETextureType::Sprite: + case ETextureType::SkinSprite: + if (!(gl_texture_hqresize_targets & 2)) upscale = false; + break; + + case ETextureType::FontChar: + if (!(gl_texture_hqresize_targets & 4)) upscale = false; + break; + + default: + if (!(gl_texture_hqresize_targets & 1)) upscale = false; + break; + } + // Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.) if (GetImage() && flags & CTF_ProcessData) { - CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly); + if (upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly); if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false); } @@ -717,9 +736,9 @@ bool FTexture::DetermineTranslucency() } -void FTexture::CleanHardwareTextures(bool cleannormal, bool cleanexpanded) +void FTexture::CleanHardwareTextures(bool reallyclean) { - SystemTextures.Clean(cleannormal, cleanexpanded); + SystemTextures.Clean(reallyclean, reallyclean); } //=========================================================================== diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index ca370dda6a..b29f00e324 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -103,7 +103,7 @@ void FTextureManager::DeleteAll() //========================================================================== // // Flushes all hardware dependent data. -// Thia must not, under any circumstances, delete the wipe textures, because +// This must not, under any circumstances, delete the wipe textures, because // all CCMDs triggering a flush can be executed while a wipe is in progress // // This now also deletes the software textures because having the software @@ -118,7 +118,7 @@ void FTextureManager::FlushAll() { for (int j = 0; j < 2; j++) { - Textures[i].Texture->GetTexture()->CleanHardwareTextures(true, true); + Textures[i].Texture->GetTexture()->CleanHardwareTextures(true); delete Textures[i].Texture->GetTexture()->SoftwareTexture; Textures[i].Texture->GetTexture()->SoftwareTexture = nullptr; } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 1b5bac4101..a826c06eb4 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -264,7 +264,7 @@ public: virtual FImageSource *GetImage() const { return nullptr; } void AddAutoMaterials(); void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); - void CleanHardwareTextures(bool cleannormal, bool cleanextended); + void CleanHardwareTextures(bool reallyclean); // These are mainly meant for 2D code which only needs logical information about the texture to position it properly. int GetDisplayWidth() { int foo = int((Width * 2) / Scale.X); return (foo >> 1) + (foo & 1); } diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index 80e425718f..4797ab82c1 100644 --- a/src/rendering/2d/f_wipe.cpp +++ b/src/rendering/2d/f_wipe.cpp @@ -373,8 +373,8 @@ bool Wiper_Burn::Run(int ticks) done = (Density < 0); } - BurnTexture->CleanHardwareTextures(true, true); - endScreen->GetTexture()->CleanHardwareTextures(false, false); + BurnTexture->CleanHardwareTextures(true); + endScreen->GetTexture()->CleanHardwareTextures(false); // this only cleans the descriptor sets for the Vulkan backend. Needs to be done better. const uint8_t *src = BurnArray; uint32_t *dest = (uint32_t *)BurnTexture->GetBuffer(); diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index fa695f925a..5c599c491e 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -227,13 +227,10 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl auto tex = TexMan.GameByIndex(i); if (tex != nullptr && tex->GetUseType() != ETextureType::FontChar) { - if (usedTextures.CheckKey(tex->GetTexture()) == nullptr) + // For now, only delete what's in neither list. The logic being used here does not really work that well for selective deletion. + if (usedTextures.CheckKey(tex->GetTexture()) == nullptr && usedSprites.CheckKey(tex->GetTexture()) == nullptr) { - tex->GetTexture()->CleanHardwareTextures(true, false); - } - if (usedSprites.CheckKey(tex->GetTexture()) == nullptr) - { - tex->GetTexture()->CleanHardwareTextures(false, true); + tex->GetTexture()->CleanHardwareTextures(true); } } } diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index 4f3a94bc9f..6b9fcd7f3e 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -57,7 +57,7 @@ FSoftwareTexture::FSoftwareTexture(FGameTexture *tex) // calculate the real size after running the scaler. auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| mBufferFlags); mPhysicalWidth = info.mWidth; - mPhysicalHeight = info.mHeight; + mPhysicalHeight = info.mHeight; mPhysicalScale = tex->GetTexelWidth() > 0 ? mPhysicalWidth / tex->GetTexelWidth() : mPhysicalWidth; Scale.X = (double)tex->GetTexelWidth() / tex->GetDisplayWidth(); Scale.Y = (double)tex->GetTexelHeight() / tex->GetDisplayHeight(); From 8505c7ee7da1fa5ac8452903f4b32f9797c9c32c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 16 Apr 2020 23:37:22 +0200 Subject: [PATCH 037/220] - major refactor of texture upscaling control. All decisions were done deep inside the texture creation code, leaving zero options to the higher level code for controlling the feature. Changed this so that the option to upscale must be passed as a parameter to FRenderState::SetMaterial and extended all needed variables to manage the added texture variants. Still not solved: Material layers need explicit control, not only for scaling but also for filtering. --- src/common/textures/hires/hqresize.cpp | 44 +++++++++++----- src/common/textures/hw_material.cpp | 16 +++--- src/common/textures/hw_material.h | 11 ++-- src/common/textures/hw_texcontainer.h | 51 ++++++++++--------- src/common/textures/texture.cpp | 27 ++-------- src/common/textures/textures.h | 16 ++---- src/rendering/gl/renderer/gl_renderer.cpp | 2 +- src/rendering/gl/renderer/gl_renderstate.cpp | 5 +- src/rendering/gl/system/gl_framebuffer.cpp | 4 +- src/rendering/hwrenderer/models/hw_models.cpp | 2 +- src/rendering/hwrenderer/scene/hw_decal.cpp | 3 +- src/rendering/hwrenderer/scene/hw_flats.cpp | 14 +++-- src/rendering/hwrenderer/scene/hw_portal.cpp | 3 +- .../hwrenderer/scene/hw_renderstate.h | 6 +-- .../hwrenderer/scene/hw_skyportal.cpp | 21 ++++---- src/rendering/hwrenderer/scene/hw_sprites.cpp | 4 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 3 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 3 +- .../hwrenderer/textures/hw_precache.cpp | 5 +- .../hwrenderer/utility/hw_draw2d.cpp | 2 +- .../polyrenderer/backend/poly_framebuffer.cpp | 6 +-- .../polyrenderer/backend/poly_hwtexture.cpp | 2 +- .../polyrenderer/backend/poly_renderstate.cpp | 2 +- src/rendering/swrenderer/r_swscene.cpp | 2 +- .../swrenderer/textures/r_swtexture.cpp | 6 ++- .../vulkan/system/vk_framebuffer.cpp | 8 +-- .../vulkan/textures/vk_hwtexture.cpp | 5 +- 27 files changed, 144 insertions(+), 129 deletions(-) diff --git a/src/common/textures/hires/hqresize.cpp b/src/common/textures/hires/hqresize.cpp index 9a4fd8b45f..67e20acfb0 100644 --- a/src/common/textures/hires/hqresize.cpp +++ b/src/common/textures/hires/hqresize.cpp @@ -409,22 +409,10 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA { // [BB] Make sure that inWidth and inHeight denote the size of // the returned buffer even if we don't upsample the input buffer. + int inWidth = texbuffer.mWidth; int inHeight = texbuffer.mHeight; - // [BB] Don't resample if width * height of the input texture is bigger than gl_texture_hqresize_maxinputsize squared. - const int maxInputSize = gl_texture_hqresize_maxinputsize; - if (inWidth * inHeight > maxInputSize * maxInputSize) - return; - - // [BB] Don't try to upsample textures based off FCanvasTexture. (This should never get here in the first place!) - if (bHasCanvas) - return; - - // already scaled? - if (Scale.X >= 2 && Scale.Y >= 2) - return; - int type = gl_texture_hqresizemode; int mult = gl_texture_hqresizemult; #ifdef HAVE_MMX @@ -493,3 +481,33 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA contentId.scalefactor = mult; texbuffer.mContentId = contentId.id; } + +bool shouldUpscale(FGameTexture *tex, ETextureType UseType) +{ + // [BB] Don't resample if width * height of the input texture is bigger than gl_texture_hqresize_maxinputsize squared. + const int maxInputSize = gl_texture_hqresize_maxinputsize; + if (tex->GetTexelWidth() * tex->GetTexelHeight() > maxInputSize * maxInputSize) + return false; + + // [BB] Don't try to upsample textures based off FCanvasTexture. (This should never get here in the first place!) + if (tex->isHardwareCanvas()) + return false; + + // already scaled? + if (tex->GetDisplayWidth() >= 2* tex->GetTexelWidth() || tex->GetDisplayHeight() >= 2*tex->GetTexelHeight()) + return false; + + switch (UseType) + { + case ETextureType::Sprite: + case ETextureType::SkinSprite: + return !!(gl_texture_hqresize_targets & 2); + + case ETextureType::FontChar: + return !!(gl_texture_hqresize_targets & 4); + + default: + return !!(gl_texture_hqresize_targets & 1); + } + +} \ No newline at end of file diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 2aa81199ff..638866a207 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -36,7 +36,7 @@ IHardwareTexture* CreateHardwareTexture(); // //=========================================================================== -FMaterial::FMaterial(FGameTexture * tx, bool expanded) +FMaterial::FMaterial(FGameTexture * tx, int scaleflags) { mShaderIndex = SHADER_Default; sourcetex = tx; @@ -122,10 +122,10 @@ FMaterial::FMaterial(FGameTexture * tx, bool expanded) } } } - mExpanded = expanded; + mScaleFlags = scaleflags; mTextureLayers.ShrinkToFit(); - imgtex->Material[expanded] = this; + imgtex->Material[scaleflags] = this; if (tx->isHardwareCanvas()) tx->SetTranslucent(false); } @@ -151,7 +151,7 @@ IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) FTexture *layer = i == 0 ? imgtex : mTextureLayers[i - 1]; if (pLayer) *pLayer = layer; - if (layer) return layer->GetHardwareTexture(translation, mExpanded); + if (layer) return layer->GetHardwareTexture(translation, mScaleFlags); return nullptr; } @@ -162,17 +162,17 @@ IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) // //========================================================================== -FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, bool expand, bool create) +FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool create) { if (gtex && gtex->isValid()) { auto tex = gtex->GetTexture(); - if (!tex->ShouldExpandSprite()) expand = false; + if (!tex->ShouldExpandSprite()) scaleflags &= ~CTF_Expand; - FMaterial *hwtex = tex->Material[expand]; + FMaterial *hwtex = tex->Material[scaleflags]; if (hwtex == NULL && create) { - hwtex = new FMaterial(gtex, expand); + hwtex = new FMaterial(gtex, scaleflags); } return hwtex; } diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index e1e27e3db8..bc9af78f0f 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -20,16 +20,17 @@ class FMaterial TArray mTextureLayers; int mShaderIndex; int mLayerFlags = 0; - bool mExpanded; + int mScaleFlags; public: FGameTexture *sourcetex; // the owning texture. FTexture* imgtex; // the first layer's texture image - should be moved into the array - FMaterial(FGameTexture *tex, bool forceexpand); + FMaterial(FGameTexture *tex, int scaleflags); ~FMaterial(); int GetLayerFlags() const { return mLayerFlags; } int GetShaderIndex() const { return mShaderIndex; } + int GetScaleFlags() const { return mScaleFlags; } FGameTexture* Source() const { @@ -45,10 +46,6 @@ public: //ValidateTexture(tex, false); mTextureLayers.Push(tex); } - bool isExpanded() const - { - return mExpanded; - } int GetLayers() const { @@ -58,7 +55,7 @@ public: 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, int scaleflags, bool create = true); const TArray &GetLayerArray() const { return mTextureLayers; diff --git a/src/common/textures/hw_texcontainer.h b/src/common/textures/hw_texcontainer.h index 247279fb06..f7020b5b79 100644 --- a/src/common/textures/hw_texcontainer.h +++ b/src/common/textures/hw_texcontainer.h @@ -7,6 +7,15 @@ struct FTextureBuffer; class IHardwareTexture; +enum ECreateTexBufferFlags +{ + CTF_Expand = 1, // create buffer with a one-pixel wide border + CTF_Upscale = 2, // Upscale the texture + CTF_CreateMask = 3, // Flags that are relevant for hardware texture creation. + CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture. + CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures. +}; + class FHardwareTextureContainer { public: @@ -40,20 +49,20 @@ private: private: - TranslatedTexture hwDefTex[2]; + TranslatedTexture hwDefTex[4]; TArray hwTex_Translated; - TranslatedTexture * GetTexID(int translation, bool expanded) + TranslatedTexture * GetTexID(int translation, int scaleflags) { auto remap = GPalette.TranslationToTable(translation); translation = remap == nullptr ? 0 : remap->Index; - if (translation == 0) + if (translation == 0 && !(scaleflags & CTF_Upscale)) { - return &hwDefTex[expanded]; + return &hwDefTex[scaleflags]; } - if (expanded) translation = -translation; + translation |= (scaleflags << 24); // normally there aren't more than very few different // translations here so this isn't performance critical. unsigned index = hwTex_Translated.FindEx([=](auto &element) @@ -73,31 +82,28 @@ private: public: - void Clean(bool cleannormal, bool cleanexpanded) + void Clean(bool reallyclean) { - if (cleannormal) hwDefTex[0].Delete(); - if (cleanexpanded) hwDefTex[1].Delete(); hwDefTex[0].DeleteDescriptors(); hwDefTex[1].DeleteDescriptors(); - for (int i = hwTex_Translated.Size() - 1; i >= 0; i--) - { - if (cleannormal && hwTex_Translated[i].translation > 0) hwTex_Translated.Delete(i); - else if (cleanexpanded && hwTex_Translated[i].translation < 0) hwTex_Translated.Delete(i); + for (unsigned int j = 0; j < hwTex_Translated.Size(); j++) + hwTex_Translated[j].DeleteDescriptors(); - for (unsigned int j = 0; j < hwTex_Translated.Size(); j++) - hwTex_Translated[j].DeleteDescriptors(); - } + if (!reallyclean) return; + hwDefTex[0].Delete(); + hwDefTex[1].Delete(); + hwTex_Translated.Clear(); } - IHardwareTexture * GetHardwareTexture(int translation, bool expanded) + IHardwareTexture * GetHardwareTexture(int translation, int scaleflags) { - auto tt = GetTexID(translation, expanded); + auto tt = GetTexID(translation, scaleflags); return tt->hwTexture; } - void AddHardwareTexture(int translation, bool expanded, IHardwareTexture *tex) + void AddHardwareTexture(int translation, int scaleflags, IHardwareTexture *tex) { - auto tt = GetTexID(translation, expanded); + auto tt = GetTexID(translation, scaleflags); tt->Delete(); tt->hwTexture =tex; } @@ -109,16 +115,15 @@ public: // //=========================================================================== - void CleanUnused(SpriteHits &usedtranslations, bool expanded) + void CleanUnused(SpriteHits &usedtranslations, int scaleflags) { if (usedtranslations.CheckKey(0) == nullptr) { - hwDefTex[expanded].Delete(); + hwDefTex[scaleflags].Delete(); } - int fac = expanded ? -1 : 1; for (int i = hwTex_Translated.Size()-1; i>= 0; i--) { - if (usedtranslations.CheckKey(hwTex_Translated[i].translation * fac) == nullptr) + if (usedtranslations.CheckKey(hwTex_Translated[i].translation & 0xffffff) == nullptr) { hwTex_Translated.Delete(i); } diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index d51d060430..26b0f14049 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -688,27 +688,10 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags) result.mWidth = W; result.mHeight = H; - bool upscale = true; - switch (UseType) - { - case ETextureType::Sprite: - case ETextureType::SkinSprite: - if (!(gl_texture_hqresize_targets & 2)) upscale = false; - break; - - case ETextureType::FontChar: - if (!(gl_texture_hqresize_targets & 4)) upscale = false; - break; - - default: - if (!(gl_texture_hqresize_targets & 1)) upscale = false; - break; - } - // Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.) if (GetImage() && flags & CTF_ProcessData) { - if (upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly); + if (flags & CTF_Upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly); if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false); } @@ -738,7 +721,7 @@ bool FTexture::DetermineTranslucency() void FTexture::CleanHardwareTextures(bool reallyclean) { - SystemTextures.Clean(reallyclean, reallyclean); + SystemTextures.Clean(reallyclean); } //=========================================================================== @@ -964,15 +947,15 @@ void FTexture::SetSpriteRect() // //=========================================================================== -IHardwareTexture* FTexture::GetHardwareTexture(int translation, bool expanded) +IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags) { if (UseType != ETextureType::Null) { - IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, expanded); + IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags); if (hwtex == nullptr) { hwtex = CreateHardwareTexture(); - SystemTextures.AddHardwareTexture(translation, expanded, hwtex); + SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex); } return hwtex; } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index a826c06eb4..65a5a7dce1 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -120,15 +120,6 @@ struct FloatRect } }; -enum ECreateTexBufferFlags -{ - CTF_Expand = 2, // create buffer with a one-pixel wide border - CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture. - CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures. -}; - - - class FBitmap; struct FRemapTable; struct FCopyInfo; @@ -258,7 +249,7 @@ public: SpritePositioningInfo *spi = nullptr; - IHardwareTexture* GetHardwareTexture(int translation, bool expanded); + IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType usetype); virtual ~FTexture (); virtual FImageSource *GetImage() const { return nullptr; } @@ -369,7 +360,7 @@ protected: int SourceLump; FTextureID id; - FMaterial *Material[2] = { nullptr, nullptr }; + FMaterial *Material[4] = { }; public: FHardwareTextureContainer SystemTextures; protected: @@ -534,7 +525,7 @@ public: FWrapperTexture(int w, int h, int bits = 1); IHardwareTexture *GetSystemTexture() { - return SystemTextures.GetHardwareTexture(0, false); + return SystemTextures.GetHardwareTexture(0, 0); } int GetColorFormat() const @@ -764,6 +755,7 @@ inline FGameTexture* MakeGameTexture(FTexture* tex) return new FGameTexture(tex); } +bool shouldUpscale(FGameTexture* tex, ETextureType UseType); #endif diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index ee5fbb09a4..23380de8b9 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -297,7 +297,7 @@ sector_t *FGLRenderer::RenderView(player_t* player) void FGLRenderer::BindToFrameBuffer(FTexture *tex) { - auto BaseLayer = static_cast(tex->GetHardwareTexture(0, false)); + auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); if (BaseLayer == nullptr) { diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index 73386ee106..1c60be381e 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -323,7 +323,7 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio int usebright = false; int maxbound = 0; - int flags = mat->isExpanded() ? CTF_Expand : 0; + int flags = mat->GetScaleFlags(); int numLayers = mat->GetLayers(); auto base = static_cast(mat->GetLayer(0, translation)); @@ -333,7 +333,8 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio { FTexture *layer; auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->BindOrCreate(layer, i, clampmode, 0, mat->isExpanded() ? CTF_Expand : 0); + // fixme: Upscale flags must be disabled for certain layers. + systex->BindOrCreate(layer, i, clampmode, 0, flags); maxbound = i; } } diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index c68ca64ca0..7ea0f3df6d 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -310,7 +310,7 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; - int flags = mat->isExpanded() ? CTF_Expand : 0; + int flags = mat->GetScaleFlags(); int numLayers = mat->GetLayers(); FTexture* layer; auto base = static_cast(mat->GetLayer(0, translation, &layer)); @@ -320,7 +320,7 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) for (int i = 1; i < numLayers; i++) { auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->BindOrCreate(layer, i, CLAMP_NONE, 0, mat->isExpanded() ? CTF_Expand : 0); + systex->BindOrCreate(layer, i, CLAMP_NONE, 0, flags); } } // unbind everything. diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 6c76126e51..2d180126e2 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -114,7 +114,7 @@ void FHWModelRenderer::SetInterpolation(double inter) void FHWModelRenderer::SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) { - state.SetMaterial(skin, false, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1); + state.SetMaterial(skin, 0, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1); state.SetLightIndex(modellightindex); } diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index e92a6c80ee..3416ddfff5 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -66,7 +66,8 @@ void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) state.SetTextureMode(decal->RenderStyle); state.SetRenderStyle(decal->RenderStyle); - state.SetMaterial(texture, false, CLAMP_XY, decal->Translation, -1); + int flags = shouldUpscale(texture, ETextureType::Sprite) ? CTF_Upscale : 0; + state.SetMaterial(texture, flags, CLAMP_XY, decal->Translation, -1); // If srcalpha is one it looks better with a higher alpha threshold diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index a4e8d1eee0..245e80a890 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -204,7 +204,8 @@ void HWFlat::DrawSubsectors(HWDrawInfo *di, FRenderState &state) void HWFlat::DrawOtherPlanes(HWDrawInfo *di, FRenderState &state) { - state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); + int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; + state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); // Draw the subsectors assigned to it due to missing textures auto pNode = (renderflags&SSRF_RENDERFLOOR) ? @@ -236,7 +237,8 @@ void HWFlat::DrawFloodPlanes(HWDrawInfo *di, FRenderState &state) // This requires a stencil because the projected plane interferes with // the depth buffer - state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); + int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; + state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); // Draw the subsectors assigned to it due to missing textures auto pNode = (renderflags&SSRF_RENDERFLOOR) ? @@ -322,16 +324,17 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) } else if (!translucent) { + int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; if (sector->special != GLSector_Skybox) { - state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); state.SetPlaneTextureRotation(&plane, texture); DrawSubsectors(di, state); state.EnableTextureMatrix(false); } else if (!hacktype) { - state.SetMaterial(texture, false, CLAMP_XY, 0, -1); + state.SetMaterial(texture, flags, CLAMP_XY, 0, -1); state.SetLightIndex(dynlightindex); state.Draw(DT_TriangleStrip,iboindex, 4); flatvertices += 4; @@ -352,7 +355,8 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) { if (!texture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); else state.AlphaFunc(Alpha_GEqual, 0.f); - state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); + int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; + state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); state.SetPlaneTextureRotation(&plane, texture); DrawSubsectors(di, state); state.EnableTextureMatrix(false); diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index f3915096f1..ad491217fb 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -975,7 +975,8 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state) } - state.SetMaterial(texture, false, CLAMP_NONE, 0, -1); + int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; + state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); state.SetObjectColor(origin->specialcolor); state.SetPlaneTextureRotation(sp, texture); diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index e0800172c7..47e08c03cf 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -569,10 +569,10 @@ public: mTextureModeFlags = mat->GetLayerFlags(); } - void SetMaterial(FGameTexture* tex, bool expandmode, int clampmode, int translation, int overrideshader) + void SetMaterial(FGameTexture* tex, int scaleflags, int clampmode, int translation, int overrideshader) { - expandmode &= tex->expandSprites(); - SetMaterial(FMaterial::ValidateTexture(tex, expandmode), clampmode, translation, overrideshader); + if (!tex->expandSprites()) scaleflags &= ~CTF_Expand; + SetMaterial(FMaterial::ValidateTexture(tex, scaleflags), clampmode, translation, overrideshader); } void SetClipSplit(float bottom, float top) diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index 5b13f73712..ef2af55659 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -52,9 +52,10 @@ void HWSkyPortal::RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode) { + int flags = shouldUpscale(tex, ETextureType::Wall) ? CTF_Upscale : 0; if (tex) { - state.SetMaterial(tex, false, CLAMP_NONE, 0, -1); + state.SetMaterial(tex, flags, CLAMP_NONE, 0, -1); state.EnableModelMatrix(true); state.EnableTextureMatrix(true); @@ -106,39 +107,41 @@ void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texn else state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector2.X, di->Level->info->skyrotatevector2.Z, di->Level->info->skyrotatevector2.Y); - if (tex->GetSkyFace(5)) + // Only test the first face - the result here must be consistent - either all get scaled or none. + int flags = shouldUpscale(tex->GetSkyFace(0), ETextureType::Flat) ? CTF_Upscale : 0; + if (tex->GetSkyFace(5)) { faces=4; // north - state.SetMaterial(tex->GetSkyFace(0), false, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(0), flags, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(0), 4); // east - state.SetMaterial(tex->GetSkyFace(1), false, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(1), flags, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(1), 4); // south - state.SetMaterial(tex->GetSkyFace(2), false, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(2), flags, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(2), 4); // west - state.SetMaterial(tex->GetSkyFace(3), false, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(3), flags, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(3), 4); } else { faces=1; - state.SetMaterial(tex->GetSkyFace(0), false, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(0), flags, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(-1), 10); } // top - state.SetMaterial(tex->GetSkyFace(faces), false, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(faces), flags, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(tex->GetSkyFlip() ? 6 : 5), 4); // bottom - state.SetMaterial(tex->GetSkyFace(faces+1), false, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(faces+1), flags, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(4), 4); state.EnableModelMatrix(false); diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 392d1caadc..dbe44637ae 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -198,7 +198,9 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) } uint32_t spritetype = (actor->renderflags & RF_SPRITETYPEMASK); - if (texture) state.SetMaterial(texture, spritetype == RF_FACESPRITE, CLAMP_XY, translation, OverrideShader); + int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; + if (spritetype == RF_FACESPRITE) flags |= CTF_Expand; + if (texture) state.SetMaterial(texture, flags, CLAMP_XY, translation, OverrideShader); else if (!modelframe) state.EnableTexture(false); //SetColor(lightlevel, rel, Colormap, trans); diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 73c19f8041..2d1235ae1f 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -156,7 +156,8 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) state.SetGlowParams(topglowcolor, bottomglowcolor); state.SetGlowPlanes(frontsector->ceilingplane, frontsector->floorplane); } - state.SetMaterial(texture, false, flags & 3, 0, -1); + int uflags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; + state.SetMaterial(texture, uflags, flags & 3, 0, -1); if (type == RENDERWALL_M2SNF) { diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index f07c667f30..6d6aaee844 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -96,7 +96,8 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) { float thresh = (huds->texture->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; state.AlphaFunc(Alpha_GEqual, thresh); - state.SetMaterial(huds->texture, true, CLAMP_XY_NOMIP, (huds->weapon->Flags & PSPF_PLAYERTRANSLATED) ? huds->owner->Translation : 0, huds->OverrideShader); + int flags = shouldUpscale(huds->texture, ETextureType::Flat) ? CTF_Upscale|CTF_Expand : CTF_Expand; + state.SetMaterial(huds->texture, flags, CLAMP_XY_NOMIP, (huds->weapon->Flags & PSPF_PLAYERTRANSLATED) ? huds->owner->Translation : 0, huds->OverrideShader); state.Draw(DT_TriangleStrip, huds->mx, 4); } diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 5c599c491e..7ce5052ca2 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -62,7 +62,7 @@ static void PrecacheTexture(FGameTexture *tex, int cache) //=========================================================================== static void PrecacheList(FMaterial *gltex, SpriteHits& translations) { - gltex->BaseLayer()->SystemTextures.CleanUnused(translations, gltex->isExpanded()); + gltex->BaseLayer()->SystemTextures.CleanUnused(translations, gltex->GetScaleFlags()); SpriteHits::Iterator it(translations); SpriteHits::Pair* pair; while (it.NextPair(pair)) screen->PrecacheMaterial(gltex, pair->Key); @@ -252,7 +252,8 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl { if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { - if (tex->GetImage() && tex->SystemTextures.GetHardwareTexture(0, false) == nullptr) + int flags = shouldUpscale(gtex, ETextureType::Wall) ? CTF_Upscale : 0; + if (tex->GetImage() && tex->SystemTextures.GetHardwareTexture(0, flags) == nullptr) { FImageSource::RegisterForPrecache(tex->GetImage(), V_IsTrueColor()); } diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index 9ea18891e0..efff2852e6 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -164,7 +164,7 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) if (cmd.mTexture != nullptr && cmd.mTexture->isValid()) { - state.SetMaterial(cmd.mTexture, false, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); + state.SetMaterial(cmd.mTexture, 0, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); state.EnableTexture(true); // Canvas textures are stored upside down diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index e8b1c5c87f..63eea8f2c7 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -377,7 +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. - auto BaseLayer = static_cast(tex->GetHardwareTexture(0, false)); + auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); DCanvas *image = BaseLayer->GetImage(tex, 0, 0); @@ -535,7 +535,7 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; - int flags = mat->isExpanded() ? CTF_Expand : 0; + int flags = mat->GetScaleFlags(); FTexture* layer; auto systex = static_cast(mat->GetLayer(0, translation, &layer)); systex->GetImage(layer, translation, flags); @@ -544,7 +544,7 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) for (int i = 1; i < numLayers; i++) { auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0); + systex->GetImage(layer, 0, flags); // fixme: Upscale flags must be disabled for certain layers. } } diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index 51a7886604..55a47fca97 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -68,7 +68,7 @@ DCanvas *PolyHardwareTexture::GetImage(FTexture *baselayer, const FMaterialState if (!mCanvas) { - int flags = state.mMaterial->isExpanded() ? CTF_Expand : 0; + int flags = state.mMaterial->GetScaleFlags(); return GetImage(baselayer, state.mTranslation, flags); } diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 41e2aeb4e1..9119ce96d2 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -327,7 +327,7 @@ void PolyRenderState::ApplyMaterial() FTexture* layer; auto systex = static_cast(mMaterial.mMaterial->GetLayer(i, 0, &layer)); - texcanvas = systex->GetImage(layer, 0, mMaterial.mMaterial->isExpanded() ? CTF_Expand : 0); + texcanvas = systex->GetImage(layer, 0, mMaterial.mMaterial->GetScaleFlags()); mDrawCommands->SetTexture(i, texcanvas->GetPixels(), texcanvas->GetWidth(), texcanvas->GetHeight(), texcanvas->IsBgra()); } } diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index ac5c382a9f..2886d4575d 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -94,7 +94,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) FBTextureIndex = (FBTextureIndex + 1) % 2; auto &fbtex = FBTexture[FBTextureIndex]; - auto GetSystemTexture = [&]() { return fbtex->GetTexture()->SystemTextures.GetHardwareTexture(0, false); }; + auto GetSystemTexture = [&]() { return fbtex->GetTexture()->SystemTextures.GetHardwareTexture(0, 0); }; if (fbtex == nullptr || GetSystemTexture() == nullptr || fbtex->GetTexelWidth() != screen->GetWidth() || diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index 6b9fcd7f3e..ace25007ee 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -54,8 +54,10 @@ FSoftwareTexture::FSoftwareTexture(FGameTexture *tex) mSource = tex->GetTexture(); mBufferFlags = CTF_ProcessData; + auto f = mBufferFlags; + if (shouldUpscale(tex, tex->GetUseType())) f |= CTF_Upscale; // calculate the real size after running the scaler. - auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| mBufferFlags); + auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| f); mPhysicalWidth = info.mWidth; mPhysicalHeight = info.mHeight; mPhysicalScale = tex->GetTexelWidth() > 0 ? mPhysicalWidth / tex->GetTexelWidth() : mPhysicalWidth; @@ -113,6 +115,8 @@ const uint8_t *FSoftwareTexture::GetPixels(int style) } else { + auto f = mBufferFlags; + if (shouldUpscale(mTexture, mTexture->GetUseType())) f |= CTF_Upscale; auto tempbuffer = mSource->CreateTexBuffer(0, mBufferFlags); Pixels.Resize(GetPhysicalWidth()*GetPhysicalHeight()); PalEntry *pe = (PalEntry*)tempbuffer.mBuffer; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index dd4ef1d79c..460a180dbb 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -515,7 +515,7 @@ sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) { - auto BaseLayer = static_cast(tex->GetHardwareTexture(0, false)); + auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0); @@ -648,17 +648,17 @@ void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; // Textures that are already scaled in the texture lump will not get replaced by hires textures. - int flags = mat->isExpanded() ? CTF_Expand : 0; + int flags = mat->GetScaleFlags(); FTexture* layer; auto systex = static_cast(mat->GetLayer(0, translation, &layer)); - systex->GetImage(layer, translation, mat->isExpanded() ? CTF_Expand : 0); + systex->GetImage(layer, translation, flags); int numLayers = mat->GetLayers(); for (int i = 1; i < numLayers; i++) { auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0); + systex->GetImage(layer, 0, flags); // fixme: Upscale flags must be disabled for certain layers. } } diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index 1868331fa2..e3c81054cc 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -119,7 +119,7 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s clampmode = base->GetClampMode(clampmode); // Textures that are already scaled in the texture lump will not get replaced by hires textures. - int flags = state.mMaterial->isExpanded() ? CTF_Expand : 0; + int flags = mat->GetScaleFlags(); for (auto &set : mDescriptorSets) { @@ -141,7 +141,8 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s { FTexture *layer; auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer, 0, mat->isExpanded() ? CTF_Expand : 0)->View.get(), sampler, systex->mImage.Layout); + // fixme: Upscale flags must be disabled for certain layers. + update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer, 0, flags)->View.get(), sampler, systex->mImage.Layout); } auto dummyImage = fb->GetRenderPassManager()->GetNullTextureView(); From 09898ef6c3eacbf5d8bf740695becc68b8efe78e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 00:22:34 +0200 Subject: [PATCH 038/220] - cache the upscaling check's result in the texture, as this will be queried quite frequently. --- src/common/textures/hires/hqresize.cpp | 12 +++++++++++- src/common/textures/textures.h | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/common/textures/hires/hqresize.cpp b/src/common/textures/hires/hqresize.cpp index 67e20acfb0..c72ac2be4c 100644 --- a/src/common/textures/hires/hqresize.cpp +++ b/src/common/textures/hires/hqresize.cpp @@ -405,6 +405,7 @@ static void xbrzOldScale(size_t factor, const uint32_t* src, uint32_t* trg, int // the upsampled buffer. // //=========================================================================== + void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly) { // [BB] Make sure that inWidth and inHeight denote the size of @@ -482,8 +483,17 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA texbuffer.mContentId = contentId.id; } -bool shouldUpscale(FGameTexture *tex, ETextureType UseType) +//=========================================================================== +// +// This was pulled out of the above function to allow running these +// checks before the texture is passed to the render state. +// +//=========================================================================== + +bool calcShouldUpscale(FGameTexture *tex, ETextureType UseType) { + if (gl_texture_hqresizemode == 0 || gl_texture_hqresizemult == 1) return false; + // [BB] Don't resample if width * height of the input texture is bigger than gl_texture_hqresize_maxinputsize squared. const int maxInputSize = gl_texture_hqresize_maxinputsize; if (tex->GetTexelWidth() * tex->GetTexelHeight() > maxInputSize * maxInputSize) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 65a5a7dce1..391fb96044 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -632,10 +632,14 @@ public: class FGameTexture { FTexture *wrapped; + int8_t shouldUpscaleFlag = -1; public: FGameTexture(FTexture* wrap) : wrapped(wrap) {} ~FGameTexture(); + void SetUpscaleFlag(int what) { shouldUpscaleFlag = what; } + int GetUpscaleFlag() { return shouldUpscaleFlag; } + FTexture* GetTexture() { return wrapped; } int GetSourceLump() const { return wrapped->GetSourceLump(); } void SetBrightmap(FGameTexture* tex) { wrapped->Brightmap = tex->GetTexture(); } @@ -755,7 +759,16 @@ inline FGameTexture* MakeGameTexture(FTexture* tex) return new FGameTexture(tex); } -bool shouldUpscale(FGameTexture* tex, ETextureType UseType); +bool calcShouldUpscale(FGameTexture* tex, ETextureType UseType); +inline bool shouldUpscale(FGameTexture* tex, ETextureType UseType) +{ + auto f = tex->GetUpscaleFlag(); + // Cache this value in the texture to save time because it is very frequently polled. + if (f != -1) return f; + auto res = calcShouldUpscale(tex, UseType); + tex->SetUpscaleFlag(res); + return res; +} #endif From 70ec20c137ce3db5c630f2efac757f2db489538c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 00:37:05 +0200 Subject: [PATCH 039/220] - optimization of texture scaling checks. The texture dimension checks can be performed up front when the texture is inserted into the texture manager. --- src/common/fonts/font.cpp | 13 ++--- src/common/fonts/hexfont.cpp | 6 +-- src/common/fonts/singlelumpfont.cpp | 9 ++-- src/common/fonts/specialfont.cpp | 6 +-- .../textures/formats/multipatchtexture.h | 6 ++- src/common/textures/formats/pngtexture.cpp | 2 +- src/common/textures/formats/shadertexture.cpp | 5 +- src/common/textures/hires/hqresize.cpp | 36 ++++++------- src/common/textures/hw_material.cpp | 2 +- .../textures/multipatchtexturebuilder.cpp | 20 +++---- src/common/textures/skyboxtexture.cpp | 1 - src/common/textures/texture.cpp | 35 ++++++------ src/common/textures/textureid.h | 1 + src/common/textures/texturemanager.cpp | 38 ++++++------- src/common/textures/textures.h | 53 ++++++++++--------- src/d_main.cpp | 7 +-- src/gamedata/textures/animations.cpp | 3 +- src/gamedata/textures/buildloader.cpp | 3 +- src/r_data/gldefs.cpp | 4 +- src/r_data/models/models_voxel.cpp | 2 +- src/rendering/hwrenderer/models/hw_models.cpp | 2 +- src/rendering/hwrenderer/scene/hw_decal.cpp | 3 +- src/rendering/hwrenderer/scene/hw_flats.cpp | 14 ++--- src/rendering/hwrenderer/scene/hw_portal.cpp | 3 +- .../hwrenderer/scene/hw_renderstate.h | 3 +- .../hwrenderer/scene/hw_skyportal.cpp | 19 +++---- src/rendering/hwrenderer/scene/hw_sprites.cpp | 4 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 5 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 3 +- .../hwrenderer/textures/hw_precache.cpp | 2 +- .../hwrenderer/utility/hw_draw2d.cpp | 3 +- src/rendering/swrenderer/r_swscene.cpp | 4 +- .../swrenderer/textures/r_swtexture.cpp | 19 ++++++- 33 files changed, 167 insertions(+), 169 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 5fb4641be1..e9ad0fb4c4 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -327,17 +327,15 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla } auto orig = pic->GetTexture(); - auto tex = MakeGameTexture(new FImageTexture(orig->GetImage(), "")); // todo - can reuse orig directly later. - tex->SetUseType(ETextureType::FontChar); + auto tex = MakeGameTexture(orig, ETextureType::FontChar); tex->CopySize(pic); TexMan.AddGameTexture(tex); Chars[i].OriginalPic = tex; if (!noTranslate) { - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(orig->GetImage()), "")); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(orig->GetImage()), ""), ETextureType::FontChar); Chars[i].TranslatedPic->CopySize(pic); - Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); TexMan.AddGameTexture(Chars[i].TranslatedPic); } else @@ -413,7 +411,6 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height part[0].Image = tex->GetTexture()->GetImage(); FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false); FImageTexture *tex = new FImageTexture(image, ""); - tex->SetUseType(ETextureType::FontChar); tex->bMultiPatch = true; tex->_LeftOffset[0] = tex->_LeftOffset[1] = @@ -425,7 +422,7 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height tex->bWorldPanning = true; tex->bNoDecals = false; tex->SourceLump = -1; // We do not really care. - auto gtex = MakeGameTexture(tex); + auto gtex = MakeGameTexture(tex, ETextureType::FontChar); TexMan.AddGameTexture(gtex); charMap.Insert(int(position) + x + y * numtex_x, gtex); } @@ -456,10 +453,10 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height auto b = pic->Get8BitPixels(false); - Chars[i].OriginalPic = MakeGameTexture(new FImageTexture(pic->GetImage(), "")); + Chars[i].OriginalPic = MakeGameTexture(pic, ETextureType::FontChar); Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); Chars[i].OriginalPic->CopySize(*lump); - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage()), "")); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage()), ""), ETextureType::FontChar); Chars[i].TranslatedPic->CopySize(*lump); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); TexMan.AddGameTexture(Chars[i].OriginalPic); diff --git a/src/common/fonts/hexfont.cpp b/src/common/fonts/hexfont.cpp index b1ac21e8a6..4b3fd39cd8 100644 --- a/src/common/fonts/hexfont.cpp +++ b/src/common/fonts/hexfont.cpp @@ -289,8 +289,7 @@ public: { auto offset = hexdata.glyphmap[i]; int size = hexdata.glyphdata[offset] / 16; - Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar (&hexdata.glyphdata[offset+1], size, size * 9, 16))); - Chars[i - FirstChar].TranslatedPic->SetUseType(ETextureType::FontChar); + Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar (&hexdata.glyphdata[offset+1], size, size * 9, 16)), ETextureType::FontChar); Chars[i - FirstChar].XMove = size * spacing; TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); } @@ -362,8 +361,7 @@ public: { auto offset = hexdata.glyphmap[i]; int size = hexdata.glyphdata[offset] / 16; - Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18))); - Chars[i - FirstChar].TranslatedPic->SetUseType(ETextureType::FontChar); + Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), ETextureType::FontChar); Chars[i - FirstChar].XMove = size * spacing; TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); } diff --git a/src/common/fonts/singlelumpfont.cpp b/src/common/fonts/singlelumpfont.cpp index 3d71f6fb78..ad81f3d0fd 100644 --- a/src/common/fonts/singlelumpfont.cpp +++ b/src/common/fonts/singlelumpfont.cpp @@ -353,8 +353,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data) } else { - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight))); - Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), ETextureType::FontChar); TexMan.AddGameTexture(Chars[i].TranslatedPic); do { @@ -488,8 +487,7 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data) chardata[chari+2], // height -(int8_t)chardata[chari+3], // x offset -(int8_t)chardata[chari+4] // y offset - ))); - tex->SetUseType(ETextureType::FontChar); + )), ETextureType::FontChar); Chars[chardata[chari] - FirstChar].TranslatedPic = tex; TexMan.AddGameTexture(tex); } @@ -556,8 +554,7 @@ void FSingleLumpFont::CheckFON1Chars (double *luminosity) if(!Chars[i].TranslatedPic) { - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight))); - Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight)), ETextureType::FontChar); Chars[i].XMove = SpaceWidth; TexMan.AddGameTexture(Chars[i].TranslatedPic); } diff --git a/src/common/fonts/specialfont.cpp b/src/common/fonts/specialfont.cpp index f7389f8345..9c6c33a810 100644 --- a/src/common/fonts/specialfont.cpp +++ b/src/common/fonts/specialfont.cpp @@ -104,16 +104,14 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture if (charlumps[i] != nullptr) { auto pic = charlumps[i]; - Chars[i].OriginalPic = MakeGameTexture(new FImageTexture(pic->GetTexture()->GetImage(), "")); - Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); + Chars[i].OriginalPic = MakeGameTexture(pic->GetTexture(), ETextureType::FontChar); Chars[i].OriginalPic->CopySize(pic); TexMan.AddGameTexture(Chars[i].OriginalPic); if (!noTranslate) { - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1 (charlumps[i]->GetTexture()->GetImage()), "")); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1 (charlumps[i]->GetTexture()->GetImage()), ""), ETextureType::FontChar); Chars[i].TranslatedPic->CopySize(charlumps[i]); - Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); TexMan.AddGameTexture(Chars[i].TranslatedPic); } else Chars[i].TranslatedPic = Chars[i].OriginalPic; diff --git a/src/common/textures/formats/multipatchtexture.h b/src/common/textures/formats/multipatchtexture.h index 2f1421a8a1..657576c7c3 100644 --- a/src/common/textures/formats/multipatchtexture.h +++ b/src/common/textures/formats/multipatchtexture.h @@ -109,7 +109,8 @@ struct BuildInfo bool bNoDecals = false; int LeftOffset[2] = {}; int TopOffset[2] = {}; - FImageTexture *tex = nullptr; + FImageTexture* itex = nullptr; + FGameTexture *texture = nullptr; void swap(BuildInfo &other) { @@ -128,7 +129,8 @@ struct BuildInfo std::swap(LeftOffset[1], other.LeftOffset[1]); std::swap(TopOffset[0], other.TopOffset[0]); std::swap(TopOffset[1], other.TopOffset[1]); - std::swap(tex, other.tex); + std::swap(itex, other.itex); + std::swap(texture, other.texture); } }; diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index 75e578b684..a808dd13bb 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -609,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 MakeGameTexture(new FPNGFileTexture (png->File, width, height, colortype)); + else return MakeGameTexture(new FPNGFileTexture (png->File, width, height, colortype), ETextureType::Override); } //========================================================================== diff --git a/src/common/textures/formats/shadertexture.cpp b/src/common/textures/formats/shadertexture.cpp index d07f307065..21fd893560 100644 --- a/src/common/textures/formats/shadertexture.cpp +++ b/src/common/textures/formats/shadertexture.cpp @@ -38,6 +38,7 @@ #include "bitmap.h" #include "imagehelpers.h" #include "image.h" +#include "textures.h" class FBarShader : public FImageSource @@ -128,9 +129,9 @@ private: }; -FTexture *CreateShaderTexture(bool vertical, bool reverse) +FGameTexture *CreateShaderTexture(bool vertical, bool reverse) { FStringf name("BarShader%c%c", vertical ? 'v' : 'h', reverse ? 'r' : 'f'); - return CreateImageTexture(new FBarShader(vertical, reverse), name.GetChars()); + return MakeGameTexture(CreateImageTexture(new FBarShader(vertical, reverse), name.GetChars()), ETextureType::Override); } diff --git a/src/common/textures/hires/hqresize.cpp b/src/common/textures/hires/hqresize.cpp index c72ac2be4c..2e7b2fb068 100644 --- a/src/common/textures/hires/hqresize.cpp +++ b/src/common/textures/hires/hqresize.cpp @@ -46,6 +46,8 @@ #include "texturemanager.h" #include "printf.h" +int upscalemask; + EXTERN_CVAR(Int, gl_texture_hqresizemult) CUSTOM_CVAR(Int, gl_texture_hqresizemode, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { @@ -54,6 +56,7 @@ CUSTOM_CVAR(Int, gl_texture_hqresizemode, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | if ((gl_texture_hqresizemult > 4) && (self < 4) && (self > 0)) gl_texture_hqresizemult = 4; TexMan.FlushAll(); + UpdateUpscaleMask(); } CUSTOM_CVAR(Int, gl_texture_hqresizemult, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) @@ -63,6 +66,7 @@ CUSTOM_CVAR(Int, gl_texture_hqresizemult, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | if ((self > 4) && (gl_texture_hqresizemode < 4) && (gl_texture_hqresizemode > 0)) self = 4; TexMan.FlushAll(); + UpdateUpscaleMask(); } CUSTOM_CVAR(Int, gl_texture_hqresize_maxinputsize, 512, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) @@ -74,6 +78,7 @@ CUSTOM_CVAR(Int, gl_texture_hqresize_maxinputsize, 512, CVAR_ARCHIVE | CVAR_GLOB CUSTOM_CVAR(Int, gl_texture_hqresize_targets, 7, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { TexMan.FlushAll(); + UpdateUpscaleMask(); } CVAR (Flag, gl_texture_hqresize_textures, gl_texture_hqresize_targets, 1); @@ -96,6 +101,13 @@ CUSTOM_CVAR(Int, gl_texture_hqresize_mt_height, 4, CVAR_ARCHIVE | CVAR_GLOBALCON CVAR(Int, xbrz_colorformat, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +void UpdateUpscaleMask() +{ + if (!gl_texture_hqresizemode || gl_texture_hqresizemult == 1) upscalemask = 0; + else upscalemask = gl_texture_hqresize_targets; +} + + static void xbrzApplyOptions() { if (gl_texture_hqresizemult != 0 && (gl_texture_hqresizemode == 4 || gl_texture_hqresizemode == 5)) @@ -490,34 +502,20 @@ void FTexture::CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasA // //=========================================================================== -bool calcShouldUpscale(FGameTexture *tex, ETextureType UseType) +int calcShouldUpscale(FGameTexture *tex) { - if (gl_texture_hqresizemode == 0 || gl_texture_hqresizemult == 1) return false; - // [BB] Don't resample if width * height of the input texture is bigger than gl_texture_hqresize_maxinputsize squared. const int maxInputSize = gl_texture_hqresize_maxinputsize; if (tex->GetTexelWidth() * tex->GetTexelHeight() > maxInputSize * maxInputSize) - return false; + return 0; // [BB] Don't try to upsample textures based off FCanvasTexture. (This should never get here in the first place!) if (tex->isHardwareCanvas()) - return false; + return 0; // already scaled? if (tex->GetDisplayWidth() >= 2* tex->GetTexelWidth() || tex->GetDisplayHeight() >= 2*tex->GetTexelHeight()) - return false; - - switch (UseType) - { - case ETextureType::Sprite: - case ETextureType::SkinSprite: - return !!(gl_texture_hqresize_targets & 2); - - case ETextureType::FontChar: - return !!(gl_texture_hqresize_targets & 4); - - default: - return !!(gl_texture_hqresize_targets & 1); - } + return 0; + return CTF_Upscale; } \ No newline at end of file diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 638866a207..14f031ee19 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -78,7 +78,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) } // Note that these layers must present a valid texture even if not used, because empty TMUs in the shader are an undefined condition. - imgtex->CreateDefaultBrightmap(); + tx->CreateDefaultBrightmap(); auto placeholder = TexMan.GameByIndex(1); if (imgtex->Brightmap) { diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index dcaefcec2a..b62a30916c 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -138,7 +138,6 @@ struct FPatchLookup void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType usetype) { FImageTexture *tex = new FImageTexture(nullptr, buildinfo.Name); - tex->SetUseType(usetype); tex->bMultiPatch = true; tex->SetSize(buildinfo.Width, buildinfo.Height); tex->_LeftOffset[0] = buildinfo.LeftOffset[0]; @@ -151,8 +150,9 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u tex->bWorldPanning = buildinfo.bWorldPanning; tex->bNoDecals = buildinfo.bNoDecals; tex->SourceLump = buildinfo.DefinitionLump; - buildinfo.tex = tex; - TexMan.AddGameTexture(MakeGameTexture(tex)); + buildinfo.itex = tex; + buildinfo.texture = MakeGameTexture(tex, usetype); + TexMan.AddGameTexture(buildinfo.texture); } //========================================================================== @@ -773,19 +773,19 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) for (unsigned i = 0; i < buildinfo.Inits.Size(); i++) { FTextureID texno = TexMan.CheckForTexture(buildinfo.Inits[i].TexName, buildinfo.Inits[i].UseType); - if (texno == buildinfo.tex->id) // we found ourselves. Try looking for another one with the same name which is not a multipatch texture itself. + if (texno == buildinfo.texture->GetID()) // we found ourselves. Try looking for another one with the same name which is not a multipatch texture itself. { TArray list; TexMan.ListTextures(buildinfo.Inits[i].TexName, list, true); for (int i = list.Size() - 1; i >= 0; i--) { - if (list[i] != buildinfo.tex->id && !TexMan.GetGameTexture(list[i])->isMultiPatch() ) + if (list[i] != buildinfo.texture->GetID() && !TexMan.GetGameTexture(list[i])->isMultiPatch() ) { texno = list[i]; break; } } - if (texno == buildinfo.tex->id) + if (texno == buildinfo.texture->GetID()) { if (buildinfo.Inits[i].HasLine) buildinfo.Inits[i].sc.Message(MSG_WARNING, "Texture '%s' references itself as patch\n", buildinfo.Inits[i].TexName.GetChars()); else Printf(TEXTCOLOR_YELLOW "Texture '%s' references itself as patch\n", buildinfo.Inits[i].TexName.GetChars()); @@ -814,7 +814,7 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) { //We cannot set the image source yet. First all textures need to be resolved. buildinfo.Inits[i].Texture = tex->GetTexture(); - buildinfo.tex->bComplex |= tex->GetTexture()->bComplex; // this one's NOT a material property! It must remain on the texture image. + buildinfo.itex->bComplex |= tex->GetTexture()->bComplex; // this one's NOT a material property! It must remain on the texture image. buildinfo.bComplex |= tex->GetTexture()->bComplex; if (buildinfo.Inits[i].UseOffsets) { @@ -898,14 +898,14 @@ void FMultipatchTextureBuilder::ResolveAllPatches() buildinfo.Parts[0].Rotate == 0 && !buildinfo.bComplex) { - buildinfo.tex->SetImage(buildinfo.Parts[0].Image); + buildinfo.itex->SetImage(buildinfo.Parts[0].Image); done = true; } } if (!done) { auto img = new FMultiPatchTexture(buildinfo.Width, buildinfo.Height, buildinfo.Parts, buildinfo.bComplex, buildinfo.textual); - buildinfo.tex->SetImage(img); + buildinfo.itex->SetImage(img); } BuiltTextures.Delete(i); @@ -918,7 +918,7 @@ void FMultipatchTextureBuilder::ResolveAllPatches() for (auto &b : BuiltTextures) { Printf("%s\n", b.Name.GetChars()); - b.tex->SetUseType(ETextureType::Null); + b.texture->SetUseType(ETextureType::Null); } break; } diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index 48520cafde..0c2820be27 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -44,7 +44,6 @@ FSkyBox::FSkyBox(const char *name) } else previous = nullptr; faces[0]=faces[1]=faces[2]=faces[3]=faces[4]=faces[5] = nullptr; - UseType = ETextureType::Override; bSkybox = true; fliptop = false; } diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 26b0f14049..01ad66c31d 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -80,7 +80,7 @@ FTexture * FTexture::CreateTexture(const char *name, int lumpnum, ETextureType u FTexture *tex = new FImageTexture(image); if (tex != nullptr) { - tex->UseType = usetype; + //tex->UseType = usetype; if (usetype == ETextureType::Flat) { int w = tex->GetTexelWidth(); @@ -117,7 +117,7 @@ FTexture * FTexture::CreateTexture(const char *name, int lumpnum, ETextureType u FTexture::FTexture (const char *name, int lumpnum) : Scale(1,1), SourceLump(lumpnum), - UseType(ETextureType::Any), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), + bNoDecals(false), bNoRemap0(false), bWorldPanning(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bFullNameTexture(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { @@ -343,17 +343,18 @@ void FTexture::AddAutoMaterials() // Checks if the texture has a default brightmap and creates it if so // //=========================================================================== -void FTexture::CreateDefaultBrightmap() +void FGameTexture::CreateDefaultBrightmap() { - if (!bBrightmapChecked) + auto tex = GetTexture(); + if (!tex->bBrightmapChecked) { // Check for brightmaps - if (GetImage() && GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap && - UseType != ETextureType::Decal && UseType != ETextureType::MiscPatch && UseType != ETextureType::FontChar && - Brightmap == NULL) + if (tex->GetImage() && tex->GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap && + GetUseType() != ETextureType::Decal && GetUseType() != ETextureType::MiscPatch && GetUseType() != ETextureType::FontChar && + tex->Brightmap == NULL) { // May have one - let's check when we use this texture - auto texbuf = Get8BitPixels(false); + auto texbuf = tex->Get8BitPixels(false); const int white = ColorMatcher.Pick(255, 255, 255); int size = GetTexelWidth() * GetTexelHeight(); @@ -362,21 +363,21 @@ void FTexture::CreateDefaultBrightmap() if (GPalette.GlobalBrightmap.Remap[texbuf[i]] == white) { // Create a brightmap - DPrintf(DMSG_NOTIFY, "brightmap created for texture '%s'\n", Name.GetChars()); - Brightmap = CreateBrightmapTexture(static_cast(this)->GetImage()); - bBrightmapChecked = true; - TexMan.AddGameTexture(MakeGameTexture(Brightmap)); + DPrintf(DMSG_NOTIFY, "brightmap created for texture '%s'\n", GetName().GetChars()); + tex->Brightmap = CreateBrightmapTexture(static_cast(tex)->GetImage()); + tex->bBrightmapChecked = true; + //TexMan.AddGameTexture(MakeGameTexture(tex->Brightmap)); return; } } // No bright pixels found - DPrintf(DMSG_SPAMMY, "No bright pixels found in texture '%s'\n", Name.GetChars()); - bBrightmapChecked = true; + DPrintf(DMSG_SPAMMY, "No bright pixels found in texture '%s'\n", GetName().GetChars()); + tex->bBrightmapChecked = true; } else { // does not have one so set the flag to 'done' - bBrightmapChecked = true; + tex->bBrightmapChecked = true; } } } @@ -440,7 +441,6 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h) // already done! if (areacount) return false; - if (UseType == ETextureType::Flat) return false; // flats don't have transparent parts areacount = -1; //whatever happens next, it shouldn't be done twice! // large textures are excluded for performance reasons @@ -949,7 +949,7 @@ void FTexture::SetSpriteRect() IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags) { - if (UseType != ETextureType::Null) + //if (UseType != ETextureType::Null) { IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags); if (hwtex == nullptr) @@ -1076,7 +1076,6 @@ 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. diff --git a/src/common/textures/textureid.h b/src/common/textures/textureid.h index 76cec58b95..5d2b7d7261 100644 --- a/src/common/textures/textureid.h +++ b/src/common/textures/textureid.h @@ -17,6 +17,7 @@ enum class ETextureType : uint8_t SkinGraphic, Null, FirstDefined, + Special, SWCanvas, }; diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index b29f00e324..f9fe4d84e0 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -107,7 +107,7 @@ void FTextureManager::DeleteAll() // all CCMDs triggering a flush can be executed while a wipe is in progress // // This now also deletes the software textures because having the software -// renderer use the texture scalers is a planned feature and that is the +// renderer can also use the texture scalers and that is the // main reason to call this outside of the destruction code. // //========================================================================== @@ -121,6 +121,7 @@ void FTextureManager::FlushAll() Textures[i].Texture->GetTexture()->CleanHardwareTextures(true); delete Textures[i].Texture->GetTexture()->SoftwareTexture; Textures[i].Texture->GetTexture()->SoftwareTexture = nullptr; + calcShouldUpscale(Textures[i].Texture); } } } @@ -229,7 +230,7 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset if (tex == NO_TEXTURE) return FTextureID(-1); if (tex != NULL) return tex->GetID(); if (flags & TEXMAN_DontCreate) return FTextureID(-1); // we only want to check, there's no need to create a texture if we don't have one yet. - tex = MakeGameTexture(FTexture::CreateTexture("", lump, ETextureType::Override)); + tex = MakeGameTexture(FTexture::CreateTexture("", lump, ETextureType::Override), ETextureType::Override); if (tex != NULL) { tex->AddAutoMaterials(); @@ -383,6 +384,7 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture, bool addtohas if (texture == NULL) return FTextureID(-1); // Later textures take precedence over earlier ones + calcShouldUpscale(texture); // calculate this once at insertion // Textures without name can't be looked for if (addtohash && texture->GetName().IsNotEmpty()) @@ -417,7 +419,7 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype) { FString str; fileSystem.GetFileShortName(str, lumpnum); - auto out = MakeGameTexture(FTexture::CreateTexture(str, lumpnum, usetype)); + auto out = MakeGameTexture(FTexture::CreateTexture(str, lumpnum, usetype), usetype); if (out != NULL) return AddGameTexture (out); else @@ -557,10 +559,9 @@ void FTextureManager::AddHiresTextures (int wadnum) if (amount == 0) { // A texture with this name does not yet exist - auto newtex = MakeGameTexture(FTexture::CreateTexture (Name, firsttx, ETextureType::Any)); + auto newtex = MakeGameTexture(FTexture::CreateTexture (Name, firsttx, ETextureType::Any), ETextureType::Override); if (newtex != NULL) { - newtex->SetUseType(ETextureType::Override); AddGameTexture(newtex); } } @@ -580,7 +581,7 @@ void FTextureManager::AddHiresTextures (int wadnum) newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); - ReplaceTexture(tlist[i], MakeGameTexture(newtex), true); + ReplaceTexture(tlist[i], MakeGameTexture(newtex, ETextureType::Override), true); } } } @@ -677,7 +678,7 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); - ReplaceTexture(tlist[i], MakeGameTexture(newtex), true); + ReplaceTexture(tlist[i], MakeGameTexture(newtex, ETextureType::Override), true); } } } @@ -706,7 +707,7 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build if (lumpnum>=0) { - auto newtex = MakeGameTexture(FTexture::CreateTexture(src, lumpnum, ETextureType::Override)); + auto newtex = MakeGameTexture(FTexture::CreateTexture(src, lumpnum, ETextureType::Override), ETextureType::Override); if (newtex != NULL) { @@ -926,7 +927,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b // Try to create a texture from this lump and add it. // Unfortunately we have to look at everything that comes through here... - auto out = MakeGameTexture(FTexture::CreateTexture(Name, i, skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch)); + auto out = MakeGameTexture(FTexture::CreateTexture(Name, i, ETextureType::MiscPatch), skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch); if (out != NULL) { @@ -1082,7 +1083,7 @@ void FTextureManager::AddLocalizedVariants() // FTextureManager :: Init // //========================================================================== -FTexture *CreateShaderTexture(bool, bool); +FGameTexture *CreateShaderTexture(bool, bool); void InitBuildTiles(); FImageSource* CreateEmptyTexture(); @@ -1093,18 +1094,17 @@ void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildI //if (BuildTileFiles.Size() == 0) CountBuildTiles (); // Texture 0 is a dummy texture used to indicate "no texture" - auto nulltex = MakeGameTexture(new FImageTexture(nullptr, "")); - nulltex->SetUseType(ETextureType::Null); + auto nulltex = MakeGameTexture(new FImageTexture(nullptr, ""), ETextureType::Null); AddGameTexture (nulltex); // This is for binding to unused texture units, because accessing an unbound texture unit is undefined. It's a one pixel empty texture. - auto emptytex = MakeGameTexture(new FImageTexture(CreateEmptyTexture(), "")); + auto emptytex = MakeGameTexture(new FImageTexture(CreateEmptyTexture(), ""), ETextureType::Override); emptytex->SetSize(1, 1); AddGameTexture(emptytex); // some special textures used in the game. - AddGameTexture(MakeGameTexture(CreateShaderTexture(false, false))); - AddGameTexture(MakeGameTexture(CreateShaderTexture(false, true))); - AddGameTexture(MakeGameTexture(CreateShaderTexture(true, false))); - AddGameTexture(MakeGameTexture(CreateShaderTexture(true, true))); + AddGameTexture(CreateShaderTexture(false, false)); + AddGameTexture(CreateShaderTexture(false, true)); + AddGameTexture(CreateShaderTexture(true, false)); + AddGameTexture(CreateShaderTexture(true, true)); int wadcnt = fileSystem.GetNumWads(); @@ -1212,7 +1212,7 @@ FTextureID FTextureManager::GetRawTexture(FTextureID texid) } // Todo: later this can just link to the already existing texture for this source graphic, once it can be retrieved through the image's SourceLump index - auto RawTexture = MakeGameTexture(new FImageTexture(source, "")); + auto RawTexture = MakeGameTexture(new FImageTexture(source, ""), ETextureType::Wall); texid = TexMan.AddGameTexture(RawTexture); Textures[texidx].RawTexture = texid.GetIndex(); Textures[texid.GetIndex()].RawTexture = texid.GetIndex(); @@ -1244,7 +1244,7 @@ FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid) // Set this up so that it serializes to the same info as the base texture - this is needed to restore it on load. // But do not link the new texture into the hash chain! - auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image, tex->GetName())); + auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image, tex->GetName()), ETextureType::Wall); FrontSkyLayer->SetUseType(tex->GetUseType()); FrontSkyLayer->GetTexture()->bNoRemap0 = true; texid = TexMan.AddGameTexture(FrontSkyLayer, false); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 391fb96044..4928078820 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -250,7 +250,7 @@ public: SpritePositioningInfo *spi = nullptr; IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); - static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType usetype); + static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType UseType); virtual ~FTexture (); virtual FImageSource *GetImage() const { return nullptr; } void AddAutoMaterials(); @@ -273,8 +273,6 @@ public: int GetTexelTopOffset(int adjusted) { return _TopOffset[adjusted]; } - bool isValid() const { return UseType != ETextureType::Null; } - bool isSWCanvas() const { return UseType == ETextureType::SWCanvas; } bool isSkybox() const { return bSkybox; } bool isFullbrightDisabled() const { return bDisableFullbright; } bool isHardwareCanvas() const { return bHasCanvas; } // There's two here so that this can deal with software canvases in the hardware renderer later. @@ -283,7 +281,6 @@ public: int GetRotations() const { return Rotations; } float GetShaderSpeed() const { return shaderspeed; } void SetRotations(int rot) { Rotations = int16_t(rot); } - bool isSprite() const { return UseType == ETextureType::Sprite || UseType == ETextureType::SkinSprite || UseType == ETextureType::Decal; } const FString &GetName() const { return Name; } void SetNoDecals(bool on) { bNoDecals = on; } @@ -301,11 +298,8 @@ public: bool isAutoGlowing() const { return bAutoGlowing; } int GetGlowHeight() const { return GlowHeight; } bool isFullbright() const { return bFullbright; } - void CreateDefaultBrightmap(); bool FindHoles(const unsigned char * buffer, int w, int h); - void SetUseType(ETextureType type) { UseType = type; } int GetSourceLump() const { return SourceLump; } - ETextureType GetUseType() const { return UseType; } void SetSpeed(float fac) { shaderspeed = fac; } bool UseWorldPanning() const { return bWorldPanning; } void SetWorldPanning(bool on) { bWorldPanning = on; } @@ -382,7 +376,6 @@ protected: protected: FString Name; - ETextureType UseType; // This texture's primary purpose uint8_t bNoDecals:1; // Decals should not stick to texture uint8_t bNoRemap0:1; // Do not remap color 0 (used by front layer of parallax skies) @@ -500,7 +493,6 @@ public: bHasCanvas = true; bTranslucent = false; bExpandSprite = false; - UseType = ETextureType::Wall; } void NeedUpdate() { bNeedsUpdate = true; } @@ -632,11 +624,15 @@ public: class FGameTexture { FTexture *wrapped; - int8_t shouldUpscaleFlag = -1; + int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture. + ETextureType UseType = ETextureType::Wall; // This texture's primary purpose + public: FGameTexture(FTexture* wrap) : wrapped(wrap) {} ~FGameTexture(); + void CreateDefaultBrightmap(); + ETextureType GetUseType() const { return UseType; } void SetUpscaleFlag(int what) { shouldUpscaleFlag = what; } int GetUpscaleFlag() { return shouldUpscaleFlag; } @@ -653,13 +649,13 @@ public: double GetDisplayLeftOffset(int adjusted = 0) /*const*/ { return wrapped->GetDisplayLeftOffsetDouble(adjusted); } double GetDisplayTopOffset(int adjusted = 0) /*const*/ { return wrapped->GetDisplayTopOffsetDouble(adjusted); } - bool isValid() { return wrapped->isValid(); } + bool isValid() const { return UseType != ETextureType::Null; } int isWarped() { return wrapped->isWarped(); } void SetWarpStyle(int style) { wrapped->bWarped = style; } bool isMasked() { return wrapped->isMasked(); } bool isHardwareCanvas() const { return wrapped->isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isSoftwareCanvas() const { return wrapped->isCanvas(); } - bool isMiscPatch() const { return wrapped->GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. + bool isMiscPatch() const { return GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. bool isMultiPatch() const { return wrapped->bMultiPatch; } bool isFullbrightDisabled() const { return wrapped->isFullbrightDisabled(); } bool isFullbright() const { return wrapped->isFullbright(); } @@ -670,8 +666,7 @@ public: bool allowNoDecals() const { return wrapped->allowNoDecals(); } void SetNoDecals(bool on) { wrapped->bNoDecals = on; } void SetTranslucent(bool on) { wrapped->bTranslucent = on; } - ETextureType GetUseType() const { return wrapped->GetUseType(); } - void SetUseType(ETextureType type) { wrapped->SetUseType(type); } + void SetUseType(ETextureType type) { UseType = type; } int GetShaderIndex() const { return wrapped->shaderindex; } float GetShaderSpeed() const { return wrapped->GetShaderSpeed(); } uint16_t GetRotations() const { return wrapped->GetRotations(); } @@ -753,21 +748,31 @@ public: } }; -inline FGameTexture* MakeGameTexture(FTexture* tex) +inline FGameTexture* MakeGameTexture(FTexture* tex, ETextureType useType) { if (!tex) return nullptr; - return new FGameTexture(tex); + auto t = new FGameTexture(tex); + t->SetUseType(useType); + return t; } -bool calcShouldUpscale(FGameTexture* tex, ETextureType UseType); -inline bool shouldUpscale(FGameTexture* tex, ETextureType UseType) +enum EUpscaleFlags { - auto f = tex->GetUpscaleFlag(); - // Cache this value in the texture to save time because it is very frequently polled. - if (f != -1) return f; - auto res = calcShouldUpscale(tex, UseType); - tex->SetUpscaleFlag(res); - return res; + UF_None = 0, + UF_Texture = 1, + UF_Sprite = 2, + UF_Font = 4 +}; + +extern int upscalemask; +void UpdateUpscaleMask(); + +int calcShouldUpscale(FGameTexture* tex); +inline int shouldUpscale(FGameTexture* tex, EUpscaleFlags UseType) +{ + // This only checks the global scale mask and the texture's validation for upscaling. Everything else has been done up front elsewhere. + if (!(upscalemask & UseType)) return 0; + return tex->GetUpscaleFlag(); } #endif diff --git a/src/d_main.cpp b/src/d_main.cpp index 98f0a884ee..11f5517c72 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -880,7 +880,7 @@ void D_Display () if (vr_mode == 0 || vid_rendermode != 4) { // save the current screen if about to wipe - wipe = MakeGameTexture(screen->WipeStartScreen ()); + wipe = MakeGameTexture(screen->WipeStartScreen(), ETextureType::SWCanvas); switch (wipegamestate) { @@ -1063,7 +1063,7 @@ void D_Display () GSnd->SetSfxPaused(true, 1); I_FreezeTime(true); screen->End2D(); - auto wipend = MakeGameTexture(screen->WipeEndScreen ()); + auto wipend = MakeGameTexture(screen->WipeEndScreen(), ETextureType::SWCanvas); auto wiper = Wiper::Create(wipe_type); wiper->SetTextures(wipe, wipend); @@ -2673,7 +2673,7 @@ static void CheckForHacks(BuildInfo& buildinfo) buildinfo.Height == 128) { buildinfo.Height = 200; - buildinfo.tex->SetSize(buildinfo.tex->GetTexelWidth(), 200); + buildinfo.texture->SetSize(buildinfo.texture->GetTexelWidth(), 200); return; } @@ -3062,6 +3062,7 @@ static int D_DoomMain_Internal (void) S_ParseMusInfo(); if (!batchrun) Printf ("Texman.Init: Init texture manager.\n"); + UpdateUpscaleMask(); SpriteFrames.Clear(); TexMan.Init([]() { StartScreen->Progress(); }, CheckForHacks); PatchTextures(); diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index f409b25311..c9104b66f8 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -709,7 +709,7 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) sc.MustGetNumber (); height = sc.Number; FTextureID picnum = TexMan.CheckForTexture (picname, ETextureType::Flat, texflags); - FGameTexture *viewer = MakeGameTexture(new FCanvasTexture (picname, width, height)); + FGameTexture *viewer = MakeGameTexture(new FCanvasTexture (picname, width, height), ETextureType::Wall); if (picnum.Exists()) { auto oldtex = TexMan.GameTexture(picnum); @@ -723,7 +723,6 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) fitwidth = width; fitheight = height; // [GRB] No need for oldtex - viewer->SetUseType(ETextureType::Wall); TexMan.AddGameTexture (viewer); } if (sc.GetString()) diff --git a/src/gamedata/textures/buildloader.cpp b/src/gamedata/textures/buildloader.cpp index e2f73e1469..37a21eb978 100644 --- a/src/gamedata/textures/buildloader.cpp +++ b/src/gamedata/textures/buildloader.cpp @@ -157,10 +157,9 @@ void AddTiles(const FString& pathprefix, const void* tiles, FRemapTable *remap) if (width <= 0 || height <= 0) continue; FStringf name("%sBTIL%04d", pathprefix.GetChars(), i); - auto tex = MakeGameTexture(new FImageTexture(new FBuildTexture(pathprefix, i, tiledata, remap, width, height, xoffs, yoffs), name)); + auto tex = MakeGameTexture(new FImageTexture(new FBuildTexture(pathprefix, i, tiledata, remap, width, height, xoffs, yoffs), name), ETextureType::Override); texnum = TexMan.AddGameTexture(tex); tiledata += size; - tex->SetUseType(ETextureType::Override); // reactivate only if the texture counter works here. diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 893b35cffb..c19c3ea3ca 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -108,7 +108,7 @@ static void ParseVavoomSkybox() sb->SetSize(); if (!error) { - TexMan.AddGameTexture(MakeGameTexture(sb)); + TexMan.AddGameTexture(MakeGameTexture(sb, ETextureType::Override)); } } } @@ -1013,7 +1013,7 @@ class GLDefsParser sc.ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->GetName().GetChars()); } sb->SetSize(); - TexMan.AddGameTexture(MakeGameTexture(sb)); + TexMan.AddGameTexture(MakeGameTexture(sb, ETextureType::Override)); } //=========================================================================== diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index 1418e6e2e2..d936a2576e 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -157,7 +157,7 @@ FVoxelModel::FVoxelModel(FVoxel *voxel, bool owned) { mVoxel = voxel; mOwningVoxel = owned; - mPalette = TexMan.AddGameTexture(MakeGameTexture(new FImageTexture(new FVoxelTexture(voxel)))); + mPalette = TexMan.AddGameTexture(MakeGameTexture(new FImageTexture(new FVoxelTexture(voxel)), ETextureType::Override)); } //=========================================================================== diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 2d180126e2..9eff4f2053 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -114,7 +114,7 @@ void FHWModelRenderer::SetInterpolation(double inter) void FHWModelRenderer::SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) { - state.SetMaterial(skin, 0, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1); + state.SetMaterial(skin, UF_None, 0, clampNoFilter ? CLAMP_NOFILTER : CLAMP_NONE, translation, -1); state.SetLightIndex(modellightindex); } diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index 3416ddfff5..2c93079db8 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -66,8 +66,7 @@ void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) state.SetTextureMode(decal->RenderStyle); state.SetRenderStyle(decal->RenderStyle); - int flags = shouldUpscale(texture, ETextureType::Sprite) ? CTF_Upscale : 0; - state.SetMaterial(texture, flags, CLAMP_XY, decal->Translation, -1); + state.SetMaterial(texture, UF_Sprite, 0, CLAMP_XY, decal->Translation, -1); // If srcalpha is one it looks better with a higher alpha threshold diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 245e80a890..82ce3ac4ea 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -204,8 +204,7 @@ void HWFlat::DrawSubsectors(HWDrawInfo *di, FRenderState &state) void HWFlat::DrawOtherPlanes(HWDrawInfo *di, FRenderState &state) { - int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; - state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1); // Draw the subsectors assigned to it due to missing textures auto pNode = (renderflags&SSRF_RENDERFLOOR) ? @@ -237,8 +236,7 @@ void HWFlat::DrawFloodPlanes(HWDrawInfo *di, FRenderState &state) // This requires a stencil because the projected plane interferes with // the depth buffer - int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; - state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1); // Draw the subsectors assigned to it due to missing textures auto pNode = (renderflags&SSRF_RENDERFLOOR) ? @@ -324,17 +322,16 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) } else if (!translucent) { - int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; if (sector->special != GLSector_Skybox) { - state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1); state.SetPlaneTextureRotation(&plane, texture); DrawSubsectors(di, state); state.EnableTextureMatrix(false); } else if (!hacktype) { - state.SetMaterial(texture, flags, CLAMP_XY, 0, -1); + state.SetMaterial(texture, UF_Texture, 0, CLAMP_XY, 0, -1); state.SetLightIndex(dynlightindex); state.Draw(DT_TriangleStrip,iboindex, 4); flatvertices += 4; @@ -355,8 +352,7 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) { if (!texture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); else state.AlphaFunc(Alpha_GEqual, 0.f); - int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; - state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1); state.SetPlaneTextureRotation(&plane, texture); DrawSubsectors(di, state); state.EnableTextureMatrix(false); diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index ad491217fb..69c9631484 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -975,8 +975,7 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state) } - int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; - state.SetMaterial(texture, flags, CLAMP_NONE, 0, -1); + state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1); state.SetObjectColor(origin->specialcolor); state.SetPlaneTextureRotation(sp, texture); diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index 47e08c03cf..eb461898fe 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -569,8 +569,9 @@ public: mTextureModeFlags = mat->GetLayerFlags(); } - void SetMaterial(FGameTexture* tex, int scaleflags, int clampmode, int translation, int overrideshader) + void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, int translation, int overrideshader) { + if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale; if (!tex->expandSprites()) scaleflags &= ~CTF_Expand; SetMaterial(FMaterial::ValidateTexture(tex, scaleflags), clampmode, translation, overrideshader); } diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index ef2af55659..79051f0ef9 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -52,10 +52,9 @@ void HWSkyPortal::RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode) { - int flags = shouldUpscale(tex, ETextureType::Wall) ? CTF_Upscale : 0; if (tex) { - state.SetMaterial(tex, flags, CLAMP_NONE, 0, -1); + state.SetMaterial(tex, UF_Texture, 0, CLAMP_NONE, 0, -1); state.EnableModelMatrix(true); state.EnableTextureMatrix(true); @@ -107,41 +106,39 @@ void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texn else state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector2.X, di->Level->info->skyrotatevector2.Z, di->Level->info->skyrotatevector2.Y); - // Only test the first face - the result here must be consistent - either all get scaled or none. - int flags = shouldUpscale(tex->GetSkyFace(0), ETextureType::Flat) ? CTF_Upscale : 0; if (tex->GetSkyFace(5)) { faces=4; // north - state.SetMaterial(tex->GetSkyFace(0), flags, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(0), UF_Texture, 0, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(0), 4); // east - state.SetMaterial(tex->GetSkyFace(1), flags, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(1), UF_Texture, 0, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(1), 4); // south - state.SetMaterial(tex->GetSkyFace(2), flags, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(2), UF_Texture, 0, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(2), 4); // west - state.SetMaterial(tex->GetSkyFace(3), flags, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(3), UF_Texture, 0, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(3), 4); } else { faces=1; - state.SetMaterial(tex->GetSkyFace(0), flags, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(0), UF_Texture, 0, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(-1), 10); } // top - state.SetMaterial(tex->GetSkyFace(faces), flags, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(faces), UF_Texture, 0, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(tex->GetSkyFlip() ? 6 : 5), 4); // bottom - state.SetMaterial(tex->GetSkyFace(faces+1), flags, CLAMP_XY, 0, -1); + state.SetMaterial(tex->GetSkyFace(faces+1), UF_Texture, 0, CLAMP_XY, 0, -1); state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(4), 4); state.EnableModelMatrix(false); diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index dbe44637ae..11e7ded60b 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -198,9 +198,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) } uint32_t spritetype = (actor->renderflags & RF_SPRITETYPEMASK); - int flags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; - if (spritetype == RF_FACESPRITE) flags |= CTF_Expand; - if (texture) state.SetMaterial(texture, flags, CLAMP_XY, translation, OverrideShader); + if (texture) state.SetMaterial(texture, UF_Sprite, (spritetype == RF_FACESPRITE) ? CTF_Expand : 0, CLAMP_XY, translation, OverrideShader); else if (!modelframe) state.EnableTexture(false); //SetColor(lightlevel, rel, Colormap, trans); diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 2d1235ae1f..eecca476e8 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -104,7 +104,7 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state) state.AlphaFunc(Alpha_Greater, 0); auto tex = TexMan.GetGameTexture(TexMan.mirrorTexture, false); - state.SetMaterial(tex, false, CLAMP_NONE, 0, -1); + state.SetMaterial(tex, UF_None, 0, CLAMP_NONE, 0, -1); // do not upscale the mirror texture. flags &= ~HWWall::HWF_GLOW; RenderWall(di, state, HWWall::RWF_BLANK); @@ -156,8 +156,7 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) state.SetGlowParams(topglowcolor, bottomglowcolor); state.SetGlowPlanes(frontsector->ceilingplane, frontsector->floorplane); } - int uflags = shouldUpscale(texture, ETextureType::Flat) ? CTF_Upscale : 0; - state.SetMaterial(texture, uflags, flags & 3, 0, -1); + state.SetMaterial(texture, UF_Texture, 0, flags & 3, 0, -1); if (type == RENDERWALL_M2SNF) { diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index 6d6aaee844..ca4f388d72 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -96,8 +96,7 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) { float thresh = (huds->texture->GetTranslucency() || huds->OverrideShader != -1) ? 0.f : gl_mask_sprite_threshold; state.AlphaFunc(Alpha_GEqual, thresh); - int flags = shouldUpscale(huds->texture, ETextureType::Flat) ? CTF_Upscale|CTF_Expand : CTF_Expand; - state.SetMaterial(huds->texture, flags, CLAMP_XY_NOMIP, (huds->weapon->Flags & PSPF_PLAYERTRANSLATED) ? huds->owner->Translation : 0, huds->OverrideShader); + state.SetMaterial(huds->texture, UF_Sprite, CTF_Expand, CLAMP_XY_NOMIP, (huds->weapon->Flags & PSPF_PLAYERTRANSLATED) ? huds->owner->Translation : 0, huds->OverrideShader); state.Draw(DT_TriangleStrip, huds->mx, 4); } diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 7ce5052ca2..0e5f2ab034 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -252,7 +252,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl { if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { - int flags = shouldUpscale(gtex, ETextureType::Wall) ? CTF_Upscale : 0; + int flags = shouldUpscale(gtex, UF_Texture); if (tex->GetImage() && tex->SystemTextures.GetHardwareTexture(0, flags) == nullptr) { FImageSource::RegisterForPrecache(tex->GetImage(), V_IsTrueColor()); diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index efff2852e6..d0010ef0d7 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -164,7 +164,8 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) if (cmd.mTexture != nullptr && cmd.mTexture->isValid()) { - state.SetMaterial(cmd.mTexture, 0, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); + auto flags = cmd.mTexture->GetUseType() >= ETextureType::Special? UF_None : cmd.mTexture->GetUseType() == ETextureType::FontChar? UF_Font : UF_Texture; + state.SetMaterial(cmd.mTexture, flags, 0, cmd.mFlags & F2DDrawer::DTF_Wrap ? CLAMP_NONE : CLAMP_XY_NOMIP, cmd.mTranslationId, -1); state.EnableTexture(true); // Canvas textures are stored upside down diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index 2886d4575d..a34f339adf 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -76,7 +76,7 @@ SWSceneDrawer::SWSceneDrawer() if (!texid.Exists()) { // We need to wrap this in a game texture object to have it managed by the texture manager, even though it will never be used as a material. - auto tex = MakeGameTexture(new FImageTexture(new FSWPaletteTexture, "@@palette@@")); + auto tex = MakeGameTexture(new FImageTexture(new FSWPaletteTexture, "@@palette@@"), ETextureType::Special); texid = TexMan.AddGameTexture(tex); } PaletteTexture = TexMan.GetGameTexture(texid)->GetTexture(); @@ -103,7 +103,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) { // This manually constructs its own material here. fbtex.reset(); - fbtex.reset(MakeGameTexture(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()))); + fbtex.reset(MakeGameTexture(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()), ETextureType::SWCanvas)); GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1); auto mat = FMaterial::ValidateTexture(fbtex.get(), false); mat->AddTextureLayer(PaletteTexture); diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index ace25007ee..6fd4b5d2b6 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -41,7 +41,21 @@ #include "texturemanager.h" +inline EUpscaleFlags scaleFlagFromUseType(ETextureType useType) +{ + switch (useType) + { + case ETextureType::Sprite: + case ETextureType::SkinSprite: + return UF_Sprite; + case ETextureType::FontChar: + return UF_Font; + + default: + return UF_Texture; + } +} //========================================================================== // // @@ -55,7 +69,8 @@ FSoftwareTexture::FSoftwareTexture(FGameTexture *tex) mBufferFlags = CTF_ProcessData; auto f = mBufferFlags; - if (shouldUpscale(tex, tex->GetUseType())) f |= CTF_Upscale; + + if (shouldUpscale(tex, scaleFlagFromUseType(tex->GetUseType()))) f |= CTF_Upscale; // calculate the real size after running the scaler. auto info = mSource->CreateTexBuffer(0, CTF_CheckOnly| f); mPhysicalWidth = info.mWidth; @@ -116,7 +131,7 @@ const uint8_t *FSoftwareTexture::GetPixels(int style) else { auto f = mBufferFlags; - if (shouldUpscale(mTexture, mTexture->GetUseType())) f |= CTF_Upscale; + if (shouldUpscale(mTexture, scaleFlagFromUseType(mTexture->GetUseType()))) f |= CTF_Upscale; auto tempbuffer = mSource->CreateTexBuffer(0, mBufferFlags); Pixels.Resize(GetPhysicalWidth()*GetPhysicalHeight()); PalEntry *pe = (PalEntry*)tempbuffer.mBuffer; From 42304d9680c753b04fa0236b86bd22833fa4c4a9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 01:03:21 +0200 Subject: [PATCH 040/220] - store the material layers in reference counted pointers in the FGameTexture object. Reference counting is used because a texture image may be shared by more than one game texture. --- src/common/textures/hw_material.cpp | 27 ++-- src/common/textures/texture.cpp | 65 ++++----- src/common/textures/texturemanager.cpp | 3 - src/common/textures/textures.h | 185 +++++++++++++------------ src/common/utility/refcounted.h | 103 ++++++++++++++ 5 files changed, 244 insertions(+), 139 deletions(-) create mode 100644 src/common/utility/refcounted.h diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 14f031ee19..41c85fccf9 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -60,17 +60,18 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) { mShaderIndex = tx->isWarped(); // This picks SHADER_Warp1 or SHADER_Warp2 } - else if (imgtex->Normal && imgtex->Specular) + // Note that the material takes no ownership of the texture! + else if (tx->Normal.get() && tx->Specular.get()) { - for (auto &texture : { imgtex->Normal, imgtex->Specular }) + for (auto &texture : { tx->Normal.get(), tx->Specular.get() }) { mTextureLayers.Push(texture); } mShaderIndex = SHADER_Specular; } - else if (imgtex->Normal && imgtex->Metallic && imgtex->Roughness && imgtex->AmbientOcclusion) + else if (tx->Normal.get() && tx->Metallic.get() && tx->Roughness.get() && tx->AmbientOcclusion.get()) { - for (auto &texture : { imgtex->Normal, imgtex->Metallic, imgtex->Roughness, imgtex->AmbientOcclusion }) + for (auto &texture : { tx->Normal.get(), tx->Metallic.get(), tx->Roughness.get(), tx->AmbientOcclusion.get() }) { mTextureLayers.Push(texture); } @@ -80,27 +81,27 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) // Note that these layers must present a valid texture even if not used, because empty TMUs in the shader are an undefined condition. tx->CreateDefaultBrightmap(); auto placeholder = TexMan.GameByIndex(1); - if (imgtex->Brightmap) + if (tx->Brightmap.get()) { - mTextureLayers.Push(imgtex->Brightmap); + mTextureLayers.Push(tx->Brightmap.get()); mLayerFlags |= TEXF_Brightmap; } else { mTextureLayers.Push(placeholder->GetTexture()); } - if (imgtex->Detailmap) + if (tx->Detailmap.get()) { - mTextureLayers.Push(imgtex->Detailmap); + mTextureLayers.Push(tx->Detailmap.get()); mLayerFlags |= TEXF_Detailmap; } else { mTextureLayers.Push(placeholder->GetTexture()); } - if (imgtex->Glowmap) + if (tx->Glowmap.get()) { - mTextureLayers.Push(imgtex->Glowmap); + mTextureLayers.Push(tx->Glowmap.get()); mLayerFlags |= TEXF_Glowmap; } else @@ -113,10 +114,10 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) const UserShaderDesc &usershader = usershaders[imgtex->shaderindex - FIRST_USER_SHADER]; if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material { - for (auto &texture : imgtex->CustomShaderTextures) + for (auto &texture : tx->CustomShaderTextures) { if (texture == nullptr) continue; - mTextureLayers.Push(texture); + mTextureLayers.Push(texture.get()); } mShaderIndex = tx->GetShaderIndex(); } @@ -167,7 +168,7 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool if (gtex && gtex->isValid()) { auto tex = gtex->GetTexture(); - if (!tex->ShouldExpandSprite()) scaleflags &= ~CTF_Expand; + if (!gtex->ShouldExpandSprite()) scaleflags &= ~CTF_Expand; FMaterial *hwtex = tex->Material[scaleflags]; if (hwtex == NULL && create) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 01ad66c31d..acdba34319 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -288,30 +288,30 @@ int FTexture::CheckRealHeight() // //========================================================================== -void FTexture::AddAutoMaterials() +void FGameTexture::AddAutoMaterials() { struct AutoTextureSearchPath { const char *path; - FTexture *FTexture::*pointer; + RefCountedPtr FGameTexture::*pointer; }; static AutoTextureSearchPath autosearchpaths[] = { - { "brightmaps/", &FTexture::Brightmap }, // For backwards compatibility, only for short names - { "materials/brightmaps/", &FTexture::Brightmap }, - { "materials/normalmaps/", &FTexture::Normal }, - { "materials/specular/", &FTexture::Specular }, - { "materials/metallic/", &FTexture::Metallic }, - { "materials/roughness/", &FTexture::Roughness }, - { "materials/ao/", &FTexture::AmbientOcclusion } + { "brightmaps/", &FGameTexture::Brightmap }, // For backwards compatibility, only for short names + { "materials/brightmaps/", &FGameTexture::Brightmap }, + { "materials/normalmaps/", &FGameTexture::Normal }, + { "materials/specular/", &FGameTexture::Specular }, + { "materials/metallic/", &FGameTexture::Metallic }, + { "materials/roughness/", &FGameTexture::Roughness }, + { "materials/ao/", &FGameTexture::AmbientOcclusion } }; - int startindex = bFullNameTexture ? 1 : 0; - FString searchname = Name; + int startindex = Base->bFullNameTexture ? 1 : 0; + FString searchname = GetName(); - if (bFullNameTexture) + if (Base->bFullNameTexture) { auto dot = searchname.LastIndexOf('.'); auto slash = searchname.LastIndexOf('/'); @@ -323,7 +323,7 @@ void FTexture::AddAutoMaterials() auto &layer = autosearchpaths[i]; if (this->*(layer.pointer) == nullptr) // only if no explicit assignment had been done. { - FStringf lookup("%s%s%s", layer.path, bFullNameTexture ? "" : "auto/", searchname.GetChars()); + FStringf lookup("%s%s%s", layer.path, Base->bFullNameTexture ? "" : "auto/", searchname.GetChars()); auto lump = fileSystem.CheckNumForFullName(lookup, false, ns_global, true); if (lump != -1) { @@ -351,7 +351,7 @@ void FGameTexture::CreateDefaultBrightmap() // Check for brightmaps if (tex->GetImage() && tex->GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap && GetUseType() != ETextureType::Decal && GetUseType() != ETextureType::MiscPatch && GetUseType() != ETextureType::FontChar && - tex->Brightmap == NULL) + Brightmap == nullptr) { // May have one - let's check when we use this texture auto texbuf = tex->Get8BitPixels(false); @@ -364,7 +364,7 @@ void FGameTexture::CreateDefaultBrightmap() { // Create a brightmap DPrintf(DMSG_NOTIFY, "brightmap created for texture '%s'\n", GetName().GetChars()); - tex->Brightmap = CreateBrightmapTexture(static_cast(tex)->GetImage()); + Brightmap = CreateBrightmapTexture(tex->GetImage()); tex->bBrightmapChecked = true; //TexMan.AddGameTexture(MakeGameTexture(tex->Brightmap)); return; @@ -743,21 +743,21 @@ TArray FTexture::Get8BitPixels(bool alphatex) // //=========================================================================== -bool FTexture::ShouldExpandSprite() +bool FGameTexture::ShouldExpandSprite() { - if (bExpandSprite != -1) return bExpandSprite; - if (isWarped() || isHardwareCanvas() || shaderindex != SHADER_Default) + if (Base->bExpandSprite != -1) return Base->bExpandSprite; + if (isWarped() || isHardwareCanvas() || GetShaderIndex() != SHADER_Default) { - bExpandSprite = false; + Base->bExpandSprite = false; return false; } if (Brightmap != NULL && (GetTexelWidth() != Brightmap->GetTexelWidth() || GetTexelHeight() != Brightmap->GetTexelHeight())) { // do not expand if the brightmap's size differs. - bExpandSprite = false; + Base->bExpandSprite = false; return false; } - bExpandSprite = true; + Base->bExpandSprite = true; return true; } @@ -857,14 +857,14 @@ outl: // //=========================================================================== -void FTexture::SetupSpriteData() +void FGameTexture::SetupSpriteData() { // Since this is only needed for real sprites it gets allocated on demand. // It also allocates from the image memory arena because it has the same lifetime and to reduce maintenance. - if (spi == nullptr) spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo)); + if (Base->spi == nullptr) Base->spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo)); for (int i = 0; i < 2; i++) { - auto& spi = this->spi[i]; + auto& spi = Base->spi[i]; spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f; spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f; spi.spriteWidth = GetTexelWidth(); @@ -872,7 +872,7 @@ void FTexture::SetupSpriteData() if (i == 1 && ShouldExpandSprite()) { - spi.mTrimResult = TrimBorders(spi.trim); // get the trim size before adding the empty frame + spi.mTrimResult = Base->TrimBorders(spi.trim); // get the trim size before adding the empty frame spi.spriteWidth += 2; spi.spriteHeight += 2; } @@ -886,19 +886,19 @@ void FTexture::SetupSpriteData() // //=========================================================================== -void FTexture::SetSpriteRect() +void FGameTexture::SetSpriteRect() { - if (!spi) return; + if (!Base->spi) return; auto leftOffset = GetLeftOffsetHW(); auto topOffset = GetTopOffsetHW(); - float fxScale = (float)Scale.X; - float fyScale = (float)Scale.Y; + float fxScale = (float)Base->Scale.X; + float fyScale = (float)Base->Scale.Y; for (int i = 0; i < 2; i++) { - auto& spi = this->spi[i]; + auto& spi = Base->spi[i]; // mSpriteRect is for positioning the sprite in the scene. spi.mSpriteRect.left = -leftOffset / fxScale; @@ -1087,12 +1087,13 @@ FGameTexture::~FGameTexture() { FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump()); if (link == this) fileSystem.SetLinkedTexture(GetSourceLump(), nullptr); - delete wrapped; + auto str = GetName(); + Printf("Deleting texture %s\n", str.GetChars()); } bool FGameTexture::isUserContent() const { - int filenum = fileSystem.GetFileContainer(wrapped->GetSourceLump()); + int filenum = fileSystem.GetFileContainer(Base->GetSourceLump()); return (filenum > fileSystem.GetMaxIwadNum()); } diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index f9fe4d84e0..8265f36172 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -1093,9 +1093,6 @@ void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildI DeleteAll(); //if (BuildTileFiles.Size() == 0) CountBuildTiles (); - // Texture 0 is a dummy texture used to indicate "no texture" - auto nulltex = MakeGameTexture(new FImageTexture(nullptr, ""), ETextureType::Null); - AddGameTexture (nulltex); // This is for binding to unused texture units, because accessing an unbound texture unit is undefined. It's a one pixel empty texture. auto emptytex = MakeGameTexture(new FImageTexture(CreateEmptyTexture(), ""), ETextureType::Override); emptytex->SetSize(1, 1); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 4928078820..6946a4d96f 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -42,6 +42,7 @@ #include "textureid.h" #include #include "hw_texcontainer.h" +#include "refcounted.h" // 15 because 0th texture is our texture #define MAX_CUSTOM_HW_SHADER_TEXTURES 15 @@ -235,7 +236,7 @@ struct SpritePositioningInfo }; // Base texture class -class FTexture +class FTexture : public RefCountedBase { friend class FGameTexture; // only for the porting work friend class FTexture; @@ -253,9 +254,9 @@ public: static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType UseType); virtual ~FTexture (); virtual FImageSource *GetImage() const { return nullptr; } - void AddAutoMaterials(); void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); void CleanHardwareTextures(bool reallyclean); + void SetSpriteRect(); // These are mainly meant for 2D code which only needs logical information about the texture to position it properly. int GetDisplayWidth() { int foo = int((Width * 2) / Scale.X); return (foo >> 1) + (foo & 1); } @@ -325,9 +326,6 @@ public: } bool TrimBorders(uint16_t* rect); - void SetSpriteRect(); - bool ShouldExpandSprite(); - void SetupSpriteData(); int GetAreas(FloatRect** pAreas) const; // Returns the whole texture, stored in column-major order @@ -360,19 +358,6 @@ public: protected: ISoftwareTexture *SoftwareTexture = nullptr; - public: - // Material layers - FTexture *Brightmap = nullptr; - FTexture* Detailmap = nullptr; - FTexture* Glowmap = nullptr; - FTexture *Normal = nullptr; // Normal map texture - FTexture *Specular = nullptr; // Specular light texture for the diffuse+normal+specular light model - FTexture *Metallic = nullptr; // Metalness texture for the physically based rendering (PBR) light model - FTexture *Roughness = nullptr; // Roughness texture for PBR - FTexture *AmbientOcclusion = nullptr; // Ambient occlusion texture for PBR - - FTexture *CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES] = { nullptr }; // Custom texture maps for custom hardware shaders - protected: FString Name; @@ -623,127 +608,145 @@ public: // Refactoring helper to allow piece by piece adjustment of the API class FGameTexture { - FTexture *wrapped; + friend class FMaterial; + + // Material layers + RefCountedPtr Base; + RefCountedPtr Brightmap; + RefCountedPtr Detailmap; + RefCountedPtr Glowmap; + RefCountedPtr Normal; // Normal map texture + RefCountedPtr Specular; // Specular light texture for the diffuse+normal+specular light model + RefCountedPtr Metallic; // Metalness texture for the physically based rendering (PBR) light model + RefCountedPtr Roughness; // Roughness texture for PBR + RefCountedPtr AmbientOcclusion; // Ambient occlusion texture for PBR + RefCountedPtr CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES]; // Custom texture maps for custom hardware shaders + int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture. ETextureType UseType = ETextureType::Wall; // This texture's primary purpose public: - FGameTexture(FTexture* wrap) : wrapped(wrap) {} + FGameTexture(FTexture* wrap) : Base(wrap) {} ~FGameTexture(); void CreateDefaultBrightmap(); + void AddAutoMaterials(); + bool ShouldExpandSprite(); + void SetupSpriteData(); + void SetSpriteRect(); ETextureType GetUseType() const { return UseType; } void SetUpscaleFlag(int what) { shouldUpscaleFlag = what; } int GetUpscaleFlag() { return shouldUpscaleFlag; } - FTexture* GetTexture() { return wrapped; } - int GetSourceLump() const { return wrapped->GetSourceLump(); } - void SetBrightmap(FGameTexture* tex) { wrapped->Brightmap = tex->GetTexture(); } + FTexture* GetTexture() { return Base.get(); } + int GetSourceLump() const { return Base->GetSourceLump(); } + void SetBrightmap(FGameTexture* tex) { Brightmap = tex->GetTexture(); } - double GetDisplayWidth() /*const*/ { return wrapped->GetDisplayWidthDouble(); } - double GetDisplayHeight() /*const*/ { return wrapped->GetDisplayHeightDouble(); } - int GetTexelWidth() /*const*/ { return wrapped->GetTexelWidth(); } - int GetTexelHeight() /*const*/ { return wrapped->GetTexelHeight(); } - int GetTexelLeftOffset(int adjusted = 0) /*const*/ { return wrapped->GetTexelLeftOffset(adjusted); } - int GetTexelTopOffset(int adjusted = 0) /*const*/ { return wrapped->GetTexelTopOffset(adjusted); } - double GetDisplayLeftOffset(int adjusted = 0) /*const*/ { return wrapped->GetDisplayLeftOffsetDouble(adjusted); } - double GetDisplayTopOffset(int adjusted = 0) /*const*/ { return wrapped->GetDisplayTopOffsetDouble(adjusted); } + double GetDisplayWidth() /*const*/ { return Base->GetDisplayWidthDouble(); } + double GetDisplayHeight() /*const*/ { return Base->GetDisplayHeightDouble(); } + int GetTexelWidth() /*const*/ { return Base->GetTexelWidth(); } + int GetTexelHeight() /*const*/ { return Base->GetTexelHeight(); } + int GetTexelLeftOffset(int adjusted = 0) /*const*/ { return Base->GetTexelLeftOffset(adjusted); } + int GetTexelTopOffset(int adjusted = 0) /*const*/ { return Base->GetTexelTopOffset(adjusted); } + double GetDisplayLeftOffset(int adjusted = 0) /*const*/ { return Base->GetDisplayLeftOffsetDouble(adjusted); } + double GetDisplayTopOffset(int adjusted = 0) /*const*/ { return Base->GetDisplayTopOffsetDouble(adjusted); } + // For the hardware renderer. The software renderer's have been offloaded to FSoftwareTexture + int GetLeftOffsetHW() { return GetTexelLeftOffset(r_spriteadjustHW); } + int GetTopOffsetHW() { return GetTexelTopOffset(r_spriteadjustHW); } bool isValid() const { return UseType != ETextureType::Null; } - int isWarped() { return wrapped->isWarped(); } - void SetWarpStyle(int style) { wrapped->bWarped = style; } - bool isMasked() { return wrapped->isMasked(); } - bool isHardwareCanvas() const { return wrapped->isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. - bool isSoftwareCanvas() const { return wrapped->isCanvas(); } + int isWarped() { return Base->isWarped(); } + void SetWarpStyle(int style) { Base->bWarped = style; } + bool isMasked() { return Base->isMasked(); } + bool isHardwareCanvas() const { return Base->isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. + bool isSoftwareCanvas() const { return Base->isCanvas(); } bool isMiscPatch() const { return GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. - bool isMultiPatch() const { return wrapped->bMultiPatch; } - bool isFullbrightDisabled() const { return wrapped->isFullbrightDisabled(); } - bool isFullbright() const { return wrapped->isFullbright(); } - bool isFullNameTexture() const { return wrapped->bFullNameTexture; } - bool expandSprites() const { return wrapped->bExpandSprite; } - bool useWorldPanning() const { return wrapped->UseWorldPanning(); } - void SetWorldPanning(bool on) { wrapped->SetWorldPanning(on); } - bool allowNoDecals() const { return wrapped->allowNoDecals(); } - void SetNoDecals(bool on) { wrapped->bNoDecals = on; } - void SetTranslucent(bool on) { wrapped->bTranslucent = on; } + bool isMultiPatch() const { return Base->bMultiPatch; } + bool isFullbrightDisabled() const { return Base->isFullbrightDisabled(); } + bool isFullbright() const { return Base->isFullbright(); } + bool isFullNameTexture() const { return Base->bFullNameTexture; } + bool expandSprites() const { return Base->bExpandSprite; } + bool useWorldPanning() const { return Base->UseWorldPanning(); } + void SetWorldPanning(bool on) { Base->SetWorldPanning(on); } + bool allowNoDecals() const { return Base->allowNoDecals(); } + void SetNoDecals(bool on) { Base->bNoDecals = on; } + void SetTranslucent(bool on) { Base->bTranslucent = on; } void SetUseType(ETextureType type) { UseType = type; } - int GetShaderIndex() const { return wrapped->shaderindex; } - float GetShaderSpeed() const { return wrapped->GetShaderSpeed(); } - uint16_t GetRotations() const { return wrapped->GetRotations(); } - void SetRotations(int index) { wrapped->SetRotations(index); } - void SetSkyOffset(int ofs) { wrapped->SetSkyOffset(ofs); } - int GetSkyOffset() const { return wrapped->GetSkyOffset(); } - FTextureID GetID() const { return wrapped->GetID(); } - ISoftwareTexture* GetSoftwareTexture() { return wrapped->GetSoftwareTexture(); } - void SetSoftwareTexture(ISoftwareTexture* swtex) { wrapped->SetSoftwareTextue(swtex); } - void SetScale(DVector2 vec) { wrapped->SetScale(vec); } - const FString& GetName() const { return wrapped->GetName(); } - void SetShaderSpeed(float speed) { wrapped->shaderspeed = speed; } - void SetShaderIndex(int index) { wrapped->shaderindex = index; } + int GetShaderIndex() const { return Base->shaderindex; } + float GetShaderSpeed() const { return Base->GetShaderSpeed(); } + uint16_t GetRotations() const { return Base->GetRotations(); } + void SetRotations(int index) { Base->SetRotations(index); } + void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); } + int GetSkyOffset() const { return Base->GetSkyOffset(); } + FTextureID GetID() const { return Base->GetID(); } + ISoftwareTexture* GetSoftwareTexture() { return Base->GetSoftwareTexture(); } + void SetSoftwareTexture(ISoftwareTexture* swtex) { Base->SetSoftwareTextue(swtex); } + void SetScale(DVector2 vec) { Base->SetScale(vec); } + const FString& GetName() const { return Base->GetName(); } + void SetShaderSpeed(float speed) { Base->shaderspeed = speed; } + void SetShaderIndex(int index) { Base->shaderindex = index; } void SetShaderLayers(MaterialLayers& lay) { // Only update layers that have something defind. - if (lay.Glossiness > -1000) wrapped->Glossiness = lay.Glossiness; - if (lay.SpecularLevel > -1000) wrapped->SpecularLevel = lay.SpecularLevel; - if (lay.Brightmap) wrapped->Brightmap = lay.Brightmap->GetTexture(); - if (lay.Normal) wrapped->Normal = lay.Normal->GetTexture(); - if (lay.Specular) wrapped->Specular = lay.Specular->GetTexture(); - if (lay.Metallic) wrapped->Metallic = lay.Metallic->GetTexture(); - if (lay.Roughness) wrapped->Roughness = lay.Roughness->GetTexture(); - if (lay.AmbientOcclusion) wrapped->AmbientOcclusion = lay.AmbientOcclusion->GetTexture(); + if (lay.Glossiness > -1000) Base->Glossiness = lay.Glossiness; + if (lay.SpecularLevel > -1000) Base->SpecularLevel = lay.SpecularLevel; + if (lay.Brightmap) Brightmap = lay.Brightmap->GetTexture(); + if (lay.Normal) Normal = lay.Normal->GetTexture(); + if (lay.Specular) Specular = lay.Specular->GetTexture(); + if (lay.Metallic) Metallic = lay.Metallic->GetTexture(); + if (lay.Roughness) Roughness = lay.Roughness->GetTexture(); + if (lay.AmbientOcclusion) AmbientOcclusion = lay.AmbientOcclusion->GetTexture(); for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) { - if (lay.CustomShaderTextures[i]) wrapped->CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); + if (lay.CustomShaderTextures[i]) CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); } } - float GetGlossiness() const { return wrapped->Glossiness; } - float GetSpecularLevel() const { return wrapped->SpecularLevel; } + float GetGlossiness() const { return Base->Glossiness; } + float GetSpecularLevel() const { return Base->SpecularLevel; } void CopySize(FGameTexture* BaseTexture) { - wrapped->CopySize(BaseTexture->wrapped); + Base->CopySize(BaseTexture->Base.get()); } // Glowing is a pure material property that should not filter down to the actual texture objects. - void GetGlowColor(float* data) { wrapped->GetGlowColor(data); } - bool isGlowing() const { return wrapped->isGlowing(); } - bool isAutoGlowing() const { return wrapped->isAutoGlowing(); } - int GetGlowHeight() const { return wrapped->GetGlowHeight(); } + void GetGlowColor(float* data) { Base->GetGlowColor(data); } + bool isGlowing() const { return Base->isGlowing(); } + bool isAutoGlowing() const { return Base->isAutoGlowing(); } + int GetGlowHeight() const { return Base->GetGlowHeight(); } void SetAutoGlowing() { auto tex = GetTexture(); tex->bAutoGlowing = tex->bGlowing = tex->bFullbright = true; } - void SetGlowHeight(int v) { wrapped->GlowHeight = v; } - void SetFullbright() { wrapped->bFullbright = true; } - void SetDisableFullbright(bool on) { wrapped->bDisableFullbright = on; } + void SetGlowHeight(int v) { Base->GlowHeight = v; } + void SetFullbright() { Base->bFullbright = true; } + void SetDisableFullbright(bool on) { Base->bDisableFullbright = on; } void SetGlowing(PalEntry color) { auto tex = GetTexture(); tex->bAutoGlowing = false; tex->bGlowing = true; tex->GlowColor = color; } bool isUserContent() const; - void AddAutoMaterials() { wrapped->AddAutoMaterials(); } - int CheckRealHeight() { return wrapped->CheckRealHeight(); } - bool isSkybox() const { return wrapped->isSkybox(); } - void SetSize(int x, int y) { wrapped->SetSize(x, y); } - void SetDisplaySize(float w, float h) { wrapped->SetSize((int)w, (int)h); } + int CheckRealHeight() { return Base->CheckRealHeight(); } + bool isSkybox() const { return Base->isSkybox(); } + void SetSize(int x, int y) { Base->SetSize(x, y); } + void SetDisplaySize(float w, float h) { Base->SetSize((int)w, (int)h); } - void SetSpriteRect() { wrapped->SetSpriteRect(); } - const SpritePositioningInfo& GetSpritePositioning(int which) { if (wrapped->spi == nullptr) wrapped->SetupSpriteData(); return wrapped->spi[which]; } - int GetAreas(FloatRect** pAreas) const { return wrapped->GetAreas(pAreas); } - PalEntry GetSkyCapColor(bool bottom) { return wrapped->GetSkyCapColor(bottom); } + const SpritePositioningInfo& GetSpritePositioning(int which) { if (Base->spi == nullptr) SetupSpriteData(); return Base->spi[which]; } + int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); } + PalEntry GetSkyCapColor(bool bottom) { return Base->GetSkyCapColor(bottom); } bool GetTranslucency() { - return wrapped->GetTranslucency(); + return Base->GetTranslucency(); } // Since these properties will later piggyback on existing members of FGameTexture, the accessors need to be here. FGameTexture *GetSkyFace(int num) { - return (isSkybox() ? static_cast(wrapped)->faces[num] : nullptr); + return (isSkybox() ? static_cast(Base.get())->faces[num] : nullptr); } - bool GetSkyFlip() { return isSkybox() ? static_cast(wrapped)->fliptop : false; } + bool GetSkyFlip() { return isSkybox() ? static_cast(Base.get())->fliptop : false; } int GetClampMode(int clampmode) { if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; else if (isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - else if ((isWarped() || wrapped->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + else if ((isWarped() || Base->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; return clampmode; } }; diff --git a/src/common/utility/refcounted.h b/src/common/utility/refcounted.h new file mode 100644 index 0000000000..b0c87d9341 --- /dev/null +++ b/src/common/utility/refcounted.h @@ -0,0 +1,103 @@ +#pragma once + +// Simple lightweight reference counting pointer alternative for std::shared_ptr which stores the reference counter in the handled object itself. + + // Base class for handled objects +class RefCountedBase +{ +public: + void IncRef() { refCount++; } + void DecRef() { if (--refCount <= 0) delete this; } +private: + int refCount = 0; +protected: + virtual ~RefCountedBase() = default; +}; + + // The actual pointer object +template +class RefCountedPtr +{ +public: + ~RefCountedPtr() + { + if (ptr) ptr->DecRef(); + } + + RefCountedPtr() : ptr(nullptr) + {} + + explicit RefCountedPtr(T* p) : ptr(p) + { + if (ptr) ptr->IncRef(); + } + + RefCountedPtr & operator=(const RefCountedPtr& r) + { + if (ptr != r.ptr) + { + if (ptr) ptr->DecRef(); + ptr = r.ptr; + if (ptr) ptr->IncRef(); + } + return *this; + } + + RefCountedPtr& operator=(T* r) + { + if (ptr != r) + { + if (ptr) ptr->DecRef(); + ptr = r; + if (ptr) ptr->IncRef(); + } + return *this; + } + + RefCountedPtr & operator=(const RefCountedPtr&& r) + { + if (ptr) ptr->DecRef(); + ptr = r.ptr; + r.ptr = nullptr; + return *this; + } + + bool operator==(T* p) const + { + return ptr == p; + } + + bool operator!=(T* p) const + { + return ptr != p; + } + + bool operator==(const RefCountedPtr &p) const + { + return ptr == p.ptr; + } + + bool operator!=(const RefCountedPtr& p) const + { + return ptr != p.ptr; + } + + T& operator* () const + { + return *ptr; + } + + T* operator-> () const + { + return ptr; + } + + T* get() const + { + return ptr; + } + +private: + + T * ptr; +}; \ No newline at end of file From 7641da8b7bf56d91ec14a11150dd2dd2c9e7c39d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 18:52:48 +0200 Subject: [PATCH 041/220] - moved several members from FTexture to FGameTexture. --- src/common/textures/hw_material.cpp | 5 +-- src/common/textures/texture.cpp | 32 +++++++------- src/common/textures/texturemanager.cpp | 4 +- src/common/textures/textures.h | 43 +++++++++---------- src/rendering/swrenderer/r_swrenderer.cpp | 4 +- .../swrenderer/textures/r_swtexture.h | 2 +- .../swrenderer/textures/swcanvastexture.cpp | 15 +++++++ 7 files changed, 59 insertions(+), 46 deletions(-) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 41c85fccf9..9f78f5d722 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -126,7 +126,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) mScaleFlags = scaleflags; mTextureLayers.ShrinkToFit(); - imgtex->Material[scaleflags] = this; + tx->Material[scaleflags] = this; if (tx->isHardwareCanvas()) tx->SetTranslucent(false); } @@ -167,10 +167,9 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool { if (gtex && gtex->isValid()) { - auto tex = gtex->GetTexture(); if (!gtex->ShouldExpandSprite()) scaleflags &= ~CTF_Expand; - FMaterial *hwtex = tex->Material[scaleflags]; + FMaterial *hwtex = gtex->Material[scaleflags]; if (hwtex == NULL && create) { hwtex = new FMaterial(gtex, scaleflags); diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index acdba34319..fbdc663f17 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -152,17 +152,6 @@ FTexture::~FTexture () { if (areas != nullptr) delete[] areas; areas = nullptr; - - for (int i = 0; i < 2; i++) - { - if (Material[i] != nullptr) DeleteMaterial(Material[i]); - Material[i] = nullptr; - } - if (SoftwareTexture != nullptr) - { - delete SoftwareTexture; - SoftwareTexture = nullptr; - } } //=========================================================================== @@ -861,10 +850,10 @@ void FGameTexture::SetupSpriteData() { // Since this is only needed for real sprites it gets allocated on demand. // It also allocates from the image memory arena because it has the same lifetime and to reduce maintenance. - if (Base->spi == nullptr) Base->spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo)); + if (spi == nullptr) spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo)); for (int i = 0; i < 2; i++) { - auto& spi = Base->spi[i]; + auto& spi = this->spi[i]; spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f; spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f; spi.spriteWidth = GetTexelWidth(); @@ -889,7 +878,7 @@ void FGameTexture::SetupSpriteData() void FGameTexture::SetSpriteRect() { - if (!Base->spi) return; + if (!spi) return; auto leftOffset = GetLeftOffsetHW(); auto topOffset = GetTopOffsetHW(); @@ -898,7 +887,7 @@ void FGameTexture::SetSpriteRect() for (int i = 0; i < 2; i++) { - auto& spi = Base->spi[i]; + auto& spi = this->spi[i]; // mSpriteRect is for positioning the sprite in the scene. spi.mSpriteRect.left = -leftOffset / fxScale; @@ -1087,8 +1076,17 @@ FGameTexture::~FGameTexture() { FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump()); if (link == this) fileSystem.SetLinkedTexture(GetSourceLump(), nullptr); - auto str = GetName(); - Printf("Deleting texture %s\n", str.GetChars()); + if (SoftwareTexture != nullptr) + { + delete SoftwareTexture; + SoftwareTexture = nullptr; + } + for (auto &mat : Material) + { + if (mat != nullptr) DeleteMaterial(mat); + mat = nullptr; + } + } bool FGameTexture::isUserContent() const diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 8265f36172..7cc959a751 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -119,8 +119,8 @@ void FTextureManager::FlushAll() for (int j = 0; j < 2; j++) { Textures[i].Texture->GetTexture()->CleanHardwareTextures(true); - delete Textures[i].Texture->GetTexture()->SoftwareTexture; - Textures[i].Texture->GetTexture()->SoftwareTexture = nullptr; + delete Textures[i].Texture->GetSoftwareTexture(); + Textures[i].Texture->SetSoftwareTexture(nullptr); calcShouldUpscale(Textures[i].Texture); } } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 6946a4d96f..459a4d0ced 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -248,8 +248,6 @@ class FTexture : public RefCountedBase public: - SpritePositioningInfo *spi = nullptr; - IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType UseType); virtual ~FTexture (); @@ -335,16 +333,6 @@ public: static bool SmoothEdges(unsigned char * buffer,int w, int h); static PalEntry averageColor(const uint32_t *data, int size, int maxout); - - ISoftwareTexture* GetSoftwareTexture() - { - return SoftwareTexture; - } - void SetSoftwareTextue(ISoftwareTexture* swtex) - { - SoftwareTexture = swtex; - } - protected: DVector2 Scale; @@ -352,11 +340,9 @@ protected: int SourceLump; FTextureID id; - FMaterial *Material[4] = { }; public: FHardwareTextureContainer SystemTextures; protected: - ISoftwareTexture *SoftwareTexture = nullptr; protected: @@ -440,10 +426,6 @@ public: { return bTranslucent != -1 ? bTranslucent : DetermineTranslucency(); } - FMaterial* GetMaterial(int num) - { - return Material[num]; - } private: int CheckDDPK3(); @@ -610,7 +592,7 @@ class FGameTexture { friend class FMaterial; - // Material layers + // Material layers. These are shared so reference counting is used. RefCountedPtr Base; RefCountedPtr Brightmap; RefCountedPtr Detailmap; @@ -624,6 +606,10 @@ class FGameTexture int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture. ETextureType UseType = ETextureType::Wall; // This texture's primary purpose + SpritePositioningInfo* spi = nullptr; + + ISoftwareTexture* SoftwareTexture = nullptr; + FMaterial* Material[4] = { }; public: FGameTexture(FTexture* wrap) : Base(wrap) {} @@ -679,9 +665,22 @@ public: void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); } int GetSkyOffset() const { return Base->GetSkyOffset(); } FTextureID GetID() const { return Base->GetID(); } - ISoftwareTexture* GetSoftwareTexture() { return Base->GetSoftwareTexture(); } - void SetSoftwareTexture(ISoftwareTexture* swtex) { Base->SetSoftwareTextue(swtex); } void SetScale(DVector2 vec) { Base->SetScale(vec); } + + ISoftwareTexture* GetSoftwareTexture() + { + return SoftwareTexture; + } + void SetSoftwareTexture(ISoftwareTexture* swtex) + { + SoftwareTexture = swtex; + } + + FMaterial* GetMaterial(int num) + { + return Material[num]; + } + const FString& GetName() const { return Base->GetName(); } void SetShaderSpeed(float speed) { Base->shaderspeed = speed; } void SetShaderIndex(int index) { Base->shaderindex = index; } @@ -726,7 +725,7 @@ public: void SetSize(int x, int y) { Base->SetSize(x, y); } void SetDisplaySize(float w, float h) { Base->SetSize((int)w, (int)h); } - const SpritePositioningInfo& GetSpritePositioning(int which) { if (Base->spi == nullptr) SetupSpriteData(); return Base->spi[which]; } + const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; } int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); } PalEntry GetSkyCapColor(bool bottom) { return Base->GetSkyCapColor(bottom); } diff --git a/src/rendering/swrenderer/r_swrenderer.cpp b/src/rendering/swrenderer/r_swrenderer.cpp index d01d89242d..24eb810498 100644 --- a/src/rendering/swrenderer/r_swrenderer.cpp +++ b/src/rendering/swrenderer/r_swrenderer.cpp @@ -227,6 +227,8 @@ void FSoftwareRenderer::SetClearColor(int color) mScene.SetClearColor(color); } +FSWCanvasTexture* GetSWCamTex(FCanvasTexture* camtex); + void FSoftwareRenderer::RenderTextureView (FCanvasTexture *camtex, AActor *viewpoint, double fov) { auto renderTarget = mScene.MainThread()->Viewport->RenderTarget; @@ -237,7 +239,7 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *camtex, AActor *viewp cameraViewpoint = r_viewpoint; cameraViewwindow = r_viewwindow; - auto tex = static_cast(camtex->GetSoftwareTexture()); + auto tex = GetSWCamTex(camtex); DCanvas *Canvas = renderTarget->IsBgra() ? tex->GetCanvasBgra() : tex->GetCanvas(); diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index bf9a83c5a6..cfd97c2eed 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -176,7 +176,7 @@ class FSWCanvasTexture : public FSoftwareTexture public: - FSWCanvasTexture(FGameTexture *source) : FSoftwareTexture(source) {} + FSWCanvasTexture(FGameTexture* source); ~FSWCanvasTexture(); // Returns the whole texture, stored in column-major order diff --git a/src/rendering/swrenderer/textures/swcanvastexture.cpp b/src/rendering/swrenderer/textures/swcanvastexture.cpp index a9a946fce9..db9471774b 100644 --- a/src/rendering/swrenderer/textures/swcanvastexture.cpp +++ b/src/rendering/swrenderer/textures/swcanvastexture.cpp @@ -39,6 +39,21 @@ #include "m_alloc.h" #include "imagehelpers.h" +static TMap canvasMap; + +FSWCanvasTexture* GetSWCamTex(FCanvasTexture* camtex) +{ + auto p = canvasMap.CheckKey(camtex); + return p ? *p : nullptr; +} + +FSWCanvasTexture::FSWCanvasTexture(FGameTexture* source) : FSoftwareTexture(source) +{ + // The SW renderer needs to link the canvas textures, but let's do that outside the texture manager. + auto camtex = static_cast(source->GetTexture()); + canvasMap.Insert(camtex, this); +} + FSWCanvasTexture::~FSWCanvasTexture() { From d1da26895b5f76437f36d80e4bdea79151d73c8c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 19:48:24 +0200 Subject: [PATCH 042/220] - moved the texture ID up one level. --- src/common/textures/texture.cpp | 25 ++------------ src/common/textures/texturemanager.cpp | 45 ++++++++++++++++++++------ src/common/textures/textures.h | 16 +++++---- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index fbdc663f17..793285029c 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -70,36 +70,16 @@ int r_spriteadjustSW, r_spriteadjustHW; // Examines the lump contents to decide what type of texture to create, // and creates the texture. -FTexture * FTexture::CreateTexture(const char *name, int lumpnum, ETextureType usetype) +FTexture * FTexture::CreateTexture(const char *name, int lumpnum, bool allowflats) { if (lumpnum == -1) return nullptr; - auto image = FImageSource::GetImage(lumpnum, usetype == ETextureType::Flat); + auto image = FImageSource::GetImage(lumpnum, allowflats); if (image != nullptr) { FTexture *tex = new FImageTexture(image); if (tex != nullptr) { - //tex->UseType = usetype; - if (usetype == ETextureType::Flat) - { - int w = tex->GetTexelWidth(); - int h = tex->GetTexelHeight(); - - // Auto-scale flats with dimensions 128x128 and 256x256. - // In hindsight, a bad idea, but RandomLag made it sound better than it really is. - // Now we're stuck with this stupid behaviour. - if (w==128 && h==128) - { - tex->Scale.X = tex->Scale.Y = 2; - tex->bWorldPanning = true; - } - else if (w==256 && h==256) - { - tex->Scale.X = tex->Scale.Y = 4; - tex->bWorldPanning = true; - } - } tex->Name = name; tex->Name.ToUpper(); return tex; @@ -132,7 +112,6 @@ FTexture::FTexture (const char *name, int lumpnum) _LeftOffset[0] = _LeftOffset[1] = _TopOffset[0] = _TopOffset[1] = 0; - id.SetInvalid(); if (name != NULL) { Name = name; diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 7cc959a751..c267bd2cfd 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -230,7 +230,7 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset if (tex == NO_TEXTURE) return FTextureID(-1); if (tex != NULL) return tex->GetID(); if (flags & TEXMAN_DontCreate) return FTextureID(-1); // we only want to check, there's no need to create a texture if we don't have one yet. - tex = MakeGameTexture(FTexture::CreateTexture("", lump, ETextureType::Override), ETextureType::Override); + tex = MakeGameTexture(FTexture::CreateTexture("", lump), ETextureType::Override); if (tex != NULL) { tex->AddAutoMaterials(); @@ -402,7 +402,9 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture, bool addtohas int trans = Textures.Push (hasher); Translation.Push (trans); if (bucket >= 0) HashFirst[bucket] = trans; - return (texture->GetTexture()->id = FTextureID(trans)); + auto id = FTextureID(trans); + texture->SetID(id); + return id; } //========================================================================== @@ -419,9 +421,32 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype) { FString str; fileSystem.GetFileShortName(str, lumpnum); - auto out = MakeGameTexture(FTexture::CreateTexture(str, lumpnum, usetype), usetype); + auto out = MakeGameTexture(FTexture::CreateTexture(str, lumpnum, usetype == ETextureType::Flat), usetype); - if (out != NULL) return AddGameTexture (out); + if (out != NULL) + { + if (usetype == ETextureType::Flat) + { + int w = out->GetTexelWidth(); + int h = out->GetTexelHeight(); + + // Auto-scale flats with dimensions 128x128 and 256x256. + // In hindsight, a bad idea, but RandomLag made it sound better than it really is. + // Now we're stuck with this stupid behaviour. + if (w == 128 && h == 128) + { + out->SetScale(DVector2(2, 2)); + out->SetWorldPanning(true); + } + else if (w == 256 && h == 256) + { + out->SetScale(DVector2(4, 4)); + out->SetWorldPanning(true); + } + } + + return AddGameTexture(out); + } else { Printf (TEXTCOLOR_ORANGE "Invalid data encountered for texture %s\n", fileSystem.GetFileFullPath(lumpnum).GetChars()); @@ -448,7 +473,7 @@ void FTextureManager::ReplaceTexture (FTextureID picnum, FGameTexture *newtextur newtexture->GetTexture()->Name = oldtexture->GetName(); newtexture->SetUseType(oldtexture->GetUseType()); Textures[index].Texture = newtexture; - newtexture->GetTexture()->id = oldtexture->GetID(); + newtexture->SetID(oldtexture->GetID()); oldtexture->GetTexture()->Name = ""; AddGameTexture(oldtexture); } @@ -559,7 +584,7 @@ void FTextureManager::AddHiresTextures (int wadnum) if (amount == 0) { // A texture with this name does not yet exist - auto newtex = MakeGameTexture(FTexture::CreateTexture (Name, firsttx, ETextureType::Any), ETextureType::Override); + auto newtex = MakeGameTexture(FTexture::CreateTexture (Name, firsttx), ETextureType::Override); if (newtex != NULL) { AddGameTexture(newtex); @@ -569,7 +594,7 @@ void FTextureManager::AddHiresTextures (int wadnum) { for(unsigned int i = 0; i < tlist.Size(); i++) { - FTexture * newtex = FTexture::CreateTexture ("", firsttx, ETextureType::Any); + FTexture * newtex = FTexture::CreateTexture ("", firsttx); if (newtex != NULL) { auto oldtex = Textures[tlist[i].GetIndex()].Texture; @@ -668,7 +693,7 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build (sl=oldtex->GetSourceLump()) >= 0 && fileSystem.GetFileNamespace(sl) == ns_sprites) ) { - FTexture * newtex = FTexture::CreateTexture ("", lumpnum, ETextureType::Any); + FTexture * newtex = FTexture::CreateTexture ("", lumpnum); if (newtex != NULL) { // Replace the entire texture and adjust the scaling and offset factors. @@ -707,7 +732,7 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build if (lumpnum>=0) { - auto newtex = MakeGameTexture(FTexture::CreateTexture(src, lumpnum, ETextureType::Override), ETextureType::Override); + auto newtex = MakeGameTexture(FTexture::CreateTexture(src, lumpnum), ETextureType::Override); if (newtex != NULL) { @@ -927,7 +952,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b // Try to create a texture from this lump and add it. // Unfortunately we have to look at everything that comes through here... - auto out = MakeGameTexture(FTexture::CreateTexture(Name, i, ETextureType::MiscPatch), skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch); + auto out = MakeGameTexture(FTexture::CreateTexture(Name, i), skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch); if (out != NULL) { diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 459a4d0ced..ca07415ae1 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -249,12 +249,11 @@ class FTexture : public RefCountedBase public: IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); - static FTexture *CreateTexture(const char *name, int lumpnum, ETextureType UseType); + static FTexture *CreateTexture(const char *name, int lumpnum, bool allowflats = false); virtual ~FTexture (); virtual FImageSource *GetImage() const { return nullptr; } void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); void CleanHardwareTextures(bool reallyclean); - void SetSpriteRect(); // These are mainly meant for 2D code which only needs logical information about the texture to position it properly. int GetDisplayWidth() { int foo = int((Width * 2) / Scale.X); return (foo >> 1) + (foo & 1); } @@ -289,7 +288,6 @@ public: bool isMasked() const { return bMasked; } void SetSkyOffset(int offs) { SkyOffset = offs; } int GetSkyOffset() const { return SkyOffset; } - FTextureID GetID() const { return id; } PalEntry GetSkyCapColor(bool bottom); virtual int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. void GetGlowColor(float *data); @@ -338,7 +336,6 @@ protected: DVector2 Scale; int SourceLump; - FTextureID id; public: FHardwareTextureContainer SystemTextures; @@ -604,6 +601,8 @@ class FGameTexture RefCountedPtr AmbientOcclusion; // Ambient occlusion texture for PBR RefCountedPtr CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES]; // Custom texture maps for custom hardware shaders + FTextureID id; + int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture. ETextureType UseType = ETextureType::Wall; // This texture's primary purpose SpritePositioningInfo* spi = nullptr; @@ -612,8 +611,14 @@ class FGameTexture FMaterial* Material[4] = { }; public: - FGameTexture(FTexture* wrap) : Base(wrap) {} + FGameTexture(FTexture* wrap) : Base(wrap) + { + id.SetInvalid(); + } ~FGameTexture(); + FTextureID GetID() const { return id; } + void SetID(FTextureID newid) { id = newid; } // should only be called by the texture manager + void CreateDefaultBrightmap(); void AddAutoMaterials(); bool ShouldExpandSprite(); @@ -664,7 +669,6 @@ public: void SetRotations(int index) { Base->SetRotations(index); } void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); } int GetSkyOffset() const { return Base->GetSkyOffset(); } - FTextureID GetID() const { return Base->GetID(); } void SetScale(DVector2 vec) { Base->SetScale(vec); } ISoftwareTexture* GetSoftwareTexture() From c563f4993fc7833317947687556af7edf5cd8e76 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 23:22:39 +0200 Subject: [PATCH 043/220] - took the sky cap color getter out of the texture system. # Conflicts: # src/common/textures/textures.h --- src/common/textures/texture.cpp | 63 ------------------- src/common/textures/textures.h | 11 ---- src/common/utility/palette.cpp | 41 ++++++++++++ src/common/utility/palutil.h | 1 + .../hwrenderer/scene/hw_skyportal.cpp | 7 +-- .../polyrenderer/backend/poly_hwtexture.cpp | 2 - src/rendering/r_sky.cpp | 42 +++++++++++++ src/rendering/r_sky.h | 2 + src/rendering/swrenderer/plane/r_skyplane.cpp | 5 +- .../swrenderer/textures/r_swtexture.h | 1 - 10 files changed, 92 insertions(+), 83 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 793285029c..1eb280552e 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -158,69 +158,6 @@ void FTexture::SetDisplaySize(int fitwidth, int fitheight) if (int(Scale.Y * fitheight) != Height) Scale.Y += (1 / 65536.); } -//=========================================================================== -// -// Gets the average color of a texture for use as a sky cap color -// -//=========================================================================== - -PalEntry FTexture::averageColor(const uint32_t *data, int size, int maxout) -{ - int i; - unsigned int r, g, b; - - // First clear them. - r = g = b = 0; - if (size == 0) - { - return PalEntry(255, 255, 255); - } - for (i = 0; i < size; i++) - { - b += BPART(data[i]); - g += GPART(data[i]); - r += RPART(data[i]); - } - - r = r / size; - g = g / size; - b = b / size; - - int maxv = MAX(MAX(r, g), b); - - if (maxv && maxout) - { - r = ::Scale(r, maxout, maxv); - g = ::Scale(g, maxout, maxv); - b = ::Scale(b, maxout, maxv); - } - return PalEntry(255, r, g, b); -} - -PalEntry FTexture::GetSkyCapColor(bool bottom) -{ - if (!bSWSkyColorDone) - { - bSWSkyColorDone = true; - - FBitmap bitmap = GetBgraBitmap(nullptr); - int w = bitmap.GetWidth(); - int h = bitmap.GetHeight(); - - const uint32_t *buffer = (const uint32_t *)bitmap.GetPixels(); - if (buffer) - { - CeilingSkyColor = averageColor((uint32_t *)buffer, w * MIN(30, h), 0); - if (h>30) - { - FloorSkyColor = averageColor(((uint32_t *)buffer) + (h - 30)*w, w * 30, 0); - } - else FloorSkyColor = CeilingSkyColor; - } - } - return bottom ? FloorSkyColor : CeilingSkyColor; -} - //==================================================================== // // CheckRealHeight diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index ca07415ae1..0df5aaa7ba 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -288,7 +288,6 @@ public: bool isMasked() const { return bMasked; } void SetSkyOffset(int offs) { SkyOffset = offs; } int GetSkyOffset() const { return SkyOffset; } - PalEntry GetSkyCapColor(bool bottom); virtual int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. void GetGlowColor(float *data); bool isGlowing() const { return bGlowing; } @@ -329,7 +328,6 @@ public: virtual FBitmap GetBgraBitmap(const PalEntry *remap, int *trans = nullptr); static bool SmoothEdges(unsigned char * buffer,int w, int h); - static PalEntry averageColor(const uint32_t *data, int size, int maxout); protected: @@ -424,14 +422,6 @@ public: return bTranslucent != -1 ? bTranslucent : DetermineTranslucency(); } -private: - int CheckDDPK3(); - int CheckExternalFile(bool & hascolorkey); - - bool bSWSkyColorDone = false; - PalEntry FloorSkyColor; - PalEntry CeilingSkyColor; - public: void CheckTrans(unsigned char * buffer, int size, int trans); @@ -731,7 +721,6 @@ public: const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; } int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); } - PalEntry GetSkyCapColor(bool bottom) { return Base->GetSkyCapColor(bottom); } bool GetTranslucency() { diff --git a/src/common/utility/palette.cpp b/src/common/utility/palette.cpp index 5be3f6a455..f4876b4b97 100644 --- a/src/common/utility/palette.cpp +++ b/src/common/utility/palette.cpp @@ -471,6 +471,47 @@ void MakeGoodRemap(uint32_t* BaseColors, uint8_t* Remap) // 256 entries are different. :-) } +//=========================================================================== +// +// Gets the average color of a texture for use as a sky cap color +// +//=========================================================================== + +PalEntry averageColor(const uint32_t* data, int size, int maxout) +{ + int i; + unsigned int r, g, b; + + // First clear them. + r = g = b = 0; + if (size == 0) + { + return PalEntry(255, 255, 255); + } + for (i = 0; i < size; i++) + { + b += BPART(data[i]); + g += GPART(data[i]); + r += RPART(data[i]); + } + + r = r / size; + g = g / size; + b = b / size; + + int maxv = MAX(MAX(r, g), b); + + if (maxv && maxout) + { + r = ::Scale(r, maxout, maxv); + g = ::Scale(g, maxout, maxv); + b = ::Scale(b, maxout, maxv); + } + return PalEntry(255, r, g, b); +} + + + //========================================================================== // // V_GetColorFromString diff --git a/src/common/utility/palutil.h b/src/common/utility/palutil.h index 077c4c0361..b1dcca40a6 100644 --- a/src/common/utility/palutil.h +++ b/src/common/utility/palutil.h @@ -30,6 +30,7 @@ FString V_GetColorStringByName(const char* name, FScriptPosition* sc = nullptr); // Tries to get color by name, then by string int V_GetColor(const uint32_t* palette, const char* str, FScriptPosition* sc = nullptr); int V_GetColor(const uint32_t* palette, FScanner& sc); +PalEntry averageColor(const uint32_t* data, int size, int maxout); enum { diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index 79051f0ef9..a41fff53e2 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -66,13 +66,12 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * // The caps only get drawn for the main layer but not for the overlay. if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL) { - PalEntry pe = tex->GetSkyCapColor(false); - state.SetObjectColor(pe); + auto &col = R_GetSkyCapColor(tex); + state.SetObjectColor(col.first); state.EnableTexture(false); RenderRow(di, state, DT_TriangleFan, 0); - pe = tex->GetSkyCapColor(true); - state.SetObjectColor(pe); + state.SetObjectColor(col.second); RenderRow(di, state, DT_TriangleFan, rc); state.EnableTexture(true); } diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index 55a47fca97..154ef8f86c 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -64,8 +64,6 @@ void PolyHardwareTexture::Reset() DCanvas *PolyHardwareTexture::GetImage(FTexture *baselayer, const FMaterialState &state) { - FGameTexture *tex = state.mMaterial->Source(); - if (!mCanvas) { int flags = state.mMaterial->GetScaleFlags(); diff --git a/src/rendering/r_sky.cpp b/src/rendering/r_sky.cpp index 0510681626..d8d340b0ef 100644 --- a/src/rendering/r_sky.cpp +++ b/src/rendering/r_sky.cpp @@ -39,6 +39,8 @@ #include "v_text.h" #include "g_levellocals.h" #include "texturemanager.h" +#include "palentry.h" +#include "bitmap.h" // // sky mapping @@ -54,6 +56,46 @@ CUSTOM_CVAR (Int, r_skymode, 2, CVAR_ARCHIVE|CVAR_NOINITCALL) CVAR(Float, skyoffset, 0, 0) // for testing + +struct SkyColor +{ + FTextureID Texture; + std::pair Colors; +}; + +static TArray SkyColors; + +std::pair& R_GetSkyCapColor(FGameTexture* tex) +{ + for (auto& sky : SkyColors) + { + if (sky.Texture == tex->GetID()) return sky.Colors; + } + + auto itex = tex->GetTexture(); + SkyColor sky; + + FBitmap bitmap = itex->GetBgraBitmap(nullptr); + int w = bitmap.GetWidth(); + int h = bitmap.GetHeight(); + + const uint32_t* buffer = (const uint32_t*)bitmap.GetPixels(); + if (buffer) + { + sky.Colors.first = averageColor((uint32_t*)buffer, w * MIN(30, h), 0); + if (h > 30) + { + sky.Colors.second = averageColor(((uint32_t*)buffer) + (h - 30) * w, w * 30, 0); + } + else sky.Colors.second = sky.Colors.first; + } + sky.Texture = tex->GetID(); + SkyColors.Push(sky); + + return SkyColors.Last().Colors; +} + + //========================================================================== // // R_InitSkyMap diff --git a/src/rendering/r_sky.h b/src/rendering/r_sky.h index f2aa868fcb..43cd7a0ce5 100644 --- a/src/rendering/r_sky.h +++ b/src/rendering/r_sky.h @@ -28,6 +28,7 @@ #ifndef __R_SKY_H__ #define __R_SKY_H__ +#include #include "textures.h" struct FLevelLocals; @@ -41,6 +42,7 @@ extern int freelookviewheight; void InitSkyMap(FLevelLocals *Level); void R_InitSkyMap(); void R_UpdateSky (uint64_t mstime); +std::pair& R_GetSkyCapColor(FGameTexture* tex); // 57 world units roughly represent one sky texel for the glTranslate call. enum diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 5b9b60c4cc..7279c906b5 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -258,8 +258,9 @@ namespace swrenderer drawerargs.SetDest(viewport, start_x, y1); drawerargs.SetCount(y2 - y1); drawerargs.SetFadeSky(r_skymode == 2 && !(Level->flags & LEVEL_FORCETILEDSKY)); - drawerargs.SetSolidTop(frontskytex->GetSkyCapColor(false)); - drawerargs.SetSolidBottom(frontskytex->GetSkyCapColor(true)); + auto& col = R_GetSkyCapColor(frontskytex->GetTexture()); + drawerargs.SetSolidTop(col.first); + drawerargs.SetSolidBottom(col.second); if (!backskytex) drawerargs.DrawSingleSkyColumn(Thread); diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index cfd97c2eed..3e462d36e0 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -62,7 +62,6 @@ public: } int GetSkyOffset() const { return mTexture->GetSkyOffset(); } - PalEntry GetSkyCapColor(bool bottom) const { return mSource->GetSkyCapColor(bottom); } int GetWidth () { return mTexture->GetTexelWidth(); } int GetHeight () { return mTexture->GetTexelHeight(); } From 9bc1d4f38fb22b3d3f0083a589f5cef4bc757dc3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 23:35:42 +0200 Subject: [PATCH 044/220] - restored null texture setup. --- src/common/textures/texturemanager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index c267bd2cfd..9a32947ef8 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -1118,6 +1118,9 @@ void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildI DeleteAll(); //if (BuildTileFiles.Size() == 0) CountBuildTiles (); + auto nulltex = MakeGameTexture(new FImageTexture(CreateEmptyTexture(), ""), ETextureType::Null); + AddGameTexture(nulltex); + // This is for binding to unused texture units, because accessing an unbound texture unit is undefined. It's a one pixel empty texture. auto emptytex = MakeGameTexture(new FImageTexture(CreateEmptyTexture(), ""), ETextureType::Override); emptytex->SetSize(1, 1); From 8843761bf8042636081fe03228bb5dd2747484c1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 21:32:09 +0200 Subject: [PATCH 045/220] - moved most of the texture size maintenance to the FGameTexture class. --- src/common/textures/texture.cpp | 36 ++++++------- src/common/textures/texturemanager.cpp | 27 +++++----- src/common/textures/textures.h | 51 +++++++++++++------ src/d_main.cpp | 11 ++-- src/gamedata/textures/animations.cpp | 4 +- src/rendering/gl/renderer/gl_renderer.cpp | 8 +-- src/rendering/gl/textures/gl_hwtexture.cpp | 4 +- .../polyrenderer/backend/poly_framebuffer.cpp | 6 +-- .../polyrenderer/backend/poly_hwtexture.cpp | 8 +-- .../vulkan/system/vk_framebuffer.cpp | 6 +-- .../vulkan/textures/vk_hwtexture.cpp | 8 +-- 11 files changed, 96 insertions(+), 73 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 1eb280552e..ffed1cc0e9 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -171,11 +171,11 @@ int FTexture::CheckRealHeight() { auto pixels = Get8BitPixels(false); - for(int h = GetTexelHeight()-1; h>= 0; h--) + for(int h = GetHeight()-1; h>= 0; h--) { - for(int w = 0; w < GetTexelWidth(); w++) + for(int w = 0; w < GetWidth(); w++) { - if (pixels[h + w * GetTexelHeight()] != 0) + if (pixels[h + w * GetHeight()] != 0) { // Scale maxy before returning it h = int((h * 2) / Scale.Y); @@ -262,7 +262,7 @@ void FGameTexture::CreateDefaultBrightmap() auto texbuf = tex->Get8BitPixels(false); const int white = ColorMatcher.Pick(255, 255, 255); - int size = GetTexelWidth() * GetTexelHeight(); + int size = tex->GetWidth() * tex->GetHeight(); for (int i = 0; ibExpandSprite = false; return false; } - if (Brightmap != NULL && (GetTexelWidth() != Brightmap->GetTexelWidth() || GetTexelHeight() != Brightmap->GetTexelHeight())) + if (Brightmap != NULL && (Base->GetWidth() != Brightmap->GetWidth() || Base->GetHeight() != Brightmap->GetHeight())) { // do not expand if the brightmap's size differs. Base->bExpandSprite = false; @@ -927,17 +927,17 @@ float FTexCoordInfo::TextureAdjustWidth() const // //=========================================================================== -void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y, bool forceworldpanning) +void FTexCoordInfo::GetFromTexture(FGameTexture *tex, float x, float y, bool forceworldpanning) { if (x == 1.f) { - mRenderWidth = tex->GetDisplayWidth(); - mScale.X = (float)tex->Scale.X; + mRenderWidth = xs_RoundToInt(tex->GetDisplayWidth()); + mScale.X = tex->GetScaleX(); mTempScale.X = 1.f; } else { - float scale_x = x * (float)tex->Scale.X; + float scale_x = x * tex->GetScaleX(); mRenderWidth = xs_CeilToInt(tex->GetTexelWidth() / scale_x); mScale.X = scale_x; mTempScale.X = x; @@ -945,30 +945,26 @@ void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y, bool forcewo if (y == 1.f) { - mRenderHeight = tex->GetDisplayHeight(); - mScale.Y = (float)tex->Scale.Y; + mRenderHeight = xs_RoundToInt(tex->GetDisplayHeight()); + mScale.Y = tex->GetScaleY(); mTempScale.Y = 1.f; } else { - float scale_y = y * (float)tex->Scale.Y; + float scale_y = y * tex->GetScaleY(); mRenderHeight = xs_CeilToInt(tex->GetTexelHeight() / scale_y); mScale.Y = scale_y; mTempScale.Y = y; } - if (tex->bHasCanvas) + if (tex->isHardwareCanvas()) { mScale.Y = -mScale.Y; mRenderHeight = -mRenderHeight; } - mWorldPanning = tex->bWorldPanning || forceworldpanning; + mWorldPanning = tex->useWorldPanning() || forceworldpanning; mWidth = tex->GetTexelWidth(); } -void FTexCoordInfo::GetFromTexture(FGameTexture* tex, float x, float y, bool forceworldpanning) -{ - GetFromTexture(tex->GetTexture(), x, y, forceworldpanning); -} //========================================================================== // diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 9a32947ef8..f4ffd18695 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -600,13 +600,14 @@ void FTextureManager::AddHiresTextures (int wadnum) auto oldtex = Textures[tlist[i].GetIndex()].Texture; // Replace the entire texture and adjust the scaling and offset factors. - newtex->bWorldPanning = true; - newtex->SetDisplaySize((int)oldtex->GetDisplayWidth(), (int)oldtex->GetDisplayHeight()); newtex->_LeftOffset[0] = int(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X); newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); - ReplaceTexture(tlist[i], MakeGameTexture(newtex, ETextureType::Override), true); + auto gtex = MakeGameTexture(newtex, ETextureType::Override); + gtex->SetWorldPanning(true); + gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); + ReplaceTexture(tlist[i], gtex, true); } } } @@ -697,13 +698,14 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build if (newtex != NULL) { // Replace the entire texture and adjust the scaling and offset factors. - newtex->bWorldPanning = true; - newtex->SetDisplaySize((int)oldtex->GetDisplayWidth(), (int)oldtex->GetDisplayHeight()); newtex->_LeftOffset[0] = int(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X); newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); - ReplaceTexture(tlist[i], MakeGameTexture(newtex, ETextureType::Override), true); + auto gtex = MakeGameTexture(newtex, ETextureType::Override); + gtex->SetWorldPanning(true); + gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); + ReplaceTexture(tlist[i], gtex, true); } } } @@ -1216,10 +1218,10 @@ FTextureID FTextureManager::GetRawTexture(FTextureID texid) // Reject anything that cannot have been a front layer for the sky in original Hexen, i.e. it needs to be an unscaled wall texture only using Doom patches. auto tex = Textures[texidx].Texture; auto ttex = tex->GetTexture(); - auto image = tex->GetTexture()->GetImage(); + auto image = ttex->GetImage(); // Reject anything that cannot have been a single-patch multipatch texture in vanilla. - if (image == nullptr || image->IsRawCompatible() || tex->GetUseType() != ETextureType::Wall || tex->GetTexelWidth() != tex->GetDisplayWidth() || - tex->GetTexelHeight() != tex->GetDisplayHeight()) + if (image == nullptr || image->IsRawCompatible() || tex->GetUseType() != ETextureType::Wall || ttex->GetWidth() != tex->GetDisplayWidth() || + ttex->GetHeight() != tex->GetDisplayHeight()) { Textures[texidx].RawTexture = texidx; return texid; @@ -1230,7 +1232,7 @@ FTextureID FTextureManager::GetRawTexture(FTextureID texid) auto source = mptimage->GetImageForPart(0); // Size must match for this to work as intended - if (source->GetWidth() != tex->GetTexelWidth() || source->GetHeight() != tex->GetTexelHeight()) + if (source->GetWidth() != ttex->GetWidth() || source->GetHeight() != ttex->GetHeight()) { Textures[texidx].RawTexture = texidx; return texid; @@ -1259,9 +1261,10 @@ FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid) // Reject anything that cannot have been a front layer for the sky in original Hexen, i.e. it needs to be an unscaled wall texture only using Doom patches. auto tex = Textures[texidx].Texture; - auto image = tex->GetTexture()->GetImage(); + auto ttex = tex->GetTexture(); + auto image = ttex->GetImage(); if (image == nullptr || !image->SupportRemap0() || tex->GetUseType() != ETextureType::Wall || tex->useWorldPanning() || tex->GetTexelTopOffset() != 0 || - tex->GetTexelWidth() != tex->GetDisplayWidth() || tex->GetTexelHeight() != tex->GetDisplayHeight()) + ttex->GetWidth() != tex->GetDisplayWidth() || ttex->GetHeight() != tex->GetDisplayHeight()) { Textures[texidx].FrontSkyLayer = texidx; return texid; diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 0df5aaa7ba..e01005ada7 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -256,17 +256,13 @@ public: void CleanHardwareTextures(bool reallyclean); // These are mainly meant for 2D code which only needs logical information about the texture to position it properly. - int GetDisplayWidth() { int foo = int((Width * 2) / Scale.X); return (foo >> 1) + (foo & 1); } - int GetDisplayHeight() { int foo = int((Height * 2) / Scale.Y); return (foo >> 1) + (foo & 1); } - double GetDisplayWidthDouble() { return Width / Scale.X; } - double GetDisplayHeightDouble() { return Height / Scale.Y; } int GetDisplayLeftOffset() { return GetScaledLeftOffset(0); } int GetDisplayTopOffset() { return GetScaledTopOffset(0); } double GetDisplayLeftOffsetDouble(int adjusted = 0) { return _LeftOffset[adjusted] / Scale.X; } double GetDisplayTopOffsetDouble(int adjusted = 0) { return _TopOffset[adjusted] / Scale.Y; } - int GetTexelWidth() { return Width; } - int GetTexelHeight() { return Height; } + int GetWidth() { return Width; } + int GetHeight() { return Height; } int GetTexelLeftOffset(int adjusted) { return _LeftOffset[adjusted]; } int GetTexelTopOffset(int adjusted) { return _TopOffset[adjusted]; } @@ -304,8 +300,8 @@ public: void CopySize(FTexture* BaseTexture) { - Width = BaseTexture->GetTexelWidth(); - Height = BaseTexture->GetTexelHeight(); + Width = BaseTexture->GetWidth(); + Height = BaseTexture->GetHeight(); _TopOffset[0] = BaseTexture->_TopOffset[0]; _TopOffset[1] = BaseTexture->_TopOffset[1]; _LeftOffset[0] = BaseTexture->_LeftOffset[0]; @@ -330,7 +326,6 @@ public: static bool SmoothEdges(unsigned char * buffer,int w, int h); protected: - DVector2 Scale; int SourceLump; @@ -447,6 +442,7 @@ public: bHasCanvas = true; bTranslucent = false; bExpandSprite = false; + aspectRatio = (float)width / height; } void NeedUpdate() { bNeedsUpdate = true; } @@ -458,6 +454,7 @@ protected: bool bNeedsUpdate = true; public: bool bFirstUpdate = true; + float aspectRatio; friend struct FCanvasTextureInfo; }; @@ -529,7 +526,6 @@ struct FTexCoordInfo float RowOffset(float ofs) const; float TextureOffset(float ofs) const; float TextureAdjustWidth() const; - void GetFromTexture(FTexture *tex, float x, float y, bool forceworldpanning); void GetFromTexture(FGameTexture* tex, float x, float y, bool forceworldpanning); }; @@ -593,6 +589,10 @@ class FGameTexture FTextureID id; + uint16_t TexelWidth, TexelHeight; + float DisplayWidth, DisplayHeight; + float ScaleX, ScaleY; + int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture. ETextureType UseType = ETextureType::Wall; // This texture's primary purpose SpritePositioningInfo* spi = nullptr; @@ -604,11 +604,23 @@ public: FGameTexture(FTexture* wrap) : Base(wrap) { id.SetInvalid(); + TexelWidth = Base->GetWidth(); + DisplayWidth = (float)TexelWidth; + TexelHeight = Base->GetHeight(); + DisplayHeight = (float)TexelHeight; + ScaleX = ScaleY = 1.f; } ~FGameTexture(); FTextureID GetID() const { return id; } void SetID(FTextureID newid) { id = newid; } // should only be called by the texture manager + float GetScaleX() { return ScaleX; } + float GetScaleY() { return ScaleY; } + float GetDisplayWidth() const { return DisplayWidth; } + float GetDisplayHeight() const { return DisplayHeight; } + int GetTexelWidth() const { return TexelWidth; } + int GetTexelHeight() const { return TexelHeight; } + void CreateDefaultBrightmap(); void AddAutoMaterials(); bool ShouldExpandSprite(); @@ -623,10 +635,6 @@ public: int GetSourceLump() const { return Base->GetSourceLump(); } void SetBrightmap(FGameTexture* tex) { Brightmap = tex->GetTexture(); } - double GetDisplayWidth() /*const*/ { return Base->GetDisplayWidthDouble(); } - double GetDisplayHeight() /*const*/ { return Base->GetDisplayHeightDouble(); } - int GetTexelWidth() /*const*/ { return Base->GetTexelWidth(); } - int GetTexelHeight() /*const*/ { return Base->GetTexelHeight(); } int GetTexelLeftOffset(int adjusted = 0) /*const*/ { return Base->GetTexelLeftOffset(adjusted); } int GetTexelTopOffset(int adjusted = 0) /*const*/ { return Base->GetTexelTopOffset(adjusted); } double GetDisplayLeftOffset(int adjusted = 0) /*const*/ { return Base->GetDisplayLeftOffsetDouble(adjusted); } @@ -716,8 +724,19 @@ public: bool isUserContent() const; int CheckRealHeight() { return Base->CheckRealHeight(); } bool isSkybox() const { return Base->isSkybox(); } - void SetSize(int x, int y) { Base->SetSize(x, y); } - void SetDisplaySize(float w, float h) { Base->SetSize((int)w, (int)h); } + void SetSize(int x, int y) + { + TexelWidth = x; + TexelHeight = y; + SetDisplaySize(float(x), float(y)); + } + void SetDisplaySize(float w, float h) + { + DisplayWidth = w; + DisplayHeight = h; + ScaleX = w / TexelWidth; + ScaleY = h / TexelHeight; + } const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; } int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); } diff --git a/src/d_main.cpp b/src/d_main.cpp index 11f5517c72..eb8a22a0fc 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2670,10 +2670,13 @@ static void CheckForHacks(BuildInfo& buildinfo) buildinfo.Name[2] == 'Y' && buildinfo.Name[3] >= '1' && buildinfo.Name[3] <= '3' && - buildinfo.Height == 128) - { - buildinfo.Height = 200; - buildinfo.texture->SetSize(buildinfo.texture->GetTexelWidth(), 200); + buildinfo.Height == 128 && + buildinfo.Parts.Size() == 1) + { + // This must alter the size of both the texture image and the game texture. + buildinfo.Height = buildinfo.Parts[0].Image->GetHeight(); + buildinfo.texture->GetTexture()->SetSize(buildinfo.texture->GetTexelWidth(), buildinfo.Height); + buildinfo.texture->SetSize(buildinfo.texture->GetTexelWidth(), buildinfo.Height); return; } diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index c9104b66f8..8db6537d9f 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -709,7 +709,8 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) sc.MustGetNumber (); height = sc.Number; FTextureID picnum = TexMan.CheckForTexture (picname, ETextureType::Flat, texflags); - FGameTexture *viewer = MakeGameTexture(new FCanvasTexture (picname, width, height), ETextureType::Wall); + auto canvas = new FCanvasTexture(picname, width, height); + FGameTexture *viewer = MakeGameTexture(canvas, ETextureType::Wall); if (picnum.Exists()) { auto oldtex = TexMan.GameTexture(picnum); @@ -750,6 +751,7 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) sc.UnGet(); } } + canvas->aspectRatio = (float)fitwidth / (float)fitheight; viewer->SetDisplaySize((float)fitwidth, (float)fitheight); } diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 23380de8b9..5858ae938b 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -306,7 +306,7 @@ void FGLRenderer::BindToFrameBuffer(FTexture *tex) FHardwareTexture::Unbind(0); gl_RenderState.ClearLastMaterial(); } - BaseLayer->BindToFrameBuffer(tex->GetTexelWidth(), tex->GetTexelHeight()); + BaseLayer->BindToFrameBuffer(tex->GetWidth(), tex->GetHeight()); } //=========================================================================== @@ -319,15 +319,15 @@ void FGLRenderer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, doub { // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. - float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); + float ratio = tex->aspectRatio; StartOffscreen(); BindToFrameBuffer(tex); IntRect bounds; bounds.left = bounds.top = 0; - bounds.width = FHardwareTexture::GetTexDimension(tex->GetTexelWidth()); - bounds.height = FHardwareTexture::GetTexDimension(tex->GetTexelHeight()); + bounds.width = FHardwareTexture::GetTexDimension(tex->GetWidth()); + bounds.height = FHardwareTexture::GetTexDimension(tex->GetHeight()); FRenderViewpoint texvp; RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); diff --git a/src/rendering/gl/textures/gl_hwtexture.cpp b/src/rendering/gl/textures/gl_hwtexture.cpp index f3743571eb..c363d2fb7e 100644 --- a/src/rendering/gl/textures/gl_hwtexture.cpp +++ b/src/rendering/gl/textures/gl_hwtexture.cpp @@ -337,8 +337,8 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i } else { - w = tex->GetTexelWidth(); - h = tex->GetTexelHeight(); + w = tex->GetWidth(); + h = tex->GetHeight(); } if (!CreateTexture(texbuffer.mBuffer, w, h, texunit, needmipmap, "FHardwareTexture.BindOrCreate")) { diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 63eea8f2c7..0731cfd2bf 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -379,15 +379,15 @@ void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, // 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(tex->GetHardwareTexture(0, 0)); - float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); + float ratio = tex->aspectRatio; DCanvas *image = BaseLayer->GetImage(tex, 0, 0); PolyDepthStencil *depthStencil = BaseLayer->GetDepthStencil(tex); mRenderState->SetRenderTarget(image, depthStencil, false); IntRect bounds; bounds.left = bounds.top = 0; - bounds.width = std::min(tex->GetTexelWidth(), image->GetWidth()); - bounds.height = std::min(tex->GetTexelHeight(), image->GetHeight()); + bounds.width = std::min(tex->GetWidth(), image->GetWidth()); + bounds.height = std::min(tex->GetHeight(), image->GetHeight()); FRenderViewpoint texvp; RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index 154ef8f86c..7e5ec45528 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -84,8 +84,8 @@ PolyDepthStencil *PolyHardwareTexture::GetDepthStencil(FTexture *tex) { if (!mDepthStencil) { - int w = tex->GetTexelWidth(); - int h = tex->GetTexelHeight(); + int w = tex->GetWidth(); + int h = tex->GetHeight(); mDepthStencil.reset(new PolyDepthStencil(w, h)); } return mDepthStencil.get(); @@ -148,8 +148,8 @@ void PolyHardwareTexture::CreateImage(FTexture *tex, int translation, int flags) } else { - int w = tex->GetTexelWidth(); - int h = tex->GetTexelHeight(); + int w = tex->GetWidth(); + int h = tex->GetHeight(); mCanvas->Resize(w, h, false); } } diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 460a180dbb..83c43b6766 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -517,7 +517,7 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint { auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); - float ratio = (float)tex->GetDisplayWidthDouble() / (float)tex->GetDisplayHeightDouble(); + float ratio = tex->aspectRatio; VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0); VkTextureImage *depthStencil = BaseLayer->GetDepthStencil(tex); @@ -531,8 +531,8 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint IntRect bounds; bounds.left = bounds.top = 0; - bounds.width = std::min(tex->GetTexelWidth(), image->Image->width); - bounds.height = std::min(tex->GetTexelHeight(), image->Image->height); + bounds.width = std::min(tex->GetWidth(), image->Image->width); + bounds.height = std::min(tex->GetHeight(), image->Image->height); FRenderViewpoint texvp; RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index e3c81054cc..3499cce3d8 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -172,8 +172,8 @@ VkTextureImage *VkHardwareTexture::GetDepthStencil(FTexture *tex) auto fb = GetVulkanFrameBuffer(); VkFormat format = fb->GetBuffers()->SceneDepthStencilFormat; - int w = tex->GetTexelWidth(); - int h = tex->GetTexelHeight(); + int w = tex->GetWidth(); + int h = tex->GetHeight(); ImageBuilder builder; builder.setSize(w, h); @@ -208,8 +208,8 @@ void VkHardwareTexture::CreateImage(FTexture *tex, int translation, int flags) auto fb = GetVulkanFrameBuffer(); VkFormat format = VK_FORMAT_R8G8B8A8_UNORM; - int w = tex->GetTexelWidth(); - int h = tex->GetTexelHeight(); + int w = tex->GetWidth(); + int h = tex->GetHeight(); ImageBuilder imgbuilder; imgbuilder.setFormat(format); From 61380fc505098ab61e7f9c4ff26d01e780842f36 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 22:30:25 +0200 Subject: [PATCH 046/220] - moved the offsets to FGameTexture. # Conflicts: # src/common/textures/textures.h --- src/common/fonts/font.cpp | 10 ++-- src/common/textures/imagetexture.cpp | 4 -- .../textures/multipatchtexturebuilder.cpp | 11 ++-- src/common/textures/texture.cpp | 9 ++- src/common/textures/texturemanager.cpp | 19 +++--- src/common/textures/textures.h | 58 ++++++------------- 6 files changed, 37 insertions(+), 74 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index e9ad0fb4c4..9543c5363e 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -290,7 +290,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla if ((int)position < minchar) minchar = (int)position; if ((int)position > maxchar) maxchar = (int)position; auto tex = TexMan.GetGameTexture(lump); - tex->SetScale(Scale); + tex->SetScale((float)Scale.X, (float)Scale.Y); charMap.Insert((int)position, tex); Type = Folder; } @@ -412,17 +412,15 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false); FImageTexture *tex = new FImageTexture(image, ""); tex->bMultiPatch = true; - tex->_LeftOffset[0] = - tex->_LeftOffset[1] = - tex->_TopOffset[0] = - tex->_TopOffset[1] = 0; - tex->Scale = Scale; tex->bMasked = true; tex->bTranslucent = -1; tex->bWorldPanning = true; tex->bNoDecals = false; tex->SourceLump = -1; // We do not really care. auto gtex = MakeGameTexture(tex, ETextureType::FontChar); + gtex->SetOffsets(0, 0, 0); + gtex->SetOffsets(1, 0, 0); + gtex->SetScale((float)Scale.X, (float)Scale.Y); TexMan.AddGameTexture(gtex); charMap.Insert(int(position) + x + y * numtex_x, gtex); } diff --git a/src/common/textures/imagetexture.cpp b/src/common/textures/imagetexture.cpp index fa70f3b557..ba4179b8ab 100644 --- a/src/common/textures/imagetexture.cpp +++ b/src/common/textures/imagetexture.cpp @@ -64,10 +64,6 @@ void FImageTexture::SetFromImage() Width = img->GetWidth(); Height = img->GetHeight(); - auto offsets = img->GetOffsets(); - _LeftOffset[1] = _LeftOffset[0] = offsets.first; - _TopOffset[1] = _TopOffset[0] = offsets.second; - bMasked = img->bMasked; bTranslucent = img->bTranslucent; } diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index b62a30916c..2c1ce45fe6 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -140,18 +140,17 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u FImageTexture *tex = new FImageTexture(nullptr, buildinfo.Name); tex->bMultiPatch = true; tex->SetSize(buildinfo.Width, buildinfo.Height); - tex->_LeftOffset[0] = buildinfo.LeftOffset[0]; - tex->_LeftOffset[1] = buildinfo.LeftOffset[1]; - tex->_TopOffset[0] = buildinfo.TopOffset[0]; - tex->_TopOffset[1] = buildinfo.TopOffset[1]; - tex->Scale = buildinfo.Scale; tex->bMasked = true; // we do not really know yet. tex->bTranslucent = -1; - tex->bWorldPanning = buildinfo.bWorldPanning; tex->bNoDecals = buildinfo.bNoDecals; tex->SourceLump = buildinfo.DefinitionLump; buildinfo.itex = tex; buildinfo.texture = MakeGameTexture(tex, usetype); + buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); + buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); + buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X); + buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning); + TexMan.AddGameTexture(buildinfo.texture); } diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index ffed1cc0e9..eb050ac6cd 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -111,7 +111,6 @@ FTexture::FTexture (const char *name, int lumpnum) bTranslucent = -1; - _LeftOffset[0] = _LeftOffset[1] = _TopOffset[0] = _TopOffset[1] = 0; if (name != NULL) { Name = name; @@ -795,11 +794,11 @@ void FGameTexture::SetSpriteRect() { if (!spi) return; - auto leftOffset = GetLeftOffsetHW(); - auto topOffset = GetTopOffsetHW(); + auto leftOffset = GetTexelLeftOffset(r_spriteadjustHW); + auto topOffset = GetTexelTopOffset(r_spriteadjustHW); - float fxScale = (float)Base->Scale.X; - float fyScale = (float)Base->Scale.Y; + float fxScale = GetScaleX(); + float fyScale = GetScaleY(); for (int i = 0; i < 2; i++) { diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index f4ffd18695..157e83e0a3 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -435,12 +435,12 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype) // Now we're stuck with this stupid behaviour. if (w == 128 && h == 128) { - out->SetScale(DVector2(2, 2)); + out->SetScale(2, 2); out->SetWorldPanning(true); } else if (w == 256 && h == 256) { - out->SetScale(DVector2(4, 4)); + out->SetScale(4, 4); out->SetWorldPanning(true); } } @@ -600,12 +600,10 @@ void FTextureManager::AddHiresTextures (int wadnum) auto oldtex = Textures[tlist[i].GetIndex()].Texture; // Replace the entire texture and adjust the scaling and offset factors. - newtex->_LeftOffset[0] = int(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X); - newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); - newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); - newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); auto gtex = MakeGameTexture(newtex, ETextureType::Override); gtex->SetWorldPanning(true); + gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y)); + gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y)); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); ReplaceTexture(tlist[i], gtex, true); } @@ -698,12 +696,10 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build if (newtex != NULL) { // Replace the entire texture and adjust the scaling and offset factors. - newtex->_LeftOffset[0] = int(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X); - newtex->_LeftOffset[1] = int(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X); - newtex->_TopOffset[0] = int(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y); - newtex->_TopOffset[1] = int(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y); auto gtex = MakeGameTexture(newtex, ETextureType::Override); gtex->SetWorldPanning(true); + gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y)); + gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y)); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); ReplaceTexture(tlist[i], gtex, true); } @@ -1471,8 +1467,7 @@ void FTextureManager::AdjustSpriteOffsets() memcpy(&sprid, tex->GetName().GetChars(), 4); if (donotprocess.CheckKey(sprid)) continue; // do not alter sprites that only get partially replaced. } - tex->GetTexture()->_LeftOffset[1] = x; - tex->GetTexture()->_TopOffset[1] = y; + tex->SetOffsets(1, x, y); } } } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index e01005ada7..99bb97e96a 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -255,17 +255,8 @@ public: void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); void CleanHardwareTextures(bool reallyclean); - // These are mainly meant for 2D code which only needs logical information about the texture to position it properly. - int GetDisplayLeftOffset() { return GetScaledLeftOffset(0); } - int GetDisplayTopOffset() { return GetScaledTopOffset(0); } - double GetDisplayLeftOffsetDouble(int adjusted = 0) { return _LeftOffset[adjusted] / Scale.X; } - double GetDisplayTopOffsetDouble(int adjusted = 0) { return _TopOffset[adjusted] / Scale.Y; } - int GetWidth() { return Width; } int GetHeight() { return Height; } - int GetTexelLeftOffset(int adjusted) { return _LeftOffset[adjusted]; } - int GetTexelTopOffset(int adjusted) { return _TopOffset[adjusted]; } - bool isSkybox() const { return bSkybox; } bool isFullbrightDisabled() const { return bDisableFullbright; } @@ -302,10 +293,6 @@ public: { Width = BaseTexture->GetWidth(); Height = BaseTexture->GetHeight(); - _TopOffset[0] = BaseTexture->_TopOffset[0]; - _TopOffset[1] = BaseTexture->_TopOffset[1]; - _LeftOffset[0] = BaseTexture->_LeftOffset[0]; - _LeftOffset[1] = BaseTexture->_LeftOffset[1]; Scale = BaseTexture->Scale; } @@ -376,25 +363,6 @@ protected: float shaderspeed = 1.f; int shaderindex = 0; - int GetScaledWidth () { int foo = int((Width * 2) / Scale.X); return (foo >> 1) + (foo & 1); } - int GetScaledHeight () { int foo = int((Height * 2) / Scale.Y); return (foo >> 1) + (foo & 1); } - double GetScaledWidthDouble () { return Width / Scale.X; } - double GetScaledHeightDouble () { return Height / Scale.Y; } - double GetScaleY() const { return Scale.Y; } - - // Now with improved offset adjustment. - int GetLeftOffset(int adjusted) { return _LeftOffset[adjusted]; } - int GetTopOffset(int adjusted) { return _TopOffset[adjusted]; } - int GetScaledLeftOffset (int adjusted) { int foo = int((_LeftOffset[adjusted] * 2) / Scale.X); return (foo >> 1) + (foo & 1); } - int GetScaledTopOffset (int adjusted) { int foo = int((_TopOffset[adjusted] * 2) / Scale.Y); return (foo >> 1) + (foo & 1); } - - // Interfaces for the different renderers. Everything that needs to check renderer-dependent offsets - // should use these, so that if changes are needed, this is the only place to edit. - - // For the hardware renderer. The software renderer's have been offloaded to FSoftwareTexture - int GetLeftOffsetHW() { return _LeftOffset[r_spriteadjustHW]; } - int GetTopOffsetHW() { return _TopOffset[r_spriteadjustHW]; } - virtual void ResolvePatches() {} public: @@ -405,7 +373,6 @@ public: protected: uint16_t Width, Height; - int16_t _LeftOffset[2], _TopOffset[2]; FTexture (const char *name = NULL, int lumpnum = -1); @@ -590,6 +557,7 @@ class FGameTexture FTextureID id; uint16_t TexelWidth, TexelHeight; + int16_t LeftOffset[2], TopOffset[2]; float DisplayWidth, DisplayHeight; float ScaleX, ScaleY; @@ -635,13 +603,10 @@ public: int GetSourceLump() const { return Base->GetSourceLump(); } void SetBrightmap(FGameTexture* tex) { Brightmap = tex->GetTexture(); } - int GetTexelLeftOffset(int adjusted = 0) /*const*/ { return Base->GetTexelLeftOffset(adjusted); } - int GetTexelTopOffset(int adjusted = 0) /*const*/ { return Base->GetTexelTopOffset(adjusted); } - double GetDisplayLeftOffset(int adjusted = 0) /*const*/ { return Base->GetDisplayLeftOffsetDouble(adjusted); } - double GetDisplayTopOffset(int adjusted = 0) /*const*/ { return Base->GetDisplayTopOffsetDouble(adjusted); } - // For the hardware renderer. The software renderer's have been offloaded to FSoftwareTexture - int GetLeftOffsetHW() { return GetTexelLeftOffset(r_spriteadjustHW); } - int GetTopOffsetHW() { return GetTexelTopOffset(r_spriteadjustHW); } + int GetTexelLeftOffset(int adjusted = 0) const { return LeftOffset[adjusted]; } + int GetTexelTopOffset(int adjusted = 0) const { return TopOffset[adjusted]; } + float GetDisplayLeftOffset(int adjusted = 0) const { return LeftOffset[adjusted] / ScaleX; } + float GetDisplayTopOffset(int adjusted = 0) const { return TopOffset[adjusted] / ScaleY; } bool isValid() const { return UseType != ETextureType::Null; } int isWarped() { return Base->isWarped(); } @@ -667,7 +632,6 @@ public: void SetRotations(int index) { Base->SetRotations(index); } void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); } int GetSkyOffset() const { return Base->GetSkyOffset(); } - void SetScale(DVector2 vec) { Base->SetScale(vec); } ISoftwareTexture* GetSoftwareTexture() { @@ -737,6 +701,18 @@ public: ScaleX = w / TexelWidth; ScaleY = h / TexelHeight; } + void SetOffsets(int which, int x, int y) + { + LeftOffset[which] = x; + TopOffset[which] = y; + } + void SetScale(float x, float y) + { + ScaleX = x; + ScaleY = y; + DisplayWidth = x * TexelWidth; + DisplayHeight = y * TexelHeight; + } const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; } int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); } From eb369dbf4161fcf2177f7178492ba9ae85daf8c6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Apr 2020 23:50:30 +0200 Subject: [PATCH 047/220] - initialize texture offsets for images on construction. --- src/common/textures/texture.cpp | 24 ++++++++++++++++++++++++ src/common/textures/textures.h | 10 +--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index eb050ac6cd..83e31f00f7 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -983,6 +983,30 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) } +FGameTexture::FGameTexture(FTexture* wrap) : Base(wrap) +{ + id.SetInvalid(); + TexelWidth = Base->GetWidth(); + DisplayWidth = (float)TexelWidth; + TexelHeight = Base->GetHeight(); + DisplayHeight = (float)TexelHeight; + auto img = Base->GetImage(); + if (img) + { + auto ofs = img->GetOffsets(); + LeftOffset[0] = LeftOffset[1] = ofs.first; + TopOffset[0] = TopOffset[1] = ofs.second; + } + else + { + LeftOffset[0] = LeftOffset[1] = + TopOffset[0] = TopOffset[1] = 0; + + } + ScaleX = ScaleY = 1.f; +} + + FGameTexture::~FGameTexture() { FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump()); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 99bb97e96a..a24e3b3c40 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -569,15 +569,7 @@ class FGameTexture FMaterial* Material[4] = { }; public: - FGameTexture(FTexture* wrap) : Base(wrap) - { - id.SetInvalid(); - TexelWidth = Base->GetWidth(); - DisplayWidth = (float)TexelWidth; - TexelHeight = Base->GetHeight(); - DisplayHeight = (float)TexelHeight; - ScaleX = ScaleY = 1.f; - } + FGameTexture(FTexture* wrap); ~FGameTexture(); FTextureID GetID() const { return id; } void SetID(FTextureID newid) { id = newid; } // should only be called by the texture manager From 7dd108c960f8858a937e2354b814e939d5bec7c7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 00:15:57 +0200 Subject: [PATCH 048/220] - removed FTexture's Scale variable. --- src/common/textures/texture.cpp | 14 +------------- src/common/textures/texturemanager.cpp | 8 ++++---- src/common/textures/textures.h | 24 +++++++++--------------- 3 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 83e31f00f7..0e699a52ca 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -96,7 +96,7 @@ FTexture * FTexture::CreateTexture(const char *name, int lumpnum, bool allowflat FTexture::FTexture (const char *name, int lumpnum) : - Scale(1,1), SourceLump(lumpnum), + SourceLump(lumpnum), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bFullNameTexture(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) @@ -148,15 +148,6 @@ FBitmap FTexture::GetBgraBitmap(const PalEntry *remap, int *ptrans) return bmp; } -void FTexture::SetDisplaySize(int fitwidth, int fitheight) -{ - Scale.X = double(Width) / fitwidth; - Scale.Y =double(Height) / fitheight; - // compensate for roundoff errors - if (int(Scale.X * fitwidth) != Width) Scale.X += (1 / 65536.); - if (int(Scale.Y * fitheight) != Height) Scale.Y += (1 / 65536.); -} - //==================================================================== // // CheckRealHeight @@ -176,9 +167,6 @@ int FTexture::CheckRealHeight() { if (pixels[h + w * GetHeight()] != 0) { - // Scale maxy before returning it - h = int((h * 2) / Scale.Y); - h = (h >> 1) + (h & 1); return h; } } diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 157e83e0a3..1e0ee8e88e 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -602,9 +602,9 @@ void FTextureManager::AddHiresTextures (int wadnum) // Replace the entire texture and adjust the scaling and offset factors. auto gtex = MakeGameTexture(newtex, ETextureType::Override); gtex->SetWorldPanning(true); - gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y)); - gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y)); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); + gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); + gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY())); ReplaceTexture(tlist[i], gtex, true); } } @@ -698,9 +698,9 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build // Replace the entire texture and adjust the scaling and offset factors. auto gtex = MakeGameTexture(newtex, ETextureType::Override); gtex->SetWorldPanning(true); - gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * newtex->Scale.X), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * newtex->Scale.Y)); - gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * newtex->Scale.X), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * newtex->Scale.Y)); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); + gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); + gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY())); ReplaceTexture(tlist[i], gtex, true); } } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index a24e3b3c40..b80e9a462a 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -43,6 +43,7 @@ #include #include "hw_texcontainer.h" #include "refcounted.h" +#include "xs_Float.h" // 15 because 0th texture is our texture #define MAX_CUSTOM_HW_SHADER_TEXTURES 15 @@ -271,7 +272,6 @@ public: void SetNoDecals(bool on) { bNoDecals = on; } void SetWarpStyle(int style) { bWarped = style; } bool allowNoDecals() const { return bNoDecals; } - bool isScaled() const { return Scale.X != 1 || Scale.Y != 1; } bool isMasked() const { return bMasked; } void SetSkyOffset(int offs) { SkyOffset = offs; } int GetSkyOffset() const { return SkyOffset; } @@ -286,14 +286,12 @@ public: void SetSpeed(float fac) { shaderspeed = fac; } bool UseWorldPanning() const { return bWorldPanning; } void SetWorldPanning(bool on) { bWorldPanning = on; } - void SetDisplaySize(int fitwidth, int fitheight); void CopySize(FTexture* BaseTexture) { Width = BaseTexture->GetWidth(); Height = BaseTexture->GetHeight(); - Scale = BaseTexture->Scale; } // This is only used for the null texture and for Heretic's skies. @@ -313,8 +311,6 @@ public: static bool SmoothEdges(unsigned char * buffer,int w, int h); protected: - DVector2 Scale; - int SourceLump; public: @@ -348,7 +344,6 @@ protected: uint8_t bNoCompress : 1; int8_t bTranslucent : 2; int8_t bExpandSprite = -1; - bool bHiresHasColorKey = false; // Support for old color-keyed Doomsday textures uint16_t Rotations; int16_t SkyOffset; @@ -365,12 +360,6 @@ protected: virtual void ResolvePatches() {} -public: - void SetScale(const DVector2 &scale) - { - Scale = scale; - } - protected: uint16_t Width, Height; @@ -678,7 +667,7 @@ public: void SetGlowing(PalEntry color) { auto tex = GetTexture(); tex->bAutoGlowing = false; tex->bGlowing = true; tex->GlowColor = color; } bool isUserContent() const; - int CheckRealHeight() { return Base->CheckRealHeight(); } + int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); } bool isSkybox() const { return Base->isSkybox(); } void SetSize(int x, int y) { @@ -690,8 +679,13 @@ public: { DisplayWidth = w; DisplayHeight = h; - ScaleX = w / TexelWidth; - ScaleY = h / TexelHeight; + ScaleX = TexelWidth / w; + ScaleY = TexelHeight / h; + + // compensate for roundoff errors + if (int(ScaleX * w) != TexelWidth) ScaleX += (1 / 65536.); + if (int(ScaleY * h) != TexelHeight) ScaleY += (1 / 65536.); + } void SetOffsets(int which, int x, int y) { From 718949f74d1bba5fc01a5718c5db25dc67a56f46 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 01:00:38 +0200 Subject: [PATCH 049/220] - moved the texture name to FGameTexture. --- src/common/fonts/font.cpp | 12 ++++---- src/common/fonts/hexfont.cpp | 4 +-- src/common/fonts/singlelumpfont.cpp | 6 ++-- src/common/fonts/specialfont.cpp | 4 +-- src/common/textures/formats/pngtexture.cpp | 2 +- src/common/textures/formats/shadertexture.cpp | 2 +- src/common/textures/image.h | 2 +- src/common/textures/imagetexture.cpp | 9 +++--- .../textures/multipatchtexturebuilder.cpp | 4 +-- src/common/textures/skyboxtexture.cpp | 2 +- src/common/textures/texture.cpp | 29 +++--------------- src/common/textures/texturemanager.cpp | 30 +++++++++---------- src/common/textures/textures.h | 23 +++++++------- src/d_main.cpp | 4 +-- src/gamedata/textures/animations.cpp | 4 +-- src/gamedata/textures/buildloader.cpp | 2 +- src/r_data/gldefs.cpp | 12 ++++---- src/r_data/models/models_voxel.cpp | 2 +- src/r_data/r_canvastexture.cpp | 5 ++-- src/rendering/swrenderer/r_swscene.cpp | 4 +-- 20 files changed, 69 insertions(+), 93 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 9543c5363e..f690c94e40 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -327,14 +327,14 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla } auto orig = pic->GetTexture(); - auto tex = MakeGameTexture(orig, ETextureType::FontChar); + auto tex = MakeGameTexture(orig, nullptr, ETextureType::FontChar); tex->CopySize(pic); TexMan.AddGameTexture(tex); Chars[i].OriginalPic = tex; if (!noTranslate) { - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(orig->GetImage()), ""), ETextureType::FontChar); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(orig->GetImage())), nullptr, ETextureType::FontChar); Chars[i].TranslatedPic->CopySize(pic); TexMan.AddGameTexture(Chars[i].TranslatedPic); } @@ -410,14 +410,14 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height part[0].OriginY = -height * y; part[0].Image = tex->GetTexture()->GetImage(); FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false); - FImageTexture *tex = new FImageTexture(image, ""); + FImageTexture *tex = new FImageTexture(image); tex->bMultiPatch = true; tex->bMasked = true; tex->bTranslucent = -1; tex->bWorldPanning = true; tex->bNoDecals = false; tex->SourceLump = -1; // We do not really care. - auto gtex = MakeGameTexture(tex, ETextureType::FontChar); + auto gtex = MakeGameTexture(tex, nullptr, ETextureType::FontChar); gtex->SetOffsets(0, 0, 0); gtex->SetOffsets(1, 0, 0); gtex->SetScale((float)Scale.X, (float)Scale.Y); @@ -451,10 +451,10 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height auto b = pic->Get8BitPixels(false); - Chars[i].OriginalPic = MakeGameTexture(pic, ETextureType::FontChar); + Chars[i].OriginalPic = MakeGameTexture(pic, nullptr, ETextureType::FontChar); Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); Chars[i].OriginalPic->CopySize(*lump); - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage()), ""), ETextureType::FontChar); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage())), nullptr, ETextureType::FontChar); Chars[i].TranslatedPic->CopySize(*lump); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); TexMan.AddGameTexture(Chars[i].OriginalPic); diff --git a/src/common/fonts/hexfont.cpp b/src/common/fonts/hexfont.cpp index 4b3fd39cd8..812973bba9 100644 --- a/src/common/fonts/hexfont.cpp +++ b/src/common/fonts/hexfont.cpp @@ -289,7 +289,7 @@ public: { auto offset = hexdata.glyphmap[i]; int size = hexdata.glyphdata[offset] / 16; - Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar (&hexdata.glyphdata[offset+1], size, size * 9, 16)), ETextureType::FontChar); + Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar (&hexdata.glyphdata[offset+1], size, size * 9, 16)), nullptr, ETextureType::FontChar); Chars[i - FirstChar].XMove = size * spacing; TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); } @@ -361,7 +361,7 @@ public: { auto offset = hexdata.glyphmap[i]; int size = hexdata.glyphdata[offset] / 16; - Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), ETextureType::FontChar); + Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), nullptr, ETextureType::FontChar); Chars[i - FirstChar].XMove = size * spacing; TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); } diff --git a/src/common/fonts/singlelumpfont.cpp b/src/common/fonts/singlelumpfont.cpp index ad81f3d0fd..ed69aea808 100644 --- a/src/common/fonts/singlelumpfont.cpp +++ b/src/common/fonts/singlelumpfont.cpp @@ -353,7 +353,7 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data) } else { - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), ETextureType::FontChar); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), nullptr, ETextureType::FontChar); TexMan.AddGameTexture(Chars[i].TranslatedPic); do { @@ -487,7 +487,7 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data) chardata[chari+2], // height -(int8_t)chardata[chari+3], // x offset -(int8_t)chardata[chari+4] // y offset - )), ETextureType::FontChar); + )), nullptr, ETextureType::FontChar); Chars[chardata[chari] - FirstChar].TranslatedPic = tex; TexMan.AddGameTexture(tex); } @@ -554,7 +554,7 @@ void FSingleLumpFont::CheckFON1Chars (double *luminosity) if(!Chars[i].TranslatedPic) { - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight)), ETextureType::FontChar); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight)), nullptr, ETextureType::FontChar); Chars[i].XMove = SpaceWidth; TexMan.AddGameTexture(Chars[i].TranslatedPic); } diff --git a/src/common/fonts/specialfont.cpp b/src/common/fonts/specialfont.cpp index 9c6c33a810..6bd544c9e5 100644 --- a/src/common/fonts/specialfont.cpp +++ b/src/common/fonts/specialfont.cpp @@ -104,13 +104,13 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture if (charlumps[i] != nullptr) { auto pic = charlumps[i]; - Chars[i].OriginalPic = MakeGameTexture(pic->GetTexture(), ETextureType::FontChar); + Chars[i].OriginalPic = MakeGameTexture(pic->GetTexture(), nullptr, ETextureType::FontChar); Chars[i].OriginalPic->CopySize(pic); TexMan.AddGameTexture(Chars[i].OriginalPic); if (!noTranslate) { - Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1 (charlumps[i]->GetTexture()->GetImage()), ""), ETextureType::FontChar); + Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1 (charlumps[i]->GetTexture()->GetImage())), nullptr, ETextureType::FontChar); Chars[i].TranslatedPic->CopySize(charlumps[i]); TexMan.AddGameTexture(Chars[i].TranslatedPic); } diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index a808dd13bb..0357b0da9f 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -609,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 MakeGameTexture(new FPNGFileTexture (png->File, width, height, colortype), ETextureType::Override); + else return MakeGameTexture(new FPNGFileTexture (png->File, width, height, colortype), nullptr, ETextureType::Override); } //========================================================================== diff --git a/src/common/textures/formats/shadertexture.cpp b/src/common/textures/formats/shadertexture.cpp index 21fd893560..6bde2b677d 100644 --- a/src/common/textures/formats/shadertexture.cpp +++ b/src/common/textures/formats/shadertexture.cpp @@ -132,6 +132,6 @@ private: FGameTexture *CreateShaderTexture(bool vertical, bool reverse) { FStringf name("BarShader%c%c", vertical ? 'v' : 'h', reverse ? 'r' : 'f'); - return MakeGameTexture(CreateImageTexture(new FBarShader(vertical, reverse), name.GetChars()), ETextureType::Override); + return MakeGameTexture(CreateImageTexture(new FBarShader(vertical, reverse)), name.GetChars(), ETextureType::Override); } diff --git a/src/common/textures/image.h b/src/common/textures/image.h index 38e5a2ee17..6ddd34bc22 100644 --- a/src/common/textures/image.h +++ b/src/common/textures/image.h @@ -171,4 +171,4 @@ protected: class FTexture; -FTexture* CreateImageTexture(FImageSource* img, const char *name = nullptr) noexcept; +FTexture* CreateImageTexture(FImageSource* img) noexcept; diff --git a/src/common/textures/imagetexture.cpp b/src/common/textures/imagetexture.cpp index ba4179b8ab..bde19f8b89 100644 --- a/src/common/textures/imagetexture.cpp +++ b/src/common/textures/imagetexture.cpp @@ -47,13 +47,12 @@ // //========================================================================== -FImageTexture::FImageTexture(FImageSource *img, const char *name) noexcept -: FTexture(name, img? img->LumpNum() : 0) +FImageTexture::FImageTexture(FImageSource *img) noexcept +: FTexture(img? img->LumpNum() : 0) { mImage = img; if (img != nullptr) { - if (name == nullptr) fileSystem.GetFileShortName(Name, img->LumpNum()); SetFromImage(); } } @@ -109,8 +108,8 @@ bool FImageTexture::DetermineTranslucency() } -FTexture* CreateImageTexture(FImageSource* img, const char *name) noexcept +FTexture* CreateImageTexture(FImageSource* img) noexcept { - return new FImageTexture(img, name); + return new FImageTexture(img); } diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 2c1ce45fe6..ea55239d73 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -137,7 +137,7 @@ struct FPatchLookup void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType usetype) { - FImageTexture *tex = new FImageTexture(nullptr, buildinfo.Name); + FImageTexture *tex = new FImageTexture(nullptr); tex->bMultiPatch = true; tex->SetSize(buildinfo.Width, buildinfo.Height); tex->bMasked = true; // we do not really know yet. @@ -145,7 +145,7 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u tex->bNoDecals = buildinfo.bNoDecals; tex->SourceLump = buildinfo.DefinitionLump; buildinfo.itex = tex; - buildinfo.texture = MakeGameTexture(tex, usetype); + buildinfo.texture = MakeGameTexture(tex, buildinfo.Name, usetype); buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X); diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index 0c2820be27..b77a2ad3b0 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -35,7 +35,7 @@ //----------------------------------------------------------------------------- FSkyBox::FSkyBox(const char *name) - : FImageTexture(name) + : FImageTexture(nullptr) { FTextureID texid = TexMan.CheckForTexture(name, ETextureType::Wall); if (texid.isValid()) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 0e699a52ca..94f9309a77 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -70,20 +70,14 @@ int r_spriteadjustSW, r_spriteadjustHW; // Examines the lump contents to decide what type of texture to create, // and creates the texture. -FTexture * FTexture::CreateTexture(const char *name, int lumpnum, bool allowflats) +FTexture * FTexture::CreateTexture(int lumpnum, bool allowflats) { if (lumpnum == -1) return nullptr; auto image = FImageSource::GetImage(lumpnum, allowflats); if (image != nullptr) { - FTexture *tex = new FImageTexture(image); - if (tex != nullptr) - { - tex->Name = name; - tex->Name.ToUpper(); - return tex; - } + return new FImageTexture(image); } return nullptr; } @@ -94,7 +88,7 @@ FTexture * FTexture::CreateTexture(const char *name, int lumpnum, bool allowflat // //========================================================================== -FTexture::FTexture (const char *name, int lumpnum) +FTexture::FTexture (int lumpnum) : SourceLump(lumpnum), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), @@ -109,21 +103,6 @@ FTexture::FTexture (const char *name, int lumpnum) bSkybox = false; bNoCompress = false; bTranslucent = -1; - - - if (name != NULL) - { - Name = name; - Name.ToUpper(); - } - else if (lumpnum < 0) - { - Name = FString(); - } - else - { - fileSystem.GetFileShortName (Name, lumpnum); - } } FTexture::~FTexture () @@ -971,7 +950,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) } -FGameTexture::FGameTexture(FTexture* wrap) : Base(wrap) +FGameTexture::FGameTexture(FTexture* wrap, const char *name) : Base(wrap), Name(name) { id.SetInvalid(); TexelWidth = Base->GetWidth(); diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 1e0ee8e88e..5ff1ad6570 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -230,7 +230,7 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset if (tex == NO_TEXTURE) return FTextureID(-1); if (tex != NULL) return tex->GetID(); if (flags & TEXMAN_DontCreate) return FTextureID(-1); // we only want to check, there's no need to create a texture if we don't have one yet. - tex = MakeGameTexture(FTexture::CreateTexture("", lump), ETextureType::Override); + tex = MakeGameTexture(FTexture::CreateTexture(lump), nullptr, ETextureType::Override); if (tex != NULL) { tex->AddAutoMaterials(); @@ -421,7 +421,7 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype) { FString str; fileSystem.GetFileShortName(str, lumpnum); - auto out = MakeGameTexture(FTexture::CreateTexture(str, lumpnum, usetype == ETextureType::Flat), usetype); + auto out = MakeGameTexture(FTexture::CreateTexture(lumpnum, usetype == ETextureType::Flat), str, usetype); if (out != NULL) { @@ -470,11 +470,11 @@ void FTextureManager::ReplaceTexture (FTextureID picnum, FGameTexture *newtextur auto oldtexture = Textures[index].Texture; - newtexture->GetTexture()->Name = oldtexture->GetName(); + newtexture->SetName(oldtexture->GetName()); newtexture->SetUseType(oldtexture->GetUseType()); Textures[index].Texture = newtexture; newtexture->SetID(oldtexture->GetID()); - oldtexture->GetTexture()->Name = ""; + oldtexture->SetName(""); AddGameTexture(oldtexture); } @@ -584,7 +584,7 @@ void FTextureManager::AddHiresTextures (int wadnum) if (amount == 0) { // A texture with this name does not yet exist - auto newtex = MakeGameTexture(FTexture::CreateTexture (Name, firsttx), ETextureType::Override); + auto newtex = MakeGameTexture(FTexture::CreateTexture(firsttx), Name, ETextureType::Override); if (newtex != NULL) { AddGameTexture(newtex); @@ -594,13 +594,13 @@ void FTextureManager::AddHiresTextures (int wadnum) { for(unsigned int i = 0; i < tlist.Size(); i++) { - FTexture * newtex = FTexture::CreateTexture ("", firsttx); + FTexture * newtex = FTexture::CreateTexture (firsttx); if (newtex != NULL) { auto oldtex = Textures[tlist[i].GetIndex()].Texture; // Replace the entire texture and adjust the scaling and offset factors. - auto gtex = MakeGameTexture(newtex, ETextureType::Override); + auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override); gtex->SetWorldPanning(true); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); @@ -692,11 +692,11 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build (sl=oldtex->GetSourceLump()) >= 0 && fileSystem.GetFileNamespace(sl) == ns_sprites) ) { - FTexture * newtex = FTexture::CreateTexture ("", lumpnum); + FTexture * newtex = FTexture::CreateTexture (lumpnum); if (newtex != NULL) { // Replace the entire texture and adjust the scaling and offset factors. - auto gtex = MakeGameTexture(newtex, ETextureType::Override); + auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override); gtex->SetWorldPanning(true); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); @@ -730,7 +730,7 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build if (lumpnum>=0) { - auto newtex = MakeGameTexture(FTexture::CreateTexture(src, lumpnum), ETextureType::Override); + auto newtex = MakeGameTexture(FTexture::CreateTexture(lumpnum), src, ETextureType::Override); if (newtex != NULL) { @@ -950,7 +950,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b // Try to create a texture from this lump and add it. // Unfortunately we have to look at everything that comes through here... - auto out = MakeGameTexture(FTexture::CreateTexture(Name, i), skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch); + auto out = MakeGameTexture(FTexture::CreateTexture(i), Name, skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch); if (out != NULL) { @@ -1116,11 +1116,11 @@ void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildI DeleteAll(); //if (BuildTileFiles.Size() == 0) CountBuildTiles (); - auto nulltex = MakeGameTexture(new FImageTexture(CreateEmptyTexture(), ""), ETextureType::Null); + auto nulltex = MakeGameTexture(new FImageTexture(CreateEmptyTexture()), nullptr, ETextureType::Null); AddGameTexture(nulltex); // This is for binding to unused texture units, because accessing an unbound texture unit is undefined. It's a one pixel empty texture. - auto emptytex = MakeGameTexture(new FImageTexture(CreateEmptyTexture(), ""), ETextureType::Override); + auto emptytex = MakeGameTexture(new FImageTexture(CreateEmptyTexture()), nullptr, ETextureType::Override); emptytex->SetSize(1, 1); AddGameTexture(emptytex); // some special textures used in the game. @@ -1235,7 +1235,7 @@ FTextureID FTextureManager::GetRawTexture(FTextureID texid) } // Todo: later this can just link to the already existing texture for this source graphic, once it can be retrieved through the image's SourceLump index - auto RawTexture = MakeGameTexture(new FImageTexture(source, ""), ETextureType::Wall); + auto RawTexture = MakeGameTexture(new FImageTexture(source), nullptr, ETextureType::Wall); texid = TexMan.AddGameTexture(RawTexture); Textures[texidx].RawTexture = texid.GetIndex(); Textures[texid.GetIndex()].RawTexture = texid.GetIndex(); @@ -1268,7 +1268,7 @@ FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid) // Set this up so that it serializes to the same info as the base texture - this is needed to restore it on load. // But do not link the new texture into the hash chain! - auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image, tex->GetName()), ETextureType::Wall); + auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image), tex->GetName(), ETextureType::Wall); FrontSkyLayer->SetUseType(tex->GetUseType()); FrontSkyLayer->GetTexture()->bNoRemap0 = true; texid = TexMan.AddGameTexture(FrontSkyLayer, false); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index b80e9a462a..7251ab90ff 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -250,7 +250,7 @@ class FTexture : public RefCountedBase public: IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); - static FTexture *CreateTexture(const char *name, int lumpnum, bool allowflats = false); + static FTexture *CreateTexture(int lumpnum, bool allowflats = false); virtual ~FTexture (); virtual FImageSource *GetImage() const { return nullptr; } void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); @@ -268,7 +268,6 @@ public: float GetShaderSpeed() const { return shaderspeed; } void SetRotations(int rot) { Rotations = int16_t(rot); } - const FString &GetName() const { return Name; } void SetNoDecals(bool on) { bNoDecals = on; } void SetWarpStyle(int style) { bWarped = style; } bool allowNoDecals() const { return bNoDecals; } @@ -319,8 +318,6 @@ protected: protected: - FString Name; - uint8_t bNoDecals:1; // Decals should not stick to texture uint8_t bNoRemap0:1; // Do not remap color 0 (used by front layer of parallax skies) uint8_t bWorldPanning:1; // Texture is panned in world units rather than texels @@ -363,7 +360,7 @@ protected: protected: uint16_t Width, Height; - FTexture (const char *name = NULL, int lumpnum = -1); + FTexture (int lumpnum = -1); public: FTextureBuffer CreateTexBuffer(int translation, int flags = 0); @@ -388,9 +385,8 @@ public: class FCanvasTexture : public FTexture { public: - FCanvasTexture(const char* name, int width, int height) + FCanvasTexture(int width, int height) { - Name = name; Width = width; Height = height; @@ -438,10 +434,9 @@ class FImageTexture : public FTexture { FImageSource* mImage; protected: - FImageTexture(const char *name) : FTexture(name) {} void SetFromImage(); public: - FImageTexture(FImageSource* image, const char* name = nullptr) noexcept; + FImageTexture(FImageSource* image) noexcept; virtual TArray Get8BitPixels(bool alphatex); void SetImage(FImageSource* img) // This is only for the multipatch texture builder! @@ -543,6 +538,7 @@ class FGameTexture RefCountedPtr AmbientOcclusion; // Ambient occlusion texture for PBR RefCountedPtr CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES]; // Custom texture maps for custom hardware shaders + FString Name; FTextureID id; uint16_t TexelWidth, TexelHeight; @@ -558,10 +554,12 @@ class FGameTexture FMaterial* Material[4] = { }; public: - FGameTexture(FTexture* wrap); + FGameTexture(FTexture* wrap, const char *name); ~FGameTexture(); FTextureID GetID() const { return id; } void SetID(FTextureID newid) { id = newid; } // should only be called by the texture manager + const FString& GetName() const { return Name; } + void SetName(const char* name) { Name = name; } // should only be called by setup code. float GetScaleX() { return ScaleX; } float GetScaleY() { return ScaleY; } @@ -628,7 +626,6 @@ public: return Material[num]; } - const FString& GetName() const { return Base->GetName(); } void SetShaderSpeed(float speed) { Base->shaderspeed = speed; } void SetShaderIndex(int index) { Base->shaderindex = index; } void SetShaderLayers(MaterialLayers& lay) @@ -724,10 +721,10 @@ public: } }; -inline FGameTexture* MakeGameTexture(FTexture* tex, ETextureType useType) +inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType) { if (!tex) return nullptr; - auto t = new FGameTexture(tex); + auto t = new FGameTexture(tex, name); t->SetUseType(useType); return t; } diff --git a/src/d_main.cpp b/src/d_main.cpp index eb8a22a0fc..47eb81928a 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -880,7 +880,7 @@ void D_Display () if (vr_mode == 0 || vid_rendermode != 4) { // save the current screen if about to wipe - wipe = MakeGameTexture(screen->WipeStartScreen(), ETextureType::SWCanvas); + wipe = MakeGameTexture(screen->WipeStartScreen(), nullptr, ETextureType::SWCanvas); switch (wipegamestate) { @@ -1063,7 +1063,7 @@ void D_Display () GSnd->SetSfxPaused(true, 1); I_FreezeTime(true); screen->End2D(); - auto wipend = MakeGameTexture(screen->WipeEndScreen(), ETextureType::SWCanvas); + auto wipend = MakeGameTexture(screen->WipeEndScreen(), nullptr, ETextureType::SWCanvas); auto wiper = Wiper::Create(wipe_type); wiper->SetTextures(wipe, wipend); diff --git a/src/gamedata/textures/animations.cpp b/src/gamedata/textures/animations.cpp index 8db6537d9f..55dcf060c4 100644 --- a/src/gamedata/textures/animations.cpp +++ b/src/gamedata/textures/animations.cpp @@ -709,8 +709,8 @@ void FTextureAnimator::ParseCameraTexture(FScanner &sc) sc.MustGetNumber (); height = sc.Number; FTextureID picnum = TexMan.CheckForTexture (picname, ETextureType::Flat, texflags); - auto canvas = new FCanvasTexture(picname, width, height); - FGameTexture *viewer = MakeGameTexture(canvas, ETextureType::Wall); + auto canvas = new FCanvasTexture(width, height); + FGameTexture *viewer = MakeGameTexture(canvas, picname, ETextureType::Wall); if (picnum.Exists()) { auto oldtex = TexMan.GameTexture(picnum); diff --git a/src/gamedata/textures/buildloader.cpp b/src/gamedata/textures/buildloader.cpp index 37a21eb978..047ad14be2 100644 --- a/src/gamedata/textures/buildloader.cpp +++ b/src/gamedata/textures/buildloader.cpp @@ -157,7 +157,7 @@ void AddTiles(const FString& pathprefix, const void* tiles, FRemapTable *remap) if (width <= 0 || height <= 0) continue; FStringf name("%sBTIL%04d", pathprefix.GetChars(), i); - auto tex = MakeGameTexture(new FImageTexture(new FBuildTexture(pathprefix, i, tiledata, remap, width, height, xoffs, yoffs), name), ETextureType::Override); + auto tex = MakeGameTexture(new FImageTexture(new FBuildTexture(pathprefix, i, tiledata, remap, width, height, xoffs, yoffs)), name, ETextureType::Override); texnum = TexMan.AddGameTexture(tex); tiledata += size; diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index c19c3ea3ca..55c6b60502 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -77,6 +77,7 @@ static void ParseVavoomSkybox() int facecount=0; int maplump = -1; bool error = false; + FString s = sc.String; FSkyBox * sb = new FSkyBox(sc.String); sb->fliptop = true; sc.MustGetStringName("{"); @@ -93,7 +94,7 @@ static void ParseVavoomSkybox() auto tex = TexMan.FindGameTexture(sc.String, ETextureType::Wall, FTextureManager::TEXMAN_TryAny); if (tex == NULL) { - sc.ScriptMessage("Texture '%s' not found in Vavoom skybox '%s'\n", sc.String, sb->GetName().GetChars()); + sc.ScriptMessage("Texture '%s' not found in Vavoom skybox '%s'\n", sc.String, s.GetChars()); error = true; } sb->faces[facecount] = tex; @@ -103,12 +104,12 @@ static void ParseVavoomSkybox() } if (facecount != 6) { - sc.ScriptError("%s: Skybox definition requires 6 faces", sb->GetName().GetChars()); + sc.ScriptError("%s: Skybox definition requires 6 faces", s.GetChars()); } sb->SetSize(); if (!error) { - TexMan.AddGameTexture(MakeGameTexture(sb, ETextureType::Override)); + TexMan.AddGameTexture(MakeGameTexture(sb, s, ETextureType::Override)); } } } @@ -992,7 +993,6 @@ class GLDefsParser sc.MustGetString(); FString s = sc.String; - s.ToUpper(); FSkyBox * sb = new FSkyBox(s); if (sc.CheckString("fliptop")) { @@ -1010,10 +1010,10 @@ class GLDefsParser } if (facecount != 3 && facecount != 6) { - sc.ScriptError("%s: Skybox definition requires either 3 or 6 faces", sb->GetName().GetChars()); + sc.ScriptError("%s: Skybox definition requires either 3 or 6 faces", s.GetChars()); } sb->SetSize(); - TexMan.AddGameTexture(MakeGameTexture(sb, ETextureType::Override)); + TexMan.AddGameTexture(MakeGameTexture(sb, s, ETextureType::Override)); } //=========================================================================== diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index d936a2576e..cfa65f4b3a 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -157,7 +157,7 @@ FVoxelModel::FVoxelModel(FVoxel *voxel, bool owned) { mVoxel = voxel; mOwningVoxel = owned; - mPalette = TexMan.AddGameTexture(MakeGameTexture(new FImageTexture(new FVoxelTexture(voxel)), ETextureType::Override)); + mPalette = TexMan.AddGameTexture(MakeGameTexture(new FImageTexture(new FVoxelTexture(voxel)), nullptr, ETextureType::Override)); } //=========================================================================== diff --git a/src/r_data/r_canvastexture.cpp b/src/r_data/r_canvastexture.cpp index dd8b91d5a2..c12d42e764 100644 --- a/src/r_data/r_canvastexture.cpp +++ b/src/r_data/r_canvastexture.cpp @@ -57,10 +57,11 @@ void FCanvasTextureInfo::Add (AActor *viewpoint, FTextureID picnum, double fov) { return; } - texture = static_cast(TexMan.GetGameTexture(picnum)->GetTexture()); + auto gt = TexMan.GetGameTexture(picnum); + texture = static_cast(gt->GetTexture()); if (!texture->bHasCanvas) { - Printf ("%s is not a valid target for a camera\n", texture->Name.GetChars()); + Printf ("%s is not a valid target for a camera\n", gt->GetName().GetChars()); return; } diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index a34f339adf..25240bcc8e 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -76,7 +76,7 @@ SWSceneDrawer::SWSceneDrawer() if (!texid.Exists()) { // We need to wrap this in a game texture object to have it managed by the texture manager, even though it will never be used as a material. - auto tex = MakeGameTexture(new FImageTexture(new FSWPaletteTexture, "@@palette@@"), ETextureType::Special); + auto tex = MakeGameTexture(new FImageTexture(new FSWPaletteTexture), "@@palette@@", ETextureType::Special); texid = TexMan.AddGameTexture(tex); } PaletteTexture = TexMan.GetGameTexture(texid)->GetTexture(); @@ -103,7 +103,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) { // This manually constructs its own material here. fbtex.reset(); - fbtex.reset(MakeGameTexture(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()), ETextureType::SWCanvas)); + fbtex.reset(MakeGameTexture(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()), nullptr, ETextureType::SWCanvas)); GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1); auto mat = FMaterial::ValidateTexture(fbtex.get(), false); mat->AddTextureLayer(PaletteTexture); From e60d75828700f3f4c9f3bdc38c02a34fe5c00d54 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 09:23:00 +0200 Subject: [PATCH 050/220] - made all member variables of FTexture protected. Also temorarily disabled the CleanUnused call of the precacher - this needs some reworking, now that the texture system is better equipped for it. --- src/common/textures/textures.h | 89 +++++++++---------- .../hwrenderer/textures/hw_precache.cpp | 4 +- src/rendering/swrenderer/r_swscene.cpp | 2 +- 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 7251ab90ff..5e4f71f8f8 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -246,6 +246,48 @@ class FTexture : public RefCountedBase friend class FMaterial; friend class FFont; +protected: + uint16_t Width, Height; + int SourceLump; + FHardwareTextureContainer SystemTextures; + + uint8_t bNoDecals : 1; // Decals should not stick to texture + uint8_t bNoRemap0 : 1; // Do not remap color 0 (used by front layer of parallax skies) + uint8_t bWorldPanning : 1; // Texture is panned in world units rather than texels + uint8_t bMasked : 1; // Texture (might) have holes + uint8_t bAlphaTexture : 1; // Texture is an alpha channel without color information + uint8_t bHasCanvas : 1; // Texture is based off FCanvasTexture + uint8_t bWarped : 2; // This is a warped texture. Used to avoid multiple warps on one texture + uint8_t bComplex : 1; // Will be used to mark extended MultipatchTextures that have to be + // fully composited before subjected to any kind of postprocessing instead of + // doing it per patch. + uint8_t bMultiPatch : 2; // This is a multipatch texture (we really could use real type info for textures...) + uint8_t bFullNameTexture : 1; + uint8_t bBrightmapChecked : 1; // Set to 1 if brightmap has been checked + + uint8_t bGlowing : 1; // Texture glow color + uint8_t bAutoGlowing : 1; // Glow info is determined from texture image. + uint8_t bFullbright : 1; // always draw fullbright + uint8_t bDisableFullbright : 1; // This texture will not be displayed as fullbright sprite + + uint8_t bSkybox : 1; // is a cubic skybox + uint8_t bNoCompress : 1; + int8_t bTranslucent : 2; + int8_t bExpandSprite = -1; + + uint16_t Rotations; + int16_t SkyOffset; + FloatRect* areas = nullptr; + int areacount = 0; + + int GlowHeight = 128; + PalEntry GlowColor = 0; + + float Glossiness = 10.f; + float SpecularLevel = 0.1f; + float shaderspeed = 1.f; + int shaderindex = 0; + public: @@ -309,56 +351,9 @@ public: static bool SmoothEdges(unsigned char * buffer,int w, int h); -protected: - int SourceLump; - -public: - FHardwareTextureContainer SystemTextures; -protected: - - protected: - - uint8_t bNoDecals:1; // Decals should not stick to texture - uint8_t bNoRemap0:1; // Do not remap color 0 (used by front layer of parallax skies) - uint8_t bWorldPanning:1; // Texture is panned in world units rather than texels - uint8_t bMasked:1; // Texture (might) have holes - uint8_t bAlphaTexture:1; // Texture is an alpha channel without color information - uint8_t bHasCanvas:1; // Texture is based off FCanvasTexture - uint8_t bWarped:2; // This is a warped texture. Used to avoid multiple warps on one texture - uint8_t bComplex:1; // Will be used to mark extended MultipatchTextures that have to be - // fully composited before subjected to any kind of postprocessing instead of - // doing it per patch. - uint8_t bMultiPatch:2; // This is a multipatch texture (we really could use real type info for textures...) - uint8_t bFullNameTexture : 1; - uint8_t bBrightmapChecked : 1; // Set to 1 if brightmap has been checked - public: - uint8_t bGlowing : 1; // Texture glow color - uint8_t bAutoGlowing : 1; // Glow info is determined from texture image. - uint8_t bFullbright : 1; // always draw fullbright - uint8_t bDisableFullbright : 1; // This texture will not be displayed as fullbright sprite - protected: - uint8_t bSkybox : 1; // is a cubic skybox - uint8_t bNoCompress : 1; - int8_t bTranslucent : 2; - int8_t bExpandSprite = -1; - - uint16_t Rotations; - int16_t SkyOffset; - FloatRect *areas = nullptr; - int areacount = 0; - public: - int GlowHeight = 128; - PalEntry GlowColor = 0; - private: - float Glossiness = 10.f; - float SpecularLevel = 0.1f; - float shaderspeed = 1.f; - int shaderindex = 0; virtual void ResolvePatches() {} -protected: - uint16_t Width, Height; FTexture (int lumpnum = -1); diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 0e5f2ab034..dd29321214 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -62,7 +62,7 @@ static void PrecacheTexture(FGameTexture *tex, int cache) //=========================================================================== static void PrecacheList(FMaterial *gltex, SpriteHits& translations) { - gltex->BaseLayer()->SystemTextures.CleanUnused(translations, gltex->GetScaleFlags()); + //gltex->BaseLayer()->SystemTextures.CleanUnused(translations, gltex->GetScaleFlags()); this needs to be redone. SpriteHits::Iterator it(translations); SpriteHits::Pair* pair; while (it.NextPair(pair)) screen->PrecacheMaterial(gltex, pair->Key); @@ -253,7 +253,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { int flags = shouldUpscale(gtex, UF_Texture); - if (tex->GetImage() && tex->SystemTextures.GetHardwareTexture(0, flags) == nullptr) + if (tex->GetImage() && tex->GetHardwareTexture(0, flags) == nullptr) { FImageSource::RegisterForPrecache(tex->GetImage(), V_IsTrueColor()); } diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index 25240bcc8e..cf8f236ccc 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -94,7 +94,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) FBTextureIndex = (FBTextureIndex + 1) % 2; auto &fbtex = FBTexture[FBTextureIndex]; - auto GetSystemTexture = [&]() { return fbtex->GetTexture()->SystemTextures.GetHardwareTexture(0, 0); }; + auto GetSystemTexture = [&]() { return fbtex->GetTexture()->GetHardwareTexture(0, 0); }; if (fbtex == nullptr || GetSystemTexture() == nullptr || fbtex->GetTexelWidth() != screen->GetWidth() || From d8128017077911438daa6a3795cd0671585ab7e9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 09:41:55 +0200 Subject: [PATCH 051/220] - moved the shader properties to FGameTexture. --- src/common/textures/hw_material.cpp | 7 +++--- src/common/textures/texture.cpp | 14 +++++------- src/common/textures/textures.h | 34 ++++++++++++++--------------- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 9f78f5d722..d85b23f6ba 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -109,9 +109,10 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) mTextureLayers.Push(placeholder->GetTexture()); } - if (imgtex->shaderindex >= FIRST_USER_SHADER) + auto index = tx->GetShaderIndex(); + if (index >= FIRST_USER_SHADER) { - const UserShaderDesc &usershader = usershaders[imgtex->shaderindex - FIRST_USER_SHADER]; + const UserShaderDesc &usershader = usershaders[index - FIRST_USER_SHADER]; if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material { for (auto &texture : tx->CustomShaderTextures) @@ -119,7 +120,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) if (texture == nullptr) continue; mTextureLayers.Push(texture.get()); } - mShaderIndex = tx->GetShaderIndex(); + mShaderIndex = index; } } } diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 94f9309a77..e2dc6ee834 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -107,8 +107,6 @@ FTexture::FTexture (int lumpnum) FTexture::~FTexture () { - if (areas != nullptr) delete[] areas; - areas = nullptr; } //=========================================================================== @@ -281,12 +279,12 @@ void FTexture::GetGlowColor(float *data) // //=========================================================================== -int FTexture::GetAreas(FloatRect** pAreas) const +int FGameTexture::GetAreas(FloatRect** pAreas) const { if (shaderindex == SHADER_Default) // texture splitting can only be done if there's no attached effects { - *pAreas = areas; - return areacount; + *pAreas = Base->areas; + return Base->areacount; } else { @@ -314,8 +312,8 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h) if (areacount) return false; areacount = -1; //whatever happens next, it shouldn't be done twice! - // large textures are excluded for performance reasons - if (h>512) return false; + // large textures and non-images are excluded for performance reasons + if (h>512 || !GetImage()) return false; startdraw = -1; lendraw = 0; @@ -366,7 +364,7 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h) if (gapc > 0) { - FloatRect * rcs = new FloatRect[gapc]; + FloatRect* rcs = (FloatRect*)ImageArena.Alloc(gapc * sizeof(FloatRect)); // allocate this on the image arena for (x = 0; x < gapc; x++) { diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 5e4f71f8f8..d73fdf28c3 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -283,12 +283,6 @@ protected: int GlowHeight = 128; PalEntry GlowColor = 0; - float Glossiness = 10.f; - float SpecularLevel = 0.1f; - float shaderspeed = 1.f; - int shaderindex = 0; - - public: IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); @@ -307,7 +301,6 @@ public: bool isCanvas() const { return bHasCanvas; } int isWarped() const { return bWarped; } int GetRotations() const { return Rotations; } - float GetShaderSpeed() const { return shaderspeed; } void SetRotations(int rot) { Rotations = int16_t(rot); } void SetNoDecals(bool on) { bNoDecals = on; } @@ -324,7 +317,6 @@ public: bool isFullbright() const { return bFullbright; } bool FindHoles(const unsigned char * buffer, int w, int h); int GetSourceLump() const { return SourceLump; } - void SetSpeed(float fac) { shaderspeed = fac; } bool UseWorldPanning() const { return bWorldPanning; } void SetWorldPanning(bool on) { bWorldPanning = on; } @@ -548,6 +540,12 @@ class FGameTexture ISoftwareTexture* SoftwareTexture = nullptr; FMaterial* Material[4] = { }; + // Material properties + float Glossiness = 10.f; + float SpecularLevel = 0.1f; + float shaderspeed = 1.f; + int shaderindex = 0; + public: FGameTexture(FTexture* wrap, const char *name); ~FGameTexture(); @@ -600,8 +598,6 @@ public: void SetNoDecals(bool on) { Base->bNoDecals = on; } void SetTranslucent(bool on) { Base->bTranslucent = on; } void SetUseType(ETextureType type) { UseType = type; } - int GetShaderIndex() const { return Base->shaderindex; } - float GetShaderSpeed() const { return Base->GetShaderSpeed(); } uint16_t GetRotations() const { return Base->GetRotations(); } void SetRotations(int index) { Base->SetRotations(index); } void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); } @@ -621,13 +617,15 @@ public: return Material[num]; } - void SetShaderSpeed(float speed) { Base->shaderspeed = speed; } - void SetShaderIndex(int index) { Base->shaderindex = index; } + int GetShaderIndex() const { return shaderindex; } + float GetShaderSpeed() const { return shaderspeed; } + void SetShaderSpeed(float speed) { shaderspeed = speed; } + void SetShaderIndex(int index) { shaderindex = index; } void SetShaderLayers(MaterialLayers& lay) { // Only update layers that have something defind. - if (lay.Glossiness > -1000) Base->Glossiness = lay.Glossiness; - if (lay.SpecularLevel > -1000) Base->SpecularLevel = lay.SpecularLevel; + if (lay.Glossiness > -1000) Glossiness = lay.Glossiness; + if (lay.SpecularLevel > -1000) SpecularLevel = lay.SpecularLevel; if (lay.Brightmap) Brightmap = lay.Brightmap->GetTexture(); if (lay.Normal) Normal = lay.Normal->GetTexture(); if (lay.Specular) Specular = lay.Specular->GetTexture(); @@ -639,8 +637,8 @@ public: if (lay.CustomShaderTextures[i]) CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); } } - float GetGlossiness() const { return Base->Glossiness; } - float GetSpecularLevel() const { return Base->SpecularLevel; } + float GetGlossiness() const { return Glossiness; } + float GetSpecularLevel() const { return SpecularLevel; } void CopySize(FGameTexture* BaseTexture) { @@ -693,7 +691,7 @@ public: } const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; } - int GetAreas(FloatRect** pAreas) const { return Base->GetAreas(pAreas); } + int GetAreas(FloatRect** pAreas) const; bool GetTranslucency() { @@ -711,7 +709,7 @@ public: { if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; else if (isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - else if ((isWarped() || Base->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + else if ((isWarped() || shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; return clampmode; } }; From 0a1bd458dbf11889a0e993f8ce2cbaf99264ce70 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 11:40:15 +0200 Subject: [PATCH 052/220] - moved most material flags out of FTexture. --- src/common/fonts/font.cpp | 6 +- .../textures/formats/multipatchtexture.h | 1 + .../textures/multipatchtexturebuilder.cpp | 16 ++-- src/common/textures/texture.cpp | 46 +++++----- src/common/textures/textures.h | 92 ++++++++----------- 5 files changed, 77 insertions(+), 84 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index f690c94e40..16cbd07d7d 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -411,13 +411,11 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height part[0].Image = tex->GetTexture()->GetImage(); FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false); FImageTexture *tex = new FImageTexture(image); - tex->bMultiPatch = true; + auto gtex = MakeGameTexture(tex, nullptr, ETextureType::FontChar); tex->bMasked = true; tex->bTranslucent = -1; - tex->bWorldPanning = true; - tex->bNoDecals = false; tex->SourceLump = -1; // We do not really care. - auto gtex = MakeGameTexture(tex, nullptr, ETextureType::FontChar); + gtex->SetWorldPanning(true); gtex->SetOffsets(0, 0, 0); gtex->SetOffsets(1, 0, 0); gtex->SetScale((float)Scale.X, (float)Scale.Y); diff --git a/src/common/textures/formats/multipatchtexture.h b/src/common/textures/formats/multipatchtexture.h index 657576c7c3..63899808eb 100644 --- a/src/common/textures/formats/multipatchtexture.h +++ b/src/common/textures/formats/multipatchtexture.h @@ -140,6 +140,7 @@ class FMultipatchTextureBuilder { FTextureManager &TexMan; TArray BuiltTextures; + TMap complex; void(*progressFunc)(); void(*checkForHacks)(BuildInfo&); diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index ea55239d73..c4d8151a67 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -138,11 +138,9 @@ struct FPatchLookup void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType usetype) { FImageTexture *tex = new FImageTexture(nullptr); - tex->bMultiPatch = true; tex->SetSize(buildinfo.Width, buildinfo.Height); tex->bMasked = true; // we do not really know yet. tex->bTranslucent = -1; - tex->bNoDecals = buildinfo.bNoDecals; tex->SourceLump = buildinfo.DefinitionLump; buildinfo.itex = tex; buildinfo.texture = MakeGameTexture(tex, buildinfo.Name, usetype); @@ -150,6 +148,7 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X); buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning); + buildinfo.texture->SetNoDecals(buildinfo.bNoDecals); TexMan.AddGameTexture(buildinfo.texture); } @@ -778,9 +777,13 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) TexMan.ListTextures(buildinfo.Inits[i].TexName, list, true); for (int i = list.Size() - 1; i >= 0; i--) { - if (list[i] != buildinfo.texture->GetID() && !TexMan.GetGameTexture(list[i])->isMultiPatch() ) + if (list[i] != buildinfo.texture->GetID()) { - texno = list[i]; + auto gtex = TexMan.GetGameTexture(list[i]); + if (gtex && !dynamic_cast(gtex->GetTexture())) + { + texno = list[i]; + } break; } } @@ -813,8 +816,9 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) { //We cannot set the image source yet. First all textures need to be resolved. buildinfo.Inits[i].Texture = tex->GetTexture(); - buildinfo.itex->bComplex |= tex->GetTexture()->bComplex; // this one's NOT a material property! It must remain on the texture image. - buildinfo.bComplex |= tex->GetTexture()->bComplex; + bool iscomplex = !!complex.CheckKey(tex->GetTexture()); + if (iscomplex) complex.Insert(buildinfo.itex, true); + buildinfo.bComplex |= iscomplex; if (buildinfo.Inits[i].UseOffsets) { buildinfo.Parts[i].OriginX -= tex->GetTexelLeftOffset(0); diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index e2dc6ee834..fbbc251330 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -91,15 +91,10 @@ FTexture * FTexture::CreateTexture(int lumpnum, bool allowflats) FTexture::FTexture (int lumpnum) : SourceLump(lumpnum), - bNoDecals(false), bNoRemap0(false), bWorldPanning(false), - bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), bMultiPatch(false), bFullNameTexture(false), + bNoRemap0(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { bBrightmapChecked = false; - bGlowing = false; - bAutoGlowing = false; - bFullbright = false; - bDisableFullbright = false; bSkybox = false; bNoCompress = false; bTranslucent = -1; @@ -177,10 +172,10 @@ void FGameTexture::AddAutoMaterials() }; - int startindex = Base->bFullNameTexture ? 1 : 0; + bool fullname = !!(flags & GTexf_FullNameTexture); FString searchname = GetName(); - if (Base->bFullNameTexture) + if (fullname) { auto dot = searchname.LastIndexOf('.'); auto slash = searchname.LastIndexOf('/'); @@ -192,7 +187,7 @@ void FGameTexture::AddAutoMaterials() auto &layer = autosearchpaths[i]; if (this->*(layer.pointer) == nullptr) // only if no explicit assignment had been done. { - FStringf lookup("%s%s%s", layer.path, Base->bFullNameTexture ? "" : "auto/", searchname.GetChars()); + FStringf lookup("%s%s%s", layer.path, fullname ? "" : "auto/", searchname.GetChars()); auto lump = fileSystem.CheckNumForFullName(lookup, false, ns_global, true); if (lump != -1) { @@ -258,19 +253,19 @@ void FGameTexture::CreateDefaultBrightmap() // //========================================================================== -void FTexture::GetGlowColor(float *data) +void FGameTexture::GetGlowColor(float *data) { - if (bGlowing && GlowColor == 0) + if (isGlowing() && GlowColor == 0) { - auto buffer = GetBgraBitmap(nullptr); + auto buffer = Base->GetBgraBitmap(nullptr); GlowColor = averageColor((uint32_t*)buffer.GetPixels(), buffer.GetWidth() * buffer.GetHeight(), 153); // Black glow equals nothing so switch glowing off - if (GlowColor == 0) bGlowing = false; + if (GlowColor == 0) flags &= ~GTexf_Glowing; } - data[0] = GlowColor.r / 255.0f; - data[1] = GlowColor.g / 255.0f; - data[2] = GlowColor.b / 255.0f; + data[0] = GlowColor.r * (1/255.0f); + data[1] = GlowColor.g * (1/255.0f); + data[2] = GlowColor.b * (1/255.0f); } //=========================================================================== @@ -614,19 +609,26 @@ TArray FTexture::Get8BitPixels(bool alphatex) bool FGameTexture::ShouldExpandSprite() { - if (Base->bExpandSprite != -1) return Base->bExpandSprite; - if (isWarped() || isHardwareCanvas() || GetShaderIndex() != SHADER_Default) + if (expandSprite != -1) return expandSprite; + // Only applicable to image textures with no shader effect. + if (GetShaderIndex() != SHADER_Default || !dynamic_cast(Base.get())) { - Base->bExpandSprite = false; + expandSprite = false; return false; } if (Brightmap != NULL && (Base->GetWidth() != Brightmap->GetWidth() || Base->GetHeight() != Brightmap->GetHeight())) { - // do not expand if the brightmap's size differs. - Base->bExpandSprite = false; + // do not expand if the brightmap's physical size differs from the base. + expandSprite = false; return false; } - Base->bExpandSprite = true; + if (Glowmap != NULL && (Base->GetWidth() != Glowmap->GetWidth() || Base->GetHeight() != Glowmap->GetHeight())) + { + // same restriction for the glow map + expandSprite = false; + return false; + } + expandSprite = true; return true; } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index d73fdf28c3..62f70f8523 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -251,38 +251,22 @@ protected: int SourceLump; FHardwareTextureContainer SystemTextures; - uint8_t bNoDecals : 1; // Decals should not stick to texture uint8_t bNoRemap0 : 1; // Do not remap color 0 (used by front layer of parallax skies) - uint8_t bWorldPanning : 1; // Texture is panned in world units rather than texels + uint8_t bNoCompress : 1; + uint8_t bMasked : 1; // Texture (might) have holes uint8_t bAlphaTexture : 1; // Texture is an alpha channel without color information uint8_t bHasCanvas : 1; // Texture is based off FCanvasTexture - uint8_t bWarped : 2; // This is a warped texture. Used to avoid multiple warps on one texture - uint8_t bComplex : 1; // Will be used to mark extended MultipatchTextures that have to be - // fully composited before subjected to any kind of postprocessing instead of - // doing it per patch. - uint8_t bMultiPatch : 2; // This is a multipatch texture (we really could use real type info for textures...) - uint8_t bFullNameTexture : 1; uint8_t bBrightmapChecked : 1; // Set to 1 if brightmap has been checked - uint8_t bGlowing : 1; // Texture glow color - uint8_t bAutoGlowing : 1; // Glow info is determined from texture image. - uint8_t bFullbright : 1; // always draw fullbright - uint8_t bDisableFullbright : 1; // This texture will not be displayed as fullbright sprite - uint8_t bSkybox : 1; // is a cubic skybox - uint8_t bNoCompress : 1; int8_t bTranslucent : 2; - int8_t bExpandSprite = -1; uint16_t Rotations; int16_t SkyOffset; FloatRect* areas = nullptr; int areacount = 0; - int GlowHeight = 128; - PalEntry GlowColor = 0; - public: IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); @@ -296,29 +280,17 @@ public: int GetHeight() { return Height; } bool isSkybox() const { return bSkybox; } - bool isFullbrightDisabled() const { return bDisableFullbright; } bool isHardwareCanvas() const { return bHasCanvas; } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isCanvas() const { return bHasCanvas; } - int isWarped() const { return bWarped; } int GetRotations() const { return Rotations; } void SetRotations(int rot) { Rotations = int16_t(rot); } - void SetNoDecals(bool on) { bNoDecals = on; } - void SetWarpStyle(int style) { bWarped = style; } - bool allowNoDecals() const { return bNoDecals; } bool isMasked() const { return bMasked; } void SetSkyOffset(int offs) { SkyOffset = offs; } int GetSkyOffset() const { return SkyOffset; } virtual int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. - void GetGlowColor(float *data); - bool isGlowing() const { return bGlowing; } - bool isAutoGlowing() const { return bAutoGlowing; } - int GetGlowHeight() const { return GlowHeight; } - bool isFullbright() const { return bFullbright; } bool FindHoles(const unsigned char * buffer, int w, int h); int GetSourceLump() const { return SourceLump; } - bool UseWorldPanning() const { return bWorldPanning; } - void SetWorldPanning(bool on) { bWorldPanning = on; } void CopySize(FTexture* BaseTexture) @@ -380,7 +352,6 @@ public: bMasked = false; bHasCanvas = true; bTranslucent = false; - bExpandSprite = false; aspectRatio = (float)width / height; } @@ -508,6 +479,17 @@ public: } }; +enum EGameTexFlags +{ + GTexf_NoDecals = 1, // Decals should not stick to texture + GTexf_WorldPanning = 2, // Texture is panned in world units rather than texels + GTexf_FullNameTexture = 4, // Name is taken from the file system. + GTexf_Glowing = 8, // Texture emits a glow + GTexf_AutoGlowing = 16, // Glow info is determined from texture image. + GTexf_RenderFullbright = 32, // always draw fullbright + Gtexf_DisableFullbrightSprites = 64, // This texture will not be displayed as fullbright sprite +}; + // Refactoring helper to allow piece by piece adjustment of the API class FGameTexture { @@ -546,6 +528,11 @@ class FGameTexture float shaderspeed = 1.f; int shaderindex = 0; + int flags = 0; + uint8_t warped = 0, expandSprite = -1; + uint16_t GlowHeight; + PalEntry GlowColor = 0; + public: FGameTexture(FTexture* wrap, const char *name); ~FGameTexture(); @@ -580,22 +567,23 @@ public: float GetDisplayLeftOffset(int adjusted = 0) const { return LeftOffset[adjusted] / ScaleX; } float GetDisplayTopOffset(int adjusted = 0) const { return TopOffset[adjusted] / ScaleY; } + bool isMiscPatch() const { return GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. + bool isFullbrightDisabled() const { return !!(flags & Gtexf_DisableFullbrightSprites); } + bool isFullbright() const { return !!(flags & GTexf_RenderFullbright); } + bool isFullNameTexture() const { return !!(flags & GTexf_FullNameTexture); } + bool expandSprites() const { return !!expandSprite; } + bool useWorldPanning() const { return !!(flags & GTexf_WorldPanning); } + void SetWorldPanning(bool on) { if (on) flags |= GTexf_WorldPanning; else flags &= ~GTexf_WorldPanning; } + bool allowNoDecals() const { return !!(flags & GTexf_NoDecals); } + void SetNoDecals(bool on) { if (on) flags |= GTexf_NoDecals; else flags &= ~GTexf_NoDecals; } + bool isValid() const { return UseType != ETextureType::Null; } - int isWarped() { return Base->isWarped(); } - void SetWarpStyle(int style) { Base->bWarped = style; } + int isWarped() { return warped; } + void SetWarpStyle(int style) { warped = style; } bool isMasked() { return Base->isMasked(); } bool isHardwareCanvas() const { return Base->isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isSoftwareCanvas() const { return Base->isCanvas(); } - bool isMiscPatch() const { return GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. - bool isMultiPatch() const { return Base->bMultiPatch; } - bool isFullbrightDisabled() const { return Base->isFullbrightDisabled(); } - bool isFullbright() const { return Base->isFullbright(); } - bool isFullNameTexture() const { return Base->bFullNameTexture; } - bool expandSprites() const { return Base->bExpandSprite; } - bool useWorldPanning() const { return Base->UseWorldPanning(); } - void SetWorldPanning(bool on) { Base->SetWorldPanning(on); } - bool allowNoDecals() const { return Base->allowNoDecals(); } - void SetNoDecals(bool on) { Base->bNoDecals = on; } + void SetTranslucent(bool on) { Base->bTranslucent = on; } void SetUseType(ETextureType type) { UseType = type; } uint16_t GetRotations() const { return Base->GetRotations(); } @@ -646,15 +634,15 @@ public: } // Glowing is a pure material property that should not filter down to the actual texture objects. - void GetGlowColor(float* data) { Base->GetGlowColor(data); } - bool isGlowing() const { return Base->isGlowing(); } - bool isAutoGlowing() const { return Base->isAutoGlowing(); } - int GetGlowHeight() const { return Base->GetGlowHeight(); } - void SetAutoGlowing() { auto tex = GetTexture(); tex->bAutoGlowing = tex->bGlowing = tex->bFullbright = true; } - void SetGlowHeight(int v) { Base->GlowHeight = v; } - void SetFullbright() { Base->bFullbright = true; } - void SetDisableFullbright(bool on) { Base->bDisableFullbright = on; } - void SetGlowing(PalEntry color) { auto tex = GetTexture(); tex->bAutoGlowing = false; tex->bGlowing = true; tex->GlowColor = color; } + void GetGlowColor(float* data); + bool isGlowing() const { return !!(flags & GTexf_Glowing); } + bool isAutoGlowing() const { return !!(flags & GTexf_AutoGlowing); } + int GetGlowHeight() const { return GlowHeight; } + void SetAutoGlowing() { flags |= (GTexf_AutoGlowing | GTexf_Glowing | GTexf_RenderFullbright); } + void SetGlowHeight(int v) { GlowHeight = v; } + void SetFullbright() { flags |= GTexf_RenderFullbright; } + void SetDisableFullbright(bool on) { if (on) flags |= Gtexf_DisableFullbrightSprites; else flags &= ~Gtexf_DisableFullbrightSprites; } + void SetGlowing(PalEntry color) { flags = (flags & ~GTexf_AutoGlowing) | GTexf_Glowing; GlowColor = color; } bool isUserContent() const; int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); } From 217b80b1fb8eea31cd3e9263d06d42cd0a032db2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 12:02:06 +0200 Subject: [PATCH 053/220] - moved the brightmap check flag out of FTexture. --- src/common/textures/texture.cpp | 16 ++-------------- src/common/textures/textures.h | 12 +++++------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index fbbc251330..d559c71312 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -94,16 +94,11 @@ FTexture::FTexture (int lumpnum) bNoRemap0(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { - bBrightmapChecked = false; bSkybox = false; bNoCompress = false; bTranslucent = -1; } -FTexture::~FTexture () -{ -} - //=========================================================================== // // FTexture::GetBgraBitmap @@ -210,8 +205,9 @@ void FGameTexture::AddAutoMaterials() void FGameTexture::CreateDefaultBrightmap() { auto tex = GetTexture(); - if (!tex->bBrightmapChecked) + if (flags & GTexf_BrightmapChecked) { + flags |= GTexf_BrightmapChecked; // Check for brightmaps if (tex->GetImage() && tex->GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap && GetUseType() != ETextureType::Decal && GetUseType() != ETextureType::MiscPatch && GetUseType() != ETextureType::FontChar && @@ -229,19 +225,11 @@ void FGameTexture::CreateDefaultBrightmap() // Create a brightmap DPrintf(DMSG_NOTIFY, "brightmap created for texture '%s'\n", GetName().GetChars()); Brightmap = CreateBrightmapTexture(tex->GetImage()); - tex->bBrightmapChecked = true; - //TexMan.AddGameTexture(MakeGameTexture(tex->Brightmap)); return; } } // No bright pixels found DPrintf(DMSG_SPAMMY, "No bright pixels found in texture '%s'\n", GetName().GetChars()); - tex->bBrightmapChecked = true; - } - else - { - // does not have one so set the flag to 'done' - tex->bBrightmapChecked = true; } } } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 62f70f8523..d6872c697a 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -257,7 +257,6 @@ protected: uint8_t bMasked : 1; // Texture (might) have holes uint8_t bAlphaTexture : 1; // Texture is an alpha channel without color information uint8_t bHasCanvas : 1; // Texture is based off FCanvasTexture - uint8_t bBrightmapChecked : 1; // Set to 1 if brightmap has been checked uint8_t bSkybox : 1; // is a cubic skybox int8_t bTranslucent : 2; @@ -271,7 +270,6 @@ public: IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); static FTexture *CreateTexture(int lumpnum, bool allowflats = false); - virtual ~FTexture (); virtual FImageSource *GetImage() const { return nullptr; } void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); void CleanHardwareTextures(bool reallyclean); @@ -279,7 +277,6 @@ public: int GetWidth() { return Width; } int GetHeight() { return Height; } - bool isSkybox() const { return bSkybox; } bool isHardwareCanvas() const { return bHasCanvas; } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isCanvas() const { return bHasCanvas; } int GetRotations() const { return Rotations; } @@ -487,7 +484,8 @@ enum EGameTexFlags GTexf_Glowing = 8, // Texture emits a glow GTexf_AutoGlowing = 16, // Glow info is determined from texture image. GTexf_RenderFullbright = 32, // always draw fullbright - Gtexf_DisableFullbrightSprites = 64, // This texture will not be displayed as fullbright sprite + GTexf_DisableFullbrightSprites = 64, // This texture will not be displayed as fullbright sprite + GTexf_BrightmapChecked = 128, // Check for a colormap-based brightmap was already done. }; // Refactoring helper to allow piece by piece adjustment of the API @@ -568,7 +566,7 @@ public: float GetDisplayTopOffset(int adjusted = 0) const { return TopOffset[adjusted] / ScaleY; } bool isMiscPatch() const { return GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. - bool isFullbrightDisabled() const { return !!(flags & Gtexf_DisableFullbrightSprites); } + bool isFullbrightDisabled() const { return !!(flags & GTexf_DisableFullbrightSprites); } bool isFullbright() const { return !!(flags & GTexf_RenderFullbright); } bool isFullNameTexture() const { return !!(flags & GTexf_FullNameTexture); } bool expandSprites() const { return !!expandSprite; } @@ -641,12 +639,12 @@ public: void SetAutoGlowing() { flags |= (GTexf_AutoGlowing | GTexf_Glowing | GTexf_RenderFullbright); } void SetGlowHeight(int v) { GlowHeight = v; } void SetFullbright() { flags |= GTexf_RenderFullbright; } - void SetDisableFullbright(bool on) { if (on) flags |= Gtexf_DisableFullbrightSprites; else flags &= ~Gtexf_DisableFullbrightSprites; } + void SetDisableFullbright(bool on) { if (on) flags |= GTexf_DisableFullbrightSprites; else flags &= ~GTexf_DisableFullbrightSprites; } void SetGlowing(PalEntry color) { flags = (flags & ~GTexf_AutoGlowing) | GTexf_Glowing; GlowColor = color; } bool isUserContent() const; int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); } - bool isSkybox() const { return Base->isSkybox(); } + bool isSkybox() const { return Base->bSkybox; } void SetSize(int x, int y) { TexelWidth = x; From f7dd16ba1602de4b834ea0c2056ec20749012790 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 13:13:57 +0200 Subject: [PATCH 054/220] - test skyboxes with dynamic_cast and scale them properly. --- src/common/textures/skyboxtexture.cpp | 1 - src/common/textures/skyboxtexture.h | 39 +++++++++++++++++++ src/common/textures/texture.cpp | 1 - src/common/textures/textures.h | 38 ------------------ src/p_setup.cpp | 11 ++++-- src/rendering/hwrenderer/scene/hw_portal.h | 3 +- .../hwrenderer/scene/hw_skyportal.cpp | 8 ++-- .../hwrenderer/textures/hw_precache.cpp | 6 +-- 8 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index b77a2ad3b0..c5616643b8 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -44,7 +44,6 @@ FSkyBox::FSkyBox(const char *name) } else previous = nullptr; faces[0]=faces[1]=faces[2]=faces[3]=faces[4]=faces[5] = nullptr; - bSkybox = true; fliptop = false; } diff --git a/src/common/textures/skyboxtexture.h b/src/common/textures/skyboxtexture.h index 14ada8b4ae..645e54b934 100644 --- a/src/common/textures/skyboxtexture.h +++ b/src/common/textures/skyboxtexture.h @@ -1,3 +1,42 @@ #pragma once #include "textures.h" + +//----------------------------------------------------------------------------- +// +// Todo: Get rid of this +// The faces can easily be stored in the material layer array +// +//----------------------------------------------------------------------------- + +class FSkyBox : public FImageTexture +{ +public: + + FGameTexture* previous; + FGameTexture* faces[6]; // the faces need to be full materials as they can have all supported effects. + bool fliptop; + + FSkyBox(const char* name); + void SetSize(); + + bool Is3Face() const + { + return faces[5] == nullptr; + } + + bool IsFlipped() const + { + return fliptop; + } + + FGameTexture* GetSkyFace(int num) const + { + return faces[num]; + } + + bool GetSkyFlip() const + { + return fliptop; + } +}; diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index d559c71312..2ffab8d1fc 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -94,7 +94,6 @@ FTexture::FTexture (int lumpnum) bNoRemap0(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) { - bSkybox = false; bNoCompress = false; bTranslucent = -1; } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index d6872c697a..a062cb6438 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -258,7 +258,6 @@ protected: uint8_t bAlphaTexture : 1; // Texture is an alpha channel without color information uint8_t bHasCanvas : 1; // Texture is based off FCanvasTexture - uint8_t bSkybox : 1; // is a cubic skybox int8_t bTranslucent : 2; uint16_t Rotations; @@ -447,35 +446,6 @@ enum }; -//----------------------------------------------------------------------------- -// -// Todo: Get rid of this -// The faces can easily be stored in the material layer array -// -//----------------------------------------------------------------------------- - -class FSkyBox : public FImageTexture -{ -public: - - FGameTexture* previous; - FGameTexture* faces[6]; // the faces need to be full materials as they can have all supported effects. - bool fliptop; - - FSkyBox(const char* name); - void SetSize(); - - bool Is3Face() const - { - return faces[5] == nullptr; - } - - bool IsFlipped() const - { - return fliptop; - } -}; - enum EGameTexFlags { GTexf_NoDecals = 1, // Decals should not stick to texture @@ -644,7 +614,6 @@ public: bool isUserContent() const; int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); } - bool isSkybox() const { return Base->bSkybox; } void SetSize(int x, int y) { TexelWidth = x; @@ -684,13 +653,6 @@ public: return Base->GetTranslucency(); } - // Since these properties will later piggyback on existing members of FGameTexture, the accessors need to be here. - FGameTexture *GetSkyFace(int num) - { - return (isSkybox() ? static_cast(Base.get())->faces[num] : nullptr); - } - bool GetSkyFlip() { return isSkybox() ? static_cast(Base.get())->fliptop : false; } - int GetClampMode(int clampmode) { if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index fbd93e75ee..c7ab8dfd4e 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -78,6 +78,7 @@ #include "s_music.h" #include "animations.h" #include "texturemanager.h" +#include "p_lnspec.h" extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position); @@ -188,9 +189,13 @@ static void PrecacheLevel(FLevelLocals *Level) for (i = Level->sides.Size() - 1; i >= 0; i--) { - AddToList(hitlist.Data(), Level->sides[i].GetTexture(side_t::top), FTextureManager::HIT_Wall); - AddToList(hitlist.Data(), Level->sides[i].GetTexture(side_t::mid), FTextureManager::HIT_Wall); - AddToList(hitlist.Data(), Level->sides[i].GetTexture(side_t::bottom), FTextureManager::HIT_Wall); + auto &sd = Level->sides[i]; + int hitflag = FTextureManager::HIT_Wall; + // Only precache skyboxes when this is actually used as a sky transfer. + if (sd.linedef->sidedef[0] == &sd && sd.linedef->special == Static_Init && sd.linedef->args[1] == Init_TransferSky) hitflag |= FTextureManager::HIT_Sky; + AddToList(hitlist.Data(), sd.GetTexture(side_t::top), hitflag); + AddToList(hitlist.Data(), sd.GetTexture(side_t::mid), FTextureManager::HIT_Wall); + AddToList(hitlist.Data(), sd.GetTexture(side_t::bottom), hitflag); } diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index 10fd90d7db..88a920a2fa 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -8,6 +8,7 @@ #include "hw_renderstate.h" #include "hw_material.h" +class FSkyBox; struct HWSkyInfo { @@ -358,7 +359,7 @@ struct HWSkyPortal : public HWPortal friend struct HWEEHorizonPortal; void RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply = true); - void RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FGameTexture * gltex, float x_offset, bool sky2); + void RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FSkyBox * gltex, float x_offset, bool sky2); void RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode); protected: diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index a41fff53e2..cc945178db 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -93,12 +93,13 @@ void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * // //----------------------------------------------------------------------------- -void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FGameTexture * tex, float x_offset, bool sky2) +void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FSkyBox * tex, float x_offset, bool sky2) { int faces; state.EnableModelMatrix(true); state.mModelMatrix.loadIdentity(); + state.mModelMatrix.scale(1, 1 / di->Level->info->pixelstretch, 1); // Undo the map's vertical scaling as skyboxes are true cubes. if (!sky2) state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector.X, di->Level->info->skyrotatevector.Z, di->Level->info->skyrotatevector.Y); @@ -171,9 +172,10 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) di->SetupView(state, 0, 0, 0, !!(mState->MirrorFlag & 1), !!(mState->PlaneMirrorFlag & 1)); state.SetVertexBuffer(vertexBuffer); - if (origin->texture[0] && origin->texture[0]->isSkybox()) + auto skybox = origin->texture[0] ? dynamic_cast(origin->texture[0]->GetTexture()) : nullptr; + if (skybox) { - RenderBox(di, state, origin->skytexno1, origin->texture[0], origin->x_offset[0], origin->sky2); + RenderBox(di, state, origin->skytexno1, skybox, origin->x_offset[0], origin->sky2); } else { diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index dd29321214..f3518bfb8c 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -101,12 +101,12 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl for (int i = 0; iisSkybox()) + auto sb = dynamic_cast(tex->GetTexture()); + if (sb) { - FSkyBox *sb = static_cast(tex->GetTexture()); for (int i = 0; i<6; i++) { if (sb->faces[i]) From 389892a0794d88e8ac14dc229db8256683762431 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 13:32:23 +0200 Subject: [PATCH 055/220] - moved SkyOffset and Rotations. --- src/common/textures/textures.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index a062cb6438..dbed3ec219 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -260,8 +260,6 @@ protected: int8_t bTranslucent : 2; - uint16_t Rotations; - int16_t SkyOffset; FloatRect* areas = nullptr; int areacount = 0; @@ -278,15 +276,10 @@ public: bool isHardwareCanvas() const { return bHasCanvas; } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isCanvas() const { return bHasCanvas; } - int GetRotations() const { return Rotations; } - void SetRotations(int rot) { Rotations = int16_t(rot); } bool isMasked() const { return bMasked; } - void SetSkyOffset(int offs) { SkyOffset = offs; } - int GetSkyOffset() const { return SkyOffset; } - virtual int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. + int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. bool FindHoles(const unsigned char * buffer, int w, int h); - int GetSourceLump() const { return SourceLump; } void CopySize(FTexture* BaseTexture) @@ -501,6 +494,10 @@ class FGameTexture uint16_t GlowHeight; PalEntry GlowColor = 0; + int16_t SkyOffset; + uint16_t Rotations; + + public: FGameTexture(FTexture* wrap, const char *name); ~FGameTexture(); @@ -554,10 +551,10 @@ public: void SetTranslucent(bool on) { Base->bTranslucent = on; } void SetUseType(ETextureType type) { UseType = type; } - uint16_t GetRotations() const { return Base->GetRotations(); } - void SetRotations(int index) { Base->SetRotations(index); } - void SetSkyOffset(int ofs) { Base->SetSkyOffset(ofs); } - int GetSkyOffset() const { return Base->GetSkyOffset(); } + int GetRotations() const { return Rotations; } + void SetRotations(int rot) { Rotations = int16_t(rot); } + void SetSkyOffset(int offs) { SkyOffset = offs; } + int GetSkyOffset() const { return SkyOffset; } ISoftwareTexture* GetSoftwareTexture() { From 59cd049b779db8b353b14e099b3dfeb749056947 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 13:32:51 +0200 Subject: [PATCH 056/220] - added missing handling for Rotations to the hardware renderer. Untested due to lack of material. --- src/rendering/hwrenderer/scene/hw_sprites.cpp | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 11e7ded60b..c9dae43480 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -785,7 +785,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t modelframe = isPicnumOverride ? nullptr : FindModelFrame(thing->GetClass(), spritenum, thing->frame, !!(thing->flags & MF_DROPPED)); if (!modelframe) { - bool mirror; + bool mirror = false; DAngle ang = (thingpos - vp.Pos).Angle(); FTextureID patch; // [ZZ] add direct picnum override @@ -794,8 +794,35 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t // Animate picnum overrides. auto tex = TexMan.GetGameTexture(thing->picnum, true); if (tex == nullptr) return; + + if (tex->GetRotations() != 0xFFFF) + { + // choose a different rotation based on player view + spriteframe_t* sprframe = &SpriteFrames[tex->GetRotations()]; + DAngle sprang = thing->GetSpriteAngle(ang, vp.TicFrac); + angle_t rot; + if (sprframe->Texture[0] == sprframe->Texture[1]) + { + if (thing->flags7 & MF7_SPRITEANGLE) + rot = (thing->SpriteAngle + 45.0 / 2 * 9).BAMs() >> 28; + else + rot = (sprang - (thing->Angles.Yaw + thing->SpriteRotation) + 45.0 / 2 * 9).BAMs() >> 28; + } + else + { + if (thing->flags7 & MF7_SPRITEANGLE) + rot = (thing->SpriteAngle + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28; + else + rot = (sprang - (thing->Angles.Yaw + thing->SpriteRotation) + (45.0 / 2 * 9 - 180.0 / 16)).BAMs() >> 28; + } + auto picnum = sprframe->Texture[rot]; + if (sprframe->Flip & (1 << rot)) + { + mirror = true; + } + } + patch = tex->GetID(); - mirror = false; } else { From ef8e7a49448809922627fc189d66c439805373f3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 21:04:55 +0200 Subject: [PATCH 057/220] - reworked the multipatch texture builder to reuse the FImageTexture objects. --- src/common/fonts/font.cpp | 7 +- .../textures/formats/multipatchtexture.cpp | 8 ++- .../textures/formats/multipatchtexture.h | 26 ++++++-- src/common/textures/formats/pngtexture.cpp | 2 + src/common/textures/imagetexture.cpp | 2 +- .../textures/multipatchtexturebuilder.cpp | 66 ++++++++++--------- src/common/textures/skyboxtexture.cpp | 1 - src/common/textures/texture.cpp | 34 ++++------ src/common/textures/texturemanager.cpp | 12 ++-- src/common/textures/textures.h | 39 +++++------ src/d_main.cpp | 2 +- .../swrenderer/textures/r_swtexture.cpp | 2 +- .../swrenderer/textures/r_swtexture.h | 2 +- 13 files changed, 104 insertions(+), 99 deletions(-) diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 16cbd07d7d..985ba49819 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -381,7 +381,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla void FFont::ReadSheetFont(TArray &folderdata, int width, int height, const DVector2 &Scale) { // all valid lumps must be named with a hex number that represents the Unicode character index for its first character, - TArray part(1, true); + TArray part(1, true); TMap charMap; int minchar = INT_MAX; int maxchar = INT_MIN; @@ -408,13 +408,10 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height { part[0].OriginX = -width * x; part[0].OriginY = -height * y; - part[0].Image = tex->GetTexture()->GetImage(); + part[0].TexImage = static_cast(tex->GetTexture()); FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false); FImageTexture *tex = new FImageTexture(image); auto gtex = MakeGameTexture(tex, nullptr, ETextureType::FontChar); - tex->bMasked = true; - tex->bTranslucent = -1; - tex->SourceLump = -1; // We do not really care. gtex->SetWorldPanning(true); gtex->SetOffsets(0, 0, 0); gtex->SetOffsets(1, 0, 0); diff --git a/src/common/textures/formats/multipatchtexture.cpp b/src/common/textures/formats/multipatchtexture.cpp index dfd63ea387..e131b90245 100644 --- a/src/common/textures/formats/multipatchtexture.cpp +++ b/src/common/textures/formats/multipatchtexture.cpp @@ -46,15 +46,19 @@ // //========================================================================== -FMultiPatchTexture::FMultiPatchTexture(int w, int h, const TArray &parts, bool complex, bool textual) +FMultiPatchTexture::FMultiPatchTexture(int w, int h, const TArray &parts, bool complex, bool textual) { Width = w; Height = h; bComplex = complex; - bTextual = textual; + bTextual = textual; Parts = (TexPart*)ImageArena.Alloc(sizeof(TexPart) * parts.Size()); NumParts = parts.Size(); memcpy(Parts, parts.Data(), sizeof(TexPart) * parts.Size()); + for (unsigned i = 0; i < parts.Size(); i++) + { + Parts[i].Image = parts[i].TexImage->GetImage(); + } bUseGamePalette = false; if (!bComplex) diff --git a/src/common/textures/formats/multipatchtexture.h b/src/common/textures/formats/multipatchtexture.h index 63899808eb..51f36abf5e 100644 --- a/src/common/textures/formats/multipatchtexture.h +++ b/src/common/textures/formats/multipatchtexture.h @@ -5,6 +5,7 @@ #include "vectors.h" #include "bitmap.h" #include "image.h" +#include "textures.h" class FImageTexture; class FTextureManager; @@ -27,6 +28,18 @@ struct TexPart uint8_t op = OP_COPY; }; +struct TexPartBuild +{ + FRemapTable* Translation = nullptr; + FImageTexture *TexImage = nullptr; + PalEntry Blend = 0; + blend_t Alpha = FRACUNIT; + int16_t OriginX = 0; + int16_t OriginY = 0; + uint8_t Rotate = 0; + uint8_t op = OP_COPY; +}; + //========================================================================== @@ -40,7 +53,7 @@ class FMultiPatchTexture : public FImageSource friend class FTexture; friend class FGameTexture; public: - FMultiPatchTexture(int w, int h, const TArray &parts, bool complex, bool textual); + FMultiPatchTexture(int w, int h, const TArray &parts, bool complex, bool textual); int GetNumParts() const { return NumParts; } // Query some needed info for texture hack support. bool SupportRemap0() override; @@ -79,7 +92,7 @@ struct TexInit { FString TexName; ETextureType UseType = ETextureType::Null; - FTexture *Texture = nullptr; + FImageTexture *Texture = nullptr; bool Silent = false; bool HasLine = false; bool UseOffsets = false; @@ -97,7 +110,7 @@ struct FPatchLookup; struct BuildInfo { FString Name; - TArray Parts; + TArray Parts; TArray Inits; int Width = 0; int Height = 0; @@ -109,7 +122,6 @@ struct BuildInfo bool bNoDecals = false; int LeftOffset[2] = {}; int TopOffset[2] = {}; - FImageTexture* itex = nullptr; FGameTexture *texture = nullptr; void swap(BuildInfo &other) @@ -129,7 +141,6 @@ struct BuildInfo std::swap(LeftOffset[1], other.LeftOffset[1]); std::swap(TopOffset[0], other.TopOffset[0]); std::swap(TopOffset[1], other.TopOffset[1]); - std::swap(itex, other.itex); std::swap(texture, other.texture); } }; @@ -140,16 +151,17 @@ class FMultipatchTextureBuilder { FTextureManager &TexMan; TArray BuiltTextures; - TMap complex; + TMap complex; void(*progressFunc)(); void(*checkForHacks)(BuildInfo&); void MakeTexture(BuildInfo &buildinfo, ETextureType usetype); + void AddImageToTexture(FImageTexture* tex, BuildInfo& buildinfo); void BuildTexture(const void *texdef, FPatchLookup *patchlookup, int maxpatchnum, bool strife, int deflumpnum, ETextureType usetyoe); void AddTexturesLump(const void *lumpdata, int lumpsize, int deflumpnum, int patcheslump, int firstdup, bool texture1); - void ParsePatch(FScanner &sc, BuildInfo &info, TexPart &part, TexInit &init); + void ParsePatch(FScanner &sc, BuildInfo &info, TexPartBuild &part, TexInit &init); void ResolvePatches(BuildInfo &buildinfo); public: diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index 0357b0da9f..790984d2e0 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -623,6 +623,8 @@ FPNGFileTexture::FPNGFileTexture (FileReader &lump, int width, int height, uint8 { Width = width; Height = height; + Masked = false; + bTranslucent = false; fr = std::move(lump); } diff --git a/src/common/textures/imagetexture.cpp b/src/common/textures/imagetexture.cpp index bde19f8b89..d222733a7e 100644 --- a/src/common/textures/imagetexture.cpp +++ b/src/common/textures/imagetexture.cpp @@ -63,7 +63,7 @@ void FImageTexture::SetFromImage() Width = img->GetWidth(); Height = img->GetHeight(); - bMasked = img->bMasked; + Masked = img->bMasked; bTranslucent = img->bTranslucent; } //=========================================================================== diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index c4d8151a67..689330eb19 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -57,7 +57,6 @@ #endif - //-------------------------------------------------------------------------- // // Data structures for the TEXTUREx lumps @@ -85,7 +84,7 @@ struct mappatch_t struct maptexture_t { uint8_t name[8]; - uint16_t Flags; // [RH] Was unused + uint16_t Flags; // [RH] Was unused uint8_t ScaleX; // [RH] Scaling (8 is normal) uint8_t ScaleY; // [RH] Same as above int16_t width; @@ -113,7 +112,7 @@ struct strifemappatch_t struct strifemaptexture_t { uint8_t name[8]; - uint16_t Flags; // [RH] Was unused + uint16_t Flags; // [RH] Was unused uint8_t ScaleX; // [RH] Scaling (8 is normal) uint8_t ScaleY; // [RH] Same as above int16_t width; @@ -137,22 +136,23 @@ struct FPatchLookup void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType usetype) { - FImageTexture *tex = new FImageTexture(nullptr); - tex->SetSize(buildinfo.Width, buildinfo.Height); - tex->bMasked = true; // we do not really know yet. - tex->bTranslucent = -1; - tex->SourceLump = buildinfo.DefinitionLump; - buildinfo.itex = tex; - buildinfo.texture = MakeGameTexture(tex, buildinfo.Name, usetype); + buildinfo.texture = new FGameTexture(nullptr, buildinfo.Name); + buildinfo.texture->SetUseType(usetype); + TexMan.AddGameTexture(buildinfo.texture); +} + +void FMultipatchTextureBuilder::AddImageToTexture(FImageTexture *tex, BuildInfo& buildinfo) +{ + buildinfo.texture->Setup(tex); buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X); buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning); buildinfo.texture->SetNoDecals(buildinfo.bNoDecals); - - TexMan.AddGameTexture(buildinfo.texture); + calcShouldUpscale(buildinfo.texture); // calculate this once at insertion } + //========================================================================== // // The reader for TEXTUREx @@ -235,7 +235,7 @@ void FMultipatchTextureBuilder::BuildTexture(const void *texdef, FPatchLookup *p } buildinfo.Parts[i].OriginX = LittleShort(mpatch.d->originx); buildinfo.Parts[i].OriginY = LittleShort(mpatch.d->originy); - buildinfo.Parts[i].Image = nullptr; + buildinfo.Parts[i].TexImage = nullptr; buildinfo.Inits[i].TexName = patchlookup[LittleShort(mpatch.d->patch)].Name; buildinfo.Inits[i].UseType = ETextureType::WallPatch; if (strife) @@ -417,7 +417,7 @@ void FMultipatchTextureBuilder::AddTexturesLumps(int lump1, int lump2, int patch // //========================================================================== -void FMultipatchTextureBuilder::ParsePatch(FScanner &sc, BuildInfo &info, TexPart & part, TexInit &init) +void FMultipatchTextureBuilder::ParsePatch(FScanner &sc, BuildInfo &info, TexPartBuild & part, TexInit &init) { FString patchname; int Mirror = 0; @@ -669,7 +669,7 @@ void FMultipatchTextureBuilder::ParseTexture(FScanner &sc, ETextureType UseType) } else if (sc.Compare("Patch")) { - TexPart part; + TexPartBuild part; TexInit init; ParsePatch(sc, buildinfo, part, init); if (init.TexName.IsNotEmpty()) @@ -681,12 +681,12 @@ void FMultipatchTextureBuilder::ParseTexture(FScanner &sc, ETextureType UseType) init.sc = sc; buildinfo.Inits.Push(init); } - part.Image = nullptr; + part.TexImage = nullptr; part.Translation = nullptr; } else if (sc.Compare("Sprite")) { - TexPart part; + TexPartBuild part; TexInit init; ParsePatch(sc, buildinfo, part, init); if (init.TexName.IsNotEmpty()) @@ -698,12 +698,12 @@ void FMultipatchTextureBuilder::ParseTexture(FScanner &sc, ETextureType UseType) init.sc = sc; buildinfo.Inits.Push(init); } - part.Image = nullptr; + part.TexImage = nullptr; part.Translation = nullptr; } else if (sc.Compare("Graphic")) { - TexPart part; + TexPartBuild part; TexInit init; ParsePatch(sc, buildinfo, part, init); if (init.TexName.IsNotEmpty()) @@ -715,7 +715,7 @@ void FMultipatchTextureBuilder::ParseTexture(FScanner &sc, ETextureType UseType) init.sc = sc; buildinfo.Inits.Push(init); } - part.Image = nullptr; + part.TexImage = nullptr; part.Translation = nullptr; } else if (sc.Compare("Offset")) @@ -812,12 +812,12 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) { FGameTexture *tex = TexMan.GetGameTexture(texno); - if (tex != nullptr && tex->isValid()) + if (tex != nullptr && tex->isValid() && dynamic_cast(tex->GetTexture())) { //We cannot set the image source yet. First all textures need to be resolved. - buildinfo.Inits[i].Texture = tex->GetTexture(); - bool iscomplex = !!complex.CheckKey(tex->GetTexture()); - if (iscomplex) complex.Insert(buildinfo.itex, true); + buildinfo.Inits[i].Texture = static_cast(tex->GetTexture()); + bool iscomplex = !!complex.CheckKey(tex); + if (iscomplex) complex.Insert(buildinfo.texture, true); buildinfo.bComplex |= iscomplex; if (buildinfo.Inits[i].UseOffsets) { @@ -876,12 +876,12 @@ void FMultipatchTextureBuilder::ResolveAllPatches() for (unsigned j = 0; j < buildinfo.Inits.Size(); j++) { - if (buildinfo.Parts[j].Image == nullptr) + if (buildinfo.Parts[j].TexImage == nullptr) { - auto image = buildinfo.Inits[j].Texture->GetImage(); - if (image != nullptr) + auto image = buildinfo.Inits[j].Texture; + if (image->GetImage() != nullptr) { - buildinfo.Parts[j].Image = image; + buildinfo.Parts[j].TexImage = image; donesomething = true; } else hasEmpty = true; @@ -896,19 +896,21 @@ void FMultipatchTextureBuilder::ResolveAllPatches() if (buildinfo.Parts.Size() == 1) { if (buildinfo.Parts[0].OriginX == 0 && buildinfo.Parts[0].OriginY == 0 && - buildinfo.Parts[0].Image->GetWidth() == buildinfo.Width && - buildinfo.Parts[0].Image->GetHeight() == buildinfo.Height && + buildinfo.Parts[0].TexImage->GetWidth() == buildinfo.Width && + buildinfo.Parts[0].TexImage->GetHeight() == buildinfo.Height && buildinfo.Parts[0].Rotate == 0 && !buildinfo.bComplex) { - buildinfo.itex->SetImage(buildinfo.Parts[0].Image); + AddImageToTexture(buildinfo.Parts[0].TexImage, buildinfo); + buildinfo.texture->Setup(buildinfo.Parts[0].TexImage); done = true; } } if (!done) { auto img = new FMultiPatchTexture(buildinfo.Width, buildinfo.Height, buildinfo.Parts, buildinfo.bComplex, buildinfo.textual); - buildinfo.itex->SetImage(img); + auto itex = new FImageTexture(img); + AddImageToTexture(itex, buildinfo); } BuiltTextures.Delete(i); diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index c5616643b8..d8c645e8b9 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -59,6 +59,5 @@ void FSkyBox::SetSize() if (previous && previous->GetTexture()->GetImage()) { SetImage(previous->GetTexture()->GetImage()); - SetFromImage(); } } diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 2ffab8d1fc..e8cf04505b 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -89,12 +89,8 @@ FTexture * FTexture::CreateTexture(int lumpnum, bool allowflats) //========================================================================== FTexture::FTexture (int lumpnum) - : - SourceLump(lumpnum), - bNoRemap0(false), bMasked(true), bAlphaTexture(false), bHasCanvas(false), - Rotations(0xFFFF), SkyOffset(0), Width(0), Height(0) + : SourceLump(lumpnum), bHasCanvas(false) { - bNoCompress = false; bTranslucent = -1; } @@ -188,7 +184,6 @@ void FGameTexture::AddAutoMaterials() auto bmtex = TexMan.FindGameTexture(fileSystem.GetFileFullName(lump), ETextureType::Any, FTextureManager::TEXMAN_TryAny); if (bmtex != nullptr) { - bmtex->GetTexture()->bMasked = false; this->*(layer.pointer) = bmtex->GetTexture(); } } @@ -471,10 +466,10 @@ bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h) bool FTexture::ProcessData(unsigned char * buffer, int w, int h, bool ispatch) { - if (bMasked) + if (Masked) { - bMasked = SmoothEdges(buffer, w, h); - if (bMasked && !ispatch) FindHoles(buffer, w, h); + Masked = SmoothEdges(buffer, w, h); + if (Masked && !ispatch) FindHoles(buffer, w, h); } return true; } @@ -557,15 +552,8 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags) bool FTexture::DetermineTranslucency() { - if (!bHasCanvas) - { - // This will calculate all we need, so just discard the result. - CreateTexBuffer(0); - } - else - { - bTranslucent = 0; - } + // This will calculate all we need, so just discard the result. + CreateTexBuffer(0); return !!bTranslucent; } @@ -930,15 +918,21 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) Width = w; Height = h; Format = bits; - bNoCompress = true; + //bNoCompress = true; auto hwtex = CreateHardwareTexture(); // todo: Initialize here. SystemTextures.AddHardwareTexture(0, false, hwtex); } -FGameTexture::FGameTexture(FTexture* wrap, const char *name) : Base(wrap), Name(name) +FGameTexture::FGameTexture(FTexture* wrap, const char* name) : Name(name) { + if (wrap) Setup(wrap); +} + +void FGameTexture::Setup(FTexture *wrap) +{ + Base = wrap; id.SetInvalid(); TexelWidth = Base->GetWidth(); DisplayWidth = (float)TexelWidth; diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 5ff1ad6570..7c71eda67a 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -383,8 +383,11 @@ FTextureID FTextureManager::AddGameTexture (FGameTexture *texture, bool addtohas if (texture == NULL) return FTextureID(-1); - // Later textures take precedence over earlier ones - calcShouldUpscale(texture); // calculate this once at insertion + if (texture->GetTexture()) + { + // Later textures take precedence over earlier ones + calcShouldUpscale(texture); // calculate this once at insertion + } // Textures without name can't be looked for if (addtohash && texture->GetName().IsNotEmpty()) @@ -1268,9 +1271,10 @@ FTextureID FTextureManager::GetFrontSkyLayer(FTextureID texid) // Set this up so that it serializes to the same info as the base texture - this is needed to restore it on load. // But do not link the new texture into the hash chain! - auto FrontSkyLayer = MakeGameTexture(new FImageTexture(image), tex->GetName(), ETextureType::Wall); + auto itex = new FImageTexture(image); + itex->SetNoRemap0(); + auto FrontSkyLayer = MakeGameTexture(itex, tex->GetName(), ETextureType::Wall); FrontSkyLayer->SetUseType(tex->GetUseType()); - FrontSkyLayer->GetTexture()->bNoRemap0 = true; texid = TexMan.AddGameTexture(FrontSkyLayer, false); Textures[texidx].FrontSkyLayer = texid.GetIndex(); Textures[texid.GetIndex()].FrontSkyLayer = texid.GetIndex(); // also let it refer to itself as its front sky layer, in case for repeated InitSkyMap calls. diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index dbed3ec219..df482d6809 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -240,28 +240,18 @@ struct SpritePositioningInfo class FTexture : public RefCountedBase { friend class FGameTexture; // only for the porting work - friend class FTexture; - friend struct FTexCoordInfo; - friend class FMultipatchTextureBuilder; - friend class FMaterial; - friend class FFont; protected: - uint16_t Width, Height; - int SourceLump; FHardwareTextureContainer SystemTextures; - - uint8_t bNoRemap0 : 1; // Do not remap color 0 (used by front layer of parallax skies) - uint8_t bNoCompress : 1; - - uint8_t bMasked : 1; // Texture (might) have holes - uint8_t bAlphaTexture : 1; // Texture is an alpha channel without color information - uint8_t bHasCanvas : 1; // Texture is based off FCanvasTexture - - int8_t bTranslucent : 2; - FloatRect* areas = nullptr; - int areacount = 0; + int SourceLump; + uint16_t Width = 0, Height = 0; + + bool Masked = false; // Texture (might) have holes + bool bHasCanvas = false; + int8_t bTranslucent = -1; + int8_t areacount = 0; // this is capped at 4 sections. + public: @@ -277,7 +267,6 @@ public: bool isHardwareCanvas() const { return bHasCanvas; } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isCanvas() const { return bHasCanvas; } - bool isMasked() const { return bMasked; } int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. bool FindHoles(const unsigned char * buffer, int w, int h); @@ -338,9 +327,7 @@ public: Width = width; Height = height; - bMasked = false; bHasCanvas = true; - bTranslucent = false; aspectRatio = (float)width / height; } @@ -380,6 +367,7 @@ public: class FImageTexture : public FTexture { FImageSource* mImage; + bool bNoRemap0; protected: void SetFromImage(); public: @@ -389,7 +377,9 @@ public: void SetImage(FImageSource* img) // This is only for the multipatch texture builder! { mImage = img; + SetFromImage(); } + void SetNoRemap0() { bNoRemap0 = true; } FImageSource* GetImage() const override { return mImage; } FBitmap GetBgraBitmap(const PalEntry* p, int* trans) override; @@ -494,13 +484,14 @@ class FGameTexture uint16_t GlowHeight; PalEntry GlowColor = 0; - int16_t SkyOffset; - uint16_t Rotations; + int16_t SkyOffset = 0; + uint16_t Rotations = 0xffff; public: FGameTexture(FTexture* wrap, const char *name); ~FGameTexture(); + void Setup(FTexture* wrap); FTextureID GetID() const { return id; } void SetID(FTextureID newid) { id = newid; } // should only be called by the texture manager const FString& GetName() const { return Name; } @@ -545,7 +536,7 @@ public: bool isValid() const { return UseType != ETextureType::Null; } int isWarped() { return warped; } void SetWarpStyle(int style) { warped = style; } - bool isMasked() { return Base->isMasked(); } + bool isMasked() { return Base->Masked; } bool isHardwareCanvas() const { return Base->isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. bool isSoftwareCanvas() const { return Base->isCanvas(); } diff --git a/src/d_main.cpp b/src/d_main.cpp index 47eb81928a..9cfb1582ff 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2674,7 +2674,7 @@ static void CheckForHacks(BuildInfo& buildinfo) buildinfo.Parts.Size() == 1) { // This must alter the size of both the texture image and the game texture. - buildinfo.Height = buildinfo.Parts[0].Image->GetHeight(); + buildinfo.Height = buildinfo.Parts[0].TexImage->GetHeight(); buildinfo.texture->GetTexture()->SetSize(buildinfo.texture->GetTexelWidth(), buildinfo.Height); buildinfo.texture->SetSize(buildinfo.texture->GetTexelWidth(), buildinfo.Height); return; diff --git a/src/rendering/swrenderer/textures/r_swtexture.cpp b/src/rendering/swrenderer/textures/r_swtexture.cpp index 6fd4b5d2b6..baa4f1c71c 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.cpp +++ b/src/rendering/swrenderer/textures/r_swtexture.cpp @@ -276,7 +276,7 @@ FSoftwareTextureSpan **FSoftwareTexture::CreateSpans (const T *pixels) { FSoftwareTextureSpan **spans, *span; - if (!mSource->isMasked()) + if (!mTexture->isMasked()) { // Texture does not have holes, so it can use a simpler span structure spans = (FSoftwareTextureSpan **)M_Malloc (sizeof(FSoftwareTextureSpan*)*GetPhysicalWidth() + sizeof(FSoftwareTextureSpan)*2); span = (FSoftwareTextureSpan *)&spans[GetPhysicalWidth()]; diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index 3e462d36e0..d44062ea4b 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -53,7 +53,7 @@ public: bool isMasked() { - return mSource->isMasked(); + return mTexture->isMasked(); } uint16_t GetRotations() const From c836dd3dbf8f086992938ce01168b3def3937a5b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 21:56:52 +0200 Subject: [PATCH 058/220] - initialize bNoRemap0 --- src/common/textures/textures.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index df482d6809..774c751614 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -367,7 +367,7 @@ public: class FImageTexture : public FTexture { FImageSource* mImage; - bool bNoRemap0; + bool bNoRemap0 = false; protected: void SetFromImage(); public: From 46e75e81070a2479e4f0590dbed9e2d157c28ca2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 22:20:15 +0200 Subject: [PATCH 059/220] - fixed crash with particles checking a non-existent actor. --- src/common/textures/textures.h | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 774c751614..9b2f6e1c2a 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -374,7 +374,7 @@ public: FImageTexture(FImageSource* image) noexcept; virtual TArray Get8BitPixels(bool alphatex); - void SetImage(FImageSource* img) // This is only for the multipatch texture builder! + void SetImage(FImageSource* img) { mImage = img; SetFromImage(); diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index c9dae43480..44dee7c84d 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -197,7 +197,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) state.SetFog(0, 0); } - uint32_t spritetype = (actor->renderflags & RF_SPRITETYPEMASK); + uint32_t spritetype = actor? uint32_t(actor->renderflags & RF_SPRITETYPEMASK) : 0; if (texture) state.SetMaterial(texture, UF_Sprite, (spritetype == RF_FACESPRITE) ? CTF_Expand : 0, CLAMP_XY, translation, OverrideShader); else if (!modelframe) state.EnableTexture(false); From 5a2a72fc957762104684c21939358bc9ac373ab9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 18 Apr 2020 23:56:22 +0200 Subject: [PATCH 060/220] - store the Vulkan descriptor sets in the material - where they belong! Having them in the base texture object was a major maintenance issue. --- src/common/textures/animtexture.cpp | 2 +- src/common/textures/hw_ihwtexture.h | 2 - src/common/textures/hw_material.cpp | 3 +- src/common/textures/hw_material.h | 3 +- src/common/textures/hw_texcontainer.h | 14 +- src/common/textures/texture.cpp | 9 +- src/common/textures/texturemanager.cpp | 2 +- src/common/textures/textures.h | 5 +- src/d_main.cpp | 1 + src/rendering/2d/f_wipe.cpp | 4 +- .../hwrenderer/textures/hw_precache.cpp | 2 +- src/rendering/v_framebuffer.cpp | 5 + src/rendering/v_video.h | 3 + .../vulkan/renderer/vk_renderstate.cpp | 3 +- .../vulkan/system/vk_framebuffer.cpp | 9 +- src/rendering/vulkan/system/vk_framebuffer.h | 1 + .../vulkan/textures/vk_hwtexture.cpp | 169 ++++++++++-------- src/rendering/vulkan/textures/vk_hwtexture.h | 39 ++-- 18 files changed, 160 insertions(+), 116 deletions(-) diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp index 7ec249025a..e1ebd1b6cc 100644 --- a/src/common/textures/animtexture.cpp +++ b/src/common/textures/animtexture.cpp @@ -50,7 +50,7 @@ void AnimTexture::SetFrame(const uint8_t *palette, const void *data_) { memcpy(Palette, palette, 768); memcpy(Image.Data(), data_, Width * Height); - CleanHardwareTextures(true); + CleanHardwareTextures(); } //=========================================================================== diff --git a/src/common/textures/hw_ihwtexture.h b/src/common/textures/hw_ihwtexture.h index 73023014cd..b207dceb4b 100644 --- a/src/common/textures/hw_ihwtexture.h +++ b/src/common/textures/hw_ihwtexture.h @@ -17,8 +17,6 @@ public: IHardwareTexture() = default; virtual ~IHardwareTexture() = default; - virtual void DeleteDescriptors() { } - virtual void AllocateBuffer(int w, int h, int texelsize) = 0; virtual uint8_t *MapBuffer() = 0; virtual unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, const char *name) = 0; diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index d85b23f6ba..70e13fdc62 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -27,6 +27,7 @@ #include "hw_material.h" #include "texturemanager.h" #include "c_cvars.h" +#include "v_video.h" IHardwareTexture* CreateHardwareTexture(); @@ -173,7 +174,7 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool FMaterial *hwtex = gtex->Material[scaleflags]; if (hwtex == NULL && create) { - hwtex = new FMaterial(gtex, scaleflags); + hwtex = screen->CreateMaterial(gtex, scaleflags); } return hwtex; } diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index bc9af78f0f..fddaa73f7b 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -27,10 +27,11 @@ public: FTexture* imgtex; // the first layer's texture image - should be moved into the array FMaterial(FGameTexture *tex, int scaleflags); - ~FMaterial(); + virtual ~FMaterial(); int GetLayerFlags() const { return mLayerFlags; } int GetShaderIndex() const { return mShaderIndex; } int GetScaleFlags() const { return mScaleFlags; } + virtual void DeleteDescriptors() { } FGameTexture* Source() const { diff --git a/src/common/textures/hw_texcontainer.h b/src/common/textures/hw_texcontainer.h index f7020b5b79..5876d6a2ca 100644 --- a/src/common/textures/hw_texcontainer.h +++ b/src/common/textures/hw_texcontainer.h @@ -36,11 +36,6 @@ private: hwTexture = nullptr; } - void DeleteDescriptors() - { - if (hwTexture) hwTexture->DeleteDescriptors(); - } - ~TranslatedTexture() { Delete(); @@ -81,15 +76,8 @@ private: } public: - - void Clean(bool reallyclean) + void Clean() { - hwDefTex[0].DeleteDescriptors(); - hwDefTex[1].DeleteDescriptors(); - for (unsigned int j = 0; j < hwTex_Translated.Size(); j++) - hwTex_Translated[j].DeleteDescriptors(); - - if (!reallyclean) return; hwDefTex[0].Delete(); hwDefTex[1].Delete(); hwTex_Translated.Clear(); diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index e8cf04505b..fcf1d871db 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -558,9 +558,9 @@ bool FTexture::DetermineTranslucency() } -void FTexture::CleanHardwareTextures(bool reallyclean) +void FTexture::CleanHardwareTextures() { - SystemTextures.Clean(reallyclean); + SystemTextures.Clean(); } //=========================================================================== @@ -787,6 +787,11 @@ void FGameTexture::SetSpriteRect() } +void FGameTexture::CleanHardwareData(bool full) +{ + +} + //=========================================================================== // // Create a hardware texture for this texture image. diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 7c71eda67a..6d6a0dbcf2 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -118,7 +118,7 @@ void FTextureManager::FlushAll() { for (int j = 0; j < 2; j++) { - Textures[i].Texture->GetTexture()->CleanHardwareTextures(true); + Textures[i].Texture->CleanHardwareData(); delete Textures[i].Texture->GetSoftwareTexture(); Textures[i].Texture->SetSoftwareTexture(nullptr); calcShouldUpscale(Textures[i].Texture); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 9b2f6e1c2a..d4e801b8f9 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -259,7 +259,7 @@ public: static FTexture *CreateTexture(int lumpnum, bool allowflats = false); virtual FImageSource *GetImage() const { return nullptr; } void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); - void CleanHardwareTextures(bool reallyclean); + void CleanHardwareTextures(); int GetWidth() { return Width; } int GetHeight() { return Height; } @@ -648,6 +648,9 @@ public: else if ((isWarped() || shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; return clampmode; } + + void CleanHardwareData(bool full = true); + }; inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType) diff --git a/src/d_main.cpp b/src/d_main.cpp index 9cfb1582ff..11f514d8f5 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -3401,6 +3401,7 @@ void D_Cleanup() DeinitMenus(); LightDefaults.DeleteAndClear(); // this can leak heap memory if it isn't cleared. TexAnim.DeleteAll(); + TexMan.DeleteAll(); // delete DoomStartupInfo data DoomStartupInfo.Name = ""; diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index 4797ab82c1..cf51b59cec 100644 --- a/src/rendering/2d/f_wipe.cpp +++ b/src/rendering/2d/f_wipe.cpp @@ -373,8 +373,8 @@ bool Wiper_Burn::Run(int ticks) done = (Density < 0); } - BurnTexture->CleanHardwareTextures(true); - endScreen->GetTexture()->CleanHardwareTextures(false); // this only cleans the descriptor sets for the Vulkan backend. Needs to be done better. + BurnTexture->CleanHardwareTextures(); + endScreen->CleanHardwareData(false); // this only cleans the descriptor sets for the Vulkan backend. We do not want to delete the wipe screen's hardware texture here. const uint8_t *src = BurnArray; uint32_t *dest = (uint32_t *)BurnTexture->GetBuffer(); diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index f3518bfb8c..55f92a8d4a 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -230,7 +230,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl // For now, only delete what's in neither list. The logic being used here does not really work that well for selective deletion. if (usedTextures.CheckKey(tex->GetTexture()) == nullptr && usedSprites.CheckKey(tex->GetTexture()) == nullptr) { - tex->GetTexture()->CleanHardwareTextures(true); + tex->CleanHardwareData(); } } } diff --git a/src/rendering/v_framebuffer.cpp b/src/rendering/v_framebuffer.cpp index d26dd03d6c..aa297fe9af 100644 --- a/src/rendering/v_framebuffer.cpp +++ b/src/rendering/v_framebuffer.cpp @@ -455,6 +455,11 @@ void DFrameBuffer::FPSLimit() } } +FMaterial* DFrameBuffer::CreateMaterial(FGameTexture* tex, int scaleflags) +{ + return new FMaterial(tex, scaleflags); +} + DEFINE_ACTION_FUNCTION(_Screen, GetViewWindow) { PARAM_PROLOGUE; diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 080aed555a..29affa2510 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -65,6 +65,8 @@ class FFlatVertexBuffer; class HWViewpointBuffer; class FLightBuffer; struct HWDrawInfo; +class FMaterial; +class FGameTexture; enum EHWCaps { @@ -266,6 +268,7 @@ public: virtual IHardwareTexture *CreateHardwareTexture() { return nullptr; } virtual void PrecacheMaterial(FMaterial *mat, int translation) {} virtual FModelRenderer *CreateModelRenderer(int mli) { return nullptr; } + virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags); virtual void TextureFilterChanged() {} virtual void BeginFrame() {} virtual void SetWindowSize(int w, int h) {} diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index bb0270fba4..21e41efa73 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -434,8 +434,7 @@ void VkRenderState::ApplyMaterial() auto fb = GetVulkanFrameBuffer(); auto passManager = fb->GetRenderPassManager(); - VkHardwareTexture* base = mMaterial.mMaterial ? static_cast(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation)) : nullptr; - VulkanDescriptorSet* descriptorset = base ? base->GetDescriptorSet(mMaterial) : passManager->GetNullTextureDescriptorSet(); + VulkanDescriptorSet* descriptorset = mMaterial.mMaterial ? static_cast(mMaterial.mMaterial)->GetDescriptorSet(mMaterial) : passManager->GetNullTextureDescriptorSet(); mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->GetPipelineLayout(mPipelineKey.NumTextureLayers), 1, descriptorset); mMaterial.mChanged = false; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 83c43b6766..6524d486ff 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -667,6 +667,11 @@ IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture() return new VkHardwareTexture(); } +FMaterial* VulkanFrameBuffer::CreateMaterial(FGameTexture* tex, int scaleflags) +{ + return new VkMaterial(tex, scaleflags); +} + FModelRenderer *VulkanFrameBuffer::CreateModelRenderer(int mli) { return new FHWModelRenderer(nullptr, *GetRenderState(), mli); @@ -711,7 +716,7 @@ void VulkanFrameBuffer::TextureFilterChanged() if (mSamplerManager) { // Destroy the texture descriptors as they used the old samplers - VkHardwareTexture::ResetAllDescriptors(); + VkMaterial::ResetAllDescriptors(); mSamplerManager->SetTextureFilterMode(); } @@ -720,7 +725,7 @@ void VulkanFrameBuffer::TextureFilterChanged() void VulkanFrameBuffer::StartPrecaching() { // Destroy the texture descriptors to avoid problems with potentially stale textures. - VkHardwareTexture::ResetAllDescriptors(); + VkMaterial::ResetAllDescriptors(); } void VulkanFrameBuffer::BlurScene(float amount) diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 64dfa3e7bd..7ab7c6bc67 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -89,6 +89,7 @@ public: void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; IHardwareTexture *CreateHardwareTexture() override; + FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; FModelRenderer *CreateModelRenderer(int mli) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index 3499cce3d8..a20be08ac1 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -64,8 +64,6 @@ void VkHardwareTexture::Reset() { if (auto fb = GetVulkanFrameBuffer()) { - ResetDescriptors(); - if (mappedSWFB) { mImage.Image->Unmap(); @@ -84,78 +82,6 @@ void VkHardwareTexture::Reset() } } -void VkHardwareTexture::ResetDescriptors() -{ - if (auto fb = GetVulkanFrameBuffer()) - { - auto &deleteList = fb->FrameDeleteList; - - for (auto &it : mDescriptorSets) - { - deleteList.Descriptors.push_back(std::move(it.descriptor)); - } - } - - mDescriptorSets.clear(); -} - -void VkHardwareTexture::ResetAllDescriptors() -{ - for (VkHardwareTexture *cur = First; cur; cur = cur->Next) - cur->ResetDescriptors(); - - auto fb = GetVulkanFrameBuffer(); - if (fb) - fb->GetRenderPassManager()->TextureSetPoolReset(); -} - -VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state) -{ - FMaterial *mat = state.mMaterial; - auto base = state.mMaterial->Source(); - int clampmode = state.mClampMode; - int translation = state.mTranslation; - - clampmode = base->GetClampMode(clampmode); - - // Textures that are already scaled in the texture lump will not get replaced by hires textures. - int flags = mat->GetScaleFlags(); - - for (auto &set : mDescriptorSets) - { - if (set.descriptor && set.clampmode == clampmode && set.flags == flags) return set.descriptor.get(); - } - - int numLayers = mat->GetLayers(); - - auto fb = GetVulkanFrameBuffer(); - auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(std::max(numLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS)); - - descriptor->SetDebugName("VkHardwareTexture.mDescriptorSets"); - - VulkanSampler *sampler = fb->GetSamplerManager()->Get(clampmode); - - WriteDescriptors update; - update.addCombinedImageSampler(descriptor.get(), 0, GetImage(mat->BaseLayer(), translation, flags)->View.get(), sampler, mImage.Layout); - for (int i = 1; i < numLayers; i++) - { - FTexture *layer; - auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - // fixme: Upscale flags must be disabled for certain layers. - update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer, 0, flags)->View.get(), sampler, systex->mImage.Layout); - } - - auto dummyImage = fb->GetRenderPassManager()->GetNullTextureView(); - for (int i = numLayers; i < SHADER_MIN_REQUIRED_TEXTURE_LAYERS; i++) - { - update.addCombinedImageSampler(descriptor.get(), i, dummyImage, sampler, mImage.Layout); - } - - update.updateSets(fb->device); - mDescriptorSets.emplace_back(clampmode, flags, std::move(descriptor)); - return mDescriptorSets.back().descriptor.get(); -} - VkTextureImage *VkHardwareTexture::GetImage(FTexture *tex, int translation, int flags) { if (!mImage.Image) @@ -392,3 +318,98 @@ void VkHardwareTexture::CreateWipeTexture(int w, int h, const char *name) transition1.execute(fb->GetTransferCommands()); } } + + +VkMaterial* VkMaterial::First = nullptr; + +VkMaterial::VkMaterial(FGameTexture* tex, int scaleflags) : FMaterial(tex, scaleflags) +{ + Next = First; + First = this; + if (Next) Next->Prev = this; +} + +VkMaterial::~VkMaterial() +{ + if (Next) Next->Prev = Prev; + if (Prev) Prev->Next = Next; + else First = Next; + + DeleteDescriptors(); +} + +void VkMaterial::DeleteDescriptors() +{ + if (auto fb = GetVulkanFrameBuffer()) + { + auto& deleteList = fb->FrameDeleteList; + + for (auto& it : mDescriptorSets) + { + deleteList.Descriptors.push_back(std::move(it.descriptor)); + } + } + + mDescriptorSets.clear(); +} + +void VkMaterial::ResetAllDescriptors() +{ + for (VkMaterial* cur = First; cur; cur = cur->Next) + cur->DeleteDescriptors(); + + auto fb = GetVulkanFrameBuffer(); + if (fb) + fb->GetRenderPassManager()->TextureSetPoolReset(); +} + +VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state) +{ + auto base = Source(); + int clampmode = state.mClampMode; + int translation = state.mTranslation; + + auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation); + if (remap) translation = remap->Index; + + clampmode = base->GetClampMode(clampmode); + + // Textures that are already scaled in the texture lump will not get replaced by hires textures. + int flags = GetScaleFlags(); + + for (auto& set : mDescriptorSets) + { + if (set.descriptor && set.clampmode == clampmode && set.flags == translation) return set.descriptor.get(); + } + + int numLayers = GetLayers(); + + auto fb = GetVulkanFrameBuffer(); + auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(std::max(numLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS)); + + descriptor->SetDebugName("VkHardwareTexture.mDescriptorSets"); + + VulkanSampler* sampler = fb->GetSamplerManager()->Get(clampmode); + + WriteDescriptors update; + FTexture* layer; + auto systex = static_cast(GetLayer(0, translation, &layer)); + update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer, translation, flags)->View.get(), sampler, systex->mImage.Layout); + for (int i = 1; i < numLayers; i++) + { + auto systex = static_cast(GetLayer(i, 0, &layer)); + // fixme: Upscale flags must be disabled for certain layers. + update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer, 0, flags)->View.get(), sampler, systex->mImage.Layout); + } + + auto dummyImage = fb->GetRenderPassManager()->GetNullTextureView(); + for (int i = numLayers; i < SHADER_MIN_REQUIRED_TEXTURE_LAYERS; i++) + { + update.addCombinedImageSampler(descriptor.get(), i, dummyImage, sampler, systex->mImage.Layout); + } + + update.updateSets(fb->device); + mDescriptorSets.emplace_back(clampmode, translation, std::move(descriptor)); + return mDescriptorSets.back().descriptor.get(); +} + diff --git a/src/rendering/vulkan/textures/vk_hwtexture.h b/src/rendering/vulkan/textures/vk_hwtexture.h index b7bd02979a..872f58aefa 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.h +++ b/src/rendering/vulkan/textures/vk_hwtexture.h @@ -11,15 +11,18 @@ #include "hw_ihwtexture.h" #include "volk/volk.h" #include "vk_imagetransition.h" +#include "hw_material.h" struct FMaterialState; class VulkanDescriptorSet; class VulkanImage; class VulkanImageView; class VulkanBuffer; +class FGameTexture; class VkHardwareTexture : public IHardwareTexture { + friend class VkMaterial; public: VkHardwareTexture(); ~VkHardwareTexture(); @@ -27,8 +30,6 @@ public: static void ResetAll(); void Reset(); - VulkanDescriptorSet *GetDescriptorSet(const FMaterialState &state); - // Software renderer stuff void AllocateBuffer(int w, int h, int texelsize) override; uint8_t *MapBuffer() override; @@ -37,12 +38,9 @@ public: // Wipe screen void CreateWipeTexture(int w, int h, const char *name); - void DeleteDescriptors() override { ResetDescriptors(); } - VkTextureImage *GetImage(FTexture *tex, int translation, int flags); VkTextureImage *GetDepthStencil(FTexture *tex); - static void ResetAllDescriptors(); private: void CreateImage(FTexture *tex, int translation, int flags); @@ -50,19 +48,32 @@ private: void CreateTexture(int w, int h, int pixelsize, VkFormat format, const void *pixels); static int GetMipLevels(int w, int h); - void ResetDescriptors(); - static VkHardwareTexture *First; VkHardwareTexture *Prev = nullptr; VkHardwareTexture *Next = nullptr; + VkTextureImage mImage; + int mTexelsize = 4; + + VkTextureImage mDepthStencil; + + uint8_t* mappedSWFB = nullptr; +}; + + +class VkMaterial : public FMaterial +{ + static VkMaterial* First; + VkMaterial* Prev = nullptr; + VkMaterial* Next = nullptr; + struct DescriptorEntry { int clampmode; int flags; std::unique_ptr descriptor; - DescriptorEntry(int cm, int f, std::unique_ptr &&d) + DescriptorEntry(int cm, int f, std::unique_ptr&& d) { clampmode = cm; flags = f; @@ -71,10 +82,12 @@ private: }; std::vector mDescriptorSets; - VkTextureImage mImage; - int mTexelsize = 4; - VkTextureImage mDepthStencil; +public: + VkMaterial(FGameTexture *tex, int scaleflags); + ~VkMaterial(); + VulkanDescriptorSet* GetDescriptorSet(const FMaterialState& state); + void DeleteDescriptors() override; + static void ResetAllDescriptors(); - uint8_t* mappedSWFB = nullptr; -}; +}; \ No newline at end of file From cedc95c2a53e5a9aa0b6bc1b71b4028b3fc35576 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Apr 2020 00:44:42 +0200 Subject: [PATCH 061/220] - split out FGameTexture into its own files. --- src/CMakeLists.txt | 1 + src/common/textures/gametexture.cpp | 512 ++++++++++++++++++ src/common/textures/gametexture.h | 316 +++++++++++ src/common/textures/texture.cpp | 457 ---------------- src/common/textures/texturemanager.cpp | 33 +- src/common/textures/textures.h | 352 +----------- src/common/utility/floatrect.h | 21 + src/r_data/gldefs.cpp | 8 +- .../hwrenderer/textures/hw_precache.cpp | 5 +- 9 files changed, 898 insertions(+), 807 deletions(-) create mode 100644 src/common/textures/gametexture.cpp create mode 100644 src/common/textures/gametexture.h create mode 100644 src/common/utility/floatrect.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 95c07ac7df..a89a6cc7d8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1070,6 +1070,7 @@ set (PCH_SOURCES common/textures/bitmap.cpp common/textures/m_png.cpp common/textures/texture.cpp + common/textures/gametexture.cpp common/textures/image.cpp common/textures/imagetexture.cpp common/textures/texturemanager.cpp diff --git a/src/common/textures/gametexture.cpp b/src/common/textures/gametexture.cpp new file mode 100644 index 0000000000..1ec6a60627 --- /dev/null +++ b/src/common/textures/gametexture.cpp @@ -0,0 +1,512 @@ +/* +** gametexture.cpp +** The game-facing texture class. +** +**--------------------------------------------------------------------------- +** Copyright 2004-2007 Randy Heit +** Copyright 2006-2020 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include "printf.h" +#include "files.h" +#include "filesystem.h" +#include "templates.h" +#include "textures.h" +#include "bitmap.h" +#include "colormatcher.h" +#include "c_dispatch.h" +#include "m_fixed.h" +#include "imagehelpers.h" +#include "image.h" +#include "formats/multipatchtexture.h" +#include "texturemanager.h" +#include "c_cvars.h" +#include "hw_material.h" + +FTexture *CreateBrightmapTexture(FImageSource*); + + +FGameTexture::FGameTexture(FTexture* wrap, const char* name) : Name(name) +{ + if (wrap) Setup(wrap); +} + +//========================================================================== +// +// +// +//========================================================================== + +void FGameTexture::Setup(FTexture *wrap) +{ + Base = wrap; + id.SetInvalid(); + TexelWidth = Base->GetWidth(); + DisplayWidth = (float)TexelWidth; + TexelHeight = Base->GetHeight(); + DisplayHeight = (float)TexelHeight; + auto img = Base->GetImage(); + if (img) + { + auto ofs = img->GetOffsets(); + LeftOffset[0] = LeftOffset[1] = ofs.first; + TopOffset[0] = TopOffset[1] = ofs.second; + } + else + { + LeftOffset[0] = LeftOffset[1] = + TopOffset[0] = TopOffset[1] = 0; + + } + ScaleX = ScaleY = 1.f; +} + +//========================================================================== +// +// +// +//========================================================================== + +FGameTexture::~FGameTexture() +{ + FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump()); + if (link == this) fileSystem.SetLinkedTexture(GetSourceLump(), nullptr); + if (SoftwareTexture != nullptr) + { + delete SoftwareTexture; + SoftwareTexture = nullptr; + } + for (auto &mat : Material) + { + if (mat != nullptr) delete mat; + mat = nullptr; + } + +} + +//========================================================================== +// +// +// +//========================================================================== + +bool FGameTexture::isUserContent() const +{ + int filenum = fileSystem.GetFileContainer(Base->GetSourceLump()); + return (filenum > fileSystem.GetMaxIwadNum()); +} + + +//========================================================================== +// +// Search auto paths for extra material textures +// +//========================================================================== + +void FGameTexture::AddAutoMaterials() +{ + struct AutoTextureSearchPath + { + const char* path; + RefCountedPtr FGameTexture::* pointer; + }; + + static AutoTextureSearchPath autosearchpaths[] = + { + { "brightmaps/", &FGameTexture::Brightmap }, // For backwards compatibility, only for short names + { "materials/brightmaps/", &FGameTexture::Brightmap }, + { "materials/normalmaps/", &FGameTexture::Normal }, + { "materials/specular/", &FGameTexture::Specular }, + { "materials/metallic/", &FGameTexture::Metallic }, + { "materials/roughness/", &FGameTexture::Roughness }, + { "materials/ao/", &FGameTexture::AmbientOcclusion } + }; + + + bool fullname = !!(flags & GTexf_FullNameTexture); + FString searchname = GetName(); + + if (fullname) + { + auto dot = searchname.LastIndexOf('.'); + auto slash = searchname.LastIndexOf('/'); + if (dot > slash) searchname.Truncate(dot); + } + + for (size_t i = 0; i < countof(autosearchpaths); i++) + { + auto& layer = autosearchpaths[i]; + if (this->*(layer.pointer) == nullptr) // only if no explicit assignment had been done. + { + FStringf lookup("%s%s%s", layer.path, fullname ? "" : "auto/", searchname.GetChars()); + auto lump = fileSystem.CheckNumForFullName(lookup, false, ns_global, true); + if (lump != -1) + { + auto bmtex = TexMan.FindGameTexture(fileSystem.GetFileFullName(lump), ETextureType::Any, FTextureManager::TEXMAN_TryAny); + if (bmtex != nullptr) + { + this->*(layer.pointer) = bmtex->GetTexture(); + } + } + } + } +} + +//=========================================================================== +// +// Checks if the texture has a default brightmap and creates it if so +// +//=========================================================================== +void FGameTexture::CreateDefaultBrightmap() +{ + auto tex = GetTexture(); + if (flags & GTexf_BrightmapChecked) + { + flags |= GTexf_BrightmapChecked; + // Check for brightmaps + if (tex->GetImage() && tex->GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap && + GetUseType() != ETextureType::Decal && GetUseType() != ETextureType::MiscPatch && GetUseType() != ETextureType::FontChar && + Brightmap == nullptr) + { + // May have one - let's check when we use this texture + auto texbuf = tex->Get8BitPixels(false); + const int white = ColorMatcher.Pick(255, 255, 255); + + int size = tex->GetWidth() * tex->GetHeight(); + for (int i = 0; i < size; i++) + { + if (GPalette.GlobalBrightmap.Remap[texbuf[i]] == white) + { + // Create a brightmap + DPrintf(DMSG_NOTIFY, "brightmap created for texture '%s'\n", GetName().GetChars()); + Brightmap = CreateBrightmapTexture(tex->GetImage()); + return; + } + } + // No bright pixels found + DPrintf(DMSG_SPAMMY, "No bright pixels found in texture '%s'\n", GetName().GetChars()); + } + } +} + + +//========================================================================== +// +// Calculates glow color for a texture +// +//========================================================================== + +void FGameTexture::GetGlowColor(float* data) +{ + if (isGlowing() && GlowColor == 0) + { + auto buffer = Base->GetBgraBitmap(nullptr); + GlowColor = averageColor((uint32_t*)buffer.GetPixels(), buffer.GetWidth() * buffer.GetHeight(), 153); + + // Black glow equals nothing so switch glowing off + if (GlowColor == 0) flags &= ~GTexf_Glowing; + } + data[0] = GlowColor.r * (1 / 255.0f); + data[1] = GlowColor.g * (1 / 255.0f); + data[2] = GlowColor.b * (1 / 255.0f); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +int FGameTexture::GetAreas(FloatRect** pAreas) const +{ + if (shaderindex == SHADER_Default) // texture splitting can only be done if there's no attached effects + { + *pAreas = Base->areas; + return Base->areacount; + } + else + { + return 0; + } +} + +//=========================================================================== +// +// Checks if a sprite may be expanded with an empty frame +// +//=========================================================================== + +bool FGameTexture::ShouldExpandSprite() +{ + if (expandSprite != -1) return expandSprite; + // Only applicable to image textures with no shader effect. + if (GetShaderIndex() != SHADER_Default || !dynamic_cast(Base.get())) + { + expandSprite = false; + return false; + } + if (Brightmap != NULL && (Base->GetWidth() != Brightmap->GetWidth() || Base->GetHeight() != Brightmap->GetHeight())) + { + // do not expand if the brightmap's physical size differs from the base. + expandSprite = false; + return false; + } + if (Glowmap != NULL && (Base->GetWidth() != Glowmap->GetWidth() || Base->GetHeight() != Glowmap->GetHeight())) + { + // same restriction for the glow map + expandSprite = false; + return false; + } + expandSprite = true; + return true; +} + +//=========================================================================== +// +// Sets up the sprite positioning data for this texture +// +//=========================================================================== + +void FGameTexture::SetupSpriteData() +{ + // Since this is only needed for real sprites it gets allocated on demand. + // It also allocates from the image memory arena because it has the same lifetime and to reduce maintenance. + if (spi == nullptr) spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo)); + for (int i = 0; i < 2; i++) + { + auto& spi = this->spi[i]; + spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f; + spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f; + spi.spriteWidth = GetTexelWidth(); + spi.spriteHeight = GetTexelHeight(); + + if (i == 1 && ShouldExpandSprite()) + { + spi.mTrimResult = Base->TrimBorders(spi.trim); // get the trim size before adding the empty frame + spi.spriteWidth += 2; + spi.spriteHeight += 2; + } + } + SetSpriteRect(); +} + +//=========================================================================== +// +// Set the sprite rectangle. This is separate because it may be called by a CVAR, too. +// +//=========================================================================== + +void FGameTexture::SetSpriteRect() +{ + + if (!spi) return; + auto leftOffset = GetTexelLeftOffset(r_spriteadjustHW); + auto topOffset = GetTexelTopOffset(r_spriteadjustHW); + + float fxScale = GetScaleX(); + float fyScale = GetScaleY(); + + for (int i = 0; i < 2; i++) + { + auto& spi = this->spi[i]; + + // mSpriteRect is for positioning the sprite in the scene. + spi.mSpriteRect.left = -leftOffset / fxScale; + spi.mSpriteRect.top = -topOffset / fyScale; + spi.mSpriteRect.width = spi.spriteWidth / fxScale; + spi.mSpriteRect.height = spi.spriteHeight / fyScale; + + if (i == 1 && ShouldExpandSprite()) + { + // a little adjustment to make sprites look better with texture filtering: + // create a 1 pixel wide empty frame around them. + + int oldwidth = spi.spriteWidth - 2; + int oldheight = spi.spriteHeight - 2; + + leftOffset += 1; + topOffset += 1; + + // Reposition the sprite with the frame considered + spi.mSpriteRect.left = -(float)leftOffset / fxScale; + spi.mSpriteRect.top = -(float)topOffset / fyScale; + spi.mSpriteRect.width = (float)spi.spriteWidth / fxScale; + spi.mSpriteRect.height = (float)spi.spriteHeight / fyScale; + + if (spi.mTrimResult > 0) + { + spi.mSpriteRect.left += (float)spi.trim[0] / fxScale; + spi.mSpriteRect.top += (float)spi.trim[1] / fyScale; + + spi.mSpriteRect.width -= float(oldwidth - spi.trim[2]) / fxScale; + spi.mSpriteRect.height -= float(oldheight - spi.trim[3]) / fyScale; + + spi.mSpriteU[0] = (float)spi.trim[0] / (float)spi.spriteWidth; + spi.mSpriteV[0] = (float)spi.trim[1] / (float)spi.spriteHeight; + spi.mSpriteU[1] -= float(oldwidth - spi.trim[0] - spi.trim[2]) / (float)spi.spriteWidth; + spi.mSpriteV[1] -= float(oldheight - spi.trim[1] - spi.trim[3]) / (float)spi.spriteHeight; + } + } + } +} + +//=========================================================================== +// +// Cleans the attached hardware resources. +// This should only be used on textures which alter their content at run time +//or when the engine shuts down. +// +//=========================================================================== + +void FGameTexture::CleanHardwareData(bool full) +{ + Base->CleanHardwareTextures(); + for (auto mat : Material) if (mat) mat->DeleteDescriptors(); +} + + +//----------------------------------------------------------------------------- +// +// Make sprite offset adjustment user-configurable per renderer. +// +//----------------------------------------------------------------------------- + +CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + r_spriteadjustHW = !!(self & 2); + r_spriteadjustSW = !!(self & 1); + for (int i = 0; i < TexMan.NumTextures(); i++) + { + auto tex = TexMan.GetGameTexture(FSetTextureID(i)); + if (tex->GetTexelLeftOffset(0) != tex->GetTexelLeftOffset(1) || tex->GetTexelTopOffset(0) != tex->GetTexelTopOffset(1)) + { + tex->SetSpriteRect(); + } + } +} + +//=========================================================================== +// +// Coordinate helper. +// The only reason this is even needed is that many years ago someone +// was convinced that having per-texel panning on walls was a good idea. +// If it wasn't for this relatively useless feature the entire positioning +// code for wall textures could be a lot simpler. +// +//=========================================================================== + +//=========================================================================== +// +// +// +//=========================================================================== + +float FTexCoordInfo::RowOffset(float rowoffset) const +{ + float scale = fabs(mScale.Y); + if (scale == 1.f || mWorldPanning) return rowoffset; + else return rowoffset / scale; +} + +//=========================================================================== +// +// +// +//=========================================================================== + +float FTexCoordInfo::TextureOffset(float textureoffset) const +{ + float scale = fabs(mScale.X); + if (scale == 1.f || mWorldPanning) return textureoffset; + else return textureoffset / scale; +} + +//=========================================================================== +// +// Returns the size for which texture offset coordinates are used. +// +//=========================================================================== + +float FTexCoordInfo::TextureAdjustWidth() const +{ + if (mWorldPanning) + { + float tscale = fabs(mTempScale.X); + if (tscale == 1.f) return (float)mRenderWidth; + else return mWidth / fabs(tscale); + } + else return (float)mWidth; +} + + +//=========================================================================== +// +// Retrieve texture coordinate info for per-wall scaling +// +//=========================================================================== + +void FTexCoordInfo::GetFromTexture(FGameTexture *tex, float x, float y, bool forceworldpanning) +{ + if (x == 1.f) + { + mRenderWidth = xs_RoundToInt(tex->GetDisplayWidth()); + mScale.X = tex->GetScaleX(); + mTempScale.X = 1.f; + } + else + { + float scale_x = x * tex->GetScaleX(); + mRenderWidth = xs_CeilToInt(tex->GetTexelWidth() / scale_x); + mScale.X = scale_x; + mTempScale.X = x; + } + + if (y == 1.f) + { + mRenderHeight = xs_RoundToInt(tex->GetDisplayHeight()); + mScale.Y = tex->GetScaleY(); + mTempScale.Y = 1.f; + } + else + { + float scale_y = y * tex->GetScaleY(); + mRenderHeight = xs_CeilToInt(tex->GetTexelHeight() / scale_y); + mScale.Y = scale_y; + mTempScale.Y = y; + } + if (tex->isHardwareCanvas()) + { + mScale.Y = -mScale.Y; + mRenderHeight = -mRenderHeight; + } + mWorldPanning = tex->useWorldPanning() || forceworldpanning; + mWidth = tex->GetTexelWidth(); +} + diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h new file mode 100644 index 0000000000..f99c45b74b --- /dev/null +++ b/src/common/textures/gametexture.h @@ -0,0 +1,316 @@ +#pragma once +#include +#include "vectors.h" +#include "floatrect.h" +#include "refcounted.h" +#include "xs_Float.h" +#include "palentry.h" +#include "zstring.h" +#include "textureid.h" + +// 15 because 0th texture is our texture +#define MAX_CUSTOM_HW_SHADER_TEXTURES 15 +class FTexture; +class ISoftwareTexture; +class FMaterial; + +struct SpritePositioningInfo +{ + uint16_t trim[4]; + int spriteWidth, spriteHeight; + float mSpriteU[2], mSpriteV[2]; + FloatRect mSpriteRect; + uint8_t mTrimResult; + + float GetSpriteUL() const { return mSpriteU[0]; } + float GetSpriteVT() const { return mSpriteV[0]; } + float GetSpriteUR() const { return mSpriteU[1]; } + float GetSpriteVB() const { return mSpriteV[1]; } + + const FloatRect &GetSpriteRect() const + { + return mSpriteRect; + } + +}; + +struct MaterialLayers +{ + float Glossiness; + float SpecularLevel; + FGameTexture* Brightmap; + FGameTexture* Normal; + FGameTexture* Specular; + FGameTexture* Metallic; + FGameTexture* Roughness; + FGameTexture* AmbientOcclusion; + FGameTexture* CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES]; +}; + +enum EGameTexFlags +{ + GTexf_NoDecals = 1, // Decals should not stick to texture + GTexf_WorldPanning = 2, // Texture is panned in world units rather than texels + GTexf_FullNameTexture = 4, // Name is taken from the file system. + GTexf_Glowing = 8, // Texture emits a glow + GTexf_AutoGlowing = 16, // Glow info is determined from texture image. + GTexf_RenderFullbright = 32, // always draw fullbright + GTexf_DisableFullbrightSprites = 64, // This texture will not be displayed as fullbright sprite + GTexf_BrightmapChecked = 128, // Check for a colormap-based brightmap was already done. +}; + +// Refactoring helper to allow piece by piece adjustment of the API +class FGameTexture +{ + friend class FMaterial; + + // Material layers. These are shared so reference counting is used. + RefCountedPtr Base; + RefCountedPtr Brightmap; + RefCountedPtr Detailmap; + RefCountedPtr Glowmap; + RefCountedPtr Normal; // Normal map texture + RefCountedPtr Specular; // Specular light texture for the diffuse+normal+specular light model + RefCountedPtr Metallic; // Metalness texture for the physically based rendering (PBR) light model + RefCountedPtr Roughness; // Roughness texture for PBR + RefCountedPtr AmbientOcclusion; // Ambient occlusion texture for PBR + RefCountedPtr CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES]; // Custom texture maps for custom hardware shaders + + FString Name; + FTextureID id; + + uint16_t TexelWidth, TexelHeight; + int16_t LeftOffset[2], TopOffset[2]; + float DisplayWidth, DisplayHeight; + float ScaleX, ScaleY; + + int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture. + ETextureType UseType = ETextureType::Wall; // This texture's primary purpose + SpritePositioningInfo* spi = nullptr; + + ISoftwareTexture* SoftwareTexture = nullptr; + FMaterial* Material[4] = { }; + + // Material properties + float Glossiness = 10.f; + float SpecularLevel = 0.1f; + float shaderspeed = 1.f; + int shaderindex = 0; + + int flags = 0; + uint8_t warped = 0, expandSprite = -1; + uint16_t GlowHeight; + PalEntry GlowColor = 0; + + int16_t SkyOffset = 0; + uint16_t Rotations = 0xffff; + + +public: + FGameTexture(FTexture* wrap, const char *name); + ~FGameTexture(); + void Setup(FTexture* wrap); + FTextureID GetID() const { return id; } + void SetID(FTextureID newid) { id = newid; } // should only be called by the texture manager + const FString& GetName() const { return Name; } + void SetName(const char* name) { Name = name; } // should only be called by setup code. + + float GetScaleX() { return ScaleX; } + float GetScaleY() { return ScaleY; } + float GetDisplayWidth() const { return DisplayWidth; } + float GetDisplayHeight() const { return DisplayHeight; } + int GetTexelWidth() const { return TexelWidth; } + int GetTexelHeight() const { return TexelHeight; } + + void CreateDefaultBrightmap(); + void AddAutoMaterials(); + bool ShouldExpandSprite(); + void SetupSpriteData(); + void SetSpriteRect(); + + ETextureType GetUseType() const { return UseType; } + void SetUpscaleFlag(int what) { shouldUpscaleFlag = what; } + int GetUpscaleFlag() { return shouldUpscaleFlag; } + + FTexture* GetTexture() { return Base.get(); } + int GetSourceLump() const { return Base->GetSourceLump(); } + void SetBrightmap(FGameTexture* tex) { Brightmap = tex->GetTexture(); } + + int GetTexelLeftOffset(int adjusted = 0) const { return LeftOffset[adjusted]; } + int GetTexelTopOffset(int adjusted = 0) const { return TopOffset[adjusted]; } + float GetDisplayLeftOffset(int adjusted = 0) const { return LeftOffset[adjusted] / ScaleX; } + float GetDisplayTopOffset(int adjusted = 0) const { return TopOffset[adjusted] / ScaleY; } + + bool isMiscPatch() const { return GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. + bool isFullbrightDisabled() const { return !!(flags & GTexf_DisableFullbrightSprites); } + bool isFullbright() const { return !!(flags & GTexf_RenderFullbright); } + bool isFullNameTexture() const { return !!(flags & GTexf_FullNameTexture); } + bool expandSprites() const { return !!expandSprite; } + bool useWorldPanning() const { return !!(flags & GTexf_WorldPanning); } + void SetWorldPanning(bool on) { if (on) flags |= GTexf_WorldPanning; else flags &= ~GTexf_WorldPanning; } + bool allowNoDecals() const { return !!(flags & GTexf_NoDecals); } + void SetNoDecals(bool on) { if (on) flags |= GTexf_NoDecals; else flags &= ~GTexf_NoDecals; } + + bool isValid() const { return UseType != ETextureType::Null; } + int isWarped() { return warped; } + void SetWarpStyle(int style) { warped = style; } + bool isMasked() { return Base->Masked; } + bool isHardwareCanvas() const { return Base->isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. + bool isSoftwareCanvas() const { return Base->isCanvas(); } + + void SetTranslucent(bool on) { Base->bTranslucent = on; } + void SetUseType(ETextureType type) { UseType = type; } + int GetRotations() const { return Rotations; } + void SetRotations(int rot) { Rotations = int16_t(rot); } + void SetSkyOffset(int offs) { SkyOffset = offs; } + int GetSkyOffset() const { return SkyOffset; } + + ISoftwareTexture* GetSoftwareTexture() + { + return SoftwareTexture; + } + void SetSoftwareTexture(ISoftwareTexture* swtex) + { + SoftwareTexture = swtex; + } + + FMaterial* GetMaterial(int num) + { + return Material[num]; + } + + int GetShaderIndex() const { return shaderindex; } + float GetShaderSpeed() const { return shaderspeed; } + void SetShaderSpeed(float speed) { shaderspeed = speed; } + void SetShaderIndex(int index) { shaderindex = index; } + void SetShaderLayers(MaterialLayers& lay) + { + // Only update layers that have something defind. + if (lay.Glossiness > -1000) Glossiness = lay.Glossiness; + if (lay.SpecularLevel > -1000) SpecularLevel = lay.SpecularLevel; + if (lay.Brightmap) Brightmap = lay.Brightmap->GetTexture(); + if (lay.Normal) Normal = lay.Normal->GetTexture(); + if (lay.Specular) Specular = lay.Specular->GetTexture(); + if (lay.Metallic) Metallic = lay.Metallic->GetTexture(); + if (lay.Roughness) Roughness = lay.Roughness->GetTexture(); + if (lay.AmbientOcclusion) AmbientOcclusion = lay.AmbientOcclusion->GetTexture(); + for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) + { + if (lay.CustomShaderTextures[i]) CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); + } + } + float GetGlossiness() const { return Glossiness; } + float GetSpecularLevel() const { return SpecularLevel; } + + void CopySize(FGameTexture* BaseTexture) + { + Base->CopySize(BaseTexture->Base.get()); + } + + // Glowing is a pure material property that should not filter down to the actual texture objects. + void GetGlowColor(float* data); + bool isGlowing() const { return !!(flags & GTexf_Glowing); } + bool isAutoGlowing() const { return !!(flags & GTexf_AutoGlowing); } + int GetGlowHeight() const { return GlowHeight; } + void SetAutoGlowing() { flags |= (GTexf_AutoGlowing | GTexf_Glowing | GTexf_RenderFullbright); } + void SetGlowHeight(int v) { GlowHeight = v; } + void SetFullbright() { flags |= GTexf_RenderFullbright; } + void SetDisableFullbright(bool on) { if (on) flags |= GTexf_DisableFullbrightSprites; else flags &= ~GTexf_DisableFullbrightSprites; } + void SetGlowing(PalEntry color) { flags = (flags & ~GTexf_AutoGlowing) | GTexf_Glowing; GlowColor = color; } + + bool isUserContent() const; + int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); } + void SetSize(int x, int y) + { + TexelWidth = x; + TexelHeight = y; + SetDisplaySize(float(x), float(y)); + } + void SetDisplaySize(float w, float h) + { + DisplayWidth = w; + DisplayHeight = h; + ScaleX = TexelWidth / w; + ScaleY = TexelHeight / h; + + // compensate for roundoff errors + if (int(ScaleX * w) != TexelWidth) ScaleX += (1 / 65536.); + if (int(ScaleY * h) != TexelHeight) ScaleY += (1 / 65536.); + + } + void SetOffsets(int which, int x, int y) + { + LeftOffset[which] = x; + TopOffset[which] = y; + } + void SetScale(float x, float y) + { + ScaleX = x; + ScaleY = y; + DisplayWidth = x * TexelWidth; + DisplayHeight = y * TexelHeight; + } + + const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; } + int GetAreas(FloatRect** pAreas) const; + + bool GetTranslucency() + { + return Base->GetTranslucency(); + } + + int GetClampMode(int clampmode) + { + if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; + else if (isHardwareCanvas()) clampmode = CLAMP_CAMTEX; + else if ((isWarped() || shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + return clampmode; + } + + void CleanHardwareData(bool full = true); + +}; + +inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType) +{ + if (!tex) return nullptr; + auto t = new FGameTexture(tex, name); + t->SetUseType(useType); + return t; +} + +enum EUpscaleFlags +{ + UF_None = 0, + UF_Texture = 1, + UF_Sprite = 2, + UF_Font = 4 +}; + +extern int upscalemask; +void UpdateUpscaleMask(); + +int calcShouldUpscale(FGameTexture* tex); +inline int shouldUpscale(FGameTexture* tex, EUpscaleFlags UseType) +{ + // This only checks the global scale mask and the texture's validation for upscaling. Everything else has been done up front elsewhere. + if (!(upscalemask & UseType)) return 0; + return tex->GetUpscaleFlag(); +} + +struct FTexCoordInfo +{ + int mRenderWidth; + int mRenderHeight; + int mWidth; + FVector2 mScale; + FVector2 mTempScale; + bool mWorldPanning; + + float FloatToTexU(float v) const { return v / mRenderWidth; } + float FloatToTexV(float v) const { return v / mRenderHeight; } + float RowOffset(float ofs) const; + float TextureOffset(float ofs) const; + float TextureAdjustWidth() const; + void GetFromTexture(FGameTexture* tex, float x, float y, bool forceworldpanning); +}; diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index fcf1d871db..87f17708cf 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -49,39 +49,12 @@ #include "texturemanager.h" #include "c_cvars.h" -EXTERN_CVAR(Int, gl_texture_hqresize_targets) - // Wrappers to keep the definitions of these classes out of here. -void DeleteMaterial(FMaterial* mat); IHardwareTexture* CreateHardwareTexture(); - -FTexture *CreateBrightmapTexture(FImageSource*); - // Make sprite offset adjustment user-configurable per renderer. int r_spriteadjustSW, r_spriteadjustHW; -//========================================================================== -// -// -// -//========================================================================== - - -// Examines the lump contents to decide what type of texture to create, -// and creates the texture. -FTexture * FTexture::CreateTexture(int lumpnum, bool allowflats) -{ - if (lumpnum == -1) return nullptr; - - auto image = FImageSource::GetImage(lumpnum, allowflats); - if (image != nullptr) - { - return new FImageTexture(image); - } - return nullptr; -} - //========================================================================== // // @@ -136,139 +109,6 @@ int FTexture::CheckRealHeight() return 0; } -//========================================================================== -// -// Search auto paths for extra material textures -// -//========================================================================== - -void FGameTexture::AddAutoMaterials() -{ - struct AutoTextureSearchPath - { - const char *path; - RefCountedPtr FGameTexture::*pointer; - }; - - static AutoTextureSearchPath autosearchpaths[] = - { - { "brightmaps/", &FGameTexture::Brightmap }, // For backwards compatibility, only for short names - { "materials/brightmaps/", &FGameTexture::Brightmap }, - { "materials/normalmaps/", &FGameTexture::Normal }, - { "materials/specular/", &FGameTexture::Specular }, - { "materials/metallic/", &FGameTexture::Metallic }, - { "materials/roughness/", &FGameTexture::Roughness }, - { "materials/ao/", &FGameTexture::AmbientOcclusion } - }; - - - bool fullname = !!(flags & GTexf_FullNameTexture); - FString searchname = GetName(); - - if (fullname) - { - auto dot = searchname.LastIndexOf('.'); - auto slash = searchname.LastIndexOf('/'); - if (dot > slash) searchname.Truncate(dot); - } - - for (size_t i = 0; i < countof(autosearchpaths); i++) - { - auto &layer = autosearchpaths[i]; - if (this->*(layer.pointer) == nullptr) // only if no explicit assignment had been done. - { - FStringf lookup("%s%s%s", layer.path, fullname ? "" : "auto/", searchname.GetChars()); - auto lump = fileSystem.CheckNumForFullName(lookup, false, ns_global, true); - if (lump != -1) - { - auto bmtex = TexMan.FindGameTexture(fileSystem.GetFileFullName(lump), ETextureType::Any, FTextureManager::TEXMAN_TryAny); - if (bmtex != nullptr) - { - this->*(layer.pointer) = bmtex->GetTexture(); - } - } - } - } -} - -//=========================================================================== -// -// Checks if the texture has a default brightmap and creates it if so -// -//=========================================================================== -void FGameTexture::CreateDefaultBrightmap() -{ - auto tex = GetTexture(); - if (flags & GTexf_BrightmapChecked) - { - flags |= GTexf_BrightmapChecked; - // Check for brightmaps - if (tex->GetImage() && tex->GetImage()->UseGamePalette() && GPalette.HasGlobalBrightmap && - GetUseType() != ETextureType::Decal && GetUseType() != ETextureType::MiscPatch && GetUseType() != ETextureType::FontChar && - Brightmap == nullptr) - { - // May have one - let's check when we use this texture - auto texbuf = tex->Get8BitPixels(false); - const int white = ColorMatcher.Pick(255, 255, 255); - - int size = tex->GetWidth() * tex->GetHeight(); - for (int i = 0; iGetImage()); - return; - } - } - // No bright pixels found - DPrintf(DMSG_SPAMMY, "No bright pixels found in texture '%s'\n", GetName().GetChars()); - } - } -} - - -//========================================================================== -// -// Calculates glow color for a texture -// -//========================================================================== - -void FGameTexture::GetGlowColor(float *data) -{ - if (isGlowing() && GlowColor == 0) - { - auto buffer = Base->GetBgraBitmap(nullptr); - GlowColor = averageColor((uint32_t*)buffer.GetPixels(), buffer.GetWidth() * buffer.GetHeight(), 153); - - // Black glow equals nothing so switch glowing off - if (GlowColor == 0) flags &= ~GTexf_Glowing; - } - data[0] = GlowColor.r * (1/255.0f); - data[1] = GlowColor.g * (1/255.0f); - data[2] = GlowColor.b * (1/255.0f); -} - -//=========================================================================== -// -// -// -//=========================================================================== - -int FGameTexture::GetAreas(FloatRect** pAreas) const -{ - if (shaderindex == SHADER_Default) // texture splitting can only be done if there's no attached effects - { - *pAreas = Base->areas; - return Base->areacount; - } - else - { - return 0; - } -} - //=========================================================================== // // Finds gaps in the texture which can be skipped by the renderer @@ -576,37 +416,6 @@ TArray FTexture::Get8BitPixels(bool alphatex) return Pixels; } -//=========================================================================== -// -// Checks if a sprite may be expanded with an empty frame -// -//=========================================================================== - -bool FGameTexture::ShouldExpandSprite() -{ - if (expandSprite != -1) return expandSprite; - // Only applicable to image textures with no shader effect. - if (GetShaderIndex() != SHADER_Default || !dynamic_cast(Base.get())) - { - expandSprite = false; - return false; - } - if (Brightmap != NULL && (Base->GetWidth() != Brightmap->GetWidth() || Base->GetHeight() != Brightmap->GetHeight())) - { - // do not expand if the brightmap's physical size differs from the base. - expandSprite = false; - return false; - } - if (Glowmap != NULL && (Base->GetWidth() != Glowmap->GetWidth() || Base->GetHeight() != Glowmap->GetHeight())) - { - // same restriction for the glow map - expandSprite = false; - return false; - } - expandSprite = true; - return true; -} - //=========================================================================== // // Finds empty space around the texture. @@ -697,101 +506,6 @@ outl: return true; } -//=========================================================================== -// -// Sets up the sprite positioning data for this texture -// -//=========================================================================== - -void FGameTexture::SetupSpriteData() -{ - // Since this is only needed for real sprites it gets allocated on demand. - // It also allocates from the image memory arena because it has the same lifetime and to reduce maintenance. - if (spi == nullptr) spi = (SpritePositioningInfo*)ImageArena.Alloc(2 * sizeof(SpritePositioningInfo)); - for (int i = 0; i < 2; i++) - { - auto& spi = this->spi[i]; - spi.mSpriteU[0] = spi.mSpriteV[0] = 0.f; - spi.mSpriteU[1] = spi.mSpriteV[1] = 1.f; - spi.spriteWidth = GetTexelWidth(); - spi.spriteHeight = GetTexelHeight(); - - if (i == 1 && ShouldExpandSprite()) - { - spi.mTrimResult = Base->TrimBorders(spi.trim); // get the trim size before adding the empty frame - spi.spriteWidth += 2; - spi.spriteHeight += 2; - } - } - SetSpriteRect(); -} - -//=========================================================================== -// -// Set the sprite rectangle. This is separate because it may be called by a CVAR, too. -// -//=========================================================================== - -void FGameTexture::SetSpriteRect() -{ - - if (!spi) return; - auto leftOffset = GetTexelLeftOffset(r_spriteadjustHW); - auto topOffset = GetTexelTopOffset(r_spriteadjustHW); - - float fxScale = GetScaleX(); - float fyScale = GetScaleY(); - - for (int i = 0; i < 2; i++) - { - auto& spi = this->spi[i]; - - // mSpriteRect is for positioning the sprite in the scene. - spi.mSpriteRect.left = -leftOffset / fxScale; - spi.mSpriteRect.top = -topOffset / fyScale; - spi.mSpriteRect.width = spi.spriteWidth / fxScale; - spi.mSpriteRect.height = spi.spriteHeight / fyScale; - - if (i == 1 && ShouldExpandSprite()) - { - // a little adjustment to make sprites look better with texture filtering: - // create a 1 pixel wide empty frame around them. - - int oldwidth = spi.spriteWidth - 2; - int oldheight = spi.spriteHeight - 2; - - leftOffset += 1; - topOffset += 1; - - // Reposition the sprite with the frame considered - spi.mSpriteRect.left = -(float)leftOffset / fxScale; - spi.mSpriteRect.top = -(float)topOffset / fyScale; - spi.mSpriteRect.width = (float)spi.spriteWidth / fxScale; - spi.mSpriteRect.height = (float)spi.spriteHeight / fyScale; - - if (spi.mTrimResult > 0) - { - spi.mSpriteRect.left += (float)spi.trim[0] / fxScale; - spi.mSpriteRect.top += (float)spi.trim[1] / fyScale; - - spi.mSpriteRect.width -= float(oldwidth - spi.trim[2]) / fxScale; - spi.mSpriteRect.height -= float(oldheight - spi.trim[3]) / fyScale; - - spi.mSpriteU[0] = (float)spi.trim[0] / (float)spi.spriteWidth; - spi.mSpriteV[0] = (float)spi.trim[1] / (float)spi.spriteHeight; - spi.mSpriteU[1] -= float(oldwidth - spi.trim[0] - spi.trim[2]) / (float)spi.spriteWidth; - spi.mSpriteV[1] -= float(oldheight - spi.trim[1] - spi.trim[3]) / (float)spi.spriteHeight; - } - } - } -} - - -void FGameTexture::CleanHardwareData(bool full) -{ - -} - //=========================================================================== // // Create a hardware texture for this texture image. @@ -813,104 +527,6 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags) return nullptr; } -//=========================================================================== -// -// Coordinate helper. -// The only reason this is even needed is that many years ago someone -// was convinced that having per-texel panning on walls was a good idea. -// If it wasn't for this relatively useless feature the entire positioning -// code for wall textures could be a lot simpler. -// -//=========================================================================== - -//=========================================================================== -// -// -// -//=========================================================================== - -float FTexCoordInfo::RowOffset(float rowoffset) const -{ - float scale = fabs(mScale.Y); - if (scale == 1.f || mWorldPanning) return rowoffset; - else return rowoffset / scale; -} - -//=========================================================================== -// -// -// -//=========================================================================== - -float FTexCoordInfo::TextureOffset(float textureoffset) const -{ - float scale = fabs(mScale.X); - if (scale == 1.f || mWorldPanning) return textureoffset; - else return textureoffset / scale; -} - -//=========================================================================== -// -// Returns the size for which texture offset coordinates are used. -// -//=========================================================================== - -float FTexCoordInfo::TextureAdjustWidth() const -{ - if (mWorldPanning) - { - float tscale = fabs(mTempScale.X); - if (tscale == 1.f) return (float)mRenderWidth; - else return mWidth / fabs(tscale); - } - else return (float)mWidth; -} - - -//=========================================================================== -// -// Retrieve texture coordinate info for per-wall scaling -// -//=========================================================================== - -void FTexCoordInfo::GetFromTexture(FGameTexture *tex, float x, float y, bool forceworldpanning) -{ - if (x == 1.f) - { - mRenderWidth = xs_RoundToInt(tex->GetDisplayWidth()); - mScale.X = tex->GetScaleX(); - mTempScale.X = 1.f; - } - else - { - float scale_x = x * tex->GetScaleX(); - mRenderWidth = xs_CeilToInt(tex->GetTexelWidth() / scale_x); - mScale.X = scale_x; - mTempScale.X = x; - } - - if (y == 1.f) - { - mRenderHeight = xs_RoundToInt(tex->GetDisplayHeight()); - mScale.Y = tex->GetScaleY(); - mTempScale.Y = 1.f; - } - else - { - float scale_y = y * tex->GetScaleY(); - mRenderHeight = xs_CeilToInt(tex->GetTexelHeight() / scale_y); - mScale.Y = scale_y; - mTempScale.Y = y; - } - if (tex->isHardwareCanvas()) - { - mScale.Y = -mScale.Y; - mRenderHeight = -mRenderHeight; - } - mWorldPanning = tex->useWorldPanning() || forceworldpanning; - mWidth = tex->GetTexelWidth(); -} - //========================================================================== // @@ -930,76 +546,3 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) } -FGameTexture::FGameTexture(FTexture* wrap, const char* name) : Name(name) -{ - if (wrap) Setup(wrap); -} - -void FGameTexture::Setup(FTexture *wrap) -{ - Base = wrap; - id.SetInvalid(); - TexelWidth = Base->GetWidth(); - DisplayWidth = (float)TexelWidth; - TexelHeight = Base->GetHeight(); - DisplayHeight = (float)TexelHeight; - auto img = Base->GetImage(); - if (img) - { - auto ofs = img->GetOffsets(); - LeftOffset[0] = LeftOffset[1] = ofs.first; - TopOffset[0] = TopOffset[1] = ofs.second; - } - else - { - LeftOffset[0] = LeftOffset[1] = - TopOffset[0] = TopOffset[1] = 0; - - } - ScaleX = ScaleY = 1.f; -} - - -FGameTexture::~FGameTexture() -{ - FGameTexture* link = fileSystem.GetLinkedTexture(GetSourceLump()); - if (link == this) fileSystem.SetLinkedTexture(GetSourceLump(), nullptr); - if (SoftwareTexture != nullptr) - { - delete SoftwareTexture; - SoftwareTexture = nullptr; - } - for (auto &mat : Material) - { - if (mat != nullptr) DeleteMaterial(mat); - mat = nullptr; - } - -} - -bool FGameTexture::isUserContent() const -{ - int filenum = fileSystem.GetFileContainer(Base->GetSourceLump()); - return (filenum > fileSystem.GetMaxIwadNum()); -} - - -//----------------------------------------------------------------------------- -// -// Make sprite offset adjustment user-configurable per renderer. -// -//----------------------------------------------------------------------------- - -CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - r_spriteadjustHW = !!(self & 2); - r_spriteadjustSW = !!(self & 1); - for (int i = 0; i < TexMan.NumTextures(); i++) - { - auto tex = TexMan.GetGameTexture(FSetTextureID(i)); - if (tex->GetTexelLeftOffset(0) != tex->GetTexelLeftOffset(1) || tex->GetTexelTopOffset(0) != tex->GetTexelTopOffset(1)) - { - tex->SetSpriteRect(); - } - } -} diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 6d6a0dbcf2..34483fc0c0 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -126,6 +126,25 @@ void FTextureManager::FlushAll() } } +//========================================================================== +// +// Examines the lump contents to decide what type of texture to create, +// and creates the texture. +// +//========================================================================== + +static FTexture* CreateTextureFromLump(int lumpnum, bool allowflats = false) +{ + if (lumpnum == -1) return nullptr; + + auto image = FImageSource::GetImage(lumpnum, allowflats); + if (image != nullptr) + { + return new FImageTexture(image); + } + return nullptr; +} + //========================================================================== // // FTextureManager :: CheckForTexture @@ -230,7 +249,7 @@ FTextureID FTextureManager::CheckForTexture (const char *name, ETextureType uset if (tex == NO_TEXTURE) return FTextureID(-1); if (tex != NULL) return tex->GetID(); if (flags & TEXMAN_DontCreate) return FTextureID(-1); // we only want to check, there's no need to create a texture if we don't have one yet. - tex = MakeGameTexture(FTexture::CreateTexture(lump), nullptr, ETextureType::Override); + tex = MakeGameTexture(CreateTextureFromLump(lump), nullptr, ETextureType::Override); if (tex != NULL) { tex->AddAutoMaterials(); @@ -424,7 +443,7 @@ FTextureID FTextureManager::CreateTexture (int lumpnum, ETextureType usetype) { FString str; fileSystem.GetFileShortName(str, lumpnum); - auto out = MakeGameTexture(FTexture::CreateTexture(lumpnum, usetype == ETextureType::Flat), str, usetype); + auto out = MakeGameTexture(CreateTextureFromLump(lumpnum, usetype == ETextureType::Flat), str, usetype); if (out != NULL) { @@ -587,7 +606,7 @@ void FTextureManager::AddHiresTextures (int wadnum) if (amount == 0) { // A texture with this name does not yet exist - auto newtex = MakeGameTexture(FTexture::CreateTexture(firsttx), Name, ETextureType::Override); + auto newtex = MakeGameTexture(CreateTextureFromLump(firsttx), Name, ETextureType::Override); if (newtex != NULL) { AddGameTexture(newtex); @@ -597,7 +616,7 @@ void FTextureManager::AddHiresTextures (int wadnum) { for(unsigned int i = 0; i < tlist.Size(); i++) { - FTexture * newtex = FTexture::CreateTexture (firsttx); + FTexture * newtex = CreateTextureFromLump(firsttx); if (newtex != NULL) { auto oldtex = Textures[tlist[i].GetIndex()].Texture; @@ -695,7 +714,7 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build (sl=oldtex->GetSourceLump()) >= 0 && fileSystem.GetFileNamespace(sl) == ns_sprites) ) { - FTexture * newtex = FTexture::CreateTexture (lumpnum); + FTexture * newtex = CreateTextureFromLump(lumpnum); if (newtex != NULL) { // Replace the entire texture and adjust the scaling and offset factors. @@ -733,7 +752,7 @@ void FTextureManager::ParseTextureDef(int lump, FMultipatchTextureBuilder &build if (lumpnum>=0) { - auto newtex = MakeGameTexture(FTexture::CreateTexture(lumpnum), src, ETextureType::Override); + auto newtex = MakeGameTexture(CreateTextureFromLump(lumpnum), src, ETextureType::Override); if (newtex != NULL) { @@ -953,7 +972,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b // Try to create a texture from this lump and add it. // Unfortunately we have to look at everything that comes through here... - auto out = MakeGameTexture(FTexture::CreateTexture(i), Name, skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch); + auto out = MakeGameTexture(CreateTextureFromLump(i), Name, skin ? ETextureType::SkinGraphic : ETextureType::MiscPatch); if (out != NULL) { diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index d4e801b8f9..1cb4843fb5 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -42,17 +42,26 @@ #include "textureid.h" #include #include "hw_texcontainer.h" +#include "floatrect.h" #include "refcounted.h" -#include "xs_Float.h" - -// 15 because 0th texture is our texture -#define MAX_CUSTOM_HW_SHADER_TEXTURES 15 typedef TMap SpriteHits; class FImageSource; class FGameTexture; class IHardwareTexture; + +enum +{ + CLAMP_NONE = 0, + CLAMP_X = 1, + CLAMP_Y = 2, + CLAMP_XY = 3, + CLAMP_XY_NOMIP = 4, + CLAMP_NOFILTER = 5, + CLAMP_CAMTEX = 6, +}; + enum MaterialShaderIndex { SHADER_Default, @@ -101,27 +110,6 @@ struct UserShaderDesc extern TArray usershaders; - -struct FloatRect -{ - float left,top; - float width,height; - - - void Offset(float xofs,float yofs) - { - left+=xofs; - top+=yofs; - } - void Scale(float xfac,float yfac) - { - left*=xfac; - width*=xfac; - top*=yfac; - height*=yfac; - } -}; - class FBitmap; struct FRemapTable; struct FCopyInfo; @@ -216,26 +204,6 @@ struct FTextureBuffer }; -struct SpritePositioningInfo -{ - uint16_t trim[4]; - int spriteWidth, spriteHeight; - float mSpriteU[2], mSpriteV[2]; - FloatRect mSpriteRect; - uint8_t mTrimResult; - - float GetSpriteUL() const { return mSpriteU[0]; } - float GetSpriteVT() const { return mSpriteV[0]; } - float GetSpriteUR() const { return mSpriteU[1]; } - float GetSpriteVB() const { return mSpriteV[1]; } - - const FloatRect &GetSpriteRect() const - { - return mSpriteRect; - } - -}; - // Base texture class class FTexture : public RefCountedBase { @@ -256,7 +224,6 @@ protected: public: IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); - static FTexture *CreateTexture(int lumpnum, bool allowflats = false); virtual FImageSource *GetImage() const { return nullptr; } void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); void CleanHardwareTextures(); @@ -387,299 +354,8 @@ public: }; -struct MaterialLayers -{ - float Glossiness; - float SpecularLevel; - FGameTexture* Brightmap; - FGameTexture* Normal; - FGameTexture* Specular; - FGameTexture* Metallic; - FGameTexture* Roughness; - FGameTexture* AmbientOcclusion; - FGameTexture* CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES]; -}; - -struct FTexCoordInfo -{ - int mRenderWidth; - int mRenderHeight; - int mWidth; - FVector2 mScale; - FVector2 mTempScale; - bool mWorldPanning; - - float FloatToTexU(float v) const { return v / mRenderWidth; } - float FloatToTexV(float v) const { return v / mRenderHeight; } - float RowOffset(float ofs) const; - float TextureOffset(float ofs) const; - float TextureAdjustWidth() const; - void GetFromTexture(FGameTexture* tex, float x, float y, bool forceworldpanning); -}; - -enum -{ - CLAMP_NONE = 0, - CLAMP_X = 1, - CLAMP_Y = 2, - CLAMP_XY = 3, - CLAMP_XY_NOMIP = 4, - CLAMP_NOFILTER = 5, - CLAMP_CAMTEX = 6, -}; - - -enum EGameTexFlags -{ - GTexf_NoDecals = 1, // Decals should not stick to texture - GTexf_WorldPanning = 2, // Texture is panned in world units rather than texels - GTexf_FullNameTexture = 4, // Name is taken from the file system. - GTexf_Glowing = 8, // Texture emits a glow - GTexf_AutoGlowing = 16, // Glow info is determined from texture image. - GTexf_RenderFullbright = 32, // always draw fullbright - GTexf_DisableFullbrightSprites = 64, // This texture will not be displayed as fullbright sprite - GTexf_BrightmapChecked = 128, // Check for a colormap-based brightmap was already done. -}; - -// Refactoring helper to allow piece by piece adjustment of the API -class FGameTexture -{ - friend class FMaterial; - - // Material layers. These are shared so reference counting is used. - RefCountedPtr Base; - RefCountedPtr Brightmap; - RefCountedPtr Detailmap; - RefCountedPtr Glowmap; - RefCountedPtr Normal; // Normal map texture - RefCountedPtr Specular; // Specular light texture for the diffuse+normal+specular light model - RefCountedPtr Metallic; // Metalness texture for the physically based rendering (PBR) light model - RefCountedPtr Roughness; // Roughness texture for PBR - RefCountedPtr AmbientOcclusion; // Ambient occlusion texture for PBR - RefCountedPtr CustomShaderTextures[MAX_CUSTOM_HW_SHADER_TEXTURES]; // Custom texture maps for custom hardware shaders - - FString Name; - FTextureID id; - - uint16_t TexelWidth, TexelHeight; - int16_t LeftOffset[2], TopOffset[2]; - float DisplayWidth, DisplayHeight; - float ScaleX, ScaleY; - - int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture. - ETextureType UseType = ETextureType::Wall; // This texture's primary purpose - SpritePositioningInfo* spi = nullptr; - - ISoftwareTexture* SoftwareTexture = nullptr; - FMaterial* Material[4] = { }; - - // Material properties - float Glossiness = 10.f; - float SpecularLevel = 0.1f; - float shaderspeed = 1.f; - int shaderindex = 0; - - int flags = 0; - uint8_t warped = 0, expandSprite = -1; - uint16_t GlowHeight; - PalEntry GlowColor = 0; - - int16_t SkyOffset = 0; - uint16_t Rotations = 0xffff; - - -public: - FGameTexture(FTexture* wrap, const char *name); - ~FGameTexture(); - void Setup(FTexture* wrap); - FTextureID GetID() const { return id; } - void SetID(FTextureID newid) { id = newid; } // should only be called by the texture manager - const FString& GetName() const { return Name; } - void SetName(const char* name) { Name = name; } // should only be called by setup code. - - float GetScaleX() { return ScaleX; } - float GetScaleY() { return ScaleY; } - float GetDisplayWidth() const { return DisplayWidth; } - float GetDisplayHeight() const { return DisplayHeight; } - int GetTexelWidth() const { return TexelWidth; } - int GetTexelHeight() const { return TexelHeight; } - - void CreateDefaultBrightmap(); - void AddAutoMaterials(); - bool ShouldExpandSprite(); - void SetupSpriteData(); - void SetSpriteRect(); - - ETextureType GetUseType() const { return UseType; } - void SetUpscaleFlag(int what) { shouldUpscaleFlag = what; } - int GetUpscaleFlag() { return shouldUpscaleFlag; } - - FTexture* GetTexture() { return Base.get(); } - int GetSourceLump() const { return Base->GetSourceLump(); } - void SetBrightmap(FGameTexture* tex) { Brightmap = tex->GetTexture(); } - - int GetTexelLeftOffset(int adjusted = 0) const { return LeftOffset[adjusted]; } - int GetTexelTopOffset(int adjusted = 0) const { return TopOffset[adjusted]; } - float GetDisplayLeftOffset(int adjusted = 0) const { return LeftOffset[adjusted] / ScaleX; } - float GetDisplayTopOffset(int adjusted = 0) const { return TopOffset[adjusted] / ScaleY; } - - bool isMiscPatch() const { return GetUseType() == ETextureType::MiscPatch; } // only used by the intermission screen to decide whether to tile the background image or not. - bool isFullbrightDisabled() const { return !!(flags & GTexf_DisableFullbrightSprites); } - bool isFullbright() const { return !!(flags & GTexf_RenderFullbright); } - bool isFullNameTexture() const { return !!(flags & GTexf_FullNameTexture); } - bool expandSprites() const { return !!expandSprite; } - bool useWorldPanning() const { return !!(flags & GTexf_WorldPanning); } - void SetWorldPanning(bool on) { if (on) flags |= GTexf_WorldPanning; else flags &= ~GTexf_WorldPanning; } - bool allowNoDecals() const { return !!(flags & GTexf_NoDecals); } - void SetNoDecals(bool on) { if (on) flags |= GTexf_NoDecals; else flags &= ~GTexf_NoDecals; } - - bool isValid() const { return UseType != ETextureType::Null; } - int isWarped() { return warped; } - void SetWarpStyle(int style) { warped = style; } - bool isMasked() { return Base->Masked; } - bool isHardwareCanvas() const { return Base->isHardwareCanvas(); } // There's two here so that this can deal with software canvases in the hardware renderer later. - bool isSoftwareCanvas() const { return Base->isCanvas(); } - - void SetTranslucent(bool on) { Base->bTranslucent = on; } - void SetUseType(ETextureType type) { UseType = type; } - int GetRotations() const { return Rotations; } - void SetRotations(int rot) { Rotations = int16_t(rot); } - void SetSkyOffset(int offs) { SkyOffset = offs; } - int GetSkyOffset() const { return SkyOffset; } - - ISoftwareTexture* GetSoftwareTexture() - { - return SoftwareTexture; - } - void SetSoftwareTexture(ISoftwareTexture* swtex) - { - SoftwareTexture = swtex; - } - - FMaterial* GetMaterial(int num) - { - return Material[num]; - } - - int GetShaderIndex() const { return shaderindex; } - float GetShaderSpeed() const { return shaderspeed; } - void SetShaderSpeed(float speed) { shaderspeed = speed; } - void SetShaderIndex(int index) { shaderindex = index; } - void SetShaderLayers(MaterialLayers& lay) - { - // Only update layers that have something defind. - if (lay.Glossiness > -1000) Glossiness = lay.Glossiness; - if (lay.SpecularLevel > -1000) SpecularLevel = lay.SpecularLevel; - if (lay.Brightmap) Brightmap = lay.Brightmap->GetTexture(); - if (lay.Normal) Normal = lay.Normal->GetTexture(); - if (lay.Specular) Specular = lay.Specular->GetTexture(); - if (lay.Metallic) Metallic = lay.Metallic->GetTexture(); - if (lay.Roughness) Roughness = lay.Roughness->GetTexture(); - if (lay.AmbientOcclusion) AmbientOcclusion = lay.AmbientOcclusion->GetTexture(); - for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) - { - if (lay.CustomShaderTextures[i]) CustomShaderTextures[i] = lay.CustomShaderTextures[i]->GetTexture(); - } - } - float GetGlossiness() const { return Glossiness; } - float GetSpecularLevel() const { return SpecularLevel; } - - void CopySize(FGameTexture* BaseTexture) - { - Base->CopySize(BaseTexture->Base.get()); - } - - // Glowing is a pure material property that should not filter down to the actual texture objects. - void GetGlowColor(float* data); - bool isGlowing() const { return !!(flags & GTexf_Glowing); } - bool isAutoGlowing() const { return !!(flags & GTexf_AutoGlowing); } - int GetGlowHeight() const { return GlowHeight; } - void SetAutoGlowing() { flags |= (GTexf_AutoGlowing | GTexf_Glowing | GTexf_RenderFullbright); } - void SetGlowHeight(int v) { GlowHeight = v; } - void SetFullbright() { flags |= GTexf_RenderFullbright; } - void SetDisableFullbright(bool on) { if (on) flags |= GTexf_DisableFullbrightSprites; else flags &= ~GTexf_DisableFullbrightSprites; } - void SetGlowing(PalEntry color) { flags = (flags & ~GTexf_AutoGlowing) | GTexf_Glowing; GlowColor = color; } - - bool isUserContent() const; - int CheckRealHeight() { return xs_RoundToInt(Base->CheckRealHeight() / ScaleY); } - void SetSize(int x, int y) - { - TexelWidth = x; - TexelHeight = y; - SetDisplaySize(float(x), float(y)); - } - void SetDisplaySize(float w, float h) - { - DisplayWidth = w; - DisplayHeight = h; - ScaleX = TexelWidth / w; - ScaleY = TexelHeight / h; - - // compensate for roundoff errors - if (int(ScaleX * w) != TexelWidth) ScaleX += (1 / 65536.); - if (int(ScaleY * h) != TexelHeight) ScaleY += (1 / 65536.); - - } - void SetOffsets(int which, int x, int y) - { - LeftOffset[which] = x; - TopOffset[which] = y; - } - void SetScale(float x, float y) - { - ScaleX = x; - ScaleY = y; - DisplayWidth = x * TexelWidth; - DisplayHeight = y * TexelHeight; - } - - const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; } - int GetAreas(FloatRect** pAreas) const; - - bool GetTranslucency() - { - return Base->GetTranslucency(); - } - - int GetClampMode(int clampmode) - { - if (GetUseType() == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; - else if (isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - else if ((isWarped() || shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; - return clampmode; - } - - void CleanHardwareData(bool full = true); - -}; - -inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType) -{ - if (!tex) return nullptr; - auto t = new FGameTexture(tex, name); - t->SetUseType(useType); - return t; -} - -enum EUpscaleFlags -{ - UF_None = 0, - UF_Texture = 1, - UF_Sprite = 2, - UF_Font = 4 -}; - -extern int upscalemask; -void UpdateUpscaleMask(); - -int calcShouldUpscale(FGameTexture* tex); -inline int shouldUpscale(FGameTexture* tex, EUpscaleFlags UseType) -{ - // This only checks the global scale mask and the texture's validation for upscaling. Everything else has been done up front elsewhere. - if (!(upscalemask & UseType)) return 0; - return tex->GetUpscaleFlag(); -} +#include "gametexture.h" #endif diff --git a/src/common/utility/floatrect.h b/src/common/utility/floatrect.h new file mode 100644 index 0000000000..8274b84989 --- /dev/null +++ b/src/common/utility/floatrect.h @@ -0,0 +1,21 @@ +#pragma once + +struct FloatRect +{ + float left,top; + float width,height; + + + void Offset(float xofs,float yofs) + { + left+=xofs; + top+=yofs; + } + void Scale(float xfac,float yfac) + { + left*=xfac; + width*=xfac; + top*=yfac; + height*=yfac; + } +}; diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 55c6b60502..db9af53cf9 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -1276,7 +1276,7 @@ class GLDefsParser if (tex) { bool okay = false; - for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) + for (size_t i = 0; i < countof(mlay.CustomShaderTextures); i++) { if (!mlay.CustomShaderTextures[i]) { @@ -1287,7 +1287,7 @@ class GLDefsParser } texNameList.Push(textureName); - texNameIndex.Push(i); + texNameIndex.Push((int)i); okay = true; break; } @@ -1571,7 +1571,7 @@ class GLDefsParser } sc.MustGetString(); bool okay = false; - for (int i = 0; i < MAX_CUSTOM_HW_SHADER_TEXTURES; i++) + for (size_t i = 0; i < countof(mlay.CustomShaderTextures); i++) { if (!mlay.CustomShaderTextures[i]) { @@ -1582,7 +1582,7 @@ class GLDefsParser } texNameList.Push(textureName); - texNameIndex.Push(i); + texNameIndex.Push((int)i); okay = true; break; } diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 55f92a8d4a..908fe66d9f 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -227,11 +227,14 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl auto tex = TexMan.GameByIndex(i); if (tex != nullptr && tex->GetUseType() != ETextureType::FontChar) { - // For now, only delete what's in neither list. The logic being used here does not really work that well for selective deletion. + // This is rather counterproductive in a system that can share hardware textures between game textures. + // The precacher needs to be redone to account for that. For now, just skip the deletion, for any normal sized map this won't be a problem. +#if 0 if (usedTextures.CheckKey(tex->GetTexture()) == nullptr && usedSprites.CheckKey(tex->GetTexture()) == nullptr) { tex->CleanHardwareData(); } +#endif } } From b2281c38e1cb9ba37d05934e3da46a3080babdb8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Apr 2020 10:08:24 +0200 Subject: [PATCH 062/220] - fixed texture layer management so that each material layer can decide for itself if it wants to allow upscaling. - rewrote the hardware texture precacher to use the new texture management to properly track the data to delete. --- src/common/textures/gametexture.h | 15 ++- src/common/textures/hw_material.cpp | 31 +++--- src/common/textures/hw_material.h | 28 ++--- src/common/textures/hw_texcontainer.h | 42 ++++++-- src/common/textures/texture.cpp | 6 -- src/common/textures/textures.h | 21 +++- src/rendering/2d/f_wipe.cpp | 2 +- src/rendering/gl/renderer/gl_renderstate.cpp | 9 +- src/rendering/gl/system/gl_framebuffer.cpp | 8 +- .../hwrenderer/scene/hw_renderstate.h | 1 - .../hwrenderer/textures/hw_precache.cpp | 101 +++++++++++------- .../polyrenderer/backend/poly_framebuffer.cpp | 13 +-- .../polyrenderer/backend/poly_framebuffer.h | 1 - .../polyrenderer/backend/poly_hwtexture.cpp | 11 -- .../polyrenderer/backend/poly_hwtexture.h | 1 - .../polyrenderer/backend/poly_renderstate.cpp | 9 +- src/rendering/swrenderer/r_swscene.cpp | 2 +- .../vulkan/renderer/vk_renderstate.cpp | 2 +- .../vulkan/system/vk_framebuffer.cpp | 10 +- .../vulkan/textures/vk_hwtexture.cpp | 12 +-- 20 files changed, 190 insertions(+), 135 deletions(-) diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index f99c45b74b..652e6fbe12 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -145,7 +145,7 @@ public: bool isFullbrightDisabled() const { return !!(flags & GTexf_DisableFullbrightSprites); } bool isFullbright() const { return !!(flags & GTexf_RenderFullbright); } bool isFullNameTexture() const { return !!(flags & GTexf_FullNameTexture); } - bool expandSprites() const { return !!expandSprite; } + bool expandSprites() { return expandSprite == -1? ShouldExpandSprite() : !!expandSprite; } bool useWorldPanning() const { return !!(flags & GTexf_WorldPanning); } void SetWorldPanning(bool on) { if (on) flags |= GTexf_WorldPanning; else flags &= ~GTexf_WorldPanning; } bool allowNoDecals() const { return !!(flags & GTexf_NoDecals); } @@ -269,6 +269,19 @@ public: void CleanHardwareData(bool full = true); + void GetLayers(TArray& layers) + { + layers.Clear(); + for (auto tex : { Base.get(), Brightmap.get(), Detailmap.get(), Glowmap.get(), Normal.get(), Specular.get(), Metallic.get(), Roughness.get(), AmbientOcclusion.get() }) + { + if (tex != nullptr) layers.Push(tex); + } + for (auto& tex : CustomShaderTextures) + { + if (tex != nullptr) layers.Push(tex.get()); + } + } + }; inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 70e13fdc62..2930826073 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -41,7 +41,8 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) { mShaderIndex = SHADER_Default; sourcetex = tx; - imgtex = tx->GetTexture(); + auto imgtex = tx->GetTexture(); + mTextureLayers.Push({ imgtex, scaleflags }); if (tx->GetUseType() == ETextureType::SWCanvas && static_cast(imgtex)->GetColorFormat() == 0) { @@ -66,7 +67,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) { for (auto &texture : { tx->Normal.get(), tx->Specular.get() }) { - mTextureLayers.Push(texture); + mTextureLayers.Push({ texture, 0 }); } mShaderIndex = SHADER_Specular; } @@ -74,7 +75,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) { for (auto &texture : { tx->Normal.get(), tx->Metallic.get(), tx->Roughness.get(), tx->AmbientOcclusion.get() }) { - mTextureLayers.Push(texture); + mTextureLayers.Push({ texture, 0 }); } mShaderIndex = SHADER_PBR; } @@ -84,30 +85,30 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) auto placeholder = TexMan.GameByIndex(1); if (tx->Brightmap.get()) { - mTextureLayers.Push(tx->Brightmap.get()); + mTextureLayers.Push({ tx->Brightmap.get(), scaleflags }); mLayerFlags |= TEXF_Brightmap; } else { - mTextureLayers.Push(placeholder->GetTexture()); + mTextureLayers.Push({ placeholder->GetTexture(), 0 }); } if (tx->Detailmap.get()) { - mTextureLayers.Push(tx->Detailmap.get()); + mTextureLayers.Push({ tx->Detailmap.get(), 0 }); mLayerFlags |= TEXF_Detailmap; } else { - mTextureLayers.Push(placeholder->GetTexture()); + mTextureLayers.Push({ placeholder->GetTexture(), 0 }); } if (tx->Glowmap.get()) { - mTextureLayers.Push(tx->Glowmap.get()); + mTextureLayers.Push({ tx->Glowmap.get(), scaleflags }); mLayerFlags |= TEXF_Glowmap; } else { - mTextureLayers.Push(placeholder->GetTexture()); + mTextureLayers.Push({ placeholder->GetTexture(), 0 }); } auto index = tx->GetShaderIndex(); @@ -119,7 +120,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) for (auto &texture : tx->CustomShaderTextures) { if (texture == nullptr) continue; - mTextureLayers.Push(texture.get()); + mTextureLayers.Push({ texture.get(), 0 }); // scalability should be user-definable. } mShaderIndex = index; } @@ -149,12 +150,12 @@ FMaterial::~FMaterial() // //=========================================================================== -IHardwareTexture *FMaterial::GetLayer(int i, int translation, FTexture **pLayer) const +IHardwareTexture *FMaterial::GetLayer(int i, int translation, MaterialLayerInfo **pLayer) const { - FTexture *layer = i == 0 ? imgtex : mTextureLayers[i - 1]; - if (pLayer) *pLayer = layer; + auto &layer = mTextureLayers[i]; + if (pLayer) *pLayer = &layer; - if (layer) return layer->GetHardwareTexture(translation, mScaleFlags); + if (layer.layerTexture) return layer.layerTexture->GetHardwareTexture(translation, layer.scaleFlags); return nullptr; } @@ -169,7 +170,7 @@ FMaterial * FMaterial::ValidateTexture(FGameTexture * gtex, int scaleflags, bool { if (gtex && gtex->isValid()) { - if (!gtex->ShouldExpandSprite()) scaleflags &= ~CTF_Expand; + if (!gtex->expandSprites()) scaleflags &= ~CTF_Expand; FMaterial *hwtex = gtex->Material[scaleflags]; if (hwtex == NULL && create) diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index fddaa73f7b..d7509cc946 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -8,6 +8,12 @@ struct FRemapTable; class IHardwareTexture; +struct MaterialLayerInfo +{ + FTexture* layerTexture; + int scaleFlags; +}; + //=========================================================================== // // this is the material class for OpenGL. @@ -17,14 +23,13 @@ class IHardwareTexture; class FMaterial { private: - TArray mTextureLayers; + TArray mTextureLayers; // the only layers allowed to scale are the brightmap and the glowmap. int mShaderIndex; int mLayerFlags = 0; int mScaleFlags; public: FGameTexture *sourcetex; // the owning texture. - FTexture* imgtex; // the first layer's texture image - should be moved into the array FMaterial(FGameTexture *tex, int scaleflags); virtual ~FMaterial(); @@ -37,27 +42,22 @@ public: { return sourcetex; } - FTexture* BaseLayer() const + + void AddTextureLayer(FTexture *tex, bool allowscale) { - // Only for spftpoly! - return imgtex; - } - void AddTextureLayer(FTexture *tex) - { - //ValidateTexture(tex, false); - mTextureLayers.Push(tex); + mTextureLayers.Push({ tex, allowscale }); } - int GetLayers() const + int NumLayers() const { - return mTextureLayers.Size() + 1; + return mTextureLayers.Size(); } - IHardwareTexture *GetLayer(int i, int translation, FTexture **pLayer = nullptr) const; + IHardwareTexture *GetLayer(int i, int translation, MaterialLayerInfo **pLayer = nullptr) const; static FMaterial *ValidateTexture(FGameTexture * tex, int scaleflags, bool create = true); - const TArray &GetLayerArray() const + const TArray &GetLayerArray() const { return mTextureLayers; } diff --git a/src/common/textures/hw_texcontainer.h b/src/common/textures/hw_texcontainer.h index 5876d6a2ca..cc350d635a 100644 --- a/src/common/textures/hw_texcontainer.h +++ b/src/common/textures/hw_texcontainer.h @@ -29,6 +29,7 @@ private: { IHardwareTexture *hwTexture = nullptr; int translation = 0; + bool precacheMarker; // This is used to check whether a texture has been hit by the precacher, so that the cleanup code can delete the unneeded ones. void Delete() { @@ -40,6 +41,16 @@ private: { Delete(); } + + void MarkForPrecache(bool on) + { + precacheMarker = on; + } + + bool isMarkedForPreache() const + { + return precacheMarker; + } }; private: @@ -99,25 +110,44 @@ public: //=========================================================================== // // Deletes all allocated resources and considers translations - // This will only be called for sprites // //=========================================================================== - void CleanUnused(SpriteHits &usedtranslations, int scaleflags) + void CleanUnused() { - if (usedtranslations.CheckKey(0) == nullptr) + for (auto& tt : hwDefTex) { - hwDefTex[scaleflags].Delete(); + if (!tt.isMarkedForPreache()) tt.Delete(); } for (int i = hwTex_Translated.Size()-1; i>= 0; i--) { - if (usedtranslations.CheckKey(hwTex_Translated[i].translation & 0xffffff) == nullptr) + auto& tt = hwTex_Translated[i]; + if (!tt.isMarkedForPreache()) { hwTex_Translated.Delete(i); } } } - + + void UnmarkAll() + { + for (auto& tt : hwDefTex) + { + if (!tt.isMarkedForPreache()) tt.MarkForPrecache(false); + } + for (auto& tt : hwTex_Translated) + { + if (!tt.isMarkedForPreache()) tt.MarkForPrecache(false); + } + } + + void MarkForPrecache(int translation, int scaleflags) + { + auto tt = GetTexID(translation, scaleflags); + tt->MarkForPrecache(true); + } + + template void Iterate(T callback) { diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 87f17708cf..432026bc9d 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -397,12 +397,6 @@ bool FTexture::DetermineTranslucency() return !!bTranslucent; } - -void FTexture::CleanHardwareTextures() -{ - SystemTextures.Clean(); -} - //=========================================================================== // // the default just returns an empty texture. diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 1cb4843fb5..bd9c79ed9b 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -226,7 +226,26 @@ public: IHardwareTexture* GetHardwareTexture(int translation, int scaleflags); virtual FImageSource *GetImage() const { return nullptr; } void CreateUpsampledTextureBuffer(FTextureBuffer &texbuffer, bool hasAlpha, bool checkonly); - void CleanHardwareTextures(); + + void CleanHardwareTextures() + { + SystemTextures.Clean(); + } + + void CleanPrecacheMarker() + { + SystemTextures.UnmarkAll(); + } + + void MarkForPrecache(int translation, int scaleflags) + { + SystemTextures.MarkForPrecache(translation, scaleflags); + } + + void CleanUnused() + { + SystemTextures.CleanUnused(); + } int GetWidth() { return Width; } int GetHeight() { return Height; } diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index cf51b59cec..79905fd743 100644 --- a/src/rendering/2d/f_wipe.cpp +++ b/src/rendering/2d/f_wipe.cpp @@ -337,7 +337,7 @@ void Wiper_Burn::SetTextures(FGameTexture *startscreen, FGameTexture *endscreen) endScreen = endscreen; BurnTexture = new FBurnTexture(WIDTH, HEIGHT); auto mat = FMaterial::ValidateTexture(endScreen, false); - mat->AddTextureLayer(BurnTexture); + mat->AddTextureLayer(BurnTexture, false); } //========================================================================== diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index 1c60be381e..653daa4e7b 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -323,18 +323,17 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio int usebright = false; int maxbound = 0; - int flags = mat->GetScaleFlags(); - int numLayers = mat->GetLayers(); + int numLayers = mat->NumLayers(); + MaterialLayerInfo* layer; auto base = static_cast(mat->GetLayer(0, translation)); - if (base->BindOrCreate(tex->GetTexture(), 0, clampmode, translation, flags)) + if (base->BindOrCreate(tex->GetTexture(), 0, clampmode, translation, layer->scaleFlags)) { for (int i = 1; i(mat->GetLayer(i, 0, &layer)); // fixme: Upscale flags must be disabled for certain layers. - systex->BindOrCreate(layer, i, clampmode, 0, flags); + systex->BindOrCreate(layer->layerTexture, i, clampmode, 0, layer->scaleFlags); maxbound = i; } } diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 7ea0f3df6d..0a8770b1e1 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -311,16 +311,16 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; int flags = mat->GetScaleFlags(); - int numLayers = mat->GetLayers(); - FTexture* layer; + int numLayers = mat->NumLayers(); + MaterialLayerInfo* layer; auto base = static_cast(mat->GetLayer(0, translation, &layer)); - if (base->BindOrCreate(layer, 0, CLAMP_NONE, translation, flags)) + if (base->BindOrCreate(layer->layerTexture, 0, CLAMP_NONE, translation, layer->scaleFlags)) { for (int i = 1; i < numLayers; i++) { auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->BindOrCreate(layer, i, CLAMP_NONE, 0, flags); + systex->BindOrCreate(layer->layerTexture, i, CLAMP_NONE, 0, layer->scaleFlags); } } // unbind everything. diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index eb461898fe..f7caed8335 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -572,7 +572,6 @@ public: void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, int translation, int overrideshader) { if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale; - if (!tex->expandSprites()) scaleflags &= ~CTF_Expand; SetMaterial(FMaterial::ValidateTexture(tex, scaleflags), clampmode, translation, overrideshader); } diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 908fe66d9f..3b240372fc 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -50,7 +50,10 @@ static void PrecacheTexture(FGameTexture *tex, int cache) { if (cache & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { - FMaterial * gltex = FMaterial::ValidateTexture(tex, false); + int scaleflags = 0; + if (shouldUpscale(tex, UF_Texture)) scaleflags |= CTF_Upscale; + + FMaterial * gltex = FMaterial::ValidateTexture(tex, scaleflags); if (gltex) screen->PrecacheMaterial(gltex, 0); } } @@ -62,7 +65,6 @@ static void PrecacheTexture(FGameTexture *tex, int cache) //=========================================================================== static void PrecacheList(FMaterial *gltex, SpriteHits& translations) { - //gltex->BaseLayer()->SystemTextures.CleanUnused(translations, gltex->GetScaleFlags()); this needs to be redone. SpriteHits::Iterator it(translations); SpriteHits::Pair* pair; while (it.NextPair(pair)) screen->PrecacheMaterial(gltex, pair->Key); @@ -76,7 +78,10 @@ static void PrecacheList(FMaterial *gltex, SpriteHits& translations) static void PrecacheSprite(FGameTexture *tex, SpriteHits &hits) { - FMaterial * gltex = FMaterial::ValidateTexture(tex, true); + int scaleflags = CTF_Expand; + if (shouldUpscale(tex, UF_Sprite)) scaleflags |= CTF_Upscale; + + FMaterial * gltex = FMaterial::ValidateTexture(tex, scaleflags); if (gltex) PrecacheList(gltex, hits); } @@ -88,26 +93,36 @@ static void PrecacheSprite(FGameTexture *tex, SpriteHits &hits) void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitlist) { - SpriteHits *spritelist = new SpriteHits[sprites.Size()]; - SpriteHits **spritehitlist = new SpriteHits*[TexMan.NumTextures()]; - TMap::Iterator it(actorhitlist); - TMap::Pair *pair; - uint8_t *modellist = new uint8_t[Models.Size()]; - memset(modellist, 0, Models.Size()); - memset(spritehitlist, 0, sizeof(SpriteHits**) * TexMan.NumTextures()); + TMap allTextures; + TArray layers; - // this isn't done by the main code so it needs to be done here first: - // check skybox textures and mark the separate faces as used - for (int i = 0; iGetTexture()->GetImage() && // only image textures are subject to precaching + gametex->GetUseType() != ETextureType::FontChar && // We do not want to delete font characters here as they are very likely to be needed constantly. + gametex->GetUseType() < ETextureType::Special) // Any texture marked as 'special' is also out. + { + gametex->GetLayers(layers); + for (auto layer : layers) + { + allTextures.Insert(layer, true); + layer->CleanPrecacheMarker(); + } + } + + // Mark the faces of a skybox as used. + // This isn't done by the main code so it needs to be done here. + // MBF sky transfers are being checked by the calling code to add HIT_Sky for them. if (texhitlist[i] & (FTextureManager::HIT_Sky)) { auto tex = TexMan.GameByIndex(i); auto sb = dynamic_cast(tex->GetTexture()); if (sb) { - for (int i = 0; i<6; i++) + for (int i = 0; i < 6; i++) { if (sb->faces[i]) { @@ -119,6 +134,14 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl } } + SpriteHits *spritelist = new SpriteHits[sprites.Size()]; + SpriteHits **spritehitlist = new SpriteHits*[TexMan.NumTextures()]; + TMap::Iterator it(actorhitlist); + TMap::Pair *pair; + uint8_t *modellist = new uint8_t[Models.Size()]; + memset(modellist, 0, Models.Size()); + memset(spritehitlist, 0, sizeof(SpriteHits**) * TexMan.NumTextures()); + // Check all used actors. // 1. mark all sprites associated with its states // 2. mark all model data and skins associated with its states @@ -190,7 +213,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl screen->StartPrecaching(); int cnt = TexMan.NumTextures(); - // prepare the textures for precaching. First collect all used layer textures so that we know which ones should not be deleted. + // prepare the textures for precaching. First mark all used layer textures so that we know which ones should not be deleted. for (int i = cnt - 1; i >= 0; i--) { auto tex = TexMan.GameByIndex(i); @@ -198,44 +221,46 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl { if (texhitlist[i] & (FTextureManager::HIT_Wall | FTextureManager::HIT_Flat | FTextureManager::HIT_Sky)) { - FMaterial* mat = FMaterial::ValidateTexture(tex, false, false); + int scaleflags = 0; + if (shouldUpscale(tex, UF_Texture)) scaleflags |= CTF_Upscale; + + FMaterial* mat = FMaterial::ValidateTexture(tex, scaleflags, true); if (mat != nullptr) { - for (auto ftex : mat->GetLayerArray()) + for (auto &layer : mat->GetLayerArray()) { - usedTextures.Insert(ftex, true); + if (layer.layerTexture) layer.layerTexture->MarkForPrecache(0, layer.scaleFlags); } } } if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0) { - FMaterial *mat = FMaterial::ValidateTexture(tex, true, false); + int scaleflags = CTF_Expand; + if (shouldUpscale(tex, UF_Sprite)) scaleflags |= CTF_Upscale; + + FMaterial *mat = FMaterial::ValidateTexture(tex, true, true); if (mat != nullptr) { - for (auto ftex : mat->GetLayerArray()) + SpriteHits::Iterator it(*spritehitlist[i]); + SpriteHits::Pair* pair; + while (it.NextPair(pair)) { - usedSprites.Insert(ftex, true); + for (auto& layer : mat->GetLayerArray()) + { + if (layer.layerTexture) layer.layerTexture->MarkForPrecache(pair->Key, layer.scaleFlags); + } } } } } } - // delete unused textures (i.e. those which didn't get referenced by any material in the cache list. - for (int i = cnt - 1; i >= 0; i--) + // delete unused hardware textures (i.e. those which didn't get referenced by any material in the cache list.) + decltype(allTextures)::Iterator ita(allTextures); + decltype(allTextures)::Pair* paira; + while (it.NextPair(pair)) { - auto tex = TexMan.GameByIndex(i); - if (tex != nullptr && tex->GetUseType() != ETextureType::FontChar) - { - // This is rather counterproductive in a system that can share hardware textures between game textures. - // The precacher needs to be redone to account for that. For now, just skip the deletion, for any normal sized map this won't be a problem. -#if 0 - if (usedTextures.CheckKey(tex->GetTexture()) == nullptr && usedSprites.CheckKey(tex->GetTexture()) == nullptr) - { - tex->CleanHardwareData(); - } -#endif - } + paira->Key->CleanUnused(); } if (gl_precache) @@ -246,7 +271,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl FImageSource::BeginPrecaching(); - // cache all used textures + // cache all used images for (int i = cnt - 1; i >= 0; i--) { auto gtex = TexMan.GameByIndex(i); @@ -262,7 +287,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl } } - // Only register untranslated sprites. Translated ones are very unlikely to require data that can be reused. + // Only register untranslated sprite images. Translated ones are very unlikely to require data that can be reused so they can just be created on demand. if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CheckKey(0)) { FImageSource::RegisterForPrecache(tex->GetImage(), V_IsTrueColor()); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 0731cfd2bf..4cfb58d65b 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -535,16 +535,15 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; - int flags = mat->GetScaleFlags(); - FTexture* layer; + MaterialLayerInfo* layer; auto systex = static_cast(mat->GetLayer(0, translation, &layer)); - systex->GetImage(layer, translation, flags); + systex->GetImage(layer->layerTexture, translation, layer->scaleFlags); - int numLayers = mat->GetLayers(); + int numLayers = mat->NumLayers(); for (int i = 1; i < numLayers; i++) { auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->GetImage(layer, 0, flags); // fixme: Upscale flags must be disabled for certain layers. + systex->GetImage(layer->layerTexture, 0, layer->scaleFlags); // fixme: Upscale flags must be disabled for certain layers. } } @@ -585,10 +584,6 @@ void PolyFrameBuffer::TextureFilterChanged() { } -void PolyFrameBuffer::StartPrecaching() -{ -} - void PolyFrameBuffer::BlurScene(float amount) { } diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index 2e06d69062..025f14a965 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -43,7 +43,6 @@ public: sector_t *RenderView(player_t *player) override; void SetTextureFilterMode() override; void TextureFilterChanged() override; - void StartPrecaching() override; void BeginFrame() override; void BlurScene(float amount) override; void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index 7e5ec45528..55a82958f8 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -62,17 +62,6 @@ void PolyHardwareTexture::Reset() } } -DCanvas *PolyHardwareTexture::GetImage(FTexture *baselayer, const FMaterialState &state) -{ - if (!mCanvas) - { - int flags = state.mMaterial->GetScaleFlags(); - return GetImage(baselayer, state.mTranslation, flags); - } - - return mCanvas.get(); -} - DCanvas *PolyHardwareTexture::GetImage(FTexture *tex, int translation, int flags) { if (!mCanvas) diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.h b/src/rendering/polyrenderer/backend/poly_hwtexture.h index 26d9beb5bc..c93f2339d7 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.h +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.h @@ -23,7 +23,6 @@ public: static void ResetAll(); void Reset(); - DCanvas *GetImage(FTexture *tex, const FMaterialState &state); DCanvas *GetImage(FTexture *tex, int translation, int flags); PolyDepthStencil *GetDepthStencil(FTexture *tex); diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 9119ce96d2..f81587a5a8 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -314,20 +314,19 @@ void PolyRenderState::ApplyMaterial() { mTempTM = mMaterial.mMaterial->Source()->isHardwareCanvas() ? TM_OPAQUE : TM_NORMAL; - FTexture* layer; + MaterialLayerInfo* layer; auto base = static_cast(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation, &layer)); if (base) { - DCanvas *texcanvas = base->GetImage(layer, mMaterial); + DCanvas *texcanvas = base->GetImage(layer->layerTexture, mMaterial.mTranslation, layer->scaleFlags); mDrawCommands->SetTexture(0, texcanvas->GetPixels(), texcanvas->GetWidth(), texcanvas->GetHeight(), texcanvas->IsBgra()); - int numLayers = mMaterial.mMaterial->GetLayers(); + int numLayers = mMaterial.mMaterial->NumLayers(); for (int i = 1; i < numLayers; i++) { - FTexture* layer; auto systex = static_cast(mMaterial.mMaterial->GetLayer(i, 0, &layer)); - texcanvas = systex->GetImage(layer, 0, mMaterial.mMaterial->GetScaleFlags()); + texcanvas = systex->GetImage(layer->layerTexture, 0, layer->scaleFlags); mDrawCommands->SetTexture(i, texcanvas->GetPixels(), texcanvas->GetWidth(), texcanvas->GetHeight(), texcanvas->IsBgra()); } } diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index cf8f236ccc..d25ba485fd 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -106,7 +106,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) fbtex.reset(MakeGameTexture(new FWrapperTexture(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor()), nullptr, ETextureType::SWCanvas)); GetSystemTexture()->AllocateBuffer(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor() ? 4 : 1); auto mat = FMaterial::ValidateTexture(fbtex.get(), false); - mat->AddTextureLayer(PaletteTexture); + mat->AddTextureLayer(PaletteTexture, false); Canvas.reset(); Canvas.reset(new DCanvas(screen->GetWidth(), screen->GetHeight(), V_IsTrueColor())); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 21e41efa73..9f63054ae2 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -228,7 +228,7 @@ void VkRenderState::ApplyRenderPass(int dt) pipelineKey.StencilPassOp = mStencilOp; pipelineKey.ColorMask = mColorMask; pipelineKey.CullMode = mCullMode; - pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->GetLayers() : 0; + pipelineKey.NumTextureLayers = mMaterial.mMaterial ? mMaterial.mMaterial->NumLayers() : 0; pipelineKey.NumTextureLayers = std::max(pipelineKey.NumTextureLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS);// Always force minimum 8 textures as the shader requires it if (mSpecialEffect > EFF_NONE) { diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 6524d486ff..fa3a1a1270 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -647,18 +647,16 @@ void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; - // Textures that are already scaled in the texture lump will not get replaced by hires textures. - int flags = mat->GetScaleFlags(); - FTexture* layer; + MaterialLayerInfo* layer; auto systex = static_cast(mat->GetLayer(0, translation, &layer)); - systex->GetImage(layer, translation, flags); + systex->GetImage(layer->layerTexture, translation, layer->scaleFlags); - int numLayers = mat->GetLayers(); + int numLayers = mat->NumLayers(); for (int i = 1; i < numLayers; i++) { auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - systex->GetImage(layer, 0, flags); // fixme: Upscale flags must be disabled for certain layers. + systex->GetImage(layer->layerTexture, 0, layer->scaleFlags); } } diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index a20be08ac1..cf6aeaa45f 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -374,15 +374,12 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state) clampmode = base->GetClampMode(clampmode); - // Textures that are already scaled in the texture lump will not get replaced by hires textures. - int flags = GetScaleFlags(); - for (auto& set : mDescriptorSets) { if (set.descriptor && set.clampmode == clampmode && set.flags == translation) return set.descriptor.get(); } - int numLayers = GetLayers(); + int numLayers = NumLayers(); auto fb = GetVulkanFrameBuffer(); auto descriptor = fb->GetRenderPassManager()->AllocateTextureDescriptorSet(std::max(numLayers, SHADER_MIN_REQUIRED_TEXTURE_LAYERS)); @@ -392,14 +389,13 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state) VulkanSampler* sampler = fb->GetSamplerManager()->Get(clampmode); WriteDescriptors update; - FTexture* layer; + MaterialLayerInfo *layer; auto systex = static_cast(GetLayer(0, translation, &layer)); - update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer, translation, flags)->View.get(), sampler, systex->mImage.Layout); + update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, translation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); for (int i = 1; i < numLayers; i++) { auto systex = static_cast(GetLayer(i, 0, &layer)); - // fixme: Upscale flags must be disabled for certain layers. - update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer, 0, flags)->View.get(), sampler, systex->mImage.Layout); + update.addCombinedImageSampler(descriptor.get(), i, systex->GetImage(layer->layerTexture, 0, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); } auto dummyImage = fb->GetRenderPassManager()->GetNullTextureView(); From d4cc217d421a952471ebdffc34b6e6a99110392f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Apr 2020 12:40:30 +0200 Subject: [PATCH 063/220] - fixed a few things that slipped through --- src/rendering/gl/renderer/gl_renderstate.cpp | 2 +- src/rendering/hwrenderer/textures/hw_precache.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index 653daa4e7b..16dbedcbe7 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -325,7 +325,7 @@ void FGLRenderState::ApplyMaterial(FMaterial *mat, int clampmode, int translatio int numLayers = mat->NumLayers(); MaterialLayerInfo* layer; - auto base = static_cast(mat->GetLayer(0, translation)); + auto base = static_cast(mat->GetLayer(0, translation, &layer)); if (base->BindOrCreate(tex->GetTexture(), 0, clampmode, translation, layer->scaleFlags)) { diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 3b240372fc..e548d667be 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -97,7 +97,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl TArray layers; // First collect the potential max. texture set - for (unsigned i = 1; i < TexMan.NumTextures(); i++) + for (int i = 1; i < TexMan.NumTextures(); i++) { auto gametex = TexMan.GameByIndex(i); if (gametex && @@ -258,7 +258,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl // delete unused hardware textures (i.e. those which didn't get referenced by any material in the cache list.) decltype(allTextures)::Iterator ita(allTextures); decltype(allTextures)::Pair* paira; - while (it.NextPair(pair)) + while (ita.NextPair(paira)) { paira->Key->CleanUnused(); } From 88d5bf68770b5bfc113386b349bf63b5c5159460 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Apr 2020 19:03:25 +0200 Subject: [PATCH 064/220] - relax pointer substitution restriction for morphed monsters. --- src/playsim/p_mobj.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index 6945bc9a55..de0ff1b6b9 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -4943,9 +4943,12 @@ void StaticPointerSubstitution(AActor* old, AActor* notOld) if (old == nullptr) return; - // This is only allowed to replace players. For everything else the results are undefined. - if (!old->IsKindOf(NAME_PlayerPawn) || (notOld != nullptr && !notOld->IsKindOf(NAME_PlayerPawn))) return; - + // This is only allowed to replace players or swap out morphed monsters + if (!old->IsKindOf(NAME_PlayerPawn) || (notOld != nullptr && !notOld->IsKindOf(NAME_PlayerPawn))) + { + if (notOld == nullptr) return; + if (!old->IsKindOf(NAME_MorphedMonster) && !notOld->IsKindOf(NAME_MorphedMonster)) return; + } // Go through all objects. i = 0; DObject* last = 0; for (probe = GC::Root; probe != NULL; probe = probe->ObjNext) From 8dbc727178ae2db30a5dfeee907012a335d42ac9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Apr 2020 19:05:50 +0200 Subject: [PATCH 065/220] - fixed compile errors pointed out by CI --- src/common/textures/gametexture.h | 3 ++- src/rendering/swrenderer/plane/r_skyplane.cpp | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 652e6fbe12..e34ce09491 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -98,7 +98,8 @@ class FGameTexture int shaderindex = 0; int flags = 0; - uint8_t warped = 0, expandSprite = -1; + uint8_t warped = 0; + int8_t expandSprite = -1; uint16_t GlowHeight; PalEntry GlowColor = 0; diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 7279c906b5..3874257e40 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -63,7 +63,7 @@ namespace swrenderer { static FSoftwareTexture *GetSWTex(FTextureID texid, bool allownull = true) { - return GetPalettedSWTexture(texid, true, nullptr, true); + return GetPalettedSWTexture(texid, true, false, true); } RenderSkyPlane::RenderSkyPlane(RenderThread *thread) @@ -71,8 +71,8 @@ namespace swrenderer Thread = thread; auto Level = Thread->Viewport->Level(); - auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, nullptr, true); - auto sskytex2 = GetPalettedSWTexture(Level->skytexture2, true, nullptr, true); + auto sskytex1 = GetPalettedSWTexture(Level->skytexture1, true, false, true); + auto sskytex2 = GetPalettedSWTexture(Level->skytexture2, true, false, true); if (sskytex1 == nullptr) return; From b7ea4833232f0e24a0f4776080e1977a5d549f56 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Apr 2020 19:52:03 +0200 Subject: [PATCH 066/220] - fixed checkForHacks placement. --- src/common/textures/multipatchtexturebuilder.cpp | 4 +--- src/d_main.cpp | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 689330eb19..d95c681dcd 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -843,8 +843,6 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) i--; } } - - checkForHacks(buildinfo); } void FMultipatchTextureBuilder::ResolveAllPatches() @@ -891,6 +889,7 @@ void FMultipatchTextureBuilder::ResolveAllPatches() { // If this texture is just a wrapper around a single patch, we can simply // use that patch's image directly here. + checkForHacks(buildinfo); bool done = false; if (buildinfo.Parts.Size() == 1) @@ -912,7 +911,6 @@ void FMultipatchTextureBuilder::ResolveAllPatches() auto itex = new FImageTexture(img); AddImageToTexture(itex, buildinfo); } - BuiltTextures.Delete(i); donesomething = true; } diff --git a/src/d_main.cpp b/src/d_main.cpp index 1c95229517..da702fc677 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -112,6 +112,7 @@ #include "formats/multipatchtexture.h" #include "scriptutil.h" #include "v_palette.h" +#include "texturemanager.h" #ifdef __unix__ #include "i_system.h" // for SHARE_DIR @@ -2681,9 +2682,7 @@ static void CheckForHacks(BuildInfo& buildinfo) buildinfo.Parts.Size() == 1) { // This must alter the size of both the texture image and the game texture. - buildinfo.Height = buildinfo.Parts[0].TexImage->GetHeight(); - buildinfo.texture->GetTexture()->SetSize(buildinfo.texture->GetTexelWidth(), buildinfo.Height); - buildinfo.texture->SetSize(buildinfo.texture->GetTexelWidth(), buildinfo.Height); + buildinfo.Height = buildinfo.Parts[0].TexImage->GetImage()->GetHeight(); return; } From f2966602660e32a07ba8d7ac3380796acbc5c535 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 19 Apr 2020 21:07:57 +0200 Subject: [PATCH 067/220] - set all texture IDs after finishing the initial texture manager initialization. As it turned out, not all textures have a valid ID at that point so it needs to be redone. --- src/common/textures/texturemanager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 34483fc0c0..a94a1592aa 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -1184,6 +1184,13 @@ void FTextureManager::Init(void (*progressFunc_)(), void (*checkForHacks)(BuildI glPart = TexMan.CheckForTexture("glstuff/glpart.png", ETextureType::MiscPatch); mirrorTexture = TexMan.CheckForTexture("glstuff/mirror.png", ETextureType::MiscPatch); AddLocalizedVariants(); + + // Make sure all ID's are correct by resetting them here to the proper index. + for (unsigned int i = 0, count = Textures.Size(); i < count; ++i) + { + Textures[i].Texture->SetID(i); + } + } //========================================================================== From ce95d7379f6ca07858520d99b0128e4f1ccf4a24 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 21 Apr 2020 21:06:11 +0200 Subject: [PATCH 068/220] - swapped out the license in two files. BSD is preferred over LGPL --- src/common/engine/sc_man.cpp | 2 +- src/common/textures/image.cpp | 2 - src/rendering/gl/textures/gl_hwtexture.cpp | 55 +++++++++++---------- src/rendering/gl/textures/gl_samplers.cpp | 56 +++++++++++++--------- 4 files changed, 66 insertions(+), 49 deletions(-) diff --git a/src/common/engine/sc_man.cpp b/src/common/engine/sc_man.cpp index af5d5d1c2f..96c79538c8 100644 --- a/src/common/engine/sc_man.cpp +++ b/src/common/engine/sc_man.cpp @@ -1119,7 +1119,7 @@ void FScanner::CheckOpen() { if (ScriptOpen == false) { - I_FatalError ("SC_ call before SC_Open()."); + I_Error ("SC_ call before SC_Open()."); } } diff --git a/src/common/textures/image.cpp b/src/common/textures/image.cpp index d68db329d0..e70c76e398 100644 --- a/src/common/textures/image.cpp +++ b/src/common/textures/image.cpp @@ -175,10 +175,8 @@ int FImageSource::CopyPixels(FBitmap *bmp, int conversion) { if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source. PalEntry *palette = GPalette.BaseColors; - for(int i=1;i<256;i++) palette[i].a = 255; // set proper alpha values auto ppix = CreatePalettedPixels(conversion); bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, palette, nullptr); - for(int i=1;i<256;i++) palette[i].a = 0; return 0; } diff --git a/src/rendering/gl/textures/gl_hwtexture.cpp b/src/rendering/gl/textures/gl_hwtexture.cpp index c363d2fb7e..6b0cd9995a 100644 --- a/src/rendering/gl/textures/gl_hwtexture.cpp +++ b/src/rendering/gl/textures/gl_hwtexture.cpp @@ -1,28 +1,35 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2004-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* -** gltexture.cpp -** Low level OpenGL texture handling. These classes are also -** containers for the various translations a texture can have. +** gl_hwtexture.cpp +** GL texture abstraction +** +**--------------------------------------------------------------------------- +** Copyright 2019 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** ** */ diff --git a/src/rendering/gl/textures/gl_samplers.cpp b/src/rendering/gl/textures/gl_samplers.cpp index f4cdd60e74..7f4e9ef3e7 100644 --- a/src/rendering/gl/textures/gl_samplers.cpp +++ b/src/rendering/gl/textures/gl_samplers.cpp @@ -1,25 +1,37 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2014-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// - +/* +** gl_samplers.cpp +** +** Texture sampler handling +** +**--------------------------------------------------------------------------- +** Copyright 2015-2019 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ #include "gl_system.h" #include "c_cvars.h" From f17617706d5a65954857c9abf9b9c2f003c3de2e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 21 Apr 2020 21:23:04 +0200 Subject: [PATCH 069/220] - moved the scale overrider to v_draw.h. --- src/common/2d/v_draw.cpp | 6 +++++ src/common/2d/v_draw.h | 36 +++++++++++++++++++++++++++++ src/common/textures/animtexture.cpp | 12 +++++----- src/common/textures/animtexture.h | 4 ++-- src/intermission/intermission.cpp | 12 +++++----- src/menu/menu.cpp | 8 +++++-- src/rendering/v_video.cpp | 6 ----- src/rendering/v_video.h | 36 ----------------------------- src/wi_stuff.cpp | 6 ++--- 9 files changed, 65 insertions(+), 61 deletions(-) diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index a85f1ac8a2..bf33d6f6aa 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -1384,3 +1384,9 @@ void DrawFrame(F2DDrawer* twod, PalEntry color, int left, int top, int width, in twod->AddColorOnlyQuad(right, top - offset, offset, height + 2 * offset, color); } +void V_CalcCleanFacs(int designwidth, int designheight, int realwidth, int realheight, int* cleanx, int* cleany, int* _cx1, int* _cx2) +{ + if (designheight < 240 && realheight >= 480) designheight = 240; + *cleanx = *cleany = std::min(realwidth / designwidth, realheight / designheight); +} + diff --git a/src/common/2d/v_draw.h b/src/common/2d/v_draw.h index e42b6f3067..fe76272f5b 100644 --- a/src/common/2d/v_draw.h +++ b/src/common/2d/v_draw.h @@ -233,3 +233,39 @@ void VirtualToRealCoordsInt(F2DDrawer* drawer, int& x, int& y, int& w, int& h, i extern int CleanWidth, CleanHeight, CleanXfac, CleanYfac; extern int CleanWidth_1, CleanHeight_1, CleanXfac_1, CleanYfac_1; + +void V_CalcCleanFacs(int designwidth, int designheight, int realwidth, int realheight, int* cleanx, int* cleany, int* cx1 = NULL, int* cx2 = NULL); + +class ScaleOverrider +{ + int savedxfac, savedyfac, savedwidth, savedheight; + +public: + // This is to allow certain elements to use an optimal fullscreen scale which for the menu would be too large. + // The old code contained far too much mess to compensate for the menus which negatively affected everything else. + // However, for compatibility reasons the currently used variables cannot be changed so they have to be overridden temporarily. + // This class provides a safe interface for this because it ensures that the values get restored afterward. + // Currently, the intermission and the level summary screen use this. + ScaleOverrider(F2DDrawer *drawer) + { + savedxfac = CleanXfac; + savedyfac = CleanYfac; + savedwidth = CleanWidth; + savedheight = CleanHeight; + + if (drawer) + { + V_CalcCleanFacs(320, 200, drawer->GetWidth(), drawer->GetHeight(), &CleanXfac, &CleanYfac); + CleanWidth = drawer->GetWidth() / CleanXfac; + CleanHeight = drawer->GetHeight() / CleanYfac; + } + } + + ~ScaleOverrider() + { + CleanXfac = savedxfac; + CleanYfac = savedyfac; + CleanWidth = savedwidth; + CleanHeight = savedheight; + } +}; diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp index e1ebd1b6cc..a396244986 100644 --- a/src/common/textures/animtexture.cpp +++ b/src/common/textures/animtexture.cpp @@ -88,8 +88,8 @@ FBitmap AnimTexture::GetBgraBitmap(const PalEntry* remap, int* trans) AnimTextures::AnimTextures() { active = 1; - tex[0] = new AnimTexture; - tex[1] = new AnimTexture; + tex[0] = MakeGameTexture(new AnimTexture, "", ETextureType::Special); + tex[1] = MakeGameTexture(new AnimTexture, "", ETextureType::Special); } AnimTextures::~AnimTextures() @@ -100,17 +100,17 @@ AnimTextures::~AnimTextures() void AnimTextures::SetSize(int width, int height) { - tex[0]->SetFrameSize(width, height); - tex[1]->SetFrameSize(width, height); + static_cast(tex[0]->GetTexture())->SetFrameSize(width, height); + static_cast(tex[1]->GetTexture())->SetFrameSize(width, height); } void AnimTextures::SetFrame(const uint8_t *palette, const void* data) { active ^= 1; - tex[active]->SetFrame(palette, data); + static_cast(tex[active]->GetTexture())->SetFrame(palette, data); } -FTexture * AnimTextures::GetFrame() +FGameTexture * AnimTextures::GetFrame() { return tex[active]; } diff --git a/src/common/textures/animtexture.h b/src/common/textures/animtexture.h index 668671a9db..74414fee47 100644 --- a/src/common/textures/animtexture.h +++ b/src/common/textures/animtexture.h @@ -17,12 +17,12 @@ public: class AnimTextures { int active; - AnimTexture *tex[2]; + FGameTexture *tex[2]; public: AnimTextures(); ~AnimTextures(); void SetSize(int width, int height); void SetFrame(const uint8_t *palette, const void* data); - FTexture *GetFrame(); + FGameTexture *GetFrame(); }; diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index be331a3a14..e8b578b194 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -941,7 +941,7 @@ void DIntermissionController::OnDestroy () void F_StartIntermission(FIntermissionDescriptor *desc, bool deleteme, uint8_t state) { - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->Destroy(); @@ -987,7 +987,7 @@ void F_StartIntermission(FName seq, uint8_t state) bool F_Responder (event_t* ev) { - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); if (DIntermissionController::CurrentIntermission != NULL) { return DIntermissionController::CurrentIntermission->Responder(ev); @@ -1003,7 +1003,7 @@ bool F_Responder (event_t* ev) void F_Ticker () { - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->Ticker(); @@ -1018,7 +1018,7 @@ void F_Ticker () void F_Drawer () { - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->Drawer(); @@ -1034,7 +1034,7 @@ void F_Drawer () void F_EndFinale () { - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->Destroy(); @@ -1050,7 +1050,7 @@ void F_EndFinale () void F_AdvanceIntermission() { - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->mAdvance = true; diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 740c6f6764..4a4b15ae21 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -381,8 +381,12 @@ void M_StartControlPanel (bool makeSound, bool scaleoverride) } BackbuttonTime = 0; BackbuttonAlpha = 0; - if (scaleoverride && !CurrentScaleOverrider) CurrentScaleOverrider = new ScaleOverrider; - else if (!scaleoverride && CurrentScaleOverrider) delete CurrentScaleOverrider; + if (scaleoverride && !CurrentScaleOverrider) CurrentScaleOverrider = new ScaleOverrider(&screen->m2DDrawer); + else if (!scaleoverride && CurrentScaleOverrider) + { + delete CurrentScaleOverrider; + CurrentScaleOverrider = nullptr; + } } //============================================================================= diff --git a/src/rendering/v_video.cpp b/src/rendering/v_video.cpp index a4c59283e2..958486e30c 100644 --- a/src/rendering/v_video.cpp +++ b/src/rendering/v_video.cpp @@ -336,12 +336,6 @@ void V_OutputResized (int width, int height) primaryLevel->automap->NewResolution(); } -void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *_cx1, int *_cx2) -{ - if (designheight < 240 && realheight >= 480) designheight = 240; - *cleanx = *cleany = std::min(realwidth / designwidth, realheight / designheight); -} - bool IVideo::SetResolution () { DFrameBuffer *buff = CreateFrameBuffer(); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 29affa2510..cdfbb75941 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -117,7 +117,6 @@ extern int DisplayWidth, DisplayHeight; void V_UpdateModeSize (int width, int height); void V_OutputResized (int width, int height); -void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany, int *cx1=NULL, int *cx2=NULL); EXTERN_CVAR(Int, vid_rendermode) EXTERN_CVAR(Bool, vid_fullscreen) @@ -193,8 +192,6 @@ public: private: int Width = 0; int Height = 0; -public: - //int clipleft = 0, cliptop = 0, clipwidth = -1, clipheight = -1; public: // Hardware render state that needs to be exposed to the API independent part of the renderer. For ease of access this is stored in the base class. @@ -385,39 +382,6 @@ inline bool IsRatioWidescreen(int ratio) { return (ratio & 3) != 0; } #include "v_draw.h" -class ScaleOverrider -{ - int savedxfac, savedyfac, savedwidth, savedheight; - -public: - // This is to allow certain elements to use an optimal fullscreen scale which for the menu would be too large. - // The old code contained far too much mess to compensate for the menus which negatively affected everything else. - // However, for compatibility reasons the currently used variables cannot be changed so they have to be overridden temporarily. - // This class provides a safe interface for this because it ensures that the values get restored afterward. - // Currently, the intermission and the level summary screen use this. - ScaleOverrider() - { - savedxfac = CleanXfac; - savedyfac = CleanYfac; - savedwidth = CleanWidth; - savedheight = CleanHeight; - - if (screen) - { - V_CalcCleanFacs(320, 200, screen->GetWidth(), screen->GetHeight(), &CleanXfac, &CleanYfac); - CleanWidth = screen->GetWidth() / CleanXfac; - CleanHeight = screen->GetHeight() / CleanYfac; - } - } - - ~ScaleOverrider() - { - CleanXfac = savedxfac; - CleanYfac = savedyfac; - CleanWidth = savedwidth; - CleanHeight = savedheight; - } -}; #endif // __V_VIDEO_H__ diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index 4334d170d9..2050683e47 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -701,7 +701,7 @@ void WI_Ticker() { if (WI_Screen) { - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Ticker) { VMValue self = WI_Screen; @@ -721,7 +721,7 @@ void WI_Drawer() { if (WI_Screen) { - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Drawer) { FillBorder(twod, nullptr); @@ -765,7 +765,7 @@ void WI_Start(wbstartstruct_t *wbstartstruct) } WI_Screen = cls->CreateNew(); - ScaleOverrider s; + ScaleOverrider s(&screen->m2DDrawer); IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Start) { VMValue val[2] = { WI_Screen, wbstartstruct }; From a40578a0a426f589381d43e3d18b064ab4eb1140 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 21 Apr 2020 22:11:59 +0200 Subject: [PATCH 070/220] - changed more license headers to BSD. --- .../hwrenderer/data/flatvertices.cpp | 51 +++++++++++-------- .../hwrenderer/utility/hw_shaderpatcher.cpp | 51 +++++++++++-------- 2 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/rendering/hwrenderer/data/flatvertices.cpp b/src/rendering/hwrenderer/data/flatvertices.cpp index 2d956e5e2b..50d9c1ebd9 100644 --- a/src/rendering/hwrenderer/data/flatvertices.cpp +++ b/src/rendering/hwrenderer/data/flatvertices.cpp @@ -1,29 +1,36 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2005-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* ** hw_flatvertices.cpp ** Creates flat vertex data for hardware rendering. ** -**/ +**--------------------------------------------------------------------------- +** Copyright 2010-2020 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ #include "doomtype.h" #include "p_local.h" diff --git a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp index 626d53494f..53fc73a57d 100644 --- a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp +++ b/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp @@ -1,29 +1,36 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2004-2018 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* ** hw_shaderpatcher.cpp -** ** Modifies shader source to account for different syntax versions or engine changes. ** +**--------------------------------------------------------------------------- +** Copyright(C) 2004-2018 Christoph Oelckers +** Copyright(C) 2016-2018 Magnus Norddahl +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** */ From 12e69adec30ce34e58056f6778f1d53cb49c5f98 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 19:57:14 +0200 Subject: [PATCH 071/220] - system backend cleanup. This is mainly for running CI on Linux and macOS. Windws is already working. --- CMakeLists.txt | 8 +- src/common/audio/sound/i_sound.cpp | 1 + src/common/audio/sound/i_soundinternal.h | 3 +- src/common/engine/i_interface.h | 2 + src/common/engine/i_specialpaths.h | 22 ++++++ src/common/engine/startupinfo.h | 24 ++++++ src/d_iwad.cpp | 12 +-- src/d_main.cpp | 97 +++++++++++++++++++----- src/d_main.h | 24 +----- src/g_level.cpp | 2 +- src/g_level.h | 4 +- src/m_misc.h | 19 +---- src/menu/menu.cpp | 20 ++--- src/menu/menu.h | 8 +- src/menu/menudef.cpp | 4 +- src/posix/cocoa/i_input.mm | 30 +++----- src/posix/cocoa/i_joystick.cpp | 3 +- src/posix/cocoa/i_main.mm | 9 +-- src/posix/cocoa/i_system.mm | 1 + src/posix/cocoa/i_video.mm | 17 ++++- src/posix/cocoa/st_console.mm | 17 +++-- src/posix/cocoa/st_start.mm | 3 +- src/posix/osx/i_specialpaths.mm | 45 ++++++++++- src/posix/osx/iwadpicker_cocoa.mm | 8 +- src/posix/sdl/hardware.cpp | 5 +- src/posix/sdl/i_gui.cpp | 1 - src/posix/sdl/i_input.cpp | 34 ++------- src/posix/sdl/i_joystick.cpp | 1 + src/posix/sdl/i_main.cpp | 71 ++--------------- src/posix/sdl/i_system.cpp | 72 ++++++++++++------ src/posix/sdl/sdlglvideo.cpp | 41 +++++++--- src/posix/sdl/st_start.cpp | 1 - src/posix/unix/gtk_dialogs.cpp | 3 +- src/sound/s_doomsound.h | 1 - src/win32/hardware.cpp | 10 ++- src/win32/i_input.cpp | 5 +- src/win32/i_main.cpp | 72 +++--------------- src/win32/i_mouse.cpp | 3 +- src/win32/i_specialpaths.cpp | 1 + src/win32/i_system.cpp | 17 +++-- src/win32/i_system.h | 25 ------ src/win32/st_start.cpp | 14 ++-- src/win32/st_start_util.cpp | 4 +- src/win32/win32glvideo.cpp | 1 + 44 files changed, 384 insertions(+), 381 deletions(-) create mode 100644 src/common/engine/i_specialpaths.h create mode 100644 src/common/engine/startupinfo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f3d10f78e9..d574b999cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,9 +203,9 @@ if( MSVC ) # Function-level linking # Disable run-time type information if ( HAVE_VULKAN ) - set( ALL_C_FLAGS "/GF /Gy /permissive- /DHAVE_VULKAN" ) + set( ALL_C_FLAGS "/GF /Gy /permissive- /DHAVE_VULKAN /D_HAVE_SOFTPOLY" ) else() - set( ALL_C_FLAGS "/GF /Gy /permissive-" ) + set( ALL_C_FLAGS "/GF /Gy /permissive- /D_HAVE_SOFTPOLY" ) endif() # Use SSE 2 as minimum always as the true color drawers needs it for __vectorcall @@ -241,9 +241,9 @@ if( MSVC ) else() set( REL_LINKER_FLAGS "" ) if ( HAVE_VULKAN ) - set( ALL_C_FLAGS "-ffp-contract=off -DHAVE_VULKAN" ) + set( ALL_C_FLAGS "-ffp-contract=off -DHAVE_VULKAN -D_HAVE_SOFTPOLY" ) else() - set( ALL_C_FLAGS "-ffp-contract=off" ) + set( ALL_C_FLAGS "-ffp-contract=off -D_HAVE_SOFTPOLY" ) endif() if ( UNIX ) diff --git a/src/common/audio/sound/i_sound.cpp b/src/common/audio/sound/i_sound.cpp index 74290c4ab7..209f58a475 100644 --- a/src/common/audio/sound/i_sound.cpp +++ b/src/common/audio/sound/i_sound.cpp @@ -486,3 +486,4 @@ SoundHandle SoundRenderer::LoadSoundVoc(uint8_t *sfxdata, int length) if (data) delete[] data; return retval; } + diff --git a/src/common/audio/sound/i_soundinternal.h b/src/common/audio/sound/i_soundinternal.h index 039e308d7c..36ccd52c0d 100644 --- a/src/common/audio/sound/i_soundinternal.h +++ b/src/common/audio/sound/i_soundinternal.h @@ -144,7 +144,6 @@ struct FISoundChannel class SoundStream; - - +void S_SetSoundPaused(int state); #endif diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index 0199f97ea4..ff26d18a80 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -8,6 +8,8 @@ struct SystemCallbacks bool (*NetGame)(); bool (*WantNativeMouse)(); bool (*CaptureModeInGame)(); + void (*CrashInfo)(char* buffer, size_t bufflen, const char* lfstr); + }; extern SystemCallbacks *sysCallbacks; diff --git a/src/common/engine/i_specialpaths.h b/src/common/engine/i_specialpaths.h new file mode 100644 index 0000000000..4d61bc3d7c --- /dev/null +++ b/src/common/engine/i_specialpaths.h @@ -0,0 +1,22 @@ +#pragma once + +#include "zstring.h" + +#ifdef __unix__ +FString GetUserFile (const char *path); +#endif +FString M_GetAppDataPath(bool create); +FString M_GetCachePath(bool create); +FString M_GetAutoexecPath(); +FString M_GetConfigPath(bool for_reading); +FString M_GetScreenshotsPath(); +FString M_GetSavegamesPath(); +FString M_GetDocumentsPath(); +FString M_GetDemoPath(); + +FString M_GetNormalizedPath(const char* path); + +#ifdef __APPLE__ +FString M_GetMacAppSupportPath(const bool create = true); +void M_GetMacSearchDirectories(FString& user_docs, FString& user_app_support, FString& local_app_support); +#endif // __APPLE__ diff --git a/src/common/engine/startupinfo.h b/src/common/engine/startupinfo.h new file mode 100644 index 0000000000..cbabba4004 --- /dev/null +++ b/src/common/engine/startupinfo.h @@ -0,0 +1,24 @@ +#pragma once + +struct FStartupInfo +{ + FString Name; + uint32_t FgColor; // Foreground color for title banner + uint32_t BkColor; // Background color for title banner + FString Song; + int Type; + int LoadLights = -1; + int LoadBrightmaps = -1; + enum + { + DefaultStartup, + DoomStartup, + HereticStartup, + HexenStartup, + StrifeStartup, + }; +}; + + +extern FStartupInfo GameStartupInfo; + diff --git a/src/d_iwad.cpp b/src/d_iwad.cpp index a4876ac107..ddbb853d8a 100644 --- a/src/d_iwad.cpp +++ b/src/d_iwad.cpp @@ -791,14 +791,14 @@ const FIWADInfo *FIWadManager::FindIWAD(TArray &wadfiles, const char *i if (iwadType == -1) return nullptr; //gameiwad = iwadType; const FIWADInfo *iwad_info = &mIWadInfos[iwadType]; - if (DoomStartupInfo.Name.IsEmpty()) DoomStartupInfo.Name = iwad_info->Name; - if (DoomStartupInfo.BkColor == 0 && DoomStartupInfo.FgColor == 0) + if (GameStartupInfo.Name.IsEmpty()) GameStartupInfo.Name = iwad_info->Name; + if (GameStartupInfo.BkColor == 0 && GameStartupInfo.FgColor == 0) { - DoomStartupInfo.BkColor = iwad_info->BkColor; - DoomStartupInfo.FgColor = iwad_info->FgColor; + GameStartupInfo.BkColor = iwad_info->BkColor; + GameStartupInfo.FgColor = iwad_info->FgColor; } - if (DoomStartupInfo.Type == 0) DoomStartupInfo.Type = iwad_info->StartupType; - if (DoomStartupInfo.Song.IsEmpty()) DoomStartupInfo.Song = iwad_info->Song; + if (GameStartupInfo.Type == 0) GameStartupInfo.Type = iwad_info->StartupType; + if (GameStartupInfo.Song.IsEmpty()) GameStartupInfo.Song = iwad_info->Song; I_SetIWADInfo(); return iwad_info; } diff --git a/src/d_main.cpp b/src/d_main.cpp index da702fc677..0720aaddee 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -279,7 +279,7 @@ FGameTexture *Advisory; FTextureID Page; const char *Subtitle; bool nospriterename; -FStartupInfo DoomStartupInfo; +FStartupInfo GameStartupInfo; FString lastIWAD; int restart = 0; bool batchrun; // just run the startup and collect all error messages in a logfile, then quit without any interaction @@ -1795,44 +1795,44 @@ static FString ParseGameInfo(TArray &pwads, const char *fn, const char else if (!nextKey.CompareNoCase("STARTUPTITLE")) { sc.MustGetString(); - DoomStartupInfo.Name = sc.String; + GameStartupInfo.Name = sc.String; } else if (!nextKey.CompareNoCase("STARTUPCOLORS")) { sc.MustGetString(); - DoomStartupInfo.FgColor = V_GetColor(NULL, sc); + GameStartupInfo.FgColor = V_GetColor(NULL, sc); sc.MustGetStringName(","); sc.MustGetString(); - DoomStartupInfo.BkColor = V_GetColor(NULL, sc); + GameStartupInfo.BkColor = V_GetColor(NULL, sc); } else if (!nextKey.CompareNoCase("STARTUPTYPE")) { sc.MustGetString(); FString sttype = sc.String; if (!sttype.CompareNoCase("DOOM")) - DoomStartupInfo.Type = FStartupInfo::DoomStartup; + GameStartupInfo.Type = FStartupInfo::DoomStartup; else if (!sttype.CompareNoCase("HERETIC")) - DoomStartupInfo.Type = FStartupInfo::HereticStartup; + GameStartupInfo.Type = FStartupInfo::HereticStartup; else if (!sttype.CompareNoCase("HEXEN")) - DoomStartupInfo.Type = FStartupInfo::HexenStartup; + GameStartupInfo.Type = FStartupInfo::HexenStartup; else if (!sttype.CompareNoCase("STRIFE")) - DoomStartupInfo.Type = FStartupInfo::StrifeStartup; - else DoomStartupInfo.Type = FStartupInfo::DefaultStartup; + GameStartupInfo.Type = FStartupInfo::StrifeStartup; + else GameStartupInfo.Type = FStartupInfo::DefaultStartup; } else if (!nextKey.CompareNoCase("STARTUPSONG")) { sc.MustGetString(); - DoomStartupInfo.Song = sc.String; + GameStartupInfo.Song = sc.String; } else if (!nextKey.CompareNoCase("LOADLIGHTS")) { sc.MustGetNumber(); - DoomStartupInfo.LoadLights = !!sc.Number; + GameStartupInfo.LoadLights = !!sc.Number; } else if (!nextKey.CompareNoCase("LOADBRIGHTMAPS")) { sc.MustGetNumber(); - DoomStartupInfo.LoadBrightmaps = !!sc.Number; + GameStartupInfo.LoadBrightmaps = !!sc.Number; } else { @@ -1956,13 +1956,13 @@ static void AddAutoloadFiles(const char *autoname) // [SP] Dialog reaction - load lights.pk3 and brightmaps.pk3 based on user choices if (!(gameinfo.flags & GI_SHAREWARE)) { - if (DoomStartupInfo.LoadLights == 1 || (DoomStartupInfo.LoadLights != 0 && autoloadlights)) + if (GameStartupInfo.LoadLights == 1 || (GameStartupInfo.LoadLights != 0 && autoloadlights)) { const char *lightswad = BaseFileSearch ("lights.pk3", NULL, false, GameConfig); if (lightswad) D_AddFile (allwads, lightswad, true, -1, GameConfig); } - if (DoomStartupInfo.LoadBrightmaps == 1 || (DoomStartupInfo.LoadBrightmaps != 0 && autoloadbrightmaps)) + if (GameStartupInfo.LoadBrightmaps == 1 || (GameStartupInfo.LoadBrightmaps != 0 && autoloadbrightmaps)) { const char *bmwad = BaseFileSearch ("brightmaps.pk3", NULL, false, GameConfig); if (bmwad) @@ -2627,6 +2627,7 @@ bool System_WantNativeMouse() static bool System_CaptureModeInGame() { + if (demoplayback || paused) return false; switch (mouse_capturemode) { default: @@ -2639,6 +2640,59 @@ static bool System_CaptureModeInGame() } } +//========================================================================== +// +// DoomSpecificInfo +// +// Called by the crash logger to get application-specific information. +// +//========================================================================== + +void System_CrashInfo(char* buffer, size_t bufflen, const char *lfstr) +{ + const char* arg; + char* const buffend = buffer + bufflen - 2; // -2 for CRLF at end + int i; + + buffer += mysnprintf(buffer, buffend - buffer, GAMENAME " version %s (%s)", GetVersionString(), GetGitHash()); + + buffer += snprintf(buffer, buffend - buffer, "%sCommand line:", lfstr); + for (i = 0; i < Args->NumArgs(); ++i) + { + buffer += snprintf(buffer, buffend - buffer, " %s", Args->GetArg(i)); + } + + for (i = 0; (arg = fileSystem.GetResourceFileName(i)) != NULL; ++i) + { + buffer += mysnprintf(buffer, buffend - buffer, "%sWad %d: %s", lfstr, i, arg); + } + + if (gamestate != GS_LEVEL && gamestate != GS_TITLELEVEL) + { + buffer += mysnprintf(buffer, buffend - buffer, "%s%sNot in a level.", lfstr, lfstr); + } + else + { + buffer += mysnprintf(buffer, buffend - buffer, "%s%sCurrent map: %s", lfstr, lfstr, primaryLevel->MapName.GetChars()); + + if (!viewactive) + { + buffer += mysnprintf(buffer, buffend - buffer, "%s%sView not active.", lfstr, lfstr); + } + else + { + auto& vp = r_viewpoint; + buffer += mysnprintf(buffer, buffend - buffer, "%s%sviewx = %f", lfstr, lfstr, vp.Pos.X); + buffer += mysnprintf(buffer, buffend - buffer, "%sviewy = %f", lfstr, vp.Pos.Y); + buffer += mysnprintf(buffer, buffend - buffer, "%sviewz = %f", lfstr, vp.Pos.Z); + buffer += mysnprintf(buffer, buffend - buffer, "%sviewangle = %f", lfstr, vp.Angles.Yaw); + } + } + buffer += mysnprintf(buffer, buffend - buffer, "%s", lfstr); + *buffer = 0; +} + + static void PatchTextures() { @@ -2788,6 +2842,7 @@ static int D_DoomMain_Internal (void) System_NetGame, System_WantNativeMouse, System_CaptureModeInGame, + System_CrashInfo, }; sysCallbacks = &syscb; @@ -3323,7 +3378,7 @@ static int D_DoomMain_Internal (void) void I_ShowFatalError(const char* message); -int D_DoomMain() +int GameMain() { int ret = 0; GameTicRate = TICRATE; @@ -3406,10 +3461,10 @@ void D_Cleanup() TexAnim.DeleteAll(); TexMan.DeleteAll(); - // delete DoomStartupInfo data - DoomStartupInfo.Name = ""; - DoomStartupInfo.BkColor = DoomStartupInfo.FgColor = DoomStartupInfo.Type = 0; - DoomStartupInfo.LoadLights = DoomStartupInfo.LoadBrightmaps = -1; + // delete GameStartupInfo data + GameStartupInfo.Name = ""; + GameStartupInfo.BkColor = GameStartupInfo.FgColor = GameStartupInfo.Type = 0; + GameStartupInfo.LoadLights = GameStartupInfo.LoadBrightmaps = -1; GC::FullGC(); // clean up before taking down the object list. @@ -3566,12 +3621,12 @@ void I_UpdateWindowTitle() if (level.LevelName && level.LevelName.GetChars()[0]) { FString titlestr; - titlestr.Format("%s - %s", level.LevelName.GetChars(), DoomStartupInfo.Name.GetChars()); + titlestr.Format("%s - %s", level.LevelName.GetChars(), GameStartupInfo.Name.GetChars()); I_SetWindowTitle(titlestr.GetChars()); break; } case 2: - I_SetWindowTitle(DoomStartupInfo.Name.GetChars()); + I_SetWindowTitle(GameStartupInfo.Name.GetChars()); break; default: I_SetWindowTitle(NULL); diff --git a/src/d_main.h b/src/d_main.h index 5d6324ba2a..92691c8375 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -30,6 +30,7 @@ #include "doomtype.h" #include "gametype.h" +#include "startupinfo.h" struct event_t; @@ -45,8 +46,6 @@ struct CRestartException char dummy; }; -int D_DoomMain (void); - void D_Display (); @@ -73,25 +72,6 @@ struct WadStuff FString Name; }; -struct FStartupInfo -{ - FString Name; - uint32_t FgColor; // Foreground color for title banner - uint32_t BkColor; // Background color for title banner - FString Song; - int Type; - int LoadLights = -1; - int LoadBrightmaps = -1; - enum - { - DefaultStartup, - DoomStartup, - HereticStartup, - HexenStartup, - StrifeStartup, - }; -}; - struct FIWADInfo { FString Name; // Title banner text for this IWAD @@ -126,8 +106,6 @@ struct FFoundWadInfo } }; -extern FStartupInfo DoomStartupInfo; - //========================================================================== // // IWAD identifier class diff --git a/src/g_level.cpp b/src/g_level.cpp index ac0d2bad9b..ddb8ebbcd4 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -196,7 +196,7 @@ void G_DeferedInitNew (const char *mapname, int newskill) gameaction = ga_newgame2; } -void G_DeferedInitNew (FGameStartup *gs) +void G_DeferedInitNew (FNewGameStartup *gs) { if (gs->PlayerClass != NULL) playerclass = gs->PlayerClass; d_mapname = AllEpisodes[gs->Episode].mEpisodeMap; diff --git a/src/g_level.h b/src/g_level.h index 620622e4d4..75a0aab564 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -15,8 +15,8 @@ void G_InitNew (const char *mapname, bool bTitleLevel); // A normal game starts at map 1, // but a warp test can start elsewhere void G_DeferedInitNew (const char *mapname, int skill = -1); -struct FGameStartup; -void G_DeferedInitNew (FGameStartup *gs); +struct FNewGameStartup; +void G_DeferedInitNew (FNewGameStartup *gs); enum { diff --git a/src/m_misc.h b/src/m_misc.h index e135398b33..4de7eb5ad9 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -44,23 +44,6 @@ void M_LoadDefaults (); bool M_SaveDefaults (const char *filename); void M_SaveCustomKeys (FConfigFile *config, char *section, char *subsection, size_t sublen); -// Get special directory paths (defined in m_specialpaths.cpp) - -#ifdef __unix__ -FString GetUserFile (const char *path); // Prepends ~/.zdoom to path -#endif -FString M_GetAppDataPath(bool create); -FString M_GetCachePath(bool create); -FString M_GetAutoexecPath(); -FString M_GetCajunPath(const char *filename); -FString M_GetConfigPath(bool for_reading); -FString M_GetScreenshotsPath(); -FString M_GetSavegamesPath(); -FString M_GetDocumentsPath(); - -#ifdef __APPLE__ -FString M_GetMacAppSupportPath(const bool create = true); -void M_GetMacSearchDirectories(FString& user_docs, FString& user_app_support, FString& local_app_support); -#endif // __APPLE__ +#include "i_specialpaths.h" #endif diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 4a4b15ae21..5700e6ccb2 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -107,7 +107,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DMenu, MenuTime, GetMenuTime) ACTION_RETURN_INT(MenuTime); } -FGameStartup GameStartupInfo; +FNewGameStartup NewGameStartupInfo; EMenuState menuactive; bool M_DemoNoPlay; FButtonStatus MenuButtons[NUM_MKEYS]; @@ -461,12 +461,12 @@ void M_SetMenu(FName menu, int param) break; case NAME_Episodemenu: // sent from the player class menu - GameStartupInfo.Skill = -1; - GameStartupInfo.Episode = -1; - GameStartupInfo.PlayerClass = + NewGameStartupInfo.Skill = -1; + NewGameStartupInfo.Episode = -1; + NewGameStartupInfo.PlayerClass = param == -1000? nullptr : param == -1? "Random" : GetPrintableDisplayName(PlayerClasses[param].Type).GetChars(); - M_StartupEpisodeMenu(&GameStartupInfo); // needs player class name from class menu (later) + M_StartupEpisodeMenu(&NewGameStartupInfo); // needs player class name from class menu (later) break; case NAME_Skillmenu: @@ -479,14 +479,14 @@ void M_SetMenu(FName menu, int param) return; } - GameStartupInfo.Episode = param; - M_StartupSkillMenu(&GameStartupInfo); // needs player class name from class menu (later) + NewGameStartupInfo.Episode = param; + M_StartupSkillMenu(&NewGameStartupInfo); // needs player class name from class menu (later) break; case NAME_StartgameConfirm: { // sent from the skill menu for a skill that needs to be confirmed - GameStartupInfo.Skill = param; + NewGameStartupInfo.Skill = param; const char *msg = AllSkills[param].MustConfirmText; if (*msg==0) msg = GStrings("NIGHTMARE"); @@ -497,10 +497,10 @@ void M_SetMenu(FName menu, int param) case NAME_Startgame: // sent either from skill menu or confirmation screen. Skill gets only set if sent from skill menu // Now we can finally start the game. Ugh... - GameStartupInfo.Skill = param; + NewGameStartupInfo.Skill = param; case NAME_StartgameConfirmed: - G_DeferedInitNew (&GameStartupInfo); + G_DeferedInitNew (&NewGameStartupInfo); if (gamestate == GS_FULLCONSOLE) { gamestate = GS_HIDECONSOLE; diff --git a/src/menu/menu.h b/src/menu/menu.h index c913cd2f2d..f6f4fe9e0b 100644 --- a/src/menu/menu.h +++ b/src/menu/menu.h @@ -47,14 +47,14 @@ enum EMenuKey }; -struct FGameStartup +struct FNewGameStartup { const char *PlayerClass; int Episode; int Skill; }; -extern FGameStartup GameStartupInfo; +extern FNewGameStartup NewGameStartupInfo; struct FSaveGameNode { @@ -345,8 +345,8 @@ void M_ActivateMenu(DMenu *menu); void M_ClearMenus (); void M_PreviousMenu (); void M_ParseMenuDefs(); -void M_StartupEpisodeMenu(FGameStartup *gs); -void M_StartupSkillMenu(FGameStartup *gs); +void M_StartupEpisodeMenu(FNewGameStartup *gs); +void M_StartupSkillMenu(FNewGameStartup *gs); void M_StartControlPanel (bool makeSound, bool scaleoverride = false); void M_SetMenu(FName menu, int param = -1); void M_StartMessage(const char *message, int messagemode, FName action = NAME_None); diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index 8289fda585..db8d29a08c 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -1113,7 +1113,7 @@ void M_ParseMenuDefs() // //============================================================================= -void M_StartupEpisodeMenu(FGameStartup *gs) +void M_StartupEpisodeMenu(FNewGameStartup *gs) { // Build episode menu bool success = false; @@ -1670,7 +1670,7 @@ DEFINE_ACTION_FUNCTION(DMenu, UpdateSkinOptions) //============================================================================= extern int restart; -void M_StartupSkillMenu(FGameStartup *gs) +void M_StartupSkillMenu(FNewGameStartup *gs) { static int done = -1; bool success = false; diff --git a/src/posix/cocoa/i_input.mm b/src/posix/cocoa/i_input.mm index 20725fbda0..87199d8b68 100644 --- a/src/posix/cocoa/i_input.mm +++ b/src/posix/cocoa/i_input.mm @@ -35,19 +35,14 @@ #import -#include "c_buttons.h" #include "c_console.h" #include "c_cvars.h" #include "c_dispatch.h" #include "d_event.h" +#include "c_buttons.h" #include "d_gui.h" #include "dikeys.h" -#include "doomdef.h" -#include "doomstat.h" #include "v_video.h" -#include "events.h" -#include "g_game.h" -#include "g_levellocals.h" #include "i_interface.h" @@ -61,7 +56,7 @@ CVAR(Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) extern int paused, chatmodeon; extern constate_e ConsoleState; - +extern bool ToggleFullscreen; bool GUICapture; @@ -77,22 +72,17 @@ size_t s_skipMouseMoves; void CheckGUICapture() { - bool wantCapture = (MENU_Off == menuactive) - ? (c_down == ConsoleState || c_falling == ConsoleState || chatmodeon) - : (MENU_On == menuactive || MENU_OnNoPause == menuactive); + bool wantCapt = sysCallbacks && sysCallbacks->WantGuiCapture && sysCallbacks->WantGuiCapture(); - // [ZZ] check active event handlers that want the UI processing - if (!wantCapture && primaryLevel->localEventManager->CheckUiProcessors()) + if (wantCapt != GUICapture) { - wantCapture = true; + GUICapture = wantCapt; + if (wantCapt && Keyboard != NULL) + { + buttonMap.ResetButtonStates(); + } } - if (wantCapture != GUICapture) - { - GUICapture = wantCapture; - - buttonMap.ResetButtonStates(); - } } void SetCursorPosition(const NSPoint position) @@ -160,7 +150,7 @@ void CheckNativeMouse() { bool captureModeInGame = sysCallbacks && sysCallbacks->CaptureModeInGame && sysCallbacks->CaptureModeInGame(); wantNative = (!m_use_mouse || MENU_WaitKey != menuactive) - && (!captureModeInGame || GUICapture || paused || demoplayback); + && (!captureModeInGame || GUICapture); } } else diff --git a/src/posix/cocoa/i_joystick.cpp b/src/posix/cocoa/i_joystick.cpp index bebf43b423..d7d7587ac9 100644 --- a/src/posix/cocoa/i_joystick.cpp +++ b/src/posix/cocoa/i_joystick.cpp @@ -36,12 +36,13 @@ #include #include "d_event.h" -#include "doomdef.h" #include "i_system.h" #include "m_argv.h" #include "m_joy.h" #include "templates.h" #include "v_text.h" +#include "printf.h" +#include "keydef.h" EXTERN_CVAR(Bool, joy_axespolling) diff --git a/src/posix/cocoa/i_main.mm b/src/posix/cocoa/i_main.mm index 5f77b58578..071ab34d37 100644 --- a/src/posix/cocoa/i_main.mm +++ b/src/posix/cocoa/i_main.mm @@ -32,19 +32,18 @@ */ #include "i_common.h" -#include "s_sound.h" +#include "s_soundinternal.h" #include #include "c_console.h" #include "c_cvars.h" #include "cmdlib.h" -#include "d_main.h" #include "i_system.h" #include "m_argv.h" #include "st_console.h" #include "version.h" -#include "engineerrors.h" +#include "printf.h" #include "s_music.h" @@ -59,7 +58,7 @@ EXTERN_CVAR(Int, vid_defwidth ) EXTERN_CVAR(Int, vid_defheight) EXTERN_CVAR(Bool, vid_vsync ) - +int GameMain(); // --------------------------------------------------------------------------- @@ -169,7 +168,7 @@ int DoMain(int argc, char** argv) progdir = [[exePath stringByDeletingLastPathComponent] UTF8String]; progdir += "/"; - auto ret = D_DoomMain(); + auto ret = GameMain(); FConsoleWindow::DeleteInstance(); return ret; } diff --git a/src/posix/cocoa/i_system.mm b/src/posix/cocoa/i_system.mm index 87ab877f7a..76a38cbcf7 100644 --- a/src/posix/cocoa/i_system.mm +++ b/src/posix/cocoa/i_system.mm @@ -33,6 +33,7 @@ #include "i_common.h" +#include #include #include "i_system.h" diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 824b429041..6cf35313e3 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -44,21 +44,24 @@ #include "v_video.h" #include "bitmap.h" #include "c_dispatch.h" -#include "doomstat.h" #include "hardware.h" #include "i_system.h" #include "m_argv.h" #include "m_png.h" -#include "swrenderer/r_swrenderer.h" #include "st_console.h" #include "v_text.h" #include "version.h" -#include "engineerrors.h" +#include "printf.h" #include "gl/system/gl_framebuffer.h" +#ifdef HAVE_VULKAN #include "vulkan/system/vk_framebuffer.h" +#endif +#ifdef HAVE_SOFTPOLY #include "rendering/polyrenderer/backend/poly_framebuffer.h" +#endif +extern bool ToggleFullscreen; @implementation NSWindow(ExitAppOnClose) @@ -441,6 +444,8 @@ public: } else #endif + +#ifdef HAVE_SOFTPOLY if (vid_preferbackend == 2) { SetupOpenGLView(ms_window, OpenGLProfile::Legacy); @@ -448,6 +453,7 @@ public: fb = new PolyFrameBuffer(nullptr, vid_fullscreen); } else +#endif { SetupOpenGLView(ms_window, OpenGLProfile::Core); } @@ -461,6 +467,7 @@ public: fb->SetMode(vid_fullscreen, vid_hidpi); fb->SetSize(fb->GetClientWidth(), fb->GetClientHeight()); +#ifdef HAVE_VULKAN // This lame hack is a temporary workaround for strange performance issues // with fullscreen window and Core Animation's Metal layer // It is somehow related to initial window level and flags @@ -470,6 +477,7 @@ public: fb->SetMode(false, vid_hidpi); fb->SetMode(true, vid_hidpi); } +#endif return fb; } @@ -480,8 +488,9 @@ public: } private: +#ifdef HAVE_VULKAN VulkanDevice *m_vulkanDevice = nullptr; - +#endif static CocoaWindow* ms_window; static bool ms_isVulkanEnabled; diff --git a/src/posix/cocoa/st_console.mm b/src/posix/cocoa/st_console.mm index cd8dd2ea00..6212079e2e 100644 --- a/src/posix/cocoa/st_console.mm +++ b/src/posix/cocoa/st_console.mm @@ -32,12 +32,13 @@ */ #include "i_common.h" - -#include "d_main.h" +#include "startupinfo.h" #include "st_console.h" #include "v_text.h" #include "version.h" - +#include "palentry.h" +#include "v_video.h" +#include "v_font.h" static NSColor* RGB(const uint8_t red, const uint8_t green, const uint8_t blue) { @@ -339,17 +340,17 @@ void FConsoleWindow::SetTitleText() // It's used in graphical startup screen, with Hexen style in particular // Native OS X backend doesn't implement this yet - if (DoomStartupInfo.FgColor == DoomStartupInfo.BkColor) + if (GameStartupInfo.FgColor == GameStartupInfo.BkColor) { - DoomStartupInfo.FgColor = ~DoomStartupInfo.FgColor; + GameStartupInfo.FgColor = ~GameStartupInfo.FgColor; } NSTextField* titleText = [[NSTextField alloc] initWithFrame:titleTextRect]; - [titleText setStringValue:[NSString stringWithCString:DoomStartupInfo.Name + [titleText setStringValue:[NSString stringWithCString:GameStartupInfo.Name encoding:NSISOLatin1StringEncoding]]; [titleText setAlignment:NSCenterTextAlignment]; - [titleText setTextColor:RGB(DoomStartupInfo.FgColor)]; - [titleText setBackgroundColor:RGB(DoomStartupInfo.BkColor)]; + [titleText setTextColor:RGB(GameStartupInfo.FgColor)]; + [titleText setBackgroundColor:RGB(GameStartupInfo.BkColor)]; [titleText setFont:[NSFont fontWithName:@"Trebuchet MS Bold" size:18.0f]]; [titleText setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin]; [titleText setSelectable:NO]; diff --git a/src/posix/cocoa/st_start.mm b/src/posix/cocoa/st_start.mm index 4e3de2ff15..76df07f185 100644 --- a/src/posix/cocoa/st_start.mm +++ b/src/posix/cocoa/st_start.mm @@ -36,10 +36,9 @@ #import #include "c_cvars.h" -#include "doomtype.h" #include "st_console.h" #include "st_start.h" -#include "engineerrors.h" +#include "printf.h" FStartupScreen *StartScreen; diff --git a/src/posix/osx/i_specialpaths.mm b/src/posix/osx/i_specialpaths.mm index b414d566a3..ff435b7695 100644 --- a/src/posix/osx/i_specialpaths.mm +++ b/src/posix/osx/i_specialpaths.mm @@ -36,9 +36,10 @@ #import #include "cmdlib.h" -#include "m_misc.h" #include "version.h" // for GAMENAME +#include "i_specialpaths.h" +FString M_GetMacAppSupportPath(const bool create); static FString GetSpecialPath(const NSSearchPathDirectory kind, const BOOL create = YES, const NSSearchPathDomainMask domain = NSUserDomainMask) { @@ -199,7 +200,7 @@ FString M_GetScreenshotsPath() { path += "/" GAME_DIR "/Screenshots/"; } - + CreatePath(path); return path; } @@ -240,5 +241,45 @@ FString M_GetDocumentsPath() path += "/" GAME_DIR "/"; } + CreatePath(path); + return path; +} + +//=========================================================================== +// +// M_GetDemoPath macOS +// +// Returns the path to the default demo directory. +// +//=========================================================================== + +FString M_GetDemoPath() +{ + FString path = GetSpecialPath(NSDocumentDirectory); + + if (path.IsNotEmpty()) + { + path += "/" GAME_DIR "/Demos/"; + } + + return path; +} + +//=========================================================================== +// +// M_NormalizedPath +// +// Normalizes the given path and returns the result. +// +//=========================================================================== + +FString M_GetNormalizedPath(const char* path) +{ + NSString *str = [NSString stringWithUTF8String:path]; + NSString *out; + if ([str completePathIntoString:&out caseSensitive:NO matchesIntoArray:nil filterTypes:nil]) + { + return out.UTF8String; + } return path; } diff --git a/src/posix/osx/iwadpicker_cocoa.mm b/src/posix/osx/iwadpicker_cocoa.mm index cb6018e480..a5d8298418 100644 --- a/src/posix/osx/iwadpicker_cocoa.mm +++ b/src/posix/osx/iwadpicker_cocoa.mm @@ -34,11 +34,9 @@ */ #include "cmdlib.h" -#include "d_main.h" #include "version.h" #include "c_cvars.h" #include "m_argv.h" -#include "m_misc.h" #include "gameconfigfile.h" #include "engineerrors.h" @@ -385,8 +383,10 @@ static void RestartWithParameters(const WadStuff& wad, NSString* parameters) defaultiwad = wad.Name; - GameConfig->DoGameSetup("Doom"); - M_SaveDefaults(NULL); + GameConfig->ArchiveGlobalData(); + GameConfig->WriteConfigFile(); + delete GameConfig; + GameConfig = nullptr; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; diff --git a/src/posix/sdl/hardware.cpp b/src/posix/sdl/hardware.cpp index 7b3be1ec2c..ea008169e9 100644 --- a/src/posix/sdl/hardware.cpp +++ b/src/posix/sdl/hardware.cpp @@ -39,10 +39,9 @@ #include "hardware.h" #include "c_dispatch.h" #include "v_text.h" -#include "doomstat.h" #include "m_argv.h" -#include "engineerrors.h" -#include "swrenderer/r_swrenderer.h" +#include "c_console.h" +#include "printf.h" IVideo *Video; diff --git a/src/posix/sdl/i_gui.cpp b/src/posix/sdl/i_gui.cpp index 27c429f5c9..d06732624f 100644 --- a/src/posix/sdl/i_gui.cpp +++ b/src/posix/sdl/i_gui.cpp @@ -36,7 +36,6 @@ #include #include "bitmap.h" -#include "v_palette.h" #include "textures.h" bool I_SetCursor(FGameTexture *cursorpic) diff --git a/src/posix/sdl/i_input.cpp b/src/posix/sdl/i_input.cpp index 1cc685c8cb..5d0cdf31b8 100644 --- a/src/posix/sdl/i_input.cpp +++ b/src/posix/sdl/i_input.cpp @@ -31,24 +31,17 @@ ** */ #include -#include "doomtype.h" -#include "doomdef.h" -#include "doomstat.h" #include "m_argv.h" #include "v_video.h" -#include "d_main.h" #include "d_event.h" #include "d_gui.h" #include "c_buttons.h" #include "c_console.h" #include "c_dispatch.h" #include "dikeys.h" -#include "events.h" -#include "g_game.h" -#include "g_levellocals.h" #include "utf8.h" -#include "engineerrors.h" +#include "keydef.h" #include "i_interface.h" @@ -58,8 +51,6 @@ static void I_CheckNativeMouse (); bool GUICapture; static bool NativeMouse = true; -extern int paused; - CVAR (Bool, use_mouse, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, m_noprescale, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, m_filter, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) @@ -174,25 +165,15 @@ static const TMap KeyScanToDIK(InitKeyScanMap()); static void I_CheckGUICapture () { - bool wantCapt; - - if (menuactive == MENU_Off) - { - wantCapt = ConsoleState == c_down || ConsoleState == c_falling || chatmodeon; - } - else - { - wantCapt = (menuactive == MENU_On || menuactive == MENU_OnNoPause); - } - - // [ZZ] check active event handlers that want the UI processing - if (!wantCapt && primaryLevel->localEventManager->CheckUiProcessors()) - wantCapt = true; + bool wantCapt = sysCallbacks && sysCallbacks->WantGuiCapture && sysCallbacks->WantGuiCapture(); if (wantCapt != GUICapture) { GUICapture = wantCapt; - buttonMap.ResetButtonStates(); + if (wantCapt && Keyboard != NULL) + { + buttonMap.ResetButtonStates(); + } } } @@ -256,10 +237,9 @@ static void MouseRead () static void I_CheckNativeMouse () { bool focus = SDL_GetKeyboardFocus() != NULL; - bool fs = screen->IsFullscreen(); bool captureModeInGame = sysCallbacks && sysCallbacks->CaptureModeInGame && sysCallbacks->CaptureModeInGame(); - bool wantNative = !focus || (!use_mouse || GUICapture || paused || demoplayback || !captureModeInGame); + bool wantNative = !focus || (!use_mouse || GUICapture || !captureModeInGame); if (wantNative != NativeMouse) { diff --git a/src/posix/sdl/i_joystick.cpp b/src/posix/sdl/i_joystick.cpp index ad3416a10d..9d5297ba0f 100644 --- a/src/posix/sdl/i_joystick.cpp +++ b/src/posix/sdl/i_joystick.cpp @@ -33,6 +33,7 @@ #include #include "basics.h" +#include "cmdlib.h" #include "templates.h" #include "m_joy.h" #include "keydef.h" diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index ed0e264505..b0e4514623 100644 --- a/src/posix/sdl/i_main.cpp +++ b/src/posix/sdl/i_main.cpp @@ -43,19 +43,11 @@ #include "engineerrors.h" #include "m_argv.h" -#include "d_main.h" #include "c_console.h" #include "version.h" -#include "filesystem.h" -#include "g_level.h" -#include "g_levellocals.h" #include "cmdlib.h" -#include "r_utility.h" -#include "doomstat.h" -#include "vm.h" #include "engineerrors.h" #include "i_system.h" -#include "g_game.h" // MACROS ------------------------------------------------------------------ @@ -74,6 +66,7 @@ void Linux_I_FatalError(const char* errortext); #endif // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- +int GameMain(); // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- @@ -91,62 +84,10 @@ FArgs *Args; -static int DoomSpecificInfo (char *buffer, char *end) +static int GetCrashInfo (char *buffer, char *end) { - const char *arg; - int size = end-buffer-2; - int i, p; - - p = 0; - p += snprintf (buffer+p, size-p, GAMENAME" version %s (%s)\n", GetVersionString(), GetGitHash()); -#ifdef __VERSION__ - p += snprintf (buffer+p, size-p, "Compiler version: %s\n", __VERSION__); -#endif - - // If Args is nullptr, then execution is at either - // * early stage of initialization, additional info contains only default values - // * late stage of shutdown, most likely main() was done, and accessing global variables is no longer safe - if (Args) - { - p += snprintf(buffer + p, size - p, "\nCommand line:"); - for (i = 0; i < Args->NumArgs(); ++i) - { - p += snprintf(buffer + p, size - p, " %s", Args->GetArg(i)); - } - p += snprintf(buffer + p, size - p, "\n"); - - for (i = 0; (arg = fileSystem.GetResourceFileName(i)) != NULL; ++i) - { - p += snprintf(buffer + p, size - p, "\nWad %d: %s", i, arg); - } - - if (gamestate != GS_LEVEL && gamestate != GS_TITLELEVEL) - { - p += snprintf(buffer + p, size - p, "\n\nNot in a level."); - } - else - { - p += snprintf(buffer + p, size - p, "\n\nCurrent map: %s", primaryLevel->MapName.GetChars()); - - if (!viewactive) - { - p += snprintf(buffer + p, size - p, "\n\nView not active."); - } - else - { - auto& vp = r_viewpoint; - p += snprintf(buffer + p, size - p, "\n\nviewx = %f", vp.Pos.X); - p += snprintf(buffer + p, size - p, "\nviewy = %f", vp.Pos.Y); - p += snprintf(buffer + p, size - p, "\nviewz = %f", vp.Pos.Z); - p += snprintf(buffer + p, size - p, "\nviewangle = %f", vp.Angles.Yaw.Degrees); - } - } - } - - buffer[p++] = '\n'; - buffer[p++] = '\0'; - - return p; + if (sysCallbacks && sysCallbacks->CrashInfo) sysCallbacks->CrashInfo(buffer, end - buffer, "\n"); + return strlen(buffer); } void I_DetectOS() @@ -161,7 +102,7 @@ int main (int argc, char **argv) #if !defined (__APPLE__) { int s[4] = { SIGSEGV, SIGILL, SIGFPE, SIGBUS }; - cc_install_handlers(argc, argv, 4, s, GAMENAMELOWERCASE "-crash.log", DoomSpecificInfo); + cc_install_handlers(argc, argv, 4, s, GAMENAMELOWERCASE "-crash.log", GetCrashInfo); } #endif // !__APPLE__ @@ -203,7 +144,7 @@ int main (int argc, char **argv) I_StartupJoysticks(); - const int result = D_DoomMain(); + const int result = GameMain(); SDL_Quit(); diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index 14aea823bf..af77751142 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -1,35 +1,59 @@ -//----------------------------------------------------------------------------- -// -// Copyright 1993-1996 id Software -// Copyright 1999-2016 Randy Heit -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//----------------------------------------------------------------------------- -// +/* +** i_system.cpp +** Main startup code +** +**--------------------------------------------------------------------------- +** Copyright 1999-2016 Randy Heit +** Copyright 2019-2020 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ +#include +#include +#include +#include +#include +#include +#include + +#include #include #include #include #include - -#include "d_main.h" -#include "i_system.h" -#include "version.h" #include "x86.h" +#include "version.h" +#include "cmdlib.h" +#include "m_argv.h" +#include "i_sound.h" + #ifndef NO_GTK bool I_GtkAvailable (); diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index ff7cc53c00..6bf64b4db8 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -33,8 +33,6 @@ // HEADER FILES ------------------------------------------------------------ -#include "doomtype.h" - #include "i_module.h" #include "i_system.h" #include "i_video.h" @@ -43,22 +41,22 @@ #include "version.h" #include "c_console.h" #include "c_dispatch.h" -#include "s_sound.h" +#include "printf.h" #include "hardware.h" #include "gl_sysfb.h" #include "gl_system.h" -#include "r_defs.h" #include "gl/renderer/gl_renderer.h" #include "gl/system/gl_framebuffer.h" -#include "gl/shaders/gl_shader.h" #ifdef HAVE_VULKAN #include "rendering/vulkan/system/vk_framebuffer.h" #endif +#ifdef HAVE_SOFTPOLY #include "rendering/polyrenderer/backend/poly_framebuffer.h" +#endif // MACROS ------------------------------------------------------------------ @@ -76,7 +74,7 @@ // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // EXTERNAL DATA DECLARATIONS ---------------------------------------------- - +extern double refreshfreq; extern IVideo *Video; EXTERN_CVAR (Int, vid_adapter) @@ -261,6 +259,7 @@ bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface) } #endif +#if HAVE_SOFTPOLY namespace { SDL_Renderer* polyrendertarget = nullptr; @@ -409,7 +408,7 @@ void I_PolyPresentDeinit() polyrendertarget = nullptr; } } - +#endif SDLVideo::SDLVideo () @@ -428,7 +427,9 @@ SDLVideo::SDLVideo () } #endif // !SDL2_STATIC_LIBRARY +#ifdef HAVE_SOFTPOLY Priv::softpolyEnabled = vid_preferbackend == 2; +#endif #ifdef HAVE_VULKAN Priv::vulkanEnabled = vid_preferbackend == 1 && Priv::Vulkan_GetDrawableSize && Priv::Vulkan_GetInstanceExtensions && Priv::Vulkan_CreateSurface; @@ -443,10 +444,25 @@ SDLVideo::SDLVideo () } } #endif +#ifdef HAVE_SOFTPOLY if (Priv::softpolyEnabled) { Priv::CreateWindow(SDL_WINDOW_HIDDEN); } +#endif + + // Get refresh rate for current display. + SDL_DisplayMode display; + + if(SDL_GetCurrentDisplayMode(vid_adapter, &display) == 0) + { + refreshfreq = display.refresh_rate; + } + else + { + fprintf(stderr, "Failed to get refresh rate: %s\n", SDL_GetError()); + return; + } } SDLVideo::~SDLVideo () @@ -482,11 +498,12 @@ DFrameBuffer *SDLVideo::CreateFrameBuffer () } #endif +#ifdef HAVE_SOFTPOLY if (Priv::softpolyEnabled) { fb = new PolyFrameBuffer(nullptr, vid_fullscreen); } - +#endif if (fb == nullptr) { fb = new OpenGLRenderer::OpenGLFrameBuffer(0, vid_fullscreen); @@ -518,6 +535,7 @@ int SystemBaseFrameBuffer::GetClientWidth() { int width = 0; +#ifdef HAVE_SOFTPOLY if (Priv::softpolyEnabled) { if (polyrendertarget) @@ -526,6 +544,7 @@ int SystemBaseFrameBuffer::GetClientWidth() SDL_GetWindowSize(Priv::window, &width, nullptr); return width; } +#endif #ifdef HAVE_VULKAN assert(Priv::vulkanEnabled); @@ -538,7 +557,8 @@ int SystemBaseFrameBuffer::GetClientWidth() int SystemBaseFrameBuffer::GetClientHeight() { int height = 0; - + +#ifdef HAVE_SOFTPOLY if (Priv::softpolyEnabled) { if (polyrendertarget) @@ -547,6 +567,7 @@ int SystemBaseFrameBuffer::GetClientHeight() SDL_GetWindowSize(Priv::window, nullptr, &height); return height; } +#endif #ifdef HAVE_VULKAN assert(Priv::vulkanEnabled); @@ -588,7 +609,7 @@ void SystemBaseFrameBuffer::SetWindowSize(int w, int h) } win_w = w; win_h = h; - if (vid_fullscreen ) + if (vid_fullscreen) { vid_fullscreen = false; } diff --git a/src/posix/sdl/st_start.cpp b/src/posix/sdl/st_start.cpp index 59470594e1..75459eac7e 100644 --- a/src/posix/sdl/st_start.cpp +++ b/src/posix/sdl/st_start.cpp @@ -39,7 +39,6 @@ #include #include "st_start.h" -#include "doomdef.h" #include "i_system.h" #include "c_cvars.h" #include "engineerrors.h" diff --git a/src/posix/unix/gtk_dialogs.cpp b/src/posix/unix/gtk_dialogs.cpp index 2475035a9a..903e05f0b3 100644 --- a/src/posix/unix/gtk_dialogs.cpp +++ b/src/posix/unix/gtk_dialogs.cpp @@ -55,10 +55,11 @@ typedef enum #endif #include "c_cvars.h" -#include "d_main.h" #include "i_module.h" #include "i_system.h" #include "version.h" +#include "startupinfo.h" +#include "cmdlib.h" EXTERN_CVAR (Bool, queryiwad); diff --git a/src/sound/s_doomsound.h b/src/sound/s_doomsound.h index 0953af4b03..e826c69dee 100644 --- a/src/sound/s_doomsound.h +++ b/src/sound/s_doomsound.h @@ -11,7 +11,6 @@ void S_Start(); void S_Shutdown(); void S_UpdateSounds(AActor* listenactor); -void S_SetSoundPaused(int state); void S_PrecacheLevel(FLevelLocals* l); diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index e654097f65..1da0918241 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -44,7 +44,9 @@ #include "version.h" #include "printf.h" #include "win32glvideo.h" +#ifdef HAVE_SOFTPOLY #include "win32polyvideo.h" +#endif #ifdef HAVE_VULKAN #include "win32vulkanvideo.h" #endif @@ -129,10 +131,13 @@ void I_InitGraphics () // are the active app. Huh? } +#ifdef HAVE_SOFTPOLY if (vid_preferbackend == 2) { Video = new Win32PolyVideo(); } + else +#endif #ifdef HAVE_VULKAN else if (vid_preferbackend == 1) { @@ -147,15 +152,16 @@ void I_InitGraphics () Video = new Win32GLVideo(); } } -#endif else +#endif { Video = new Win32GLVideo(); } +#ifdef HAVE_SOFTPOLY if (Video == NULL) Video = new Win32PolyVideo(); - +#endif // we somehow STILL don't have a display!! if (Video == NULL) I_FatalError ("Failed to initialize display"); diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index 9f62559f88..c0d896dcb6 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -74,7 +74,7 @@ #include "i_sound.h" #include "d_gui.h" #include "c_console.h" -#include "s_sound.h" +#include "s_soundinternal.h" #include "gameconfigfile.h" #include "hardware.h" #include "d_event.h" @@ -87,8 +87,6 @@ #include "c_buttons.h" #include "cmdlib.h" -int32_t refreshfreq = -1; - // Compensate for w32api's lack #ifndef GET_XBUTTON_WPARAM #define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam)) @@ -138,6 +136,7 @@ extern bool AppActive; int SessionState = 0; int BlockMouseMove; +double refreshfreq; static bool EventHandlerResultForNativeMouse; diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 9a591e27d0..d4deb33bf9 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -59,17 +59,13 @@ #include "hardware.h" #include "m_argv.h" -#include "d_main.h" #include "i_module.h" #include "c_console.h" #include "version.h" #include "i_input.h" #include "filesystem.h" #include "cmdlib.h" -#include "g_game.h" -#include "r_utility.h" -#include "g_levellocals.h" -#include "s_sound.h" +#include "s_soundinternal.h" #include "vm.h" #include "i_system.h" #include "gstrings.h" @@ -77,6 +73,8 @@ #include "stats.h" #include "st_start.h" +#include "i_interface.h" +#include "startupinfo.h" // MACROS ------------------------------------------------------------------ @@ -96,6 +94,7 @@ void CreateCrashLog (const char *custominfo, DWORD customsize, HWND richedit); void DisplayCrashLog (); void I_FlushBufferedConsoleStuff(); void DestroyCustomCursor(); +int GameMain(); // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- @@ -268,7 +267,7 @@ void LayoutMainWindow (HWND hWnd, HWND pane) w = rect.right; h = rect.bottom; - if (DoomStartupInfo.Name.IsNotEmpty() && GameTitleWindow != NULL) + if (GameStartupInfo.Name.IsNotEmpty() && GameTitleWindow != NULL) { bannerheight = GameTitleFontHeight + 5; MoveWindow (GameTitleWindow, 0, 0, w, bannerheight, TRUE); @@ -426,7 +425,7 @@ LRESULT CALLBACK LConProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_DRAWITEM: // Draw title banner. - if (wParam == IDC_STATIC_TITLE && DoomStartupInfo.Name.IsNotEmpty()) + if (wParam == IDC_STATIC_TITLE && GameStartupInfo.Name.IsNotEmpty()) { const PalEntry *c; @@ -436,7 +435,7 @@ LRESULT CALLBACK LConProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) // Draw the background. rect = drawitem->rcItem; rect.bottom -= 1; - c = (const PalEntry *)&DoomStartupInfo.BkColor; + c = (const PalEntry *)&GameStartupInfo.BkColor; hbr = CreateSolidBrush (RGB(c->r,c->g,c->b)); FillRect (drawitem->hDC, &drawitem->rcItem, hbr); DeleteObject (hbr); @@ -444,11 +443,11 @@ LRESULT CALLBACK LConProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) // Calculate width of the title string. SetTextAlign (drawitem->hDC, TA_TOP); oldfont = SelectObject (drawitem->hDC, GameTitleFont != NULL ? GameTitleFont : (HFONT)GetStockObject (DEFAULT_GUI_FONT)); - auto widename = DoomStartupInfo.Name.WideString(); + auto widename = GameStartupInfo.Name.WideString(); GetTextExtentPoint32W (drawitem->hDC, widename.c_str(), (int)widename.length(), &size); // Draw the title. - c = (const PalEntry *)&DoomStartupInfo.FgColor; + c = (const PalEntry *)&GameStartupInfo.FgColor; SetTextColor (drawitem->hDC, RGB(c->r,c->g,c->b)); SetBkMode (drawitem->hDC, TRANSPARENT); TextOutW (drawitem->hDC, rect.left + (rect.right - rect.left - size.cx) / 2, 2, widename.c_str(), (int)widename.length()); @@ -950,7 +949,7 @@ int DoMain (HINSTANCE hInstance) CoInitialize (NULL); atexit (UnCOM); - int ret = D_DoomMain (); + int ret = GameMain (); DestroyCustomCursor(); if (ret == 1337) // special exit code for 'norun'. { @@ -998,55 +997,6 @@ void I_ShowFatalError(const char *msg) } } -//========================================================================== -// -// DoomSpecificInfo -// -// Called by the crash logger to get application-specific information. -// -//========================================================================== - -void DoomSpecificInfo (char *buffer, size_t bufflen) -{ - const char *arg; - char *const buffend = buffer + bufflen - 2; // -2 for CRLF at end - int i; - - buffer += mysnprintf (buffer, buffend - buffer, GAMENAME " version %s (%s)", GetVersionString(), GetGitHash()); - FString cmdline(GetCommandLineW()); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nCommand line: %s\r\n", cmdline.GetChars() ); - - for (i = 0; (arg = fileSystem.GetResourceFileName (i)) != NULL; ++i) - { - buffer += mysnprintf (buffer, buffend - buffer, "\r\nWad %d: %s", i, arg); - } - - if (gamestate != GS_LEVEL && gamestate != GS_TITLELEVEL) - { - buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nNot in a level."); - } - else - { - buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nCurrent map: %s", primaryLevel->MapName.GetChars()); - - if (!viewactive) - { - buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nView not active."); - } - else - { - auto &vp = r_viewpoint; - buffer += mysnprintf (buffer, buffend - buffer, "\r\n\r\nviewx = %f", vp.Pos.X); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewy = %f", vp.Pos.Y); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewz = %f", vp.Pos.Z); - buffer += mysnprintf (buffer, buffend - buffer, "\r\nviewangle = %f", vp.Angles.Yaw); - } - } - *buffer++ = '\r'; - *buffer++ = '\n'; - *buffer++ = '\0'; -} - // Here is how the error logging system works. // // To catch exceptions that occur in secondary threads, CatchAllExceptions is @@ -1139,7 +1089,7 @@ LONG WINAPI CatchAllExceptions (LPEXCEPTION_POINTERS info) char *custominfo = (char *)HeapAlloc (GetProcessHeap(), 0, 16384); CrashPointers = *info; - DoomSpecificInfo (custominfo, 16384); + if (sysCallbacks && sysCallbacks->CrashInfo && custominfo) sysCallbacks->CrashInfo(custominfo, 16384, "\r\n"); CreateCrashLog (custominfo, (DWORD)strlen(custominfo), ConWindow); // If the main thread crashed, then make it clean up after itself. diff --git a/src/win32/i_mouse.cpp b/src/win32/i_mouse.cpp index 62f68ad440..a3aaec6745 100644 --- a/src/win32/i_mouse.cpp +++ b/src/win32/i_mouse.cpp @@ -268,9 +268,10 @@ void I_CheckNativeMouse(bool preferNative, bool eventhandlerresult) } else { + bool pauseState = false; bool captureModeInGame = sysCallbacks && sysCallbacks->CaptureModeInGame && sysCallbacks->CaptureModeInGame(); want_native = ((!m_use_mouse || menuactive != MENU_WaitKey) && - (!captureModeInGame || GUICapture ||paused || demoplayback)); + (!captureModeInGame || GUICapture)); } } diff --git a/src/win32/i_specialpaths.cpp b/src/win32/i_specialpaths.cpp index 8cff2d92ce..3078f59c16 100644 --- a/src/win32/i_specialpaths.cpp +++ b/src/win32/i_specialpaths.cpp @@ -38,6 +38,7 @@ #include #include +#include "i_specialpaths.h" #include "printf.h" #include "cmdlib.h" #include "findfile.h" diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 9b8073ef3a..39b4394e3e 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -59,16 +59,14 @@ #include #include #include +#include #include "hardware.h" -#include "engineerrors.h" -#include "cmdlib.h" +#include "printf.h" #include "version.h" -#include "m_misc.h" #include "i_sound.h" #include "resource.h" -#include "x86.h" #include "stats.h" #include "v_text.h" #include "utf8.h" @@ -85,6 +83,7 @@ #include "doomstat.h" #include "i_system.h" #include "bitmap.h" +#include "cmdlib.h" // MACROS ------------------------------------------------------------------ @@ -98,7 +97,6 @@ // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- -extern void CheckCPUID(CPUInfo *cpu); extern void LayoutMainWindow(HWND hWnd, HWND pane); // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- @@ -549,7 +547,10 @@ BOOL CALLBACK IWADBoxCallback(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa filepart = WadList[i].Path; else filepart++; - FStringf work("%s (%s)", WadList[i].Name.GetChars(), filepart); + + FString work; + if (*filepart) work.Format("%s (%s)", WadList[i].Name.GetChars(), filepart); + else work = WadList[i].Name.GetChars(); std::wstring wide = work.WideString(); SendMessage(ctrl, LB_ADDSTRING, 0, (LPARAM)wide.c_str()); SendMessage(ctrl, LB_SETITEMDATA, i, (LPARAM)i); @@ -651,8 +652,8 @@ bool I_SetCursor(FGameTexture *cursorpic) return false; } // Fixme: This should get a raw image, not a texture. (Once raw images get implemented.) - int lo = cursorpic->GetDisplayLeftOffset(); - int to = cursorpic->GetDisplayTopOffset(); + int lo = cursorpic->GetTexelLeftOffset(); + int to = cursorpic->GetTexelTopOffset(); cursor = CreateAlphaCursor(image, lo, to); if (cursor == NULL) diff --git a/src/win32/i_system.h b/src/win32/i_system.h index 18cc68aac2..c9413631ce 100644 --- a/src/win32/i_system.h +++ b/src/win32/i_system.h @@ -1,28 +1,3 @@ -//----------------------------------------------------------------------------- -// -// Copyright 1993-1996 id Software -// Copyright 1999-2016 Randy Heit -// Copyright 2002-2016 Christoph Oelckers -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//----------------------------------------------------------------------------- -// -// DESCRIPTION: -// System specific interface stuff. -// -//----------------------------------------------------------------------------- #ifndef __I_SYSTEM__ diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp index 030e341931..34e919bb4e 100644 --- a/src/win32/st_start.cpp +++ b/src/win32/st_start.cpp @@ -117,18 +117,18 @@ FStartupScreen *FStartupScreen::CreateInstance(int max_progress) if (!Args->CheckParm("-nostartup")) { - if (DoomStartupInfo.Type == FStartupInfo::HexenStartup || - (gameinfo.gametype == GAME_Hexen && DoomStartupInfo.Type == FStartupInfo::DefaultStartup)) + if (GameStartupInfo.Type == FStartupInfo::HexenStartup || + (gameinfo.gametype == GAME_Hexen && GameStartupInfo.Type == FStartupInfo::DefaultStartup)) { scr = new FHexenStartupScreen(max_progress, hr); } - else if (DoomStartupInfo.Type == FStartupInfo::HereticStartup || - (gameinfo.gametype == GAME_Heretic && DoomStartupInfo.Type == FStartupInfo::DefaultStartup)) + else if (GameStartupInfo.Type == FStartupInfo::HereticStartup || + (gameinfo.gametype == GAME_Heretic && GameStartupInfo.Type == FStartupInfo::DefaultStartup)) { scr = new FHereticStartupScreen(max_progress, hr); } - else if (DoomStartupInfo.Type == FStartupInfo::StrifeStartup || - (gameinfo.gametype == GAME_Strife && DoomStartupInfo.Type == FStartupInfo::DefaultStartup)) + else if (GameStartupInfo.Type == FStartupInfo::StrifeStartup || + (gameinfo.gametype == GAME_Strife && GameStartupInfo.Type == FStartupInfo::DefaultStartup)) { scr = new FStrifeStartupScreen(max_progress, hr); } @@ -354,7 +354,7 @@ void FBasicStartupScreen :: NetProgress(int count) mysnprintf (buf, countof(buf), "%d/%d", NetCurPos, NetMaxPos); SetDlgItemTextA (NetStartPane, IDC_NETSTARTCOUNT, buf); - SendDlgItemMessage (NetStartPane, IDC_NETSTARTPROGRESS, PBM_SETPOS, MIN(NetCurPos, NetMaxPos), 0); + SendDlgItemMessage (NetStartPane, IDC_NETSTARTPROGRESS, PBM_SETPOS, std::min(NetCurPos, NetMaxPos), 0); } } diff --git a/src/win32/st_start_util.cpp b/src/win32/st_start_util.cpp index 730ea31aa4..86377ed35e 100644 --- a/src/win32/st_start_util.cpp +++ b/src/win32/st_start_util.cpp @@ -458,9 +458,9 @@ FHexenStartupScreen::FHexenStartupScreen(int max_progress, long& hr) if (!batchrun) { - if (DoomStartupInfo.Song.IsNotEmpty()) + if (GameStartupInfo.Song.IsNotEmpty()) { - S_ChangeMusic(DoomStartupInfo.Song.GetChars(), true, true); + S_ChangeMusic(GameStartupInfo.Song.GetChars(), true, true); } else { diff --git a/src/win32/win32glvideo.cpp b/src/win32/win32glvideo.cpp index 007c6076e4..4227f55b91 100644 --- a/src/win32/win32glvideo.cpp +++ b/src/win32/win32glvideo.cpp @@ -36,6 +36,7 @@ #include #include #include "wglext.h" +#include #include "gl_sysfb.h" #include "hardware.h" From 4da23516718c3ac45f86d7010866f825cfc5ec8f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 20:42:13 +0200 Subject: [PATCH 072/220] - fixed compile errors in POSIX platform code. --- src/CMakeLists.txt | 3 +++ src/common/engine/i_interface.h | 9 +++++++++ src/common/engine/startupinfo.h | 3 +++ src/common/menu/menustate.h | 10 ++++++++++ src/d_iwad.cpp | 1 + src/d_main.cpp | 2 +- src/d_main.h | 6 ------ src/doomstat.h | 9 +-------- src/posix/cocoa/i_input.mm | 4 +++- src/posix/cocoa/i_main.mm | 1 + src/posix/cocoa/st_console.mm | 2 +- src/posix/osx/iwadpicker_cocoa.mm | 1 + src/posix/sdl/i_input.cpp | 4 +++- src/posix/sdl/i_main.cpp | 1 + src/posix/unix/gtk_dialogs.cpp | 1 + src/rendering/hwrenderer/scene/hw_walls.cpp | 6 ++++-- src/rendering/hwrenderer/utility/hw_draw2d.cpp | 1 + src/win32/i_system.cpp | 1 + 18 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 src/common/menu/menustate.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a89a6cc7d8..02b4638f7c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -605,6 +605,7 @@ file( GLOB HEADER_FILES common/console/*.h common/utility/*.h common/engine/*.h + common/menu/*.h common/fonts/*.h common/objects/*.h common/filesystem/*.h @@ -1251,6 +1252,7 @@ include_directories( . common/utility common/console common/engine + common/menu common/fonts common/objects common/rendering @@ -1457,6 +1459,7 @@ source_group("Common\\Utility" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/ source_group("Common\\Engine" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/engine/.+") source_group("Common\\2D" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/2d/.+") source_group("Common\\Objects" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/objects/.+") +source_group("Common\\Menu" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/menu/.+") source_group("Common\\Fonts" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/fonts/.+") source_group("Common\\File System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/filesystem/.+") source_group("Common\\Scripting" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/.+") diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index ff26d18a80..134cae975a 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -1,5 +1,6 @@ #pragma once +#include "zstring.h" struct SystemCallbacks { @@ -13,3 +14,11 @@ struct SystemCallbacks }; extern SystemCallbacks *sysCallbacks; + +struct WadStuff +{ + FString Path; + FString Name; +}; + + diff --git a/src/common/engine/startupinfo.h b/src/common/engine/startupinfo.h index cbabba4004..53f79e8800 100644 --- a/src/common/engine/startupinfo.h +++ b/src/common/engine/startupinfo.h @@ -1,5 +1,8 @@ #pragma once +#include +#include "zstring.h" + struct FStartupInfo { FString Name; diff --git a/src/common/menu/menustate.h b/src/common/menu/menustate.h new file mode 100644 index 0000000000..5dfd386095 --- /dev/null +++ b/src/common/menu/menustate.h @@ -0,0 +1,10 @@ +#pragma once + +enum EMenuState : int +{ + MENU_Off, // Menu is closed + MENU_On, // Menu is opened + MENU_WaitKey, // Menu is opened and waiting for a key in the controls menu + MENU_OnNoPause, // Menu is opened but does not pause the game +}; +extern EMenuState menuactive; // Menu overlayed? diff --git a/src/d_iwad.cpp b/src/d_iwad.cpp index ddbb853d8a..bbecbf81b4 100644 --- a/src/d_iwad.cpp +++ b/src/d_iwad.cpp @@ -47,6 +47,7 @@ #include "engineerrors.h" #include "v_text.h" #include "findfile.h" +#include "i_interface.h" CVAR (Bool, queryiwad, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); CVAR (String, defaultiwad, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG); diff --git a/src/d_main.cpp b/src/d_main.cpp index 0720aaddee..eaae9b22e0 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2685,7 +2685,7 @@ void System_CrashInfo(char* buffer, size_t bufflen, const char *lfstr) buffer += mysnprintf(buffer, buffend - buffer, "%s%sviewx = %f", lfstr, lfstr, vp.Pos.X); buffer += mysnprintf(buffer, buffend - buffer, "%sviewy = %f", lfstr, vp.Pos.Y); buffer += mysnprintf(buffer, buffend - buffer, "%sviewz = %f", lfstr, vp.Pos.Z); - buffer += mysnprintf(buffer, buffend - buffer, "%sviewangle = %f", lfstr, vp.Angles.Yaw); + buffer += mysnprintf(buffer, buffend - buffer, "%sviewangle = %f", lfstr, vp.Angles.Yaw.Degrees); } } buffer += mysnprintf(buffer, buffend - buffer, "%s", lfstr); diff --git a/src/d_main.h b/src/d_main.h index 92691c8375..ce8d9d778e 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -66,12 +66,6 @@ extern const char *D_DrawIcon; extern uint32_t r_renderercaps; -struct WadStuff -{ - FString Path; - FString Name; -}; - struct FIWADInfo { FString Name; // Title banner text for this IWAD diff --git a/src/doomstat.h b/src/doomstat.h index 879dcd83a9..873301c980 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -105,16 +105,9 @@ EXTERN_CVAR (Float, snd_musicvolume) // maximum volume for music // Status flags for refresh. // -enum EMenuState : int -{ - MENU_Off, // Menu is closed - MENU_On, // Menu is opened - MENU_WaitKey, // Menu is opened and waiting for a key in the controls menu - MENU_OnNoPause, // Menu is opened but does not pause the game -}; +#include "menustate.h" extern bool automapactive; // In AutoMap mode? -extern EMenuState menuactive; // Menu overlayed? extern int paused; // Game Pause? extern bool pauseext; diff --git a/src/posix/cocoa/i_input.mm b/src/posix/cocoa/i_input.mm index 87199d8b68..b3315f804f 100644 --- a/src/posix/cocoa/i_input.mm +++ b/src/posix/cocoa/i_input.mm @@ -44,6 +44,8 @@ #include "dikeys.h" #include "v_video.h" #include "i_interface.h" +#include "menustate.h" +#include "engineerrors.h" EXTERN_CVAR(Int, m_use_mouse) @@ -77,7 +79,7 @@ void CheckGUICapture() if (wantCapt != GUICapture) { GUICapture = wantCapt; - if (wantCapt && Keyboard != NULL) + if (wantCapt) { buttonMap.ResetButtonStates(); } diff --git a/src/posix/cocoa/i_main.mm b/src/posix/cocoa/i_main.mm index 071ab34d37..f33b206fdf 100644 --- a/src/posix/cocoa/i_main.mm +++ b/src/posix/cocoa/i_main.mm @@ -45,6 +45,7 @@ #include "version.h" #include "printf.h" #include "s_music.h" +#include "engineerrors.h" #define ZD_UNUSED(VARIABLE) ((void)(VARIABLE)) diff --git a/src/posix/cocoa/st_console.mm b/src/posix/cocoa/st_console.mm index 6212079e2e..b4c0878c8d 100644 --- a/src/posix/cocoa/st_console.mm +++ b/src/posix/cocoa/st_console.mm @@ -346,7 +346,7 @@ void FConsoleWindow::SetTitleText() } NSTextField* titleText = [[NSTextField alloc] initWithFrame:titleTextRect]; - [titleText setStringValue:[NSString stringWithCString:GameStartupInfo.Name + [titleText setStringValue:[NSString stringWithCString:GameStartupInfo.Name.GetChars() encoding:NSISOLatin1StringEncoding]]; [titleText setAlignment:NSCenterTextAlignment]; [titleText setTextColor:RGB(GameStartupInfo.FgColor)]; diff --git a/src/posix/osx/iwadpicker_cocoa.mm b/src/posix/osx/iwadpicker_cocoa.mm index a5d8298418..8670ec2bd3 100644 --- a/src/posix/osx/iwadpicker_cocoa.mm +++ b/src/posix/osx/iwadpicker_cocoa.mm @@ -39,6 +39,7 @@ #include "m_argv.h" #include "gameconfigfile.h" #include "engineerrors.h" +#include "i_interface.h" #include #include diff --git a/src/posix/sdl/i_input.cpp b/src/posix/sdl/i_input.cpp index 5d0cdf31b8..ad2181ae6a 100644 --- a/src/posix/sdl/i_input.cpp +++ b/src/posix/sdl/i_input.cpp @@ -43,6 +43,8 @@ #include "utf8.h" #include "keydef.h" #include "i_interface.h" +#include "engineerrors.h" +#include "i_interface.h" static void I_CheckGUICapture (); @@ -170,7 +172,7 @@ static void I_CheckGUICapture () if (wantCapt != GUICapture) { GUICapture = wantCapt; - if (wantCapt && Keyboard != NULL) + if (wantCapt) { buttonMap.ResetButtonStates(); } diff --git a/src/posix/sdl/i_main.cpp b/src/posix/sdl/i_main.cpp index b0e4514623..7fc179a510 100644 --- a/src/posix/sdl/i_main.cpp +++ b/src/posix/sdl/i_main.cpp @@ -48,6 +48,7 @@ #include "cmdlib.h" #include "engineerrors.h" #include "i_system.h" +#include "i_interface.h" // MACROS ------------------------------------------------------------------ diff --git a/src/posix/unix/gtk_dialogs.cpp b/src/posix/unix/gtk_dialogs.cpp index 903e05f0b3..b5fbfdd386 100644 --- a/src/posix/unix/gtk_dialogs.cpp +++ b/src/posix/unix/gtk_dialogs.cpp @@ -60,6 +60,7 @@ typedef enum #include "version.h" #include "startupinfo.h" #include "cmdlib.h" +#include "i_interface.h" EXTERN_CVAR (Bool, queryiwad); diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index eecca476e8..eb907770fd 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -459,8 +459,10 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent) Colormap.Clear(); } - if (di->isFullbrightScene() || (Colormap.LightColor.isWhite() && lightlevel == 255)) - flags &= ~HWF_GLOW; + if (di->isFullbrightScene() || (Colormap.LightColor.isWhite() && lightlevel == 255)) + { + flags &= ~HWF_GLOW; + } if (!screen->BuffersArePersistent()) { diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index d0010ef0d7..9404c9f869 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -188,6 +188,7 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state) switch (cmd.mType) { + default: case F2DDrawer::DrawTypeTriangles: state.DrawIndexed(DT_Triangles, cmd.mIndexIndex, cmd.mIndexCount); break; diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 39b4394e3e..4a2ddcdf3c 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -84,6 +84,7 @@ #include "i_system.h" #include "bitmap.h" #include "cmdlib.h" +#include "i_interface.h" // MACROS ------------------------------------------------------------------ From 7f83b190cc318dc5083e71401be2553c39c42deb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 21:46:22 +0200 Subject: [PATCH 073/220] - a few more fixes. --- src/posix/cocoa/i_input.mm | 2 +- src/posix/cocoa/st_start.mm | 1 + src/posix/sdl/i_input.cpp | 3 +++ src/posix/sdl/i_system.cpp | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/posix/cocoa/i_input.mm b/src/posix/cocoa/i_input.mm index b3315f804f..8b81f86add 100644 --- a/src/posix/cocoa/i_input.mm +++ b/src/posix/cocoa/i_input.mm @@ -162,7 +162,7 @@ void CheckNativeMouse() && (MENU_On == menuactive || MENU_OnNoPause == menuactive); } - if (!wantNative && primaryLevel->localEventManager->CheckRequireMouse()) + if (!wantNative && sysCallbacks && sysCallbacks->WantNativeMouse && sysCallbacks->WantNativeMouse()) wantNative = true; I_SetNativeMouse(wantNative); diff --git a/src/posix/cocoa/st_start.mm b/src/posix/cocoa/st_start.mm index 76df07f185..044c36986e 100644 --- a/src/posix/cocoa/st_start.mm +++ b/src/posix/cocoa/st_start.mm @@ -39,6 +39,7 @@ #include "st_console.h" #include "st_start.h" #include "printf.h" +#include "engineerrors.h" FStartupScreen *StartScreen; diff --git a/src/posix/sdl/i_input.cpp b/src/posix/sdl/i_input.cpp index ad2181ae6a..164b0b2285 100644 --- a/src/posix/sdl/i_input.cpp +++ b/src/posix/sdl/i_input.cpp @@ -243,6 +243,9 @@ static void I_CheckNativeMouse () bool captureModeInGame = sysCallbacks && sysCallbacks->CaptureModeInGame && sysCallbacks->CaptureModeInGame(); bool wantNative = !focus || (!use_mouse || GUICapture || !captureModeInGame); + if (!wantNative && sysCallbacks && sysCallbacks->WantNativeMouse && sysCallbacks->WantNativeMouse()) + wantNative = true; + if (wantNative != NativeMouse) { NativeMouse = wantNative; diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index af77751142..43b8c86649 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -53,6 +53,7 @@ #include "cmdlib.h" #include "m_argv.h" #include "i_sound.h" +#include "i_interface.h" #ifndef NO_GTK From 6934aebbe6a2cd72fadd968a4d1a597e2e6f4553 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 21:57:59 +0200 Subject: [PATCH 074/220] - fixed typo in HAVE_SOFTPOLY. --- CMakeLists.txt | 8 ++++---- src/posix/sdl/sdlglvideo.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d574b999cf..95dba3dc3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,9 +203,9 @@ if( MSVC ) # Function-level linking # Disable run-time type information if ( HAVE_VULKAN ) - set( ALL_C_FLAGS "/GF /Gy /permissive- /DHAVE_VULKAN /D_HAVE_SOFTPOLY" ) + set( ALL_C_FLAGS "/GF /Gy /permissive- /DHAVE_VULKAN /DHAVE_SOFTPOLY" ) else() - set( ALL_C_FLAGS "/GF /Gy /permissive- /D_HAVE_SOFTPOLY" ) + set( ALL_C_FLAGS "/GF /Gy /permissive- /DHAVE_SOFTPOLY" ) endif() # Use SSE 2 as minimum always as the true color drawers needs it for __vectorcall @@ -241,9 +241,9 @@ if( MSVC ) else() set( REL_LINKER_FLAGS "" ) if ( HAVE_VULKAN ) - set( ALL_C_FLAGS "-ffp-contract=off -DHAVE_VULKAN -D_HAVE_SOFTPOLY" ) + set( ALL_C_FLAGS "-ffp-contract=off -DHAVE_VULKAN -DHAVE_SOFTPOLY" ) else() - set( ALL_C_FLAGS "-ffp-contract=off -D_HAVE_SOFTPOLY" ) + set( ALL_C_FLAGS "-ffp-contract=off -DHAVE_SOFTPOLY" ) endif() if ( UNIX ) diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/posix/sdl/sdlglvideo.cpp index 6bf64b4db8..66edd075e0 100644 --- a/src/posix/sdl/sdlglvideo.cpp +++ b/src/posix/sdl/sdlglvideo.cpp @@ -259,7 +259,7 @@ bool I_CreateVulkanSurface(VkInstance instance, VkSurfaceKHR *surface) } #endif -#if HAVE_SOFTPOLY +#ifdef HAVE_SOFTPOLY namespace { SDL_Renderer* polyrendertarget = nullptr; From 3961f708fef4f81916199c6eb440d61f143abea5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 22:32:24 +0200 Subject: [PATCH 075/220] - moved refreshfreq variable to a common place. --- src/common/engine/i_interface.cpp | 1 + src/win32/hardware.cpp | 2 +- src/win32/i_input.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/engine/i_interface.cpp b/src/common/engine/i_interface.cpp index b95563279c..7fc82c4cc5 100644 --- a/src/common/engine/i_interface.cpp +++ b/src/common/engine/i_interface.cpp @@ -1,3 +1,4 @@ #include "i_interface.h" SystemCallbacks *sysCallbacks; +double refreshfreq; \ No newline at end of file diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 1da0918241..3cadc1ced0 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -139,7 +139,7 @@ void I_InitGraphics () else #endif #ifdef HAVE_VULKAN - else if (vid_preferbackend == 1) + if (vid_preferbackend == 1) { // first try Vulkan, if that fails OpenGL try diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index c0d896dcb6..2a67766bdd 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -136,7 +136,7 @@ extern bool AppActive; int SessionState = 0; int BlockMouseMove; -double refreshfreq; +extern double refreshfreq; static bool EventHandlerResultForNativeMouse; From 8473be2a0c25f7130985a7e6102cea385a258c47 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 22:35:28 +0200 Subject: [PATCH 076/220] - some final cleanup. --- src/win32/i_system.h | 5 ++++- src/win32/win32glvideo.cpp | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/win32/i_system.h b/src/win32/i_system.h index c9413631ce..cf2673717d 100644 --- a/src/win32/i_system.h +++ b/src/win32/i_system.h @@ -3,8 +3,11 @@ #ifndef __I_SYSTEM__ #define __I_SYSTEM__ -#include "doomtype.h" +#include "basics.h" #include +#include "tarray.h" +#include "zstring.h" +#include "utf8.h" struct ticcmd_t; struct WadStuff; diff --git a/src/win32/win32glvideo.cpp b/src/win32/win32glvideo.cpp index 4227f55b91..80dadfd0e7 100644 --- a/src/win32/win32glvideo.cpp +++ b/src/win32/win32glvideo.cpp @@ -409,7 +409,6 @@ bool Win32GLVideo::InitHardware(HWND Window, int multisample) int prof = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; const char *version = Args->CheckValue("-glversion"); - if (version != nullptr && strtod(version, nullptr) < 3.0) prof = WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; for (; prof <= WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; prof++) { From d19ac5b260d850a82550972019121f3a7d120c65 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 22:56:15 +0200 Subject: [PATCH 077/220] - separated the game specific Steam code from the pure backend. --- src/CMakeLists.txt | 1 + src/posix/i_system.h | 55 +--------- src/win32/i_steam.cpp | 224 +++++++++++++++++++++++++++++++++++++++++ src/win32/i_system.cpp | 143 -------------------------- src/win32/i_system.h | 31 ------ 5 files changed, 228 insertions(+), 226 deletions(-) create mode 100644 src/win32/i_steam.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02b4638f7c..35cd655925 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -447,6 +447,7 @@ set( PLAT_WIN32_SOURCES win32/i_rawps2.cpp win32/i_xinput.cpp win32/i_main.cpp + win32/i_steam.cpp win32/i_system.cpp win32/i_specialpaths.cpp win32/st_start.cpp diff --git a/src/posix/i_system.h b/src/posix/i_system.h index 09473091e2..1988d16bef 100644 --- a/src/posix/i_system.h +++ b/src/posix/i_system.h @@ -1,29 +1,3 @@ -//----------------------------------------------------------------------------- -// -// Copyright 1993-1996 id Software -// Copyright 1999-2016 Randy Heit -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//----------------------------------------------------------------------------- -// -// DESCRIPTION: -// System specific interface stuff. -// -//----------------------------------------------------------------------------- - - #ifndef __I_SYSTEM__ #define __I_SYSTEM__ @@ -34,9 +8,10 @@ #define __solaris__ 1 #endif -#include "doomtype.h" #include #include +#include "tarray.h" +#include "zstring.h" struct ticcmd_t; struct WadStuff; @@ -51,34 +26,11 @@ void CalculateCPUSpeed(void); unsigned int I_MakeRNGSeed(); -// -// Called by D_DoomLoop, -// called before processing any tics in a frame -// (just after displaying a frame). -// Time consuming syncronous operations -// are performed here (joystick reading). -// Can call D_PostEvent. -// + void I_StartFrame (void); - -// -// Called by D_DoomLoop, -// called before processing each tic in a frame. -// Quick syncronous operations are performed here. -// Can call D_PostEvent. void I_StartTic (void); -// Asynchronous interrupt functions should maintain private queues -// that are read by the synchronous functions -// to be converted into events. - -// Either returns a null ticcmd, -// or calls a loadable driver to build it. -// This ticcmd will then be modified by the gameloop -// for normal input. -ticcmd_t *I_BaseTiccmd (void); - // Print a console string void I_PrintStr (const char *str); @@ -100,7 +52,6 @@ bool I_WriteIniFailed (); class FGameTexture; bool I_SetCursor(FGameTexture *); - static inline char *strlwr(char *str) { char *ptr = str; diff --git a/src/win32/i_steam.cpp b/src/win32/i_steam.cpp new file mode 100644 index 0000000000..cf5ccb0c74 --- /dev/null +++ b/src/win32/i_steam.cpp @@ -0,0 +1,224 @@ +/* +** i_system.cpp +** Timers, pre-console output, IWAD selection, and misc system routines. +** +**--------------------------------------------------------------------------- +** Copyright 1998-2009 Randy Heit +** Copyright (C) 2007-2012 Skulltag Development Team +** Copyright (C) 2007-2016 Zandronum Development Team +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** 4. Redistributions in any form must be accompanied by information on how to +** obtain complete source code for the software and any accompanying software +** that uses the software. The source code must either be included in the +** distribution or be available for no more than the cost of distribution plus +** a nominal fee, and must be freely redistributable under reasonable +** conditions. For an executable file, complete source code means the source +** code for all modules it contains. It does not include source code for +** modules or files that typically accompany the major components of the +** operating system on which the executable file runs. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +#include +#include +#include +#include +#include +#include + +#include + +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#include +#include + +#include "hardware.h" +#include "printf.h" + +#include "version.h" +#include "i_sound.h" +#include "resource.h" +#include "stats.h" +#include "v_text.h" +#include "utf8.h" + +#include "d_main.h" +#include "d_net.h" +#include "g_game.h" +#include "i_input.h" +#include "c_dispatch.h" +#include "templates.h" +#include "gameconfigfile.h" +#include "v_font.h" +#include "g_level.h" +#include "doomstat.h" +#include "i_system.h" +#include "bitmap.h" +#include "cmdlib.h" +#include "i_interface.h" + +//========================================================================== +// +// QueryPathKey +// +// Returns the value of a registry key into the output variable value. +// +//========================================================================== + +static bool QueryPathKey(HKEY key, const wchar_t *keypath, const wchar_t *valname, FString &value) +{ + HKEY pathkey; + DWORD pathtype; + DWORD pathlen; + LONG res; + + value = ""; + if(ERROR_SUCCESS == RegOpenKeyEx(key, keypath, 0, KEY_QUERY_VALUE, &pathkey)) + { + if (ERROR_SUCCESS == RegQueryValueEx(pathkey, valname, 0, &pathtype, NULL, &pathlen) && + pathtype == REG_SZ && pathlen != 0) + { + // Don't include terminating null in count + TArray chars(pathlen + 1, true); + res = RegQueryValueEx(pathkey, valname, 0, NULL, (LPBYTE)chars.Data(), &pathlen); + if (res == ERROR_SUCCESS) value = FString(chars.Data()); + } + RegCloseKey(pathkey); + } + return value.IsNotEmpty(); +} + +//========================================================================== +// +// I_GetGogPaths +// +// Check the registry for GOG installation paths, so we can search for IWADs +// that were bought from GOG.com. This is a bit different from the Steam +// version because each game has its own independent installation path, no +// such thing as /SteamApps/common/. +// +//========================================================================== + +TArray I_GetGogPaths() +{ + TArray result; + FString path; + std::wstring gamepath; + +#ifdef _WIN64 + std::wstring gogregistrypath = L"Software\\Wow6432Node\\GOG.com\\Games"; +#else + // If a 32-bit ZDoom runs on a 64-bit Windows, this will be transparently and + // automatically redirected to the Wow6432Node address instead, so this address + // should be safe to use in all cases. + std::wstring gogregistrypath = L"Software\\GOG.com\\Games"; +#endif + + // Look for Ultimate Doom + gamepath = gogregistrypath + L"\\1435827232"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + result.Push(path); // directly in install folder + } + + // Look for Doom II + gamepath = gogregistrypath + L"\\1435848814"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + result.Push(path + "/doom2"); // in a subdirectory + // If direct support for the Master Levels is ever added, they are in path + /master/wads + } + + // Look for Final Doom + gamepath = gogregistrypath + L"\\1435848742"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + // in subdirectories + result.Push(path + "/TNT"); + result.Push(path + "/Plutonia"); + } + + // Look for Doom 3: BFG Edition + gamepath = gogregistrypath + L"\\1135892318"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + result.Push(path + "/base/wads"); // in a subdirectory + } + + // Look for Strife: Veteran Edition + gamepath = gogregistrypath + L"\\1432899949"; + if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) + { + result.Push(path); // directly in install folder + } + + return result; +} + +//========================================================================== +// +// I_GetSteamPath +// +// Check the registry for the path to Steam, so that we can search for +// IWADs that were bought with Steam. +// +//========================================================================== + +TArray I_GetSteamPath() +{ + TArray result; + static const char *const steam_dirs[] = + { + "doom 2/base", + "final doom/base", + "heretic shadow of the serpent riders/base", + "hexen/base", + "hexen deathkings of the dark citadel/base", + "ultimate doom/base", + "DOOM 3 BFG Edition/base/wads", + "Strife" + }; + + FString path; + + if (!QueryPathKey(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", L"SteamPath", path)) + { + if (!QueryPathKey(HKEY_LOCAL_MACHINE, L"Software\\Valve\\Steam", L"InstallPath", path)) + return result; + } + path += "/SteamApps/common/"; + + for(unsigned int i = 0; i < countof(steam_dirs); ++i) + { + result.Push(path + steam_dirs[i]); + } + + return result; +} diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index 4a2ddcdf3c..48bf64541d 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -71,16 +71,11 @@ #include "v_text.h" #include "utf8.h" -#include "d_main.h" -#include "d_net.h" -#include "g_game.h" #include "i_input.h" #include "c_dispatch.h" #include "templates.h" #include "gameconfigfile.h" #include "v_font.h" -#include "g_level.h" -#include "doomstat.h" #include "i_system.h" #include "bitmap.h" #include "cmdlib.h" @@ -907,144 +902,6 @@ bool I_WriteIniFailed() return MessageBoxA(Window, errortext.GetChars(), GAMENAME " configuration not saved", MB_ICONEXCLAMATION | MB_RETRYCANCEL) == IDRETRY; } -//========================================================================== -// -// QueryPathKey -// -// Returns the value of a registry key into the output variable value. -// -//========================================================================== - -static bool QueryPathKey(HKEY key, const wchar_t *keypath, const wchar_t *valname, FString &value) -{ - HKEY pathkey; - DWORD pathtype; - DWORD pathlen; - LONG res; - - value = ""; - if(ERROR_SUCCESS == RegOpenKeyEx(key, keypath, 0, KEY_QUERY_VALUE, &pathkey)) - { - if (ERROR_SUCCESS == RegQueryValueEx(pathkey, valname, 0, &pathtype, NULL, &pathlen) && - pathtype == REG_SZ && pathlen != 0) - { - // Don't include terminating null in count - TArray chars(pathlen + 1, true); - res = RegQueryValueEx(pathkey, valname, 0, NULL, (LPBYTE)chars.Data(), &pathlen); - if (res == ERROR_SUCCESS) value = FString(chars.Data()); - } - RegCloseKey(pathkey); - } - return value.IsNotEmpty(); -} - -//========================================================================== -// -// I_GetGogPaths -// -// Check the registry for GOG installation paths, so we can search for IWADs -// that were bought from GOG.com. This is a bit different from the Steam -// version because each game has its own independent installation path, no -// such thing as /SteamApps/common/. -// -//========================================================================== - -TArray I_GetGogPaths() -{ - TArray result; - FString path; - std::wstring gamepath; - -#ifdef _WIN64 - std::wstring gogregistrypath = L"Software\\Wow6432Node\\GOG.com\\Games"; -#else - // If a 32-bit ZDoom runs on a 64-bit Windows, this will be transparently and - // automatically redirected to the Wow6432Node address instead, so this address - // should be safe to use in all cases. - std::wstring gogregistrypath = L"Software\\GOG.com\\Games"; -#endif - - // Look for Ultimate Doom - gamepath = gogregistrypath + L"\\1435827232"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - result.Push(path); // directly in install folder - } - - // Look for Doom II - gamepath = gogregistrypath + L"\\1435848814"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - result.Push(path + "/doom2"); // in a subdirectory - // If direct support for the Master Levels is ever added, they are in path + /master/wads - } - - // Look for Final Doom - gamepath = gogregistrypath + L"\\1435848742"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - // in subdirectories - result.Push(path + "/TNT"); - result.Push(path + "/Plutonia"); - } - - // Look for Doom 3: BFG Edition - gamepath = gogregistrypath + L"\\1135892318"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - result.Push(path + "/base/wads"); // in a subdirectory - } - - // Look for Strife: Veteran Edition - gamepath = gogregistrypath + L"\\1432899949"; - if (QueryPathKey(HKEY_LOCAL_MACHINE, gamepath.c_str(), L"Path", path)) - { - result.Push(path); // directly in install folder - } - - return result; -} - -//========================================================================== -// -// I_GetSteamPath -// -// Check the registry for the path to Steam, so that we can search for -// IWADs that were bought with Steam. -// -//========================================================================== - -TArray I_GetSteamPath() -{ - TArray result; - static const char *const steam_dirs[] = - { - "doom 2/base", - "final doom/base", - "heretic shadow of the serpent riders/base", - "hexen/base", - "hexen deathkings of the dark citadel/base", - "ultimate doom/base", - "DOOM 3 BFG Edition/base/wads", - "Strife" - }; - - FString path; - - if (!QueryPathKey(HKEY_CURRENT_USER, L"Software\\Valve\\Steam", L"SteamPath", path)) - { - if (!QueryPathKey(HKEY_LOCAL_MACHINE, L"Software\\Valve\\Steam", L"InstallPath", path)) - return result; - } - path += "/SteamApps/common/"; - - for(unsigned int i = 0; i < countof(steam_dirs); ++i) - { - result.Push(path + steam_dirs[i]); - } - - return result; -} //========================================================================== // diff --git a/src/win32/i_system.h b/src/win32/i_system.h index cf2673717d..1e27a0368b 100644 --- a/src/win32/i_system.h +++ b/src/win32/i_system.h @@ -22,40 +22,9 @@ void CalculateCPUSpeed (void); unsigned int I_MakeRNGSeed(); -// -// Called by D_DoomLoop, -// called before processing any tics in a frame -// (just after displaying a frame). -// Time consuming syncronous operations -// are performed here (joystick reading). -// Can call D_PostEvent. -// void I_StartFrame (void); - - -// -// Called by D_DoomLoop, -// called before processing each tic in a frame. -// Quick syncronous operations are performed here. -// Can call D_PostEvent. void I_StartTic (void); -// Asynchronous interrupt functions should maintain private queues -// that are read by the synchronous functions -// to be converted into events. - -// Either returns a null ticcmd, -// or calls a loadable driver to build it. -// This ticcmd will then be modified by the gameloop -// for normal input. -ticcmd_t *I_BaseTiccmd (void); - - -// Called by M_Responder when quit is selected. -// Clean exit, displays sell blurb. -void I_Quit (void); - - // Set the mouse cursor. The texture must be 32x32. class FGameTexture; bool I_SetCursor(FGameTexture *cursor); From ea30707c41ea0ab6a9b1ce7352b8af768840f47f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 22 Apr 2020 23:48:20 +0200 Subject: [PATCH 078/220] - added missing include. --- src/posix/unix/gtk_dialogs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/posix/unix/gtk_dialogs.cpp b/src/posix/unix/gtk_dialogs.cpp index b5fbfdd386..6a3042e440 100644 --- a/src/posix/unix/gtk_dialogs.cpp +++ b/src/posix/unix/gtk_dialogs.cpp @@ -61,6 +61,7 @@ typedef enum #include "startupinfo.h" #include "cmdlib.h" #include "i_interface.h" +#include "printf.h" EXTERN_CVAR (Bool, queryiwad); From 612bf2080985d88c553c4d958e422d0438aa1935 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 23 Apr 2020 00:02:34 +0200 Subject: [PATCH 079/220] - moved game state connections of the startup screen out of the backend code. --- src/common/engine/i_interface.cpp | 3 ++- src/common/engine/i_interface.h | 1 + src/d_main.cpp | 22 ++++++++++++++++++++++ src/win32/st_start.cpp | 20 ++++++++------------ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/common/engine/i_interface.cpp b/src/common/engine/i_interface.cpp index 7fc82c4cc5..73d06ff041 100644 --- a/src/common/engine/i_interface.cpp +++ b/src/common/engine/i_interface.cpp @@ -1,4 +1,5 @@ #include "i_interface.h" SystemCallbacks *sysCallbacks; -double refreshfreq; \ No newline at end of file +double refreshfreq; +FString endoomName; diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index 134cae975a..77f223806a 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -22,3 +22,4 @@ struct WadStuff }; +extern FString endoomName; diff --git a/src/d_main.cpp b/src/d_main.cpp index eaae9b22e0..bc664e4d32 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2958,6 +2958,8 @@ static int D_DoomMain_Internal (void) gameinfo.nokeyboardcheats = iwad_info->nokeyboardcheats; gameinfo.ConfigName = iwad_info->Configname; lastIWAD = iwad; + endoomName = gameinfo.Endoom; + if ((gameinfo.flags & GI_SHAREWARE) && pwads.Size() > 0) { @@ -3098,6 +3100,26 @@ static int D_DoomMain_Internal (void) if (!batchrun) Printf ("ST_Init: Init startup screen.\n"); if (!restart) { + if (GameStartupInfo.Type == FStartupInfo::DefaultStartup) + { + switch (gameinfo.gametype) + { + case GAME_Hexen: + GameStartupInfo.Type = FStartupInfo::HexenStartup; + break; + + case GAME_Heretic: + GameStartupInfo.Type = FStartupInfo::HereticStartup; + break; + + case GAME_Strife: + GameStartupInfo.Type = FStartupInfo::StrifeStartup; + break; + + default: + break; + } + } StartScreen = FStartupScreen::CreateInstance (TexMan.GuesstimateNumTextures() + 5); } else diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp index 34e919bb4e..32aa3c1c68 100644 --- a/src/win32/st_start.cpp +++ b/src/win32/st_start.cpp @@ -45,17 +45,16 @@ #include "i_system.h" #include "i_input.h" #include "hardware.h" -#include "gi.h" #include "filesystem.h" -#include "s_sound.h" #include "m_argv.h" -#include "d_main.h" #include "engineerrors.h" #include "s_music.h" +#include "printf.h" +#include "startupinfo.h" +#include "i_interface.h" // MACROS ------------------------------------------------------------------ - // How many ms elapse between blinking text flips. On a standard VGA // adapter, the characters are on for 16 frames and then off for another 16. // The number here therefore corresponds roughly to the blink rate on a @@ -117,18 +116,15 @@ FStartupScreen *FStartupScreen::CreateInstance(int max_progress) if (!Args->CheckParm("-nostartup")) { - if (GameStartupInfo.Type == FStartupInfo::HexenStartup || - (gameinfo.gametype == GAME_Hexen && GameStartupInfo.Type == FStartupInfo::DefaultStartup)) + if (GameStartupInfo.Type == FStartupInfo::HexenStartup) { scr = new FHexenStartupScreen(max_progress, hr); } - else if (GameStartupInfo.Type == FStartupInfo::HereticStartup || - (gameinfo.gametype == GAME_Heretic && GameStartupInfo.Type == FStartupInfo::DefaultStartup)) + else if (GameStartupInfo.Type == FStartupInfo::HereticStartup) { scr = new FHereticStartupScreen(max_progress, hr); } - else if (GameStartupInfo.Type == FStartupInfo::StrifeStartup || - (gameinfo.gametype == GAME_Strife && GameStartupInfo.Type == FStartupInfo::DefaultStartup)) + else if (GameStartupInfo.Type == FStartupInfo::StrifeStartup) { scr = new FStrifeStartupScreen(max_progress, hr); } @@ -512,12 +508,12 @@ void FStrifeStartupScreen::SetWindowSize() int RunEndoom() { - if (showendoom == 0 || gameinfo.Endoom.Len() == 0) + if (showendoom == 0 || endoomName.Len() == 0) { return 0; } - int endoom_lump = fileSystem.CheckNumForFullName (gameinfo.Endoom, true); + int endoom_lump = fileSystem.CheckNumForFullName (endoomName, true); uint8_t endoom_screen[4000]; uint8_t *font; From 0b544f295699d9bfbed01bbde3e80c159ef3d64e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 23 Apr 2020 21:48:50 +0200 Subject: [PATCH 080/220] - moved the Posix platform files to 'common' after making sure that Raze can compiled with them as-is. No content changes. --- src/CMakeLists.txt | 64 +++++++++---------- src/common/audio/sound/i_soundinternal.h | 1 + src/{ => common/engine}/g_input.h | 0 .../platform}/posix/cocoa/gl_sysfb.h | 0 .../platform}/posix/cocoa/i_common.h | 0 .../platform}/posix/cocoa/i_input.mm | 0 .../platform}/posix/cocoa/i_joystick.cpp | 0 .../platform}/posix/cocoa/i_main.mm | 0 .../platform}/posix/cocoa/i_system.mm | 0 .../platform}/posix/cocoa/i_video.mm | 0 .../platform}/posix/cocoa/st_console.h | 0 .../platform}/posix/cocoa/st_console.mm | 0 .../platform}/posix/cocoa/st_start.mm | 0 src/{ => common/platform}/posix/dikeys.h | 0 src/{ => common/platform}/posix/hardware.h | 0 src/{ => common/platform}/posix/i_system.h | 0 .../platform}/posix/i_system_posix.cpp | 0 .../platform}/posix/osx/i_specialpaths.mm | 0 .../platform}/posix/osx/iwadpicker_cocoa.mm | 0 src/{ => common/platform}/posix/readme.md | 0 .../platform}/posix/sdl/crashcatcher.c | 0 .../platform}/posix/sdl/gl_sysfb.h | 0 .../platform}/posix/sdl/hardware.cpp | 0 src/{ => common/platform}/posix/sdl/i_gui.cpp | 0 .../platform}/posix/sdl/i_input.cpp | 0 .../platform}/posix/sdl/i_joystick.cpp | 0 .../platform}/posix/sdl/i_main.cpp | 0 .../platform}/posix/sdl/i_system.cpp | 0 .../platform}/posix/sdl/i_system.mm | 0 .../platform}/posix/sdl/sdlglvideo.cpp | 0 .../platform}/posix/sdl/st_start.cpp | 0 .../platform}/posix/unix/gtk_dialogs.cpp | 0 .../platform}/posix/unix/i_specialpaths.cpp | 0 33 files changed, 33 insertions(+), 32 deletions(-) rename src/{ => common/engine}/g_input.h (100%) rename src/{ => common/platform}/posix/cocoa/gl_sysfb.h (100%) rename src/{ => common/platform}/posix/cocoa/i_common.h (100%) rename src/{ => common/platform}/posix/cocoa/i_input.mm (100%) rename src/{ => common/platform}/posix/cocoa/i_joystick.cpp (100%) rename src/{ => common/platform}/posix/cocoa/i_main.mm (100%) rename src/{ => common/platform}/posix/cocoa/i_system.mm (100%) rename src/{ => common/platform}/posix/cocoa/i_video.mm (100%) rename src/{ => common/platform}/posix/cocoa/st_console.h (100%) rename src/{ => common/platform}/posix/cocoa/st_console.mm (100%) rename src/{ => common/platform}/posix/cocoa/st_start.mm (100%) rename src/{ => common/platform}/posix/dikeys.h (100%) rename src/{ => common/platform}/posix/hardware.h (100%) rename src/{ => common/platform}/posix/i_system.h (100%) rename src/{ => common/platform}/posix/i_system_posix.cpp (100%) rename src/{ => common/platform}/posix/osx/i_specialpaths.mm (100%) rename src/{ => common/platform}/posix/osx/iwadpicker_cocoa.mm (100%) rename src/{ => common/platform}/posix/readme.md (100%) rename src/{ => common/platform}/posix/sdl/crashcatcher.c (100%) rename src/{ => common/platform}/posix/sdl/gl_sysfb.h (100%) rename src/{ => common/platform}/posix/sdl/hardware.cpp (100%) rename src/{ => common/platform}/posix/sdl/i_gui.cpp (100%) rename src/{ => common/platform}/posix/sdl/i_input.cpp (100%) rename src/{ => common/platform}/posix/sdl/i_joystick.cpp (100%) rename src/{ => common/platform}/posix/sdl/i_main.cpp (100%) rename src/{ => common/platform}/posix/sdl/i_system.cpp (100%) rename src/{ => common/platform}/posix/sdl/i_system.mm (100%) rename src/{ => common/platform}/posix/sdl/sdlglvideo.cpp (100%) rename src/{ => common/platform}/posix/sdl/st_start.cpp (100%) rename src/{ => common/platform}/posix/unix/gtk_dialogs.cpp (100%) rename src/{ => common/platform}/posix/unix/i_specialpaths.cpp (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 35cd655925..7ae6248e93 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -464,32 +464,32 @@ endif() set( PLAT_POSIX_SOURCES posix/i_steam.cpp - posix/i_system_posix.cpp ) + common/platform/posix/i_system_posix.cpp ) set( PLAT_SDL_SOURCES - posix/sdl/crashcatcher.c - posix/sdl/hardware.cpp - posix/sdl/i_gui.cpp - posix/sdl/i_input.cpp - posix/sdl/i_joystick.cpp - posix/sdl/i_main.cpp - posix/sdl/i_system.cpp - posix/sdl/sdlglvideo.cpp - posix/sdl/st_start.cpp ) + common/platform/posix/sdl/crashcatcher.c + common/platform/posix/sdl/hardware.cpp + common/platform/posix/sdl/i_gui.cpp + common/platform/posix/sdl/i_input.cpp + common/platform/posix/sdl/i_joystick.cpp + common/platform/posix/sdl/i_main.cpp + common/platform/posix/sdl/i_system.cpp + common/platform/posix/sdl/sdlglvideo.cpp + common/platform/posix/sdl/st_start.cpp ) set( PLAT_UNIX_SOURCES - posix/unix/i_specialpaths.cpp - posix/unix/gtk_dialogs.cpp ) + common/platform/posix/unix/i_specialpaths.cpp + common/platform/posix/unix/gtk_dialogs.cpp ) set( PLAT_OSX_SOURCES - posix/osx/iwadpicker_cocoa.mm - posix/osx/i_specialpaths.mm + common/platform/posix/osx/iwadpicker_cocoa.mm + common/platform/posix/osx/i_specialpaths.mm posix/osx/zdoom.icns ) set( PLAT_COCOA_SOURCES - posix/cocoa/i_input.mm - posix/cocoa/i_joystick.cpp - posix/cocoa/i_main.mm - posix/cocoa/i_system.mm - posix/cocoa/i_video.mm - posix/cocoa/st_console.mm - posix/cocoa/st_start.mm ) + common/platform/posix/cocoa/i_input.mm + common/platform/posix/cocoa/i_joystick.cpp + common/platform/posix/cocoa/i_main.mm + common/platform/posix/cocoa/i_system.mm + common/platform/posix/cocoa/i_video.mm + common/platform/posix/cocoa/st_console.mm + common/platform/posix/cocoa/st_start.mm ) if( WIN32 ) set( SYSTEM_SOURCES_DIR win32 ) @@ -499,22 +499,22 @@ if( WIN32 ) set( SYSTEM_SOURCES ${SYSTEM_SOURCES} win32/zdoom.rc ) elseif( APPLE ) if( OSX_COCOA_BACKEND ) - set( SYSTEM_SOURCES_DIR posix posix/cocoa ) + set( SYSTEM_SOURCES_DIR common/platform/posix common/platform/posix/cocoa ) set( SYSTEM_SOURCES ${PLAT_COCOA_SOURCES} ) set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_UNIX_SOURCES} ) else() - set( SYSTEM_SOURCES_DIR posix posix/sdl ) + set( SYSTEM_SOURCES_DIR common/platform/posix common/platform/posix/sdl ) set( SYSTEM_SOURCES ${PLAT_SDL_SOURCES} ) - set( PLAT_OSX_SOURCES ${PLAT_OSX_SOURCES} posix/sdl/i_system.mm ) + set( PLAT_OSX_SOURCES ${PLAT_OSX_SOURCES} common/platform/posix/sdl/i_system.mm ) set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_COCOA_SOURCES} ${PLAT_UNIX_SOURCES} ) endif() set( SYSTEM_SOURCES ${SYSTEM_SOURCES} ${PLAT_POSIX_SOURCES} ${PLAT_OSX_SOURCES} ) set_source_files_properties( posix/osx/zdoom.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources ) - set_source_files_properties( posix/osx/iwadpicker_cocoa.mm PROPERTIES COMPILE_FLAGS -fobjc-exceptions ) + set_source_files_properties( common/platform/posix/osx/iwadpicker_cocoa.mm PROPERTIES COMPILE_FLAGS -fobjc-exceptions ) else() - set( SYSTEM_SOURCES_DIR posix posix/sdl ) + set( SYSTEM_SOURCES_DIR common/platform/posix common/platform/posix/sdl ) set( SYSTEM_SOURCES ${PLAT_POSIX_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_UNIX_SOURCES} ) set( OTHER_SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ${PLAT_OSX_SOURCES} ${PLAT_COCOA_SOURCES} ) endif() @@ -594,8 +594,6 @@ file( GLOB HEADER_FILES sound/*.h sound/backend/*.h* posix/*.h - posix/cocoa/*.h - posix/sdl/*.h win32/*.h r_data/*.h r_data/models/*.h @@ -610,6 +608,8 @@ file( GLOB HEADER_FILES common/fonts/*.h common/objects/*.h common/filesystem/*.h + common/platform/posix/cocoa/*.h + common/platform/posix/sdl/*.h common/textures/*.h common/textures/hires/hqnx/*.h common/textures/hires/hqnx_asm/*.h @@ -1441,10 +1441,6 @@ source_group("Render Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r_da source_group("Render Data\\Models" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r_data/models/.+") source_group("Render Interface" FILES r_defs.h r_renderer.h r_sky.cpp r_sky.h r_state.h r_utility.cpp r_utility.h) source_group("Platforms\\POSIX Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/.+") -source_group("Platforms\\Cocoa Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/cocoa/.+") -source_group("Platforms\\OS X Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/osx/.+") -source_group("Platforms\\Unix Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/unix/.+") -source_group("Platforms\\SDL Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/sdl/.+") source_group("Platforms\\Win32 Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/win32/.+") source_group("Scripting\\Decorate frontend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/decorate/.+") source_group("Scripting\\ZScript frontend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/scripting/zscript/.+") @@ -1470,6 +1466,10 @@ source_group("Common\\Scripting\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_S source_group("Common\\Scripting\\Core" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/core/.+") source_group("Common\\Scripting\\JIT" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/jit/.+") source_group("Common\\Scripting\\VM" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/scripting/vm/.+") +source_group("Common\\Platforms\\Cocoa Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/cocoa/.+") +source_group("Common\\Platforms\\OS X Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/osx/.+") +source_group("Common\\Platforms\\Unix Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/unix/.+") +source_group("Common\\Platforms\\SDL Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/sdl/.+") source_group("Common\\Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/.+") source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+") source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+") diff --git a/src/common/audio/sound/i_soundinternal.h b/src/common/audio/sound/i_soundinternal.h index 36ccd52c0d..be3486440f 100644 --- a/src/common/audio/sound/i_soundinternal.h +++ b/src/common/audio/sound/i_soundinternal.h @@ -146,4 +146,5 @@ class SoundStream; void S_SetSoundPaused(int state); + #endif diff --git a/src/g_input.h b/src/common/engine/g_input.h similarity index 100% rename from src/g_input.h rename to src/common/engine/g_input.h diff --git a/src/posix/cocoa/gl_sysfb.h b/src/common/platform/posix/cocoa/gl_sysfb.h similarity index 100% rename from src/posix/cocoa/gl_sysfb.h rename to src/common/platform/posix/cocoa/gl_sysfb.h diff --git a/src/posix/cocoa/i_common.h b/src/common/platform/posix/cocoa/i_common.h similarity index 100% rename from src/posix/cocoa/i_common.h rename to src/common/platform/posix/cocoa/i_common.h diff --git a/src/posix/cocoa/i_input.mm b/src/common/platform/posix/cocoa/i_input.mm similarity index 100% rename from src/posix/cocoa/i_input.mm rename to src/common/platform/posix/cocoa/i_input.mm diff --git a/src/posix/cocoa/i_joystick.cpp b/src/common/platform/posix/cocoa/i_joystick.cpp similarity index 100% rename from src/posix/cocoa/i_joystick.cpp rename to src/common/platform/posix/cocoa/i_joystick.cpp diff --git a/src/posix/cocoa/i_main.mm b/src/common/platform/posix/cocoa/i_main.mm similarity index 100% rename from src/posix/cocoa/i_main.mm rename to src/common/platform/posix/cocoa/i_main.mm diff --git a/src/posix/cocoa/i_system.mm b/src/common/platform/posix/cocoa/i_system.mm similarity index 100% rename from src/posix/cocoa/i_system.mm rename to src/common/platform/posix/cocoa/i_system.mm diff --git a/src/posix/cocoa/i_video.mm b/src/common/platform/posix/cocoa/i_video.mm similarity index 100% rename from src/posix/cocoa/i_video.mm rename to src/common/platform/posix/cocoa/i_video.mm diff --git a/src/posix/cocoa/st_console.h b/src/common/platform/posix/cocoa/st_console.h similarity index 100% rename from src/posix/cocoa/st_console.h rename to src/common/platform/posix/cocoa/st_console.h diff --git a/src/posix/cocoa/st_console.mm b/src/common/platform/posix/cocoa/st_console.mm similarity index 100% rename from src/posix/cocoa/st_console.mm rename to src/common/platform/posix/cocoa/st_console.mm diff --git a/src/posix/cocoa/st_start.mm b/src/common/platform/posix/cocoa/st_start.mm similarity index 100% rename from src/posix/cocoa/st_start.mm rename to src/common/platform/posix/cocoa/st_start.mm diff --git a/src/posix/dikeys.h b/src/common/platform/posix/dikeys.h similarity index 100% rename from src/posix/dikeys.h rename to src/common/platform/posix/dikeys.h diff --git a/src/posix/hardware.h b/src/common/platform/posix/hardware.h similarity index 100% rename from src/posix/hardware.h rename to src/common/platform/posix/hardware.h diff --git a/src/posix/i_system.h b/src/common/platform/posix/i_system.h similarity index 100% rename from src/posix/i_system.h rename to src/common/platform/posix/i_system.h diff --git a/src/posix/i_system_posix.cpp b/src/common/platform/posix/i_system_posix.cpp similarity index 100% rename from src/posix/i_system_posix.cpp rename to src/common/platform/posix/i_system_posix.cpp diff --git a/src/posix/osx/i_specialpaths.mm b/src/common/platform/posix/osx/i_specialpaths.mm similarity index 100% rename from src/posix/osx/i_specialpaths.mm rename to src/common/platform/posix/osx/i_specialpaths.mm diff --git a/src/posix/osx/iwadpicker_cocoa.mm b/src/common/platform/posix/osx/iwadpicker_cocoa.mm similarity index 100% rename from src/posix/osx/iwadpicker_cocoa.mm rename to src/common/platform/posix/osx/iwadpicker_cocoa.mm diff --git a/src/posix/readme.md b/src/common/platform/posix/readme.md similarity index 100% rename from src/posix/readme.md rename to src/common/platform/posix/readme.md diff --git a/src/posix/sdl/crashcatcher.c b/src/common/platform/posix/sdl/crashcatcher.c similarity index 100% rename from src/posix/sdl/crashcatcher.c rename to src/common/platform/posix/sdl/crashcatcher.c diff --git a/src/posix/sdl/gl_sysfb.h b/src/common/platform/posix/sdl/gl_sysfb.h similarity index 100% rename from src/posix/sdl/gl_sysfb.h rename to src/common/platform/posix/sdl/gl_sysfb.h diff --git a/src/posix/sdl/hardware.cpp b/src/common/platform/posix/sdl/hardware.cpp similarity index 100% rename from src/posix/sdl/hardware.cpp rename to src/common/platform/posix/sdl/hardware.cpp diff --git a/src/posix/sdl/i_gui.cpp b/src/common/platform/posix/sdl/i_gui.cpp similarity index 100% rename from src/posix/sdl/i_gui.cpp rename to src/common/platform/posix/sdl/i_gui.cpp diff --git a/src/posix/sdl/i_input.cpp b/src/common/platform/posix/sdl/i_input.cpp similarity index 100% rename from src/posix/sdl/i_input.cpp rename to src/common/platform/posix/sdl/i_input.cpp diff --git a/src/posix/sdl/i_joystick.cpp b/src/common/platform/posix/sdl/i_joystick.cpp similarity index 100% rename from src/posix/sdl/i_joystick.cpp rename to src/common/platform/posix/sdl/i_joystick.cpp diff --git a/src/posix/sdl/i_main.cpp b/src/common/platform/posix/sdl/i_main.cpp similarity index 100% rename from src/posix/sdl/i_main.cpp rename to src/common/platform/posix/sdl/i_main.cpp diff --git a/src/posix/sdl/i_system.cpp b/src/common/platform/posix/sdl/i_system.cpp similarity index 100% rename from src/posix/sdl/i_system.cpp rename to src/common/platform/posix/sdl/i_system.cpp diff --git a/src/posix/sdl/i_system.mm b/src/common/platform/posix/sdl/i_system.mm similarity index 100% rename from src/posix/sdl/i_system.mm rename to src/common/platform/posix/sdl/i_system.mm diff --git a/src/posix/sdl/sdlglvideo.cpp b/src/common/platform/posix/sdl/sdlglvideo.cpp similarity index 100% rename from src/posix/sdl/sdlglvideo.cpp rename to src/common/platform/posix/sdl/sdlglvideo.cpp diff --git a/src/posix/sdl/st_start.cpp b/src/common/platform/posix/sdl/st_start.cpp similarity index 100% rename from src/posix/sdl/st_start.cpp rename to src/common/platform/posix/sdl/st_start.cpp diff --git a/src/posix/unix/gtk_dialogs.cpp b/src/common/platform/posix/unix/gtk_dialogs.cpp similarity index 100% rename from src/posix/unix/gtk_dialogs.cpp rename to src/common/platform/posix/unix/gtk_dialogs.cpp diff --git a/src/posix/unix/i_specialpaths.cpp b/src/common/platform/posix/unix/i_specialpaths.cpp similarity index 100% rename from src/posix/unix/i_specialpaths.cpp rename to src/common/platform/posix/unix/i_specialpaths.cpp From f8e23500c73b9ba23a48f3cf0829593d22289f12 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 23 Apr 2020 22:26:30 +0200 Subject: [PATCH 081/220] - moved Windows platform code as well. --- src/CMakeLists.txt | 49 +++-- src/common/engine/i_interface.cpp | 3 + src/common/engine/i_interface.h | 1 + src/common/engine/st_start.h | 207 ++++++++++++++++++ src/common/engine/startupinfo.h | 1 + src/{ => common/platform}/win32/afxres.h | 0 .../platform}/win32/base_sysfb.cpp | 0 src/{ => common/platform}/win32/base_sysfb.h | 0 src/{ => common/platform}/win32/gl_sysfb.cpp | 0 src/{ => common/platform}/win32/gl_sysfb.h | 0 src/{ => common/platform}/win32/hardware.cpp | 0 src/{ => common/platform}/win32/hardware.h | 0 src/{ => common/platform}/win32/i_crash.cpp | 0 src/{ => common/platform}/win32/i_dijoy.cpp | 0 src/{ => common/platform}/win32/i_input.cpp | 0 src/{ => common/platform}/win32/i_input.h | 0 .../platform}/win32/i_keyboard.cpp | 0 src/{ => common/platform}/win32/i_main.cpp | 1 + src/{ => common/platform}/win32/i_mouse.cpp | 0 src/{ => common/platform}/win32/i_rawps2.cpp | 0 .../platform}/win32/i_specialpaths.cpp | 0 src/{ => common/platform}/win32/i_system.cpp | 0 src/{ => common/platform}/win32/i_system.h | 1 - src/{ => common/platform}/win32/i_xinput.cpp | 0 .../platform/win32/manifest.xml} | 0 src/{ => common/platform}/win32/resource.h | 0 src/{ => common/platform}/win32/st_start.cpp | 0 .../platform}/win32/st_start_util.cpp | 18 +- src/{ => common/platform}/win32/wglext.h | 0 .../platform}/win32/win32basevideo.cpp | 0 .../platform}/win32/win32basevideo.h | 0 .../platform}/win32/win32glvideo.cpp | 0 .../platform}/win32/win32glvideo.h | 0 .../platform}/win32/win32polyvideo.cpp | 4 + .../platform}/win32/win32polyvideo.h | 0 .../platform}/win32/win32vulkanvideo.cpp | 0 .../platform}/win32/win32vulkanvideo.h | 0 src/{ => common/platform}/win32/winres.h | 0 .../platform/win32/zutil.natvis} | 0 src/d_main.cpp | 3 - .../polyrenderer/backend/poly_framebuffer.cpp | 1 - src/win32/i_steam.cpp | 4 - src/win32/zdoom.rc | 2 +- 43 files changed, 255 insertions(+), 40 deletions(-) create mode 100644 src/common/engine/st_start.h rename src/{ => common/platform}/win32/afxres.h (100%) rename src/{ => common/platform}/win32/base_sysfb.cpp (100%) rename src/{ => common/platform}/win32/base_sysfb.h (100%) rename src/{ => common/platform}/win32/gl_sysfb.cpp (100%) rename src/{ => common/platform}/win32/gl_sysfb.h (100%) rename src/{ => common/platform}/win32/hardware.cpp (100%) rename src/{ => common/platform}/win32/hardware.h (100%) rename src/{ => common/platform}/win32/i_crash.cpp (100%) rename src/{ => common/platform}/win32/i_dijoy.cpp (100%) rename src/{ => common/platform}/win32/i_input.cpp (100%) rename src/{ => common/platform}/win32/i_input.h (100%) rename src/{ => common/platform}/win32/i_keyboard.cpp (100%) rename src/{ => common/platform}/win32/i_main.cpp (99%) rename src/{ => common/platform}/win32/i_mouse.cpp (100%) rename src/{ => common/platform}/win32/i_rawps2.cpp (100%) rename src/{ => common/platform}/win32/i_specialpaths.cpp (100%) rename src/{ => common/platform}/win32/i_system.cpp (100%) rename src/{ => common/platform}/win32/i_system.h (99%) rename src/{ => common/platform}/win32/i_xinput.cpp (100%) rename src/{win32/zdoom.exe.manifest => common/platform/win32/manifest.xml} (100%) rename src/{ => common/platform}/win32/resource.h (100%) rename src/{ => common/platform}/win32/st_start.cpp (100%) rename src/{ => common/platform}/win32/st_start_util.cpp (99%) rename src/{ => common/platform}/win32/wglext.h (100%) rename src/{ => common/platform}/win32/win32basevideo.cpp (100%) rename src/{ => common/platform}/win32/win32basevideo.h (100%) rename src/{ => common/platform}/win32/win32glvideo.cpp (100%) rename src/{ => common/platform}/win32/win32glvideo.h (100%) rename src/{ => common/platform}/win32/win32polyvideo.cpp (99%) rename src/{ => common/platform}/win32/win32polyvideo.h (100%) rename src/{ => common/platform}/win32/win32vulkanvideo.cpp (100%) rename src/{ => common/platform}/win32/win32vulkanvideo.h (100%) rename src/{ => common/platform}/win32/winres.h (100%) rename src/{win32/zdoom.natvis => common/platform/win32/zutil.natvis} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7ae6248e93..c391b83b52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -438,28 +438,28 @@ endif() # Start defining source files for ZDoom set( PLAT_WIN32_SOURCES - win32/hardware.cpp - win32/i_crash.cpp - win32/i_input.cpp - win32/i_keyboard.cpp - win32/i_mouse.cpp - win32/i_dijoy.cpp - win32/i_rawps2.cpp - win32/i_xinput.cpp - win32/i_main.cpp win32/i_steam.cpp - win32/i_system.cpp - win32/i_specialpaths.cpp - win32/st_start.cpp - win32/st_start_util.cpp - win32/gl_sysfb.cpp - win32/base_sysfb.cpp - win32/win32basevideo.cpp - win32/win32glvideo.cpp - win32/win32polyvideo.cpp) - + common/platform/win32/hardware.cpp + common/platform/win32/i_crash.cpp + common/platform/win32/i_input.cpp + common/platform/win32/i_keyboard.cpp + common/platform/win32/i_mouse.cpp + common/platform/win32/i_dijoy.cpp + common/platform/win32/i_rawps2.cpp + common/platform/win32/i_xinput.cpp + common/platform/win32/i_main.cpp + common/platform/win32/i_system.cpp + common/platform/win32/i_specialpaths.cpp + common/platform/win32/st_start.cpp + common/platform/win32/st_start_util.cpp + common/platform/win32/gl_sysfb.cpp + common/platform/win32/base_sysfb.cpp + common/platform/win32/win32basevideo.cpp + common/platform/win32/win32glvideo.cpp + common/platform/win32/win32polyvideo.cpp) + if (HAVE_VULKAN) - set (PLAT_WIN32_SOURCES ${PLAT_WIN32_SOURCES} win32/win32vulkanvideo.cpp ) + set (PLAT_WIN32_SOURCES ${PLAT_WIN32_SOURCES} common/platform/win32/win32vulkanvideo.cpp ) endif() set( PLAT_POSIX_SOURCES @@ -492,7 +492,7 @@ set( PLAT_COCOA_SOURCES common/platform/posix/cocoa/st_start.mm ) if( WIN32 ) - set( SYSTEM_SOURCES_DIR win32 ) + set( SYSTEM_SOURCES_DIR common/platform/win32 ) set( SYSTEM_SOURCES ${PLAT_WIN32_SOURCES} ) set( OTHER_SYSTEM_SOURCES ${PLAT_POSIX_SOURCES} ${PLAT_SDL_SOURCES} ${PLAT_OSX_SOURCES} ${PLAT_COCOA_SOURCES} ${PLAT_UNIX_SOURCES} ) @@ -594,7 +594,6 @@ file( GLOB HEADER_FILES sound/*.h sound/backend/*.h* posix/*.h - win32/*.h r_data/*.h r_data/models/*.h common/audio/sound/thirdparty/*.h @@ -610,6 +609,7 @@ file( GLOB HEADER_FILES common/filesystem/*.h common/platform/posix/cocoa/*.h common/platform/posix/sdl/*.h + common/platform/win32/*.h common/textures/*.h common/textures/hires/hqnx/*.h common/textures/hires/hqnx_asm/*.h @@ -738,7 +738,7 @@ set( NOT_COMPILED_SOURCE_FILES common/scripting/frontend/zcc-parse.lemon zcc-parse.c zcc-parse.h - win32/zdoom.natvis + common/platform/win32/zutil.natvis ) set( VM_JIT_SOURCES @@ -1321,7 +1321,7 @@ if( MSVC ) set_target_properties(zdoom PROPERTIES LINK_FLAGS ${LINKERSTUFF}) add_custom_command(TARGET zdoom POST_BUILD - COMMAND "mt.exe" -manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\win32\\zdoom.exe.manifest\" -outputresource:\"$\"\;\#1 + COMMAND "mt.exe" -manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\common\\platform\\win32\\manifest.xml\" -outputresource:\"$\"\;\#1 COMMENT "Adding manifest..." ) @@ -1470,6 +1470,7 @@ source_group("Common\\Platforms\\Cocoa Files" REGULAR_EXPRESSION "^${CMAKE_CURRE source_group("Common\\Platforms\\OS X Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/osx/.+") source_group("Common\\Platforms\\Unix Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/unix/.+") source_group("Common\\Platforms\\SDL Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/sdl/.+") +source_group("Common\\Platforms\\Win32 Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/win32/.+") source_group("Common\\Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/.+") source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+") source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+") diff --git a/src/common/engine/i_interface.cpp b/src/common/engine/i_interface.cpp index 73d06ff041..803317a81f 100644 --- a/src/common/engine/i_interface.cpp +++ b/src/common/engine/i_interface.cpp @@ -1,5 +1,8 @@ #include "i_interface.h" +// Some global engine variables taken out of the backend code. SystemCallbacks *sysCallbacks; double refreshfreq; FString endoomName; +bool batchrun; + diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index 77f223806a..c862feb20f 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -23,3 +23,4 @@ struct WadStuff extern FString endoomName; +extern bool batchrun; diff --git a/src/common/engine/st_start.h b/src/common/engine/st_start.h new file mode 100644 index 0000000000..5b8edad4b1 --- /dev/null +++ b/src/common/engine/st_start.h @@ -0,0 +1,207 @@ +#pragma once +/* +** st_start.h +** Interface for the startup screen. +** +**--------------------------------------------------------------------------- +** Copyright 2006-2007 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** The startup screen interface is based on a mix of Heretic and Hexen. +** Actual implementation is system-specific. +*/ +#include + +class FStartupScreen +{ +public: + static FStartupScreen *CreateInstance(int max_progress); + + FStartupScreen(int max_progress) + { + MaxPos = max_progress; + CurPos = 0; + NotchPos = 0; + } + + virtual ~FStartupScreen() = default; + + virtual void Progress() {} + + virtual void NetInit(const char *message, int num_players) {} + virtual void NetProgress(int count) {} + virtual void NetMessage(const char *format, ...) {} // cover for printf + virtual void NetDone() {} + virtual bool NetLoop(bool (*timer_callback)(void *), void *userdata) { return false; } +protected: + int MaxPos, CurPos, NotchPos; +}; + +class FBasicStartupScreen : public FStartupScreen +{ +public: + FBasicStartupScreen(int max_progress, bool show_bar); + ~FBasicStartupScreen(); + + void Progress(); + void NetInit(const char* message, int num_players); + void NetProgress(int count); + void NetMessage(const char* format, ...); // cover for printf + void NetDone(); + bool NetLoop(bool (*timer_callback)(void*), void* userdata); +protected: + long long NetMarqueeMode; + int NetMaxPos, NetCurPos; +}; + +class FGraphicalStartupScreen : public FBasicStartupScreen +{ +public: + FGraphicalStartupScreen(int max_progress); + ~FGraphicalStartupScreen(); +}; + +class FHereticStartupScreen : public FGraphicalStartupScreen +{ +public: + FHereticStartupScreen(int max_progress, long &hr); + + void Progress(); + void LoadingStatus(const char *message, int colors); + void AppendStatusLine(const char *status); +protected: + void SetWindowSize(); + + int ThermX, ThermY, ThermWidth, ThermHeight; + int HMsgY, SMsgX; +}; + +class FHexenStartupScreen : public FGraphicalStartupScreen +{ +public: + FHexenStartupScreen(int max_progress, long &hr); + ~FHexenStartupScreen(); + + void Progress(); + void NetProgress(int count); + void NetDone(); + void SetWindowSize(); + + // Hexen's notch graphics, converted to chunky pixels. + uint8_t * NotchBits; + uint8_t * NetNotchBits; +}; + +class FStrifeStartupScreen : public FGraphicalStartupScreen +{ +public: + FStrifeStartupScreen(int max_progress, long &hr); + ~FStrifeStartupScreen(); + + void Progress(); +protected: + void DrawStuff(int old_laser, int new_laser); + void SetWindowSize(); + + uint8_t *StartupPics[4+2+1]; +}; + + + +extern FStartupScreen *StartScreen; + +void DeleteStartupScreen(); +extern void ST_Endoom(); + +// The entire set of functions here uses native Windows types. These are recreations of those types so that the code doesn't need to be changed more than necessary + +struct BitmapInfoHeader +{ + uint32_t biSize; + int32_t biWidth; + int32_t biHeight; + uint16_t biPlanes; + uint16_t biBitCount; + uint32_t biCompression; + uint32_t biSizeImage; + int32_t biXPelsPerMeter; + int32_t biYPelsPerMeter; + uint32_t biClrUsed; + uint32_t biClrImportant; +}; + +struct RgbQuad +{ + uint8_t rgbBlue; + uint8_t rgbGreen; + uint8_t rgbRed; + uint8_t rgbReserved; +}; + + +struct BitmapInfo +{ + BitmapInfoHeader bmiHeader; + RgbQuad bmiColors[1]; +}; + +extern BitmapInfo* StartupBitmap; + + +void ST_Util_PlanarToChunky4(uint8_t* dest, const uint8_t* src, int width, int height); +void ST_Util_DrawBlock(BitmapInfo* bitmap_info, const uint8_t* src, int x, int y, int bytewidth, int height); +void ST_Util_ClearBlock(BitmapInfo* bitmap_info, uint8_t fill, int x, int y, int bytewidth, int height); +BitmapInfo* ST_Util_CreateBitmap(int width, int height, int color_bits); +uint8_t* ST_Util_BitsForBitmap(BitmapInfo* bitmap_info); +void ST_Util_FreeBitmap(BitmapInfo* bitmap_info); +void ST_Util_BitmapColorsFromPlaypal(BitmapInfo* bitmap_info); +uint8_t* ST_Util_LoadFont(const char* filename); +void ST_Util_FreeFont(uint8_t* font); +BitmapInfo* ST_Util_AllocTextBitmap(const uint8_t* font); +void ST_Util_DrawTextScreen(BitmapInfo* bitmap_info, const uint8_t* text_screen, const uint8_t* font); +void ST_Util_DrawChar(BitmapInfo* screen, const uint8_t* font, int x, int y, uint8_t charnum, uint8_t attrib); +void ST_Util_UpdateTextBlink(BitmapInfo* bitmap_info, const uint8_t* text_screen, const uint8_t* font, bool on); + + +//=========================================================================== +// +// DeleteStartupScreen +// +// Makes sure the startup screen has been deleted before quitting. +// +//=========================================================================== + +inline void DeleteStartupScreen() +{ + if (StartScreen != nullptr) + { + delete StartScreen; + StartScreen = nullptr; + } +} + + diff --git a/src/common/engine/startupinfo.h b/src/common/engine/startupinfo.h index 53f79e8800..9cf9724fde 100644 --- a/src/common/engine/startupinfo.h +++ b/src/common/engine/startupinfo.h @@ -12,6 +12,7 @@ struct FStartupInfo int Type; int LoadLights = -1; int LoadBrightmaps = -1; + int modern = -1; enum { DefaultStartup, diff --git a/src/win32/afxres.h b/src/common/platform/win32/afxres.h similarity index 100% rename from src/win32/afxres.h rename to src/common/platform/win32/afxres.h diff --git a/src/win32/base_sysfb.cpp b/src/common/platform/win32/base_sysfb.cpp similarity index 100% rename from src/win32/base_sysfb.cpp rename to src/common/platform/win32/base_sysfb.cpp diff --git a/src/win32/base_sysfb.h b/src/common/platform/win32/base_sysfb.h similarity index 100% rename from src/win32/base_sysfb.h rename to src/common/platform/win32/base_sysfb.h diff --git a/src/win32/gl_sysfb.cpp b/src/common/platform/win32/gl_sysfb.cpp similarity index 100% rename from src/win32/gl_sysfb.cpp rename to src/common/platform/win32/gl_sysfb.cpp diff --git a/src/win32/gl_sysfb.h b/src/common/platform/win32/gl_sysfb.h similarity index 100% rename from src/win32/gl_sysfb.h rename to src/common/platform/win32/gl_sysfb.h diff --git a/src/win32/hardware.cpp b/src/common/platform/win32/hardware.cpp similarity index 100% rename from src/win32/hardware.cpp rename to src/common/platform/win32/hardware.cpp diff --git a/src/win32/hardware.h b/src/common/platform/win32/hardware.h similarity index 100% rename from src/win32/hardware.h rename to src/common/platform/win32/hardware.h diff --git a/src/win32/i_crash.cpp b/src/common/platform/win32/i_crash.cpp similarity index 100% rename from src/win32/i_crash.cpp rename to src/common/platform/win32/i_crash.cpp diff --git a/src/win32/i_dijoy.cpp b/src/common/platform/win32/i_dijoy.cpp similarity index 100% rename from src/win32/i_dijoy.cpp rename to src/common/platform/win32/i_dijoy.cpp diff --git a/src/win32/i_input.cpp b/src/common/platform/win32/i_input.cpp similarity index 100% rename from src/win32/i_input.cpp rename to src/common/platform/win32/i_input.cpp diff --git a/src/win32/i_input.h b/src/common/platform/win32/i_input.h similarity index 100% rename from src/win32/i_input.h rename to src/common/platform/win32/i_input.h diff --git a/src/win32/i_keyboard.cpp b/src/common/platform/win32/i_keyboard.cpp similarity index 100% rename from src/win32/i_keyboard.cpp rename to src/common/platform/win32/i_keyboard.cpp diff --git a/src/win32/i_main.cpp b/src/common/platform/win32/i_main.cpp similarity index 99% rename from src/win32/i_main.cpp rename to src/common/platform/win32/i_main.cpp index d4deb33bf9..0eaceba726 100644 --- a/src/win32/i_main.cpp +++ b/src/common/platform/win32/i_main.cpp @@ -75,6 +75,7 @@ #include "st_start.h" #include "i_interface.h" #include "startupinfo.h" +#include "printf.h" // MACROS ------------------------------------------------------------------ diff --git a/src/win32/i_mouse.cpp b/src/common/platform/win32/i_mouse.cpp similarity index 100% rename from src/win32/i_mouse.cpp rename to src/common/platform/win32/i_mouse.cpp diff --git a/src/win32/i_rawps2.cpp b/src/common/platform/win32/i_rawps2.cpp similarity index 100% rename from src/win32/i_rawps2.cpp rename to src/common/platform/win32/i_rawps2.cpp diff --git a/src/win32/i_specialpaths.cpp b/src/common/platform/win32/i_specialpaths.cpp similarity index 100% rename from src/win32/i_specialpaths.cpp rename to src/common/platform/win32/i_specialpaths.cpp diff --git a/src/win32/i_system.cpp b/src/common/platform/win32/i_system.cpp similarity index 100% rename from src/win32/i_system.cpp rename to src/common/platform/win32/i_system.cpp diff --git a/src/win32/i_system.h b/src/common/platform/win32/i_system.h similarity index 99% rename from src/win32/i_system.h rename to src/common/platform/win32/i_system.h index 1e27a0368b..b0d9b702fa 100644 --- a/src/win32/i_system.h +++ b/src/common/platform/win32/i_system.h @@ -1,5 +1,4 @@ - #ifndef __I_SYSTEM__ #define __I_SYSTEM__ diff --git a/src/win32/i_xinput.cpp b/src/common/platform/win32/i_xinput.cpp similarity index 100% rename from src/win32/i_xinput.cpp rename to src/common/platform/win32/i_xinput.cpp diff --git a/src/win32/zdoom.exe.manifest b/src/common/platform/win32/manifest.xml similarity index 100% rename from src/win32/zdoom.exe.manifest rename to src/common/platform/win32/manifest.xml diff --git a/src/win32/resource.h b/src/common/platform/win32/resource.h similarity index 100% rename from src/win32/resource.h rename to src/common/platform/win32/resource.h diff --git a/src/win32/st_start.cpp b/src/common/platform/win32/st_start.cpp similarity index 100% rename from src/win32/st_start.cpp rename to src/common/platform/win32/st_start.cpp diff --git a/src/win32/st_start_util.cpp b/src/common/platform/win32/st_start_util.cpp similarity index 99% rename from src/win32/st_start_util.cpp rename to src/common/platform/win32/st_start_util.cpp index 86377ed35e..11a0b146c3 100644 --- a/src/win32/st_start_util.cpp +++ b/src/common/platform/win32/st_start_util.cpp @@ -38,10 +38,11 @@ #include "st_start.h" #include "m_alloc.h" #include "filesystem.h" -#include "v_palette.h" -#include "s_sound.h" +#include "s_soundinternal.h" #include "s_music.h" -#include "d_main.h" +#include "startupinfo.h" +#include "palutil.h" +#include "i_interface.h" void I_GetEvent(); // i_input.h pulls in too much garbage. @@ -393,6 +394,11 @@ static const int StrifeStartupPicSizes[4 + 2 + 1] = }; +static void ST_Sound(const char* sndname) +{ + //S_Sound(CHAN_BODY, 0, sndname, 1, ATTN_NONE); +} + //========================================================================== // // FHexenStartupScreen Constructor @@ -511,7 +517,7 @@ void FHexenStartupScreen::Progress() y = ST_PROGRESS_Y; ST_Util_DrawBlock(StartupBitmap, NotchBits, x, y, ST_NOTCH_WIDTH / 2, ST_NOTCH_HEIGHT); } - S_Sound(CHAN_BODY, 0, "StartupTick", 1, ATTN_NONE); + ST_Sound("StartupTick"); } } I_GetEvent(); @@ -539,7 +545,7 @@ void FHexenStartupScreen::NetProgress(int count) y = ST_NETPROGRESS_Y; ST_Util_DrawBlock(StartupBitmap, NetNotchBits, x, y, ST_NETNOTCH_WIDTH / 2, ST_NETNOTCH_HEIGHT); } - S_Sound(CHAN_BODY, 0, "misc/netnotch", 1, ATTN_NONE); + ST_Sound("misc/netnotch"); I_GetEvent(); } } @@ -554,7 +560,7 @@ void FHexenStartupScreen::NetProgress(int count) void FHexenStartupScreen::NetDone() { - S_Sound(CHAN_BODY, 0, "PickupWeapon", 1, ATTN_NORM); + ST_Sound("PickupWeapon"); FGraphicalStartupScreen::NetDone(); } diff --git a/src/win32/wglext.h b/src/common/platform/win32/wglext.h similarity index 100% rename from src/win32/wglext.h rename to src/common/platform/win32/wglext.h diff --git a/src/win32/win32basevideo.cpp b/src/common/platform/win32/win32basevideo.cpp similarity index 100% rename from src/win32/win32basevideo.cpp rename to src/common/platform/win32/win32basevideo.cpp diff --git a/src/win32/win32basevideo.h b/src/common/platform/win32/win32basevideo.h similarity index 100% rename from src/win32/win32basevideo.h rename to src/common/platform/win32/win32basevideo.h diff --git a/src/win32/win32glvideo.cpp b/src/common/platform/win32/win32glvideo.cpp similarity index 100% rename from src/win32/win32glvideo.cpp rename to src/common/platform/win32/win32glvideo.cpp diff --git a/src/win32/win32glvideo.h b/src/common/platform/win32/win32glvideo.h similarity index 100% rename from src/win32/win32glvideo.h rename to src/common/platform/win32/win32glvideo.h diff --git a/src/win32/win32polyvideo.cpp b/src/common/platform/win32/win32polyvideo.cpp similarity index 99% rename from src/win32/win32polyvideo.cpp rename to src/common/platform/win32/win32polyvideo.cpp index 553c9e513d..9a4538d292 100644 --- a/src/win32/win32polyvideo.cpp +++ b/src/common/platform/win32/win32polyvideo.cpp @@ -4,6 +4,8 @@ #include "engineerrors.h" #include +#ifdef HAVE_SOFTPOLY + EXTERN_CVAR(Bool, vid_vsync) bool ViewportLinearScale(); @@ -193,3 +195,5 @@ void I_PolyPresentDeinit() if (device) device->Release(); if (d3d9) d3d9->Release(); } + +#endif \ No newline at end of file diff --git a/src/win32/win32polyvideo.h b/src/common/platform/win32/win32polyvideo.h similarity index 100% rename from src/win32/win32polyvideo.h rename to src/common/platform/win32/win32polyvideo.h diff --git a/src/win32/win32vulkanvideo.cpp b/src/common/platform/win32/win32vulkanvideo.cpp similarity index 100% rename from src/win32/win32vulkanvideo.cpp rename to src/common/platform/win32/win32vulkanvideo.cpp diff --git a/src/win32/win32vulkanvideo.h b/src/common/platform/win32/win32vulkanvideo.h similarity index 100% rename from src/win32/win32vulkanvideo.h rename to src/common/platform/win32/win32vulkanvideo.h diff --git a/src/win32/winres.h b/src/common/platform/win32/winres.h similarity index 100% rename from src/win32/winres.h rename to src/common/platform/win32/winres.h diff --git a/src/win32/zdoom.natvis b/src/common/platform/win32/zutil.natvis similarity index 100% rename from src/win32/zdoom.natvis rename to src/common/platform/win32/zutil.natvis diff --git a/src/d_main.cpp b/src/d_main.cpp index bc664e4d32..c51bf72aa6 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -282,7 +282,6 @@ bool nospriterename; FStartupInfo GameStartupInfo; FString lastIWAD; int restart = 0; -bool batchrun; // just run the startup and collect all error messages in a logfile, then quit without any interaction bool AppActive = true; cycle_t FrameCycles; @@ -3398,8 +3397,6 @@ static int D_DoomMain_Internal (void) while (1); } -void I_ShowFatalError(const char* message); - int GameMain() { int ret = 0; diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 4cfb58d65b..e82a32cb17 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -24,7 +24,6 @@ #include "m_png.h" #include "templates.h" #include "r_videoscale.h" -#include "actor.h" #include "i_time.h" #include "g_game.h" #include "v_text.h" diff --git a/src/win32/i_steam.cpp b/src/win32/i_steam.cpp index cf5ccb0c74..ca0373474c 100644 --- a/src/win32/i_steam.cpp +++ b/src/win32/i_steam.cpp @@ -59,12 +59,10 @@ #include #include -#include "hardware.h" #include "printf.h" #include "version.h" #include "i_sound.h" -#include "resource.h" #include "stats.h" #include "v_text.h" #include "utf8.h" @@ -72,14 +70,12 @@ #include "d_main.h" #include "d_net.h" #include "g_game.h" -#include "i_input.h" #include "c_dispatch.h" #include "templates.h" #include "gameconfigfile.h" #include "v_font.h" #include "g_level.h" #include "doomstat.h" -#include "i_system.h" #include "bitmap.h" #include "cmdlib.h" #include "i_interface.h" diff --git a/src/win32/zdoom.rc b/src/win32/zdoom.rc index 6ac1a23406..6d4a2d27c6 100644 --- a/src/win32/zdoom.rc +++ b/src/win32/zdoom.rc @@ -313,7 +313,7 @@ END // Generated from the TEXTINCLUDE 3 resource. // #ifndef NO_MANIFEST - CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "zdoom.exe.manifest" + CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "..\\common\\platform\\win32\\manifest.xml" #endif ///////////////////////////////////////////////////////////////////////////// From 72533e2f8a378e4d99e862a1331299a98ecb6848 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 23 Apr 2020 22:33:43 +0200 Subject: [PATCH 082/220] - redirect ST_Sound to a callback because the sound code is game specific --- src/common/engine/i_interface.h | 1 + src/common/platform/win32/st_start_util.cpp | 3 ++- src/d_main.cpp | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index c862feb20f..d992203d9e 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -10,6 +10,7 @@ struct SystemCallbacks bool (*WantNativeMouse)(); bool (*CaptureModeInGame)(); void (*CrashInfo)(char* buffer, size_t bufflen, const char* lfstr); + void (*PlayStartupSound)(const char* name); }; diff --git a/src/common/platform/win32/st_start_util.cpp b/src/common/platform/win32/st_start_util.cpp index 11a0b146c3..047aa83108 100644 --- a/src/common/platform/win32/st_start_util.cpp +++ b/src/common/platform/win32/st_start_util.cpp @@ -396,7 +396,8 @@ static const int StrifeStartupPicSizes[4 + 2 + 1] = static void ST_Sound(const char* sndname) { - //S_Sound(CHAN_BODY, 0, sndname, 1, ATTN_NONE); + if (sysCallbacks && sysCallbacks->PlayStartupSound) + sysCallbacks->PlayStartupSound(sndname); } //========================================================================== diff --git a/src/d_main.cpp b/src/d_main.cpp index c51bf72aa6..d699a69c1e 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2639,6 +2639,11 @@ static bool System_CaptureModeInGame() } } +static void System_PlayStartupSound(const char* sndname) +{ + S_Sound(CHAN_BODY, 0, sndname, 1, ATTN_NONE); +} + //========================================================================== // // DoomSpecificInfo From ab16cbe29859057e7d4e80cde5393e231778c259 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 24 Apr 2020 13:08:22 +0200 Subject: [PATCH 083/220] Fix missing texture update --- src/rendering/polyrenderer/backend/poly_renderstate.cpp | 2 ++ src/rendering/vulkan/renderer/vk_renderstate.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index f81587a5a8..5b56af5c19 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -314,6 +314,8 @@ void PolyRenderState::ApplyMaterial() { mTempTM = mMaterial.mMaterial->Source()->isHardwareCanvas() ? TM_OPAQUE : TM_NORMAL; + if (mMaterial.mMaterial->Source()->isHardwareCanvas()) static_cast(mMaterial.mMaterial->Source()->GetTexture())->NeedUpdate(); + MaterialLayerInfo* layer; auto base = static_cast(mMaterial.mMaterial->GetLayer(0, mMaterial.mTranslation, &layer)); if (base) diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 9f63054ae2..721c56861b 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -434,6 +434,8 @@ void VkRenderState::ApplyMaterial() auto fb = GetVulkanFrameBuffer(); auto passManager = fb->GetRenderPassManager(); + if (mMaterial.mMaterial && mMaterial.mMaterial->Source()->isHardwareCanvas()) static_cast(mMaterial.mMaterial->Source()->GetTexture())->NeedUpdate(); + VulkanDescriptorSet* descriptorset = mMaterial.mMaterial ? static_cast(mMaterial.mMaterial)->GetDescriptorSet(mMaterial) : passManager->GetNullTextureDescriptorSet(); mCommandBuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, passManager->GetPipelineLayout(mPipelineKey.NumTextureLayers), 1, descriptorset); From 70d30feb4c9861afd0328beed1cd0c6e1f1d2380 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 24 Apr 2020 15:52:31 +0200 Subject: [PATCH 084/220] - moved the render interface functions out of FGLRenderer into OpenGLFrameBuffer. These need some consolidation among the backends, and the additional indirection in the OpenGL backend made it harder than necessary. --- src/CMakeLists.txt | 3 +- src/rendering/gl/renderer/gl_renderer.cpp | 152 --------------------- src/rendering/gl/renderer/gl_renderer.h | 3 - src/rendering/gl/system/gl_framebuffer.cpp | 145 +++++++++++++++++++- src/rendering/gl/system/gl_framebuffer.h | 2 + 5 files changed, 147 insertions(+), 158 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c391b83b52..d035e752e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1288,7 +1288,8 @@ include_directories( . ../libraries/glslang/glslang/Public ../libraries/glslang/spirv ${CMAKE_BINARY_DIR}/libraries/gdtoa - ${SYSTEM_SOURCES_DIR} ) + ${SYSTEM_SOURCES_DIR} +) add_dependencies( zdoom revision_check ) diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 5858ae938b..79713ae756 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -62,12 +62,9 @@ #include "texturemanager.h" EXTERN_CVAR(Int, screenblocks) -EXTERN_CVAR(Bool, cl_capfps) extern bool NoInterpolateView; -void DoWriteSavePic(FileWriter *file, ESSType ssformat, uint8_t *scr, int width, int height, sector_t *viewsector, bool upsidedown); - namespace OpenGLRenderer { @@ -217,78 +214,6 @@ void FGLRenderer::UpdateShadowMap() } } -//----------------------------------------------------------------------------- -// -// renders the view -// -//----------------------------------------------------------------------------- - -sector_t *FGLRenderer::RenderView(player_t* player) -{ - gl_RenderState.SetVertexBuffer(screen->mVertexData); - screen->mVertexData->Reset(); - sector_t *retsec; - - if (!V_IsHardwareRenderer()) - { - if (swdrawer == nullptr) swdrawer = new SWSceneDrawer; - retsec = swdrawer->RenderView(player); - } - else - { - hw_ClearFakeFlat(); - - iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; - - checkBenchActive(); - - // reset statistics counters - ResetProfilingData(); - - // Get this before everything else - if (cl_capfps || r_NoInterpolate) r_viewpoint.TicFrac = 1.; - else r_viewpoint.TicFrac = I_GetTimeFrac(); - - screen->mLights->Clear(); - screen->mViewpoints->Clear(); - - // NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below. - bool saved_niv = NoInterpolateView; - NoInterpolateView = false; - - // Shader start time does not need to be handled per level. Just use the one from the camera to render from. - if (player->camera) - gl_RenderState.CheckTimer(player->camera->Level->ShaderStartTime); - // prepare all camera textures that have been used in the last frame. - // This must be done for all levels, not just the primary one! - for (auto Level : AllLevels()) - { - Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) - { - RenderTextureView(camtex, camera, fov); - }); - } - NoInterpolateView = saved_niv; - - - // now render the main view - float fovratio; - float ratio = r_viewwindow.WidescreenRatio; - if (r_viewwindow.WidescreenRatio >= 1.3f) - { - fovratio = 1.333333f; - } - else - { - fovratio = ratio; - } - - retsec = RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); - } - All.Unclock(); - return retsec; -} - //=========================================================================== // // @@ -309,83 +234,6 @@ void FGLRenderer::BindToFrameBuffer(FTexture *tex) BaseLayer->BindToFrameBuffer(tex->GetWidth(), tex->GetHeight()); } -//=========================================================================== -// -// Camera texture rendering -// -//=========================================================================== - -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. - - float ratio = tex->aspectRatio; - - StartOffscreen(); - BindToFrameBuffer(tex); - - IntRect bounds; - bounds.left = bounds.top = 0; - bounds.width = FHardwareTexture::GetTexDimension(tex->GetWidth()); - bounds.height = FHardwareTexture::GetTexDimension(tex->GetHeight()); - - FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); - - EndOffscreen(); - - tex->SetUpdated(true); - static_cast(screen)->camtexcount++; -} - -//=========================================================================== -// -// Render the view to a savegame picture -// -//=========================================================================== - -void FGLRenderer::WriteSavePic (player_t *player, FileWriter *file, int width, int height) -{ - IntRect bounds; - bounds.left = 0; - bounds.top = 0; - bounds.width = width; - bounds.height = height; - - // we must be sure the GPU finished reading from the buffer before we fill it with new data. - glFinish(); - - // Switch to render buffers dimensioned for the savepic - mBuffers = mSaveBuffers; - - hw_ClearFakeFlat(); - gl_RenderState.SetVertexBuffer(screen->mVertexData); - screen->mVertexData->Reset(); - screen->mLights->Clear(); - screen->mViewpoints->Clear(); - - // This shouldn't overwrite the global viewpoint even for a short time. - FRenderViewpoint savevp; - sector_t *viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); - glDisable(GL_STENCIL_TEST); - gl_RenderState.SetNoSoftLightLevel(); - CopyToBackbuffer(&bounds, false); - - // strictly speaking not needed as the glReadPixels should block until the scene is rendered, but this is to safeguard against shitty drivers - glFinish(); - - int numpixels = width * height; - uint8_t * scr = (uint8_t *)M_Malloc(numpixels * 3); - glReadPixels(0,0,width, height,GL_RGB,GL_UNSIGNED_BYTE,scr); - - DoWriteSavePic(file, SS_RGB, scr, width, height, viewsector, true); - M_Free(scr); - - // Switch back the screen render buffers - screen->SetViewportRects(nullptr); - mBuffers = mScreenBuffers; -} - //=========================================================================== // // diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index bf59a55326..3dde0195cd 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -89,9 +89,6 @@ public: void DrawPresentTexture(const IntRect &box, bool applyGamma); void Flush(); void Draw2D(F2DDrawer *data); - void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); - void WriteSavePic(player_t *player, FileWriter *file, int width, int height); - sector_t *RenderView(player_t *player); void BeginFrame(); sector_t *RenderViewpoint (FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 0a8770b1e1..961f807fee 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -30,6 +30,7 @@ #include "v_video.h" #include "m_png.h" #include "templates.h" +#include "i_time.h" #include "gl_interface.h" #include "gl/system/gl_framebuffer.h" @@ -40,18 +41,25 @@ #include "hwrenderer/utility/hw_vrmodes.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_skydome.h" +#include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" #include "gl/shaders/gl_shaderprogram.h" #include "gl_debug.h" #include "r_videoscale.h" #include "gl_buffers.h" +#include "swrenderer/r_swscene.h" #include "hwrenderer/data/flatvertices.h" EXTERN_CVAR (Bool, vid_vsync) EXTERN_CVAR(Bool, r_drawvoxels) EXTERN_CVAR(Int, gl_tonemap) +EXTERN_CVAR(Bool, cl_capfps) + +void DoWriteSavePic(FileWriter* file, ESSType ssformat, uint8_t* scr, int width, int height, sector_t* viewsector, bool upsidedown); + +extern bool NoInterpolateView; void gl_LoadExtensions(); void gl_PrintStartupLog(); @@ -193,9 +201,79 @@ void OpenGLFrameBuffer::Update() void OpenGLFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int width, int height) { if (!V_IsHardwareRenderer()) + { Super::WriteSavePic(player, file, width, height); + } else if (GLRenderer != nullptr) - GLRenderer->WriteSavePic(player, file, width, height); + { + IntRect bounds; + bounds.left = 0; + bounds.top = 0; + bounds.width = width; + bounds.height = height; + + // we must be sure the GPU finished reading from the buffer before we fill it with new data. + glFinish(); + + // Switch to render buffers dimensioned for the savepic + GLRenderer->mBuffers = GLRenderer->mSaveBuffers; + + hw_ClearFakeFlat(); + gl_RenderState.SetVertexBuffer(screen->mVertexData); + screen->mVertexData->Reset(); + screen->mLights->Clear(); + screen->mViewpoints->Clear(); + + // This shouldn't overwrite the global viewpoint even for a short time. + FRenderViewpoint savevp; + sector_t* viewsector = GLRenderer->RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); + glDisable(GL_STENCIL_TEST); + gl_RenderState.SetNoSoftLightLevel(); + GLRenderer->CopyToBackbuffer(&bounds, false); + + // strictly speaking not needed as the glReadPixels should block until the scene is rendered, but this is to safeguard against shitty drivers + glFinish(); + + int numpixels = width * height; + uint8_t* scr = (uint8_t*)M_Malloc(numpixels * 3); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, scr); + + DoWriteSavePic(file, SS_RGB, scr, width, height, viewsector, true); + M_Free(scr); + + // Switch back the screen render buffers + screen->SetViewportRects(nullptr); + GLRenderer->mBuffers = GLRenderer->mScreenBuffers; + } +} + +//=========================================================================== +// +// Camera texture rendering +// +//=========================================================================== + +void OpenGLFrameBuffer::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. + + float ratio = tex->aspectRatio; + + GLRenderer->StartOffscreen(); + GLRenderer->BindToFrameBuffer(tex); + + IntRect bounds; + bounds.left = bounds.top = 0; + bounds.width = FHardwareTexture::GetTexDimension(tex->GetWidth()); + bounds.height = FHardwareTexture::GetTexDimension(tex->GetHeight()); + + FRenderViewpoint texvp; + GLRenderer->RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); + + GLRenderer->EndOffscreen(); + + tex->SetUpdated(true); + static_cast(screen)->camtexcount++; } //=========================================================================== @@ -207,7 +285,70 @@ void OpenGLFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int wid sector_t *OpenGLFrameBuffer::RenderView(player_t *player) { if (GLRenderer != nullptr) - return GLRenderer->RenderView(player); + { + gl_RenderState.SetVertexBuffer(screen->mVertexData); + screen->mVertexData->Reset(); + sector_t* retsec; + + if (!V_IsHardwareRenderer()) + { + if (GLRenderer->swdrawer == nullptr) GLRenderer->swdrawer = new SWSceneDrawer; + retsec = GLRenderer->swdrawer->RenderView(player); + } + else + { + hw_ClearFakeFlat(); + + iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; + + checkBenchActive(); + + // reset statistics counters + ResetProfilingData(); + + // Get this before everything else + if (cl_capfps || r_NoInterpolate) r_viewpoint.TicFrac = 1.; + else r_viewpoint.TicFrac = I_GetTimeFrac(); + + screen->mLights->Clear(); + screen->mViewpoints->Clear(); + + // NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below. + bool saved_niv = NoInterpolateView; + NoInterpolateView = false; + + // Shader start time does not need to be handled per level. Just use the one from the camera to render from. + if (player->camera) + gl_RenderState.CheckTimer(player->camera->Level->ShaderStartTime); + // prepare all camera textures that have been used in the last frame. + // This must be done for all levels, not just the primary one! + for (auto Level : AllLevels()) + { + Level->canvasTextureInfo.UpdateAll([&](AActor* camera, FCanvasTexture* camtex, double fov) + { + RenderTextureView(camtex, camera, fov); + }); + } + NoInterpolateView = saved_niv; + + + // now render the main view + float fovratio; + float ratio = r_viewwindow.WidescreenRatio; + if (r_viewwindow.WidescreenRatio >= 1.3f) + { + fovratio = 1.333333f; + } + else + { + fovratio = ratio; + } + + retsec = GLRenderer->RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); + } + All.Unclock(); + return retsec; + } return nullptr; } diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index 7578103fb4..ec780dd383 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -16,6 +16,8 @@ class OpenGLFrameBuffer : public SystemGLFrameBuffer { typedef SystemGLFrameBuffer Super; + void RenderTextureView(FCanvasTexture* tex, AActor* Viewpoint, double FOV); + public: explicit OpenGLFrameBuffer() {} From 90585c49315beba10d9a35ac80b519acde854380 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 24 Apr 2020 16:15:18 +0200 Subject: [PATCH 085/220] - added a RenderState virtual to the FrameBuffer class. --- src/rendering/gl/system/gl_framebuffer.cpp | 5 +++++ src/rendering/gl/system/gl_framebuffer.h | 1 + src/rendering/polyrenderer/backend/poly_framebuffer.cpp | 6 ++++++ src/rendering/polyrenderer/backend/poly_framebuffer.h | 1 + src/rendering/v_video.h | 2 ++ src/rendering/vulkan/system/vk_framebuffer.cpp | 7 ++++++- src/rendering/vulkan/system/vk_framebuffer.h | 1 + 7 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 961f807fee..7d99c37517 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -514,6 +514,11 @@ void OpenGLFrameBuffer::UpdatePalette() GLRenderer->ClearTonemapPalette(); } +FRenderState* OpenGLFrameBuffer::RenderState() +{ + return &gl_RenderState; +} + //=========================================================================== // diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index ec780dd383..c8663a997a 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -27,6 +27,7 @@ public: void InitializeState() override; void Update() override; + FRenderState* RenderState() override; void CleanForRestart() override; void UpdatePalette() override; uint32_t GetCaps() override; diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index e82a32cb17..b452e7924c 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -530,6 +530,12 @@ void PolyFrameBuffer::CleanForRestart() swdrawer.reset(); } +FRenderState* PolyFrameBuffer::RenderState() +{ + return mRenderState.get(); +} + + void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index 025f14a965..776d864127 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -35,6 +35,7 @@ public: void InitializeState() override; + FRenderState* RenderState() override; void CleanForRestart() override; void PrecacheMaterial(FMaterial *mat, int translation) override; void UpdatePalette() override; diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index cdfbb75941..d7d9d7e05f 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -67,6 +67,7 @@ class FLightBuffer; struct HWDrawInfo; class FMaterial; class FGameTexture; +class FRenderState; enum EHWCaps { @@ -270,6 +271,7 @@ public: virtual void BeginFrame() {} virtual void SetWindowSize(int w, int h) {} virtual void StartPrecaching() {} + virtual FRenderState* RenderState() { return nullptr; } virtual int GetClientWidth() = 0; virtual int GetClientHeight() = 0; diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index fa3a1a1270..0c7b9a0e7c 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -584,7 +584,7 @@ void VulkanFrameBuffer::DrawScene(HWDrawInfo *di, int drawmode) } GetRenderState()->SetDepthMask(true); - if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, di, *GetRenderState()); + if (!gl_no_skyclear) mPortalState->RenderFirstSkyPortal(recursion, di, *GetRenderState()); di->RenderScene(*GetRenderState()); @@ -995,3 +995,8 @@ void VulkanFrameBuffer::UpdateShadowMap() { mPostprocess->UpdateShadowMap(); } + +FRenderState* VulkanFrameBuffer::RenderState() +{ + return mRenderState.get(); +} diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 7ab7c6bc67..5535f1e8af 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -35,6 +35,7 @@ public: VkRenderState *GetRenderState() { return mRenderState.get(); } VkPostprocess *GetPostprocess() { return mPostprocess.get(); } VkRenderBuffers *GetBuffers() { return mActiveRenderBuffers; } + FRenderState* RenderState() override; void FlushCommands(bool finish, bool lastsubmit = false); From c203df5edb6fde00ef6525afe5198327cd3aca73 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 24 Apr 2020 21:47:18 +0200 Subject: [PATCH 086/220] - consolidated the 3 virtually identical instances of DrawScene and moved the function to HWDrawInfo. The only backend dependent call in there, ambient occlusion, has been made a virtual of DFrameBuffer. --- src/rendering/gl/renderer/gl_renderer.h | 1 - src/rendering/gl/renderer/gl_scene.cpp | 72 +------------------ src/rendering/gl/system/gl_framebuffer.cpp | 10 +++ src/rendering/gl/system/gl_framebuffer.h | 1 + .../hwrenderer/scene/hw_drawinfo.cpp | 71 ++++++++++++++++-- src/rendering/hwrenderer/scene/hw_drawinfo.h | 5 +- src/rendering/hwrenderer/scene/hw_portal.h | 2 +- .../polyrenderer/backend/poly_framebuffer.cpp | 65 ++--------------- .../polyrenderer/backend/poly_framebuffer.h | 2 +- src/rendering/v_video.h | 1 + .../vulkan/system/vk_framebuffer.cpp | 65 ++--------------- src/rendering/vulkan/system/vk_framebuffer.h | 2 +- 12 files changed, 96 insertions(+), 201 deletions(-) diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index 3dde0195cd..84448bfc37 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -102,7 +102,6 @@ public: private: - void DrawScene(HWDrawInfo *di, int drawmode); bool QuadStereoCheckInitialRenderContextState(); void PresentAnaglyph(bool r, bool g, bool b); void PresentSideBySide(); diff --git a/src/rendering/gl/renderer/gl_scene.cpp b/src/rendering/gl/renderer/gl_scene.cpp index a1c7a9f7a8..4f99f2e2a7 100644 --- a/src/rendering/gl/renderer/gl_scene.cpp +++ b/src/rendering/gl/renderer/gl_scene.cpp @@ -65,7 +65,6 @@ // //========================================================================== CVAR(Bool, gl_texture, true, 0) -CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_mask_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) @@ -78,72 +77,6 @@ EXTERN_CVAR (Bool, r_drawvoxels) namespace OpenGLRenderer { -//----------------------------------------------------------------------------- -// -// gl_drawscene - this function renders the scene from the current -// viewpoint, including mirrors and skyboxes and other portals -// It is assumed that the HWPortal::EndFrame returns with the -// stencil, z-buffer and the projection matrix intact! -// -//----------------------------------------------------------------------------- - -void FGLRenderer::DrawScene(HWDrawInfo *di, int drawmode) -{ - static int recursion=0; - static int ssao_portals_available = 0; - const auto &vp = di->Viewpoint; - - bool applySSAO = false; - if (drawmode == DM_MAINVIEW) - { - ssao_portals_available = gl_ssao_portals; - applySSAO = true; - } - else if (drawmode == DM_OFFSCREEN) - { - ssao_portals_available = 0; - } - else if (drawmode == DM_PORTAL && ssao_portals_available > 0) - { - applySSAO = true; - ssao_portals_available--; - } - - if (vp.camera != nullptr) - { - ActorRenderFlags savedflags = vp.camera->renderflags; - di->CreateScene(drawmode == DM_MAINVIEW); - vp.camera->renderflags = savedflags; - } - else - { - di->CreateScene(false); - } - - glDepthMask(true); - if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, di, gl_RenderState); - - di->RenderScene(gl_RenderState); - - if (applySSAO && gl_RenderState.GetPassType() == GBUFFER_PASS) - { - gl_RenderState.EnableDrawBuffers(1); - GLRenderer->AmbientOccludeScene(di->VPUniforms.mProjectionMatrix.get()[5]); - glViewport(screen->mSceneViewport.left, screen->mSceneViewport.top, screen->mSceneViewport.width, screen->mSceneViewport.height); - GLRenderer->mBuffers->BindSceneFB(true); - gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); - gl_RenderState.Apply(); - screen->mViewpoints->Bind(gl_RenderState, di->vpIndex); - } - - // Handle all portals after rendering the opaque objects but before - // doing all translucent stuff - recursion++; - screen->mPortalState->EndFrame(di, gl_RenderState); - recursion--; - di->RenderTranslucent(gl_RenderState); -} - //----------------------------------------------------------------------------- // // Renders one viewpoint in a scene @@ -195,10 +128,7 @@ sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * came vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); di->SetupView(gl_RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - // std::function until this can be done better in a cross-API fashion. - di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) { - DrawScene(di, mode); - }); + di->ProcessScene(toscreen); if (mainview) { diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 7d99c37517..d85a4b3515 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -519,6 +519,16 @@ FRenderState* OpenGLFrameBuffer::RenderState() return &gl_RenderState; } +void OpenGLFrameBuffer::AmbientOccludeScene(float m5) +{ + gl_RenderState.EnableDrawBuffers(1); + GLRenderer->AmbientOccludeScene(m5); + glViewport(screen->mSceneViewport.left, mSceneViewport.top, mSceneViewport.width, mSceneViewport.height); + GLRenderer->mBuffers->BindSceneFB(true); + gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); + gl_RenderState.Apply(); +} + //=========================================================================== // diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index c8663a997a..1875abdbd7 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -27,6 +27,7 @@ public: void InitializeState() override; void Update() override; + void AmbientOccludeScene(float m5) override; FRenderState* RenderState() override; void CleanForRestart() override; void UpdatePalette() override; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 143e779931..15c5ab290a 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -47,6 +47,7 @@ EXTERN_CVAR(Float, r_visibility) CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE) CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool back); @@ -90,7 +91,6 @@ HWDrawInfo *FDrawInfoList::GetNew() void FDrawInfoList::Release(HWDrawInfo * di) { - di->DrawScene = nullptr; di->ClearBuffers(); di->Level = nullptr; mList.Push(di); @@ -105,7 +105,6 @@ void FDrawInfoList::Release(HWDrawInfo * di) HWDrawInfo *HWDrawInfo::StartDrawInfo(FLevelLocals *lev, HWDrawInfo *parent, FRenderViewpoint &parentvp, HWViewpointUniforms *uniforms) { HWDrawInfo *di = di_list.GetNew(); - if (parent) di->DrawScene = parent->DrawScene; di->Level = lev; di->StartScene(parentvp, uniforms); return di; @@ -642,20 +641,82 @@ void HWDrawInfo::Set3DViewport(FRenderState &state) state.SetStencil(0, SOP_Keep, SF_AllOn); } +//----------------------------------------------------------------------------- +// +// gl_drawscene - this function renders the scene from the current +// viewpoint, including mirrors and skyboxes and other portals +// It is assumed that the HWPortal::EndFrame returns with the +// stencil, z-buffer and the projection matrix intact! +// +//----------------------------------------------------------------------------- + +void HWDrawInfo::DrawScene(int drawmode) +{ + static int recursion = 0; + static int ssao_portals_available = 0; + const auto& vp = Viewpoint; + + bool applySSAO = false; + if (drawmode == DM_MAINVIEW) + { + ssao_portals_available = gl_ssao_portals; + applySSAO = true; + } + else if (drawmode == DM_OFFSCREEN) + { + ssao_portals_available = 0; + } + else if (drawmode == DM_PORTAL && ssao_portals_available > 0) + { + applySSAO = true; + ssao_portals_available--; + } + + if (vp.camera != nullptr) + { + ActorRenderFlags savedflags = vp.camera->renderflags; + CreateScene(drawmode == DM_MAINVIEW); + vp.camera->renderflags = savedflags; + } + else + { + CreateScene(false); + } + auto& RenderState = *screen->RenderState(); + + RenderState.SetDepthMask(true); + if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this, RenderState); + + RenderScene(RenderState); + + if (applySSAO && RenderState.GetPassType() == GBUFFER_PASS) + { + screen->AmbientOccludeScene(VPUniforms.mProjectionMatrix.get()[5]); + screen->mViewpoints->Bind(RenderState, vpIndex); + } + + // Handle all portals after rendering the opaque objects but before + // doing all translucent stuff + recursion++; + screen->mPortalState->EndFrame(this, RenderState); + recursion--; + RenderTranslucent(RenderState); +} + + //----------------------------------------------------------------------------- // // R_RenderView - renders one view - either the screen or a camera texture // //----------------------------------------------------------------------------- -void HWDrawInfo::ProcessScene(bool toscreen, const std::function &drawScene) +void HWDrawInfo::ProcessScene(bool toscreen) { screen->mPortalState->BeginScene(); int mapsection = Level->PointInRenderSubsector(Viewpoint.Pos)->mapsection; CurrentMapSections.Set(mapsection); - DrawScene = drawScene; - DrawScene(this, toscreen ? DM_MAINVIEW : DM_OFFSCREEN); + DrawScene(toscreen ? DM_MAINVIEW : DM_OFFSCREEN); } diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.h b/src/rendering/hwrenderer/scene/hw_drawinfo.h index 1a81a4a949..9b86ecf378 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.h +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.h @@ -179,8 +179,6 @@ struct HWDrawInfo fixed_t viewx, viewy; // since the nodes are still fixed point, keeping the view position also fixed point for node traversal is faster. bool multithread; - std::function DrawScene = nullptr; - private: // For ProcessLowerMiniseg bool inview; @@ -246,6 +244,7 @@ public: void SetViewArea(); int SetFullbrightFlags(player_t *player); + void DrawScene(int drawmode); void CreateScene(bool drawpsprites); void RenderScene(FRenderState &state); void RenderTranslucent(FRenderState &state); @@ -253,7 +252,7 @@ public: void EndDrawScene(sector_t * viewsector, FRenderState &state); void DrawEndScene2D(sector_t * viewsector, FRenderState &state); void Set3DViewport(FRenderState &state); - void ProcessScene(bool toscreen, const std::function &drawScene); + void ProcessScene(bool toscreen); bool DoOneSectorUpper(subsector_t * subsec, float planez, area_t in_area); bool DoOneSectorLower(subsector_t * subsec, float planez, area_t in_area); diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index 88a920a2fa..a6bf05f42f 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -143,7 +143,7 @@ public: { if (Setup(di, state, di->mClipper)) { - di->DrawScene(di, DM_PORTAL); + di->DrawScene(DM_PORTAL); Shutdown(di, state); } else state.ClearScreen(); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index b452e7924c..658b31a804 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -59,7 +59,6 @@ EXTERN_CVAR(Bool, r_drawvoxels) EXTERN_CVAR(Int, gl_tonemap) EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Bool, cl_capfps) -EXTERN_CVAR(Bool, gl_no_skyclear) extern bool NoInterpolateView; extern int rendered_commandbuffers; @@ -340,10 +339,7 @@ sector_t *PolyFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * ca vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - // std::function until this can be done better in a cross-API fashion. - di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) { - DrawScene(di, mode); - }); + di->ProcessScene(toscreen); if (mainview) { @@ -398,60 +394,6 @@ void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, tex->SetUpdated(true); } -void PolyFrameBuffer::DrawScene(HWDrawInfo *di, int drawmode) -{ - // To do: this is virtually identical to FGLRenderer::DrawScene and should be merged. - - static int recursion = 0; - static int ssao_portals_available = 0; - const auto &vp = di->Viewpoint; - - bool applySSAO = false; - if (drawmode == DM_MAINVIEW) - { - ssao_portals_available = gl_ssao_portals; - applySSAO = true; - } - else if (drawmode == DM_OFFSCREEN) - { - ssao_portals_available = 0; - } - else if (drawmode == DM_PORTAL && ssao_portals_available > 0) - { - applySSAO = true; - ssao_portals_available--; - } - - if (vp.camera != nullptr) - { - ActorRenderFlags savedflags = vp.camera->renderflags; - di->CreateScene(drawmode == DM_MAINVIEW); - vp.camera->renderflags = savedflags; - } - else - { - di->CreateScene(false); - } - - GetRenderState()->SetDepthMask(true); - if (!gl_no_skyclear) mPortalState->RenderFirstSkyPortal(recursion, di, *GetRenderState()); - - di->RenderScene(*GetRenderState()); - - if (applySSAO && GetRenderState()->GetPassType() == GBUFFER_PASS) - { - //mPostprocess->AmbientOccludeScene(di->VPUniforms.mProjectionMatrix.get()[5]); - //mViewpoints->Bind(*GetRenderState(), di->vpIndex); - } - - // Handle all portals after rendering the opaque objects but before - // doing all translucent stuff - recursion++; - mPortalState->EndFrame(di, *GetRenderState()); - recursion--; - di->RenderTranslucent(*GetRenderState()); -} - static uint8_t ToIntColorComponent(float v) { return clamp((int)(v * 255.0f + 0.5f), 0, 255); @@ -678,3 +620,8 @@ unsigned int PolyFrameBuffer::GetLightBufferBlockSize() const void PolyFrameBuffer::UpdateShadowMap() { } + +void PolyFrameBuffer::AmbientOccludeScene(float m5) +{ + //mPostprocess->AmbientOccludeScene(m5); +} diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index 776d864127..2b58476237 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -47,6 +47,7 @@ public: void BeginFrame() override; void BlurScene(float amount) override; void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; + void AmbientOccludeScene(float m5) override; IHardwareTexture *CreateHardwareTexture() override; FModelRenderer *CreateModelRenderer(int mli) override; @@ -71,7 +72,6 @@ public: private: sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); - void DrawScene(HWDrawInfo *di, int drawmode); void UpdateShadowMap(); void CheckCanvas(); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index d7d9d7e05f..300b054421 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -311,6 +311,7 @@ public: virtual const char* DeviceName() const { return "Unknown"; } virtual void WriteSavePic(player_t *player, FileWriter *file, int width, int height); virtual sector_t *RenderView(player_t *player) { return nullptr; } + virtual void AmbientOccludeScene(float m5) {} // Screen wiping virtual FTexture *WipeStartScreen(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 0c7b9a0e7c..32013a919b 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -67,7 +67,6 @@ EXTERN_CVAR(Bool, r_drawvoxels) EXTERN_CVAR(Int, gl_tonemap) EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Bool, cl_capfps) -EXTERN_CVAR(Bool, gl_no_skyclear) extern bool NoInterpolateView; extern int rendered_commandbuffers; @@ -480,10 +479,7 @@ sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - // std::function until this can be done better in a cross-API fashion. - di->ProcessScene(toscreen, [&](HWDrawInfo *di, int mode) { - DrawScene(di, mode); - }); + di->ProcessScene(toscreen); if (mainview) { @@ -548,60 +544,6 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint tex->SetUpdated(true); } -void VulkanFrameBuffer::DrawScene(HWDrawInfo *di, int drawmode) -{ - // To do: this is virtually identical to FGLRenderer::DrawScene and should be merged. - - static int recursion = 0; - static int ssao_portals_available = 0; - const auto &vp = di->Viewpoint; - - bool applySSAO = false; - if (drawmode == DM_MAINVIEW) - { - ssao_portals_available = gl_ssao_portals; - applySSAO = true; - } - else if (drawmode == DM_OFFSCREEN) - { - ssao_portals_available = 0; - } - else if (drawmode == DM_PORTAL && ssao_portals_available > 0) - { - applySSAO = true; - ssao_portals_available--; - } - - if (vp.camera != nullptr) - { - ActorRenderFlags savedflags = vp.camera->renderflags; - di->CreateScene(drawmode == DM_MAINVIEW); - vp.camera->renderflags = savedflags; - } - else - { - di->CreateScene(false); - } - - GetRenderState()->SetDepthMask(true); - if (!gl_no_skyclear) mPortalState->RenderFirstSkyPortal(recursion, di, *GetRenderState()); - - di->RenderScene(*GetRenderState()); - - if (applySSAO && GetRenderState()->GetPassType() == GBUFFER_PASS) - { - mPostprocess->AmbientOccludeScene(di->VPUniforms.mProjectionMatrix.get()[5]); - screen->mViewpoints->Bind(*GetRenderState(), di->vpIndex); - } - - // Handle all portals after rendering the opaque objects but before - // doing all translucent stuff - recursion++; - screen->mPortalState->EndFrame(di, *GetRenderState()); - recursion--; - di->RenderTranslucent(*GetRenderState()); -} - void VulkanFrameBuffer::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) { mPostprocess->PostProcessScene(fixedcm, afterBloomDrawEndScene2D); @@ -1000,3 +942,8 @@ FRenderState* VulkanFrameBuffer::RenderState() { return mRenderState.get(); } + +void VulkanFrameBuffer::AmbientOccludeScene(float m5) +{ + mPostprocess->AmbientOccludeScene(m5); +} diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 5535f1e8af..e9b6ac1580 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -88,6 +88,7 @@ public: void BeginFrame() override; void BlurScene(float amount) override; void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; + void AmbientOccludeScene(float m5) override; IHardwareTexture *CreateHardwareTexture() override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; @@ -114,7 +115,6 @@ public: private: sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); - void DrawScene(HWDrawInfo *di, int drawmode); void PrintStartupLog(); void CreateFanToTrisIndexBuffer(); void CopyScreenToBuffer(int w, int h, void *data); From 6177ed153d27c2f1ea30501d9f564d4658bdacf2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 10:51:45 +0200 Subject: [PATCH 087/220] - consolidated the 3 RenderViewpoint variants and took the function out of the framebuffer class. --- src/rendering/gl/renderer/gl_renderer.h | 3 - src/rendering/gl/renderer/gl_renderstate.h | 5 +- src/rendering/gl/renderer/gl_scene.cpp | 79 +++++------------- src/rendering/gl/system/gl_framebuffer.cpp | 28 ++++++- src/rendering/gl/system/gl_framebuffer.h | 7 +- .../hwrenderer/scene/hw_drawinfo.cpp | 4 + src/rendering/hwrenderer/scene/hw_drawinfo.h | 1 + .../hwrenderer/scene/hw_renderstate.h | 2 +- src/rendering/hwrenderer/utility/hw_cvars.h | 2 +- .../polyrenderer/backend/poly_framebuffer.cpp | 74 +---------------- .../polyrenderer/backend/poly_framebuffer.h | 4 +- .../polyrenderer/backend/poly_renderstate.cpp | 2 +- .../polyrenderer/backend/poly_renderstate.h | 2 +- src/rendering/swrenderer/r_swscene.cpp | 4 +- src/rendering/v_video.h | 6 +- .../vulkan/renderer/vk_renderstate.cpp | 2 +- .../vulkan/renderer/vk_renderstate.h | 2 +- .../vulkan/system/vk_framebuffer.cpp | 81 ++----------------- src/rendering/vulkan/system/vk_framebuffer.h | 6 +- 19 files changed, 85 insertions(+), 229 deletions(-) diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index 84448bfc37..ea8aaf44ae 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -91,9 +91,6 @@ public: void Draw2D(F2DDrawer *data); void BeginFrame(); - sector_t *RenderViewpoint (FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); - - bool StartOffscreen(); void EndOffscreen(); void UpdateShadowMap(); diff --git a/src/rendering/gl/renderer/gl_renderstate.h b/src/rendering/gl/renderer/gl_renderstate.h index 9a52a1d149..a366f75d04 100644 --- a/src/rendering/gl/renderer/gl_renderstate.h +++ b/src/rendering/gl/renderer/gl_renderstate.h @@ -40,7 +40,7 @@ namespace OpenGLRenderer class FShader; struct HWSectorPlane; -class FGLRenderState : public FRenderState +class FGLRenderState final : public FRenderState { uint8_t mLastDepthClamp : 1; @@ -108,7 +108,7 @@ public: mSpecularLevel = specularLevel; } - void EnableDrawBuffers(int count) override + void EnableDrawBuffers(int count, bool apply = false) override { count = MIN(count, 3); if (mNumDrawBuffers != count) @@ -117,6 +117,7 @@ public: glDrawBuffers(count, buffers); mNumDrawBuffers = count; } + if (apply) Apply(); } void ToggleState(int state, bool on); diff --git a/src/rendering/gl/renderer/gl_scene.cpp b/src/rendering/gl/renderer/gl_scene.cpp index 4f99f2e2a7..55f3730990 100644 --- a/src/rendering/gl/renderer/gl_scene.cpp +++ b/src/rendering/gl/renderer/gl_scene.cpp @@ -29,53 +29,20 @@ #include "gi.h" #include "m_png.h" #include "doomstat.h" -#include "g_level.h" #include "r_data/r_interpolate.h" #include "r_utility.h" #include "d_player.h" -#include "p_effect.h" -#include "sbar.h" -#include "po_man.h" -#include "p_local.h" -#include "serializer.h" -#include "g_levellocals.h" -#include "actorinlines.h" -#include "r_data/models/models.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" -#include "gl_interface.h" -#include "gl/system/gl_framebuffer.h" -#include "gl/system/gl_debug.h" #include "hwrenderer/utility/hw_cvars.h" -#include "gl/renderer/gl_renderstate.h" -#include "gl/renderer/gl_renderbuffers.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/scene/hw_clipper.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_vrmodes.h" -#include "gl/renderer/gl_renderer.h" -#include "gl/system/gl_buffers.h" -//========================================================================== -// -// CVARs -// -//========================================================================== -CVAR(Bool, gl_texture, true, 0) -CVAR(Float, gl_mask_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -CVAR(Float, gl_mask_sprite_threshold, 0.5f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG) - -EXTERN_CVAR (Bool, cl_capfps) -EXTERN_CVAR (Bool, r_deathcamera) -EXTERN_CVAR (Float, r_visibility) -EXTERN_CVAR (Bool, r_drawvoxels) - - -namespace OpenGLRenderer -{ //----------------------------------------------------------------------------- // @@ -83,75 +50,71 @@ namespace OpenGLRenderer // //----------------------------------------------------------------------------- -sector_t * FGLRenderer::RenderViewpoint (FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) +sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) { - R_SetupFrame (mainvp, r_viewwindow, camera); + auto& RenderState = *screen->RenderState(); + + R_SetupFrame(mainvp, r_viewwindow, camera); if (mainview && toscreen) - UpdateShadowMap(); + screen->UpdateShadowMap(); // Update the attenuation flag of all light defaults for each viewpoint. // This function will only do something if the setting differs. FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); - // Render (potentially) multiple views for stereo 3d + // Render (potentially) multiple views for stereo 3d // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. auto vrmode = VRMode::GetVRMode(mainview && toscreen); const int eyeCount = vrmode->mEyeCount; - mBuffers->CurrentEye() = 0; // always begin at zero, in case eye count changed + screen->FirstEye(); for (int eye_ix = 0; eye_ix < eyeCount; ++eye_ix) { - const auto &eye = vrmode->mEyes[mBuffers->CurrentEye()]; + const auto& eye = vrmode->mEyes[eye_ix]; screen->SetViewportRects(bounds); if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao { bool useSSAO = (gl_ssao != 0); - mBuffers->BindSceneFB(useSSAO); - gl_RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); - gl_RenderState.EnableDrawBuffers(gl_RenderState.GetPassDrawBufferCount()); - gl_RenderState.Apply(); + screen->SetSceneRenderTarget(useSSAO); + RenderState.SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); + RenderState.EnableDrawBuffers(RenderState.GetPassDrawBufferCount(), true); } - auto di = HWDrawInfo::StartDrawInfo(mainvp.ViewLevel, nullptr, mainvp, nullptr); - auto &vp = di->Viewpoint; + auto& vp = di->Viewpoint; - di->Set3DViewport(gl_RenderState); + di->Set3DViewport(RenderState); di->SetViewArea(); - auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr); + auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr); di->Viewpoint.FieldOfView = fov; // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint) // Stereo mode specific perspective projection di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio); // Stereo mode specific viewpoint adjustment vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); - di->SetupView(gl_RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); + di->SetupView(RenderState, vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); di->ProcessScene(toscreen); if (mainview) { PostProcess.Clock(); - if (toscreen) di->EndDrawScene(mainvp.sector, gl_RenderState); // do not call this for camera textures. + if (toscreen) di->EndDrawScene(mainvp.sector, RenderState); // do not call this for camera textures. - if (gl_RenderState.GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers + if (RenderState.GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers { - gl_RenderState.SetPassType(NORMAL_PASS); - gl_RenderState.EnableDrawBuffers(1); + RenderState.SetPassType(NORMAL_PASS); + RenderState.EnableDrawBuffers(1); } - mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture - - PostProcessScene(cm, [&]() { di->DrawEndScene2D(mainvp.sector, gl_RenderState); }); + screen->PostProcessScene(false, cm, [&]() { di->DrawEndScene2D(mainvp.sector, RenderState); }); PostProcess.Unclock(); } di->EndDrawInfo(); if (eyeCount - eye_ix > 1) - mBuffers->NextEye(eyeCount); + screen->NextEye(eyeCount); } return mainvp.sector; } - -} diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index d85a4b3515..8eed568693 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -226,7 +226,7 @@ void OpenGLFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int wid // This shouldn't overwrite the global viewpoint even for a short time. FRenderViewpoint savevp; - sector_t* viewsector = GLRenderer->RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); + sector_t* viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); glDisable(GL_STENCIL_TEST); gl_RenderState.SetNoSoftLightLevel(); GLRenderer->CopyToBackbuffer(&bounds, false); @@ -268,7 +268,7 @@ void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, AActor* Viewpoint bounds.height = FHardwareTexture::GetTexDimension(tex->GetHeight()); FRenderViewpoint texvp; - GLRenderer->RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); + RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); GLRenderer->EndOffscreen(); @@ -344,7 +344,7 @@ sector_t *OpenGLFrameBuffer::RenderView(player_t *player) fovratio = ratio; } - retsec = GLRenderer->RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); + retsec = RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); } All.Unclock(); return retsec; @@ -529,6 +529,25 @@ void OpenGLFrameBuffer::AmbientOccludeScene(float m5) gl_RenderState.Apply(); } +void OpenGLFrameBuffer::FirstEye() +{ + GLRenderer->mBuffers->CurrentEye() = 0; // always begin at zero, in case eye count changed +} + +void OpenGLFrameBuffer::NextEye(int eyecount) +{ + GLRenderer->mBuffers->NextEye(eyecount); +} + +void OpenGLFrameBuffer::SetSceneRenderTarget(bool useSSAO) +{ + GLRenderer->mBuffers->BindSceneFB(useSSAO); +} + +void OpenGLFrameBuffer::UpdateShadowMap() +{ + GLRenderer->UpdateShadowMap(); +} //=========================================================================== // @@ -610,8 +629,9 @@ void OpenGLFrameBuffer::Draw2D() } } -void OpenGLFrameBuffer::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) +void OpenGLFrameBuffer::PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) { + if (!swscene) GLRenderer->mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture GLRenderer->PostProcessScene(fixedcm, afterBloomDrawEndScene2D); } diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index 1875abdbd7..a6286fcb3b 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -28,6 +28,11 @@ public: void Update() override; void AmbientOccludeScene(float m5) override; + void FirstEye() override; + void NextEye(int eyecount) override; + void SetSceneRenderTarget(bool useSSAO) override; + void UpdateShadowMap() override; + FRenderState* RenderState() override; void CleanForRestart() override; void UpdatePalette() override; @@ -58,7 +63,7 @@ public: void SetVSync(bool vsync); void Draw2D() override; - void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; + void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) override; bool HWGammaActive = false; // Are we using hardware or software gamma? std::shared_ptr mDebug; // Debug API diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 15c5ab290a..b1cad03a1e 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -49,6 +49,10 @@ CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE) CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Bool, gl_texture, true, 0) +CVAR(Float, gl_mask_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Float, gl_mask_sprite_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + sector_t * hw_FakeFlat(sector_t * sec, sector_t * dest, area_t in_area, bool back); //========================================================================== diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.h b/src/rendering/hwrenderer/scene/hw_drawinfo.h index 9b86ecf378..27db44e828 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.h +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.h @@ -329,3 +329,4 @@ public: }; +sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/rendering/hwrenderer/scene/hw_renderstate.h index f7caed8335..d5399ad712 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/rendering/hwrenderer/scene/hw_renderstate.h @@ -672,7 +672,7 @@ public: virtual void EnableDepthTest(bool on) = 0; // used by 2D, portals and render hacks. virtual void EnableMultisampling(bool on) = 0; // only active for 2D virtual void EnableLineSmooth(bool on) = 0; // constant setting for each 2D drawer operation - virtual void EnableDrawBuffers(int count) = 0; // Used by SSAO and EnableDrawBufferAttachments + virtual void EnableDrawBuffers(int count, bool apply = false) = 0; // Used by SSAO and EnableDrawBufferAttachments void SetColorMask(bool on) { diff --git a/src/rendering/hwrenderer/utility/hw_cvars.h b/src/rendering/hwrenderer/utility/hw_cvars.h index 8d184206dd..79c97b6827 100644 --- a/src/rendering/hwrenderer/utility/hw_cvars.h +++ b/src/rendering/hwrenderer/utility/hw_cvars.h @@ -4,9 +4,9 @@ #include "r_defs.h" #include "c_cvars.h" + EXTERN_CVAR(Bool,gl_enhanced_nightvision) EXTERN_CVAR(Int, screenblocks); -EXTERN_CVAR(Bool, gl_texture) EXTERN_CVAR(Int, gl_texture_filter) EXTERN_CVAR(Float, gl_texture_filter_anisotropic) EXTERN_CVAR(Int, gl_texture_format) diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 658b31a804..427e24ffe8 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -296,78 +296,6 @@ sector_t *PolyFrameBuffer::RenderView(player_t *player) return retsec; } -sector_t *PolyFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) -{ - // To do: this is virtually identical to FGLRenderer::RenderViewpoint and should be merged. - - R_SetupFrame(mainvp, r_viewwindow, camera); - - if (mainview && toscreen) - UpdateShadowMap(); - - // Update the attenuation flag of all light defaults for each viewpoint. - // This function will only do something if the setting differs. - FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); - - // Render (potentially) multiple views for stereo 3d - // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. - auto vrmode = VRMode::GetVRMode(mainview && toscreen); - for (int eye_ix = 0; eye_ix < vrmode->mEyeCount; ++eye_ix) - { - const auto &eye = vrmode->mEyes[eye_ix]; - SetViewportRects(bounds); - - if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao - { - //mRenderState->SetRenderTarget(GetBuffers()->SceneColor.View.get(), GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), Poly_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); - bool useSSAO = (gl_ssao != 0); - GetRenderState()->SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); - GetRenderState()->EnableDrawBuffers(GetRenderState()->GetPassDrawBufferCount()); - } - - auto di = HWDrawInfo::StartDrawInfo(mainvp.ViewLevel, nullptr, mainvp, nullptr); - auto &vp = di->Viewpoint; - - di->Set3DViewport(*GetRenderState()); - di->SetViewArea(); - auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr); - di->Viewpoint.FieldOfView = fov; // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint) - - // Stereo mode specific perspective projection - di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio); - // Stereo mode specific viewpoint adjustment - vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); - di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - - di->ProcessScene(toscreen); - - if (mainview) - { - PostProcess.Clock(); - if (toscreen) di->EndDrawScene(mainvp.sector, *GetRenderState()); // do not call this for camera textures. - - if (GetRenderState()->GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers - { - GetRenderState()->SetPassType(NORMAL_PASS); - GetRenderState()->EnableDrawBuffers(1); - } - - //mPostprocess->BlitSceneToPostprocess(); // Copy the resulting scene to the current post process texture - - PostProcessScene(cm, [&]() { di->DrawEndScene2D(mainvp.sector, *GetRenderState()); }); - - PostProcess.Unclock(); - } - di->EndDrawInfo(); - -#if 0 - if (vrmode->mEyeCount > 1) - mBuffers->BlitToEyeTexture(eye_ix); -#endif - } - - return mainvp.sector; -} void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) { @@ -399,7 +327,7 @@ static uint8_t ToIntColorComponent(float v) return clamp((int)(v * 255.0f + 0.5f), 0, 255); } -void PolyFrameBuffer::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) +void PolyFrameBuffer::PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) { afterBloomDrawEndScene2D(); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index 2b58476237..a7e6ee14e0 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -46,8 +46,9 @@ public: void TextureFilterChanged() override; void BeginFrame() override; void BlurScene(float amount) override; - void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; + void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) override; void AmbientOccludeScene(float m5) override; + //void SetSceneRenderTarget(bool useSSAO) override; IHardwareTexture *CreateHardwareTexture() override; FModelRenderer *CreateModelRenderer(int mli) override; @@ -70,7 +71,6 @@ public: } FrameDeleteList; private: - sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); void UpdateShadowMap(); diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 5b56af5c19..a8f1550558 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -200,7 +200,7 @@ void PolyRenderState::EnableLineSmooth(bool on) { } -void PolyRenderState::EnableDrawBuffers(int count) +void PolyRenderState::EnableDrawBuffers(int count, bool apply) { } diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.h b/src/rendering/polyrenderer/backend/poly_renderstate.h index e8069ffe85..1db19c71a5 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.h +++ b/src/rendering/polyrenderer/backend/poly_renderstate.h @@ -38,7 +38,7 @@ public: void EnableDepthTest(bool on) override; void EnableMultisampling(bool on) override; void EnableLineSmooth(bool on) override; - void EnableDrawBuffers(int count) override; + void EnableDrawBuffers(int count, bool apply) override; void SetRenderTarget(DCanvas *canvas, PolyDepthStencil *depthStencil, bool topdown); void Bind(PolyDataBuffer *buffer, uint32_t offset, uint32_t length); diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index d25ba485fd..1f49803684 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -122,7 +122,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) DrawTexture(twod, fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE); screen->Draw2D(); screen->Clear2D(); - screen->PostProcessScene(CM_DEFAULT, [&]() { + screen->PostProcessScene(true, CM_DEFAULT, [&]() { SWRenderer->DrawRemainingPlayerSprites(); screen->Draw2D(); screen->Clear2D(); @@ -138,7 +138,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) int cm = CM_DEFAULT; auto map = swrenderer::CameraLight::Instance()->ShaderColormap(); if (map) cm = (int)(ptrdiff_t)(map - SpecialColormaps.Data()) + CM_FIRSTSPECIALCOLORMAP; - screen->PostProcessScene(cm, [&]() { }); + screen->PostProcessScene(true, cm, [&]() { }); SWRenderer->DrawRemainingPlayerSprites(); screen->Draw2D(); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 300b054421..4b7aedd1a8 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -312,12 +312,16 @@ public: virtual void WriteSavePic(player_t *player, FileWriter *file, int width, int height); virtual sector_t *RenderView(player_t *player) { return nullptr; } virtual void AmbientOccludeScene(float m5) {} + virtual void FirstEye() {} + virtual void NextEye(int eyecount) {} + virtual void SetSceneRenderTarget(bool useSSAO) {} + virtual void UpdateShadowMap() {} // Screen wiping virtual FTexture *WipeStartScreen(); virtual FTexture *WipeEndScreen(); - virtual void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) { if (afterBloomDrawEndScene2D) afterBloomDrawEndScene2D(); } + virtual void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) { if (afterBloomDrawEndScene2D) afterBloomDrawEndScene2D(); } void ScaleCoordsFromWindow(int16_t &x, int16_t &y); diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 721c56861b..3e2cc97e74 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -506,7 +506,7 @@ void VkRenderState::EndFrame() mStreamBufferWriter.Reset(); } -void VkRenderState::EnableDrawBuffers(int count) +void VkRenderState::EnableDrawBuffers(int count, bool apply) { if (mRenderTarget.DrawBuffers != count) { diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index fcdc8efb1d..9494a794b2 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -42,7 +42,7 @@ public: void EnableDepthTest(bool on) override; void EnableMultisampling(bool on) override; void EnableLineSmooth(bool on) override; - void EnableDrawBuffers(int count) override; + void EnableDrawBuffers(int count, bool apply) override; void BeginFrame(); void SetRenderTarget(VkTextureImage *image, VulkanImageView *depthStencilView, int width, int height, VkFormat Format, VkSampleCountFlagBits samples); diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 32013a919b..f3404ef80c 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -436,79 +436,6 @@ sector_t *VulkanFrameBuffer::RenderView(player_t *player) return retsec; } -sector_t *VulkanFrameBuffer::RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen) -{ - // To do: this is virtually identical to FGLRenderer::RenderViewpoint and should be merged. - - R_SetupFrame(mainvp, r_viewwindow, camera); - - if (mainview && toscreen) - UpdateShadowMap(); - - // Update the attenuation flag of all light defaults for each viewpoint. - // This function will only do something if the setting differs. - FLightDefaults::SetAttenuationForLevel(!!(camera->Level->flags3 & LEVEL3_ATTENUATE)); - - // Render (potentially) multiple views for stereo 3d - // Fixme. The view offsetting should be done with a static table and not require setup of the entire render state for the mode. - auto vrmode = VRMode::GetVRMode(mainview && toscreen); - for (int eye_ix = 0; eye_ix < vrmode->mEyeCount; ++eye_ix) - { - const auto &eye = vrmode->mEyes[eye_ix]; - screen->SetViewportRects(bounds); - - if (mainview) // Bind the scene frame buffer and turn on draw buffers used by ssao - { - mRenderState->SetRenderTarget(&GetBuffers()->SceneColor, GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); - bool useSSAO = (gl_ssao != 0); - GetRenderState()->SetPassType(useSSAO ? GBUFFER_PASS : NORMAL_PASS); - GetRenderState()->EnableDrawBuffers(GetRenderState()->GetPassDrawBufferCount()); - } - - auto di = HWDrawInfo::StartDrawInfo(mainvp.ViewLevel, nullptr, mainvp, nullptr); - auto &vp = di->Viewpoint; - - di->Set3DViewport(*GetRenderState()); - di->SetViewArea(); - auto cm = di->SetFullbrightFlags(mainview ? vp.camera->player : nullptr); - di->Viewpoint.FieldOfView = fov; // Set the real FOV for the current scene (it's not necessarily the same as the global setting in r_viewpoint) - - // Stereo mode specific perspective projection - di->VPUniforms.mProjectionMatrix = eye.GetProjection(fov, ratio, fovratio); - // Stereo mode specific viewpoint adjustment - vp.Pos += eye.GetViewShift(vp.HWAngles.Yaw.Degrees); - di->SetupView(*GetRenderState(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, false, false); - - di->ProcessScene(toscreen); - - if (mainview) - { - PostProcess.Clock(); - if (toscreen) di->EndDrawScene(mainvp.sector, *GetRenderState()); // do not call this for camera textures. - - if (GetRenderState()->GetPassType() == GBUFFER_PASS) // Turn off ssao draw buffers - { - GetRenderState()->SetPassType(NORMAL_PASS); - GetRenderState()->EnableDrawBuffers(1); - } - - mPostprocess->BlitSceneToPostprocess(); // Copy the resulting scene to the current post process texture - - PostProcessScene(cm, [&]() { di->DrawEndScene2D(mainvp.sector, *GetRenderState()); }); - - PostProcess.Unclock(); - } - di->EndDrawInfo(); - -#if 0 - if (vrmode->mEyeCount > 1) - mBuffers->BlitToEyeTexture(eye_ix); -#endif - } - - return mainvp.sector; -} - void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) { auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); @@ -544,8 +471,9 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint tex->SetUpdated(true); } -void VulkanFrameBuffer::PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) +void VulkanFrameBuffer::PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) { + if (!swscene) mPostprocess->BlitSceneToPostprocess(); // Copy the resulting scene to the current post process texture mPostprocess->PostProcessScene(fixedcm, afterBloomDrawEndScene2D); } @@ -947,3 +875,8 @@ void VulkanFrameBuffer::AmbientOccludeScene(float m5) { mPostprocess->AmbientOccludeScene(m5); } + +void VulkanFrameBuffer::SetSceneRenderTarget(bool useSSAO) +{ + mRenderState->SetRenderTarget(&GetBuffers()->SceneColor, GetBuffers()->SceneDepthStencil.View.get(), GetBuffers()->GetWidth(), GetBuffers()->GetHeight(), VK_FORMAT_R16G16B16A16_SFLOAT, GetBuffers()->GetSceneSamples()); +} diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index e9b6ac1580..6a1f1697d0 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -87,8 +87,10 @@ public: void StartPrecaching() override; void BeginFrame() override; void BlurScene(float amount) override; - void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D) override; + void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) override; void AmbientOccludeScene(float m5) override; + void SetSceneRenderTarget(bool useSSAO) override; + void UpdateShadowMap() override; IHardwareTexture *CreateHardwareTexture() override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; @@ -113,12 +115,10 @@ public: void UpdateGpuStats(); private: - sector_t *RenderViewpoint(FRenderViewpoint &mainvp, AActor * camera, IntRect * bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); void PrintStartupLog(); void CreateFanToTrisIndexBuffer(); void CopyScreenToBuffer(int w, int h, void *data); - void UpdateShadowMap(); void DeleteFrameObjects(); void FlushCommands(VulkanCommandBuffer **commands, size_t count, bool finish, bool lastsubmit); From 44d39ef63ec447f4a764c140fec221592aaffb78 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 13:18:57 +0200 Subject: [PATCH 088/220] - consolidated the savegame picture code. --- src/g_game.cpp | 53 +-------- src/rendering/gl/renderer/gl_scene.cpp | 106 ++++++++++++++++++ src/rendering/gl/system/gl_framebuffer.cpp | 75 ++++--------- src/rendering/gl/system/gl_framebuffer.h | 5 +- src/rendering/hwrenderer/scene/hw_drawinfo.h | 1 + .../polyrenderer/backend/poly_framebuffer.cpp | 12 -- .../polyrenderer/backend/poly_framebuffer.h | 1 - src/rendering/v_framebuffer.cpp | 6 - src/rendering/v_video.h | 7 +- .../vulkan/system/vk_framebuffer.cpp | 62 +++------- src/rendering/vulkan/system/vk_framebuffer.h | 7 +- 11 files changed, 158 insertions(+), 177 deletions(-) diff --git a/src/g_game.cpp b/src/g_game.cpp index 0bf7812604..9cb948b889 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -82,6 +82,7 @@ #include "events.h" #include "c_buttons.h" #include "d_buttons.h" +#include "hwrenderer/scene/hw_drawinfo.h" static FRandom pr_dmspawn ("DMSpawn"); @@ -2252,56 +2253,6 @@ static void PutSaveComment (FSerializer &arc) arc.AddString("Comment", comment); } -void DoWriteSavePic(FileWriter *file, ESSType ssformat, uint8_t *scr, int width, int height, sector_t *viewsector, bool upsidedown) -{ - PalEntry palette[256]; - PalEntry modulateColor; - auto blend = V_CalcBlend(viewsector, &modulateColor); - int pixelsize = 1; - // Apply the screen blend, because the renderer does not provide this. - if (ssformat == SS_RGB) - { - int numbytes = width * height * 3; - pixelsize = 3; - if (modulateColor != 0xffffffff) - { - float r = modulateColor.r / 255.f; - float g = modulateColor.g / 255.f; - float b = modulateColor.b / 255.f; - for (int i = 0; i < numbytes; i += 3) - { - scr[i] = uint8_t(scr[i] * r); - scr[i + 1] = uint8_t(scr[i + 1] * g); - scr[i + 2] = uint8_t(scr[i + 2] * b); - } - } - float iblendfac = 1.f - blend.W; - blend.X *= blend.W; - blend.Y *= blend.W; - blend.Z *= blend.W; - for (int i = 0; i < numbytes; i += 3) - { - scr[i] = uint8_t(scr[i] * iblendfac + blend.X); - scr[i + 1] = uint8_t(scr[i + 1] * iblendfac + blend.Y); - scr[i + 2] = uint8_t(scr[i + 2] * iblendfac + blend.Z); - } - } - else - { - // Apply the screen blend to the palette. The colormap related parts get skipped here because these are already part of the image. - DoBlending(GPalette.BaseColors, palette, 256, uint8_t(blend.X), uint8_t(blend.Y), uint8_t(blend.Z), uint8_t(blend.W*255)); - } - - int pitch = width * pixelsize; - if (upsidedown) - { - scr += ((height - 1) * width * pixelsize); - pitch *= -1; - } - - M_CreatePNG(file, scr, ssformat == SS_PAL? palette : nullptr, ssformat, width, height, pitch, Gamma); -} - static void PutSavePic (FileWriter *file, int width, int height) { if (width <= 0 || height <= 0 || !storesavepic) @@ -2312,7 +2263,7 @@ static void PutSavePic (FileWriter *file, int width, int height) { D_Render([&]() { - screen->WriteSavePic(&players[consoleplayer], file, width, height); + WriteSavePic(&players[consoleplayer], file, width, height); }, false); } } diff --git a/src/rendering/gl/renderer/gl_scene.cpp b/src/rendering/gl/renderer/gl_scene.cpp index 55f3730990..324703a453 100644 --- a/src/rendering/gl/renderer/gl_scene.cpp +++ b/src/rendering/gl/renderer/gl_scene.cpp @@ -32,6 +32,7 @@ #include "r_data/r_interpolate.h" #include "r_utility.h" #include "d_player.h" +#include "swrenderer/r_renderer.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/flatvertices.h" @@ -39,6 +40,7 @@ #include "hwrenderer/dynlights/hw_lightbuffer.h" #include "hwrenderer/utility/hw_cvars.h" #include "hwrenderer/data/hw_viewpointbuffer.h" +#include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_clipper.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_vrmodes.h" @@ -118,3 +120,107 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou return mainvp.sector; } + +void DoWriteSavePic(FileWriter* file, ESSType ssformat, uint8_t* scr, int width, int height, sector_t* viewsector, bool upsidedown) +{ + PalEntry palette[256]; + PalEntry modulateColor; + auto blend = V_CalcBlend(viewsector, &modulateColor); + int pixelsize = 1; + // Apply the screen blend, because the renderer does not provide this. + if (ssformat == SS_RGB) + { + int numbytes = width * height * 3; + pixelsize = 3; + if (modulateColor != 0xffffffff) + { + float r = modulateColor.r / 255.f; + float g = modulateColor.g / 255.f; + float b = modulateColor.b / 255.f; + for (int i = 0; i < numbytes; i += 3) + { + scr[i] = uint8_t(scr[i] * r); + scr[i + 1] = uint8_t(scr[i + 1] * g); + scr[i + 2] = uint8_t(scr[i + 2] * b); + } + } + float iblendfac = 1.f - blend.W; + blend.X *= blend.W; + blend.Y *= blend.W; + blend.Z *= blend.W; + for (int i = 0; i < numbytes; i += 3) + { + scr[i] = uint8_t(scr[i] * iblendfac + blend.X); + scr[i + 1] = uint8_t(scr[i + 1] * iblendfac + blend.Y); + scr[i + 2] = uint8_t(scr[i + 2] * iblendfac + blend.Z); + } + } + else + { + // Apply the screen blend to the palette. The colormap related parts get skipped here because these are already part of the image. + DoBlending(GPalette.BaseColors, palette, 256, uint8_t(blend.X), uint8_t(blend.Y), uint8_t(blend.Z), uint8_t(blend.W * 255)); + } + + int pitch = width * pixelsize; + if (upsidedown) + { + scr += ((height - 1) * width * pixelsize); + pitch *= -1; + } + + M_CreatePNG(file, scr, ssformat == SS_PAL ? palette : nullptr, ssformat, width, height, pitch, Gamma); +} + +//=========================================================================== +// +// Render the view to a savegame picture +// +//=========================================================================== + +void WriteSavePic(player_t* player, FileWriter* file, int width, int height) +{ + if (!V_IsHardwareRenderer()) + { + SWRenderer->WriteSavePic(player, file, width, height); + } + else + { + IntRect bounds; + bounds.left = 0; + bounds.top = 0; + bounds.width = width; + bounds.height = height; + auto& RenderState = *screen->RenderState(); + + // we must be sure the GPU finished reading from the buffer before we fill it with new data. + screen->WaitForCommands(false); + + // Switch to render buffers dimensioned for the savepic + screen->SetSaveBuffers(true); + screen->ImageTransitionScene(true); + + hw_ClearFakeFlat(); + RenderState.SetVertexBuffer(screen->mVertexData); + screen->mVertexData->Reset(); + screen->mLights->Clear(); + screen->mViewpoints->Clear(); + + // This shouldn't overwrite the global viewpoint even for a short time. + FRenderViewpoint savevp; + sector_t* viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); + RenderState.EnableStencil(false); + RenderState.SetNoSoftLightLevel(); + + int numpixels = width * height; + uint8_t* scr = (uint8_t*)M_Malloc(numpixels * 3); + screen->CopyScreenToBuffer(width, height, scr); + + DoWriteSavePic(file, SS_RGB, scr, width, height, viewsector, screen->FlipSavePic()); + M_Free(scr); + + // Switch back the screen render buffers + screen->SetViewportRects(nullptr); + screen->SetSaveBuffers(false); + } +} + diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 8eed568693..278cefdf8e 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -57,8 +57,6 @@ EXTERN_CVAR(Bool, r_drawvoxels) EXTERN_CVAR(Int, gl_tonemap) EXTERN_CVAR(Bool, cl_capfps) -void DoWriteSavePic(FileWriter* file, ESSType ssformat, uint8_t* scr, int width, int height, sector_t* viewsector, bool upsidedown); - extern bool NoInterpolateView; void gl_LoadExtensions(); @@ -192,59 +190,18 @@ void OpenGLFrameBuffer::Update() Super::Update(); } -//=========================================================================== -// -// Render the view to a savegame picture -// -//=========================================================================== - -void OpenGLFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int width, int height) +void OpenGLFrameBuffer::CopyScreenToBuffer(int width, int height, uint8_t* scr) { - if (!V_IsHardwareRenderer()) - { - Super::WriteSavePic(player, file, width, height); - } - else if (GLRenderer != nullptr) - { - IntRect bounds; - bounds.left = 0; - bounds.top = 0; - bounds.width = width; - bounds.height = height; + IntRect bounds; + bounds.left = 0; + bounds.top = 0; + bounds.width = width; + bounds.height = height; + GLRenderer->CopyToBackbuffer(&bounds, false); - // we must be sure the GPU finished reading from the buffer before we fill it with new data. - glFinish(); - - // Switch to render buffers dimensioned for the savepic - GLRenderer->mBuffers = GLRenderer->mSaveBuffers; - - hw_ClearFakeFlat(); - gl_RenderState.SetVertexBuffer(screen->mVertexData); - screen->mVertexData->Reset(); - screen->mLights->Clear(); - screen->mViewpoints->Clear(); - - // This shouldn't overwrite the global viewpoint even for a short time. - FRenderViewpoint savevp; - sector_t* viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); - glDisable(GL_STENCIL_TEST); - gl_RenderState.SetNoSoftLightLevel(); - GLRenderer->CopyToBackbuffer(&bounds, false); - - // strictly speaking not needed as the glReadPixels should block until the scene is rendered, but this is to safeguard against shitty drivers - glFinish(); - - int numpixels = width * height; - uint8_t* scr = (uint8_t*)M_Malloc(numpixels * 3); - glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, scr); - - DoWriteSavePic(file, SS_RGB, scr, width, height, viewsector, true); - M_Free(scr); - - // Switch back the screen render buffers - screen->SetViewportRects(nullptr); - GLRenderer->mBuffers = GLRenderer->mScreenBuffers; - } + // strictly speaking not needed as the glReadPixels should block until the scene is rendered, but this is to safeguard against shitty drivers + glFinish(); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, scr); } //=========================================================================== @@ -549,6 +506,18 @@ void OpenGLFrameBuffer::UpdateShadowMap() GLRenderer->UpdateShadowMap(); } +void OpenGLFrameBuffer::WaitForCommands(bool finish) +{ + glFinish(); +} + +void OpenGLFrameBuffer::SetSaveBuffers(bool yes) +{ + if (!GLRenderer) return; + if (yes) GLRenderer->mBuffers = GLRenderer->mSaveBuffers; + else GLRenderer->mBuffers = GLRenderer->mScreenBuffers; +} + //=========================================================================== // // diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index a6286fcb3b..5412293aee 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -32,13 +32,16 @@ public: void NextEye(int eyecount) override; void SetSceneRenderTarget(bool useSSAO) override; void UpdateShadowMap() override; + void WaitForCommands(bool finish) override; + void SetSaveBuffers(bool yes) override; + void CopyScreenToBuffer(int width, int height, uint8_t* buffer) override; + bool FlipSavePic() const override { return true; } FRenderState* RenderState() override; void CleanForRestart() override; void UpdatePalette() override; uint32_t GetCaps() override; const char* DeviceName() const override; - void WriteSavePic(player_t *player, FileWriter *file, int width, int height) override; sector_t *RenderView(player_t *player) override; void SetTextureFilterMode() override; IHardwareTexture *CreateHardwareTexture() override; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.h b/src/rendering/hwrenderer/scene/hw_drawinfo.h index 27db44e828..a3eab8ccc1 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.h +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.h @@ -330,3 +330,4 @@ public: }; sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); +void WriteSavePic(player_t* player, FileWriter* file, int width, int height); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 427e24ffe8..9a02a6b223 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -53,7 +53,6 @@ #include "engineerrors.h" void Draw2D(F2DDrawer *drawer, FRenderState &state); -void DoWriteSavePic(FileWriter *file, ESSType ssformat, uint8_t *scr, int width, int height, sector_t *viewsector, bool upsidedown); EXTERN_CVAR(Bool, r_drawvoxels) EXTERN_CVAR(Int, gl_tonemap) @@ -218,17 +217,6 @@ void PolyFrameBuffer::Update() } -void PolyFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int width, int height) -{ - if (!V_IsHardwareRenderer()) - { - Super::WriteSavePic(player, file, width, height); - } - else - { - } -} - sector_t *PolyFrameBuffer::RenderView(player_t *player) { // To do: this is virtually identical to FGLRenderer::RenderView and should be merged. diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index a7e6ee14e0..ad7bc56ba8 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -40,7 +40,6 @@ public: void PrecacheMaterial(FMaterial *mat, int translation) override; void UpdatePalette() override; uint32_t GetCaps() override; - void WriteSavePic(player_t *player, FileWriter *file, int width, int height) override; sector_t *RenderView(player_t *player) override; void SetTextureFilterMode() override; void TextureFilterChanged() override; diff --git a/src/rendering/v_framebuffer.cpp b/src/rendering/v_framebuffer.cpp index aa297fe9af..143189a3f1 100644 --- a/src/rendering/v_framebuffer.cpp +++ b/src/rendering/v_framebuffer.cpp @@ -312,12 +312,6 @@ uint32_t DFrameBuffer::GetCaps() return (uint32_t)FlagSet; } -void DFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int width, int height) -{ - SWRenderer->WriteSavePic(player, file, width, height); -} - - //========================================================================== // // Calculates the viewport values needed for 2D and 3D operations diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 4b7aedd1a8..a504c37002 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -309,13 +309,18 @@ public: virtual uint32_t GetCaps(); virtual int Backend() { return 0; } virtual const char* DeviceName() const { return "Unknown"; } - virtual void WriteSavePic(player_t *player, FileWriter *file, int width, int height); virtual sector_t *RenderView(player_t *player) { return nullptr; } virtual void AmbientOccludeScene(float m5) {} virtual void FirstEye() {} virtual void NextEye(int eyecount) {} virtual void SetSceneRenderTarget(bool useSSAO) {} virtual void UpdateShadowMap() {} + virtual void WaitForCommands(bool finish) {} + virtual void SetSaveBuffers(bool yes) {} + virtual void ImageTransitionScene(bool unknown) {} + virtual void CopyScreenToBuffer(int width, int height, uint8_t* buffer) { memset(buffer, 0, width* height); } + virtual bool FlipSavePic() const { return false; } + // Screen wiping virtual FTexture *WipeStartScreen(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index f3404ef80c..0fabe75ae8 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -61,7 +61,6 @@ #include "engineerrors.h" void Draw2D(F2DDrawer *drawer, FRenderState &state); -void DoWriteSavePic(FileWriter *file, ESSType ssformat, uint8_t *scr, int width, int height, sector_t *viewsector, bool upsidedown); EXTERN_CVAR(Bool, r_drawvoxels) EXTERN_CVAR(Int, gl_tonemap) @@ -318,53 +317,6 @@ void VulkanFrameBuffer::WaitForCommands(bool finish) } } -void VulkanFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int width, int height) -{ - if (!V_IsHardwareRenderer()) - { - Super::WriteSavePic(player, file, width, height); - } - else - { - IntRect bounds; - bounds.left = 0; - bounds.top = 0; - bounds.width = width; - bounds.height = height; - - // we must be sure the GPU finished reading from the buffer before we fill it with new data. - WaitForCommands(false); - - // Switch to render buffers dimensioned for the savepic - mActiveRenderBuffers = mSaveBuffers.get(); - - mPostprocess->ImageTransitionScene(true); - - hw_ClearFakeFlat(); - GetRenderState()->SetVertexBuffer(screen->mVertexData); - screen->mVertexData->Reset(); - screen->mLights->Clear(); - screen->mViewpoints->Clear(); - - // This shouldn't overwrite the global viewpoint even for a short time. - FRenderViewpoint savevp; - sector_t *viewsector = RenderViewpoint(savevp, players[consoleplayer].camera, &bounds, r_viewpoint.FieldOfView.Degrees, 1.6f, 1.6f, true, false); - GetRenderState()->EnableStencil(false); - GetRenderState()->SetNoSoftLightLevel(); - - int numpixels = width * height; - uint8_t * scr = (uint8_t *)M_Malloc(numpixels * 3); - CopyScreenToBuffer(width, height, scr); - - DoWriteSavePic(file, SS_RGB, scr, width, height, viewsector, false); - M_Free(scr); - - // Switch back the screen render buffers - screen->SetViewportRects(nullptr); - mActiveRenderBuffers = mScreenBuffers.get(); - } -} - sector_t *VulkanFrameBuffer::RenderView(player_t *player) { // To do: this is virtually identical to FGLRenderer::RenderView and should be merged. @@ -634,7 +586,7 @@ FTexture *VulkanFrameBuffer::WipeEndScreen() return tex; } -void VulkanFrameBuffer::CopyScreenToBuffer(int w, int h, void *data) +void VulkanFrameBuffer::CopyScreenToBuffer(int w, int h, uint8_t *data) { VkTextureImage image; @@ -866,6 +818,18 @@ void VulkanFrameBuffer::UpdateShadowMap() mPostprocess->UpdateShadowMap(); } +void VulkanFrameBuffer::SetSaveBuffers(bool yes) +{ + if (yes) mActiveRenderBuffers = mSaveBuffers.get(); + else mActiveRenderBuffers = mScreenBuffers.get(); +} + +void VulkanFrameBuffer::ImageTransitionScene(bool unknown) +{ + mPostprocess->ImageTransitionScene(unknown); +} + + FRenderState* VulkanFrameBuffer::RenderState() { return mRenderState.get(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 6a1f1697d0..85a5d363ff 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -80,7 +80,6 @@ public: uint32_t GetCaps() override; const char* DeviceName() const override; int Backend() override { return 1; } - void WriteSavePic(player_t *player, FileWriter *file, int width, int height) override; sector_t *RenderView(player_t *player) override; void SetTextureFilterMode() override; void TextureFilterChanged() override; @@ -91,6 +90,8 @@ public: void AmbientOccludeScene(float m5) override; void SetSceneRenderTarget(bool useSSAO) override; void UpdateShadowMap() override; + void SetSaveBuffers(bool yes) override; + void ImageTransitionScene(bool unknown) override; IHardwareTexture *CreateHardwareTexture() override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; @@ -108,7 +109,7 @@ public: void Draw2D() override; - void WaitForCommands(bool finish); + void WaitForCommands(bool finish) override; void PushGroup(const FString &name); void PopGroup(); @@ -118,7 +119,7 @@ private: void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); void PrintStartupLog(); void CreateFanToTrisIndexBuffer(); - void CopyScreenToBuffer(int w, int h, void *data); + void CopyScreenToBuffer(int w, int h, uint8_t *data) override; void DeleteFrameObjects(); void FlushCommands(VulkanCommandBuffer **commands, size_t count, bool finish, bool lastsubmit); From 730d07fbf7cd12d7acd3dc8105ad8a353d94859f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 14:13:36 +0200 Subject: [PATCH 089/220] - reworked canvas texture updater to avoid passing game data to the render backends. These are now handled one level above using a callback to perform the actual rendering. --- src/rendering/gl/system/gl_framebuffer.cpp | 21 +++++++++++-------- src/rendering/gl/system/gl_framebuffer.h | 2 +- .../polyrenderer/backend/poly_framebuffer.cpp | 12 +++++++---- .../polyrenderer/backend/poly_framebuffer.h | 2 +- src/rendering/v_video.h | 1 + .../vulkan/system/vk_framebuffer.cpp | 16 +++++++++----- src/rendering/vulkan/system/vk_framebuffer.h | 4 +++- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 278cefdf8e..b2b3263f00 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -210,23 +210,21 @@ void OpenGLFrameBuffer::CopyScreenToBuffer(int width, int height, uint8_t* scr) // //=========================================================================== -void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, AActor* Viewpoint, double FOV) +void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) + { - // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. - - float ratio = tex->aspectRatio; - GLRenderer->StartOffscreen(); GLRenderer->BindToFrameBuffer(tex); + // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. + float ratio = tex->aspectRatio; + IntRect bounds; bounds.left = bounds.top = 0; bounds.width = FHardwareTexture::GetTexDimension(tex->GetWidth()); bounds.height = FHardwareTexture::GetTexDimension(tex->GetHeight()); - FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); - + renderFunc(bounds); GLRenderer->EndOffscreen(); tex->SetUpdated(true); @@ -283,7 +281,12 @@ sector_t *OpenGLFrameBuffer::RenderView(player_t *player) { Level->canvasTextureInfo.UpdateAll([&](AActor* camera, FCanvasTexture* camtex, double fov) { - RenderTextureView(camtex, camera, fov); + RenderTextureView(camtex, [=](IntRect &bounds) + { + FRenderViewpoint texvp; + float ratio = camtex->aspectRatio; + RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); + }); }); } NoInterpolateView = saved_niv; diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index 5412293aee..f84fcf8b70 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -16,7 +16,7 @@ class OpenGLFrameBuffer : public SystemGLFrameBuffer { typedef SystemGLFrameBuffer Super; - void RenderTextureView(FCanvasTexture* tex, AActor* Viewpoint, double FOV); + void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; public: diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 9a02a6b223..dbbde9492b 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -261,7 +261,12 @@ sector_t *PolyFrameBuffer::RenderView(player_t *player) { Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) { - RenderTextureView(camtex, camera, fov); + RenderTextureView(camtex, [=](IntRect &bounds) + { + FRenderViewpoint texvp; + float ratio = camtex->aspectRatio; + RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); + }); }); } NoInterpolateView = saved_niv; @@ -285,7 +290,7 @@ sector_t *PolyFrameBuffer::RenderView(player_t *player) } -void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) +void PolyFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) { // 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(tex->GetHardwareTexture(0, 0)); @@ -300,8 +305,7 @@ void PolyFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, bounds.width = std::min(tex->GetWidth(), image->GetWidth()); bounds.height = std::min(tex->GetHeight(), image->GetHeight()); - FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); + renderFunc(bounds); FlushDrawCommands(); DrawerThreads::WaitForWorkers(); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index ad7bc56ba8..d902e6fe3f 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -70,7 +70,7 @@ public: } FrameDeleteList; private: - void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); + void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; void UpdateShadowMap(); void CheckCanvas(); diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index a504c37002..79aa6cbdca 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -320,6 +320,7 @@ public: virtual void ImageTransitionScene(bool unknown) {} virtual void CopyScreenToBuffer(int width, int height, uint8_t* buffer) { memset(buffer, 0, width* height); } virtual bool FlipSavePic() const { return false; } + virtual void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) {} // Screen wiping diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 0fabe75ae8..a276ee3a2b 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -363,7 +363,12 @@ sector_t *VulkanFrameBuffer::RenderView(player_t *player) { Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) { - RenderTextureView(camtex, camera, fov); + RenderTextureView(camtex, [=](IntRect &bounds) + { + FRenderViewpoint texvp; + float ratio = camtex->aspectRatio; + RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); + }); }); } NoInterpolateView = saved_niv; @@ -388,11 +393,12 @@ sector_t *VulkanFrameBuffer::RenderView(player_t *player) return retsec; } -void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV) +void VulkanFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) + { + // 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(tex->GetHardwareTexture(0, 0)); - float ratio = tex->aspectRatio; VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0); VkTextureImage *depthStencil = BaseLayer->GetDepthStencil(tex); @@ -404,13 +410,13 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint mRenderState->SetRenderTarget(image, depthStencil->View.get(), image->Image->width, image->Image->height, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT); + float ratio = tex->aspectRatio; IntRect bounds; bounds.left = bounds.top = 0; bounds.width = std::min(tex->GetWidth(), image->Image->width); bounds.height = std::min(tex->GetHeight(), image->Image->height); - FRenderViewpoint texvp; - RenderViewpoint(texvp, Viewpoint, &bounds, FOV, ratio, ratio, false, false); + renderFunc(bounds); mRenderState->EndRenderPass(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 85a5d363ff..9b26c4b153 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -114,9 +114,11 @@ public: void PushGroup(const FString &name); void PopGroup(); void UpdateGpuStats(); + IntRect SetupTextureView(FCanvasTexture* tex); + void FinishTextureView(FCanvasTexture* tex); private: - void RenderTextureView(FCanvasTexture *tex, AActor *Viewpoint, double FOV); + void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; void PrintStartupLog(); void CreateFanToTrisIndexBuffer(); void CopyScreenToBuffer(int w, int h, uint8_t *data) override; From 9dceedd3b0f1cacb3de1975678747fd70b12f889 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 14:15:15 +0200 Subject: [PATCH 090/220] - cleanup --- src/rendering/gl/system/gl_framebuffer.cpp | 3 --- src/rendering/polyrenderer/backend/poly_framebuffer.cpp | 2 -- src/rendering/vulkan/system/vk_framebuffer.cpp | 3 --- 3 files changed, 8 deletions(-) diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index b2b3263f00..77bb54bfe8 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -216,9 +216,6 @@ void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::functionStartOffscreen(); GLRenderer->BindToFrameBuffer(tex); - // This doesn't need to clear the fake flat cache. It can be shared between camera textures and the main view of a scene. - float ratio = tex->aspectRatio; - IntRect bounds; bounds.left = bounds.top = 0; bounds.width = FHardwareTexture::GetTexDimension(tex->GetWidth()); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index dbbde9492b..b4491f6f92 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -292,10 +292,8 @@ sector_t *PolyFrameBuffer::RenderView(player_t *player) void PolyFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) { - // 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(tex->GetHardwareTexture(0, 0)); - float ratio = tex->aspectRatio; DCanvas *image = BaseLayer->GetImage(tex, 0, 0); PolyDepthStencil *depthStencil = BaseLayer->GetDepthStencil(tex); mRenderState->SetRenderTarget(image, depthStencil, false); diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index a276ee3a2b..ee236d945e 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -394,9 +394,7 @@ sector_t *VulkanFrameBuffer::RenderView(player_t *player) } void VulkanFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) - { - // 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(tex->GetHardwareTexture(0, 0)); VkTextureImage *image = BaseLayer->GetImage(tex, 0, 0); @@ -410,7 +408,6 @@ void VulkanFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::functionSetRenderTarget(image, depthStencil->View.get(), image->Image->width, image->Image->height, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT); - float ratio = tex->aspectRatio; IntRect bounds; bounds.left = bounds.top = 0; bounds.width = std::min(tex->GetWidth(), image->Image->width); From 10bc37b37eeded2797b423e9ac6a77a37f5d0b52 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 17:58:26 +0200 Subject: [PATCH 091/220] - moved RenderView out of the framebuffer classes to complete the consolidation of the renderer's entry points. --- src/d_main.cpp | 5 +- src/rendering/gl/renderer/gl_renderer.cpp | 16 ---- src/rendering/gl/renderer/gl_renderer.h | 4 - src/rendering/gl/renderer/gl_scene.cpp | 93 +++++++++++++++++++ src/rendering/gl/system/gl_framebuffer.cpp | 91 ------------------ src/rendering/gl/system/gl_framebuffer.h | 2 - src/rendering/hwrenderer/scene/hw_drawinfo.h | 2 + .../polyrenderer/backend/poly_framebuffer.cpp | 80 ---------------- .../polyrenderer/backend/poly_framebuffer.h | 4 - src/rendering/swrenderer/r_swscene.h | 1 + src/rendering/v_framebuffer.cpp | 1 + src/rendering/v_video.h | 4 +- .../vulkan/system/vk_framebuffer.cpp | 89 ++---------------- src/rendering/vulkan/system/vk_framebuffer.h | 5 +- 14 files changed, 108 insertions(+), 289 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index d699a69c1e..815a726d0f 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -113,6 +113,7 @@ #include "scriptutil.h" #include "v_palette.h" #include "texturemanager.h" +#include "hwrenderer/scene/hw_drawinfo.h" #ifdef __unix__ #include "i_system.h" // for SHARE_DIR @@ -925,7 +926,7 @@ void D_Display () D_Render([&]() { - viewsec = screen->RenderView(&players[consoleplayer]); + viewsec = RenderView(&players[consoleplayer]); }, true); screen->Begin2D(); @@ -3471,7 +3472,7 @@ void D_Cleanup() M_SaveDefaults(NULL); // save config before the restart // delete all data that cannot be left until reinitialization - if (screen) screen->CleanForRestart(); + CleanSWDrawer(); V_ClearFonts(); // must clear global font pointers ColorSets.Clear(); PainFlashes.Clear(); diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 79713ae756..acaed25007 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -63,8 +63,6 @@ EXTERN_CVAR(Int, screenblocks) -extern bool NoInterpolateView; - namespace OpenGLRenderer { @@ -124,7 +122,6 @@ FGLRenderer::~FGLRenderer() } if (PortalQueryObject != 0) glDeleteQueries(1, &PortalQueryObject); - if (swdrawer) delete swdrawer; if (mBuffers) delete mBuffers; if (mSaveBuffers) delete mSaveBuffers; if (mPresentShader) delete mPresentShader; @@ -140,19 +137,6 @@ FGLRenderer::~FGLRenderer() // //=========================================================================== -void FGLRenderer::ResetSWScene() -{ - // force recreation of the SW scene drawer to ensure it gets a new set of resources. - if (swdrawer != nullptr) delete swdrawer; - swdrawer = nullptr; -} - -//=========================================================================== -// -// -// -//=========================================================================== - bool FGLRenderer::StartOffscreen() { bool firstBind = (mFBID == 0); diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index ea8aaf44ae..5b61d7aa8f 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -68,8 +68,6 @@ public: //FRotator mAngles; - SWSceneDrawer *swdrawer = nullptr; - FGLRenderer(OpenGLFrameBuffer *fb); ~FGLRenderer() ; @@ -77,8 +75,6 @@ public: void ClearBorders(); - void ResetSWScene(); - void PresentStereo(); void RenderScreenQuad(); void PostProcessScene(int fixedcm, const std::function &afterBloomDrawEndScene2D); diff --git a/src/rendering/gl/renderer/gl_scene.cpp b/src/rendering/gl/renderer/gl_scene.cpp index 324703a453..dd8a22c9c7 100644 --- a/src/rendering/gl/renderer/gl_scene.cpp +++ b/src/rendering/gl/renderer/gl_scene.cpp @@ -32,6 +32,8 @@ #include "r_data/r_interpolate.h" #include "r_utility.h" #include "d_player.h" +#include "i_time.h" +#include "swrenderer/r_swscene.h" #include "swrenderer/r_renderer.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/utility/hw_clock.h" @@ -45,6 +47,16 @@ #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_vrmodes.h" +EXTERN_CVAR(Bool, cl_capfps) +extern bool NoInterpolateView; + +static SWSceneDrawer *swdrawer; + +void CleanSWDrawer() +{ + if (swdrawer) delete swdrawer; + swdrawer = nullptr; +} //----------------------------------------------------------------------------- // @@ -224,3 +236,84 @@ void WriteSavePic(player_t* player, FileWriter* file, int width, int height) } } +//=========================================================================== +// +// Renders the main view +// +//=========================================================================== + +sector_t* RenderView(player_t* player) +{ + auto RenderState = screen->RenderState(); + RenderState->SetVertexBuffer(screen->mVertexData); + screen->mVertexData->Reset(); + + sector_t* retsec; + if (!V_IsHardwareRenderer()) + { + screen->SetActiveRenderTarget(); // only relevant for Vulkan + + if (!swdrawer) swdrawer = new SWSceneDrawer; + retsec = swdrawer->RenderView(player); + } + else + { + hw_ClearFakeFlat(); + + iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; + + checkBenchActive(); + + // reset statistics counters + ResetProfilingData(); + + // Get this before everything else + if (cl_capfps || r_NoInterpolate) r_viewpoint.TicFrac = 1.; + else r_viewpoint.TicFrac = I_GetTimeFrac(); + + screen->mLights->Clear(); + screen->mViewpoints->Clear(); + + // NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below. + bool saved_niv = NoInterpolateView; + NoInterpolateView = false; + + // Shader start time does not need to be handled per level. Just use the one from the camera to render from. + if (player->camera) + RenderState->CheckTimer(player->camera->Level->ShaderStartTime); + // prepare all camera textures that have been used in the last frame. + // This must be done for all levels, not just the primary one! + for (auto Level : AllLevels()) + { + Level->canvasTextureInfo.UpdateAll([&](AActor* camera, FCanvasTexture* camtex, double fov) + { + screen->RenderTextureView(camtex, [=](IntRect& bounds) + { + FRenderViewpoint texvp; + float ratio = camtex->aspectRatio; + RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); + }); + }); + } + NoInterpolateView = saved_niv; + + // now render the main view + float fovratio; + float ratio = r_viewwindow.WidescreenRatio; + if (r_viewwindow.WidescreenRatio >= 1.3f) + { + fovratio = 1.333333f; + } + else + { + fovratio = ratio; + } + + screen->ImageTransitionScene(true); // Only relevant for Vulkan. + + retsec = RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); + } + All.Unclock(); + return retsec; +} + diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 77bb54bfe8..0ec8d4eafd 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -57,8 +57,6 @@ EXTERN_CVAR(Bool, r_drawvoxels) EXTERN_CVAR(Int, gl_tonemap) EXTERN_CVAR(Bool, cl_capfps) -extern bool NoInterpolateView; - void gl_LoadExtensions(); void gl_PrintStartupLog(); void Draw2D(F2DDrawer *drawer, FRenderState &state); @@ -228,89 +226,6 @@ void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function(screen)->camtexcount++; } -//=========================================================================== -// -// -// -//=========================================================================== - -sector_t *OpenGLFrameBuffer::RenderView(player_t *player) -{ - if (GLRenderer != nullptr) - { - gl_RenderState.SetVertexBuffer(screen->mVertexData); - screen->mVertexData->Reset(); - sector_t* retsec; - - if (!V_IsHardwareRenderer()) - { - if (GLRenderer->swdrawer == nullptr) GLRenderer->swdrawer = new SWSceneDrawer; - retsec = GLRenderer->swdrawer->RenderView(player); - } - else - { - hw_ClearFakeFlat(); - - iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; - - checkBenchActive(); - - // reset statistics counters - ResetProfilingData(); - - // Get this before everything else - if (cl_capfps || r_NoInterpolate) r_viewpoint.TicFrac = 1.; - else r_viewpoint.TicFrac = I_GetTimeFrac(); - - screen->mLights->Clear(); - screen->mViewpoints->Clear(); - - // NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below. - bool saved_niv = NoInterpolateView; - NoInterpolateView = false; - - // Shader start time does not need to be handled per level. Just use the one from the camera to render from. - if (player->camera) - gl_RenderState.CheckTimer(player->camera->Level->ShaderStartTime); - // prepare all camera textures that have been used in the last frame. - // This must be done for all levels, not just the primary one! - for (auto Level : AllLevels()) - { - Level->canvasTextureInfo.UpdateAll([&](AActor* camera, FCanvasTexture* camtex, double fov) - { - RenderTextureView(camtex, [=](IntRect &bounds) - { - FRenderViewpoint texvp; - float ratio = camtex->aspectRatio; - RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); - }); - }); - } - NoInterpolateView = saved_niv; - - - // now render the main view - float fovratio; - float ratio = r_viewwindow.WidescreenRatio; - if (r_viewwindow.WidescreenRatio >= 1.3f) - { - fovratio = 1.333333f; - } - else - { - fovratio = ratio; - } - - retsec = RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); - } - All.Unclock(); - return retsec; - } - return nullptr; -} - - - //=========================================================================== // // @@ -388,12 +303,6 @@ void OpenGLFrameBuffer::SetVSync(bool vsync) // //=========================================================================== -void OpenGLFrameBuffer::CleanForRestart() -{ - if (GLRenderer) - GLRenderer->ResetSWScene(); -} - void OpenGLFrameBuffer::SetTextureFilterMode() { if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode(); diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index f84fcf8b70..46a91e88c1 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -38,11 +38,9 @@ public: bool FlipSavePic() const override { return true; } FRenderState* RenderState() override; - void CleanForRestart() override; void UpdatePalette() override; uint32_t GetCaps() override; const char* DeviceName() const override; - sector_t *RenderView(player_t *player) override; void SetTextureFilterMode() override; IHardwareTexture *CreateHardwareTexture() override; void PrecacheMaterial(FMaterial *mat, int translation) override; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.h b/src/rendering/hwrenderer/scene/hw_drawinfo.h index a3eab8ccc1..65d12c56c5 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.h +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.h @@ -329,5 +329,7 @@ public: }; +void CleanSWDrawer(); sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void WriteSavePic(player_t* player, FileWriter* file, int width, int height); +sector_t* RenderView(player_t* player); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index b4491f6f92..6fbdb0fd41 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -59,7 +59,6 @@ EXTERN_CVAR(Int, gl_tonemap) EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Bool, cl_capfps) -extern bool NoInterpolateView; extern int rendered_commandbuffers; extern int current_rendered_commandbuffers; @@ -217,79 +216,6 @@ void PolyFrameBuffer::Update() } -sector_t *PolyFrameBuffer::RenderView(player_t *player) -{ - // To do: this is virtually identical to FGLRenderer::RenderView and should be merged. - - mRenderState->SetVertexBuffer(mVertexData); - mVertexData->Reset(); - - sector_t *retsec; - if (!V_IsHardwareRenderer()) - { - if (!swdrawer) swdrawer.reset(new SWSceneDrawer); - retsec = swdrawer->RenderView(player); - } - else - { - hw_ClearFakeFlat(); - - iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; - - checkBenchActive(); - - // reset statistics counters - ResetProfilingData(); - - // Get this before everything else - if (cl_capfps || r_NoInterpolate) r_viewpoint.TicFrac = 1.; - else r_viewpoint.TicFrac = I_GetTimeFrac(); - - mLights->Clear(); - mViewpoints->Clear(); - - // NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below. - bool saved_niv = NoInterpolateView; - NoInterpolateView = false; - - // Shader start time does not need to be handled per level. Just use the one from the camera to render from. - if (player->camera) - GetRenderState()->CheckTimer(player->camera->Level->ShaderStartTime); - // prepare all camera textures that have been used in the last frame. - // This must be done for all levels, not just the primary one! - for (auto Level : AllLevels()) - { - Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) - { - RenderTextureView(camtex, [=](IntRect &bounds) - { - FRenderViewpoint texvp; - float ratio = camtex->aspectRatio; - RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); - }); - }); - } - NoInterpolateView = saved_niv; - - // now render the main view - float fovratio; - float ratio = r_viewwindow.WidescreenRatio; - if (r_viewwindow.WidescreenRatio >= 1.3f) - { - fovratio = 1.333333f; - } - else - { - fovratio = ratio; - } - - retsec = RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); - } - All.Unclock(); - return retsec; -} - - void PolyFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) { auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); @@ -384,12 +310,6 @@ void PolyFrameBuffer::SetVSync(bool vsync) cur_vsync = vsync; } -void PolyFrameBuffer::CleanForRestart() -{ - // force recreation of the SW scene drawer to ensure it gets a new set of resources. - swdrawer.reset(); -} - FRenderState* PolyFrameBuffer::RenderState() { return mRenderState.get(); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index d902e6fe3f..b3c2c56101 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -24,8 +24,6 @@ public: unsigned int GetLightBufferBlockSize() const; - std::unique_ptr swdrawer; - PolyFrameBuffer(void *hMonitor, bool fullscreen); ~PolyFrameBuffer(); @@ -36,11 +34,9 @@ public: void InitializeState() override; FRenderState* RenderState() override; - void CleanForRestart() override; void PrecacheMaterial(FMaterial *mat, int translation) override; void UpdatePalette() override; uint32_t GetCaps() override; - sector_t *RenderView(player_t *player) override; void SetTextureFilterMode() override; void TextureFilterChanged() override; void BeginFrame() override; diff --git a/src/rendering/swrenderer/r_swscene.h b/src/rendering/swrenderer/r_swscene.h index ad6b6d450c..cff2eb7a55 100644 --- a/src/rendering/swrenderer/r_swscene.h +++ b/src/rendering/swrenderer/r_swscene.h @@ -9,6 +9,7 @@ #include class FWrapperTexture; +class DCanvas; class SWSceneDrawer { diff --git a/src/rendering/v_framebuffer.cpp b/src/rendering/v_framebuffer.cpp index 143189a3f1..470409c9ab 100644 --- a/src/rendering/v_framebuffer.cpp +++ b/src/rendering/v_framebuffer.cpp @@ -51,6 +51,7 @@ #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/flatvertices.h" +#include "swrenderer/r_swscene.h" #include #include diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 79aa6cbdca..d01775676c 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -215,7 +215,6 @@ public: IntRect mOutputLetterbox; float mSceneClearColor[4]; - public: DFrameBuffer (int width=1, int height=1); virtual ~DFrameBuffer(); @@ -261,7 +260,6 @@ public: virtual void SetVSync (bool vsync); // Delete any resources that need to be deleted after restarting with a different IWAD - virtual void CleanForRestart() {} virtual void SetTextureFilterMode() {} virtual IHardwareTexture *CreateHardwareTexture() { return nullptr; } virtual void PrecacheMaterial(FMaterial *mat, int translation) {} @@ -309,7 +307,6 @@ public: virtual uint32_t GetCaps(); virtual int Backend() { return 0; } virtual const char* DeviceName() const { return "Unknown"; } - virtual sector_t *RenderView(player_t *player) { return nullptr; } virtual void AmbientOccludeScene(float m5) {} virtual void FirstEye() {} virtual void NextEye(int eyecount) {} @@ -321,6 +318,7 @@ public: virtual void CopyScreenToBuffer(int width, int height, uint8_t* buffer) { memset(buffer, 0, width* height); } virtual bool FlipSavePic() const { return false; } virtual void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) {} + virtual void SetActiveRenderTarget() {} // Screen wiping diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index ee236d945e..7cf64196b4 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -67,7 +67,6 @@ EXTERN_CVAR(Int, gl_tonemap) EXTERN_CVAR(Int, screenblocks) EXTERN_CVAR(Bool, cl_capfps) -extern bool NoInterpolateView; extern int rendered_commandbuffers; int current_rendered_commandbuffers; @@ -317,82 +316,6 @@ void VulkanFrameBuffer::WaitForCommands(bool finish) } } -sector_t *VulkanFrameBuffer::RenderView(player_t *player) -{ - // To do: this is virtually identical to FGLRenderer::RenderView and should be merged. - - mRenderState->SetVertexBuffer(screen->mVertexData); - screen->mVertexData->Reset(); - - sector_t *retsec; - if (!V_IsHardwareRenderer()) - { - mPostprocess->SetActiveRenderTarget(); - - if (!swdrawer) swdrawer.reset(new SWSceneDrawer); - retsec = swdrawer->RenderView(player); - } - else - { - hw_ClearFakeFlat(); - - iter_dlightf = iter_dlight = draw_dlight = draw_dlightf = 0; - - checkBenchActive(); - - // reset statistics counters - ResetProfilingData(); - - // Get this before everything else - if (cl_capfps || r_NoInterpolate) r_viewpoint.TicFrac = 1.; - else r_viewpoint.TicFrac = I_GetTimeFrac(); - - screen->mLights->Clear(); - screen->mViewpoints->Clear(); - - // NoInterpolateView should have no bearing on camera textures, but needs to be preserved for the main view below. - bool saved_niv = NoInterpolateView; - NoInterpolateView = false; - - // Shader start time does not need to be handled per level. Just use the one from the camera to render from. - if (player->camera) - GetRenderState()->CheckTimer(player->camera->Level->ShaderStartTime); - // prepare all camera textures that have been used in the last frame. - // This must be done for all levels, not just the primary one! - for (auto Level : AllLevels()) - { - Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) - { - RenderTextureView(camtex, [=](IntRect &bounds) - { - FRenderViewpoint texvp; - float ratio = camtex->aspectRatio; - RenderViewpoint(texvp, camera, &bounds, fov, ratio, ratio, false, false); - }); - }); - } - NoInterpolateView = saved_niv; - - // now render the main view - float fovratio; - float ratio = r_viewwindow.WidescreenRatio; - if (r_viewwindow.WidescreenRatio >= 1.3f) - { - fovratio = 1.333333f; - } - else - { - fovratio = ratio; - } - - mPostprocess->ImageTransitionScene(true); // This is the only line that differs compared to FGLRenderer::RenderView - - retsec = RenderViewpoint(r_viewpoint, player->camera, NULL, r_viewpoint.FieldOfView.Degrees, ratio, fovratio, true, true); - } - All.Unclock(); - return retsec; -} - void VulkanFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) { auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); @@ -462,12 +385,6 @@ void VulkanFrameBuffer::SetVSync(bool vsync) cur_vsync = vsync; } -void VulkanFrameBuffer::CleanForRestart() -{ - // force recreation of the SW scene drawer to ensure it gets a new set of resources. - swdrawer.reset(); -} - void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) { if (mat->Source()->GetUseType() == ETextureType::SWCanvas) return; @@ -638,6 +555,12 @@ void VulkanFrameBuffer::CopyScreenToBuffer(int w, int h, uint8_t *data) staging->Unmap(); } +void VulkanFrameBuffer::SetActiveRenderTarget() +{ + mPostprocess->SetActiveRenderTarget(); +} + + TArray VulkanFrameBuffer::GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma) { int w = SCREENWIDTH; diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 9b26c4b153..9acc4c70f4 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -64,8 +64,6 @@ public: std::vector> CommandBuffers; } FrameDeleteList; - std::unique_ptr swdrawer; - VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevice *dev); ~VulkanFrameBuffer(); bool IsVulkan() override { return true; } @@ -74,13 +72,11 @@ public: void InitializeState() override; - void CleanForRestart() override; void PrecacheMaterial(FMaterial *mat, int translation) override; void UpdatePalette() override; uint32_t GetCaps() override; const char* DeviceName() const override; int Backend() override { return 1; } - sector_t *RenderView(player_t *player) override; void SetTextureFilterMode() override; void TextureFilterChanged() override; void StartPrecaching() override; @@ -92,6 +88,7 @@ public: void UpdateShadowMap() override; void SetSaveBuffers(bool yes) override; void ImageTransitionScene(bool unknown) override; + void SetActiveRenderTarget() override; IHardwareTexture *CreateHardwareTexture() override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; From 9872065fc6a5be73b3ec5853c5a7f1663a20484b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 18:38:17 +0200 Subject: [PATCH 092/220] - moved file to its proper place. --- src/CMakeLists.txt | 2 +- .../{gl/renderer/gl_scene.cpp => hwrenderer/hw_entrypoint.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/rendering/{gl/renderer/gl_scene.cpp => hwrenderer/hw_entrypoint.cpp} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d035e752e5..902091b7a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -949,7 +949,6 @@ set (PCH_SOURCES rendering/gl/renderer/gl_postprocess.cpp rendering/gl/renderer/gl_postprocessstate.cpp rendering/gl/renderer/gl_stereo3d.cpp - rendering/gl/renderer/gl_scene.cpp rendering/gl/shaders/gl_shader.cpp rendering/gl/shaders/gl_shaderprogram.cpp rendering/gl/system/gl_framebuffer.cpp @@ -957,6 +956,7 @@ set (PCH_SOURCES rendering/gl/system/gl_buffers.cpp rendering/gl/textures/gl_hwtexture.cpp rendering/gl/textures/gl_samplers.cpp + rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp rendering/hwrenderer/data/flatvertices.cpp rendering/hwrenderer/data/hw_viewpointbuffer.cpp diff --git a/src/rendering/gl/renderer/gl_scene.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp similarity index 100% rename from src/rendering/gl/renderer/gl_scene.cpp rename to src/rendering/hwrenderer/hw_entrypoint.cpp From 59360f2d77f4f6c6d7dd97eb67208a3eb331d834 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 21:08:07 +0200 Subject: [PATCH 093/220] - started cleanup of dependencies of the framebuffer class. * made the portal state global, outside the framebuffer, because it is pure logic state without dependencies on the backend. * took the setup functions out of FDynLightData - there is no need to have them as members and they age game dependent. --- .../hwrenderer/dynlights/hw_dynlightdata.cpp | 11 ++++---- .../hwrenderer/dynlights/hw_dynlightdata.h | 5 ---- .../hwrenderer/dynlights/hw_lightbuffer.h | 1 - .../hwrenderer/dynlights/hw_shadowmap.cpp | 1 + src/rendering/hwrenderer/hw_entrypoint.cpp | 1 + src/rendering/hwrenderer/models/hw_models.cpp | 4 +-- .../hwrenderer/scene/hw_drawinfo.cpp | 10 +++---- .../hwrenderer/scene/hw_drawlistadd.cpp | 1 + .../hwrenderer/scene/hw_drawstructs.h | 5 ++++ src/rendering/hwrenderer/scene/hw_flats.cpp | 3 +- src/rendering/hwrenderer/scene/hw_portal.cpp | 1 + src/rendering/hwrenderer/scene/hw_portal.h | 2 ++ .../hwrenderer/scene/hw_renderhacks.cpp | 3 +- .../hwrenderer/scene/hw_renderstate.cpp | 2 +- .../hwrenderer/scene/hw_spritelight.cpp | 4 ++- src/rendering/hwrenderer/scene/hw_walls.cpp | 28 +++++++++---------- 16 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp index 5139b545d7..c7107f8470 100644 --- a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp @@ -26,8 +26,9 @@ **/ #include "actorinlines.h" - +#include "a_dynlight.h" #include "hw_dynlightdata.h" +#include "hwrenderer/scene/hw_drawstructs.h" // If we want to share the array to avoid constant allocations it needs to be thread local unless it'd be littered with expensive synchronization. thread_local FDynLightData lightdata; @@ -48,7 +49,7 @@ CVAR (Bool, gl_light_particles, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); // Sets up the parameters to render one dynamic light onto one plane // //========================================================================== -bool FDynLightData::GetLight(int group, Plane & p, FDynamicLight * light, bool checkside) +bool GetLight(FDynLightData& dld, int group, Plane & p, FDynamicLight * light, bool checkside) { DVector3 pos = light->PosRelative(group); float radius = (light->GetRadius()); @@ -62,7 +63,7 @@ bool FDynLightData::GetLight(int group, Plane & p, FDynamicLight * light, bool c return false; } - AddLightToList(group, light, false); + AddLightToList(dld, group, light, false); return true; } @@ -71,7 +72,7 @@ bool FDynLightData::GetLight(int group, Plane & p, FDynamicLight * light, bool c // Add one dynamic light to the light data list // //========================================================================== -void FDynLightData::AddLightToList(int group, FDynamicLight * light, bool forceAttenuate) +void AddLightToList(FDynLightData &dld, int group, FDynamicLight * light, bool forceAttenuate) { int i = 0; @@ -129,7 +130,7 @@ void FDynLightData::AddLightToList(int group, FDynamicLight * light, bool forceA spotDirZ = float(-Angle.Sin() * xzLen); } - float *data = &arrays[i][arrays[i].Reserve(16)]; + float *data = &dld.arrays[i][dld.arrays[i].Reserve(16)]; data[0] = float(pos.X); data[1] = float(pos.Z); data[2] = float(pos.Y); diff --git a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h index ec5f6d89ea..e24e49bed6 100644 --- a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h +++ b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h @@ -23,9 +23,6 @@ #ifndef __GLC_DYNLIGHT_H #define __GLC_DYNLIGHT_H -#include "a_dynlight.h" - - struct FDynLightData { TArray arrays[3]; @@ -53,8 +50,6 @@ struct FDynLightData if (siz[2] > max) siz[2] = max; } - bool GetLight(int group, Plane & p, FDynamicLight * light, bool checkside); - void AddLightToList(int group, FDynamicLight * light, bool forceAttenuate); }; diff --git a/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h b/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h index df9d679a7f..aae08dbedf 100644 --- a/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h +++ b/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h @@ -43,7 +43,6 @@ public: }; -int gl_SetDynModelLight(AActor *self, int dynlightindex); #endif diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp index aba51140a8..e9fb4686f5 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp @@ -28,6 +28,7 @@ #include "stats.h" #include "g_levellocals.h" #include "v_video.h" +#include "a_dynlight.h" /* The 1D shadow maps are stored in a 1024x1024 texture as float depth values (R32F). diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index dd8a22c9c7..d4e9fdab9e 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -27,6 +27,7 @@ #include "gl_system.h" #include "gi.h" +#include "a_dynlight.h" #include "m_png.h" #include "doomstat.h" #include "r_data/r_interpolate.h" diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 9eff4f2053..6b1aa5a33b 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -62,7 +62,7 @@ void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, con // TO-DO: Implement proper depth sorting. if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES)) { - state.SetCulling((mirrored ^ screen->mPortalState->isMirrored()) ? Cull_CCW : Cull_CW); + state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CCW : Cull_CW); } state.mModelMatrix = objectToWorldMatrix; @@ -86,7 +86,7 @@ void FHWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectTo // TO-DO: Implement proper depth sorting. if (!(actor->RenderStyle == DefaultRenderStyle())) { - state.SetCulling((mirrored ^ screen->mPortalState->isMirrored()) ? Cull_CW : Cull_CCW); + state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CW : Cull_CCW); } state.mModelMatrix = objectToWorldMatrix; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index b1cad03a1e..e1697adec3 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -432,7 +432,7 @@ void HWDrawInfo::CreateScene(bool drawpsprites) mClipper->SafeAddClipRangeRealAngles(vp.Angles.Yaw.BAMs() + a1, vp.Angles.Yaw.BAMs() - a1); // reset the portal manager - screen->mPortalState->StartFrame(); + portalState.StartFrame(); ProcessAll.Clock(); @@ -689,7 +689,7 @@ void HWDrawInfo::DrawScene(int drawmode) auto& RenderState = *screen->RenderState(); RenderState.SetDepthMask(true); - if (!gl_no_skyclear) screen->mPortalState->RenderFirstSkyPortal(recursion, this, RenderState); + if (!gl_no_skyclear) portalState.RenderFirstSkyPortal(recursion, this, RenderState); RenderScene(RenderState); @@ -702,7 +702,7 @@ void HWDrawInfo::DrawScene(int drawmode) // Handle all portals after rendering the opaque objects but before // doing all translucent stuff recursion++; - screen->mPortalState->EndFrame(this, RenderState); + portalState.EndFrame(this, RenderState); recursion--; RenderTranslucent(RenderState); } @@ -716,7 +716,7 @@ void HWDrawInfo::DrawScene(int drawmode) void HWDrawInfo::ProcessScene(bool toscreen) { - screen->mPortalState->BeginScene(); + portalState.BeginScene(); int mapsection = Level->PointInRenderSubsector(Viewpoint.Pos)->mapsection; CurrentMapSections.Set(mapsection); @@ -735,7 +735,7 @@ void HWDrawInfo::AddSubsectorToPortal(FSectorPortalGroup *ptg, subsector_t *sub) auto portal = FindPortal(ptg); if (!portal) { - portal = new HWSectorStackPortal(screen->mPortalState, ptg); + portal = new HWSectorStackPortal(&portalState, ptg); Portals.Push(portal); } auto ptl = static_cast(portal); diff --git a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp index 7224824d35..3c4a85f38a 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -26,6 +26,7 @@ #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hw_material.h" +#include "actor.h" EXTERN_CVAR(Bool, gl_seamless) diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index e8a244562d..271f24a09b 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -430,3 +430,8 @@ bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FGameTexture * g void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata); extern const float LARGE_VALUE; + +struct FDynLightData; +struct FDynamicLight; +bool GetLight(FDynLightData& dld, int group, Plane& p, FDynamicLight* light, bool checkside); +void AddLightToList(FDynLightData &dld, int group, FDynamicLight* light, bool forceAttenuate); diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 82ce3ac4ea..eb64cea2a3 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -26,6 +26,7 @@ */ #include "a_sharedglobal.h" +#include "a_dynlight.h" #include "r_defs.h" #include "r_sky.h" #include "r_utility.h" @@ -168,7 +169,7 @@ void HWFlat::SetupLights(HWDrawInfo *di, FLightNode * node, FDynLightData &light } p.Set(plane.plane.Normal(), plane.plane.fD()); - draw_dlightf += lightdata.GetLight(portalgroup, p, light, false); + draw_dlightf += GetLight(lightdata, portalgroup, p, light, false); node = node->nextLight; } diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index 69c9631484..11d0e95f1d 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -71,6 +71,7 @@ CCMD(gl_portalinfo) } static FString indent; +FPortalSceneState portalState; //----------------------------------------------------------------------------- // diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index a6bf05f42f..28767e15de 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -128,6 +128,8 @@ struct FPortalSceneState void RenderPortal(HWPortal *p, FRenderState &state, bool usestencil, HWDrawInfo *outer_di); }; +extern FPortalSceneState portalState; + class HWScenePortalBase : public HWPortal { diff --git a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp index 6ebdab3f8a..cc8a2af3e8 100644 --- a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp @@ -26,6 +26,7 @@ */ #include "a_sharedglobal.h" +#include "a_dynlight.h" #include "r_utility.h" #include "r_sky.h" #include "g_levellocals.h" @@ -128,7 +129,7 @@ int HWDrawInfo::SetupLightsForOtherPlane(subsector_t * sub, FDynLightData &light iter_dlightf++; p.Set(plane->Normal(), plane->fD()); - draw_dlightf += lightdata.GetLight(sub->sector->PortalGroup, p, light, true); + draw_dlightf += GetLight(lightdata, sub->sector->PortalGroup, p, light, true); node = node->nextLight; } diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.cpp b/src/rendering/hwrenderer/scene/hw_renderstate.cpp index 60fad5dbb0..3f08c7f333 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderstate.cpp @@ -118,7 +118,7 @@ void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool } // Make fog a little denser when inside a skybox - if (screen->mPortalState->inskybox) fogdensity += fogdensity / 2; + if (portalState.inskybox) fogdensity += fogdensity / 2; // no fog in enhanced vision modes! diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index a8bc1f849d..b5019975f4 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -26,6 +26,7 @@ */ #include "c_dispatch.h" +#include "a_dynlight.h" #include "p_local.h" #include "p_effect.h" #include "g_level.h" @@ -34,6 +35,7 @@ #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/dynlights/hw_shadowmap.h" #include "hwrenderer/scene/hw_drawinfo.h" +#include "hwrenderer/scene/hw_drawstructs.h" #include "r_data/models/models.h" template @@ -182,7 +184,7 @@ void hw_GetDynModelLight(AActor *self, FDynLightData &modellightdata) { if (std::find(addedLights.begin(), addedLights.end(), light) == addedLights.end()) // Check if we already added this light from a different subsector { - modellightdata.AddLightToList(group, light, true); + AddLightToList(modellightdata, group, light, true); addedLights.Push(light); } } diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index eb907770fd..dcde26054d 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -22,6 +22,7 @@ #include "p_local.h" #include "p_lnspec.h" +#include "a_dynlight.h" #include "a_sharedglobal.h" #include "r_defs.h" #include "r_sky.h" @@ -412,7 +413,7 @@ void HWWall::SetupLights(HWDrawInfo *di, FDynLightData &lightdata) } if (outcnt[0]!=4 && outcnt[1]!=4 && outcnt[2]!=4 && outcnt[3]!=4) { - draw_dlight += lightdata.GetLight(seg->frontsector->PortalGroup, p, node->lightsource, true); + draw_dlight += GetLight(lightdata, seg->frontsector->PortalGroup, p, node->lightsource, true); } } } @@ -497,7 +498,6 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent) void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) { - auto pstate = screen->mPortalState; HWPortal * portal = nullptr; MakeVertices(di, false); @@ -506,11 +506,11 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) // portals don't go into the draw list. // Instead they are added to the portal manager case PORTALTYPE_HORIZON: - horizon = pstate->UniqueHorizons.Get(horizon); + horizon = portalState.UniqueHorizons.Get(horizon); portal = di->FindPortal(horizon); if (!portal) { - portal = new HWHorizonPortal(pstate, horizon, di->Viewpoint); + portal = new HWHorizonPortal(&portalState, horizon, di->Viewpoint); di->Portals.Push(portal); } portal->AddLine(this); @@ -521,10 +521,10 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) if (!portal) { // either a regular skybox or an Eternity-style horizon - if (secportal->mType != PORTS_SKYVIEWPOINT) portal = new HWEEHorizonPortal(pstate, secportal); + if (secportal->mType != PORTS_SKYVIEWPOINT) portal = new HWEEHorizonPortal(&portalState, secportal); else { - portal = new HWSkyboxPortal(pstate, secportal); + portal = new HWSkyboxPortal(&portalState, secportal); di->Portals.Push(portal); } } @@ -535,20 +535,20 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) portal = di->FindPortal(this->portal); if (!portal) { - portal = new HWSectorStackPortal(pstate, this->portal); + portal = new HWSectorStackPortal(&portalState, this->portal); di->Portals.Push(portal); } portal->AddLine(this); break; case PORTALTYPE_PLANEMIRROR: - if (pstate->PlaneMirrorMode * planemirror->fC() <= 0) + if (portalState.PlaneMirrorMode * planemirror->fC() <= 0) { - planemirror = pstate->UniquePlaneMirrors.Get(planemirror); + planemirror = portalState.UniquePlaneMirrors.Get(planemirror); portal = di->FindPortal(planemirror); if (!portal) { - portal = new HWPlaneMirrorPortal(pstate, planemirror); + portal = new HWPlaneMirrorPortal(&portalState, planemirror); di->Portals.Push(portal); } portal->AddLine(this); @@ -559,7 +559,7 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) portal = di->FindPortal(seg->linedef); if (!portal) { - portal = new HWMirrorPortal(pstate, seg->linedef); + portal = new HWMirrorPortal(&portalState, seg->linedef); di->Portals.Push(portal); } portal->AddLine(this); @@ -581,18 +581,18 @@ void HWWall::PutPortal(HWDrawInfo *di, int ptype, int plane) { di->ProcessActorsInPortal(otherside->getPortal()->mGroup, di->in_area); } - portal = new HWLineToLinePortal(pstate, lineportal); + portal = new HWLineToLinePortal(&portalState, lineportal); di->Portals.Push(portal); } portal->AddLine(this); break; case PORTALTYPE_SKY: - sky = pstate->UniqueSkies.Get(sky); + sky = portalState.UniqueSkies.Get(sky); portal = di->FindPortal(sky); if (!portal) { - portal = new HWSkyPortal(screen->mSkyData, pstate, sky); + portal = new HWSkyPortal(screen->mSkyData, &portalState, sky); di->Portals.Push(portal); } portal->AddLine(this); From b9e3c9681ba64911580c50b5c59d0ec4e7450e35 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 21:52:21 +0200 Subject: [PATCH 094/220] - moved a few files from 'rendering' to 'common'. --- src/CMakeLists.txt | 2 +- src/common/engine/i_interface.h | 2 +- src/{ => common}/rendering/i_video.h | 0 src/{ => common}/rendering/r_videoscale.cpp | 18 ++++++++---------- src/{ => common}/rendering/r_videoscale.h | 0 src/d_main.cpp | 12 ++++++++++++ src/rendering/gl/renderer/gl_postprocess.cpp | 2 -- .../polyrenderer/backend/poly_framebuffer.cpp | 3 +-- src/rendering/v_video.h | 3 --- 9 files changed, 23 insertions(+), 19 deletions(-) rename src/{ => common}/rendering/i_video.h (100%) rename src/{ => common}/rendering/r_videoscale.cpp (96%) rename src/{ => common}/rendering/r_videoscale.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 902091b7a2..9fb536ca3c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -876,7 +876,6 @@ set (PCH_SOURCES playsim/p_user.cpp rendering/r_utility.cpp rendering/r_sky.cpp - rendering/r_videoscale.cpp sound/s_advsound.cpp sound/s_reverbedit.cpp sound/s_sndseq.cpp @@ -1147,6 +1146,7 @@ set (PCH_SOURCES common/objects/dobject.cpp common/objects/dobjgc.cpp common/objects/dobjtype.cpp + common/rendering/r_videoscale.cpp common/rendering/gl_load/gl_interface.cpp common/scripting/core/dictionary.cpp common/scripting/core/dynarrays.cpp diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index d992203d9e..564b7d91c0 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -11,7 +11,7 @@ struct SystemCallbacks bool (*CaptureModeInGame)(); void (*CrashInfo)(char* buffer, size_t bufflen, const char* lfstr); void (*PlayStartupSound)(const char* name); - + bool (*IsSpecialUI)(); }; extern SystemCallbacks *sysCallbacks; diff --git a/src/rendering/i_video.h b/src/common/rendering/i_video.h similarity index 100% rename from src/rendering/i_video.h rename to src/common/rendering/i_video.h diff --git a/src/rendering/r_videoscale.cpp b/src/common/rendering/r_videoscale.cpp similarity index 96% rename from src/rendering/r_videoscale.cpp rename to src/common/rendering/r_videoscale.cpp index a71ee7c3eb..b528d992f6 100644 --- a/src/rendering/r_videoscale.cpp +++ b/src/common/rendering/r_videoscale.cpp @@ -36,19 +36,15 @@ #include "v_video.h" #include "templates.h" #include "r_videoscale.h" - -#include "c_console.h" -#include "menu/menu.h" +#include "cmdlib.h" +#include "v_draw.h" +#include "i_interface.h" #define NUMSCALEMODES countof(vScaleTable) - -extern bool setsizeneeded, multiplayer, generic_ui; +extern bool setsizeneeded; EXTERN_CVAR(Int, vid_aspect) -EXTERN_CVAR(Bool, log_vgafont) -EXTERN_CVAR(Bool, dlg_vgafont) - CUSTOM_CVAR(Int, vid_scale_customwidth, VID_MIN_WIDTH, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { if (self < VID_MIN_WIDTH) @@ -69,6 +65,9 @@ CUSTOM_CVAR(Float, vid_scale_custompixelaspect, 1.0, CVAR_ARCHIVE | CVAR_GLOBALC self = 1.0; } +static const int VID_MIN_UI_WIDTH = 640; +static const int VID_MIN_UI_HEIGHT = 400; + namespace { uint32_t min_width = VID_MIN_WIDTH; @@ -108,8 +107,7 @@ namespace static bool lastspecialUI = false; bool isInActualMenu = false; - bool specialUI = (generic_ui || !!log_vgafont || !!dlg_vgafont || ConsoleState != c_up || multiplayer || - (menuactive == MENU_On && CurrentMenu && !CurrentMenu->IsKindOf("ConversationMenu"))); + bool specialUI = sysCallbacks && (!sysCallbacks->IsSpecialUI || sysCallbacks->IsSpecialUI()); if (specialUI == lastspecialUI) return; diff --git a/src/rendering/r_videoscale.h b/src/common/rendering/r_videoscale.h similarity index 100% rename from src/rendering/r_videoscale.h rename to src/common/rendering/r_videoscale.h diff --git a/src/d_main.cpp b/src/d_main.cpp index 815a726d0f..5d7f8f19e7 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -122,6 +122,9 @@ EXTERN_CVAR(Bool, hud_althud) EXTERN_CVAR(Int, vr_mode) EXTERN_CVAR(Bool, cl_customizeinvulmap) +EXTERN_CVAR(Bool, log_vgafont) +EXTERN_CVAR(Bool, dlg_vgafont) + void DrawHUD(); void D_DoAnonStats(); void I_DetectOS(); @@ -2645,6 +2648,13 @@ static void System_PlayStartupSound(const char* sndname) S_Sound(CHAN_BODY, 0, sndname, 1, ATTN_NONE); } +static bool System_IsSpecialUI() +{ + return (generic_ui || !!log_vgafont || !!dlg_vgafont || ConsoleState != c_up || multiplayer || + (menuactive == MENU_On && CurrentMenu && !CurrentMenu->IsKindOf("ConversationMenu"))); + +} + //========================================================================== // // DoomSpecificInfo @@ -2848,6 +2858,8 @@ static int D_DoomMain_Internal (void) System_WantNativeMouse, System_CaptureModeInGame, System_CrashInfo, + System_PlayStartupSound, + System_IsSpecialUI, }; sysCallbacks = &syscb; diff --git a/src/rendering/gl/renderer/gl_postprocess.cpp b/src/rendering/gl/renderer/gl_postprocess.cpp index 8d1cee2c6d..274667c321 100644 --- a/src/rendering/gl/renderer/gl_postprocess.cpp +++ b/src/rendering/gl/renderer/gl_postprocess.cpp @@ -20,10 +20,8 @@ */ #include "gl_system.h" -#include "gi.h" #include "m_png.h" #include "r_utility.h" -#include "d_player.h" #include "gl/system/gl_buffers.h" #include "gl/system/gl_framebuffer.h" #include "hwrenderer/utility/hw_cvars.h" diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 6fbdb0fd41..24aea91793 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -27,8 +27,7 @@ #include "i_time.h" #include "g_game.h" #include "v_text.h" - -#include "rendering/i_video.h" +#include "i_video.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_vrmodes.h" diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index d01775676c..91934bc6ba 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -51,9 +51,6 @@ static const int VID_MIN_WIDTH = 320; static const int VID_MIN_HEIGHT = 200; -static const int VID_MIN_UI_WIDTH = 640; -static const int VID_MIN_UI_HEIGHT = 400; - class player_t; struct sector_t; struct FPortalSceneState; From b6cc31eb0d5ad5af5b3cf99fc8f63efd747f4772 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 22:17:41 +0200 Subject: [PATCH 095/220] - moved around a few more files. --- src/CMakeLists.txt | 5 +++++ src/{ => common}/rendering/hwrenderer/data/buffers.h | 0 src/{ => common}/rendering/hwrenderer/data/renderqueue.h | 0 src/{ => common}/rendering/hwrenderer/data/shaderuniforms.h | 0 src/common/rendering/r_videoscale.cpp | 1 + src/r_data/v_palette.cpp | 1 + src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp | 1 - src/rendering/v_video.h | 4 ---- 8 files changed, 7 insertions(+), 5 deletions(-) rename src/{ => common}/rendering/hwrenderer/data/buffers.h (100%) rename src/{ => common}/rendering/hwrenderer/data/renderqueue.h (100%) rename src/{ => common}/rendering/hwrenderer/data/shaderuniforms.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9fb536ca3c..494127d5d1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -617,7 +617,9 @@ file( GLOB HEADER_FILES common/thirdparty/*.h common/thirdparty/rapidjson/*.h common/thirdparty/math/*h + common/rendering/*.h common/rendering/gl_load/*.h + common/rendering/hwrenderer/data/*.h common/scripting/core/*h common/scripting/vm/*h common/scripting/jit/*h @@ -1257,6 +1259,7 @@ include_directories( . common/fonts common/objects common/rendering + common/rendering/hwrenderer/data common/rendering/gl_load common/scripting/vm common/scripting/jit @@ -1473,6 +1476,8 @@ source_group("Common\\Platforms\\Unix Files" REGULAR_EXPRESSION "^${CMAKE_CURREN source_group("Common\\Platforms\\SDL Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/posix/sdl/.+") source_group("Common\\Platforms\\Win32 Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/win32/.+") source_group("Common\\Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/.+") +source_group("Common\\Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/.+") +source_group("Common\\Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/data/.+") source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+") source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+") source_group("Common\\Textures\\Hires" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/.+") diff --git a/src/rendering/hwrenderer/data/buffers.h b/src/common/rendering/hwrenderer/data/buffers.h similarity index 100% rename from src/rendering/hwrenderer/data/buffers.h rename to src/common/rendering/hwrenderer/data/buffers.h diff --git a/src/rendering/hwrenderer/data/renderqueue.h b/src/common/rendering/hwrenderer/data/renderqueue.h similarity index 100% rename from src/rendering/hwrenderer/data/renderqueue.h rename to src/common/rendering/hwrenderer/data/renderqueue.h diff --git a/src/rendering/hwrenderer/data/shaderuniforms.h b/src/common/rendering/hwrenderer/data/shaderuniforms.h similarity index 100% rename from src/rendering/hwrenderer/data/shaderuniforms.h rename to src/common/rendering/hwrenderer/data/shaderuniforms.h diff --git a/src/common/rendering/r_videoscale.cpp b/src/common/rendering/r_videoscale.cpp index b528d992f6..236493fb1f 100644 --- a/src/common/rendering/r_videoscale.cpp +++ b/src/common/rendering/r_videoscale.cpp @@ -39,6 +39,7 @@ #include "cmdlib.h" #include "v_draw.h" #include "i_interface.h" +#include "printf.h" #define NUMSCALEMODES countof(vScaleTable) extern bool setsizeneeded; diff --git a/src/r_data/v_palette.cpp b/src/r_data/v_palette.cpp index 800e0fab35..2c78131e36 100644 --- a/src/r_data/v_palette.cpp +++ b/src/r_data/v_palette.cpp @@ -49,6 +49,7 @@ #include "x86.h" #include "g_levellocals.h" #include "m_png.h" +#include "v_colortables.h" /* Current color blending values */ int BlendR, BlendG, BlendB, BlendA; diff --git a/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp b/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp index 268bd4902c..3846a4ccdb 100644 --- a/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp +++ b/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp @@ -27,7 +27,6 @@ #include "hwrenderer/data/shaderuniforms.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" -#include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_renderstate.h" #include "hw_viewpointbuffer.h" diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 91934bc6ba..dc98b80e54 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -35,15 +35,11 @@ #define __V_VIDEO_H__ #include -#include "doomtype.h" #include "vectors.h" -#include "doomdef.h" #include "m_png.h" -#include "dobject.h" #include "renderstyle.h" #include "c_cvars.h" -#include "v_colortables.h" #include "v_2ddrawer.h" #include "hwrenderer/dynlights/hw_shadowmap.h" From 21f32834b211249fec37c9066c6a02fbcb1825b0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 22:37:27 +0200 Subject: [PATCH 096/220] - moved the postprocessing code to 'common', except for the game-dependent script exports. --- src/CMakeLists.txt | 10 +++++----- .../hwrenderer/postprocessing/hw_postprocess.cpp | 0 .../hwrenderer/postprocessing/hw_postprocess.h | 0 .../hwrenderer/postprocessing/hw_postprocess_cvars.cpp | 0 .../hwrenderer/postprocessing/hw_postprocess_cvars.h | 0 .../hwrenderer/postprocessing/hw_postprocessshader.h | 0 .../hwrenderer/postprocessing/hw_postprocessshader.cpp | 2 +- 7 files changed, 6 insertions(+), 6 deletions(-) rename src/{ => common}/rendering/hwrenderer/postprocessing/hw_postprocess.cpp (100%) rename src/{ => common}/rendering/hwrenderer/postprocessing/hw_postprocess.h (100%) rename src/{ => common}/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp (100%) rename src/{ => common}/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.h (100%) rename src/{ => common}/rendering/hwrenderer/postprocessing/hw_postprocessshader.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 494127d5d1..1f9c4e7b49 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -770,8 +770,6 @@ set( FASTMATH_SOURCES common/textures/hires/xbr/xbrz.cpp common/textures/hires/xbr/xbrz_old.cpp common/rendering/gl_load/gl_load.c - rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp - rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp rendering/hwrenderer/dynlights/hw_dynlightdata.cpp rendering/hwrenderer/scene/hw_bsp.cpp rendering/hwrenderer/scene/hw_fakeflat.cpp @@ -968,8 +966,6 @@ set (PCH_SOURCES rendering/hwrenderer/scene/hw_skydome.cpp rendering/hwrenderer/scene/hw_drawlistadd.cpp rendering/hwrenderer/scene/hw_renderstate.cpp - rendering/hwrenderer/postprocessing/hw_postprocess.cpp - rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp rendering/hwrenderer/textures/hw_precache.cpp rendering/hwrenderer/utility/hw_clock.cpp @@ -1149,6 +1145,9 @@ set (PCH_SOURCES common/objects/dobjgc.cpp common/objects/dobjtype.cpp common/rendering/r_videoscale.cpp + common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp + common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp + common/rendering/gl_load/gl_interface.cpp common/scripting/core/dictionary.cpp common/scripting/core/dynarrays.cpp @@ -1477,7 +1476,8 @@ source_group("Common\\Platforms\\SDL Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT source_group("Common\\Platforms\\Win32 Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/platform/win32/.+") source_group("Common\\Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/.+") source_group("Common\\Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/.+") -source_group("Common\\Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/data/.+") +source_group("Common\\Rendering\\Hardware Renderer\\Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/data/.+") +source_group("Common\\Rendering\\Hardware Renderer\\Postprocessing" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/postprocessing/.+") source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+") source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+") source_group("Common\\Textures\\Hires" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/.+") diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp similarity index 100% rename from src/rendering/hwrenderer/postprocessing/hw_postprocess.cpp rename to src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocess.h b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h similarity index 100% rename from src/rendering/hwrenderer/postprocessing/hw_postprocess.h rename to src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp similarity index 100% rename from src/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp rename to src/common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.h b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.h similarity index 100% rename from src/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.h rename to src/common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.h diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.h b/src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader.h similarity index 100% rename from src/rendering/hwrenderer/postprocessing/hw_postprocessshader.h rename to src/common/rendering/hwrenderer/postprocessing/hw_postprocessshader.h diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp b/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp index 16eea4c133..1b181ec5a5 100644 --- a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp +++ b/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp @@ -21,7 +21,7 @@ #include "vm.h" #include "d_player.h" -#include "hw_postprocessshader.h" +#include "hwrenderer/postprocessing/hw_postprocessshader.h" #include "g_levellocals.h" TArray PostProcessShaders; From 0c63f5c83280f84b936ea8523b7f5091d2ba56fe Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 25 Apr 2020 23:29:38 +0200 Subject: [PATCH 097/220] - moved FRenderState to 'common' and removed some game-dependent parts from it. --- .../hwrenderer/data}/hw_renderstate.h | 42 ++++++------------- src/rendering/gl/renderer/gl_renderstate.h | 2 +- .../hwrenderer/data/flatvertices.cpp | 2 +- .../hwrenderer/data/hw_viewpointbuffer.cpp | 2 +- src/rendering/hwrenderer/hw_entrypoint.cpp | 11 ++++- src/rendering/hwrenderer/models/hw_models.cpp | 2 +- src/rendering/hwrenderer/scene/hw_decal.cpp | 2 +- .../hwrenderer/scene/hw_drawstructs.h | 1 + src/rendering/hwrenderer/scene/hw_flats.cpp | 13 +++++- src/rendering/hwrenderer/scene/hw_portal.cpp | 4 +- src/rendering/hwrenderer/scene/hw_portal.h | 1 + .../hwrenderer/scene/hw_renderstate.cpp | 9 +--- .../hwrenderer/scene/hw_skyportal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 4 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 41 +++++++++++++++--- .../hwrenderer/utility/hw_draw2d.cpp | 2 +- .../polyrenderer/backend/poly_hwtexture.cpp | 2 +- .../polyrenderer/backend/poly_renderstate.h | 2 +- .../polyrenderer/drawers/poly_vertex_shader.h | 2 +- .../drawers/screen_scanline_setup.cpp | 8 ++-- src/rendering/vulkan/renderer/vk_renderpass.h | 2 +- .../vulkan/renderer/vk_renderstate.h | 2 +- src/rendering/vulkan/shaders/vk_shader.h | 2 +- .../vulkan/textures/vk_hwtexture.cpp | 2 +- 24 files changed, 94 insertions(+), 68 deletions(-) rename src/{rendering/hwrenderer/scene => common/rendering/hwrenderer/data}/hw_renderstate.h (91%) diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.h b/src/common/rendering/hwrenderer/data/hw_renderstate.h similarity index 91% rename from src/rendering/hwrenderer/scene/hw_renderstate.h rename to src/common/rendering/hwrenderer/data/hw_renderstate.h index d5399ad712..24692656ae 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.h +++ b/src/common/rendering/hwrenderer/data/hw_renderstate.h @@ -2,11 +2,9 @@ #include "v_palette.h" #include "vectors.h" -#include "g_levellocals.h" -#include "hw_drawstructs.h" -#include "hw_drawlist.h" #include "matrix.h" #include "hw_material.h" +#include "texmanip.h" struct FColormap; class IVertexBuffer; @@ -239,9 +237,9 @@ protected: EPassType mPassType = NORMAL_PASS; - uint64_t firstFrame = 0; - public: + + uint64_t firstFrame = 0; VSMatrix mModelMatrix; VSMatrix mTextureMatrix; @@ -432,28 +430,22 @@ public: mLightParms[3] = -1.f; } - void SetGlowPlanes(const secplane_t &top, const secplane_t &bottom) + void SetGlowPlanes(const FVector4 &tp, const FVector4& bp) { - auto &tn = top.Normal(); - auto &bn = bottom.Normal(); - mStreamData.uGlowTopPlane = { (float)tn.X, (float)tn.Y, (float)top.negiC, (float)top.fD() }; - mStreamData.uGlowBottomPlane = { (float)bn.X, (float)bn.Y, (float)bottom.negiC, (float)bottom.fD() }; + mStreamData.uGlowTopPlane = tp; + mStreamData.uGlowBottomPlane = bp; } - void SetGradientPlanes(const secplane_t &top, const secplane_t &bottom) + void SetGradientPlanes(const FVector4& tp, const FVector4& bp) { - auto &tn = top.Normal(); - auto &bn = bottom.Normal(); - mStreamData.uGradientTopPlane = { (float)tn.X, (float)tn.Y, (float)top.negiC, (float)top.fD() }; - mStreamData.uGradientBottomPlane = { (float)bn.X, (float)bn.Y, (float)bottom.negiC, (float)bottom.fD() }; + mStreamData.uGradientTopPlane = tp; + mStreamData.uGradientBottomPlane = bp; } - void SetSplitPlanes(const secplane_t &top, const secplane_t &bottom) + void SetSplitPlanes(const FVector4& tp, const FVector4& bp) { - auto &tn = top.Normal(); - auto &bn = bottom.Normal(); - mStreamData.uSplitTopPlane = { (float)tn.X, (float)tn.Y, (float)top.negiC, (float)top.fD() }; - mStreamData.uSplitBottomPlane = { (float)bn.X, (float)bn.Y, (float)bottom.negiC, (float)bottom.fD() }; + mStreamData.uSplitTopPlane = tp; + mStreamData.uSplitBottomPlane = bp; } void SetDetailParms(float xscale, float yscale, float bias) @@ -522,14 +514,6 @@ public: else mAlphaThreshold = thresh - 0.001f; } - void SetPlaneTextureRotation(HWSectorPlane *plane, FGameTexture *texture) - { - if (hw_SetPlaneTextureRotation(plane, texture, mTextureMatrix)) - { - EnableTextureMatrix(true); - } - } - void SetLightIndex(int index) { mLightIndex = index; @@ -647,8 +631,6 @@ public: return mPassType; } - void CheckTimer(uint64_t ShaderStartTime); - // API-dependent render interface // Draw commands diff --git a/src/rendering/gl/renderer/gl_renderstate.h b/src/rendering/gl/renderer/gl_renderstate.h index a366f75d04..7c66eb87fb 100644 --- a/src/rendering/gl/renderer/gl_renderstate.h +++ b/src/rendering/gl/renderer/gl_renderstate.h @@ -27,7 +27,7 @@ #include "gl_interface.h" #include "matrix.h" #include "hwrenderer/scene//hw_drawstructs.h" -#include "hwrenderer/scene//hw_renderstate.h" +#include "hw_renderstate.h" #include "hw_material.h" #include "c_cvars.h" #include "r_defs.h" diff --git a/src/rendering/hwrenderer/data/flatvertices.cpp b/src/rendering/hwrenderer/data/flatvertices.cpp index 50d9c1ebd9..8b0058ba3a 100644 --- a/src/rendering/hwrenderer/data/flatvertices.cpp +++ b/src/rendering/hwrenderer/data/flatvertices.cpp @@ -41,7 +41,7 @@ #include "v_video.h" #include "cmdlib.h" #include "hwrenderer/data/buffers.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" //========================================================================== // diff --git a/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp b/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp index 3846a4ccdb..01e3e626ea 100644 --- a/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp +++ b/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp @@ -27,7 +27,7 @@ #include "hwrenderer/data/shaderuniforms.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include "hw_viewpointbuffer.h" static const int INITIAL_BUFFER_SIZE = 100; // 100 viewpoints per frame should nearly always be enough diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index d4e9fdab9e..e5b0411b5d 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -243,6 +243,15 @@ void WriteSavePic(player_t* player, FileWriter* file, int width, int height) // //=========================================================================== +static void CheckTimer(FRenderState &state, uint64_t ShaderStartTime) +{ + // if firstFrame is not yet initialized, initialize it to current time + // if we're going to overflow a float (after ~4.6 hours, or 24 bits), re-init to regain precision + if ((state.firstFrame == 0) || (screen->FrameTime - state.firstFrame >= 1 << 24) || ShaderStartTime >= state.firstFrame) + state.firstFrame = screen->FrameTime; +} + + sector_t* RenderView(player_t* player) { auto RenderState = screen->RenderState(); @@ -281,7 +290,7 @@ sector_t* RenderView(player_t* player) // Shader start time does not need to be handled per level. Just use the one from the camera to render from. if (player->camera) - RenderState->CheckTimer(player->camera->Level->ShaderStartTime); + CheckTimer(*RenderState, player->camera->Level->ShaderStartTime); // prepare all camera textures that have been used in the last frame. // This must be done for all levels, not just the primary one! for (auto Level : AllLevels()) diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 6b1aa5a33b..015b8598bb 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -39,7 +39,7 @@ #include "hwrenderer/data/buffers.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/scene/hw_drawinfo.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include "hwrenderer/scene/hw_portal.h" #include "hw_models.h" diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index 2c93079db8..de9b28305e 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -108,7 +108,7 @@ void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state) di->SetColor(state, thisll, rellight, di->isFullbrightScene(), thiscm, alpha); if (di->Level->flags3 & LEVEL3_NOCOLOREDSPRITELIGHTING) thiscm.Decolorize(); di->SetFog(state, thisll, rellight, di->isFullbrightScene(), &thiscm, false); - state.SetSplitPlanes(lightlist[k].plane, lowplane); + SetSplitPlanes(state, lightlist[k].plane, lowplane); state.Draw(DT_TriangleStrip, vertindex, 4); } diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 271f24a09b..8c0d291737 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -435,3 +435,4 @@ struct FDynLightData; struct FDynamicLight; bool GetLight(FDynLightData& dld, int group, Plane& p, FDynamicLight* light, bool checkside); void AddLightToList(FDynLightData &dld, int group, FDynamicLight* light, bool forceAttenuate); +void SetSplitPlanes(FRenderState& state, const secplane_t& top, const secplane_t& bottom); diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index eb64cea2a3..69b1712c33 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -91,6 +91,15 @@ bool hw_SetPlaneTextureRotation(const HWSectorPlane * secplane, FGameTexture * g return false; } +void SetPlaneTextureRotation(FRenderState &state, HWSectorPlane* plane, FGameTexture* texture) +{ + if (hw_SetPlaneTextureRotation(plane, texture, state.mTextureMatrix)) + { + state.EnableTextureMatrix(true); + } +} + + //========================================================================== // @@ -326,7 +335,7 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) if (sector->special != GLSector_Skybox) { state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1); - state.SetPlaneTextureRotation(&plane, texture); + SetPlaneTextureRotation(state, &plane, texture); DrawSubsectors(di, state); state.EnableTextureMatrix(false); } @@ -354,7 +363,7 @@ void HWFlat::DrawFlat(HWDrawInfo *di, FRenderState &state, bool translucent) if (!texture->GetTranslucency()) state.AlphaFunc(Alpha_GEqual, gl_mask_threshold); else state.AlphaFunc(Alpha_GEqual, 0.f); state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1); - state.SetPlaneTextureRotation(&plane, texture); + SetPlaneTextureRotation(state, &plane, texture); DrawSubsectors(di, state); state.EnableTextureMatrix(false); } diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index 11d0e95f1d..657159e7dd 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -41,6 +41,8 @@ EXTERN_CVAR(Int, r_mirror_recursions) EXTERN_CVAR(Bool, gl_portals) +void SetPlaneTextureRotation(FRenderState& state, HWSectorPlane* plane, FGameTexture* texture); + //----------------------------------------------------------------------------- // // StartFrame @@ -979,7 +981,7 @@ void HWHorizonPortal::DrawContents(HWDrawInfo *di, FRenderState &state) state.SetMaterial(texture, UF_Texture, 0, CLAMP_NONE, 0, -1); state.SetObjectColor(origin->specialcolor); - state.SetPlaneTextureRotation(sp, texture); + SetPlaneTextureRotation(state, sp, texture); state.AlphaFunc(Alpha_GEqual, 0.f); state.SetRenderStyle(STYLE_Source); diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index 28767e15de..56e6cb1392 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -2,6 +2,7 @@ #include "tarray.h" #include "r_utility.h" +#include "r_sections.h" #include "actor.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.cpp b/src/rendering/hwrenderer/scene/hw_renderstate.cpp index 3f08c7f333..62841f0b63 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderstate.cpp @@ -25,6 +25,7 @@ ** */ +#include "g_levellocals.h" #include "hw_renderstate.h" #include "hw_drawstructs.h" #include "hw_portal.h" @@ -157,11 +158,3 @@ void HWDrawInfo::SetFog(FRenderState &state, int lightlevel, int rellight, bool } } - -void FRenderState::CheckTimer(uint64_t ShaderStartTime) -{ - // if firstFrame is not yet initialized, initialize it to current time - // if we're going to overflow a float (after ~4.6 hours, or 24 bits), re-init to regain precision - if ((firstFrame == 0) || (screen->FrameTime - firstFrame >= 1 << 24) || ShaderStartTime >= firstFrame) - firstFrame = screen->FrameTime; -} diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index cc945178db..d97b026882 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -28,7 +28,7 @@ #include "g_levellocals.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include "skyboxtexture.h" diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 388179b1a7..a735842a32 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -237,11 +237,11 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) { di->SetFog(state, thislight, rel, di->isFullbrightScene(), &thiscm, additivefog); } - state.SetSplitPlanes(*topplane, *lowplane); + SetSplitPlanes(state, *topplane, *lowplane); } else if (clipping) { - state.SetSplitPlanes(topp, bottomp); + SetSplitPlanes(state, topp, bottomp); } if (!modelframe) diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index dcde26054d..bbb2482169 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -44,6 +44,35 @@ #include "hw_renderstate.h" #include "hw_skydome.h" + +void SetGlowPlanes(FRenderState &state, const secplane_t& top, const secplane_t& bottom) +{ + auto& tn = top.Normal(); + auto& bn = bottom.Normal(); + FVector4 tp = { (float)tn.X, (float)tn.Y, (float)top.negiC, (float)top.fD() }; + FVector4 bp = { (float)bn.X, (float)bn.Y, (float)bottom.negiC, (float)bottom.fD() }; + state.SetGlowPlanes(tp, bp); +} + +void SetGradientPlanes(FRenderState& state, const secplane_t& top, const secplane_t& bottom) +{ + auto& tn = top.Normal(); + auto& bn = bottom.Normal(); + FVector4 tp = { (float)tn.X, (float)tn.Y, (float)top.negiC, (float)top.fD() }; + FVector4 bp = { (float)bn.X, (float)bn.Y, (float)bottom.negiC, (float)bottom.fD() }; + state.SetGradientPlanes(tp, bp); +} + +void SetSplitPlanes(FRenderState& state, const secplane_t& top, const secplane_t& bottom) +{ + auto& tn = top.Normal(); + auto& bn = bottom.Normal(); + FVector4 tp = { (float)tn.X, (float)tn.Y, (float)top.negiC, (float)top.fD() }; + FVector4 bp = { (float)bn.X, (float)bn.Y, (float)bottom.negiC, (float)bottom.fD() }; + state.SetSplitPlanes(tp, bp); +} + + //========================================================================== // // General purpose wall rendering function @@ -155,7 +184,7 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) { state.EnableGlow(true); state.SetGlowParams(topglowcolor, bottomglowcolor); - state.SetGlowPlanes(frontsector->ceilingplane, frontsector->floorplane); + SetGlowPlanes(state, frontsector->ceilingplane, frontsector->floorplane); } state.SetMaterial(texture, UF_Texture, 0, flags & 3, 0, -1); @@ -191,20 +220,20 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) { if (tierndx == side_t::top) { - state.SetGradientPlanes(frontsector->ceilingplane, backsector->ceilingplane); + SetGradientPlanes(state, frontsector->ceilingplane, backsector->ceilingplane); } else if (tierndx == side_t::mid) { - state.SetGradientPlanes(backsector->ceilingplane, backsector->floorplane); + SetGradientPlanes(state, backsector->ceilingplane, backsector->floorplane); } else // side_t::bottom: { - state.SetGradientPlanes(backsector->floorplane, frontsector->floorplane); + SetGradientPlanes(state, backsector->floorplane, frontsector->floorplane); } } else { - state.SetGradientPlanes(frontsector->ceilingplane, frontsector->floorplane); + SetGradientPlanes(state, frontsector->ceilingplane, frontsector->floorplane); } } } @@ -237,7 +266,7 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) CopyFrom3DLight(thiscm, &(*lightlist)[i]); di->SetColor(state, thisll, rel, false, thiscm, absalpha); if (type != RENDERWALL_M2SNF) di->SetFog(state, thisll, rel, false, &thiscm, RenderStyle == STYLE_Add); - state.SetSplitPlanes((*lightlist)[i].plane, lowplane); + SetSplitPlanes(state, (*lightlist)[i].plane, lowplane); RenderWall(di, state, rflags); } if (low1 <= zbottom[0] && low2 <= zbottom[1]) break; diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index 9404c9f869..40e3451c77 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -34,7 +34,7 @@ #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_cvars.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include "r_videoscale.h" diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index 55a82958f8..3736242092 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -25,7 +25,7 @@ #include "r_data/colormaps.h" #include "hw_material.h" #include "hwrenderer/utility/hw_cvars.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include "poly_framebuffer.h" #include "poly_hwtexture.h" diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.h b/src/rendering/polyrenderer/backend/poly_renderstate.h index 1db19c71a5..733578dd91 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.h +++ b/src/rendering/polyrenderer/backend/poly_renderstate.h @@ -7,7 +7,7 @@ #include "name.h" #include "hwrenderer/scene/hw_drawstructs.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include "hw_material.h" struct HWViewpointUniforms; diff --git a/src/rendering/polyrenderer/drawers/poly_vertex_shader.h b/src/rendering/polyrenderer/drawers/poly_vertex_shader.h index 5b53137634..22539e9725 100644 --- a/src/rendering/polyrenderer/drawers/poly_vertex_shader.h +++ b/src/rendering/polyrenderer/drawers/poly_vertex_shader.h @@ -2,7 +2,7 @@ #pragma once #include "hwrenderer/scene/hw_viewpointuniforms.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #ifndef NO_SSE #include diff --git a/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp b/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp index 7567901a9f..9f1a7af529 100644 --- a/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp +++ b/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp @@ -421,8 +421,8 @@ static void WriteVaryingWarp1(float posU, float posV, float stepU, float stepV, float u = posU * w[x]; float v = posV * w[x]; - v += g_sin(pi2 * (u + timer)) * 0.1f; - u += g_sin(pi2 * (v + timer)) * 0.1f; + v += (float)g_sin(pi2 * (u + timer)) * 0.1f; + u += (float)g_sin(pi2 * (v + timer)) * 0.1f; u = u - std::floor(u); v = v - std::floor(v); @@ -448,8 +448,8 @@ static void WriteVaryingWarp2(float posU, float posV, float stepU, float stepV, float u = posU * w[x]; float v = posV * w[x]; - v += (0.5f + g_sin(pi2 * (v + timer * 0.61f + 900.f/8192.f)) + g_sin(pi2 * (u * 2.0f + timer * 0.36f + 300.0f/8192.0f))) * 0.025f; - u += (0.5f + g_sin(pi2 * (v + timer * 0.49f + 700.f/8192.f)) + g_sin(pi2 * (u * 2.0f + timer * 0.49f + 1200.0f/8192.0f))) * 0.025f; + v += (0.5f + (float)g_sin(pi2 * (v + timer * 0.61f + 900.f/8192.f)) + (float)g_sin(pi2 * (u * 2.0f + timer * 0.36f + 300.0f/8192.0f))) * 0.025f; + u += (0.5f + (float)g_sin(pi2 * (v + timer * 0.49f + 700.f/8192.f)) + (float)g_sin(pi2 * (u * 2.0f + timer * 0.49f + 1200.0f/8192.0f))) * 0.025f; u = u - std::floor(u); v = v - std::floor(v); diff --git a/src/rendering/vulkan/renderer/vk_renderpass.h b/src/rendering/vulkan/renderer/vk_renderpass.h index c2c3b3e8e1..f192525225 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.h +++ b/src/rendering/vulkan/renderer/vk_renderpass.h @@ -4,7 +4,7 @@ #include "vulkan/system/vk_objects.h" #include "renderstyle.h" #include "hwrenderer/data/buffers.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include #include diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/rendering/vulkan/renderer/vk_renderstate.h index 9494a794b2..71e467f193 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/rendering/vulkan/renderer/vk_renderstate.h @@ -9,7 +9,7 @@ #include "name.h" #include "hwrenderer/scene/hw_drawstructs.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include "hw_material.h" class VkRenderPassSetup; diff --git a/src/rendering/vulkan/shaders/vk_shader.h b/src/rendering/vulkan/shaders/vk_shader.h index a9936293c0..daa9dc845c 100644 --- a/src/rendering/vulkan/shaders/vk_shader.h +++ b/src/rendering/vulkan/shaders/vk_shader.h @@ -6,7 +6,7 @@ #include "vectors.h" #include "matrix.h" #include "name.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #define SHADER_MIN_REQUIRED_TEXTURE_LAYERS 8 diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index cf6aeaa45f..d686fedd74 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -25,7 +25,7 @@ #include "r_data/colormaps.h" #include "hw_material.h" #include "hwrenderer/utility/hw_cvars.h" -#include "hwrenderer/scene/hw_renderstate.h" +#include "hw_renderstate.h" #include "vulkan/system/vk_objects.h" #include "vulkan/system/vk_builders.h" #include "vulkan/system/vk_framebuffer.h" From 4b56714199182a1cb4a658a2b4fd32c1cb81e9d6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 00:03:08 +0200 Subject: [PATCH 098/220] - made hw_postprocess.cpp compatible. The shadowmap is not universal, it depends on Doom's map format. --- .../postprocessing/hw_postprocess.cpp | 24 ++++--------------- .../postprocessing/hw_postprocessshader.cpp | 20 +++++++++++++++- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp index c8a32f30fe..db991145a6 100644 --- a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -26,10 +26,14 @@ #include "hwrenderer/postprocessing/hw_postprocessshader.h" #include #include "texturemanager.h" +#include "templates.h" +#include "stats.h" +#include "colormaps.h" Postprocess hw_postprocess; PPResource *PPResource::First = nullptr; +TArray PostProcessShaders; bool gpuStatActive = false; bool keepGpuStatActive = false; @@ -862,26 +866,6 @@ PPPresent::PPPresent() ///////////////////////////////////////////////////////////////////////////// -void PPShadowMap::Update(PPRenderState *renderstate) -{ - ShadowMapUniforms uniforms; - uniforms.ShadowmapQuality = (float)gl_shadowmap_quality; - uniforms.NodesCount = screen->mShadowMap.NodesCount(); - - renderstate->PushGroup("shadowmap"); - - renderstate->Clear(); - renderstate->Shader = &ShadowMap; - renderstate->Uniforms.Set(uniforms); - renderstate->Viewport = { 0, 0, gl_shadowmap_quality, 1024 }; - renderstate->SetShadowMapBuffers(true); - renderstate->SetOutputShadowMap(); - renderstate->SetNoBlend(); - renderstate->Draw(); - - renderstate->PopGroup(); -} - ///////////////////////////////////////////////////////////////////////////// CVAR(Bool, gl_custompost, true, 0) diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp b/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp index 1b181ec5a5..9b90fbd622 100644 --- a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp +++ b/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp @@ -24,7 +24,25 @@ #include "hwrenderer/postprocessing/hw_postprocessshader.h" #include "g_levellocals.h" -TArray PostProcessShaders; +void PPShadowMap::Update(PPRenderState *renderstate) +{ + ShadowMapUniforms uniforms; + uniforms.ShadowmapQuality = (float)gl_shadowmap_quality; + uniforms.NodesCount = screen->mShadowMap.NodesCount(); + + renderstate->PushGroup("shadowmap"); + + renderstate->Clear(); + renderstate->Shader = &ShadowMap; + renderstate->Uniforms.Set(uniforms); + renderstate->Viewport = { 0, 0, gl_shadowmap_quality, 1024 }; + renderstate->SetShadowMapBuffers(true); + renderstate->SetOutputShadowMap(); + renderstate->SetNoBlend(); + renderstate->Draw(); + + renderstate->PopGroup(); +} static bool IsConsolePlayer(player_t *player) From 686aa9779d2f74c4248a41a1e9311476fa07a17e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 10:26:29 +0200 Subject: [PATCH 099/220] - moved VR code and IntRect to 'common' --- src/CMakeLists.txt | 2 +- .../rendering/hwrenderer/data}/hw_vrmodes.cpp | 6 +++- .../rendering/hwrenderer/data}/hw_vrmodes.h | 0 .../postprocessing/hw_postprocess.h | 22 +++++++------ src/common/utility/intrect.h | 31 ++++++++++++++++++ src/gameconfigfile.cpp | 11 +++++++ src/r_data/v_palette.cpp | 8 ++--- src/rendering/gl/renderer/gl_postprocess.cpp | 6 ++-- src/rendering/gl/renderer/gl_renderer.cpp | 2 +- src/rendering/gl/renderer/gl_stereo3d.cpp | 4 +-- src/rendering/gl/system/gl_framebuffer.cpp | 2 +- src/rendering/gl/textures/gl_hwtexture.h | 1 - .../hwrenderer/dynlights/hw_shadowmap.cpp | 21 ++++++++++++ src/rendering/hwrenderer/hw_entrypoint.cpp | 4 +-- .../postprocessing/hw_postprocessshader.cpp | 22 +------------ .../hwrenderer/scene/hw_drawinfo.cpp | 2 +- src/rendering/hwrenderer/scene/hw_skydome.cpp | 4 +-- .../polyrenderer/backend/poly_framebuffer.cpp | 2 +- src/rendering/v_video.h | 32 ++----------------- .../vulkan/renderer/vk_postprocess.cpp | 4 +-- .../vulkan/system/vk_framebuffer.cpp | 2 +- src/version.h | 3 +- wadsrc/static/menudef.txt | 2 +- 23 files changed, 108 insertions(+), 85 deletions(-) rename src/{rendering/hwrenderer/utility => common/rendering/hwrenderer/data}/hw_vrmodes.cpp (98%) rename src/{rendering/hwrenderer/utility => common/rendering/hwrenderer/data}/hw_vrmodes.h (100%) create mode 100644 src/common/utility/intrect.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f9c4e7b49..426cb505ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -973,7 +973,6 @@ set (PCH_SOURCES rendering/hwrenderer/utility/hw_draw2d.cpp rendering/hwrenderer/utility/hw_lighting.cpp rendering/hwrenderer/utility/hw_shaderpatcher.cpp - rendering/hwrenderer/utility/hw_vrmodes.cpp maploader/edata.cpp maploader/specials.cpp maploader/maploader.cpp @@ -1145,6 +1144,7 @@ set (PCH_SOURCES common/objects/dobjgc.cpp common/objects/dobjtype.cpp common/rendering/r_videoscale.cpp + common/rendering/hwrenderer/data/hw_vrmodes.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp diff --git a/src/rendering/hwrenderer/utility/hw_vrmodes.cpp b/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp similarity index 98% rename from src/rendering/hwrenderer/utility/hw_vrmodes.cpp rename to src/common/rendering/hwrenderer/data/hw_vrmodes.cpp index ebb2aad9fd..c57a6297e7 100644 --- a/src/rendering/hwrenderer/utility/hw_vrmodes.cpp +++ b/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp @@ -26,10 +26,10 @@ */ #include "vectors.h" // RAD2DEG -#include "doomtype.h" // M_PI #include "hwrenderer/utility/hw_cvars.h" #include "hw_vrmodes.h" #include "v_video.h" +#include "version.h" // Set up 3D-specific console variables: CVAR(Int, vr_mode, 0, CVAR_GLOBALCONFIG) @@ -59,6 +59,7 @@ static VRMode vrmi_checker = { 2, isqrt2, isqrt2, 1.f,{ { -.5f, 1.f },{ .5f, 1.f const VRMode *VRMode::GetVRMode(bool toscreen) { +#ifdef VR3D_ENABLED switch (toscreen && vid_rendermode == 4 ? vr_mode : 0) { default: @@ -91,6 +92,9 @@ const VRMode *VRMode::GetVRMode(bool toscreen) case VR_CHECKERINTERLEAVED: return &vrmi_checker; } +#else + return &vrmi_mono; +#endif } void VRMode::AdjustViewport(DFrameBuffer *screen) const diff --git a/src/rendering/hwrenderer/utility/hw_vrmodes.h b/src/common/rendering/hwrenderer/data/hw_vrmodes.h similarity index 100% rename from src/rendering/hwrenderer/utility/hw_vrmodes.h rename to src/common/rendering/hwrenderer/data/hw_vrmodes.h diff --git a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h index 8c74af83e5..7b715c5b2e 100644 --- a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h +++ b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h @@ -3,6 +3,7 @@ #include "hwrenderer/data/shaderuniforms.h" #include #include +#include "intrect.h" struct PostProcessShader; @@ -777,15 +778,6 @@ struct ShadowMapUniforms } }; -class PPShadowMap -{ -public: - void Update(PPRenderState *renderstate); - -private: - PPShader ShadowMap = { "shaders/glsl/shadowmap.fp", "", ShadowMapUniforms::Desc() }; -}; - class PPCustomShaderInstance { public: @@ -819,6 +811,18 @@ private: std::vector> mShaders; }; +class PPShadowMap +{ +public: + void Update(PPRenderState* renderstate); + +private: + PPShader ShadowMap = { "shaders/glsl/shadowmap.fp", "", ShadowMapUniforms::Desc() }; +}; + + + + ///////////////////////////////////////////////////////////////////////////// class Postprocess diff --git a/src/common/utility/intrect.h b/src/common/utility/intrect.h new file mode 100644 index 0000000000..3cda7613e6 --- /dev/null +++ b/src/common/utility/intrect.h @@ -0,0 +1,31 @@ +#pragma once + + +struct IntRect +{ + int left, top; + int width, height; + + + void Offset(int xofs, int yofs) + { + left += xofs; + top += yofs; + } + + void AddToRect(int x, int y) + { + if (x < left) + left = x; + if (x > left + width) + width = x - left; + + if (y < top) + top = y; + if (y > top + height) + height = y - top; + } + + +}; + diff --git a/src/gameconfigfile.cpp b/src/gameconfigfile.cpp index a04264dbef..7ea9734ae4 100644 --- a/src/gameconfigfile.cpp +++ b/src/gameconfigfile.cpp @@ -47,6 +47,7 @@ #include "doomstat.h" #include "gi.h" #include "d_main.h" +#include "v_video.h" #if !defined _MSC_VER && !defined __APPLE__ #include "i_system.h" // for SHARE_DIR #endif // !_MSC_VER && !__APPLE__ @@ -560,6 +561,16 @@ void FGameConfigFile::DoGlobalSetup () } } } + if (last < 220) + { + auto var = FindCVar("Gamma", NULL); + if (var != NULL) + { + UCVarValue v = var->GetGenericRep(CVAR_Float); + vid_gamma = v.Float; + } + + } } } } diff --git a/src/r_data/v_palette.cpp b/src/r_data/v_palette.cpp index 2c78131e36..1b007099b5 100644 --- a/src/r_data/v_palette.cpp +++ b/src/r_data/v_palette.cpp @@ -59,7 +59,7 @@ int BlendR, BlendG, BlendB, BlendA; /**************************/ uint8_t newgamma[256]; -CUSTOM_CVAR (Float, Gamma, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +CUSTOM_CVAR (Float, vid_gamma, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) { if (self == 0.f) { // Gamma values of 0 are illegal. @@ -78,13 +78,13 @@ CCMD (bumpgamma) // [RH] Gamma correction tables are now generated on the fly for *any* gamma level // Q: What are reasonable limits to use here? - float newgamma = Gamma + 0.1f; + float newgamma = vid_gamma + 0.1f; if (newgamma > 3.0) newgamma = 1.0; - Gamma = newgamma; - Printf ("Gamma correction level %g\n", *Gamma); + vid_gamma = newgamma; + Printf ("Gamma correction level %g\n", *vid_gamma); } diff --git a/src/rendering/gl/renderer/gl_postprocess.cpp b/src/rendering/gl/renderer/gl_postprocess.cpp index 274667c321..4c4025df5a 100644 --- a/src/rendering/gl/renderer/gl_postprocess.cpp +++ b/src/rendering/gl/renderer/gl_postprocess.cpp @@ -33,7 +33,7 @@ #include "gl/shaders/gl_shaderprogram.h" #include "hwrenderer/postprocessing/hw_postprocess.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" #include "hwrenderer/data/flatvertices.h" #include "gl/textures/gl_hwtexture.h" #include "r_videoscale.h" @@ -62,7 +62,7 @@ void FGLRenderer::PostProcessScene(int fixedcm, const std::function &aft hw_postprocess.Pass1(&renderstate, fixedcm, sceneWidth, sceneHeight); mBuffers->BindCurrentFB(); - afterBloomDrawEndScene2D(); + if (afterBloomDrawEndScene2D) afterBloomDrawEndScene2D(); hw_postprocess.Pass2(&renderstate, fixedcm, sceneWidth, sceneHeight); } @@ -199,7 +199,7 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma) } else { - mPresentShader->Uniforms->InvGamma = 1.0f / clamp(Gamma, 0.1f, 4.f); + mPresentShader->Uniforms->InvGamma = 1.0f / clamp(vid_gamma, 0.1f, 4.f); mPresentShader->Uniforms->Contrast = clamp(vid_contrast, 0.1f, 3.f); mPresentShader->Uniforms->Brightness = clamp(vid_brightness, -0.8f, 0.8f); mPresentShader->Uniforms->Saturation = clamp(vid_saturation, -15.0f, 15.f); diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index acaed25007..a101f7ec7e 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -48,7 +48,7 @@ #include "gl/renderer/gl_renderstate.h" #include "gl/renderer/gl_renderbuffers.h" #include "gl/shaders/gl_shaderprogram.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" diff --git a/src/rendering/gl/renderer/gl_stereo3d.cpp b/src/rendering/gl/renderer/gl_stereo3d.cpp index 00f830b8f3..6df5ee69e0 100644 --- a/src/rendering/gl/renderer/gl_stereo3d.cpp +++ b/src/rendering/gl/renderer/gl_stereo3d.cpp @@ -28,7 +28,7 @@ #include "gl_system.h" #include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderbuffers.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" #include "gl/system/gl_framebuffer.h" #include "gl/renderer/gl_postprocessstate.h" #include "gl/system/gl_framebuffer.h" @@ -162,7 +162,7 @@ void FGLRenderer::prepareInterleavedPresent(FPresentShaderBase& shader) } else { - shader.Uniforms->InvGamma = 1.0f / clamp(Gamma, 0.1f, 4.f); + shader.Uniforms->InvGamma = 1.0f / clamp(vid_gamma, 0.1f, 4.f); shader.Uniforms->Contrast = clamp(vid_contrast, 0.1f, 3.f); shader.Uniforms->Brightness = clamp(vid_brightness, -0.8f, 0.8f); shader.Uniforms->Saturation = clamp(vid_saturation, -15.0f, 15.0f); diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 0ec8d4eafd..20b6319381 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -38,7 +38,7 @@ #include "gl/renderer/gl_renderbuffers.h" #include "gl/textures/gl_samplers.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" diff --git a/src/rendering/gl/textures/gl_hwtexture.h b/src/rendering/gl/textures/gl_hwtexture.h index 727774672c..d25131d777 100644 --- a/src/rendering/gl/textures/gl_hwtexture.h +++ b/src/rendering/gl/textures/gl_hwtexture.h @@ -14,7 +14,6 @@ #include "hw_ihwtexture.h" class FCanvasTexture; -class AActor; namespace OpenGLRenderer { diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp index e9fb4686f5..99bdaed530 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp @@ -29,6 +29,7 @@ #include "g_levellocals.h" #include "v_video.h" #include "a_dynlight.h" +#include "hwrenderer/postprocessing/hw_postprocess.h" /* The 1D shadow maps are stored in a 1024x1024 texture as float depth values (R32F). @@ -224,3 +225,23 @@ IShadowMap::~IShadowMap() Reset(); } +void PPShadowMap::Update(PPRenderState* renderstate) +{ + ShadowMapUniforms uniforms; + uniforms.ShadowmapQuality = (float)gl_shadowmap_quality; + uniforms.NodesCount = screen->mShadowMap.NodesCount(); + + renderstate->PushGroup("shadowmap"); + + renderstate->Clear(); + renderstate->Shader = &ShadowMap; + renderstate->Uniforms.Set(uniforms); + renderstate->Viewport = { 0, 0, gl_shadowmap_quality, 1024 }; + renderstate->SetShadowMapBuffers(true); + renderstate->SetOutputShadowMap(); + renderstate->SetNoBlend(); + renderstate->Draw(); + + renderstate->PopGroup(); +} + diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index e5b0411b5d..c2e06a8302 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -46,7 +46,7 @@ #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_clipper.h" #include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" EXTERN_CVAR(Bool, cl_capfps) extern bool NoInterpolateView; @@ -181,7 +181,7 @@ void DoWriteSavePic(FileWriter* file, ESSType ssformat, uint8_t* scr, int width, pitch *= -1; } - M_CreatePNG(file, scr, ssformat == SS_PAL ? palette : nullptr, ssformat, width, height, pitch, Gamma); + M_CreatePNG(file, scr, ssformat == SS_PAL ? palette : nullptr, ssformat, width, height, pitch, vid_gamma); } //=========================================================================== diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp b/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp index 9b90fbd622..f8e6e3e8bd 100644 --- a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp +++ b/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp @@ -23,27 +23,7 @@ #include "d_player.h" #include "hwrenderer/postprocessing/hw_postprocessshader.h" #include "g_levellocals.h" - -void PPShadowMap::Update(PPRenderState *renderstate) -{ - ShadowMapUniforms uniforms; - uniforms.ShadowmapQuality = (float)gl_shadowmap_quality; - uniforms.NodesCount = screen->mShadowMap.NodesCount(); - - renderstate->PushGroup("shadowmap"); - - renderstate->Clear(); - renderstate->Shader = &ShadowMap; - renderstate->Uniforms.Set(uniforms); - renderstate->Viewport = { 0, 0, gl_shadowmap_quality, 1024 }; - renderstate->SetShadowMapBuffers(true); - renderstate->SetOutputShadowMap(); - renderstate->SetNoBlend(); - renderstate->Draw(); - - renderstate->PopGroup(); -} - +#include "hwrenderer/postprocessing/hw_postprocess.h" static bool IsConsolePlayer(player_t *player) { diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index e1697adec3..2df708ca91 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -41,7 +41,7 @@ #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" #include "hw_clipper.h" EXTERN_CVAR(Float, r_visibility) diff --git a/src/rendering/hwrenderer/scene/hw_skydome.cpp b/src/rendering/hwrenderer/scene/hw_skydome.cpp index 58f25f5329..e0e1103294 100644 --- a/src/rendering/hwrenderer/scene/hw_skydome.cpp +++ b/src/rendering/hwrenderer/scene/hw_skydome.cpp @@ -284,8 +284,8 @@ void FSkyVertexBuffer::CreateDome() void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix) { - int texw = tex->GetDisplayWidth(); - int texh = tex->GetDisplayHeight(); + float texw = tex->GetDisplayWidth(); + float texh = tex->GetDisplayHeight(); modelMatrix.loadIdentity(); modelMatrix.rotate(-180.0f + x_offset, 0.f, 1.f, 0.f); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 24aea91793..6091b4ed97 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -30,7 +30,7 @@ #include "i_video.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" #include "hwrenderer/utility/hw_cvars.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_skydome.h" diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index dc98b80e54..0fa592ff38 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -41,6 +41,7 @@ #include "renderstyle.h" #include "c_cvars.h" #include "v_2ddrawer.h" +#include "intrect.h" #include "hwrenderer/dynlights/hw_shadowmap.h" @@ -78,35 +79,6 @@ enum EHWCaps }; -struct IntRect -{ - int left, top; - int width, height; - - - void Offset(int xofs, int yofs) - { - left += xofs; - top += yofs; - } - - void AddToRect(int x, int y) - { - if (x < left) - left = x; - if (x > left + width) - width = x - left; - - if (y < top) - top = y; - if (y > top + height) - height = y - top; - } - - -}; - - extern int DisplayWidth, DisplayHeight; void V_UpdateModeSize (int width, int height); @@ -366,7 +338,7 @@ extern DFrameBuffer *screen; #define SCREENHEIGHT (screen->GetHeight ()) #define SCREENPITCH (screen->GetPitch ()) -EXTERN_CVAR (Float, Gamma) +EXTERN_CVAR (Float, vid_gamma) // Allocates buffer screens, call before R_Init. diff --git a/src/rendering/vulkan/renderer/vk_postprocess.cpp b/src/rendering/vulkan/renderer/vk_postprocess.cpp index 51105c811f..403a9dfcd1 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.cpp +++ b/src/rendering/vulkan/renderer/vk_postprocess.cpp @@ -32,7 +32,7 @@ #include "hwrenderer/utility/hw_cvars.h" #include "hwrenderer/postprocessing/hw_postprocess.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" #include "hwrenderer/data/flatvertices.h" #include "r_videoscale.h" #include "filesystem.h" @@ -201,7 +201,7 @@ void VkPostprocess::DrawPresentTexture(const IntRect &box, bool applyGamma, bool } else { - uniforms.InvGamma = 1.0f / clamp(Gamma, 0.1f, 4.f); + uniforms.InvGamma = 1.0f / clamp(vid_gamma, 0.1f, 4.f); uniforms.Contrast = clamp(vid_contrast, 0.1f, 3.f); uniforms.Brightness = clamp(vid_brightness, -0.8f, 0.8f); uniforms.Saturation = clamp(vid_saturation, -15.0f, 15.f); diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 7cf64196b4..a783f8c10f 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -32,7 +32,7 @@ #include "v_text.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/utility/hw_vrmodes.h" +#include "hw_vrmodes.h" #include "hwrenderer/utility/hw_cvars.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_skydome.h" diff --git a/src/version.h b/src/version.h index 92b4e70518..1be840a5f5 100644 --- a/src/version.h +++ b/src/version.h @@ -65,7 +65,7 @@ const char *GetVersionString(); // Version stored in the ini's [LastRun] section. // Bump it if you made some configuration change that you want to // be able to migrate in FGameConfigFile::DoGlobalSetup(). -#define LASTRUNVERSION "219" +#define LASTRUNVERSION "220" // Protocol version used in demos. // Bump it if you change existing DEM_ commands or add new ones. @@ -95,6 +95,7 @@ const char *GetVersionString(); #define BASEWAD "gzdoom.pk3" #define OPTIONALWAD "game_support.pk3" #define GZDOOM 1 +#define VR3D_ENABLED // More stuff that needs to be different for derivatives. #define GAMENAME "GZDoom" diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index b59af595f4..1b390c469e 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -926,7 +926,7 @@ OptionMenu "VideoOptions" protected StaticText " " Slider "$DSPLYMNU_SCREENSIZE", "screenblocks", 3.0, 12.0, 1.0, 0 - Slider "$DSPLYMNU_GAMMA", "Gamma", 0.75, 3.0, 0.05, 2 + Slider "$DSPLYMNU_GAMMA", "vid_gamma", 0.75, 3.0, 0.05, 2 Slider "$DSPLYMNU_BRIGHTNESS", "vid_brightness", -0.8,0.8, 0.05,2 Slider "$DSPLYMNU_CONTRAST", "vid_contrast", 0.1, 3.0, 0.1 Slider "$DSPLYMNU_SATURATION", "vid_saturation", -3.0, 3.0, 0.25, 2 From 1ad2f30e0d47f6df67b05d8421e77dd2249bfb63 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 10:47:57 +0200 Subject: [PATCH 100/220] - moved sprite CVARs out of the global CVAR storage file. They are local to hw_sprites.cpp now, as they aren't used anywhere else. --- src/rendering/gl/renderer/gl_postprocess.cpp | 8 +- .../gl/renderer/gl_postprocessstate.h | 1 - .../gl/renderer/gl_renderbuffers.cpp | 3 + src/rendering/gl/renderer/gl_renderbuffers.h | 1 - src/rendering/gl/renderer/gl_renderer.h | 2 +- src/rendering/gl/shaders/gl_shader.cpp | 1 + .../hwrenderer/data/hw_vertexbuilder.h | 1 + .../hwrenderer/scene/hw_drawinfo.cpp | 1 + src/rendering/hwrenderer/scene/hw_sprites.cpp | 20 +++++ src/rendering/hwrenderer/utility/hw_cvars.cpp | 81 +++++++++---------- src/rendering/hwrenderer/utility/hw_cvars.h | 15 ---- .../vulkan/renderer/vk_renderbuffers.cpp | 1 + 12 files changed, 69 insertions(+), 66 deletions(-) diff --git a/src/rendering/gl/renderer/gl_postprocess.cpp b/src/rendering/gl/renderer/gl_postprocess.cpp index 4c4025df5a..b0dfe1c3e9 100644 --- a/src/rendering/gl/renderer/gl_postprocess.cpp +++ b/src/rendering/gl/renderer/gl_postprocess.cpp @@ -21,22 +21,20 @@ #include "gl_system.h" #include "m_png.h" -#include "r_utility.h" #include "gl/system/gl_buffers.h" #include "gl/system/gl_framebuffer.h" -#include "hwrenderer/utility/hw_cvars.h" #include "gl/system/gl_debug.h" -#include "gl/renderer/gl_renderstate.h" #include "gl/renderer/gl_renderbuffers.h" #include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_postprocessstate.h" #include "gl/shaders/gl_shaderprogram.h" #include "hwrenderer/postprocessing/hw_postprocess.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" -#include "hw_vrmodes.h" #include "hwrenderer/data/flatvertices.h" -#include "gl/textures/gl_hwtexture.h" #include "r_videoscale.h" +#include "v_video.h" +#include "templates.h" +#include "hw_vrmodes.h" extern bool vid_hdr_active; diff --git a/src/rendering/gl/renderer/gl_postprocessstate.h b/src/rendering/gl/renderer/gl_postprocessstate.h index c5a89445b7..b21e73840d 100644 --- a/src/rendering/gl/renderer/gl_postprocessstate.h +++ b/src/rendering/gl/renderer/gl_postprocessstate.h @@ -5,7 +5,6 @@ #include "gl_interface.h" #include "matrix.h" #include "c_cvars.h" -#include "r_defs.h" namespace OpenGLRenderer { diff --git a/src/rendering/gl/renderer/gl_renderbuffers.cpp b/src/rendering/gl/renderer/gl_renderbuffers.cpp index 6953fd9eee..319cf12789 100644 --- a/src/rendering/gl/renderer/gl_renderbuffers.cpp +++ b/src/rendering/gl/renderer/gl_renderbuffers.cpp @@ -22,6 +22,7 @@ #include "gl_system.h" #include "v_video.h" #include "gl_interface.h" +#include "printf.h" #include "hwrenderer/utility/hw_cvars.h" #include "gl/system/gl_debug.h" #include "gl/renderer/gl_renderer.h" @@ -29,8 +30,10 @@ #include "gl/renderer/gl_postprocessstate.h" #include "gl/shaders/gl_shaderprogram.h" #include "gl/system/gl_buffers.h" +#include "templates.h" #include +EXTERN_CVAR(Int, gl_debug_level) CVAR(Int, gl_multisample, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); namespace OpenGLRenderer diff --git a/src/rendering/gl/renderer/gl_renderbuffers.h b/src/rendering/gl/renderer/gl_renderbuffers.h index 4e1fd977c3..da967f021e 100644 --- a/src/rendering/gl/renderer/gl_renderbuffers.h +++ b/src/rendering/gl/renderer/gl_renderbuffers.h @@ -1,7 +1,6 @@ #pragma once -#include "gl/shaders/gl_shader.h" #include "hwrenderer/postprocessing/hw_postprocess.h" namespace OpenGLRenderer diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index 5b61d7aa8f..ab260563dc 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -19,7 +19,6 @@ struct particle_t; class FCanvasTexture; class FFlatVertexBuffer; class FSkyVertexBuffer; -class FShaderManager; class HWPortal; class FLightBuffer; class DPSprite; @@ -32,6 +31,7 @@ struct FRenderViewpoint; namespace OpenGLRenderer { + class FShaderManager; class FSamplerManager; class OpenGLFrameBuffer; class FPresentShaderBase; diff --git a/src/rendering/gl/shaders/gl_shader.cpp b/src/rendering/gl/shaders/gl_shader.cpp index 8487c29818..5dac1332e2 100644 --- a/src/rendering/gl/shaders/gl_shader.cpp +++ b/src/rendering/gl/shaders/gl_shader.cpp @@ -34,6 +34,7 @@ #include "cmdlib.h" #include "md5.h" #include "m_misc.h" +#include "gl/shaders/gl_shader.h" #include "hwrenderer/utility/hw_shaderpatcher.h" #include "hwrenderer/data/shaderuniforms.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" diff --git a/src/rendering/hwrenderer/data/hw_vertexbuilder.h b/src/rendering/hwrenderer/data/hw_vertexbuilder.h index 8ab7d21d86..e13e5e7aff 100644 --- a/src/rendering/hwrenderer/data/hw_vertexbuilder.h +++ b/src/rendering/hwrenderer/data/hw_vertexbuilder.h @@ -1,5 +1,6 @@ #include "tarray.h" +#include "r_defs.h" struct vertex_t; struct FQualifiedVertex diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 2df708ca91..2d07869a57 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -48,6 +48,7 @@ EXTERN_CVAR(Float, r_visibility) CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE) CVAR(Bool, gl_sort_textures, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, gl_no_skyclear, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Int, gl_enhanced_nv_stealth, 3, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Bool, gl_texture, true, 0) CVAR(Float, gl_mask_threshold, 0.5f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index a735842a32..020bae1f20 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -68,6 +68,26 @@ EXTERN_CVAR(Bool, r_debug_disable_vis_filter) EXTERN_CVAR(Float, transsouls) +//========================================================================== +// +// Sprite CVARs +// +//========================================================================== + +CVAR(Bool, gl_usecolorblending, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Bool, gl_sprite_blend, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); +CVAR(Int, gl_spriteclip, 1, CVAR_ARCHIVE) +CVAR(Float, gl_sclipthreshold, 10.0, CVAR_ARCHIVE) +CVAR(Float, gl_sclipfactor, 1.8f, CVAR_ARCHIVE) +CVAR(Int, gl_particles_style, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // 0 = square, 1 = round, 2 = smooth +CVAR(Int, gl_billboard_mode, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Bool, gl_billboard_faces_camera, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Bool, gl_billboard_particles, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE) +{ + if (self < 0 || self > 8) self = 0; +} + //========================================================================== // // diff --git a/src/rendering/hwrenderer/utility/hw_cvars.cpp b/src/rendering/hwrenderer/utility/hw_cvars.cpp index 348fc8821e..42b5ddacd7 100644 --- a/src/rendering/hwrenderer/utility/hw_cvars.cpp +++ b/src/rendering/hwrenderer/utility/hw_cvars.cpp @@ -1,24 +1,39 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2005-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// +/* +** hw_cvars.cpp +** +** most of the hardware renderer's CVARs. +** +**--------------------------------------------------------------------------- +** Copyright 2005-2020 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + #include "c_cvars.h" @@ -65,7 +80,7 @@ CVAR(Int, gl_satformula, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); // Texture CVARs // //========================================================================== -CUSTOM_CVAR(Float,gl_texture_filter_anisotropic,8.0f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) +CUSTOM_CVARD(Float, gl_texture_filter_anisotropic, 8, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL, "changes the OpenGL texture anisotropy setting") { screen->TextureFilterChanged(); } @@ -75,7 +90,7 @@ CCMD(gl_flush) TexMan.FlushAll(); } -CUSTOM_CVAR(Int, gl_texture_filter, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) +CUSTOM_CVARD(Int, gl_texture_filter, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL, "changes the texture filtering settings") { if (self < 0 || self > 6) self=4; screen->TextureFilterChanged(); @@ -83,26 +98,6 @@ CUSTOM_CVAR(Int, gl_texture_filter, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINI CVAR(Bool, gl_precache, false, CVAR_ARCHIVE) -//========================================================================== -// -// Sprite CVARs -// -//========================================================================== - -CVAR(Bool, gl_usecolorblending, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -CVAR(Bool, gl_sprite_blend, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); -CVAR(Int, gl_spriteclip, 1, CVAR_ARCHIVE) -CVAR(Float, gl_sclipthreshold, 10.0, CVAR_ARCHIVE) -CVAR(Float, gl_sclipfactor, 1.8f, CVAR_ARCHIVE) -CVAR(Int, gl_particles_style, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // 0 = square, 1 = round, 2 = smooth -CVAR(Int, gl_billboard_mode, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CVAR(Bool, gl_billboard_faces_camera, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CVAR(Bool, gl_billboard_particles, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CVAR(Int, gl_enhanced_nv_stealth, 3, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE) -{ - if (self < 0 || self > 8) self = 0; -} CUSTOM_CVAR(Int, gl_shadowmap_filter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { diff --git a/src/rendering/hwrenderer/utility/hw_cvars.h b/src/rendering/hwrenderer/utility/hw_cvars.h index 79c97b6827..0b9d8f09b8 100644 --- a/src/rendering/hwrenderer/utility/hw_cvars.h +++ b/src/rendering/hwrenderer/utility/hw_cvars.h @@ -1,10 +1,8 @@ #pragma once -#include "r_defs.h" #include "c_cvars.h" - EXTERN_CVAR(Bool,gl_enhanced_nightvision) EXTERN_CVAR(Int, screenblocks); EXTERN_CVAR(Int, gl_texture_filter) @@ -52,19 +50,6 @@ EXTERN_CVAR(Float, gl_ssao_blur_amount) EXTERN_CVAR(Int, gl_debug_level) EXTERN_CVAR(Bool, gl_debug_breakpoint) - -EXTERN_CVAR(Bool, gl_usecolorblending) -EXTERN_CVAR(Bool, gl_sprite_blend) -EXTERN_CVAR(Int, gl_spriteclip) -EXTERN_CVAR(Float, gl_sclipthreshold) -EXTERN_CVAR(Float, gl_sclipfactor) -EXTERN_CVAR(Int, gl_particles_style) -EXTERN_CVAR(Int, gl_billboard_mode) -EXTERN_CVAR(Bool, gl_billboard_faces_camera) -EXTERN_CVAR(Bool, gl_billboard_particles) -EXTERN_CVAR(Int, gl_enhanced_nv_stealth) -EXTERN_CVAR(Int, gl_fuzztype) - EXTERN_CVAR(Int, gl_shadowmap_filter) EXTERN_CVAR(Bool, gl_brightfog) diff --git a/src/rendering/vulkan/renderer/vk_renderbuffers.cpp b/src/rendering/vulkan/renderer/vk_renderbuffers.cpp index 80e619fe7b..2557054ea7 100644 --- a/src/rendering/vulkan/renderer/vk_renderbuffers.cpp +++ b/src/rendering/vulkan/renderer/vk_renderbuffers.cpp @@ -27,6 +27,7 @@ #include "vulkan/system/vk_builders.h" #include "vulkan/system/vk_framebuffer.h" #include "hwrenderer/utility/hw_cvars.h" +#include "templates.h" VkRenderBuffers::VkRenderBuffers() { From 61c94c25ed7e87c6f06f0dceda8f4d7d191e0017 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 10:58:44 +0200 Subject: [PATCH 101/220] - more hw_cvars cleanup. Copied several range checks from Raze, moved vid_gamma to hw_cvars.cpp and removed some old and no longer necessary gamma setup code. --- src/r_data/v_palette.cpp | 41 ----------------- src/rendering/hwrenderer/utility/hw_cvars.cpp | 45 ++++++++++++++++--- src/rendering/v_video.cpp | 2 - src/rendering/v_video.h | 2 - 4 files changed, 39 insertions(+), 51 deletions(-) diff --git a/src/r_data/v_palette.cpp b/src/r_data/v_palette.cpp index 1b007099b5..795580be67 100644 --- a/src/r_data/v_palette.cpp +++ b/src/r_data/v_palette.cpp @@ -34,12 +34,6 @@ #include "g_level.h" -#ifdef _WIN32 -#include -#else -#define O_BINARY 0 -#endif - #include "templates.h" #include "v_video.h" #include "filesystem.h" @@ -54,39 +48,6 @@ /* Current color blending values */ int BlendR, BlendG, BlendB, BlendA; -/**************************/ -/* Gamma correction stuff */ -/**************************/ - -uint8_t newgamma[256]; -CUSTOM_CVAR (Float, vid_gamma, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -{ - if (self == 0.f) - { // Gamma values of 0 are illegal. - self = 1.f; - return; - } - - if (screen != NULL) - { - screen->SetGamma (); - } -} - -CCMD (bumpgamma) -{ - // [RH] Gamma correction tables are now generated on the fly for *any* gamma level - // Q: What are reasonable limits to use here? - - float newgamma = vid_gamma + 0.1f; - - if (newgamma > 3.0) - newgamma = 1.0; - - vid_gamma = newgamma; - Printf ("Gamma correction level %g\n", *vid_gamma); -} - void InitPalette () @@ -103,8 +64,6 @@ void InitPalette () if (lump != -1) { FileData cmap = fileSystem.ReadFile(lump); - uint8_t palbuffer[768]; - ReadPalette(fileSystem.GetNumForName("PLAYPAL"), palbuffer); const unsigned char* cmapdata = (const unsigned char*)cmap.GetMem(); GPalette.GenerateGlobalBrightmapFromColormap(cmapdata, 32); } diff --git a/src/rendering/hwrenderer/utility/hw_cvars.cpp b/src/rendering/hwrenderer/utility/hw_cvars.cpp index 42b5ddacd7..d0a4c19e91 100644 --- a/src/rendering/hwrenderer/utility/hw_cvars.cpp +++ b/src/rendering/hwrenderer/utility/hw_cvars.cpp @@ -40,16 +40,13 @@ #include "c_dispatch.h" #include "v_video.h" #include "hw_cvars.h" -#include "hw_material.h" #include "menu/menu.h" -#include "texturemanager.h" // OpenGL stuff moved here // GL related CVARs CVAR(Bool, gl_portals, true, 0) -CVAR(Bool, gl_noquery, false, 0) CVAR(Bool,gl_mirrors,true,0) // This is for debugging only! CVAR(Bool,gl_mirror_envmap, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) CVAR(Bool, gl_seamless, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) @@ -70,9 +67,45 @@ CUSTOM_CVAR(Bool, gl_render_precise, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) gl_seamless=self; } -CVAR (Float, vid_brightness, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -CVAR (Float, vid_contrast, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) -CVAR (Float, vid_saturation, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +CUSTOM_CVARD(Float, vid_gamma, 1.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "adjusts gamma component of gamma ramp") +{ + if (self < 0) self = 1; + else if (self > 4) self = 4; +} + +CUSTOM_CVARD(Float, vid_contrast, 1.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "adjusts contrast component of gamma ramp") +{ + if (self < 0) self = 0; + else if (self > 5) self = 5; +} + +CUSTOM_CVARD(Float, vid_brightness, 0.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "adjusts brightness component of gamma ramp") +{ + if (self < -2) self = -2; + else if (self > 2) self = 2; +} + +CUSTOM_CVARD(Float, vid_saturation, 1.f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "adjusts saturation component of gamma ramp") +{ + if (self < -3) self = -3; + else if (self > 3) self = 3; +} + +CCMD (bumpgamma) +{ + // [RH] Gamma correction tables are now generated on the fly for *any* gamma level + // Q: What are reasonable limits to use here? + + float newgamma = vid_gamma + 0.1f; + + if (newgamma > 4.0) + newgamma = 1.0; + + vid_gamma = newgamma; + Printf ("Gamma correction level %g\n", newgamma); +} + + CVAR(Int, gl_satformula, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); //========================================================================== diff --git a/src/rendering/v_video.cpp b/src/rendering/v_video.cpp index 958486e30c..ff65646296 100644 --- a/src/rendering/v_video.cpp +++ b/src/rendering/v_video.cpp @@ -347,7 +347,6 @@ bool IVideo::SetResolution () screen = buff; screen->InitializeState(); - screen->SetGamma(); V_UpdateModeSize(screen->GetWidth(), screen->GetHeight()); @@ -423,7 +422,6 @@ void V_Init2() menu_resolution_custom_height = SCREENHEIGHT; screen->SetVSync(vid_vsync); - screen->SetGamma (); FBaseCVar::ResetColors (); C_NewModeAdjust(); setsizeneeded = true; diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index 0fa592ff38..e790d72271 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -215,8 +215,6 @@ public: // Mark the palette as changed. It will be updated on the next Update(). virtual void UpdatePalette() {} - virtual void SetGamma() {} - // Returns true if running fullscreen. virtual bool IsFullscreen () = 0; virtual void ToggleFullscreen(bool yes) {} From cf41a0b1fb716d58da9319fd5c69e568254e6817 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 11:38:38 +0200 Subject: [PATCH 102/220] - moved hw_cvars to 'common'. --- src/CMakeLists.txt | 2 +- .../rendering/hwrenderer/data}/hw_cvars.cpp | 5 ----- .../utility => common/rendering/hwrenderer/data}/hw_cvars.h | 0 src/common/rendering/hwrenderer/data/hw_vrmodes.cpp | 2 +- .../rendering/hwrenderer/postprocessing/hw_postprocess.cpp | 2 +- src/common/textures/texturemanager.cpp | 6 ++++++ src/rendering/2d/v_blend.cpp | 2 +- src/rendering/gl/renderer/gl_renderbuffers.cpp | 2 +- src/rendering/gl/renderer/gl_renderer.cpp | 2 +- src/rendering/gl/renderer/gl_renderstate.cpp | 2 +- src/rendering/gl/shaders/gl_shaderprogram.cpp | 2 +- src/rendering/gl/textures/gl_hwtexture.cpp | 2 +- src/rendering/gl/textures/gl_samplers.cpp | 2 +- src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp | 2 +- src/rendering/hwrenderer/hw_entrypoint.cpp | 2 +- src/rendering/hwrenderer/scene/hw_decal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_drawinfo.cpp | 2 +- src/rendering/hwrenderer/scene/hw_drawlistadd.cpp | 2 +- src/rendering/hwrenderer/scene/hw_fakeflat.cpp | 2 +- src/rendering/hwrenderer/scene/hw_flats.cpp | 2 +- src/rendering/hwrenderer/scene/hw_renderstate.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 2 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 2 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 2 +- src/rendering/hwrenderer/utility/hw_draw2d.cpp | 2 +- src/rendering/polyrenderer/backend/poly_framebuffer.cpp | 2 +- src/rendering/polyrenderer/backend/poly_hwtexture.cpp | 2 +- src/rendering/polyrenderer/backend/poly_renderstate.cpp | 2 +- src/rendering/vulkan/renderer/vk_postprocess.cpp | 2 +- src/rendering/vulkan/renderer/vk_renderbuffers.cpp | 2 +- src/rendering/vulkan/renderer/vk_renderstate.cpp | 2 +- src/rendering/vulkan/system/vk_framebuffer.cpp | 2 +- src/rendering/vulkan/textures/vk_hwtexture.cpp | 2 +- src/rendering/vulkan/textures/vk_samplers.cpp | 2 +- 34 files changed, 37 insertions(+), 36 deletions(-) rename src/{rendering/hwrenderer/utility => common/rendering/hwrenderer/data}/hw_cvars.cpp (99%) rename src/{rendering/hwrenderer/utility => common/rendering/hwrenderer/data}/hw_cvars.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 426cb505ff..e7606aa5cb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -969,7 +969,6 @@ set (PCH_SOURCES rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp rendering/hwrenderer/textures/hw_precache.cpp rendering/hwrenderer/utility/hw_clock.cpp - rendering/hwrenderer/utility/hw_cvars.cpp rendering/hwrenderer/utility/hw_draw2d.cpp rendering/hwrenderer/utility/hw_lighting.cpp rendering/hwrenderer/utility/hw_shaderpatcher.cpp @@ -1144,6 +1143,7 @@ set (PCH_SOURCES common/objects/dobjgc.cpp common/objects/dobjtype.cpp common/rendering/r_videoscale.cpp + common/rendering/hwrenderer/data/hw_cvars.cpp common/rendering/hwrenderer/data/hw_vrmodes.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp diff --git a/src/rendering/hwrenderer/utility/hw_cvars.cpp b/src/common/rendering/hwrenderer/data/hw_cvars.cpp similarity index 99% rename from src/rendering/hwrenderer/utility/hw_cvars.cpp rename to src/common/rendering/hwrenderer/data/hw_cvars.cpp index d0a4c19e91..2d5d4a9f29 100644 --- a/src/rendering/hwrenderer/utility/hw_cvars.cpp +++ b/src/common/rendering/hwrenderer/data/hw_cvars.cpp @@ -118,11 +118,6 @@ CUSTOM_CVARD(Float, gl_texture_filter_anisotropic, 8, CVAR_ARCHIVE | CVAR_GLOBAL screen->TextureFilterChanged(); } -CCMD(gl_flush) -{ - TexMan.FlushAll(); -} - CUSTOM_CVARD(Int, gl_texture_filter, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL, "changes the texture filtering settings") { if (self < 0 || self > 6) self=4; diff --git a/src/rendering/hwrenderer/utility/hw_cvars.h b/src/common/rendering/hwrenderer/data/hw_cvars.h similarity index 100% rename from src/rendering/hwrenderer/utility/hw_cvars.h rename to src/common/rendering/hwrenderer/data/hw_cvars.h diff --git a/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp b/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp index c57a6297e7..a105f48c21 100644 --- a/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp +++ b/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp @@ -26,7 +26,7 @@ */ #include "vectors.h" // RAD2DEG -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hw_vrmodes.h" #include "v_video.h" #include "version.h" diff --git a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp index db991145a6..519e03b11e 100644 --- a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -21,7 +21,7 @@ #include "v_video.h" #include "hw_postprocess.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" #include "hwrenderer/postprocessing/hw_postprocessshader.h" #include diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index a94a1592aa..c7cffd07cd 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -1541,3 +1541,9 @@ FTextureID FTextureID::operator +(int offset) throw() if (texnum + offset >= TexMan.NumTextures()) return FTextureID(-1); return FTextureID(texnum + offset); } + +CCMD(flushtextures) +{ + TexMan.FlushAll(); +} + diff --git a/src/rendering/2d/v_blend.cpp b/src/rendering/2d/v_blend.cpp index 95780e31c7..f654ee39b0 100644 --- a/src/rendering/2d/v_blend.cpp +++ b/src/rendering/2d/v_blend.cpp @@ -46,7 +46,7 @@ #include "vm.h" #include "v_palette.h" #include "r_utility.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" CVAR(Float, underwater_fade_scalar, 1.0f, CVAR_ARCHIVE) // [Nash] user-settable underwater blend intensity CVAR( Float, blood_fade_scalar, 1.0f, CVAR_ARCHIVE ) // [SP] Pulled from Skulltag - changed default from 0.5 to 1.0 diff --git a/src/rendering/gl/renderer/gl_renderbuffers.cpp b/src/rendering/gl/renderer/gl_renderbuffers.cpp index 319cf12789..b6e1000fdd 100644 --- a/src/rendering/gl/renderer/gl_renderbuffers.cpp +++ b/src/rendering/gl/renderer/gl_renderbuffers.cpp @@ -23,7 +23,7 @@ #include "v_video.h" #include "gl_interface.h" #include "printf.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "gl/system/gl_debug.h" #include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderbuffers.h" diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index a101f7ec7e..eaffe1d3ca 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -42,7 +42,7 @@ #include "gl_interface.h" #include "gl/system/gl_framebuffer.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "gl/system/gl_debug.h" #include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderstate.h" diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index 16dbedcbe7..e59265020f 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -30,7 +30,7 @@ #include "r_data/colormaps.h" #include "gl_system.h" #include "gl_interface.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/scene/hw_skydome.h" #include "gl/shaders/gl_shader.h" diff --git a/src/rendering/gl/shaders/gl_shaderprogram.cpp b/src/rendering/gl/shaders/gl_shaderprogram.cpp index f958bd35d0..a79af0ce1a 100644 --- a/src/rendering/gl/shaders/gl_shaderprogram.cpp +++ b/src/rendering/gl/shaders/gl_shaderprogram.cpp @@ -28,7 +28,7 @@ #include "gl_system.h" #include "v_video.h" #include "gl_interface.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "gl/system/gl_debug.h" #include "gl/shaders/gl_shaderprogram.h" #include "hwrenderer/utility/hw_shaderpatcher.h" diff --git a/src/rendering/gl/textures/gl_hwtexture.cpp b/src/rendering/gl/textures/gl_hwtexture.cpp index 6b0cd9995a..2f807a5d66 100644 --- a/src/rendering/gl/textures/gl_hwtexture.cpp +++ b/src/rendering/gl/textures/gl_hwtexture.cpp @@ -41,7 +41,7 @@ #include "hw_material.h" #include "gl_interface.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "gl/system/gl_debug.h" #include "gl/renderer/gl_renderer.h" #include "gl/renderer/gl_renderstate.h" diff --git a/src/rendering/gl/textures/gl_samplers.cpp b/src/rendering/gl/textures/gl_samplers.cpp index 7f4e9ef3e7..39d8146d72 100644 --- a/src/rendering/gl/textures/gl_samplers.cpp +++ b/src/rendering/gl/textures/gl_samplers.cpp @@ -36,7 +36,7 @@ #include "c_cvars.h" #include "gl_interface.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "gl/system/gl_debug.h" #include "gl/renderer/gl_renderer.h" #include "gl_samplers.h" diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp index 99bdaed530..d32d2d7a26 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp @@ -21,7 +21,7 @@ // #include "hwrenderer/dynlights/hw_shadowmap.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hwrenderer/data/buffers.h" #include "hwrenderer/data/shaderuniforms.h" diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index c2e06a8302..ea61d8230c 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -41,7 +41,7 @@ #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_clipper.h" diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index de9b28305e..45596b1514 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -30,7 +30,7 @@ #include "r_utility.h" #include "g_levellocals.h" #include "hw_material.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/utility/hw_lighting.h" diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 2d07869a57..d8146664fa 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -37,7 +37,7 @@ #include "po_man.h" #include "r_data/models/models.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" diff --git a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp index 3c4a85f38a..e48326e110 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -21,7 +21,7 @@ // #include "hwrenderer/dynlights/hw_dynlightdata.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" diff --git a/src/rendering/hwrenderer/scene/hw_fakeflat.cpp b/src/rendering/hwrenderer/scene/hw_fakeflat.cpp index a5431bc3b8..a436c12098 100644 --- a/src/rendering/hwrenderer/scene/hw_fakeflat.cpp +++ b/src/rendering/hwrenderer/scene/hw_fakeflat.cpp @@ -33,7 +33,7 @@ #include "r_sky.h" #include "hw_fakeflat.h" #include "hw_drawinfo.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "r_utility.h" #include "texturemanager.h" diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index 69b1712c33..b2976527c2 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -37,7 +37,7 @@ #include "p_lnspec.h" #include "matrix.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hw_material.h" diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.cpp b/src/rendering/hwrenderer/scene/hw_renderstate.cpp index 62841f0b63..b0d892b615 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderstate.cpp @@ -30,7 +30,7 @@ #include "hw_drawstructs.h" #include "hw_portal.h" #include "hwrenderer/utility/hw_lighting.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" //========================================================================== diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 020bae1f20..00ee37e9fa 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -50,7 +50,7 @@ #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/data/flatvertices.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hw_material.h" diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index bbb2482169..bc788fe1d4 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -34,7 +34,7 @@ #include "texturemanager.h" #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hw_material.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hwrenderer/scene/hw_drawinfo.h" diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index ca4f388d72..debbf71bbd 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -40,7 +40,7 @@ #include "hwrenderer/dynlights/hw_dynlightdata.h" #include "hw_material.h" #include "hwrenderer/utility/hw_lighting.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/data/flatvertices.h" diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index 40e3451c77..2abc5397eb 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -33,7 +33,7 @@ #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hw_renderstate.h" #include "r_videoscale.h" diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 6091b4ed97..3eb79890b4 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -31,7 +31,7 @@ #include "hwrenderer/utility/hw_clock.h" #include "hw_vrmodes.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index 3736242092..2971665142 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -24,7 +24,7 @@ #include "c_cvars.h" #include "r_data/colormaps.h" #include "hw_material.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hw_renderstate.h" #include "poly_framebuffer.h" #include "poly_hwtexture.h" diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index a8f1550558..c114c9ac30 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -29,7 +29,7 @@ #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" diff --git a/src/rendering/vulkan/renderer/vk_postprocess.cpp b/src/rendering/vulkan/renderer/vk_postprocess.cpp index 403a9dfcd1..1e85705a25 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.cpp +++ b/src/rendering/vulkan/renderer/vk_postprocess.cpp @@ -29,7 +29,7 @@ #include "vulkan/system/vk_swapchain.h" #include "vulkan/renderer/vk_renderstate.h" #include "vulkan/textures/vk_imagetransition.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/postprocessing/hw_postprocess.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" #include "hw_vrmodes.h" diff --git a/src/rendering/vulkan/renderer/vk_renderbuffers.cpp b/src/rendering/vulkan/renderer/vk_renderbuffers.cpp index 2557054ea7..e3217076de 100644 --- a/src/rendering/vulkan/renderer/vk_renderbuffers.cpp +++ b/src/rendering/vulkan/renderer/vk_renderbuffers.cpp @@ -26,7 +26,7 @@ #include "vulkan/shaders/vk_shader.h" #include "vulkan/system/vk_builders.h" #include "vulkan/system/vk_framebuffer.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "templates.h" VkRenderBuffers::VkRenderBuffers() diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 3e2cc97e74..55484d8946 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -32,7 +32,7 @@ #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" #include "hwrenderer/dynlights/hw_lightbuffer.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index a783f8c10f..9a96f87e9a 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -33,7 +33,7 @@ #include "hwrenderer/utility/hw_clock.h" #include "hw_vrmodes.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hwrenderer/models/hw_models.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index d686fedd74..e39c5e0092 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -24,7 +24,7 @@ #include "c_cvars.h" #include "r_data/colormaps.h" #include "hw_material.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "hw_renderstate.h" #include "vulkan/system/vk_objects.h" #include "vulkan/system/vk_builders.h" diff --git a/src/rendering/vulkan/textures/vk_samplers.cpp b/src/rendering/vulkan/textures/vk_samplers.cpp index d82f4bb019..23afff2c6e 100644 --- a/src/rendering/vulkan/textures/vk_samplers.cpp +++ b/src/rendering/vulkan/textures/vk_samplers.cpp @@ -24,7 +24,7 @@ #include "c_cvars.h" #include "v_video.h" -#include "hwrenderer/utility/hw_cvars.h" +#include "hw_cvars.h" #include "vulkan/system/vk_device.h" #include "vulkan/system/vk_builders.h" #include "vk_samplers.h" From c5dca89e6617852f72cd789242073963d0442253 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 12:12:07 +0200 Subject: [PATCH 103/220] - clean separation of vertex creation from map data and the buffer object. This was yet another object with too broad scope, the vertex creation has been offloaded into out-of-class functions now. --- src/CMakeLists.txt | 3 +- .../hwrenderer/data/hw_viewpointbuffer.cpp | 0 .../hwrenderer/data/hw_viewpointbuffer.h | 0 src/maploader/maploader.cpp | 3 +- .../hwrenderer/data/flatvertices.cpp | 254 +----------------- src/rendering/hwrenderer/data/flatvertices.h | 54 ++-- .../hwrenderer/data/hw_vertexbuilder.cpp | 253 +++++++++++++++++ .../hwrenderer/data/hw_vertexbuilder.h | 3 + src/rendering/hwrenderer/scene/hw_bsp.cpp | 3 +- 9 files changed, 279 insertions(+), 294 deletions(-) rename src/{ => common}/rendering/hwrenderer/data/hw_viewpointbuffer.cpp (100%) rename src/{ => common}/rendering/hwrenderer/data/hw_viewpointbuffer.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e7606aa5cb..4a0e5df984 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -958,7 +958,6 @@ set (PCH_SOURCES rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp rendering/hwrenderer/data/flatvertices.cpp - rendering/hwrenderer/data/hw_viewpointbuffer.cpp rendering/hwrenderer/dynlights/hw_aabbtree.cpp rendering/hwrenderer/dynlights/hw_shadowmap.cpp rendering/hwrenderer/dynlights/hw_lightbuffer.cpp @@ -1143,11 +1142,11 @@ set (PCH_SOURCES common/objects/dobjgc.cpp common/objects/dobjtype.cpp common/rendering/r_videoscale.cpp + common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp common/rendering/hwrenderer/data/hw_cvars.cpp common/rendering/hwrenderer/data/hw_vrmodes.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp - common/rendering/gl_load/gl_interface.cpp common/scripting/core/dictionary.cpp common/scripting/core/dynarrays.cpp diff --git a/src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp b/src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp similarity index 100% rename from src/rendering/hwrenderer/data/hw_viewpointbuffer.cpp rename to src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp diff --git a/src/rendering/hwrenderer/data/hw_viewpointbuffer.h b/src/common/rendering/hwrenderer/data/hw_viewpointbuffer.h similarity index 100% rename from src/rendering/hwrenderer/data/hw_viewpointbuffer.h rename to src/common/rendering/hwrenderer/data/hw_viewpointbuffer.h diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 4a3b66bd60..2fc70e5597 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -81,6 +81,7 @@ #include "xlat/xlat.h" #include "vm.h" #include "texturemanager.h" +#include "hwrenderer/data/hw_vertexbuilder.h" enum { @@ -3223,7 +3224,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) InitRenderInfo(); // create hardware independent renderer resources for the level. This must be done BEFORE the PolyObj Spawn!!! Level->ClearDynamic3DFloorData(); // CreateVBO must be run on the plain 3D floor data. - screen->mVertexData->CreateVBO(Level->sectors); + CreateVBO(screen->mVertexData, Level->sectors); for (auto &sec : Level->sectors) { diff --git a/src/rendering/hwrenderer/data/flatvertices.cpp b/src/rendering/hwrenderer/data/flatvertices.cpp index 8b0058ba3a..bdee1e5c1f 100644 --- a/src/rendering/hwrenderer/data/flatvertices.cpp +++ b/src/rendering/hwrenderer/data/flatvertices.cpp @@ -32,16 +32,12 @@ ** */ -#include "doomtype.h" -#include "p_local.h" -#include "r_state.h" #include "c_cvars.h" -#include "g_levellocals.h" #include "flatvertices.h" #include "v_video.h" #include "cmdlib.h" +#include "printf.h" #include "hwrenderer/data/buffers.h" -#include "hw_renderstate.h" //========================================================================== // @@ -94,7 +90,7 @@ FFlatVertexBuffer::FFlatVertexBuffer(int width, int height) }; mVertexBuffer->SetFormat(1, 2, sizeof(FFlatVertex), format); - mIndex = mCurIndex = 0; + mIndex = mCurIndex = NUM_RESERVED; mNumReserved = NUM_RESERVED; Copy(0, NUM_RESERVED); } @@ -128,238 +124,6 @@ void FFlatVertexBuffer::OutputResized(int width, int height) Copy(4, 4); } -//========================================================================== -// -// Initialize a single vertex -// -//========================================================================== - -void FFlatVertex::SetFlatVertex(vertex_t *vt, const secplane_t & plane) -{ - x = (float)vt->fX(); - y = (float)vt->fY(); - z = (float)plane.ZatPoint(vt); - u = (float)vt->fX()/64.f; - v = -(float)vt->fY()/64.f; -} - -//========================================================================== -// -// Find a 3D floor -// -//========================================================================== - -static F3DFloor *Find3DFloor(sector_t *target, sector_t *model) -{ - for(unsigned i=0; ie->XFloor.ffloors.Size(); i++) - { - F3DFloor *ffloor = target->e->XFloor.ffloors[i]; - if (ffloor->model == model && !(ffloor->flags & FF_THISINSIDE)) return ffloor; - } - return NULL; -} - -//========================================================================== -// -// Creates the vertices for one plane in one subsector -// -//========================================================================== - -int FFlatVertexBuffer::CreateIndexedSectorVertices(sector_t *sec, const secplane_t &plane, int floor, VertexContainer &verts) -{ - unsigned vi = vbo_shadowdata.Reserve(verts.vertices.Size()); - float diff; - - // Create the actual vertices. - if (sec->transdoor && floor) diff = -1.f; - else diff = 0.f; - for (unsigned i = 0; i < verts.vertices.Size(); i++) - { - vbo_shadowdata[vi + i].SetFlatVertex(verts.vertices[i].vertex, plane); - vbo_shadowdata[vi + i].z += diff; - } - - unsigned rt = ibo_data.Reserve(verts.indices.Size()); - for (unsigned i = 0; i < verts.indices.Size(); i++) - { - ibo_data[rt + i] = vi + verts.indices[i]; - } - return (int)rt; -} - -//========================================================================== -// -// -// -//========================================================================== - -int FFlatVertexBuffer::CreateIndexedVertices(int h, sector_t *sec, const secplane_t &plane, int floor, VertexContainers &verts) -{ - sec->vboindex[h] = vbo_shadowdata.Size(); - // First calculate the vertices for the sector itself - sec->vboheight[h] = sec->GetPlaneTexZ(h); - sec->ibocount = verts[sec->Index()].indices.Size(); - sec->iboindex[h] = CreateIndexedSectorVertices(sec, plane, floor, verts[sec->Index()]); - - // Next are all sectors using this one as heightsec - TArray &fakes = sec->e->FakeFloor.Sectors; - for (unsigned g = 0; g < fakes.Size(); g++) - { - sector_t *fsec = fakes[g]; - fsec->iboindex[2 + h] = CreateIndexedSectorVertices(fsec, plane, false, verts[fsec->Index()]); - } - - // and finally all attached 3D floors - TArray &xf = sec->e->XFloor.attached; - for (unsigned g = 0; g < xf.Size(); g++) - { - sector_t *fsec = xf[g]; - F3DFloor *ffloor = Find3DFloor(fsec, sec); - - if (ffloor != NULL && ffloor->flags & FF_RENDERPLANES) - { - bool dotop = (ffloor->top.model == sec) && (ffloor->top.isceiling == h); - bool dobottom = (ffloor->bottom.model == sec) && (ffloor->bottom.isceiling == h); - - if (dotop || dobottom) - { - auto ndx = CreateIndexedSectorVertices(fsec, plane, false, verts[fsec->Index()]); - if (dotop) ffloor->top.vindex = ndx; - if (dobottom) ffloor->bottom.vindex = ndx; - } - } - } - sec->vbocount[h] = vbo_shadowdata.Size() - sec->vboindex[h]; - return sec->iboindex[h]; -} - - -//========================================================================== -// -// -// -//========================================================================== - -void FFlatVertexBuffer::CreateIndexedFlatVertices(TArray §ors) -{ - auto verts = BuildVertices(sectors); - - int i = 0; - /* - for (auto &vert : verts) - { - Printf(PRINT_LOG, "Sector %d\n", i); - Printf(PRINT_LOG, "%d vertices, %d indices\n", vert.vertices.Size(), vert.indices.Size()); - int j = 0; - for (auto &v : vert.vertices) - { - Printf(PRINT_LOG, " %d: (%2.3f, %2.3f)\n", j++, v.vertex->fX(), v.vertex->fY()); - } - for (unsigned i=0;iXFloor.ffloors) - { - if (ff->top.model == &sec) - { - ff->top.vindex = sec.iboindex[ff->top.isceiling]; - } - if (ff->bottom.model == &sec) - { - ff->bottom.vindex = sec.iboindex[ff->top.isceiling]; - } - } - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void FFlatVertexBuffer::UpdatePlaneVertices(sector_t *sec, int plane) -{ - int startvt = sec->vboindex[plane]; - int countvt = sec->vbocount[plane]; - secplane_t &splane = sec->GetSecPlane(plane); - FFlatVertex *vt = &vbo_shadowdata[startvt]; - FFlatVertex *mapvt = GetBuffer(startvt); - for(int i=0; iz = (float)splane.ZatPoint(vt->x, vt->y); - if (plane == sector_t::floor && sec->transdoor) vt->z -= 1; - mapvt->z = vt->z; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void FFlatVertexBuffer::CreateVertices(TArray §ors) -{ - vbo_shadowdata.Resize(NUM_RESERVED); - CreateIndexedFlatVertices(sectors); -} - -//========================================================================== -// -// -// -//========================================================================== - -void FFlatVertexBuffer::CheckPlanes(sector_t *sector) -{ - if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling]) - { - UpdatePlaneVertices(sector, sector_t::ceiling); - sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling); - } - if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor]) - { - UpdatePlaneVertices(sector, sector_t::floor); - sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor); - } -} - -//========================================================================== -// -// checks the validity of all planes attached to this sector -// and updates them if possible. -// -//========================================================================== - -void FFlatVertexBuffer::CheckUpdate(sector_t *sector) -{ - CheckPlanes(sector); - sector_t *hs = sector->GetHeightSec(); - if (hs != NULL) CheckPlanes(hs); - for (unsigned i = 0; i < sector->e->XFloor.ffloors.Size(); i++) - CheckPlanes(sector->e->XFloor.ffloors[i]->model); -} - //========================================================================== // // @@ -392,17 +156,3 @@ void FFlatVertexBuffer::Copy(int start, int count) Unmap(); } -//========================================================================== -// -// -// -//========================================================================== - -void FFlatVertexBuffer::CreateVBO(TArray §ors) -{ - vbo_shadowdata.Resize(mNumReserved); - FFlatVertexBuffer::CreateVertices(sectors); - mCurIndex = mIndex = vbo_shadowdata.Size(); - Copy(0, mIndex); - mIndexBuffer->SetData(ibo_data.Size() * sizeof(uint32_t), &ibo_data[0]); -} diff --git a/src/rendering/hwrenderer/data/flatvertices.h b/src/rendering/hwrenderer/data/flatvertices.h index 6161cea292..04feb83880 100644 --- a/src/rendering/hwrenderer/data/flatvertices.h +++ b/src/rendering/hwrenderer/data/flatvertices.h @@ -1,31 +1,9 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2005-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// #ifndef _HW__VERTEXBUFFER_H #define _HW__VERTEXBUFFER_H #include "tarray.h" #include "hwrenderer/data/buffers.h" -#include "hw_vertexbuilder.h" #include #include @@ -38,7 +16,6 @@ struct FFlatVertex float x, z, y; // world position float u, v; // texture coordinates - void SetFlatVertex(vertex_t *vt, const secplane_t &plane); void Set(float xx, float zz, float yy, float uu, float vv) { x = xx; @@ -47,10 +24,25 @@ struct FFlatVertex u = uu; v = vv; } + + void SetVertex(float _x, float _y, float _z = 0) + { + x = _x; + z = _y; + y = _z; + } + + void SetTexCoord(float _u = 0, float _v = 0) + { + u = _u; + v = _v; + } + }; class FFlatVertexBuffer { +public: TArray vbo_shadowdata; TArray ibo_data; @@ -63,7 +55,7 @@ class FFlatVertexBuffer static const unsigned int BUFFER_SIZE = 2000000; - static const unsigned int BUFFER_SIZE_TO_USE = 1999500; + static const unsigned int BUFFER_SIZE_TO_USE = BUFFER_SIZE-500; public: enum @@ -86,7 +78,6 @@ public: return std::make_pair(mVertexBuffer, mIndexBuffer); } - void CreateVBO(TArray §ors); void Copy(int start, int count); FFlatVertex *GetBuffer(int index) const @@ -117,19 +108,6 @@ public: mVertexBuffer->Unmap(); } -private: - int CreateIndexedSectionVertices(subsector_t *sub, const secplane_t &plane, int floor, VertexContainer &cont); - int CreateIndexedSectorVertices(sector_t *sec, const secplane_t &plane, int floor, VertexContainer &cont); - int CreateIndexedVertices(int h, sector_t *sec, const secplane_t &plane, int floor, VertexContainers &cont); - void CreateIndexedFlatVertices(TArray §ors); - - void UpdatePlaneVertices(sector_t *sec, int plane); -protected: - void CreateVertices(TArray §ors); - void CheckPlanes(sector_t *sector); -public: - void CheckUpdate(sector_t *sector); - }; #endif diff --git a/src/rendering/hwrenderer/data/hw_vertexbuilder.cpp b/src/rendering/hwrenderer/data/hw_vertexbuilder.cpp index a21b3c78f1..459b1e605c 100644 --- a/src/rendering/hwrenderer/data/hw_vertexbuilder.cpp +++ b/src/rendering/hwrenderer/data/hw_vertexbuilder.cpp @@ -24,6 +24,7 @@ #include "g_levellocals.h" #include "hw_vertexbuilder.h" +#include "flatvertices.h" #include "earcut.hpp" @@ -146,3 +147,255 @@ TArray BuildVertices(TArray §ors) } return verticesPerSector; } + +//========================================================================== +// +// Creates the vertices for one plane in one subsector +// +//========================================================================== + +//========================================================================== +// +// Find a 3D floor +// +//========================================================================== + +static F3DFloor* Find3DFloor(sector_t* target, sector_t* model) +{ + for (unsigned i = 0; i < target->e->XFloor.ffloors.Size(); i++) + { + F3DFloor* ffloor = target->e->XFloor.ffloors[i]; + if (ffloor->model == model && !(ffloor->flags & FF_THISINSIDE)) return ffloor; + } + return NULL; +} + +//========================================================================== +// +// Initialize a single vertex +// +//========================================================================== + +static void SetFlatVertex(FFlatVertex& ffv, vertex_t* vt, const secplane_t& plane) +{ + ffv.x = (float)vt->fX(); + ffv.y = (float)vt->fY(); + ffv.z = (float)plane.ZatPoint(vt); + ffv.u = (float)vt->fX() / 64.f; + ffv.v = -(float)vt->fY() / 64.f; +} + + + +static int CreateIndexedSectorVertices(FFlatVertexBuffer* fvb, sector_t* sec, const secplane_t& plane, int floor, VertexContainer& verts) +{ + auto& vbo_shadowdata = fvb->vbo_shadowdata; + unsigned vi = vbo_shadowdata.Reserve(verts.vertices.Size()); + float diff; + + // Create the actual vertices. + if (sec->transdoor && floor) diff = -1.f; + else diff = 0.f; + for (unsigned i = 0; i < verts.vertices.Size(); i++) + { + SetFlatVertex(vbo_shadowdata[vi + i], verts.vertices[i].vertex, plane); + vbo_shadowdata[vi + i].z += diff; + } + + auto& ibo_data = fvb->ibo_data; + unsigned rt = ibo_data.Reserve(verts.indices.Size()); + for (unsigned i = 0; i < verts.indices.Size(); i++) + { + ibo_data[rt + i] = vi + verts.indices[i]; + } + return (int)rt; +} + +//========================================================================== +// +// +// +//========================================================================== + +static int CreateIndexedVertices(FFlatVertexBuffer* fvb, int h, sector_t* sec, const secplane_t& plane, int floor, VertexContainers& verts) +{ + auto& vbo_shadowdata = fvb->vbo_shadowdata; + sec->vboindex[h] = vbo_shadowdata.Size(); + // First calculate the vertices for the sector itself + sec->vboheight[h] = sec->GetPlaneTexZ(h); + sec->ibocount = verts[sec->Index()].indices.Size(); + sec->iboindex[h] = CreateIndexedSectorVertices(fvb, sec, plane, floor, verts[sec->Index()]); + + // Next are all sectors using this one as heightsec + TArray& fakes = sec->e->FakeFloor.Sectors; + for (unsigned g = 0; g < fakes.Size(); g++) + { + sector_t* fsec = fakes[g]; + fsec->iboindex[2 + h] = CreateIndexedSectorVertices(fvb, fsec, plane, false, verts[fsec->Index()]); + } + + // and finally all attached 3D floors + TArray& xf = sec->e->XFloor.attached; + for (unsigned g = 0; g < xf.Size(); g++) + { + sector_t* fsec = xf[g]; + F3DFloor* ffloor = Find3DFloor(fsec, sec); + + if (ffloor != NULL && ffloor->flags & FF_RENDERPLANES) + { + bool dotop = (ffloor->top.model == sec) && (ffloor->top.isceiling == h); + bool dobottom = (ffloor->bottom.model == sec) && (ffloor->bottom.isceiling == h); + + if (dotop || dobottom) + { + auto ndx = CreateIndexedSectorVertices(fvb, fsec, plane, false, verts[fsec->Index()]); + if (dotop) ffloor->top.vindex = ndx; + if (dobottom) ffloor->bottom.vindex = ndx; + } + } + } + sec->vbocount[h] = vbo_shadowdata.Size() - sec->vboindex[h]; + return sec->iboindex[h]; +} + + +//========================================================================== +// +// +// +//========================================================================== + +static void CreateIndexedFlatVertices(FFlatVertexBuffer* fvb, TArray& sectors) +{ + auto verts = BuildVertices(sectors); + + int i = 0; + /* + for (auto &vert : verts) + { + Printf(PRINT_LOG, "Sector %d\n", i); + Printf(PRINT_LOG, "%d vertices, %d indices\n", vert.vertices.Size(), vert.indices.Size()); + int j = 0; + for (auto &v : vert.vertices) + { + Printf(PRINT_LOG, " %d: (%2.3f, %2.3f)\n", j++, v.vertex->fX(), v.vertex->fY()); + } + for (unsigned i=0;iXFloor.ffloors) + { + if (ff->top.model == &sec) + { + ff->top.vindex = sec.iboindex[ff->top.isceiling]; + } + if (ff->bottom.model == &sec) + { + ff->bottom.vindex = sec.iboindex[ff->top.isceiling]; + } + } + } +} + +//========================================================================== +// +// +// +//========================================================================== + +static void UpdatePlaneVertices(FFlatVertexBuffer *fvb, sector_t* sec, int plane) +{ + int startvt = sec->vboindex[plane]; + int countvt = sec->vbocount[plane]; + secplane_t& splane = sec->GetSecPlane(plane); + FFlatVertex* vt = &fvb->vbo_shadowdata[startvt]; + FFlatVertex* mapvt = fvb->GetBuffer(startvt); + for (int i = 0; i < countvt; i++, vt++, mapvt++) + { + vt->z = (float)splane.ZatPoint(vt->x, vt->y); + if (plane == sector_t::floor && sec->transdoor) vt->z -= 1; + mapvt->z = vt->z; + } +} + +//========================================================================== +// +// +// +//========================================================================== + +static void CreateVertices(FFlatVertexBuffer* fvb, TArray& sectors) +{ + fvb->vbo_shadowdata.Resize(FFlatVertexBuffer::NUM_RESERVED); + CreateIndexedFlatVertices(fvb, sectors); +} + +//========================================================================== +// +// +// +//========================================================================== + +static void CheckPlanes(FFlatVertexBuffer* fvb, sector_t* sector) +{ + if (sector->GetPlaneTexZ(sector_t::ceiling) != sector->vboheight[sector_t::ceiling]) + { + UpdatePlaneVertices(fvb, sector, sector_t::ceiling); + sector->vboheight[sector_t::ceiling] = sector->GetPlaneTexZ(sector_t::ceiling); + } + if (sector->GetPlaneTexZ(sector_t::floor) != sector->vboheight[sector_t::floor]) + { + UpdatePlaneVertices(fvb, sector, sector_t::floor); + sector->vboheight[sector_t::floor] = sector->GetPlaneTexZ(sector_t::floor); + } +} + +//========================================================================== +// +// checks the validity of all planes attached to this sector +// and updates them if possible. +// +//========================================================================== + +void CheckUpdate(FFlatVertexBuffer* fvb, sector_t* sector) +{ + CheckPlanes(fvb, sector); + sector_t* hs = sector->GetHeightSec(); + if (hs != NULL) CheckPlanes(fvb, hs); + for (unsigned i = 0; i < sector->e->XFloor.ffloors.Size(); i++) + CheckPlanes(fvb, sector->e->XFloor.ffloors[i]->model); +} + +//========================================================================== +// +// +// +//========================================================================== + +void CreateVBO(FFlatVertexBuffer* fvb, TArray& sectors) +{ + fvb->vbo_shadowdata.Resize(fvb->mNumReserved); + CreateVertices(fvb, sectors); + fvb->mCurIndex = fvb->mIndex = fvb->vbo_shadowdata.Size(); + fvb->Copy(0, fvb->mIndex); + fvb->mIndexBuffer->SetData(fvb->ibo_data.Size() * sizeof(uint32_t), &fvb->ibo_data[0]); +} diff --git a/src/rendering/hwrenderer/data/hw_vertexbuilder.h b/src/rendering/hwrenderer/data/hw_vertexbuilder.h index e13e5e7aff..4fbe9916f3 100644 --- a/src/rendering/hwrenderer/data/hw_vertexbuilder.h +++ b/src/rendering/hwrenderer/data/hw_vertexbuilder.h @@ -67,4 +67,7 @@ using VertexContainers = TArray; VertexContainers BuildVertices(TArray §ors); +class FFlatVertexBuffer; +void CheckUpdate(FFlatVertexBuffer* fvb, sector_t* sector); +void CreateVBO(FFlatVertexBuffer* fvb, TArray& sectors); diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index d2ce57e4dc..f8e7c96878 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -41,6 +41,7 @@ #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/flatvertices.h" +#include "hwrenderer/data/hw_vertexbuilder.h" #ifdef ARCH_IA32 #include @@ -628,7 +629,7 @@ void HWDrawInfo::DoSubsector(subsector_t * sub) if (sector->validcount != validcount) { - screen->mVertexData->CheckUpdate(sector); + CheckUpdate(screen->mVertexData, sector); } // [RH] Add particles From 69d724ae733e415c7eaf4e313c6a42aeee2bf04a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 12:30:36 +0200 Subject: [PATCH 104/220] - moved lightbuffers and flatvertices to 'common'. --- src/CMakeLists.txt | 4 ++-- src/{ => common}/rendering/hwrenderer/data/flatvertices.cpp | 0 src/{ => common}/rendering/hwrenderer/data/flatvertices.h | 0 .../rendering/hwrenderer/data}/hw_dynlightdata.h | 0 .../rendering/hwrenderer/data}/hw_lightbuffer.cpp | 5 ++--- .../rendering/hwrenderer/data}/hw_lightbuffer.h | 2 +- src/maploader/maploader.cpp | 2 +- src/rendering/gl/renderer/gl_postprocess.cpp | 2 +- src/rendering/gl/renderer/gl_renderer.cpp | 4 ++-- src/rendering/gl/renderer/gl_renderstate.cpp | 4 ++-- src/rendering/gl/shaders/gl_shader.cpp | 2 +- src/rendering/gl/system/gl_framebuffer.cpp | 4 ++-- src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp | 2 +- src/rendering/hwrenderer/hw_entrypoint.cpp | 6 +++--- src/rendering/hwrenderer/models/hw_models.cpp | 2 +- src/rendering/hwrenderer/scene/hw_bsp.cpp | 2 +- src/rendering/hwrenderer/scene/hw_decal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_drawinfo.cpp | 4 ++-- src/rendering/hwrenderer/scene/hw_drawlist.cpp | 2 +- src/rendering/hwrenderer/scene/hw_drawlistadd.cpp | 4 ++-- src/rendering/hwrenderer/scene/hw_flats.cpp | 6 +++--- src/rendering/hwrenderer/scene/hw_portal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_renderhacks.cpp | 6 +++--- src/rendering/hwrenderer/scene/hw_spritelight.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 6 +++--- src/rendering/hwrenderer/scene/hw_walls.cpp | 4 ++-- src/rendering/hwrenderer/scene/hw_walls_vertex.cpp | 2 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 6 +++--- src/rendering/hwrenderer/utility/hw_draw2d.cpp | 2 +- src/rendering/polyrenderer/backend/poly_framebuffer.cpp | 4 ++-- src/rendering/polyrenderer/backend/poly_renderstate.cpp | 4 ++-- src/rendering/v_framebuffer.cpp | 2 +- src/rendering/vulkan/renderer/vk_postprocess.cpp | 2 +- src/rendering/vulkan/renderer/vk_renderpass.cpp | 2 +- src/rendering/vulkan/renderer/vk_renderstate.cpp | 4 ++-- src/rendering/vulkan/system/vk_framebuffer.cpp | 4 ++-- 36 files changed, 55 insertions(+), 56 deletions(-) rename src/{ => common}/rendering/hwrenderer/data/flatvertices.cpp (100%) rename src/{ => common}/rendering/hwrenderer/data/flatvertices.h (100%) rename src/{rendering/hwrenderer/dynlights => common/rendering/hwrenderer/data}/hw_dynlightdata.h (100%) rename src/{rendering/hwrenderer/dynlights => common/rendering/hwrenderer/data}/hw_lightbuffer.cpp (96%) rename src/{rendering/hwrenderer/dynlights => common/rendering/hwrenderer/data}/hw_lightbuffer.h (94%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a0e5df984..dc82019069 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -957,10 +957,8 @@ set (PCH_SOURCES rendering/gl/textures/gl_samplers.cpp rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp - rendering/hwrenderer/data/flatvertices.cpp rendering/hwrenderer/dynlights/hw_aabbtree.cpp rendering/hwrenderer/dynlights/hw_shadowmap.cpp - rendering/hwrenderer/dynlights/hw_lightbuffer.cpp rendering/hwrenderer/models/hw_models.cpp rendering/hwrenderer/scene/hw_skydome.cpp rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -1142,9 +1140,11 @@ set (PCH_SOURCES common/objects/dobjgc.cpp common/objects/dobjtype.cpp common/rendering/r_videoscale.cpp + common/rendering/hwrenderer/data/flatvertices.cpp common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp common/rendering/hwrenderer/data/hw_cvars.cpp common/rendering/hwrenderer/data/hw_vrmodes.cpp + common/rendering/hwrenderer/data/hw_lightbuffer.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp common/rendering/gl_load/gl_interface.cpp diff --git a/src/rendering/hwrenderer/data/flatvertices.cpp b/src/common/rendering/hwrenderer/data/flatvertices.cpp similarity index 100% rename from src/rendering/hwrenderer/data/flatvertices.cpp rename to src/common/rendering/hwrenderer/data/flatvertices.cpp diff --git a/src/rendering/hwrenderer/data/flatvertices.h b/src/common/rendering/hwrenderer/data/flatvertices.h similarity index 100% rename from src/rendering/hwrenderer/data/flatvertices.h rename to src/common/rendering/hwrenderer/data/flatvertices.h diff --git a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.h b/src/common/rendering/hwrenderer/data/hw_dynlightdata.h similarity index 100% rename from src/rendering/hwrenderer/dynlights/hw_dynlightdata.h rename to src/common/rendering/hwrenderer/data/hw_dynlightdata.h diff --git a/src/rendering/hwrenderer/dynlights/hw_lightbuffer.cpp b/src/common/rendering/hwrenderer/data/hw_lightbuffer.cpp similarity index 96% rename from src/rendering/hwrenderer/dynlights/hw_lightbuffer.cpp rename to src/common/rendering/hwrenderer/data/hw_lightbuffer.cpp index 30326155f8..2783ab6695 100644 --- a/src/rendering/hwrenderer/dynlights/hw_lightbuffer.cpp +++ b/src/common/rendering/hwrenderer/data/hw_lightbuffer.cpp @@ -26,9 +26,8 @@ **/ #include "hw_lightbuffer.h" -#include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" -#include "hwrenderer/data/shaderuniforms.h" +#include "hw_dynlightdata.h" +#include "shaderuniforms.h" static const int ELEMENTS_PER_LIGHT = 4; // each light needs 4 vec4's. static const int ELEMENT_SIZE = (4*sizeof(float)); diff --git a/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h b/src/common/rendering/hwrenderer/data/hw_lightbuffer.h similarity index 94% rename from src/rendering/hwrenderer/dynlights/hw_lightbuffer.h rename to src/common/rendering/hwrenderer/data/hw_lightbuffer.h index aae08dbedf..2e5849346c 100644 --- a/src/rendering/hwrenderer/dynlights/hw_lightbuffer.h +++ b/src/common/rendering/hwrenderer/data/hw_lightbuffer.h @@ -2,7 +2,7 @@ #define __GL_LIGHTBUFFER_H #include "tarray.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hw_dynlightdata.h" #include "hwrenderer/data/buffers.h" #include #include diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 2fc70e5597..050292e5d1 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -77,7 +77,7 @@ #include "m_argv.h" #include "fragglescript/t_fs.h" #include "swrenderer/r_swrenderer.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "xlat/xlat.h" #include "vm.h" #include "texturemanager.h" diff --git a/src/rendering/gl/renderer/gl_postprocess.cpp b/src/rendering/gl/renderer/gl_postprocess.cpp index b0dfe1c3e9..b3400f2194 100644 --- a/src/rendering/gl/renderer/gl_postprocess.cpp +++ b/src/rendering/gl/renderer/gl_postprocess.cpp @@ -30,7 +30,7 @@ #include "gl/shaders/gl_shaderprogram.h" #include "hwrenderer/postprocessing/hw_postprocess.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "r_videoscale.h" #include "v_video.h" #include "templates.h" diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index eaffe1d3ca..ecaeebbc01 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -49,11 +49,11 @@ #include "gl/renderer/gl_renderbuffers.h" #include "gl/shaders/gl_shaderprogram.h" #include "hw_vrmodes.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "gl/textures/gl_samplers.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "r_videoscale.h" #include "r_data/models/models.h" diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/rendering/gl/renderer/gl_renderstate.cpp index e59265020f..34cc5ebffc 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/rendering/gl/renderer/gl_renderstate.cpp @@ -31,11 +31,11 @@ #include "gl_system.h" #include "gl_interface.h" #include "hw_cvars.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/scene/hw_skydome.h" #include "gl/shaders/gl_shader.h" #include "gl/renderer/gl_renderer.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "gl/renderer/gl_renderbuffers.h" #include "gl/textures/gl_hwtexture.h" #include "gl/system/gl_buffers.h" diff --git a/src/rendering/gl/shaders/gl_shader.cpp b/src/rendering/gl/shaders/gl_shader.cpp index 5dac1332e2..a9799638a7 100644 --- a/src/rendering/gl/shaders/gl_shader.cpp +++ b/src/rendering/gl/shaders/gl_shader.cpp @@ -38,7 +38,7 @@ #include "hwrenderer/utility/hw_shaderpatcher.h" #include "hwrenderer/data/shaderuniforms.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "gl_interface.h" #include "gl/system/gl_debug.h" diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 20b6319381..ea90b21018 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -43,14 +43,14 @@ #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/data/hw_viewpointbuffer.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "gl/shaders/gl_shaderprogram.h" #include "gl_debug.h" #include "r_videoscale.h" #include "gl_buffers.h" #include "swrenderer/r_swscene.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" EXTERN_CVAR (Bool, vid_vsync) EXTERN_CVAR(Bool, r_drawvoxels) diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp index d32d2d7a26..3bc9750f96 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp @@ -22,7 +22,7 @@ #include "hwrenderer/dynlights/hw_shadowmap.h" #include "hw_cvars.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hw_dynlightdata.h" #include "hwrenderer/data/buffers.h" #include "hwrenderer/data/shaderuniforms.h" #include "stats.h" diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index ea61d8230c..adaccd971d 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -36,11 +36,11 @@ #include "i_time.h" #include "swrenderer/r_swscene.h" #include "swrenderer/r_renderer.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hw_dynlightdata.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "hw_cvars.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/scene/hw_fakeflat.h" diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 015b8598bb..8bf1ce55e0 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -37,7 +37,7 @@ #include "cmdlib.h" #include "hw_material.h" #include "hwrenderer/data/buffers.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hw_renderstate.h" #include "hwrenderer/scene/hw_portal.h" diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index f8e7c96878..5009f37ee9 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -40,7 +40,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/data/hw_vertexbuilder.h" #ifdef ARCH_IA32 diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index 45596b1514..6dc727731e 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -35,7 +35,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/utility/hw_lighting.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hw_renderstate.h" #include "texturemanager.h" diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index d8146664fa..1335ffa8e1 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -39,8 +39,8 @@ #include "hwrenderer/utility/hw_clock.h" #include "hw_cvars.h" #include "hwrenderer/data/hw_viewpointbuffer.h" -#include "hwrenderer/data/flatvertices.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "flatvertices.h" +#include "hw_lightbuffer.h" #include "hw_vrmodes.h" #include "hw_clipper.h" diff --git a/src/rendering/hwrenderer/scene/hw_drawlist.cpp b/src/rendering/hwrenderer/scene/hw_drawlist.cpp index ae3a83e78f..18e425c9fe 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlist.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlist.cpp @@ -32,7 +32,7 @@ #include "g_levellocals.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawlist.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/utility/hw_clock.h" #include "hw_renderstate.h" #include "hw_drawinfo.h" diff --git a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp index e48326e110..a034276a43 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -20,9 +20,9 @@ //-------------------------------------------------------------------------- // -#include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hw_dynlightdata.h" #include "hw_cvars.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hw_material.h" diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index b2976527c2..f051aaa4fa 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -36,14 +36,14 @@ #include "actorinlines.h" #include "p_lnspec.h" #include "matrix.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hw_dynlightdata.h" #include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hw_material.h" #include "hwrenderer/scene/hw_drawinfo.h" -#include "hwrenderer/data/flatvertices.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "flatvertices.h" +#include "hw_lightbuffer.h" #include "hw_drawstructs.h" #include "hw_renderstate.h" #include "texturemanager.h" diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index 657159e7dd..06ae4c7e3e 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -33,7 +33,7 @@ #include "r_sky.h" #include "g_levellocals.h" #include "hw_renderstate.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "texturemanager.h" diff --git a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp index cc8a2af3e8..3835784100 100644 --- a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp @@ -36,9 +36,9 @@ #include "hw_drawinfo.h" #include "hw_drawstructs.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" -#include "hwrenderer/data/flatvertices.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_dynlightdata.h" +#include "flatvertices.h" +#include "hw_lightbuffer.h" #include "hwrenderer/scene/hw_portal.h" #include "hw_fakeflat.h" diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index b5019975f4..292a970a60 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -32,7 +32,7 @@ #include "g_level.h" #include "g_levellocals.h" #include "actorinlines.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hw_dynlightdata.h" #include "hwrenderer/dynlights/hw_shadowmap.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 00ee37e9fa..93e56cca38 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -49,13 +49,13 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hw_material.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_dynlightdata.h" +#include "hw_lightbuffer.h" #include "hw_renderstate.h" extern TArray sprites; diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index bc788fe1d4..bdc848aef3 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -32,7 +32,7 @@ #include "g_levellocals.h" #include "actorinlines.h" #include "texturemanager.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hw_dynlightdata.h" #include "hw_material.h" #include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" @@ -40,7 +40,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "hw_renderstate.h" #include "hw_skydome.h" diff --git a/src/rendering/hwrenderer/scene/hw_walls_vertex.cpp b/src/rendering/hwrenderer/scene/hw_walls_vertex.cpp index 81a2582778..751dbde64b 100644 --- a/src/rendering/hwrenderer/scene/hw_walls_vertex.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls_vertex.cpp @@ -22,7 +22,7 @@ #include "r_defs.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index debbf71bbd..acca62c9a2 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -37,14 +37,14 @@ #include "texturemanager.h" #include "hwrenderer/models/hw_models.h" -#include "hwrenderer/dynlights/hw_dynlightdata.h" +#include "hw_dynlightdata.h" #include "hw_material.h" #include "hwrenderer/utility/hw_lighting.h" #include "hw_cvars.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" -#include "hwrenderer/data/flatvertices.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "flatvertices.h" +#include "hw_lightbuffer.h" #include "hw_renderstate.h" EXTERN_CVAR(Float, transsouls) diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index 2abc5397eb..8d4df16960 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -30,7 +30,7 @@ #include "cmdlib.h" #include "r_defs.h" #include "hwrenderer/data/buffers.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/utility/hw_clock.h" #include "hw_cvars.h" diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 3eb79890b4..2398c818ef 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -38,9 +38,9 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/data/hw_viewpointbuffer.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/data/shaderuniforms.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "hwrenderer/postprocessing/hw_postprocess.h" #include "swrenderer/r_swscene.h" diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index c114c9ac30..cd13c3c48a 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -28,10 +28,10 @@ #include "r_data/colormaps.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/shaderuniforms.h" #include "swrenderer/r_swcolormaps.h" diff --git a/src/rendering/v_framebuffer.cpp b/src/rendering/v_framebuffer.cpp index 470409c9ab..bedab9d88a 100644 --- a/src/rendering/v_framebuffer.cpp +++ b/src/rendering/v_framebuffer.cpp @@ -50,7 +50,7 @@ #include "i_time.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "swrenderer/r_swscene.h" #include diff --git a/src/rendering/vulkan/renderer/vk_postprocess.cpp b/src/rendering/vulkan/renderer/vk_postprocess.cpp index 1e85705a25..b2b7d1ae4f 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.cpp +++ b/src/rendering/vulkan/renderer/vk_postprocess.cpp @@ -33,7 +33,7 @@ #include "hwrenderer/postprocessing/hw_postprocess.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" #include "hw_vrmodes.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "r_videoscale.h" #include "filesystem.h" diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/rendering/vulkan/renderer/vk_renderpass.cpp index 7567ee90fa..24a3968aa4 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/rendering/vulkan/renderer/vk_renderpass.cpp @@ -28,7 +28,7 @@ #include "vulkan/system/vk_builders.h" #include "vulkan/system/vk_framebuffer.h" #include "vulkan/system/vk_buffers.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" #include "v_2ddrawer.h" diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 55484d8946..52a458d184 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -31,10 +31,10 @@ #include "r_data/colormaps.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/shaderuniforms.h" diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 9a96f87e9a..7aca21c0ea 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -40,9 +40,9 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/data/hw_viewpointbuffer.h" -#include "hwrenderer/data/flatvertices.h" +#include "flatvertices.h" #include "hwrenderer/data/shaderuniforms.h" -#include "hwrenderer/dynlights/hw_lightbuffer.h" +#include "hw_lightbuffer.h" #include "swrenderer/r_swscene.h" From 5611fe0f4162ed7195ec3ea94d87c3723f499e05 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 13:19:57 +0200 Subject: [PATCH 105/220] - cleaned up the dependencies in the model rendering code and separated it into game-independent and game-dependent parts. --- src/CMakeLists.txt | 1 + .../hwrenderer/data/hw_modelvertexbuffer.cpp | 112 ++++++++++++++++++ .../hwrenderer/data/hw_modelvertexbuffer.h | 26 ++++ src/common/rendering/i_modelvertexbuffer.h | 43 +++++++ src/r_data/models/models.h | 46 +------ src/r_data/models/models_md2.cpp | 2 +- src/r_data/models/models_md3.cpp | 2 +- src/r_data/models/models_obj.cpp | 2 +- src/r_data/models/models_ue1.cpp | 2 +- src/r_data/models/models_voxel.cpp | 2 +- src/rendering/hwrenderer/models/hw_models.cpp | 86 +------------- src/rendering/hwrenderer/models/hw_models.h | 21 +--- 12 files changed, 197 insertions(+), 148 deletions(-) create mode 100644 src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp create mode 100644 src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.h create mode 100644 src/common/rendering/i_modelvertexbuffer.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dc82019069..9e281cbda5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1142,6 +1142,7 @@ set (PCH_SOURCES common/rendering/r_videoscale.cpp common/rendering/hwrenderer/data/flatvertices.cpp common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp + common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp common/rendering/hwrenderer/data/hw_cvars.cpp common/rendering/hwrenderer/data/hw_vrmodes.cpp common/rendering/hwrenderer/data/hw_lightbuffer.cpp diff --git a/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp b/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp new file mode 100644 index 0000000000..e4d5ba030b --- /dev/null +++ b/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp @@ -0,0 +1,112 @@ +// +//--------------------------------------------------------------------------- +// +// Copyright(C) 2005-2020 Christoph Oelckers +// All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/ +// +//-------------------------------------------------------------------------- +// +/* +** gl_models.cpp +** +** hardware renderer model handling code +** +**/ + + +#include "v_video.h" +#include "cmdlib.h" +#include "hw_modelvertexbuffer.h" + +//=========================================================================== +// +// +// +//=========================================================================== + +FModelVertexBuffer::FModelVertexBuffer(bool needindex, bool singleframe) +{ + mVertexBuffer = screen->CreateVertexBuffer(); + mIndexBuffer = needindex ? screen->CreateIndexBuffer() : nullptr; + + static const FVertexBufferAttribute format[] = { + { 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FModelVertex, x) }, + { 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FModelVertex, u) }, + { 0, VATTR_NORMAL, VFmt_Packed_A2R10G10B10, (int)myoffsetof(FModelVertex, packedNormal) }, + { 1, VATTR_VERTEX2, VFmt_Float3, (int)myoffsetof(FModelVertex, x) }, + { 1, VATTR_NORMAL2, VFmt_Packed_A2R10G10B10, (int)myoffsetof(FModelVertex, packedNormal) } + }; + mVertexBuffer->SetFormat(2, 5, sizeof(FModelVertex), format); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +FModelVertexBuffer::~FModelVertexBuffer() +{ + if (mIndexBuffer) delete mIndexBuffer; + delete mVertexBuffer; +} + +//=========================================================================== +// +// +// +//=========================================================================== + +FModelVertex *FModelVertexBuffer::LockVertexBuffer(unsigned int size) +{ + return static_cast(mVertexBuffer->Lock(size * sizeof(FModelVertex))); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void FModelVertexBuffer::UnlockVertexBuffer() +{ + mVertexBuffer->Unlock(); +} + +//=========================================================================== +// +// +// +//=========================================================================== + +unsigned int *FModelVertexBuffer::LockIndexBuffer(unsigned int size) +{ + if (mIndexBuffer) return static_cast(mIndexBuffer->Lock(size * sizeof(unsigned int))); + else return nullptr; +} + +//=========================================================================== +// +// +// +//=========================================================================== + +void FModelVertexBuffer::UnlockIndexBuffer() +{ + if (mIndexBuffer) mIndexBuffer->Unlock(); +} + + diff --git a/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.h b/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.h new file mode 100644 index 0000000000..4907637d46 --- /dev/null +++ b/src/common/rendering/hwrenderer/data/hw_modelvertexbuffer.h @@ -0,0 +1,26 @@ +#pragma once + +#include "hwrenderer/data/buffers.h" +#include "i_modelvertexbuffer.h" + +class FModelRenderer; + +class FModelVertexBuffer : public IModelVertexBuffer +{ + IVertexBuffer *mVertexBuffer; + IIndexBuffer *mIndexBuffer; + +public: + + FModelVertexBuffer(bool needindex, bool singleframe); + ~FModelVertexBuffer(); + + FModelVertex *LockVertexBuffer(unsigned int size) override; + void UnlockVertexBuffer() override; + + unsigned int *LockIndexBuffer(unsigned int size) override; + void UnlockIndexBuffer() override; + + IVertexBuffer* vertexBuffer() const { return mVertexBuffer; } + IIndexBuffer* indexBuffer() const { return mIndexBuffer; } +}; diff --git a/src/common/rendering/i_modelvertexbuffer.h b/src/common/rendering/i_modelvertexbuffer.h new file mode 100644 index 0000000000..febec3c71b --- /dev/null +++ b/src/common/rendering/i_modelvertexbuffer.h @@ -0,0 +1,43 @@ +#pragma once + +#include "templates.h" + +struct FModelVertex +{ + float x, y, z; // world position + float u, v; // texture coordinates + unsigned packedNormal; // normal vector as GL_INT_2_10_10_10_REV. + + void Set(float xx, float yy, float zz, float uu, float vv) + { + x = xx; + y = yy; + z = zz; + u = uu; + v = vv; + } + + void SetNormal(float nx, float ny, float nz) + { + int inx = clamp(int(nx * 512), -512, 511); + int iny = clamp(int(ny * 512), -512, 511); + int inz = clamp(int(nz * 512), -512, 511); + int inw = 0; + packedNormal = (inw << 30) | ((inz & 1023) << 20) | ((iny & 1023) << 10) | (inx & 1023); + } +}; + +#define VMO ((FModelVertex*)nullptr) + +class IModelVertexBuffer +{ +public: + virtual ~IModelVertexBuffer() { } + + virtual FModelVertex *LockVertexBuffer(unsigned int size) = 0; + virtual void UnlockVertexBuffer() = 0; + + virtual unsigned int *LockIndexBuffer(unsigned int size) = 0; + virtual void UnlockIndexBuffer() = 0; +}; + diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index e6c30323fb..33e9056deb 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -31,6 +31,7 @@ #include "r_data/voxels.h" #include "info.h" #include "g_levellocals.h" +#include "i_modelvertexbuffer.h" #define MAX_LODS 4 @@ -47,6 +48,7 @@ FTextureID LoadSkin(const char * path, const char * fn); struct FSpriteModelFrame; class IModelVertexBuffer; struct FLevelLocals; +class FModel; enum ModelRendererType { @@ -80,54 +82,12 @@ public: virtual void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) = 0; virtual void DrawArrays(int start, int count) = 0; virtual void DrawElements(int numIndices, size_t offset) = 0; + virtual void SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) = 0; private: void RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation); }; -struct FModelVertex -{ - float x, y, z; // world position - float u, v; // texture coordinates - unsigned packedNormal; // normal vector as GL_INT_2_10_10_10_REV. - - void Set(float xx, float yy, float zz, float uu, float vv) - { - x = xx; - y = yy; - z = zz; - u = uu; - v = vv; - } - - void SetNormal(float nx, float ny, float nz) - { - int inx = clamp(int(nx * 512), -512, 511); - int iny = clamp(int(ny * 512), -512, 511); - int inz = clamp(int(nz * 512), -512, 511); - int inw = 0; - packedNormal = (inw << 30) | ((inz & 1023) << 20) | ((iny & 1023) << 10) | (inx & 1023); - } -}; - -#define VMO ((FModelVertex*)NULL) - -class FModelRenderer; - -class IModelVertexBuffer -{ -public: - virtual ~IModelVertexBuffer() { } - - virtual FModelVertex *LockVertexBuffer(unsigned int size) = 0; - virtual void UnlockVertexBuffer() = 0; - - virtual unsigned int *LockIndexBuffer(unsigned int size) = 0; - virtual void UnlockIndexBuffer() = 0; - - virtual void SetupFrame(FModelRenderer *renderer, unsigned int frame1, unsigned int frame2, unsigned int size) = 0; -}; - class FModel { public: diff --git a/src/r_data/models/models_md2.cpp b/src/r_data/models/models_md2.cpp index 31387f000a..f4142ea631 100644 --- a/src/r_data/models/models_md2.cpp +++ b/src/r_data/models/models_md2.cpp @@ -371,7 +371,7 @@ void FDMDModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f renderer->SetInterpolation(inter); renderer->SetMaterial(skin, false, translation); - GetVertexBuffer(renderer)->SetupFrame(renderer, frames[frameno].vindex, frames[frameno2].vindex, lodInfo[0].numTriangles * 3); + renderer->SetupFrame(this, frames[frameno].vindex, frames[frameno2].vindex, lodInfo[0].numTriangles * 3); renderer->DrawArrays(0, lodInfo[0].numTriangles * 3); renderer->SetInterpolation(0.f); } diff --git a/src/r_data/models/models_md3.cpp b/src/r_data/models/models_md3.cpp index b37b3df36f..42e2fd4963 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/r_data/models/models_md3.cpp @@ -372,7 +372,7 @@ void FMD3Model::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f } renderer->SetMaterial(surfaceSkin, false, translation); - GetVertexBuffer(renderer)->SetupFrame(renderer, surf->vindex + frameno * surf->numVertices, surf->vindex + frameno2 * surf->numVertices, surf->numVertices); + renderer->SetupFrame(this, surf->vindex + frameno * surf->numVertices, surf->vindex + frameno2 * surf->numVertices, surf->numVertices); renderer->DrawElements(surf->numTriangles * 3, surf->iindex * sizeof(unsigned int)); } renderer->SetInterpolation(0.f); diff --git a/src/r_data/models/models_obj.cpp b/src/r_data/models/models_obj.cpp index 67c1106357..7028ca22b7 100644 --- a/src/r_data/models/models_obj.cpp +++ b/src/r_data/models/models_obj.cpp @@ -652,7 +652,7 @@ void FOBJModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int f } renderer->SetMaterial(userSkin, false, translation); - GetVertexBuffer(renderer)->SetupFrame(renderer, surf->vbStart, surf->vbStart, surf->numTris * 3); + renderer->SetupFrame(this, surf->vbStart, surf->vbStart, surf->numTris * 3); renderer->DrawArrays(0, surf->numTris * 3); } } diff --git a/src/r_data/models/models_ue1.cpp b/src/r_data/models/models_ue1.cpp index 7d53798916..8ee05b9db9 100644 --- a/src/r_data/models/models_ue1.cpp +++ b/src/r_data/models/models_ue1.cpp @@ -246,7 +246,7 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int f // TODO: Handle per-group render styles and other flags once functions for it are implemented // Future note: poly renderstyles should always be enforced unless the actor itself has a style other than Normal renderer->SetMaterial(sskin,false,translation); - GetVertexBuffer(renderer)->SetupFrame(renderer,vofs+frame*fsize,vofs+frame2*fsize,vsize); + renderer->SetupFrame(this, vofs+frame*fsize,vofs+frame2*fsize,vsize); renderer->DrawArrays(0,vsize); vofs += vsize; } diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index cfa65f4b3a..5eedc08660 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -398,7 +398,7 @@ float FVoxelModel::getAspectFactor(FLevelLocals *Level) void FVoxelModel::RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation) { renderer->SetMaterial(skin, true, translation); - GetVertexBuffer(renderer)->SetupFrame(renderer, 0, 0, 0); + renderer->SetupFrame(this, 0, 0, 0); renderer->DrawElements(mNumIndices, 0); } diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 8bf1ce55e0..20d2386d58 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -134,88 +134,10 @@ void FHWModelRenderer::DrawElements(int numIndices, size_t offset) // //=========================================================================== -FModelVertexBuffer::FModelVertexBuffer(bool needindex, bool singleframe) +void FHWModelRenderer::SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) { - mVertexBuffer = screen->CreateVertexBuffer(); - mIndexBuffer = needindex ? screen->CreateIndexBuffer() : nullptr; - - static const FVertexBufferAttribute format[] = { - { 0, VATTR_VERTEX, VFmt_Float3, (int)myoffsetof(FModelVertex, x) }, - { 0, VATTR_TEXCOORD, VFmt_Float2, (int)myoffsetof(FModelVertex, u) }, - { 0, VATTR_NORMAL, VFmt_Packed_A2R10G10B10, (int)myoffsetof(FModelVertex, packedNormal) }, - { 1, VATTR_VERTEX2, VFmt_Float3, (int)myoffsetof(FModelVertex, x) }, - { 1, VATTR_NORMAL2, VFmt_Packed_A2R10G10B10, (int)myoffsetof(FModelVertex, packedNormal) } - }; - mVertexBuffer->SetFormat(2, 5, sizeof(FModelVertex), format); + auto mdbuff = static_cast(model->GetVertexBuffer(this)); + state.SetVertexBuffer(mdbuff->vertexBuffer(), frame1, frame2); + if (mdbuff->indexBuffer()) state.SetIndexBuffer(mdbuff->indexBuffer()); } -//=========================================================================== -// -// -// -//=========================================================================== - -FModelVertexBuffer::~FModelVertexBuffer() -{ - if (mIndexBuffer) delete mIndexBuffer; - delete mVertexBuffer; -} - -//=========================================================================== -// -// -// -//=========================================================================== - -FModelVertex *FModelVertexBuffer::LockVertexBuffer(unsigned int size) -{ - return static_cast(mVertexBuffer->Lock(size * sizeof(FModelVertex))); -} - -//=========================================================================== -// -// -// -//=========================================================================== - -void FModelVertexBuffer::UnlockVertexBuffer() -{ - mVertexBuffer->Unlock(); -} - -//=========================================================================== -// -// -// -//=========================================================================== - -unsigned int *FModelVertexBuffer::LockIndexBuffer(unsigned int size) -{ - if (mIndexBuffer) return static_cast(mIndexBuffer->Lock(size * sizeof(unsigned int))); - else return nullptr; -} - -//=========================================================================== -// -// -// -//=========================================================================== - -void FModelVertexBuffer::UnlockIndexBuffer() -{ - if (mIndexBuffer) mIndexBuffer->Unlock(); -} - - -//=========================================================================== -// -// -// -//=========================================================================== - -void FModelVertexBuffer::SetupFrame(FModelRenderer *renderer, unsigned int frame1, unsigned int frame2, unsigned int size) -{ - auto &state = static_cast(renderer)->state; - state.SetVertexBuffer(mVertexBuffer, frame1, frame2); - if (mIndexBuffer) state.SetIndexBuffer(mIndexBuffer); -} diff --git a/src/rendering/hwrenderer/models/hw_models.h b/src/rendering/hwrenderer/models/hw_models.h index efe1e18698..5644ab09df 100644 --- a/src/rendering/hwrenderer/models/hw_models.h +++ b/src/rendering/hwrenderer/models/hw_models.h @@ -27,29 +27,12 @@ #include "r_data/voxels.h" #include "r_data/models/models.h" #include "hwrenderer/data/buffers.h" +#include "hw_modelvertexbuffer.h" class HWSprite; struct HWDrawInfo; class FRenderState; -class FModelVertexBuffer : public IModelVertexBuffer -{ - IVertexBuffer *mVertexBuffer; - IIndexBuffer *mIndexBuffer; - -public: - - FModelVertexBuffer(bool needindex, bool singleframe); - ~FModelVertexBuffer(); - - FModelVertex *LockVertexBuffer(unsigned int size) override; - void UnlockVertexBuffer() override; - - unsigned int *LockIndexBuffer(unsigned int size) override; - void UnlockIndexBuffer() override; - - void SetupFrame(FModelRenderer *renderer, unsigned int frame1, unsigned int frame2, unsigned int size) override; -}; class FHWModelRenderer : public FModelRenderer { @@ -71,5 +54,7 @@ public: void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) override; void DrawArrays(int start, int count) override; void DrawElements(int numIndices, size_t offset) override; + void SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) override; + }; From 763e9e0f35db08a962163dd1324e62161fa4dff8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 13:48:51 +0200 Subject: [PATCH 106/220] - fixed texture scaling setup in a few places. --- src/common/textures/gametexture.h | 5 +++-- src/common/textures/hires/hqresize.cpp | 2 +- src/common/textures/multipatchtexturebuilder.cpp | 1 - src/common/textures/texturemanager.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index e34ce09491..3b2b690293 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -206,6 +206,7 @@ public: void CopySize(FGameTexture* BaseTexture) { Base->CopySize(BaseTexture->Base.get()); + SetDisplaySize(BaseTexture->GetDisplayWidth(), BaseTexture->GetDisplayHeight()); } // Glowing is a pure material property that should not filter down to the actual texture objects. @@ -248,8 +249,8 @@ public: { ScaleX = x; ScaleY = y; - DisplayWidth = x * TexelWidth; - DisplayHeight = y * TexelHeight; + DisplayWidth = TexelWidth / x; + DisplayHeight = TexelHeight / y; } const SpritePositioningInfo& GetSpritePositioning(int which) { if (spi == nullptr) SetupSpriteData(); return spi[which]; } diff --git a/src/common/textures/hires/hqresize.cpp b/src/common/textures/hires/hqresize.cpp index 2e7b2fb068..fe5beda4e3 100644 --- a/src/common/textures/hires/hqresize.cpp +++ b/src/common/textures/hires/hqresize.cpp @@ -514,7 +514,7 @@ int calcShouldUpscale(FGameTexture *tex) return 0; // already scaled? - if (tex->GetDisplayWidth() >= 2* tex->GetTexelWidth() || tex->GetDisplayHeight() >= 2*tex->GetTexelHeight()) + if (tex->GetScaleX() >= 2.f || tex->GetScaleY() > 2.f) return 0; return CTF_Upscale; diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index d95c681dcd..1ee3634930 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -901,7 +901,6 @@ void FMultipatchTextureBuilder::ResolveAllPatches() !buildinfo.bComplex) { AddImageToTexture(buildinfo.Parts[0].TexImage, buildinfo); - buildinfo.texture->Setup(buildinfo.Parts[0].TexImage); done = true; } } diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index c7cffd07cd..80458a6ab8 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -625,8 +625,8 @@ void FTextureManager::AddHiresTextures (int wadnum) auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override); gtex->SetWorldPanning(true); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); - gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); - gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY())); + gtex->SetOffsets(0, oldtex->GetTexelLeftOffset(0), oldtex->GetTexelTopOffset(0)); + gtex->SetOffsets(1, oldtex->GetTexelLeftOffset(1), oldtex->GetTexelTopOffset(1)); ReplaceTexture(tlist[i], gtex, true); } } From 02832297ff2429d7614c1d0a8b05e77a7addb4e1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 14:44:19 +0200 Subject: [PATCH 107/220] - moved most of the OpenGL backend to 'common'. A few things are yet to do, because they still need some changes. --- src/CMakeLists.txt | 22 ++-- .../rendering/gl}/gl_buffers.cpp | 60 +++++---- .../rendering/gl}/gl_buffers.h | 8 +- .../rendering/gl}/gl_debug.cpp | 43 +++---- .../system => common/rendering/gl}/gl_debug.h | 1 - .../rendering/gl}/gl_hwtexture.cpp | 8 +- .../rendering/gl}/gl_hwtexture.h | 0 .../rendering/gl}/gl_postprocess.cpp | 8 +- .../rendering/gl}/gl_postprocessstate.cpp | 2 +- .../rendering/gl}/gl_postprocessstate.h | 0 .../rendering/gl}/gl_renderbuffers.cpp | 8 +- .../rendering/gl}/gl_renderbuffers.h | 0 .../rendering/gl}/gl_renderstate.cpp | 6 +- .../rendering/gl}/gl_renderstate.h | 0 .../rendering/gl}/gl_samplers.cpp | 2 +- .../rendering/gl}/gl_samplers.h | 0 src/g_game.h | 2 - src/rendering/gl/renderer/gl_renderer.cpp | 118 ++++++------------ src/rendering/gl/renderer/gl_renderer.h | 4 +- src/rendering/gl/renderer/gl_stereo3d.cpp | 6 +- src/rendering/gl/shaders/gl_shader.cpp | 2 +- src/rendering/gl/shaders/gl_shader.h | 2 +- src/rendering/gl/shaders/gl_shaderprogram.cpp | 44 +++---- src/rendering/gl/system/gl_framebuffer.cpp | 86 +++++++++---- .../vulkan/system/vk_framebuffer.cpp | 1 + src/version.h | 3 + 26 files changed, 216 insertions(+), 220 deletions(-) rename src/{rendering/gl/system => common/rendering/gl}/gl_buffers.cpp (71%) rename src/{rendering/gl/system => common/rendering/gl}/gl_buffers.h (85%) rename src/{rendering/gl/system => common/rendering/gl}/gl_debug.cpp (90%) rename src/{rendering/gl/system => common/rendering/gl}/gl_debug.h (98%) rename src/{rendering/gl/textures => common/rendering/gl}/gl_hwtexture.cpp (98%) rename src/{rendering/gl/textures => common/rendering/gl}/gl_hwtexture.h (100%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_postprocess.cpp (98%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_postprocessstate.cpp (98%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_postprocessstate.h (100%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_renderbuffers.cpp (99%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_renderbuffers.h (100%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_renderstate.cpp (99%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_renderstate.h (100%) rename src/{rendering/gl/textures => common/rendering/gl}/gl_samplers.cpp (99%) rename src/{rendering/gl/textures => common/rendering/gl}/gl_samplers.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9e281cbda5..2f6e1d2a8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -659,13 +659,9 @@ file( GLOB HEADER_FILES rendering/vulkan/renderer/*.h rendering/vulkan/shaders/*.h rendering/vulkan/textures/*.h - rendering/gl/*.h - rendering/gl/models/*.h rendering/gl/renderer/*.h - rendering/gl/scene/*.h rendering/gl/shaders/*.h rendering/gl/system/*.h - rendering/gl/textures/*.h *.h ) @@ -943,18 +939,10 @@ set (PCH_SOURCES rendering/2d/f_wipe.cpp rendering/2d/v_blend.cpp rendering/gl/renderer/gl_renderer.cpp - rendering/gl/renderer/gl_renderstate.cpp - rendering/gl/renderer/gl_renderbuffers.cpp - rendering/gl/renderer/gl_postprocess.cpp - rendering/gl/renderer/gl_postprocessstate.cpp rendering/gl/renderer/gl_stereo3d.cpp rendering/gl/shaders/gl_shader.cpp rendering/gl/shaders/gl_shaderprogram.cpp rendering/gl/system/gl_framebuffer.cpp - rendering/gl/system/gl_debug.cpp - rendering/gl/system/gl_buffers.cpp - rendering/gl/textures/gl_hwtexture.cpp - rendering/gl/textures/gl_samplers.cpp rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp rendering/hwrenderer/dynlights/hw_aabbtree.cpp @@ -1149,6 +1137,14 @@ set (PCH_SOURCES common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp common/rendering/gl_load/gl_interface.cpp + common/rendering/gl/gl_renderstate.cpp + common/rendering/gl/gl_renderbuffers.cpp + common/rendering/gl/gl_postprocess.cpp + common/rendering/gl/gl_postprocessstate.cpp + common/rendering/gl/gl_debug.cpp + common/rendering/gl/gl_buffers.cpp + common/rendering/gl/gl_hwtexture.cpp + common/rendering/gl/gl_samplers.cpp common/scripting/core/dictionary.cpp common/scripting/core/dynarrays.cpp common/scripting/core/symbols.cpp @@ -1260,6 +1256,7 @@ include_directories( . common/rendering common/rendering/hwrenderer/data common/rendering/gl_load + common/rendering/gl common/scripting/vm common/scripting/jit common/scripting/core @@ -1479,6 +1476,7 @@ source_group("Common\\Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE source_group("Common\\Rendering\\Hardware Renderer\\Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/data/.+") source_group("Common\\Rendering\\Hardware Renderer\\Postprocessing" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/postprocessing/.+") source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+") +source_group("Common\\Rendering\\OpenGL Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl/.+") source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+") source_group("Common\\Textures\\Hires" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/.+") source_group("Common\\Textures\\Hires\\HQ Resize" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/hqnx/.+") diff --git a/src/rendering/gl/system/gl_buffers.cpp b/src/common/rendering/gl/gl_buffers.cpp similarity index 71% rename from src/rendering/gl/system/gl_buffers.cpp rename to src/common/rendering/gl/gl_buffers.cpp index 702aae2db1..1f88195bf3 100644 --- a/src/rendering/gl/system/gl_buffers.cpp +++ b/src/common/rendering/gl/gl_buffers.cpp @@ -1,32 +1,41 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2018 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* +** gl_buffers.cpp ** Low level vertex buffer class ** +**--------------------------------------------------------------------------- +** Copyright 2018-2020 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** **/ -#include "gl_system.h" +#include +#include "gl_load.h" #include "gl_buffers.h" -#include "gl/renderer/gl_renderstate.h" +#include "gl_renderstate.h" #include "v_video.h" namespace OpenGLRenderer @@ -220,4 +229,9 @@ void GLDataBuffer::BindBase() glBindBufferBase(mUseType, mBindingPoint, mBufferId); } + +GLVertexBuffer::GLVertexBuffer() : GLBuffer(GL_ARRAY_BUFFER) {} +GLIndexBuffer::GLIndexBuffer() : GLBuffer(GL_ELEMENT_ARRAY_BUFFER) {} +GLDataBuffer::GLDataBuffer(int bindingpoint, bool is_ssbo) : GLBuffer(is_ssbo ? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER), mBindingPoint(bindingpoint) {} + } \ No newline at end of file diff --git a/src/rendering/gl/system/gl_buffers.h b/src/common/rendering/gl/gl_buffers.h similarity index 85% rename from src/rendering/gl/system/gl_buffers.h rename to src/common/rendering/gl/gl_buffers.h index a9e44061d8..950556ff9f 100644 --- a/src/rendering/gl/system/gl_buffers.h +++ b/src/common/rendering/gl/gl_buffers.h @@ -1,6 +1,6 @@ #pragma once -#include "hwrenderer/data/buffers.h" +#include "buffers.h" #ifdef _MSC_VER // silence bogus warning C4250: 'GLVertexBuffer': inherits 'GLBuffer::GLBuffer::SetData' via dominance @@ -50,7 +50,7 @@ class GLVertexBuffer : public IVertexBuffer, public GLBuffer size_t mStride = 0; public: - GLVertexBuffer() : GLBuffer(GL_ARRAY_BUFFER) {} + GLVertexBuffer(); void SetFormat(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute *attrs) override; void Bind(int *offsets); }; @@ -58,14 +58,14 @@ public: class GLIndexBuffer : public IIndexBuffer, public GLBuffer { public: - GLIndexBuffer() : GLBuffer(GL_ELEMENT_ARRAY_BUFFER) {} + GLIndexBuffer(); }; class GLDataBuffer : public IDataBuffer, public GLBuffer { int mBindingPoint; public: - GLDataBuffer(int bindingpoint, bool is_ssbo) : GLBuffer(is_ssbo? GL_SHADER_STORAGE_BUFFER : GL_UNIFORM_BUFFER), mBindingPoint(bindingpoint) {} + GLDataBuffer(int bindingpoint, bool is_ssbo); void BindRange(FRenderState* state, size_t start, size_t length); void BindBase(); }; diff --git a/src/rendering/gl/system/gl_debug.cpp b/src/common/rendering/gl/gl_debug.cpp similarity index 90% rename from src/rendering/gl/system/gl_debug.cpp rename to src/common/rendering/gl/gl_debug.cpp index 5c65814f77..c6c3adbfc9 100644 --- a/src/rendering/gl/system/gl_debug.cpp +++ b/src/common/rendering/gl/gl_debug.cpp @@ -1,34 +1,29 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2016 Magnus Norddahl -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* -** gl_debig.cpp -** OpenGL debugging support functions +** OpenGL debugging support functions +** Copyright (c) 2016-2020 Magnus Norddahl ** +** This software is provided 'as-is', without any express or implied +** warranty. In no event will the authors be held liable for any damages +** arising from the use of this software. +** +** Permission is granted to anyone to use this software for any purpose, +** including commercial applications, and to alter it and redistribute it +** freely, subject to the following restrictions: +** +** 1. The origin of this software must not be misrepresented; you must not +** claim that you wrote the original software. If you use this software +** in a product, an acknowledgment in the product documentation would be +** appreciated but is not required. +** 2. Altered source versions must be plainly marked as such, and must not be +** misrepresented as being the original software. +** 3. This notice may not be removed or altered from any source distribution. */ #include "templates.h" #include "gl_system.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "stats.h" +#include "printf.h" #include #include #include diff --git a/src/rendering/gl/system/gl_debug.h b/src/common/rendering/gl/gl_debug.h similarity index 98% rename from src/rendering/gl/system/gl_debug.h rename to src/common/rendering/gl/gl_debug.h index 03c10c67e3..e9d64a110a 100644 --- a/src/rendering/gl/system/gl_debug.h +++ b/src/common/rendering/gl/gl_debug.h @@ -4,7 +4,6 @@ #include #include "gl_interface.h" #include "c_cvars.h" -#include "r_defs.h" #include "v_video.h" namespace OpenGLRenderer diff --git a/src/rendering/gl/textures/gl_hwtexture.cpp b/src/common/rendering/gl/gl_hwtexture.cpp similarity index 98% rename from src/rendering/gl/textures/gl_hwtexture.cpp rename to src/common/rendering/gl/gl_hwtexture.cpp index 2f807a5d66..3aa4aad79a 100644 --- a/src/rendering/gl/textures/gl_hwtexture.cpp +++ b/src/common/rendering/gl/gl_hwtexture.cpp @@ -36,16 +36,14 @@ #include "gl_system.h" #include "templates.h" #include "c_cvars.h" -#include "doomtype.h" -#include "r_data/colormaps.h" #include "hw_material.h" #include "gl_interface.h" #include "hw_cvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_renderstate.h" -#include "gl/textures/gl_samplers.h" +#include "gl_renderstate.h" +#include "gl_samplers.h" namespace OpenGLRenderer { diff --git a/src/rendering/gl/textures/gl_hwtexture.h b/src/common/rendering/gl/gl_hwtexture.h similarity index 100% rename from src/rendering/gl/textures/gl_hwtexture.h rename to src/common/rendering/gl/gl_hwtexture.h diff --git a/src/rendering/gl/renderer/gl_postprocess.cpp b/src/common/rendering/gl/gl_postprocess.cpp similarity index 98% rename from src/rendering/gl/renderer/gl_postprocess.cpp rename to src/common/rendering/gl/gl_postprocess.cpp index b3400f2194..90b7cf335c 100644 --- a/src/rendering/gl/renderer/gl_postprocess.cpp +++ b/src/common/rendering/gl/gl_postprocess.cpp @@ -21,12 +21,12 @@ #include "gl_system.h" #include "m_png.h" -#include "gl/system/gl_buffers.h" +#include "gl_buffers.h" #include "gl/system/gl_framebuffer.h" -#include "gl/system/gl_debug.h" -#include "gl/renderer/gl_renderbuffers.h" +#include "gl_debug.h" +#include "gl_renderbuffers.h" #include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_postprocessstate.h" +#include "gl_postprocessstate.h" #include "gl/shaders/gl_shaderprogram.h" #include "hwrenderer/postprocessing/hw_postprocess.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" diff --git a/src/rendering/gl/renderer/gl_postprocessstate.cpp b/src/common/rendering/gl/gl_postprocessstate.cpp similarity index 98% rename from src/rendering/gl/renderer/gl_postprocessstate.cpp rename to src/common/rendering/gl/gl_postprocessstate.cpp index 095aa24fe0..2e6a04f050 100644 --- a/src/rendering/gl/renderer/gl_postprocessstate.cpp +++ b/src/common/rendering/gl/gl_postprocessstate.cpp @@ -22,7 +22,7 @@ #include "templates.h" #include "gl_system.h" #include "gl_interface.h" -#include "gl/renderer/gl_postprocessstate.h" +#include "gl_postprocessstate.h" namespace OpenGLRenderer { diff --git a/src/rendering/gl/renderer/gl_postprocessstate.h b/src/common/rendering/gl/gl_postprocessstate.h similarity index 100% rename from src/rendering/gl/renderer/gl_postprocessstate.h rename to src/common/rendering/gl/gl_postprocessstate.h diff --git a/src/rendering/gl/renderer/gl_renderbuffers.cpp b/src/common/rendering/gl/gl_renderbuffers.cpp similarity index 99% rename from src/rendering/gl/renderer/gl_renderbuffers.cpp rename to src/common/rendering/gl/gl_renderbuffers.cpp index b6e1000fdd..3cec2c9370 100644 --- a/src/rendering/gl/renderer/gl_renderbuffers.cpp +++ b/src/common/rendering/gl/gl_renderbuffers.cpp @@ -24,12 +24,12 @@ #include "gl_interface.h" #include "printf.h" #include "hw_cvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_renderbuffers.h" -#include "gl/renderer/gl_postprocessstate.h" +#include "gl_renderbuffers.h" +#include "gl_postprocessstate.h" #include "gl/shaders/gl_shaderprogram.h" -#include "gl/system/gl_buffers.h" +#include "gl_buffers.h" #include "templates.h" #include diff --git a/src/rendering/gl/renderer/gl_renderbuffers.h b/src/common/rendering/gl/gl_renderbuffers.h similarity index 100% rename from src/rendering/gl/renderer/gl_renderbuffers.h rename to src/common/rendering/gl/gl_renderbuffers.h diff --git a/src/rendering/gl/renderer/gl_renderstate.cpp b/src/common/rendering/gl/gl_renderstate.cpp similarity index 99% rename from src/rendering/gl/renderer/gl_renderstate.cpp rename to src/common/rendering/gl/gl_renderstate.cpp index 34cc5ebffc..8de101c2f8 100644 --- a/src/rendering/gl/renderer/gl_renderstate.cpp +++ b/src/common/rendering/gl/gl_renderstate.cpp @@ -36,9 +36,9 @@ #include "gl/shaders/gl_shader.h" #include "gl/renderer/gl_renderer.h" #include "hw_lightbuffer.h" -#include "gl/renderer/gl_renderbuffers.h" -#include "gl/textures/gl_hwtexture.h" -#include "gl/system/gl_buffers.h" +#include "gl_renderbuffers.h" +#include "gl_hwtexture.h" +#include "gl_buffers.h" #include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/data/hw_viewpointbuffer.h" diff --git a/src/rendering/gl/renderer/gl_renderstate.h b/src/common/rendering/gl/gl_renderstate.h similarity index 100% rename from src/rendering/gl/renderer/gl_renderstate.h rename to src/common/rendering/gl/gl_renderstate.h diff --git a/src/rendering/gl/textures/gl_samplers.cpp b/src/common/rendering/gl/gl_samplers.cpp similarity index 99% rename from src/rendering/gl/textures/gl_samplers.cpp rename to src/common/rendering/gl/gl_samplers.cpp index 39d8146d72..12be63e43d 100644 --- a/src/rendering/gl/textures/gl_samplers.cpp +++ b/src/common/rendering/gl/gl_samplers.cpp @@ -37,7 +37,7 @@ #include "gl_interface.h" #include "hw_cvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "gl/renderer/gl_renderer.h" #include "gl_samplers.h" #include "hw_material.h" diff --git a/src/rendering/gl/textures/gl_samplers.h b/src/common/rendering/gl/gl_samplers.h similarity index 100% rename from src/rendering/gl/textures/gl_samplers.h rename to src/common/rendering/gl/gl_samplers.h diff --git a/src/g_game.h b/src/g_game.h index 4edd33c588..0a86c29163 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -109,7 +109,5 @@ FBaseCVar* G_GetUserCVar(int playernum, const char* cvarname); extern const AActor *SendItemUse, *SendItemDrop; extern int SendItemDropAmount; -const int SAVEPICWIDTH = 216; -const int SAVEPICHEIGHT = 162; #endif diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index ecaeebbc01..3562714660 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -1,28 +1,35 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2005-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* -** gl1_renderer.cpp +** gl_renderer.cpp ** Renderer interface ** +**--------------------------------------------------------------------------- +** Copyright 2005-2020 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** */ #include "gl_system.h" @@ -36,6 +43,7 @@ #include "d_player.h" #include "a_dynlight.h" #include "cmdlib.h" +#include "version.h" #include "g_game.h" #include "swrenderer/r_swscene.h" #include "hwrenderer/utility/hw_clock.h" @@ -43,22 +51,22 @@ #include "gl_interface.h" #include "gl/system/gl_framebuffer.h" #include "hw_cvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_renderstate.h" -#include "gl/renderer/gl_renderbuffers.h" +#include "gl_renderstate.h" +#include "gl_renderbuffers.h" #include "gl/shaders/gl_shaderprogram.h" #include "hw_vrmodes.h" #include "flatvertices.h" #include "hwrenderer/scene/hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" -#include "gl/textures/gl_samplers.h" +#include "gl_samplers.h" #include "hw_lightbuffer.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "r_videoscale.h" #include "r_data/models/models.h" -#include "gl/renderer/gl_postprocessstate.h" -#include "gl/system/gl_buffers.h" +#include "gl_postprocessstate.h" +#include "gl_buffers.h" #include "texturemanager.h" EXTERN_CVAR(Int, screenblocks) @@ -95,8 +103,6 @@ void FGLRenderer::Initialize(int width, int height) mShadowMapShader = new FShadowMapShader(); // needed for the core profile, because someone decided it was a good idea to remove the default VAO. - glGenQueries(1, &PortalQueryObject); - glGenVertexArrays(1, &mVAOID); glBindVertexArray(mVAOID); FGLDebug::LabelObject(GL_VERTEX_ARRAY, mVAOID, "FGLRenderer.mVAOID"); @@ -120,8 +126,6 @@ FGLRenderer::~FGLRenderer() glBindVertexArray(0); glDeleteVertexArrays(1, &mVAOID); } - if (PortalQueryObject != 0) glDeleteQueries(1, &PortalQueryObject); - if (mBuffers) delete mBuffers; if (mSaveBuffers) delete mSaveBuffers; if (mPresentShader) delete mPresentShader; @@ -160,44 +164,6 @@ void FGLRenderer::EndOffscreen() glBindFramebuffer(GL_FRAMEBUFFER, mOldFBID); } -//=========================================================================== -// -// -// -//=========================================================================== - -void FGLRenderer::UpdateShadowMap() -{ - if (screen->mShadowMap.PerformUpdate()) - { - FGLDebug::PushGroup("ShadowMap"); - - FGLPostProcessState savedState; - - static_cast(screen->mShadowMap.mLightList)->BindBase(); - static_cast(screen->mShadowMap.mNodesBuffer)->BindBase(); - static_cast(screen->mShadowMap.mLinesBuffer)->BindBase(); - - mBuffers->BindShadowMapFB(); - - mShadowMapShader->Bind(); - mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality; - mShadowMapShader->Uniforms->NodesCount = screen->mShadowMap.NodesCount(); - mShadowMapShader->Uniforms.SetData(); - static_cast(mShadowMapShader->Uniforms.GetBuffer())->BindBase(); - - glViewport(0, 0, gl_shadowmap_quality, 1024); - RenderScreenQuad(); - - const auto &viewport = screen->mScreenViewport; - glViewport(viewport.left, viewport.top, viewport.width, viewport.height); - - mBuffers->BindShadowMapTexture(16); - FGLDebug::PopGroup(); - screen->mShadowMap.FinishUpdate(); - } -} - //=========================================================================== // // @@ -207,14 +173,10 @@ void FGLRenderer::UpdateShadowMap() void FGLRenderer::BindToFrameBuffer(FTexture *tex) { auto BaseLayer = static_cast(tex->GetHardwareTexture(0, 0)); - - if (BaseLayer == nullptr) - { - // must create the hardware texture first - BaseLayer->BindOrCreate(tex, 0, 0, 0, 0); - FHardwareTexture::Unbind(0); - gl_RenderState.ClearLastMaterial(); - } + // must create the hardware texture first + BaseLayer->BindOrCreate(tex, 0, 0, 0, 0); + FHardwareTexture::Unbind(0); + gl_RenderState.ClearLastMaterial(); BaseLayer->BindToFrameBuffer(tex->GetWidth(), tex->GetHeight()); } diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index ab260563dc..ab4e36459b 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -6,7 +6,7 @@ #include "vectors.h" #include "swrenderer/r_renderer.h" #include "matrix.h" -#include "gl/renderer/gl_renderbuffers.h" +#include "gl_renderbuffers.h" #include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/dynlights/hw_shadowmap.h" #include @@ -52,7 +52,6 @@ public: FSamplerManager *mSamplerManager = nullptr; unsigned int mFBID; unsigned int mVAOID; - unsigned int PortalQueryObject; unsigned int mStencilValue = 0; int mOldFBID; @@ -89,7 +88,6 @@ public: bool StartOffscreen(); void EndOffscreen(); - void UpdateShadowMap(); void BindToFrameBuffer(FTexture *mat); diff --git a/src/rendering/gl/renderer/gl_stereo3d.cpp b/src/rendering/gl/renderer/gl_stereo3d.cpp index 6df5ee69e0..df6cb11ce3 100644 --- a/src/rendering/gl/renderer/gl_stereo3d.cpp +++ b/src/rendering/gl/renderer/gl_stereo3d.cpp @@ -27,13 +27,13 @@ #include "gl_system.h" #include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_renderbuffers.h" +#include "gl_renderbuffers.h" #include "hw_vrmodes.h" #include "gl/system/gl_framebuffer.h" -#include "gl/renderer/gl_postprocessstate.h" +#include "gl_postprocessstate.h" #include "gl/system/gl_framebuffer.h" #include "gl/shaders/gl_shaderprogram.h" -#include "gl/system/gl_buffers.h" +#include "gl_buffers.h" #include "menu/menu.h" EXTERN_CVAR(Int, vr_mode) diff --git a/src/rendering/gl/shaders/gl_shader.cpp b/src/rendering/gl/shaders/gl_shader.cpp index a9799638a7..125fbb964a 100644 --- a/src/rendering/gl/shaders/gl_shader.cpp +++ b/src/rendering/gl/shaders/gl_shader.cpp @@ -41,7 +41,7 @@ #include "hw_lightbuffer.h" #include "gl_interface.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "matrix.h" #include "gl/renderer/gl_renderer.h" #include "gl/shaders/gl_shader.h" diff --git a/src/rendering/gl/shaders/gl_shader.h b/src/rendering/gl/shaders/gl_shader.h index c5068f5a23..3027376d52 100644 --- a/src/rendering/gl/shaders/gl_shader.h +++ b/src/rendering/gl/shaders/gl_shader.h @@ -23,7 +23,7 @@ #ifndef __GL_SHADERS_H__ #define __GL_SHADERS_H__ -#include "gl/renderer/gl_renderstate.h" +#include "gl_renderstate.h" #include "name.h" extern bool gl_shaderactive; diff --git a/src/rendering/gl/shaders/gl_shaderprogram.cpp b/src/rendering/gl/shaders/gl_shaderprogram.cpp index a79af0ce1a..0a9e8a7a9a 100644 --- a/src/rendering/gl/shaders/gl_shaderprogram.cpp +++ b/src/rendering/gl/shaders/gl_shaderprogram.cpp @@ -1,35 +1,29 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2016 Magnus Norddahl -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* -** gl_shaderprogram.cpp -** GLSL shader program compile and link +** Postprocessing framework +** Copyright (c) 2016-2020 Magnus Norddahl ** +** This software is provided 'as-is', without any express or implied +** warranty. In no event will the authors be held liable for any damages +** arising from the use of this software. +** +** Permission is granted to anyone to use this software for any purpose, +** including commercial applications, and to alter it and redistribute it +** freely, subject to the following restrictions: +** +** 1. The origin of this software must not be misrepresented; you must not +** claim that you wrote the original software. If you use this software +** in a product, an acknowledgment in the product documentation would be +** appreciated but is not required. +** 2. Altered source versions must be plainly marked as such, and must not be +** misrepresented as being the original software. +** 3. This notice may not be removed or altered from any source distribution. */ #include "gl_system.h" #include "v_video.h" #include "gl_interface.h" #include "hw_cvars.h" -#include "gl/system/gl_debug.h" +#include "gl_debug.h" #include "gl/shaders/gl_shaderprogram.h" #include "hwrenderer/utility/hw_shaderpatcher.h" #include "filesystem.h" @@ -268,7 +262,7 @@ FString FShaderProgram::PatchShader(ShaderType type, const FString &code, const // If we have 4.2, always use it because it adds important new syntax. if (maxGlslVersion < 420 && gl.glslversion >= 4.2f) maxGlslVersion = 420; - int shaderVersion = MIN((int)round(gl.glslversion * 10) * 10, maxGlslVersion); + int shaderVersion = std::min((int)round(gl.glslversion * 10) * 10, maxGlslVersion); patchedCode.AppendFormat("#version %d\n", shaderVersion); // TODO: Find some way to add extension requirements to the patching diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index ea90b21018..814a2ace52 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -1,30 +1,37 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2010-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* ** gl_framebuffer.cpp ** Implementation of the non-hardware specific parts of the ** OpenGL frame buffer ** -*/ +**--------------------------------------------------------------------------- +** Copyright 2010-2020 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ #include "gl_system.h" #include "v_video.h" @@ -35,8 +42,8 @@ #include "gl_interface.h" #include "gl/system/gl_framebuffer.h" #include "gl/renderer/gl_renderer.h" -#include "gl/renderer/gl_renderbuffers.h" -#include "gl/textures/gl_samplers.h" +#include "gl_renderbuffers.h" +#include "gl_samplers.h" #include "hwrenderer/utility/hw_clock.h" #include "hw_vrmodes.h" #include "hwrenderer/models/hw_models.h" @@ -49,8 +56,10 @@ #include "r_videoscale.h" #include "gl_buffers.h" #include "swrenderer/r_swscene.h" +#include "gl_postprocessstate.h" #include "flatvertices.h" +#include "hw_cvars.h" EXTERN_CVAR (Bool, vid_vsync) EXTERN_CVAR(Bool, r_drawvoxels) @@ -412,7 +421,34 @@ void OpenGLFrameBuffer::SetSceneRenderTarget(bool useSSAO) void OpenGLFrameBuffer::UpdateShadowMap() { - GLRenderer->UpdateShadowMap(); + if (mShadowMap.PerformUpdate()) + { + FGLDebug::PushGroup("ShadowMap"); + + FGLPostProcessState savedState; + + static_cast(screen->mShadowMap.mLightList)->BindBase(); + static_cast(screen->mShadowMap.mNodesBuffer)->BindBase(); + static_cast(screen->mShadowMap.mLinesBuffer)->BindBase(); + + GLRenderer->mBuffers->BindShadowMapFB(); + + GLRenderer->mShadowMapShader->Bind(); + GLRenderer->mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality; + GLRenderer->mShadowMapShader->Uniforms->NodesCount = screen->mShadowMap.NodesCount(); + GLRenderer->mShadowMapShader->Uniforms.SetData(); + static_cast(GLRenderer->mShadowMapShader->Uniforms.GetBuffer())->BindBase(); + + glViewport(0, 0, gl_shadowmap_quality, 1024); + GLRenderer->RenderScreenQuad(); + + const auto& viewport = screen->mScreenViewport; + glViewport(viewport.left, viewport.top, viewport.width, viewport.height); + + GLRenderer->mBuffers->BindShadowMapTexture(16); + FGLDebug::PopGroup(); + screen->mShadowMap.FinishUpdate(); + } } void OpenGLFrameBuffer::WaitForCommands(bool finish) diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 7aca21c0ea..cabc62b3cc 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -30,6 +30,7 @@ #include "i_time.h" #include "g_game.h" #include "v_text.h" +#include "version.h" #include "hwrenderer/utility/hw_clock.h" #include "hw_vrmodes.h" diff --git a/src/version.h b/src/version.h index 1be840a5f5..213e3f517e 100644 --- a/src/version.h +++ b/src/version.h @@ -110,5 +110,8 @@ const char *GetVersionString(); #define GAME_DIR ".config/" GAMENAMELOWERCASE #endif +const int SAVEPICWIDTH = 216; +const int SAVEPICHEIGHT = 162; + #endif //__VERSION_H__ From 0a3e9a49f8d45aeaa24821f4d8df523415fb27bb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 14:53:26 +0200 Subject: [PATCH 108/220] - changed the light parameter of ShadowTest to a position vector. This was one of two places where game state leaked into the shadowmap implementation. --- src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp | 6 +++--- src/rendering/hwrenderer/dynlights/hw_shadowmap.h | 2 +- src/rendering/hwrenderer/scene/hw_spritelight.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp index 3bc9750f96..5f8cf06768 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp @@ -98,10 +98,10 @@ CUSTOM_CVAR (Bool, gl_light_shadowmap, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) } } -bool IShadowMap::ShadowTest(FDynamicLight *light, const DVector3 &pos) +bool IShadowMap::ShadowTest(const DVector3 &lpos, const DVector3 &pos) { - if (light->shadowmapped && light->GetRadius() > 0.0 && IsEnabled() && mAABBTree) - return mAABBTree->RayTest(light->Pos, pos) >= 1.0f; + if (mAABBTree) + return mAABBTree->RayTest(lpos, pos) >= 1.0f; else return true; } diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.h b/src/rendering/hwrenderer/dynlights/hw_shadowmap.h index bc11f99ba1..a3b837e1c1 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.h +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.h @@ -19,7 +19,7 @@ public: void Reset(); // Test if a world position is in shadow relative to the specified light and returns false if it is - bool ShadowTest(FDynamicLight *light, const DVector3 &pos); + bool ShadowTest(const DVector3 &lpos, const DVector3 &pos); // Returns true if gl_light_shadowmap is enabled and supported by the hardware bool IsEnabled() const; diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index 292a970a60..abbc1a64d5 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -106,7 +106,7 @@ void HWDrawInfo::GetDynSpriteLight(AActor *self, float x, float y, float z, FLig frac *= (float)smoothstep(light->pSpotOuterAngle->Cos(), light->pSpotInnerAngle->Cos(), cosDir); } - if (frac > 0 && (!light->shadowmapped || screen->mShadowMap.ShadowTest(light, { x, y, z }))) + if (frac > 0 && (!light->shadowmapped || (light->GetRadius() > 0 && screen->mShadowMap.ShadowTest(light->Pos, { x, y, z })))) { lr = light->GetRed() / 255.0f; lg = light->GetGreen() / 255.0f; From ba0b42465d2357188cd739c3b3ec3c8aecf749f7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 18:54:43 +0200 Subject: [PATCH 109/220] - changed shadowmap setup so that the AABB tree is owned and controlled by the map, not the renderer. Needed to properly separate game logic from backend implementation, the shadowmap had both in the same object thanks to the old setup. --- src/CMakeLists.txt | 1 + .../postprocessing/hw_postprocess.cpp | 21 ++ src/g_level.cpp | 1 + src/g_levellocals.h | 2 + src/maploader/maploader.cpp | 2 + src/p_setup.cpp | 3 + .../hwrenderer/dynlights/doom_aabbtree.cpp | 273 ++++++++++++++++++ .../hwrenderer/dynlights/doom_aabbtree.h | 21 ++ .../hwrenderer/dynlights/hw_aabbtree.cpp | 243 ---------------- .../hwrenderer/dynlights/hw_aabbtree.h | 36 +-- .../hwrenderer/dynlights/hw_shadowmap.cpp | 44 +-- .../hwrenderer/dynlights/hw_shadowmap.h | 17 +- src/rendering/hwrenderer/hw_entrypoint.cpp | 3 + src/rendering/v_video.h | 4 + 14 files changed, 356 insertions(+), 315 deletions(-) create mode 100644 src/rendering/hwrenderer/dynlights/doom_aabbtree.cpp create mode 100644 src/rendering/hwrenderer/dynlights/doom_aabbtree.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f6e1d2a8b..899e45fd68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -945,6 +945,7 @@ set (PCH_SOURCES rendering/gl/system/gl_framebuffer.cpp rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp + rendering/hwrenderer/dynlights/doom_aabbtree.cpp rendering/hwrenderer/dynlights/hw_aabbtree.cpp rendering/hwrenderer/dynlights/hw_shadowmap.cpp rendering/hwrenderer/models/hw_models.cpp diff --git a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp index 519e03b11e..a206a4c166 100644 --- a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -866,6 +866,27 @@ PPPresent::PPPresent() ///////////////////////////////////////////////////////////////////////////// + +void PPShadowMap::Update(PPRenderState* renderstate) +{ + ShadowMapUniforms uniforms; + uniforms.ShadowmapQuality = (float)gl_shadowmap_quality; + uniforms.NodesCount = screen->mShadowMap.NodesCount(); + + renderstate->PushGroup("shadowmap"); + + renderstate->Clear(); + renderstate->Shader = &ShadowMap; + renderstate->Uniforms.Set(uniforms); + renderstate->Viewport = { 0, 0, gl_shadowmap_quality, 1024 }; + renderstate->SetShadowMapBuffers(true); + renderstate->SetOutputShadowMap(); + renderstate->SetNoBlend(); + renderstate->Draw(); + + renderstate->PopGroup(); +} + ///////////////////////////////////////////////////////////////////////////// CVAR(Bool, gl_custompost, true, 0) diff --git a/src/g_level.cpp b/src/g_level.cpp index ddb8ebbcd4..57d0ac6c67 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1573,6 +1573,7 @@ FLevelLocals::FLevelLocals() : Behaviors(this), tagManager(this) FLevelLocals::~FLevelLocals() { if (localEventManager) delete localEventManager; + if (aabbTree) delete aabbTree; } //========================================================================== diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 863133705d..576cdd6060 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -54,6 +54,7 @@ #include "r_data/r_sections.h" #include "r_data/r_canvastexture.h" #include "r_data/r_interpolate.h" +#include "hwrenderer/dynlights/doom_aabbtree.h" //============================================================================ // @@ -456,6 +457,7 @@ public: FSectionContainer sections; FCanvasTextureInfo canvasTextureInfo; EventManager *localEventManager = nullptr; + DoomLevelAABBTree* aabbTree = nullptr; // [ZZ] Destructible geometry information TMap healthGroups; diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 050292e5d1..bf560e1ac9 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -3239,5 +3239,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position) PO_Init(); // Initialize the polyobjs if (!Level->IsReentering()) Level->FinalizePortals(); // finalize line portals after polyobjects have been initialized. This info is needed for properly flagging them. + + Level->aabbTree = new DoomLevelAABBTree(Level); } diff --git a/src/p_setup.cpp b/src/p_setup.cpp index c7ab8dfd4e..d65d08ec1a 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -363,6 +363,9 @@ void FLevelLocals::ClearLevelData() if (automap) automap->Destroy(); Behaviors.UnloadModules(); localEventManager->Shutdown(); + if (aabbTree) delete aabbTree; + aabbTree = nullptr; + } //========================================================================== diff --git a/src/rendering/hwrenderer/dynlights/doom_aabbtree.cpp b/src/rendering/hwrenderer/dynlights/doom_aabbtree.cpp new file mode 100644 index 0000000000..21256271df --- /dev/null +++ b/src/rendering/hwrenderer/dynlights/doom_aabbtree.cpp @@ -0,0 +1,273 @@ +// +//--------------------------------------------------------------------------- +// AABB-tree used for ray testing +// Copyright(C) 2017 Magnus Norddahl +// All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/ +// +//-------------------------------------------------------------------------- +// + + + +#include "doom_aabbtree.h" +#include "g_levellocals.h" + +using namespace hwrenderer; + +DoomLevelAABBTree::DoomLevelAABBTree(FLevelLocals *lev) +{ + Level = lev; + // Calculate the center of all lines + TArray centroids; + for (unsigned int i = 0; i < Level->lines.Size(); i++) + { + FVector2 v1 = { (float)Level->lines[i].v1->fX(), (float)Level->lines[i].v1->fY() }; + FVector2 v2 = { (float)Level->lines[i].v2->fX(), (float)Level->lines[i].v2->fY() }; + centroids.Push((v1 + v2) * 0.5f); + } + + // Create the static subtree + if (!GenerateTree(¢roids[0], false)) + return; + + int staticroot = nodes.Size() - 1; + + dynamicStartNode = nodes.Size(); + dynamicStartLine = treelines.Size(); + + // Create the dynamic subtree + if (GenerateTree(¢roids[0], true)) + { + int dynamicroot = nodes.Size() - 1; + + // Create a shared root node + FVector2 aabb_min, aabb_max; + const auto &left = nodes[staticroot]; + const auto &right = nodes[dynamicroot]; + aabb_min.X = MIN(left.aabb_left, right.aabb_left); + aabb_min.Y = MIN(left.aabb_top, right.aabb_top); + aabb_max.X = MAX(left.aabb_right, right.aabb_right); + aabb_max.Y = MAX(left.aabb_bottom, right.aabb_bottom); + nodes.Push({ aabb_min, aabb_max, staticroot, dynamicroot }); + } + + // Add the lines referenced by the leaf nodes + treelines.Resize(mapLines.Size()); + for (unsigned int i = 0; i < mapLines.Size(); i++) + { + const auto &line = Level->lines[mapLines[i]]; + auto &treeline = treelines[i]; + + treeline.x = (float)line.v1->fX(); + treeline.y = (float)line.v1->fY(); + treeline.dx = (float)line.v2->fX() - treeline.x; + treeline.dy = (float)line.v2->fY() - treeline.y; + } +} + +bool DoomLevelAABBTree::GenerateTree(const FVector2 *centroids, bool dynamicsubtree) +{ + // Create a list of level lines we want to add: + TArray line_elements; + auto &maplines = Level->lines; + for (unsigned int i = 0; i < maplines.Size(); i++) + { + if (!maplines[i].backsector) + { + bool isPolyLine = maplines[i].sidedef[0] && (maplines[i].sidedef[0]->Flags & WALLF_POLYOBJ); + if (isPolyLine && dynamicsubtree) + { + line_elements.Push(mapLines.Size()); + mapLines.Push(i); + } + else if (!isPolyLine && !dynamicsubtree) + { + line_elements.Push(mapLines.Size()); + mapLines.Push(i); + } + } + } + + if (line_elements.Size() == 0) + return false; + + // GenerateTreeNode needs a buffer where it can store line indices temporarily when sorting lines into the left and right child AABB buckets + TArray work_buffer; + work_buffer.Resize(line_elements.Size() * 2); + + // Generate the AABB tree + GenerateTreeNode(&line_elements[0], (int)line_elements.Size(), centroids, &work_buffer[0]); + return true; +} + +bool DoomLevelAABBTree::Update() +{ + bool modified = false; + for (unsigned int i = dynamicStartLine; i < mapLines.Size(); i++) + { + const auto &line = Level->lines[mapLines[i]]; + + AABBTreeLine treeline; + treeline.x = (float)line.v1->fX(); + treeline.y = (float)line.v1->fY(); + treeline.dx = (float)line.v2->fX() - treeline.x; + treeline.dy = (float)line.v2->fY() - treeline.y; + + if (memcmp(&treelines[i], &treeline, sizeof(AABBTreeLine))) + { + TArray path = FindNodePath(i, nodes.Size() - 1); + if (path.Size()) + { + float x1 = (float)line.v1->fX(); + float y1 = (float)line.v1->fY(); + float x2 = (float)line.v2->fX(); + float y2 = (float)line.v2->fY(); + + int nodeIndex = path[0]; + nodes[nodeIndex].aabb_left = MIN(x1, x2); + nodes[nodeIndex].aabb_right = MAX(x1, x2); + nodes[nodeIndex].aabb_top = MIN(y1, y2); + nodes[nodeIndex].aabb_bottom = MAX(y1, y2); + + for (unsigned int j = 1; j < path.Size(); j++) + { + auto &cur = nodes[path[j]]; + const auto &left = nodes[cur.left_node]; + const auto &right = nodes[cur.right_node]; + cur.aabb_left = MIN(left.aabb_left, right.aabb_left); + cur.aabb_top = MIN(left.aabb_top, right.aabb_top); + cur.aabb_right = MAX(left.aabb_right, right.aabb_right); + cur.aabb_bottom = MAX(left.aabb_bottom, right.aabb_bottom); + } + + treelines[i] = treeline; + modified = true; + } + } + } + return modified; +} + + +int DoomLevelAABBTree::GenerateTreeNode(int *lines, int num_lines, const FVector2 *centroids, int *work_buffer) +{ + if (num_lines == 0) + return -1; + + // Find bounding box and median of the lines + FVector2 median = FVector2(0.0f, 0.0f); + FVector2 aabb_min, aabb_max; + auto &maplines = Level->lines; + aabb_min.X = (float)maplines[mapLines[lines[0]]].v1->fX(); + aabb_min.Y = (float)maplines[mapLines[lines[0]]].v1->fY(); + aabb_max = aabb_min; + for (int i = 0; i < num_lines; i++) + { + float x1 = (float)maplines[mapLines[lines[i]]].v1->fX(); + float y1 = (float)maplines[mapLines[lines[i]]].v1->fY(); + float x2 = (float)maplines[mapLines[lines[i]]].v2->fX(); + float y2 = (float)maplines[mapLines[lines[i]]].v2->fY(); + + aabb_min.X = MIN(aabb_min.X, x1); + aabb_min.X = MIN(aabb_min.X, x2); + aabb_min.Y = MIN(aabb_min.Y, y1); + aabb_min.Y = MIN(aabb_min.Y, y2); + aabb_max.X = MAX(aabb_max.X, x1); + aabb_max.X = MAX(aabb_max.X, x2); + aabb_max.Y = MAX(aabb_max.Y, y1); + aabb_max.Y = MAX(aabb_max.Y, y2); + + median += centroids[mapLines[lines[i]]]; + } + median /= (float)num_lines; + + if (num_lines == 1) // Leaf node + { + nodes.Push(AABBTreeNode(aabb_min, aabb_max, lines[0])); + return (int)nodes.Size() - 1; + } + + // Find the longest axis + float axis_lengths[2] = + { + aabb_max.X - aabb_min.X, + aabb_max.Y - aabb_min.Y + }; + int axis_order[2] = { 0, 1 }; + FVector2 axis_plane[2] = { FVector2(1.0f, 0.0f), FVector2(0.0f, 1.0f) }; + std::sort(axis_order, axis_order + 2, [&](int a, int b) { return axis_lengths[a] > axis_lengths[b]; }); + + // Try sort at longest axis, then if that fails then the other one. + // We place the sorted lines into work_buffer and then move the result back to the lines list when done. + int left_count, right_count; + for (int attempt = 0; attempt < 2; attempt++) + { + // Find the sort plane for axis + FVector2 axis = axis_plane[axis_order[attempt]]; + FVector3 plane(axis, -(median | axis)); + + // Sort lines into two based ib whether the line center is on the front or back side of a plane + left_count = 0; + right_count = 0; + for (int i = 0; i < num_lines; i++) + { + int line_index = lines[i]; + + float side = FVector3(centroids[mapLines[lines[i]]], 1.0f) | plane; + if (side >= 0.0f) + { + work_buffer[left_count] = line_index; + left_count++; + } + else + { + work_buffer[num_lines + right_count] = line_index; + right_count++; + } + } + + if (left_count != 0 && right_count != 0) + break; + } + + // Check if something went wrong when sorting and do a random sort instead + if (left_count == 0 || right_count == 0) + { + left_count = num_lines / 2; + right_count = num_lines - left_count; + } + else + { + // Move result back into lines list: + for (int i = 0; i < left_count; i++) + lines[i] = work_buffer[i]; + for (int i = 0; i < right_count; i++) + lines[i + left_count] = work_buffer[num_lines + i]; + } + + // Create child nodes: + int left_index = -1; + int right_index = -1; + if (left_count > 0) + left_index = GenerateTreeNode(lines, left_count, centroids, work_buffer); + if (right_count > 0) + right_index = GenerateTreeNode(lines + left_count, right_count, centroids, work_buffer); + + // Store resulting node and return its index + nodes.Push(AABBTreeNode(aabb_min, aabb_max, left_index, right_index)); + return (int)nodes.Size() - 1; +} + diff --git a/src/rendering/hwrenderer/dynlights/doom_aabbtree.h b/src/rendering/hwrenderer/dynlights/doom_aabbtree.h new file mode 100644 index 0000000000..f41612b445 --- /dev/null +++ b/src/rendering/hwrenderer/dynlights/doom_aabbtree.h @@ -0,0 +1,21 @@ +#pragma once +#include "hw_aabbtree.h" + +// Axis aligned bounding box tree used for ray testing treelines. +class DoomLevelAABBTree : public hwrenderer::LevelAABBTree +{ +public: + // Constructs a tree for the current level + DoomLevelAABBTree(FLevelLocals *lev); + bool Update() override; + +private: + bool GenerateTree(const FVector2 *centroids, bool dynamicsubtree); + + // Generate a tree node and its children recursively + int GenerateTreeNode(int *treelines, int num_lines, const FVector2 *centroids, int *work_buffer); + + TArray mapLines; + FLevelLocals *Level; +}; + diff --git a/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp b/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp index a0c3657404..61e6da9477 100644 --- a/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp @@ -27,140 +27,6 @@ namespace hwrenderer { -LevelAABBTree::LevelAABBTree(FLevelLocals *lev) -{ - Level = lev; - // Calculate the center of all lines - TArray centroids; - for (unsigned int i = 0; i < Level->lines.Size(); i++) - { - FVector2 v1 = { (float)Level->lines[i].v1->fX(), (float)Level->lines[i].v1->fY() }; - FVector2 v2 = { (float)Level->lines[i].v2->fX(), (float)Level->lines[i].v2->fY() }; - centroids.Push((v1 + v2) * 0.5f); - } - - // Create the static subtree - if (!GenerateTree(¢roids[0], false)) - return; - - int staticroot = nodes.Size() - 1; - - dynamicStartNode = nodes.Size(); - dynamicStartLine = treelines.Size(); - - // Create the dynamic subtree - if (GenerateTree(¢roids[0], true)) - { - int dynamicroot = nodes.Size() - 1; - - // Create a shared root node - FVector2 aabb_min, aabb_max; - const auto &left = nodes[staticroot]; - const auto &right = nodes[dynamicroot]; - aabb_min.X = MIN(left.aabb_left, right.aabb_left); - aabb_min.Y = MIN(left.aabb_top, right.aabb_top); - aabb_max.X = MAX(left.aabb_right, right.aabb_right); - aabb_max.Y = MAX(left.aabb_bottom, right.aabb_bottom); - nodes.Push({ aabb_min, aabb_max, staticroot, dynamicroot }); - } - - // Add the lines referenced by the leaf nodes - treelines.Resize(mapLines.Size()); - for (unsigned int i = 0; i < mapLines.Size(); i++) - { - const auto &line = Level->lines[mapLines[i]]; - auto &treeline = treelines[i]; - - treeline.x = (float)line.v1->fX(); - treeline.y = (float)line.v1->fY(); - treeline.dx = (float)line.v2->fX() - treeline.x; - treeline.dy = (float)line.v2->fY() - treeline.y; - } -} - -bool LevelAABBTree::GenerateTree(const FVector2 *centroids, bool dynamicsubtree) -{ - // Create a list of level lines we want to add: - TArray line_elements; - auto &maplines = Level->lines; - for (unsigned int i = 0; i < maplines.Size(); i++) - { - if (!maplines[i].backsector) - { - bool isPolyLine = maplines[i].sidedef[0] && (maplines[i].sidedef[0]->Flags & WALLF_POLYOBJ); - if (isPolyLine && dynamicsubtree) - { - line_elements.Push(mapLines.Size()); - mapLines.Push(i); - } - else if (!isPolyLine && !dynamicsubtree) - { - line_elements.Push(mapLines.Size()); - mapLines.Push(i); - } - } - } - - if (line_elements.Size() == 0) - return false; - - // GenerateTreeNode needs a buffer where it can store line indices temporarily when sorting lines into the left and right child AABB buckets - TArray work_buffer; - work_buffer.Resize(line_elements.Size() * 2); - - // Generate the AABB tree - GenerateTreeNode(&line_elements[0], (int)line_elements.Size(), centroids, &work_buffer[0]); - return true; -} - -bool LevelAABBTree::Update() -{ - bool modified = false; - for (unsigned int i = dynamicStartLine; i < mapLines.Size(); i++) - { - const auto &line = Level->lines[mapLines[i]]; - - AABBTreeLine treeline; - treeline.x = (float)line.v1->fX(); - treeline.y = (float)line.v1->fY(); - treeline.dx = (float)line.v2->fX() - treeline.x; - treeline.dy = (float)line.v2->fY() - treeline.y; - - if (memcmp(&treelines[i], &treeline, sizeof(AABBTreeLine))) - { - TArray path = FindNodePath(i, nodes.Size() - 1); - if (path.Size()) - { - float x1 = (float)line.v1->fX(); - float y1 = (float)line.v1->fY(); - float x2 = (float)line.v2->fX(); - float y2 = (float)line.v2->fY(); - - int nodeIndex = path[0]; - nodes[nodeIndex].aabb_left = MIN(x1, x2); - nodes[nodeIndex].aabb_right = MAX(x1, x2); - nodes[nodeIndex].aabb_top = MIN(y1, y2); - nodes[nodeIndex].aabb_bottom = MAX(y1, y2); - - for (unsigned int j = 1; j < path.Size(); j++) - { - auto &cur = nodes[path[j]]; - const auto &left = nodes[cur.left_node]; - const auto &right = nodes[cur.right_node]; - cur.aabb_left = MIN(left.aabb_left, right.aabb_left); - cur.aabb_top = MIN(left.aabb_top, right.aabb_top); - cur.aabb_right = MAX(left.aabb_right, right.aabb_right); - cur.aabb_bottom = MAX(left.aabb_bottom, right.aabb_bottom); - } - - treelines[i] = treeline; - modified = true; - } - } - } - return modified; -} - TArray LevelAABBTree::FindNodePath(unsigned int line, unsigned int node) { const AABBTreeNode &n = nodes[node]; @@ -297,114 +163,5 @@ double LevelAABBTree::IntersectRayLine(const DVector2 &ray_start, const DVector2 return 1.0; } -int LevelAABBTree::GenerateTreeNode(int *lines, int num_lines, const FVector2 *centroids, int *work_buffer) -{ - if (num_lines == 0) - return -1; - - // Find bounding box and median of the lines - FVector2 median = FVector2(0.0f, 0.0f); - FVector2 aabb_min, aabb_max; - auto &maplines = Level->lines; - aabb_min.X = (float)maplines[mapLines[lines[0]]].v1->fX(); - aabb_min.Y = (float)maplines[mapLines[lines[0]]].v1->fY(); - aabb_max = aabb_min; - for (int i = 0; i < num_lines; i++) - { - float x1 = (float)maplines[mapLines[lines[i]]].v1->fX(); - float y1 = (float)maplines[mapLines[lines[i]]].v1->fY(); - float x2 = (float)maplines[mapLines[lines[i]]].v2->fX(); - float y2 = (float)maplines[mapLines[lines[i]]].v2->fY(); - - aabb_min.X = MIN(aabb_min.X, x1); - aabb_min.X = MIN(aabb_min.X, x2); - aabb_min.Y = MIN(aabb_min.Y, y1); - aabb_min.Y = MIN(aabb_min.Y, y2); - aabb_max.X = MAX(aabb_max.X, x1); - aabb_max.X = MAX(aabb_max.X, x2); - aabb_max.Y = MAX(aabb_max.Y, y1); - aabb_max.Y = MAX(aabb_max.Y, y2); - - median += centroids[mapLines[lines[i]]]; - } - median /= (float)num_lines; - - if (num_lines == 1) // Leaf node - { - nodes.Push(AABBTreeNode(aabb_min, aabb_max, lines[0])); - return (int)nodes.Size() - 1; - } - - // Find the longest axis - float axis_lengths[2] = - { - aabb_max.X - aabb_min.X, - aabb_max.Y - aabb_min.Y - }; - int axis_order[2] = { 0, 1 }; - FVector2 axis_plane[2] = { FVector2(1.0f, 0.0f), FVector2(0.0f, 1.0f) }; - std::sort(axis_order, axis_order + 2, [&](int a, int b) { return axis_lengths[a] > axis_lengths[b]; }); - - // Try sort at longest axis, then if that fails then the other one. - // We place the sorted lines into work_buffer and then move the result back to the lines list when done. - int left_count, right_count; - for (int attempt = 0; attempt < 2; attempt++) - { - // Find the sort plane for axis - FVector2 axis = axis_plane[axis_order[attempt]]; - FVector3 plane(axis, -(median | axis)); - - // Sort lines into two based ib whether the line center is on the front or back side of a plane - left_count = 0; - right_count = 0; - for (int i = 0; i < num_lines; i++) - { - int line_index = lines[i]; - - float side = FVector3(centroids[mapLines[lines[i]]], 1.0f) | plane; - if (side >= 0.0f) - { - work_buffer[left_count] = line_index; - left_count++; - } - else - { - work_buffer[num_lines + right_count] = line_index; - right_count++; - } - } - - if (left_count != 0 && right_count != 0) - break; - } - - // Check if something went wrong when sorting and do a random sort instead - if (left_count == 0 || right_count == 0) - { - left_count = num_lines / 2; - right_count = num_lines - left_count; - } - else - { - // Move result back into lines list: - for (int i = 0; i < left_count; i++) - lines[i] = work_buffer[i]; - for (int i = 0; i < right_count; i++) - lines[i + left_count] = work_buffer[num_lines + i]; - } - - // Create child nodes: - int left_index = -1; - int right_index = -1; - if (left_count > 0) - left_index = GenerateTreeNode(lines, left_count, centroids, work_buffer); - if (right_count > 0) - right_index = GenerateTreeNode(lines + left_count, right_count, centroids, work_buffer); - - // Store resulting node and return its index - nodes.Push(AABBTreeNode(aabb_min, aabb_max, left_index, right_index)); - return (int)nodes.Size() - 1; -} - } diff --git a/src/rendering/hwrenderer/dynlights/hw_aabbtree.h b/src/rendering/hwrenderer/dynlights/hw_aabbtree.h index f435d68cef..19f3e75311 100644 --- a/src/rendering/hwrenderer/dynlights/hw_aabbtree.h +++ b/src/rendering/hwrenderer/dynlights/hw_aabbtree.h @@ -37,18 +37,22 @@ struct AABBTreeLine float dx, dy; }; -// Axis aligned bounding box tree used for ray testing treelines. class LevelAABBTree { -public: - // Constructs a tree for the current level - LevelAABBTree(FLevelLocals *lev); +protected: + // Nodes in the AABB tree. Last node is the root node. + TArray nodes; + // Line segments for the leaf nodes in the tree. + TArray treelines; + + int dynamicStartNode = 0; + int dynamicStartLine = 0; + +public: // Shoot a ray from ray_start to ray_end and return the closest hit as a fractional value between 0 and 1. Returns 1 if no line was hit. double RayTest(const DVector3 &ray_start, const DVector3 &ray_end); - bool Update(); - const void *Nodes() const { return nodes.Data(); } const void *Lines() const { return treelines.Data(); } size_t NodesSize() const { return nodes.Size() * sizeof(AABBTreeNode); } @@ -62,31 +66,17 @@ public: size_t DynamicNodesOffset() const { return dynamicStartNode * sizeof(AABBTreeNode); } size_t DynamicLinesOffset() const { return dynamicStartLine * sizeof(AABBTreeLine); } -private: - bool GenerateTree(const FVector2 *centroids, bool dynamicsubtree); + virtual bool Update() = 0; +protected: + TArray FindNodePath(unsigned int line, unsigned int node); // Test if a ray overlaps an AABB node or not bool OverlapRayAABB(const DVector2 &ray_start2d, const DVector2 &ray_end2d, const AABBTreeNode &node); // Intersection test between a ray and a line segment double IntersectRayLine(const DVector2 &ray_start, const DVector2 &ray_end, int line_index, const DVector2 &raydelta, double rayd, double raydist2); - // Generate a tree node and its children recursively - int GenerateTreeNode(int *treelines, int num_lines, const FVector2 *centroids, int *work_buffer); - TArray FindNodePath(unsigned int line, unsigned int node); - - // Nodes in the AABB tree. Last node is the root node. - TArray nodes; - - // Line segments for the leaf nodes in the tree. - TArray treelines; - - int dynamicStartNode = 0; - int dynamicStartLine = 0; - - TArray mapLines; - FLevelLocals *Level; }; } // namespace diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp index 5f8cf06768..5510de719d 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp @@ -146,25 +146,6 @@ void IShadowMap::CollectLights() } } -bool IShadowMap::ValidateAABBTree(FLevelLocals *Level) -{ - // Just comparing the level info is not enough. If two MAPINFO-less levels get played after each other, - // they can both refer to the same default level info. - if (Level->info != mLastLevel && (Level->nodes.Size() != mLastNumNodes || Level->segs.Size() != mLastNumSegs)) - { - mAABBTree.reset(); - - mLastLevel = Level->info; - mLastNumNodes = Level->nodes.Size(); - mLastNumSegs = Level->segs.Size(); - } - - if (mAABBTree) - return true; - - mAABBTree.reset(new hwrenderer::LevelAABBTree(Level)); - return false; -} bool IShadowMap::PerformUpdate() { @@ -196,8 +177,10 @@ void IShadowMap::UploadLights() void IShadowMap::UploadAABBTree() { - if (!ValidateAABBTree(&level)) + if (mNewTree) { + mNewTree = false; + if (!mNodesBuffer) mNodesBuffer = screen->CreateDataBuffer(LIGHTNODES_BINDINGPOINT, true, false); mNodesBuffer->SetData(mAABBTree->NodesSize(), mAABBTree->Nodes()); @@ -224,24 +207,3 @@ IShadowMap::~IShadowMap() { Reset(); } - -void PPShadowMap::Update(PPRenderState* renderstate) -{ - ShadowMapUniforms uniforms; - uniforms.ShadowmapQuality = (float)gl_shadowmap_quality; - uniforms.NodesCount = screen->mShadowMap.NodesCount(); - - renderstate->PushGroup("shadowmap"); - - renderstate->Clear(); - renderstate->Shader = &ShadowMap; - renderstate->Uniforms.Set(uniforms); - renderstate->Viewport = { 0, 0, gl_shadowmap_quality, 1024 }; - renderstate->SetShadowMapBuffers(true); - renderstate->SetOutputShadowMap(); - renderstate->SetNoBlend(); - renderstate->Draw(); - - renderstate->PopGroup(); -} - diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.h b/src/rendering/hwrenderer/dynlights/hw_shadowmap.h index a3b837e1c1..08c44d1cf6 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.h +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.h @@ -40,9 +40,14 @@ public: return mAABBTree->NodesCount(); } + void SetAABBTree(hwrenderer::LevelAABBTree* tree) + { + mAABBTree = tree; + mNewTree = true; + } + protected: void CollectLights(); - bool ValidateAABBTree(FLevelLocals *lev); // Upload the AABB-tree to the GPU void UploadAABBTree(); @@ -53,13 +58,9 @@ protected: // Working buffer for creating the list of lights. Stored here to avoid allocating memory each frame TArray mLights; - // Used to detect when a level change requires the AABB tree to be regenerated - level_info_t *mLastLevel = nullptr; - unsigned mLastNumNodes = 0; - unsigned mLastNumSegs = 0; - - // AABB-tree of the level, used for ray tests - std::unique_ptr mAABBTree; + // AABB-tree of the level, used for ray tests, owned by the playsim, not the renderer. + hwrenderer::LevelAABBTree* mAABBTree = nullptr; + bool mNewTree = false; IShadowMap(const IShadowMap &) = delete; IShadowMap &operator=(IShadowMap &) = delete; diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index adaccd971d..70b1d5e05e 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -72,7 +72,10 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou R_SetupFrame(mainvp, r_viewwindow, camera); if (mainview && toscreen) + { + screen->SetAABBTree(camera->Level->aabbTree); screen->UpdateShadowMap(); + } // Update the attenuation flag of all light defaults for each viewpoint. // This function will only do something if the setting differs. diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index e790d72271..ead9eb5a2c 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -186,6 +186,10 @@ public: virtual void InitializeState() = 0; // For stuff that needs 'screen' set. virtual bool IsVulkan() { return false; } virtual bool IsPoly() { return false; } + void SetAABBTree(hwrenderer::LevelAABBTree * tree) + { + mShadowMap.SetAABBTree(tree); + } virtual DCanvas* GetCanvas() { return nullptr; } From c30165db0d17bdb5e3e593659149e35d5451aa03 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 19:58:17 +0200 Subject: [PATCH 110/220] - removed the remaining dependencies of the shadowmap code on game data. Everything is handled with callbacks now. --- .../hwrenderer/dynlights/hw_aabbtree.cpp | 5 +- .../hwrenderer/dynlights/hw_dynlightdata.cpp | 12 +++- .../hwrenderer/dynlights/hw_shadowmap.cpp | 66 ++----------------- .../hwrenderer/dynlights/hw_shadowmap.h | 26 +++++--- src/rendering/hwrenderer/hw_entrypoint.cpp | 38 +++++++++++ 5 files changed, 71 insertions(+), 76 deletions(-) diff --git a/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp b/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp index 61e6da9477..0a8c819009 100644 --- a/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp @@ -20,8 +20,7 @@ //-------------------------------------------------------------------------- // -#include "r_state.h" -#include "g_levellocals.h" +#include #include "hw_aabbtree.h" namespace hwrenderer @@ -82,7 +81,7 @@ double LevelAABBTree::RayTest(const DVector3 &ray_start, const DVector3 &ray_end else if (nodes[node_index].line_index != -1) // isLeaf(node_index) { // We reached a leaf node. Do a ray/line intersection test to see if we hit the line. - hit_fraction = MIN(IntersectRayLine(ray_start, ray_end, nodes[node_index].line_index, raydelta, rayd, raydist2), hit_fraction); + hit_fraction = std::min(IntersectRayLine(ray_start, ray_end, nodes[node_index].line_index, raydelta, rayd, raydist2), hit_fraction); stack_pos--; } else if (stack_pos == 32) diff --git a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp index c7107f8470..82087a8519 100644 --- a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp @@ -28,6 +28,7 @@ #include "actorinlines.h" #include "a_dynlight.h" #include "hw_dynlightdata.h" +#include"hw_cvars.h" #include "hwrenderer/scene/hw_drawstructs.h" // If we want to share the array to avoid constant allocations it needs to be thread local unless it'd be littered with expensive synchronization. @@ -105,10 +106,15 @@ void AddLightToList(FDynLightData &dld, int group, FDynamicLight * light, bool f i = 1; } - float shadowIndex = light->mShadowmapIndex + 1.0f; + float shadowIndex; + if (gl_light_shadowmap) + { + shadowIndex = light->mShadowmapIndex + 1.0f; - // Store attenuate flag in the sign bit of the float. - if (light->IsAttenuated() || forceAttenuate) shadowIndex = -shadowIndex; + // Store attenuate flag in the sign bit of the float. + if (light->IsAttenuated() || forceAttenuate) shadowIndex = -shadowIndex; + } + else shadowIndex = 1025.f; float lightType = 0.0f; float spotInnerAngle = 0.0f; diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp index 5510de719d..20b6f53a32 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp @@ -25,10 +25,6 @@ #include "hw_dynlightdata.h" #include "hwrenderer/data/buffers.h" #include "hwrenderer/data/shaderuniforms.h" -#include "stats.h" -#include "g_levellocals.h" -#include "v_video.h" -#include "a_dynlight.h" #include "hwrenderer/postprocessing/hw_postprocess.h" /* @@ -63,6 +59,8 @@ cycle_t IShadowMap::UpdateCycles; int IShadowMap::LightsProcessed; int IShadowMap::LightsShadowmapped; +CVAR(Bool, gl_light_shadowmap, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) + ADD_STAT(shadowmap) { FString out; @@ -85,68 +83,14 @@ CUSTOM_CVAR(Int, gl_shadowmap_quality, 512, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) } } -CUSTOM_CVAR (Bool, gl_light_shadowmap, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - if (!self) for (auto Level : AllLevels()) - { - auto light = Level->lights; - while (light) - { - light->mShadowmapIndex = 1024; - light = light->next; - } - } -} - bool IShadowMap::ShadowTest(const DVector3 &lpos, const DVector3 &pos) { - if (mAABBTree) + if (mAABBTree && gl_light_shadowmap) return mAABBTree->RayTest(lpos, pos) >= 1.0f; else return true; } -bool IShadowMap::IsEnabled() const -{ - return gl_light_shadowmap && (screen->hwcaps & RFL_SHADER_STORAGE_BUFFER); -} - -void IShadowMap::CollectLights() -{ - if (mLights.Size() != 1024 * 4) mLights.Resize(1024 * 4); - int lightindex = 0; - auto Level = &level; - - // Todo: this should go through the blockmap in a spiral pattern around the player so that closer lights are preferred. - for (auto light = Level->lights; light; light = light->next) - { - LightsProcessed++; - if (light->shadowmapped && light->IsActive() && lightindex < 1024 * 4) - { - LightsShadowmapped++; - - light->mShadowmapIndex = lightindex >> 2; - - mLights[lightindex] = (float)light->X(); - mLights[lightindex+1] = (float)light->Y(); - mLights[lightindex+2] = (float)light->Z(); - mLights[lightindex+3] = light->GetRadius(); - lightindex += 4; - } - else - { - light->mShadowmapIndex = 1024; - } - - } - - for (; lightindex < 1024 * 4; lightindex++) - { - mLights[lightindex] = 0; - } -} - - bool IShadowMap::PerformUpdate() { UpdateCycles.Reset(); @@ -154,7 +98,7 @@ bool IShadowMap::PerformUpdate() LightsProcessed = 0; LightsShadowmapped = 0; - if (IsEnabled()) + if (gl_light_shadowmap && (screen->hwcaps & RFL_SHADER_STORAGE_BUFFER) && CollectLights != nullptr) { UpdateCycles.Clock(); UploadAABBTree(); @@ -166,6 +110,7 @@ bool IShadowMap::PerformUpdate() void IShadowMap::UploadLights() { + mLights.Resize(1024 * 4); CollectLights(); if (mLightList == nullptr) @@ -207,3 +152,4 @@ IShadowMap::~IShadowMap() { Reset(); } + diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.h b/src/rendering/hwrenderer/dynlights/hw_shadowmap.h index 08c44d1cf6..5a65e7620f 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.h +++ b/src/rendering/hwrenderer/dynlights/hw_shadowmap.h @@ -5,10 +5,7 @@ #include "stats.h" #include -struct FDynamicLight; -struct level_info_t; class IDataBuffer; -struct FLevelLocals; class IShadowMap { @@ -21,9 +18,6 @@ public: // Test if a world position is in shadow relative to the specified light and returns false if it is bool ShadowTest(const DVector3 &lpos, const DVector3 &pos); - // Returns true if gl_light_shadowmap is enabled and supported by the hardware - bool IsEnabled() const; - static cycle_t UpdateCycles; static int LightsProcessed; static int LightsShadowmapped; @@ -46,13 +40,23 @@ public: mNewTree = true; } -protected: - void CollectLights(); + void SetCollectLights(std::function func) + { + CollectLights = std::move(func); + } + void SetLight(int index, float x, float y, float z, float r) + { + index *= 4; + mLights[index] = x; + mLights[index + 1] = y; + mLights[index + 2] = z; + mLights[index + 3] = r; + } + +protected: // Upload the AABB-tree to the GPU void UploadAABBTree(); - - // Upload light list to the GPU void UploadLights(); // Working buffer for creating the list of lights. Stored here to avoid allocating memory each frame @@ -74,4 +78,6 @@ public: IDataBuffer *mNodesBuffer = nullptr; IDataBuffer *mLinesBuffer = nullptr; + std::function CollectLights = nullptr; + }; diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index 70b1d5e05e..abe499df1b 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -59,6 +59,41 @@ void CleanSWDrawer() swdrawer = nullptr; } +#include "g_levellocals.h" +#include "a_dynlight.h" + + +void CollectLights(FLevelLocals* Level) +{ + IShadowMap* sm = &screen->mShadowMap; + int lightindex = 0; + + // Todo: this should go through the blockmap in a spiral pattern around the player so that closer lights are preferred. + for (auto light = Level->lights; light; light = light->next) + { + IShadowMap::LightsProcessed++; + if (light->shadowmapped && light->IsActive() && lightindex < 1024 * 4) + { + IShadowMap::LightsShadowmapped++; + + light->mShadowmapIndex = lightindex; + sm->SetLight(lightindex, (float)light->X(), (float)light->Y(), (float)light->Z(), light->GetRadius()); + lightindex++; + } + else + { + light->mShadowmapIndex = 1024; + } + + } + + for (; lightindex < 1024; lightindex++) + { + sm->SetLight(lightindex, 0, 0, 0, 0); + } +} + + //----------------------------------------------------------------------------- // // Renders one viewpoint in a scene @@ -75,6 +110,9 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou { screen->SetAABBTree(camera->Level->aabbTree); screen->UpdateShadowMap(); + screen->mShadowMap.SetCollectLights([=] { + CollectLights(camera->Level); + }); } // Update the attenuation flag of all light defaults for each viewpoint. From fde9172ea311bdddc893f15efafc626421e998cb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 20:28:43 +0200 Subject: [PATCH 111/220] - moved shadowmap to 'common'. --- src/CMakeLists.txt | 4 ++-- .../rendering/hwrenderer/data}/hw_aabbtree.cpp | 0 .../rendering/hwrenderer/data}/hw_aabbtree.h | 0 .../rendering/hwrenderer/data}/hw_shadowmap.cpp | 6 +++--- .../rendering/hwrenderer/data}/hw_shadowmap.h | 0 src/rendering/gl/renderer/gl_renderer.h | 2 +- src/rendering/hwrenderer/scene/hw_spritelight.cpp | 2 +- src/rendering/v_video.h | 3 +-- 8 files changed, 8 insertions(+), 9 deletions(-) rename src/{rendering/hwrenderer/dynlights => common/rendering/hwrenderer/data}/hw_aabbtree.cpp (100%) rename src/{rendering/hwrenderer/dynlights => common/rendering/hwrenderer/data}/hw_aabbtree.h (100%) rename src/{rendering/hwrenderer/dynlights => common/rendering/hwrenderer/data}/hw_shadowmap.cpp (97%) rename src/{rendering/hwrenderer/dynlights => common/rendering/hwrenderer/data}/hw_shadowmap.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 899e45fd68..83b8618add 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -946,8 +946,6 @@ set (PCH_SOURCES rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp rendering/hwrenderer/dynlights/doom_aabbtree.cpp - rendering/hwrenderer/dynlights/hw_aabbtree.cpp - rendering/hwrenderer/dynlights/hw_shadowmap.cpp rendering/hwrenderer/models/hw_models.cpp rendering/hwrenderer/scene/hw_skydome.cpp rendering/hwrenderer/scene/hw_drawlistadd.cpp @@ -1135,6 +1133,8 @@ set (PCH_SOURCES common/rendering/hwrenderer/data/hw_cvars.cpp common/rendering/hwrenderer/data/hw_vrmodes.cpp common/rendering/hwrenderer/data/hw_lightbuffer.cpp + common/rendering/hwrenderer/data/hw_aabbtree.cpp + common/rendering/hwrenderer/data/hw_shadowmap.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp common/rendering/gl_load/gl_interface.cpp diff --git a/src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp b/src/common/rendering/hwrenderer/data/hw_aabbtree.cpp similarity index 100% rename from src/rendering/hwrenderer/dynlights/hw_aabbtree.cpp rename to src/common/rendering/hwrenderer/data/hw_aabbtree.cpp diff --git a/src/rendering/hwrenderer/dynlights/hw_aabbtree.h b/src/common/rendering/hwrenderer/data/hw_aabbtree.h similarity index 100% rename from src/rendering/hwrenderer/dynlights/hw_aabbtree.h rename to src/common/rendering/hwrenderer/data/hw_aabbtree.h diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp b/src/common/rendering/hwrenderer/data/hw_shadowmap.cpp similarity index 97% rename from src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp rename to src/common/rendering/hwrenderer/data/hw_shadowmap.cpp index 20b6f53a32..cb5630594a 100644 --- a/src/rendering/hwrenderer/dynlights/hw_shadowmap.cpp +++ b/src/common/rendering/hwrenderer/data/hw_shadowmap.cpp @@ -20,11 +20,11 @@ //-------------------------------------------------------------------------- // -#include "hwrenderer/dynlights/hw_shadowmap.h" +#include "hw_shadowmap.h" #include "hw_cvars.h" #include "hw_dynlightdata.h" -#include "hwrenderer/data/buffers.h" -#include "hwrenderer/data/shaderuniforms.h" +#include "buffers.h" +#include "shaderuniforms.h" #include "hwrenderer/postprocessing/hw_postprocess.h" /* diff --git a/src/rendering/hwrenderer/dynlights/hw_shadowmap.h b/src/common/rendering/hwrenderer/data/hw_shadowmap.h similarity index 100% rename from src/rendering/hwrenderer/dynlights/hw_shadowmap.h rename to src/common/rendering/hwrenderer/data/hw_shadowmap.h diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index ab4e36459b..5831c48668 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -8,7 +8,7 @@ #include "matrix.h" #include "gl_renderbuffers.h" #include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/dynlights/hw_shadowmap.h" +#include "hw_shadowmap.h" #include #ifdef _MSC_VER diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index abbc1a64d5..759f61a7dc 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -33,7 +33,7 @@ #include "g_levellocals.h" #include "actorinlines.h" #include "hw_dynlightdata.h" -#include "hwrenderer/dynlights/hw_shadowmap.h" +#include "hw_shadowmap.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "r_data/models/models.h" diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index ead9eb5a2c..e40d919f1b 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -42,8 +42,7 @@ #include "c_cvars.h" #include "v_2ddrawer.h" #include "intrect.h" - -#include "hwrenderer/dynlights/hw_shadowmap.h" +#include "hw_shadowmap.h" static const int VID_MIN_WIDTH = 320; static const int VID_MIN_HEIGHT = 200; From f8dcb09ff04a27ce949ff7ec4888cb681d384fd0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 21:22:57 +0200 Subject: [PATCH 112/220] - moved postprocessing shaders to their own folder. --- .../postprocessing/hw_postprocess.h | 40 +++++++++---------- src/rendering/gl/renderer/gl_renderer.h | 2 +- src/rendering/gl/shaders/gl_shaderprogram.cpp | 15 +++---- .../shaders/{glsl => pp}/bloomcombine.fp | 0 .../shaders/{glsl => pp}/bloomextract.fp | 0 wadsrc/static/shaders/{glsl => pp}/blur.fp | 0 .../static/shaders/{glsl => pp}/colormap.fp | 0 .../static/shaders/{glsl => pp}/depthblur.fp | 0 .../shaders/{glsl => pp}/exposureaverage.fp | 0 .../shaders/{glsl => pp}/exposurecombine.fp | 0 .../shaders/{glsl => pp}/exposureextract.fp | 0 wadsrc/static/shaders/{glsl => pp}/fxaa.fp | 0 .../shaders/{glsl => pp}/lensdistortion.fp | 0 .../shaders/{glsl => pp}/lineardepth.fp | 0 wadsrc/static/shaders/{glsl => pp}/present.fp | 0 .../shaders/{glsl => pp}/present_checker3d.fp | 0 .../shaders/{glsl => pp}/present_column3d.fp | 0 .../shaders/{glsl => pp}/present_row3d.fp | 0 .../static/shaders/{glsl => pp}/screenquad.vp | 0 .../static/shaders/{glsl => pp}/shadowmap.fp | 0 wadsrc/static/shaders/{glsl => pp}/ssao.fp | 0 .../shaders/{glsl => pp}/ssaocombine.fp | 0 wadsrc/static/shaders/{glsl => pp}/tonemap.fp | 0 23 files changed, 29 insertions(+), 28 deletions(-) rename wadsrc/static/shaders/{glsl => pp}/bloomcombine.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/bloomextract.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/blur.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/colormap.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/depthblur.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/exposureaverage.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/exposurecombine.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/exposureextract.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/fxaa.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/lensdistortion.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/lineardepth.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/present.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/present_checker3d.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/present_column3d.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/present_row3d.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/screenquad.vp (100%) rename wadsrc/static/shaders/{glsl => pp}/shadowmap.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/ssao.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/ssaocombine.fp (100%) rename wadsrc/static/shaders/{glsl => pp}/tonemap.fp (100%) diff --git a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h index 7b715c5b2e..09c0d25534 100644 --- a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h +++ b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.h @@ -304,7 +304,7 @@ public: void ResetBackend() override { Backend.reset(); } - FString VertexShader = "shaders/glsl/screenquad.vp"; + FString VertexShader = "shaders/pp/screenquad.vp"; FString FragmentShader; FString Defines; std::vector Uniforms; @@ -377,10 +377,10 @@ private: int lastWidth = 0; int lastHeight = 0; - PPShader BloomCombine = { "shaders/glsl/bloomcombine.fp", "", {} }; - PPShader BloomExtract = { "shaders/glsl/bloomextract.fp", "", ExtractUniforms::Desc() }; - PPShader BlurVertical = { "shaders/glsl/blur.fp", "#define BLUR_VERTICAL\n", BlurUniforms::Desc() }; - PPShader BlurHorizontal = { "shaders/glsl/blur.fp", "#define BLUR_HORIZONTAL\n", BlurUniforms::Desc() }; + PPShader BloomCombine = { "shaders/pp/bloomcombine.fp", "", {} }; + PPShader BloomExtract = { "shaders/pp/bloomextract.fp", "", ExtractUniforms::Desc() }; + PPShader BlurVertical = { "shaders/pp/blur.fp", "#define BLUR_VERTICAL\n", BlurUniforms::Desc() }; + PPShader BlurHorizontal = { "shaders/pp/blur.fp", "#define BLUR_HORIZONTAL\n", BlurUniforms::Desc() }; }; ///////////////////////////////////////////////////////////////////////////// @@ -413,7 +413,7 @@ public: void Render(PPRenderState *renderstate); private: - PPShader Lens = { "shaders/glsl/lensdistortion.fp", "", LensUniforms::Desc() }; + PPShader Lens = { "shaders/pp/lensdistortion.fp", "", LensUniforms::Desc() }; }; ///////////////////////////////////////////////////////////////////////////// @@ -505,9 +505,9 @@ private: std::vector ExposureLevels; bool FirstExposureFrame = true; - PPShader ExposureExtract = { "shaders/glsl/exposureextract.fp", "", ExposureExtractUniforms::Desc() }; - PPShader ExposureAverage = { "shaders/glsl/exposureaverage.fp", "", {}, 400 }; - PPShader ExposureCombine = { "shaders/glsl/exposurecombine.fp", "", ExposureCombineUniforms::Desc() }; + PPShader ExposureExtract = { "shaders/pp/exposureextract.fp", "", ExposureExtractUniforms::Desc() }; + PPShader ExposureAverage = { "shaders/pp/exposureaverage.fp", "", {}, 400 }; + PPShader ExposureCombine = { "shaders/pp/exposurecombine.fp", "", ExposureCombineUniforms::Desc() }; }; ///////////////////////////////////////////////////////////////////////////// @@ -533,7 +533,7 @@ public: void Render(PPRenderState *renderstate, int fixedcm); private: - PPShader Colormap = { "shaders/glsl/colormap.fp", "", ColormapUniforms::Desc() }; + PPShader Colormap = { "shaders/pp/colormap.fp", "", ColormapUniforms::Desc() }; }; ///////////////////////////////////////////////////////////////////////////// @@ -549,11 +549,11 @@ private: PPTexture PaletteTexture; - PPShader LinearShader = { "shaders/glsl/tonemap.fp", "#define LINEAR\n", {} }; - PPShader ReinhardShader = { "shaders/glsl/tonemap.fp", "#define REINHARD\n", {} }; - PPShader HejlDawsonShader = { "shaders/glsl/tonemap.fp", "#define HEJLDAWSON\n", {} }; - PPShader Uncharted2Shader = { "shaders/glsl/tonemap.fp", "#define UNCHARTED2\n", {} }; - PPShader PaletteShader = { "shaders/glsl/tonemap.fp", "#define PALETTE\n", {} }; + PPShader LinearShader = { "shaders/pp/tonemap.fp", "#define LINEAR\n", {} }; + PPShader ReinhardShader = { "shaders/pp/tonemap.fp", "#define REINHARD\n", {} }; + PPShader HejlDawsonShader = { "shaders/pp/tonemap.fp", "#define HEJLDAWSON\n", {} }; + PPShader Uncharted2Shader = { "shaders/pp/tonemap.fp", "#define UNCHARTED2\n", {} }; + PPShader PaletteShader = { "shaders/pp/tonemap.fp", "#define PALETTE\n", {} }; enum TonemapMode { @@ -754,10 +754,10 @@ public: PPTexture Dither; - PPShader Present = { "shaders/glsl/present.fp", "", PresentUniforms::Desc() }; - PPShader Checker3D = { "shaders/glsl/present_checker3d.fp", "", PresentUniforms::Desc() }; - PPShader Column3D = { "shaders/glsl/present_column3d.fp", "", PresentUniforms::Desc() }; - PPShader Row3D = { "shaders/glsl/present_row3d.fp", "", PresentUniforms::Desc() }; + PPShader Present = { "shaders/pp/present.fp", "", PresentUniforms::Desc() }; + PPShader Checker3D = { "shaders/pp/present_checker3d.fp", "", PresentUniforms::Desc() }; + PPShader Column3D = { "shaders/pp/present_column3d.fp", "", PresentUniforms::Desc() }; + PPShader Row3D = { "shaders/pp/present_row3d.fp", "", PresentUniforms::Desc() }; }; struct ShadowMapUniforms @@ -817,7 +817,7 @@ public: void Update(PPRenderState* renderstate); private: - PPShader ShadowMap = { "shaders/glsl/shadowmap.fp", "", ShadowMapUniforms::Desc() }; + PPShader ShadowMap = { "shaders/pp/shadowmap.fp", "", ShadowMapUniforms::Desc() }; }; diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/rendering/gl/renderer/gl_renderer.h index 5831c48668..4eb59d0882 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/rendering/gl/renderer/gl_renderer.h @@ -89,7 +89,7 @@ public: bool StartOffscreen(); void EndOffscreen(); - void BindToFrameBuffer(FTexture *mat); + void BindToFrameBuffer(FTexture* tex); private: diff --git a/src/rendering/gl/shaders/gl_shaderprogram.cpp b/src/rendering/gl/shaders/gl_shaderprogram.cpp index 0a9e8a7a9a..5bd808dd58 100644 --- a/src/rendering/gl/shaders/gl_shaderprogram.cpp +++ b/src/rendering/gl/shaders/gl_shaderprogram.cpp @@ -27,6 +27,7 @@ #include "gl/shaders/gl_shaderprogram.h" #include "hwrenderer/utility/hw_shaderpatcher.h" #include "filesystem.h" +#include "printf.h" namespace OpenGLRenderer { @@ -296,7 +297,7 @@ void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program FString prolog = Uniforms.CreateDeclaration("Uniforms", PresentUniforms::Desc()); mShader.reset(new FShaderProgram()); - mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", prolog, 330); + mShader->Compile(FShaderProgram::Vertex, "shaders/pp/screenquad.vp", prolog, 330); mShader->Compile(FShaderProgram::Fragment, vtx_shader_name, prolog, 330); mShader->Link(program_name); mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms"); @@ -307,7 +308,7 @@ void FPresentShader::Bind() { if (!mShader) { - Init("shaders/glsl/present.fp", "shaders/glsl/present"); + Init("shaders/pp/present.fp", "shaders/pp/present"); } mShader->Bind(); } @@ -318,7 +319,7 @@ void FPresent3DCheckerShader::Bind() { if (!mShader) { - Init("shaders/glsl/present_checker3d.fp", "shaders/glsl/presentChecker3d"); + Init("shaders/pp/present_checker3d.fp", "shaders/pp/presentChecker3d"); } mShader->Bind(); } @@ -327,7 +328,7 @@ void FPresent3DColumnShader::Bind() { if (!mShader) { - Init("shaders/glsl/present_column3d.fp", "shaders/glsl/presentColumn3d"); + Init("shaders/pp/present_column3d.fp", "shaders/pp/presentColumn3d"); } mShader->Bind(); } @@ -336,7 +337,7 @@ void FPresent3DRowShader::Bind() { if (!mShader) { - Init("shaders/glsl/present_row3d.fp", "shaders/glsl/presentRow3d"); + Init("shaders/pp/present_row3d.fp", "shaders/pp/presentRow3d"); } mShader->Bind(); } @@ -350,8 +351,8 @@ void FShadowMapShader::Bind() FString prolog = Uniforms.CreateDeclaration("Uniforms", ShadowMapUniforms::Desc()); mShader.reset(new FShaderProgram()); - mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 430); - mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/shadowmap.fp", prolog, 430); + mShader->Compile(FShaderProgram::Vertex, "shaders/pp/screenquad.vp", "", 430); + mShader->Compile(FShaderProgram::Fragment, "shaders/pp/shadowmap.fp", prolog, 430); mShader->Link("shaders/glsl/shadowmap"); mShader->SetUniformBufferLocation(Uniforms.BindingPoint(), "Uniforms"); Uniforms.Init(); diff --git a/wadsrc/static/shaders/glsl/bloomcombine.fp b/wadsrc/static/shaders/pp/bloomcombine.fp similarity index 100% rename from wadsrc/static/shaders/glsl/bloomcombine.fp rename to wadsrc/static/shaders/pp/bloomcombine.fp diff --git a/wadsrc/static/shaders/glsl/bloomextract.fp b/wadsrc/static/shaders/pp/bloomextract.fp similarity index 100% rename from wadsrc/static/shaders/glsl/bloomextract.fp rename to wadsrc/static/shaders/pp/bloomextract.fp diff --git a/wadsrc/static/shaders/glsl/blur.fp b/wadsrc/static/shaders/pp/blur.fp similarity index 100% rename from wadsrc/static/shaders/glsl/blur.fp rename to wadsrc/static/shaders/pp/blur.fp diff --git a/wadsrc/static/shaders/glsl/colormap.fp b/wadsrc/static/shaders/pp/colormap.fp similarity index 100% rename from wadsrc/static/shaders/glsl/colormap.fp rename to wadsrc/static/shaders/pp/colormap.fp diff --git a/wadsrc/static/shaders/glsl/depthblur.fp b/wadsrc/static/shaders/pp/depthblur.fp similarity index 100% rename from wadsrc/static/shaders/glsl/depthblur.fp rename to wadsrc/static/shaders/pp/depthblur.fp diff --git a/wadsrc/static/shaders/glsl/exposureaverage.fp b/wadsrc/static/shaders/pp/exposureaverage.fp similarity index 100% rename from wadsrc/static/shaders/glsl/exposureaverage.fp rename to wadsrc/static/shaders/pp/exposureaverage.fp diff --git a/wadsrc/static/shaders/glsl/exposurecombine.fp b/wadsrc/static/shaders/pp/exposurecombine.fp similarity index 100% rename from wadsrc/static/shaders/glsl/exposurecombine.fp rename to wadsrc/static/shaders/pp/exposurecombine.fp diff --git a/wadsrc/static/shaders/glsl/exposureextract.fp b/wadsrc/static/shaders/pp/exposureextract.fp similarity index 100% rename from wadsrc/static/shaders/glsl/exposureextract.fp rename to wadsrc/static/shaders/pp/exposureextract.fp diff --git a/wadsrc/static/shaders/glsl/fxaa.fp b/wadsrc/static/shaders/pp/fxaa.fp similarity index 100% rename from wadsrc/static/shaders/glsl/fxaa.fp rename to wadsrc/static/shaders/pp/fxaa.fp diff --git a/wadsrc/static/shaders/glsl/lensdistortion.fp b/wadsrc/static/shaders/pp/lensdistortion.fp similarity index 100% rename from wadsrc/static/shaders/glsl/lensdistortion.fp rename to wadsrc/static/shaders/pp/lensdistortion.fp diff --git a/wadsrc/static/shaders/glsl/lineardepth.fp b/wadsrc/static/shaders/pp/lineardepth.fp similarity index 100% rename from wadsrc/static/shaders/glsl/lineardepth.fp rename to wadsrc/static/shaders/pp/lineardepth.fp diff --git a/wadsrc/static/shaders/glsl/present.fp b/wadsrc/static/shaders/pp/present.fp similarity index 100% rename from wadsrc/static/shaders/glsl/present.fp rename to wadsrc/static/shaders/pp/present.fp diff --git a/wadsrc/static/shaders/glsl/present_checker3d.fp b/wadsrc/static/shaders/pp/present_checker3d.fp similarity index 100% rename from wadsrc/static/shaders/glsl/present_checker3d.fp rename to wadsrc/static/shaders/pp/present_checker3d.fp diff --git a/wadsrc/static/shaders/glsl/present_column3d.fp b/wadsrc/static/shaders/pp/present_column3d.fp similarity index 100% rename from wadsrc/static/shaders/glsl/present_column3d.fp rename to wadsrc/static/shaders/pp/present_column3d.fp diff --git a/wadsrc/static/shaders/glsl/present_row3d.fp b/wadsrc/static/shaders/pp/present_row3d.fp similarity index 100% rename from wadsrc/static/shaders/glsl/present_row3d.fp rename to wadsrc/static/shaders/pp/present_row3d.fp diff --git a/wadsrc/static/shaders/glsl/screenquad.vp b/wadsrc/static/shaders/pp/screenquad.vp similarity index 100% rename from wadsrc/static/shaders/glsl/screenquad.vp rename to wadsrc/static/shaders/pp/screenquad.vp diff --git a/wadsrc/static/shaders/glsl/shadowmap.fp b/wadsrc/static/shaders/pp/shadowmap.fp similarity index 100% rename from wadsrc/static/shaders/glsl/shadowmap.fp rename to wadsrc/static/shaders/pp/shadowmap.fp diff --git a/wadsrc/static/shaders/glsl/ssao.fp b/wadsrc/static/shaders/pp/ssao.fp similarity index 100% rename from wadsrc/static/shaders/glsl/ssao.fp rename to wadsrc/static/shaders/pp/ssao.fp diff --git a/wadsrc/static/shaders/glsl/ssaocombine.fp b/wadsrc/static/shaders/pp/ssaocombine.fp similarity index 100% rename from wadsrc/static/shaders/glsl/ssaocombine.fp rename to wadsrc/static/shaders/pp/ssaocombine.fp diff --git a/wadsrc/static/shaders/glsl/tonemap.fp b/wadsrc/static/shaders/pp/tonemap.fp similarity index 100% rename from wadsrc/static/shaders/glsl/tonemap.fp rename to wadsrc/static/shaders/pp/tonemap.fp From 1346787e294c433bf337aef89d4e8d20c32336d9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 21:38:34 +0200 Subject: [PATCH 113/220] - moved 2 more modules to 'common'. --- src/CMakeLists.txt | 4 ++-- src/common/rendering/gl/gl_postprocess.cpp | 2 +- src/common/rendering/gl/gl_renderbuffers.cpp | 2 +- .../rendering/gl}/gl_shaderprogram.cpp | 4 ++-- .../rendering/gl}/gl_shaderprogram.h | 2 +- .../hwrenderer/data}/hw_shaderpatcher.cpp | 2 +- .../hwrenderer/data}/hw_shaderpatcher.h | 0 .../postprocessing/hw_postprocess.cpp | 20 +++++++++---------- src/rendering/gl/renderer/gl_renderer.cpp | 2 +- src/rendering/gl/renderer/gl_stereo3d.cpp | 2 +- src/rendering/gl/shaders/gl_shader.cpp | 2 +- src/rendering/gl/system/gl_framebuffer.cpp | 2 +- src/rendering/vulkan/shaders/vk_shader.cpp | 2 +- 13 files changed, 23 insertions(+), 23 deletions(-) rename src/{rendering/gl/shaders => common/rendering/gl}/gl_shaderprogram.cpp (99%) rename src/{rendering/gl/shaders => common/rendering/gl}/gl_shaderprogram.h (98%) rename src/{rendering/hwrenderer/utility => common/rendering/hwrenderer/data}/hw_shaderpatcher.cpp (99%) rename src/{rendering/hwrenderer/utility => common/rendering/hwrenderer/data}/hw_shaderpatcher.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83b8618add..93aa6d264d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -941,7 +941,6 @@ set (PCH_SOURCES rendering/gl/renderer/gl_renderer.cpp rendering/gl/renderer/gl_stereo3d.cpp rendering/gl/shaders/gl_shader.cpp - rendering/gl/shaders/gl_shaderprogram.cpp rendering/gl/system/gl_framebuffer.cpp rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp @@ -955,7 +954,6 @@ set (PCH_SOURCES rendering/hwrenderer/utility/hw_clock.cpp rendering/hwrenderer/utility/hw_draw2d.cpp rendering/hwrenderer/utility/hw_lighting.cpp - rendering/hwrenderer/utility/hw_shaderpatcher.cpp maploader/edata.cpp maploader/specials.cpp maploader/maploader.cpp @@ -1135,6 +1133,7 @@ set (PCH_SOURCES common/rendering/hwrenderer/data/hw_lightbuffer.cpp common/rendering/hwrenderer/data/hw_aabbtree.cpp common/rendering/hwrenderer/data/hw_shadowmap.cpp + common/rendering/hwrenderer/data/hw_shaderpatcher.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp common/rendering/gl_load/gl_interface.cpp @@ -1146,6 +1145,7 @@ set (PCH_SOURCES common/rendering/gl/gl_buffers.cpp common/rendering/gl/gl_hwtexture.cpp common/rendering/gl/gl_samplers.cpp + common/rendering/gl/gl_shaderprogram.cpp common/scripting/core/dictionary.cpp common/scripting/core/dynarrays.cpp common/scripting/core/symbols.cpp diff --git a/src/common/rendering/gl/gl_postprocess.cpp b/src/common/rendering/gl/gl_postprocess.cpp index 90b7cf335c..8b97f51e0e 100644 --- a/src/common/rendering/gl/gl_postprocess.cpp +++ b/src/common/rendering/gl/gl_postprocess.cpp @@ -27,7 +27,7 @@ #include "gl_renderbuffers.h" #include "gl/renderer/gl_renderer.h" #include "gl_postprocessstate.h" -#include "gl/shaders/gl_shaderprogram.h" +#include "gl_shaderprogram.h" #include "hwrenderer/postprocessing/hw_postprocess.h" #include "hwrenderer/postprocessing/hw_postprocess_cvars.h" #include "flatvertices.h" diff --git a/src/common/rendering/gl/gl_renderbuffers.cpp b/src/common/rendering/gl/gl_renderbuffers.cpp index 3cec2c9370..5e212a3bee 100644 --- a/src/common/rendering/gl/gl_renderbuffers.cpp +++ b/src/common/rendering/gl/gl_renderbuffers.cpp @@ -28,7 +28,7 @@ #include "gl/renderer/gl_renderer.h" #include "gl_renderbuffers.h" #include "gl_postprocessstate.h" -#include "gl/shaders/gl_shaderprogram.h" +#include "gl_shaderprogram.h" #include "gl_buffers.h" #include "templates.h" #include diff --git a/src/rendering/gl/shaders/gl_shaderprogram.cpp b/src/common/rendering/gl/gl_shaderprogram.cpp similarity index 99% rename from src/rendering/gl/shaders/gl_shaderprogram.cpp rename to src/common/rendering/gl/gl_shaderprogram.cpp index 5bd808dd58..eb322fb942 100644 --- a/src/rendering/gl/shaders/gl_shaderprogram.cpp +++ b/src/common/rendering/gl/gl_shaderprogram.cpp @@ -24,8 +24,8 @@ #include "gl_interface.h" #include "hw_cvars.h" #include "gl_debug.h" -#include "gl/shaders/gl_shaderprogram.h" -#include "hwrenderer/utility/hw_shaderpatcher.h" +#include "gl_shaderprogram.h" +#include "hw_shaderpatcher.h" #include "filesystem.h" #include "printf.h" diff --git a/src/rendering/gl/shaders/gl_shaderprogram.h b/src/common/rendering/gl/gl_shaderprogram.h similarity index 98% rename from src/rendering/gl/shaders/gl_shaderprogram.h rename to src/common/rendering/gl/gl_shaderprogram.h index 90e2572974..da45250525 100644 --- a/src/rendering/gl/shaders/gl_shaderprogram.h +++ b/src/common/rendering/gl/gl_shaderprogram.h @@ -2,7 +2,7 @@ #pragma once #include "gl_system.h" -#include "gl_shader.h" +#include "gl/shaders/gl_shader.h" #include "hwrenderer/postprocessing/hw_postprocess.h" namespace OpenGLRenderer diff --git a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp similarity index 99% rename from src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp rename to src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp index 53fc73a57d..0362306d35 100644 --- a/src/rendering/hwrenderer/utility/hw_shaderpatcher.cpp +++ b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.cpp @@ -66,7 +66,7 @@ static FString NextGlslToken(const char *chars, long len, long &pos) pos = tokenEnd; return FString(chars + tokenStart, tokenEnd - tokenStart); -} +} static bool isShaderType(const char *name) { diff --git a/src/rendering/hwrenderer/utility/hw_shaderpatcher.h b/src/common/rendering/hwrenderer/data/hw_shaderpatcher.h similarity index 100% rename from src/rendering/hwrenderer/utility/hw_shaderpatcher.h rename to src/common/rendering/hwrenderer/data/hw_shaderpatcher.h diff --git a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp index a206a4c166..1dc670de0b 100644 --- a/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp +++ b/src/common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp @@ -395,8 +395,8 @@ void PPFXAA::CreateShaders() if (LastQuality == gl_fxaa) return; - FXAALuma = { "shaders/glsl/fxaa.fp", "#define FXAA_LUMA_PASS\n", {} }; - FXAA = { "shaders/glsl/fxaa.fp", GetDefines(), FXAAUniforms::Desc(), GetMaxVersion() }; + FXAALuma = { "shaders/pp/fxaa.fp", "#define FXAA_LUMA_PASS\n", {} }; + FXAA = { "shaders/pp/fxaa.fp", GetDefines(), FXAAUniforms::Desc(), GetMaxVersion() }; LastQuality = gl_fxaa; } @@ -681,14 +681,14 @@ void PPAmbientOcclusion::CreateShaders() #define NUM_STEPS %d.0 )", numDirections, numSteps); - LinearDepth = { "shaders/glsl/lineardepth.fp", "", LinearDepthUniforms::Desc() }; - LinearDepthMS = { "shaders/glsl/lineardepth.fp", "#define MULTISAMPLE\n", LinearDepthUniforms::Desc() }; - AmbientOcclude = { "shaders/glsl/ssao.fp", defines, SSAOUniforms::Desc() }; - AmbientOccludeMS = { "shaders/glsl/ssao.fp", defines + "\n#define MULTISAMPLE\n", SSAOUniforms::Desc() }; - BlurVertical = { "shaders/glsl/depthblur.fp", "#define BLUR_VERTICAL\n", DepthBlurUniforms::Desc() }; - BlurHorizontal = { "shaders/glsl/depthblur.fp", "#define BLUR_HORIZONTAL\n", DepthBlurUniforms::Desc() }; - Combine = { "shaders/glsl/ssaocombine.fp", "", AmbientCombineUniforms::Desc() }; - CombineMS = { "shaders/glsl/ssaocombine.fp", "#define MULTISAMPLE\n", AmbientCombineUniforms::Desc() }; + LinearDepth = { "shaders/pp/lineardepth.fp", "", LinearDepthUniforms::Desc() }; + LinearDepthMS = { "shaders/pp/lineardepth.fp", "#define MULTISAMPLE\n", LinearDepthUniforms::Desc() }; + AmbientOcclude = { "shaders/pp/ssao.fp", defines, SSAOUniforms::Desc() }; + AmbientOccludeMS = { "shaders/pp/ssao.fp", defines + "\n#define MULTISAMPLE\n", SSAOUniforms::Desc() }; + BlurVertical = { "shaders/pp/depthblur.fp", "#define BLUR_VERTICAL\n", DepthBlurUniforms::Desc() }; + BlurHorizontal = { "shaders/pp/depthblur.fp", "#define BLUR_HORIZONTAL\n", DepthBlurUniforms::Desc() }; + Combine = { "shaders/pp/ssaocombine.fp", "", AmbientCombineUniforms::Desc() }; + CombineMS = { "shaders/pp/ssaocombine.fp", "#define MULTISAMPLE\n", AmbientCombineUniforms::Desc() }; LastQuality = gl_ssao; } diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 3562714660..624a5ef9ce 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -55,7 +55,7 @@ #include "gl/renderer/gl_renderer.h" #include "gl_renderstate.h" #include "gl_renderbuffers.h" -#include "gl/shaders/gl_shaderprogram.h" +#include "gl_shaderprogram.h" #include "hw_vrmodes.h" #include "flatvertices.h" #include "hwrenderer/scene/hw_skydome.h" diff --git a/src/rendering/gl/renderer/gl_stereo3d.cpp b/src/rendering/gl/renderer/gl_stereo3d.cpp index df6cb11ce3..8bcb2768fc 100644 --- a/src/rendering/gl/renderer/gl_stereo3d.cpp +++ b/src/rendering/gl/renderer/gl_stereo3d.cpp @@ -32,7 +32,7 @@ #include "gl/system/gl_framebuffer.h" #include "gl_postprocessstate.h" #include "gl/system/gl_framebuffer.h" -#include "gl/shaders/gl_shaderprogram.h" +#include "gl_shaderprogram.h" #include "gl_buffers.h" #include "menu/menu.h" diff --git a/src/rendering/gl/shaders/gl_shader.cpp b/src/rendering/gl/shaders/gl_shader.cpp index 125fbb964a..9a30674fd2 100644 --- a/src/rendering/gl/shaders/gl_shader.cpp +++ b/src/rendering/gl/shaders/gl_shader.cpp @@ -35,7 +35,7 @@ #include "md5.h" #include "m_misc.h" #include "gl/shaders/gl_shader.h" -#include "hwrenderer/utility/hw_shaderpatcher.h" +#include "hw_shaderpatcher.h" #include "hwrenderer/data/shaderuniforms.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" #include "hw_lightbuffer.h" diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 814a2ace52..9f3210f68b 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -51,7 +51,7 @@ #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hw_lightbuffer.h" -#include "gl/shaders/gl_shaderprogram.h" +#include "gl_shaderprogram.h" #include "gl_debug.h" #include "r_videoscale.h" #include "gl_buffers.h" diff --git a/src/rendering/vulkan/shaders/vk_shader.cpp b/src/rendering/vulkan/shaders/vk_shader.cpp index d7b461cf10..8162cf7b32 100644 --- a/src/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/rendering/vulkan/shaders/vk_shader.cpp @@ -22,7 +22,7 @@ #include "vk_shader.h" #include "vulkan/system/vk_builders.h" -#include "hwrenderer/utility/hw_shaderpatcher.h" +#include "hw_shaderpatcher.h" #include "filesystem.h" #include "engineerrors.h" #include From cb1e8a177fa5b455f92cf1a3b8cb522d80c38814 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 22:24:27 +0200 Subject: [PATCH 114/220] - moved gl_shader.cpp to 'common'. --- src/CMakeLists.txt | 2 +- src/common/rendering/gl/gl_renderstate.cpp | 2 +- .../gl/shaders => common/rendering/gl}/gl_shader.cpp | 3 +-- .../gl/shaders => common/rendering/gl}/gl_shader.h | 0 src/common/rendering/gl/gl_shaderprogram.h | 2 +- src/rendering/gl/renderer/gl_renderer.cpp | 8 +------- src/rendering/v_framebuffer.cpp | 2 +- 7 files changed, 6 insertions(+), 13 deletions(-) rename src/{rendering/gl/shaders => common/rendering/gl}/gl_shader.cpp (99%) rename src/{rendering/gl/shaders => common/rendering/gl}/gl_shader.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93aa6d264d..3f1449ddf4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -940,7 +940,6 @@ set (PCH_SOURCES rendering/2d/v_blend.cpp rendering/gl/renderer/gl_renderer.cpp rendering/gl/renderer/gl_stereo3d.cpp - rendering/gl/shaders/gl_shader.cpp rendering/gl/system/gl_framebuffer.cpp rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp @@ -1145,6 +1144,7 @@ set (PCH_SOURCES common/rendering/gl/gl_buffers.cpp common/rendering/gl/gl_hwtexture.cpp common/rendering/gl/gl_samplers.cpp + common/rendering/gl/gl_shader.cpp common/rendering/gl/gl_shaderprogram.cpp common/scripting/core/dictionary.cpp common/scripting/core/dynarrays.cpp diff --git a/src/common/rendering/gl/gl_renderstate.cpp b/src/common/rendering/gl/gl_renderstate.cpp index 8de101c2f8..555dbba918 100644 --- a/src/common/rendering/gl/gl_renderstate.cpp +++ b/src/common/rendering/gl/gl_renderstate.cpp @@ -33,7 +33,7 @@ #include "hw_cvars.h" #include "flatvertices.h" #include "hwrenderer/scene/hw_skydome.h" -#include "gl/shaders/gl_shader.h" +#include "gl_shader.h" #include "gl/renderer/gl_renderer.h" #include "hw_lightbuffer.h" #include "gl_renderbuffers.h" diff --git a/src/rendering/gl/shaders/gl_shader.cpp b/src/common/rendering/gl/gl_shader.cpp similarity index 99% rename from src/rendering/gl/shaders/gl_shader.cpp rename to src/common/rendering/gl/gl_shader.cpp index 9a30674fd2..844f979d72 100644 --- a/src/rendering/gl/shaders/gl_shader.cpp +++ b/src/common/rendering/gl/gl_shader.cpp @@ -34,7 +34,7 @@ #include "cmdlib.h" #include "md5.h" #include "m_misc.h" -#include "gl/shaders/gl_shader.h" +#include "gl_shader.h" #include "hw_shaderpatcher.h" #include "hwrenderer/data/shaderuniforms.h" #include "hwrenderer/scene/hw_viewpointuniforms.h" @@ -44,7 +44,6 @@ #include "gl_debug.h" #include "matrix.h" #include "gl/renderer/gl_renderer.h" -#include "gl/shaders/gl_shader.h" #include #include diff --git a/src/rendering/gl/shaders/gl_shader.h b/src/common/rendering/gl/gl_shader.h similarity index 100% rename from src/rendering/gl/shaders/gl_shader.h rename to src/common/rendering/gl/gl_shader.h diff --git a/src/common/rendering/gl/gl_shaderprogram.h b/src/common/rendering/gl/gl_shaderprogram.h index da45250525..90e2572974 100644 --- a/src/common/rendering/gl/gl_shaderprogram.h +++ b/src/common/rendering/gl/gl_shaderprogram.h @@ -2,7 +2,7 @@ #pragma once #include "gl_system.h" -#include "gl/shaders/gl_shader.h" +#include "gl_shader.h" #include "hwrenderer/postprocessing/hw_postprocess.h" namespace OpenGLRenderer diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 624a5ef9ce..e35446e796 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -30,22 +30,16 @@ ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **--------------------------------------------------------------------------- ** -*/ +*/ #include "gl_system.h" #include "files.h" #include "v_video.h" #include "m_png.h" #include "filesystem.h" -#include "doomstat.h" #include "i_time.h" -#include "p_effect.h" -#include "d_player.h" -#include "a_dynlight.h" #include "cmdlib.h" #include "version.h" -#include "g_game.h" -#include "swrenderer/r_swscene.h" #include "hwrenderer/utility/hw_clock.h" #include "gl_interface.h" diff --git a/src/rendering/v_framebuffer.cpp b/src/rendering/v_framebuffer.cpp index bedab9d88a..bd08acc852 100644 --- a/src/rendering/v_framebuffer.cpp +++ b/src/rendering/v_framebuffer.cpp @@ -355,7 +355,7 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds) int screenWidth = GetWidth(); int screenHeight = GetHeight(); float scaleX, scaleY; - scaleX = MIN(clientWidth / (float)screenWidth, clientHeight / ((float)screenHeight * ViewportPixelAspect())); + scaleX = std::min(clientWidth / (float)screenWidth, clientHeight / ((float)screenHeight * ViewportPixelAspect())); scaleY = scaleX * ViewportPixelAspect(); mOutputLetterbox.width = (int)round(screenWidth * scaleX); mOutputLetterbox.height = (int)round(screenHeight * scaleY); From b58e3172fc9df4c128062fab4c2bd33175135d3e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 26 Apr 2020 23:02:16 +0200 Subject: [PATCH 115/220] - need hw_viewpointuniforms.h as well in 'common', after decoupling it from game data. --- src/common/rendering/gl/gl_shader.cpp | 2 +- .../hwrenderer/data/hw_viewpointbuffer.cpp | 13 ++++++-- .../hwrenderer/data}/hw_viewpointuniforms.h | 4 --- .../hwrenderer/scene/hw_drawinfo.cpp | 32 +++++++------------ .../polyrenderer/backend/poly_renderstate.cpp | 2 +- .../polyrenderer/drawers/poly_vertex_shader.h | 2 +- .../vulkan/renderer/vk_renderpass.cpp | 2 +- .../vulkan/renderer/vk_renderstate.cpp | 2 +- 8 files changed, 27 insertions(+), 32 deletions(-) rename src/{rendering/hwrenderer/scene => common/rendering/hwrenderer/data}/hw_viewpointuniforms.h (87%) diff --git a/src/common/rendering/gl/gl_shader.cpp b/src/common/rendering/gl/gl_shader.cpp index 844f979d72..3fd70d3886 100644 --- a/src/common/rendering/gl/gl_shader.cpp +++ b/src/common/rendering/gl/gl_shader.cpp @@ -37,7 +37,7 @@ #include "gl_shader.h" #include "hw_shaderpatcher.h" #include "hwrenderer/data/shaderuniforms.h" -#include "hwrenderer/scene/hw_viewpointuniforms.h" +#include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" #include "gl_interface.h" diff --git a/src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp b/src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp index 01e3e626ea..d112842280 100644 --- a/src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp +++ b/src/common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp @@ -26,9 +26,10 @@ **/ #include "hwrenderer/data/shaderuniforms.h" -#include "hwrenderer/scene/hw_viewpointuniforms.h" +#include "hw_viewpointuniforms.h" #include "hw_renderstate.h" #include "hw_viewpointbuffer.h" +#include "hw_cvars.h" static const int INITIAL_BUFFER_SIZE = 100; // 100 viewpoints per frame should nearly always be enough @@ -77,7 +78,15 @@ void HWViewpointBuffer::Set2D(FRenderState &di, int width, int height) if (width != m2DWidth || height != m2DHeight) { HWViewpointUniforms matrices; - matrices.SetDefaults(nullptr); + + matrices.mViewMatrix.loadIdentity(); + matrices.mNormalViewMatrix.loadIdentity(); + matrices.mViewHeight = 0; + matrices.mGlobVis = 1.f; + matrices.mPalLightLevels = 0; + matrices.mClipLine.X = -10000000.0f; + matrices.mShadowmapFilter = gl_shadowmap_filter; + matrices.mProjectionMatrix.ortho(0, (float)width, (float)height, 0, -1.0f, 1.0f); matrices.CalcDependencies(); mBuffer->Map(); diff --git a/src/rendering/hwrenderer/scene/hw_viewpointuniforms.h b/src/common/rendering/hwrenderer/data/hw_viewpointuniforms.h similarity index 87% rename from src/rendering/hwrenderer/scene/hw_viewpointuniforms.h rename to src/common/rendering/hwrenderer/data/hw_viewpointuniforms.h index 5a1a1749d1..3d28f5c4af 100644 --- a/src/rendering/hwrenderer/scene/hw_viewpointuniforms.h +++ b/src/common/rendering/hwrenderer/data/hw_viewpointuniforms.h @@ -1,7 +1,6 @@ #pragma once #include "matrix.h" -#include "r_utility.h" struct HWDrawInfo; @@ -24,9 +23,6 @@ struct HWViewpointUniforms { mNormalViewMatrix.computeNormalMatrix(mViewMatrix); } - - void SetDefaults(HWDrawInfo *drawInfo); - }; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 1335ffa8e1..18204307f2 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -139,7 +139,17 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni VPUniforms.mClipLine.X = -1000001.f; VPUniforms.mClipHeight = 0; } - else VPUniforms.SetDefaults(this); + else + { + VPUniforms.mProjectionMatrix.loadIdentity(); + VPUniforms.mViewMatrix.loadIdentity(); + VPUniforms.mNormalViewMatrix.loadIdentity(); + VPUniforms.mViewHeight = viewheight; + VPUniforms.mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f; + VPUniforms.mPalLightLevels = static_cast(gl_bandedswlight) | (static_cast(gl_fogmode) << 8) | ((int)lightmode << 16); + VPUniforms.mClipLine.X = -10000000.0f; + VPUniforms.mShadowmapFilter = gl_shadowmap_filter; + } mClipper->SetViewpoint(Viewpoint); ClearBuffers(); @@ -391,26 +401,6 @@ HWPortal * HWDrawInfo::FindPortal(const void * src) // //----------------------------------------------------------------------------- -void HWViewpointUniforms::SetDefaults(HWDrawInfo *drawInfo) -{ - mProjectionMatrix.loadIdentity(); - mViewMatrix.loadIdentity(); - mNormalViewMatrix.loadIdentity(); - mViewHeight = viewheight; - mGlobVis = (float)R_GetGlobVis(r_viewwindow, r_visibility) / 32.f; - const int lightMode = drawInfo == nullptr ? static_cast(*gl_lightmode) : static_cast(drawInfo->lightmode); - mPalLightLevels = static_cast(gl_bandedswlight) | (static_cast(gl_fogmode) << 8) | (lightMode << 16); - mClipLine.X = -10000000.0f; - mShadowmapFilter = gl_shadowmap_filter; - -} - -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - HWDecal *HWDrawInfo::AddDecal(bool onmirror) { auto decal = (HWDecal*)RenderDataAllocator.Alloc(sizeof(HWDecal)); diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index cd13c3c48a..5f4cf463d4 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -27,7 +27,7 @@ #include "doomstat.h" #include "r_data/colormaps.h" #include "hwrenderer/scene/hw_skydome.h" -#include "hwrenderer/scene/hw_viewpointuniforms.h" +#include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" #include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" diff --git a/src/rendering/polyrenderer/drawers/poly_vertex_shader.h b/src/rendering/polyrenderer/drawers/poly_vertex_shader.h index 22539e9725..8ae178127f 100644 --- a/src/rendering/polyrenderer/drawers/poly_vertex_shader.h +++ b/src/rendering/polyrenderer/drawers/poly_vertex_shader.h @@ -1,7 +1,7 @@ #pragma once -#include "hwrenderer/scene/hw_viewpointuniforms.h" +#include "hw_viewpointuniforms.h" #include "hw_renderstate.h" #ifndef NO_SSE diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/rendering/vulkan/renderer/vk_renderpass.cpp index 24a3968aa4..53b1cd732b 100644 --- a/src/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/rendering/vulkan/renderer/vk_renderpass.cpp @@ -29,7 +29,7 @@ #include "vulkan/system/vk_framebuffer.h" #include "vulkan/system/vk_buffers.h" #include "flatvertices.h" -#include "hwrenderer/scene/hw_viewpointuniforms.h" +#include "hw_viewpointuniforms.h" #include "v_2ddrawer.h" VkRenderPassManager::VkRenderPassManager() diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 52a458d184..8a0223552a 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -30,7 +30,7 @@ #include "doomstat.h" #include "r_data/colormaps.h" #include "hwrenderer/scene/hw_skydome.h" -#include "hwrenderer/scene/hw_viewpointuniforms.h" +#include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" #include "hw_cvars.h" #include "hwrenderer/utility/hw_clock.h" From 67a50d084a15b4c3f461e8747abf552d19a74cee Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 00:03:23 +0200 Subject: [PATCH 116/220] - started cleanup of model code. * refactored FBoundingBox so that the game dependent members are global functions now. * changed some methods of the model renderer to take a render style parameter instead of a full actor. --- src/common/rendering/gl/gl_buffers.cpp | 1 + src/common/rendering/gl/gl_renderstate.h | 7 +-- src/common/rendering/gl/gl_shader.cpp | 5 +- .../rendering/hwrenderer/data/hw_cvars.cpp | 6 +++ .../hwrenderer/data/hw_renderstate.h | 1 - src/gamedata/r_defs.h | 10 ++-- src/playsim/p_enemy.cpp | 4 +- src/playsim/p_map.cpp | 10 ++-- src/playsim/p_maputl.cpp | 49 +++++++++++++++++++ src/playsim/p_maputl.h | 2 + src/playsim/p_secnodes.cpp | 4 +- src/playsim/po_man.cpp | 2 +- src/playsim/portal.cpp | 4 +- src/playsim/portal.h | 3 ++ src/r_data/models/modelrenderer.h | 37 ++++++++++++++ src/r_data/models/models.cpp | 11 +++-- src/r_data/models/models.h | 48 ++++-------------- src/r_data/models/models_md2.cpp | 5 +- src/r_data/models/models_md3.cpp | 5 +- src/r_data/models/models_obj.cpp | 5 +- src/r_data/models/models_ue1.cpp | 5 +- src/r_data/models/models_voxel.cpp | 9 ++-- src/rendering/hwrenderer/hw_entrypoint.cpp | 1 + src/rendering/hwrenderer/models/hw_models.cpp | 18 +++---- src/rendering/hwrenderer/models/hw_models.h | 9 ++-- .../hwrenderer/utility/hw_lighting.cpp | 7 --- src/rendering/swrenderer/things/r_model.cpp | 16 +++--- src/rendering/swrenderer/things/r_model.h | 8 +-- src/utility/m_bbox.cpp | 48 ------------------ src/utility/m_bbox.h | 7 --- 30 files changed, 179 insertions(+), 168 deletions(-) create mode 100644 src/r_data/models/modelrenderer.h diff --git a/src/common/rendering/gl/gl_buffers.cpp b/src/common/rendering/gl/gl_buffers.cpp index 1f88195bf3..9b49d431ad 100644 --- a/src/common/rendering/gl/gl_buffers.cpp +++ b/src/common/rendering/gl/gl_buffers.cpp @@ -37,6 +37,7 @@ #include "gl_buffers.h" #include "gl_renderstate.h" #include "v_video.h" +#include "flatvertices.h" namespace OpenGLRenderer { diff --git a/src/common/rendering/gl/gl_renderstate.h b/src/common/rendering/gl/gl_renderstate.h index 7c66eb87fb..948255d710 100644 --- a/src/common/rendering/gl/gl_renderstate.h +++ b/src/common/rendering/gl/gl_renderstate.h @@ -23,16 +23,13 @@ #ifndef __GL_RENDERSTATE_H #define __GL_RENDERSTATE_H +#include #include #include "gl_interface.h" #include "matrix.h" -#include "hwrenderer/scene//hw_drawstructs.h" #include "hw_renderstate.h" #include "hw_material.h" #include "c_cvars.h" -#include "r_defs.h" -#include "r_data/r_translate.h" -#include "g_levellocals.h" namespace OpenGLRenderer { @@ -110,7 +107,7 @@ public: void EnableDrawBuffers(int count, bool apply = false) override { - count = MIN(count, 3); + count = std::min(count, 3); if (mNumDrawBuffers != count) { static GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; diff --git a/src/common/rendering/gl/gl_shader.cpp b/src/common/rendering/gl/gl_shader.cpp index 3fd70d3886..4bf727efd9 100644 --- a/src/common/rendering/gl/gl_shader.cpp +++ b/src/common/rendering/gl/gl_shader.cpp @@ -33,12 +33,13 @@ #include "engineerrors.h" #include "cmdlib.h" #include "md5.h" -#include "m_misc.h" #include "gl_shader.h" #include "hw_shaderpatcher.h" -#include "hwrenderer/data/shaderuniforms.h" +#include "shaderuniforms.h" #include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" +#include "i_specialpaths.h" +#include "printf.h" #include "gl_interface.h" #include "gl_debug.h" diff --git a/src/common/rendering/hwrenderer/data/hw_cvars.cpp b/src/common/rendering/hwrenderer/data/hw_cvars.cpp index 2d5d4a9f29..74edce16b3 100644 --- a/src/common/rendering/hwrenderer/data/hw_cvars.cpp +++ b/src/common/rendering/hwrenderer/data/hw_cvars.cpp @@ -43,6 +43,12 @@ #include "menu/menu.h" +CUSTOM_CVAR(Int, gl_fogmode, 1, CVAR_ARCHIVE | CVAR_NOINITCALL) +{ + if (self > 2) self = 2; + if (self < 0) self = 0; +} + // OpenGL stuff moved here // GL related CVARs diff --git a/src/common/rendering/hwrenderer/data/hw_renderstate.h b/src/common/rendering/hwrenderer/data/hw_renderstate.h index 24692656ae..5da24d2098 100644 --- a/src/common/rendering/hwrenderer/data/hw_renderstate.h +++ b/src/common/rendering/hwrenderer/data/hw_renderstate.h @@ -1,6 +1,5 @@ #pragma once -#include "v_palette.h" #include "vectors.h" #include "matrix.h" #include "hw_material.h" diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index a0045cc8d7..f26724dec8 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -1652,12 +1652,12 @@ typedef uint8_t lighttable_t; // This could be wider for >8 bit display. // //---------------------------------------------------------------------------------- -inline bool FBoundingBox::inRange(const line_t *ld) const +inline bool inRange(const FBoundingBox &box, const line_t *ld) { - return Left() < ld->bbox[BOXRIGHT] && - Right() > ld->bbox[BOXLEFT] && - Top() > ld->bbox[BOXBOTTOM] && - Bottom() < ld->bbox[BOXTOP]; + return box.Left() < ld->bbox[BOXRIGHT] && + box.Right() > ld->bbox[BOXLEFT] && + box.Top() > ld->bbox[BOXBOTTOM] && + box.Bottom() < ld->bbox[BOXTOP]; } diff --git a/src/playsim/p_enemy.cpp b/src/playsim/p_enemy.cpp index 7089c74e25..ee3b9ed14f 100644 --- a/src/playsim/p_enemy.cpp +++ b/src/playsim/p_enemy.cpp @@ -875,8 +875,8 @@ void P_NewChaseDir(AActor * actor) while ((line = it.Next())) { if (line->backsector && // Ignore one-sided linedefs - box.inRange(line) && - box.BoxOnLineSide(line) == -1) + inRange(box, line) && + BoxOnLineSide(box, line) == -1) { double front = line->frontsector->floorplane.ZatPoint(actor->PosRelative(line)); double back = line->backsector->floorplane.ZatPoint(actor->PosRelative(line)); diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index ae0eecef0c..bb08c0ad3f 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -204,7 +204,7 @@ static bool PIT_FindFloorCeiling(FMultiBlockLinesIterator &mit, FMultiBlockLines { line_t *ld = cres.line; - if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1) + if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1) return true; // A line has been hit @@ -776,7 +776,7 @@ bool PIT_CheckLine(FMultiBlockLinesIterator &mit, FMultiBlockLinesIterator::Chec line_t *ld = cres.line; bool rail = false; - if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1) + if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1) return true; // A line has been hit @@ -1073,7 +1073,7 @@ static bool PIT_CheckPortal(FMultiBlockLinesIterator &mit, FMultiBlockLinesItera // if in another vertical section let's just ignore it. if (cres.portalflags & (FFCF_NOCEILING | FFCF_NOFLOOR)) return false; - if (!box.inRange(cres.line) || box.BoxOnLineSide(cres.line) != -1) + if (!inRange(box, cres.line) || BoxOnLineSide(box, cres.line) != -1) return false; line_t *lp = cres.line->getPortalDestination(); @@ -1095,7 +1095,7 @@ static bool PIT_CheckPortal(FMultiBlockLinesIterator &mit, FMultiBlockLinesItera // Check all lines at the destination while ((ld = it.Next())) { - if (!pbox.inRange(ld) || pbox.BoxOnLineSide(ld) != -1) + if (!inRange(pbox, ld) || BoxOnLineSide(pbox, ld) != -1) continue; if (ld->backsector == NULL) @@ -3453,7 +3453,7 @@ bool FSlide::BounceWall(AActor *mo) movelen = mo->Vel.XY().Length() * mo->wallbouncefactor; FBoundingBox box(mo->X(), mo->Y(), mo->radius); - if (box.BoxOnLineSide(line) == -1) + if (BoxOnLineSide(box, line) == -1) { DVector2 ofs = deltaangle.ToVector(mo->radius); DVector3 pos = mo->Vec3Offset(ofs.X, ofs.Y, 0.); diff --git a/src/playsim/p_maputl.cpp b/src/playsim/p_maputl.cpp index cb21be2e35..ffc7a1f430 100644 --- a/src/playsim/p_maputl.cpp +++ b/src/playsim/p_maputl.cpp @@ -2017,3 +2017,52 @@ subsector_t *FLevelLocals::PointInRenderSubsector (fixed_t x, fixed_t y) return (subsector_t *)((uint8_t *)node - 1); } + +//========================================================================== +// +// FBoundingBox :: BoxOnLineSide +// +// Considers the line to be infinite +// Returns side 0 or 1, -1 if box crosses the line. +// +//========================================================================== + +int BoxOnLineSide(const FBoundingBox &box, const line_t* ld) +{ + int p1; + int p2; + + if (ld->Delta().X == 0) + { // ST_VERTICAL + p1 = box.Right() < ld->v1->fX(); + p2 = box.Left() < ld->v1->fX(); + if (ld->Delta().Y < 0) + { + p1 ^= 1; + p2 ^= 1; + } + } + else if (ld->Delta().Y == 0) + { // ST_HORIZONTAL: + p1 = box.Top() > ld->v1->fY(); + p2 = box.Bottom() > ld->v1->fY(); + if (ld->Delta().X < 0) + { + p1 ^= 1; + p2 ^= 1; + } + } + else if ((ld->Delta().X * ld->Delta().Y) >= 0) + { // ST_POSITIVE: + p1 = P_PointOnLineSide(box.Left(), box.Top(), ld); + p2 = P_PointOnLineSide(box.Right(), box.Bottom(), ld); + } + else + { // ST_NEGATIVE: + p1 = P_PointOnLineSide(box.Right(), box.Top(), ld); + p2 = P_PointOnLineSide(box.Left(), box.Bottom(), ld); + } + + return (p1 == p2) ? p1 : -1; +} + diff --git a/src/playsim/p_maputl.h b/src/playsim/p_maputl.h index 7bbf4f83aa..e293f317fb 100644 --- a/src/playsim/p_maputl.h +++ b/src/playsim/p_maputl.h @@ -417,4 +417,6 @@ double P_InterceptVector(const divline_t *v2, const divline_t *v1); #define PT_COMPATIBLE 4 #define PT_DELTA 8 // x2,y2 is passed as a delta, not as an endpoint +int BoxOnLineSide(const FBoundingBox& box, const line_t* ld); + #endif diff --git a/src/playsim/p_secnodes.cpp b/src/playsim/p_secnodes.cpp index bdbc99eabc..3e479e77ce 100644 --- a/src/playsim/p_secnodes.cpp +++ b/src/playsim/p_secnodes.cpp @@ -242,7 +242,7 @@ msecnode_t *P_CreateSecNodeList(AActor *thing, double radius, msecnode_t *sector while ((ld = it.Next())) { - if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1) + if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1) continue; // This line crosses through the object. @@ -398,7 +398,7 @@ void AActor::UpdateRenderSectorList() for (auto &p : Level->linePortals) { if (p.mType == PORTT_VISUAL) continue; - if (bb.inRange(p.mOrigin) && bb.BoxOnLineSide(p.mOrigin)) + if (inRange(bb, p.mOrigin) && BoxOnLineSide(bb, p.mOrigin)) { touching_lineportallist = P_AddPortalnode(&p, this, touching_lineportallist); } diff --git a/src/playsim/po_man.cpp b/src/playsim/po_man.cpp index 1c6eac3d9d..14b84e1a03 100644 --- a/src/playsim/po_man.cpp +++ b/src/playsim/po_man.cpp @@ -1103,7 +1103,7 @@ bool FPolyObj::CheckMobjBlocking (side_t *sd) DVector2 pos = mobj->PosRelative(ld); FBoundingBox box(pos.X, pos.Y, mobj->radius); - if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1) + if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1) { continue; } diff --git a/src/playsim/portal.cpp b/src/playsim/portal.cpp index 5076e0a984..6a0170111d 100644 --- a/src/playsim/portal.cpp +++ b/src/playsim/portal.cpp @@ -1079,7 +1079,7 @@ bool FLevelLocals::CollectConnectedGroups(int startgroup, const DVector3 &positi FBoundingBox box(position.X + disp.pos.X, position.Y + disp.pos.Y, checkradius); - if (!box.inRange(ld) || box.BoxOnLineSide(linkedPortals[i]->mOrigin) != -1) continue; // not touched + if (!inRange(box, ld) || BoxOnLineSide(box, linkedPortals[i]->mOrigin) != -1) continue; // not touched foundPortals.Push(linkedPortals[i]); } bool foundone = true; @@ -1138,7 +1138,7 @@ bool FLevelLocals::CollectConnectedGroups(int startgroup, const DVector3 &positi line_t *ld; while ((ld = it.Next())) { - if (!box.inRange(ld) || box.BoxOnLineSide(ld) != -1) + if (!inRange(box, ld) || BoxOnLineSide(box, ld) != -1) continue; if (!(thisgroup & FPortalGroupArray::LOWER)) diff --git a/src/playsim/portal.h b/src/playsim/portal.h index 9d3873b718..abffde16ba 100644 --- a/src/playsim/portal.h +++ b/src/playsim/portal.h @@ -4,6 +4,9 @@ #include "basics.h" #include "m_bbox.h" +struct line_t; +struct sector_t; + struct FPortalGroupArray; struct portnode_t; struct subsector_t; diff --git a/src/r_data/models/modelrenderer.h b/src/r_data/models/modelrenderer.h new file mode 100644 index 0000000000..848890c8e9 --- /dev/null +++ b/src/r_data/models/modelrenderer.h @@ -0,0 +1,37 @@ + +#include "models.h" +#include "actor.h" +#include "p_pspr.h" +#include "info.h" +#include "g_levellocals.h" + +class FModelRenderer +{ +public: + virtual ~FModelRenderer() { } + + void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor, double ticFrac); + void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy); + + virtual ModelRendererType GetType() const = 0; + + virtual void BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) = 0; + virtual void EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf) = 0; + + virtual IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) = 0; + + virtual VSMatrix GetViewToWorldMatrix() = 0; + + virtual void BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored) = 0; + virtual void EndDrawHUDModel(FRenderStyle style) = 0; + + virtual void SetInterpolation(double interpolation) = 0; + virtual void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) = 0; + virtual void DrawArrays(int start, int count) = 0; + virtual void DrawElements(int numIndices, size_t offset) = 0; + virtual void SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) = 0; + +private: + void RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation); +}; + diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 92a5ad34e3..756fdfa95a 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -43,6 +43,7 @@ #include "r_data/models/models_obj.h" #include "i_time.h" #include "texturemanager.h" +#include "modelrenderer.h" #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data @@ -168,14 +169,14 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s objectToWorldMatrix.rotate(-smf->rolloffset, 1, 0, 0); // consider the pixel stretching. For non-voxels this must be factored out here - float stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level) : 1.f) / actor->Level->info->pixelstretch; + float stretch = (smf->modelIDs[0] != -1 ? Models[smf->modelIDs[0]]->getAspectFactor(actor->Level->info->pixelstretch) : 1.f) / actor->Level->info->pixelstretch; objectToWorldMatrix.scale(1, stretch, 1); float orientation = scaleFactorX * scaleFactorY * scaleFactorZ; - BeginDrawModel(actor, smf, objectToWorldMatrix, orientation < 0); + BeginDrawModel(actor->RenderStyle, smf, objectToWorldMatrix, orientation < 0); RenderFrameModels(actor->Level, smf, actor->state, actor->tics, actor->GetClass(), translation); - EndDrawModel(actor, smf); + EndDrawModel(actor->RenderStyle, smf); } void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) @@ -211,9 +212,9 @@ void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) float orientation = smf->xscale * smf->yscale * smf->zscale; - BeginDrawHUDModel(playermo, objectToWorldMatrix, orientation < 0); + BeginDrawHUDModel(playermo->RenderStyle, objectToWorldMatrix, orientation < 0); RenderFrameModels(playermo->Level, smf, psp->GetState(), psp->GetTics(), playermo->player->ReadyWeapon->GetClass(), psp->Flags & PSPF_PLAYERTRANSLATED ? psp->Owner->mo->Translation : 0); - EndDrawHUDModel(playermo); + EndDrawHUDModel(playermo->RenderStyle); } void FModelRenderer::RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation) diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index 33e9056deb..2ab61ee579 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -25,14 +25,14 @@ #include "tarray.h" #include "matrix.h" -#include "actor.h" -#include "dobject.h" -#include "p_pspr.h" -#include "r_data/voxels.h" -#include "info.h" +#include "m_bbox.h" +#include "r_defs.h" #include "g_levellocals.h" +#include "r_data/voxels.h" #include "i_modelvertexbuffer.h" +class FModelRenderer; + #define MAX_LODS 4 enum { VX, VZ, VY }; @@ -58,36 +58,6 @@ enum ModelRendererType NumModelRendererTypes }; -class FModelRenderer -{ -public: - virtual ~FModelRenderer() { } - - void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor, double ticFrac); - void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy); - - virtual ModelRendererType GetType() const = 0; - - virtual void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) = 0; - virtual void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) = 0; - - virtual IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) = 0; - - virtual VSMatrix GetViewToWorldMatrix() = 0; - - virtual void BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) = 0; - virtual void EndDrawHUDModel(AActor *actor) = 0; - - virtual void SetInterpolation(double interpolation) = 0; - virtual void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) = 0; - virtual void DrawArrays(int start, int count) = 0; - virtual void DrawElements(int numIndices, size_t offset) = 0; - virtual void SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) = 0; - -private: - void RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation); -}; - class FModel { public: @@ -99,10 +69,10 @@ public: virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0; virtual void AddSkins(uint8_t *hitlist) = 0; - virtual float getAspectFactor(FLevelLocals *) { return 1.f; } + virtual float getAspectFactor(float vscale) { return 1.f; } - void SetVertexBuffer(FModelRenderer *renderer, IModelVertexBuffer *buffer) { mVBuf[renderer->GetType()] = buffer; } - IModelVertexBuffer *GetVertexBuffer(FModelRenderer *renderer) const { return mVBuf[renderer->GetType()]; } + void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; } + IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; } void DestroyVertexBuffer(); const FSpriteModelFrame *curSpriteMDLFrame; @@ -368,7 +338,7 @@ public: virtual void AddSkins(uint8_t *hitlist); FTextureID GetPaletteTexture() const { return mPalette; } void BuildVertexBuffer(FModelRenderer *renderer); - float getAspectFactor(FLevelLocals *) override; + float getAspectFactor(float vscale) override; }; diff --git a/src/r_data/models/models_md2.cpp b/src/r_data/models/models_md2.cpp index f4142ea631..95a45c605d 100644 --- a/src/r_data/models/models_md2.cpp +++ b/src/r_data/models/models_md2.cpp @@ -29,6 +29,7 @@ #include "filesystem.h" #include "r_data/models/models.h" #include "texturemanager.h" +#include "modelrenderer.h" #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data @@ -280,7 +281,7 @@ FDMDModel::~FDMDModel() void FDMDModel::BuildVertexBuffer(FModelRenderer *renderer) { - if (!GetVertexBuffer(renderer)) + if (!GetVertexBuffer(renderer->GetType())) { LoadGeometry(); @@ -288,7 +289,7 @@ void FDMDModel::BuildVertexBuffer(FModelRenderer *renderer) unsigned int vindex = 0; auto vbuf = renderer->CreateVertexBuffer(false, info.numFrames == 1); - SetVertexBuffer(renderer, vbuf); + SetVertexBuffer(renderer->GetType(), vbuf); FModelVertex *vertptr = vbuf->LockVertexBuffer(VertexBufferSize); diff --git a/src/r_data/models/models_md3.cpp b/src/r_data/models/models_md3.cpp index 42e2fd4963..a50fa5eff6 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/r_data/models/models_md3.cpp @@ -24,6 +24,7 @@ #include "cmdlib.h" #include "r_data/models/models.h" #include "texturemanager.h" +#include "modelrenderer.h" #define MAX_QPATH 64 @@ -239,7 +240,7 @@ void FMD3Model::LoadGeometry() void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer) { - if (!GetVertexBuffer(renderer)) + if (!GetVertexBuffer(renderer->GetType())) { LoadGeometry(); @@ -254,7 +255,7 @@ void FMD3Model::BuildVertexBuffer(FModelRenderer *renderer) } auto vbuf = renderer->CreateVertexBuffer(true, Frames.Size() == 1); - SetVertexBuffer(renderer, vbuf); + SetVertexBuffer(renderer->GetType(), vbuf); FModelVertex *vertptr = vbuf->LockVertexBuffer(vbufsize); unsigned int *indxptr = vbuf->LockIndexBuffer(ibufsize); diff --git a/src/r_data/models/models_obj.cpp b/src/r_data/models/models_obj.cpp index 7028ca22b7..6e8fcef8a6 100644 --- a/src/r_data/models/models_obj.cpp +++ b/src/r_data/models/models_obj.cpp @@ -22,6 +22,7 @@ #include "filesystem.h" #include "r_data/models/models_obj.h" #include "texturemanager.h" +#include "modelrenderer.h" /** * Load an OBJ model @@ -355,7 +356,7 @@ int FOBJModel::ResolveIndex(int origIndex, FaceElement el) */ void FOBJModel::BuildVertexBuffer(FModelRenderer *renderer) { - if (GetVertexBuffer(renderer)) + if (GetVertexBuffer(renderer->GetType())) { return; } @@ -375,7 +376,7 @@ void FOBJModel::BuildVertexBuffer(FModelRenderer *renderer) } auto vbuf = renderer->CreateVertexBuffer(false,true); - SetVertexBuffer(renderer, vbuf); + SetVertexBuffer(renderer->GetType(), vbuf); FModelVertex *vertptr = vbuf->LockVertexBuffer(vbufsize); diff --git a/src/r_data/models/models_ue1.cpp b/src/r_data/models/models_ue1.cpp index 8ee05b9db9..5ac8ea52fd 100644 --- a/src/r_data/models/models_ue1.cpp +++ b/src/r_data/models/models_ue1.cpp @@ -24,6 +24,7 @@ #include "cmdlib.h" #include "r_data/models/models_ue1.h" #include "texturemanager.h" +#include "modelrenderer.h" float unpackuvert( uint32_t n, int c ) { @@ -255,7 +256,7 @@ void FUE1Model::RenderFrame( FModelRenderer *renderer, FGameTexture *skin, int f void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer ) { - if (GetVertexBuffer(renderer)) + if (GetVertexBuffer(renderer->GetType())) return; if ( !mDataLoaded ) LoadGeometry(); @@ -264,7 +265,7 @@ void FUE1Model::BuildVertexBuffer( FModelRenderer *renderer ) vsize += groups[i].numPolys*3; vsize *= numFrames; auto vbuf = renderer->CreateVertexBuffer(false,numFrames==1); - SetVertexBuffer(renderer, vbuf); + SetVertexBuffer(renderer->GetType(), vbuf); FModelVertex *vptr = vbuf->LockVertexBuffer(vsize); int vidx = 0; for ( int i=0; iGetType())) { Initialize(); auto vbuf = renderer->CreateVertexBuffer(true, true); - SetVertexBuffer(renderer, vbuf); + SetVertexBuffer(renderer->GetType(), vbuf); FModelVertex *vertptr = vbuf->LockVertexBuffer(mVertices.Size()); unsigned int *indxptr = vbuf->LockIndexBuffer(mIndices.Size()); @@ -384,9 +385,9 @@ int FVoxelModel::FindFrame(const char * name) // //=========================================================================== -float FVoxelModel::getAspectFactor(FLevelLocals *Level) +float FVoxelModel::getAspectFactor(float stretch) { - return Level->info->pixelstretch; + return stretch; } //=========================================================================== diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index abe499df1b..c6c0e15f8d 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -39,6 +39,7 @@ #include "hw_dynlightdata.h" #include "hwrenderer/utility/hw_clock.h" #include "flatvertices.h" +#include "v_palette.h" #include "hw_lightbuffer.h" #include "hw_cvars.h" diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/models/hw_models.cpp index 20d2386d58..6a4bff6016 100644 --- a/src/rendering/hwrenderer/models/hw_models.cpp +++ b/src/rendering/hwrenderer/models/hw_models.cpp @@ -52,7 +52,7 @@ VSMatrix FHWModelRenderer::GetViewToWorldMatrix() return objectToWorldMatrix; } -void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) +void FHWModelRenderer::BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) { state.SetDepthFunc(DF_LEqual); state.EnableTexture(true); @@ -60,7 +60,7 @@ void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, con // This solves a few of the problems caused by the lack of depth sorting. // [Nash] Don't do back face culling if explicitly specified in MODELDEF // TO-DO: Implement proper depth sorting. - if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES)) + if (!(style == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES)) { state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CCW : Cull_CW); } @@ -69,22 +69,22 @@ void FHWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, con state.EnableModelMatrix(true); } -void FHWModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf) +void FHWModelRenderer::EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf) { state.EnableModelMatrix(false); state.SetDepthFunc(DF_Less); - if (!(actor->RenderStyle == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES)) + if (!(style == DefaultRenderStyle()) && !(smf->flags & MDL_DONTCULLBACKFACES)) state.SetCulling(Cull_None); } -void FHWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) +void FHWModelRenderer::BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored) { state.SetDepthFunc(DF_LEqual); // [BB] In case the model should be rendered translucent, do back face culling. // This solves a few of the problems caused by the lack of depth sorting. // TO-DO: Implement proper depth sorting. - if (!(actor->RenderStyle == DefaultRenderStyle())) + if (!(style == DefaultRenderStyle())) { state.SetCulling((mirrored ^ portalState.isMirrored()) ? Cull_CW : Cull_CCW); } @@ -93,12 +93,12 @@ void FHWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectTo state.EnableModelMatrix(true); } -void FHWModelRenderer::EndDrawHUDModel(AActor *actor) +void FHWModelRenderer::EndDrawHUDModel(FRenderStyle style) { state.EnableModelMatrix(false); state.SetDepthFunc(DF_Less); - if (!(actor->RenderStyle == DefaultRenderStyle())) + if (!(style == DefaultRenderStyle())) state.SetCulling(Cull_None); } @@ -136,7 +136,7 @@ void FHWModelRenderer::DrawElements(int numIndices, size_t offset) void FHWModelRenderer::SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) { - auto mdbuff = static_cast(model->GetVertexBuffer(this)); + auto mdbuff = static_cast(model->GetVertexBuffer(GetType())); state.SetVertexBuffer(mdbuff->vertexBuffer(), frame1, frame2); if (mdbuff->indexBuffer()) state.SetIndexBuffer(mdbuff->indexBuffer()); } diff --git a/src/rendering/hwrenderer/models/hw_models.h b/src/rendering/hwrenderer/models/hw_models.h index 5644ab09df..6304e54ba5 100644 --- a/src/rendering/hwrenderer/models/hw_models.h +++ b/src/rendering/hwrenderer/models/hw_models.h @@ -28,6 +28,7 @@ #include "r_data/models/models.h" #include "hwrenderer/data/buffers.h" #include "hw_modelvertexbuffer.h" +#include "r_data/models/modelrenderer.h" class HWSprite; struct HWDrawInfo; @@ -44,12 +45,12 @@ public: FHWModelRenderer(HWDrawInfo *d, FRenderState &st, int mli) : modellightindex(mli), di(d), state(st) {} ModelRendererType GetType() const override { return GLModelRendererType; } - void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override; - void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override; + void BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override; + void EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf) override; IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override; VSMatrix GetViewToWorldMatrix() override; - void BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) override; - void EndDrawHUDModel(AActor *actor) override; + void BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored) override; + void EndDrawHUDModel(FRenderStyle style) override; void SetInterpolation(double interpolation) override; void SetMaterial(FGameTexture *skin, bool clampNoFilter, int translation) override; void DrawArrays(int start, int count) override; diff --git a/src/rendering/hwrenderer/utility/hw_lighting.cpp b/src/rendering/hwrenderer/utility/hw_lighting.cpp index e1845b51a9..bb45f08561 100644 --- a/src/rendering/hwrenderer/utility/hw_lighting.cpp +++ b/src/rendering/hwrenderer/utility/hw_lighting.cpp @@ -70,13 +70,6 @@ CUSTOM_CVAR(Int, gl_distfog, 70, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) } } -CUSTOM_CVAR(Int,gl_fogmode,1,CVAR_ARCHIVE|CVAR_NOINITCALL) -{ - if (self>2) self=2; - if (self<0) self=0; -} - - //========================================================================== // // Get current light level diff --git a/src/rendering/swrenderer/things/r_model.cpp b/src/rendering/swrenderer/things/r_model.cpp index bb8c66d5e3..60f8a9865c 100644 --- a/src/rendering/swrenderer/things/r_model.cpp +++ b/src/rendering/swrenderer/things/r_model.cpp @@ -223,7 +223,7 @@ namespace swrenderer } } - void SWModelRenderer::BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) + void SWModelRenderer::BeginDrawModel(FRenderStyale style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) { const_cast(objectToWorldMatrix).copy(ObjectToWorld.Matrix); @@ -261,14 +261,14 @@ namespace swrenderer SetTransform(); - if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES)) + if (style == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES)) PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, true); PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, !(mirrored ^ MirrorWorldToClip)); } - void SWModelRenderer::EndDrawModel(AActor *actor, FSpriteModelFrame *smf) + void SWModelRenderer::EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf) { - if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES)) + if (style == LegacyRenderStyles[STYLE_Normal] || !!(smf->flags & MDL_DONTCULLBACKFACES)) PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, false); PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, true); } @@ -314,7 +314,7 @@ namespace swrenderer return objectToWorld; } - void SWModelRenderer::BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) + void SWModelRenderer::BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored) { const_cast(objectToWorldMatrix).copy(ObjectToWorld.Matrix); ClipTop = {}; @@ -322,16 +322,16 @@ namespace swrenderer SetTransform(); PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, true); - if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal]) + if (style == LegacyRenderStyles[STYLE_Normal]) PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, true); PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, !(mirrored ^ MirrorWorldToClip)); } - void SWModelRenderer::EndDrawHUDModel(AActor *actor) + void SWModelRenderer::EndDrawHUDModel(FRenderStyle style) { PolyTriangleDrawer::SetWeaponScene(Thread->DrawQueue, false); - if (actor->RenderStyle == LegacyRenderStyles[STYLE_Normal]) + if (style == LegacyRenderStyles[STYLE_Normal]) PolyTriangleDrawer::SetTwoSided(Thread->DrawQueue, false); PolyTriangleDrawer::SetCullCCW(Thread->DrawQueue, true); } diff --git a/src/rendering/swrenderer/things/r_model.h b/src/rendering/swrenderer/things/r_model.h index 28fa38f541..67db288816 100644 --- a/src/rendering/swrenderer/things/r_model.h +++ b/src/rendering/swrenderer/things/r_model.h @@ -63,12 +63,12 @@ namespace swrenderer ModelRendererType GetType() const override { return SWModelRendererType; } - void BeginDrawModel(AActor *actor, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override; - void EndDrawModel(AActor *actor, FSpriteModelFrame *smf) override; + void BeginDrawModel(FRenderStyle style, FSpriteModelFrame *smf, const VSMatrix &objectToWorldMatrix, bool mirrored) override; + void EndDrawModel(FRenderStyle style, FSpriteModelFrame *smf) override; IModelVertexBuffer *CreateVertexBuffer(bool needindex, bool singleframe) override; VSMatrix GetViewToWorldMatrix() override; - void BeginDrawHUDModel(AActor *actor, const VSMatrix &objectToWorldMatrix, bool mirrored) override; - void EndDrawHUDModel(AActor *actor) override; + void BeginDrawHUDModel(FRenderStyle style, const VSMatrix &objectToWorldMatrix, bool mirrored) override; + void EndDrawHUDModel(FRenderStyle style) override; void SetInterpolation(double interpolation) override; void SetMaterial(FTexture *skin, bool clampNoFilter, int translation) override; void DrawArrays(int start, int count) override; diff --git a/src/utility/m_bbox.cpp b/src/utility/m_bbox.cpp index 1fb6ca1423..01fed1624d 100644 --- a/src/utility/m_bbox.cpp +++ b/src/utility/m_bbox.cpp @@ -47,51 +47,3 @@ void FBoundingBox::AddToBox (const DVector2 &pos) m_Box[BOXTOP] = pos.Y; } -//========================================================================== -// -// FBoundingBox :: BoxOnLineSide -// -// Considers the line to be infinite -// Returns side 0 or 1, -1 if box crosses the line. -// -//========================================================================== - -int FBoundingBox::BoxOnLineSide (const line_t *ld) const -{ - int p1; - int p2; - - if (ld->Delta().X == 0) - { // ST_VERTICAL - p1 = m_Box[BOXRIGHT] < ld->v1->fX(); - p2 = m_Box[BOXLEFT] < ld->v1->fX(); - if (ld->Delta().Y < 0) - { - p1 ^= 1; - p2 ^= 1; - } - } - else if (ld->Delta().Y == 0) - { // ST_HORIZONTAL: - p1 = m_Box[BOXTOP] > ld->v1->fY(); - p2 = m_Box[BOXBOTTOM] > ld->v1->fY(); - if (ld->Delta().X < 0) - { - p1 ^= 1; - p2 ^= 1; - } - } - else if ((ld->Delta().X * ld->Delta().Y) >= 0) - { // ST_POSITIVE: - p1 = P_PointOnLineSide (m_Box[BOXLEFT], m_Box[BOXTOP], ld); - p2 = P_PointOnLineSide (m_Box[BOXRIGHT], m_Box[BOXBOTTOM], ld); - } - else - { // ST_NEGATIVE: - p1 = P_PointOnLineSide (m_Box[BOXRIGHT], m_Box[BOXTOP], ld); - p2 = P_PointOnLineSide (m_Box[BOXLEFT], m_Box[BOXBOTTOM], ld); - } - - return (p1 == p2) ? p1 : -1; -} - diff --git a/src/utility/m_bbox.h b/src/utility/m_bbox.h index e529f9b03b..0d022e5979 100644 --- a/src/utility/m_bbox.h +++ b/src/utility/m_bbox.h @@ -31,9 +31,6 @@ #include "vectors.h" #include "m_fixed.h" -struct line_t; -struct node_t; - enum { BOXTOP, @@ -95,10 +92,6 @@ public: inline double Left () const { return m_Box[BOXLEFT]; } inline double Right () const { return m_Box[BOXRIGHT]; } - bool inRange(const line_t *ld) const; - - int BoxOnLineSide (const line_t *ld) const; - void Set(int index, double value) {m_Box[index] = value;} protected: From 6afa73bdcd15af5b91ef90e2b0ecbdb54848b6fc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 00:07:17 +0200 Subject: [PATCH 117/220] - moved m_bbox to 'common' --- src/CMakeLists.txt | 2 +- src/{ => common}/utility/m_bbox.cpp | 2 -- src/{ => common}/utility/m_bbox.h | 1 - src/rendering/hwrenderer/textures/hw_precache.cpp | 1 + 4 files changed, 2 insertions(+), 4 deletions(-) rename src/{ => common}/utility/m_bbox.cpp (97%) rename src/{ => common}/utility/m_bbox.h (99%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3f1449ddf4..9ad52a7bd2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1097,6 +1097,7 @@ set (PCH_SOURCES common/utility/s_playlist.cpp common/utility/zstrformat.cpp common/utility/name.cpp + common/utility/m_bbox.cpp common/thirdparty/md5.cpp common/thirdparty/superfasthash.cpp common/filesystem/filesystem.cpp @@ -1169,7 +1170,6 @@ set (PCH_SOURCES utility/nodebuilder/nodebuild_extract.cpp utility/nodebuilder/nodebuild_gl.cpp utility/nodebuilder/nodebuild_utility.cpp - utility/m_bbox.cpp utility/v_collection.cpp ) diff --git a/src/utility/m_bbox.cpp b/src/common/utility/m_bbox.cpp similarity index 97% rename from src/utility/m_bbox.cpp rename to src/common/utility/m_bbox.cpp index 01fed1624d..d62c4ec5fe 100644 --- a/src/utility/m_bbox.cpp +++ b/src/common/utility/m_bbox.cpp @@ -25,8 +25,6 @@ //----------------------------------------------------------------------------- #include "m_bbox.h" -#include "p_local.h" -#include "p_maputl.h" //========================================================================== // diff --git a/src/utility/m_bbox.h b/src/common/utility/m_bbox.h similarity index 99% rename from src/utility/m_bbox.h rename to src/common/utility/m_bbox.h index 0d022e5979..0286ef2307 100644 --- a/src/utility/m_bbox.h +++ b/src/common/utility/m_bbox.h @@ -29,7 +29,6 @@ #include #include "vectors.h" -#include "m_fixed.h" enum { diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index e548d667be..4b1dbb15a6 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -37,6 +37,7 @@ #include "v_video.h" #include "v_font.h" #include "texturemanager.h" +#include "r_data/models/modelrenderer.h" EXTERN_CVAR(Bool, gl_precache) From 8ea0a0c5f85cea873150af309a6d87e657983eda Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 00:25:53 +0200 Subject: [PATCH 118/220] - took the game dependent model render functions out of the FModelRenderer class. This makes FModelRenderer game independent - the 3 functions in question may just be global functions instead. --- src/r_data/models/models.cpp | 29 ++++++++++--------- src/r_data/models/models.h | 3 ++ src/rendering/hwrenderer/scene/hw_sprites.cpp | 2 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 2 +- src/rendering/swrenderer/things/r_model.cpp | 4 +-- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 756fdfa95a..446a5840b1 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -57,7 +57,10 @@ extern TDeletingArray VoxelDefs; TDeletingArray Models; -void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *smf, AActor *actor, double ticFrac) +void RenderFrameModels(FModelRenderer* renderer, FLevelLocals* Level, const FSpriteModelFrame* smf, const FState* curState, const int curTics, const PClass* ti, int translation); + + +void RenderModel(FModelRenderer *renderer, float x, float y, float z, FSpriteModelFrame *smf, AActor *actor, double ticFrac) { // Setup transformation. @@ -174,12 +177,12 @@ void FModelRenderer::RenderModel(float x, float y, float z, FSpriteModelFrame *s float orientation = scaleFactorX * scaleFactorY * scaleFactorZ; - BeginDrawModel(actor->RenderStyle, smf, objectToWorldMatrix, orientation < 0); - RenderFrameModels(actor->Level, smf, actor->state, actor->tics, actor->GetClass(), translation); - EndDrawModel(actor->RenderStyle, smf); + renderer->BeginDrawModel(actor->RenderStyle, smf, objectToWorldMatrix, orientation < 0); + RenderFrameModels(renderer, actor->Level, smf, actor->state, actor->tics, actor->GetClass(), translation); + renderer->EndDrawModel(actor->RenderStyle, smf); } -void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) +void RenderHUDModel(FModelRenderer *renderer, DPSprite *psp, float ofsX, float ofsY) { AActor * playermo = players[consoleplayer].camera; FSpriteModelFrame *smf = FindModelFrame(playermo->player->ReadyWeapon->GetClass(), psp->GetSprite(), psp->GetFrame(), false); @@ -190,7 +193,7 @@ void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) // The model position and orientation has to be drawn independently from the position of the player, // but we need to position it correctly in the world for light to work properly. - VSMatrix objectToWorldMatrix = GetViewToWorldMatrix(); + VSMatrix objectToWorldMatrix = renderer->GetViewToWorldMatrix(); // Scaling model (y scale for a sprite means height, i.e. z in the world!). objectToWorldMatrix.scale(smf->xscale, smf->zscale, smf->yscale); @@ -212,12 +215,12 @@ void FModelRenderer::RenderHUDModel(DPSprite *psp, float ofsX, float ofsY) float orientation = smf->xscale * smf->yscale * smf->zscale; - BeginDrawHUDModel(playermo->RenderStyle, objectToWorldMatrix, orientation < 0); - RenderFrameModels(playermo->Level, smf, psp->GetState(), psp->GetTics(), playermo->player->ReadyWeapon->GetClass(), psp->Flags & PSPF_PLAYERTRANSLATED ? psp->Owner->mo->Translation : 0); - EndDrawHUDModel(playermo->RenderStyle); + renderer->BeginDrawHUDModel(playermo->RenderStyle, objectToWorldMatrix, orientation < 0); + RenderFrameModels(renderer, playermo->Level, smf, psp->GetState(), psp->GetTics(), playermo->player->ReadyWeapon->GetClass(), psp->Flags & PSPF_PLAYERTRANSLATED ? psp->Owner->mo->Translation : 0); + renderer->EndDrawHUDModel(playermo->RenderStyle); } -void FModelRenderer::RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation) +void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation) { // [BB] Frame interpolation: Find the FSpriteModelFrame smfNext which follows after smf in the animation // and the scalar value inter ( element of [0,1) ), both necessary to determine the interpolated frame. @@ -271,14 +274,14 @@ void FModelRenderer::RenderFrameModels(FLevelLocals *Level, const FSpriteModelFr { FModel * mdl = Models[smf->modelIDs[i]]; auto tex = smf->skinIDs[i].isValid() ? TexMan.GetGameTexture(smf->skinIDs[i], true) : nullptr; - mdl->BuildVertexBuffer(this); + mdl->BuildVertexBuffer(renderer); mdl->PushSpriteMDLFrame(smf, i); if (smfNext && smf->modelframes[i] != smfNext->modelframes[i]) - mdl->RenderFrame(this, tex, smf->modelframes[i], smfNext->modelframes[i], inter, translation); + mdl->RenderFrame(renderer, tex, smf->modelframes[i], smfNext->modelframes[i], inter, translation); else - mdl->RenderFrame(this, tex, smf->modelframes[i], smf->modelframes[i], 0.f, translation); + mdl->RenderFrame(renderer, tex, smf->modelframes[i], smf->modelframes[i], 0.f, translation); } } } diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index 2ab61ee579..ad36f7190a 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -441,4 +441,7 @@ void BSPWalkCircle(FLevelLocals *Level, float x, float y, float radiusSquared, c BSPNodeWalkCircle(Level->HeadNode(), x, y, radiusSquared, callback); } +void RenderModel(FModelRenderer* renderer, float x, float y, float z, FSpriteModelFrame* smf, AActor* actor, double ticFrac); +void RenderHUDModel(FModelRenderer* renderer, DPSprite* psp, float ofsX, float ofsY); + #endif diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 93e56cca38..c0dd3bd1ef 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -293,7 +293,7 @@ void HWSprite::DrawSprite(HWDrawInfo *di, FRenderState &state, bool translucent) else { FHWModelRenderer renderer(di, state, dynlightindex); - renderer.RenderModel(x, y, z, modelframe, actor, di->Viewpoint.TicFrac); + RenderModel(&renderer, x, y, z, modelframe, actor, di->Viewpoint.TicFrac); state.SetVertexBuffer(screen->mVertexData); } } diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index acca62c9a2..20ac4848b9 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -89,7 +89,7 @@ void HWDrawInfo::DrawPSprite(HUDSprite *huds, FRenderState &state) state.AlphaFunc(Alpha_GEqual, 0); FHWModelRenderer renderer(this, state, huds->lightindex); - renderer.RenderHUDModel(huds->weapon, huds->mx, huds->my); + RenderHUDModel(&renderer, huds->weapon, huds->mx, huds->my); state.SetVertexBuffer(screen->mVertexData); } else diff --git a/src/rendering/swrenderer/things/r_model.cpp b/src/rendering/swrenderer/things/r_model.cpp index 60f8a9865c..ec7a5273cc 100644 --- a/src/rendering/swrenderer/things/r_model.cpp +++ b/src/rendering/swrenderer/things/r_model.cpp @@ -94,7 +94,7 @@ namespace swrenderer renderer.Translation = actor->Translation; renderer.AddLights(actor); - renderer.RenderModel(x, y, z, smf, actor, r_viewpoint.TicFrac); + RenderModel(&renderer, x, y, z, smf, actor, r_viewpoint.TicFrac); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f); #endif } @@ -143,7 +143,7 @@ namespace swrenderer renderer.fillcolor = fullbrightSprite ? ThingColor : ThingColor.Modulate(playermo->Sector->SpecialColors[sector_t::sprites]); renderer.Translation = 0xffffffff;// playermo->Translation; - renderer.RenderHUDModel(psp, ofsx, ofsy); + RenderHUDModel(&renderer, psp, ofsx, ofsy); PolyTriangleDrawer::SetModelVertexShader(thread->DrawQueue, -1, -1, 0.0f); #endif } From 46d263b5a8ec0b39526566e8ac51ab9cdc4837f7 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 01:16:17 +0200 Subject: [PATCH 119/220] - header separation of model code. --- src/common/textures/texturemanager.h | 1 + src/r_data/models/model.h | 77 ++++ src/r_data/models/model_kvx.h | 61 ++++ src/r_data/models/model_md2.h | 136 +++++++ src/r_data/models/model_md3.h | 75 ++++ .../models/{models_obj.h => model_obj.h} | 4 +- .../models/{models_ue1.h => model_ue1.h} | 4 +- src/r_data/models/modelrenderer.h | 12 +- src/r_data/models/models.cpp | 33 +- src/r_data/models/models.h | 338 +----------------- src/r_data/models/models_md2.cpp | 4 + src/r_data/models/models_md3.cpp | 1 + src/r_data/models/models_obj.cpp | 2 +- src/r_data/models/models_ue1.cpp | 2 +- src/r_data/models/models_voxel.cpp | 1 + 15 files changed, 385 insertions(+), 366 deletions(-) create mode 100644 src/r_data/models/model.h create mode 100644 src/r_data/models/model_kvx.h create mode 100644 src/r_data/models/model_md2.h create mode 100644 src/r_data/models/model_md3.h rename src/r_data/models/{models_obj.h => model_obj.h} (98%) rename src/r_data/models/{models_ue1.h => model_ue1.h} (97%) diff --git a/src/common/textures/texturemanager.h b/src/common/textures/texturemanager.h index 9cdfa58b47..2aa53da241 100644 --- a/src/common/textures/texturemanager.h +++ b/src/common/textures/texturemanager.h @@ -10,6 +10,7 @@ class FxAddSub; struct BuildInfo; class FMultipatchTextureBuilder; +class FScanner; int PalCheck(int tex); // Texture manager diff --git a/src/r_data/models/model.h b/src/r_data/models/model.h new file mode 100644 index 0000000000..1daf7c8c65 --- /dev/null +++ b/src/r_data/models/model.h @@ -0,0 +1,77 @@ +#pragma once + +#include +#include "textureid.h" + +class FModelRenderer; +class FGameTexture; +class IModelVertexBuffer; +class FModel; + +FTextureID LoadSkin(const char* path, const char* fn); +void FlushModels(); +extern TDeletingArray Models; + +#define MAX_MODELS_PER_FRAME 4 +#define MD3_MAX_SURFACES 32 + +struct FSpriteModelFrame +{ + int modelIDs[MAX_MODELS_PER_FRAME]; + FTextureID skinIDs[MAX_MODELS_PER_FRAME]; + FTextureID surfaceskinIDs[MAX_MODELS_PER_FRAME][MD3_MAX_SURFACES]; + int modelframes[MAX_MODELS_PER_FRAME]; + float xscale, yscale, zscale; + // [BB] Added zoffset, rotation parameters and flags. + // Added xoffset, yoffset + float xoffset, yoffset, zoffset; + float xrotate, yrotate, zrotate; + float rotationCenterX, rotationCenterY, rotationCenterZ; + float rotationSpeed; + unsigned int flags; + const void* type; // used for hashing, must point to something usable as identifier for the model's owner. + short sprite; + short frame; + int hashnext; + float angleoffset; + // added pithoffset, rolloffset. + float pitchoffset, rolloffset; // I don't want to bother with type transformations, so I made this variables float. + bool isVoxel; +}; + + +enum ModelRendererType +{ + GLModelRendererType, + SWModelRendererType, + PolyModelRendererType, + NumModelRendererTypes +}; + +class FModel +{ +public: + FModel(); + virtual ~FModel(); + + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0; + virtual int FindFrame(const char * name) = 0; + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; + virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0; + virtual void AddSkins(uint8_t *hitlist) = 0; + virtual float getAspectFactor(float vscale) { return 1.f; } + + void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; } + IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; } + void DestroyVertexBuffer(); + + const FSpriteModelFrame *curSpriteMDLFrame; + int curMDLIndex; + void PushSpriteMDLFrame(const FSpriteModelFrame *smf, int index) { curSpriteMDLFrame = smf; curMDLIndex = index; }; + + FString mFileName; + +private: + IModelVertexBuffer *mVBuf[NumModelRendererTypes]; +}; + diff --git a/src/r_data/models/model_kvx.h b/src/r_data/models/model_kvx.h new file mode 100644 index 0000000000..c934491e89 --- /dev/null +++ b/src/r_data/models/model_kvx.h @@ -0,0 +1,61 @@ +#pragma once + +#include "model.h" + +struct FVoxelVertexHash +{ + // Returns the hash value for a key. + hash_t Hash(const FModelVertex &key) + { + int ix = xs_RoundToInt(key.x); + int iy = xs_RoundToInt(key.y); + int iz = xs_RoundToInt(key.z); + return (hash_t)(ix + (iy<<9) + (iz<<18)); + } + + // Compares two keys, returning zero if they are the same. + int Compare(const FModelVertex &left, const FModelVertex &right) + { + return left.x != right.x || left.y != right.y || left.z != right.z || left.u != right.u || left.v != right.v; + } +}; + +struct FIndexInit +{ + void Init(unsigned int &value) + { + value = 0xffffffff; + } +}; + +typedef TMap FVoxelMap; + + +class FVoxelModel : public FModel +{ +protected: + FVoxel *mVoxel; + bool mOwningVoxel; // if created through MODELDEF deleting this object must also delete the voxel object + FTextureID mPalette; + unsigned int mNumIndices; + TArray mVertices; + TArray mIndices; + + void MakeSlabPolys(int x, int y, kvxslab_t *voxptr, FVoxelMap &check); + void AddFace(int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3, int x4, int y4, int z4, uint8_t color, FVoxelMap &check); + unsigned int AddVertex(FModelVertex &vert, FVoxelMap &check); + +public: + FVoxelModel(FVoxel *voxel, bool owned); + ~FVoxelModel(); + bool Load(const char * fn, int lumpnum, const char * buffer, int length); + void Initialize(); + virtual int FindFrame(const char * name); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); + virtual void AddSkins(uint8_t *hitlist); + FTextureID GetPaletteTexture() const { return mPalette; } + void BuildVertexBuffer(FModelRenderer *renderer); + float getAspectFactor(float vscale) override; +}; + + diff --git a/src/r_data/models/model_md2.h b/src/r_data/models/model_md2.h new file mode 100644 index 0000000000..1636315320 --- /dev/null +++ b/src/r_data/models/model_md2.h @@ -0,0 +1,136 @@ +#pragma once +#include "model.h" + +#define MD2_MAGIC 0x32504449 +#define DMD_MAGIC 0x4D444D44 + +class FDMDModel : public FModel +{ +protected: + + struct FTriangle + { + unsigned short vertexIndices[3]; + unsigned short textureIndices[3]; + }; + + + struct DMDHeader + { + int magic; + int version; + int flags; + }; + + struct DMDModelVertex + { + float xyz[3]; + }; + + struct FTexCoord + { + short s, t; + }; + + struct FGLCommandVertex + { + float s, t; + int index; + }; + + struct DMDInfo + { + int skinWidth; + int skinHeight; + int frameSize; + int numSkins; + int numVertices; + int numTexCoords; + int numFrames; + int numLODs; + int offsetSkins; + int offsetTexCoords; + int offsetFrames; + int offsetLODs; + int offsetEnd; + }; + + struct ModelFrame + { + char name[16]; + unsigned int vindex; + }; + + struct ModelFrameVertexData + { + DMDModelVertex *vertices; + DMDModelVertex *normals; + }; + + struct DMDLoDInfo + { + int numTriangles; + int numGlCommands; + int offsetTriangles; + int offsetGlCommands; + }; + + struct DMDLoD + { + FTriangle * triangles; + }; + + + int mLumpNum; + DMDHeader header; + DMDInfo info; + FTextureID * skins; + ModelFrame * frames; + bool allowTexComp; // Allow texture compression with this. + + // Temp data only needed for buffer construction + FTexCoord * texCoords; + ModelFrameVertexData *framevtx; + DMDLoDInfo lodInfo[MAX_LODS]; + DMDLoD lods[MAX_LODS]; + +public: + FDMDModel() + { + mLumpNum = -1; + frames = NULL; + skins = NULL; + for (int i = 0; i < MAX_LODS; i++) + { + lods[i].triangles = NULL; + } + info.numLODs = 0; + texCoords = NULL; + framevtx = NULL; + } + virtual ~FDMDModel(); + + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); + virtual int FindFrame(const char * name); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); + virtual void LoadGeometry(); + virtual void AddSkins(uint8_t *hitlist); + + void UnloadGeometry(); + void BuildVertexBuffer(FModelRenderer *renderer); + +}; + +// This uses the same internal representation as DMD +class FMD2Model : public FDMDModel +{ +public: + FMD2Model() {} + virtual ~FMD2Model(); + + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); + virtual void LoadGeometry(); + +}; + + diff --git a/src/r_data/models/model_md3.h b/src/r_data/models/model_md3.h new file mode 100644 index 0000000000..3e6630a5af --- /dev/null +++ b/src/r_data/models/model_md3.h @@ -0,0 +1,75 @@ +#pragma once +#include "model.h" + +#define MD3_MAGIC 0x33504449 + +class FMD3Model : public FModel +{ + struct MD3Tag + { + // Currently I have no use for this + }; + + struct MD3TexCoord + { + float s,t; + }; + + struct MD3Vertex + { + float x,y,z; + float nx,ny,nz; + }; + + struct MD3Triangle + { + int VertIndex[3]; + }; + + struct MD3Surface + { + unsigned numVertices; + unsigned numTriangles; + unsigned numSkins; + + TArray Skins; + TArray Tris; + TArray Texcoords; + TArray Vertices; + + unsigned int vindex = UINT_MAX; // contains numframes arrays of vertices + unsigned int iindex = UINT_MAX; + + void UnloadGeometry() + { + Tris.Reset(); + Vertices.Reset(); + Texcoords.Reset(); + } + }; + + struct MD3Frame + { + // The bounding box information is of no use in the Doom engine + // That will still be done with the actor's size information. + char Name[16]; + float origin[3]; + }; + + int numTags; + int mLumpNum; + + TArray Frames; + TArray Surfaces; + +public: + FMD3Model() = default; + + virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); + virtual int FindFrame(const char * name); + virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); + void LoadGeometry(); + void BuildVertexBuffer(FModelRenderer *renderer); + virtual void AddSkins(uint8_t *hitlist); +}; + diff --git a/src/r_data/models/models_obj.h b/src/r_data/models/model_obj.h similarity index 98% rename from src/r_data/models/models_obj.h rename to src/r_data/models/model_obj.h index c58c30a5ae..ed190c1cd3 100644 --- a/src/r_data/models/models_obj.h +++ b/src/r_data/models/model_obj.h @@ -23,8 +23,10 @@ #ifndef __GL_MODELS_OBJ_H__ #define __GL_MODELS_OBJ_H__ -#include "models.h" +#include "model.h" #include "sc_man.h" +#include "tarray.h" +#include "vectors.h" class FOBJModel : public FModel { diff --git a/src/r_data/models/models_ue1.h b/src/r_data/models/model_ue1.h similarity index 97% rename from src/r_data/models/models_ue1.h rename to src/r_data/models/model_ue1.h index fb3c85483d..5696cbf43e 100644 --- a/src/r_data/models/models_ue1.h +++ b/src/r_data/models/model_ue1.h @@ -1,6 +1,8 @@ #pragma once -#include "models.h" +#include +#include "model.h" +#include "vectors.h" class FUE1Model : public FModel { diff --git a/src/r_data/models/modelrenderer.h b/src/r_data/models/modelrenderer.h index 848890c8e9..96c8f2a716 100644 --- a/src/r_data/models/modelrenderer.h +++ b/src/r_data/models/modelrenderer.h @@ -1,17 +1,10 @@ #include "models.h" -#include "actor.h" -#include "p_pspr.h" -#include "info.h" -#include "g_levellocals.h" class FModelRenderer { public: - virtual ~FModelRenderer() { } - - void RenderModel(float x, float y, float z, FSpriteModelFrame *modelframe, AActor *actor, double ticFrac); - void RenderHUDModel(DPSprite *psp, float ofsx, float ofsy); + virtual ~FModelRenderer() = default; virtual ModelRendererType GetType() const = 0; @@ -30,8 +23,5 @@ public: virtual void DrawArrays(int start, int count) = 0; virtual void DrawElements(int numIndices, size_t offset) = 0; virtual void SetupFrame(FModel *model, unsigned int frame1, unsigned int frame2, unsigned int size) = 0; - -private: - void RenderFrameModels(FLevelLocals *Level, const FSpriteModelFrame *smf, const FState *curState, const int curTics, const PClass *ti, int translation); }; diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 446a5840b1..918af38fb8 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -39,12 +39,16 @@ #include "g_levellocals.h" #include "r_utility.h" #include "r_data/models/models.h" -#include "r_data/models/models_ue1.h" -#include "r_data/models/models_obj.h" +#include "r_data/models/model_ue1.h" +#include "r_data/models/model_obj.h" +#include "r_data/models/model_md2.h" +#include "r_data/models/model_md3.h" +#include "r_data/models/model_kvx.h" #include "i_time.h" #include "texturemanager.h" #include "modelrenderer.h" + #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data #endif @@ -571,11 +575,12 @@ static void ParseModelDefLump(int Lump) smf.modelIDs[0] = smf.modelIDs[1] = smf.modelIDs[2] = smf.modelIDs[3] = -1; smf.xscale=smf.yscale=smf.zscale=1.f; - smf.type = PClass::FindClass(sc.String); - if (!smf.type || smf.type->Defaults == nullptr) + auto type = PClass::FindClass(sc.String); + if (!type || type->Defaults == nullptr) { sc.ScriptError("MODELDEF: Unknown actor type '%s'\n", sc.String); } + smf.type = type; sc.MustGetStringName("{"); while (!sc.CheckString("}")) { @@ -593,7 +598,7 @@ static void ParseModelDefLump(int Lump) index = sc.Number; if (index < 0 || index >= MAX_MODELS_PER_FRAME) { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + sc.ScriptError("Too many models in %s", type->TypeName.GetChars()); } sc.MustGetString(); FixPathSeperator(sc.String); @@ -718,7 +723,7 @@ static void ParseModelDefLump(int Lump) index=sc.Number; if (index<0 || index>=MAX_MODELS_PER_FRAME) { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + sc.ScriptError("Too many models in %s", type->TypeName.GetChars()); } sc.MustGetString(); FixPathSeperator(sc.String); @@ -732,7 +737,7 @@ static void ParseModelDefLump(int Lump) if (!smf.skinIDs[index].isValid()) { Printf("Skin '%s' not found in '%s'\n", - sc.String, smf.type->TypeName.GetChars()); + sc.String, type->TypeName.GetChars()); } } } @@ -745,12 +750,12 @@ static void ParseModelDefLump(int Lump) if (index<0 || index >= MAX_MODELS_PER_FRAME) { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + sc.ScriptError("Too many models in %s", type->TypeName.GetChars()); } if (surface<0 || surface >= MD3_MAX_SURFACES) { - sc.ScriptError("Invalid MD3 Surface %d in %s", MD3_MAX_SURFACES, smf.type->TypeName.GetChars()); + sc.ScriptError("Invalid MD3 Surface %d in %s", MD3_MAX_SURFACES, type->TypeName.GetChars()); } sc.MustGetString(); @@ -765,7 +770,7 @@ static void ParseModelDefLump(int Lump) if (!smf.surfaceskinIDs[index][surface].isValid()) { Printf("Surface Skin '%s' not found in '%s'\n", - sc.String, smf.type->TypeName.GetChars()); + sc.String, type->TypeName.GetChars()); } } } @@ -789,7 +794,7 @@ static void ParseModelDefLump(int Lump) } if (smf.sprite==-1) { - sc.ScriptError("Unknown sprite %s in model definition for %s", sc.String, smf.type->TypeName.GetChars()); + sc.ScriptError("Unknown sprite %s in model definition for %s", sc.String, type->TypeName.GetChars()); } sc.MustGetString(); @@ -799,7 +804,7 @@ static void ParseModelDefLump(int Lump) index=sc.Number; if (index<0 || index>=MAX_MODELS_PER_FRAME) { - sc.ScriptError("Too many models in %s", smf.type->TypeName.GetChars()); + sc.ScriptError("Too many models in %s", type->TypeName.GetChars()); } if (isframe) { @@ -808,7 +813,7 @@ static void ParseModelDefLump(int Lump) { FModel *model = Models[smf.modelIDs[index]]; smf.modelframes[index] = model->FindFrame(sc.String); - if (smf.modelframes[index]==-1) sc.ScriptError("Unknown frame '%s' in %s", sc.String, smf.type->TypeName.GetChars()); + if (smf.modelframes[index]==-1) sc.ScriptError("Unknown frame '%s' in %s", sc.String, type->TypeName.GetChars()); } else smf.modelframes[index] = -1; } @@ -830,7 +835,7 @@ static void ParseModelDefLump(int Lump) if (map[c]) continue; smf.frame=c; SpriteModelFrames.Push(smf); - GetDefaultByType(smf.type)->hasmodel = true; + GetDefaultByType(type)->hasmodel = true; map[c]=1; } } diff --git a/src/r_data/models/models.h b/src/r_data/models/models.h index ad36f7190a..eb67a0c92f 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models/models.h @@ -30,320 +30,13 @@ #include "g_levellocals.h" #include "r_data/voxels.h" #include "i_modelvertexbuffer.h" +#include "model.h" class FModelRenderer; -#define MAX_LODS 4 - -enum { VX, VZ, VY }; - -#define MD2_MAGIC 0x32504449 -#define DMD_MAGIC 0x4D444D44 -#define MD3_MAGIC 0x33504449 -#define NUMVERTEXNORMALS 162 -#define MD3_MAX_SURFACES 32 - -FTextureID LoadSkin(const char * path, const char * fn); - struct FSpriteModelFrame; class IModelVertexBuffer; struct FLevelLocals; -class FModel; - -enum ModelRendererType -{ - GLModelRendererType, - SWModelRendererType, - PolyModelRendererType, - NumModelRendererTypes -}; - -class FModel -{ -public: - FModel(); - virtual ~FModel(); - - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length) = 0; - virtual int FindFrame(const char * name) = 0; - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0) = 0; - virtual void BuildVertexBuffer(FModelRenderer *renderer) = 0; - virtual void AddSkins(uint8_t *hitlist) = 0; - virtual float getAspectFactor(float vscale) { return 1.f; } - - void SetVertexBuffer(int type, IModelVertexBuffer *buffer) { mVBuf[type] = buffer; } - IModelVertexBuffer *GetVertexBuffer(int type) const { return mVBuf[type]; } - void DestroyVertexBuffer(); - - const FSpriteModelFrame *curSpriteMDLFrame; - int curMDLIndex; - void PushSpriteMDLFrame(const FSpriteModelFrame *smf, int index) { curSpriteMDLFrame = smf; curMDLIndex = index; }; - - FString mFileName; - -private: - IModelVertexBuffer *mVBuf[NumModelRendererTypes]; -}; - -class FDMDModel : public FModel -{ -protected: - - struct FTriangle - { - unsigned short vertexIndices[3]; - unsigned short textureIndices[3]; - }; - - - struct DMDHeader - { - int magic; - int version; - int flags; - }; - - struct DMDModelVertex - { - float xyz[3]; - }; - - struct FTexCoord - { - short s, t; - }; - - struct FGLCommandVertex - { - float s, t; - int index; - }; - - struct DMDInfo - { - int skinWidth; - int skinHeight; - int frameSize; - int numSkins; - int numVertices; - int numTexCoords; - int numFrames; - int numLODs; - int offsetSkins; - int offsetTexCoords; - int offsetFrames; - int offsetLODs; - int offsetEnd; - }; - - struct ModelFrame - { - char name[16]; - unsigned int vindex; - }; - - struct ModelFrameVertexData - { - DMDModelVertex *vertices; - DMDModelVertex *normals; - }; - - struct DMDLoDInfo - { - int numTriangles; - int numGlCommands; - int offsetTriangles; - int offsetGlCommands; - }; - - struct DMDLoD - { - FTriangle * triangles; - }; - - - int mLumpNum; - DMDHeader header; - DMDInfo info; - FTextureID * skins; - ModelFrame * frames; - bool allowTexComp; // Allow texture compression with this. - - // Temp data only needed for buffer construction - FTexCoord * texCoords; - ModelFrameVertexData *framevtx; - DMDLoDInfo lodInfo[MAX_LODS]; - DMDLoD lods[MAX_LODS]; - -public: - FDMDModel() - { - mLumpNum = -1; - frames = NULL; - skins = NULL; - for (int i = 0; i < MAX_LODS; i++) - { - lods[i].triangles = NULL; - } - info.numLODs = 0; - texCoords = NULL; - framevtx = NULL; - } - virtual ~FDMDModel(); - - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); - virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); - virtual void LoadGeometry(); - virtual void AddSkins(uint8_t *hitlist); - - void UnloadGeometry(); - void BuildVertexBuffer(FModelRenderer *renderer); - -}; - -// This uses the same internal representation as DMD -class FMD2Model : public FDMDModel -{ -public: - FMD2Model() {} - virtual ~FMD2Model(); - - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); - virtual void LoadGeometry(); - -}; - - -class FMD3Model : public FModel -{ - struct MD3Tag - { - // Currently I have no use for this - }; - - struct MD3TexCoord - { - float s,t; - }; - - struct MD3Vertex - { - float x,y,z; - float nx,ny,nz; - }; - - struct MD3Triangle - { - int VertIndex[3]; - }; - - struct MD3Surface - { - unsigned numVertices; - unsigned numTriangles; - unsigned numSkins; - - TArray Skins; - TArray Tris; - TArray Texcoords; - TArray Vertices; - - unsigned int vindex = UINT_MAX; // contains numframes arrays of vertices - unsigned int iindex = UINT_MAX; - - void UnloadGeometry() - { - Tris.Reset(); - Vertices.Reset(); - Texcoords.Reset(); - } - }; - - struct MD3Frame - { - // The bounding box information is of no use in the Doom engine - // That will still be done with the actor's size information. - char Name[16]; - float origin[3]; - }; - - int numTags; - int mLumpNum; - - TArray Frames; - TArray Surfaces; - -public: - FMD3Model() = default; - - virtual bool Load(const char * fn, int lumpnum, const char * buffer, int length); - virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); - void LoadGeometry(); - void BuildVertexBuffer(FModelRenderer *renderer); - virtual void AddSkins(uint8_t *hitlist); -}; - -struct FVoxelVertexHash -{ - // Returns the hash value for a key. - hash_t Hash(const FModelVertex &key) - { - int ix = xs_RoundToInt(key.x); - int iy = xs_RoundToInt(key.y); - int iz = xs_RoundToInt(key.z); - return (hash_t)(ix + (iy<<9) + (iz<<18)); - } - - // Compares two keys, returning zero if they are the same. - int Compare(const FModelVertex &left, const FModelVertex &right) - { - return left.x != right.x || left.y != right.y || left.z != right.z || left.u != right.u || left.v != right.v; - } -}; - -struct FIndexInit -{ - void Init(unsigned int &value) - { - value = 0xffffffff; - } -}; - -typedef TMap FVoxelMap; - - -class FVoxelModel : public FModel -{ -protected: - FVoxel *mVoxel; - bool mOwningVoxel; // if created through MODELDEF deleting this object must also delete the voxel object - FTextureID mPalette; - unsigned int mNumIndices; - TArray mVertices; - TArray mIndices; - - void MakeSlabPolys(int x, int y, kvxslab_t *voxptr, FVoxelMap &check); - void AddFace(int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3, int x4, int y4, int z4, uint8_t color, FVoxelMap &check); - unsigned int AddVertex(FModelVertex &vert, FVoxelMap &check); - -public: - FVoxelModel(FVoxel *voxel, bool owned); - ~FVoxelModel(); - bool Load(const char * fn, int lumpnum, const char * buffer, int length); - void Initialize(); - virtual int FindFrame(const char * name); - virtual void RenderFrame(FModelRenderer *renderer, FGameTexture * skin, int frame, int frame2, double inter, int translation=0); - virtual void AddSkins(uint8_t *hitlist); - FTextureID GetPaletteTexture() const { return mPalette; } - void BuildVertexBuffer(FModelRenderer *renderer); - float getAspectFactor(float vscale) override; -}; - - - -#define MAX_MODELS_PER_FRAME 4 // // [BB] Model rendering flags. @@ -364,37 +57,8 @@ enum MDL_USEROTATIONCENTER = 512, }; -struct FSpriteModelFrame -{ - int modelIDs[MAX_MODELS_PER_FRAME]; - FTextureID skinIDs[MAX_MODELS_PER_FRAME]; - FTextureID surfaceskinIDs[MAX_MODELS_PER_FRAME][MD3_MAX_SURFACES]; - int modelframes[MAX_MODELS_PER_FRAME]; - float xscale, yscale, zscale; - // [BB] Added zoffset, rotation parameters and flags. - // Added xoffset, yoffset - float xoffset, yoffset, zoffset; - float xrotate, yrotate, zrotate; - float rotationCenterX, rotationCenterY, rotationCenterZ; - float rotationSpeed; - unsigned int flags; - const PClass * type; - short sprite; - short frame; - FState * state; // for later! - int hashnext; - float angleoffset; - // added pithoffset, rolloffset. - float pitchoffset, rolloffset; // I don't want to bother with type transformations, so I made this variables float. - bool isVoxel; -}; - FSpriteModelFrame * FindModelFrame(const PClass * ti, int sprite, int frame, bool dropped); bool IsHUDModelForPlayerAvailable(player_t * player); -void FlushModels(); - - -extern TDeletingArray Models; // Check if circle potentially intersects with node AABB inline bool CheckBBoxCircle(float *bbox, float x, float y, float radiusSquared) diff --git a/src/r_data/models/models_md2.cpp b/src/r_data/models/models_md2.cpp index 95a45c605d..03130aaccb 100644 --- a/src/r_data/models/models_md2.cpp +++ b/src/r_data/models/models_md2.cpp @@ -28,6 +28,7 @@ #include "filesystem.h" #include "r_data/models/models.h" +#include "r_data/models/model_md2.h" #include "texturemanager.h" #include "modelrenderer.h" @@ -35,6 +36,9 @@ #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data #endif +enum { VX, VZ, VY }; +#define NUMVERTEXNORMALS 162 + static float avertexnormals[NUMVERTEXNORMALS][3] = { #include "tab_anorms.h" }; diff --git a/src/r_data/models/models_md3.cpp b/src/r_data/models/models_md3.cpp index a50fa5eff6..4eafdaede1 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/r_data/models/models_md3.cpp @@ -23,6 +23,7 @@ #include "filesystem.h" #include "cmdlib.h" #include "r_data/models/models.h" +#include "r_data/models/model_md3.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_obj.cpp b/src/r_data/models/models_obj.cpp index 6e8fcef8a6..643fc64f2d 100644 --- a/src/r_data/models/models_obj.cpp +++ b/src/r_data/models/models_obj.cpp @@ -20,7 +20,7 @@ //-------------------------------------------------------------------------- #include "filesystem.h" -#include "r_data/models/models_obj.h" +#include "r_data/models/model_obj.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_ue1.cpp b/src/r_data/models/models_ue1.cpp index 5ac8ea52fd..73733c9bb7 100644 --- a/src/r_data/models/models_ue1.cpp +++ b/src/r_data/models/models_ue1.cpp @@ -22,7 +22,7 @@ #include "filesystem.h" #include "cmdlib.h" -#include "r_data/models/models_ue1.h" +#include "r_data/models/model_ue1.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_voxel.cpp b/src/r_data/models/models_voxel.cpp index be83256ce8..eccd863bd5 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/r_data/models/models_voxel.cpp @@ -32,6 +32,7 @@ #include "bitmap.h" #include "g_levellocals.h" #include "models.h" +#include "model_kvx.h" #include "image.h" #include "texturemanager.h" #include "modelrenderer.h" From d6dca40cb791934427a4d27b1b8c4fd754d4cc5a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 01:29:25 +0200 Subject: [PATCH 120/220] - separated models.cpp as well into engine and game parts. --- src/CMakeLists.txt | 3 +- src/r_data/models/model.cpp | 236 ++++++++++++++++++++++++++++++++++ src/r_data/models/model.h | 5 + src/r_data/models/model_md2.h | 1 + src/r_data/models/models.cpp | 196 +--------------------------- 5 files changed, 245 insertions(+), 196 deletions(-) create mode 100644 src/r_data/models/model.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ad52a7bd2..18acfc0366 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -783,7 +783,6 @@ set( FASTMATH_SOURCES rendering/hwrenderer/scene/hw_walls.cpp rendering/hwrenderer/scene/hw_walls_vertex.cpp rendering/hwrenderer/scene/hw_weapon.cpp - r_data/models/models.cpp common/utility/matrix.cpp ) @@ -1007,6 +1006,8 @@ set (PCH_SOURCES r_data/models/models_voxel.cpp r_data/models/models_ue1.cpp r_data/models/models_obj.cpp + r_data/models/models.cpp + r_data/models/model.cpp scripting/vmiterators.cpp scripting/vmthunks.cpp scripting/vmthunks_actors.cpp diff --git a/src/r_data/models/model.cpp b/src/r_data/models/model.cpp new file mode 100644 index 0000000000..8c5ce7a807 --- /dev/null +++ b/src/r_data/models/model.cpp @@ -0,0 +1,236 @@ +// +//--------------------------------------------------------------------------- +// +// Copyright(C) 2005-2016 Christoph Oelckers +// All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this program. If not, see http://www.gnu.org/licenses/ +// +//-------------------------------------------------------------------------- +// +/* +** gl_models.cpp +** +** General model handling code +** +**/ + +#include "filesystem.h" +#include "cmdlib.h" +#include "sc_man.h" +#include "m_crc32.h" +#include "printf.h" +#include "r_data/models/models.h" +#include "r_data/models/model_ue1.h" +#include "r_data/models/model_obj.h" +#include "r_data/models/model_md2.h" +#include "r_data/models/model_md3.h" +#include "r_data/models/model_kvx.h" +#include "i_time.h" +#include "texturemanager.h" +#include "modelrenderer.h" + + +TDeletingArray Models; +TArray SpriteModelFrames; + + +///////////////////////////////////////////////////////////////////////////// + +void FlushModels() +{ + for (int i = Models.Size() - 1; i >= 0; i--) + { + Models[i]->DestroyVertexBuffer(); + } +} + +///////////////////////////////////////////////////////////////////////////// + +FModel::FModel() +{ + for (int i = 0; i < NumModelRendererTypes; i++) + mVBuf[i] = nullptr; +} + +FModel::~FModel() +{ + DestroyVertexBuffer(); +} + +void FModel::DestroyVertexBuffer() +{ + for (int i = 0; i < NumModelRendererTypes; i++) + { + delete mVBuf[i]; + mVBuf[i] = nullptr; + } +} + +//=========================================================================== +// +// FindGFXFile +// +//=========================================================================== + +static int FindGFXFile(FString & fn) +{ + int lump = fileSystem.CheckNumForFullName(fn); // if we find something that matches the name plus the extension, return it and do not enter the substitution logic below. + if (lump != -1) return lump; + + int best = -1; + int dot = fn.LastIndexOf('.'); + int slash = fn.LastIndexOf('/'); + if (dot > slash) fn.Truncate(dot); + + static const char * extensions[] = { ".png", ".jpg", ".tga", ".pcx", nullptr }; + + for (const char ** extp=extensions; *extp; extp++) + { + int lump = fileSystem.CheckNumForFullName(fn + *extp); + if (lump >= best) best = lump; + } + return best; +} + + +//=========================================================================== +// +// LoadSkin +// +//=========================================================================== + +FTextureID LoadSkin(const char * path, const char * fn) +{ + FString buffer; + + buffer.Format("%s%s", path, fn); + + int texlump = FindGFXFile(buffer); + const char * const texname = texlump < 0 ? fn : fileSystem.GetFileFullName(texlump); + return TexMan.CheckForTexture(texname, ETextureType::Any, FTextureManager::TEXMAN_TryAny); +} + +//=========================================================================== +// +// ModelFrameHash +// +//=========================================================================== + +int ModelFrameHash(FSpriteModelFrame * smf) +{ + const uint32_t *table = GetCRCTable (); + uint32_t hash = 0xffffffff; + + const char * s = (const char *)(&smf->type); // this uses type, sprite and frame for hashing + const char * se= (const char *)(&smf->hashnext); + + for (; smFileName.CompareNoCase(fullname)) return i; + } + + int len = fileSystem.FileLength(lump); + FileData lumpd = fileSystem.ReadFile(lump); + char * buffer = (char*)lumpd.GetMem(); + + if ( (size_t)fullname.LastIndexOf("_d.3d") == fullname.Len()-5 ) + { + FString anivfile = fullname.GetChars(); + anivfile.Substitute("_d.3d","_a.3d"); + if ( fileSystem.CheckNumForFullName(anivfile) > 0 ) + { + model = new FUE1Model; + } + } + else if ( (size_t)fullname.LastIndexOf("_a.3d") == fullname.Len()-5 ) + { + FString datafile = fullname.GetChars(); + datafile.Substitute("_a.3d","_d.3d"); + if ( fileSystem.CheckNumForFullName(datafile) > 0 ) + { + model = new FUE1Model; + } + } + else if ( (size_t)fullname.LastIndexOf(".obj") == fullname.Len() - 4 ) + { + model = new FOBJModel; + } + else if (!memcmp(buffer, "DMDM", 4)) + { + model = new FDMDModel; + } + else if (!memcmp(buffer, "IDP2", 4)) + { + model = new FMD2Model; + } + else if (!memcmp(buffer, "IDP3", 4)) + { + model = new FMD3Model; + } + + if (model != nullptr) + { + if (!model->Load(path, lump, buffer, len)) + { + delete model; + return -1; + } + } + else + { + // try loading as a voxel + FVoxel *voxel = R_LoadKVX(lump); + if (voxel != nullptr) + { + model = new FVoxelModel(voxel, true); + } + else + { + Printf("LoadModel: Unknown model format in '%s'\n", fullname.GetChars()); + return -1; + } + } + // The vertex buffer cannot be initialized here because this gets called before OpenGL is initialized + model->mFileName = fullname; + return Models.Push(model); +} + diff --git a/src/r_data/models/model.h b/src/r_data/models/model.h index 1daf7c8c65..a8e14d2e2f 100644 --- a/src/r_data/models/model.h +++ b/src/r_data/models/model.h @@ -7,10 +7,12 @@ class FModelRenderer; class FGameTexture; class IModelVertexBuffer; class FModel; +struct FSpriteModelFrame; FTextureID LoadSkin(const char* path, const char* fn); void FlushModels(); extern TDeletingArray Models; +extern TArray SpriteModelFrames; #define MAX_MODELS_PER_FRAME 4 #define MD3_MAX_SURFACES 32 @@ -75,3 +77,6 @@ private: IModelVertexBuffer *mVBuf[NumModelRendererTypes]; }; +int ModelFrameHash(FSpriteModelFrame* smf); +unsigned FindModel(const char* path, const char* modelfile); + diff --git a/src/r_data/models/model_md2.h b/src/r_data/models/model_md2.h index 1636315320..c04445535a 100644 --- a/src/r_data/models/model_md2.h +++ b/src/r_data/models/model_md2.h @@ -3,6 +3,7 @@ #define MD2_MAGIC 0x32504449 #define DMD_MAGIC 0x4D444D44 +#define MAX_LODS 4 class FDMDModel : public FModel { diff --git a/src/r_data/models/models.cpp b/src/r_data/models/models.cpp index 918af38fb8..7e8b963a8a 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models/models.cpp @@ -39,11 +39,7 @@ #include "g_levellocals.h" #include "r_utility.h" #include "r_data/models/models.h" -#include "r_data/models/model_ue1.h" -#include "r_data/models/model_obj.h" -#include "r_data/models/model_md2.h" -#include "r_data/models/model_md3.h" -#include "r_data/models/model_kvx.h" +#include "model_kvx.h" #include "i_time.h" #include "texturemanager.h" #include "modelrenderer.h" @@ -59,8 +55,6 @@ EXTERN_CVAR (Bool, r_drawvoxels) extern TDeletingArray Voxels; extern TDeletingArray VoxelDefs; -TDeletingArray Models; - void RenderFrameModels(FModelRenderer* renderer, FLevelLocals* Level, const FSpriteModelFrame* smf, const FState* curState, const int curTics, const PClass* ti, int translation); @@ -290,198 +284,10 @@ void RenderFrameModels(FModelRenderer *renderer, FLevelLocals *Level, const FSpr } } -///////////////////////////////////////////////////////////////////////////// -void FlushModels() -{ - for (int i = Models.Size() - 1; i >= 0; i--) - { - Models[i]->DestroyVertexBuffer(); - } -} - -///////////////////////////////////////////////////////////////////////////// - -FModel::FModel() -{ - for (int i = 0; i < NumModelRendererTypes; i++) - mVBuf[i] = nullptr; -} - -FModel::~FModel() -{ - DestroyVertexBuffer(); -} - -void FModel::DestroyVertexBuffer() -{ - for (int i = 0; i < NumModelRendererTypes; i++) - { - delete mVBuf[i]; - mVBuf[i] = nullptr; - } -} - -static TArray SpriteModelFrames; static TArray SpriteModelHash; //TArray StateModelFrames; -//=========================================================================== -// -// FindGFXFile -// -//=========================================================================== - -static int FindGFXFile(FString & fn) -{ - int lump = fileSystem.CheckNumForFullName(fn); // if we find something that matches the name plus the extension, return it and do not enter the substitution logic below. - if (lump != -1) return lump; - - int best = -1; - int dot = fn.LastIndexOf('.'); - int slash = fn.LastIndexOf('/'); - if (dot > slash) fn.Truncate(dot); - - static const char * extensions[] = { ".png", ".jpg", ".tga", ".pcx", nullptr }; - - for (const char ** extp=extensions; *extp; extp++) - { - int lump = fileSystem.CheckNumForFullName(fn + *extp); - if (lump >= best) best = lump; - } - return best; -} - - -//=========================================================================== -// -// LoadSkin -// -//=========================================================================== - -FTextureID LoadSkin(const char * path, const char * fn) -{ - FString buffer; - - buffer.Format("%s%s", path, fn); - - int texlump = FindGFXFile(buffer); - const char * const texname = texlump < 0 ? fn : fileSystem.GetFileFullName(texlump); - return TexMan.CheckForTexture(texname, ETextureType::Any, FTextureManager::TEXMAN_TryAny); -} - -//=========================================================================== -// -// ModelFrameHash -// -//=========================================================================== - -static int ModelFrameHash(FSpriteModelFrame * smf) -{ - const uint32_t *table = GetCRCTable (); - uint32_t hash = 0xffffffff; - - const char * s = (const char *)(&smf->type); // this uses type, sprite and frame for hashing - const char * se= (const char *)(&smf->hashnext); - - for (; smFileName.CompareNoCase(fullname)) return i; - } - - int len = fileSystem.FileLength(lump); - FileData lumpd = fileSystem.ReadFile(lump); - char * buffer = (char*)lumpd.GetMem(); - - if ( (size_t)fullname.LastIndexOf("_d.3d") == fullname.Len()-5 ) - { - FString anivfile = fullname.GetChars(); - anivfile.Substitute("_d.3d","_a.3d"); - if ( fileSystem.CheckNumForFullName(anivfile) > 0 ) - { - model = new FUE1Model; - } - } - else if ( (size_t)fullname.LastIndexOf("_a.3d") == fullname.Len()-5 ) - { - FString datafile = fullname.GetChars(); - datafile.Substitute("_a.3d","_d.3d"); - if ( fileSystem.CheckNumForFullName(datafile) > 0 ) - { - model = new FUE1Model; - } - } - else if ( (size_t)fullname.LastIndexOf(".obj") == fullname.Len() - 4 ) - { - model = new FOBJModel; - } - else if (!memcmp(buffer, "DMDM", 4)) - { - model = new FDMDModel; - } - else if (!memcmp(buffer, "IDP2", 4)) - { - model = new FMD2Model; - } - else if (!memcmp(buffer, "IDP3", 4)) - { - model = new FMD3Model; - } - - if (model != nullptr) - { - if (!model->Load(path, lump, buffer, len)) - { - delete model; - return -1; - } - } - else - { - // try loading as a voxel - FVoxel *voxel = R_LoadKVX(lump); - if (voxel != nullptr) - { - model = new FVoxelModel(voxel, true); - } - else - { - Printf("LoadModel: Unknown model format in '%s'\n", fullname.GetChars()); - return -1; - } - } - // The vertex buffer cannot be initialized here because this gets called before OpenGL is initialized - model->mFileName = fullname; - return Models.Push(model); -} - //=========================================================================== // // InitModels From b79230da9b331d3fe8b9e83c440f28c8de392ae4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 19:46:13 +0200 Subject: [PATCH 121/220] - added missing include to macOS code. --- src/common/platform/posix/cocoa/i_input.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/platform/posix/cocoa/i_input.mm b/src/common/platform/posix/cocoa/i_input.mm index 8b81f86add..dad875fba0 100644 --- a/src/common/platform/posix/cocoa/i_input.mm +++ b/src/common/platform/posix/cocoa/i_input.mm @@ -46,6 +46,7 @@ #include "i_interface.h" #include "menustate.h" #include "engineerrors.h" +#include "keydef.h" EXTERN_CVAR(Int, m_use_mouse) From d434ce32c8750527dfb93c5efed890ba1d4c1fac Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 19:46:27 +0200 Subject: [PATCH 122/220] - split voxels.cpp into a backend and a game dependent part. --- src/CMakeLists.txt | 1 + src/r_data/sprites.cpp | 1 + src/r_data/voxeldef.cpp | 274 ++++++++++++++++++++++++++++++++++++++++ src/r_data/voxels.cpp | 229 +-------------------------------- src/r_data/voxels.h | 3 +- 5 files changed, 281 insertions(+), 227 deletions(-) create mode 100644 src/r_data/voxeldef.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 18acfc0366..8ae9265ab3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -997,6 +997,7 @@ set (PCH_SOURCES r_data/sprites.cpp r_data/portalgroups.cpp r_data/voxels.cpp + r_data/voxeldef.cpp r_data/r_canvastexture.cpp r_data/r_interpolate.cpp r_data/r_vanillatrans.cpp diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index 6dfc34d969..5add837330 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -36,6 +36,7 @@ #include "texturemanager.h" void InitModels(); +void R_InitVoxels(); // variables used to look up // and range check thing_t sprites patches diff --git a/src/r_data/voxeldef.cpp b/src/r_data/voxeldef.cpp new file mode 100644 index 0000000000..300872ffc0 --- /dev/null +++ b/src/r_data/voxeldef.cpp @@ -0,0 +1,274 @@ + +/* +** voxels.cpp +** +**--------------------------------------------------------------------------- +** Copyright 2010-2011 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +** +*/ + +#include +#include +#include +#include + +#include "m_swap.h" +#include "m_argv.h" +#include "filesystem.h" +#include "v_video.h" +#include "sc_man.h" +#include "voxels.h" +#include "info.h" +#include "s_sound.h" +#include "sbar.h" +#include "g_level.h" +#include "r_data/sprites.h" + +struct VoxelOptions +{ + VoxelOptions() + : DroppedSpin(0), PlacedSpin(0), Scale(1.), AngleOffset(90.), OverridePalette(false) + {} + + int DroppedSpin; + int PlacedSpin; + double Scale; + DAngle AngleOffset; + bool OverridePalette; +}; + +void VOX_AddVoxel(int sprnum, int frame, FVoxelDef* def); + +//========================================================================== +// +// VOX_ReadSpriteNames +// +// Reads a list of sprite names from a VOXELDEF lump. +// +//========================================================================== + +static bool VOX_ReadSpriteNames(FScanner &sc, TArray &vsprites) +{ + vsprites.Clear(); + while (sc.GetString()) + { + // A sprite name list is terminated by an '=' character. + if (sc.String[0] == '=') + { + if (vsprites.Size() == 0) + { + sc.ScriptMessage("No sprites specified for voxel.\n"); + } + return true; + } + if (sc.StringLen != 4 && sc.StringLen != 5) + { + sc.ScriptMessage("Sprite name \"%s\" is wrong size.\n", sc.String); + } + else if (sc.StringLen == 5 && (sc.String[4] = toupper(sc.String[4]), sc.String[4] < 'A' || sc.String[4] >= 'A' + MAX_SPRITE_FRAMES)) + { + sc.ScriptMessage("Sprite frame %c is invalid.\n", sc.String[4]); + } + else + { + int frame = (sc.StringLen == 4) ? 255 : sc.String[4] - 'A'; + int i = GetSpriteIndex(sc.String, false); + if (i != -1) + { + vsprites.Push((frame << 24) | i); + } + } + } + if (vsprites.Size() != 0) + { + sc.ScriptMessage("Unexpected end of file\n"); + } + return false; +} + +//========================================================================== +// +// VOX_ReadOptions +// +// Reads a list of options from a VOXELDEF lump, terminated with a '}' +// character. The leading '{' must already be consumed +// +//========================================================================== + +static void VOX_ReadOptions(FScanner &sc, VoxelOptions &opts) +{ + while (sc.GetToken()) + { + if (sc.TokenType == '}') + { + return; + } + sc.TokenMustBe(TK_Identifier); + if (sc.Compare("scale")) + { + sc.MustGetToken('='); + sc.MustGetToken(TK_FloatConst); + opts.Scale = sc.Float; + } + else if (sc.Compare("spin")) + { + int mul = 1; + sc.MustGetToken('='); + if (sc.CheckToken('-')) mul = -1; + sc.MustGetToken(TK_IntConst); + opts.DroppedSpin = opts.PlacedSpin = sc.Number*mul; + } + else if (sc.Compare("placedspin")) + { + int mul = 1; + sc.MustGetToken('='); + if (sc.CheckToken('-')) mul = -1; + sc.MustGetToken(TK_IntConst); + opts.PlacedSpin = sc.Number*mul; + } + else if (sc.Compare("droppedspin")) + { + int mul = 1; + sc.MustGetToken('='); + if (sc.CheckToken('-')) mul = -1; + sc.MustGetToken(TK_IntConst); + opts.DroppedSpin = sc.Number*mul; + } + else if (sc.Compare("angleoffset")) + { + int mul = 1; + sc.MustGetToken('='); + if (sc.CheckToken('-')) mul = -1; + sc.MustGetAnyToken(); + if (sc.TokenType == TK_IntConst) + { + sc.Float = sc.Number; + } + else + { + sc.TokenMustBe(TK_FloatConst); + } + opts.AngleOffset = mul * sc.Float + 90.; + } + else if (sc.Compare("overridepalette")) + { + opts.OverridePalette = true; + } + else + { + sc.ScriptMessage("Unknown voxel option '%s'\n", sc.String); + if (sc.CheckToken('=')) + { + sc.MustGetAnyToken(); + } + } + } + sc.ScriptMessage("Unterminated voxel option block\n"); +} + +//========================================================================== +// +// R_InitVoxels +// +// Process VOXELDEF lumps for defining voxel options that cannot be +// condensed neatly into a sprite name format. +// +//========================================================================== + +void R_InitVoxels() +{ + int lump, lastlump = 0; + + while ((lump = fileSystem.FindLump("VOXELDEF", &lastlump)) != -1) + { + FScanner sc(lump); + TArray vsprites; + + while (VOX_ReadSpriteNames(sc, vsprites)) + { + FVoxel *voxeldata = NULL; + int voxelfile; + VoxelOptions opts; + + sc.SetCMode(true); + sc.MustGetToken(TK_StringConst); + voxelfile = fileSystem.CheckNumForFullName(sc.String, true, ns_voxels); + if (voxelfile < 0) + { + sc.ScriptMessage("Voxel \"%s\" not found.\n", sc.String); + } + else + { + voxeldata = VOX_GetVoxel(voxelfile); + if (voxeldata == NULL) + { + sc.ScriptMessage("\"%s\" is not a valid voxel file.\n", sc.String); + } + } + if (sc.CheckToken('{')) + { + VOX_ReadOptions(sc, opts); + } + sc.SetCMode(false); + if (voxeldata != NULL && vsprites.Size() != 0) + { + if (opts.OverridePalette) + { + voxeldata->RemovePalette(); + } + FVoxelDef *def = new FVoxelDef; + + def->Voxel = voxeldata; + def->Scale = opts.Scale; + def->DroppedSpin = opts.DroppedSpin; + def->PlacedSpin = opts.PlacedSpin; + def->AngleOffset = opts.AngleOffset; + VoxelDefs.Push(def); + + for (unsigned i = 0; i < vsprites.Size(); ++i) + { + int sprnum = int(vsprites[i] & 0xFFFFFF); + int frame = int(vsprites[i] >> 24); + if (frame == 255) + { // Apply voxel to all frames. + for (int j = MAX_SPRITE_FRAMES - 1; j >= 0; --j) + { + VOX_AddVoxel(sprnum, j, def); + } + } + else + { // Apply voxel to only one frame. + VOX_AddVoxel(sprnum, frame, def); + } + } + } + } + } +} + diff --git a/src/r_data/voxels.cpp b/src/r_data/voxels.cpp index 71666918ef..74c6cac387 100644 --- a/src/r_data/voxels.cpp +++ b/src/r_data/voxels.cpp @@ -42,31 +42,15 @@ #include "filesystem.h" #include "v_video.h" #include "sc_man.h" -#include "s_sound.h" -#include "sbar.h" -#include "g_level.h" -#include "r_data/sprites.h" #include "voxels.h" #include "info.h" +#include "printf.h" void VOX_AddVoxel(int sprnum, int frame, FVoxelDef *def); TDeletingArray Voxels; // used only to auto-delete voxels on exit. TDeletingArray VoxelDefs; -struct VoxelOptions -{ - VoxelOptions() - : DroppedSpin(0), PlacedSpin(0), Scale(1.), AngleOffset(90.), OverridePalette(false) - {} - - int DroppedSpin; - int PlacedSpin; - double Scale; - DAngle AngleOffset; - bool OverridePalette; -}; - //========================================================================== // // GetVoxelRemap @@ -476,134 +460,6 @@ void FVoxel::RemovePalette() } - -//========================================================================== -// -// VOX_ReadSpriteNames -// -// Reads a list of sprite names from a VOXELDEF lump. -// -//========================================================================== - -static bool VOX_ReadSpriteNames(FScanner &sc, TArray &vsprites) -{ - vsprites.Clear(); - while (sc.GetString()) - { - // A sprite name list is terminated by an '=' character. - if (sc.String[0] == '=') - { - if (vsprites.Size() == 0) - { - sc.ScriptMessage("No sprites specified for voxel.\n"); - } - return true; - } - if (sc.StringLen != 4 && sc.StringLen != 5) - { - sc.ScriptMessage("Sprite name \"%s\" is wrong size.\n", sc.String); - } - else if (sc.StringLen == 5 && (sc.String[4] = toupper(sc.String[4]), sc.String[4] < 'A' || sc.String[4] >= 'A' + MAX_SPRITE_FRAMES)) - { - sc.ScriptMessage("Sprite frame %c is invalid.\n", sc.String[4]); - } - else - { - int frame = (sc.StringLen == 4) ? 255 : sc.String[4] - 'A'; - int i = GetSpriteIndex(sc.String, false); - if (i != -1) - { - vsprites.Push((frame << 24) | i); - } - } - } - if (vsprites.Size() != 0) - { - sc.ScriptMessage("Unexpected end of file\n"); - } - return false; -} - -//========================================================================== -// -// VOX_ReadOptions -// -// Reads a list of options from a VOXELDEF lump, terminated with a '}' -// character. The leading '{' must already be consumed -// -//========================================================================== - -static void VOX_ReadOptions(FScanner &sc, VoxelOptions &opts) -{ - while (sc.GetToken()) - { - if (sc.TokenType == '}') - { - return; - } - sc.TokenMustBe(TK_Identifier); - if (sc.Compare("scale")) - { - sc.MustGetToken('='); - sc.MustGetToken(TK_FloatConst); - opts.Scale = sc.Float; - } - else if (sc.Compare("spin")) - { - int mul = 1; - sc.MustGetToken('='); - if (sc.CheckToken('-')) mul = -1; - sc.MustGetToken(TK_IntConst); - opts.DroppedSpin = opts.PlacedSpin = sc.Number*mul; - } - else if (sc.Compare("placedspin")) - { - int mul = 1; - sc.MustGetToken('='); - if (sc.CheckToken('-')) mul = -1; - sc.MustGetToken(TK_IntConst); - opts.PlacedSpin = sc.Number*mul; - } - else if (sc.Compare("droppedspin")) - { - int mul = 1; - sc.MustGetToken('='); - if (sc.CheckToken('-')) mul = -1; - sc.MustGetToken(TK_IntConst); - opts.DroppedSpin = sc.Number*mul; - } - else if (sc.Compare("angleoffset")) - { - int mul = 1; - sc.MustGetToken('='); - if (sc.CheckToken('-')) mul = -1; - sc.MustGetAnyToken(); - if (sc.TokenType == TK_IntConst) - { - sc.Float = sc.Number; - } - else - { - sc.TokenMustBe(TK_FloatConst); - } - opts.AngleOffset = mul * sc.Float + 90.; - } - else if (sc.Compare("overridepalette")) - { - opts.OverridePalette = true; - } - else - { - sc.ScriptMessage("Unknown voxel option '%s'\n", sc.String); - if (sc.CheckToken('=')) - { - sc.MustGetAnyToken(); - } - } - } - sc.ScriptMessage("Unterminated voxel option block\n"); -} - //========================================================================== // // VOX_GetVoxel @@ -613,7 +469,7 @@ static void VOX_ReadOptions(FScanner &sc, VoxelOptions &opts) // //========================================================================== -static FVoxel *VOX_GetVoxel(int lumpnum) +FVoxel* VOX_GetVoxel(int lumpnum) { // Is this voxel already loaded? If so, return it. for (unsigned i = 0; i < Voxels.Size(); ++i) @@ -623,7 +479,7 @@ static FVoxel *VOX_GetVoxel(int lumpnum) return Voxels[i]; } } - FVoxel *vox = R_LoadKVX(lumpnum); + FVoxel* vox = R_LoadKVX(lumpnum); if (vox != NULL) { Voxels.Push(vox); @@ -631,83 +487,4 @@ static FVoxel *VOX_GetVoxel(int lumpnum) return vox; } -//========================================================================== -// -// R_InitVoxels -// -// Process VOXELDEF lumps for defining voxel options that cannot be -// condensed neatly into a sprite name format. -// -//========================================================================== - -void R_InitVoxels() -{ - int lump, lastlump = 0; - - while ((lump = fileSystem.FindLump("VOXELDEF", &lastlump)) != -1) - { - FScanner sc(lump); - TArray vsprites; - - while (VOX_ReadSpriteNames(sc, vsprites)) - { - FVoxel *voxeldata = NULL; - int voxelfile; - VoxelOptions opts; - - sc.SetCMode(true); - sc.MustGetToken(TK_StringConst); - voxelfile = fileSystem.CheckNumForFullName(sc.String, true, ns_voxels); - if (voxelfile < 0) - { - sc.ScriptMessage("Voxel \"%s\" not found.\n", sc.String); - } - else - { - voxeldata = VOX_GetVoxel(voxelfile); - if (voxeldata == NULL) - { - sc.ScriptMessage("\"%s\" is not a valid voxel file.\n", sc.String); - } - } - if (sc.CheckToken('{')) - { - VOX_ReadOptions(sc, opts); - } - sc.SetCMode(false); - if (voxeldata != NULL && vsprites.Size() != 0) - { - if (opts.OverridePalette) - { - voxeldata->RemovePalette(); - } - FVoxelDef *def = new FVoxelDef; - - def->Voxel = voxeldata; - def->Scale = opts.Scale; - def->DroppedSpin = opts.DroppedSpin; - def->PlacedSpin = opts.PlacedSpin; - def->AngleOffset = opts.AngleOffset; - VoxelDefs.Push(def); - - for (unsigned i = 0; i < vsprites.Size(); ++i) - { - int sprnum = int(vsprites[i] & 0xFFFFFF); - int frame = int(vsprites[i] >> 24); - if (frame == 255) - { // Apply voxel to all frames. - for (int j = MAX_SPRITE_FRAMES - 1; j >= 0; --j) - { - VOX_AddVoxel(sprnum, j, def); - } - } - else - { // Apply voxel to only one frame. - VOX_AddVoxel(sprnum, frame, def); - } - } - } - } - } -} diff --git a/src/r_data/voxels.h b/src/r_data/voxels.h index 60a149be9c..ea71d2b0cb 100644 --- a/src/r_data/voxels.h +++ b/src/r_data/voxels.h @@ -76,8 +76,9 @@ struct FVoxelDef extern TDeletingArray Voxels; // used only to auto-delete voxels on exit. extern TDeletingArray VoxelDefs; +FVoxel* VOX_GetVoxel(int lumpnum); + FVoxel *R_LoadKVX(int lumpnum); FVoxelDef *R_LoadVoxelDef(int lumpnum, int spin); -void R_InitVoxels(); #endif From 573b2958c66cdc03a489c1d0205b2caca0b0c3f6 Mon Sep 17 00:00:00 2001 From: PaulyB <43163391+3saster@users.noreply.github.com> Date: Fri, 24 Apr 2020 19:16:06 -0700 Subject: [PATCH 123/220] Added MTF_NOCOUNT to spawn flags --- src/doomdata.h | 1 + src/playsim/p_mobj.cpp | 13 +++++++++++++ wadsrc/static/zscript/constants.zs | 1 + 3 files changed, 15 insertions(+) diff --git a/src/doomdata.h b/src/doomdata.h index 572ebb61eb..d52d823892 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -418,6 +418,7 @@ enum EMapThingFlags MTF_SECRET = 0x080000, // Secret pickup MTF_NOINFIGHTING = 0x100000, + MTF_NOCOUNT = 0x200000, // Removes COUNTKILL/COUNTITEM // BOOM and DOOM compatible versions of some of the above diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index de0ff1b6b9..0f6f32e9d4 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -4664,6 +4664,19 @@ void AActor::HandleSpawnFlags () Level->total_secrets++; } } + if (SpawnFlags & MTF_NOCOUNT) + { + if (flags & MF_COUNTKILL) + { + flags &= ~MF_COUNTKILL; + Level->total_monsters--; + } + if (flags & MF_COUNTITEM) + { + flags &= ~MF_COUNTITEM; + Level->total_items--; + } + } } DEFINE_ACTION_FUNCTION(AActor, HandleSpawnFlags) diff --git a/wadsrc/static/zscript/constants.zs b/wadsrc/static/zscript/constants.zs index 02e6d4fced..725044afe1 100644 --- a/wadsrc/static/zscript/constants.zs +++ b/wadsrc/static/zscript/constants.zs @@ -997,6 +997,7 @@ enum EMapThingFlags MTF_SECRET = 0x080000, // Secret pickup MTF_NOINFIGHTING = 0x100000, + MTF_NOCOUNT = 0x200000, // Removes COUNTKILL/COUNTITEM }; enum ESkillProperty From 3377486b8e38b11d308b7a79a10dfd57e3a4004a Mon Sep 17 00:00:00 2001 From: Skepticist Date: Sun, 26 Apr 2020 23:34:57 -0700 Subject: [PATCH 124/220] Added a number of maps that can make use of the MTF_NOCOUNT flag All but the Hell Revealed case are thanks to Skepticist from Doomworld --- wadsrc/static/zscript/level_compatibility.zs | 151 +++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/wadsrc/static/zscript/level_compatibility.zs b/wadsrc/static/zscript/level_compatibility.zs index 44fb88e71d..ee81f4d7a8 100644 --- a/wadsrc/static/zscript/level_compatibility.zs +++ b/wadsrc/static/zscript/level_compatibility.zs @@ -1040,6 +1040,20 @@ class LevelCompatibility : LevelPostProcessor ClearSectorTags(214); break; } + case '9A4615498C3451413F1CD3D15099ACC7': // Eternal Doom map05 + { + // an imp and two cyberdemons are located at the softlock area + SetThingFlags(272, GetThingFlags (272) | MTF_NOCOUNT); + SetThingFlags(273, GetThingFlags (273) | MTF_NOCOUNT); + SetThingFlags(274, GetThingFlags (274) | MTF_NOCOUNT); + break; + } + case '8B55842D5A509902738040AF10B4E787': // Eternal Doom map10 + { + // soulsphere at the end of the level is there merely to replicate the start of the next map + SetThingFlags(548, GetThingFlags (548) | MTF_NOCOUNT); + break; + } case 'DCE862393CAAA6FF1294FB7056B53057': // UAC Ultra map07 { @@ -1488,6 +1502,16 @@ class LevelCompatibility : LevelPostProcessor SetLineFlags(2040, Line.ML_REPEAT_SPECIAL); break; } + case '145C4DFCF843F2B92C73036BA0E1D98A': // Hell Revealed MAP26 + { + // The 4 archviles that produce the ghost monsters cannot be killed + // Make them not count so they still produce ghosts while allowing 100% kills. + SetThingFlags(320, GetThingFlags (320) | MTF_NOCOUNT); + SetThingFlags(347, GetThingFlags (347) | MTF_NOCOUNT); + SetThingFlags(495, GetThingFlags (495) | MTF_NOCOUNT); + SetThingFlags(496, GetThingFlags (496) | MTF_NOCOUNT); + break; + } case '0E379EEBEB189F294ED122BC60D10A68': // Hellbound MAP29 { @@ -1948,6 +1972,133 @@ class LevelCompatibility : LevelPostProcessor SetSectorSpecial(240, 0); break; } + + case '1497894956B3C8EBE8A240B7FDD99C6A': // Memento Mori 2 MAP25 + { + // an imp is used for the lift activation and cannot be killed + SetThingFlags(51, GetThingFlags (51) | MTF_NOCOUNT); + break; + } + + case '51960F3E9D46449E98DBC7D97F49DB23': // Shotgun Symphony E1M1 + { + // harmless cyberdemon included for the 'story' sake + SetThingFlags(158, GetThingFlags (158) | MTF_NOCOUNT); + break; + } + + case '60D362BAE16B4C10A1DCEE442C878CAE': // 50 Shades of Graytall MAP06 + { + // there are four invisibility spheres used for decoration + SetThingFlags(144, GetThingFlags (144) | MTF_NOCOUNT); + SetThingFlags(145, GetThingFlags (145) | MTF_NOCOUNT); + SetThingFlags(194, GetThingFlags (194) | MTF_NOCOUNT); + SetThingFlags(195, GetThingFlags (195) | MTF_NOCOUNT); + break; + } + + case 'C104E740CC3F70BCFD5D2EA8E833318D': // 50 Monsters MAP29 + { + // there are two invisibility spheres used for decoration + SetThingFlags(111, GetThingFlags (111) | MTF_NOCOUNT); + SetThingFlags(112, GetThingFlags (112) | MTF_NOCOUNT); + break; + } + + case '76393C84102480A4C75A4674C9C3217A': // Deadly Standards 2 E2M8 + { + // 923 lost souls are used as environmental hazard + for (int i = 267; i < 275; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 482; i < 491; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 510; i < 522; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 880; i < 1510; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 1622; i < 1660; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + + for (int i = 1682; i < 1820; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 1847; i < 1875; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 2110; i < 2114; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 2243; i < 2293; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + + SetThingFlags(493, GetThingFlags (493) | MTF_NOCOUNT); + SetThingFlags(573, GetThingFlags (573) | MTF_NOCOUNT); + SetThingFlags(613, GetThingFlags (613) | MTF_NOCOUNT); + SetThingFlags(614, GetThingFlags (614) | MTF_NOCOUNT); + SetThingFlags(1679, GetThingFlags (1679) | MTF_NOCOUNT); + SetThingFlags(1680, GetThingFlags (1680) | MTF_NOCOUNT); + break; + } + + case '42B4D294A60BE4E3500AF150291CF6D4': // Hell Ground MAP05 + { + // 5 cyberdemons are located at the 'pain end' sector + for (int i = 523; i < 528; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + break; + } + + case '0C0513A9821F26F3D7997E3B0359A318': // Mayhem 1500 MAP06 + { + // there's an archvile behind the bossbrain at the very end that can't be killed + SetThingFlags(61, GetThingFlags (61) | MTF_NOCOUNT); + break; + } + + case '00641DA23DDE998F6725BC5896A0DBC2': // 20 Years of Doom E1M8 + { + // 32 lost souls are located at the 'pain end' sector + for (int i = 1965; i < 1975; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 2189; i < 2202; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 2311; i < 2320; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + break; + } + + case 'EEBDD9CA280F6FF06C30AF2BEE85BF5F': // 2002ad10.wad E3M3 + { + // swarm of cacodemons at the end meant to be pseudo-endless and not killed + for (int i = 467; i < 547; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + break; + } + + case '988DFF5BB7073B857DEE3957A91C8518': // Speed of Doom MAP14 + { + // you can get only one of the soulspheres, the other, depending on your choice, becomes unavailable + SetThingFlags(1044, GetThingFlags (1044) | MTF_NOCOUNT); + SetThingFlags(1045, GetThingFlags (1045) | MTF_NOCOUNT); + break; + } + + case '361734AC5D78E872A05335C83E4F6DB8': // inf-lutz.wad E3M8 + { + // there is a trap with 10 cyberdemons at the end of the map, you are not meant to kill them + for (int i = 541; i < 546; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + for (int i = 638; i < 643; i++) + SetThingFlags (i, GetThingFlags (i) | MTF_NOCOUNT); + break; + } + + case '8F844B272E7235E82EA78AD2A2EB2D4A': // Serenity E3M7 + { + // two spheres can't be obtained and thus should not count towards 100% items + SetThingFlags(443, GetThingFlags (443) | MTF_NOCOUNT); + SetThingFlags(444, GetThingFlags (444) | MTF_NOCOUNT); + // one secret is unobtainable + SetSectorSpecial (97, 0); + break; + } } } } From 8d1451689b51ce992b9787e6bb4136268a264bc0 Mon Sep 17 00:00:00 2001 From: PaulyB <43163391+3saster@users.noreply.github.com> Date: Mon, 27 Apr 2020 00:35:07 -0700 Subject: [PATCH 125/220] Exposed MTF_NOCOUNT to UDMF --- src/common/engine/namedef.h | 1 + src/maploader/udmf.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/common/engine/namedef.h b/src/common/engine/namedef.h index 5cafc87ce9..7d7cff000e 100644 --- a/src/common/engine/namedef.h +++ b/src/common/engine/namedef.h @@ -462,6 +462,7 @@ xx(Friend) xx(Strifeally) xx(Standing) xx(Countsecret) +xx(NoCount) xx(Score) xx(Roll) xx(Scale) diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index 5a059be0b0..febaae9453 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -637,6 +637,10 @@ public: Flag(th->flags, MTF_SECRET, key); break; + case NAME_NoCount: + Flag(th->flags, MTF_NOCOUNT, key); + break; + case NAME_Floatbobphase: CHECK_N(Zd | Zdt) th->FloatbobPhase = CheckInt(key); From 66bac4561501a6fa8de40940e86239ecfe806034 Mon Sep 17 00:00:00 2001 From: PaulyB <43163391+3saster@users.noreply.github.com> Date: Mon, 27 Apr 2020 11:25:41 -0700 Subject: [PATCH 126/220] Properly namespaced UDMF flag --- src/maploader/udmf.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/maploader/udmf.cpp b/src/maploader/udmf.cpp index febaae9453..e4428263a3 100644 --- a/src/maploader/udmf.cpp +++ b/src/maploader/udmf.cpp @@ -638,6 +638,7 @@ public: break; case NAME_NoCount: + CHECK_N(Zd | Zdt) Flag(th->flags, MTF_NOCOUNT, key); break; From 3ee1aa76c30715a07cc6ee8a42be8b5547c474f5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 20:50:46 +0200 Subject: [PATCH 127/220] - moved model code to 'common'. --- src/CMakeLists.txt | 21 ++++++++++--------- src/{r_data => common}/models/model.cpp | 12 +++++------ src/{r_data => common}/models/model.h | 0 src/{r_data => common}/models/model_kvx.h | 8 +++++++ src/{r_data => common}/models/model_md2.h | 0 src/{r_data => common}/models/model_md3.h | 0 src/{r_data => common}/models/model_obj.h | 0 src/{r_data => common}/models/model_ue1.h | 0 src/{r_data => common}/models/modelrenderer.h | 0 src/{r_data => common}/models/models_md2.cpp | 3 +-- src/{r_data => common}/models/models_md3.cpp | 3 +-- src/{r_data => common}/models/models_obj.cpp | 2 +- src/{r_data => common}/models/models_ue1.cpp | 2 +- .../models/models_voxel.cpp | 3 --- src/{r_data => common}/models/tab_anorms.h | 0 src/{r_data => common/models}/voxels.cpp | 0 src/{r_data => common/models}/voxels.h | 0 src/r_data/{models => }/models.cpp | 2 +- src/r_data/{models => }/models.h | 2 +- src/r_data/sprites.cpp | 2 +- src/rendering/gl/renderer/gl_renderer.cpp | 2 +- src/rendering/hwrenderer/models/hw_models.h | 6 +++--- .../hwrenderer/scene/hw_drawinfo.cpp | 4 ++-- .../hwrenderer/scene/hw_spritelight.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 2 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 2 +- .../hwrenderer/textures/hw_precache.cpp | 4 ++-- .../polyrenderer/drawers/poly_thread.cpp | 2 +- .../polyrenderer/drawers/poly_triangle.cpp | 2 +- src/rendering/swrenderer/r_swrenderer.cpp | 2 +- src/rendering/swrenderer/things/r_model.h | 2 +- .../swrenderer/things/r_particle.cpp | 2 +- .../swrenderer/things/r_playersprite.cpp | 2 +- src/rendering/swrenderer/things/r_sprite.cpp | 2 +- src/rendering/swrenderer/things/r_voxel.cpp | 2 +- .../swrenderer/things/r_wallsprite.cpp | 2 +- 36 files changed, 52 insertions(+), 48 deletions(-) rename src/{r_data => common}/models/model.cpp (96%) rename src/{r_data => common}/models/model.h (100%) rename src/{r_data => common}/models/model_kvx.h (92%) rename src/{r_data => common}/models/model_md2.h (100%) rename src/{r_data => common}/models/model_md3.h (100%) rename src/{r_data => common}/models/model_obj.h (100%) rename src/{r_data => common}/models/model_ue1.h (100%) rename src/{r_data => common}/models/modelrenderer.h (100%) rename src/{r_data => common}/models/models_md2.cpp (99%) rename src/{r_data => common}/models/models_md3.cpp (99%) rename src/{r_data => common}/models/models_obj.cpp (99%) rename src/{r_data => common}/models/models_ue1.cpp (99%) rename src/{r_data => common}/models/models_voxel.cpp (99%) rename src/{r_data => common}/models/tab_anorms.h (100%) rename src/{r_data => common/models}/voxels.cpp (100%) rename src/{r_data => common/models}/voxels.h (100%) rename src/r_data/{models => }/models.cpp (99%) rename src/r_data/{models => }/models.h (99%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ae9265ab3..55408d4fae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -595,7 +595,6 @@ file( GLOB HEADER_FILES sound/backend/*.h* posix/*.h r_data/*.h - r_data/models/*.h common/audio/sound/thirdparty/*.h common/audio/sound/*.h common/audio/music/*.h* @@ -610,6 +609,7 @@ file( GLOB HEADER_FILES common/platform/posix/cocoa/*.h common/platform/posix/sdl/*.h common/platform/win32/*.h + common/models/*.h common/textures/*.h common/textures/hires/hqnx/*.h common/textures/hires/hqnx_asm/*.h @@ -996,19 +996,12 @@ set (PCH_SOURCES r_data/r_translate.cpp r_data/sprites.cpp r_data/portalgroups.cpp - r_data/voxels.cpp r_data/voxeldef.cpp r_data/r_canvastexture.cpp r_data/r_interpolate.cpp r_data/r_vanillatrans.cpp r_data/r_sections.cpp - r_data/models/models_md3.cpp - r_data/models/models_md2.cpp - r_data/models/models_voxel.cpp - r_data/models/models_ue1.cpp - r_data/models/models_obj.cpp - r_data/models/models.cpp - r_data/models/model.cpp + r_data/models.cpp scripting/vmiterators.cpp scripting/vmthunks.cpp scripting/vmthunks_actors.cpp @@ -1076,6 +1069,13 @@ set (PCH_SOURCES common/textures/formats/tgatexture.cpp common/textures/formats/stbtexture.cpp common/textures/hires/hqresize.cpp + common/models/models_md3.cpp + common/models/models_md2.cpp + common/models/models_voxel.cpp + common/models/models_ue1.cpp + common/models/models_obj.cpp + common/models/model.cpp + common/models/voxels.cpp common/console/c_commandline.cpp common/console/c_buttons.cpp common/console/c_bind.cpp @@ -1249,6 +1249,7 @@ include_directories( . common/textures/formats common/textures/hires common/textures + common/models common/filesystem common/utility common/console @@ -1441,7 +1442,6 @@ source_group("Rendering\\Poly Renderer\\Math" REGULAR_EXPRESSION "^${CMAKE_CURRE source_group("Rendering\\Poly Renderer\\Drawers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/drawers/.+") source_group("Rendering\\Poly Renderer\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/backend/.+") source_group("Render Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r_data/.+") -source_group("Render Data\\Models" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r_data/models/.+") source_group("Render Interface" FILES r_defs.h r_renderer.h r_sky.cpp r_sky.h r_state.h r_utility.cpp r_utility.h) source_group("Platforms\\POSIX Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/.+") source_group("Platforms\\Win32 Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/win32/.+") @@ -1480,6 +1480,7 @@ source_group("Common\\Rendering\\Hardware Renderer\\Data" REGULAR_EXPRESSION "^$ source_group("Common\\Rendering\\Hardware Renderer\\Postprocessing" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/postprocessing/.+") source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+") source_group("Common\\Rendering\\OpenGL Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl/.+") +source_group("Common\\Models" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/models/.+") source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+") source_group("Common\\Textures\\Hires" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/.+") source_group("Common\\Textures\\Hires\\HQ Resize" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/hqnx/.+") diff --git a/src/r_data/models/model.cpp b/src/common/models/model.cpp similarity index 96% rename from src/r_data/models/model.cpp rename to src/common/models/model.cpp index 8c5ce7a807..bd5d9ced9f 100644 --- a/src/r_data/models/model.cpp +++ b/src/common/models/model.cpp @@ -31,12 +31,12 @@ #include "sc_man.h" #include "m_crc32.h" #include "printf.h" -#include "r_data/models/models.h" -#include "r_data/models/model_ue1.h" -#include "r_data/models/model_obj.h" -#include "r_data/models/model_md2.h" -#include "r_data/models/model_md3.h" -#include "r_data/models/model_kvx.h" +#include "models.h" +#include "model_ue1.h" +#include "model_obj.h" +#include "model_md2.h" +#include "model_md3.h" +#include "model_kvx.h" #include "i_time.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/model.h b/src/common/models/model.h similarity index 100% rename from src/r_data/models/model.h rename to src/common/models/model.h diff --git a/src/r_data/models/model_kvx.h b/src/common/models/model_kvx.h similarity index 92% rename from src/r_data/models/model_kvx.h rename to src/common/models/model_kvx.h index c934491e89..bea2fdfd2f 100644 --- a/src/r_data/models/model_kvx.h +++ b/src/common/models/model_kvx.h @@ -1,6 +1,14 @@ #pragma once #include "model.h" +#include "i_modelvertexbuffer.h" +#include "tarray.h" +#include "xs_Float.h" + +struct FVoxel; +struct kvxslab_t; +class FModelRenderer; +class FGameTexture; struct FVoxelVertexHash { diff --git a/src/r_data/models/model_md2.h b/src/common/models/model_md2.h similarity index 100% rename from src/r_data/models/model_md2.h rename to src/common/models/model_md2.h diff --git a/src/r_data/models/model_md3.h b/src/common/models/model_md3.h similarity index 100% rename from src/r_data/models/model_md3.h rename to src/common/models/model_md3.h diff --git a/src/r_data/models/model_obj.h b/src/common/models/model_obj.h similarity index 100% rename from src/r_data/models/model_obj.h rename to src/common/models/model_obj.h diff --git a/src/r_data/models/model_ue1.h b/src/common/models/model_ue1.h similarity index 100% rename from src/r_data/models/model_ue1.h rename to src/common/models/model_ue1.h diff --git a/src/r_data/models/modelrenderer.h b/src/common/models/modelrenderer.h similarity index 100% rename from src/r_data/models/modelrenderer.h rename to src/common/models/modelrenderer.h diff --git a/src/r_data/models/models_md2.cpp b/src/common/models/models_md2.cpp similarity index 99% rename from src/r_data/models/models_md2.cpp rename to src/common/models/models_md2.cpp index 03130aaccb..6e255cf405 100644 --- a/src/r_data/models/models_md2.cpp +++ b/src/common/models/models_md2.cpp @@ -27,8 +27,7 @@ **/ #include "filesystem.h" -#include "r_data/models/models.h" -#include "r_data/models/model_md2.h" +#include "model_md2.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_md3.cpp b/src/common/models/models_md3.cpp similarity index 99% rename from src/r_data/models/models_md3.cpp rename to src/common/models/models_md3.cpp index 4eafdaede1..15224e4fe9 100644 --- a/src/r_data/models/models_md3.cpp +++ b/src/common/models/models_md3.cpp @@ -22,8 +22,7 @@ #include "filesystem.h" #include "cmdlib.h" -#include "r_data/models/models.h" -#include "r_data/models/model_md3.h" +#include "model_md3.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_obj.cpp b/src/common/models/models_obj.cpp similarity index 99% rename from src/r_data/models/models_obj.cpp rename to src/common/models/models_obj.cpp index 643fc64f2d..54c237c653 100644 --- a/src/r_data/models/models_obj.cpp +++ b/src/common/models/models_obj.cpp @@ -20,7 +20,7 @@ //-------------------------------------------------------------------------- #include "filesystem.h" -#include "r_data/models/model_obj.h" +#include "model_obj.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_ue1.cpp b/src/common/models/models_ue1.cpp similarity index 99% rename from src/r_data/models/models_ue1.cpp rename to src/common/models/models_ue1.cpp index 73733c9bb7..1fb6146a1f 100644 --- a/src/r_data/models/models_ue1.cpp +++ b/src/common/models/models_ue1.cpp @@ -22,7 +22,7 @@ #include "filesystem.h" #include "cmdlib.h" -#include "r_data/models/model_ue1.h" +#include "model_ue1.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/r_data/models/models_voxel.cpp b/src/common/models/models_voxel.cpp similarity index 99% rename from src/r_data/models/models_voxel.cpp rename to src/common/models/models_voxel.cpp index eccd863bd5..42c21e1d03 100644 --- a/src/r_data/models/models_voxel.cpp +++ b/src/common/models/models_voxel.cpp @@ -27,11 +27,8 @@ **/ #include "filesystem.h" -#include "g_level.h" #include "colormatcher.h" #include "bitmap.h" -#include "g_levellocals.h" -#include "models.h" #include "model_kvx.h" #include "image.h" #include "texturemanager.h" diff --git a/src/r_data/models/tab_anorms.h b/src/common/models/tab_anorms.h similarity index 100% rename from src/r_data/models/tab_anorms.h rename to src/common/models/tab_anorms.h diff --git a/src/r_data/voxels.cpp b/src/common/models/voxels.cpp similarity index 100% rename from src/r_data/voxels.cpp rename to src/common/models/voxels.cpp diff --git a/src/r_data/voxels.h b/src/common/models/voxels.h similarity index 100% rename from src/r_data/voxels.h rename to src/common/models/voxels.h diff --git a/src/r_data/models/models.cpp b/src/r_data/models.cpp similarity index 99% rename from src/r_data/models/models.cpp rename to src/r_data/models.cpp index 7e8b963a8a..d98e554136 100644 --- a/src/r_data/models/models.cpp +++ b/src/r_data/models.cpp @@ -38,7 +38,7 @@ #include "d_player.h" #include "g_levellocals.h" #include "r_utility.h" -#include "r_data/models/models.h" +#include "models.h" #include "model_kvx.h" #include "i_time.h" #include "texturemanager.h" diff --git a/src/r_data/models/models.h b/src/r_data/models.h similarity index 99% rename from src/r_data/models/models.h rename to src/r_data/models.h index eb67a0c92f..715ca73be1 100644 --- a/src/r_data/models/models.h +++ b/src/r_data/models.h @@ -28,7 +28,7 @@ #include "m_bbox.h" #include "r_defs.h" #include "g_levellocals.h" -#include "r_data/voxels.h" +#include "voxels.h" #include "i_modelvertexbuffer.h" #include "model.h" diff --git a/src/r_data/sprites.cpp b/src/r_data/sprites.cpp index 5add837330..3b88669e80 100644 --- a/src/r_data/sprites.cpp +++ b/src/r_data/sprites.cpp @@ -31,7 +31,7 @@ #include "c_dispatch.h" #include "v_text.h" #include "r_data/sprites.h" -#include "r_data/voxels.h" +#include "voxels.h" #include "vm.h" #include "texturemanager.h" diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index e35446e796..15e151739c 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -58,7 +58,7 @@ #include "hw_lightbuffer.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "r_videoscale.h" -#include "r_data/models/models.h" +#include "model.h" #include "gl_postprocessstate.h" #include "gl_buffers.h" #include "texturemanager.h" diff --git a/src/rendering/hwrenderer/models/hw_models.h b/src/rendering/hwrenderer/models/hw_models.h index 6304e54ba5..28026905e0 100644 --- a/src/rendering/hwrenderer/models/hw_models.h +++ b/src/rendering/hwrenderer/models/hw_models.h @@ -24,11 +24,11 @@ #include "tarray.h" #include "p_pspr.h" -#include "r_data/voxels.h" -#include "r_data/models/models.h" +#include "voxels.h" +#include "models.h" #include "hwrenderer/data/buffers.h" #include "hw_modelvertexbuffer.h" -#include "r_data/models/modelrenderer.h" +#include "modelrenderer.h" class HWSprite; struct HWDrawInfo; diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 18204307f2..dd239bb25a 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -35,10 +35,10 @@ #include "hw_renderstate.h" #include "hw_drawinfo.h" #include "po_man.h" -#include "r_data/models/models.h" +#include "models.h" #include "hwrenderer/utility/hw_clock.h" #include "hw_cvars.h" -#include "hwrenderer/data/hw_viewpointbuffer.h" +#include "hw_viewpointbuffer.h" #include "flatvertices.h" #include "hw_lightbuffer.h" #include "hw_vrmodes.h" diff --git a/src/rendering/hwrenderer/scene/hw_spritelight.cpp b/src/rendering/hwrenderer/scene/hw_spritelight.cpp index 759f61a7dc..71b4868882 100644 --- a/src/rendering/hwrenderer/scene/hw_spritelight.cpp +++ b/src/rendering/hwrenderer/scene/hw_spritelight.cpp @@ -36,7 +36,7 @@ #include "hw_shadowmap.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" -#include "r_data/models/models.h" +#include "models.h" template T smoothstep(const T edge0, const T edge1, const T x) diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index c0dd3bd1ef..dbedea82cc 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -39,7 +39,7 @@ #include "actorinlines.h" #include "r_data/r_vanillatrans.h" #include "matrix.h" -#include "r_data/models/models.h" +#include "models.h" #include "vectors.h" #include "texturemanager.h" #include "basics.h" diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index 20ac4848b9..49e4728a4f 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -31,7 +31,7 @@ #include "doomstat.h" #include "d_player.h" #include "g_levellocals.h" -#include "r_data/models/models.h" +#include "models.h" #include "hw_weapon.h" #include "hw_fakeflat.h" #include "texturemanager.h" diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 4b1dbb15a6..58839f49ad 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -30,14 +30,14 @@ #include "c_dispatch.h" #include "r_state.h" #include "actor.h" -#include "r_data/models/models.h" +#include "models.h" #include "skyboxtexture.h" #include "hw_material.h" #include "image.h" #include "v_video.h" #include "v_font.h" #include "texturemanager.h" -#include "r_data/models/modelrenderer.h" +#include "modelrenderer.h" EXTERN_CVAR(Bool, gl_precache) diff --git a/src/rendering/polyrenderer/drawers/poly_thread.cpp b/src/rendering/polyrenderer/drawers/poly_thread.cpp index 4613d65750..4b6d1a51a4 100644 --- a/src/rendering/polyrenderer/drawers/poly_thread.cpp +++ b/src/rendering/polyrenderer/drawers/poly_thread.cpp @@ -31,7 +31,7 @@ #include "g_game.h" #include "g_level.h" #include "r_data/r_translate.h" -#include "r_data/models/models.h" +#include "model.h" #include "v_palette.h" #include "r_data/colormaps.h" #include "poly_thread.h" diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.cpp b/src/rendering/polyrenderer/drawers/poly_triangle.cpp index 58aba69ced..54676b9479 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/poly_triangle.cpp @@ -31,7 +31,7 @@ #include "g_game.h" #include "g_level.h" #include "r_data/r_translate.h" -#include "r_data/models/models.h" +#include "model.h" #include "v_palette.h" #include "r_data/colormaps.h" #include "poly_triangle.h" diff --git a/src/rendering/swrenderer/r_swrenderer.cpp b/src/rendering/swrenderer/r_swrenderer.cpp index 24eb810498..e43e431694 100644 --- a/src/rendering/swrenderer/r_swrenderer.cpp +++ b/src/rendering/swrenderer/r_swrenderer.cpp @@ -46,7 +46,7 @@ #include "scene/r_3dfloors.h" #include "scene/r_portal.h" #include "textures.h" -#include "r_data/voxels.h" +#include "voxels.h" #include "drawers/r_draw_rgba.h" #include "p_setup.h" #include "g_levellocals.h" diff --git a/src/rendering/swrenderer/things/r_model.h b/src/rendering/swrenderer/things/r_model.h index 67db288816..4c0c5a3429 100644 --- a/src/rendering/swrenderer/things/r_model.h +++ b/src/rendering/swrenderer/things/r_model.h @@ -24,7 +24,7 @@ #include "polyrenderer/drawers/poly_triangle.h" #include "matrix.h" -#include "r_data/models/models.h" +#include "models.h" #include "swrenderer/r_renderthread.h" #include "swrenderer/things/r_visiblesprite.h" diff --git a/src/rendering/swrenderer/things/r_particle.cpp b/src/rendering/swrenderer/things/r_particle.cpp index 6aa2cdb595..4fbc97c388 100644 --- a/src/rendering/swrenderer/things/r_particle.cpp +++ b/src/rendering/swrenderer/things/r_particle.cpp @@ -47,7 +47,7 @@ #include "v_palette.h" #include "r_data/r_translate.h" #include "r_data/colormaps.h" -#include "r_data/voxels.h" +#include "voxels.h" #include "p_local.h" #include "p_maputl.h" #include "r_voxel.h" diff --git a/src/rendering/swrenderer/things/r_playersprite.cpp b/src/rendering/swrenderer/things/r_playersprite.cpp index d59f0a64c7..0c6fd08237 100644 --- a/src/rendering/swrenderer/things/r_playersprite.cpp +++ b/src/rendering/swrenderer/things/r_playersprite.cpp @@ -52,7 +52,7 @@ #include "v_palette.h" #include "r_data/r_translate.h" #include "r_data/colormaps.h" -#include "r_data/voxels.h" +#include "voxels.h" #include "p_local.h" #include "p_maputl.h" #include "r_voxel.h" diff --git a/src/rendering/swrenderer/things/r_sprite.cpp b/src/rendering/swrenderer/things/r_sprite.cpp index c0ebeae756..29afd0f7ea 100644 --- a/src/rendering/swrenderer/things/r_sprite.cpp +++ b/src/rendering/swrenderer/things/r_sprite.cpp @@ -53,7 +53,7 @@ #include "v_palette.h" #include "r_data/r_translate.h" #include "r_data/colormaps.h" -#include "r_data/voxels.h" +#include "voxels.h" #include "p_local.h" #include "r_voxel.h" #include "swrenderer/segments/r_drawsegment.h" diff --git a/src/rendering/swrenderer/things/r_voxel.cpp b/src/rendering/swrenderer/things/r_voxel.cpp index 662fd1bc3d..62e0e46559 100644 --- a/src/rendering/swrenderer/things/r_voxel.cpp +++ b/src/rendering/swrenderer/things/r_voxel.cpp @@ -37,7 +37,7 @@ #include "sbar.h" #include "r_data/r_translate.h" #include "r_data/colormaps.h" -#include "r_data/voxels.h" +#include "voxels.h" #include "r_data/sprites.h" #include "d_net.h" #include "po_man.h" diff --git a/src/rendering/swrenderer/things/r_wallsprite.cpp b/src/rendering/swrenderer/things/r_wallsprite.cpp index a3a526e2c7..5fb431e36f 100644 --- a/src/rendering/swrenderer/things/r_wallsprite.cpp +++ b/src/rendering/swrenderer/things/r_wallsprite.cpp @@ -53,7 +53,7 @@ #include "v_palette.h" #include "r_data/r_translate.h" #include "r_data/colormaps.h" -#include "r_data/voxels.h" +#include "voxels.h" #include "p_local.h" #include "p_maputl.h" #include "r_voxel.h" From 5f3e4a5d0e7214f9124d51fb8a31a03d0002c687 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 22:24:41 +0200 Subject: [PATCH 128/220] - did a bit of cleanup on DFrameBuffer, most notably taking GetCaps out of it. With the old softpoly renderer and OpenGL 2.x being gone there is no more need for such complex handling, it is now a single function in d_main.cpp. --- src/d_main.cpp | 32 +++++++++++++++- src/gameconfigfile.h | 2 +- src/rendering/gl/system/gl_framebuffer.cpp | 17 --------- src/rendering/gl/system/gl_framebuffer.h | 1 - .../polyrenderer/backend/poly_framebuffer.cpp | 16 -------- .../polyrenderer/backend/poly_framebuffer.h | 1 - src/rendering/swrenderer/drawers/r_draw.cpp | 4 +- src/rendering/v_framebuffer.cpp | 38 ------------------- src/rendering/v_video.h | 8 +--- .../vulkan/system/vk_framebuffer.cpp | 17 --------- src/rendering/vulkan/system/vk_framebuffer.h | 1 - src/scripting/vmthunks.cpp | 10 +++++ 12 files changed, 45 insertions(+), 102 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 5d7f8f19e7..b2179d9fdb 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -802,6 +802,36 @@ CVAR (Flag, compat_railing, compatflags2, COMPATF2_RAILING); CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +EXTERN_CVAR(Bool, r_drawvoxels) +EXTERN_CVAR(Int, gl_tonemap) +static uint32_t GetCaps() +{ + ActorRenderFeatureFlags FlagSet; + if (!V_IsHardwareRenderer()) + { + FlagSet = RFF_UNCLIPPEDTEX; + + if (V_IsTrueColor()) + FlagSet |= RFF_TRUECOLOR; + else + FlagSet |= RFF_COLORMAP; + + } + else + { + // describe our basic feature set + FlagSet = RFF_FLATSPRITES | RFF_MODELS | RFF_SLOPE3DFLOORS | + RFF_TILTPITCH | RFF_ROLLSPRITES | RFF_POLYGONAL | RFF_MATSHADER | RFF_POSTSHADER | RFF_BRIGHTMAP; + + if (gl_tonemap != 5) // not running palette tonemap shader + FlagSet |= RFF_TRUECOLOR; + } + + if (r_drawvoxels) + FlagSet |= RFF_VOXELS; + return (uint32_t)FlagSet; +} + //========================================================================== // // D_Display @@ -830,7 +860,7 @@ void D_Display () cycles.Clock(); r_UseVanillaTransparency = UseVanillaTransparency(); // [SP] Cache UseVanillaTransparency() call - r_renderercaps = screen->GetCaps(); // [SP] Get the current capabilities of the renderer + r_renderercaps = GetCaps(); // [SP] Get the current capabilities of the renderer if (players[consoleplayer].camera == NULL) { diff --git a/src/gameconfigfile.h b/src/gameconfigfile.h index 9ef4684898..88f5fe30e4 100644 --- a/src/gameconfigfile.h +++ b/src/gameconfigfile.h @@ -63,7 +63,7 @@ protected: private: void SetRavenDefaults (bool isHexen); - void ReadCVars (uint32_t flags); + void ReadCVars (unsigned flags); bool bModSetup; diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 9f3210f68b..f435058b13 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -241,23 +241,6 @@ void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function 0) ret[0].SetInt(viewwindowx); - if (numret > 1) ret[1].SetInt(viewwindowy); - if (numret > 2) ret[2].SetInt(viewwidth); - if (numret > 3) ret[3].SetInt(viewheight); - return MIN(numret, 4); -} //========================================================================== // diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index e40d919f1b..dc51af9069 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -102,14 +102,9 @@ inline bool V_IsSoftwareRenderer() return vid_rendermode < 2; } -inline bool V_IsPolyRenderer() -{ - return vid_rendermode == 2 || vid_rendermode == 3; -} - inline bool V_IsTrueColor() { - return vid_rendermode == 1 || vid_rendermode == 3 || vid_rendermode == 4; + return vid_rendermode == 1 || vid_rendermode == 4; } @@ -270,7 +265,6 @@ public: // Report a game restart void SetClearColor(int color); - virtual uint32_t GetCaps(); virtual int Backend() { return 0; } virtual const char* DeviceName() const { return "Unknown"; } virtual void AmbientOccludeScene(float m5) {} diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index cabc62b3cc..edd5b6b959 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -356,23 +356,6 @@ void VulkanFrameBuffer::PostProcessScene(bool swscene, int fixedcm, const std::f mPostprocess->PostProcessScene(fixedcm, afterBloomDrawEndScene2D); } -uint32_t VulkanFrameBuffer::GetCaps() -{ - if (!V_IsHardwareRenderer()) - return Super::GetCaps(); - - // describe our basic feature set - ActorRenderFeatureFlags FlagSet = RFF_FLATSPRITES | RFF_MODELS | RFF_SLOPE3DFLOORS | - RFF_TILTPITCH | RFF_ROLLSPRITES | RFF_POLYGONAL | RFF_MATSHADER | RFF_POSTSHADER | RFF_BRIGHTMAP; - if (r_drawvoxels) - FlagSet |= RFF_VOXELS; - - if (gl_tonemap != 5) // not running palette tonemap shader - FlagSet |= RFF_TRUECOLOR; - - return (uint32_t)FlagSet; -} - const char* VulkanFrameBuffer::DeviceName() const { const auto &props = device->PhysicalDevice.Properties; diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 9acc4c70f4..707880599b 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -74,7 +74,6 @@ public: void PrecacheMaterial(FMaterial *mat, int translation) override; void UpdatePalette() override; - uint32_t GetCaps() override; const char* DeviceName() const override; int Backend() override { return 1; } void SetTextureFilterMode() override; diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index 497feba3e8..d95a0c1576 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -3300,6 +3300,16 @@ DEFINE_ACTION_FUNCTION(DObject, S_ChangeMusic) } +DEFINE_ACTION_FUNCTION(_Screen, GetViewWindow) +{ + PARAM_PROLOGUE; + if (numret > 0) ret[0].SetInt(viewwindowx); + if (numret > 1) ret[1].SetInt(viewwindowy); + if (numret > 2) ret[2].SetInt(viewwidth); + if (numret > 3) ret[3].SetInt(viewheight); + return MIN(numret, 4); +} + //========================================================================== // // From 2196b4fb04dedcec2ba28528397f706710412333 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 27 Apr 2020 23:53:26 +0200 Subject: [PATCH 129/220] - moved the frame rate drawer out of DFrameBuffer. Too much of this is not shareable and all it consists of are drawing operations on the 2D drawer. --- src/am_map.cpp | 3 +- src/common/engine/i_interface.h | 1 + src/common/rendering/gl/gl_samplers.cpp | 3 +- .../rendering/hwrenderer/data/hw_vrmodes.cpp | 5 +- src/d_main.cpp | 120 +++++++++++++++++- src/d_main.h | 14 ++ src/p_setup.cpp | 1 + src/playsim/p_user.cpp | 3 +- src/rendering/2d/v_blend.cpp | 1 + src/rendering/hwrenderer/hw_entrypoint.cpp | 1 + src/rendering/hwrenderer/scene/hw_drawinfo.h | 2 + .../hwrenderer/textures/hw_precache.cpp | 1 + src/rendering/hwrenderer/utility/hw_clock.cpp | 3 +- src/rendering/swrenderer/r_swrenderer.cpp | 1 + src/rendering/swrenderer/r_swscene.cpp | 1 + .../swrenderer/textures/r_swtexture.h | 1 + src/rendering/v_framebuffer.cpp | 118 ----------------- src/rendering/v_video.h | 35 ----- src/rendering/vulkan/textures/vk_samplers.cpp | 3 +- 19 files changed, 155 insertions(+), 162 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index d86da9506b..02edc6142b 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -47,6 +47,7 @@ #include "p_blockmap.h" #include "g_game.h" #include "v_video.h" +#include "d_main.h" #include "m_cheat.h" #include "c_dispatch.h" @@ -2139,7 +2140,7 @@ void DAutomap::drawSubsectors() // is necessary in order to best reproduce Doom's original lighting. double fadelevel; - if (vid_rendermode != 4 || primaryLevel->lightMode == ELightMode::Doom || primaryLevel->lightMode == ELightMode::ZDoomSoftware || primaryLevel->lightMode == ELightMode::DoomSoftware) + if (!V_IsHardwareRenderer() || primaryLevel->lightMode == ELightMode::Doom || primaryLevel->lightMode == ELightMode::ZDoomSoftware || primaryLevel->lightMode == ELightMode::DoomSoftware) { double map = (NUMCOLORMAPS * 2.) - ((floorlight + 12) * (NUMCOLORMAPS / 128.)); fadelevel = clamp((map - 12) / NUMCOLORMAPS, 0.0, 1.0); diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index 564b7d91c0..cd6a46e673 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -12,6 +12,7 @@ struct SystemCallbacks void (*CrashInfo)(char* buffer, size_t bufflen, const char* lfstr); void (*PlayStartupSound)(const char* name); bool (*IsSpecialUI)(); + bool (*DisableTextureFilter)(); }; extern SystemCallbacks *sysCallbacks; diff --git a/src/common/rendering/gl/gl_samplers.cpp b/src/common/rendering/gl/gl_samplers.cpp index 12be63e43d..1371ec3d1c 100644 --- a/src/common/rendering/gl/gl_samplers.cpp +++ b/src/common/rendering/gl/gl_samplers.cpp @@ -41,6 +41,7 @@ #include "gl/renderer/gl_renderer.h" #include "gl_samplers.h" #include "hw_material.h" +#include "i_interface.h" namespace OpenGLRenderer { @@ -98,7 +99,7 @@ uint8_t FSamplerManager::Bind(int texunit, int num, int lastval) void FSamplerManager::SetTextureFilterMode() { UnbindAll(); - int filter = V_IsHardwareRenderer() ? gl_texture_filter : 0; + int filter = sysCallbacks && sysCallbacks->DisableTextureFilter && sysCallbacks->DisableTextureFilter() ? 0 : gl_texture_filter; for (int i = 0; i < 4; i++) { diff --git a/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp b/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp index a105f48c21..17bfefaef9 100644 --- a/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp +++ b/src/common/rendering/hwrenderer/data/hw_vrmodes.cpp @@ -30,6 +30,7 @@ #include "hw_vrmodes.h" #include "v_video.h" #include "version.h" +#include "i_interface.h" // Set up 3D-specific console variables: CVAR(Int, vr_mode, 0, CVAR_GLOBALCONFIG) @@ -60,7 +61,9 @@ static VRMode vrmi_checker = { 2, isqrt2, isqrt2, 1.f,{ { -.5f, 1.f },{ .5f, 1.f const VRMode *VRMode::GetVRMode(bool toscreen) { #ifdef VR3D_ENABLED - switch (toscreen && vid_rendermode == 4 ? vr_mode : 0) + int mode = !toscreen || (sysCallbacks && sysCallbacks->DisableTextureFilter && sysCallbacks->DisableTextureFilter()) ? 0 : vr_mode; + + switch (mode) { default: case VR_MONO: diff --git a/src/d_main.cpp b/src/d_main.cpp index b2179d9fdb..0609b9d605 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -182,6 +182,7 @@ EXTERN_CVAR (Bool, sv_cheats) EXTERN_CVAR (Bool, sv_unlimited_pickup) EXTERN_CVAR (Bool, r_drawplayersprites) EXTERN_CVAR (Bool, show_messages) +EXTERN_CVAR(Bool, ticker) extern bool setmodeneeded; extern bool demorecording; @@ -260,6 +261,8 @@ CVAR (Bool, disableautoload, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBAL CVAR (Bool, autoloadbrightmaps, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG) CVAR (Bool, autoloadlights, false, CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOBALCONFIG) CVAR (Bool, r_debug_disable_vis_filter, false, 0) +CVAR(Bool, vid_fps, false, 0) +CVAR(Int, vid_showpalette, 0, 0) bool hud_toggled = false; bool wantToRestart; @@ -832,6 +835,111 @@ static uint32_t GetCaps() return (uint32_t)FlagSet; } +//========================================================================== +// +// +// +//========================================================================== + +static void DrawPaletteTester(int paletteno) +{ + int blocksize = screen->GetHeight() / 50; + + int t = paletteno; + int k = 0; + for (int i = 0; i < 16; ++i) + { + for (int j = 0; j < 16; ++j) + { + PalEntry pe; + if (t > 1) + { + auto palette = GPalette.GetTranslation(TRANSLATION_Standard, t - 2)->Palette; + pe = palette[k]; + } + else GPalette.BaseColors[k]; + k++; + Dim(twod, pe, 1.f, j * blocksize, i * blocksize, blocksize, blocksize); + } + } +} + +//========================================================================== +// +// DFrameBuffer :: DrawRateStuff +// +// Draws the fps counter, dot ticker, and palette debug. +// +//========================================================================== +uint64_t LastCount; + +static void DrawRateStuff() +{ + static uint64_t LastMS = 0, LastSec = 0, FrameCount = 0, LastTic = 0; + + // Draws frame time and cumulative fps + if (vid_fps) + { + uint64_t ms = screen->FrameTime; + uint64_t howlong = ms - LastMS; + if ((signed)howlong >= 0) + { + char fpsbuff[40]; + int chars; + int rate_x; + + int textScale = active_con_scale(twod); + + chars = mysnprintf(fpsbuff, countof(fpsbuff), "%2llu ms (%3llu fps)", (unsigned long long)howlong, (unsigned long long)LastCount); + rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]); + ClearRect(twod, rate_x * textScale, 0, screen->GetWidth(), NewConsoleFont->GetHeight() * textScale, GPalette.BlackIndex, 0); + DrawText(twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char*)&fpsbuff[0], + DTA_VirtualWidth, screen->GetWidth() / textScale, + DTA_VirtualHeight, screen->GetHeight() / textScale, + DTA_KeepRatio, true, TAG_DONE); + + uint32_t thisSec = (uint32_t)(ms / 1000); + if (LastSec < thisSec) + { + LastCount = FrameCount / (thisSec - LastSec); + LastSec = thisSec; + FrameCount = 0; + } + FrameCount++; + } + LastMS = ms; + } + + int Height = screen->GetHeight(); + + // draws little dots on the bottom of the screen + if (ticker) + { + int64_t t = I_GetTime(); + int64_t tics = t - LastTic; + + LastTic = t; + if (tics > 20) tics = 20; + + int i; + for (i = 0; i < tics * 2; i += 2) ClearRect(twod, i, Height - 1, i + 1, Height, 255, 0); + for (; i < 20 * 2; i += 2) ClearRect(twod, i, Height - 1, i + 1, Height, 0, 0); + } + + // draws the palette for debugging + if (vid_showpalette) + { + DrawPaletteTester(vid_showpalette); + } +} + +static void End2DAndUpdate() +{ + DrawRateStuff(); + twod->End(); + screen->Update(); +} + //========================================================================== // // D_Display @@ -1016,7 +1124,7 @@ void D_Display () screen->Begin2D(); C_DrawConsole (); M_Drawer (); - screen->End2DAndUpdate (); + End2DAndUpdate (); return; case GS_INTERMISSION: @@ -1089,7 +1197,7 @@ void D_Display () M_Drawer (); // menu is drawn even on top of everything if (!hud_toggled) FStat::PrintStat (twod); - screen->End2DAndUpdate (); + End2DAndUpdate (); } else { @@ -1120,7 +1228,7 @@ void D_Display () done = wiper->Run(1); C_DrawConsole (); // console and M_Drawer (); // menu are drawn even on top of wipes - screen->End2DAndUpdate (); + End2DAndUpdate (); NetUpdate (); // [RH] not sure this is needed anymore } while (!done); delete wiper; @@ -2685,6 +2793,11 @@ static bool System_IsSpecialUI() } +static bool System_DisableTextureFilter() +{ + return !V_IsHardwareRenderer(); +} + //========================================================================== // // DoomSpecificInfo @@ -2890,6 +3003,7 @@ static int D_DoomMain_Internal (void) System_CrashInfo, System_PlayStartupSound, System_IsSpecialUI, + System_DisableTextureFilter, }; sysCallbacks = &syscb; diff --git a/src/d_main.h b/src/d_main.h index ce8d9d778e..ad6929422c 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -31,6 +31,7 @@ #include "doomtype.h" #include "gametype.h" #include "startupinfo.h" +#include "c_cvars.h" struct event_t; @@ -136,6 +137,19 @@ public: else return 0; } + }; +EXTERN_CVAR(Int, vid_rendermode) + +inline bool V_IsHardwareRenderer() +{ + return vid_rendermode == 4; +} + +inline bool V_IsTrueColor() +{ + return vid_rendermode == 1 || vid_rendermode == 4; +} + #endif diff --git a/src/p_setup.cpp b/src/p_setup.cpp index d65d08ec1a..03e2a7a5e3 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -79,6 +79,7 @@ #include "animations.h" #include "texturemanager.h" #include "p_lnspec.h" +#include "d_main.h" extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position); diff --git a/src/playsim/p_user.cpp b/src/playsim/p_user.cpp index 47241679b1..f4a4e344d1 100644 --- a/src/playsim/p_user.cpp +++ b/src/playsim/p_user.cpp @@ -93,6 +93,7 @@ #include "v_video.h" #include "gstrings.h" #include "s_music.h" +#include "d_main.h" static FRandom pr_skullpop ("SkullPop"); @@ -632,7 +633,7 @@ void player_t::SendPitchLimits() const { int uppitch, downpitch; - if (V_IsSoftwareRenderer()) + if (!V_IsHardwareRenderer()) { uppitch = GetSoftPitch(false); downpitch = GetSoftPitch(true); diff --git a/src/rendering/2d/v_blend.cpp b/src/rendering/2d/v_blend.cpp index f654ee39b0..9a0f7404c0 100644 --- a/src/rendering/2d/v_blend.cpp +++ b/src/rendering/2d/v_blend.cpp @@ -47,6 +47,7 @@ #include "v_palette.h" #include "r_utility.h" #include "hw_cvars.h" +#include "d_main.h" CVAR(Float, underwater_fade_scalar, 1.0f, CVAR_ARCHIVE) // [Nash] user-settable underwater blend intensity CVAR( Float, blood_fade_scalar, 1.0f, CVAR_ARCHIVE ) // [SP] Pulled from Skulltag - changed default from 0.5 to 1.0 diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index c6c0e15f8d..61ebf3c617 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -40,6 +40,7 @@ #include "hwrenderer/utility/hw_clock.h" #include "flatvertices.h" #include "v_palette.h" +#include "d_main.h" #include "hw_lightbuffer.h" #include "hw_cvars.h" diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.h b/src/rendering/hwrenderer/scene/hw_drawinfo.h index 65d12c56c5..e603716742 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.h +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.h @@ -333,3 +333,5 @@ void CleanSWDrawer(); sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bounds, float fov, float ratio, float fovratio, bool mainview, bool toscreen); void WriteSavePic(player_t* player, FileWriter* file, int width, int height); sector_t* RenderView(player_t* player); + + diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 58839f49ad..462b340845 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -38,6 +38,7 @@ #include "v_font.h" #include "texturemanager.h" #include "modelrenderer.h" +#include "d_main.h" EXTERN_CVAR(Bool, gl_precache) diff --git a/src/rendering/hwrenderer/utility/hw_clock.cpp b/src/rendering/hwrenderer/utility/hw_clock.cpp index dff667b1a7..f337f6581f 100644 --- a/src/rendering/hwrenderer/utility/hw_clock.cpp +++ b/src/rendering/hwrenderer/utility/hw_clock.cpp @@ -154,6 +154,7 @@ ADD_STAT(lightstats) static int printstats; static bool switchfps; static uint64_t waitstart; +extern uint64_t LastCount; EXTERN_CVAR(Bool, vid_fps) void CheckBench() @@ -175,7 +176,7 @@ void CheckBench() AppendRenderTimes(compose); AppendLightStats(compose); //AppendMissingTextureStats(compose); - compose.AppendFormat("%llu fps\n\n", (unsigned long long)screen->GetLastFPS()); + compose.AppendFormat("%llu fps\n\n", (unsigned long long)LastCount); FILE *f = fopen("benchmarks.txt", "at"); if (f != NULL) diff --git a/src/rendering/swrenderer/r_swrenderer.cpp b/src/rendering/swrenderer/r_swrenderer.cpp index e43e431694..5eece9b3fa 100644 --- a/src/rendering/swrenderer/r_swrenderer.cpp +++ b/src/rendering/swrenderer/r_swrenderer.cpp @@ -53,6 +53,7 @@ #include "image.h" #include "imagehelpers.h" #include "texturemanager.h" +#include "d_main.h" // [BB] Use ZDoom's freelook limit for the sotfware renderer. // Note: ZDoom's limit is chosen such that the sky is rendered properly. diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index 1f49803684..7a2fc9cb9b 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -36,6 +36,7 @@ #include "image.h" #include "engineerrors.h" #include "texturemanager.h" +#include "d_main.h" // [RH] Base blending values (for e.g. underwater) int BaseBlendR, BaseBlendG, BaseBlendB; diff --git a/src/rendering/swrenderer/textures/r_swtexture.h b/src/rendering/swrenderer/textures/r_swtexture.h index d44062ea4b..83c8f6fc62 100644 --- a/src/rendering/swrenderer/textures/r_swtexture.h +++ b/src/rendering/swrenderer/textures/r_swtexture.h @@ -2,6 +2,7 @@ #include "textures.h" #include "v_video.h" #include "g_levellocals.h" +#include "d_main.h" struct FSoftwareTextureSpan diff --git a/src/rendering/v_framebuffer.cpp b/src/rendering/v_framebuffer.cpp index ede0c17369..c7f120a9c9 100644 --- a/src/rendering/v_framebuffer.cpp +++ b/src/rendering/v_framebuffer.cpp @@ -58,36 +58,11 @@ CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE); -CVAR(Bool, vid_fps, false, 0) -CVAR(Int, vid_showpalette, 0, 0) -EXTERN_CVAR(Bool, ticker) -EXTERN_CVAR(Float, vid_brightness) -EXTERN_CVAR(Float, vid_contrast) EXTERN_CVAR(Int, vid_maxfps) EXTERN_CVAR(Bool, cl_capfps) EXTERN_CVAR(Int, screenblocks) -//========================================================================== -// -// DCanvas :: CalcGamma -// -//========================================================================== - -void DFrameBuffer::CalcGamma (float gamma, uint8_t gammalookup[256]) -{ - // I found this formula on the web at - // , - // but that page no longer exits. - double invgamma = 1.f / gamma; - int i; - - for (i = 0; i < 256; i++) - { - gammalookup[i] = (uint8_t)(255.0 * pow (i / 255.0, invgamma) + 0.5); - } -} - //========================================================================== // // DFrameBuffer Constructor @@ -117,99 +92,6 @@ void DFrameBuffer::SetSize(int width, int height) m2DDrawer.SetSize(width, height); } -//========================================================================== -// -// -// -//========================================================================== - -void V_DrawPaletteTester(int paletteno) -{ - int blocksize = screen->GetHeight() / 50; - - int t = paletteno; - int k = 0; - for (int i = 0; i < 16; ++i) - { - for (int j = 0; j < 16; ++j) - { - PalEntry pe; - if (t > 1) - { - auto palette = GPalette.GetTranslation(TRANSLATION_Standard, t - 2)->Palette; - pe = palette[k]; - } - else GPalette.BaseColors[k]; - k++; - Dim(twod, pe, 1.f, j*blocksize, i*blocksize, blocksize, blocksize); - } - } -} - -//========================================================================== -// -// DFrameBuffer :: DrawRateStuff -// -// Draws the fps counter, dot ticker, and palette debug. -// -//========================================================================== - -void DFrameBuffer::DrawRateStuff () -{ - // Draws frame time and cumulative fps - if (vid_fps) - { - uint64_t ms = screen->FrameTime; - uint64_t howlong = ms - LastMS; - if ((signed)howlong >= 0) - { - char fpsbuff[40]; - int chars; - int rate_x; - - int textScale = active_con_scale(twod); - - chars = mysnprintf (fpsbuff, countof(fpsbuff), "%2llu ms (%3llu fps)", (unsigned long long)howlong, (unsigned long long)LastCount); - rate_x = Width / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]); - ClearRect (twod, rate_x * textScale, 0, Width, NewConsoleFont->GetHeight() * textScale, GPalette.BlackIndex, 0); - DrawText (twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char *)&fpsbuff[0], - DTA_VirtualWidth, screen->GetWidth() / textScale, - DTA_VirtualHeight, screen->GetHeight() / textScale, - DTA_KeepRatio, true, TAG_DONE); - - uint32_t thisSec = (uint32_t)(ms/1000); - if (LastSec < thisSec) - { - LastCount = FrameCount / (thisSec - LastSec); - LastSec = thisSec; - FrameCount = 0; - } - FrameCount++; - } - LastMS = ms; - } - - // draws little dots on the bottom of the screen - if (ticker) - { - int64_t t = I_GetTime(); - int64_t tics = t - LastTic; - - LastTic = t; - if (tics > 20) tics = 20; - - int i; - for (i = 0; i < tics*2; i += 2) ClearRect(twod, i, Height-1, i+1, Height, 255, 0); - for ( ; i < 20*2; i += 2) ClearRect(twod, i, Height-1, i+1, Height, 0, 0); - } - - // draws the palette for debugging - if (vid_showpalette) - { - V_DrawPaletteTester(vid_showpalette); - } -} - //========================================================================== // // Palette stuff. diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index dc51af9069..fd10970e62 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -83,7 +83,6 @@ extern int DisplayWidth, DisplayHeight; void V_UpdateModeSize (int width, int height); void V_OutputResized (int width, int height); -EXTERN_CVAR(Int, vid_rendermode) EXTERN_CVAR(Bool, vid_fullscreen) EXTERN_CVAR(Int, win_x) EXTERN_CVAR(Int, win_y) @@ -91,23 +90,6 @@ EXTERN_CVAR(Int, win_w) EXTERN_CVAR(Int, win_h) EXTERN_CVAR(Bool, win_maximized) - -inline bool V_IsHardwareRenderer() -{ - return vid_rendermode == 4; -} - -inline bool V_IsSoftwareRenderer() -{ - return vid_rendermode < 2; -} - -inline bool V_IsTrueColor() -{ - return vid_rendermode == 1 || vid_rendermode == 4; -} - - struct FColormap; class FileWriter; enum FTextureFormat : uint32_t; @@ -250,13 +232,6 @@ public: } void End2D() { m2DDrawer.End(); } - void End2DAndUpdate() - { - DrawRateStuff(); - m2DDrawer.End(); - Update(); - } - // This is overridable in case Vulkan does it differently. virtual bool RenderTextureIsFlipped() const { @@ -289,14 +264,9 @@ public: void ScaleCoordsFromWindow(int16_t &x, int16_t &y); - uint64_t GetLastFPS() const { return LastCount; } - virtual void Draw2D() {} void Clear2D() { m2DDrawer.Clear(); } - // Calculate gamma table - void CalcGamma(float gamma, uint8_t gammalookup[256]); - virtual void SetViewportRects(IntRect *bounds); int ScreenToWindowX(int x); int ScreenToWindowY(int y); @@ -314,14 +284,9 @@ public: // The original size of the framebuffer as selected in the video menu. uint64_t FrameTime = 0; -protected: - void DrawRateStuff (); - private: uint64_t fpsLimitTime = 0; - uint64_t LastMS = 0, LastSec = 0, FrameCount = 0, LastCount = 0, LastTic = 0; - bool isIn2D = false; }; diff --git a/src/rendering/vulkan/textures/vk_samplers.cpp b/src/rendering/vulkan/textures/vk_samplers.cpp index 23afff2c6e..a7b94326a7 100644 --- a/src/rendering/vulkan/textures/vk_samplers.cpp +++ b/src/rendering/vulkan/textures/vk_samplers.cpp @@ -29,6 +29,7 @@ #include "vulkan/system/vk_builders.h" #include "vk_samplers.h" #include "hw_material.h" +#include "i_interface.h" struct VkTexFilter { @@ -83,7 +84,7 @@ void VkSamplerManager::SetTextureFilterMode() void VkSamplerManager::Create() { - int filter = V_IsHardwareRenderer() ? gl_texture_filter : 0; + int filter = sysCallbacks && sysCallbacks->DisableTextureFilter && sysCallbacks->DisableTextureFilter()? 0 : gl_texture_filter; for(int i = 0; i < 7; i++) { From ddef3f7b98b95d2bf9600b64c9ebf2258a1a3260 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 28 Apr 2020 17:22:17 +0200 Subject: [PATCH 130/220] - made video base code game independent --- src/am_map.cpp | 1 + src/common/2d/v_2ddrawer.cpp | 3 +- src/common/2d/v_2ddrawer.h | 2 +- src/common/2d/v_draw.cpp | 4 +- src/common/2d/v_draw.h | 1 - src/common/engine/i_interface.h | 3 + src/common/fonts/v_font.h | 1 - src/common/models/model.cpp | 2 +- src/common/models/model.h | 1 + src/common/models/modelrenderer.h | 4 +- src/common/models/models_md2.cpp | 1 + src/common/models/models_obj.cpp | 2 + src/common/models/models_voxel.cpp | 4 + src/common/models/voxels.cpp | 1 - src/common/models/voxels.h | 3 +- src/common/rendering/gl/gl_postprocess.cpp | 5 +- src/common/rendering/gl/gl_renderstate.cpp | 3 - src/common/rendering/r_videoscale.cpp | 3 +- src/common/textures/textureid.h | 6 + src/common/textures/textures.h | 6 - src/console/c_cmds.cpp | 1 + src/console/c_console.cpp | 3 +- src/ct_chat.cpp | 1 + src/d_main.cpp | 69 +++++++++- src/d_net.cpp | 3 +- src/g_statusbar/hudmessages.cpp | 1 + src/g_statusbar/sbarinfo.cpp | 1 + src/g_statusbar/shared_hud.cpp | 1 + src/g_statusbar/shared_sbar.cpp | 54 +++++++- src/gameconfigfile.cpp | 6 + src/hu_scores.cpp | 1 + src/intermission/intermission.cpp | 12 +- src/menu/loadsavemenu.cpp | 1 + src/menu/menu.cpp | 3 +- src/p_conversation.cpp | 1 + src/rendering/2d/f_wipe.cpp | 1 + src/rendering/2d/v_blend.cpp | 1 + src/rendering/gl/system/gl_framebuffer.cpp | 3 +- .../hwrenderer/scene/hw_drawinfo.cpp | 1 + .../hwrenderer/utility/hw_draw2d.cpp | 1 + .../polyrenderer/backend/poly_framebuffer.cpp | 7 +- src/rendering/r_utility.cpp | 28 +--- src/rendering/swrenderer/r_swscene.cpp | 7 +- src/rendering/swrenderer/scene/r_light.cpp | 1 + src/rendering/swrenderer/scene/r_scene.cpp | 2 +- .../swrenderer/things/r_playersprite.cpp | 1 + .../swrenderer/viewport/r_viewport.cpp | 1 + src/rendering/v_framebuffer.cpp | 46 ++----- src/rendering/v_video.cpp | 130 ++++-------------- src/rendering/v_video.h | 27 +--- .../vulkan/system/vk_framebuffer.cpp | 7 +- src/scripting/vmthunks.cpp | 2 + src/sound/s_doomsound.cpp | 1 + src/version.h | 2 + src/wi_stuff.cpp | 7 +- wadsrc/static/menudef.txt | 2 +- 56 files changed, 251 insertions(+), 241 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index 02edc6142b..f121f92bbd 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -48,6 +48,7 @@ #include "g_game.h" #include "v_video.h" #include "d_main.h" +#include "v_draw.h" #include "m_cheat.h" #include "c_dispatch.h" diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 704d2e1cf7..08560c35c0 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -39,7 +39,8 @@ #include "v_draw.h" #include "fcolormap.h" -F2DDrawer* twod; +static F2DDrawer drawer; +F2DDrawer* twod = &drawer; EXTERN_CVAR(Float, transsouls) diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index 07115f0f92..93712a8f8f 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -198,7 +198,7 @@ public: int GetWidth() const { return Width; } int GetHeight() const { return Height; } void SetSize(int w, int h) { Width = w; Height = h; } - void Begin() { isIn2D = true; } + void Begin(int w, int h) { isIn2D = true; Width = w; Height = h; } void End() { isIn2D = false; } bool HasBegun2D() { return isIn2D; } diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index bf33d6f6aa..bc04333e0c 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -1222,7 +1222,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawThickLine, DrawThickLine) //========================================================================== // -// DCanvas :: Clear +// ClearRect // // Set an area to a specified color. // @@ -1281,7 +1281,7 @@ DEFINE_ACTION_FUNCTION(_Screen, Clear) //========================================================================== // -// DCanvas :: Dim +// DoDim // // Applies a colored overlay to an area of the screen. // diff --git a/src/common/2d/v_draw.h b/src/common/2d/v_draw.h index fe76272f5b..2322232e7c 100644 --- a/src/common/2d/v_draw.h +++ b/src/common/2d/v_draw.h @@ -219,7 +219,6 @@ void DoDim(F2DDrawer* drawer, PalEntry color, float amount, int x1, int y1, int void Dim(F2DDrawer* drawer, PalEntry color, float damount, int x1, int y1, int w, int h, FRenderStyle* style = nullptr); void FillBorder(F2DDrawer *drawer, FGameTexture* img); // Fills the border around a 4:3 part of the screen on non-4:3 displays -void DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height); void DrawBorder(F2DDrawer* drawer, FTextureID, int x1, int y1, int x2, int y2); void DrawFrame(F2DDrawer* twod, PalEntry color, int left, int top, int width, int height, int thickness); diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index cd6a46e673..594d5ab2b7 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -1,6 +1,7 @@ #pragma once #include "zstring.h" +#include "intrect.h" struct SystemCallbacks { @@ -13,6 +14,8 @@ struct SystemCallbacks void (*PlayStartupSound)(const char* name); bool (*IsSpecialUI)(); bool (*DisableTextureFilter)(); + void (*OnScreenSizeChanged)(); + IntRect(*GetSceneRect)(); }; extern SystemCallbacks *sysCallbacks; diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 4e78da08f8..779137b61e 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -38,7 +38,6 @@ #include "palentry.h" #include "name.h" -class DCanvas; class FGameTexture; struct FRemapTable; diff --git a/src/common/models/model.cpp b/src/common/models/model.cpp index bd5d9ced9f..90dedc2725 100644 --- a/src/common/models/model.cpp +++ b/src/common/models/model.cpp @@ -31,13 +31,13 @@ #include "sc_man.h" #include "m_crc32.h" #include "printf.h" -#include "models.h" #include "model_ue1.h" #include "model_obj.h" #include "model_md2.h" #include "model_md3.h" #include "model_kvx.h" #include "i_time.h" +#include "voxels.h" #include "texturemanager.h" #include "modelrenderer.h" diff --git a/src/common/models/model.h b/src/common/models/model.h index a8e14d2e2f..5fdec020c5 100644 --- a/src/common/models/model.h +++ b/src/common/models/model.h @@ -2,6 +2,7 @@ #include #include "textureid.h" +#include "i_modelvertexbuffer.h" class FModelRenderer; class FGameTexture; diff --git a/src/common/models/modelrenderer.h b/src/common/models/modelrenderer.h index 96c8f2a716..1018d7ebbd 100644 --- a/src/common/models/modelrenderer.h +++ b/src/common/models/modelrenderer.h @@ -1,5 +1,7 @@ -#include "models.h" +#include "renderstyle.h" +#include "matrix.h" +#include "model.h" class FModelRenderer { diff --git a/src/common/models/models_md2.cpp b/src/common/models/models_md2.cpp index 6e255cf405..c3439faea0 100644 --- a/src/common/models/models_md2.cpp +++ b/src/common/models/models_md2.cpp @@ -30,6 +30,7 @@ #include "model_md2.h" #include "texturemanager.h" #include "modelrenderer.h" +#include "printf.h" #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data diff --git a/src/common/models/models_obj.cpp b/src/common/models/models_obj.cpp index 54c237c653..264ffd6ac2 100644 --- a/src/common/models/models_obj.cpp +++ b/src/common/models/models_obj.cpp @@ -23,6 +23,8 @@ #include "model_obj.h" #include "texturemanager.h" #include "modelrenderer.h" +#include "printf.h" +#include "textureid.h" /** * Load an OBJ model diff --git a/src/common/models/models_voxel.cpp b/src/common/models/models_voxel.cpp index 42c21e1d03..cfac12372d 100644 --- a/src/common/models/models_voxel.cpp +++ b/src/common/models/models_voxel.cpp @@ -33,6 +33,10 @@ #include "image.h" #include "texturemanager.h" #include "modelrenderer.h" +#include "voxels.h" +#include "texturemanager.h" +#include "palettecontainer.h" +#include "textures.h" #ifdef _MSC_VER #pragma warning(disable:4244) // warning C4244: conversion from 'double' to 'float', possible loss of data diff --git a/src/common/models/voxels.cpp b/src/common/models/voxels.cpp index 74c6cac387..75acb8ddab 100644 --- a/src/common/models/voxels.cpp +++ b/src/common/models/voxels.cpp @@ -43,7 +43,6 @@ #include "v_video.h" #include "sc_man.h" #include "voxels.h" -#include "info.h" #include "printf.h" void VOX_AddVoxel(int sprnum, int frame, FVoxelDef *def); diff --git a/src/common/models/voxels.h b/src/common/models/voxels.h index ea71d2b0cb..b4a1cdfcd1 100644 --- a/src/common/models/voxels.h +++ b/src/common/models/voxels.h @@ -1,8 +1,7 @@ #ifndef __RES_VOXEL_H #define __RES_VOXEL_H -#include "doomdef.h" - +#include // [RH] Voxels from Build #define MAXVOXMIPS 5 diff --git a/src/common/rendering/gl/gl_postprocess.cpp b/src/common/rendering/gl/gl_postprocess.cpp index 8b97f51e0e..8af1a2272d 100644 --- a/src/common/rendering/gl/gl_postprocess.cpp +++ b/src/common/rendering/gl/gl_postprocess.cpp @@ -35,6 +35,7 @@ #include "v_video.h" #include "templates.h" #include "hw_vrmodes.h" +#include "v_draw.h" extern bool vid_hdr_active; @@ -123,7 +124,7 @@ void FGLRenderer::Flush() if (eyeCount - eye_ix > 1) mBuffers->NextEye(eyeCount); } - screen->Clear2D(); + twod->Clear(); FGLPostProcessState savedState; FGLDebug::PushGroup("PresentEyes"); @@ -143,7 +144,7 @@ void FGLRenderer::Flush() void FGLRenderer::CopyToBackbuffer(const IntRect *bounds, bool applyGamma) { screen->Draw2D(); // draw all pending 2D stuff before copying the buffer - screen->Clear2D(); + twod->Clear(); GLPPRenderState renderstate(mBuffers); hw_postprocess.customShaders.Run(&renderstate, "screen"); diff --git a/src/common/rendering/gl/gl_renderstate.cpp b/src/common/rendering/gl/gl_renderstate.cpp index 555dbba918..ac9e470250 100644 --- a/src/common/rendering/gl/gl_renderstate.cpp +++ b/src/common/rendering/gl/gl_renderstate.cpp @@ -26,13 +26,10 @@ */ #include "templates.h" -#include "doomstat.h" -#include "r_data/colormaps.h" #include "gl_system.h" #include "gl_interface.h" #include "hw_cvars.h" #include "flatvertices.h" -#include "hwrenderer/scene/hw_skydome.h" #include "gl_shader.h" #include "gl/renderer/gl_renderer.h" #include "hw_lightbuffer.h" diff --git a/src/common/rendering/r_videoscale.cpp b/src/common/rendering/r_videoscale.cpp index 236493fb1f..dee86723ed 100644 --- a/src/common/rendering/r_videoscale.cpp +++ b/src/common/rendering/r_videoscale.cpp @@ -40,12 +40,11 @@ #include "v_draw.h" #include "i_interface.h" #include "printf.h" +#include "version.h" #define NUMSCALEMODES countof(vScaleTable) extern bool setsizeneeded; -EXTERN_CVAR(Int, vid_aspect) - CUSTOM_CVAR(Int, vid_scale_customwidth, VID_MIN_WIDTH, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { if (self < VID_MIN_WIDTH) diff --git a/src/common/textures/textureid.h b/src/common/textures/textureid.h index 5d2b7d7261..c7a6355cc0 100644 --- a/src/common/textures/textureid.h +++ b/src/common/textures/textureid.h @@ -50,6 +50,12 @@ private: int texnum; }; +class FNullTextureID : public FTextureID +{ +public: + FNullTextureID() : FTextureID(0) {} +}; + // This is for the script interface which needs to do casts from int to texture. class FSetTextureID : public FTextureID { diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index bd9c79ed9b..f0b5b4dfce 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -124,12 +124,6 @@ class FMultipatchTextureBuilder; extern int r_spriteadjustSW, r_spriteadjustHW; -class FNullTextureID : public FTextureID -{ -public: - FNullTextureID() : FTextureID(0) {} -}; - enum FTextureFormat : uint32_t { TEX_Pal, diff --git a/src/console/c_cmds.cpp b/src/console/c_cmds.cpp index 8718b820d8..a4b868963a 100644 --- a/src/console/c_cmds.cpp +++ b/src/console/c_cmds.cpp @@ -68,6 +68,7 @@ #include "i_music.h" #include "s_music.h" #include "texturemanager.h" +#include "v_draw.h" extern FILE *Logfile; extern bool insave; diff --git a/src/console/c_console.cpp b/src/console/c_console.cpp index 1204b2c7a2..ad4fb08205 100644 --- a/src/console/c_console.cpp +++ b/src/console/c_console.cpp @@ -67,6 +67,7 @@ #include "s_music.h" #include "i_time.h" #include "texturemanager.h" +#include "v_draw.h" #include "gi.h" @@ -1000,7 +1001,7 @@ void C_AdjustBottom () void C_NewModeAdjust () { - C_InitConsole (twod->GetWidth(), twod->GetHeight(), true); + C_InitConsole (screen->GetWidth(), screen->GetHeight(), true); C_FlushDisplay (); C_AdjustBottom (); } diff --git a/src/ct_chat.cpp b/src/ct_chat.cpp index 9f2260049f..73c77e6d1f 100644 --- a/src/ct_chat.cpp +++ b/src/ct_chat.cpp @@ -44,6 +44,7 @@ #include "vm.h" #include "c_buttons.h" #include "d_buttons.h" +#include "v_draw.h" enum { diff --git a/src/d_main.cpp b/src/d_main.cpp index 0609b9d605..5b9dbcd6f8 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -89,6 +89,7 @@ #include "d_netinf.h" #include "m_cheat.h" #include "m_joy.h" +#include "v_draw.h" #include "po_man.h" #include "p_local.h" #include "autosegs.h" @@ -113,6 +114,7 @@ #include "scriptutil.h" #include "v_palette.h" #include "texturemanager.h" +#include "hwrenderer/utility/hw_clock.h" #include "hwrenderer/scene/hw_drawinfo.h" #ifdef __unix__ @@ -216,6 +218,27 @@ CUSTOM_CVAR(Float, i_timescale, 1.0f, CVAR_NOINITCALL) // PUBLIC DATA DEFINITIONS ------------------------------------------------- +CUSTOM_CVAR(Int, vid_rendermode, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) +{ + if (self < 0 || self > 4) + { + self = 4; + } + else if (self == 2 || self == 3) + { + self = self - 2; // softpoly to software + } + + if (usergame) + { + // [SP] Update pitch limits to the netgame/gamesim. + players[consoleplayer].SendPitchLimits(); + } + screen->SetTextureFilterMode(); + + // No further checks needed. All this changes now is which scene drawer the render backend calls. +} + CUSTOM_CVAR (Int, fraglimit, 0, CVAR_SERVERINFO) { // Check for the fraglimit being hit because the fraglimit is being @@ -937,6 +960,7 @@ static void End2DAndUpdate() { DrawRateStuff(); twod->End(); + CheckBench(); screen->Update(); } @@ -1070,7 +1094,7 @@ void D_Display () viewsec = RenderView(&players[consoleplayer]); }, true); - screen->Begin2D(); + twod->Begin(screen->GetWidth(), screen->GetHeight()); if (!hud_toggled) { V_DrawBlend(viewsec); @@ -1117,11 +1141,10 @@ void D_Display () } else { - screen->Begin2D(); + twod->Begin(screen->GetWidth(), screen->GetHeight()); switch (gamestate) { case GS_FULLCONSOLE: - screen->Begin2D(); C_DrawConsole (); M_Drawer (); End2DAndUpdate (); @@ -1207,7 +1230,7 @@ void D_Display () GSnd->SetSfxPaused(true, 1); I_FreezeTime(true); - screen->End2D(); + twod->End(); auto wipend = MakeGameTexture(screen->WipeEndScreen(), nullptr, ETextureType::SWCanvas); auto wiper = Wiper::Create(wipe_type); wiper->SetTextures(wipe, wipend); @@ -1224,7 +1247,7 @@ void D_Display () diff = (nowtime - wipestart) * 40 / 1000; // Using 35 here feels too slow. } while (diff < 1); wipestart = nowtime; - screen->Begin2D(); + twod->Begin(screen->GetWidth(), screen->GetHeight()); done = wiper->Run(1); C_DrawConsole (); // console and M_Drawer (); // menu are drawn even on top of wipes @@ -2798,6 +2821,40 @@ static bool System_DisableTextureFilter() return !V_IsHardwareRenderer(); } +static void System_OnScreenSizeChanged() +{ + if (StatusBar != NULL) + { + StatusBar->CallScreenSizeChanged(); + } + // Reload crosshair if transitioned to a different size + ST_LoadCrosshair(true); + if (primaryLevel && primaryLevel->automap) + primaryLevel->automap->NewResolution(); +} + +IntRect System_GetSceneRect() +{ + IntRect mSceneViewport; + // Special handling so the view with a visible status bar displays properly + int height, width; + if (screenblocks >= 10) + { + height = screen->GetHeight(); + width = screen->GetWidth(); + } + else + { + height = (screenblocks * screen->GetHeight() / 10) & ~7; + width = (screenblocks * screen->GetWidth() / 10); + } + + mSceneViewport.left = viewwindowx; + mSceneViewport.top = screen->GetHeight() - (height + viewwindowy - ((height - viewheight) / 2)); + mSceneViewport.width = viewwidth; + mSceneViewport.height = height; + return mSceneViewport; +} //========================================================================== // // DoomSpecificInfo @@ -3004,6 +3061,8 @@ static int D_DoomMain_Internal (void) System_PlayStartupSound, System_IsSpecialUI, System_DisableTextureFilter, + System_OnScreenSizeChanged, + System_GetSceneRect, }; sysCallbacks = &syscb; diff --git a/src/d_net.cpp b/src/d_net.cpp index f186538f85..0962cec0e1 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -71,6 +71,7 @@ EXTERN_CVAR (Int, disableautosave) EXTERN_CVAR (Int, autosavecount) +EXTERN_CVAR(Bool, cl_capfps) //#define SIMULATEERRORS (RAND_MAX/3) #define SIMULATEERRORS 0 @@ -146,8 +147,6 @@ static int oldentertics; extern bool advancedemo; -CVAR (Bool, cl_capfps, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) - CVAR(Bool, net_ticbalance, false, CVAR_SERVERINFO | CVAR_NOSAVE) CUSTOM_CVAR(Int, net_extratic, 0, CVAR_SERVERINFO | CVAR_NOSAVE) { diff --git a/src/g_statusbar/hudmessages.cpp b/src/g_statusbar/hudmessages.cpp index 33c6a7b283..21321ab191 100644 --- a/src/g_statusbar/hudmessages.cpp +++ b/src/g_statusbar/hudmessages.cpp @@ -42,6 +42,7 @@ #include "serialize_obj.h" #include "doomstat.h" #include "vm.h" +#include "v_draw.h" EXTERN_CVAR(Int, con_scaletext) diff --git a/src/g_statusbar/sbarinfo.cpp b/src/g_statusbar/sbarinfo.cpp index 06427abd62..7efaff6412 100644 --- a/src/g_statusbar/sbarinfo.cpp +++ b/src/g_statusbar/sbarinfo.cpp @@ -51,6 +51,7 @@ #include "utf8.h" #include "texturemanager.h" #include "v_palette.h" +#include "v_draw.h" #define ARTIFLASH_OFFSET (statusBar->invBarOffset+6) enum diff --git a/src/g_statusbar/shared_hud.cpp b/src/g_statusbar/shared_hud.cpp index 32ee782517..c209e21cd0 100644 --- a/src/g_statusbar/shared_hud.cpp +++ b/src/g_statusbar/shared_hud.cpp @@ -48,6 +48,7 @@ #include "cmdlib.h" #include "g_levellocals.h" #include "vm.h" +#include "v_draw.h" #include diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 20d1148db4..b639e67316 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -62,6 +62,7 @@ #include "utf8.h" #include "texturemanager.h" #include "v_palette.h" +#include "v_draw.h" #include "../version.h" @@ -141,6 +142,57 @@ CUSTOM_CVAR(Int, am_showmaplabel, 2, CVAR_ARCHIVE) CVAR (Bool, idmypos, false, 0); +//========================================================================== +// +// V_DrawFrame +// +// Draw a frame around the specified area using the view border +// frame graphics. The border is drawn outside the area, not in it. +// +//========================================================================== + +void V_DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height) +{ + FGameTexture* p; + const gameborder_t* border = &gameinfo.Border; + // Sanity check for incomplete gameinfo + if (border == NULL) + return; + int offset = border->offset; + int right = left + width; + int bottom = top + height; + + // Draw top and bottom sides. + p = TexMan.GetGameTextureByName(border->t); + drawer->AddFlatFill(left, top - (int)p->GetDisplayHeight(), right, top, p, true); + p = TexMan.GetGameTextureByName(border->b); + drawer->AddFlatFill(left, bottom, right, bottom + (int)p->GetDisplayHeight(), p, true); + + // Draw left and right sides. + p = TexMan.GetGameTextureByName(border->l); + drawer->AddFlatFill(left - (int)p->GetDisplayWidth(), top, left, bottom, p, true); + p = TexMan.GetGameTextureByName(border->r); + drawer->AddFlatFill(right, top, right + (int)p->GetDisplayWidth(), bottom, p, true); + + // Draw beveled corners. + DrawTexture(drawer, TexMan.GetGameTextureByName(border->tl), left - offset, top - offset, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->tr), left + width, top - offset, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->bl), left - offset, top + height, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->br), left + width, top + height, TAG_DONE); +} + +DEFINE_ACTION_FUNCTION(_Screen, DrawFrame) +{ + PARAM_PROLOGUE; + PARAM_INT(x); + PARAM_INT(y); + PARAM_INT(w); + PARAM_INT(h); + if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + V_DrawFrame(twod, x, y, w, h); + return 0; +} + //--------------------------------------------------------------------------- // // Load crosshair definitions @@ -964,7 +1016,7 @@ void DBaseStatusBar::RefreshViewBorder () DrawBorder(twod, tex, viewwindowx + viewwidth, viewwindowy, Width, viewheight + viewwindowy); DrawBorder(twod, tex, 0, viewwindowy + viewheight, Width, StatusBar->GetTopOfStatusbar()); - DrawFrame(twod, viewwindowx, viewwindowy, viewwidth, viewheight); + V_DrawFrame(twod, viewwindowx, viewwindowy, viewwidth, viewheight); } } diff --git a/src/gameconfigfile.cpp b/src/gameconfigfile.cpp index 7ea9734ae4..7f7e55a21f 100644 --- a/src/gameconfigfile.cpp +++ b/src/gameconfigfile.cpp @@ -569,6 +569,12 @@ void FGameConfigFile::DoGlobalSetup () UCVarValue v = var->GetGenericRep(CVAR_Float); vid_gamma = v.Float; } + var = FindCVar("fullscreen", NULL); + if (var != NULL) + { + UCVarValue v = var->GetGenericRep(CVAR_Bool); + vid_fullscreen = v.Float; + } } } diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index 5305440ef0..6e662ab6bb 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -52,6 +52,7 @@ #include "g_game.h" #include "sbar.h" #include "texturemanager.h" +#include "v_draw.h" // MACROS ------------------------------------------------------------------ diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index e8b578b194..9291190b1e 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -53,6 +53,7 @@ #include "templates.h" #include "s_music.h" #include "texturemanager.h" +#include "v_draw.h" FIntermissionDescriptorList IntermissionDescriptors; @@ -941,7 +942,7 @@ void DIntermissionController::OnDestroy () void F_StartIntermission(FIntermissionDescriptor *desc, bool deleteme, uint8_t state) { - ScaleOverrider s(&screen->m2DDrawer); + ScaleOverrider s(twod); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->Destroy(); @@ -987,7 +988,7 @@ void F_StartIntermission(FName seq, uint8_t state) bool F_Responder (event_t* ev) { - ScaleOverrider s(&screen->m2DDrawer); + ScaleOverrider s(twod); if (DIntermissionController::CurrentIntermission != NULL) { return DIntermissionController::CurrentIntermission->Responder(ev); @@ -1003,7 +1004,7 @@ bool F_Responder (event_t* ev) void F_Ticker () { - ScaleOverrider s(&screen->m2DDrawer); + ScaleOverrider s(twod); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->Ticker(); @@ -1018,7 +1019,7 @@ void F_Ticker () void F_Drawer () { - ScaleOverrider s(&screen->m2DDrawer); + ScaleOverrider s(twod); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->Drawer(); @@ -1034,7 +1035,6 @@ void F_Drawer () void F_EndFinale () { - ScaleOverrider s(&screen->m2DDrawer); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->Destroy(); @@ -1050,7 +1050,7 @@ void F_EndFinale () void F_AdvanceIntermission() { - ScaleOverrider s(&screen->m2DDrawer); + ScaleOverrider s(twod); if (DIntermissionController::CurrentIntermission != NULL) { DIntermissionController::CurrentIntermission->mAdvance = true; diff --git a/src/menu/loadsavemenu.cpp b/src/menu/loadsavemenu.cpp index 25bc4b16bd..668c6b7069 100644 --- a/src/menu/loadsavemenu.cpp +++ b/src/menu/loadsavemenu.cpp @@ -45,6 +45,7 @@ #include "i_system.h" #include "v_video.h" #include "findfile.h" +#include "v_draw.h" // Save name length limit for old binary formats. #define OLDSAVESTRINGSIZE 24 diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 5700e6ccb2..c9cacb718a 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -56,6 +56,7 @@ #include "c_buttons.h" #include "types.h" #include "texturemanager.h" +#include "v_draw.h" int DMenu::InMenu; static ScaleOverrider *CurrentScaleOverrider; @@ -381,7 +382,7 @@ void M_StartControlPanel (bool makeSound, bool scaleoverride) } BackbuttonTime = 0; BackbuttonAlpha = 0; - if (scaleoverride && !CurrentScaleOverrider) CurrentScaleOverrider = new ScaleOverrider(&screen->m2DDrawer); + if (scaleoverride && !CurrentScaleOverrider) CurrentScaleOverrider = new ScaleOverrider(twod); else if (!scaleoverride && CurrentScaleOverrider) { delete CurrentScaleOverrider; diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index 390c1de4ad..d270af0d41 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -57,6 +57,7 @@ #include "vm.h" #include "v_video.h" #include "actorinlines.h" +#include "v_draw.h" static FRandom pr_randomspeech("RandomSpeech"); diff --git a/src/rendering/2d/f_wipe.cpp b/src/rendering/2d/f_wipe.cpp index 79905fd743..6109cb3d62 100644 --- a/src/rendering/2d/f_wipe.cpp +++ b/src/rendering/2d/f_wipe.cpp @@ -29,6 +29,7 @@ #include "templates.h" #include "bitmap.h" #include "hw_material.h" +#include "v_draw.h" class FBurnTexture : public FTexture { diff --git a/src/rendering/2d/v_blend.cpp b/src/rendering/2d/v_blend.cpp index 9a0f7404c0..1a0a5af861 100644 --- a/src/rendering/2d/v_blend.cpp +++ b/src/rendering/2d/v_blend.cpp @@ -48,6 +48,7 @@ #include "r_utility.h" #include "hw_cvars.h" #include "d_main.h" +#include "v_draw.h" CVAR(Float, underwater_fade_scalar, 1.0f, CVAR_ARCHIVE) // [Nash] user-settable underwater blend intensity CVAR( Float, blood_fade_scalar, 1.0f, CVAR_ARCHIVE ) // [SP] Pulled from Skulltag - changed default from 0.5 to 1.0 diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index f435058b13..f995867bbe 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -57,6 +57,7 @@ #include "gl_buffers.h" #include "swrenderer/r_swscene.h" #include "gl_postprocessstate.h" +#include "v_draw.h" #include "flatvertices.h" #include "hw_cvars.h" @@ -522,7 +523,7 @@ void OpenGLFrameBuffer::Draw2D() if (GLRenderer != nullptr) { GLRenderer->mBuffers->BindCurrentFB(); - ::Draw2D(&m2DDrawer, gl_RenderState); + ::Draw2D(twod, gl_RenderState); } } diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index dd239bb25a..8365eeb342 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -43,6 +43,7 @@ #include "hw_lightbuffer.h" #include "hw_vrmodes.h" #include "hw_clipper.h" +#include "v_draw.h" EXTERN_CVAR(Float, r_visibility) CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE) diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index 8d4df16960..2ea531fa9b 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -36,6 +36,7 @@ #include "hw_cvars.h" #include "hw_renderstate.h" #include "r_videoscale.h" +#include "v_draw.h" //=========================================================================== diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 71c7866e94..6712ac407f 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -28,6 +28,7 @@ #include "g_game.h" #include "v_text.h" #include "i_video.h" +#include "v_draw.h" #include "hwrenderer/utility/hw_clock.h" #include "hw_vrmodes.h" @@ -171,7 +172,7 @@ void PolyFrameBuffer::Update() Flush3D.Clock(); Draw2D(); - Clear2D(); + twod->Clear(); Flush3D.Unclock(); @@ -375,7 +376,7 @@ FTexture *PolyFrameBuffer::WipeStartScreen() FTexture *PolyFrameBuffer::WipeEndScreen() { Draw2D(); - Clear2D(); + twod->Clear(); auto tex = new FWrapperTexture(mScreenViewport.width, mScreenViewport.height, 1); auto systex = static_cast(tex->GetSystemTexture()); @@ -430,7 +431,7 @@ void PolyFrameBuffer::BeginFrame() void PolyFrameBuffer::Draw2D() { - ::Draw2D(&m2DDrawer, *mRenderState); + ::Draw2D(twod, *mRenderState); } unsigned int PolyFrameBuffer::GetLightBufferBlockSize() const diff --git a/src/rendering/r_utility.cpp b/src/rendering/r_utility.cpp index 3445c7ac38..76ecc5e683 100644 --- a/src/rendering/r_utility.cpp +++ b/src/rendering/r_utility.cpp @@ -64,6 +64,7 @@ #include "actorinlines.h" #include "g_game.h" #include "i_system.h" +#include "v_draw.h" // EXTERNAL DATA DECLARATIONS ---------------------------------------------- @@ -140,7 +141,6 @@ int LocalViewPitch; bool LocalKeyboardTurner; int setblocks; -bool setsizeneeded; unsigned int R_OldBlend = ~0; int validcount = 1; // increment every time a check is made @@ -368,7 +368,7 @@ CUSTOM_CVAR (Int, screenblocks, 10, CVAR_ARCHIVE) //========================================================================== FRenderer *CreateSWRenderer(); - +FRenderer* SWRenderer; //========================================================================== // @@ -1031,30 +1031,6 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor } -//========================================================================== -// -// CVAR transsouls -// -// How translucent things drawn with STYLE_SoulTrans are. Normally, only -// Lost Souls have this render style. -// Values less than 0.25 will automatically be set to -// 0.25 to ensure some degree of visibility. Likewise, values above 1.0 will -// be set to 1.0, because anything higher doesn't make sense. -// -//========================================================================== - -CUSTOM_CVAR(Float, transsouls, 0.75f, CVAR_ARCHIVE) -{ - if (self < 0.25f) - { - self = 0.25f; - } - else if (self > 1.f) - { - self = 1.f; - } -} - CUSTOM_CVAR(Float, maxviewpitch, 90.f, CVAR_ARCHIVE | CVAR_SERVERINFO) { if (self>90.f) self = 90.f; diff --git a/src/rendering/swrenderer/r_swscene.cpp b/src/rendering/swrenderer/r_swscene.cpp index 7a2fc9cb9b..d163df8f20 100644 --- a/src/rendering/swrenderer/r_swscene.cpp +++ b/src/rendering/swrenderer/r_swscene.cpp @@ -37,6 +37,7 @@ #include "engineerrors.h" #include "texturemanager.h" #include "d_main.h" +#include "v_draw.h" // [RH] Base blending values (for e.g. underwater) int BaseBlendR, BaseBlendG, BaseBlendB; @@ -122,11 +123,11 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) auto map = swrenderer::CameraLight::Instance()->ShaderColormap(); DrawTexture(twod, fbtex.get(), 0, 0, DTA_SpecialColormap, map, TAG_DONE); screen->Draw2D(); - screen->Clear2D(); + twod->Clear(); screen->PostProcessScene(true, CM_DEFAULT, [&]() { SWRenderer->DrawRemainingPlayerSprites(); screen->Draw2D(); - screen->Clear2D(); + twod->Clear(); }); } else @@ -143,7 +144,7 @@ sector_t *SWSceneDrawer::RenderView(player_t *player) SWRenderer->DrawRemainingPlayerSprites(); screen->Draw2D(); - screen->Clear2D(); + twod->Clear(); } return r_viewpoint.sector; diff --git a/src/rendering/swrenderer/scene/r_light.cpp b/src/rendering/swrenderer/scene/r_light.cpp index dea748350c..5b8a689b2a 100644 --- a/src/rendering/swrenderer/scene/r_light.cpp +++ b/src/rendering/swrenderer/scene/r_light.cpp @@ -36,6 +36,7 @@ #include "c_dispatch.h" #include "cmdlib.h" #include "d_net.h" +#include "v_draw.h" #include "g_level.h" #include "r_utility.h" #include "d_player.h" diff --git a/src/rendering/swrenderer/scene/r_scene.cpp b/src/rendering/swrenderer/scene/r_scene.cpp index 2cae785ed5..e987ad5092 100644 --- a/src/rendering/swrenderer/scene/r_scene.cpp +++ b/src/rendering/swrenderer/scene/r_scene.cpp @@ -23,7 +23,7 @@ #include #include "templates.h" - +#include "v_draw.h" #include "filesystem.h" #include "doomdef.h" #include "doomstat.h" diff --git a/src/rendering/swrenderer/things/r_playersprite.cpp b/src/rendering/swrenderer/things/r_playersprite.cpp index 0c6fd08237..2b0825fb2f 100644 --- a/src/rendering/swrenderer/things/r_playersprite.cpp +++ b/src/rendering/swrenderer/things/r_playersprite.cpp @@ -66,6 +66,7 @@ #include "swrenderer/r_memory.h" #include "swrenderer/r_renderthread.h" #include "g_levellocals.h" +#include "v_draw.h" EXTERN_CVAR(Bool, r_drawplayersprites) EXTERN_CVAR(Bool, r_deathcamera) diff --git a/src/rendering/swrenderer/viewport/r_viewport.cpp b/src/rendering/swrenderer/viewport/r_viewport.cpp index 57c2f49c9c..3fdbe558e8 100644 --- a/src/rendering/swrenderer/viewport/r_viewport.cpp +++ b/src/rendering/swrenderer/viewport/r_viewport.cpp @@ -43,6 +43,7 @@ #include "swrenderer/plane/r_flatplane.h" #include "swrenderer/drawers/r_draw_pal.h" #include "swrenderer/drawers/r_draw_rgba.h" +#include "v_draw.h" CVAR(String, r_viewsize, "", CVAR_NOSET) diff --git a/src/rendering/v_framebuffer.cpp b/src/rendering/v_framebuffer.cpp index c7f120a9c9..4d55989c33 100644 --- a/src/rendering/v_framebuffer.cpp +++ b/src/rendering/v_framebuffer.cpp @@ -35,23 +35,21 @@ #include -#include "x86.h" -#include "actor.h" - #include "v_video.h" #include "c_dispatch.h" -#include "sbar.h" #include "hardware.h" -#include "r_utility.h" -#include "swrenderer/r_renderer.h" -#include "vm.h" #include "r_videoscale.h" #include "i_time.h" -#include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/utility/hw_clock.h" +#include "v_font.h" +#include "v_draw.h" +#include "i_time.h" +#include "v_2ddrawer.h" +#include "vm.h" +#include "i_interface.h" #include "flatvertices.h" -#include "swrenderer/r_swscene.h" +#include "version.h" +#include "hw_material.h" #include #include @@ -60,7 +58,7 @@ CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE); EXTERN_CVAR(Int, vid_maxfps) -EXTERN_CVAR(Bool, cl_capfps) +CVAR(Bool, cl_capfps, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) EXTERN_CVAR(Int, screenblocks) //========================================================================== @@ -75,21 +73,16 @@ EXTERN_CVAR(Int, screenblocks) DFrameBuffer::DFrameBuffer (int width, int height) { SetSize(width, height); - mPortalState = new FPortalSceneState; - twod = &m2DDrawer; } DFrameBuffer::~DFrameBuffer() { - if (twod == &m2DDrawer) twod = nullptr; - delete mPortalState; } void DFrameBuffer::SetSize(int width, int height) { Width = ViewportScaledWidth(width, height); Height = ViewportScaledHeight(width, height); - m2DDrawer.SetSize(width, height); } //========================================================================== @@ -100,8 +93,6 @@ void DFrameBuffer::SetSize(int width, int height) void DFrameBuffer::Update() { - CheckBench(); - int initialWidth = GetClientWidth(); int initialHeight = GetClientHeight(); int clientWidth = ViewportScaledWidth(initialWidth, initialHeight); @@ -182,19 +173,6 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds) return; } - // Special handling so the view with a visible status bar displays properly - int height, width; - if (screenblocks >= 10) - { - height = GetHeight(); - width = GetWidth(); - } - else - { - height = (screenblocks*GetHeight() / 10) & ~7; - width = (screenblocks*GetWidth() / 10); - } - // Back buffer letterbox for the final output int clientWidth = GetClientWidth(); int clientHeight = GetClientHeight(); @@ -222,10 +200,8 @@ void DFrameBuffer::SetViewportRects(IntRect *bounds) mScreenViewport.height = screenHeight; // Viewport for the 3D scene - mSceneViewport.left = viewwindowx; - mSceneViewport.top = screenHeight - (height + viewwindowy - ((height - viewheight) / 2)); - mSceneViewport.width = viewwidth; - mSceneViewport.height = height; + if (sysCallbacks && sysCallbacks->GetSceneRect) mSceneViewport = sysCallbacks->GetSceneRect(); + else mSceneViewport = mScreenViewport; // Scale viewports to fit letterbox bool notScaled = ((mScreenViewport.width == ViewportScaledWidth(mScreenViewport.width, mScreenViewport.height)) && diff --git a/src/rendering/v_video.cpp b/src/rendering/v_video.cpp index ff65646296..49a843414a 100644 --- a/src/rendering/v_video.cpp +++ b/src/rendering/v_video.cpp @@ -39,13 +39,8 @@ #include "c_cvars.h" #include "x86.h" #include "i_video.h" -#include "r_state.h" -#include "am_map.h" - -#include "doomstat.h" #include "c_console.h" -#include "hu_stuff.h" #include "m_argv.h" @@ -54,23 +49,19 @@ #include "sc_man.h" #include "filesystem.h" - #include "c_dispatch.h" #include "cmdlib.h" -#include "sbar.h" #include "hardware.h" #include "m_png.h" -#include "r_utility.h" -#include "swrenderer/r_renderer.h" #include "menu/menu.h" #include "vm.h" #include "r_videoscale.h" #include "i_time.h" #include "version.h" -#include "g_levellocals.h" -#include "am_map.h" #include "texturemanager.h" -#include "v_palette.h" +#include "i_interface.h" +#include "v_draw.h" +#include "templates.h" EXTERN_CVAR(Int, menu_resolution_custom_width) EXTERN_CVAR(Int, menu_resolution_custom_height) @@ -83,37 +74,16 @@ CVAR(Bool, win_maximized, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITC CUSTOM_CVAR(Int, vid_maxfps, 200, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) { - if (vid_maxfps < TICRATE && vid_maxfps != 0) + if (self < GameTicRate && self != 0) { - vid_maxfps = TICRATE; + self = GameTicRate; } else if (vid_maxfps > 1000) { - vid_maxfps = 1000; + self = 1000; } } -CUSTOM_CVAR(Int, vid_rendermode, 4, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) -{ - if (self < 0 || self > 4) - { - self = 4; - } - else if (self == 2 || self == 3) - { - self = self - 2; // softpoly to software - } - - if (usergame) - { - // [SP] Update pitch limits to the netgame/gamesim. - players[consoleplayer].SendPitchLimits(); - } - screen->SetTextureFilterMode(); - - // No further checks needed. All this changes now is which scene drawer the render backend calls. -} - CUSTOM_CVAR(Int, vid_preferbackend, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { // [SP] This may seem pointless - but I don't want to implement live switching just @@ -146,10 +116,8 @@ CUSTOM_CVAR(Int, uiscale, 0, CVAR_ARCHIVE | CVAR_NOINITCALL) self = 0; return; } - if (StatusBar != NULL) - { - StatusBar->CallScreenSizeChanged(); - } + if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) + sysCallbacks->OnScreenSizeChanged(); setsizeneeded = true; } @@ -159,8 +127,6 @@ EXTERN_CVAR(Bool, r_blendmethod) int active_con_scale(); -FRenderer *SWRenderer; - #define DBGBREAK assert(0) class DDummyFrameBuffer : public DFrameBuffer @@ -201,7 +167,8 @@ CUSTOM_CVAR (Bool, vid_vsync, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) } // [RH] Set true when vid_setmode command has been executed -bool setmodeneeded = false; +bool setmodeneeded = false; +bool setsizeneeded = false; //========================================================================== // @@ -317,23 +284,15 @@ void V_UpdateModeSize (int width, int height) DisplayWidth = width; DisplayHeight = height; - - R_OldBlend = ~0; } void V_OutputResized (int width, int height) { V_UpdateModeSize(width, height); setsizeneeded = true; - if (StatusBar != NULL) - { - StatusBar->CallScreenSizeChanged(); - } C_NewModeAdjust(); - // Reload crosshair if transitioned to a different size - ST_LoadCrosshair(true); - if (primaryLevel && primaryLevel->automap) - primaryLevel->automap->NewResolution(); + if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) + sysCallbacks->OnScreenSizeChanged(); } bool IVideo::SetResolution () @@ -430,10 +389,8 @@ void V_Init2() CUSTOM_CVAR (Int, vid_aspect, 0, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) { setsizeneeded = true; - if (StatusBar != NULL) - { - StatusBar->CallScreenSizeChanged(); - } + if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) + sysCallbacks->OnScreenSizeChanged(); } DEFINE_ACTION_FUNCTION(_Screen, GetAspectRatio) @@ -460,7 +417,7 @@ void IVideo::DumpAdapters () Printf("Multi-monitor support unavailable.\n"); } -CUSTOM_CVAR_NAMED(Bool, vid_fullscreen, fullscreen, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) +CUSTOM_CVAR(Bool, vid_fullscreen, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { setmodeneeded = true; } @@ -496,7 +453,6 @@ DEFINE_GLOBAL(CleanXfac_1) DEFINE_GLOBAL(CleanYfac_1) DEFINE_GLOBAL(CleanWidth_1) DEFINE_GLOBAL(CleanHeight_1) -DEFINE_GLOBAL(generic_ui) IHardwareTexture* CreateHardwareTexture() { @@ -505,51 +461,25 @@ IHardwareTexture* CreateHardwareTexture() //========================================================================== // -// V_DrawFrame +// CVAR transsouls // -// Draw a frame around the specified area using the view border -// frame graphics. The border is drawn outside the area, not in it. +// How translucent things drawn with STYLE_SoulTrans are. Normally, only +// Lost Souls have this render style. +// Values less than 0.25 will automatically be set to +// 0.25 to ensure some degree of visibility. Likewise, values above 1.0 will +// be set to 1.0, because anything higher doesn't make sense. // //========================================================================== -void DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height) +CUSTOM_CVAR(Float, transsouls, 0.75f, CVAR_ARCHIVE) { - FGameTexture* p; - const gameborder_t* border = &gameinfo.Border; - // Sanity check for incomplete gameinfo - if (border == NULL) - return; - int offset = border->offset; - int right = left + width; - int bottom = top + height; - - // Draw top and bottom sides. - p = TexMan.GetGameTextureByName(border->t); - drawer->AddFlatFill(left, top - (int)p->GetDisplayHeight(), right, top, p, true); - p = TexMan.GetGameTextureByName(border->b); - drawer->AddFlatFill(left, bottom, right, bottom + (int)p->GetDisplayHeight(), p, true); - - // Draw left and right sides. - p = TexMan.GetGameTextureByName(border->l); - drawer->AddFlatFill(left - (int)p->GetDisplayWidth(), top, left, bottom, p, true); - p = TexMan.GetGameTextureByName(border->r); - drawer->AddFlatFill(right, top, right + (int)p->GetDisplayWidth(), bottom, p, true); - - // Draw beveled corners. - DrawTexture(drawer, TexMan.GetGameTextureByName(border->tl), left - offset, top - offset, TAG_DONE); - DrawTexture(drawer, TexMan.GetGameTextureByName(border->tr), left + width, top - offset, TAG_DONE); - DrawTexture(drawer, TexMan.GetGameTextureByName(border->bl), left - offset, top + height, TAG_DONE); - DrawTexture(drawer, TexMan.GetGameTextureByName(border->br), left + width, top + height, TAG_DONE); + if (self < 0.25f) + { + self = 0.25f; + } + else if (self > 1.f) + { + self = 1.f; + } } -DEFINE_ACTION_FUNCTION(_Screen, DrawFrame) -{ - PARAM_PROLOGUE; - PARAM_INT(x); - PARAM_INT(y); - PARAM_INT(w); - PARAM_INT(h); - if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); - DrawFrame(twod, x, y, w, h); - return 0; -} diff --git a/src/rendering/v_video.h b/src/rendering/v_video.h index fd10970e62..72a89bc30f 100644 --- a/src/rendering/v_video.h +++ b/src/rendering/v_video.h @@ -35,8 +35,8 @@ #define __V_VIDEO_H__ #include +#include "basics.h" #include "vectors.h" - #include "m_png.h" #include "renderstyle.h" #include "c_cvars.h" @@ -44,10 +44,7 @@ #include "intrect.h" #include "hw_shadowmap.h" -static const int VID_MIN_WIDTH = 320; -static const int VID_MIN_HEIGHT = 200; -class player_t; struct sector_t; struct FPortalSceneState; class FSkyVertexBuffer; @@ -128,9 +125,6 @@ class FTexture; class DFrameBuffer { -public: - - F2DDrawer m2DDrawer; private: int Width = 0; int Height = 0; @@ -144,7 +138,6 @@ public: unsigned int uniformblockalignment = 256; // Hardware dependent uniform buffer alignment. unsigned int maxuniformblock = 65536; const char *vendorstring; // We have to account for some issues with particular vendors. - FPortalSceneState *mPortalState; // global portal state. FSkyVertexBuffer *mSkyData = nullptr; // the sky vertex buffer FFlatVertexBuffer *mVertexData = nullptr; // Global vertex data HWViewpointBuffer *mViewpoints = nullptr; // Viewpoint render data. @@ -224,14 +217,6 @@ public: virtual IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) { return nullptr; } bool BuffersArePersistent() { return !!(hwcaps & RFL_BUFFER_STORAGE); } - // Begin/End 2D drawing operations. - void Begin2D() - { - m2DDrawer.Begin(); - m2DDrawer.SetSize(Width, Height); - } - void End2D() { m2DDrawer.End(); } - // This is overridable in case Vulkan does it differently. virtual bool RenderTextureIsFlipped() const { @@ -255,7 +240,6 @@ public: virtual void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) {} virtual void SetActiveRenderTarget() {} - // Screen wiping virtual FTexture *WipeStartScreen(); virtual FTexture *WipeEndScreen(); @@ -265,7 +249,6 @@ public: void ScaleCoordsFromWindow(int16_t &x, int16_t &y); virtual void Draw2D() {} - void Clear2D() { m2DDrawer.Clear(); } virtual void SetViewportRects(IntRect *bounds); int ScreenToWindowX(int x); @@ -310,14 +293,8 @@ void V_Init2 (); void V_Shutdown (); -class FScanner; -struct FScriptPosition; - inline bool IsRatioWidescreen(int ratio) { return (ratio & 3) != 0; } - - -#include "v_draw.h" - +extern bool setsizeneeded, setmodeneeded; #endif // __V_VIDEO_H__ diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index edd5b6b959..ec0d42954d 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -31,6 +31,7 @@ #include "g_game.h" #include "v_text.h" #include "version.h" +#include "v_draw.h" #include "hwrenderer/utility/hw_clock.h" #include "hw_vrmodes.h" @@ -192,7 +193,7 @@ void VulkanFrameBuffer::Update() GetPostprocess()->SetActiveRenderTarget(); Draw2D(); - Clear2D(); + twod->Clear(); mRenderState->EndRenderPass(); mRenderState->EndFrame(); @@ -480,7 +481,7 @@ FTexture *VulkanFrameBuffer::WipeEndScreen() { GetPostprocess()->SetActiveRenderTarget(); Draw2D(); - Clear2D(); + twod->Clear(); auto tex = new FWrapperTexture(mScreenViewport.width, mScreenViewport.height, 1); auto systex = static_cast(tex->GetSystemTexture()); @@ -643,7 +644,7 @@ void VulkanFrameBuffer::UpdateGpuStats() void VulkanFrameBuffer::Draw2D() { - ::Draw2D(&m2DDrawer, *mRenderState); + ::Draw2D(twod, *mRenderState); } VulkanCommandBuffer *VulkanFrameBuffer::GetTransferCommands() diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index d95a0c1576..5fb7f2a08f 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -58,6 +58,7 @@ #include "c_dispatch.h" #include "s_music.h" #include "texturemanager.h" +#include "v_draw.h" DVector2 AM_GetPosition(); int Net_GetLatency(int *ld, int *ad); @@ -3498,3 +3499,4 @@ DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, name); DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, baseorder); DEFINE_FIELD_X(MusPlayingInfo, MusPlayingInfo, loop); +DEFINE_GLOBAL(generic_ui) diff --git a/src/sound/s_doomsound.cpp b/src/sound/s_doomsound.cpp index 4887f8e5c2..fccd817e4b 100644 --- a/src/sound/s_doomsound.cpp +++ b/src/sound/s_doomsound.cpp @@ -65,6 +65,7 @@ #include "vm.h" #include "g_game.h" #include "s_music.h" +#include "v_draw.h" // PUBLIC DATA DEFINITIONS ------------------------------------------------- diff --git a/src/version.h b/src/version.h index 213e3f517e..b2a6ba1fca 100644 --- a/src/version.h +++ b/src/version.h @@ -112,6 +112,8 @@ const char *GetVersionString(); const int SAVEPICWIDTH = 216; const int SAVEPICHEIGHT = 162; +const int VID_MIN_WIDTH = 320; +const int VID_MIN_HEIGHT = 200; #endif //__VERSION_H__ diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index 2050683e47..1796b309c3 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -55,6 +55,7 @@ #include "g_levellocals.h" #include "vm.h" #include "texturemanager.h" +#include "v_draw.h" CVAR(Bool, wi_percents, true, CVAR_ARCHIVE) CVAR(Bool, wi_showtotaltime, true, CVAR_ARCHIVE) @@ -701,7 +702,7 @@ void WI_Ticker() { if (WI_Screen) { - ScaleOverrider s(&screen->m2DDrawer); + ScaleOverrider s(twod); IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Ticker) { VMValue self = WI_Screen; @@ -721,7 +722,7 @@ void WI_Drawer() { if (WI_Screen) { - ScaleOverrider s(&screen->m2DDrawer); + ScaleOverrider s(twod); IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Drawer) { FillBorder(twod, nullptr); @@ -765,7 +766,7 @@ void WI_Start(wbstartstruct_t *wbstartstruct) } WI_Screen = cls->CreateNew(); - ScaleOverrider s(&screen->m2DDrawer); + ScaleOverrider s(twod); IFVIRTUALPTRNAME(WI_Screen, "StatusScreen", Start) { VMValue val[2] = { WI_Screen, wbstartstruct }; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 1b390c469e..f68533bfa8 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -2216,7 +2216,7 @@ OptionMenu VideoModeMenu protected Option "$VIDMNU_PREFERBACKEND", "vid_preferbackend", "PreferBackend" StaticText " " Option "$VIDMNU_RENDERMODE", "vid_rendermode", "RenderMode" - Option "$VIDMNU_FULLSCREEN", "fullscreen", "YesNo" + Option "$VIDMNU_FULLSCREEN", "vid_fullscreen", "YesNo" IfOption(Mac) { From b1dd1eff5032986434cc3eb48c1954ff91e9afa8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 28 Apr 2020 23:08:27 +0200 Subject: [PATCH 131/220] - moved video files to 'common'. --- src/CMakeLists.txt | 4 ++-- src/{ => common}/rendering/v_framebuffer.cpp | 0 src/{ => common}/rendering/v_video.cpp | 0 src/{ => common}/rendering/v_video.h | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename src/{ => common}/rendering/v_framebuffer.cpp (100%) rename src/{ => common}/rendering/v_video.cpp (100%) rename src/{ => common}/rendering/v_video.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55408d4fae..a38f58e168 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -878,9 +878,7 @@ set (PCH_SOURCES serializer_doom.cpp scriptutil.cpp st_stuff.cpp - rendering/v_framebuffer.cpp r_data/v_palette.cpp - rendering/v_video.cpp wi_stuff.cpp gamedata/a_keys.cpp gamedata/a_weapons.cpp @@ -1126,6 +1124,8 @@ set (PCH_SOURCES common/objects/dobject.cpp common/objects/dobjgc.cpp common/objects/dobjtype.cpp + common/rendering/v_framebuffer.cpp + common/rendering/v_video.cpp common/rendering/r_videoscale.cpp common/rendering/hwrenderer/data/flatvertices.cpp common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp diff --git a/src/rendering/v_framebuffer.cpp b/src/common/rendering/v_framebuffer.cpp similarity index 100% rename from src/rendering/v_framebuffer.cpp rename to src/common/rendering/v_framebuffer.cpp diff --git a/src/rendering/v_video.cpp b/src/common/rendering/v_video.cpp similarity index 100% rename from src/rendering/v_video.cpp rename to src/common/rendering/v_video.cpp diff --git a/src/rendering/v_video.h b/src/common/rendering/v_video.h similarity index 100% rename from src/rendering/v_video.h rename to src/common/rendering/v_video.h From 4b8fb7d48b0effaaa2d277350396b74cb5983268 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 00:14:42 +0200 Subject: [PATCH 132/220] - moved around some sky rendering code so that the game independent parts are grouped together. --- src/common/models/modelrenderer.h | 2 +- src/common/rendering/v_video.h | 1 - src/rendering/gl/system/gl_framebuffer.cpp | 7 - src/rendering/gl/system/gl_framebuffer.h | 1 - src/rendering/hwrenderer/scene/hw_portal.h | 4 - src/rendering/hwrenderer/scene/hw_skydome.cpp | 172 +++++++++++++++++- src/rendering/hwrenderer/scene/hw_skydome.h | 8 +- .../hwrenderer/scene/hw_skyportal.cpp | 119 +----------- .../hwrenderer/textures/hw_precache.cpp | 4 +- .../polyrenderer/backend/poly_framebuffer.cpp | 5 - .../polyrenderer/backend/poly_framebuffer.h | 1 - src/rendering/r_sky.cpp | 39 ---- src/rendering/r_sky.h | 6 - src/rendering/swrenderer/plane/r_skyplane.cpp | 2 + .../vulkan/system/vk_framebuffer.cpp | 5 - src/rendering/vulkan/system/vk_framebuffer.h | 1 - 16 files changed, 179 insertions(+), 198 deletions(-) diff --git a/src/common/models/modelrenderer.h b/src/common/models/modelrenderer.h index 1018d7ebbd..38786afe6f 100644 --- a/src/common/models/modelrenderer.h +++ b/src/common/models/modelrenderer.h @@ -1,4 +1,4 @@ - +#pragma once #include "renderstyle.h" #include "matrix.h" #include "model.h" diff --git a/src/common/rendering/v_video.h b/src/common/rendering/v_video.h index 72a89bc30f..e284ca79f0 100644 --- a/src/common/rendering/v_video.h +++ b/src/common/rendering/v_video.h @@ -199,7 +199,6 @@ public: virtual void SetTextureFilterMode() {} virtual IHardwareTexture *CreateHardwareTexture() { return nullptr; } virtual void PrecacheMaterial(FMaterial *mat, int translation) {} - virtual FModelRenderer *CreateModelRenderer(int mli) { return nullptr; } virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags); virtual void TextureFilterChanged() {} virtual void BeginFrame() {} diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index f995867bbe..37e7478384 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -169,10 +169,8 @@ void OpenGLFrameBuffer::InitializeState() mSkyData = new FSkyVertexBuffer; mViewpoints = new HWViewpointBuffer; mLights = new FLightBuffer(); - GLRenderer = new FGLRenderer(this); GLRenderer->Initialize(GetWidth(), GetHeight()); - static_cast(mLights->GetBuffer())->BindBase(); mDebug = std::make_shared(); @@ -327,11 +325,6 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) FHardwareTexture::UnbindAll(); } -FModelRenderer *OpenGLFrameBuffer::CreateModelRenderer(int mli) -{ - return new FHWModelRenderer(nullptr, gl_RenderState, mli); -} - IVertexBuffer *OpenGLFrameBuffer::CreateVertexBuffer() { return new GLVertexBuffer; diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/rendering/gl/system/gl_framebuffer.h index 0682ce02e2..28c4c4d2a3 100644 --- a/src/rendering/gl/system/gl_framebuffer.h +++ b/src/rendering/gl/system/gl_framebuffer.h @@ -43,7 +43,6 @@ public: void SetTextureFilterMode() override; IHardwareTexture *CreateHardwareTexture() override; void PrecacheMaterial(FMaterial *mat, int translation) override; - FModelRenderer *CreateModelRenderer(int mli) override; void TextureFilterChanged() override; void BeginFrame() override; void SetViewportRects(IntRect *bounds) override; diff --git a/src/rendering/hwrenderer/scene/hw_portal.h b/src/rendering/hwrenderer/scene/hw_portal.h index 56e6cb1392..2f1abd4646 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.h +++ b/src/rendering/hwrenderer/scene/hw_portal.h @@ -361,10 +361,6 @@ struct HWSkyPortal : public HWPortal FSkyVertexBuffer *vertexBuffer; friend struct HWEEHorizonPortal; - void RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply = true); - void RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FSkyBox * gltex, float x_offset, bool sky2); - void RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode); - protected: virtual void DrawContents(HWDrawInfo *di, FRenderState &state); virtual void * GetSource() const { return origin; } diff --git a/src/rendering/hwrenderer/scene/hw_skydome.cpp b/src/rendering/hwrenderer/scene/hw_skydome.cpp index e0e1103294..a2deb4998d 100644 --- a/src/rendering/hwrenderer/scene/hw_skydome.cpp +++ b/src/rendering/hwrenderer/scene/hw_skydome.cpp @@ -53,15 +53,9 @@ **--------------------------------------------------------------------------- ** */ -#include "doomtype.h" -#include "g_level.h" #include "filesystem.h" -#include "r_state.h" -#include "r_utility.h" -#include "g_levellocals.h" -#include "r_sky.h" #include "cmdlib.h" - +#include "bitmap.h" #include "skyboxtexture.h" #include "hw_material.h" #include "hw_skydome.h" @@ -69,6 +63,13 @@ #include "hw_drawinfo.h" #include "hwrenderer/data/buffers.h" +// 57 world units roughly represent one sky texel for the glTranslate call. +enum +{ + skyoffsetfactor = 57 +}; + + //----------------------------------------------------------------------------- // // Shamelessly lifted from Doomsday (written by Jaakko Keränen) @@ -77,6 +78,47 @@ //----------------------------------------------------------------------------- EXTERN_CVAR(Float, skyoffset) + +struct SkyColor +{ + FTextureID Texture; + std::pair Colors; +}; + +static TArray SkyColors; + +std::pair& R_GetSkyCapColor(FGameTexture* tex) +{ + for (auto& sky : SkyColors) + { + if (sky.Texture == tex->GetID()) return sky.Colors; + } + + auto itex = tex->GetTexture(); + SkyColor sky; + + FBitmap bitmap = itex->GetBgraBitmap(nullptr); + int w = bitmap.GetWidth(); + int h = bitmap.GetHeight(); + + const uint32_t* buffer = (const uint32_t*)bitmap.GetPixels(); + if (buffer) + { + sky.Colors.first = averageColor((uint32_t*)buffer, w * MIN(30, h), 0); + if (h > 30) + { + sky.Colors.second = averageColor(((uint32_t*)buffer) + (h - 30) * w, w * 30, 0); + } + else sky.Colors.second = sky.Colors.first; + } + sky.Texture = tex->GetID(); + SkyColors.Push(sky); + + return SkyColors.Last().Colors; +} + + + //----------------------------------------------------------------------------- // // @@ -282,7 +324,7 @@ void FSkyVertexBuffer::CreateDome() // //----------------------------------------------------------------------------- -void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix) +void FSkyVertexBuffer::SetupMatrices(FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelMatrix, VSMatrix &textureMatrix, bool tiled) { float texw = tex->GetDisplayWidth(); float texh = tex->GetDisplayHeight(); @@ -293,7 +335,7 @@ void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FGameTexture *tex, float x_ float xscale = texw < 1024.f ? floor(1024.f / float(texw)) : 1.f; float yscale = 1.f; auto texskyoffset = tex->GetSkyOffset() + skyoffset; - if (texh <= 128 && (di->Level->flags & LEVEL_FORCETILEDSKY)) + if (texh <= 128 && tiled) { modelMatrix.translate(0.f, (-40 + texskyoffset)*skyoffsetfactor, 0.f); modelMatrix.scale(1.f, 1.2f * 1.17f, 1.f); @@ -326,3 +368,115 @@ void FSkyVertexBuffer::SetupMatrices(HWDrawInfo *di, FGameTexture *tex, float x_ textureMatrix.scale(mirror ? -xscale : xscale, yscale, 1.f); textureMatrix.translate(1.f, y_offset / texh, 1.f); } + +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- + +void FSkyVertexBuffer::RenderRow(FRenderState& state, EDrawType prim, int row, bool apply) +{ + state.Draw(prim, mPrimStart[row], mPrimStart[row + 1] - mPrimStart[row]); +} + +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- + +void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled) +{ + if (tex) + { + state.SetMaterial(tex, UF_Texture, 0, CLAMP_NONE, 0, -1); + state.EnableModelMatrix(true); + state.EnableTextureMatrix(true); + + SetupMatrices(tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix, tiled); + } + + int rc = mRows + 1; + + // The caps only get drawn for the main layer but not for the overlay. + if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL) + { + auto& col = R_GetSkyCapColor(tex); + state.SetObjectColor(col.first); + state.EnableTexture(false); + RenderRow(state, DT_TriangleFan, 0); + + state.SetObjectColor(col.second); + RenderRow(state, DT_TriangleFan, rc); + state.EnableTexture(true); + } + state.SetObjectColor(0xffffffff); + for (int i = 1; i <= mRows; i++) + { + RenderRow(state, DT_TriangleStrip, i, i == 1); + RenderRow(state, DT_TriangleStrip, rc + i, false); + } + + state.EnableTextureMatrix(false); + state.EnableModelMatrix(false); +} + + +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- + +void FSkyVertexBuffer::RenderBox(FRenderState& state, FTextureID texno, FSkyBox* tex, float x_offset, bool sky2, float stretch, const FVector3& skyrotatevector, const FVector3& skyrotatevector2) +{ + int faces; + + state.EnableModelMatrix(true); + state.mModelMatrix.loadIdentity(); + state.mModelMatrix.scale(1, 1 / stretch, 1); // Undo the map's vertical scaling as skyboxes are true cubes. + + if (!sky2) + state.mModelMatrix.rotate(-180.0f + x_offset, skyrotatevector.X, skyrotatevector.Z, skyrotatevector.Y); + else + state.mModelMatrix.rotate(-180.0f + x_offset, skyrotatevector2.X, skyrotatevector2.Z, skyrotatevector2.Y); + + if (tex->GetSkyFace(5)) + { + faces = 4; + + // north + state.SetMaterial(tex->GetSkyFace(0), UF_Texture, 0, CLAMP_XY, 0, -1); + state.Draw(DT_TriangleStrip, FaceStart(0), 4); + + // east + state.SetMaterial(tex->GetSkyFace(1), UF_Texture, 0, CLAMP_XY, 0, -1); + state.Draw(DT_TriangleStrip, FaceStart(1), 4); + + // south + state.SetMaterial(tex->GetSkyFace(2), UF_Texture, 0, CLAMP_XY, 0, -1); + state.Draw(DT_TriangleStrip, FaceStart(2), 4); + + // west + state.SetMaterial(tex->GetSkyFace(3), UF_Texture, 0, CLAMP_XY, 0, -1); + state.Draw(DT_TriangleStrip, FaceStart(3), 4); + } + else + { + faces = 1; + state.SetMaterial(tex->GetSkyFace(0), UF_Texture, 0, CLAMP_XY, 0, -1); + state.Draw(DT_TriangleStrip, FaceStart(-1), 10); + } + + // top + state.SetMaterial(tex->GetSkyFace(faces), UF_Texture, 0, CLAMP_XY, 0, -1); + state.Draw(DT_TriangleStrip, FaceStart(tex->GetSkyFlip() ? 6 : 5), 4); + + // bottom + state.SetMaterial(tex->GetSkyFace(faces + 1), UF_Texture, 0, CLAMP_XY, 0, -1); + state.Draw(DT_TriangleStrip, FaceStart(4), 4); + + state.EnableModelMatrix(false); +} + diff --git a/src/rendering/hwrenderer/scene/hw_skydome.h b/src/rendering/hwrenderer/scene/hw_skydome.h index e4865f3308..527bd3fa8a 100644 --- a/src/rendering/hwrenderer/scene/hw_skydome.h +++ b/src/rendering/hwrenderer/scene/hw_skydome.h @@ -3,6 +3,8 @@ #include "v_palette.h" #include "matrix.h" #include "hwrenderer/data/buffers.h" +#include "hw_renderstate.h" +#include "skyboxtexture.h" class FGameTexture; class FRenderState; @@ -70,7 +72,7 @@ public: FSkyVertexBuffer(); ~FSkyVertexBuffer(); - void SetupMatrices(HWDrawInfo *di, FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix); + void SetupMatrices(FGameTexture *tex, float x_offset, float y_offset, bool mirror, int mode, VSMatrix &modelmatrix, VSMatrix &textureMatrix, bool tiled); std::pair GetBufferObjects() const { return std::make_pair(mVertexBuffer, nullptr); @@ -82,4 +84,8 @@ public: else return mSideStart; } + void RenderRow(FRenderState& state, EDrawType prim, int row, bool apply = true); + void RenderDome(FRenderState& state, FGameTexture* tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled); + void RenderBox(FRenderState& state, FTextureID texno, FSkyBox* tex, float x_offset, bool sky2, float stretch, const FVector3& skyrotatevector, const FVector3& skyrotatevector2); + }; diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index d97b026882..58848a30f7 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -31,119 +31,6 @@ #include "hw_renderstate.h" #include "skyboxtexture.h" - - -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - -void HWSkyPortal::RenderRow(HWDrawInfo *di, FRenderState &state, EDrawType prim, int row, bool apply) -{ - state.Draw(prim, vertexBuffer->mPrimStart[row], vertexBuffer->mPrimStart[row + 1] - vertexBuffer->mPrimStart[row]); -} - -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - -void HWSkyPortal::RenderDome(HWDrawInfo *di, FRenderState &state, FGameTexture * tex, float x_offset, float y_offset, bool mirror, int mode) -{ - if (tex) - { - state.SetMaterial(tex, UF_Texture, 0, CLAMP_NONE, 0, -1); - state.EnableModelMatrix(true); - state.EnableTextureMatrix(true); - - vertexBuffer->SetupMatrices(di, tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix); - } - - int rc = vertexBuffer->mRows + 1; - - // The caps only get drawn for the main layer but not for the overlay. - if (mode == FSkyVertexBuffer::SKYMODE_MAINLAYER && tex != NULL) - { - auto &col = R_GetSkyCapColor(tex); - state.SetObjectColor(col.first); - state.EnableTexture(false); - RenderRow(di, state, DT_TriangleFan, 0); - - state.SetObjectColor(col.second); - RenderRow(di, state, DT_TriangleFan, rc); - state.EnableTexture(true); - } - state.SetObjectColor(0xffffffff); - for (int i = 1; i <= vertexBuffer->mRows; i++) - { - RenderRow(di, state, DT_TriangleStrip, i, i == 1); - RenderRow(di, state, DT_TriangleStrip, rc + i, false); - } - - state.EnableTextureMatrix(false); - state.EnableModelMatrix(false); -} - - -//----------------------------------------------------------------------------- -// -// -// -//----------------------------------------------------------------------------- - -void HWSkyPortal::RenderBox(HWDrawInfo *di, FRenderState &state, FTextureID texno, FSkyBox * tex, float x_offset, bool sky2) -{ - int faces; - - state.EnableModelMatrix(true); - state.mModelMatrix.loadIdentity(); - state.mModelMatrix.scale(1, 1 / di->Level->info->pixelstretch, 1); // Undo the map's vertical scaling as skyboxes are true cubes. - - if (!sky2) - state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector.X, di->Level->info->skyrotatevector.Z, di->Level->info->skyrotatevector.Y); - else - state.mModelMatrix.rotate(-180.0f+x_offset, di->Level->info->skyrotatevector2.X, di->Level->info->skyrotatevector2.Z, di->Level->info->skyrotatevector2.Y); - - if (tex->GetSkyFace(5)) - { - faces=4; - - // north - state.SetMaterial(tex->GetSkyFace(0), UF_Texture, 0, CLAMP_XY, 0, -1); - state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(0), 4); - - // east - state.SetMaterial(tex->GetSkyFace(1), UF_Texture, 0, CLAMP_XY, 0, -1); - state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(1), 4); - - // south - state.SetMaterial(tex->GetSkyFace(2), UF_Texture, 0, CLAMP_XY, 0, -1); - state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(2), 4); - - // west - state.SetMaterial(tex->GetSkyFace(3), UF_Texture, 0, CLAMP_XY, 0, -1); - state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(3), 4); - } - else - { - faces=1; - state.SetMaterial(tex->GetSkyFace(0), UF_Texture, 0, CLAMP_XY, 0, -1); - state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(-1), 10); - } - - // top - state.SetMaterial(tex->GetSkyFace(faces), UF_Texture, 0, CLAMP_XY, 0, -1); - state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(tex->GetSkyFlip() ? 6 : 5), 4); - - // bottom - state.SetMaterial(tex->GetSkyFace(faces+1), UF_Texture, 0, CLAMP_XY, 0, -1); - state.Draw(DT_TriangleStrip, vertexBuffer->FaceStart(4), 4); - - state.EnableModelMatrix(false); -} - //----------------------------------------------------------------------------- // // @@ -175,7 +62,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) auto skybox = origin->texture[0] ? dynamic_cast(origin->texture[0]->GetTexture()) : nullptr; if (skybox) { - RenderBox(di, state, origin->skytexno1, skybox, origin->x_offset[0], origin->sky2); + vertexBuffer->RenderBox(state, origin->skytexno1, skybox, origin->x_offset[0], origin->sky2, di->Level->info->pixelstretch, di->Level->info->skyrotatevector, di->Level->info->skyrotatevector2); } else { @@ -184,7 +71,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) if (origin->texture[0]) { state.SetTextureMode(TM_OPAQUE); - RenderDome(di, state, origin->texture[0], origin->x_offset[0], origin->y_offset, origin->mirrored, FSkyVertexBuffer::SKYMODE_MAINLAYER); + vertexBuffer->RenderDome(state, origin->texture[0], origin->x_offset[0], origin->y_offset, origin->mirrored, FSkyVertexBuffer::SKYMODE_MAINLAYER, !!(di->Level->flags & LEVEL_FORCETILEDSKY)); state.SetTextureMode(TM_NORMAL); } @@ -192,7 +79,7 @@ void HWSkyPortal::DrawContents(HWDrawInfo *di, FRenderState &state) if (origin->doublesky && origin->texture[1]) { - RenderDome(di, state, origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER); + vertexBuffer->RenderDome(state, origin->texture[1], origin->x_offset[1], origin->y_offset, false, FSkyVertexBuffer::SKYMODE_SECONDLAYER, !!(di->Level->flags & LEVEL_FORCETILEDSKY)); } if (di->Level->skyfog>0 && !di->isFullbrightScene() && (origin->fadecolor & 0xffffff) != 0) diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/textures/hw_precache.cpp index 462b340845..1260ae77b5 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/textures/hw_precache.cpp @@ -38,6 +38,7 @@ #include "v_font.h" #include "texturemanager.h" #include "modelrenderer.h" +#include "hwrenderer/models/hw_models.h" #include "d_main.h" EXTERN_CVAR(Bool, gl_precache) @@ -87,6 +88,7 @@ static void PrecacheSprite(FGameTexture *tex, SpriteHits &hits) if (gltex) PrecacheList(gltex, hits); } + //========================================================================== // // DFrameBuffer :: Precache @@ -315,7 +317,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl FImageSource::EndPrecaching(); // cache all used models - FModelRenderer *renderer = screen->CreateModelRenderer(-1); + FModelRenderer* renderer = new FHWModelRenderer(nullptr, *screen->RenderState(), -1); for (unsigned i = 0; i < Models.Size(); i++) { if (modellist[i]) diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 6712ac407f..487cc4160d 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -321,11 +321,6 @@ IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture() return new PolyHardwareTexture(); } -FModelRenderer *PolyFrameBuffer::CreateModelRenderer(int mli) -{ - return new FHWModelRenderer(nullptr, *GetRenderState(), mli); -} - IVertexBuffer *PolyFrameBuffer::CreateVertexBuffer() { return new PolyVertexBuffer(); diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index 6f06b7d2b9..200abce3a1 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -45,7 +45,6 @@ public: //void SetSceneRenderTarget(bool useSSAO) override; IHardwareTexture *CreateHardwareTexture() override; - FModelRenderer *CreateModelRenderer(int mli) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override; diff --git a/src/rendering/r_sky.cpp b/src/rendering/r_sky.cpp index d8d340b0ef..ef74707ce4 100644 --- a/src/rendering/r_sky.cpp +++ b/src/rendering/r_sky.cpp @@ -57,45 +57,6 @@ CUSTOM_CVAR (Int, r_skymode, 2, CVAR_ARCHIVE|CVAR_NOINITCALL) CVAR(Float, skyoffset, 0, 0) // for testing -struct SkyColor -{ - FTextureID Texture; - std::pair Colors; -}; - -static TArray SkyColors; - -std::pair& R_GetSkyCapColor(FGameTexture* tex) -{ - for (auto& sky : SkyColors) - { - if (sky.Texture == tex->GetID()) return sky.Colors; - } - - auto itex = tex->GetTexture(); - SkyColor sky; - - FBitmap bitmap = itex->GetBgraBitmap(nullptr); - int w = bitmap.GetWidth(); - int h = bitmap.GetHeight(); - - const uint32_t* buffer = (const uint32_t*)bitmap.GetPixels(); - if (buffer) - { - sky.Colors.first = averageColor((uint32_t*)buffer, w * MIN(30, h), 0); - if (h > 30) - { - sky.Colors.second = averageColor(((uint32_t*)buffer) + (h - 30) * w, w * 30, 0); - } - else sky.Colors.second = sky.Colors.first; - } - sky.Texture = tex->GetID(); - SkyColors.Push(sky); - - return SkyColors.Last().Colors; -} - - //========================================================================== // // R_InitSkyMap diff --git a/src/rendering/r_sky.h b/src/rendering/r_sky.h index 43cd7a0ce5..fa36e535b8 100644 --- a/src/rendering/r_sky.h +++ b/src/rendering/r_sky.h @@ -44,11 +44,5 @@ void R_InitSkyMap(); void R_UpdateSky (uint64_t mstime); std::pair& R_GetSkyCapColor(FGameTexture* tex); -// 57 world units roughly represent one sky texel for the glTranslate call. -enum -{ - skyoffsetfactor = 57 -}; - #endif //__R_SKY_H__ diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 3874257e40..4d1664948e 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -59,6 +59,8 @@ CVAR(Bool, r_linearsky, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); EXTERN_CVAR(Int, r_skymode) EXTERN_CVAR(Bool, cl_oldfreelooklimit) +std::pair& R_GetSkyCapColor(FGameTexture* tex); + namespace swrenderer { static FSoftwareTexture *GetSWTex(FTextureID texid, bool allownull = true) diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index ec0d42954d..27a53ed956 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -397,11 +397,6 @@ FMaterial* VulkanFrameBuffer::CreateMaterial(FGameTexture* tex, int scaleflags) return new VkMaterial(tex, scaleflags); } -FModelRenderer *VulkanFrameBuffer::CreateModelRenderer(int mli) -{ - return new FHWModelRenderer(nullptr, *GetRenderState(), mli); -} - IVertexBuffer *VulkanFrameBuffer::CreateVertexBuffer() { return new VKVertexBuffer(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 707880599b..bf062afe2c 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -91,7 +91,6 @@ public: IHardwareTexture *CreateHardwareTexture() override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; - FModelRenderer *CreateModelRenderer(int mli) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override; From 64e301130bd3521a32e2e188c9347d9bf354957f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 00:21:30 +0200 Subject: [PATCH 133/220] - moved low level sky rendering to 'common' --- src/CMakeLists.txt | 2 +- .../scene => common/rendering/hwrenderer/data}/hw_skydome.cpp | 2 +- .../scene => common/rendering/hwrenderer/data}/hw_skydome.h | 0 src/rendering/gl/renderer/gl_renderer.cpp | 2 +- src/rendering/gl/system/gl_framebuffer.cpp | 2 +- src/rendering/hwrenderer/scene/hw_skyportal.cpp | 2 +- src/rendering/polyrenderer/backend/poly_framebuffer.cpp | 2 +- src/rendering/polyrenderer/backend/poly_renderstate.cpp | 2 +- src/rendering/vulkan/renderer/vk_renderstate.cpp | 2 +- src/rendering/vulkan/system/vk_framebuffer.cpp | 2 +- 10 files changed, 9 insertions(+), 9 deletions(-) rename src/{rendering/hwrenderer/scene => common/rendering/hwrenderer/data}/hw_skydome.cpp (99%) rename src/{rendering/hwrenderer/scene => common/rendering/hwrenderer/data}/hw_skydome.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a38f58e168..d94f0877dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -942,7 +942,6 @@ set (PCH_SOURCES rendering/hwrenderer/data/hw_vertexbuilder.cpp rendering/hwrenderer/dynlights/doom_aabbtree.cpp rendering/hwrenderer/models/hw_models.cpp - rendering/hwrenderer/scene/hw_skydome.cpp rendering/hwrenderer/scene/hw_drawlistadd.cpp rendering/hwrenderer/scene/hw_renderstate.cpp rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp @@ -1127,6 +1126,7 @@ set (PCH_SOURCES common/rendering/v_framebuffer.cpp common/rendering/v_video.cpp common/rendering/r_videoscale.cpp + common/rendering/hwrenderer/data/hw_skydome.cpp common/rendering/hwrenderer/data/flatvertices.cpp common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp common/rendering/hwrenderer/data/hw_modelvertexbuffer.cpp diff --git a/src/rendering/hwrenderer/scene/hw_skydome.cpp b/src/common/rendering/hwrenderer/data/hw_skydome.cpp similarity index 99% rename from src/rendering/hwrenderer/scene/hw_skydome.cpp rename to src/common/rendering/hwrenderer/data/hw_skydome.cpp index a2deb4998d..7e882acd07 100644 --- a/src/rendering/hwrenderer/scene/hw_skydome.cpp +++ b/src/common/rendering/hwrenderer/data/hw_skydome.cpp @@ -60,7 +60,7 @@ #include "hw_material.h" #include "hw_skydome.h" #include "hw_renderstate.h" -#include "hw_drawinfo.h" +#include "v_video.h" #include "hwrenderer/data/buffers.h" // 57 world units roughly represent one sky texel for the glTranslate call. diff --git a/src/rendering/hwrenderer/scene/hw_skydome.h b/src/common/rendering/hwrenderer/data/hw_skydome.h similarity index 100% rename from src/rendering/hwrenderer/scene/hw_skydome.h rename to src/common/rendering/hwrenderer/data/hw_skydome.h diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 15e151739c..2f2f5ebaa6 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -52,7 +52,7 @@ #include "gl_shaderprogram.h" #include "hw_vrmodes.h" #include "flatvertices.h" -#include "hwrenderer/scene/hw_skydome.h" +#include "hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "gl_samplers.h" #include "hw_lightbuffer.h" diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/rendering/gl/system/gl_framebuffer.cpp index 37e7478384..2cff171e0f 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/rendering/gl/system/gl_framebuffer.cpp @@ -47,7 +47,7 @@ #include "hwrenderer/utility/hw_clock.h" #include "hw_vrmodes.h" #include "hwrenderer/models/hw_models.h" -#include "hwrenderer/scene/hw_skydome.h" +#include "hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hw_lightbuffer.h" diff --git a/src/rendering/hwrenderer/scene/hw_skyportal.cpp b/src/rendering/hwrenderer/scene/hw_skyportal.cpp index 58848a30f7..f02ce5a29c 100644 --- a/src/rendering/hwrenderer/scene/hw_skyportal.cpp +++ b/src/rendering/hwrenderer/scene/hw_skyportal.cpp @@ -26,7 +26,7 @@ #include "r_state.h" #include "r_utility.h" #include "g_levellocals.h" -#include "hwrenderer/scene/hw_skydome.h" +#include "hw_skydome.h" #include "hwrenderer/scene/hw_portal.h" #include "hw_renderstate.h" #include "skyboxtexture.h" diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 487cc4160d..5693c2cff9 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -34,7 +34,7 @@ #include "hw_vrmodes.h" #include "hw_cvars.h" #include "hwrenderer/models/hw_models.h" -#include "hwrenderer/scene/hw_skydome.h" +#include "hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_portal.h" diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 5f4cf463d4..830a344e7d 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -26,7 +26,7 @@ #include "templates.h" #include "doomstat.h" #include "r_data/colormaps.h" -#include "hwrenderer/scene/hw_skydome.h" +#include "hw_skydome.h" #include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" #include "hw_cvars.h" diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 8a0223552a..a3ae824f08 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -29,7 +29,7 @@ #include "templates.h" #include "doomstat.h" #include "r_data/colormaps.h" -#include "hwrenderer/scene/hw_skydome.h" +#include "hw_skydome.h" #include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" #include "hw_cvars.h" diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 27a53ed956..f7af67ea19 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -37,7 +37,7 @@ #include "hw_vrmodes.h" #include "hw_cvars.h" #include "hwrenderer/models/hw_models.h" -#include "hwrenderer/scene/hw_skydome.h" +#include "hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_portal.h" From 2adf1c6a6b8b6459d031f019f3103ede11178b73 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 07:57:17 +0200 Subject: [PATCH 134/220] - fixed ZScript compiler crash with dereferencing null pointers --- src/common/scripting/backend/codegen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index aaef459a66..8368220d33 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -6362,7 +6362,7 @@ FxExpression *FxMemberIdentifier::Resolve(FCompileContext& ctx) if (Object->ValueType->isRealPointer()) { auto ptype = Object->ValueType->toPointer()->PointedType; - if (ptype->isContainer()) + if (ptype && ptype->isContainer()) { auto ret = ResolveMember(ctx, ctx.Class, Object, static_cast(ptype)); delete this; From c996600de7ff9cba744029603ca090b65542997f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 08:01:29 +0200 Subject: [PATCH 135/220] - gl_renderer.cpp include cleanup --- src/rendering/gl/renderer/gl_renderer.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/rendering/gl/renderer/gl_renderer.cpp index 2f2f5ebaa6..78f58ab8c9 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/rendering/gl/renderer/gl_renderer.cpp @@ -40,8 +40,6 @@ #include "i_time.h" #include "cmdlib.h" #include "version.h" -#include "hwrenderer/utility/hw_clock.h" - #include "gl_interface.h" #include "gl/system/gl_framebuffer.h" #include "hw_cvars.h" @@ -50,13 +48,9 @@ #include "gl_renderstate.h" #include "gl_renderbuffers.h" #include "gl_shaderprogram.h" -#include "hw_vrmodes.h" #include "flatvertices.h" -#include "hw_skydome.h" -#include "hwrenderer/scene/hw_fakeflat.h" #include "gl_samplers.h" #include "hw_lightbuffer.h" -#include "hwrenderer/data/hw_viewpointbuffer.h" #include "r_videoscale.h" #include "model.h" #include "gl_postprocessstate.h" From 6cf91d3941e382a5289a026163ccd2fb12b1a244 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 17:19:17 +0200 Subject: [PATCH 136/220] - moved the remaining core parts of the GL renderer to 'common'. --- src/CMakeLists.txt | 20 ++++--------------- src/common/engine/i_interface.h | 1 + src/common/platform/posix/cocoa/i_video.mm | 2 +- src/common/platform/posix/sdl/sdlglvideo.cpp | 4 ++-- src/common/platform/win32/win32basevideo.cpp | 2 +- src/common/platform/win32/win32glvideo.cpp | 2 +- .../rendering/gl}/gl_framebuffer.cpp | 6 +++--- .../rendering/gl}/gl_framebuffer.h | 0 src/common/rendering/gl/gl_hwtexture.cpp | 2 +- src/common/rendering/gl/gl_postprocess.cpp | 4 ++-- src/common/rendering/gl/gl_renderbuffers.cpp | 2 +- .../rendering/gl}/gl_renderer.cpp | 4 ++-- .../rendering/gl}/gl_renderer.h | 5 ----- src/common/rendering/gl/gl_renderstate.cpp | 4 ++-- src/common/rendering/gl/gl_samplers.cpp | 2 +- src/common/rendering/gl/gl_shader.cpp | 2 +- .../rendering/gl}/gl_stereo3d.cpp | 10 ++++++---- .../rendering/hwrenderer/data}/hw_clock.cpp | 9 +++------ .../rendering/hwrenderer/data}/hw_clock.h | 0 .../rendering/hwrenderer/data/hw_skydome.cpp | 2 +- .../rendering/hwrenderer/data/hw_skydome.h | 1 - src/d_main.cpp | 13 +++++++++++- src/playsim/p_pspr.h | 1 + src/rendering/hwrenderer/hw_entrypoint.cpp | 2 +- src/rendering/hwrenderer/scene/hw_bsp.cpp | 2 +- src/rendering/hwrenderer/scene/hw_decal.cpp | 2 +- .../hwrenderer/scene/hw_drawinfo.cpp | 2 +- .../hwrenderer/scene/hw_drawlist.cpp | 2 +- src/rendering/hwrenderer/scene/hw_flats.cpp | 2 +- src/rendering/hwrenderer/scene/hw_portal.cpp | 2 +- .../hwrenderer/scene/hw_renderhacks.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 2 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 2 +- .../hwrenderer/utility/hw_draw2d.cpp | 2 +- .../polyrenderer/backend/poly_framebuffer.cpp | 2 +- .../polyrenderer/backend/poly_renderstate.cpp | 2 +- src/rendering/r_sky.cpp | 3 --- .../vulkan/renderer/vk_renderstate.cpp | 2 +- .../vulkan/system/vk_framebuffer.cpp | 2 +- 39 files changed, 61 insertions(+), 70 deletions(-) rename src/{rendering/gl/system => common/rendering/gl}/gl_framebuffer.cpp (99%) rename src/{rendering/gl/system => common/rendering/gl}/gl_framebuffer.h (100%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_renderer.cpp (98%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_renderer.h (94%) rename src/{rendering/gl/renderer => common/rendering/gl}/gl_stereo3d.cpp (98%) rename src/{rendering/hwrenderer/utility => common/rendering/hwrenderer/data}/hw_clock.cpp (95%) rename src/{rendering/hwrenderer/utility => common/rendering/hwrenderer/data}/hw_clock.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d94f0877dc..d6678ec690 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -659,9 +659,6 @@ file( GLOB HEADER_FILES rendering/vulkan/renderer/*.h rendering/vulkan/shaders/*.h rendering/vulkan/textures/*.h - rendering/gl/renderer/*.h - rendering/gl/shaders/*.h - rendering/gl/system/*.h *.h ) @@ -935,9 +932,6 @@ set (PCH_SOURCES g_statusbar/shared_sbar.cpp rendering/2d/f_wipe.cpp rendering/2d/v_blend.cpp - rendering/gl/renderer/gl_renderer.cpp - rendering/gl/renderer/gl_stereo3d.cpp - rendering/gl/system/gl_framebuffer.cpp rendering/hwrenderer/hw_entrypoint.cpp rendering/hwrenderer/data/hw_vertexbuilder.cpp rendering/hwrenderer/dynlights/doom_aabbtree.cpp @@ -946,7 +940,6 @@ set (PCH_SOURCES rendering/hwrenderer/scene/hw_renderstate.cpp rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp rendering/hwrenderer/textures/hw_precache.cpp - rendering/hwrenderer/utility/hw_clock.cpp rendering/hwrenderer/utility/hw_draw2d.cpp rendering/hwrenderer/utility/hw_lighting.cpp maploader/edata.cpp @@ -1126,6 +1119,7 @@ set (PCH_SOURCES common/rendering/v_framebuffer.cpp common/rendering/v_video.cpp common/rendering/r_videoscale.cpp + common/rendering/hwrenderer/data/hw_clock.cpp common/rendering/hwrenderer/data/hw_skydome.cpp common/rendering/hwrenderer/data/flatvertices.cpp common/rendering/hwrenderer/data/hw_viewpointbuffer.cpp @@ -1139,6 +1133,9 @@ set (PCH_SOURCES common/rendering/hwrenderer/postprocessing/hw_postprocess.cpp common/rendering/hwrenderer/postprocessing/hw_postprocess_cvars.cpp common/rendering/gl_load/gl_interface.cpp + common/rendering/gl/gl_renderer.cpp + common/rendering/gl/gl_stereo3d.cpp + common/rendering/gl/gl_framebuffer.cpp common/rendering/gl/gl_renderstate.cpp common/rendering/gl/gl_renderbuffers.cpp common/rendering/gl/gl_postprocess.cpp @@ -1420,15 +1417,6 @@ source_group("Rendering\\Vulkan Renderer\\Textures" REGULAR_EXPRESSION "^${CMAKE source_group("Rendering\\Vulkan Renderer\\Third Party" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/thirdparty/.+") source_group("Rendering\\Vulkan Renderer\\Third Party\\Volk" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/thirdparty/volk/.+") source_group("Rendering\\Vulkan Renderer\\Third Party\\Vk_Mem_Alloc" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/thirdparty/vk_mem_alloc.+") -source_group("Rendering\\OpenGL Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/.+") -source_group("Rendering\\OpenGL Renderer\\Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/data/.+") -source_group("Rendering\\OpenGL Renderer\\Dynamic Lights" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/dynlights/.+") -source_group("Rendering\\OpenGL Renderer\\Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/renderer/.+") -source_group("Rendering\\OpenGL Renderer\\Scene" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/scene/.+") -source_group("Rendering\\OpenGL Renderer\\Shaders" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/shaders/.+") -source_group("Rendering\\OpenGL Renderer\\System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/system/.+") -source_group("Rendering\\OpenGL Renderer\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/textures/.+") -source_group("Rendering\\OpenGL Renderer\\Utilities" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/gl/utility/.+") source_group("Rendering\\Software Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/.+") source_group("Rendering\\Software Renderer\\Drawers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/drawers/.+") source_group("Rendering\\Software Renderer\\Scene" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/scene/.+") diff --git a/src/common/engine/i_interface.h b/src/common/engine/i_interface.h index 594d5ab2b7..5bd03dd0b6 100644 --- a/src/common/engine/i_interface.h +++ b/src/common/engine/i_interface.h @@ -16,6 +16,7 @@ struct SystemCallbacks bool (*DisableTextureFilter)(); void (*OnScreenSizeChanged)(); IntRect(*GetSceneRect)(); + FString(*GetLocationDescription)(); }; extern SystemCallbacks *sysCallbacks; diff --git a/src/common/platform/posix/cocoa/i_video.mm b/src/common/platform/posix/cocoa/i_video.mm index 6cf35313e3..1f2056ab53 100644 --- a/src/common/platform/posix/cocoa/i_video.mm +++ b/src/common/platform/posix/cocoa/i_video.mm @@ -53,7 +53,7 @@ #include "version.h" #include "printf.h" -#include "gl/system/gl_framebuffer.h" +#include "gl_framebuffer.h" #ifdef HAVE_VULKAN #include "vulkan/system/vk_framebuffer.h" #endif diff --git a/src/common/platform/posix/sdl/sdlglvideo.cpp b/src/common/platform/posix/sdl/sdlglvideo.cpp index 66edd075e0..65133a7923 100644 --- a/src/common/platform/posix/sdl/sdlglvideo.cpp +++ b/src/common/platform/posix/sdl/sdlglvideo.cpp @@ -47,8 +47,8 @@ #include "gl_sysfb.h" #include "gl_system.h" -#include "gl/renderer/gl_renderer.h" -#include "gl/system/gl_framebuffer.h" +#include "gl_renderer.h" +#include "gl_framebuffer.h" #ifdef HAVE_VULKAN #include "rendering/vulkan/system/vk_framebuffer.h" diff --git a/src/common/platform/win32/win32basevideo.cpp b/src/common/platform/win32/win32basevideo.cpp index bb1fb81baa..fe2ba3b9a3 100644 --- a/src/common/platform/win32/win32basevideo.cpp +++ b/src/common/platform/win32/win32basevideo.cpp @@ -52,7 +52,7 @@ #include "win32basevideo.h" #include "cmdlib.h" -#include "gl/system/gl_framebuffer.h" +#include "gl_framebuffer.h" CVAR(Int, vid_adapter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) diff --git a/src/common/platform/win32/win32glvideo.cpp b/src/common/platform/win32/win32glvideo.cpp index 80dadfd0e7..034ec86918 100644 --- a/src/common/platform/win32/win32glvideo.cpp +++ b/src/common/platform/win32/win32glvideo.cpp @@ -53,7 +53,7 @@ #include "engineerrors.h" #include "win32glvideo.h" -#include "gl/system/gl_framebuffer.h" +#include "gl_framebuffer.h" EXTERN_CVAR(Int, vid_adapter) EXTERN_CVAR(Bool, vid_hdr) diff --git a/src/rendering/gl/system/gl_framebuffer.cpp b/src/common/rendering/gl/gl_framebuffer.cpp similarity index 99% rename from src/rendering/gl/system/gl_framebuffer.cpp rename to src/common/rendering/gl/gl_framebuffer.cpp index 2cff171e0f..26d1cc58c1 100644 --- a/src/rendering/gl/system/gl_framebuffer.cpp +++ b/src/common/rendering/gl/gl_framebuffer.cpp @@ -40,11 +40,11 @@ #include "i_time.h" #include "gl_interface.h" -#include "gl/system/gl_framebuffer.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_framebuffer.h" +#include "gl_renderer.h" #include "gl_renderbuffers.h" #include "gl_samplers.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hw_vrmodes.h" #include "hwrenderer/models/hw_models.h" #include "hw_skydome.h" diff --git a/src/rendering/gl/system/gl_framebuffer.h b/src/common/rendering/gl/gl_framebuffer.h similarity index 100% rename from src/rendering/gl/system/gl_framebuffer.h rename to src/common/rendering/gl/gl_framebuffer.h diff --git a/src/common/rendering/gl/gl_hwtexture.cpp b/src/common/rendering/gl/gl_hwtexture.cpp index 3aa4aad79a..143aba1831 100644 --- a/src/common/rendering/gl/gl_hwtexture.cpp +++ b/src/common/rendering/gl/gl_hwtexture.cpp @@ -41,7 +41,7 @@ #include "gl_interface.h" #include "hw_cvars.h" #include "gl_debug.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_renderer.h" #include "gl_renderstate.h" #include "gl_samplers.h" diff --git a/src/common/rendering/gl/gl_postprocess.cpp b/src/common/rendering/gl/gl_postprocess.cpp index 8af1a2272d..2ac2db3136 100644 --- a/src/common/rendering/gl/gl_postprocess.cpp +++ b/src/common/rendering/gl/gl_postprocess.cpp @@ -22,10 +22,10 @@ #include "gl_system.h" #include "m_png.h" #include "gl_buffers.h" -#include "gl/system/gl_framebuffer.h" +#include "gl_framebuffer.h" #include "gl_debug.h" #include "gl_renderbuffers.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_renderer.h" #include "gl_postprocessstate.h" #include "gl_shaderprogram.h" #include "hwrenderer/postprocessing/hw_postprocess.h" diff --git a/src/common/rendering/gl/gl_renderbuffers.cpp b/src/common/rendering/gl/gl_renderbuffers.cpp index 5e212a3bee..a1d8899bb1 100644 --- a/src/common/rendering/gl/gl_renderbuffers.cpp +++ b/src/common/rendering/gl/gl_renderbuffers.cpp @@ -25,7 +25,7 @@ #include "printf.h" #include "hw_cvars.h" #include "gl_debug.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_renderer.h" #include "gl_renderbuffers.h" #include "gl_postprocessstate.h" #include "gl_shaderprogram.h" diff --git a/src/rendering/gl/renderer/gl_renderer.cpp b/src/common/rendering/gl/gl_renderer.cpp similarity index 98% rename from src/rendering/gl/renderer/gl_renderer.cpp rename to src/common/rendering/gl/gl_renderer.cpp index 78f58ab8c9..305ee0a974 100644 --- a/src/rendering/gl/renderer/gl_renderer.cpp +++ b/src/common/rendering/gl/gl_renderer.cpp @@ -41,10 +41,10 @@ #include "cmdlib.h" #include "version.h" #include "gl_interface.h" -#include "gl/system/gl_framebuffer.h" +#include "gl_framebuffer.h" #include "hw_cvars.h" #include "gl_debug.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_renderer.h" #include "gl_renderstate.h" #include "gl_renderbuffers.h" #include "gl_shaderprogram.h" diff --git a/src/rendering/gl/renderer/gl_renderer.h b/src/common/rendering/gl/gl_renderer.h similarity index 94% rename from src/rendering/gl/renderer/gl_renderer.h rename to src/common/rendering/gl/gl_renderer.h index 4eb59d0882..5613fd5fd2 100644 --- a/src/rendering/gl/renderer/gl_renderer.h +++ b/src/common/rendering/gl/gl_renderer.h @@ -1,14 +1,10 @@ #ifndef __GL_RENDERER_H #define __GL_RENDERER_H -#include "r_defs.h" #include "v_video.h" #include "vectors.h" -#include "swrenderer/r_renderer.h" #include "matrix.h" #include "gl_renderbuffers.h" -#include "hwrenderer/scene/hw_portal.h" -#include "hw_shadowmap.h" #include #ifdef _MSC_VER @@ -83,7 +79,6 @@ public: void CopyToBackbuffer(const IntRect *bounds, bool applyGamma); void DrawPresentTexture(const IntRect &box, bool applyGamma); void Flush(); - void Draw2D(F2DDrawer *data); void BeginFrame(); bool StartOffscreen(); diff --git a/src/common/rendering/gl/gl_renderstate.cpp b/src/common/rendering/gl/gl_renderstate.cpp index ac9e470250..9eee22c66e 100644 --- a/src/common/rendering/gl/gl_renderstate.cpp +++ b/src/common/rendering/gl/gl_renderstate.cpp @@ -31,12 +31,12 @@ #include "hw_cvars.h" #include "flatvertices.h" #include "gl_shader.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_renderer.h" #include "hw_lightbuffer.h" #include "gl_renderbuffers.h" #include "gl_hwtexture.h" #include "gl_buffers.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hwrenderer/data/hw_viewpointbuffer.h" namespace OpenGLRenderer diff --git a/src/common/rendering/gl/gl_samplers.cpp b/src/common/rendering/gl/gl_samplers.cpp index 1371ec3d1c..a9f45dc2f3 100644 --- a/src/common/rendering/gl/gl_samplers.cpp +++ b/src/common/rendering/gl/gl_samplers.cpp @@ -38,7 +38,7 @@ #include "gl_interface.h" #include "hw_cvars.h" #include "gl_debug.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_renderer.h" #include "gl_samplers.h" #include "hw_material.h" #include "i_interface.h" diff --git a/src/common/rendering/gl/gl_shader.cpp b/src/common/rendering/gl/gl_shader.cpp index 4bf727efd9..c00ab09117 100644 --- a/src/common/rendering/gl/gl_shader.cpp +++ b/src/common/rendering/gl/gl_shader.cpp @@ -44,7 +44,7 @@ #include "gl_interface.h" #include "gl_debug.h" #include "matrix.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_renderer.h" #include #include diff --git a/src/rendering/gl/renderer/gl_stereo3d.cpp b/src/common/rendering/gl/gl_stereo3d.cpp similarity index 98% rename from src/rendering/gl/renderer/gl_stereo3d.cpp rename to src/common/rendering/gl/gl_stereo3d.cpp index 8bcb2768fc..032fb71ad3 100644 --- a/src/rendering/gl/renderer/gl_stereo3d.cpp +++ b/src/common/rendering/gl/gl_stereo3d.cpp @@ -26,15 +26,15 @@ */ #include "gl_system.h" -#include "gl/renderer/gl_renderer.h" +#include "gl_renderer.h" #include "gl_renderbuffers.h" #include "hw_vrmodes.h" -#include "gl/system/gl_framebuffer.h" +#include "gl_framebuffer.h" #include "gl_postprocessstate.h" -#include "gl/system/gl_framebuffer.h" +#include "gl_framebuffer.h" #include "gl_shaderprogram.h" #include "gl_buffers.h" -#include "menu/menu.h" +#include "templates.h" EXTERN_CVAR(Int, vr_mode) EXTERN_CVAR(Float, vid_saturation) @@ -43,6 +43,8 @@ EXTERN_CVAR(Float, vid_contrast) EXTERN_CVAR(Int, gl_satformula) EXTERN_CVAR(Int, gl_dither_bpc) +void UpdateVRModes(bool considerQuadBuffered = true); + namespace OpenGLRenderer { diff --git a/src/rendering/hwrenderer/utility/hw_clock.cpp b/src/common/rendering/hwrenderer/data/hw_clock.cpp similarity index 95% rename from src/rendering/hwrenderer/utility/hw_clock.cpp rename to src/common/rendering/hwrenderer/data/hw_clock.cpp index f337f6581f..ea47d0cb18 100644 --- a/src/rendering/hwrenderer/utility/hw_clock.cpp +++ b/src/common/rendering/hwrenderer/data/hw_clock.cpp @@ -38,9 +38,9 @@ #include "c_dispatch.h" #include "r_utility.h" #include "v_video.h" -#include "g_levellocals.h" #include "hw_clock.h" #include "i_time.h" +#include "i_interface.h" glcycle_t RenderWall,SetupWall,ClipWall; glcycle_t RenderFlat,SetupFlat; @@ -167,11 +167,8 @@ void CheckBench() FString compose; - auto &vp = r_viewpoint; - auto Level = vp.ViewLevel; - compose.Format("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n", - Level->MapName.GetChars(), Level->LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees); - + if (sysCallbacks && sysCallbacks->GetLocationDescription) compose = sysCallbacks->GetLocationDescription(); + AppendRenderStats(compose); AppendRenderTimes(compose); AppendLightStats(compose); diff --git a/src/rendering/hwrenderer/utility/hw_clock.h b/src/common/rendering/hwrenderer/data/hw_clock.h similarity index 100% rename from src/rendering/hwrenderer/utility/hw_clock.h rename to src/common/rendering/hwrenderer/data/hw_clock.h diff --git a/src/common/rendering/hwrenderer/data/hw_skydome.cpp b/src/common/rendering/hwrenderer/data/hw_skydome.cpp index 7e882acd07..45c813fc70 100644 --- a/src/common/rendering/hwrenderer/data/hw_skydome.cpp +++ b/src/common/rendering/hwrenderer/data/hw_skydome.cpp @@ -76,7 +76,7 @@ enum // also shamelessly lifted from ZDoomGL! ;) // //----------------------------------------------------------------------------- -EXTERN_CVAR(Float, skyoffset) +CVAR(Float, skyoffset, 0, 0) // for testing struct SkyColor diff --git a/src/common/rendering/hwrenderer/data/hw_skydome.h b/src/common/rendering/hwrenderer/data/hw_skydome.h index 527bd3fa8a..7cbd379489 100644 --- a/src/common/rendering/hwrenderer/data/hw_skydome.h +++ b/src/common/rendering/hwrenderer/data/hw_skydome.h @@ -1,6 +1,5 @@ #pragma once -#include "v_palette.h" #include "matrix.h" #include "hwrenderer/data/buffers.h" #include "hw_renderstate.h" diff --git a/src/d_main.cpp b/src/d_main.cpp index 5b9dbcd6f8..509e803208 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -114,7 +114,7 @@ #include "scriptutil.h" #include "v_palette.h" #include "texturemanager.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hwrenderer/scene/hw_drawinfo.h" #ifdef __unix__ @@ -2855,6 +2855,16 @@ IntRect System_GetSceneRect() mSceneViewport.height = height; return mSceneViewport; } + +FString System_GetLocationDescription() +{ + auto& vp = r_viewpoint; + auto Level = vp.ViewLevel; + return FStringf("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n", + Level->MapName.GetChars(), Level->LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees); + +} + //========================================================================== // // DoomSpecificInfo @@ -3063,6 +3073,7 @@ static int D_DoomMain_Internal (void) System_DisableTextureFilter, System_OnScreenSizeChanged, System_GetSceneRect, + System_GetLocationDescription, }; sysCallbacks = &syscb; diff --git a/src/playsim/p_pspr.h b/src/playsim/p_pspr.h index d39fdd2e44..a4097a9440 100644 --- a/src/playsim/p_pspr.h +++ b/src/playsim/p_pspr.h @@ -41,6 +41,7 @@ #define WEAPON_FUDGE_Y 0.375 struct FTranslatedLineTarget; struct FState; +class player_t; // // Overlay psprites are scaled shapes diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index 61ebf3c617..b7e6916058 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -37,7 +37,7 @@ #include "swrenderer/r_swscene.h" #include "swrenderer/r_renderer.h" #include "hw_dynlightdata.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "flatvertices.h" #include "v_palette.h" #include "d_main.h" diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index 5009f37ee9..a2b79eecdc 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -39,7 +39,7 @@ #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "flatvertices.h" #include "hwrenderer/data/hw_vertexbuilder.h" diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index 6dc727731e..6dae20c569 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -34,7 +34,7 @@ #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/utility/hw_lighting.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "flatvertices.h" #include "hw_renderstate.h" #include "texturemanager.h" diff --git a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp index 8365eeb342..421024947f 100644 --- a/src/rendering/hwrenderer/scene/hw_drawinfo.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawinfo.cpp @@ -36,7 +36,7 @@ #include "hw_drawinfo.h" #include "po_man.h" #include "models.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hw_cvars.h" #include "hw_viewpointbuffer.h" #include "flatvertices.h" diff --git a/src/rendering/hwrenderer/scene/hw_drawlist.cpp b/src/rendering/hwrenderer/scene/hw_drawlist.cpp index 18e425c9fe..902d68f294 100644 --- a/src/rendering/hwrenderer/scene/hw_drawlist.cpp +++ b/src/rendering/hwrenderer/scene/hw_drawlist.cpp @@ -33,7 +33,7 @@ #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawlist.h" #include "flatvertices.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hw_renderstate.h" #include "hw_drawinfo.h" #include "hw_fakeflat.h" diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index f051aaa4fa..dfc73b55c5 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -38,7 +38,7 @@ #include "matrix.h" #include "hw_dynlightdata.h" #include "hw_cvars.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hw_material.h" #include "hwrenderer/scene/hw_drawinfo.h" diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index 06ae4c7e3e..711e811089 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -34,7 +34,7 @@ #include "g_levellocals.h" #include "hw_renderstate.h" #include "flatvertices.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "texturemanager.h" diff --git a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp index 3835784100..d0775d109d 100644 --- a/src/rendering/hwrenderer/scene/hw_renderhacks.cpp +++ b/src/rendering/hwrenderer/scene/hw_renderhacks.cpp @@ -35,7 +35,7 @@ #include "hw_drawinfo.h" #include "hw_drawstructs.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hw_dynlightdata.h" #include "flatvertices.h" #include "hw_lightbuffer.h" diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index dbedea82cc..5ee5470ef8 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -51,7 +51,7 @@ #include "hwrenderer/scene/hw_portal.h" #include "flatvertices.h" #include "hw_cvars.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hw_material.h" #include "hw_dynlightdata.h" diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index bdc848aef3..93de62a881 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -35,7 +35,7 @@ #include "hw_dynlightdata.h" #include "hw_material.h" #include "hw_cvars.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hwrenderer/utility/hw_lighting.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/utility/hw_draw2d.cpp index 2ea531fa9b..25f330c626 100644 --- a/src/rendering/hwrenderer/utility/hw_draw2d.cpp +++ b/src/rendering/hwrenderer/utility/hw_draw2d.cpp @@ -32,7 +32,7 @@ #include "hwrenderer/data/buffers.h" #include "flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hw_cvars.h" #include "hw_renderstate.h" #include "r_videoscale.h" diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 5693c2cff9..d059db3211 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -30,7 +30,7 @@ #include "i_video.h" #include "v_draw.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hw_vrmodes.h" #include "hw_cvars.h" #include "hwrenderer/models/hw_models.h" diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index 830a344e7d..af15229523 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -30,7 +30,7 @@ #include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" #include "hw_cvars.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/shaderuniforms.h" diff --git a/src/rendering/r_sky.cpp b/src/rendering/r_sky.cpp index ef74707ce4..96cc6083a7 100644 --- a/src/rendering/r_sky.cpp +++ b/src/rendering/r_sky.cpp @@ -54,9 +54,6 @@ CUSTOM_CVAR (Int, r_skymode, 2, CVAR_ARCHIVE|CVAR_NOINITCALL) R_InitSkyMap (); } -CVAR(Float, skyoffset, 0, 0) // for testing - - //========================================================================== // // R_InitSkyMap diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index a3ae824f08..18425e29d9 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -33,7 +33,7 @@ #include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" #include "hw_cvars.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/shaderuniforms.h" diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index f7af67ea19..7eca202c75 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -33,7 +33,7 @@ #include "version.h" #include "v_draw.h" -#include "hwrenderer/utility/hw_clock.h" +#include "hw_clock.h" #include "hw_vrmodes.h" #include "hw_cvars.h" #include "hwrenderer/models/hw_models.h" From 5d10d6c44841630589686623b6934a26a0867325 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 17:36:58 +0200 Subject: [PATCH 137/220] - directory structure cleanup. The hwrenderer folder did not contain sufficient files anymore for such extensive subgrouping. --- src/CMakeLists.txt | 37 ++++++------------- src/common/rendering/gl/gl_framebuffer.cpp | 4 +- src/g_levellocals.h | 2 +- src/maploader/maploader.cpp | 2 +- .../{dynlights => }/doom_aabbtree.cpp | 0 .../{dynlights => }/doom_aabbtree.h | 0 .../hwrenderer/{utility => }/hw_draw2d.cpp | 0 .../{dynlights => }/hw_dynlightdata.cpp | 0 .../hwrenderer/{models => }/hw_models.cpp | 0 .../hwrenderer/{models => }/hw_models.h | 0 .../hw_postprocessshader.cpp | 0 .../hwrenderer/{textures => }/hw_precache.cpp | 2 +- .../{data => }/hw_vertexbuilder.cpp | 0 .../hwrenderer/{data => }/hw_vertexbuilder.h | 0 src/rendering/hwrenderer/scene/hw_bsp.cpp | 2 +- src/rendering/hwrenderer/scene/hw_decal.cpp | 2 +- src/rendering/hwrenderer/scene/hw_flats.cpp | 2 +- .../{utility => scene}/hw_lighting.cpp | 0 .../{utility => scene}/hw_lighting.h | 0 src/rendering/hwrenderer/scene/hw_portal.cpp | 2 +- .../{hw_renderstate.cpp => hw_setcolor.cpp} | 2 +- src/rendering/hwrenderer/scene/hw_sky.cpp | 2 +- src/rendering/hwrenderer/scene/hw_sprites.cpp | 4 +- src/rendering/hwrenderer/scene/hw_walls.cpp | 2 +- src/rendering/hwrenderer/scene/hw_weapon.cpp | 4 +- .../polyrenderer/backend/poly_framebuffer.cpp | 2 +- .../vulkan/system/vk_framebuffer.cpp | 2 +- 27 files changed, 29 insertions(+), 44 deletions(-) rename src/rendering/hwrenderer/{dynlights => }/doom_aabbtree.cpp (100%) rename src/rendering/hwrenderer/{dynlights => }/doom_aabbtree.h (100%) rename src/rendering/hwrenderer/{utility => }/hw_draw2d.cpp (100%) rename src/rendering/hwrenderer/{dynlights => }/hw_dynlightdata.cpp (100%) rename src/rendering/hwrenderer/{models => }/hw_models.cpp (100%) rename src/rendering/hwrenderer/{models => }/hw_models.h (100%) rename src/rendering/hwrenderer/{postprocessing => }/hw_postprocessshader.cpp (100%) rename src/rendering/hwrenderer/{textures => }/hw_precache.cpp (99%) rename src/rendering/hwrenderer/{data => }/hw_vertexbuilder.cpp (100%) rename src/rendering/hwrenderer/{data => }/hw_vertexbuilder.h (100%) rename src/rendering/hwrenderer/{utility => scene}/hw_lighting.cpp (100%) rename src/rendering/hwrenderer/{utility => scene}/hw_lighting.h (100%) rename src/rendering/hwrenderer/scene/{hw_renderstate.cpp => hw_setcolor.cpp} (99%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d6678ec690..c8b5c050aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -647,13 +647,8 @@ file( GLOB HEADER_FILES rendering/polyrenderer/math/*.h rendering/polyrenderer/drawers/*.h rendering/polyrenderer/backend/*.h - rendering/hwrenderer/data/*.h - rendering/hwrenderer/dynlights/*.h - rendering/hwrenderer/models/*.h - rendering/hwrenderer/postprocessing/*.h + rendering/hwrenderer/*.h rendering/hwrenderer/scene/*.h - rendering/hwrenderer/textures/*.h - rendering/hwrenderer/utility/*.h rendering/vulkan/*.h rendering/vulkan/system/*.h rendering/vulkan/renderer/*.h @@ -763,7 +758,7 @@ set( FASTMATH_SOURCES common/textures/hires/xbr/xbrz.cpp common/textures/hires/xbr/xbrz_old.cpp common/rendering/gl_load/gl_load.c - rendering/hwrenderer/dynlights/hw_dynlightdata.cpp + rendering/hwrenderer/hw_dynlightdata.cpp rendering/hwrenderer/scene/hw_bsp.cpp rendering/hwrenderer/scene/hw_fakeflat.cpp rendering/hwrenderer/scene/hw_decal.cpp @@ -783,7 +778,7 @@ set( FASTMATH_SOURCES common/utility/matrix.cpp ) -#Vulkan stuff must go into a separate list later because it needs to be disabled for some platforms +#Vulkan stuff must go into a separate list because it needs to be disabled for some platforms set (VULKAN_SOURCES rendering/vulkan/system/vk_device.cpp rendering/vulkan/system/vk_swapchain.cpp @@ -933,15 +928,15 @@ set (PCH_SOURCES rendering/2d/f_wipe.cpp rendering/2d/v_blend.cpp rendering/hwrenderer/hw_entrypoint.cpp - rendering/hwrenderer/data/hw_vertexbuilder.cpp - rendering/hwrenderer/dynlights/doom_aabbtree.cpp - rendering/hwrenderer/models/hw_models.cpp + rendering/hwrenderer/hw_vertexbuilder.cpp + rendering/hwrenderer/doom_aabbtree.cpp + rendering/hwrenderer/hw_models.cpp + rendering/hwrenderer/hw_postprocessshader.cpp + rendering/hwrenderer/hw_precache.cpp + rendering/hwrenderer/hw_draw2d.cpp + rendering/hwrenderer/scene/hw_lighting.cpp rendering/hwrenderer/scene/hw_drawlistadd.cpp - rendering/hwrenderer/scene/hw_renderstate.cpp - rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp - rendering/hwrenderer/textures/hw_precache.cpp - rendering/hwrenderer/utility/hw_draw2d.cpp - rendering/hwrenderer/utility/hw_lighting.cpp + rendering/hwrenderer/scene/hw_setcolor.cpp maploader/edata.cpp maploader/specials.cpp maploader/maploader.cpp @@ -1273,6 +1268,7 @@ include_directories( . gamedata/textures gamedata/fonts rendering + rendering/hwrenderer rendering/2d r_data sound @@ -1400,16 +1396,7 @@ source_group("Playsim\\Map Thinkers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE source_group("Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/.+") source_group("Rendering\\2D" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/2d/.+") source_group("Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/gl/.+") -source_group("Rendering\\Hardware Renderer\\Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/data/.+") -source_group("Rendering\\Hardware Renderer\\Dynamic Lights" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/dynlights/.+") -source_group("Rendering\\Hardware Renderer\\Models" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/models/.+") -source_group("Rendering\\Hardware Renderer\\Postprocessing" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/postprocessing/.+") -source_group("Rendering\\Hardware Renderer\\Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/renderer/.+") source_group("Rendering\\Hardware Renderer\\Scene" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/scene/.+") -source_group("Rendering\\Hardware Renderer\\Shaders" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/shaders/.+") -source_group("Rendering\\Hardware Renderer\\System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/system/.+") -source_group("Rendering\\Hardware Renderer\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/textures/.+") -source_group("Rendering\\Hardware Renderer\\Utilities" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/utility/.+") source_group("Rendering\\Vulkan Renderer\\System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/system/.+") source_group("Rendering\\Vulkan Renderer\\Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/renderer/.+") source_group("Rendering\\Vulkan Renderer\\Shaders" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/shaders/.+") diff --git a/src/common/rendering/gl/gl_framebuffer.cpp b/src/common/rendering/gl/gl_framebuffer.cpp index 26d1cc58c1..5487db3bc2 100644 --- a/src/common/rendering/gl/gl_framebuffer.cpp +++ b/src/common/rendering/gl/gl_framebuffer.cpp @@ -46,10 +46,8 @@ #include "gl_samplers.h" #include "hw_clock.h" #include "hw_vrmodes.h" -#include "hwrenderer/models/hw_models.h" #include "hw_skydome.h" -#include "hwrenderer/scene/hw_fakeflat.h" -#include "hwrenderer/data/hw_viewpointbuffer.h" +#include "hw_viewpointbuffer.h" #include "hw_lightbuffer.h" #include "gl_shaderprogram.h" #include "gl_debug.h" diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 576cdd6060..40dc85c203 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -54,7 +54,7 @@ #include "r_data/r_sections.h" #include "r_data/r_canvastexture.h" #include "r_data/r_interpolate.h" -#include "hwrenderer/dynlights/doom_aabbtree.h" +#include "doom_aabbtree.h" //============================================================================ // diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index bf560e1ac9..2342455569 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -81,7 +81,7 @@ #include "xlat/xlat.h" #include "vm.h" #include "texturemanager.h" -#include "hwrenderer/data/hw_vertexbuilder.h" +#include "hw_vertexbuilder.h" enum { diff --git a/src/rendering/hwrenderer/dynlights/doom_aabbtree.cpp b/src/rendering/hwrenderer/doom_aabbtree.cpp similarity index 100% rename from src/rendering/hwrenderer/dynlights/doom_aabbtree.cpp rename to src/rendering/hwrenderer/doom_aabbtree.cpp diff --git a/src/rendering/hwrenderer/dynlights/doom_aabbtree.h b/src/rendering/hwrenderer/doom_aabbtree.h similarity index 100% rename from src/rendering/hwrenderer/dynlights/doom_aabbtree.h rename to src/rendering/hwrenderer/doom_aabbtree.h diff --git a/src/rendering/hwrenderer/utility/hw_draw2d.cpp b/src/rendering/hwrenderer/hw_draw2d.cpp similarity index 100% rename from src/rendering/hwrenderer/utility/hw_draw2d.cpp rename to src/rendering/hwrenderer/hw_draw2d.cpp diff --git a/src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp b/src/rendering/hwrenderer/hw_dynlightdata.cpp similarity index 100% rename from src/rendering/hwrenderer/dynlights/hw_dynlightdata.cpp rename to src/rendering/hwrenderer/hw_dynlightdata.cpp diff --git a/src/rendering/hwrenderer/models/hw_models.cpp b/src/rendering/hwrenderer/hw_models.cpp similarity index 100% rename from src/rendering/hwrenderer/models/hw_models.cpp rename to src/rendering/hwrenderer/hw_models.cpp diff --git a/src/rendering/hwrenderer/models/hw_models.h b/src/rendering/hwrenderer/hw_models.h similarity index 100% rename from src/rendering/hwrenderer/models/hw_models.h rename to src/rendering/hwrenderer/hw_models.h diff --git a/src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp b/src/rendering/hwrenderer/hw_postprocessshader.cpp similarity index 100% rename from src/rendering/hwrenderer/postprocessing/hw_postprocessshader.cpp rename to src/rendering/hwrenderer/hw_postprocessshader.cpp diff --git a/src/rendering/hwrenderer/textures/hw_precache.cpp b/src/rendering/hwrenderer/hw_precache.cpp similarity index 99% rename from src/rendering/hwrenderer/textures/hw_precache.cpp rename to src/rendering/hwrenderer/hw_precache.cpp index 1260ae77b5..ca5f37f727 100644 --- a/src/rendering/hwrenderer/textures/hw_precache.cpp +++ b/src/rendering/hwrenderer/hw_precache.cpp @@ -38,7 +38,7 @@ #include "v_font.h" #include "texturemanager.h" #include "modelrenderer.h" -#include "hwrenderer/models/hw_models.h" +#include "hw_models.h" #include "d_main.h" EXTERN_CVAR(Bool, gl_precache) diff --git a/src/rendering/hwrenderer/data/hw_vertexbuilder.cpp b/src/rendering/hwrenderer/hw_vertexbuilder.cpp similarity index 100% rename from src/rendering/hwrenderer/data/hw_vertexbuilder.cpp rename to src/rendering/hwrenderer/hw_vertexbuilder.cpp diff --git a/src/rendering/hwrenderer/data/hw_vertexbuilder.h b/src/rendering/hwrenderer/hw_vertexbuilder.h similarity index 100% rename from src/rendering/hwrenderer/data/hw_vertexbuilder.h rename to src/rendering/hwrenderer/hw_vertexbuilder.h diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index a2b79eecdc..7006e0592f 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -41,7 +41,7 @@ #include "hwrenderer/scene/hw_portal.h" #include "hw_clock.h" #include "flatvertices.h" -#include "hwrenderer/data/hw_vertexbuilder.h" +#include "hw_vertexbuilder.h" #ifdef ARCH_IA32 #include diff --git a/src/rendering/hwrenderer/scene/hw_decal.cpp b/src/rendering/hwrenderer/scene/hw_decal.cpp index 6dae20c569..88c78ceda5 100644 --- a/src/rendering/hwrenderer/scene/hw_decal.cpp +++ b/src/rendering/hwrenderer/scene/hw_decal.cpp @@ -33,7 +33,7 @@ #include "hw_cvars.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" -#include "hwrenderer/utility/hw_lighting.h" +#include "hw_lighting.h" #include "hw_clock.h" #include "flatvertices.h" #include "hw_renderstate.h" diff --git a/src/rendering/hwrenderer/scene/hw_flats.cpp b/src/rendering/hwrenderer/scene/hw_flats.cpp index dfc73b55c5..77ad936494 100644 --- a/src/rendering/hwrenderer/scene/hw_flats.cpp +++ b/src/rendering/hwrenderer/scene/hw_flats.cpp @@ -39,7 +39,7 @@ #include "hw_dynlightdata.h" #include "hw_cvars.h" #include "hw_clock.h" -#include "hwrenderer/utility/hw_lighting.h" +#include "hw_lighting.h" #include "hw_material.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "flatvertices.h" diff --git a/src/rendering/hwrenderer/utility/hw_lighting.cpp b/src/rendering/hwrenderer/scene/hw_lighting.cpp similarity index 100% rename from src/rendering/hwrenderer/utility/hw_lighting.cpp rename to src/rendering/hwrenderer/scene/hw_lighting.cpp diff --git a/src/rendering/hwrenderer/utility/hw_lighting.h b/src/rendering/hwrenderer/scene/hw_lighting.h similarity index 100% rename from src/rendering/hwrenderer/utility/hw_lighting.h rename to src/rendering/hwrenderer/scene/hw_lighting.h diff --git a/src/rendering/hwrenderer/scene/hw_portal.cpp b/src/rendering/hwrenderer/scene/hw_portal.cpp index 711e811089..76e49d6d61 100644 --- a/src/rendering/hwrenderer/scene/hw_portal.cpp +++ b/src/rendering/hwrenderer/scene/hw_portal.cpp @@ -35,7 +35,7 @@ #include "hw_renderstate.h" #include "flatvertices.h" #include "hw_clock.h" -#include "hwrenderer/utility/hw_lighting.h" +#include "hw_lighting.h" #include "texturemanager.h" EXTERN_CVAR(Int, r_mirror_recursions) diff --git a/src/rendering/hwrenderer/scene/hw_renderstate.cpp b/src/rendering/hwrenderer/scene/hw_setcolor.cpp similarity index 99% rename from src/rendering/hwrenderer/scene/hw_renderstate.cpp rename to src/rendering/hwrenderer/scene/hw_setcolor.cpp index b0d892b615..a81db3a1c6 100644 --- a/src/rendering/hwrenderer/scene/hw_renderstate.cpp +++ b/src/rendering/hwrenderer/scene/hw_setcolor.cpp @@ -29,7 +29,7 @@ #include "hw_renderstate.h" #include "hw_drawstructs.h" #include "hw_portal.h" -#include "hwrenderer/utility/hw_lighting.h" +#include "hw_lighting.h" #include "hw_cvars.h" diff --git a/src/rendering/hwrenderer/scene/hw_sky.cpp b/src/rendering/hwrenderer/scene/hw_sky.cpp index 5a0c4f139d..5e4fc02ef8 100644 --- a/src/rendering/hwrenderer/scene/hw_sky.cpp +++ b/src/rendering/hwrenderer/scene/hw_sky.cpp @@ -31,7 +31,7 @@ #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_portal.h" -#include "hwrenderer/utility/hw_lighting.h" +#include "hw_lighting.h" #include "hw_material.h" CVAR(Bool,gl_noskyboxes, false, 0) diff --git a/src/rendering/hwrenderer/scene/hw_sprites.cpp b/src/rendering/hwrenderer/scene/hw_sprites.cpp index 5ee5470ef8..3e77ea06db 100644 --- a/src/rendering/hwrenderer/scene/hw_sprites.cpp +++ b/src/rendering/hwrenderer/scene/hw_sprites.cpp @@ -44,7 +44,7 @@ #include "texturemanager.h" #include "basics.h" -#include "hwrenderer/models/hw_models.h" +#include "hw_models.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_fakeflat.h" @@ -52,7 +52,7 @@ #include "flatvertices.h" #include "hw_cvars.h" #include "hw_clock.h" -#include "hwrenderer/utility/hw_lighting.h" +#include "hw_lighting.h" #include "hw_material.h" #include "hw_dynlightdata.h" #include "hw_lightbuffer.h" diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 93de62a881..4a2d0ab927 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -36,7 +36,7 @@ #include "hw_material.h" #include "hw_cvars.h" #include "hw_clock.h" -#include "hwrenderer/utility/hw_lighting.h" +#include "hw_lighting.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" #include "hwrenderer/scene/hw_portal.h" diff --git a/src/rendering/hwrenderer/scene/hw_weapon.cpp b/src/rendering/hwrenderer/scene/hw_weapon.cpp index 49e4728a4f..99702923bf 100644 --- a/src/rendering/hwrenderer/scene/hw_weapon.cpp +++ b/src/rendering/hwrenderer/scene/hw_weapon.cpp @@ -36,10 +36,10 @@ #include "hw_fakeflat.h" #include "texturemanager.h" -#include "hwrenderer/models/hw_models.h" +#include "hw_models.h" #include "hw_dynlightdata.h" #include "hw_material.h" -#include "hwrenderer/utility/hw_lighting.h" +#include "hw_lighting.h" #include "hw_cvars.h" #include "hwrenderer/scene/hw_drawinfo.h" #include "hwrenderer/scene/hw_drawstructs.h" diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index d059db3211..4d41fb0da4 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -33,7 +33,7 @@ #include "hw_clock.h" #include "hw_vrmodes.h" #include "hw_cvars.h" -#include "hwrenderer/models/hw_models.h" +#include "hw_models.h" #include "hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_drawinfo.h" diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 7eca202c75..b7117175f1 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -36,7 +36,7 @@ #include "hw_clock.h" #include "hw_vrmodes.h" #include "hw_cvars.h" -#include "hwrenderer/models/hw_models.h" +#include "hw_models.h" #include "hw_skydome.h" #include "hwrenderer/scene/hw_fakeflat.h" #include "hwrenderer/scene/hw_drawinfo.h" From 808a7d28cfb0ccfa4f190d5a3a52a582b9ebec4f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 17:44:43 +0200 Subject: [PATCH 138/220] - moved benchmark fps output to the custom part of it because it depends on game data. --- src/common/rendering/gl/gl_framebuffer.cpp | 2 +- src/common/rendering/hwrenderer/data/hw_clock.cpp | 6 ++---- src/d_main.cpp | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/common/rendering/gl/gl_framebuffer.cpp b/src/common/rendering/gl/gl_framebuffer.cpp index 5487db3bc2..96d8170b6e 100644 --- a/src/common/rendering/gl/gl_framebuffer.cpp +++ b/src/common/rendering/gl/gl_framebuffer.cpp @@ -53,9 +53,9 @@ #include "gl_debug.h" #include "r_videoscale.h" #include "gl_buffers.h" -#include "swrenderer/r_swscene.h" #include "gl_postprocessstate.h" #include "v_draw.h" +#include "printf.h" #include "flatvertices.h" #include "hw_cvars.h" diff --git a/src/common/rendering/hwrenderer/data/hw_clock.cpp b/src/common/rendering/hwrenderer/data/hw_clock.cpp index ea47d0cb18..84576875bb 100644 --- a/src/common/rendering/hwrenderer/data/hw_clock.cpp +++ b/src/common/rendering/hwrenderer/data/hw_clock.cpp @@ -33,14 +33,13 @@ */ -#include "g_level.h" #include "c_console.h" #include "c_dispatch.h" -#include "r_utility.h" #include "v_video.h" #include "hw_clock.h" #include "i_time.h" #include "i_interface.h" +#include "printf.h" glcycle_t RenderWall,SetupWall,ClipWall; glcycle_t RenderFlat,SetupFlat; @@ -172,8 +171,7 @@ void CheckBench() AppendRenderStats(compose); AppendRenderTimes(compose); AppendLightStats(compose); - //AppendMissingTextureStats(compose); - compose.AppendFormat("%llu fps\n\n", (unsigned long long)LastCount); + compose << "\n\n\n"; FILE *f = fopen("benchmarks.txt", "at"); if (f != NULL) diff --git a/src/d_main.cpp b/src/d_main.cpp index 509e803208..e86b83c38c 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2860,8 +2860,8 @@ FString System_GetLocationDescription() { auto& vp = r_viewpoint; auto Level = vp.ViewLevel; - return FStringf("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n", - Level->MapName.GetChars(), Level->LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees); + return FStringf("Map %s: \"%s\",\nx = %1.4f, y = %1.4f, z = %1.4f, angle = %1.4f, pitch = %1.4f\n%llu fps\n\n", + Level->MapName.GetChars(), Level->LevelName.GetChars(), vp.Pos.X, vp.Pos.Y, vp.Pos.Z, vp.Angles.Yaw.Degrees, vp.Angles.Pitch.Degrees, (unsigned long long)LastCount); } From e3fdf2194e2851378d552474a776a209fc5a0e88 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 17:51:04 +0200 Subject: [PATCH 139/220] - moved a few leftover utility classes to 'common'. --- src/CMakeLists.txt | 4 ++-- src/{r_data => common/engine}/cycler.cpp | 0 src/{r_data => common/engine}/cycler.h | 0 src/{utility => common/textures}/v_collection.cpp | 0 src/{utility => common/textures}/v_collection.h | 4 ++-- src/{ => common}/utility/weightedlist.h | 3 +-- src/events.h | 3 +++ src/playsim/a_dynlight.h | 2 +- 8 files changed, 9 insertions(+), 7 deletions(-) rename src/{r_data => common/engine}/cycler.cpp (100%) rename src/{r_data => common/engine}/cycler.h (100%) rename src/{utility => common/textures}/v_collection.cpp (100%) rename src/{utility => common/textures}/v_collection.h (98%) rename src/{ => common}/utility/weightedlist.h (99%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c8b5c050aa..8eb804f788 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -975,7 +975,6 @@ set (PCH_SOURCES intermission/intermission.cpp intermission/intermission_parse.cpp r_data/colormaps.cpp - r_data/cycler.cpp r_data/gldefs.cpp r_data/a_dynlightdata.cpp r_data/r_translate.cpp @@ -1035,6 +1034,7 @@ set (PCH_SOURCES common/textures/multipatchtexturebuilder.cpp common/textures/skyboxtexture.cpp common/textures/animtexture.cpp + common/textures/v_collection.cpp common/textures/formats/automaptexture.cpp common/textures/formats/brightmaptexture.cpp common/textures/formats/buildtexture.cpp @@ -1099,6 +1099,7 @@ set (PCH_SOURCES common/filesystem/file_whres.cpp common/filesystem/file_directory.cpp common/filesystem/resourcefile.cpp + common/engine/cycler.cpp common/engine/stats.cpp common/engine/sc_man.cpp common/engine/palettecontainer.cpp @@ -1164,7 +1165,6 @@ set (PCH_SOURCES utility/nodebuilder/nodebuild_extract.cpp utility/nodebuilder/nodebuild_gl.cpp utility/nodebuilder/nodebuild_utility.cpp - utility/v_collection.cpp ) if( ${HAVE_VM_JIT} ) diff --git a/src/r_data/cycler.cpp b/src/common/engine/cycler.cpp similarity index 100% rename from src/r_data/cycler.cpp rename to src/common/engine/cycler.cpp diff --git a/src/r_data/cycler.h b/src/common/engine/cycler.h similarity index 100% rename from src/r_data/cycler.h rename to src/common/engine/cycler.h diff --git a/src/utility/v_collection.cpp b/src/common/textures/v_collection.cpp similarity index 100% rename from src/utility/v_collection.cpp rename to src/common/textures/v_collection.cpp diff --git a/src/utility/v_collection.h b/src/common/textures/v_collection.h similarity index 98% rename from src/utility/v_collection.h rename to src/common/textures/v_collection.h index f5df863bf4..8574e58027 100644 --- a/src/utility/v_collection.h +++ b/src/common/textures/v_collection.h @@ -34,8 +34,8 @@ #ifndef __V_COLLECTION_H__ #define __V_COLLECTION_H__ -#include "doomtype.h" -#include "r_defs.h" +#include "tarray.h" +#include "textureid.h" class FGameTexture; diff --git a/src/utility/weightedlist.h b/src/common/utility/weightedlist.h similarity index 99% rename from src/utility/weightedlist.h rename to src/common/utility/weightedlist.h index 4582f6e0f7..cd6a4ba0ed 100644 --- a/src/utility/weightedlist.h +++ b/src/common/utility/weightedlist.h @@ -33,8 +33,7 @@ */ #include - -#include "doomtype.h" +#include class FRandom; diff --git a/src/events.h b/src/events.h index 52bf9ac217..c0ecb047b8 100755 --- a/src/events.h +++ b/src/events.h @@ -8,6 +8,9 @@ class DStaticEventHandler; struct EventManager; +struct line_t; +struct sector_t; +struct FLevelLocals; enum class EventHandlerType { diff --git a/src/playsim/a_dynlight.h b/src/playsim/a_dynlight.h index 38f9019bd9..d5be0438ae 100644 --- a/src/playsim/a_dynlight.h +++ b/src/playsim/a_dynlight.h @@ -1,7 +1,7 @@ #pragma once #include "c_cvars.h" #include "actor.h" -#include "r_data/cycler.h" +#include "cycler.h" #include "g_levellocals.h" struct side_t; From 8cce6207c719b3135083882524be9cf5e41a9969 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 18:15:56 +0200 Subject: [PATCH 140/220] - sanitized includes in a few files. --- .../polyrenderer/backend/poly_framebuffer.cpp | 12 ------------ .../polyrenderer/backend/poly_hwtexture.cpp | 1 - .../polyrenderer/backend/poly_renderstate.cpp | 3 --- src/rendering/swrenderer/r_memory.cpp | 16 ---------------- 4 files changed, 32 deletions(-) diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index 4d41fb0da4..bc02d501aa 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -25,7 +25,6 @@ #include "templates.h" #include "r_videoscale.h" #include "i_time.h" -#include "g_game.h" #include "v_text.h" #include "i_video.h" #include "v_draw.h" @@ -33,19 +32,13 @@ #include "hw_clock.h" #include "hw_vrmodes.h" #include "hw_cvars.h" -#include "hw_models.h" #include "hw_skydome.h" -#include "hwrenderer/scene/hw_fakeflat.h" -#include "hwrenderer/scene/hw_drawinfo.h" -#include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "flatvertices.h" #include "hwrenderer/data/shaderuniforms.h" #include "hw_lightbuffer.h" #include "hwrenderer/postprocessing/hw_postprocess.h" -#include "swrenderer/r_swscene.h" - #include "poly_framebuffer.h" #include "poly_buffers.h" #include "poly_renderstate.h" @@ -54,11 +47,6 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state); -EXTERN_CVAR(Bool, r_drawvoxels) -EXTERN_CVAR(Int, gl_tonemap) -EXTERN_CVAR(Int, screenblocks) -EXTERN_CVAR(Bool, cl_capfps) - extern int rendered_commandbuffers; extern int current_rendered_commandbuffers; diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp index 2971665142..0e56303fe7 100644 --- a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp +++ b/src/rendering/polyrenderer/backend/poly_hwtexture.cpp @@ -22,7 +22,6 @@ #include "templates.h" #include "c_cvars.h" -#include "r_data/colormaps.h" #include "hw_material.h" #include "hw_cvars.h" #include "hw_renderstate.h" diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/rendering/polyrenderer/backend/poly_renderstate.cpp index af15229523..6c22b99b02 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.cpp +++ b/src/rendering/polyrenderer/backend/poly_renderstate.cpp @@ -24,8 +24,6 @@ #include "polyrenderer/backend/poly_framebuffer.h" #include "polyrenderer/backend/poly_hwtexture.h" #include "templates.h" -#include "doomstat.h" -#include "r_data/colormaps.h" #include "hw_skydome.h" #include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" @@ -34,7 +32,6 @@ #include "flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "hwrenderer/data/shaderuniforms.h" -#include "swrenderer/r_swcolormaps.h" static PolyDrawMode dtToDrawMode[] = { diff --git a/src/rendering/swrenderer/r_memory.cpp b/src/rendering/swrenderer/r_memory.cpp index 4177e56211..0a29a5314b 100644 --- a/src/rendering/swrenderer/r_memory.cpp +++ b/src/rendering/swrenderer/r_memory.cpp @@ -20,22 +20,6 @@ #include #include "templates.h" -#include "doomdef.h" -#include "m_bbox.h" - -#include "p_lnspec.h" -#include "p_setup.h" -#include "swrenderer/drawers/r_draw.h" -#include "swrenderer/plane/r_visibleplane.h" -#include "a_sharedglobal.h" -#include "g_level.h" -#include "p_effect.h" -#include "doomstat.h" -#include "r_state.h" -#include "v_palette.h" -#include "r_sky.h" -#include "po_man.h" -#include "r_data/colormaps.h" #include "r_memory.h" #include From 68630d67823e44b0eb2236fa2d5227f4b1f77b6c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 18:48:15 +0200 Subject: [PATCH 141/220] - sanitized dependencies of the softpoly render backend. This included half the game state and lots of unneeded parts of the software renderer. The two modules that are shared between softpoly and the classic software renderer have been moved to a neutral place. --- src/CMakeLists.txt | 3 +- src/common/platform/posix/i_system_posix.cpp | 51 +++++++++++-------- .../drawers => common/rendering}/r_thread.h | 4 +- src/common/utility/basics.h | 3 ++ src/common/utility/m_bbox.cpp | 47 ----------------- src/common/utility/m_bbox.h | 38 +++++--------- .../utility}/r_memory.cpp | 40 ++++++++------- .../swrenderer => common/utility}/r_memory.h | 0 src/gamedata/r_defs.h | 3 -- .../polyrenderer/backend/poly_framebuffer.cpp | 3 ++ .../polyrenderer/backend/poly_framebuffer.h | 4 +- .../polyrenderer/backend/poly_renderstate.h | 1 - .../polyrenderer/drawers/poly_thread.cpp | 13 ++--- .../polyrenderer/drawers/poly_triangle.cpp | 9 ---- .../polyrenderer/drawers/poly_triangle.h | 4 +- .../polyrenderer/drawers/screen_blend.cpp | 4 ++ .../drawers/screen_scanline_setup.cpp | 5 +- .../polyrenderer/drawers/screen_shader.cpp | 1 - .../polyrenderer/drawers/screen_triangle.cpp | 9 ---- .../polyrenderer/drawers/screen_triangle.h | 2 +- src/rendering/swrenderer/drawers/r_thread.cpp | 2 +- .../swrenderer/line/r_farclip_line.cpp | 2 +- .../swrenderer/line/r_fogboundary.cpp | 2 +- src/rendering/swrenderer/line/r_line.cpp | 2 +- .../swrenderer/line/r_renderdrawsegment.cpp | 2 +- src/rendering/swrenderer/line/r_walldraw.cpp | 2 +- src/rendering/swrenderer/line/r_wallsetup.cpp | 2 +- .../swrenderer/plane/r_flatplane.cpp | 2 +- src/rendering/swrenderer/plane/r_skyplane.cpp | 2 +- .../swrenderer/plane/r_slopeplane.cpp | 2 +- .../swrenderer/plane/r_visibleplane.cpp | 2 +- .../swrenderer/plane/r_visibleplane.h | 2 +- .../swrenderer/plane/r_visibleplanelist.cpp | 2 +- src/rendering/swrenderer/r_all.cpp | 1 - src/rendering/swrenderer/r_renderthread.cpp | 2 +- src/rendering/swrenderer/scene/r_3dfloors.cpp | 2 +- src/rendering/swrenderer/scene/r_portal.cpp | 2 +- src/rendering/swrenderer/scene/r_scene.cpp | 4 +- .../swrenderer/scene/r_translucent_pass.cpp | 2 +- .../swrenderer/segments/r_drawsegment.cpp | 2 +- .../swrenderer/segments/r_portalsegment.cpp | 2 +- src/rendering/swrenderer/things/r_decal.cpp | 2 +- src/rendering/swrenderer/things/r_model.cpp | 2 +- .../swrenderer/things/r_particle.cpp | 2 +- .../swrenderer/things/r_playersprite.cpp | 2 +- src/rendering/swrenderer/things/r_sprite.cpp | 2 +- .../swrenderer/things/r_visiblesprite.cpp | 2 +- .../swrenderer/things/r_visiblespritelist.cpp | 2 +- src/rendering/swrenderer/things/r_voxel.cpp | 4 +- .../swrenderer/things/r_wallsprite.cpp | 2 +- 50 files changed, 121 insertions(+), 186 deletions(-) rename src/{rendering/swrenderer/drawers => common/rendering}/r_thread.h (98%) delete mode 100644 src/common/utility/m_bbox.cpp rename src/{rendering/swrenderer => common/utility}/r_memory.cpp (62%) rename src/{rendering/swrenderer => common/utility}/r_memory.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8eb804f788..02228a1182 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -660,7 +660,6 @@ file( GLOB HEADER_FILES set ( SWRENDER_SOURCES rendering/swrenderer/r_swcolormaps.cpp rendering/swrenderer/r_swrenderer.cpp - rendering/swrenderer/r_memory.cpp rendering/swrenderer/r_renderthread.cpp rendering/swrenderer/drawers/r_draw.cpp rendering/swrenderer/drawers/r_draw_pal.cpp @@ -1084,7 +1083,7 @@ set (PCH_SOURCES common/utility/s_playlist.cpp common/utility/zstrformat.cpp common/utility/name.cpp - common/utility/m_bbox.cpp + common/utility/r_memory.cpp common/thirdparty/md5.cpp common/thirdparty/superfasthash.cpp common/filesystem/filesystem.cpp diff --git a/src/common/platform/posix/i_system_posix.cpp b/src/common/platform/posix/i_system_posix.cpp index cef139be45..46be3f0526 100644 --- a/src/common/platform/posix/i_system_posix.cpp +++ b/src/common/platform/posix/i_system_posix.cpp @@ -1,24 +1,33 @@ -//----------------------------------------------------------------------------- -// -// Copyright 1993-1996 id Software -// Copyright 1999-2016 Randy Heit -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//----------------------------------------------------------------------------- -// - +/* +**--------------------------------------------------------------------------- +** Copyright 2016 Randy Heit +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ #include #ifdef __APPLE__ diff --git a/src/rendering/swrenderer/drawers/r_thread.h b/src/common/rendering/r_thread.h similarity index 98% rename from src/rendering/swrenderer/drawers/r_thread.h rename to src/common/rendering/r_thread.h index 0d45b2caca..87319cf0cd 100644 --- a/src/rendering/swrenderer/drawers/r_thread.h +++ b/src/common/rendering/r_thread.h @@ -22,12 +22,14 @@ #pragma once -#include "r_draw.h" #include #include #include #include #include +#include "templates.h" +#include "c_cvars.h" +#include "basics.h" // Use multiple threads when drawing EXTERN_CVAR(Int, r_multithreaded) diff --git a/src/common/utility/basics.h b/src/common/utility/basics.h index 503d3ea7ba..615789b58c 100644 --- a/src/common/utility/basics.h +++ b/src/common/utility/basics.h @@ -3,6 +3,9 @@ #include #include +#define MAXWIDTH 12000 +#define MAXHEIGHT 5000 + // // fixed point, 32bit as 16.16. // diff --git a/src/common/utility/m_bbox.cpp b/src/common/utility/m_bbox.cpp deleted file mode 100644 index d62c4ec5fe..0000000000 --- a/src/common/utility/m_bbox.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Copyright 1993-1996 id Software -// Copyright 1999-2016 Randy Heit -// Copyright 2002-2016 Christoph Oelckers -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//----------------------------------------------------------------------------- -// -// DESCRIPTION: -// bounding box class -// -//----------------------------------------------------------------------------- - -#include "m_bbox.h" - -//========================================================================== -// -// -// -//========================================================================== - -void FBoundingBox::AddToBox (const DVector2 &pos) -{ - if (pos.X < m_Box[BOXLEFT]) - m_Box[BOXLEFT] = pos.X; - if (pos.X > m_Box[BOXRIGHT]) - m_Box[BOXRIGHT] = pos.X; - - if (pos.Y < m_Box[BOXBOTTOM]) - m_Box[BOXBOTTOM] = pos.Y; - if (pos.Y > m_Box[BOXTOP]) - m_Box[BOXTOP] = pos.Y; -} - diff --git a/src/common/utility/m_bbox.h b/src/common/utility/m_bbox.h index 0286ef2307..f117c290b9 100644 --- a/src/common/utility/m_bbox.h +++ b/src/common/utility/m_bbox.h @@ -1,28 +1,3 @@ -//----------------------------------------------------------------------------- -// -// Copyright 1993-1996 id Software -// Copyright 1999-2016 Randy Heit -// Copyright 2002-2016 Christoph Oelckers -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//----------------------------------------------------------------------------- -// -// DESCRIPTION: -// Nil. -// -//----------------------------------------------------------------------------- #ifndef __M_BBOX_H__ #define __M_BBOX_H__ @@ -84,7 +59,18 @@ public: m_Box[BOXTOP] > box2.m_Box[BOXTOP] ? m_Box[BOXTOP] : box2.m_Box[BOXTOP]); } - void AddToBox(const DVector2 &pos); + void AddToBox(const DVector2 &pos) + { + if (pos.X < m_Box[BOXLEFT]) + m_Box[BOXLEFT] = pos.X; + if (pos.X > m_Box[BOXRIGHT]) + m_Box[BOXRIGHT] = pos.X; + + if (pos.Y < m_Box[BOXBOTTOM]) + m_Box[BOXBOTTOM] = pos.Y; + if (pos.Y > m_Box[BOXTOP]) + m_Box[BOXTOP] = pos.Y; + } inline double Top () const { return m_Box[BOXTOP]; } inline double Bottom () const { return m_Box[BOXBOTTOM]; } diff --git a/src/rendering/swrenderer/r_memory.cpp b/src/common/utility/r_memory.cpp similarity index 62% rename from src/rendering/swrenderer/r_memory.cpp rename to src/common/utility/r_memory.cpp index 0a29a5314b..99a75d0f7a 100644 --- a/src/rendering/swrenderer/r_memory.cpp +++ b/src/common/utility/r_memory.cpp @@ -1,22 +1,24 @@ -//----------------------------------------------------------------------------- -// -// Copyright 1999-2016 Randy Heit -// Copyright 2016 Magnus Norddahl -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//----------------------------------------------------------------------------- +/* +** Render memory allocation +** Copyright (c) 2016-2020 Magnus Norddahl +** +** This software is provided 'as-is', without any express or implied +** warranty. In no event will the authors be held liable for any damages +** arising from the use of this software. +** +** Permission is granted to anyone to use this software for any purpose, +** including commercial applications, and to alter it and redistribute it +** freely, subject to the following restrictions: +** +** 1. The origin of this software must not be misrepresented; you must not +** claim that you wrote the original software. If you use this software +** in a product, an acknowledgment in the product documentation would be +** appreciated but is not required. +** 2. Altered source versions must be plainly marked as such, and must not be +** misrepresented as being the original software. +** 3. This notice may not be removed or altered from any source distribution. +** +*/ #include #include "templates.h" diff --git a/src/rendering/swrenderer/r_memory.h b/src/common/utility/r_memory.h similarity index 100% rename from src/rendering/swrenderer/r_memory.h rename to src/common/utility/r_memory.h diff --git a/src/gamedata/r_defs.h b/src/gamedata/r_defs.h index f26724dec8..a5e73a186e 100644 --- a/src/gamedata/r_defs.h +++ b/src/gamedata/r_defs.h @@ -57,9 +57,6 @@ class AActor; struct FSection; struct FLevelLocals; -#define MAXWIDTH 12000 -#define MAXHEIGHT 5000 - const uint16_t NO_INDEX = 0xffffu; const uint32_t NO_SIDE = 0xffffffffu; diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp index bc02d501aa..19ecb68711 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -28,6 +28,7 @@ #include "v_text.h" #include "i_video.h" #include "v_draw.h" +#include "colormaps.h" #include "hw_clock.h" #include "hw_vrmodes.h" @@ -404,12 +405,14 @@ void PolyFrameBuffer::BeginFrame() SetViewportRects(nullptr); CheckCanvas(); +#if 0 swrenderer::R_InitFuzzTable(GetCanvas()->GetPitch()); static int next_random = 0; swrenderer::fuzzpos = (swrenderer::fuzzpos + swrenderer::fuzz_random_x_offset[next_random] * FUZZTABLE / 100) % FUZZTABLE; next_random++; if (next_random == FUZZ_RANDOM_X_SIZE) next_random = 0; +#endif } void PolyFrameBuffer::Draw2D() diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/rendering/polyrenderer/backend/poly_framebuffer.h index 200abce3a1..8ba6592726 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/rendering/polyrenderer/backend/poly_framebuffer.h @@ -1,8 +1,8 @@ #pragma once #include "gl_sysfb.h" -#include "rendering/swrenderer/r_memory.h" -#include "rendering/swrenderer/drawers/r_thread.h" +#include "r_memory.h" +#include "r_thread.h" #include "rendering/polyrenderer/drawers/poly_triangle.h" struct FRenderViewpoint; diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.h b/src/rendering/polyrenderer/backend/poly_renderstate.h index 733578dd91..a99a9eab56 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.h +++ b/src/rendering/polyrenderer/backend/poly_renderstate.h @@ -6,7 +6,6 @@ #include "name.h" -#include "hwrenderer/scene/hw_drawstructs.h" #include "hw_renderstate.h" #include "hw_material.h" diff --git a/src/rendering/polyrenderer/drawers/poly_thread.cpp b/src/rendering/polyrenderer/drawers/poly_thread.cpp index 4b6d1a51a4..809ebca49f 100644 --- a/src/rendering/polyrenderer/drawers/poly_thread.cpp +++ b/src/rendering/polyrenderer/drawers/poly_thread.cpp @@ -22,23 +22,18 @@ #include #include "templates.h" -#include "doomdef.h" #include "filesystem.h" #include "v_video.h" -#include "doomstat.h" -#include "st_stuff.h" -#include "g_game.h" -#include "g_level.h" -#include "r_data/r_translate.h" #include "model.h" -#include "v_palette.h" -#include "r_data/colormaps.h" #include "poly_thread.h" -#include "swrenderer/drawers/r_draw_rgba.h" #include "screen_triangle.h" #include "x86.h" +#ifndef NO_SSE +#include +#endif + PolyTriangleThreadData::PolyTriangleThreadData(int32_t core, int32_t num_cores, int32_t numa_node, int32_t num_numa_nodes, int numa_start_y, int numa_end_y) : core(core), num_cores(num_cores), numa_node(numa_node), num_numa_nodes(num_numa_nodes), numa_start_y(numa_start_y), numa_end_y(numa_end_y) { diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.cpp b/src/rendering/polyrenderer/drawers/poly_triangle.cpp index 54676b9479..772c7ad7c9 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/poly_triangle.cpp @@ -22,21 +22,12 @@ #include #include "templates.h" -#include "doomdef.h" #include "filesystem.h" #include "v_video.h" -#include "doomstat.h" -#include "st_stuff.h" -#include "g_game.h" -#include "g_level.h" -#include "r_data/r_translate.h" #include "model.h" -#include "v_palette.h" -#include "r_data/colormaps.h" #include "poly_triangle.h" #include "poly_thread.h" -#include "swrenderer/drawers/r_draw_rgba.h" #include "screen_triangle.h" #include "x86.h" diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.h b/src/rendering/polyrenderer/drawers/poly_triangle.h index ffee6201e4..ded2d65cbc 100644 --- a/src/rendering/polyrenderer/drawers/poly_triangle.h +++ b/src/rendering/polyrenderer/drawers/poly_triangle.h @@ -22,8 +22,8 @@ #pragma once -#include "swrenderer/drawers/r_draw.h" -#include "swrenderer/drawers/r_thread.h" +//#include "swrenderer/drawers/r_draw.h" +#include "r_thread.h" #include "polyrenderer/drawers/screen_triangle.h" #include "polyrenderer/drawers/poly_vertex_shader.h" diff --git a/src/rendering/polyrenderer/drawers/screen_blend.cpp b/src/rendering/polyrenderer/drawers/screen_blend.cpp index a8a7d1a8d2..8f05bbdd3f 100644 --- a/src/rendering/polyrenderer/drawers/screen_blend.cpp +++ b/src/rendering/polyrenderer/drawers/screen_blend.cpp @@ -22,6 +22,10 @@ #include "screen_blend.h" +#ifndef NO_SSE +#include +#endif + static const int shiftTable[] = { 0, 0, 0, 0, // STYLEALPHA_Zero 0, 0, 0, 0, // STYLEALPHA_One diff --git a/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp b/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp index 9f1a7af529..4b4ca47e87 100644 --- a/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp +++ b/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp @@ -22,12 +22,15 @@ #include #include "templates.h" -#include "doomdef.h" #include "poly_thread.h" #include "screen_scanline_setup.h" #include "x86.h" #include +#ifndef NO_SSE +#include +#endif + #ifdef NO_SSE void WriteW(int y, int x0, int x1, const TriDrawTriangleArgs* args, PolyTriangleThreadData* thread) { diff --git a/src/rendering/polyrenderer/drawers/screen_shader.cpp b/src/rendering/polyrenderer/drawers/screen_shader.cpp index af23172a6c..c4ceb02195 100644 --- a/src/rendering/polyrenderer/drawers/screen_shader.cpp +++ b/src/rendering/polyrenderer/drawers/screen_shader.cpp @@ -22,7 +22,6 @@ #include #include "templates.h" -#include "doomdef.h" #include "poly_thread.h" #include "screen_scanline_setup.h" #include "x86.h" diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.cpp b/src/rendering/polyrenderer/drawers/screen_triangle.cpp index 45fe74b068..717f260a01 100644 --- a/src/rendering/polyrenderer/drawers/screen_triangle.cpp +++ b/src/rendering/polyrenderer/drawers/screen_triangle.cpp @@ -22,19 +22,10 @@ #include #include "templates.h" -#include "doomdef.h" #include "filesystem.h" #include "v_video.h" -#include "doomstat.h" -#include "st_stuff.h" -#include "g_game.h" -#include "g_level.h" -#include "r_data/r_translate.h" -#include "v_palette.h" -#include "r_data/colormaps.h" #include "poly_triangle.h" -#include "swrenderer/drawers/r_draw_rgba.h" #include "screen_triangle.h" #include "screen_blend.h" #include "screen_scanline_setup.h" diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.h b/src/rendering/polyrenderer/drawers/screen_triangle.h index 7ccd644008..520ab4d000 100644 --- a/src/rendering/polyrenderer/drawers/screen_triangle.h +++ b/src/rendering/polyrenderer/drawers/screen_triangle.h @@ -25,7 +25,7 @@ #include #include #include "renderstyle.h" -#include "rendering/swrenderer/drawers/r_draw.h" +//#include "rendering/swrenderer/drawers/r_draw.h" class FString; class PolyTriangleThreadData; diff --git a/src/rendering/swrenderer/drawers/r_thread.cpp b/src/rendering/swrenderer/drawers/r_thread.cpp index a12562cc7e..e5c4f698ca 100644 --- a/src/rendering/swrenderer/drawers/r_thread.cpp +++ b/src/rendering/swrenderer/drawers/r_thread.cpp @@ -31,7 +31,7 @@ #include "g_game.h" #include "g_level.h" #include "r_thread.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" #include "polyrenderer/drawers/poly_triangle.h" #include diff --git a/src/rendering/swrenderer/line/r_farclip_line.cpp b/src/rendering/swrenderer/line/r_farclip_line.cpp index 6f4b919cf6..e0f0275789 100644 --- a/src/rendering/swrenderer/line/r_farclip_line.cpp +++ b/src/rendering/swrenderer/line/r_farclip_line.cpp @@ -40,7 +40,7 @@ #include "v_palette.h" #include "r_utility.h" #include "r_data/colormaps.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/scene/r_opaque_pass.h" #include "swrenderer/scene/r_3dfloors.h" #include "swrenderer/scene/r_portal.h" diff --git a/src/rendering/swrenderer/line/r_fogboundary.cpp b/src/rendering/swrenderer/line/r_fogboundary.cpp index 03599193dc..1a6e405199 100644 --- a/src/rendering/swrenderer/line/r_fogboundary.cpp +++ b/src/rendering/swrenderer/line/r_fogboundary.cpp @@ -45,7 +45,7 @@ #include "swrenderer/segments/r_clipsegment.h" #include "swrenderer/segments/r_drawsegment.h" #include "swrenderer/line/r_fogboundary.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/scene/r_light.h" #ifdef _MSC_VER diff --git a/src/rendering/swrenderer/line/r_line.cpp b/src/rendering/swrenderer/line/r_line.cpp index d6fb813214..eaa2a80b04 100644 --- a/src/rendering/swrenderer/line/r_line.cpp +++ b/src/rendering/swrenderer/line/r_line.cpp @@ -43,7 +43,7 @@ #include "r_utility.h" #include "r_data/colormaps.h" #include "texturemanager.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/scene/r_opaque_pass.h" #include "swrenderer/scene/r_3dfloors.h" #include "swrenderer/scene/r_portal.h" diff --git a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp index 041e96b181..b4c5fa544a 100644 --- a/src/rendering/swrenderer/line/r_renderdrawsegment.cpp +++ b/src/rendering/swrenderer/line/r_renderdrawsegment.cpp @@ -39,7 +39,7 @@ #include "r_data/colormaps.h" #include "d_net.h" #include "texturemanager.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" #include "swrenderer/drawers/r_draw.h" #include "swrenderer/scene/r_3dfloors.h" diff --git a/src/rendering/swrenderer/line/r_walldraw.cpp b/src/rendering/swrenderer/line/r_walldraw.cpp index 35f3403606..61945fefb0 100644 --- a/src/rendering/swrenderer/line/r_walldraw.cpp +++ b/src/rendering/swrenderer/line/r_walldraw.cpp @@ -50,7 +50,7 @@ #include "swrenderer/line/r_walldraw.h" #include "swrenderer/line/r_wallsetup.h" #include "swrenderer/r_renderthread.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) diff --git a/src/rendering/swrenderer/line/r_wallsetup.cpp b/src/rendering/swrenderer/line/r_wallsetup.cpp index d1ccb1514a..1e70dc0af7 100644 --- a/src/rendering/swrenderer/line/r_wallsetup.cpp +++ b/src/rendering/swrenderer/line/r_wallsetup.cpp @@ -40,7 +40,7 @@ #include "v_palette.h" #include "r_data/colormaps.h" #include "r_walldraw.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/line/r_line.h" #include "swrenderer/scene/r_scene.h" #include "swrenderer/scene/r_light.h" diff --git a/src/rendering/swrenderer/plane/r_flatplane.cpp b/src/rendering/swrenderer/plane/r_flatplane.cpp index e95bf450ef..9075fe9100 100644 --- a/src/rendering/swrenderer/plane/r_flatplane.cpp +++ b/src/rendering/swrenderer/plane/r_flatplane.cpp @@ -50,7 +50,7 @@ #include "swrenderer/scene/r_light.h" #include "swrenderer/plane/r_visibleplane.h" #include "swrenderer/viewport/r_viewport.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" namespace swrenderer diff --git a/src/rendering/swrenderer/plane/r_skyplane.cpp b/src/rendering/swrenderer/plane/r_skyplane.cpp index 4d1664948e..08a263a018 100644 --- a/src/rendering/swrenderer/plane/r_skyplane.cpp +++ b/src/rendering/swrenderer/plane/r_skyplane.cpp @@ -51,7 +51,7 @@ #include "swrenderer/scene/r_scene.h" #include "swrenderer/scene/r_light.h" #include "swrenderer/viewport/r_viewport.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" #include "g_levellocals.h" diff --git a/src/rendering/swrenderer/plane/r_slopeplane.cpp b/src/rendering/swrenderer/plane/r_slopeplane.cpp index 156576d8a4..6bc8e946ca 100644 --- a/src/rendering/swrenderer/plane/r_slopeplane.cpp +++ b/src/rendering/swrenderer/plane/r_slopeplane.cpp @@ -50,7 +50,7 @@ #include "swrenderer/scene/r_light.h" #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/plane/r_visibleplane.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" #ifdef _MSC_VER diff --git a/src/rendering/swrenderer/plane/r_visibleplane.cpp b/src/rendering/swrenderer/plane/r_visibleplane.cpp index 889d2f0be0..c4b6c2b89b 100644 --- a/src/rendering/swrenderer/plane/r_visibleplane.cpp +++ b/src/rendering/swrenderer/plane/r_visibleplane.cpp @@ -38,7 +38,7 @@ #include "g_level.h" #include "a_dynlight.h" #include "texturemanager.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" #include "swrenderer/scene/r_opaque_pass.h" #include "swrenderer/scene/r_3dfloors.h" diff --git a/src/rendering/swrenderer/plane/r_visibleplane.h b/src/rendering/swrenderer/plane/r_visibleplane.h index afb493cfd4..101be05bc1 100644 --- a/src/rendering/swrenderer/plane/r_visibleplane.h +++ b/src/rendering/swrenderer/plane/r_visibleplane.h @@ -25,7 +25,7 @@ #include #include "r_defs.h" #include "r_state.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" struct FDynamicLight; struct FLightNode; diff --git a/src/rendering/swrenderer/plane/r_visibleplanelist.cpp b/src/rendering/swrenderer/plane/r_visibleplanelist.cpp index 50dc968970..a265be5d25 100644 --- a/src/rendering/swrenderer/plane/r_visibleplanelist.cpp +++ b/src/rendering/swrenderer/plane/r_visibleplanelist.cpp @@ -37,7 +37,7 @@ #include "d_net.h" #include "g_level.h" #include "a_dynlight.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/scene/r_opaque_pass.h" #include "swrenderer/scene/r_3dfloors.h" #include "swrenderer/scene/r_portal.h" diff --git a/src/rendering/swrenderer/r_all.cpp b/src/rendering/swrenderer/r_all.cpp index c1dc53734c..a15525ecde 100644 --- a/src/rendering/swrenderer/r_all.cpp +++ b/src/rendering/swrenderer/r_all.cpp @@ -1,5 +1,4 @@ #include "textures/r_swtexture.h" -#include "r_memory.cpp" #include "r_renderthread.cpp" #include "r_swrenderer.cpp" #include "r_swcolormaps.cpp" diff --git a/src/rendering/swrenderer/r_renderthread.cpp b/src/rendering/swrenderer/r_renderthread.cpp index 036e297307..f2fb7bb99d 100644 --- a/src/rendering/swrenderer/r_renderthread.cpp +++ b/src/rendering/swrenderer/r_renderthread.cpp @@ -47,7 +47,7 @@ #include "swrenderer/plane/r_visibleplanelist.h" #include "swrenderer/segments/r_drawsegment.h" #include "swrenderer/segments/r_clipsegment.h" -#include "swrenderer/drawers/r_thread.h" +#include "r_thread.h" #include "swrenderer/drawers/r_draw.h" #include "swrenderer/drawers/r_draw_rgba.h" #include "swrenderer/drawers/r_draw_pal.h" diff --git a/src/rendering/swrenderer/scene/r_3dfloors.cpp b/src/rendering/swrenderer/scene/r_3dfloors.cpp index d468c9611e..8196462f46 100644 --- a/src/rendering/swrenderer/scene/r_3dfloors.cpp +++ b/src/rendering/swrenderer/scene/r_3dfloors.cpp @@ -41,7 +41,7 @@ #include "r_3dfloors.h" #include "r_utility.h" #include "swrenderer/r_renderthread.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" CVAR(Int, r_3dfloors, true, 0); diff --git a/src/rendering/swrenderer/scene/r_portal.cpp b/src/rendering/swrenderer/scene/r_portal.cpp index a39340c4d3..f0c914671c 100644 --- a/src/rendering/swrenderer/scene/r_portal.cpp +++ b/src/rendering/swrenderer/scene/r_portal.cpp @@ -65,7 +65,7 @@ #include "swrenderer/scene/r_scene.h" #include "swrenderer/scene/r_light.h" #include "swrenderer/viewport/r_viewport.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" CVAR(Int, r_portal_recursions, 4, CVAR_ARCHIVE) diff --git a/src/rendering/swrenderer/scene/r_scene.cpp b/src/rendering/swrenderer/scene/r_scene.cpp index e987ad5092..7c6e6f6a3d 100644 --- a/src/rendering/swrenderer/scene/r_scene.cpp +++ b/src/rendering/swrenderer/scene/r_scene.cpp @@ -53,8 +53,8 @@ #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/drawers/r_draw.h" #include "swrenderer/drawers/r_draw_rgba.h" -#include "swrenderer/drawers/r_thread.h" -#include "swrenderer/r_memory.h" +#include "r_thread.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" #include "swrenderer/things/r_playersprite.h" #include diff --git a/src/rendering/swrenderer/scene/r_translucent_pass.cpp b/src/rendering/swrenderer/scene/r_translucent_pass.cpp index 347c32140f..9d83549d07 100644 --- a/src/rendering/swrenderer/scene/r_translucent_pass.cpp +++ b/src/rendering/swrenderer/scene/r_translucent_pass.cpp @@ -44,7 +44,7 @@ #include "swrenderer/plane/r_visibleplanelist.h" #include "swrenderer/line/r_renderdrawsegment.h" #include "swrenderer/viewport/r_viewport.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" EXTERN_CVAR(Int, r_drawfuzz) diff --git a/src/rendering/swrenderer/segments/r_drawsegment.cpp b/src/rendering/swrenderer/segments/r_drawsegment.cpp index f90f8db55c..fd7517d723 100644 --- a/src/rendering/swrenderer/segments/r_drawsegment.cpp +++ b/src/rendering/swrenderer/segments/r_drawsegment.cpp @@ -36,7 +36,7 @@ #include "po_man.h" #include "r_data/colormaps.h" #include "d_net.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/drawers/r_draw.h" #include "swrenderer/scene/r_3dfloors.h" #include "swrenderer/scene/r_opaque_pass.h" diff --git a/src/rendering/swrenderer/segments/r_portalsegment.cpp b/src/rendering/swrenderer/segments/r_portalsegment.cpp index 983921533d..d8aff120a0 100644 --- a/src/rendering/swrenderer/segments/r_portalsegment.cpp +++ b/src/rendering/swrenderer/segments/r_portalsegment.cpp @@ -39,7 +39,7 @@ #include "po_man.h" #include "r_data/colormaps.h" #include "swrenderer/segments/r_portalsegment.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" namespace swrenderer diff --git a/src/rendering/swrenderer/things/r_decal.cpp b/src/rendering/swrenderer/things/r_decal.cpp index fcc3055f43..df8f6fb387 100644 --- a/src/rendering/swrenderer/things/r_decal.cpp +++ b/src/rendering/swrenderer/things/r_decal.cpp @@ -51,7 +51,7 @@ #include "swrenderer/things/r_wallsprite.h" #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/viewport/r_spritedrawer.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" namespace swrenderer diff --git a/src/rendering/swrenderer/things/r_model.cpp b/src/rendering/swrenderer/things/r_model.cpp index ec7a5273cc..b2dd3ed45c 100644 --- a/src/rendering/swrenderer/things/r_model.cpp +++ b/src/rendering/swrenderer/things/r_model.cpp @@ -30,7 +30,7 @@ #include "actorinlines.h" #include "i_time.h" #include "texturemanager.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_swcolormaps.h" #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/scene/r_light.h" diff --git a/src/rendering/swrenderer/things/r_particle.cpp b/src/rendering/swrenderer/things/r_particle.cpp index 4fbc97c388..a91ddb4739 100644 --- a/src/rendering/swrenderer/things/r_particle.cpp +++ b/src/rendering/swrenderer/things/r_particle.cpp @@ -62,7 +62,7 @@ #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/drawers/r_draw_rgba.h" #include "swrenderer/drawers/r_draw_pal.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor); diff --git a/src/rendering/swrenderer/things/r_playersprite.cpp b/src/rendering/swrenderer/things/r_playersprite.cpp index 2b0825fb2f..3291de29c1 100644 --- a/src/rendering/swrenderer/things/r_playersprite.cpp +++ b/src/rendering/swrenderer/things/r_playersprite.cpp @@ -63,7 +63,7 @@ #include "swrenderer/scene/r_light.h" #include "swrenderer/things/r_sprite.h" #include "swrenderer/viewport/r_viewport.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" #include "g_levellocals.h" #include "v_draw.h" diff --git a/src/rendering/swrenderer/things/r_sprite.cpp b/src/rendering/swrenderer/things/r_sprite.cpp index 29afd0f7ea..1554379434 100644 --- a/src/rendering/swrenderer/things/r_sprite.cpp +++ b/src/rendering/swrenderer/things/r_sprite.cpp @@ -62,7 +62,7 @@ #include "swrenderer/scene/r_light.h" #include "swrenderer/things/r_sprite.h" #include "swrenderer/viewport/r_viewport.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" #include "a_dynlight.h" #include "r_data/r_vanillatrans.h" diff --git a/src/rendering/swrenderer/things/r_visiblesprite.cpp b/src/rendering/swrenderer/things/r_visiblesprite.cpp index 6a524c6e07..4102f912dd 100644 --- a/src/rendering/swrenderer/things/r_visiblesprite.cpp +++ b/src/rendering/swrenderer/things/r_visiblesprite.cpp @@ -42,7 +42,7 @@ #include "swrenderer/scene/r_portal.h" #include "swrenderer/scene/r_light.h" #include "swrenderer/viewport/r_viewport.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor); diff --git a/src/rendering/swrenderer/things/r_visiblespritelist.cpp b/src/rendering/swrenderer/things/r_visiblespritelist.cpp index 6c0f391740..99c3748ce1 100644 --- a/src/rendering/swrenderer/things/r_visiblespritelist.cpp +++ b/src/rendering/swrenderer/things/r_visiblespritelist.cpp @@ -32,7 +32,7 @@ #include "p_maputl.h" #include "swrenderer/things/r_visiblesprite.h" #include "swrenderer/things/r_visiblespritelist.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" namespace swrenderer { diff --git a/src/rendering/swrenderer/things/r_voxel.cpp b/src/rendering/swrenderer/things/r_voxel.cpp index 62e0e46559..5dfbb58844 100644 --- a/src/rendering/swrenderer/things/r_voxel.cpp +++ b/src/rendering/swrenderer/things/r_voxel.cpp @@ -44,7 +44,7 @@ #include "r_utility.h" #include "i_time.h" #include "swrenderer/drawers/r_draw.h" -#include "swrenderer/drawers/r_thread.h" +#include "r_thread.h" #include "swrenderer/things/r_visiblesprite.h" #include "swrenderer/things/r_voxel.h" #include "swrenderer/scene/r_portal.h" @@ -53,7 +53,7 @@ #include "swrenderer/scene/r_light.h" #include "swrenderer/viewport/r_viewport.h" #include "swrenderer/viewport/r_spritedrawer.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor) diff --git a/src/rendering/swrenderer/things/r_wallsprite.cpp b/src/rendering/swrenderer/things/r_wallsprite.cpp index 5fb431e36f..8ebf68dda3 100644 --- a/src/rendering/swrenderer/things/r_wallsprite.cpp +++ b/src/rendering/swrenderer/things/r_wallsprite.cpp @@ -64,7 +64,7 @@ #include "swrenderer/line/r_wallsetup.h" #include "swrenderer/line/r_walldraw.h" #include "swrenderer/viewport/r_viewport.h" -#include "swrenderer/r_memory.h" +#include "r_memory.h" #include "swrenderer/r_renderthread.h" namespace swrenderer From bc8335de3bb2d20f768df84c060437a8efb7ea96 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 18:52:08 +0200 Subject: [PATCH 142/220] - Vulkan backend dependency cleanup. --- src/rendering/vulkan/renderer/vk_renderstate.cpp | 2 -- src/rendering/vulkan/system/vk_framebuffer.cpp | 6 ------ src/rendering/vulkan/textures/vk_hwtexture.cpp | 1 - 3 files changed, 9 deletions(-) diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/rendering/vulkan/renderer/vk_renderstate.cpp index 18425e29d9..b933046e30 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.cpp +++ b/src/rendering/vulkan/renderer/vk_renderstate.cpp @@ -27,8 +27,6 @@ #include "vulkan/renderer/vk_renderbuffers.h" #include "vulkan/textures/vk_hwtexture.h" #include "templates.h" -#include "doomstat.h" -#include "r_data/colormaps.h" #include "hw_skydome.h" #include "hw_viewpointuniforms.h" #include "hw_lightbuffer.h" diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index b7117175f1..f750b4f392 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -26,7 +26,6 @@ #include "m_png.h" #include "templates.h" #include "r_videoscale.h" -#include "actor.h" #include "i_time.h" #include "g_game.h" #include "v_text.h" @@ -38,16 +37,11 @@ #include "hw_cvars.h" #include "hw_models.h" #include "hw_skydome.h" -#include "hwrenderer/scene/hw_fakeflat.h" -#include "hwrenderer/scene/hw_drawinfo.h" -#include "hwrenderer/scene/hw_portal.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "flatvertices.h" #include "hwrenderer/data/shaderuniforms.h" #include "hw_lightbuffer.h" -#include "swrenderer/r_swscene.h" - #include "vk_framebuffer.h" #include "vk_buffers.h" #include "vulkan/renderer/vk_renderstate.h" diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index e39c5e0092..cac4985ef4 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -22,7 +22,6 @@ #include "templates.h" #include "c_cvars.h" -#include "r_data/colormaps.h" #include "hw_material.h" #include "hw_cvars.h" #include "hw_renderstate.h" From 652712d970af26de89487e076332656cf6b4db89 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 22:17:35 +0200 Subject: [PATCH 143/220] - moved Vulkan and Softpoly backends to 'common'. --- CMakeLists.txt | 1 + src/CMakeLists.txt | 101 +++++++++--------- src/common/platform/posix/cocoa/i_video.mm | 2 +- src/common/platform/posix/sdl/sdlglvideo.cpp | 2 +- src/common/platform/win32/win32polyvideo.h | 2 +- src/common/platform/win32/win32vulkanvideo.h | 2 +- .../polyrenderer/backend/poly_buffers.cpp | 2 +- .../polyrenderer/backend/poly_buffers.h | 0 .../polyrenderer/backend/poly_framebuffer.cpp | 0 .../polyrenderer/backend/poly_framebuffer.h | 2 +- .../polyrenderer/backend/poly_hwtexture.cpp | 0 .../polyrenderer/backend/poly_hwtexture.h | 0 .../polyrenderer/backend/poly_renderstate.cpp | 0 .../polyrenderer/backend/poly_renderstate.h | 2 +- .../polyrenderer/drawers/poly_thread.cpp | 0 .../polyrenderer/drawers/poly_thread.h | 0 .../polyrenderer/drawers/poly_triangle.cpp | 0 .../polyrenderer/drawers/poly_triangle.h | 0 .../polyrenderer/drawers/poly_vertex_shader.h | 0 .../polyrenderer/drawers/screen_blend.cpp | 0 .../polyrenderer/drawers/screen_blend.h | 0 .../drawers/screen_scanline_setup.cpp | 0 .../drawers/screen_scanline_setup.h | 0 .../polyrenderer/drawers/screen_shader.cpp | 0 .../polyrenderer/drawers/screen_shader.h | 0 .../polyrenderer/drawers/screen_triangle.cpp | 0 .../polyrenderer/drawers/screen_triangle.h | 0 .../rendering/polyrenderer/poly_all.cpp | 1 - .../drawers => common/rendering}/r_thread.cpp | 8 +- .../vulkan/renderer/vk_postprocess.cpp | 1 + .../vulkan/renderer/vk_postprocess.h | 0 .../vulkan/renderer/vk_renderbuffers.cpp | 0 .../vulkan/renderer/vk_renderbuffers.h | 0 .../vulkan/renderer/vk_renderpass.cpp | 0 .../rendering/vulkan/renderer/vk_renderpass.h | 0 .../vulkan/renderer/vk_renderstate.cpp | 0 .../vulkan/renderer/vk_renderstate.h | 1 - .../vulkan/renderer/vk_streambuffer.cpp | 0 .../vulkan/renderer/vk_streambuffer.h | 0 .../rendering/vulkan/shaders/vk_shader.cpp | 0 .../rendering/vulkan/shaders/vk_shader.h | 0 .../rendering/vulkan/system/vk_buffers.cpp | 0 .../rendering/vulkan/system/vk_buffers.h | 0 .../rendering/vulkan/system/vk_builders.cpp | 0 .../rendering/vulkan/system/vk_builders.h | 0 .../rendering/vulkan/system/vk_device.cpp | 0 .../rendering/vulkan/system/vk_device.h | 0 .../vulkan/system/vk_framebuffer.cpp | 2 - .../rendering/vulkan/system/vk_framebuffer.h | 0 .../rendering/vulkan/system/vk_objects.h | 0 .../rendering/vulkan/system/vk_swapchain.cpp | 0 .../rendering/vulkan/system/vk_swapchain.h | 0 .../vulkan/textures/vk_hwtexture.cpp | 0 .../rendering/vulkan/textures/vk_hwtexture.h | 0 .../vulkan/textures/vk_imagetransition.cpp | 0 .../vulkan/textures/vk_imagetransition.h | 0 .../rendering/vulkan/textures/vk_samplers.cpp | 0 .../rendering/vulkan/textures/vk_samplers.h | 2 +- .../thirdparty/vk_mem_alloc/vk_mem_alloc.cpp | 0 .../thirdparty/vk_mem_alloc/vk_mem_alloc.h | 0 .../rendering/vulkan/thirdparty/volk/volk.c | 0 .../rendering/vulkan/thirdparty/volk/volk.h | 0 .../vulkan/thirdparty/vulkan/vk_icd.h | 0 .../vulkan/thirdparty/vulkan/vk_layer.h | 0 .../vulkan/vk_layer_dispatch_table.h | 0 .../vulkan/thirdparty/vulkan/vk_platform.h | 0 .../thirdparty/vulkan/vk_sdk_platform.h | 0 .../vulkan/thirdparty/vulkan/vulkan.h | 0 .../vulkan/thirdparty/vulkan/vulkan_android.h | 0 .../vulkan/thirdparty/vulkan/vulkan_core.h | 0 .../vulkan/thirdparty/vulkan/vulkan_fuchsia.h | 0 .../vulkan/thirdparty/vulkan/vulkan_ggp.h | 0 .../vulkan/thirdparty/vulkan/vulkan_ios.h | 0 .../vulkan/thirdparty/vulkan/vulkan_macos.h | 0 .../vulkan/thirdparty/vulkan/vulkan_metal.h | 0 .../vulkan/thirdparty/vulkan/vulkan_mir.h | 0 .../vulkan/thirdparty/vulkan/vulkan_vi.h | 0 .../vulkan/thirdparty/vulkan/vulkan_wayland.h | 0 .../vulkan/thirdparty/vulkan/vulkan_win32.h | 0 .../vulkan/thirdparty/vulkan/vulkan_xcb.h | 0 .../vulkan/thirdparty/vulkan/vulkan_xlib.h | 0 .../thirdparty/vulkan/vulkan_xlib_xrandr.h | 0 src/common/scripting/backend/codegen.cpp | 4 - src/common/scripting/core/dynarrays.cpp | 4 - src/common/scripting/core/imports.cpp | 4 - .../scripting/interface/stringformat.cpp | 4 - src/rendering/swrenderer/r_all.cpp | 1 - 87 files changed, 63 insertions(+), 85 deletions(-) rename src/{ => common}/rendering/polyrenderer/backend/poly_buffers.cpp (98%) rename src/{ => common}/rendering/polyrenderer/backend/poly_buffers.h (100%) rename src/{ => common}/rendering/polyrenderer/backend/poly_framebuffer.cpp (100%) rename src/{ => common}/rendering/polyrenderer/backend/poly_framebuffer.h (97%) rename src/{ => common}/rendering/polyrenderer/backend/poly_hwtexture.cpp (100%) rename src/{ => common}/rendering/polyrenderer/backend/poly_hwtexture.h (100%) rename src/{ => common}/rendering/polyrenderer/backend/poly_renderstate.cpp (100%) rename src/{ => common}/rendering/polyrenderer/backend/poly_renderstate.h (97%) rename src/{ => common}/rendering/polyrenderer/drawers/poly_thread.cpp (100%) rename src/{ => common}/rendering/polyrenderer/drawers/poly_thread.h (100%) rename src/{ => common}/rendering/polyrenderer/drawers/poly_triangle.cpp (100%) rename src/{ => common}/rendering/polyrenderer/drawers/poly_triangle.h (100%) rename src/{ => common}/rendering/polyrenderer/drawers/poly_vertex_shader.h (100%) rename src/{ => common}/rendering/polyrenderer/drawers/screen_blend.cpp (100%) rename src/{ => common}/rendering/polyrenderer/drawers/screen_blend.h (100%) rename src/{ => common}/rendering/polyrenderer/drawers/screen_scanline_setup.cpp (100%) rename src/{ => common}/rendering/polyrenderer/drawers/screen_scanline_setup.h (100%) rename src/{ => common}/rendering/polyrenderer/drawers/screen_shader.cpp (100%) rename src/{ => common}/rendering/polyrenderer/drawers/screen_shader.h (100%) rename src/{ => common}/rendering/polyrenderer/drawers/screen_triangle.cpp (100%) rename src/{ => common}/rendering/polyrenderer/drawers/screen_triangle.h (100%) rename src/{ => common}/rendering/polyrenderer/poly_all.cpp (82%) rename src/{rendering/swrenderer/drawers => common/rendering}/r_thread.cpp (98%) rename src/{ => common}/rendering/vulkan/renderer/vk_postprocess.cpp (99%) rename src/{ => common}/rendering/vulkan/renderer/vk_postprocess.h (100%) rename src/{ => common}/rendering/vulkan/renderer/vk_renderbuffers.cpp (100%) rename src/{ => common}/rendering/vulkan/renderer/vk_renderbuffers.h (100%) rename src/{ => common}/rendering/vulkan/renderer/vk_renderpass.cpp (100%) rename src/{ => common}/rendering/vulkan/renderer/vk_renderpass.h (100%) rename src/{ => common}/rendering/vulkan/renderer/vk_renderstate.cpp (100%) rename src/{ => common}/rendering/vulkan/renderer/vk_renderstate.h (98%) rename src/{ => common}/rendering/vulkan/renderer/vk_streambuffer.cpp (100%) rename src/{ => common}/rendering/vulkan/renderer/vk_streambuffer.h (100%) rename src/{ => common}/rendering/vulkan/shaders/vk_shader.cpp (100%) rename src/{ => common}/rendering/vulkan/shaders/vk_shader.h (100%) rename src/{ => common}/rendering/vulkan/system/vk_buffers.cpp (100%) rename src/{ => common}/rendering/vulkan/system/vk_buffers.h (100%) rename src/{ => common}/rendering/vulkan/system/vk_builders.cpp (100%) rename src/{ => common}/rendering/vulkan/system/vk_builders.h (100%) rename src/{ => common}/rendering/vulkan/system/vk_device.cpp (100%) rename src/{ => common}/rendering/vulkan/system/vk_device.h (100%) rename src/{ => common}/rendering/vulkan/system/vk_framebuffer.cpp (99%) rename src/{ => common}/rendering/vulkan/system/vk_framebuffer.h (100%) rename src/{ => common}/rendering/vulkan/system/vk_objects.h (100%) rename src/{ => common}/rendering/vulkan/system/vk_swapchain.cpp (100%) rename src/{ => common}/rendering/vulkan/system/vk_swapchain.h (100%) rename src/{ => common}/rendering/vulkan/textures/vk_hwtexture.cpp (100%) rename src/{ => common}/rendering/vulkan/textures/vk_hwtexture.h (100%) rename src/{ => common}/rendering/vulkan/textures/vk_imagetransition.cpp (100%) rename src/{ => common}/rendering/vulkan/textures/vk_imagetransition.h (100%) rename src/{ => common}/rendering/vulkan/textures/vk_samplers.cpp (100%) rename src/{ => common}/rendering/vulkan/textures/vk_samplers.h (90%) rename src/{ => common}/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.cpp (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/volk/volk.c (100%) rename src/{ => common}/rendering/vulkan/thirdparty/volk/volk.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vk_icd.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vk_layer.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vk_layer_dispatch_table.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vk_platform.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vk_sdk_platform.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_android.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_core.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_fuchsia.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_ggp.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_ios.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_macos.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_metal.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_mir.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_vi.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_wayland.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_win32.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_xcb.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_xlib.h (100%) rename src/{ => common}/rendering/vulkan/thirdparty/vulkan/vulkan_xlib_xrandr.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95dba3dc3a..4e59452f2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,7 @@ macro( use_fast_math ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ZD_FASTMATH_FLAG}" ) endmacro() + include( CheckFunctionExists ) macro( require_stricmp ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02228a1182..126a5fe323 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -620,6 +620,15 @@ file( GLOB HEADER_FILES common/rendering/*.h common/rendering/gl_load/*.h common/rendering/hwrenderer/data/*.h + common/rendering/polyrenderer/*.h + common/rendering/polyrenderer/math/*.h + common/rendering/polyrenderer/drawers/*.h + common/rendering/polyrenderer/backend/*.h + common/rendering/vulkan/*.h + common/rendering/vulkan/system/*.h + common/rendering/vulkan/renderer/*.h + common/rendering/vulkan/shaders/*.h + common/rendering/vulkan/textures/*.h common/scripting/core/*h common/scripting/vm/*h common/scripting/jit/*h @@ -643,17 +652,8 @@ file( GLOB HEADER_FILES rendering/swrenderer/plane/*.h rendering/swrenderer/things/*.h rendering/swrenderer/viewport/*.h - rendering/polyrenderer/*.h - rendering/polyrenderer/math/*.h - rendering/polyrenderer/drawers/*.h - rendering/polyrenderer/backend/*.h rendering/hwrenderer/*.h rendering/hwrenderer/scene/*.h - rendering/vulkan/*.h - rendering/vulkan/system/*.h - rendering/vulkan/renderer/*.h - rendering/vulkan/shaders/*.h - rendering/vulkan/textures/*.h *.h ) @@ -664,7 +664,6 @@ set ( SWRENDER_SOURCES rendering/swrenderer/drawers/r_draw.cpp rendering/swrenderer/drawers/r_draw_pal.cpp rendering/swrenderer/drawers/r_draw_rgba.cpp - rendering/swrenderer/drawers/r_thread.cpp rendering/swrenderer/scene/r_3dfloors.cpp rendering/swrenderer/scene/r_light.cpp rendering/swrenderer/scene/r_opaque_pass.cpp @@ -704,12 +703,12 @@ set ( SWRENDER_SOURCES ) set( POLYRENDER_SOURCES - rendering/polyrenderer/drawers/poly_triangle.cpp - rendering/polyrenderer/drawers/poly_thread.cpp - rendering/polyrenderer/drawers/screen_triangle.cpp - rendering/polyrenderer/drawers/screen_scanline_setup.cpp - rendering/polyrenderer/drawers/screen_shader.cpp - rendering/polyrenderer/drawers/screen_blend.cpp + common/rendering/polyrenderer/drawers/poly_triangle.cpp + common/rendering/polyrenderer/drawers/poly_thread.cpp + common/rendering/polyrenderer/drawers/screen_triangle.cpp + common/rendering/polyrenderer/drawers/screen_scanline_setup.cpp + common/rendering/polyrenderer/drawers/screen_shader.cpp + common/rendering/polyrenderer/drawers/screen_blend.cpp ) # These files will be flagged as "headers" so that they appear in project files @@ -749,7 +748,7 @@ set( VM_JIT_SOURCES set( FASTMATH_SOURCES rendering/swrenderer/r_all.cpp rendering/swrenderer/r_swscene.cpp - rendering/polyrenderer/poly_all.cpp + common/rendering/polyrenderer/poly_all.cpp common/textures/hires/hqnx/init.cpp common/textures/hires/hqnx/hq2x.cpp common/textures/hires/hqnx/hq3x.cpp @@ -779,22 +778,22 @@ set( FASTMATH_SOURCES #Vulkan stuff must go into a separate list because it needs to be disabled for some platforms set (VULKAN_SOURCES - rendering/vulkan/system/vk_device.cpp - rendering/vulkan/system/vk_swapchain.cpp - rendering/vulkan/system/vk_builders.cpp - rendering/vulkan/system/vk_framebuffer.cpp - rendering/vulkan/system/vk_buffers.cpp - rendering/vulkan/renderer/vk_renderstate.cpp - rendering/vulkan/renderer/vk_renderpass.cpp - rendering/vulkan/renderer/vk_streambuffer.cpp - rendering/vulkan/renderer/vk_postprocess.cpp - rendering/vulkan/renderer/vk_renderbuffers.cpp - rendering/vulkan/shaders/vk_shader.cpp - rendering/vulkan/textures/vk_samplers.cpp - rendering/vulkan/textures/vk_hwtexture.cpp - rendering/vulkan/textures/vk_imagetransition.cpp - rendering/vulkan/thirdparty/volk/volk.c - rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.cpp + common/rendering/vulkan/system/vk_device.cpp + common/rendering/vulkan/system/vk_swapchain.cpp + common/rendering/vulkan/system/vk_builders.cpp + common/rendering/vulkan/system/vk_framebuffer.cpp + common/rendering/vulkan/system/vk_buffers.cpp + common/rendering/vulkan/renderer/vk_renderstate.cpp + common/rendering/vulkan/renderer/vk_renderpass.cpp + common/rendering/vulkan/renderer/vk_streambuffer.cpp + common/rendering/vulkan/renderer/vk_postprocess.cpp + common/rendering/vulkan/renderer/vk_renderbuffers.cpp + common/rendering/vulkan/shaders/vk_shader.cpp + common/rendering/vulkan/textures/vk_samplers.cpp + common/rendering/vulkan/textures/vk_hwtexture.cpp + common/rendering/vulkan/textures/vk_imagetransition.cpp + common/rendering/vulkan/thirdparty/volk/volk.c + common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.cpp ) if (HAVE_VULKAN) @@ -802,10 +801,10 @@ if (HAVE_VULKAN) endif() set (POLYBACKEND_SOURCES - rendering/polyrenderer/backend/poly_framebuffer.cpp - rendering/polyrenderer/backend/poly_buffers.cpp - rendering/polyrenderer/backend/poly_hwtexture.cpp - rendering/polyrenderer/backend/poly_renderstate.cpp + common/rendering/polyrenderer/backend/poly_framebuffer.cpp + common/rendering/polyrenderer/backend/poly_buffers.cpp + common/rendering/polyrenderer/backend/poly_hwtexture.cpp + common/rendering/polyrenderer/backend/poly_renderstate.cpp ) set (FASTMATH_SOURCES ${FASTMATH_SOURCES} ${POLYBACKEND_SOURCES}) @@ -1113,6 +1112,7 @@ set (PCH_SOURCES common/objects/dobjtype.cpp common/rendering/v_framebuffer.cpp common/rendering/v_video.cpp + common/rendering/r_thread.cpp common/rendering/r_videoscale.cpp common/rendering/hwrenderer/data/hw_clock.cpp common/rendering/hwrenderer/data/hw_skydome.cpp @@ -1252,6 +1252,9 @@ include_directories( . common/rendering/hwrenderer/data common/rendering/gl_load common/rendering/gl + common/rendering/vulkan/thirdparty + common/rendering/polyrenderer/backend + common/rendering/polyrenderer/drawers common/scripting/vm common/scripting/jit common/scripting/core @@ -1278,7 +1281,6 @@ include_directories( . scripting scripting/zscript rendering - rendering/vulkan/thirdparty ../libraries/gdtoa ../libraries/glslang/glslang/Public ../libraries/glslang/spirv @@ -1347,7 +1349,7 @@ if( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) # Need to enable intrinsics for these files. if( SSE_MATTERS ) set_property( SOURCE - rendering/polyrenderer/poly_all.cpp + common/rendering/polyrenderer/poly_all.cpp rendering/swrenderer/r_all.cpp utility/palette.cpp utility/x86.cpp @@ -1396,13 +1398,6 @@ source_group("Rendering" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/render source_group("Rendering\\2D" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/2d/.+") source_group("Rendering\\Hardware Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/gl/.+") source_group("Rendering\\Hardware Renderer\\Scene" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/hwrenderer/scene/.+") -source_group("Rendering\\Vulkan Renderer\\System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/system/.+") -source_group("Rendering\\Vulkan Renderer\\Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/renderer/.+") -source_group("Rendering\\Vulkan Renderer\\Shaders" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/shaders/.+") -source_group("Rendering\\Vulkan Renderer\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/textures/.+") -source_group("Rendering\\Vulkan Renderer\\Third Party" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/thirdparty/.+") -source_group("Rendering\\Vulkan Renderer\\Third Party\\Volk" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/thirdparty/volk/.+") -source_group("Rendering\\Vulkan Renderer\\Third Party\\Vk_Mem_Alloc" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/vulkan/thirdparty/vk_mem_alloc.+") source_group("Rendering\\Software Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/.+") source_group("Rendering\\Software Renderer\\Drawers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/drawers/.+") source_group("Rendering\\Software Renderer\\Scene" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/scene/.+") @@ -1411,10 +1406,6 @@ source_group("Rendering\\Software Renderer\\Line" REGULAR_EXPRESSION "^${CMAKE_C source_group("Rendering\\Software Renderer\\Plane" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/plane/.+") source_group("Rendering\\Software Renderer\\Things" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/things/.+") source_group("Rendering\\Software Renderer\\Viewport" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/swrenderer/viewport/.+") -source_group("Rendering\\Poly Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/.+") -source_group("Rendering\\Poly Renderer\\Math" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/math/.+") -source_group("Rendering\\Poly Renderer\\Drawers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/drawers/.+") -source_group("Rendering\\Poly Renderer\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rendering/polyrenderer/backend/.+") source_group("Render Data" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/r_data/.+") source_group("Render Interface" FILES r_defs.h r_renderer.h r_sky.cpp r_sky.h r_state.h r_utility.cpp r_utility.h) source_group("Platforms\\POSIX Files" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/posix/.+") @@ -1454,6 +1445,16 @@ source_group("Common\\Rendering\\Hardware Renderer\\Data" REGULAR_EXPRESSION "^$ source_group("Common\\Rendering\\Hardware Renderer\\Postprocessing" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/hwrenderer/postprocessing/.+") source_group("Common\\Rendering\\OpenGL Loader" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl_load/.+") source_group("Common\\Rendering\\OpenGL Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/gl/.+") +source_group("Common\\Rendering\\Vulkan Renderer\\System" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/system/.+") +source_group("Common\\Rendering\\Vulkan Renderer\\Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/renderer/.+") +source_group("Common\\Rendering\\Vulkan Renderer\\Shaders" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/shaders/.+") +source_group("Common\\Rendering\\Vulkan Renderer\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/textures/.+") +source_group("Common\\Rendering\\Vulkan Renderer\\Third Party" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/thirdparty/.+") +source_group("Common\\Rendering\\Vulkan Renderer\\Third Party\\Volk" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/thirdparty/volk/.+") +source_group("Common\\Rendering\\Vulkan Renderer\\Third Party\\Vk_Mem_Alloc" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/vulkan/thirdparty/vk_mem_alloc.+") +source_group("Common\\Rendering\\Poly Renderer" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/polyrenderer/.+") +source_group("Common\\Rendering\\Poly Renderer\\Drawers" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/polyrenderer/drawers/.+") +source_group("Common\\Rendering\\Poly Renderer\\Backend" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/rendering/polyrenderer/backend/.+") source_group("Common\\Models" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/models/.+") source_group("Common\\Textures" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/.+") source_group("Common\\Textures\\Hires" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/common/textures/hires/.+") diff --git a/src/common/platform/posix/cocoa/i_video.mm b/src/common/platform/posix/cocoa/i_video.mm index 1f2056ab53..a7465cfabe 100644 --- a/src/common/platform/posix/cocoa/i_video.mm +++ b/src/common/platform/posix/cocoa/i_video.mm @@ -58,7 +58,7 @@ #include "vulkan/system/vk_framebuffer.h" #endif #ifdef HAVE_SOFTPOLY -#include "rendering/polyrenderer/backend/poly_framebuffer.h" +#include "poly_framebuffer.h" #endif extern bool ToggleFullscreen; diff --git a/src/common/platform/posix/sdl/sdlglvideo.cpp b/src/common/platform/posix/sdl/sdlglvideo.cpp index 65133a7923..ead04b73c4 100644 --- a/src/common/platform/posix/sdl/sdlglvideo.cpp +++ b/src/common/platform/posix/sdl/sdlglvideo.cpp @@ -55,7 +55,7 @@ #endif #ifdef HAVE_SOFTPOLY -#include "rendering/polyrenderer/backend/poly_framebuffer.h" +#include "poly_framebuffer.h" #endif // MACROS ------------------------------------------------------------------ diff --git a/src/common/platform/win32/win32polyvideo.h b/src/common/platform/win32/win32polyvideo.h index 6d1648d0c6..3a1c362421 100644 --- a/src/common/platform/win32/win32polyvideo.h +++ b/src/common/platform/win32/win32polyvideo.h @@ -2,7 +2,7 @@ #include "win32basevideo.h" #include "c_cvars.h" -#include "rendering/polyrenderer/backend/poly_framebuffer.h" +#include "poly_framebuffer.h" EXTERN_CVAR(Bool, vid_fullscreen) diff --git a/src/common/platform/win32/win32vulkanvideo.h b/src/common/platform/win32/win32vulkanvideo.h index c34c41d726..2654597c7e 100644 --- a/src/common/platform/win32/win32vulkanvideo.h +++ b/src/common/platform/win32/win32vulkanvideo.h @@ -2,7 +2,7 @@ #include "win32basevideo.h" #include "c_cvars.h" -#include "rendering/vulkan/system/vk_framebuffer.h" +#include "vulkan/system/vk_framebuffer.h" EXTERN_CVAR(Bool, vid_fullscreen) diff --git a/src/rendering/polyrenderer/backend/poly_buffers.cpp b/src/common/rendering/polyrenderer/backend/poly_buffers.cpp similarity index 98% rename from src/rendering/polyrenderer/backend/poly_buffers.cpp rename to src/common/rendering/polyrenderer/backend/poly_buffers.cpp index 32be46eff7..599c9e088b 100644 --- a/src/rendering/polyrenderer/backend/poly_buffers.cpp +++ b/src/common/rendering/polyrenderer/backend/poly_buffers.cpp @@ -23,7 +23,7 @@ #include "poly_buffers.h" #include "poly_framebuffer.h" #include "poly_renderstate.h" -#include "rendering/polyrenderer/drawers/poly_thread.h" +#include "poly_thread.h" #include "engineerrors.h" PolyBuffer *PolyBuffer::First = nullptr; diff --git a/src/rendering/polyrenderer/backend/poly_buffers.h b/src/common/rendering/polyrenderer/backend/poly_buffers.h similarity index 100% rename from src/rendering/polyrenderer/backend/poly_buffers.h rename to src/common/rendering/polyrenderer/backend/poly_buffers.h diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp similarity index 100% rename from src/rendering/polyrenderer/backend/poly_framebuffer.cpp rename to src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp diff --git a/src/rendering/polyrenderer/backend/poly_framebuffer.h b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h similarity index 97% rename from src/rendering/polyrenderer/backend/poly_framebuffer.h rename to src/common/rendering/polyrenderer/backend/poly_framebuffer.h index 8ba6592726..38b8974f81 100644 --- a/src/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h @@ -3,7 +3,7 @@ #include "gl_sysfb.h" #include "r_memory.h" #include "r_thread.h" -#include "rendering/polyrenderer/drawers/poly_triangle.h" +#include "poly_triangle.h" struct FRenderViewpoint; class PolyDataBuffer; diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.cpp b/src/common/rendering/polyrenderer/backend/poly_hwtexture.cpp similarity index 100% rename from src/rendering/polyrenderer/backend/poly_hwtexture.cpp rename to src/common/rendering/polyrenderer/backend/poly_hwtexture.cpp diff --git a/src/rendering/polyrenderer/backend/poly_hwtexture.h b/src/common/rendering/polyrenderer/backend/poly_hwtexture.h similarity index 100% rename from src/rendering/polyrenderer/backend/poly_hwtexture.h rename to src/common/rendering/polyrenderer/backend/poly_hwtexture.h diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.cpp b/src/common/rendering/polyrenderer/backend/poly_renderstate.cpp similarity index 100% rename from src/rendering/polyrenderer/backend/poly_renderstate.cpp rename to src/common/rendering/polyrenderer/backend/poly_renderstate.cpp diff --git a/src/rendering/polyrenderer/backend/poly_renderstate.h b/src/common/rendering/polyrenderer/backend/poly_renderstate.h similarity index 97% rename from src/rendering/polyrenderer/backend/poly_renderstate.h rename to src/common/rendering/polyrenderer/backend/poly_renderstate.h index a99a9eab56..f539bc7c28 100644 --- a/src/rendering/polyrenderer/backend/poly_renderstate.h +++ b/src/common/rendering/polyrenderer/backend/poly_renderstate.h @@ -2,7 +2,7 @@ #pragma once #include "polyrenderer/backend/poly_buffers.h" -#include "rendering/polyrenderer/drawers/poly_triangle.h" +#include "poly_triangle.h" #include "name.h" diff --git a/src/rendering/polyrenderer/drawers/poly_thread.cpp b/src/common/rendering/polyrenderer/drawers/poly_thread.cpp similarity index 100% rename from src/rendering/polyrenderer/drawers/poly_thread.cpp rename to src/common/rendering/polyrenderer/drawers/poly_thread.cpp diff --git a/src/rendering/polyrenderer/drawers/poly_thread.h b/src/common/rendering/polyrenderer/drawers/poly_thread.h similarity index 100% rename from src/rendering/polyrenderer/drawers/poly_thread.h rename to src/common/rendering/polyrenderer/drawers/poly_thread.h diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.cpp b/src/common/rendering/polyrenderer/drawers/poly_triangle.cpp similarity index 100% rename from src/rendering/polyrenderer/drawers/poly_triangle.cpp rename to src/common/rendering/polyrenderer/drawers/poly_triangle.cpp diff --git a/src/rendering/polyrenderer/drawers/poly_triangle.h b/src/common/rendering/polyrenderer/drawers/poly_triangle.h similarity index 100% rename from src/rendering/polyrenderer/drawers/poly_triangle.h rename to src/common/rendering/polyrenderer/drawers/poly_triangle.h diff --git a/src/rendering/polyrenderer/drawers/poly_vertex_shader.h b/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h similarity index 100% rename from src/rendering/polyrenderer/drawers/poly_vertex_shader.h rename to src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h diff --git a/src/rendering/polyrenderer/drawers/screen_blend.cpp b/src/common/rendering/polyrenderer/drawers/screen_blend.cpp similarity index 100% rename from src/rendering/polyrenderer/drawers/screen_blend.cpp rename to src/common/rendering/polyrenderer/drawers/screen_blend.cpp diff --git a/src/rendering/polyrenderer/drawers/screen_blend.h b/src/common/rendering/polyrenderer/drawers/screen_blend.h similarity index 100% rename from src/rendering/polyrenderer/drawers/screen_blend.h rename to src/common/rendering/polyrenderer/drawers/screen_blend.h diff --git a/src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp b/src/common/rendering/polyrenderer/drawers/screen_scanline_setup.cpp similarity index 100% rename from src/rendering/polyrenderer/drawers/screen_scanline_setup.cpp rename to src/common/rendering/polyrenderer/drawers/screen_scanline_setup.cpp diff --git a/src/rendering/polyrenderer/drawers/screen_scanline_setup.h b/src/common/rendering/polyrenderer/drawers/screen_scanline_setup.h similarity index 100% rename from src/rendering/polyrenderer/drawers/screen_scanline_setup.h rename to src/common/rendering/polyrenderer/drawers/screen_scanline_setup.h diff --git a/src/rendering/polyrenderer/drawers/screen_shader.cpp b/src/common/rendering/polyrenderer/drawers/screen_shader.cpp similarity index 100% rename from src/rendering/polyrenderer/drawers/screen_shader.cpp rename to src/common/rendering/polyrenderer/drawers/screen_shader.cpp diff --git a/src/rendering/polyrenderer/drawers/screen_shader.h b/src/common/rendering/polyrenderer/drawers/screen_shader.h similarity index 100% rename from src/rendering/polyrenderer/drawers/screen_shader.h rename to src/common/rendering/polyrenderer/drawers/screen_shader.h diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.cpp b/src/common/rendering/polyrenderer/drawers/screen_triangle.cpp similarity index 100% rename from src/rendering/polyrenderer/drawers/screen_triangle.cpp rename to src/common/rendering/polyrenderer/drawers/screen_triangle.cpp diff --git a/src/rendering/polyrenderer/drawers/screen_triangle.h b/src/common/rendering/polyrenderer/drawers/screen_triangle.h similarity index 100% rename from src/rendering/polyrenderer/drawers/screen_triangle.h rename to src/common/rendering/polyrenderer/drawers/screen_triangle.h diff --git a/src/rendering/polyrenderer/poly_all.cpp b/src/common/rendering/polyrenderer/poly_all.cpp similarity index 82% rename from src/rendering/polyrenderer/poly_all.cpp rename to src/common/rendering/polyrenderer/poly_all.cpp index 97fda79d1a..64098aa8e0 100644 --- a/src/rendering/polyrenderer/poly_all.cpp +++ b/src/common/rendering/polyrenderer/poly_all.cpp @@ -1,4 +1,3 @@ -#include "../swrenderer/textures/r_swtexture.h" #include "drawers/poly_triangle.cpp" #include "drawers/poly_thread.cpp" #include "drawers/screen_triangle.cpp" diff --git a/src/rendering/swrenderer/drawers/r_thread.cpp b/src/common/rendering/r_thread.cpp similarity index 98% rename from src/rendering/swrenderer/drawers/r_thread.cpp rename to src/common/rendering/r_thread.cpp index e5c4f698ca..0415bd40c3 100644 --- a/src/rendering/swrenderer/drawers/r_thread.cpp +++ b/src/common/rendering/r_thread.cpp @@ -22,17 +22,13 @@ #include #include "templates.h" -#include "doomdef.h" #include "i_system.h" #include "filesystem.h" #include "v_video.h" -#include "doomstat.h" -#include "st_stuff.h" -#include "g_game.h" -#include "g_level.h" #include "r_thread.h" #include "r_memory.h" -#include "swrenderer/r_renderthread.h" +#include "poly_thread.h" +#include "printf.h" #include "polyrenderer/drawers/poly_triangle.h" #include diff --git a/src/rendering/vulkan/renderer/vk_postprocess.cpp b/src/common/rendering/vulkan/renderer/vk_postprocess.cpp similarity index 99% rename from src/rendering/vulkan/renderer/vk_postprocess.cpp rename to src/common/rendering/vulkan/renderer/vk_postprocess.cpp index b2b7d1ae4f..c1c4148cae 100644 --- a/src/rendering/vulkan/renderer/vk_postprocess.cpp +++ b/src/common/rendering/vulkan/renderer/vk_postprocess.cpp @@ -36,6 +36,7 @@ #include "flatvertices.h" #include "r_videoscale.h" #include "filesystem.h" +#include "templates.h" EXTERN_CVAR(Int, gl_dither_bpc) diff --git a/src/rendering/vulkan/renderer/vk_postprocess.h b/src/common/rendering/vulkan/renderer/vk_postprocess.h similarity index 100% rename from src/rendering/vulkan/renderer/vk_postprocess.h rename to src/common/rendering/vulkan/renderer/vk_postprocess.h diff --git a/src/rendering/vulkan/renderer/vk_renderbuffers.cpp b/src/common/rendering/vulkan/renderer/vk_renderbuffers.cpp similarity index 100% rename from src/rendering/vulkan/renderer/vk_renderbuffers.cpp rename to src/common/rendering/vulkan/renderer/vk_renderbuffers.cpp diff --git a/src/rendering/vulkan/renderer/vk_renderbuffers.h b/src/common/rendering/vulkan/renderer/vk_renderbuffers.h similarity index 100% rename from src/rendering/vulkan/renderer/vk_renderbuffers.h rename to src/common/rendering/vulkan/renderer/vk_renderbuffers.h diff --git a/src/rendering/vulkan/renderer/vk_renderpass.cpp b/src/common/rendering/vulkan/renderer/vk_renderpass.cpp similarity index 100% rename from src/rendering/vulkan/renderer/vk_renderpass.cpp rename to src/common/rendering/vulkan/renderer/vk_renderpass.cpp diff --git a/src/rendering/vulkan/renderer/vk_renderpass.h b/src/common/rendering/vulkan/renderer/vk_renderpass.h similarity index 100% rename from src/rendering/vulkan/renderer/vk_renderpass.h rename to src/common/rendering/vulkan/renderer/vk_renderpass.h diff --git a/src/rendering/vulkan/renderer/vk_renderstate.cpp b/src/common/rendering/vulkan/renderer/vk_renderstate.cpp similarity index 100% rename from src/rendering/vulkan/renderer/vk_renderstate.cpp rename to src/common/rendering/vulkan/renderer/vk_renderstate.cpp diff --git a/src/rendering/vulkan/renderer/vk_renderstate.h b/src/common/rendering/vulkan/renderer/vk_renderstate.h similarity index 98% rename from src/rendering/vulkan/renderer/vk_renderstate.h rename to src/common/rendering/vulkan/renderer/vk_renderstate.h index 71e467f193..d4df3a7747 100644 --- a/src/rendering/vulkan/renderer/vk_renderstate.h +++ b/src/common/rendering/vulkan/renderer/vk_renderstate.h @@ -8,7 +8,6 @@ #include "name.h" -#include "hwrenderer/scene/hw_drawstructs.h" #include "hw_renderstate.h" #include "hw_material.h" diff --git a/src/rendering/vulkan/renderer/vk_streambuffer.cpp b/src/common/rendering/vulkan/renderer/vk_streambuffer.cpp similarity index 100% rename from src/rendering/vulkan/renderer/vk_streambuffer.cpp rename to src/common/rendering/vulkan/renderer/vk_streambuffer.cpp diff --git a/src/rendering/vulkan/renderer/vk_streambuffer.h b/src/common/rendering/vulkan/renderer/vk_streambuffer.h similarity index 100% rename from src/rendering/vulkan/renderer/vk_streambuffer.h rename to src/common/rendering/vulkan/renderer/vk_streambuffer.h diff --git a/src/rendering/vulkan/shaders/vk_shader.cpp b/src/common/rendering/vulkan/shaders/vk_shader.cpp similarity index 100% rename from src/rendering/vulkan/shaders/vk_shader.cpp rename to src/common/rendering/vulkan/shaders/vk_shader.cpp diff --git a/src/rendering/vulkan/shaders/vk_shader.h b/src/common/rendering/vulkan/shaders/vk_shader.h similarity index 100% rename from src/rendering/vulkan/shaders/vk_shader.h rename to src/common/rendering/vulkan/shaders/vk_shader.h diff --git a/src/rendering/vulkan/system/vk_buffers.cpp b/src/common/rendering/vulkan/system/vk_buffers.cpp similarity index 100% rename from src/rendering/vulkan/system/vk_buffers.cpp rename to src/common/rendering/vulkan/system/vk_buffers.cpp diff --git a/src/rendering/vulkan/system/vk_buffers.h b/src/common/rendering/vulkan/system/vk_buffers.h similarity index 100% rename from src/rendering/vulkan/system/vk_buffers.h rename to src/common/rendering/vulkan/system/vk_buffers.h diff --git a/src/rendering/vulkan/system/vk_builders.cpp b/src/common/rendering/vulkan/system/vk_builders.cpp similarity index 100% rename from src/rendering/vulkan/system/vk_builders.cpp rename to src/common/rendering/vulkan/system/vk_builders.cpp diff --git a/src/rendering/vulkan/system/vk_builders.h b/src/common/rendering/vulkan/system/vk_builders.h similarity index 100% rename from src/rendering/vulkan/system/vk_builders.h rename to src/common/rendering/vulkan/system/vk_builders.h diff --git a/src/rendering/vulkan/system/vk_device.cpp b/src/common/rendering/vulkan/system/vk_device.cpp similarity index 100% rename from src/rendering/vulkan/system/vk_device.cpp rename to src/common/rendering/vulkan/system/vk_device.cpp diff --git a/src/rendering/vulkan/system/vk_device.h b/src/common/rendering/vulkan/system/vk_device.h similarity index 100% rename from src/rendering/vulkan/system/vk_device.h rename to src/common/rendering/vulkan/system/vk_device.h diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/common/rendering/vulkan/system/vk_framebuffer.cpp similarity index 99% rename from src/rendering/vulkan/system/vk_framebuffer.cpp rename to src/common/rendering/vulkan/system/vk_framebuffer.cpp index f750b4f392..8cc0046ea3 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/common/rendering/vulkan/system/vk_framebuffer.cpp @@ -27,7 +27,6 @@ #include "templates.h" #include "r_videoscale.h" #include "i_time.h" -#include "g_game.h" #include "v_text.h" #include "version.h" #include "v_draw.h" @@ -35,7 +34,6 @@ #include "hw_clock.h" #include "hw_vrmodes.h" #include "hw_cvars.h" -#include "hw_models.h" #include "hw_skydome.h" #include "hwrenderer/data/hw_viewpointbuffer.h" #include "flatvertices.h" diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/common/rendering/vulkan/system/vk_framebuffer.h similarity index 100% rename from src/rendering/vulkan/system/vk_framebuffer.h rename to src/common/rendering/vulkan/system/vk_framebuffer.h diff --git a/src/rendering/vulkan/system/vk_objects.h b/src/common/rendering/vulkan/system/vk_objects.h similarity index 100% rename from src/rendering/vulkan/system/vk_objects.h rename to src/common/rendering/vulkan/system/vk_objects.h diff --git a/src/rendering/vulkan/system/vk_swapchain.cpp b/src/common/rendering/vulkan/system/vk_swapchain.cpp similarity index 100% rename from src/rendering/vulkan/system/vk_swapchain.cpp rename to src/common/rendering/vulkan/system/vk_swapchain.cpp diff --git a/src/rendering/vulkan/system/vk_swapchain.h b/src/common/rendering/vulkan/system/vk_swapchain.h similarity index 100% rename from src/rendering/vulkan/system/vk_swapchain.h rename to src/common/rendering/vulkan/system/vk_swapchain.h diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp similarity index 100% rename from src/rendering/vulkan/textures/vk_hwtexture.cpp rename to src/common/rendering/vulkan/textures/vk_hwtexture.cpp diff --git a/src/rendering/vulkan/textures/vk_hwtexture.h b/src/common/rendering/vulkan/textures/vk_hwtexture.h similarity index 100% rename from src/rendering/vulkan/textures/vk_hwtexture.h rename to src/common/rendering/vulkan/textures/vk_hwtexture.h diff --git a/src/rendering/vulkan/textures/vk_imagetransition.cpp b/src/common/rendering/vulkan/textures/vk_imagetransition.cpp similarity index 100% rename from src/rendering/vulkan/textures/vk_imagetransition.cpp rename to src/common/rendering/vulkan/textures/vk_imagetransition.cpp diff --git a/src/rendering/vulkan/textures/vk_imagetransition.h b/src/common/rendering/vulkan/textures/vk_imagetransition.h similarity index 100% rename from src/rendering/vulkan/textures/vk_imagetransition.h rename to src/common/rendering/vulkan/textures/vk_imagetransition.h diff --git a/src/rendering/vulkan/textures/vk_samplers.cpp b/src/common/rendering/vulkan/textures/vk_samplers.cpp similarity index 100% rename from src/rendering/vulkan/textures/vk_samplers.cpp rename to src/common/rendering/vulkan/textures/vk_samplers.cpp diff --git a/src/rendering/vulkan/textures/vk_samplers.h b/src/common/rendering/vulkan/textures/vk_samplers.h similarity index 90% rename from src/rendering/vulkan/textures/vk_samplers.h rename to src/common/rendering/vulkan/textures/vk_samplers.h index 0a088cf74c..cd1b8462fa 100644 --- a/src/rendering/vulkan/textures/vk_samplers.h +++ b/src/common/rendering/vulkan/textures/vk_samplers.h @@ -1,7 +1,7 @@ #ifndef __VK_SAMPLERS_H #define __VK_SAMPLERS_H -#include "rendering/vulkan/system/vk_objects.h" +#include "vulkan/system/vk_objects.h" class VulkanDevice; diff --git a/src/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.cpp b/src/common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.cpp similarity index 100% rename from src/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.cpp rename to src/common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.cpp diff --git a/src/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h b/src/common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h rename to src/common/rendering/vulkan/thirdparty/vk_mem_alloc/vk_mem_alloc.h diff --git a/src/rendering/vulkan/thirdparty/volk/volk.c b/src/common/rendering/vulkan/thirdparty/volk/volk.c similarity index 100% rename from src/rendering/vulkan/thirdparty/volk/volk.c rename to src/common/rendering/vulkan/thirdparty/volk/volk.c diff --git a/src/rendering/vulkan/thirdparty/volk/volk.h b/src/common/rendering/vulkan/thirdparty/volk/volk.h similarity index 100% rename from src/rendering/vulkan/thirdparty/volk/volk.h rename to src/common/rendering/vulkan/thirdparty/volk/volk.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vk_icd.h b/src/common/rendering/vulkan/thirdparty/vulkan/vk_icd.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vk_icd.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vk_icd.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vk_layer.h b/src/common/rendering/vulkan/thirdparty/vulkan/vk_layer.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vk_layer.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vk_layer.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vk_layer_dispatch_table.h b/src/common/rendering/vulkan/thirdparty/vulkan/vk_layer_dispatch_table.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vk_layer_dispatch_table.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vk_layer_dispatch_table.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vk_platform.h b/src/common/rendering/vulkan/thirdparty/vulkan/vk_platform.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vk_platform.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vk_platform.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vk_sdk_platform.h b/src/common/rendering/vulkan/thirdparty/vulkan/vk_sdk_platform.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vk_sdk_platform.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vk_sdk_platform.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_android.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_android.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_android.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_android.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_core.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_core.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_core.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_core.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_fuchsia.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_fuchsia.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_fuchsia.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_fuchsia.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_ggp.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_ggp.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_ggp.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_ggp.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_ios.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_ios.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_ios.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_ios.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_macos.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_macos.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_macos.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_macos.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_metal.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_metal.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_metal.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_metal.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_mir.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_mir.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_mir.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_mir.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_vi.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_vi.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_vi.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_vi.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_wayland.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_wayland.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_wayland.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_wayland.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_win32.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_win32.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_win32.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_win32.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_xcb.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_xcb.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_xcb.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_xcb.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_xlib.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_xlib.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_xlib.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_xlib.h diff --git a/src/rendering/vulkan/thirdparty/vulkan/vulkan_xlib_xrandr.h b/src/common/rendering/vulkan/thirdparty/vulkan/vulkan_xlib_xrandr.h similarity index 100% rename from src/rendering/vulkan/thirdparty/vulkan/vulkan_xlib_xrandr.h rename to src/common/rendering/vulkan/thirdparty/vulkan/vulkan_xlib_xrandr.h diff --git a/src/common/scripting/backend/codegen.cpp b/src/common/scripting/backend/codegen.cpp index 8368220d33..1c9209c588 100644 --- a/src/common/scripting/backend/codegen.cpp +++ b/src/common/scripting/backend/codegen.cpp @@ -18,10 +18,6 @@ ** documentation and/or other materials provided with the distribution. ** 3. The name of the author may not be used to endorse or promote products ** derived from this software without specific prior written permission. -** 4. When not used as part of ZDoom or a ZDoom derivative, this code will be -** covered by the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or (at -** your option) any later version. ** ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/src/common/scripting/core/dynarrays.cpp b/src/common/scripting/core/dynarrays.cpp index daedd60e66..16bb57ca85 100644 --- a/src/common/scripting/core/dynarrays.cpp +++ b/src/common/scripting/core/dynarrays.cpp @@ -18,10 +18,6 @@ ** documentation and/or other materials provided with the distribution. ** 3. The name of the author may not be used to endorse or promote products ** derived from this software without specific prior written permission. -** 4. When not used as part of ZDoom or a ZDoom derivative, this code will be -** covered by the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or (at -** your option) any later version. ** ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/src/common/scripting/core/imports.cpp b/src/common/scripting/core/imports.cpp index 2b4d567568..0c277c9643 100644 --- a/src/common/scripting/core/imports.cpp +++ b/src/common/scripting/core/imports.cpp @@ -19,10 +19,6 @@ ** documentation and/or other materials provided with the distribution. ** 3. The name of the author may not be used to endorse or promote products ** derived from this software without specific prior written permission. -** 4. When not used as part of ZDoom or a ZDoom derivative, this code will be -** covered by the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or (at -** your option) any later version. ** ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/src/common/scripting/interface/stringformat.cpp b/src/common/scripting/interface/stringformat.cpp index b4d0bc4d86..8e0bf0c75b 100644 --- a/src/common/scripting/interface/stringformat.cpp +++ b/src/common/scripting/interface/stringformat.cpp @@ -19,10 +19,6 @@ ** documentation and/or other materials provided with the distribution. ** 3. The name of the author may not be used to endorse or promote products ** derived from this software without specific prior written permission. -** 4. When not used as part of ZDoom or a ZDoom derivative, this code will be -** covered by the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or (at -** your option) any later version. ** ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/src/rendering/swrenderer/r_all.cpp b/src/rendering/swrenderer/r_all.cpp index a15525ecde..91142a1df2 100644 --- a/src/rendering/swrenderer/r_all.cpp +++ b/src/rendering/swrenderer/r_all.cpp @@ -5,7 +5,6 @@ #include "drawers/r_draw.cpp" #include "drawers/r_draw_pal.cpp" #include "drawers/r_draw_rgba.cpp" -#include "drawers/r_thread.cpp" #include "line/r_fogboundary.cpp" #include "line/r_line.cpp" #include "line/r_farclip_line.cpp" From d71ef669571d84db6112f1064db1ecd3bc8bce21 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 29 Apr 2020 23:58:50 +0200 Subject: [PATCH 144/220] - fixes copied from Raze. --- src/common/engine/serializer.cpp | 2 +- src/common/objects/dobject.h | 2 +- src/common/platform/posix/i_system_posix.cpp | 1 - src/common/platform/posix/sdl/sdlglvideo.cpp | 2 +- src/common/rendering/gl/gl_renderer.h | 2 +- .../rendering/polyrenderer/backend/poly_framebuffer.h | 4 ++-- .../rendering/polyrenderer/drawers/screen_triangle.h | 1 + .../rendering/vulkan/renderer/vk_postprocess.cpp | 10 +++++----- src/common/rendering/vulkan/renderer/vk_renderpass.cpp | 2 +- src/common/rendering/vulkan/system/vk_framebuffer.h | 2 +- src/common/scripting/backend/codegen.h | 2 +- src/common/scripting/core/dictionary.cpp | 2 +- src/common/textures/textures.h | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/common/engine/serializer.cpp b/src/common/engine/serializer.cpp index d500826ed6..f0d31a13dc 100644 --- a/src/common/engine/serializer.cpp +++ b/src/common/engine/serializer.cpp @@ -1504,7 +1504,7 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, Dictionary { if (arc.isWriting()) { - FString contents { dict ? DictionaryToString(*dict) : "null" }; + FString contents { dict ? DictionaryToString(*dict) : FString("null") }; return arc(key, contents); } else diff --git a/src/common/objects/dobject.h b/src/common/objects/dobject.h index 3c98d144bb..98d9106a24 100644 --- a/src/common/objects/dobject.h +++ b/src/common/objects/dobject.h @@ -110,7 +110,7 @@ enum EInPlace { EC_InPlace }; #define DECLARE_ABSTRACT_CLASS(cls,parent) \ public: \ - virtual PClass *StaticType() const; \ + PClass *StaticType() const override; \ static ClassReg RegistrationInfo, * const RegistrationInfoPtr; \ typedef parent Super; \ private: \ diff --git a/src/common/platform/posix/i_system_posix.cpp b/src/common/platform/posix/i_system_posix.cpp index 46be3f0526..aa8bea6d29 100644 --- a/src/common/platform/posix/i_system_posix.cpp +++ b/src/common/platform/posix/i_system_posix.cpp @@ -35,7 +35,6 @@ #endif // __APPLE__ #include "cmdlib.h" -#include "d_protocol.h" #include "i_system.h" #include "gameconfigfile.h" #include "x86.h" diff --git a/src/common/platform/posix/sdl/sdlglvideo.cpp b/src/common/platform/posix/sdl/sdlglvideo.cpp index ead04b73c4..da64bb9d47 100644 --- a/src/common/platform/posix/sdl/sdlglvideo.cpp +++ b/src/common/platform/posix/sdl/sdlglvideo.cpp @@ -51,7 +51,7 @@ #include "gl_framebuffer.h" #ifdef HAVE_VULKAN -#include "rendering/vulkan/system/vk_framebuffer.h" +#include "vk_framebuffer.h" #endif #ifdef HAVE_SOFTPOLY diff --git a/src/common/rendering/gl/gl_renderer.h b/src/common/rendering/gl/gl_renderer.h index 5613fd5fd2..8b5fe7e038 100644 --- a/src/common/rendering/gl/gl_renderer.h +++ b/src/common/rendering/gl/gl_renderer.h @@ -20,13 +20,13 @@ class FLightBuffer; class DPSprite; class FGLRenderBuffers; class FGL2DDrawer; -class FHardwareTexture; class SWSceneDrawer; class HWViewpointBuffer; struct FRenderViewpoint; namespace OpenGLRenderer { + class FHardwareTexture; class FShaderManager; class FSamplerManager; class OpenGLFrameBuffer; diff --git a/src/common/rendering/polyrenderer/backend/poly_framebuffer.h b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h index 38b8974f81..c96dfa321e 100644 --- a/src/common/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h @@ -27,7 +27,7 @@ public: PolyFrameBuffer(void *hMonitor, bool fullscreen); ~PolyFrameBuffer(); - void Update(); + void Update() override; bool IsPoly() override { return true; } @@ -65,7 +65,7 @@ public: private: void RenderTextureView(FCanvasTexture* tex, std::function renderFunc) override; - void UpdateShadowMap(); + void UpdateShadowMap() override; void CheckCanvas(); diff --git a/src/common/rendering/polyrenderer/drawers/screen_triangle.h b/src/common/rendering/polyrenderer/drawers/screen_triangle.h index 520ab4d000..24af616999 100644 --- a/src/common/rendering/polyrenderer/drawers/screen_triangle.h +++ b/src/common/rendering/polyrenderer/drawers/screen_triangle.h @@ -24,6 +24,7 @@ #include #include +#include #include "renderstyle.h" //#include "rendering/swrenderer/drawers/r_draw.h" diff --git a/src/common/rendering/vulkan/renderer/vk_postprocess.cpp b/src/common/rendering/vulkan/renderer/vk_postprocess.cpp index c1c4148cae..6d3656fd92 100644 --- a/src/common/rendering/vulkan/renderer/vk_postprocess.cpp +++ b/src/common/rendering/vulkan/renderer/vk_postprocess.cpp @@ -533,10 +533,10 @@ void VkPPRenderState::RenderScreenQuad(VkPPRenderPassSetup *passSetup, VulkanDes auto cmdbuffer = fb->GetDrawCommands(); VkViewport viewport = { }; - viewport.x = x; - viewport.y = y; - viewport.width = width; - viewport.height = height; + viewport.x = (float)x; + viewport.y = (float)y; + viewport.width = (float)width; + viewport.height = (float)height; viewport.minDepth = 0.0f; viewport.maxDepth = 1.0f; @@ -761,7 +761,7 @@ void VkPPRenderPassSetup::CreatePipeline(const VkPPRenderPassKey &key) builder.addDynamicState(VK_DYNAMIC_STATE_SCISSOR); // Note: the actual values are ignored since we use dynamic viewport+scissor states builder.setViewport(0.0f, 0.0f, 320.0f, 200.0f); - builder.setScissor(0.0f, 0.0f, 320.0f, 200.0f); + builder.setScissor(0, 0, 320, 200); if (key.StencilTest) { builder.addDynamicState(VK_DYNAMIC_STATE_STENCIL_REFERENCE); diff --git a/src/common/rendering/vulkan/renderer/vk_renderpass.cpp b/src/common/rendering/vulkan/renderer/vk_renderpass.cpp index 53b1cd732b..2e0973c087 100644 --- a/src/common/rendering/vulkan/renderer/vk_renderpass.cpp +++ b/src/common/rendering/vulkan/renderer/vk_renderpass.cpp @@ -404,7 +404,7 @@ std::unique_ptr VkRenderPassSetup::CreatePipeline(const VkPipeli // Note: the actual values are ignored since we use dynamic viewport+scissor states builder.setViewport(0.0f, 0.0f, 320.0f, 200.0f); - builder.setScissor(0, 0, 320.0f, 200.0f); + builder.setScissor(0, 0, 320, 200); static const VkPrimitiveTopology vktopology[] = { VK_PRIMITIVE_TOPOLOGY_POINT_LIST, diff --git a/src/common/rendering/vulkan/system/vk_framebuffer.h b/src/common/rendering/vulkan/system/vk_framebuffer.h index bf062afe2c..537879e6a6 100644 --- a/src/common/rendering/vulkan/system/vk_framebuffer.h +++ b/src/common/rendering/vulkan/system/vk_framebuffer.h @@ -68,7 +68,7 @@ public: ~VulkanFrameBuffer(); bool IsVulkan() override { return true; } - void Update(); + void Update() override; void InitializeState() override; diff --git a/src/common/scripting/backend/codegen.h b/src/common/scripting/backend/codegen.h index 5a0fc06644..bcadae39db 100644 --- a/src/common/scripting/backend/codegen.h +++ b/src/common/scripting/backend/codegen.h @@ -198,7 +198,7 @@ struct ExpVal const FString GetString() const { - return Type == TypeString ? *(FString *)&pointer : Type == TypeName ? FString(FName(ENamedName(Int)).GetChars()) : ""; + return Type == TypeString ? *(FString *)&pointer : Type == TypeName ? FString(FName(ENamedName(Int)).GetChars()) : FString(); } bool GetBool() const diff --git a/src/common/scripting/core/dictionary.cpp b/src/common/scripting/core/dictionary.cpp index b8dacd2bcd..5d4b05a3da 100644 --- a/src/common/scripting/core/dictionary.cpp +++ b/src/common/scripting/core/dictionary.cpp @@ -62,7 +62,7 @@ static void DictInsert(Dictionary *dict, const FString &key, const FString &valu static void DictAt(const Dictionary *dict, const FString &key, FString *result) { const FString *value = dict->Map.CheckKey(key); - *result = value ? *value : ""; + *result = value ? *value : FString(); } static void DictToString(const Dictionary *dict, FString *result) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index f0b5b4dfce..9ca6be736b 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -352,7 +352,7 @@ protected: void SetFromImage(); public: FImageTexture(FImageSource* image) noexcept; - virtual TArray Get8BitPixels(bool alphatex); + TArray Get8BitPixels(bool alphatex) override; void SetImage(FImageSource* img) { From 3eecb6b3b64587a89d82c1abf793851e7a19ebc3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 30 Apr 2020 00:12:28 +0200 Subject: [PATCH 145/220] - fixed creation of multipatch textures using other multipatch textures as their source. --- .../textures/formats/multipatchtexture.h | 2 +- .../textures/multipatchtexturebuilder.cpp | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/common/textures/formats/multipatchtexture.h b/src/common/textures/formats/multipatchtexture.h index 51f36abf5e..5c75fa4743 100644 --- a/src/common/textures/formats/multipatchtexture.h +++ b/src/common/textures/formats/multipatchtexture.h @@ -92,7 +92,7 @@ struct TexInit { FString TexName; ETextureType UseType = ETextureType::Null; - FImageTexture *Texture = nullptr; + FGameTexture *GameTexture = nullptr; bool Silent = false; bool HasLine = false; bool UseOffsets = false; diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 1ee3634930..fcd12bac5d 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -138,6 +138,8 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u { buildinfo.texture = new FGameTexture(nullptr, buildinfo.Name); buildinfo.texture->SetUseType(usetype); + buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); // These are needed for construction of other multipatch textures. + buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); TexMan.AddGameTexture(buildinfo.texture); } @@ -812,10 +814,10 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) { FGameTexture *tex = TexMan.GetGameTexture(texno); - if (tex != nullptr && tex->isValid() && dynamic_cast(tex->GetTexture())) + if (tex != nullptr && tex->isValid() && (tex->GetTexture() == nullptr || dynamic_cast(tex->GetTexture()))) { - //We cannot set the image source yet. First all textures need to be resolved. - buildinfo.Inits[i].Texture = static_cast(tex->GetTexture()); + //We cannot set the image texture yet. First all textures need to be resolved. + buildinfo.Inits[i].GameTexture = tex; bool iscomplex = !!complex.CheckKey(tex); if (iscomplex) complex.Insert(buildinfo.texture, true); buildinfo.bComplex |= iscomplex; @@ -830,13 +832,15 @@ void FMultipatchTextureBuilder::ResolvePatches(BuildInfo &buildinfo) // The patch is bogus. Remove it. if (buildinfo.Inits[i].HasLine) buildinfo.Inits[i].sc.Message(MSG_WARNING, "Invalid patch '%s' in texture '%s'\n", buildinfo.Inits[i].TexName.GetChars(), buildinfo.Name.GetChars()); else Printf(TEXTCOLOR_YELLOW "Invalid patch '%s' in texture '%s'\n", buildinfo.Inits[i].TexName.GetChars(), buildinfo.Name.GetChars()); + buildinfo.Inits.Delete(i); + buildinfo.Parts.Delete(i); i--; } } } for (unsigned i = 0; i < buildinfo.Inits.Size(); i++) { - if (buildinfo.Inits[i].Texture == nullptr) + if (buildinfo.Inits[i].GameTexture == nullptr) { buildinfo.Inits.Delete(i); buildinfo.Parts.Delete(i); @@ -876,10 +880,10 @@ void FMultipatchTextureBuilder::ResolveAllPatches() { if (buildinfo.Parts[j].TexImage == nullptr) { - auto image = buildinfo.Inits[j].Texture; - if (image->GetImage() != nullptr) + auto image = buildinfo.Inits[j].GameTexture->GetTexture(); + if (image && image->GetImage() != nullptr) { - buildinfo.Parts[j].TexImage = image; + buildinfo.Parts[j].TexImage = static_cast(image); donesomething = true; } else hasEmpty = true; From f65a97322e9debe2c9c155c4b7dd75a32809c6dc Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Tue, 31 Mar 2020 19:30:27 +0800 Subject: [PATCH 146/220] Add an alpha parameter to StatusBar.DrawBar --- wadsrc/static/zscript/ui/statusbar/statusbar.zs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wadsrc/static/zscript/ui/statusbar/statusbar.zs b/wadsrc/static/zscript/ui/statusbar/statusbar.zs index 131649a2fe..4944104d82 100644 --- a/wadsrc/static/zscript/ui/statusbar/statusbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/statusbar.zs @@ -1019,7 +1019,7 @@ class BaseStatusBar native ui // //============================================================================ - void DrawBar(String ongfx, String offgfx, double curval, double maxval, Vector2 position, int border, int vertical, int flags = 0) + void DrawBar(String ongfx, String offgfx, double curval, double maxval, Vector2 position, int border, int vertical, int flags = 0, double alpha = 1.0) { let ontex = TexMan.CheckForTexture(ongfx, TexMan.TYPE_MiscPatch); if (!ontex.IsValid()) return; @@ -1050,17 +1050,17 @@ class BaseStatusBar native ui for(int i = 0; i < 4; i++) Clip[i] += border; //Draw the whole foreground - DrawTexture(ontex, position, flags | DI_ITEM_LEFT_TOP); + DrawTexture(ontex, position, flags | DI_ITEM_LEFT_TOP, alpha); SetClipRect(position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3], flags); } if (offtex.IsValid() && TexMan.GetScaledSize(offtex) == texsize) DrawTexture(offtex, position, flags | DI_ITEM_LEFT_TOP); - else Fill(color(255,0,0,0), position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3]); + else Fill(color(int(255*alpha),0,0,0), position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3]); - if (border == 0) + if (border == 0) { SetClipRect(position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3], flags); - DrawTexture(ontex, position, flags | DI_ITEM_LEFT_TOP); + DrawTexture(ontex, position, flags | DI_ITEM_LEFT_TOP, alpha); } // restore the previous clipping rectangle screen.SetClipRect(cx, cy, cw, ch); From d563b0339c236e3867500343123b5e4b825f369d Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Wed, 1 Apr 2020 01:45:28 +0800 Subject: [PATCH 147/220] Apply alpha to the background texture in DrawBar --- wadsrc/static/zscript/ui/statusbar/statusbar.zs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wadsrc/static/zscript/ui/statusbar/statusbar.zs b/wadsrc/static/zscript/ui/statusbar/statusbar.zs index 4944104d82..c2ed4c6d9d 100644 --- a/wadsrc/static/zscript/ui/statusbar/statusbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/statusbar.zs @@ -1054,7 +1054,7 @@ class BaseStatusBar native ui SetClipRect(position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3], flags); } - if (offtex.IsValid() && TexMan.GetScaledSize(offtex) == texsize) DrawTexture(offtex, position, flags | DI_ITEM_LEFT_TOP); + if (offtex.IsValid() && TexMan.GetScaledSize(offtex) == texsize) DrawTexture(offtex, position, flags | DI_ITEM_LEFT_TOP, alpha); else Fill(color(int(255*alpha),0,0,0), position.X + Clip[0], position.Y + Clip[1], texsize.X - Clip[0] - Clip[2], texsize.Y - Clip[1] - Clip[3]); if (border == 0) From 6b70cad6e1fc8d161e893f4e118f4e20d14e1622 Mon Sep 17 00:00:00 2001 From: arookas Date: Tue, 24 Mar 2020 23:21:26 -0400 Subject: [PATCH 148/220] Add option to invert mouse x --- src/d_main.cpp | 6 +++++- src/g_game.cpp | 1 + wadsrc/static/menudef.txt | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 163c9824f0..bf2eb02df1 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -171,6 +171,7 @@ EXTERN_CVAR (Bool, freelook) EXTERN_CVAR (Float, m_pitch) EXTERN_CVAR (Float, m_yaw) EXTERN_CVAR (Bool, invertmouse) +EXTERN_CVAR (Bool, invertmousex) EXTERN_CVAR (Bool, lookstrafe) EXTERN_CVAR (Int, screenblocks) EXTERN_CVAR (Bool, sv_cheats) @@ -449,7 +450,10 @@ void D_PostEvent (const event_t *ev) } if (!buttonMap.ButtonDown(Button_Strafe) && !lookstrafe) { - G_AddViewAngle (int(ev->x * m_yaw * mouse_sensitivity * 8.0), true); + int turn = int(ev->x * m_yaw * mouse_sensitivity * 8.0); + if (invertmousex) + turn = -turn; + G_AddViewAngle (turn, true); events[eventhead].x = 0; } if ((events[eventhead].x | events[eventhead].y) == 0) diff --git a/src/g_game.cpp b/src/g_game.cpp index 0bf7812604..b29f67d6bf 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -202,6 +202,7 @@ int lookspeed[2] = {450, 512}; CVAR (Bool, cl_run, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Always run? CVAR (Bool, invertmouse, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Invert mouse look down/up? +CVAR (Bool, invertmousex, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Invert mouse look left/right? CVAR (Bool, freelook, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Always mlook? CVAR (Bool, lookstrafe, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Always strafe with mouse? CVAR (Float, m_pitch, 1.f, CVAR_GLOBALCONFIG|CVAR_ARCHIVE) // Mouse speeds diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index b59af595f4..e7803545ef 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -734,6 +734,7 @@ OptionMenu "MouseOptions" protected Slider "$MOUSEMNU_STRAFESPEED", "m_side", 0, 2.5, 0.1 StaticText "" Option "$MOUSEMNU_ALWAYSMOUSELOOK", "freelook", "OnOff" + Option "$MOUSEMNU_INVERTMOUSEX", "invertmousex", "OnOff" Option "$MOUSEMNU_INVERTMOUSE", "invertmouse", "OnOff" Option "$MOUSEMNU_LOOKSPRING", "lookspring", "OnOff" Option "$MOUSEMNU_LOOKSTRAFE", "lookstrafe", "OnOff" From 4b4ff8dd0e55178be233ab97d04bcaa28a425e63 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 30 Apr 2020 12:55:09 +0600 Subject: [PATCH 149/220] Fix bouncing missiles not dealing damage when hitting top/bottom (#1068) * Fix bouncing missiles not dealing damage when hitting top/bottom --- src/playsim/p_local.h | 1 + src/playsim/p_map.cpp | 84 +++++++++++++++++---------- src/playsim/p_mobj.cpp | 1 + wadsrc/static/zscript/actors/actor.zs | 1 + 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/playsim/p_local.h b/src/playsim/p_local.h index 0c7bb1bc72..2a031b6895 100644 --- a/src/playsim/p_local.h +++ b/src/playsim/p_local.h @@ -246,6 +246,7 @@ extern TArray portalhit; int P_TestMobjLocation (AActor *mobj); int P_TestMobjZ (AActor *mobj, bool quick=true, AActor **pOnmobj = NULL); bool P_CheckPosition(AActor *thing, const DVector2 &pos, bool actorsonly = false); +void P_DoMissileDamage(AActor* inflictor, AActor* target); bool P_CheckPosition(AActor *thing, const DVector2 &pos, FCheckPosition &tm, bool actorsonly = false); AActor *P_CheckOnmobj (AActor *thing); void P_FakeZMovement (AActor *mo); diff --git a/src/playsim/p_map.cpp b/src/playsim/p_map.cpp index ae0eecef0c..ac7b817d59 100644 --- a/src/playsim/p_map.cpp +++ b/src/playsim/p_map.cpp @@ -1230,6 +1230,57 @@ static bool CanAttackHurt(AActor *victim, AActor *shooter) return true; } +//========================================================================== +// +// P_DoMissileDamage +// Handle damaging/poisoning enemies from missiles. +// target is the target to be dealt damage to. +// inflictor is the actor dealing the damage. +// +//========================================================================== + +void P_DoMissileDamage(AActor* inflictor, AActor* target) +{ + // Do poisoning (if using new style poison) + if (inflictor->PoisonDamage > 0 && inflictor->PoisonDuration != INT_MIN) + { + P_PoisonMobj(target, inflictor, inflictor->target, inflictor->PoisonDamage, inflictor->PoisonDuration, inflictor->PoisonPeriod, inflictor->PoisonDamageType); + } + + // Do damage + int damage = inflictor->GetMissileDamage((inflictor->flags4 & MF4_STRIFEDAMAGE) ? 3 : 7, 1); + if ((damage > 0) || (inflictor->flags6 & MF6_FORCEPAIN) || (inflictor->flags7 & MF7_CAUSEPAIN)) + { + int newdam = P_DamageMobj(target, inflictor, inflictor->target, damage, inflictor->DamageType); + if (damage > 0) + { + if ((inflictor->flags5 & MF5_BLOODSPLATTER) && + !(target->flags & MF_NOBLOOD) && + !(target->flags2 & MF2_REFLECTIVE) && + !(target->flags2 & (MF2_INVULNERABLE | MF2_DORMANT)) && + !(inflictor->flags3 & MF3_BLOODLESSIMPACT) && + (pr_checkthing() < 192)) + { + P_BloodSplatter(inflictor->Pos(), target, inflictor->AngleTo(target)); + } + if (!(inflictor->flags3 & MF3_BLOODLESSIMPACT)) + { + P_TraceBleed(newdam > 0 ? newdam : damage, target, inflictor); + } + } + } + else + { + P_GiveBody(target, -damage); + } +} +DEFINE_ACTION_FUNCTION(AActor, DoMissileDamage) +{ + PARAM_SELF_PROLOGUE(AActor); + PARAM_OBJECT_NOT_NULL(target, AActor); + P_DoMissileDamage(self, target); + return 0; +} //========================================================================== // // PIT_CheckThing @@ -1555,38 +1606,7 @@ bool PIT_CheckThing(FMultiBlockThingsIterator &it, FMultiBlockThingsIterator::Ch } } - // Do poisoning (if using new style poison) - if (tm.thing->PoisonDamage > 0 && tm.thing->PoisonDuration != INT_MIN) - { - P_PoisonMobj(thing, tm.thing, tm.thing->target, tm.thing->PoisonDamage, tm.thing->PoisonDuration, tm.thing->PoisonPeriod, tm.thing->PoisonDamageType); - } - - // Do damage - damage = tm.thing->GetMissileDamage((tm.thing->flags4 & MF4_STRIFEDAMAGE) ? 3 : 7, 1); - if ((damage > 0) || (tm.thing->flags6 & MF6_FORCEPAIN) || (tm.thing->flags7 & MF7_CAUSEPAIN)) - { - int newdam = P_DamageMobj(thing, tm.thing, tm.thing->target, damage, tm.thing->DamageType); - if (damage > 0) - { - if ((tm.thing->flags5 & MF5_BLOODSPLATTER) && - !(thing->flags & MF_NOBLOOD) && - !(thing->flags2 & MF2_REFLECTIVE) && - !(thing->flags2 & (MF2_INVULNERABLE | MF2_DORMANT)) && - !(tm.thing->flags3 & MF3_BLOODLESSIMPACT) && - (pr_checkthing() < 192)) - { - P_BloodSplatter(tm.thing->Pos(), thing, tm.thing->AngleTo(thing)); - } - if (!(tm.thing->flags3 & MF3_BLOODLESSIMPACT)) - { - P_TraceBleed(newdam > 0 ? newdam : damage, thing, tm.thing); - } - } - } - else - { - P_GiveBody(thing, -damage); - } + P_DoMissileDamage(tm.thing, thing); if ((thing->flags7 & MF7_THRUREFLECT) && (thing->flags2 & MF2_REFLECTIVE) && (tm.thing->flags & MF_MISSILE)) { diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index 0f6f32e9d4..c98bc9c7b1 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -3976,6 +3976,7 @@ void AActor::Tick () // to be in line with the case when an actor's side is hit. if (!res && (flags & MF_MISSILE)) { + P_DoMissileDamage(this, onmo); P_ExplodeMissile(this, nullptr, onmo); } } diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 0b3841a19c..27a929fdd4 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -759,6 +759,7 @@ class Actor : Thinker native native void GiveSecret(bool printmsg = true, bool playsound = true); native clearscope double GetCameraHeight() const; native clearscope double GetGravity() const; + native void DoMissileDamage(Actor target); //========================================================================== // From 028cc6a82844f57f690d05854efc744051e7ec90 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 30 Apr 2020 11:28:35 +0300 Subject: [PATCH 150/220] - fixed compilation of SDL backend --- src/common/platform/posix/sdl/sdlglvideo.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/platform/posix/sdl/sdlglvideo.cpp b/src/common/platform/posix/sdl/sdlglvideo.cpp index da64bb9d47..857abe981e 100644 --- a/src/common/platform/posix/sdl/sdlglvideo.cpp +++ b/src/common/platform/posix/sdl/sdlglvideo.cpp @@ -34,6 +34,7 @@ // HEADER FILES ------------------------------------------------------------ #include "i_module.h" +#include "i_soundinternal.h" #include "i_system.h" #include "i_video.h" #include "m_argv.h" @@ -51,7 +52,7 @@ #include "gl_framebuffer.h" #ifdef HAVE_VULKAN -#include "vk_framebuffer.h" +#include "vulkan/system/vk_framebuffer.h" #endif #ifdef HAVE_SOFTPOLY From 331f3d85d61fb52c571afbdb9f76a8da8a834ca4 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 30 Apr 2020 16:26:12 +0300 Subject: [PATCH 151/220] - fixed secondary ammo display in strife status bar https://forum.zdoom.org/viewtopic.php?t=68315 --- wadsrc/static/zscript/ui/statusbar/strife_sbar.zs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs b/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs index 79fc0ada4a..912effbb46 100644 --- a/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs +++ b/wadsrc/static/zscript/ui/statusbar/strife_sbar.zs @@ -353,8 +353,8 @@ class StrifeStatusBar : BaseStatusBar if (ammo2 != NULL && ammo1!=ammo2) { // Draw secondary ammo just above the primary ammo - DrawString(mGrnFont, FormatNumber(ammo1.Amount, 3), (-23, -48)); - DrawInventoryIcon(ammo1, (-14, -55)); + DrawString(mGrnFont, FormatNumber(ammo2.Amount, 3), (-23, -48)); + DrawInventoryIcon(ammo2, (-14, -55)); } } From a528290b5c6e1bae4179756adb56beeedc1cfa22 Mon Sep 17 00:00:00 2001 From: PaulyB <43163391+3saster@users.noreply.github.com> Date: Sat, 2 May 2020 23:22:44 -0700 Subject: [PATCH 152/220] Fix single top level filter folder not being read I have no idea why the missing comma broke it in this particular way... --- src/d_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index bf2eb02df1..eee2b36479 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -186,7 +186,7 @@ extern bool insave; extern TDeletingArray LightDefaults; const char* iwad_folders[13] = { "flats/", "textures/", "hires/", "sprites/", "voxels/", "colormaps/", "acs/", "maps/", "voices/", "patches/", "graphics/", "sounds/", "music/" }; -const char* iwad_reserved[12] = { "mapinfo", "zmapinfo", "gameinfo", "sndinfo", "sbarinfo", "menudef", "gldefs", "animdefs", "decorate", "zscript", "iwadinfo" "maps/" }; +const char* iwad_reserved[12] = { "mapinfo", "zmapinfo", "gameinfo", "sndinfo", "sbarinfo", "menudef", "gldefs", "animdefs", "decorate", "zscript", "iwadinfo", "maps/" }; CUSTOM_CVAR(Float, i_timescale, 1.0f, CVAR_NOINITCALL) From 3fd4d08004c3bc8cc0e4e0ba77163111b07d4fcb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 4 May 2020 20:06:54 +0200 Subject: [PATCH 153/220] - fixed startup and font init crashes. --- src/CMakeLists.txt | 2 +- src/common/2d/v_2ddrawer.cpp | 96 +++++++++++++--- src/common/2d/v_2ddrawer.h | 4 +- src/common/engine/palettecontainer.h | 1 + src/common/fonts/font.cpp | 11 +- src/common/fonts/hexfont.cpp | 65 ++++++----- src/common/fonts/singlelumpfont.cpp | 9 +- src/common/fonts/specialfont.cpp | 4 - src/common/fonts/v_font.cpp | 36 +++--- src/common/fonts/v_font.h | 6 +- src/common/rendering/gl/gl_shader.h | 2 +- .../rendering/hwrenderer/hw_draw2d.cpp | 55 ++++----- src/common/textures/animtexture.cpp | 2 + src/common/textures/formats/pngtexture.cpp | 106 ++++++++++++++---- src/d_main.cpp | 4 + 15 files changed, 271 insertions(+), 132 deletions(-) rename src/{ => common}/rendering/hwrenderer/hw_draw2d.cpp (76%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 126a5fe323..661214bf16 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -931,7 +931,6 @@ set (PCH_SOURCES rendering/hwrenderer/hw_models.cpp rendering/hwrenderer/hw_postprocessshader.cpp rendering/hwrenderer/hw_precache.cpp - rendering/hwrenderer/hw_draw2d.cpp rendering/hwrenderer/scene/hw_lighting.cpp rendering/hwrenderer/scene/hw_drawlistadd.cpp rendering/hwrenderer/scene/hw_setcolor.cpp @@ -1114,6 +1113,7 @@ set (PCH_SOURCES common/rendering/v_video.cpp common/rendering/r_thread.cpp common/rendering/r_videoscale.cpp + common/rendering/hwrenderer/hw_draw2d.cpp common/rendering/hwrenderer/data/hw_clock.cpp common/rendering/hwrenderer/data/hw_skydome.cpp common/rendering/hwrenderer/data/flatvertices.cpp diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 08560c35c0..665ea3d8ca 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -677,7 +677,7 @@ void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, unsigne // //========================================================================== -void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, bool local_origin) +void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin, double flatscale) { float fU1, fU2, fV1, fV2; @@ -690,27 +690,83 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu dg.mTexture = src; dg.mFlags = DTF_Wrap; - // scaling is not used here. - if (!local_origin) - { - fU1 = float(left) / (float)src->GetDisplayWidth(); - fV1 = float(top) / (float)src->GetDisplayHeight(); - fU2 = float(right) / (float)src->GetDisplayWidth(); - fV2 = float(bottom) / (float)src->GetDisplayHeight(); - } - else + float fs = 1.f / float(flatscale); + bool flipc = false; + switch (local_origin) { + case 0: + fU1 = float(left) / (float)src->GetDisplayWidth() * fs; + fV1 = float(top) / (float)src->GetDisplayHeight() * fs; + fU2 = float(right) / (float)src->GetDisplayWidth() * fs; + fV2 = float(bottom) / (float)src->GetDisplayHeight() * fs; + break; + + case 1: fU1 = 0; fV1 = 0; - fU2 = float(right - left) / (float)src->GetDisplayWidth(); - fV2 = float(bottom - top) / (float)src->GetDisplayHeight(); + fU2 = float(right - left) / (float)src->GetDisplayWidth() * fs; + fV2 = float(bottom - top) / (float)src->GetDisplayHeight() * fs; + break; + + // The following are for drawing frames with elements of pnly one orientation + case 2: // flip vertically + fU1 = 0; + fV2 = 0; + fU2 = float(right - left) / (float)src->GetDisplayWidth() * fs; + fV1 = float(bottom - top) / (float)src->GetDisplayHeight() * fs; + break; + + case 3: // flip horizontally + fU2 = 0; + fV1 = 0; + fU1 = float(right - left) / (float)src->GetDisplayWidth() * fs; + fV2 = float(bottom - top) / (float)src->GetDisplayHeight() * fs; + break; + + case 4: // flip vertically and horizontally + fU2 = 0; + fV2 = 0; + fU1 = float(right - left) / (float)src->GetDisplayWidth() * fs; + fV1 = float(bottom - top) / (float)src->GetDisplayHeight() * fs; + break; + + + case 5: // flip coordinates + fU1 = 0; + fV1 = 0; + fU2 = float(bottom - top) / (float)src->GetDisplayWidth() * fs; + fV2 = float(right - left) / (float)src->GetDisplayHeight() * fs; + break; + + case 6: // flip coordinates and vertically + fU2 = 0; + fV1 = 0; + fU1 = float(bottom - top) / (float)src->GetDisplayWidth() * fs; + fV2 = float(right - left) / (float)src->GetDisplayHeight() * fs; + break; + + case 7: // flip coordinates and horizontally + fU1 = 0; + fV2 = 0; + fU2 = float(bottom - top) / (float)src->GetDisplayWidth() * fs; + fV1 = float(right - left) / (float)src->GetDisplayHeight() * fs; + break; + } dg.mVertIndex = (int)mVertices.Reserve(4); auto ptr = &mVertices[dg.mVertIndex]; ptr->Set(left, top, 0, fU1, fV1, 0xffffffff); ptr++; - ptr->Set(left, bottom, 0, fU1, fV2, 0xffffffff); ptr++; - ptr->Set(right, top, 0, fU2, fV1, 0xffffffff); ptr++; + if (local_origin < 4) + { + ptr->Set(left, bottom, 0, fU1, fV2, 0xffffffff); ptr++; + ptr->Set(right, top, 0, fU2, fV1, 0xffffffff); ptr++; + } + else + { + ptr->Set(left, bottom, 0, fU2, fV1, 0xffffffff); ptr++; + ptr->Set(right, top, 0, fU1, fV2, 0xffffffff); ptr++; + } ptr->Set(right, bottom, 0, fU2, fV2, 0xffffffff); ptr++; dg.mIndexIndex = mIndices.Size(); dg.mIndexCount += 6; @@ -721,11 +777,11 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu //=========================================================================== // -// +// // //=========================================================================== -void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, FRenderStyle *style) +void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, FRenderStyle *style, bool prepend) { RenderCommand dg; @@ -741,7 +797,13 @@ void F2DDrawer::AddColorOnlyQuad(int x1, int y1, int w, int h, PalEntry color, F dg.mIndexIndex = mIndices.Size(); dg.mIndexCount += 6; AddIndices(dg.mVertIndex, 6, 0, 1, 2, 1, 3, 2); - AddCommand(&dg); + if (!prepend) AddCommand(&dg); + else + { + // Only needed by Raze's fullscreen blends because they are being calculated late when half of the 2D content has already been submitted, + // This ensures they are below the HUD, not above it. + mData.Insert(0, dg); + } } void F2DDrawer::ClearScreen(PalEntry color) diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index 93712a8f8f..f7a31ac79b 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -182,9 +182,9 @@ public: void AddPoly(FGameTexture* img, FVector4 *vt, size_t vtcount, unsigned int *ind, size_t idxcount, int translation, PalEntry color, FRenderStyle style, int clipx1, int clipy1, int clipx2, int clipy2); void FillPolygon(int* rx1, int* ry1, int* xb1, int32_t npoints, int picnum, int palette, int shade, int props, const FVector2& xtex, const FVector2& ytex, const FVector2& otex, int clipx1, int clipy1, int clipx2, int clipy2); - void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, bool local_origin = false); + void AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin = false, double flatscale = 1.0); - void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style = nullptr); + void AddColorOnlyQuad(int left, int top, int width, int height, PalEntry color, FRenderStyle *style = nullptr, bool prepend = false); void ClearScreen(PalEntry color = 0xff000000); void AddDim(PalEntry color, float damount, int x1, int y1, int w, int h); void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color); diff --git a/src/common/engine/palettecontainer.h b/src/common/engine/palettecontainer.h index c8c5499d3b..f858eefb02 100644 --- a/src/common/engine/palettecontainer.h +++ b/src/common/engine/palettecontainer.h @@ -34,6 +34,7 @@ struct FRemapTable int Index; int NumEntries; // # of elements in this table (usually 256) bool Inactive = false; // This table is inactive and should be treated as if it was passed as NULL + bool TwodOnly = false; // Only used for 2D rendering bool ForFont = false; // Mark font translations because they may require different handling than the ones for sprites- private: diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 985ba49819..c8964accfd 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -372,10 +372,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla FixXMoves(); } - - if (!noTranslate) LoadTranslations(); - - } void FFont::ReadSheetFont(TArray &folderdata, int width, int height, const DVector2 &Scale) @@ -443,16 +439,13 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height if (lump != nullptr) { auto pic = (*lump)->GetTexture(); - - auto b = pic->Get8BitPixels(false); - - Chars[i].OriginalPic = MakeGameTexture(pic, nullptr, ETextureType::FontChar); + Chars[i].OriginalPic = (*lump)->GetUseType() == ETextureType::FontChar? (*lump) : MakeGameTexture(pic, nullptr, ETextureType::FontChar); Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); Chars[i].OriginalPic->CopySize(*lump); Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage())), nullptr, ETextureType::FontChar); Chars[i].TranslatedPic->CopySize(*lump); Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar); - TexMan.AddGameTexture(Chars[i].OriginalPic); + if (Chars[i].OriginalPic != *lump) TexMan.AddGameTexture(Chars[i].OriginalPic); TexMan.AddGameTexture(Chars[i].TranslatedPic); } Chars[i].XMove = width; diff --git a/src/common/fonts/hexfont.cpp b/src/common/fonts/hexfont.cpp index 812973bba9..1c23d3bd01 100644 --- a/src/common/fonts/hexfont.cpp +++ b/src/common/fonts/hexfont.cpp @@ -245,6 +245,7 @@ public: FHexFont (const char *fontname, int lump) : FFont(lump) { + const int spacing = 9; assert(lump >= 0); FontName = fontname; @@ -258,8 +259,22 @@ public: SpaceWidth = 9; GlobalKerning = 0; translateUntranslated = true; - - LoadTranslations(); + + Chars.Resize(LastChar - FirstChar + 1); + for (int i = FirstChar; i <= LastChar; i++) + { + if (hexdata.glyphmap[i] > 0) + { + auto offset = hexdata.glyphmap[i]; + int size = hexdata.glyphdata[offset] / 16; + Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar(&hexdata.glyphdata[offset + 1], size, size * 9, 16)), nullptr, ETextureType::FontChar); + Chars[i - FirstChar].OriginalPic = Chars[i - FirstChar].TranslatedPic; + Chars[i - FirstChar].XMove = size * spacing; + TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); + } + else Chars[i - FirstChar].XMove = spacing; + + } } //========================================================================== @@ -270,7 +285,6 @@ public: void LoadTranslations() { - const int spacing = 9; double luminosity[256]; memset (PatchRemap, 0, 256); @@ -282,20 +296,6 @@ public: } ActiveColors = 18; - Chars.Resize(LastChar - FirstChar + 1); - for (int i = FirstChar; i <= LastChar; i++) - { - if (hexdata.glyphmap[i] > 0) - { - auto offset = hexdata.glyphmap[i]; - int size = hexdata.glyphdata[offset] / 16; - Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar (&hexdata.glyphdata[offset+1], size, size * 9, 16)), nullptr, ETextureType::FontChar); - Chars[i - FirstChar].XMove = size * spacing; - TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); - } - else Chars[i - FirstChar].XMove = spacing; - - } BuildTranslations (luminosity, nullptr, &TranslationParms[1][0], ActiveColors, nullptr); } @@ -317,6 +317,7 @@ public: FHexFont2(const char *fontname, int lump) : FFont(lump) { + const int spacing = 9; assert(lump >= 0); FontName = fontname; @@ -330,8 +331,21 @@ public: SpaceWidth = 9; GlobalKerning = -1; translateUntranslated = true; + Chars.Resize(LastChar - FirstChar + 1); + for (int i = FirstChar; i <= LastChar; i++) + { + if (hexdata.glyphmap[i] > 0) + { + auto offset = hexdata.glyphmap[i]; + int size = hexdata.glyphdata[offset] / 16; + Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), nullptr, ETextureType::FontChar); + Chars[i - FirstChar].OriginalPic = Chars[i - FirstChar].TranslatedPic; + Chars[i - FirstChar].XMove = size * spacing; + TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); + } + else Chars[i - FirstChar].XMove = spacing; - LoadTranslations(); + } } //========================================================================== @@ -342,7 +356,6 @@ public: void LoadTranslations() override { - const int spacing = 9; double luminosity[256]; memset(PatchRemap, 0, 256); @@ -354,20 +367,6 @@ public: } ActiveColors = 18; - Chars.Resize(LastChar - FirstChar + 1); - for (int i = FirstChar; i <= LastChar; i++) - { - if (hexdata.glyphmap[i] > 0) - { - auto offset = hexdata.glyphmap[i]; - int size = hexdata.glyphdata[offset] / 16; - Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), nullptr, ETextureType::FontChar); - Chars[i - FirstChar].XMove = size * spacing; - TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); - } - else Chars[i - FirstChar].XMove = spacing; - - } BuildTranslations(luminosity, nullptr, &TranslationParms[0][0], ActiveColors, nullptr); } diff --git a/src/common/fonts/singlelumpfont.cpp b/src/common/fonts/singlelumpfont.cpp index ed69aea808..a9cd6ee046 100644 --- a/src/common/fonts/singlelumpfont.cpp +++ b/src/common/fonts/singlelumpfont.cpp @@ -176,6 +176,7 @@ void FSingleLumpFont::CreateFontFromPic (FTextureID picnum) FirstChar = LastChar = 'A'; Chars.Resize(1); Chars[0].TranslatedPic = pic; + Chars[0].OriginalPic = pic; // Only one color range. Don't bother with the others. ActiveColors = 0; @@ -255,7 +256,6 @@ void FSingleLumpFont::LoadFON1 (int lump, const uint8_t *data) LastChar = 255; // This is to allow LoadTranslations to function. The way this is all set up really needs to be changed. GlobalKerning = 0; translateUntranslated = true; - LoadTranslations(); LastChar = 0x2122; // Move the Windows-1252 characters to their proper place. @@ -350,10 +350,12 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data) if (destSize <= 0) { Chars[i].TranslatedPic = nullptr; + Chars[i].OriginalPic = nullptr; } else { Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), nullptr, ETextureType::FontChar); + Chars[i].OriginalPic = Chars[i].TranslatedPic; TexMan.AddGameTexture(Chars[i].TranslatedPic); do { @@ -376,8 +378,6 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data) I_Error ("Overflow decompressing char %d (%c) of %s", i, i, FontName.GetChars()); } } - - LoadTranslations(); } //========================================================================== @@ -489,6 +489,7 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data) -(int8_t)chardata[chari+4] // y offset )), nullptr, ETextureType::FontChar); Chars[chardata[chari] - FirstChar].TranslatedPic = tex; + Chars[chardata[chari] - FirstChar].OriginalPic = tex; TexMan.AddGameTexture(tex); } @@ -506,7 +507,6 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data) } FixXMoves(); - LoadTranslations(); } //========================================================================== @@ -555,6 +555,7 @@ void FSingleLumpFont::CheckFON1Chars (double *luminosity) if(!Chars[i].TranslatedPic) { Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight)), nullptr, ETextureType::FontChar); + Chars[i].OriginalPic = Chars[i].TranslatedPic; Chars[i].XMove = SpaceWidth; TexMan.AddGameTexture(Chars[i].TranslatedPic); } diff --git a/src/common/fonts/specialfont.cpp b/src/common/fonts/specialfont.cpp index 6bd544c9e5..4dca54d3fb 100644 --- a/src/common/fonts/specialfont.cpp +++ b/src/common/fonts/specialfont.cpp @@ -140,10 +140,6 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture { ActiveColors = 0; } - else - { - LoadTranslations(); - } } //========================================================================== diff --git a/src/common/fonts/v_font.cpp b/src/common/fonts/v_font.cpp index 4057bc8788..4d0937d840 100644 --- a/src/common/fonts/v_font.cpp +++ b/src/common/fonts/v_font.cpp @@ -728,13 +728,6 @@ void V_InitFonts() OriginalSmallFont = new FFont("OriginalSmallFont", "STCFN%.3d", "defsmallfont", HU_FONTSTART, HU_FONTSIZE, HU_FONTSTART, -1, -1, false, true); } - if (SmallFont) - { - uint32_t colors[256] = {}; - SmallFont->RecordAllTextureColors(colors); - if (OriginalSmallFont != nullptr) OriginalSmallFont->SetDefaultTranslation(colors); - NewSmallFont->SetDefaultTranslation(colors); - } if (!(SmallFont2 = V_GetFont("SmallFont2"))) // Only used by Strife { @@ -770,13 +763,6 @@ void V_InitFonts() OriginalBigFont = new FFont("OriginalBigFont", nullptr, "bigfont", HU_FONTSTART, HU_FONTSIZE, 1, -1, -1, false, true); } - if (BigFont) - { - uint32_t colors[256] = {}; - BigFont->RecordAllTextureColors(colors); - if (OriginalBigFont != nullptr) OriginalBigFont->SetDefaultTranslation(colors); - } - // let PWAD BIGFONTs override the stock BIGUPPER font. (This check needs to be made smarter.) if (BigUpper && BigFont->Type != FFont::Folder && BigUpper->Type == FFont::Folder) { @@ -828,6 +814,28 @@ void V_InitFonts() AlternativeSmallFont = OriginalSmallFont; } +void V_LoadTranslations() +{ + for (auto font = FFont::FirstFont; font; font = font->Next) + { + if (!font->noTranslate) font->LoadTranslations(); + else font->ActiveColors = 0; + } + if (BigFont) + { + uint32_t colors[256] = {}; + BigFont->RecordAllTextureColors(colors); + if (OriginalBigFont != nullptr) OriginalBigFont->SetDefaultTranslation(colors); + } + if (SmallFont) + { + uint32_t colors[256] = {}; + SmallFont->RecordAllTextureColors(colors); + if (OriginalSmallFont != nullptr) OriginalSmallFont->SetDefaultTranslation(colors); + NewSmallFont->SetDefaultTranslation(colors); + } +} + void V_ClearFonts() { while (FFont::FirstFont != nullptr) diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 779137b61e..6de1dae868 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -80,6 +80,7 @@ using GlyphSet = TMap; class FFont { + friend void V_LoadTranslations(); public: enum EFontType @@ -154,7 +155,7 @@ protected: int TranslationType = 0; int Displacement = 0; char Cursor; - bool noTranslate; + bool noTranslate = false; bool translateUntranslated; bool MixedCase = false; bool forceremap = false; @@ -165,7 +166,7 @@ protected: int XMove = INT_MIN; }; TArray Chars; - int ActiveColors; + int ActiveColors = -1; TArray Translations; uint8_t PatchRemap[256]; @@ -191,5 +192,6 @@ EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int FFont *V_GetFont(const char *fontname, const char *fontlumpname = nullptr); void V_InitFontColors(); char* CleanseString(char* str); +void V_LoadTranslations(); diff --git a/src/common/rendering/gl/gl_shader.h b/src/common/rendering/gl/gl_shader.h index 3027376d52..fef8372cd8 100644 --- a/src/common/rendering/gl/gl_shader.h +++ b/src/common/rendering/gl/gl_shader.h @@ -305,8 +305,8 @@ public: FShader *BindEffect(int effect, EPassType passType); FShader *Get(unsigned int eff, bool alphateston, EPassType passType); -private: void SetActiveShader(FShader *sh); +private: FShader *mActiveShader = nullptr; TArray mPassShaders; diff --git a/src/rendering/hwrenderer/hw_draw2d.cpp b/src/common/rendering/hwrenderer/hw_draw2d.cpp similarity index 76% rename from src/rendering/hwrenderer/hw_draw2d.cpp rename to src/common/rendering/hwrenderer/hw_draw2d.cpp index 25f330c626..fc0b850a9f 100644 --- a/src/rendering/hwrenderer/hw_draw2d.cpp +++ b/src/common/rendering/hwrenderer/hw_draw2d.cpp @@ -1,34 +1,39 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2018 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// /* -** 2d drawer -** Renderer interface +** hw_draw2d.cpp +** 2d drawer Renderer interface +** +**--------------------------------------------------------------------------- +** Copyright 2018-2019 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- ** */ -#include "doomstat.h" #include "v_video.h" #include "cmdlib.h" -#include "r_defs.h" #include "hwrenderer/data/buffers.h" #include "flatvertices.h" #include "hwrenderer/data/hw_viewpointbuffer.h" diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp index a396244986..387464fd0d 100644 --- a/src/common/textures/animtexture.cpp +++ b/src/common/textures/animtexture.cpp @@ -102,6 +102,8 @@ void AnimTextures::SetSize(int width, int height) { static_cast(tex[0]->GetTexture())->SetFrameSize(width, height); static_cast(tex[1]->GetTexture())->SetFrameSize(width, height); + tex[0]->SetSize(width, height); + tex[1]->SetSize(width, height); } void AnimTextures::SetFrame(const uint8_t *palette, const void* data) diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index 790984d2e0..f8ba8648f9 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -59,6 +59,7 @@ public: protected: void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap); + void SetupPalette(FileReader &lump); uint8_t BitDepth; uint8_t ColorType; @@ -152,11 +153,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height, : FImageSource(lumpnum), BitDepth(depth), ColorType(colortype), Interlace(interlace), HaveTrans(false) { - union - { - uint32_t palette[256]; - uint8_t pngpal[256][3]; - } p; uint8_t trans[256]; uint32_t len, id; int i; @@ -210,15 +206,7 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height, case MAKE_ID('P','L','T','E'): PaletteSize = MIN (len / 3, 256); StartOfPalette = (uint32_t)lump.Tell(); - lump.Read (p.pngpal, PaletteSize * 3); - if (PaletteSize * 3 != (int)len) - { - lump.Seek (len - PaletteSize * 3, FileReader::SeekCur); - } - for (i = PaletteSize - 1; i >= 0; --i) - { - p.palette[i] = MAKERGB(p.pngpal[i][0], p.pngpal[i][1], p.pngpal[i][2]); - } + lump.Seek(len, FileReader::SeekCur); break; case MAKE_ID('t','R','N','S'): @@ -248,9 +236,6 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height, { bMasked = true; PaletteSize = 256; - PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize); - memcpy (PaletteMap, GPalette.GrayMap, 256); - PaletteMap[NonPaletteTrans[0]] = 0; } else { @@ -259,14 +244,11 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height, break; case 3: // Paletted - PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize); - MakeRemap ((uint32_t*)GPalette.BaseColors, p.palette, PaletteMap, trans, PaletteSize); for (i = 0; i < PaletteSize; ++i) { if (trans[i] == 0) { bMasked = true; - PaletteMap[i] = 0; } } break; @@ -281,6 +263,87 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, int width, int height, } } +void FPNGTexture::SetupPalette(FileReader &lump) +{ + union + { + uint32_t palette[256]; + uint8_t pngpal[256][3]; + } p; + uint8_t trans[256]; + uint32_t len, id; + int i; + + auto pos = lump.Tell(); + + memset(trans, 255, 256); + + // Parse pre-IDAT chunks. I skip the CRCs. Is that bad? + lump.Seek(33, FileReader::SeekSet); + + lump.Read(&len, 4); + lump.Read(&id, 4); + while (id != MAKE_ID('I', 'D', 'A', 'T') && id != MAKE_ID('I', 'E', 'N', 'D')) + { + len = BigLong((unsigned int)len); + switch (id) + { + default: + lump.Seek(len, FileReader::SeekCur); + break; + + case MAKE_ID('P', 'L', 'T', 'E'): + lump.Read(p.pngpal, PaletteSize * 3); + if (PaletteSize * 3 != (int)len) + { + lump.Seek(len - PaletteSize * 3, FileReader::SeekCur); + } + for (i = PaletteSize - 1; i >= 0; --i) + { + p.palette[i] = MAKERGB(p.pngpal[i][0], p.pngpal[i][1], p.pngpal[i][2]); + } + break; + + case MAKE_ID('t', 'R', 'N', 'S'): + lump.Read(trans, len); + break; + } + lump.Seek(4, FileReader::SeekCur); // Skip CRC + lump.Read(&len, 4); + id = MAKE_ID('I', 'E', 'N', 'D'); + lump.Read(&id, 4); + } + StartOfIDAT = (uint32_t)lump.Tell() - 8; + + switch (ColorType) + { + case 0: // Grayscale + if (HaveTrans && NonPaletteTrans[0] < 256) + { + PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize); + memcpy(PaletteMap, GPalette.GrayMap, 256); + PaletteMap[NonPaletteTrans[0]] = 0; + } + break; + + case 3: // Paletted + PaletteMap = (uint8_t*)ImageArena.Alloc(PaletteSize); + MakeRemap((uint32_t*)GPalette.BaseColors, p.palette, PaletteMap, trans, PaletteSize); + for (i = 0; i < PaletteSize; ++i) + { + if (trans[i] == 0) + { + PaletteMap[i] = 0; + } + } + break; + + default: + break; + } + lump.Seek(pos, FileReader::SeekSet); +} + //========================================================================== // // @@ -336,6 +399,7 @@ TArray FPNGTexture::CreatePalettedPixels(int conversion) { if (conversion != luminance) { + if (!PaletteMap) SetupPalette(lfr); ImageHelpers::FlipSquareBlockRemap (Pixels.Data(), Width, PaletteMap); } else if (ColorType == 0) @@ -354,6 +418,7 @@ TArray FPNGTexture::CreatePalettedPixels(int conversion) TArray newpix(Width*Height, true); if (conversion != luminance) { + if (!PaletteMap) SetupPalette(lfr); ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap); } else if (ColorType == 0) @@ -408,6 +473,7 @@ TArray FPNGTexture::CreatePalettedPixels(int conversion) case 4: // Grayscale + Alpha pitch = Width * 2; backstep = Height * pitch - 2; + if (!PaletteMap) SetupPalette(lfr); for (x = Width; x > 0; --x) { for (y = Height; y > 0; --y) diff --git a/src/d_main.cpp b/src/d_main.cpp index e86b83c38c..78225f582c 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -3385,6 +3385,7 @@ static int D_DoomMain_Internal (void) StartScreen->Progress(); V_InitFonts(); + V_LoadTranslations(); UpdateGenericUI(false); // [CW] Parse any TEAMINFO lumps. @@ -3545,6 +3546,9 @@ static int D_DoomMain_Internal (void) V_Init2(); twod->fullscreenautoaspect = gameinfo.fullscreenautoaspect; + // Initialize the size of the 2D drawer so that an attempt to access it outside the draw code won't crash. + twod->Begin(screen->GetWidth(), screen->GetHeight()); + twod->End(); UpdateJoystickMenu(NULL); UpdateVRModes(); From 192ea40634735e21203dd930ffd5b69e8e20a6ef Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 4 May 2020 21:24:36 +0200 Subject: [PATCH 154/220] - fixed order of multipatch texture initialization. This didn't play well with hires replacements - the texture size needs to be set as early as possible. --- src/common/textures/gametexture.h | 4 ++++ src/common/textures/multipatchtexturebuilder.cpp | 12 ++++++------ src/common/textures/texturemanager.cpp | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 3b2b690293..31864f9eba 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -240,6 +240,10 @@ public: if (int(ScaleY * h) != TexelHeight) ScaleY += (1 / 65536.); } + void SetBase(FTexture* Tex) + { + Base = Tex; + } void SetOffsets(int which, int x, int y) { LeftOffset[which] = x; diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index fcd12bac5d..46447f86d7 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -138,19 +138,18 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u { buildinfo.texture = new FGameTexture(nullptr, buildinfo.Name); buildinfo.texture->SetUseType(usetype); + buildinfo.texture->SetSize(buildinfo.Width, buildinfo.Height); buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); // These are needed for construction of other multipatch textures. buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); + buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X); + buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning); + buildinfo.texture->SetNoDecals(buildinfo.bNoDecals); TexMan.AddGameTexture(buildinfo.texture); } void FMultipatchTextureBuilder::AddImageToTexture(FImageTexture *tex, BuildInfo& buildinfo) { - buildinfo.texture->Setup(tex); - buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); - buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); - buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X); - buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning); - buildinfo.texture->SetNoDecals(buildinfo.bNoDecals); + buildinfo.texture->SetBase(tex); calcShouldUpscale(buildinfo.texture); // calculate this once at insertion } @@ -874,6 +873,7 @@ void FMultipatchTextureBuilder::ResolveAllPatches() for (int i = BuiltTextures.Size()-1; i>= 0; i--) { auto &buildinfo = BuiltTextures[i]; + bool hasEmpty = false; for (unsigned j = 0; j < buildinfo.Inits.Size(); j++) diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 80458a6ab8..eac5f30081 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -625,8 +625,9 @@ void FTextureManager::AddHiresTextures (int wadnum) auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override); gtex->SetWorldPanning(true); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); - gtex->SetOffsets(0, oldtex->GetTexelLeftOffset(0), oldtex->GetTexelTopOffset(0)); - gtex->SetOffsets(1, oldtex->GetTexelLeftOffset(1), oldtex->GetTexelTopOffset(1)); + + gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); + gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY())); ReplaceTexture(tlist[i], gtex, true); } } From c6cc76390766f5f6915c97b633995afc09f29435 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 4 May 2020 22:14:50 +0200 Subject: [PATCH 155/220] - fixed: screen resolution changes did not notify the 2D drawer. --- src/common/rendering/v_video.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/rendering/v_video.cpp b/src/common/rendering/v_video.cpp index 49a843414a..9a4b455f85 100644 --- a/src/common/rendering/v_video.cpp +++ b/src/common/rendering/v_video.cpp @@ -289,6 +289,9 @@ void V_UpdateModeSize (int width, int height) void V_OutputResized (int width, int height) { V_UpdateModeSize(width, height); + // set new resolution in 2D drawer + twod->Begin(screen->GetWidth(), screen->GetHeight()); + twod->End(); setsizeneeded = true; C_NewModeAdjust(); if (sysCallbacks && sysCallbacks->OnScreenSizeChanged) From 0cf967dc0637a86eb6fcb239528ff78e7e6686f5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 4 May 2020 22:15:18 +0200 Subject: [PATCH 156/220] - fixed wrong order of actions on shadow map updater. --- src/rendering/hwrenderer/hw_entrypoint.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index b7e6916058..e1ad075a37 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -111,10 +111,10 @@ sector_t* RenderViewpoint(FRenderViewpoint& mainvp, AActor* camera, IntRect* bou if (mainview && toscreen) { screen->SetAABBTree(camera->Level->aabbTree); - screen->UpdateShadowMap(); screen->mShadowMap.SetCollectLights([=] { CollectLights(camera->Level); }); + screen->UpdateShadowMap(); } // Update the attenuation flag of all light defaults for each viewpoint. From 50e0353668738c54e7f3e6bbaf6bf3f399e368fb Mon Sep 17 00:00:00 2001 From: Nemrtvi <26684396+Nemrtvi@users.noreply.github.com> Date: Wed, 6 May 2020 10:55:44 +0200 Subject: [PATCH 157/220] =?UTF-8?q?Revised=20Serbian=20characters=20=D0=8B?= =?UTF-8?q?/=D0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/doom.id/fonts/bigfont/0402.lmp | Bin 281 -> 301 bytes .../filter/doom.id/fonts/bigfont/040B.lmp | Bin 279 -> 297 bytes .../filter/doom.id/fonts/bigupper/0402.lmp | Bin 376 -> 404 bytes .../filter/doom.id/fonts/bigupper/040B.lmp | Bin 368 -> 397 bytes .../filter/doom.id/fonts/bigupper/0452.lmp | Bin 281 -> 301 bytes .../filter/doom.id/fonts/bigupper/045B.lmp | Bin 279 -> 297 bytes 6 files changed, 0 insertions(+), 0 deletions(-) diff --git a/wadsrc_extra/static/filter/doom.id/fonts/bigfont/0402.lmp b/wadsrc_extra/static/filter/doom.id/fonts/bigfont/0402.lmp index a00a09d09988ad747ef8e578264644a5d6582d23..e159c4c17faf44240992bdb8e1e3cd16c17e9905 100644 GIT binary patch literal 301 zcmYk0%MHRX3_y)k3Wp+b<<2l18%0qS5-Acw9Ks5$zzVFu3ar2itiS-}IpOE(RnBwl zcqyG|Y{0-4j&OoAT;K{fxWfaUAQO=VtY8h&~m zHhzS)+;Kl)eBg`W+hXXAt`06U^toXE#DIwG5fAU7T1yDOM>KP-`s8#6Jp|*1P%1O7 Qk?StgmfR=REu9+U3uSm*X#fBK literal 281 zcmYL@!3hE}5Je-p=CUC6o6o5Ru+Y+z!q%57Hq*5Y{3>Rz(f4WX7$4h!z1&P zm1h6wIYT`o6jn!gySTPbq2UF z3FkWGFD!ek1piyH*rjePE~WW7CXv|J4ubI93+=1Omj|Xm2Z%I8qWo{i z_STF>;{Xs`gma&9+X=RnlhK@neSg5je4*-vd6)g!3Gd;n3RAt0 IBX#-77m@{5{{R30 diff --git a/wadsrc_extra/static/filter/doom.id/fonts/bigupper/0402.lmp b/wadsrc_extra/static/filter/doom.id/fonts/bigupper/0402.lmp index 4f72414a26a931d8cd3dcc9177d4c6449f546c1a..23ca1421525be18a0f18e97e991f00f703e200e1 100644 GIT binary patch literal 404 zcmZ9GJx&BM426Tx{y?+Mb{v93aDj&E3sR6^{>Xa#vv{rg@T!CJ{t)&iPLxib+)wz079Cwx<$rL`%1| z&K{cUu%ajz&%I%2vq38cZ6X_*L|-w2LD=PtB S6^h=uS;tcN)V96uHtiRG%7Cu` literal 376 zcmZ9I%?$z}5QQ=E_hjP9A}qoZ7Fh%wHe@%RIPBRXEW#oz!Xhlf4%Rp0E(a(1;N|5F z1MJjRaaG^~uAm1ua0d_Y1TXLgA26ROwFd`q1U2YD57Z+6YGCEsF6Td`JMp$TiyGtD z2E|@VDaJ^IC5>K{5(Ve1v!)7@7r3l7TI=Fj%bi3a(A295(+p9$6=s+u9wJgQ*A_38 w`0a z9`I53?sPwUGa2d#GI$4{;0v6=1zf>5_yND5-x+fNPv9B601w{42RH%KmAfhYx zBAZ)oDy2p1@Ay>1oT|ncL%^eJZdMKAz4LCFWy=ZW++wZ$%Q?r+5JbY(YXi2uCcacP zV=0R=r(v~@HmlvL5jMrm3acr)b#I%JqF_E%yAf5aj7fP0ZT5mIWQKisgl&%F`hj~i LB_22Q>~E?!ga>`U literal 368 zcmZ9G%?$z}5QXvJ>UwY!ORxxw@U&#Z0uF@iMlW;lY!Mb=5f)()7GVeYV1HtqTx7mDn;QYaD}em3a;P^uHXs|AQJzisUCdC@p1Pj zE2@a-6E^5uumfjs0Ry;#8@Pi9c!C#rgK|c+2DH#rAr9uK8mLmOWwfzp!KtL3L~U#h zte=Fn4eBq9IGlL*J2ANBW(-cD@i}4Dw#yj|;iOaEXAzfsVb2GMqEz*Q$UL8%NRN40 NV5yBCE9WUad;xMwS-JoK diff --git a/wadsrc_extra/static/filter/doom.id/fonts/bigupper/045B.lmp b/wadsrc_extra/static/filter/doom.id/fonts/bigupper/045B.lmp index 4687f235651967ee302bc14ac820c00e08d12673..cd1b9de37475c79ea0c97281d63db0e87a639e98 100644 GIT binary patch literal 297 zcmYL@%?ScA5JpFER}Xs-3$PxK8$t*%fd!AT1zWHMTd)NiumM}J0WT8YB&;U9FyEK? z+sGgypR(sQaDWq>;R08GWLuzuZagjCSXcmpuBRsPcJJjx)G|ihW`AsJH+DJuo&Uu}y UVhYX&72OJvLedTUzKtRL0`J*fzyJUM literal 279 zcmYL^;RymU422`=c|Q(a%D=*ua)!|Ap@>2za0ORz1y^tZS8xRf@R!urYpa1TJRW%o zSx`enpRhzU2&x=NY%1U|TsE#X;EjJ4{Sxs$Q5kSs$J77P_i1 K)%!S7mruT~;8^ Date: Mon, 30 Mar 2020 14:27:36 +0300 Subject: [PATCH 158/220] Add optional direction parameters for SprayDecal and its A_SprayDecal zscript counterpart --- src/playsim/a_decals.cpp | 21 +++++++++++++++------ src/playsim/a_sharedglobal.h | 2 +- src/playsim/p_actionfunctions.cpp | 5 ++++- wadsrc/static/zscript/actors/actor.zs | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/playsim/a_decals.cpp b/src/playsim/a_decals.cpp index fc712a5d85..1eb5a588e2 100644 --- a/src/playsim/a_decals.cpp +++ b/src/playsim/a_decals.cpp @@ -830,14 +830,23 @@ DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, doubl // //---------------------------------------------------------------------------- -void SprayDecal(AActor *shooter, const char *name, double distance) +void SprayDecal(AActor *shooter, const char *name, double distance, double DirX, double DirY, double DirZ) { FTraceResults trace; - - DAngle ang = shooter->Angles.Yaw; - DAngle pitch = shooter->Angles.Pitch; - double c = pitch.Cos(); - DVector3 vec(c * ang.Cos(), c * ang.Sin(), -pitch.Sin()); + DVector3 vec; + //use new behavior only if directional vector not equal to zero vector + if (DirX != 0 || DirY != 0 || DirZ != 0) + { + vec = DVector3(DirX, DirY, DirZ); + } + + else + { + DAngle ang = shooter->Angles.Yaw; + DAngle pitch = shooter->Angles.Pitch; + double c = pitch.Cos(); + vec = DVector3(c * ang.Cos(), c * ang.Sin(), -pitch.Sin()); + } if (Trace(shooter->PosPlusZ(shooter->Height / 2), shooter->Sector, vec, distance, 0, ML_BLOCKEVERYTHING, shooter, trace, TRACE_NoSky)) { diff --git a/src/playsim/a_sharedglobal.h b/src/playsim/a_sharedglobal.h index 9396b10a80..1246255ea7 100644 --- a/src/playsim/a_sharedglobal.h +++ b/src/playsim/a_sharedglobal.h @@ -12,7 +12,7 @@ class DBaseDecal; struct SpreadInfo; DBaseDecal *ShootDecal(FLevelLocals *Level, const FDecalTemplate *tpl, sector_t *sec, double x, double y, double z, DAngle angle, double tracedist, bool permanent); -void SprayDecal(AActor *shooter, const char *name,double distance = 172.); +void SprayDecal(AActor *shooter, const char *name,double distance = 172., double DirX = 0., double DirY = 0., double DirZ = 0.); class DBaseDecal : public DThinker { diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index 78dce58526..047aed2a50 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -4917,7 +4917,10 @@ DEFINE_ACTION_FUNCTION(AActor, A_SprayDecal) PARAM_SELF_PROLOGUE(AActor); PARAM_STRING(name); PARAM_FLOAT(dist); - SprayDecal(self, name, dist); + PARAM_FLOAT(DirX); + PARAM_FLOAT(DirY); + PARAM_FLOAT(DirZ); + SprayDecal(self, name, dist, DirX, DirY, DirZ); return 0; } diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 27a929fdd4..28dd0b2953 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1157,7 +1157,7 @@ class Actor : Thinker native native bool A_SetVisibleRotation(double anglestart = 0, double angleend = 0, double pitchstart = 0, double pitchend = 0, int flags = 0, int ptr = AAPTR_DEFAULT); native void A_SetTranslation(name transname); native bool A_SetSize(double newradius = -1, double newheight = -1, bool testpos = false); - native void A_SprayDecal(String name, double dist = 172); + native void A_SprayDecal(String name, double dist = 172, double DirX = 0, double DirY = 0, double DirZ = 0); native void A_SetMugshotState(String name); native void CopyBloodColor(Actor other); From 0e9ca3c850668441b1175955e2c8570802bc2d22 Mon Sep 17 00:00:00 2001 From: Mekboss Date: Mon, 30 Mar 2020 18:52:27 +0300 Subject: [PATCH 159/220] Replace function variables to DVector3 --- src/playsim/a_decals.cpp | 6 +++--- src/playsim/a_sharedglobal.h | 2 +- src/playsim/p_actionfunctions.cpp | 2 +- wadsrc/static/zscript/actors/actor.zs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/playsim/a_decals.cpp b/src/playsim/a_decals.cpp index 1eb5a588e2..03fd79ebd7 100644 --- a/src/playsim/a_decals.cpp +++ b/src/playsim/a_decals.cpp @@ -830,14 +830,14 @@ DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, doubl // //---------------------------------------------------------------------------- -void SprayDecal(AActor *shooter, const char *name, double distance, double DirX, double DirY, double DirZ) +void SprayDecal(AActor *shooter, const char *name, double distance, DVector3 Dir) { FTraceResults trace; DVector3 vec; //use new behavior only if directional vector not equal to zero vector - if (DirX != 0 || DirY != 0 || DirZ != 0) + if (!Dir.isZero() ) { - vec = DVector3(DirX, DirY, DirZ); + vec = Dir; } else diff --git a/src/playsim/a_sharedglobal.h b/src/playsim/a_sharedglobal.h index 1246255ea7..0ca4673b9d 100644 --- a/src/playsim/a_sharedglobal.h +++ b/src/playsim/a_sharedglobal.h @@ -12,7 +12,7 @@ class DBaseDecal; struct SpreadInfo; DBaseDecal *ShootDecal(FLevelLocals *Level, const FDecalTemplate *tpl, sector_t *sec, double x, double y, double z, DAngle angle, double tracedist, bool permanent); -void SprayDecal(AActor *shooter, const char *name,double distance = 172., double DirX = 0., double DirY = 0., double DirZ = 0.); +void SprayDecal(AActor *shooter, const char *name,double distance = 172., DVector3 Dir = (0, 0, 0) ); class DBaseDecal : public DThinker { diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index 047aed2a50..c1a2015afb 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -4920,7 +4920,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_SprayDecal) PARAM_FLOAT(DirX); PARAM_FLOAT(DirY); PARAM_FLOAT(DirZ); - SprayDecal(self, name, dist, DirX, DirY, DirZ); + SprayDecal(self, name, dist, DVector3(DirX, DirY, DirZ) ); return 0; } diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 28dd0b2953..02aaab2052 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1157,7 +1157,7 @@ class Actor : Thinker native native bool A_SetVisibleRotation(double anglestart = 0, double angleend = 0, double pitchstart = 0, double pitchend = 0, int flags = 0, int ptr = AAPTR_DEFAULT); native void A_SetTranslation(name transname); native bool A_SetSize(double newradius = -1, double newheight = -1, bool testpos = false); - native void A_SprayDecal(String name, double dist = 172, double DirX = 0, double DirY = 0, double DirZ = 0); + native void A_SprayDecal(String name, double dist = 172, vector3 Dir = (0, 0, 0) ); native void A_SetMugshotState(String name); native void CopyBloodColor(Actor other); From 4807f4240b7e972c05ca47770f83619cde9a8bbf Mon Sep 17 00:00:00 2001 From: Mekboss Date: Tue, 7 Apr 2020 23:11:49 +0300 Subject: [PATCH 160/220] Fix MSVS compile bug and add offset parameter for SprayDecal --- src/playsim/a_decals.cpp | 31 ++++++++++++++++++--------- src/playsim/a_sharedglobal.h | 2 +- src/playsim/p_actionfunctions.cpp | 11 ++++++---- wadsrc/static/zscript/actors/actor.zs | 2 +- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/playsim/a_decals.cpp b/src/playsim/a_decals.cpp index 03fd79ebd7..b9e54d25ab 100644 --- a/src/playsim/a_decals.cpp +++ b/src/playsim/a_decals.cpp @@ -830,25 +830,36 @@ DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, doubl // //---------------------------------------------------------------------------- -void SprayDecal(AActor *shooter, const char *name, double distance, DVector3 Dir) +void SprayDecal(AActor *shooter, const char *name, double distance, DVector3 offset, DVector3 direction) { + //just in case + if (!shooter) + return; + FTraceResults trace; - DVector3 vec; - //use new behavior only if directional vector not equal to zero vector - if (!Dir.isZero() ) - { - vec = Dir; - } - + DVector3 off(0, 0, 0), dir(0, 0, 0); + + //use vanilla offset only if "custom" equal to zero + if (offset.isZero() ) + off = shooter->PosPlusZ(shooter->Height / 2); + else + off = shooter->Pos() + offset; + + //same for direction + if (direction.isZero() ) { DAngle ang = shooter->Angles.Yaw; DAngle pitch = shooter->Angles.Pitch; double c = pitch.Cos(); - vec = DVector3(c * ang.Cos(), c * ang.Sin(), -pitch.Sin()); + dir = DVector3(c * ang.Cos(), c * ang.Sin(), -pitch.Sin()); } + + else + dir = direction; - if (Trace(shooter->PosPlusZ(shooter->Height / 2), shooter->Sector, vec, distance, 0, ML_BLOCKEVERYTHING, shooter, trace, TRACE_NoSky)) + + if (Trace(off, shooter->Sector, dir, distance, 0, ML_BLOCKEVERYTHING, shooter, trace, TRACE_NoSky)) { if (trace.HitType == TRACE_HitWall) { diff --git a/src/playsim/a_sharedglobal.h b/src/playsim/a_sharedglobal.h index 0ca4673b9d..955d8d9002 100644 --- a/src/playsim/a_sharedglobal.h +++ b/src/playsim/a_sharedglobal.h @@ -12,7 +12,7 @@ class DBaseDecal; struct SpreadInfo; DBaseDecal *ShootDecal(FLevelLocals *Level, const FDecalTemplate *tpl, sector_t *sec, double x, double y, double z, DAngle angle, double tracedist, bool permanent); -void SprayDecal(AActor *shooter, const char *name,double distance = 172., DVector3 Dir = (0, 0, 0) ); +void SprayDecal(AActor *shooter, const char *name,double distance = 172., DVector3 offset = DVector3(0., 0., 0.), DVector3 direction = DVector3(0., 0., 0.) ); class DBaseDecal : public DThinker { diff --git a/src/playsim/p_actionfunctions.cpp b/src/playsim/p_actionfunctions.cpp index c1a2015afb..5983e77a98 100644 --- a/src/playsim/p_actionfunctions.cpp +++ b/src/playsim/p_actionfunctions.cpp @@ -4917,10 +4917,13 @@ DEFINE_ACTION_FUNCTION(AActor, A_SprayDecal) PARAM_SELF_PROLOGUE(AActor); PARAM_STRING(name); PARAM_FLOAT(dist); - PARAM_FLOAT(DirX); - PARAM_FLOAT(DirY); - PARAM_FLOAT(DirZ); - SprayDecal(self, name, dist, DVector3(DirX, DirY, DirZ) ); + PARAM_FLOAT(offset_x); + PARAM_FLOAT(offset_y); + PARAM_FLOAT(offset_z); + PARAM_FLOAT(direction_x); + PARAM_FLOAT(direction_y); + PARAM_FLOAT(direction_z); + SprayDecal(self, name, dist, DVector3(offset_x, offset_y, offset_z), DVector3(direction_x, direction_y, direction_z) ); return 0; } diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 02aaab2052..b80415cbde 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -1157,7 +1157,7 @@ class Actor : Thinker native native bool A_SetVisibleRotation(double anglestart = 0, double angleend = 0, double pitchstart = 0, double pitchend = 0, int flags = 0, int ptr = AAPTR_DEFAULT); native void A_SetTranslation(name transname); native bool A_SetSize(double newradius = -1, double newheight = -1, bool testpos = false); - native void A_SprayDecal(String name, double dist = 172, vector3 Dir = (0, 0, 0) ); + native void A_SprayDecal(String name, double dist = 172, vector3 offset = (0, 0, 0), vector3 direction = (0, 0, 0) ); native void A_SetMugshotState(String name); native void CopyBloodColor(Actor other); From 0f0768652ae7f209c805048e2627c00df53b80c7 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 2 May 2020 09:20:37 -0400 Subject: [PATCH 161/220] - force player respawn to call up the player's default class settings before determining where to respawn the player --- src/g_game.cpp | 19 ++++++++++++++- src/g_levellocals.h | 1 + src/playsim/p_mobj.cpp | 53 +++++++++++++++++++++++------------------- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/g_game.cpp b/src/g_game.cpp index 09445e3136..d5662767c5 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1709,7 +1709,24 @@ void FLevelLocals::DoReborn (int playernum, bool freshbot) } else { - bool isUnfriendly = players[playernum].mo && !(players[playernum].mo->flags & MF_FRIENDLY); + bool isUnfriendly; + + PlayerSpawnPickClass(playernum); + + // this condition should never be false + assert(players[playernum].cls != NULL); + + if (players[playernum].cls != NULL) + { + isUnfriendly = !(GetDefaultByType(players[playernum].cls)->flags & MF_FRIENDLY); + DPrintf(DMSG_NOTIFY, "Player class IS defined: unfriendly is %i\n", isUnfriendly); + } + else + { + // we shouldn't be here, but if we are, get the player's current status + isUnfriendly = players[playernum].mo && !(players[playernum].mo->flags & MF_FRIENDLY); + DPrintf(DMSG_NOTIFY, "Player class NOT defined: unfriendly is %i\n", isUnfriendly); + } // respawn at the start // first disassociate the corpse diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 40dc85c203..cfde061189 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -165,6 +165,7 @@ private: void ReadOnePlayer(FSerializer &arc, bool skipload); void ReadMultiplePlayers(FSerializer &arc, int numPlayers, int numPlayersNow, bool skipload); void SerializeSounds(FSerializer &arc); + void PlayerSpawnPickClass (int playernum); public: void SnapshotLevel(); diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index c98bc9c7b1..74d311551b 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -4996,31 +4996,9 @@ void StaticPointerSubstitution(AActor* old, AActor* notOld) } } - - -AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flags) +void FLevelLocals::PlayerSpawnPickClass (int playernum) { - player_t *p; - AActor *mobj, *oldactor; - uint8_t state; - DVector3 spawn; - DAngle SpawnAngle; - - if (mthing == NULL) - { - return NULL; - } - // not playing? - if ((unsigned)playernum >= (unsigned)MAXPLAYERS || !PlayerInGame(playernum) ) - return NULL; - - // Old lerp data needs to go - if (playernum == consoleplayer) - { - P_PredictionLerpReset(); - } - - p = Players[playernum]; + auto p = Players[playernum]; if (p->cls == NULL) { @@ -5049,6 +5027,33 @@ AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flag } p->cls = PlayerClasses[p->CurrentPlayerClass].Type; } +} + +AActor *FLevelLocals::SpawnPlayer (FPlayerStart *mthing, int playernum, int flags) +{ + player_t *p; + AActor *mobj, *oldactor; + uint8_t state; + DVector3 spawn; + DAngle SpawnAngle; + + if (mthing == NULL) + { + return NULL; + } + // not playing? + if ((unsigned)playernum >= (unsigned)MAXPLAYERS || !PlayerInGame(playernum) ) + return NULL; + + // Old lerp data needs to go + if (playernum == consoleplayer) + { + P_PredictionLerpReset(); + } + + p = Players[playernum]; + + PlayerSpawnPickClass(playernum); if (( dmflags2 & DF2_SAME_SPAWN_SPOT ) && ( p->playerstate == PST_REBORN ) && From 6e3ec9625021bef1acefc926a0ce49fbbde76740 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Wed, 6 May 2020 00:04:05 -0400 Subject: [PATCH 162/220] - export common formulae to functions instead of copy-pasting them - screen bevel now enlarges also when screenblocks <= 11 - make intermission and status bar scaling game-specific in the config - add scaling customization for classic ui flat scaling - make screen border flat scale up - inter_classic_scaling now defaults to true - fixed: last commit I accidentally left hardcoded testing values and did not change them back to check for the texture's original size - implement cvar 'inter_classic_scaling' to render the intermission flat as if it were 320x200 --- src/common/2d/v_2ddrawer.cpp | 33 +++++++++++++ src/common/2d/v_2ddrawer.h | 2 + src/common/2d/v_draw.cpp | 13 +++-- src/g_statusbar/shared_sbar.cpp | 79 ++++++++++++++++++++++++------- src/intermission/intermission.cpp | 4 +- 5 files changed, 107 insertions(+), 24 deletions(-) diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 665ea3d8ca..9d89d3e663 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -37,12 +37,15 @@ #include "vm.h" #include "c_cvars.h" #include "v_draw.h" +#include "v_video.h" #include "fcolormap.h" static F2DDrawer drawer; F2DDrawer* twod = &drawer; EXTERN_CVAR(Float, transsouls) +CVAR(Float, classic_scaling_factor, 1.0, CVAR_ARCHIVE) +CVAR(Float, classic_scaling_pixelaspect, 1.2, CVAR_ARCHIVE) IMPLEMENT_CLASS(DShape2DTransform, false, false) @@ -677,6 +680,19 @@ void F2DDrawer::AddPoly(FGameTexture* img, FVector4* vt, size_t vtcount, unsigne // //========================================================================== +float F2DDrawer::GetClassicFlatScalarWidth() +{ + float ar = 4.f / 3.f / (float)ActiveRatio((float)screen->GetWidth(), (float)screen->GetHeight()); + float sw = 320.f * classic_scaling_factor / (float)screen->GetWidth() / ar; + return sw; +} + +float F2DDrawer::GetClassicFlatScalarHeight() +{ + float sh = 240.f / classic_scaling_pixelaspect * classic_scaling_factor / (float)screen->GetHeight(); + return sh; +} + void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTexture *src, int local_origin, double flatscale) { float fU1, fU2, fV1, fV2; @@ -692,6 +708,10 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu float fs = 1.f / float(flatscale); bool flipc = false; + + float sw = GetClassicFlatScalarWidth(); + float sh = GetClassicFlatScalarHeight(); + switch (local_origin) { case 0: @@ -752,6 +772,19 @@ void F2DDrawer::AddFlatFill(int left, int top, int right, int bottom, FGameTextu fV1 = float(right - left) / (float)src->GetDisplayHeight() * fs; break; + case -1: // classic flat scaling + fU1 = float(left) / (float)src->GetDisplayWidth() * fs * sw; + fV1 = float(top) / (float)src->GetDisplayHeight() * fs * sh; + fU2 = float(right) / (float)src->GetDisplayWidth() * fs * sw; + fV2 = float(bottom) / (float)src->GetDisplayHeight() * fs * sh; + break; + + case -2: // classic scaling for screen bevel + fU1 = 0; + fV1 = 0; + fU2 = float(right - left) / (float)src->GetDisplayWidth() * fs * sw; + fV2 = float(bottom - top) / (float)src->GetDisplayHeight() * fs * sh; + break; } dg.mVertIndex = (int)mVertices.Reserve(4); auto ptr = &mVertices[dg.mVertIndex]; diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index f7a31ac79b..bd8797d4cf 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -174,6 +174,8 @@ private: void SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcolor, PalEntry &overlaycolor); public: + float GetClassicFlatScalarWidth(); + float GetClassicFlatScalarHeight(); void AddTexture(FGameTexture* img, DrawParms& parms); void AddShape(FGameTexture *img, DShape2D *shape, DrawParms &parms); void AddPoly(FGameTexture *texture, FVector2 *points, int npoints, diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index bc04333e0c..4a5853a34c 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -43,6 +43,7 @@ EXTERN_CVAR(Int, vid_aspect) EXTERN_CVAR(Int, uiscale) +CVAR(Bool, ui_screenborder_classic_scaling, true, CVAR_ARCHIVE) // Helper for ActiveRatio and CheckRatio. Returns the forced ratio type, or -1 if none. int ActiveFakeRatio(int width, int height) @@ -1161,10 +1162,11 @@ void FillBorder (F2DDrawer *drawer, FGameTexture *img) if (img != NULL) { - drawer->AddFlatFill(0, 0, Width, bordtop, img); // Top - drawer->AddFlatFill(0, bordtop, bordleft, Height - bordbottom, img); // Left - drawer->AddFlatFill(Width - bordright, bordtop, Width, Height - bordbottom, img); // Right - drawer->AddFlatFill(0, Height - bordbottom, Width, Height, img); // Bottom + int filltype = (ui_screenborder_classic_scaling) ? -1 : 0; + drawer->AddFlatFill(0, 0, Width, bordtop, img, filltype); // Top + drawer->AddFlatFill(0, bordtop, bordleft, Height - bordbottom, img, filltype); // Left + drawer->AddFlatFill(Width - bordright, bordtop, Width, Height - bordbottom, img, filltype); // Right + drawer->AddFlatFill(0, Height - bordbottom, Width, Height, img, filltype); // Bottom } else { @@ -1351,9 +1353,10 @@ DEFINE_ACTION_FUNCTION(_Screen, Dim) void DrawBorder (F2DDrawer *drawer, FTextureID picnum, int x1, int y1, int x2, int y2) { + int filltype = (ui_screenborder_classic_scaling) ? -1 : 0; if (picnum.isValid()) { - drawer->AddFlatFill (x1, y1, x2, y2, TexMan.GetGameTexture(picnum, false)); + drawer->AddFlatFill (x1, y1, x2, y2, TexMan.GetGameTexture(picnum, false), filltype); } else { diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index b639e67316..1de65415e8 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -89,6 +89,8 @@ EXTERN_CVAR (Bool, noisedebug) EXTERN_CVAR (Int, con_scaletext) EXTERN_CVAR(Bool, vid_fps) EXTERN_CVAR(Bool, inter_subtitles) +EXTERN_CVAR(Bool, ui_screenborder_classic_scaling) + CVAR(Int, hud_scale, 0, CVAR_ARCHIVE); CVAR(Bool, log_vgafont, false, CVAR_ARCHIVE) @@ -162,23 +164,53 @@ void V_DrawFrame(F2DDrawer* drawer, int left, int top, int width, int height) int right = left + width; int bottom = top + height; - // Draw top and bottom sides. - p = TexMan.GetGameTextureByName(border->t); - drawer->AddFlatFill(left, top - (int)p->GetDisplayHeight(), right, top, p, true); - p = TexMan.GetGameTextureByName(border->b); - drawer->AddFlatFill(left, bottom, right, bottom + (int)p->GetDisplayHeight(), p, true); + float sw = drawer->GetClassicFlatScalarWidth(); + float sh = drawer->GetClassicFlatScalarHeight(); - // Draw left and right sides. - p = TexMan.GetGameTextureByName(border->l); - drawer->AddFlatFill(left - (int)p->GetDisplayWidth(), top, left, bottom, p, true); - p = TexMan.GetGameTextureByName(border->r); - drawer->AddFlatFill(right, top, right + (int)p->GetDisplayWidth(), bottom, p, true); + if (!ui_screenborder_classic_scaling) + { + // Draw top and bottom sides. + p = TexMan.GetGameTextureByName(border->t); + drawer->AddFlatFill(left, top - (int)p->GetDisplayHeight(), right, top, p, true); + p = TexMan.GetGameTextureByName(border->b); + drawer->AddFlatFill(left, bottom, right, bottom + (int)p->GetDisplayHeight(), p, true); - // Draw beveled corners. - DrawTexture(drawer, TexMan.GetGameTextureByName(border->tl), left - offset, top - offset, TAG_DONE); - DrawTexture(drawer, TexMan.GetGameTextureByName(border->tr), left + width, top - offset, TAG_DONE); - DrawTexture(drawer, TexMan.GetGameTextureByName(border->bl), left - offset, top + height, TAG_DONE); - DrawTexture(drawer, TexMan.GetGameTextureByName(border->br), left + width, top + height, TAG_DONE); + // Draw left and right sides. + p = TexMan.GetGameTextureByName(border->l); + drawer->AddFlatFill(left - (int)p->GetDisplayWidth(), top, left, bottom, p, true); + p = TexMan.GetGameTextureByName(border->r); + drawer->AddFlatFill(right, top, right + (int)p->GetDisplayWidth(), bottom, p, true); + + // Draw beveled corners. + DrawTexture(drawer, TexMan.GetGameTextureByName(border->tl), left - offset, top - offset, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->tr), left + width, top - offset, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->bl), left - offset, top + height, TAG_DONE); + DrawTexture(drawer, TexMan.GetGameTextureByName(border->br), left + width, top + height, TAG_DONE); + } + else + { + // Draw top and bottom sides. + p = TexMan.GetGameTextureByName(border->t); + drawer->AddFlatFill(left, top - (int)(p->GetDisplayHeight() / sh), right, top, p, -2); + p = TexMan.GetGameTextureByName(border->b); + drawer->AddFlatFill(left, bottom, right, bottom + (int)(p->GetDisplayHeight() / sh), p, -2); + + // Draw left and right sides. + p = TexMan.GetGameTextureByName(border->l); + drawer->AddFlatFill(left - (int)(p->GetDisplayWidth() / sw), top, left, bottom, p, -2); + p = TexMan.GetGameTextureByName(border->r); + drawer->AddFlatFill(right, top, right + (int)(p->GetDisplayWidth() / sw), bottom, p, -2); + + // Draw beveled corners. + p = TexMan.GetGameTextureByName(border->tl); + drawer->AddFlatFill(left - (int)(p->GetDisplayWidth() / sw), top - (int)(p->GetDisplayHeight() / sh), left, top, p, -2); + p = TexMan.GetGameTextureByName(border->tr); + drawer->AddFlatFill(right, top - (int)(p->GetDisplayHeight() / sh), right + (int)(p->GetDisplayWidth() / sw), top, p, -2); + p = TexMan.GetGameTextureByName(border->bl); + drawer->AddFlatFill(left - (int)(p->GetDisplayWidth() / sw), bottom, left, bottom + (int)(p->GetDisplayHeight() / sh), p, -2); + p = TexMan.GetGameTextureByName(border->br); + drawer->AddFlatFill(right, bottom, right + (int)(p->GetDisplayWidth() / sw), bottom + (int)(p->GetDisplayHeight() / sh), p, -2); + } } DEFINE_ACTION_FUNCTION(_Screen, DrawFrame) @@ -1038,6 +1070,8 @@ void DBaseStatusBar::RefreshBackground () const auto tex = GetBorderTexture(primaryLevel); + float sh = twod->GetClassicFlatScalarHeight(); + if(!CompleteBorder) { if(y < twod->GetHeight()) @@ -1070,9 +1104,18 @@ void DBaseStatusBar::RefreshBackground () const FGameTexture *p = TexMan.GetGameTextureByName(gameinfo.Border.b); if (p != NULL) { - int h = int(0.5 + p->GetDisplayHeight()); - twod->AddFlatFill(0, y, x, y + h, p, true); - twod->AddFlatFill(x2, y, twod->GetWidth(), y + h, p, true); + if (!ui_screenborder_classic_scaling) + { + int h = int(0.5 + p->GetDisplayHeight()); + twod->AddFlatFill(0, y, x, y + h, p, true); + twod->AddFlatFill(x2, y, twod->GetWidth(), y + h, p, true); + } + else + { + int h = (int)((0.5f + p->GetDisplayHeight()) / sh); + twod->AddFlatFill(0, y, x, y + h, p, -2); + twod->AddFlatFill(x2, y, twod->GetWidth(), y + h, p, -2); + } } } } diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index f2d1609f2d..08c43a9e74 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -73,6 +73,8 @@ extern int NoWipe; CVAR(Bool, nointerscrollabort, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); CVAR(Bool, inter_subtitles, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); +CVAR(Bool, inter_classic_scaling, true, CVAR_ARCHIVE); + //========================================================================== // // This also gets used by the title loop. @@ -221,7 +223,7 @@ void DIntermissionScreen::Drawer () } else { - twod->AddFlatFill(0,0, twod->GetWidth(), twod->GetHeight(), TexMan.GetGameTexture(mBackground)); + twod->AddFlatFill(0,0, twod->GetWidth(), twod->GetHeight(), TexMan.GetGameTexture(mBackground), (inter_classic_scaling ? -1 : 0)); } } else From b70bc2b152d85dc98c352d7a8dabcdb00111cef3 Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Sat, 9 May 2020 16:16:45 -0500 Subject: [PATCH 163/220] Fixed an issue where multiple invulnerability powerups could cancel each other out from just one expiring. --- wadsrc/static/zscript/actors/inventory/powerups.zs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wadsrc/static/zscript/actors/inventory/powerups.zs b/wadsrc/static/zscript/actors/inventory/powerups.zs index 6ac852aba0..aaea851425 100644 --- a/wadsrc/static/zscript/actors/inventory/powerups.zs +++ b/wadsrc/static/zscript/actors/inventory/powerups.zs @@ -356,7 +356,7 @@ class PowerInvulnerable : Powerup { return; } - + Owner.bInvulnerable = true; if (Mode == 'Ghost') { if (!Owner.bShadow) From 079e7ee4e9760a66ca830d4c803075db293dfd90 Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Sat, 9 May 2020 16:44:23 -0500 Subject: [PATCH 164/220] Enforce the reflective flag as well. --- wadsrc/static/zscript/actors/inventory/powerups.zs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wadsrc/static/zscript/actors/inventory/powerups.zs b/wadsrc/static/zscript/actors/inventory/powerups.zs index aaea851425..157fab1b22 100644 --- a/wadsrc/static/zscript/actors/inventory/powerups.zs +++ b/wadsrc/static/zscript/actors/inventory/powerups.zs @@ -357,6 +357,10 @@ class PowerInvulnerable : Powerup return; } Owner.bInvulnerable = true; + if (Mode == 'Reflective') + { + Owner.bReflective = true; + } if (Mode == 'Ghost') { if (!Owner.bShadow) From 0631670a66800c7af47ac06e434b363c101620c6 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 18 May 2020 13:58:22 +0300 Subject: [PATCH 165/220] - restored warning about missing aiming camera target --- wadsrc/static/zscript/actors/shared/camera.zs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wadsrc/static/zscript/actors/shared/camera.zs b/wadsrc/static/zscript/actors/shared/camera.zs index 91923b1335..74d0a4b398 100644 --- a/wadsrc/static/zscript/actors/shared/camera.zs +++ b/wadsrc/static/zscript/actors/shared/camera.zs @@ -70,7 +70,7 @@ class AimingCamera : SecurityCamera tracer = it.Next (); if (tracer == NULL) { - //Printf ("AimingCamera %d: Can't find TID %d\n", tid, args[3]); + console.Printf ("AimingCamera %d: Can't find TID %d\n", tid, args[3]); } else { // Don't try for a new target upon losing this one. From 1fd2ea46d216398f44c4ec5ff73987843c74957f Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 18 May 2020 14:00:48 +0300 Subject: [PATCH 166/220] - fixed aiming camera that didn't follow target https://forum.zdoom.org/viewtopic.php?t=68600 --- wadsrc/static/zscript/actors/shared/camera.zs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wadsrc/static/zscript/actors/shared/camera.zs b/wadsrc/static/zscript/actors/shared/camera.zs index 74d0a4b398..d9e579284b 100644 --- a/wadsrc/static/zscript/actors/shared/camera.zs +++ b/wadsrc/static/zscript/actors/shared/camera.zs @@ -63,7 +63,7 @@ class AimingCamera : SecurityCamera args[2] = 0; Super.PostBeginPlay (); - MaxPitchChange = double(changepitch / TICRATE); + MaxPitchChange = double(changepitch) / TICRATE; Range /= TICRATE; ActorIterator it = Level.CreateActorIterator(args[3]); From dd40778c75796511804f66334ac2544a96e365eb Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Mon, 18 May 2020 17:48:10 +0300 Subject: [PATCH 167/220] - fixed map things erroneously treated as polyobject anchors/spots https://forum.zdoom.org/viewtopic.php?t=68601 --- src/maploader/polyobjects.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maploader/polyobjects.cpp b/src/maploader/polyobjects.cpp index 3c0a567adb..d1516e84b8 100644 --- a/src/maploader/polyobjects.cpp +++ b/src/maploader/polyobjects.cpp @@ -331,7 +331,7 @@ void MapLoader::PO_Init (void) TArray polythings; for (auto &mthing : MapThingsConverted) { - if (mthing.EdNum == 0 || mthing.EdNum == -1 || mthing.info == nullptr) continue; + if (mthing.EdNum == 0 || mthing.EdNum == -1 || mthing.info == nullptr || mthing.info->Type != nullptr) continue; FDoomEdEntry *mentry = mthing.info; switch (mentry->Special) From 53ea19c6a8cdc92a62985398f175f245f4439a8b Mon Sep 17 00:00:00 2001 From: Alexander Kromm Date: Mon, 18 May 2020 22:47:11 +0700 Subject: [PATCH 168/220] fix "'ictionary' is freed outside the GC process" warning --- src/common/scripting/core/dictionary.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/scripting/core/dictionary.cpp b/src/common/scripting/core/dictionary.cpp index b8dacd2bcd..b3d78d0cc3 100644 --- a/src/common/scripting/core/dictionary.cpp +++ b/src/common/scripting/core/dictionary.cpp @@ -43,7 +43,7 @@ void Dictionary::Serialize(FSerializer &arc) Dictionary *pointerToDeserializedDictionary; arc(key, pointerToDeserializedDictionary); Map.TransferFrom(pointerToDeserializedDictionary->Map); - delete pointerToDeserializedDictionary; + pointerToDeserializedDictionary->Destroy(); } } From 3f9b9314a06ce61dfbc804e192308b5d40287d21 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Thu, 21 May 2020 10:06:50 +0300 Subject: [PATCH 169/220] - added #include to fix compilation with MSVC 16.6.0 https://forum.zdoom.org/viewtopic.php?t=68641 --- src/common/audio/music/music.cpp | 2 +- src/common/utility/files_decompress.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/audio/music/music.cpp b/src/common/audio/music/music.cpp index 8a385b2919..2d9008021e 100644 --- a/src/common/audio/music/music.cpp +++ b/src/common/audio/music/music.cpp @@ -37,7 +37,7 @@ #include #include - +#include #include "i_sound.h" #include "i_music.h" diff --git a/src/common/utility/files_decompress.cpp b/src/common/utility/files_decompress.cpp index c14079b636..c79d762e69 100644 --- a/src/common/utility/files_decompress.cpp +++ b/src/common/utility/files_decompress.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "files.h" #include "templates.h" From 3dfb417f07afb444ba0161b9fc8d808168599735 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 22 May 2020 19:28:45 +0200 Subject: [PATCH 170/220] - attenuated lights for Strife. --- wadsrc_lights/static/filter/strife/gldefs.txt | 940 +++++++++++------- 1 file changed, 571 insertions(+), 369 deletions(-) diff --git a/wadsrc_lights/static/filter/strife/gldefs.txt b/wadsrc_lights/static/filter/strife/gldefs.txt index 7474486ba0..9234b2175f 100644 --- a/wadsrc_lights/static/filter/strife/gldefs.txt +++ b/wadsrc_lights/static/filter/strife/gldefs.txt @@ -9,89 +9,100 @@ flickerlight SPUFF1 { color 1.0 1.0 0.0 - size 6 - secondarySize 8 + size 9 + secondarySize 12 chance 0.8 + attenuate 1 } flickerlight SPUFF2 { color 1.0 0.8 0.0 - size 5 - secondarySize 6 + size 7 + secondarySize 9 chance 0.8 + attenuate 1 } flickerlight SPUFF3 { color 1.0 0.6 0.0 - size 8 - secondarySize 10 + size 12 + secondarySize 15 chance 0.8 + attenuate 1 } flickerlight SPUFF4 { color 0.8 0.8 1.0 - size 2 - secondarySize 4 + size 3 + secondarySize 6 chance 0.8 + attenuate 1 } flickerlight SPUFF5 { color 0.8 0.8 1.0 - size 4 - secondarySize 6 + size 6 + secondarySize 9 chance 0.8 + attenuate 1 } flickerlight SPUFF6 { color 0.6 0.6 1.0 - size 6 - secondarySize 8 + size 9 + secondarySize 12 chance 0.8 + attenuate 1 } flickerlight SPUFF7 { color 0.4 0.4 0.8 - size 7 - secondarySize 9 + size 10 + secondarySize 14 chance 0.8 + attenuate 1 } flickerlight SPUFF8 { color 1.0 1.0 0.0 - size 2 - secondarySize 4 + size 3 + secondarySize 6 chance 0.8 + attenuate 1 } flickerlight SPUFF9 { color 1.0 0.8 0.0 - size 3 - secondarySize 4 + size 4 + secondarySize 6 chance 0.8 + attenuate 1 } flickerlight SPUFF10 { color 1.0 0.6 0.0 - size 5 - secondarySize 6 + size 7 + secondarySize 9 chance 0.8 + attenuate 1 } flickerlight SPUFF11 { color 1.0 0.4 0.0 - size 7 - secondarySize 8 + size 10 + secondarySize 12 chance 0.8 + attenuate 1 } object StrifePuff @@ -113,41 +124,46 @@ object StrifePuff flickerlight SSPARK1 { color 0.5 0.5 1.0 - size 4 - secondarySize 6 + size 6 + secondarySize 9 chance 0.8 + attenuate 1 } flickerlight SSPARK2 { color 0.5 0.5 1.0 - size 6 - secondarySize 8 + size 9 + secondarySize 12 chance 0.8 + attenuate 1 } flickerlight SSPARK3 { color 0.4 0.4 1.0 - size 8 - secondarySize 10 + size 12 + secondarySize 15 chance 0.8 + attenuate 1 } flickerlight SSPARK4 { color 0.3 0.3 1.0 - size 6 - secondarySize 8 + size 9 + secondarySize 12 chance 0.8 + attenuate 1 } flickerlight SSPARK5 { color 0.2 0.2 1.0 - size 4 - secondarySize 6 + size 6 + secondarySize 9 chance 0.8 + attenuate 1 } object StrifeSpark @@ -172,49 +188,55 @@ object StrifeSpark flickerlight ARROWZAP1 { color 0.4 0.4 1.0 - size 8 - secondarySize 16 + size 12 + secondarySize 24 chance 0.4 + attenuate 1 } flickerlight ARROWZAP2 { color 0.45 0.45 1.0 - size 16 - secondarySize 24 + size 24 + secondarySize 36 chance 0.4 + attenuate 1 } flickerlight ARROWZAP3 { color 0.5 0.5 1.0 - size 24 - secondarySize 30 + size 36 + secondarySize 45 chance 0.4 + attenuate 1 } flickerlight ARROWZAP4 { color 0.6 0.6 1.0 - size 30 - secondarySize 36 + size 45 + secondarySize 54 chance 0.4 + attenuate 1 } flickerlight ARROWZAP5 { color 0.7 0.7 1.0 - size 36 - secondarySize 40 + size 54 + secondarySize 60 chance 0.4 + attenuate 1 } flickerlight ARROWZAP6 { color 0.8 0.8 1.0 - size 40 - secondarySize 42 + size 60 + secondarySize 43 chance 0.4 + attenuate 1 } object ElectricBolt @@ -231,64 +253,72 @@ object ElectricBolt pointlight MISSILE { color 1.0 0.7 0.0 - size 56 + size 84 offset -40 0 0 + attenuate 1 } flickerlight MISSILE_X1 { color 1.0 0.7 0.0 - size 56 - secondarySize 60 + size 84 + secondarySize 90 chance 0.3 + attenuate 1 } flickerlight MISSILE_X2 { color 1.0 0.65 0.0 - size 60 - secondarySize 64 + size 90 + secondarySize 96 chance 0.3 + attenuate 1 } flickerlight MISSILE_X3 { color 1.0 0.6 0.0 - size 64 - secondarySize 68 + size 96 + secondarySize 102 chance 0.3 + attenuate 1 } flickerlight MISSILE_X4 { color 1.0 0.6 0.0 - size 68 - secondarySize 72 + size 102 + secondarySize 108 chance 0.3 + attenuate 1 } flickerlight MISSILE_X5 { color 1.0 0.6 0.0 - size 72 - secondarySize 76 + size 108 + secondarySize 114 chance 0.3 + attenuate 1 } flickerlight MISSILE_X6 { color 1.0 0.6 0.0 - size 76 - secondarySize 80 + size 114 + secondarySize 120 chance 0.3 + attenuate 1 } flickerlight MISSILE_X7 { color 1.0 0.6 0.0 - size 80 - secondarySize 88 + size 120 + secondarySize 132 chance 0.3 + attenuate 1 } object MiniMissile @@ -308,37 +338,43 @@ object MiniMissile pointlight FLMMISSILE { color 1.0 0.7 0.0 - size 56 + size 84 + attenuate 1 } pointlight FLMMSL_X1 { color 1.0 0.7 0.0 - size 52 + size 78 + attenuate 1 } pointlight FLMMSL_X2 { color 0.8 0.56 0.0 - size 46 + size 69 + attenuate 1 } pointlight FLMMSL_X3 { color 0.6 0.42 0.0 - size 38 + size 57 + attenuate 1 } pointlight FLMMSL_X4 { color 0.4 0.28 0.0 - size 24 + size 36 + attenuate 1 } pointlight FLMMSL_X5 { color 0.2 0.14 0.0 - size 16 + size 24 + attenuate 1 } object FlameMissile @@ -358,49 +394,55 @@ object FlameMissile flickerlight MPUFFG { color 0.0 1.0 0.0 - size 6 - secondarySize 8 + size 9 + secondarySize 12 chance 0.8 + attenuate 1 } flickerlight MPUFF1 { color 1.0 1.0 1.0 - size 6 - secondarySize 8 + size 9 + secondarySize 12 chance 0.8 + attenuate 1 } flickerlight MPUFF2 { color 1.0 1.0 1.0 - size 8 - secondarySize 10 + size 12 + secondarySize 15 chance 0.8 + attenuate 1 } flickerlight MPUFF3 { color 1.0 1.0 1.0 - size 10 - secondarySize 12 + size 15 + secondarySize 18 chance 0.8 + attenuate 1 } flickerlight MPUFF4 { color 1.0 1.0 1.0 - size 12 - secondarySize 14 + size 18 + secondarySize 21 chance 0.8 + attenuate 1 } flickerlight MPUFF5 { color 1.0 1.0 1.0 - size 14 - secondarySize 16 + size 21 + secondarySize 24 chance 0.8 + attenuate 1 } object MaulerPuff @@ -417,47 +459,53 @@ object MaulerPuff pointlight MTORPEDO { color 0.0 1.0 0.0 - size 80 + size 120 + attenuate 1 } flickerlight MTORP_X1 { color 0.5 1.0 0.5 - size 80 - secondarySize 84 + size 120 + secondarySize 126 chance 0.3 + attenuate 1 } flickerlight MTORP_X2 { color 0.4 1.0 0.4 - size 84 - secondarySize 88 + size 126 + secondarySize 132 chance 0.3 + attenuate 1 } flickerlight MTORP_X3 { color 0.2 1.0 0.2 - size 88 - secondarySize 92 + size 132 + secondarySize 138 chance 0.3 + attenuate 1 } flickerlight MTORP_X4 { color 0.125 0.5 0.125 - size 92 - secondarySize 96 + size 138 + secondarySize 144 chance 0.3 + attenuate 1 } flickerlight MTORP_X5 { color 0.0 0.25 0.0 - size 96 - secondarySize 100 + size 144 + secondarySize 150 chance 0.3 + attenuate 1 } object MaulerTorpedo @@ -474,25 +522,28 @@ object MaulerTorpedo flickerlight MWAVE_X1 { color 0.0 1.0 0.0 - size 112 - secondarySize 128 + size 168 + secondarySize 192 chance 0.3 + attenuate 1 } flickerlight MWAVE_X2 { color 0.0 0.75 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 + attenuate 1 } flickerlight MWAVE_X3 { color 0.0 0.5 0.0 - size 24 - secondarySize 32 + size 36 + secondarySize 48 chance 0.3 + attenuate 1 } object MaulerTorpedoWave @@ -561,89 +612,100 @@ object HEGrenade flickerlight PHFIRE_FX1 { color 1.0 0.75 0.0 - size 28 - secondarySize 32 + size 42 + secondarySize 48 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX2 { color 1.0 0.7 0.0 - size 40 - secondarySize 48 + size 60 + secondarySize 72 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX3 { color 1.0 0.65 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX4 { color 1.0 0.55 0.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX5 { color 1.0 0.5 0.0 - size 66 - secondarySize 72 + size 99 + secondarySize 108 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX6 { color 1.0 0.55 0.0 - size 66 - secondarySize 72 + size 99 + secondarySize 108 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX7 { color 1.0 0.6 0.0 - size 66 - secondarySize 72 + size 99 + secondarySize 108 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX8 { color 1.0 0.5 0.0 - size 60 - secondarySize 68 + size 90 + secondarySize 102 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX9 { color 1.0 0.4 0.0 - size 48 - secondarySize 52 + size 72 + secondarySize 78 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX10 { color 1.0 0.45 0.0 - size 44 - secondarySize 48 + size 66 + secondarySize 72 chance 0.3 + attenuate 1 } flickerlight PHFIRE_FX11 { color 1.0 0.3 0.0 - size 36 - secondarySize 40 + size 54 + secondarySize 60 chance 0.3 + attenuate 1 } object PhosphorousFire @@ -670,65 +732,73 @@ object PhosphorousFire flickerlight DEGORE_X1 { color 1.0 0.6 0.0 - size 32 - secondarySize 40 + size 48 + secondarySize 60 chance 0.3 + attenuate 1 } flickerlight DEGORE_X2 { color 1.0 0.8 0.0 - size 40 - secondarySize 48 + size 60 + secondarySize 72 chance 0.3 + attenuate 1 } flickerlight DEGORE_X3 { color 1.0 0.8 0.0 - size 44 - secondarySize 52 + size 66 + secondarySize 78 chance 0.3 + attenuate 1 } flickerlight DEGORE_X4 { color 1.0 0.75 0.0 - size 48 - secondarySize 56 + size 72 + secondarySize 84 chance 0.3 + attenuate 1 } flickerlight DEGORE_X5 { color 1.0 0.7 0.0 - size 52 - secondarySize 60 + size 78 + secondarySize 90 chance 0.3 + attenuate 1 } flickerlight DEGORE_X6 { color 1.0 0.5 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 + attenuate 1 } flickerlight DEGORE_X7 { color 0.5 0.125 0.0 - size 60 - secondarySize 68 + size 90 + secondarySize 102 chance 0.3 + attenuate 1 } flickerlight DEGORE_X8 { color 0.25 0.05 0.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 + attenuate 1 } object DegninOre @@ -747,13 +817,15 @@ object DegninOre pointlight POWCOUP1 { color 0.5 0.5 1.0 - size 24 + size 36 + attenuate 1 } pointlight POWCOUP2 { color 0.7 0.7 1.0 - size 32 + size 48 + attenuate 1 } object PowerCoupling @@ -766,13 +838,15 @@ object PowerCoupling pointlight ENERGY1 { color 0.4 1.0 0.4 - size 16 + size 24 + attenuate 1 } pointlight ENERGY2 { color 0.4 1.0 0.4 - size 32 + size 48 + attenuate 1 } object EnergyPod @@ -793,10 +867,11 @@ object EnergyPack flickerlight2 HUMNDATK { color 1.0 0.8 0.2 - size 48 - secondarySize 56 + size 72 + secondarySize 84 interval 1 offset 0 40 0 + attenuate 1 } object Acolyte @@ -926,64 +1001,71 @@ object StrifePlayer flickerlight2 CTURRETATK1 { color 1.0 0.8 0.2 - size 40 - secondarySize 48 + size 60 + secondarySize 72 interval 1 offset 0 0 0 + attenuate 1 } flickerlight2 CTURRETATK2 { color 1.0 0.8 0.2 - size 48 - secondarySize 56 + size 72 + secondarySize 84 interval 1 offset 0 0 0 + attenuate 1 } flickerlight2 CTURRETDTH1 { color 1.0 1.0 1.0 - size 32 - secondarySize 36 + size 48 + secondarySize 54 interval 1 offset 0 0 0 + attenuate 1 } flickerlight2 CTURRETDTH2 { color 0.9 0.9 0.9 - size 36 - secondarySize 40 + size 54 + secondarySize 60 interval 1 offset 0 0 0 + attenuate 1 } flickerlight2 CTURRETDTH3 { color 0.7 0.7 0.7 - size 42 - secondarySize 46 + size 63 + secondarySize 69 interval 1 offset 0 0 0 + attenuate 1 } flickerlight2 CTURRETDTH4 { color 0.5 0.5 0.5 - size 48 - secondarySize 52 + size 72 + secondarySize 78 interval 1 offset 0 0 0 + attenuate 1 } flickerlight2 CTURRETDTH5 { color 0.3 0.3 0.3 - size 52 - secondarySize 56 + size 78 + secondarySize 84 interval 1 offset 0 0 0 + attenuate 1 } object CeilingTurret @@ -1002,91 +1084,101 @@ object CeilingTurret flickerlight2 STLKATK { color 1.0 0.8 0.2 - size 48 - secondarySize 56 + size 73 + secondarySize 84 interval 1 offset 0 10 0 + attenuate 1 } flickerlight STLKDTH1 { color 0.2 1.0 0.2 - size 32 - secondarySize 36 + size 48 + secondarySize 54 chance 0.3 offset 0 15 0 + attenuate 1 } flickerlight STLKDTH2 { color 0.3 1.0 0.3 - size 36 - secondarySize 40 + size 54 + secondarySize 60 chance 0.3 offset 0 15 0 + attenuate 1 } flickerlight STLKDTH3 { color 0.2 1.0 0.2 - size 40 - secondarySize 48 + size 60 + secondarySize 72 chance 0.3 offset 0 15 0 + attenuate 1 } flickerlight STLKDTH4 { color 0.35 1.0 0.35 - size 44 - secondarySize 52 + size 66 + secondarySize 78 chance 0.3 offset 0 15 0 + attenuate 1 } flickerlight STLKDTH5 { color 0.5 1.0 0.2 - size 40 - secondarySize 44 + size 60 + secondarySize 66 chance 0.3 offset 0 15 0 + attenuate 1 } flickerlight STLKDTH6 { color 1.0 0.2 0.0 - size 32 - secondarySize 40 + size 48 + secondarySize 60 chance 0.3 offset 0 15 0 + attenuate 1 } flickerlight STLKDTH7 { color 0.7 0.3 0.0 - size 40 - secondarySize 48 + size 60 + secondarySize 72 chance 0.3 offset 0 15 0 + attenuate 1 } flickerlight STLKDTH8 { color 0.5 0.15 0.0 - size 36 - secondarySize 44 + size 54 + secondarySize 66 chance 0.3 offset 0 15 0 + attenuate 1 } flickerlight STLKDTH9 { color 0.35 0.05 0.0 - size 32 - secondarySize 36 + size 48 + secondarySize 54 chance 0.3 offset 0 15 0 + attenuate 1 } object Stalker @@ -1110,19 +1202,21 @@ object Stalker flickerlight SNTNLDTH1 { color 1.0 0.4 0.0 - size 24 - secondarySize 36 + size 36 + secondarySize 54 chance 0.3 offset 0 12 0 + attenuate 1 } flickerlight SNTNLDTH2 { color 1.0 0.6 0.0 - size 48 - secondarySize 56 + size 72 + secondarySize 84 chance 0.3 offset 0 12 0 + attenuate 1 } object Sentinel @@ -1134,43 +1228,50 @@ object Sentinel pointlight SNTNL_FX1 { color 1.0 0.0 0.0 - size 16 + size 24 + attenuate 1 } pointlight SNTNL_FX2 { color 0.5 0.0 0.0 - size 16 + size 24 + attenuate 1 } pointlight SNTNL_FX3 { color 1.0 0.0 0.0 - size 18 + size 27 + attenuate 1 } pointlight SNTNL_FX4 { color 0.8 0.0 0.0 - size 20 + size 30 + attenuate 1 } pointlight SNTNL_FX5 { color 0.6 0.0 0.0 - size 22 + size 33 + attenuate 1 } pointlight SNTNL_FX6 { color 0.4 0.0 0.0 - size 24 + size 36 + attenuate 1 } pointlight SNTNL_FX7 { color 0.2 0.0 0.0 - size 28 + size 42 + attenuate 1 } object SentinelFX1 @@ -1201,46 +1302,51 @@ object SentinelFX2 flickerlight CRSDRDTH1 { color 1.0 0.5 0.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 offset 0 80 0 + attenuate 1 } flickerlight CRSDRDTH2 { color 1.0 0.8 0.0 - size 68 - secondarySize 74 + size 102 + secondarySize 111 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight CRSDRDTH3 { color 1.0 0.8 0.0 - size 72 - secondarySize 76 + size 108 + secondarySize 114 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight CRSDRDTH4 { color 1.0 0.9 0.0 - size 76 - secondarySize 80 + size 114 + secondarySize 120 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight CRSDRDTH5 { color 1.0 0.6 0.0 - size 80 - secondarySize 84 + size 120 + secondarySize 126 chance 0.3 offset 0 40 0 + attenuate 1 } object Crusader @@ -1285,64 +1391,71 @@ object CrusaderMissile flickerlight REAV_X1 { color 1.0 0.3 0.0 - size 16 - secondarySize 20 + size 24 + secondarySize 30 chance 0.3 offset 0 16 16 + attenuate 1 } flickerlight REAV_X2 { color 1.0 0.2 0.0 - size 32 - secondarySize 40 + size 48 + secondarySize 60 chance 0.3 offset 0 32 -16 + attenuate 1 } flickerlight REAV_X3 { color 1.0 0.6 0.0 - size 40 - secondarySize 44 + size 60 + secondarySize 66 chance 0.3 offset 0 12 16 + attenuate 1 } flickerlight REAV_X4 { color 1.0 0.5 0.0 - size 20 - secondarySize 24 + size 30 + secondarySize 36 chance 0.3 offset 0 10 0 + attenuate 1 } flickerlight REAV_X5 { color 1.0 0.8 0.0 - size 28 - secondarySize 32 + size 42 + secondarySize 48 chance 0.3 offset 0 18 0 + attenuate 1 } flickerlight REAV_X6 { color 1.0 0.7 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 offset 0 20 0 + attenuate 1 } flickerlight REAV_X7 { color 0.5 0.05 0.0 - size 52 - secondarySize 56 + size 78 + secondarySize 84 chance 0.3 offset 0 20 0 + attenuate 1 } object Reaver @@ -1362,64 +1475,71 @@ object Reaver flickerlight2 TEMPATK { color 0.2 1.0 0.2 - size 48 - secondarySize 56 + size 72 + secondarySize 84 interval 1 offset 20 40 0 + attenuate 1 } flickerlight TEMP_X1 { color 1.0 0.8 0.2 - size 8 - secondarySize 12 + size 12 + secondarySize 18 chance 0.3 offset 0 20 32 + attenuate 1 } flickerlight TEMP_X2 { color 1.0 0.5 0.0 - size 32 - secondarySize 36 + size 48 + secondarySize 54 chance 0.3 offset 0 20 24 + attenuate 1 } flickerlight TEMP_X3 { color 1.0 0.75 0.1 - size 24 - secondarySize 28 + size 36 + secondarySize 42 chance 0.3 offset 0 20 24 + attenuate 1 } flickerlight TEMP_X4 { color 1.0 0.65 0.1 - size 28 - secondarySize 32 + size 42 + secondarySize 48 chance 0.3 offset 0 20 16 + attenuate 1 } flickerlight TEMP_X5 { color 1.0 0.6 0.0 - size 30 - secondarySize 34 + size 45 + secondarySize 51 chance 0.3 offset 0 20 8 + attenuate 1 } flickerlight TEMP_X6 { color 1.0 0.5 0.0 - size 32 - secondarySize 36 + size 48 + secondarySize 54 chance 0.3 offset 0 20 0 + attenuate 1 } object Templar @@ -1438,163 +1558,181 @@ object Templar flickerlight2 INQATK1 { color 1.0 0.6 0.0 - size 88 - secondarySize 96 + size 132 + secondarySize 144 interval 1 offset 20 72 -40 + attenuate 1 } flickerlight2 INQATK2 { color 1.0 0.6 0.0 - size 88 - secondarySize 96 + size 132 + secondarySize 144 interval 1 offset 20 96 0 + attenuate 1 } flickerlight2 INQFLY1 { color 0.5 0.5 1.0 - size 80 - secondarySize 84 + size 120 + secondarySize 126 interval 1 offset -40 36 0 + attenuate 1 } flickerlight2 INQFLY2 { color 0.33 0.33 1.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 interval 1 offset -40 36 0 + attenuate 1 } flickerlight INQDTH1 { color 1.0 0.4 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 offset 0 72 0 + attenuate 1 } flickerlight INQDTH2 { color 1.0 0.7 0.0 - size 84 - secondarySize 96 + size 126 + secondarySize 144 chance 0.3 offset 0 64 0 + attenuate 1 } flickerlight INQDTH3 { color 1.0 0.6 0.0 - size 92 - secondarySize 100 + size 138 + secondarySize 150 chance 0.3 offset 0 56 0 + attenuate 1 } flickerlight INQDTH4 { color 0.7 0.07 0.0 - size 72 - secondarySize 80 + size 108 + secondarySize 120 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight INQDTH5 { color 0.3 0.0 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight INQDTH6 { color 0.5 0.3 0.0 - size 32 - secondarySize 40 + size 48 + secondarySize 60 chance 0.3 offset 0 32 0 + attenuate 1 } flickerlight INQDTH7 { color 1.0 0.6 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 offset 0 32 0 + attenuate 1 } flickerlight INQDTH8 { color 1.0 0.7 0.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 offset 0 32 0 + attenuate 1 } flickerlight INQDTH9 { color 1.0 0.7 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 offset 0 56 0 + attenuate 1 } flickerlight INQDTH10 { color 1.0 0.6 0.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 offset 0 56 0 + attenuate 1 } flickerlight INQDTH11 { color 1.0 0.5 0.0 - size 100 - secondarySize 128 + size 150 + secondarySize 192 chance 0.3 offset 0 32 0 + attenuate 1 } flickerlight INQDTH12 { color 1.0 0.4 0.0 - size 80 - secondarySize 96 + size 120 + secondarySize 144 chance 0.3 offset 0 32 0 + attenuate 1 } flickerlight INQDTH13 { color 1.0 0.3 0.0 - size 60 - secondarySize 72 + size 90 + secondarySize 108 chance 0.3 offset 0 24 0 + attenuate 1 } flickerlight INQDTH14 { color 0.5 0.15 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 offset 0 18 0 + attenuate 1 } object Inquisitor @@ -1630,73 +1768,82 @@ object Inquisitor flickerlight INQSHOT_X1 { color 1.0 0.8 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 + attenuate 1 } flickerlight INQSHOT_X2 { color 1.0 0.7 0.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 + attenuate 1 } flickerlight INQSHOT_X3 { color 0.8 0.45 0.0 - size 72 - secondarySize 80 + size 108 + secondarySize 120 chance 0.3 + attenuate 1 } flickerlight INQSHOT_X4 { color 0.5 0.3 0.0 - size 80 - secondarySize 84 + size 120 + secondarySize 126 chance 0.3 + attenuate 1 } flickerlight INQSHOT_X5 { color 1.0 0.6 0.0 - size 56 - secondarySize 60 + size 84 + secondarySize 90 chance 0.3 + attenuate 1 } flickerlight INQSHOT_X6 { color 1.0 0.7 0.0 - size 60 - secondarySize 64 + size 90 + secondarySize 96 chance 0.3 + attenuate 1 } flickerlight INQSHOT_X7 { color 1.0 0.7 0.0 - size 64 - secondarySize 68 + size 96 + secondarySize 102 chance 0.3 + attenuate 1 } flickerlight INQSHOT_X8 { color 1.0 0.6 0.0 - size 40 - secondarySize 48 + size 60 + secondarySize 72 chance 0.3 + attenuate 1 } flickerlight INQSHOT_X9 { color 1.0 0.4 0.0 - size 24 - secondarySize 32 + size 36 + secondarySize 48 chance 0.3 + attenuate 1 } object InquisitorShot @@ -1716,46 +1863,51 @@ object InquisitorShot flickerlight PROGATK1 { color 0.5 0.5 1.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 offset 0 60 0 + attenuate 1 } flickerlight PROGATK2 { color 0.6 0.6 1.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 offset 0 60 0 + attenuate 1 } flickerlight PROGATK3 { color 0.8 0.8 1.0 - size 80 - secondarySize 96 + size 120 + secondarySize 144 chance 0.3 offset 0 60 0 + attenuate 1 } flickerlight PROGDTH1 { color 1.0 0.4 0.0 - size 112 - secondarySize 128 + size 168 + secondarySize 192 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight PROGDTH2 { color 1.0 0.6 0.0 - size 128 - secondarySize 140 + size 192 + secondarySize 210 chance 0.3 offset 0 40 0 + attenuate 1 } object Programmer @@ -1771,28 +1923,31 @@ object Programmer flickerlight BASE_X1 { color 1.0 0.55 0.0 - size 96 - secondarySize 112 + size 144 + secondarySize 168 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight BASE_X2 { color 1.0 0.50 0.0 - size 80 - secondarySize 96 + size 120 + secondarySize 144 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight BASE_X3 { color 0.5 0.2 0.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 offset 0 32 0 + attenuate 1 } object ProgrammerBase @@ -1806,10 +1961,11 @@ object ProgrammerBase flickerlight BISHOP { color 1.0 1.0 1.0 - size 96 - secondarySize 108 + size 144 + secondarySize 162 chance 0.3 offset 0 120 0 + attenuate 1 } object StrifeBishop @@ -1838,35 +1994,40 @@ object BishopMissile pointlight LIGHT1 { color 1.0 1.0 1.0 - size 56 + size 90 offset 0 30 0 + attenuate 1 } pointlight LIGHT2 { color 1.0 1.0 1.0 - size 40 + size 60 offset 0 72 0 + attenuate 1 } pointlight LIGHT3 { color 1.0 1.0 1.0 - size 64 + size 96 + attenuate 1 } pointlight LIGHT4 { color 1.0 1.0 1.0 - size 64 + size 96 offset 0 80 0 + attenuate 1 } pointlight LIGHT5 { color 1.0 1.0 1.0 - size 56 + size 84 offset 0 72 0 + attenuate 1 } pointlight CLIGHT1 @@ -1879,91 +2040,102 @@ pointlight CLIGHT1 pulselight CLIGHT2 { color 1.0 1.0 0.0 - size 48 - secondarySize 50 + size 66 + secondarySize 75 interval 8.0 offset 0 64 0 + attenuate 1 } pulselight LLIGHT { color 1.0 0.5 0.0 - size 24 - secondarySize 32 + size 42 + secondarySize 54 interval 12.0 offset 0 76 0 + attenuate 1 } pulselight TLLIGHT1 { color 0.9 0.9 1.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 interval 3.0 offset 0 48 0 + attenuate 1 } pointlight TLLIGHT2 { color 1.0 1.0 0.5 - size 80 + size 120 offset 0 56 0 + attenuate 1 } flickerlight HTECH { color 0.3 1.0 0.3 - size 96 - secondarySize 104 + size 144 + secondarySize 156 chance 0.5 offset 0 80 0 + attenuate 1 } pulselight BCOLUMN { color 0.5 1.0 0.5 - size 120 - secondarySize 128 + size 180 + secondarySize 192 interval 10.0 offset 0 64 0 + attenuate 1 } pulselight FBUBBLE { color 0.5 1.0 0.5 - size 60 - secondarySize 64 + size 90 + secondarySize 96 interval 10.0 offset 0 32 0 + attenuate 1 } pulselight CBUBBLE { color 0.5 1.0 0.5 - size 60 - secondarySize 64 + size 90 + secondarySize 96 interval 10.0 + attenuate 1 } pointlight SPIDLGHT1 { color 0.5 1.0 0.5 - size 64 + size 96 offset 0 10 0 + attenuate 1 } pointlight SPIDLGHT2 { color 0.2 0.75 0.2 - size 56 + size 84 offset 0 10 0 + attenuate 1 } pointlight SPIDLGHT3 { color 0.0 0.25 0.0 - size 48 + size 72 offset 0 10 0 + attenuate 1 } object LightSilverFluorescent @@ -2052,64 +2224,71 @@ object AlienSpiderLight flickerlight BBARREL { color 1.0 0.6 0.0 - size 32 - secondarySize 40 + size 54 + secondarySize 66 chance 0.8 offset 0 32 0 + attenuate 1 } flickerlight BBOWL { color 1.0 0.7 0.0 - size 24 - secondarySize 32 + size 40 + secondarySize 52 chance 0.5 offset 0 10 0 + attenuate 1 } flickerlight BBRAZIER { color 1.0 0.8 0.0 - size 40 - secondarySize 48 + size 66 + secondarySize 78 chance 0.2 offset 0 32 0 + attenuate 1 } pulselight STORCH { color 1.0 0.6 0.0 - size 28 - secondarySize 32 + size 48 + secondarySize 54 interval 5.0 offset 0 56 0 + attenuate 1 } pulselight MTORCH { color 1.0 0.6 0.0 - size 56 - secondarySize 64 + size 90 + secondarySize 102 interval 5.0 offset 0 64 0 + attenuate 1 } pulselight LTORCH { color 1.0 0.8 0.0 - size 64 - secondarySize 72 + size 102 + secondarySize 114 interval 2.0 offset 0 64 0 + attenuate 1 } pulselight HTORCH { color 1.0 0.6 0.0 - size 72 - secondarySize 76 + size 114 + secondarySize 120 interval 3.0 offset 0 72 0 + attenuate 1 } object StrifeBurningBarrel @@ -2455,10 +2634,11 @@ object PowerCrystal pulselight COMPUTER { color 0.25 1.0 0.25 - size 112 - secondarySize 128 + size 168 + secondarySize 192 interval 0.25 offset 0 64 0 + attenuate 1 } object Computer @@ -2473,76 +2653,85 @@ object Computer flickerlight BARREL_X1 { color 1.0 0.6 0.1 - size 48 - secondarySize 56 + size 72 + secondarySize 84 chance 0.3 + attenuate 1 } flickerlight BARREL_X2 { color 1.0 0.8 0.0 - size 56 - secondarySize 64 + size 84 + secondarySize 96 chance 0.3 + attenuate 1 } flickerlight BARREL_X3 { color 1.0 0.7 0.0 - size 72 - secondarySize 80 + size 108 + secondarySize 120 chance 0.3 + attenuate 1 } flickerlight BARREL_X4 { color 1.0 0.6 0.0 - size 80 - secondarySize 88 + size 120 + secondarySize 132 chance 0.3 + attenuate 1 } flickerlight BARREL_X5 { color 1.0 0.5 0.0 - size 72 - secondarySize 76 + size 108 + secondarySize 114 chance 0.3 + attenuate 1 } flickerlight BARREL_X6 { color 1.0 0.45 0.0 - size 56 - secondarySize 60 + size 84 + secondarySize 90 chance 0.3 + attenuate 1 } flickerlight BARREL_X7 { color 1.0 0.4 0.0 - size 52 - secondarySize 56 + size 78 + secondarySize 84 chance 0.3 offset 0 24 0 + attenuate 1 } flickerlight BARREL_X8 { color 1.0 0.35 0.0 - size 36 - secondarySize 40 + size 54 + secondarySize 60 chance 0.3 offset 0 40 0 + attenuate 1 } flickerlight BARREL_X9 { color 1.0 0.3 0.0 - size 16 - secondarySize 24 + size 24 + secondarySize 36 chance 0.3 offset 0 56 0 + attenuate 1 } object ExplosiveBarrel2 @@ -2562,7 +2751,8 @@ object ExplosiveBarrel2 pointlight KLAXON { color 1.0 0.0 0.0 - size 24 + size 36 + attenuate 1 } object KlaxonWarningLight @@ -2606,49 +2796,55 @@ object FireDroplet flickerlight ZAPBALL1 { color 0.8 0.8 1.0 - size 64 - secondarySize 72 + size 96 + secondarySize 108 chance 0.3 + attenuate 1 } flickerlight ZAPBALL2 { color 0.8 0.8 1.0 - size 128 - secondarySize 144 + size 192 + secondarySize 216 chance 0.5 + attenuate 1 } flickerlight LIGHTNING1 { color 0.8 0.8 1.0 - size 72 - secondarySize 80 + size 108 + secondarySize 120 chance 0.8 + attenuate 1 } flickerlight LIGHTNING2 { color 0.8 0.8 1.0 - size 80 - secondarySize 96 + size 120 + secondarySize 144 chance 0.8 + attenuate 1 } flickerlight LIGHT_SPT { color 0.8 0.8 1.0 - size 24 - secondarySize 32 + size 36 + secondarySize 48 chance 0.8 + attenuate 1 } flickerlight LGNTAIL { color 0.4 0.4 0.5 - size 72 - secondarySize 80 + size 108 + secondarySize 120 chance 0.8 + attenuate 1 } object SpectralLightningBase @@ -2814,43 +3010,49 @@ object SpectralLightningBigV2 pointlight TFOG1 { color 0.5 0.5 0.25 - size 32 + size 48 offset 0 40 0 + attenuate 1 } pointlight TFOG2 { color 0.5 0.5 0.25 - size 40 + size 60 offset 0 40 0 + attenuate 1 } pointlight TFOG3 { color 0.5 0.5 0.25 - size 48 + size 72 offset 0 40 0 + attenuate 1 } pointlight TFOG4 { color 0.5 0.5 0.25 - size 56 + size 84 offset 0 40 0 + attenuate 1 } pointlight TFOG5 { color 0.5 0.5 0.25 - size 64 + size 96 offset 0 40 0 + attenuate 1 } pointlight TFOG6 { color 0.5 0.5 0.25 - size 72 + size 108 offset 0 40 0 + attenuate 1 } object TeleportFog From 5c86ad850731bfb080c08499320c542d90f26707 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sat, 23 May 2020 09:08:40 -0400 Subject: [PATCH 171/220] - defcvars: handle values from a version 219 config --- src/d_main.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index c4673ece63..3a59e5d1df 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -353,6 +353,7 @@ void D_GrabCVarDefaults() sc.ScriptError("Version must be at least 219 (current version %i)", gamelastrunversion); FBaseCVar* var; + FString CurrentFindCVar; while (sc.GetString()) { @@ -360,7 +361,30 @@ void D_GrabCVarDefaults() { sc.MustGetString(); } - var = FindCVar(sc.String, NULL); + + CurrentFindCVar = sc.String; + + if (lumpversion < 220) + { + CurrentFindCVar.ToLower(); + + // these two got renamed + if (strcmp(CurrentFindCVar, "gamma") == 0) + { + CurrentFindCVar = "vid_gamma"; + } + if (strcmp(CurrentFindCVar, "fullscreen") == 0) + { + CurrentFindCVar = "vid_fullscreen"; + } + + // this was removed + if (strcmp(CurrentFindCVar, "cd_drive") == 0) + break; + } + + var = FindCVar(CurrentFindCVar, NULL); + if (var != NULL) { if (var->GetFlags() & CVAR_ARCHIVE) From 7d5df1dd7e4dd29e60820349f726bf2500355279 Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Sat, 23 May 2020 10:23:54 +0200 Subject: [PATCH 172/220] Add mapinfo option to disable merging of identical pickup messages on same tic --- src/gamedata/gi.cpp | 1 + src/gamedata/gi.h | 1 + src/playsim/a_pickups.cpp | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gamedata/gi.cpp b/src/gamedata/gi.cpp index a09035f5ae..d21f33b0c6 100644 --- a/src/gamedata/gi.cpp +++ b/src/gamedata/gi.cpp @@ -440,6 +440,7 @@ void FMapInfoParser::ParseGameInfo() GAMEINFOKEY_STRING(statusscreen_dm, "statscreen_dm") GAMEINFOKEY_TWODOUBLES(normforwardmove, "normforwardmove") GAMEINFOKEY_TWODOUBLES(normsidemove, "normsidemove") + GAMEINFOKEY_BOOL(nomergepickupmsg, "nomergepickupmsg") else { diff --git a/src/gamedata/gi.h b/src/gamedata/gi.h index 6118aa6209..124b6742e9 100644 --- a/src/gamedata/gi.h +++ b/src/gamedata/gi.h @@ -206,6 +206,7 @@ struct gameinfo_t double normforwardmove[2]; double normsidemove[2]; int fullscreenautoaspect = 0; + bool nomergepickupmsg; const char *GetFinalePage(unsigned int num) const; }; diff --git a/src/playsim/a_pickups.cpp b/src/playsim/a_pickups.cpp index 98347df84a..f4c72b5f97 100644 --- a/src/playsim/a_pickups.cpp +++ b/src/playsim/a_pickups.cpp @@ -41,6 +41,7 @@ #include "d_player.h" #include "vm.h" #include "g_levellocals.h" +#include "gi.h" EXTERN_CVAR(Bool, sv_unlimited_pickup) @@ -55,7 +56,8 @@ static FString StaticLastMessage; void PrintPickupMessage(bool localview, const FString &str) { - if (str.IsNotEmpty() && localview && (StaticLastMessageTic != gametic || StaticLastMessage.Compare(str))) + // [MK] merge identical messages on same tic unless disabled in gameinfo + if (str.IsNotEmpty() && localview && (gameinfo.nomergepickupmsg || StaticLastMessageTic != gametic || StaticLastMessage.Compare(str))) { StaticLastMessageTic = gametic; StaticLastMessage = str; From 991661e11e7eaeb4ecf8a5ff22cdfb57d76d2b77 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 16:24:06 +0200 Subject: [PATCH 173/220] - fixed missing sound for Polyobj_MoveTo. --- src/playsim/po_man.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/playsim/po_man.cpp b/src/playsim/po_man.cpp index 14b84e1a03..8bbf80142f 100644 --- a/src/playsim/po_man.cpp +++ b/src/playsim/po_man.cpp @@ -511,6 +511,7 @@ bool EV_MovePolyTo(FLevelLocals *Level, line_t *line, int polyNum, double speed, pe->m_Speed = speed; pe->m_Speedv = dist * speed; pe->m_Target = poly->StartSpot.pos + dist * distlen; + SN_StartSequence(poly, poly->seqType, SEQ_DOOR, 0); if ((pe->m_Dist / pe->m_Speed) <= 2) { pe->StopInterpolation(); From c9b37f8320ffa71e1a178129b4ee7e77f915084e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 16:32:27 +0200 Subject: [PATCH 174/220] - fixed bad Heretic light definitions. --- wadsrc_lights/static/filter/heretic/gldefs.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/wadsrc_lights/static/filter/heretic/gldefs.txt b/wadsrc_lights/static/filter/heretic/gldefs.txt index f96ffe59cd..65796e7530 100644 --- a/wadsrc_lights/static/filter/heretic/gldefs.txt +++ b/wadsrc_lights/static/filter/heretic/gldefs.txt @@ -1663,7 +1663,7 @@ object VolcanoBlast } // Small volcano fireball -flickerlight VOLCANOBALL1 +flickerlight VOLCANOBALL2 { color 1.0 0.5 0.0 size 60 @@ -1674,7 +1674,7 @@ flickerlight VOLCANOBALL1 object VolcanoTBlast { - frame VTFB { light VOLCANOBALL1 } + frame VTFB { light VOLCANOBALL2 } } // Blue Key Statue @@ -1733,7 +1733,7 @@ flickerlight TIMEBOMB_X1 attenuate 1 } -flickerlight TIMEBOMB_X1 +flickerlight TIMEBOMB_X2 { color 0.8 0.4 0.3 size 88 @@ -1742,7 +1742,7 @@ flickerlight TIMEBOMB_X1 attenuate 1 } -flickerlight TIMEBOMB_X1 +flickerlight TIMEBOMB_X3 { color 0.6 0.3 0.2 size 96 @@ -1751,7 +1751,7 @@ flickerlight TIMEBOMB_X1 attenuate 1 } -flickerlight TIMEBOMB_X1 +flickerlight TIMEBOMB_X4 { color 0.4 0.2 0.1 size 108 @@ -1760,7 +1760,7 @@ flickerlight TIMEBOMB_X1 attenuate 1 } -flickerlight TIMEBOMB_X1 +flickerlight TIMEBOMB_X5 { color 0.2 0.1 0.0 size 120 @@ -1774,7 +1774,7 @@ object ActivatedTimeBomb frame XPL1A { light TIMEBOMB_X1 } frame XPL1B { light TIMEBOMB_X2 } frame XPL1C { light TIMEBOMB_X3 } - frame XPL1D { light TIMEBOMB_X4 } + frame XPL1D { light TIMEBOMB_X12 } frame XPL1E { light TIMEBOMB_X5 } frame XPL1F { light TIMEBOMB_X5 } } From 6444a7535cab2a4fd3b8c3ff1eafb89ba7c3ae24 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 16:43:01 +0200 Subject: [PATCH 175/220] - fixed use of Powerup.Strength in PowerInvisibility. An integer division made the feature useless. --- wadsrc/static/zscript/actors/inventory/powerups.zs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wadsrc/static/zscript/actors/inventory/powerups.zs b/wadsrc/static/zscript/actors/inventory/powerups.zs index 157fab1b22..f3fed4b7bc 100644 --- a/wadsrc/static/zscript/actors/inventory/powerups.zs +++ b/wadsrc/static/zscript/actors/inventory/powerups.zs @@ -569,7 +569,7 @@ class PowerInvisibility : Powerup Super.DoEffect(); // Due to potential interference with other PowerInvisibility items // the effect has to be refreshed each tic. - double ts = (Strength / 100) * (special1 + 1); + double ts = (Strength / 100.) * (special1 + 1); if (ts > 1.) ts = 1.; let newAlpha = clamp((1. - ts), 0., 1.); From ea0da8533cbcece6392017d655e9c94e4258cb93 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 19:20:51 +0200 Subject: [PATCH 176/220] - added missing range check to section code. Fixes asserts on some maps in Kama Sutra. --- src/r_data/r_sections.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r_data/r_sections.h b/src/r_data/r_sections.h index fcd7cd3b2a..221d19e638 100644 --- a/src/r_data/r_sections.h +++ b/src/r_data/r_sections.h @@ -141,6 +141,7 @@ public: } TArrayView SectionsForSector(int sindex) { + if (numberOfSectionForSectorPtr[sindex] == 0) return TArrayView(nullptr); return sindex < 0 ? TArrayView(0) : TArrayView(&allSections[firstSectionForSectorPtr[sindex]], numberOfSectionForSectorPtr[sindex]); } int SectionIndex(const FSection *sect) From 2828dbe095fb116692e3c8689a281742e4766507 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 19:33:14 +0200 Subject: [PATCH 177/220] - fixed: TRF_ALLACTORS did not consider actors without any flag being set. --- src/playsim/p_trace.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/playsim/p_trace.cpp b/src/playsim/p_trace.cpp index 02608b8dea..9cff0ffb2e 100644 --- a/src/playsim/p_trace.cpp +++ b/src/playsim/p_trace.cpp @@ -839,10 +839,10 @@ bool FTraceInfo::TraceTraverse (int ptflags) { if (in->d.line->isLinePortal() && P_PointOnLineSidePrecise(Start, in->d.line) == 0) { - sector_t *entersector = in->d.line->backsector; + sector_t* entersector = in->d.line->backsector; if (entersector == NULL || (hit.Z >= entersector->floorplane.ZatPoint(hit) && hit.Z <= entersector->ceilingplane.ZatPoint(hit))) { - FLinePortal *port = in->d.line->getPortal(); + FLinePortal* port = in->d.line->getPortal(); // The caller cannot handle portals without global offset. if (port->mType == PORTT_LINKED || !(TraceFlags & TRACE_PortalRestrict)) { @@ -853,7 +853,7 @@ bool FTraceInfo::TraceTraverse (int ptflags) } if (!LineCheck(in, dist, hit, false)) break; } - else if ((in->d.thing->flags & ActorMask) && in->d.thing != IgnoreThis) + else if (((in->d.thing->flags & ActorMask) || ActorMask == 0xffffffff) && in->d.thing != IgnoreThis) { if (!ThingCheck(in, dist, hit)) break; } From 667b2d6bf4df5686989b1d156185e2e9d2dbb074 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 19:44:06 +0200 Subject: [PATCH 178/220] - fixed: V_GetFont must load the translations once the game has been set up. --- src/common/fonts/v_font.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common/fonts/v_font.cpp b/src/common/fonts/v_font.cpp index 4d0937d840..50db740740 100644 --- a/src/common/fonts/v_font.cpp +++ b/src/common/fonts/v_font.cpp @@ -89,6 +89,7 @@ FFont* SmallFont, * SmallFont2, * BigFont, * BigUpper, * ConFont, * Intermission FFont *FFont::FirstFont = nullptr; int NumTextColors; +static bool translationsLoaded; // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -138,7 +139,9 @@ FFont *V_GetFont(const char *name, const char *fontlumpname) head == MAKE_ID(0xE1,0xE6,0xD5,0x1A)) { FFont *CreateSingleLumpFont (const char *fontname, int lump); - return CreateSingleLumpFont (name, lump); + font = CreateSingleLumpFont (name, lump); + if (translationsLoaded) font->LoadTranslations(); + return font; } } FTextureID picnum = TexMan.CheckForTexture (name, ETextureType::Any); @@ -148,12 +151,16 @@ FFont *V_GetFont(const char *name, const char *fontlumpname) if (tex && tex->GetSourceLump() >= folderfile) { FFont *CreateSinglePicFont(const char *name); - return CreateSinglePicFont (name); + font = CreateSinglePicFont (name); + if (translationsLoaded) font->LoadTranslations(); + return font; } } if (folderdata.Size() > 0) { - return new FFont(name, nullptr, name, HU_FONTSTART, HU_FONTSIZE, 1, -1); + font = new FFont(name, nullptr, name, HU_FONTSTART, HU_FONTSIZE, 1, -1); + if (translationsLoaded) font->LoadTranslations(); + return font; } } return font; @@ -834,6 +841,7 @@ void V_LoadTranslations() if (OriginalSmallFont != nullptr) OriginalSmallFont->SetDefaultTranslation(colors); NewSmallFont->SetDefaultTranslation(colors); } + translationsLoaded = true; } void V_ClearFonts() From 3e8f53e98c73efbb42f998e1792b142b6ac4922e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 20:26:58 +0200 Subject: [PATCH 179/220] - fixed shader building. We really need a version directive for user shaders, this is getting too messy. :( --- src/common/rendering/gl/gl_shader.cpp | 8 +++++--- src/common/rendering/vulkan/shaders/vk_shader.cpp | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common/rendering/gl/gl_shader.cpp b/src/common/rendering/gl/gl_shader.cpp index c00ab09117..51f3fb3ebd 100644 --- a/src/common/rendering/gl/gl_shader.cpp +++ b/src/common/rendering/gl/gl_shader.cpp @@ -379,14 +379,16 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * vp_comb << "#define SUPPORTS_SHADOWMAPS\n"; } - vp_comb << defines << i_data.GetChars(); FString fp_comb = vp_comb; + vp_comb << defines << i_data.GetChars(); + fp_comb << "$placeholder$\n" << defines << i_data.GetChars(); vp_comb << "#line 1\n"; fp_comb << "#line 1\n"; vp_comb << RemoveLayoutLocationDecl(vp_data.GetString(), "out").GetChars() << "\n"; fp_comb << RemoveLayoutLocationDecl(fp_data.GetString(), "in").GetChars() << "\n"; + FString placeholder = "\n"; if (proc_prog_lump != NULL) { @@ -448,9 +450,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * if (pp_data.GetString().IndexOf("ProcessMaterial") >= 0 && pp_data.GetString().IndexOf("SetupMaterial") < 0) { // This reactivates the old logic and disables all features that cannot be supported with that method. - fp_comb.Insert(0, "#define LEGACY_USER_SHADER\n"); + placeholder << "#define LEGACY_USER_SHADER\n"; } - } else { @@ -458,6 +459,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * fp_comb << proc_prog_lump + 1; } } + fp_comb.Substitute("$placeholder$", placeholder); if (light_fragprog) { diff --git a/src/common/rendering/vulkan/shaders/vk_shader.cpp b/src/common/rendering/vulkan/shaders/vk_shader.cpp index 8162cf7b32..092a20e696 100644 --- a/src/common/rendering/vulkan/shaders/vk_shader.cpp +++ b/src/common/rendering/vulkan/shaders/vk_shader.cpp @@ -284,8 +284,10 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername { FString code = GetTargetGlslVersion(); code << defines; + code << "\n$placeholder$"; // here the code can later add more needed #defines. code << "\n#define MAX_STREAM_DATA " << std::to_string(MAX_STREAM_DATA).c_str() << "\n"; code << shaderBindings; + FString placeholder = "\n"; if (!device->UsedDeviceFeatures.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n"; if (!alphatest) code << "#define NO_ALPHATEST\n"; @@ -342,7 +344,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername if (pp_code.IndexOf("ProcessMaterial") >= 0 && pp_code.IndexOf("SetupMaterial") < 0) { // This reactivates the old logic and disables all features that cannot be supported with that method. - code.Insert(0, "#define LEGACY_USER_SHADER\n"); + placeholder << "#define LEGACY_USER_SHADER\n"; } } else @@ -351,6 +353,7 @@ std::unique_ptr VkShaderManager::LoadFragShader(FString shadername code << (material_lump + 1) << "\n"; } } + code.Substitute("$placeholder$", placeholder); if (light_lump) { From 29344006a0f912fa06f976d1ad58ac2b526e3170 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 20:41:47 +0200 Subject: [PATCH 180/220] - fixed: texture upscaling was disabled by default. It should only be disabled if the scale of a texture is greater than 2. --- src/common/textures/gametexture.cpp | 2 +- src/common/textures/gametexture.h | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common/textures/gametexture.cpp b/src/common/textures/gametexture.cpp index 1ec6a60627..caf5d43573 100644 --- a/src/common/textures/gametexture.cpp +++ b/src/common/textures/gametexture.cpp @@ -430,7 +430,7 @@ CUSTOM_CVAR(Int, r_spriteadjust, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) float FTexCoordInfo::RowOffset(float rowoffset) const { - float scale = fabs(mScale.Y); + float scale = fabsf(mScale.Y); if (scale == 1.f || mWorldPanning) return rowoffset; else return rowoffset / scale; } diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 31864f9eba..7b4c461746 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -84,7 +84,7 @@ class FGameTexture float DisplayWidth, DisplayHeight; float ScaleX, ScaleY; - int8_t shouldUpscaleFlag = 0; // Without explicit setup, scaling is disabled for a texture. + int8_t shouldUpscaleFlag = 1; ETextureType UseType = ETextureType::Wall; // This texture's primary purpose SpritePositioningInfo* spi = nullptr; @@ -131,7 +131,7 @@ public: ETextureType GetUseType() const { return UseType; } void SetUpscaleFlag(int what) { shouldUpscaleFlag = what; } - int GetUpscaleFlag() { return shouldUpscaleFlag; } + int GetUpscaleFlag() { return shouldUpscaleFlag == 1; } FTexture* GetTexture() { return Base.get(); } int GetSourceLump() const { return Base->GetSourceLump(); } @@ -234,6 +234,10 @@ public: DisplayHeight = h; ScaleX = TexelWidth / w; ScaleY = TexelHeight / h; + if (shouldUpscaleFlag < 2) + { + shouldUpscaleFlag = ScaleX < 2 && ScaleY < 2; + } // compensate for roundoff errors if (int(ScaleX * w) != TexelWidth) ScaleX += (1 / 65536.); @@ -253,6 +257,10 @@ public: { ScaleX = x; ScaleY = y; + if (shouldUpscaleFlag < 2) + { + shouldUpscaleFlag = ScaleX < 2 && ScaleY < 2; + } DisplayWidth = TexelWidth / x; DisplayHeight = TexelHeight / y; } From b2b1ecc11ff3eff6ed4b3f918a11e768b7f1d2a5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 21:16:36 +0200 Subject: [PATCH 181/220] - Single image fonts do not use translations. --- src/common/fonts/v_font.cpp | 1 - src/common/textures/gametexture.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/common/fonts/v_font.cpp b/src/common/fonts/v_font.cpp index 50db740740..3f64b16253 100644 --- a/src/common/fonts/v_font.cpp +++ b/src/common/fonts/v_font.cpp @@ -152,7 +152,6 @@ FFont *V_GetFont(const char *name, const char *fontlumpname) { FFont *CreateSinglePicFont(const char *name); font = CreateSinglePicFont (name); - if (translationsLoaded) font->LoadTranslations(); return font; } } diff --git a/src/common/textures/gametexture.cpp b/src/common/textures/gametexture.cpp index caf5d43573..3ab74a5c38 100644 --- a/src/common/textures/gametexture.cpp +++ b/src/common/textures/gametexture.cpp @@ -443,7 +443,7 @@ float FTexCoordInfo::RowOffset(float rowoffset) const float FTexCoordInfo::TextureOffset(float textureoffset) const { - float scale = fabs(mScale.X); + float scale = fabsf(mScale.X); if (scale == 1.f || mWorldPanning) return textureoffset; else return textureoffset / scale; } @@ -458,7 +458,7 @@ float FTexCoordInfo::TextureAdjustWidth() const { if (mWorldPanning) { - float tscale = fabs(mTempScale.X); + float tscale = fabsf(mTempScale.X); if (tscale == 1.f) return (float)mRenderWidth; else return mWidth / fabs(tscale); } From dbb181923894fb8e4c5d598622a9b94ea8a94402 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 21:17:28 +0200 Subject: [PATCH 182/220] - fixed setup for translated textures in Vulkan. It was passing the wrong IDs to high level code. --- src/common/rendering/vulkan/textures/vk_hwtexture.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp index cac4985ef4..aac0185180 100644 --- a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp @@ -369,7 +369,8 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state) int translation = state.mTranslation; auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation); - if (remap) translation = remap->Index; + if (remap) + translation = remap->Index; clampmode = base->GetClampMode(clampmode); @@ -389,8 +390,8 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state) WriteDescriptors update; MaterialLayerInfo *layer; - auto systex = static_cast(GetLayer(0, translation, &layer)); - update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, translation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); + auto systex = static_cast(GetLayer(0, state.mTranslation, &layer)); + update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, state.mTranslation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); for (int i = 1; i < numLayers; i++) { auto systex = static_cast(GetLayer(i, 0, &layer)); From 3b65b0caec415ef5cedd3590c5bcfc9a0d2a7e2b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 21:32:49 +0200 Subject: [PATCH 183/220] - fixed: The size parameters for automap sprites are floats, so they need the matching tag. --- src/am_map.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/am_map.cpp b/src/am_map.cpp index f121f92bbd..aa7ed83b6a 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -3037,8 +3037,8 @@ void DAutomap::DrawMarker (FGameTexture *tex, double x, double y, int yadjust, rotatePoint (&x, &y); } DrawTexture(twod, tex, CXMTOF(x) + f_x, CYMTOF(y) + yadjust + f_y, - DTA_DestWidth, tex->GetDisplayWidth() * CleanXfac * xscale, - DTA_DestHeight, tex->GetDisplayHeight() * CleanYfac * yscale, + DTA_DestWidthF, tex->GetDisplayWidth() * CleanXfac * xscale, + DTA_DestHeightF, tex->GetDisplayHeight() * CleanYfac * yscale, DTA_ClipTop, f_y, DTA_ClipBottom, f_y + f_h, DTA_ClipLeft, f_x, From 233d0b62b912018cab79c9d3b3d1e60d4810f991 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 25 May 2020 22:12:08 +0200 Subject: [PATCH 184/220] - fixed space calculations for oversized episode and skill menus. --- src/menu/menudef.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index db8d29a08c..13f95583fd 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -1154,7 +1154,7 @@ void M_StartupEpisodeMenu(FNewGameStartup *gs) if (totalheight < 190 || AllEpisodes.Size() == 1) { - int newtop = (200 - totalheight + topy) / 2; + int newtop = (200 - totalheight) / 2; int topdelta = newtop - topy; if (topdelta < 0) { @@ -1162,7 +1162,8 @@ void M_StartupEpisodeMenu(FNewGameStartup *gs) { ld->mItems[i]->OffsetPositionY(topdelta); } - posy -= topdelta; + posy += topdelta; + ld->mYpos += topdelta; } if (!isOld) ld->mSelectedItem = ld->mItems.Size(); @@ -1751,7 +1752,7 @@ void M_StartupSkillMenu(FNewGameStartup *gs) if (totalheight < 190 || MenuSkills.Size() == 1) { - int newtop = (200 - totalheight + topy) / 2; + int newtop = (200 - totalheight) / 2; int topdelta = newtop - topy; if (topdelta < 0) { @@ -1759,7 +1760,7 @@ void M_StartupSkillMenu(FNewGameStartup *gs) { ld->mItems[i]->OffsetPositionY(topdelta); } - ld->mYpos = y = posy - topdelta; + ld->mYpos = y = posy + topdelta; } } else From 555845222d19482b6b3c38c6f8874195d4c00f90 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 26 May 2020 10:02:16 +0300 Subject: [PATCH 185/220] - fixed fullscreen toggle via shortcut --- src/g_game.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_game.cpp b/src/g_game.cpp index d5662767c5..7cdebeee85 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1102,7 +1102,7 @@ void G_Ticker () if (ToggleFullscreen) { ToggleFullscreen = false; - AddCommandString ("toggle fullscreen"); + AddCommandString ("toggle vid_fullscreen"); } // do things to change the game state From 12a55ff161ae8f93b660d8a78b453b90de2b519e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 26 May 2020 11:51:15 +0200 Subject: [PATCH 186/220] - removed entry for non-functional linear tonemap. --- wadsrc/static/menudef.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 3de49f9404..4ed6d2d6de 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -2348,7 +2348,6 @@ OptionValue "TonemapModes" 1, "$OPTVAL_UNCHARTED2" 2, "$OPTVAL_HEJLDAWSON" 3, "$OPTVAL_REINHARD" - 4, "$OPTVAL_LINEAR_3" 5, "$OPTVAL_PALETTE" } From 2a063c96da97b8f5eeed517fecf5d6ba15fed73d Mon Sep 17 00:00:00 2001 From: Alexander Kromm Date: Wed, 27 May 2020 00:02:34 +0700 Subject: [PATCH 187/220] more descriptive message for server CVAR change attempt in netgame Rationale: while the previous description contains the name of a CVAR, it doesn't specify that it's a CVAR. Unsuspecting user may be not aware that the engine or a mod contains such a CVAR. --- src/d_netinfo.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/d_netinfo.cpp b/src/d_netinfo.cpp index 00ad7e62ce..9cd0302b22 100644 --- a/src/d_netinfo.cpp +++ b/src/d_netinfo.cpp @@ -629,7 +629,7 @@ bool D_SendServerInfoChange (FBaseCVar *cvar, UCVarValue value, ECVarType type) { if (netgame && !players[consoleplayer].settings_controller) { - Printf("Only setting controllers can change %s\n", cvar->GetName()); + Printf("Only setting controllers can change server CVAR %s\n", cvar->GetName()); cvar->MarkSafe(); return true; } @@ -659,7 +659,10 @@ bool D_SendServerFlagChange (FBaseCVar *cvar, int bitnum, bool set, bool silent) { if (netgame && !players[consoleplayer].settings_controller) { - if (!silent) Printf("Only setting controllers can change %s\n", cvar->GetName()); + if (!silent) + { + Printf("Only setting controllers can change server CVAR %s\n", cvar->GetName()); + } return true; } From 4881ec257a8a4cc3f6b5513c8e051757cf1f9a5d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 26 May 2020 22:19:30 +0200 Subject: [PATCH 188/220] - don't let CHANF_AUTO hijack other channels. With CHANF_OVERLAP this isn't needed anymore - any sound started on CHAN_AUTO can actually play on this channel with overlap implicitly allowed. This has the added advantage that these sounds can be reliably accessed with other function by using CHAN_AUTO. --- src/common/2d/v_2ddrawer.cpp | 1 + src/common/audio/sound/s_sound.cpp | 23 +++-------------------- src/common/thirdparty/sfmt/SFMT.h | 2 ++ 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 9d89d3e663..98c0ba7117 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -397,6 +397,7 @@ void F2DDrawer::SetColorOverlay(PalEntry color, float alpha, PalEntry &vertexcol void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms) { if (parms.style.BlendOp == STYLEOP_None) return; // not supposed to be drawn. + assert(img && img->isValid()); double xscale = parms.destwidth / parms.texwidth; double yscale = parms.destheight / parms.texheight; diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index b274a57547..b6d6bb2423 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -494,26 +494,9 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source, int seen = 0; if (source != NULL && channel == CHAN_AUTO) { - // Select a channel that isn't already playing something. - // Try channel 0 first, then travel from channel 7 down. - if (!IsChannelUsed(type, source, 0, &seen)) - { - channel = 0; - } - else - { - for (channel = 7; channel > 0; --channel) - { - if (!IsChannelUsed(type, source, channel, &seen)) - { - break; - } - } - if (channel == 0) - { // Crap. No free channels. - return NULL; - } - } + // In the old sound system, 'AUTO' hijacked one of the other channels. + // Now, with CHANF_OVERLAP at our disposal that isn't needed anymore. Just set the flag and let all sounds play on channel 0. + chanflags |= CHANF_OVERLAP; } // If this actor is already playing something on the selected channel, stop it. diff --git a/src/common/thirdparty/sfmt/SFMT.h b/src/common/thirdparty/sfmt/SFMT.h index ddaabf2461..b7d3c42f37 100644 --- a/src/common/thirdparty/sfmt/SFMT.h +++ b/src/common/thirdparty/sfmt/SFMT.h @@ -28,6 +28,8 @@ * unsigned int and 64-bit unsigned int in hexadecimal format. */ +#include + #ifndef SFMT_H #define SFMT_H From c892fb1ddb50521b18d1e6cdb1a0cdfdf5f71129 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 26 May 2020 22:59:50 +0200 Subject: [PATCH 189/220] - backend sync with Raze Mostly code reformatting plus license and copyright adjustments --- src/common/2d/v_2ddrawer.cpp | 2 +- src/common/scripting/jit/jit_move.cpp | 1 + src/common/scripting/vm/vmexec.cpp | 1 + src/common/textures/animtexture.cpp | 38 +++++------ src/common/textures/animtexture.h | 12 ++-- src/common/textures/formats/ddstexture.cpp | 5 +- src/common/textures/formats/jpegtexture.cpp | 3 +- src/common/textures/formats/pcxtexture.cpp | 2 +- src/common/textures/formats/pngtexture.cpp | 9 +-- src/common/textures/formats/tgatexture.cpp | 2 +- src/common/textures/gametexture.h | 9 +++ src/common/textures/hw_texcontainer.h | 10 ++- src/common/textures/imagehelpers.h | 1 - .../textures/multipatchtexturebuilder.cpp | 1 - src/common/textures/skyboxtexture.cpp | 53 +++++++++------ src/common/textures/texture.cpp | 68 +++++++++---------- src/common/textures/texturemanager.cpp | 1 - src/common/textures/textures.h | 6 +- 18 files changed, 126 insertions(+), 98 deletions(-) diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 98c0ba7117..b397cc88d7 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -45,7 +45,7 @@ F2DDrawer* twod = &drawer; EXTERN_CVAR(Float, transsouls) CVAR(Float, classic_scaling_factor, 1.0, CVAR_ARCHIVE) -CVAR(Float, classic_scaling_pixelaspect, 1.2, CVAR_ARCHIVE) +CVAR(Float, classic_scaling_pixelaspect, 1.2f, CVAR_ARCHIVE) IMPLEMENT_CLASS(DShape2DTransform, false, false) diff --git a/src/common/scripting/jit/jit_move.cpp b/src/common/scripting/jit/jit_move.cpp index a02898ac06..53644568c3 100644 --- a/src/common/scripting/jit/jit_move.cpp +++ b/src/common/scripting/jit/jit_move.cpp @@ -3,6 +3,7 @@ #include "v_video.h" #include "s_soundinternal.h" #include "texturemanager.h" +#include "palutil.h" void JitCompiler::EmitMOVE() { diff --git a/src/common/scripting/vm/vmexec.cpp b/src/common/scripting/vm/vmexec.cpp index 6921d3dac9..7180cb1034 100644 --- a/src/common/scripting/vm/vmexec.cpp +++ b/src/common/scripting/vm/vmexec.cpp @@ -42,6 +42,7 @@ #include "types.h" #include "basics.h" #include "texturemanager.h" +#include "palutil.h" extern cycle_t VMCycles[10]; extern int VMCalls[10]; diff --git a/src/common/textures/animtexture.cpp b/src/common/textures/animtexture.cpp index 387464fd0d..2d06eccab5 100644 --- a/src/common/textures/animtexture.cpp +++ b/src/common/textures/animtexture.cpp @@ -43,13 +43,13 @@ void AnimTexture::SetFrameSize(int width, int height) { FTexture::SetSize(width, height); - Image.Resize(width*height); + Image.Resize(width * height); } -void AnimTexture::SetFrame(const uint8_t *palette, const void *data_) +void AnimTexture::SetFrame(const uint8_t* palette, const void* data_) { - memcpy(Palette, palette, 768); - memcpy(Image.Data(), data_, Width * Height); + memcpy(Palette, palette, 768); + memcpy(Image.Data(), data_, Width * Height); CleanHardwareTextures(); } @@ -70,10 +70,10 @@ FBitmap AnimTexture::GetBgraBitmap(const PalEntry* remap, int* trans) for (int i = 0; i < Width * Height; i++) { int p = i * 4; - int index = spix[i]; - dpix[p + 0] = Palette[index*3+2]; - dpix[p + 1] = Palette[index*3+1]; - dpix[p + 2] = Palette[index*3]; + int index = spix[i]; + dpix[p + 0] = Palette[index * 3 + 2]; + dpix[p + 1] = Palette[index * 3 + 1]; + dpix[p + 2] = Palette[index * 3]; dpix[p + 3] = 255; } return bmp; @@ -87,32 +87,32 @@ FBitmap AnimTexture::GetBgraBitmap(const PalEntry* remap, int* trans) AnimTextures::AnimTextures() { - active = 1; - tex[0] = MakeGameTexture(new AnimTexture, "", ETextureType::Special); - tex[1] = MakeGameTexture(new AnimTexture, "", ETextureType::Special); + active = 1; + tex[0] = MakeGameTexture(new AnimTexture, "", ETextureType::Special); + tex[1] = MakeGameTexture(new AnimTexture, "", ETextureType::Special); } AnimTextures::~AnimTextures() { - delete tex[0]; - delete tex[1]; + delete tex[0]; + delete tex[1]; } void AnimTextures::SetSize(int width, int height) { - static_cast(tex[0]->GetTexture())->SetFrameSize(width, height); + static_cast(tex[0]->GetTexture())->SetFrameSize(width, height); static_cast(tex[1]->GetTexture())->SetFrameSize(width, height); tex[0]->SetSize(width, height); tex[1]->SetSize(width, height); } - -void AnimTextures::SetFrame(const uint8_t *palette, const void* data) + +void AnimTextures::SetFrame(const uint8_t* palette, const void* data) { - active ^= 1; + active ^= 1; static_cast(tex[active]->GetTexture())->SetFrame(palette, data); } -FGameTexture * AnimTextures::GetFrame() +FGameTexture* AnimTextures::GetFrame() { - return tex[active]; + return tex[active]; } diff --git a/src/common/textures/animtexture.h b/src/common/textures/animtexture.h index 74414fee47..2515253a77 100644 --- a/src/common/textures/animtexture.h +++ b/src/common/textures/animtexture.h @@ -8,21 +8,21 @@ class AnimTexture : public FTexture uint8_t Palette[768]; TArray Image; public: - AnimTexture() = default; + AnimTexture() = default; void SetFrameSize(int width, int height); - void SetFrame(const uint8_t *palette, const void* data); - virtual FBitmap GetBgraBitmap(const PalEntry* remap, int* trans) override; + void SetFrame(const uint8_t* palette, const void* data); + virtual FBitmap GetBgraBitmap(const PalEntry* remap, int* trans) override; }; class AnimTextures { int active; - FGameTexture *tex[2]; + FGameTexture* tex[2]; public: AnimTextures(); ~AnimTextures(); void SetSize(int width, int height); - void SetFrame(const uint8_t *palette, const void* data); - FGameTexture *GetFrame(); + void SetFrame(const uint8_t* palette, const void* data); + FGameTexture* GetFrame(); }; diff --git a/src/common/textures/formats/ddstexture.cpp b/src/common/textures/formats/ddstexture.cpp index 64b1b8604c..3a88fcdd14 100644 --- a/src/common/textures/formats/ddstexture.cpp +++ b/src/common/textures/formats/ddstexture.cpp @@ -1,9 +1,10 @@ /* -** pngtexture.cpp +** ddstexture.cpp ** Texture class for DDS images ** **--------------------------------------------------------------------------- -** Copyright 2006-2007 Randy Heit +** Copyright 2006-2016 Randy Heit +** Copyright 2006-2019 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without diff --git a/src/common/textures/formats/jpegtexture.cpp b/src/common/textures/formats/jpegtexture.cpp index 1d98ea85a4..e07f4425de 100644 --- a/src/common/textures/formats/jpegtexture.cpp +++ b/src/common/textures/formats/jpegtexture.cpp @@ -3,7 +3,8 @@ ** Texture class for JPEG images ** **--------------------------------------------------------------------------- -** Copyright 2006-2007 Randy Heit +** Copyright 2005-2016 Randy Heit +** Copyright 2005-2019 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without diff --git a/src/common/textures/formats/pcxtexture.cpp b/src/common/textures/formats/pcxtexture.cpp index a995ec672a..89d05e4271 100644 --- a/src/common/textures/formats/pcxtexture.cpp +++ b/src/common/textures/formats/pcxtexture.cpp @@ -4,7 +4,7 @@ ** **--------------------------------------------------------------------------- ** Copyright 2005 David HENRY -** Copyright 2006 Christoph Oelckers +** Copyright 2006-2019 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without diff --git a/src/common/textures/formats/pngtexture.cpp b/src/common/textures/formats/pngtexture.cpp index f8ba8648f9..48eb2437c6 100644 --- a/src/common/textures/formats/pngtexture.cpp +++ b/src/common/textures/formats/pngtexture.cpp @@ -4,6 +4,7 @@ ** **--------------------------------------------------------------------------- ** Copyright 2004-2007 Randy Heit +** Copyright 2005-2019 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -34,7 +35,6 @@ */ #include "files.h" -#include "filesystem.h" #include "templates.h" #include "m_png.h" #include "bitmap.h" @@ -42,6 +42,7 @@ #include "image.h" #include "printf.h" #include "texturemanager.h" +#include "filesystem.h" //========================================================================== // @@ -640,7 +641,7 @@ class FPNGFileTexture : public FTexture { public: FPNGFileTexture (FileReader &lump, int width, int height, uint8_t colortype); - virtual FBitmap GetBgraBitmap(const PalEntry *remap, int *trans); + virtual FBitmap GetBgraBitmap(const PalEntry *remap, int *trans) override; protected: @@ -721,7 +722,7 @@ FBitmap FPNGFileTexture::GetBgraBitmap(const PalEntry *remap, int *trans) lump->Seek (len, FileReader::SeekCur); else { - PaletteSize = MIN (len / 3, 256); + PaletteSize = std::min (len / 3, 256); for(int i = 0; i < PaletteSize; i++) { pe[i].r = lump->ReadUInt8(); @@ -753,4 +754,4 @@ FBitmap FPNGFileTexture::GetBgraBitmap(const PalEntry *remap, int *trans) bmp.CopyPixelDataRGB(0, 0, Pixels.Data(), Width, Height, 3, pixwidth, 0, CF_RGB); } return bmp; -} +} \ No newline at end of file diff --git a/src/common/textures/formats/tgatexture.cpp b/src/common/textures/formats/tgatexture.cpp index 0cc0d210a9..80c7b04a89 100644 --- a/src/common/textures/formats/tgatexture.cpp +++ b/src/common/textures/formats/tgatexture.cpp @@ -3,7 +3,7 @@ ** Texture class for TGA images ** **--------------------------------------------------------------------------- -** Copyright 2006 Christoph Oelckers +** Copyright 2006-2019 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 7b4c461746..38c0908c62 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -108,6 +108,8 @@ class FGameTexture public: + float alphaThreshold = 0.5f; + FGameTexture(FTexture* wrap, const char *name); ~FGameTexture(); void Setup(FTexture* wrap); @@ -253,6 +255,13 @@ public: LeftOffset[which] = x; TopOffset[which] = y; } + void SetOffsets(int x, int y) + { + LeftOffset[0] = x; + TopOffset[0] = y; + LeftOffset[1] = x; + TopOffset[1] = y; + } void SetScale(float x, float y) { ScaleX = x; diff --git a/src/common/textures/hw_texcontainer.h b/src/common/textures/hw_texcontainer.h index cc350d635a..c75d42278d 100644 --- a/src/common/textures/hw_texcontainer.h +++ b/src/common/textures/hw_texcontainer.h @@ -60,8 +60,14 @@ private: TranslatedTexture * GetTexID(int translation, int scaleflags) { - auto remap = GPalette.TranslationToTable(translation); - translation = remap == nullptr ? 0 : remap->Index; + // Allow negative indices to pass through unchanged. + // This is needed for allowing the client to allocate slots that aren't matched to a palette, e.g. Build's indexed variants. + if (translation >= 0) + { + auto remap = GPalette.TranslationToTable(translation); + translation = remap == nullptr ? 0 : remap->Index; + } + else translation &= ~0x7fffffff; if (translation == 0 && !(scaleflags & CTF_Upscale)) { diff --git a/src/common/textures/imagehelpers.h b/src/common/textures/imagehelpers.h index feb5bfcac7..8923f92dba 100644 --- a/src/common/textures/imagehelpers.h +++ b/src/common/textures/imagehelpers.h @@ -147,5 +147,4 @@ namespace ImageHelpers } } } - } diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 46447f86d7..7def5cb7aa 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -873,7 +873,6 @@ void FMultipatchTextureBuilder::ResolveAllPatches() for (int i = BuiltTextures.Size()-1; i>= 0; i--) { auto &buildinfo = BuiltTextures[i]; - bool hasEmpty = false; for (unsigned j = 0; j < buildinfo.Inits.Size(); j++) diff --git a/src/common/textures/skyboxtexture.cpp b/src/common/textures/skyboxtexture.cpp index d8c645e8b9..2ca476a20e 100644 --- a/src/common/textures/skyboxtexture.cpp +++ b/src/common/textures/skyboxtexture.cpp @@ -1,24 +1,35 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2004-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// +/* +** skyboxtexture.cpp +** +**--------------------------------------------------------------------------- +** Copyright 2004-2019 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ #include "filesystem.h" #include "textures.h" diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 432026bc9d..016ac4fecc 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -76,7 +76,7 @@ FTexture::FTexture (int lumpnum) // //=========================================================================== -FBitmap FTexture::GetBgraBitmap(const PalEntry *remap, int *ptrans) +FBitmap FTexture::GetBgraBitmap(const PalEntry* remap, int* ptrans) { FBitmap bmp; bmp.Create(Width, Height); @@ -116,9 +116,9 @@ int FTexture::CheckRealHeight() // //=========================================================================== -bool FTexture::FindHoles(const unsigned char * buffer, int w, int h) +bool FTexture::FindHoles(const unsigned char* buffer, int w, int h) { - const unsigned char * li; + const unsigned char* li; int y, x; int startdraw, lendraw; int gaps[5][2]; @@ -134,11 +134,11 @@ bool FTexture::FindHoles(const unsigned char * buffer, int w, int h) startdraw = -1; lendraw = 0; - for (y = 0; y> 24; @@ -244,13 +244,13 @@ void FTexture::CheckTrans(unsigned char * buffer, int size, int trans) #define CHKPIX(ofs) (l1[(ofs)*4+MSB]==255 ? (( ((uint32_t*)l1)[0] = ((uint32_t*)l1)[ofs]&SOME_MASK), trans=true ) : false) -bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h) +bool FTexture::SmoothEdges(unsigned char* buffer, int w, int h) { int x, y; bool trans = buffer[MSB] == 0; // If I set this to false here the code won't detect textures // that only contain transparent pixels. bool semitrans = false; - unsigned char * l1; + unsigned char* l1; if (h <= 1 || w <= 1) return false; // makes (a) no sense and (b) doesn't work with this code! @@ -258,42 +258,42 @@ bool FTexture::SmoothEdges(unsigned char * buffer, int w, int h) if (l1[MSB] == 0 && !CHKPIX(1)) CHKPIX(w); - else if (l1[MSB]<255) semitrans = true; + else if (l1[MSB] < 255) semitrans = true; l1 += 4; - for (x = 1; xPalette : nullptr, &trans); + auto Pixels = GetBgraBitmap(remap ? remap->Palette : nullptr, &trans); bmp.Blit(exx, exx, Pixels); if (remap == nullptr) { - CheckTrans(buffer, W*H, trans); + CheckTrans(buffer, W * H, trans); isTransparent = bTranslucent; } else @@ -375,9 +375,10 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags) result.mHeight = H; // Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.) - if (GetImage() && flags & CTF_ProcessData) + if (GetImage() && flags & CTF_ProcessData) { if (flags & CTF_Upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly); + if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false); } @@ -392,8 +393,8 @@ FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags) bool FTexture::DetermineTranslucency() { - // This will calculate all we need, so just discard the result. - CreateTexBuffer(0); + // This will calculate all we need, so just discard the result. + CreateTexBuffer(0); return !!bTranslucent; } @@ -512,10 +513,10 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags) { IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags); if (hwtex == nullptr) - { + { hwtex = CreateHardwareTexture(); SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex); - } + } return hwtex; } return nullptr; @@ -539,4 +540,3 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) SystemTextures.AddHardwareTexture(0, false, hwtex); } - diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index eac5f30081..c7cffd07cd 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -625,7 +625,6 @@ void FTextureManager::AddHiresTextures (int wadnum) auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override); gtex->SetWorldPanning(true); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); - gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY())); ReplaceTexture(tlist[i], gtex, true); diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index 9ca6be736b..b3e900ef6a 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -3,7 +3,7 @@ ** **--------------------------------------------------------------------------- ** Copyright 2005-2016 Randy Heit -** Copyright 2005-2016 Christoph Oelckers +** Copyright 2005-2019 Christoph Oelckers ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without @@ -203,8 +203,9 @@ class FTexture : public RefCountedBase { friend class FGameTexture; // only for the porting work -protected: +public: FHardwareTextureContainer SystemTextures; +protected: FloatRect* areas = nullptr; int SourceLump; uint16_t Width = 0, Height = 0; @@ -250,7 +251,6 @@ public: int GetSourceLump() { return SourceLump; } // needed by the scripted GetName method. bool FindHoles(const unsigned char * buffer, int w, int h); - void CopySize(FTexture* BaseTexture) { Width = BaseTexture->GetWidth(); From 332dfa4d6fb33fb9cd106c3d1d274d14887b5724 Mon Sep 17 00:00:00 2001 From: drfrag Date: Wed, 27 May 2020 18:41:34 +0200 Subject: [PATCH 190/220] - Remove wrong GL includes. --- src/common/platform/win32/win32basevideo.cpp | 5 ----- src/rendering/hwrenderer/hw_entrypoint.cpp | 1 - 2 files changed, 6 deletions(-) diff --git a/src/common/platform/win32/win32basevideo.cpp b/src/common/platform/win32/win32basevideo.cpp index fe2ba3b9a3..de149ae9b5 100644 --- a/src/common/platform/win32/win32basevideo.cpp +++ b/src/common/platform/win32/win32basevideo.cpp @@ -33,10 +33,7 @@ */ #include -#include -#include "wglext.h" -#include "gl_sysfb.h" #include "hardware.h" #include "x86.h" #include "templates.h" @@ -52,8 +49,6 @@ #include "win32basevideo.h" #include "cmdlib.h" -#include "gl_framebuffer.h" - CVAR(Int, vid_adapter, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) //========================================================================== diff --git a/src/rendering/hwrenderer/hw_entrypoint.cpp b/src/rendering/hwrenderer/hw_entrypoint.cpp index e1ad075a37..c11e3d7d5c 100644 --- a/src/rendering/hwrenderer/hw_entrypoint.cpp +++ b/src/rendering/hwrenderer/hw_entrypoint.cpp @@ -25,7 +25,6 @@ ** */ -#include "gl_system.h" #include "gi.h" #include "a_dynlight.h" #include "m_png.h" From a517b04908349f1ed3b98c8cc224b13b49c462ed Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 28 May 2020 22:51:17 +0200 Subject: [PATCH 191/220] - texture sampler cleanup. --- src/common/rendering/gl/gl_framebuffer.cpp | 4 +- src/common/rendering/gl/gl_framebuffer.h | 2 +- src/common/rendering/gl/gl_hwtexture.cpp | 14 ------ src/common/rendering/gl/gl_hwtexture.h | 9 ++-- src/common/rendering/gl/gl_samplers.cpp | 47 ++++++++++++------- src/common/rendering/gl/gl_samplers.h | 6 +-- .../polyrenderer/backend/poly_framebuffer.cpp | 2 +- .../polyrenderer/backend/poly_framebuffer.h | 2 +- .../polyrenderer/drawers/poly_vertex_shader.h | 6 +-- src/common/rendering/v_video.cpp | 4 +- src/common/rendering/v_video.h | 2 +- .../vulkan/system/vk_framebuffer.cpp | 2 +- .../rendering/vulkan/system/vk_framebuffer.h | 2 +- src/common/textures/hw_material.cpp | 2 - src/common/textures/texture.cpp | 6 +-- src/common/textures/textures.h | 16 ++++--- 16 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/common/rendering/gl/gl_framebuffer.cpp b/src/common/rendering/gl/gl_framebuffer.cpp index 96d8170b6e..628756b6de 100644 --- a/src/common/rendering/gl/gl_framebuffer.cpp +++ b/src/common/rendering/gl/gl_framebuffer.cpp @@ -297,9 +297,9 @@ void OpenGLFrameBuffer::SetTextureFilterMode() if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode(); } -IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture() +IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(int numchannels) { - return new FHardwareTexture(true/*tex->bNoCompress*/); + return new FHardwareTexture(numchannels); } void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) diff --git a/src/common/rendering/gl/gl_framebuffer.h b/src/common/rendering/gl/gl_framebuffer.h index 28c4c4d2a3..a99aef08cd 100644 --- a/src/common/rendering/gl/gl_framebuffer.h +++ b/src/common/rendering/gl/gl_framebuffer.h @@ -41,7 +41,7 @@ public: void UpdatePalette() override; const char* DeviceName() const override; void SetTextureFilterMode() override; - IHardwareTexture *CreateHardwareTexture() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; void PrecacheMaterial(FMaterial *mat, int translation) override; void TextureFilterChanged() override; void BeginFrame() override; diff --git a/src/common/rendering/gl/gl_hwtexture.cpp b/src/common/rendering/gl/gl_hwtexture.cpp index 143aba1831..c27304ee63 100644 --- a/src/common/rendering/gl/gl_hwtexture.cpp +++ b/src/common/rendering/gl/gl_hwtexture.cpp @@ -59,20 +59,6 @@ TexFilter_s TexFilter[]={ {GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST, true}, }; -int TexFormat[]={ - GL_RGBA8, - GL_RGB5_A1, - GL_RGBA4, - GL_RGBA2, - // [BB] Added compressed texture formats. - GL_COMPRESSED_RGBA_ARB, - GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, - GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, -}; - - - //=========================================================================== // // Static texture data diff --git a/src/common/rendering/gl/gl_hwtexture.h b/src/common/rendering/gl/gl_hwtexture.h index d25131d777..41d8ae44aa 100644 --- a/src/common/rendering/gl/gl_hwtexture.h +++ b/src/common/rendering/gl/gl_hwtexture.h @@ -34,20 +34,21 @@ public: private: - bool forcenocompression; + bool forcenofilter; unsigned int glTexID = 0; unsigned int glDepthID = 0; // only used by camera textures unsigned int glBufferID = 0; - int glTextureBytes = 4; + int glTextureBytes; bool mipmapped = false; int GetDepthBuffer(int w, int h); public: - FHardwareTexture(bool nocompress) + FHardwareTexture(int numchannels = 4, bool disablefilter = false) { - forcenocompression = nocompress; + forcenofilter = disablefilter; + glTextureBytes = numchannels; } ~FHardwareTexture(); diff --git a/src/common/rendering/gl/gl_samplers.cpp b/src/common/rendering/gl/gl_samplers.cpp index a9f45dc2f3..caaedd6cce 100644 --- a/src/common/rendering/gl/gl_samplers.cpp +++ b/src/common/rendering/gl/gl_samplers.cpp @@ -51,22 +51,33 @@ extern TexFilter_s TexFilter[]; FSamplerManager::FSamplerManager() { - glGenSamplers(7, mSamplers); + glGenSamplers(NUMSAMPLERS, mSamplers); + + glSamplerParameteri(mSamplers[CLAMP_X], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_Y], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_XY], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_XY], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_NOFILTER_X], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_NOFILTER_Y], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_NOFILTER_XY], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_NOFILTER_XY], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + for (int i = CLAMP_NOFILTER; i <= CLAMP_NOFILTER_XY; i++) + { + glSamplerParameteri(mSamplers[i], GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glSamplerParameteri(mSamplers[i], GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); + + } + + glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glSamplerParameterf(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); + glSamplerParameterf(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); + SetTextureFilterMode(); - glSamplerParameteri(mSamplers[5], GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glSamplerParameteri(mSamplers[5], GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glSamplerParameterf(mSamplers[5], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); - glSamplerParameterf(mSamplers[4], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); - glSamplerParameterf(mSamplers[6], GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.f); - glSamplerParameteri(mSamplers[1], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[2], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[3], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[3], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[4], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glSamplerParameteri(mSamplers[4], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - for (int i = 0; i < 7; i++) + for (int i = 0; i < NUMSAMPLERS; i++) { FString name; name.Format("mSamplers[%d]", i); @@ -77,7 +88,7 @@ FSamplerManager::FSamplerManager() FSamplerManager::~FSamplerManager() { UnbindAll(); - glDeleteSamplers(7, mSamplers); + glDeleteSamplers(NUMSAMPLERS, mSamplers); } void FSamplerManager::UnbindAll() @@ -107,10 +118,10 @@ void FSamplerManager::SetTextureFilterMode() glSamplerParameteri(mSamplers[i], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_texture_filter_anisotropic); } - glSamplerParameteri(mSamplers[4], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); - glSamplerParameteri(mSamplers[4], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); - glSamplerParameteri(mSamplers[6], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); - glSamplerParameteri(mSamplers[6], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter); + glSamplerParameteri(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter); } diff --git a/src/common/rendering/gl/gl_samplers.h b/src/common/rendering/gl/gl_samplers.h index 93c8c74191..109f910a5f 100644 --- a/src/common/rendering/gl/gl_samplers.h +++ b/src/common/rendering/gl/gl_samplers.h @@ -2,15 +2,15 @@ #define __GL_SAMPLERS_H #include "gl_hwtexture.h" +#include "textures.h" namespace OpenGLRenderer { + class FSamplerManager { - // We need 6 different samplers: 4 for the different clamping modes, - // one for 2D-textures and one for voxel textures - unsigned int mSamplers[7]; + unsigned int mSamplers[NUMSAMPLERS]; void UnbindAll(); diff --git a/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp index 19ecb68711..d9cb212e3a 100644 --- a/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -305,7 +305,7 @@ void PolyFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) } } -IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture() +IHardwareTexture *PolyFrameBuffer::CreateHardwareTexture(int numchannels) { return new PolyHardwareTexture(); } diff --git a/src/common/rendering/polyrenderer/backend/poly_framebuffer.h b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h index c96dfa321e..68e722a2b5 100644 --- a/src/common/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h @@ -44,7 +44,7 @@ public: void AmbientOccludeScene(float m5) override; //void SetSceneRenderTarget(bool useSSAO) override; - IHardwareTexture *CreateHardwareTexture() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; IDataBuffer *CreateDataBuffer(int bindingpoint, bool ssbo, bool needsresize) override; diff --git a/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h b/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h index 8ae178127f..aaf613d986 100644 --- a/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h +++ b/src/common/rendering/polyrenderer/drawers/poly_vertex_shader.h @@ -104,7 +104,7 @@ public: FVector3 u = normalize3(eyeCoordPos); FVector3 n = normalize3(mul(Viewpoint->mNormalViewMatrix, FVector4(parmTexCoord.X, 0.0f, parmTexCoord.Y, 0.0f))); FVector3 r = reflect(u, n); - float m = 2.0f * sqrt(r.X*r.X + r.Y*r.Y + (r.Z + 1.0f)*(r.Z + 1.0f)); + float m = 2.0f * sqrtf(r.X*r.X + r.Y*r.Y + (r.Z + 1.0f)*(r.Z + 1.0f)); vTexCoord.X = r.X / m + 0.5f; vTexCoord.Y = r.Y / m + 0.5f; } @@ -138,13 +138,13 @@ public: private: static FVector3 normalize(const FVector3 &a) { - float rcplen = 1.0f / sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z); + float rcplen = 1.0f / sqrtf(a.X * a.X + a.Y * a.Y + a.Z * a.Z); return FVector3(a.X * rcplen, a.Y * rcplen, a.Z * rcplen); } static FVector3 normalize3(const FVector4 &a) { - float rcplen = 1.0f / sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z); + float rcplen = 1.0f / sqrtf(a.X * a.X + a.Y * a.Y + a.Z * a.Z); return FVector3(a.X * rcplen, a.Y * rcplen, a.Z * rcplen); } diff --git a/src/common/rendering/v_video.cpp b/src/common/rendering/v_video.cpp index 9a4b455f85..7035e54cc1 100644 --- a/src/common/rendering/v_video.cpp +++ b/src/common/rendering/v_video.cpp @@ -457,9 +457,9 @@ DEFINE_GLOBAL(CleanYfac_1) DEFINE_GLOBAL(CleanWidth_1) DEFINE_GLOBAL(CleanHeight_1) -IHardwareTexture* CreateHardwareTexture() +IHardwareTexture* CreateHardwareTexture(int numchannels) { - return screen->CreateHardwareTexture(); + return screen->CreateHardwareTexture(numchannels); } //========================================================================== diff --git a/src/common/rendering/v_video.h b/src/common/rendering/v_video.h index e284ca79f0..1cb32573ee 100644 --- a/src/common/rendering/v_video.h +++ b/src/common/rendering/v_video.h @@ -197,7 +197,7 @@ public: // Delete any resources that need to be deleted after restarting with a different IWAD virtual void SetTextureFilterMode() {} - virtual IHardwareTexture *CreateHardwareTexture() { return nullptr; } + virtual IHardwareTexture *CreateHardwareTexture(int numchannels) { return nullptr; } virtual void PrecacheMaterial(FMaterial *mat, int translation) {} virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags); virtual void TextureFilterChanged() {} diff --git a/src/common/rendering/vulkan/system/vk_framebuffer.cpp b/src/common/rendering/vulkan/system/vk_framebuffer.cpp index 8cc0046ea3..76e9c219f8 100644 --- a/src/common/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/common/rendering/vulkan/system/vk_framebuffer.cpp @@ -379,7 +379,7 @@ void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) } } -IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture() +IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture(int numchannels) { return new VkHardwareTexture(); } diff --git a/src/common/rendering/vulkan/system/vk_framebuffer.h b/src/common/rendering/vulkan/system/vk_framebuffer.h index 537879e6a6..b325466fed 100644 --- a/src/common/rendering/vulkan/system/vk_framebuffer.h +++ b/src/common/rendering/vulkan/system/vk_framebuffer.h @@ -89,7 +89,7 @@ public: void ImageTransitionScene(bool unknown) override; void SetActiveRenderTarget() override; - IHardwareTexture *CreateHardwareTexture() override; + IHardwareTexture *CreateHardwareTexture(int numchannels) override; FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override; IVertexBuffer *CreateVertexBuffer() override; IIndexBuffer *CreateIndexBuffer() override; diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 2930826073..4f5c301dbd 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -29,8 +29,6 @@ #include "c_cvars.h" #include "v_video.h" -IHardwareTexture* CreateHardwareTexture(); - //=========================================================================== // // Constructor diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 016ac4fecc..e8626eaf73 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -50,7 +50,7 @@ #include "c_cvars.h" // Wrappers to keep the definitions of these classes out of here. -IHardwareTexture* CreateHardwareTexture(); +IHardwareTexture* CreateHardwareTexture(int numchannels); // Make sprite offset adjustment user-configurable per renderer. int r_spriteadjustSW, r_spriteadjustHW; @@ -514,7 +514,7 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags) IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags); if (hwtex == nullptr) { - hwtex = CreateHardwareTexture(); + hwtex = CreateHardwareTexture(4); SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex); } return hwtex; @@ -535,7 +535,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) Height = h; Format = bits; //bNoCompress = true; - auto hwtex = CreateHardwareTexture(); + auto hwtex = CreateHardwareTexture(4); // todo: Initialize here. SystemTextures.AddHardwareTexture(0, false, hwtex); } diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index b3e900ef6a..9fc99bda9b 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -54,12 +54,16 @@ class IHardwareTexture; enum { CLAMP_NONE = 0, - CLAMP_X = 1, - CLAMP_Y = 2, - CLAMP_XY = 3, - CLAMP_XY_NOMIP = 4, - CLAMP_NOFILTER = 5, - CLAMP_CAMTEX = 6, + CLAMP_X, + CLAMP_Y, + CLAMP_XY, + CLAMP_XY_NOMIP, + CLAMP_NOFILTER, + CLAMP_NOFILTER_X, + CLAMP_NOFILTER_Y, + CLAMP_NOFILTER_XY, + CLAMP_CAMTEX, + NUMSAMPLERS }; enum MaterialShaderIndex From 5861fdd4bdc3da0a55a84503cd3d5f61577d4aca Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 29 May 2020 11:48:29 +0200 Subject: [PATCH 192/220] - minor cleanup of FHardwareTexture. Inlining of a trivial function and removing dependency on the render state, unbinding the render state should be done elsewhere. --- src/common/rendering/gl/gl_framebuffer.cpp | 2 ++ src/common/rendering/gl/gl_hwtexture.cpp | 10 ++-------- src/common/rendering/gl/gl_hwtexture.h | 22 +++++++++++++++------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/common/rendering/gl/gl_framebuffer.cpp b/src/common/rendering/gl/gl_framebuffer.cpp index 628756b6de..6c5dbb3db7 100644 --- a/src/common/rendering/gl/gl_framebuffer.cpp +++ b/src/common/rendering/gl/gl_framebuffer.cpp @@ -263,6 +263,7 @@ void OpenGLFrameBuffer::Swap() Finish.Unclock(); camtexcount = 0; FHardwareTexture::UnbindAll(); + gl_RenderState.ClearLastMaterial(); mDebug->Update(); } @@ -321,6 +322,7 @@ void OpenGLFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) } // unbind everything. FHardwareTexture::UnbindAll(); + gl_RenderState.ClearLastMaterial(); } IVertexBuffer *OpenGLFrameBuffer::CreateVertexBuffer() diff --git a/src/common/rendering/gl/gl_hwtexture.cpp b/src/common/rendering/gl/gl_hwtexture.cpp index c27304ee63..31e104cfeb 100644 --- a/src/common/rendering/gl/gl_hwtexture.cpp +++ b/src/common/rendering/gl/gl_hwtexture.cpp @@ -42,14 +42,14 @@ #include "hw_cvars.h" #include "gl_debug.h" #include "gl_renderer.h" -#include "gl_renderstate.h" #include "gl_samplers.h" +#include "gl_hwtexture.h" namespace OpenGLRenderer { -TexFilter_s TexFilter[]={ +TexFilter_s TexFilter[] = { {GL_NEAREST, GL_NEAREST, false}, {GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST, true}, {GL_LINEAR, GL_LINEAR, false}, @@ -237,11 +237,6 @@ unsigned int FHardwareTexture::Bind(int texunit, bool needmipmap) return 0; } -unsigned int FHardwareTexture::GetTextureHandle(int translation) -{ - return glTexID; -} - void FHardwareTexture::Unbind(int texunit) { if (lastbound[texunit] != 0) @@ -259,7 +254,6 @@ void FHardwareTexture::UnbindAll() { Unbind(texunit); } - gl_RenderState.ClearLastMaterial(); } //=========================================================================== diff --git a/src/common/rendering/gl/gl_hwtexture.h b/src/common/rendering/gl/gl_hwtexture.h index 41d8ae44aa..1b3cdff2cc 100644 --- a/src/common/rendering/gl/gl_hwtexture.h +++ b/src/common/rendering/gl/gl_hwtexture.h @@ -1,6 +1,10 @@ +#pragma once +class FBitmap; +class FTexture; + +#include "tarray.h" +#include "hw_ihwtexture.h" -#ifndef __GLTEXTURE_H -#define __GLTEXTURE_H #ifdef LoadImage #undef LoadImage @@ -59,14 +63,18 @@ public: void BindToFrameBuffer(int w, int h); unsigned int Bind(int texunit, bool needmipmap); - bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags); + bool BindOrCreate(FTexture* tex, int texunit, int clampmode, int translation, int flags); void AllocateBuffer(int w, int h, int texelsize); - uint8_t *MapBuffer(); + uint8_t* MapBuffer(); - unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, const char *name); - unsigned int GetTextureHandle(int translation); + unsigned int CreateTexture(unsigned char* buffer, int w, int h, int texunit, bool mipmap, const char* name); + unsigned int GetTextureHandle() + { + return glTexID; + } + + int numChannels() { return glTextureBytes; } }; } -#endif From b60fd4d8bca73e0f77714f61f673c0df0c161aa0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 29 May 2020 11:53:37 +0200 Subject: [PATCH 193/220] - removed redundant TextureFilterChanged method from DFrameBuffer. --- src/common/rendering/gl/gl_framebuffer.cpp | 5 ----- src/common/rendering/gl/gl_framebuffer.h | 1 - src/common/rendering/hwrenderer/data/hw_cvars.cpp | 4 ++-- .../rendering/polyrenderer/backend/poly_framebuffer.cpp | 5 ----- src/common/rendering/polyrenderer/backend/poly_framebuffer.h | 1 - src/common/rendering/v_video.h | 1 - src/common/rendering/vulkan/system/vk_framebuffer.cpp | 5 ----- src/common/rendering/vulkan/system/vk_framebuffer.h | 1 - 8 files changed, 2 insertions(+), 21 deletions(-) diff --git a/src/common/rendering/gl/gl_framebuffer.cpp b/src/common/rendering/gl/gl_framebuffer.cpp index 6c5dbb3db7..d91503c3ce 100644 --- a/src/common/rendering/gl/gl_framebuffer.cpp +++ b/src/common/rendering/gl/gl_framebuffer.cpp @@ -340,11 +340,6 @@ IDataBuffer *OpenGLFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo, bo return new GLDataBuffer(bindingpoint, ssbo); } -void OpenGLFrameBuffer::TextureFilterChanged() -{ - if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode(); -} - void OpenGLFrameBuffer::BlurScene(float amount) { GLRenderer->BlurScene(amount); diff --git a/src/common/rendering/gl/gl_framebuffer.h b/src/common/rendering/gl/gl_framebuffer.h index a99aef08cd..aaebbfeb3f 100644 --- a/src/common/rendering/gl/gl_framebuffer.h +++ b/src/common/rendering/gl/gl_framebuffer.h @@ -43,7 +43,6 @@ public: void SetTextureFilterMode() override; IHardwareTexture *CreateHardwareTexture(int numchannels) override; void PrecacheMaterial(FMaterial *mat, int translation) override; - void TextureFilterChanged() override; void BeginFrame() override; void SetViewportRects(IntRect *bounds) override; void BlurScene(float amount) override; diff --git a/src/common/rendering/hwrenderer/data/hw_cvars.cpp b/src/common/rendering/hwrenderer/data/hw_cvars.cpp index 74edce16b3..c8a7abc289 100644 --- a/src/common/rendering/hwrenderer/data/hw_cvars.cpp +++ b/src/common/rendering/hwrenderer/data/hw_cvars.cpp @@ -121,13 +121,13 @@ CVAR(Int, gl_satformula, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); //========================================================================== CUSTOM_CVARD(Float, gl_texture_filter_anisotropic, 8, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL, "changes the OpenGL texture anisotropy setting") { - screen->TextureFilterChanged(); + screen->SetTextureFilterMode(); } CUSTOM_CVARD(Int, gl_texture_filter, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL, "changes the texture filtering settings") { if (self < 0 || self > 6) self=4; - screen->TextureFilterChanged(); + screen->SetTextureFilterMode(); } CVAR(Bool, gl_precache, false, CVAR_ARCHIVE) diff --git a/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp b/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp index d9cb212e3a..d1dbd63db0 100644 --- a/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp +++ b/src/common/rendering/polyrenderer/backend/poly_framebuffer.cpp @@ -329,11 +329,6 @@ IDataBuffer *PolyFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo, bool } void PolyFrameBuffer::SetTextureFilterMode() -{ - TextureFilterChanged(); -} - -void PolyFrameBuffer::TextureFilterChanged() { } diff --git a/src/common/rendering/polyrenderer/backend/poly_framebuffer.h b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h index 68e722a2b5..84982d9d5f 100644 --- a/src/common/rendering/polyrenderer/backend/poly_framebuffer.h +++ b/src/common/rendering/polyrenderer/backend/poly_framebuffer.h @@ -37,7 +37,6 @@ public: void PrecacheMaterial(FMaterial *mat, int translation) override; void UpdatePalette() override; void SetTextureFilterMode() override; - void TextureFilterChanged() override; void BeginFrame() override; void BlurScene(float amount) override; void PostProcessScene(bool swscene, int fixedcm, const std::function &afterBloomDrawEndScene2D) override; diff --git a/src/common/rendering/v_video.h b/src/common/rendering/v_video.h index 1cb32573ee..ac61291dd3 100644 --- a/src/common/rendering/v_video.h +++ b/src/common/rendering/v_video.h @@ -200,7 +200,6 @@ public: virtual IHardwareTexture *CreateHardwareTexture(int numchannels) { return nullptr; } virtual void PrecacheMaterial(FMaterial *mat, int translation) {} virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags); - virtual void TextureFilterChanged() {} virtual void BeginFrame() {} virtual void SetWindowSize(int w, int h) {} virtual void StartPrecaching() {} diff --git a/src/common/rendering/vulkan/system/vk_framebuffer.cpp b/src/common/rendering/vulkan/system/vk_framebuffer.cpp index 76e9c219f8..602d628b10 100644 --- a/src/common/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/common/rendering/vulkan/system/vk_framebuffer.cpp @@ -419,11 +419,6 @@ IDataBuffer *VulkanFrameBuffer::CreateDataBuffer(int bindingpoint, bool ssbo, bo } void VulkanFrameBuffer::SetTextureFilterMode() -{ - TextureFilterChanged(); -} - -void VulkanFrameBuffer::TextureFilterChanged() { if (mSamplerManager) { diff --git a/src/common/rendering/vulkan/system/vk_framebuffer.h b/src/common/rendering/vulkan/system/vk_framebuffer.h index b325466fed..b1a7764525 100644 --- a/src/common/rendering/vulkan/system/vk_framebuffer.h +++ b/src/common/rendering/vulkan/system/vk_framebuffer.h @@ -77,7 +77,6 @@ public: const char* DeviceName() const override; int Backend() override { return 1; } void SetTextureFilterMode() override; - void TextureFilterChanged() override; void StartPrecaching() override; void BeginFrame() override; void BlurScene(float amount) override; From 8c539539dfa23837f99ffc1dce4425807933c4f0 Mon Sep 17 00:00:00 2001 From: drfrag Date: Fri, 29 May 2020 13:01:34 +0200 Subject: [PATCH 194/220] - Fixed crash on maps with out of range sidedef and sector numbers, adapted from PRBoom. --- src/maploader/maploader.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/maploader/maploader.cpp b/src/maploader/maploader.cpp index 2342455569..961159590c 100644 --- a/src/maploader/maploader.cpp +++ b/src/maploader/maploader.cpp @@ -1702,13 +1702,6 @@ void MapLoader::LoadLineDefs (MapData * map) } else { - // patch missing first sides instead of crashing out. - // Visual glitches are better than not being able to play. - if (LittleShort(mld->sidenum[0]) == NO_INDEX) - { - Printf("Line %d has no first side.\n", i); - mld->sidenum[0] = 0; - } sidecount++; if (LittleShort(mld->sidenum[1]) != NO_INDEX) sidecount++; @@ -1747,6 +1740,22 @@ void MapLoader::LoadLineDefs (MapData * map) ProcessEDLinedef(ld, mld->tag); } #endif + // cph 2006/09/30 - fix sidedef errors right away. + for (int j=0; j < 2; j++) + { + if (LittleShort(mld->sidenum[j]) != NO_INDEX && mld->sidenum[j] >= Level->sides.Size()) + { + mld->sidenum[j] = 0; // dummy sidedef + Printf("Linedef %d has a bad sidedef\n", i); + } + } + // patch missing first sides instead of crashing out. + // Visual glitches are better than not being able to play. + if (LittleShort(mld->sidenum[0]) == NO_INDEX) + { + Printf("Line %d has no first side.\n", i); + mld->sidenum[0] = 0; + } ld->v1 = &Level->vertexes[LittleShort(mld->v1)]; ld->v2 = &Level->vertexes[LittleShort(mld->v2)]; @@ -2180,11 +2189,11 @@ void MapLoader::LoadSideDefs2 (MapData *map, FMissingTextureTracker &missingtex) // killough 4/4/98: allow sidedef texture names to be overloaded // killough 4/11/98: refined to allow colormaps to work as wall // textures if invalid as colormaps but valid as textures. - + // cph 2006/09/30 - catch out-of-range sector numbers; use sector 0 instead if ((unsigned)LittleShort(msd->sector)>=Level->sectors.Size()) { Printf (PRINT_HIGH, "Sidedef %d has a bad sector\n", i); - sd->sector = sec = nullptr; + sd->sector = sec = &Level->sectors[0]; } else { From 80c5b4d37b86cd7f8e64c25a0201b5bec0b7bc5e Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Sat, 18 Jan 2020 01:45:42 +0100 Subject: [PATCH 195/220] Add a cvar to control weapon bobbing while firing This simulates a feature found in Crispy Doom, which keeps the weapon bobbing while firing. This leads to a "smoother" appearance which may look a bit prettier to some people. The default value of 0 preserves the old behavior. --- src/common/engine/namedef.h | 1 + src/d_netinfo.cpp | 2 ++ src/playsim/d_player.h | 4 ++++ src/playsim/p_user.cpp | 6 ++++++ wadsrc/static/menudef.txt | 1 + wadsrc/static/zscript/actors/player/player.zs | 21 ++++++++++--------- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/common/engine/namedef.h b/src/common/engine/namedef.h index 7d7cff000e..9e20b35c23 100644 --- a/src/common/engine/namedef.h +++ b/src/common/engine/namedef.h @@ -810,6 +810,7 @@ xx(MoveBob) xx(StillBob) xx(ClassicFlight) xx(WBobSpeed) +xx(WBobFire) xx(PlayerClass) xx(MonsterClass) xx(MorphedMonster) diff --git a/src/d_netinfo.cpp b/src/d_netinfo.cpp index 9cd0302b22..f2fb30bee7 100644 --- a/src/d_netinfo.cpp +++ b/src/d_netinfo.cpp @@ -65,6 +65,7 @@ CVAR (Bool, neverswitchonpickup, false, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Float, movebob, 0.25f, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Float, stillbob, 0.f, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Float, wbobspeed, 1.f, CVAR_USERINFO | CVAR_ARCHIVE); +CVAR (Float, wbobfire, 0.f, CVAR_USERINFO | CVAR_ARCHIVE); CVAR (String, playerclass, "Fighter", CVAR_USERINFO | CVAR_ARCHIVE); CVAR (Bool, classicflight, false, CVAR_USERINFO | CVAR_ARCHIVE); @@ -80,6 +81,7 @@ enum INFO_MoveBob, INFO_StillBob, INFO_WBobSpeed, + INFO_WBobFire, INFO_PlayerClass, INFO_ColorSet, INFO_ClassicFlight, diff --git a/src/playsim/d_player.h b/src/playsim/d_player.h index 95ab1b8933..20f2d2f3b9 100644 --- a/src/playsim/d_player.h +++ b/src/playsim/d_player.h @@ -232,6 +232,10 @@ struct userinfo_t : TMap { return *static_cast(*CheckKey(NAME_WBobSpeed)); } + double GetWBobFire() const + { + return *static_cast(*CheckKey(NAME_WBobFire)); + } int GetPlayerClassNum() const { return *static_cast(*CheckKey(NAME_PlayerClass)); diff --git a/src/playsim/p_user.cpp b/src/playsim/p_user.cpp index f4a4e344d1..539a259112 100644 --- a/src/playsim/p_user.cpp +++ b/src/playsim/p_user.cpp @@ -790,6 +790,12 @@ DEFINE_ACTION_FUNCTION(_PlayerInfo, GetWBobSpeed) ACTION_RETURN_FLOAT(self->userinfo.GetWBobSpeed()); } +DEFINE_ACTION_FUNCTION(_PlayerInfo, GetWBobFire) +{ + PARAM_SELF_STRUCT_PROLOGUE(player_t); + ACTION_RETURN_FLOAT(self->userinfo.GetWBobFire()); +} + DEFINE_ACTION_FUNCTION(_PlayerInfo, GetMoveBob) { PARAM_SELF_STRUCT_PROLOGUE(player_t); diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 3de49f9404..ce03c396ac 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -1046,6 +1046,7 @@ OptionMenu "HUDOptions" protected Slider "$DSPLYMNU_MOVEBOB", "movebob", 0, 1.0, 0.05, 2 Slider "$DSPLYMNU_STILLBOB", "stillbob", 0, 1.0, 0.05, 2 Slider "$DSPLYMNU_BOBSPEED", "wbobspeed", 0, 2.0, 0.1 + Slider "$DSPLYMNU_BOBFIRE", "wbobfire", 0, 1.0, 0.1 StaticText " " Slider "$DSPLYMNU_MENUDIM", "dimamount", 0, 1.0, 0.05, 2 ColorPicker "$DSPLYMNU_DIMCOLOR", "dimcolor" diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index 3a57277393..d47b091826 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -2301,8 +2301,6 @@ class PlayerPawn : Actor Vector2 p1, p2, r; Vector2 result; - float bobtarget; - let player = self.player; if (!player) return (0, 0); let weapon = player.ReadyWeapon; @@ -2326,17 +2324,16 @@ class PlayerPawn : Actor // [RH] Smooth transitions between bobbing and not-bobbing frames. // This also fixes the bug where you can "stick" a weapon off-center by // shooting it when it's at the peak of its swing. - bobtarget = double((player.WeaponState & WF_WEAPONBOBBING) ? player.bob : 0.); - if (curbob != bobtarget) + if (curbob != player.bob) { - if (abs(bobtarget - curbob) <= 1) + if (abs(player.bob - curbob) <= 1) { - curbob = bobtarget; + curbob = player.bob; } else { - double zoom = MAX(1., abs(curbob - bobtarget) / 40); - if (curbob > bobtarget) + double zoom = MAX(1., abs(curbob - player.bob) / 40); + if (curbob > player.bob) { curbob -= zoom; } @@ -2347,11 +2344,14 @@ class PlayerPawn : Actor } } + // The weapon bobbing intensity while firing can be adjusted by the player. + double BobIntensity = (player.WeaponState & WF_WEAPONBOBBING) ? 1. : player.GetWBobFire(); + if (curbob != 0) { //[SP] Added in decorate player.viewbob checks - double bobx = (player.bob * Rangex * ViewBob); - double boby = (player.bob * Rangey * ViewBob); + double bobx = (player.bob * BobIntensity * Rangex * ViewBob); + double boby = (player.bob * BobIntensity * Rangey * ViewBob); switch (bobstyle) { case Bob_Normal: @@ -2710,6 +2710,7 @@ struct PlayerInfo native play // self is what internally is known as player_t native float GetAutoaim() const; native bool GetNoAutostartMap() const; native double GetWBobSpeed() const; + native double GetWBobFire() const; native double GetMoveBob() const; native double GetStillBob() const; native void SetFOV(float fov); From 4c11b0158881bb51118209730940ab7203f54f6a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 31 May 2020 23:37:11 +0200 Subject: [PATCH 196/220] - backend sync with Raze. --- src/common/rendering/gl/gl_framebuffer.cpp | 4 +- src/common/rendering/gl/gl_hwtexture.cpp | 10 +- src/common/rendering/gl/gl_samplers.cpp | 2 +- src/common/rendering/v_video.cpp | 5 - .../vulkan/textures/vk_hwtexture.cpp | 4 +- src/common/textures/gametexture.cpp | 2 +- src/common/textures/gametexture.h | 44 +++++++ src/common/textures/hw_material.cpp | 12 +- src/common/textures/hw_material.h | 5 + src/common/textures/hw_texcontainer.h | 1 + src/common/textures/texture.cpp | 122 ++++++++++-------- src/common/textures/texturemanager.cpp | 4 +- 12 files changed, 142 insertions(+), 73 deletions(-) diff --git a/src/common/rendering/gl/gl_framebuffer.cpp b/src/common/rendering/gl/gl_framebuffer.cpp index d91503c3ce..a089699492 100644 --- a/src/common/rendering/gl/gl_framebuffer.cpp +++ b/src/common/rendering/gl/gl_framebuffer.cpp @@ -56,6 +56,7 @@ #include "gl_postprocessstate.h" #include "v_draw.h" #include "printf.h" +#include "gl_hwtexture.h" #include "flatvertices.h" #include "hw_cvars.h" @@ -87,9 +88,9 @@ OpenGLFrameBuffer::OpenGLFrameBuffer(void *hMonitor, bool fullscreen) : // SetVSync needs to be at the very top to workaround a bug in Nvidia's OpenGL driver. // If wglSwapIntervalEXT is called after glBindFramebuffer in a frame the setting is not changed! Super::SetVSync(vid_vsync); + FHardwareTexture::InitGlobalState(); // Make sure all global variables tracking OpenGL context state are reset.. - FHardwareTexture::InitGlobalState(); gl_RenderState.Reset(); GLRenderer = nullptr; @@ -215,7 +216,6 @@ void OpenGLFrameBuffer::CopyScreenToBuffer(int width, int height, uint8_t* scr) //=========================================================================== void OpenGLFrameBuffer::RenderTextureView(FCanvasTexture* tex, std::function renderFunc) - { GLRenderer->StartOffscreen(); GLRenderer->BindToFrameBuffer(tex); diff --git a/src/common/rendering/gl/gl_hwtexture.cpp b/src/common/rendering/gl/gl_hwtexture.cpp index 31e104cfeb..70c3530821 100644 --- a/src/common/rendering/gl/gl_hwtexture.cpp +++ b/src/common/rendering/gl/gl_hwtexture.cpp @@ -42,6 +42,7 @@ #include "hw_cvars.h" #include "gl_debug.h" #include "gl_renderer.h" +#include "gl_renderstate.h" #include "gl_samplers.h" #include "gl_hwtexture.h" @@ -302,12 +303,16 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i { int usebright = false; - bool needmipmap = (clampmode <= CLAMP_XY); + bool needmipmap = (clampmode <= CLAMP_XY) && !forcenofilter; // Bind it to the system. if (!Bind(texunit, needmipmap)) { - + if (flags & CTF_Indexed) + { + glTextureBytes = 1; + forcenofilter = true; + } int w = 0, h = 0; // Create this texture @@ -331,6 +336,7 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i return false; } } + if (forcenofilter && clampmode <= CLAMP_XY) clampmode += CLAMP_NOFILTER - CLAMP_NONE; GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255); return true; } diff --git a/src/common/rendering/gl/gl_samplers.cpp b/src/common/rendering/gl/gl_samplers.cpp index caaedd6cce..a0573c468b 100644 --- a/src/common/rendering/gl/gl_samplers.cpp +++ b/src/common/rendering/gl/gl_samplers.cpp @@ -93,7 +93,7 @@ FSamplerManager::~FSamplerManager() void FSamplerManager::UnbindAll() { - for (int i = 0; i < FHardwareTexture::MAX_TEXTURES; i++) + for (int i = 0; i < IHardwareTexture::MAX_TEXTURES; i++) { glBindSampler(i, 0); } diff --git a/src/common/rendering/v_video.cpp b/src/common/rendering/v_video.cpp index 7035e54cc1..ce4dab80af 100644 --- a/src/common/rendering/v_video.cpp +++ b/src/common/rendering/v_video.cpp @@ -457,11 +457,6 @@ DEFINE_GLOBAL(CleanYfac_1) DEFINE_GLOBAL(CleanWidth_1) DEFINE_GLOBAL(CleanHeight_1) -IHardwareTexture* CreateHardwareTexture(int numchannels) -{ - return screen->CreateHardwareTexture(numchannels); -} - //========================================================================== // // CVAR transsouls diff --git a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp index aac0185180..0a30a76e41 100644 --- a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp @@ -390,8 +390,8 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state) WriteDescriptors update; MaterialLayerInfo *layer; - auto systex = static_cast(GetLayer(0, state.mTranslation, &layer)); - update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, state.mTranslation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); + auto systex = static_cast(GetLayer(0, translation, &layer)); + update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, translation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); for (int i = 1; i < numLayers; i++) { auto systex = static_cast(GetLayer(i, 0, &layer)); diff --git a/src/common/textures/gametexture.cpp b/src/common/textures/gametexture.cpp index 3ab74a5c38..d47ffb733c 100644 --- a/src/common/textures/gametexture.cpp +++ b/src/common/textures/gametexture.cpp @@ -187,7 +187,7 @@ void FGameTexture::AddAutoMaterials() void FGameTexture::CreateDefaultBrightmap() { auto tex = GetTexture(); - if (flags & GTexf_BrightmapChecked) + if (!(flags & GTexf_BrightmapChecked)) { flags |= GTexf_BrightmapChecked; // Check for brightmaps diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 38c0908c62..4c717a8b9f 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -92,6 +92,7 @@ class FGameTexture FMaterial* Material[4] = { }; // Material properties + FVector2 detailScale = { 1.f, 1.f }; float Glossiness = 10.f; float SpecularLevel = 0.1f; float shaderspeed = 1.f; @@ -305,6 +306,49 @@ public: } } + FVector2 GetDetailScale() const + { + return detailScale; + } + + void SetDetailScale(float x, float y) + { + detailScale.X = x; + detailScale.Y = y; + } + + FTexture* GetBrightmap() + { + if (Brightmap.get() || (flags & GTexf_BrightmapChecked)) return Brightmap.get(); + CreateDefaultBrightmap(); + return Brightmap.get(); + } + FTexture* GetGlowmap() + { + return Glowmap.get(); + } + FTexture* GetDetailmap() + { + return Detailmap.get(); + } + + void SetGlowmap(FTexture *T) + { + Glowmap = T; + } + void SetDetailmap(FTexture* T) + { + Detailmap = T; + } + void SetNormalmap(FTexture* T) + { + Normal = T; + } + void SetSpecularmap(FTexture* T) + { + Specular = T; + } + }; inline FGameTexture* MakeGameTexture(FTexture* tex, const char *name, ETextureType useType) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 4f5c301dbd..8df0b62989 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -83,30 +83,30 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) auto placeholder = TexMan.GameByIndex(1); if (tx->Brightmap.get()) { - mTextureLayers.Push({ tx->Brightmap.get(), scaleflags }); + mTextureLayers.Push({ tx->Brightmap.get(), scaleflags, -1 }); mLayerFlags |= TEXF_Brightmap; } else { - mTextureLayers.Push({ placeholder->GetTexture(), 0 }); + mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 }); } if (tx->Detailmap.get()) { - mTextureLayers.Push({ tx->Detailmap.get(), 0 }); + mTextureLayers.Push({ tx->Detailmap.get(), 0, CLAMP_NONE }); mLayerFlags |= TEXF_Detailmap; } else { - mTextureLayers.Push({ placeholder->GetTexture(), 0 }); + mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 }); } if (tx->Glowmap.get()) { - mTextureLayers.Push({ tx->Glowmap.get(), scaleflags }); + mTextureLayers.Push({ tx->Glowmap.get(), scaleflags, -1 }); mLayerFlags |= TEXF_Glowmap; } else { - mTextureLayers.Push({ placeholder->GetTexture(), 0 }); + mTextureLayers.Push({ placeholder->GetTexture(), 0, -1 }); } auto index = tx->GetShaderIndex(); diff --git a/src/common/textures/hw_material.h b/src/common/textures/hw_material.h index d7509cc946..e8c013d2b1 100644 --- a/src/common/textures/hw_material.h +++ b/src/common/textures/hw_material.h @@ -12,6 +12,7 @@ struct MaterialLayerInfo { FTexture* layerTexture; int scaleFlags; + int clampflags; }; //=========================================================================== @@ -37,6 +38,10 @@ public: int GetShaderIndex() const { return mShaderIndex; } int GetScaleFlags() const { return mScaleFlags; } virtual void DeleteDescriptors() { } + FVector2 GetDetailScale() const + { + return sourcetex->GetDetailScale(); + } FGameTexture* Source() const { diff --git a/src/common/textures/hw_texcontainer.h b/src/common/textures/hw_texcontainer.h index c75d42278d..a29fc63960 100644 --- a/src/common/textures/hw_texcontainer.h +++ b/src/common/textures/hw_texcontainer.h @@ -14,6 +14,7 @@ enum ECreateTexBufferFlags CTF_CreateMask = 3, // Flags that are relevant for hardware texture creation. CTF_ProcessData = 4, // run postprocessing on the generated buffer. This is only needed when using the data for a hardware texture. CTF_CheckOnly = 8, // Only runs the code to get a content ID but does not create a texture. Can be used to access a caching system for the hardware textures. + CTF_Indexed = 16 // Tell the backend to create an indexed texture. }; class FHardwareTextureContainer diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index e8626eaf73..20a8d97762 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -48,6 +48,8 @@ #include "formats/multipatchtexture.h" #include "texturemanager.h" #include "c_cvars.h" +#include "imagehelpers.h" +#include "v_video.h" // Wrappers to keep the definitions of these classes out of here. IHardwareTexture* CreateHardwareTexture(int numchannels); @@ -323,66 +325,82 @@ bool FTexture::ProcessData(unsigned char* buffer, int w, int h, bool ispatch) FTextureBuffer FTexture::CreateTexBuffer(int translation, int flags) { FTextureBuffer result; - - unsigned char* buffer = nullptr; - int W, H; - int isTransparent = -1; - bool checkonly = !!(flags & CTF_CheckOnly); - - int exx = !!(flags & CTF_Expand); - - W = GetWidth() + 2 * exx; - H = GetHeight() + 2 * exx; - - if (!checkonly) + if (flags & CTF_Indexed) { - buffer = new unsigned char[W * (H + 1) * 4]; - memset(buffer, 0, W * (H + 1) * 4); + // Indexed textures will never be translated and never be scaled. + int w = GetWidth(), h = GetHeight(); - auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation); - if (remap) translation = remap->Index; - FBitmap bmp(buffer, W * 4, W, H); + auto store = Get8BitPixels(false); + const uint8_t* p = store.Data(); - int trans; - auto Pixels = GetBgraBitmap(remap ? remap->Palette : nullptr, &trans); - bmp.Blit(exx, exx, Pixels); + result.mBuffer = new uint8_t[w * h]; + result.mWidth = w; + result.mHeight = h; + result.mContentId = 0; + ImageHelpers::FlipNonSquareBlock(result.mBuffer, p, h, w, h); + } + else + { + unsigned char* buffer = nullptr; + int W, H; + int isTransparent = -1; + bool checkonly = !!(flags & CTF_CheckOnly); - if (remap == nullptr) + int exx = !!(flags & CTF_Expand); + + W = GetWidth() + 2 * exx; + H = GetHeight() + 2 * exx; + + if (!checkonly) { - CheckTrans(buffer, W * H, trans); - isTransparent = bTranslucent; + buffer = new unsigned char[W * (H + 1) * 4]; + memset(buffer, 0, W * (H + 1) * 4); + + auto remap = translation <= 0 ? nullptr : GPalette.TranslationToTable(translation); + if (remap) translation = remap->Index; + FBitmap bmp(buffer, W * 4, W, H); + + int trans; + auto Pixels = GetBgraBitmap(remap ? remap->Palette : nullptr, &trans); + bmp.Blit(exx, exx, Pixels); + + if (remap == nullptr) + { + CheckTrans(buffer, W * H, trans); + isTransparent = bTranslucent; + } + else + { + isTransparent = 0; + // A translated image is not conclusive for setting the texture's transparency info. + } } - else + + if (GetImage()) { - isTransparent = 0; - // A translated image is not conclusive for setting the texture's transparency info. + FContentIdBuilder builder; + builder.id = 0; + builder.imageID = GetImage()->GetId(); + builder.translation = MAX(0, translation); + builder.expand = exx; + result.mContentId = builder.id; + } + else result.mContentId = 0; // for non-image backed textures this has no meaning so leave it at 0. + + result.mBuffer = buffer; + result.mWidth = W; + result.mHeight = H; + + // Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.) + if (GetImage() && flags & CTF_ProcessData) + { + if (flags & CTF_Upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly); + + if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false); } } - - if (GetImage()) - { - FContentIdBuilder builder; - builder.id = 0; - builder.imageID = GetImage()->GetId(); - builder.translation = MAX(0, translation); - builder.expand = exx; - result.mContentId = builder.id; - } - else result.mContentId = 0; // for non-image backed textures this has no meaning so leave it at 0. - - result.mBuffer = buffer; - result.mWidth = W; - result.mHeight = H; - - // Only do postprocessing for image-backed textures. (i.e. not for the burn texture which can also pass through here.) - if (GetImage() && flags & CTF_ProcessData) - { - if (flags & CTF_Upscale) CreateUpsampledTextureBuffer(result, !!isTransparent, checkonly); - - if (!checkonly) ProcessData(result.mBuffer, result.mWidth, result.mHeight, false); - } - return result; + } //=========================================================================== @@ -514,7 +532,7 @@ IHardwareTexture* FTexture::GetHardwareTexture(int translation, int scaleflags) IHardwareTexture* hwtex = SystemTextures.GetHardwareTexture(translation, scaleflags); if (hwtex == nullptr) { - hwtex = CreateHardwareTexture(4); + hwtex = screen->CreateHardwareTexture(4); SystemTextures.AddHardwareTexture(translation, scaleflags, hwtex); } return hwtex; @@ -535,7 +553,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) Height = h; Format = bits; //bNoCompress = true; - auto hwtex = CreateHardwareTexture(4); + auto hwtex = screen->CreateHardwareTexture(4); // todo: Initialize here. SystemTextures.AddHardwareTexture(0, false, hwtex); } diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index c7cffd07cd..80458a6ab8 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -625,8 +625,8 @@ void FTextureManager::AddHiresTextures (int wadnum) auto gtex = MakeGameTexture(newtex, nullptr, ETextureType::Override); gtex->SetWorldPanning(true); gtex->SetDisplaySize(oldtex->GetDisplayWidth(), oldtex->GetDisplayHeight()); - gtex->SetOffsets(0, xs_RoundToInt(oldtex->GetDisplayLeftOffset(0) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(0) * gtex->GetScaleY())); - gtex->SetOffsets(1, xs_RoundToInt(oldtex->GetDisplayLeftOffset(1) * gtex->GetScaleX()), xs_RoundToInt(oldtex->GetDisplayTopOffset(1) * gtex->GetScaleY())); + gtex->SetOffsets(0, oldtex->GetTexelLeftOffset(0), oldtex->GetTexelTopOffset(0)); + gtex->SetOffsets(1, oldtex->GetTexelLeftOffset(1), oldtex->GetTexelTopOffset(1)); ReplaceTexture(tlist[i], gtex, true); } } From 83153efcada271b3e59390cd2f70f13d9e26d7d8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 11:41:49 +0200 Subject: [PATCH 197/220] - refixed translations on Vulkan. --- src/common/rendering/vulkan/textures/vk_hwtexture.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp index 0a30a76e41..aac0185180 100644 --- a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp @@ -390,8 +390,8 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state) WriteDescriptors update; MaterialLayerInfo *layer; - auto systex = static_cast(GetLayer(0, translation, &layer)); - update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, translation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); + auto systex = static_cast(GetLayer(0, state.mTranslation, &layer)); + update.addCombinedImageSampler(descriptor.get(), 0, systex->GetImage(layer->layerTexture, state.mTranslation, layer->scaleFlags)->View.get(), sampler, systex->mImage.Layout); for (int i = 1; i < numLayers; i++) { auto systex = static_cast(GetLayer(i, 0, &layer)); From 8480a390a1c7ddd02558daae2dd3257bbc9a2e99 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 11:45:34 +0200 Subject: [PATCH 198/220] - synced texture sampler setup fixes from Raze. --- src/common/audio/music/music.cpp | 8 ++++---- src/common/textures/hw_material.cpp | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/common/audio/music/music.cpp b/src/common/audio/music/music.cpp index 2d9008021e..1f8b0a0046 100644 --- a/src/common/audio/music/music.cpp +++ b/src/common/audio/music/music.cpp @@ -166,9 +166,9 @@ static bool S_StartMusicPlaying(ZMusic_MusicStream song, bool loop, float rel_vo //========================================================================== // -// S_PauseSound +// S_PauseMusic // -// Stop music and sound effects, during game PAUSE. +// Stop music, during game PAUSE. //========================================================================== void S_PauseMusic () @@ -183,9 +183,9 @@ void S_PauseMusic () //========================================================================== // -// S_ResumeSound +// S_ResumeMusic // -// Resume music and sound effects, after game PAUSE. +// Resume music, after game PAUSE. //========================================================================== void S_ResumeMusic () diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index 8df0b62989..c4a1ba9d3d 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -40,7 +40,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) mShaderIndex = SHADER_Default; sourcetex = tx; auto imgtex = tx->GetTexture(); - mTextureLayers.Push({ imgtex, scaleflags }); + mTextureLayers.Push({ imgtex, scaleflags, -1 }); if (tx->GetUseType() == ETextureType::SWCanvas && static_cast(imgtex)->GetColorFormat() == 0) { @@ -52,7 +52,8 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) { mShaderIndex = tx->GetShaderIndex(); } - // no brightmap for cameratexture + mTextureLayers.Last().clampflags = CLAMP_CAMTEX; + // no additional layers for cameratexture } else { @@ -65,7 +66,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) { for (auto &texture : { tx->Normal.get(), tx->Specular.get() }) { - mTextureLayers.Push({ texture, 0 }); + mTextureLayers.Push({ texture, 0, -1 }); } mShaderIndex = SHADER_Specular; } @@ -73,7 +74,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) { for (auto &texture : { tx->Normal.get(), tx->Metallic.get(), tx->Roughness.get(), tx->AmbientOcclusion.get() }) { - mTextureLayers.Push({ texture, 0 }); + mTextureLayers.Push({ texture, 0, -1 }); } mShaderIndex = SHADER_PBR; } From 8f07ab87c8ae95dc9d80484ef351d06e50be8ded Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 20:15:55 +0200 Subject: [PATCH 199/220] - make sure that incomplete multipatch textures are technically complete. They need a valid FTexture backing them and should have their name cleared so that nothing references them by accident. --- src/common/textures/multipatchtexturebuilder.cpp | 3 +++ src/rendering/hwrenderer/hw_precache.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 7def5cb7aa..41daa0035f 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -923,7 +923,10 @@ void FMultipatchTextureBuilder::ResolveAllPatches() for (auto &b : BuiltTextures) { Printf("%s\n", b.Name.GetChars()); + // make it hard to find but also ensure that it references valid backing data. b.texture->SetUseType(ETextureType::Null); + b.texture->SetBase(TexMan.GameByIndex(0)->GetTexture()); + b.texture->SetName(""); } break; } diff --git a/src/rendering/hwrenderer/hw_precache.cpp b/src/rendering/hwrenderer/hw_precache.cpp index ca5f37f727..72b977f80c 100644 --- a/src/rendering/hwrenderer/hw_precache.cpp +++ b/src/rendering/hwrenderer/hw_precache.cpp @@ -104,7 +104,7 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap &actorhitl for (int i = 1; i < TexMan.NumTextures(); i++) { auto gametex = TexMan.GameByIndex(i); - if (gametex && + if (gametex && gametex->isValid() && gametex->GetTexture()->GetImage() && // only image textures are subject to precaching gametex->GetUseType() != ETextureType::FontChar && // We do not want to delete font characters here as they are very likely to be needed constantly. gametex->GetUseType() < ETextureType::Special) // Any texture marked as 'special' is also out. From f118cd78bf9859c9be5c4fa67b14c93cf9258863 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 20:20:18 +0200 Subject: [PATCH 200/220] - fixed missing custom shader setup in cases where a shader got used more than once. --- src/r_data/gldefs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index db9af53cf9..f59000619b 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -1643,6 +1643,7 @@ class GLDefsParser !usershaders[i].defines.Compare(desc.defines)) { SetShaderIndex(tex, i + FIRST_USER_SHADER); + tex->SetShaderLayers(mlay); return; } } From f91958e88d6759663617c2e5a77338f527a3dd5e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 20:38:46 +0200 Subject: [PATCH 201/220] - fixed scale setup for multipatch textures. --- src/common/textures/multipatchtexturebuilder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/textures/multipatchtexturebuilder.cpp b/src/common/textures/multipatchtexturebuilder.cpp index 41daa0035f..89d4adaf38 100644 --- a/src/common/textures/multipatchtexturebuilder.cpp +++ b/src/common/textures/multipatchtexturebuilder.cpp @@ -141,7 +141,7 @@ void FMultipatchTextureBuilder::MakeTexture(BuildInfo &buildinfo, ETextureType u buildinfo.texture->SetSize(buildinfo.Width, buildinfo.Height); buildinfo.texture->SetOffsets(0, buildinfo.LeftOffset[0], buildinfo.TopOffset[0]); // These are needed for construction of other multipatch textures. buildinfo.texture->SetOffsets(1, buildinfo.LeftOffset[1], buildinfo.TopOffset[1]); - buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.X); + buildinfo.texture->SetScale((float)buildinfo.Scale.X, (float)buildinfo.Scale.Y); buildinfo.texture->SetWorldPanning(buildinfo.bWorldPanning); buildinfo.texture->SetNoDecals(buildinfo.bNoDecals); TexMan.AddGameTexture(buildinfo.texture); From 96cf16c923bfdace0ffe298b7500f8e3fa8168eb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 21:23:38 +0200 Subject: [PATCH 202/220] - fixed: Copying a texture's size must also copy the offset. --- src/common/textures/gametexture.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 4c717a8b9f..32a2e40be5 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -210,6 +210,8 @@ public: { Base->CopySize(BaseTexture->Base.get()); SetDisplaySize(BaseTexture->GetDisplayWidth(), BaseTexture->GetDisplayHeight()); + SetOffsets(0, BaseTexture->GetTexelLeftOffset(0), BaseTexture->GetTexelTopOffset(0)); + SetOffsets(1, BaseTexture->GetTexelLeftOffset(1), BaseTexture->GetTexelTopOffset(1)); } // Glowing is a pure material property that should not filter down to the actual texture objects. From c48fa818ffe2790351096c171dd1b01a4030bf00 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 21:24:34 +0200 Subject: [PATCH 203/220] - use modulo, not bitwise and-ing to check the damage delay for terrain based damage. This was apparently overlooked when refactoring the damage system 4 years ago. --- src/playsim/p_spec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/playsim/p_spec.cpp b/src/playsim/p_spec.cpp index 80a506f257..97b2cf82bf 100644 --- a/src/playsim/p_spec.cpp +++ b/src/playsim/p_spec.cpp @@ -625,7 +625,7 @@ void P_PlayerOnSpecialFlat (player_t *player, int floorType) auto Level = player->mo->Level; if (Terrains[floorType].DamageAmount && - !(Level->time & Terrains[floorType].DamageTimeMask)) + !(Level->time % (Terrains[floorType].DamageTimeMask+1))) { AActor *ironfeet = NULL; From 1881cb45d2cb46ebe1172427c5b18b193e47894e Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 21:38:55 +0200 Subject: [PATCH 204/220] - reject all 0-special lines for activation. This is to ensure consistency between all callers of this function. --- src/playsim/p_spec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/playsim/p_spec.cpp b/src/playsim/p_spec.cpp index 97b2cf82bf..ee19cfb092 100644 --- a/src/playsim/p_spec.cpp +++ b/src/playsim/p_spec.cpp @@ -249,7 +249,7 @@ bool P_TestActivateLine (line_t *line, AActor *mo, int side, int activationType, auto Level = line->GetLevel(); int lineActivation = line->activation; - if (line->flags & ML_FIRSTSIDEONLY && side == 1) + if ((line->flags & ML_FIRSTSIDEONLY && side == 1) || line->special == 0) { return false; } From 1279ec081a2dc0fc42c881423fa39391757f3321 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 21:49:53 +0200 Subject: [PATCH 205/220] - Strip out any color escape sequences before setting a window title. --- src/d_main.cpp | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 3a59e5d1df..454e7cac6a 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -3898,20 +3898,47 @@ CUSTOM_CVAR(Int, I_FriendlyWindowTitle, 1, CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CVAR_N void I_UpdateWindowTitle() { + FString titlestr; switch (I_FriendlyWindowTitle) { case 1: if (level.LevelName && level.LevelName.GetChars()[0]) { - FString titlestr; titlestr.Format("%s - %s", level.LevelName.GetChars(), GameStartupInfo.Name.GetChars()); - I_SetWindowTitle(titlestr.GetChars()); break; } case 2: - I_SetWindowTitle(GameStartupInfo.Name.GetChars()); + titlestr = GameStartupInfo.Name; break; default: I_SetWindowTitle(NULL); + return; } + + // Strip out any color escape sequences before setting a window title + TArray copy(titlestr.Len() + 1); + const char* srcp = titlestr; + char* dstp = copy.Data(); + + while (*srcp != 0) + { + + if (*srcp != TEXTCOLOR_ESCAPE) + { + *dstp++ = *srcp++; + } + else if (srcp[1] == '[') + { + srcp += 2; + while (*srcp != ']' && *srcp != 0) srcp++; + if (*srcp == ']') srcp++; + } + else + { + if (srcp[1] != 0) srcp += 2; + else break; + } + } + *dstp = 0; + I_SetWindowTitle(copy.Data()); } From c537e5a0b78dc4ac9a92a4c9e62759a38f5be155 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 22:31:04 +0200 Subject: [PATCH 206/220] - fixed bad ACS translation indexing. --- src/playsim/p_acs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/playsim/p_acs.cpp b/src/playsim/p_acs.cpp index b33a397b2f..f6fcd47cbf 100644 --- a/src/playsim/p_acs.cpp +++ b/src/playsim/p_acs.cpp @@ -9505,7 +9505,7 @@ scriptwait: { translation = new FRemapTable; translation->MakeIdentity(); - transi = i + 1; + transi = i - 1; } } break; From 932b2d820db7bcfcb062b9641088dc8eef36fc82 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 2 Jun 2020 23:04:05 +0200 Subject: [PATCH 207/220] - fixed floorclipping checks for 3D floors. Neither the setup nor the in-game checks were correct, because this code comes from a time where ceilings could not have a terrain, meaning that 3D floors couldn't have one. --- src/playsim/p_mobj.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index 74d311551b..a2fc66faa6 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -4887,22 +4887,37 @@ void AActor::AdjustFloorClip () double shallowestclip = INT_MAX; const msecnode_t *m; - // possibly standing on a 3D-floor - if (Sector->e->XFloor.ffloors.Size() && Z() > Sector->floorplane.ZatPoint(this)) Floorclip = 0; - // [RH] clip based on shallowest floor player is standing on // If the sector has a deep water effect, then let that effect // do the floorclipping instead of the terrain type. for (m = touching_sectorlist; m; m = m->m_tnext) { DVector3 pos = PosRelative(m->m_sector); - sector_t *hsec = m->m_sector->GetHeightSec(); - if (hsec == NULL && m->m_sector->floorplane.ZatPoint (pos) == Z()) + sector_t* hsec = m->m_sector->GetHeightSec(); + if (hsec == NULL) { - double clip = Terrains[m->m_sector->GetTerrain(sector_t::floor)].FootClip; - if (clip < shallowestclip) + if (m->m_sector->floorplane.ZatPoint(pos) == Z()) { - shallowestclip = clip; + double clip = Terrains[m->m_sector->GetTerrain(sector_t::floor)].FootClip; + if (clip < shallowestclip) + { + shallowestclip = clip; + } + } + else + { + for (auto& ff : m->m_sector->e->XFloor.ffloors) + { + if ((ff->flags & FF_SOLID) && (ff->flags & FF_EXISTS) && ff->top.plane->ZatPoint(pos) == Z()) + { + double clip = Terrains[ff->top.model->GetTerrain(ff->top.isceiling)].FootClip; + if (clip < shallowestclip) + { + shallowestclip = clip; + } + } + } + } } } @@ -5548,6 +5563,11 @@ AActor *FLevelLocals::SpawnMapThing (FMapThing *mthing, int position) else if (sz == ONCEILINGZ) mobj->AddZ(-mthing->pos.Z); + if (mobj->flags2 & MF2_FLOORCLIP) + { + mobj->AdjustFloorClip(); + } + mobj->SpawnPoint = mthing->pos; mobj->SpawnAngle = mthing->angle; mobj->SpawnFlags = mthing->flags; From fa54afbd085cd207a1cdec3397b651de00259953 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 3 Jun 2020 00:16:25 +0200 Subject: [PATCH 208/220] - addressed a problem with materials depending on automatically added textures. This isn't a fix, it just removes a sanity check that really shouldn't be, but thanks of an underspecification of the material definition it was never possible to do this case properly. --- src/common/textures/hw_material.cpp | 2 +- src/r_data/gldefs.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index c4a1ba9d3d..af4bc2c60e 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -114,7 +114,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) if (index >= FIRST_USER_SHADER) { const UserShaderDesc &usershader = usershaders[index - FIRST_USER_SHADER]; - if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material + //if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material { for (auto &texture : tx->CustomShaderTextures) { diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index f59000619b..b561000c47 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -1401,6 +1401,7 @@ class GLDefsParser !usershaders[i].defines.Compare(usershader.defines)) { SetShaderIndex(tex, i + FIRST_USER_SHADER); + tex->SetShaderLayers(mlay); return; } } From 392f78dfbc0bd83effb617b4d41443a19926fb9a Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 3 Jun 2020 11:40:49 +0600 Subject: [PATCH 209/220] Allow dialogs to be displayed on other Unix-like OSs --- src/common/platform/posix/sdl/i_system.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/platform/posix/sdl/i_system.cpp b/src/common/platform/posix/sdl/i_system.cpp index 43b8c86649..6e2f3f35de 100644 --- a/src/common/platform/posix/sdl/i_system.cpp +++ b/src/common/platform/posix/sdl/i_system.cpp @@ -78,8 +78,8 @@ void I_SetIWADInfo() void Mac_I_FatalError(const char* errortext); #endif -#ifdef __linux__ -void Linux_I_FatalError(const char* errortext) +#ifdef __unix__ +void Unix_I_FatalError(const char* errortext) { // Close window or exit fullscreen and release mouse capture SDL_Quit(); @@ -116,8 +116,8 @@ void I_ShowFatalError(const char *message) { #ifdef __APPLE__ Mac_I_FatalError(message); -#elif defined __linux__ - Linux_I_FatalError(message); +#elif defined __unix__ + Unix_I_FatalError(message); #else // ??? #endif From e2e47b8d8c6e7332002d9c07dac45a5a4d747191 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Wed, 3 Jun 2020 12:25:07 +0600 Subject: [PATCH 210/220] Include signal.h if either compiling for macOS or one of the BSD systems --- src/common/platform/posix/sdl/crashcatcher.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/platform/posix/sdl/crashcatcher.c b/src/common/platform/posix/sdl/crashcatcher.c index be0e8f5990..698707027e 100644 --- a/src/common/platform/posix/sdl/crashcatcher.c +++ b/src/common/platform/posix/sdl/crashcatcher.c @@ -11,7 +11,7 @@ #ifndef PR_SET_PTRACER #define PR_SET_PTRACER 0x59616d61 #endif -#elif defined (__APPLE__) || defined (__FreeBSD__) || defined(__OpenBSD__) +#elif defined (__APPLE__) || defined (BSD) #include #endif From 8ab6575bd1687fc1c17d00aa54254f49ff894118 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Wed, 3 Jun 2020 14:37:52 +0200 Subject: [PATCH 211/220] - Fixed OpenAL regression with looping sounds with playing length 0. If such case occurs, the starttime parameter passed to the sound functions is ignored and truncated to 0. --- src/common/audio/sound/oalsound.cpp | 5 ++++- src/common/audio/sound/s_sound.cpp | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/audio/sound/oalsound.cpp b/src/common/audio/sound/oalsound.cpp index 69d00151c4..be3cc5d658 100644 --- a/src/common/audio/sound/oalsound.cpp +++ b/src/common/audio/sound/oalsound.cpp @@ -1420,7 +1420,10 @@ FISoundChannel *OpenALSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener if(!reuse_chan || reuse_chan->StartTime == 0) { - float st = (chanflags & SNDF_LOOP) ? fmod(startTime, (float)GetMSLength(sfx) / 1000.f) : clamp(startTime, 0.f, (float)GetMSLength(sfx) / 1000.f); + float sfxlength = (float)GetMSLength(sfx) / 1000.f; + float st = (chanflags & SNDF_LOOP) + ? (sfxlength > 0 ? fmod(startTime, sfxlength) : 0) + : clamp(startTime, 0.f, sfxlength); alSourcef(source, AL_SEC_OFFSET, st); } else diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index b6d6bb2423..04a5649133 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -547,9 +547,10 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source, if (chanflags & (CHANF_UI|CHANF_NOPAUSE)) startflags |= SNDF_NOPAUSE; if (chanflags & CHANF_UI) startflags |= SNDF_NOREVERB; + float sfxlength = (float)GSnd->GetMSLength(sfx->data) / 1000.f; startTime = (startflags & SNDF_LOOP) - ? fmod(startTime, (float)GSnd->GetMSLength(sfx->data) / 1000.f) - : clamp(startTime, 0.f, (float)GSnd->GetMSLength(sfx->data) / 1000.f); + ? (sfxlength > 0 ? fmod(startTime, sfxlength) : 0) + : clamp(startTime, 0.f, sfxlength); if (attenuation > 0 && type != SOURCE_None) { From 720853cff89f9499807aa81ebf9f046ecebdab72 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 3 Jun 2020 21:15:32 +0200 Subject: [PATCH 212/220] - made some changes so that material definitions can properly check automatic layers when determining their material type. Most importantly this means that any texture with a custom material definition needs to load its automatic layers before applying the definition. --- src/common/engine/startupinfo.h | 2 +- src/common/textures/gametexture.cpp | 2 ++ src/common/textures/gametexture.h | 2 ++ src/common/textures/hw_material.cpp | 2 +- src/r_data/gldefs.cpp | 12 ++++++------ 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/common/engine/startupinfo.h b/src/common/engine/startupinfo.h index 9cf9724fde..5054a45075 100644 --- a/src/common/engine/startupinfo.h +++ b/src/common/engine/startupinfo.h @@ -12,7 +12,7 @@ struct FStartupInfo int Type; int LoadLights = -1; int LoadBrightmaps = -1; - int modern = -1; + int modern = 0; enum { DefaultStartup, diff --git a/src/common/textures/gametexture.cpp b/src/common/textures/gametexture.cpp index d47ffb733c..e4e1ac6b29 100644 --- a/src/common/textures/gametexture.cpp +++ b/src/common/textures/gametexture.cpp @@ -149,6 +149,7 @@ void FGameTexture::AddAutoMaterials() { "materials/ao/", &FGameTexture::AmbientOcclusion } }; + if (flags & GTexf_AutoMaterialsAdded) return; // do this only once bool fullname = !!(flags & GTexf_FullNameTexture); FString searchname = GetName(); @@ -177,6 +178,7 @@ void FGameTexture::AddAutoMaterials() } } } + flags |= GTexf_AutoMaterialsAdded; } //=========================================================================== diff --git a/src/common/textures/gametexture.h b/src/common/textures/gametexture.h index 32a2e40be5..e6b3461cf0 100644 --- a/src/common/textures/gametexture.h +++ b/src/common/textures/gametexture.h @@ -57,12 +57,14 @@ enum EGameTexFlags GTexf_RenderFullbright = 32, // always draw fullbright GTexf_DisableFullbrightSprites = 64, // This texture will not be displayed as fullbright sprite GTexf_BrightmapChecked = 128, // Check for a colormap-based brightmap was already done. + GTexf_AutoMaterialsAdded = 256, // AddAutoMaterials has been called on this texture. }; // Refactoring helper to allow piece by piece adjustment of the API class FGameTexture { friend class FMaterial; + friend class GLDefsParser; // this needs access to set up the texture properly // Material layers. These are shared so reference counting is used. RefCountedPtr Base; diff --git a/src/common/textures/hw_material.cpp b/src/common/textures/hw_material.cpp index af4bc2c60e..c4a1ba9d3d 100644 --- a/src/common/textures/hw_material.cpp +++ b/src/common/textures/hw_material.cpp @@ -114,7 +114,7 @@ FMaterial::FMaterial(FGameTexture * tx, int scaleflags) if (index >= FIRST_USER_SHADER) { const UserShaderDesc &usershader = usershaders[index - FIRST_USER_SHADER]; - //if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material + if (usershader.shaderType == mShaderIndex) // Only apply user shader if it matches the expected material { for (auto &texture : tx->CustomShaderTextures) { diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index b561000c47..44467244d5 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -1216,6 +1216,7 @@ class GLDefsParser { sc.ScriptMessage("Material definition refers nonexistent texture '%s'\n", sc.String); } + else tex->AddAutoMaterials(); // We need these before setting up the texture. sc.MustGetToken('{'); while (!sc.CheckToken('}')) @@ -1242,14 +1243,12 @@ class GLDefsParser else if (sc.Compare("glossiness")) { sc.MustGetFloat(); - if (tex) - mlay.Glossiness = (float)sc.Float; + mlay.Glossiness = (float)sc.Float; } else if (sc.Compare("specularlevel")) { sc.MustGetFloat(); - if (tex) - mlay.SpecularLevel = (float)sc.Float; + mlay.SpecularLevel = (float)sc.Float; } else if (sc.Compare("speed")) { @@ -1367,12 +1366,12 @@ class GLDefsParser if (usershader.shader.IsNotEmpty()) { int firstUserTexture; - if (mlay.Normal && mlay.Specular) + if ((mlay.Normal || tex->Normal.get()) && (mlay.Specular || tex->Specular.get())) { usershader.shaderType = SHADER_Specular; firstUserTexture = 7; } - else if (mlay.Normal && mlay.Metallic && mlay.Roughness && mlay.AmbientOcclusion) + else if ((mlay.Normal || tex->Normal.get()) && (mlay.Metallic || tex->Metallic.get()) && (mlay.Roughness || tex->Roughness.get()) && (mlay.AmbientOcclusion || tex->AmbientOcclusion.get())) { usershader.shaderType = SHADER_PBR; firstUserTexture = 9; @@ -1523,6 +1522,7 @@ class GLDefsParser sc.MustGetString(); FTextureID no = TexMan.CheckForTexture(sc.String, type); auto tex = TexMan.GetGameTexture(no); + if (tex) tex->AddAutoMaterials(); MaterialLayers mlay = { -1000, -1000 }; sc.MustGetToken('{'); From 87d81656e1059e5471bc82419463914be697f6c2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 3 Jun 2020 21:35:09 +0200 Subject: [PATCH 213/220] - fixed: the 3D floor processing code in the renderer did not restore the render style after finishing. Normally this won't be noticable, the only exception is if the last processed 3D floor had additive translucency and colored fog - this case is special because for additive rendering the fog color needs to be disabled. --- src/rendering/hwrenderer/scene/hw_walls.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 4a2d0ab927..78c532333f 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -1641,6 +1641,7 @@ void HWWall::BuildFFBlock(HWDrawInfo *di, seg_t * seg, F3DFloor * rover, lightlevel = savelight; Colormap = savecolor; flags &= ~HWF_CLAMPY; + RenderStyle = STYLE_Normal; } From fd3845ce0973546a2b1db683ee7eccc9de2e218b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 3 Jun 2020 22:30:44 +0200 Subject: [PATCH 214/220] - fixed: vertically mirrored textures should not be subjected to empty space optimizations because the algorithm cannot deal with the inverted case. --- src/rendering/hwrenderer/scene/hw_drawstructs.h | 7 ++++--- src/rendering/hwrenderer/scene/hw_walls.cpp | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rendering/hwrenderer/scene/hw_drawstructs.h b/src/rendering/hwrenderer/scene/hw_drawstructs.h index 8c0d291737..1d20ced4a9 100644 --- a/src/rendering/hwrenderer/scene/hw_drawstructs.h +++ b/src/rendering/hwrenderer/scene/hw_drawstructs.h @@ -128,7 +128,8 @@ public: HWF_NOSPLITUPPER=16, HWF_NOSPLITLOWER=32, HWF_NOSPLIT=64, - HWF_TRANSLUCENT = 128 + HWF_TRANSLUCENT = 128, + HWF_NOSLICE = 256 }; enum @@ -164,9 +165,9 @@ public: float ViewDistance; - int lightlevel; + short lightlevel; + uint16_t flags; uint8_t type; - uint8_t flags; short rellight; float topglowcolor[4]; diff --git a/src/rendering/hwrenderer/scene/hw_walls.cpp b/src/rendering/hwrenderer/scene/hw_walls.cpp index 78c532333f..37ccd66bbc 100644 --- a/src/rendering/hwrenderer/scene/hw_walls.cpp +++ b/src/rendering/hwrenderer/scene/hw_walls.cpp @@ -1404,6 +1404,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, { tci.mRenderHeight = -tci.mRenderHeight; tci.mScale.Y = -tci.mScale.Y; + flags |= HWF_NOSLICE; } SetWallCoordinates(seg, &tci, texturetop, topleft, topright, bottomleft, bottomright, t_ofs); @@ -1464,7 +1465,7 @@ void HWWall::DoMidTexture(HWDrawInfo *di, seg_t * seg, bool drawfogboundary, FloatRect *splitrect; int v = texture->GetAreas(&splitrect); if (seg->frontsector == seg->backsector) flags |= HWF_NOSPLIT; // we don't need to do vertex splits if a line has both sides in the same sector - if (v>0 && !drawfogboundary && !(seg->linedef->flags&ML_WRAP_MIDTEX)) + if (v>0 && !drawfogboundary && !(seg->linedef->flags&ML_WRAP_MIDTEX) && !(flags & HWF_NOSLICE)) { // split the poly! int i,t=0; From a81becccb0252a8d28a2fc7960e8a61115b970ec Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 4 Jun 2020 00:19:23 +0200 Subject: [PATCH 215/220] - Strife dynamic light tweaks by ReaperAA. --- wadsrc_lights/static/filter/strife/gldefs.txt | 93 ++++++++----------- 1 file changed, 39 insertions(+), 54 deletions(-) diff --git a/wadsrc_lights/static/filter/strife/gldefs.txt b/wadsrc_lights/static/filter/strife/gldefs.txt index 9234b2175f..f33a930dac 100644 --- a/wadsrc_lights/static/filter/strife/gldefs.txt +++ b/wadsrc_lights/static/filter/strife/gldefs.txt @@ -1994,7 +1994,7 @@ object BishopMissile pointlight LIGHT1 { color 1.0 1.0 1.0 - size 90 + size 84 offset 0 30 0 attenuate 1 } @@ -2035,12 +2035,13 @@ pointlight CLIGHT1 color 1.0 1.0 0.0 size 24 offset 0 12 0 + attenuate 1 } pulselight CLIGHT2 { color 1.0 1.0 0.0 - size 66 + size 72 secondarySize 75 interval 8.0 offset 0 64 0 @@ -2071,7 +2072,7 @@ pointlight TLLIGHT2 { color 1.0 1.0 0.5 size 120 - offset 0 56 0 + offset 0 40 0 attenuate 1 } @@ -2224,8 +2225,8 @@ object AlienSpiderLight flickerlight BBARREL { color 1.0 0.6 0.0 - size 54 - secondarySize 66 + size 48 + secondarySize 60 chance 0.8 offset 0 32 0 attenuate 1 @@ -2234,8 +2235,8 @@ flickerlight BBARREL flickerlight BBOWL { color 1.0 0.7 0.0 - size 40 - secondarySize 52 + size 36 + secondarySize 48 chance 0.5 offset 0 10 0 attenuate 1 @@ -2244,8 +2245,8 @@ flickerlight BBOWL flickerlight BBRAZIER { color 1.0 0.8 0.0 - size 66 - secondarySize 78 + size 60 + secondarySize 66 chance 0.2 offset 0 32 0 attenuate 1 @@ -2256,7 +2257,7 @@ pulselight STORCH color 1.0 0.6 0.0 size 48 secondarySize 54 - interval 5.0 + interval 5.0 offset 0 56 0 attenuate 1 } @@ -2264,8 +2265,8 @@ pulselight STORCH pulselight MTORCH { color 1.0 0.6 0.0 - size 90 - secondarySize 102 + size 84 + secondarySize 96 interval 5.0 offset 0 64 0 attenuate 1 @@ -2274,8 +2275,8 @@ pulselight MTORCH pulselight LTORCH { color 1.0 0.8 0.0 - size 102 - secondarySize 114 + size 96 + secondarySize 108 interval 2.0 offset 0 64 0 attenuate 1 @@ -2284,8 +2285,8 @@ pulselight LTORCH pulselight HTORCH { color 1.0 0.6 0.0 - size 114 - secondarySize 120 + size 108 + secondarySize 114 interval 3.0 offset 0 72 0 attenuate 1 @@ -2405,7 +2406,7 @@ flickerlight POWCRYS_X5 { color 1.0 0.7 0.27 size 114 - secondarySize 113 + secondarySize 116 chance 0.3 } @@ -2477,7 +2478,7 @@ flickerlight POWCRYS_X13 { color 1.0 0.48 0.10 size 105 - secondarySize 106 + secondarySize 107 chance 0.3 } @@ -2485,37 +2486,21 @@ flickerlight POWCRYS_X14 { color 1.0 0.46 0.08 size 103 - secondarySize 104 + secondarySize 105 chance 0.3 } flickerlight POWCRYS_X15 { color 1.0 0.44 0.06 - size 102 - secondarySize 104 + size 101 + secondarySize 103 chance 0.3 } flickerlight POWCRYS_X16 { color 1.0 0.42 0.04 - size 101 - secondarySize 103 - chance 0.3 -} - -flickerlight POWCRYS_X15 -{ - color 1.0 0.4 0.02 - size 100 - secondarySize 102 - chance 0.3 -} - -flickerlight POWCRYS_X16 -{ - color 1.0 0.38 0.0 size 99 secondarySize 101 chance 0.3 @@ -2523,7 +2508,7 @@ flickerlight POWCRYS_X16 flickerlight POWCRYS_X17 { - color 1.0 0.36 0.02 + color 1.0 0.40 0.02 size 98 secondarySize 100 chance 0.3 @@ -2531,65 +2516,65 @@ flickerlight POWCRYS_X17 flickerlight POWCRYS_X18 { - color 1.0 0.34 0.0 + color 1.0 0.38 0.0 size 97 - secondarySize 100 + secondarySize 99 chance 0.3 } flickerlight POWCRYS_X19 { - color 1.0 0.32 0.0 + color 1.0 0.36 0.0 size 96 - secondarySize 99 + secondarySize 98 chance 0.3 } flickerlight POWCRYS_X20 { - color 1.0 0.3 0.0 + color 1.0 0.34 0.0 size 95 - secondarySize 98 + secondarySize 97 chance 0.3 } flickerlight POWCRYS_X21 { - color 1.0 0.28 0.0 + color 1.0 0.32 0.0 size 94 - secondarySize 93 + secondarySize 96 chance 0.3 } flickerlight POWCRYS_X22 { - color 1.0 0.26 0.0 + color 1.0 0.3 0.0 size 93 - secondarySize 92 + secondarySize 95 chance 0.3 } flickerlight POWCRYS_X23 { - color 1.0 0.24 0.0 + color 1.0 0.28 0.0 size 92 - secondarySize 91 + secondarySize 94 chance 0.3 } flickerlight POWCRYS_X24 { - color 1.0 0.22 0.0 - size 90 + color 1.0 0.26 0.0 + size 89 secondarySize 92 chance 0.3 } flickerlight POWCRYS_X25 { - color 1.0 0.2 0.0 + color 1.0 0.24 0.0 size 86 - secondarySize 90 + secondarySize 89 chance 0.3 } From 8b91bf9b61ab18b8f5748708746911b41cf59f34 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 4 Jun 2020 08:04:51 +0200 Subject: [PATCH 216/220] - enabled CVAR descriptions. --- src/common/console/c_cvars.h | 2 +- src/common/console/c_dispatch.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/common/console/c_cvars.h b/src/common/console/c_cvars.h index 1b3ac6fa98..d1b0e65068 100644 --- a/src/common/console/c_cvars.h +++ b/src/common/console/c_cvars.h @@ -171,7 +171,7 @@ public: static void ListVars (const char *filter, bool plain); - const char *GetDescription() const { return Description; }; + const FString &GetDescription() const { return Description; }; protected: virtual void DoSet (UCVarValue value, ECVarType type) = 0; diff --git a/src/common/console/c_dispatch.cpp b/src/common/console/c_dispatch.cpp index 03f3ebd461..6b4680e359 100644 --- a/src/common/console/c_dispatch.cpp +++ b/src/common/console/c_dispatch.cpp @@ -300,6 +300,7 @@ void C_DoCommand (const char *cmd, int keynum) } else { // Get the variable's value + if (var->GetDescription().Len()) Printf("%s\n", var->GetDescription().GetChars()); Printf ("\"%s\" is \"%s\"\n", var->GetName(), var->GetHumanString()); } } From b441b649c4c99a4d016c208f54f501cd95707828 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 4 Jun 2020 08:05:38 +0200 Subject: [PATCH 217/220] - fixed some double to float conversion warnings. --- src/common/utility/basics.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/utility/basics.h b/src/common/utility/basics.h index 615789b58c..2f2ff7f431 100644 --- a/src/common/utility/basics.h +++ b/src/common/utility/basics.h @@ -88,6 +88,10 @@ inline float RAD2DEG(float deg) return deg * float(180. / M_PI); } +inline double RAD2DEG(double deg) +{ + return deg * (180. / M_PI); +} // Auto-registration sections for GCC. // Apparently, you cannot do string concatenation inside section attributes. From 328d9c75c45a30bee08bace3f37c991e7950ec82 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 4 Jun 2020 14:11:36 +0200 Subject: [PATCH 218/220] - redid mouse control for the conversation menu. Since the page operates on different coordinate systems, the only working way to check the mouse is to store the real coordinates when drawing and check the mouse position against those. --- .../zscript/ui/menu/conversationmenu.zs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/wadsrc/static/zscript/ui/menu/conversationmenu.zs b/wadsrc/static/zscript/ui/menu/conversationmenu.zs index 53c86aed60..70a114c9b2 100644 --- a/wadsrc/static/zscript/ui/menu/conversationmenu.zs +++ b/wadsrc/static/zscript/ui/menu/conversationmenu.zs @@ -93,7 +93,7 @@ class ConversationMenu : Menu int fontScale; int refwidth; int refheight; - double fontfactor; + Array ypositions; int SpeechWidth; int ReplyWidth; @@ -127,7 +127,6 @@ class ConversationMenu : Menu displayWidth = CleanWidth; displayHeight = CleanHeight; fontScale = CleanXfac; - fontFactor = 1; refwidth = 320; refheight = 200; ReplyWidth = 320-50-10; @@ -140,7 +139,6 @@ class ConversationMenu : Menu { displayFont = NewSmallFont; fontScale = (CleanXfac+1) / 2; - fontFactor = double(CleanXfac) / fontScale; refwidth = 640; refheight = 400; ReplyWidth = 640-100-20; @@ -365,18 +363,14 @@ class ConversationMenu : Menu // convert x/y from screen to virtual coordinates, according to CleanX/Yfac use in DrawTexture x = ((x - (screen.GetWidth() / 2)) / fontScale) + refWidth/2; - y = ((y - (screen.GetHeight() / 2)) / fontScale) + refHeight/2; - int ypos = int(mYpos * FontFactor); - - if (x >= 24 && x <= refWidth-24 && y >= ypos && y < ypos + fh * mResponseLines.Size()) + if (x >= 24 && x <= refWidth-24) { - sel = (y - ypos) / fh; - for(int i = 0; i < mResponses.Size(); i++) + for (int i = 0; i < ypositions.Size()-1; i++) { - if (mResponses[i] > sel) + if (y > ypositions[i] && y <= ypositions[i+1]) { - sel = i-1; + sel = i; break; } } @@ -498,6 +492,7 @@ class ConversationMenu : Menu int y = mYpos; int response = 0; + ypositions.Clear(); for (int i = 0; i < mResponseLines.Size(); i++) { int width = displayFont.StringWidth(mResponseLines[i]); @@ -506,6 +501,7 @@ class ConversationMenu : Menu double sx = (x - 160.0) * CleanXfac + (screen.GetWidth() * 0.5); double sy = (y - 100.0) * CleanYfac + (screen.GetHeight() * 0.5); + ypositions.Push(sy); screen.DrawText(displayFont, Font.CR_GREEN, sx / fontScale, sy / fontScale, mResponseLines[i], DTA_KeepRatio, true, DTA_VirtualWidth, displayWidth, DTA_VirtualHeight, displayHeight); @@ -530,6 +526,8 @@ class ConversationMenu : Menu } y += ReplyLineHeight; } + double sy = (y - 100.0) * CleanYfac + (screen.GetHeight() * 0.5); + ypositions.Push(sy); } virtual void DrawGold() From 5151dff03c64d74bd6096d8eb411c9a9bfd90fcf Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 4 Jun 2020 14:30:56 +0200 Subject: [PATCH 219/220] - added a compatibility option for a bad teleporter in the final Strife map. --- wadsrc/static/zscript/level_compatibility.zs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wadsrc/static/zscript/level_compatibility.zs b/wadsrc/static/zscript/level_compatibility.zs index ee81f4d7a8..02c9ca1d6c 100644 --- a/wadsrc/static/zscript/level_compatibility.zs +++ b/wadsrc/static/zscript/level_compatibility.zs @@ -1010,6 +1010,12 @@ class LevelCompatibility : LevelPostProcessor break; } + case '775CBC35C0A58326FE87AAD638FF9E2A': // Strife1.wad map29 + case 'A75099ACB622C7013EE737480FCB0D67': // SVE.wad map29 + // disable teleporter that would always teleport into a blocking position. + ClearLineSpecial(271); + break; + case 'DB31D71B11E3E4393B9C0CCB44A8639F': // rop_2015.wad e1m5 { // Lower floor a bit so secret switch becomes accessible From 9bf0f9bbfcac47476d3b18f868852e6250a17934 Mon Sep 17 00:00:00 2001 From: Cacodemon345 Date: Thu, 4 Jun 2020 15:48:59 +0600 Subject: [PATCH 220/220] Add option to disable SDL joystick support. This also adds some extra sanity checks to avoid crashes when the joystick isn't initialized. --- src/CMakeLists.txt | 5 +++++ src/common/platform/posix/sdl/i_joystick.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 661214bf16..244ef6329c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -159,6 +159,11 @@ else() endif() endif() + option( NO_SDL_JOYSTICK "Disable SDL joystick support (Not applicable to Windows)" OFF ) + if ( NO_SDL_JOYSTICK ) + add_definitions( -DNO_SDL_JOYSTICK=1 ) + endif ( NO_SDL_JOYSTICK ) + if( NO_GTK ) add_definitions( -DNO_GTK ) elseif( DYN_GTK ) diff --git a/src/common/platform/posix/sdl/i_joystick.cpp b/src/common/platform/posix/sdl/i_joystick.cpp index 9d5297ba0f..fe4b25eb64 100644 --- a/src/common/platform/posix/sdl/i_joystick.cpp +++ b/src/common/platform/posix/sdl/i_joystick.cpp @@ -300,8 +300,10 @@ static SDLInputJoystickManager *JoystickManager; void I_StartupJoysticks() { +#ifndef NO_SDL_JOYSTICK if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0) JoystickManager = new SDLInputJoystickManager(); +#endif } void I_ShutdownInput() { @@ -316,7 +318,8 @@ void I_GetJoysticks(TArray &sticks) { sticks.Clear(); - JoystickManager->GetDevices(sticks); + if (JoystickManager) + JoystickManager->GetDevices(sticks); } void I_GetAxes(float axes[NUM_JOYAXIS]) @@ -325,7 +328,7 @@ void I_GetAxes(float axes[NUM_JOYAXIS]) { axes[i] = 0; } - if (use_joystick) + if (use_joystick && JoystickManager) { JoystickManager->AddAxes(axes); } @@ -333,7 +336,7 @@ void I_GetAxes(float axes[NUM_JOYAXIS]) void I_ProcessJoysticks() { - if (use_joystick) + if (use_joystick && JoystickManager) JoystickManager->ProcessInput(); }