From ed599d0f0541e08a30e5e77e808f27ebbb831ac5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 10 Nov 2020 16:22:02 +0100 Subject: [PATCH] - moved the hires texture replacement logic into a backend callback. This way it can be handled transparently to the calling code. Fonts do not work yet, though. --- source/build/src/mdsprite.cpp | 3 +- source/build/src/polymost.cpp | 13 ++--- source/build/src/voxmodel.cpp | 13 +---- source/common/engine/i_interface.h | 2 +- .../hwrenderer/data/hw_renderstate.h | 6 ++- source/core/gamecontrol.cpp | 5 +- source/core/textures/buildtiles.cpp | 53 +++++++++++++++++++ source/games/duke/src/render.cpp | 2 - source/glbackend/gl_texture.cpp | 25 ++++----- source/glbackend/glbackend.cpp | 34 ++---------- source/glbackend/glbackend.h | 20 +------ source/glbackend/pm_renderstate.h | 3 -- 12 files changed, 85 insertions(+), 94 deletions(-) diff --git a/source/build/src/mdsprite.cpp b/source/build/src/mdsprite.cpp index e1bfd55cc..1a0e1a824 100644 --- a/source/build/src/mdsprite.cpp +++ b/source/build/src/mdsprite.cpp @@ -1495,7 +1495,7 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) #endif int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal); GLInterface.SetFade(sector[tspr->sectnum].floorpal); - GLInterface.SetTexture(-1, tex, palid, CLAMP_XY); + GLInterface.SetTexture(tex, palid, CLAMP_XY); if (tspr->clipdist & TSPR_FLAGS_MDHACK) { @@ -1559,7 +1559,6 @@ static int32_t polymost_md3draw(md3model_t *m, tspriteptr_t tspr) GLInterface.SetCull(Cull_None); GLInterface.SetIdentityMatrix(Matrix_Model); - GLInterface.SetTinting(-1, 0xffffff, 0xffffff); globalnoeffect=0; return 1; diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 9d0bdd18a..53d0762df 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -29,12 +29,10 @@ CVARD(Bool, hw_animsmoothing, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enable/di CVARD(Bool, hw_hightile, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enable/disable hightile texture rendering") CVARD(Bool, hw_models, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enable/disable model rendering") CVARD(Bool, hw_parallaxskypanning, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enable/disable parallaxed floor/ceiling panning when drawing a parallaxing sky") -CVARD(Bool, hw_shadeinterpolate, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enable/disable shade interpolation") CVARD(Float, hw_shadescale, 1.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "multiplier for shading") bool hw_int_useindexedcolortextures; CUSTOM_CVARD(Bool, hw_useindexedcolortextures, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enable/disable indexed color texture rendering") { - hw_int_useindexedcolortextures = self; if (screen) screen->SetTextureFilterMode(); } @@ -379,7 +377,7 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal); GLInterface.SetFade(globalfloorpal); - bool success = GLInterface.SetTexture(globalpicnum, tileGetTexture(globalpicnum), palid, sampleroverride); + bool success = GLInterface.SetTexture(tileGetTexture(globalpicnum), palid, sampleroverride); if (!success) { tsiz.x = tsiz.y = 1; @@ -461,7 +459,6 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 } GLInterface.Draw(DT_TriangleFan, data.second, npoints); - GLInterface.SetTinting(-1, 0xffffff, 0xffffff); GLInterface.SetNpotEmulation(0.f, 0.f); GLInterface.SetTextureMode(TM_NORMAL); @@ -2489,8 +2486,6 @@ void polymost_drawrooms() ghoriz = FixedToFloat(qglobalhoriz); ghorizcorrect = FixedToFloat(divscale16(xdimenscale, viewingrange)); - GLInterface.SetShadeInterpolate(hw_shadeinterpolate); - //global cos/sin height angle if (r_yshearing) { @@ -3604,7 +3599,9 @@ void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype) //Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype); hicprecaching = 1; int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); - GLInterface.SetTexture(dapicnum, tileGetTexture(dapicnum), palid, CLAMP_NONE); + auto tex = tileGetTexture(dapicnum); + if (tex->isValid()) + GLInterface.SetTexture(tex, palid, CLAMP_NONE); hicprecaching = 0; if (datype == 0 || !hw_models) return; @@ -3619,7 +3616,7 @@ void polymost_precache(int32_t dapicnum, int32_t dapalnum, int32_t datype) { auto tex = mdloadskin((md2model_t *)models[mid], 0, dapalnum, i, nullptr); int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); - if (tex) GLInterface.SetTexture(-1, tex, palid, CLAMP_NONE); + if (tex) GLInterface.SetTexture(tex, palid, CLAMP_NONE); } } diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index 59a57cecb..5f6aafb5c 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -1151,16 +1151,8 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr) GLInterface.SetPalswap(globalpal); GLInterface.SetFade(sector[tspr->sectnum].floorpal); - // The texture here is already translated. - GLInterface.SetTexture(-1, htex, 0/*TRANSLATION(Translation_Remap + curbasepal, globalpal)*/, CLAMP_NOFILTER_XY, true); - - // This must be done after setting up the texture. - auto& h = lookups.tables[globalpal]; - if (h.tintFlags & (TINTF_USEONART|TINTF_ALWAYSUSEART)) - GLInterface.SetTinting(h.tintFlags, h.tintColor, h.tintColor); - else - GLInterface.SetTinting(-1, 0xffffff, 0xffffff); - + // The texture here is already translated. + GLInterface.SetTexture(htex, 0/*TRANSLATION(Translation_Remap + curbasepal, globalpal)*/, CLAMP_NOFILTER_XY, true); #endif auto data = screen->mVertexData->AllocVertices(m->qcnt * 6); @@ -1216,7 +1208,6 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr) } GLInterface.SetIdentityMatrix(Matrix_Model); GLInterface.SetFadeDisable(false); - GLInterface.SetTinting(-1, 0xffffff, 0xffffff); return 1; } #endif diff --git a/source/common/engine/i_interface.h b/source/common/engine/i_interface.h index 73d7fb8c8..131e0cce2 100644 --- a/source/common/engine/i_interface.h +++ b/source/common/engine/i_interface.h @@ -30,7 +30,7 @@ struct SystemCallbacks void (*MenuClosed)(); bool (*CheckMenudefOption)(const char* opt); void (*ConsoleToggled)(int state); - bool (*PreBindTexture)(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& clampmode, int& translation, int& overrideshader); + bool (*PreBindTexture)(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& scaleflags, int& clampmode, int& translation, int& overrideshader); }; extern SystemCallbacks sysCallbacks; diff --git a/source/common/rendering/hwrenderer/data/hw_renderstate.h b/source/common/rendering/hwrenderer/data/hw_renderstate.h index 9a90983f3..9cf1015d2 100644 --- a/source/common/rendering/hwrenderer/data/hw_renderstate.h +++ b/source/common/rendering/hwrenderer/data/hw_renderstate.h @@ -586,11 +586,13 @@ private: public: void SetMaterial(FGameTexture* tex, EUpscaleFlags upscalemask, int scaleflags, int clampmode, int translation, int overrideshader) { - if (sysCallbacks.PreBindTexture && !sysCallbacks.PreBindTexture(this, tex, upscalemask, clampmode, translation, overrideshader)) + if (!sysCallbacks.PreBindTexture || !sysCallbacks.PreBindTexture(this, tex, upscalemask, scaleflags, clampmode, translation, overrideshader)) { if (shouldUpscale(tex, upscalemask)) scaleflags |= CTF_Upscale; } - SetMaterial(FMaterial::ValidateTexture(tex, scaleflags), clampmode, translation, overrideshader); + auto mat = FMaterial::ValidateTexture(tex, scaleflags); + assert(mat); + SetMaterial(mat, clampmode, translation, overrideshader); } void SetClipSplit(float bottom, float top) diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index 922f6483e..0cbe2286d 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -131,6 +131,7 @@ void I_DetectOS(void); void LoadScripts(); void MainLoop(); void SetConsoleNotifyBuffer(); +bool PreBindTexture(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& scaleflags, int& clampmode, int& translation, int& overrideshader); DBaseStatusBar* StatusBar; @@ -521,7 +522,9 @@ int GameMain() validFilter, StrTable_GetGender, System_MenuClosed, - nullptr + nullptr, + nullptr, + PreBindTexture }; try diff --git a/source/core/textures/buildtiles.cpp b/source/core/textures/buildtiles.cpp index 022f3cb72..e809dffb3 100644 --- a/source/core/textures/buildtiles.cpp +++ b/source/core/textures/buildtiles.cpp @@ -48,6 +48,10 @@ #include "sc_man.h" #include "gamestruct.h" +#include "hw_renderstate.h" + +CVARD(Bool, hw_shadeinterpolate, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG, "enable/disable shade interpolation") + enum { MAXARTFILES_BASE = 200, @@ -1237,3 +1241,52 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TileFiles, GetTexture, GetTexture) ACTION_RETURN_INT(GetTexture(tile, animate)); } #endif + + +bool PreBindTexture(FRenderState* state, FGameTexture*& tex, EUpscaleFlags& flags, int& scaleflags, int& clampmode, int& translation, int& overrideshader) +{ + TexturePick pick; + auto t = tex; + + if (PickTexture(-1, tex, translation, pick)) + { + int TextureType = (pick.translation & 0x80000000) ? TT_INDEXED : TT_TRUECOLOR; + int lookuppal = pick.translation & 0x7fffffff; + + if (pick.translation & 0x80000000) scaleflags |= CTF_Indexed; + tex = pick.texture; + translation = lookuppal; + + FVector4 addcol(0, 0, 0, 0); + FVector4 modcol(pick.basepalTint.r * (1.f / 255.f), pick.basepalTint.g * (1.f / 255.f), pick.basepalTint.b * (1.f / 255.f), 1); + FVector4 blendcol(0, 0, 0, 0); + int flags = 0; + + if (pick.basepalTint != 0xffffff) flags |= TextureManipulation::ActiveBit; + if (pick.tintFlags != -1) + { + flags |= TextureManipulation::ActiveBit; + if (pick.tintFlags & TINTF_COLORIZE) + { + modcol.X *= pick.tintColor.r * (1.f / 64.f); + modcol.Y *= pick.tintColor.g * (1.f / 64.f); + modcol.Z *= pick.tintColor.b * (1.f / 64.f); + } + if (pick.tintFlags & TINTF_GRAYSCALE) + modcol.W = 1.f; + + if (pick.tintFlags & TINTF_INVERT) + flags |= TextureManipulation::InvertBit; + + if (pick.tintFlags & TINTF_BLENDMASK) + { + blendcol = modcol; // WTF???, but the tinting code really uses the same color for both! + flags |= (((pick.tintFlags & TINTF_BLENDMASK) >> 6) + 1) & TextureManipulation::BlendMask; + } + } + addcol.W = flags; + if ((pick.translation & 0x80000000) && hw_shadeinterpolate) addcol.W += 16384; // hijack a free bit in here. + state->SetTextureColors(&modcol.X, &addcol.X, &blendcol.X); + } + return tex->GetTexelWidth() > t->GetTexelWidth() && tex->GetTexelHeight() > t->GetTexelHeight(); // returning 'true' means to disable programmatic upscaling. +} diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index d832529c5..cfb4d1432 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -502,7 +502,6 @@ void displayrooms(int snum, double smoothratio) if (sect < 0 || sect >= MAXSECTORS) return; GLInterface.SetMapFog(fogactive != 0); - if (fogactive) hw_int_useindexedcolortextures = false; dointerpolations(smoothratio); setgamepalette(BASEPAL); @@ -659,7 +658,6 @@ void displayrooms(int snum, double smoothratio) } else p->visibility = ud.const_visibility; } - if (fogactive) hw_int_useindexedcolortextures = hw_useindexedcolortextures; } bool GameInterface::GenerateSavePic() diff --git a/source/glbackend/gl_texture.cpp b/source/glbackend/gl_texture.cpp index 7b931af8e..023c9475d 100644 --- a/source/glbackend/gl_texture.cpp +++ b/source/glbackend/gl_texture.cpp @@ -43,6 +43,7 @@ #include "../../glbackend/glbackend.h" #include "texturemanager.h" #include "v_video.h" +#include "printf.h" //=========================================================================== // @@ -56,8 +57,12 @@ CVAR(Int, fixpalette, -1, 0) CVAR(Int, fixpalswap, -1, 0) #endif -bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sampler, bool notindexed) +bool GLInstance::SetTexture(FGameTexture* tex, int paletteid, int sampler, bool notindexed) { + if (!tex->isValid()) + { + return false; + } #ifdef _DEBUG int basepal = GetTranslationType(paletteid) - Translation_Remap; int translation = GetTranslationIndex(paletteid); @@ -66,23 +71,15 @@ bool GLInstance::SetTexture(int picnum, FGameTexture* tex, int paletteid, int sa paletteid = TRANSLATION(Translation_Remap + usepalette, usepalswap); #endif - TexturePick texpick; - if (!PickTexture(picnum, tex, paletteid, texpick)) return false; + SetPalswap(GetTranslationIndex(paletteid)); - int TextureType = (texpick.translation & 0x80000000) ? TT_INDEXED : TT_TRUECOLOR; - - // This is intentionally the same value for both parameters. The shader does not use the same uniform for modulation and overlay colors. - SetTinting(texpick.tintFlags, texpick.tintColor, texpick.tintColor); - int lookuppal = texpick.translation & 0x7fffffff; - SetPalswap(GetTranslationIndex(lookuppal)); - - SetBasepalTint(texpick.basepalTint); auto &mat = renderState.mMaterial; - mat.mTexture = texpick.texture; + assert(tex->isValid()); + mat.mTexture = tex; mat.uFlags = UF_None; - mat.mScaleFlags = (TextureType == TT_INDEXED) ? CTF_Indexed : 0; + mat.mScaleFlags = 0; mat.mClampMode = sampler; - mat.mTranslation = texpick.translation; + mat.mTranslation = paletteid; mat.mOverrideShader = -1; mat.mChanged = true; GLInterface.SetAlphaThreshold(tex->alphaThreshold); diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index bea6ca904..bbb718f6a 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -106,6 +106,8 @@ void GLInstance::DoDraw() if (rendercommands.Size() > 0) { + if (!useMapFog) hw_int_useindexedcolortextures = hw_useindexedcolortextures; + lastState.Flags = ~rendercommands[0].StateFlags; // Force ALL flags to be considered 'changed'. lastState.DepthFunc = INT_MIN; // Something totally invalid. screen->RenderState()->EnableMultisampling(true); @@ -117,6 +119,7 @@ void GLInstance::DoDraw() } renderState.Apply(*screen->RenderState(), lastState); // apply any pending change before returning. rendercommands.Clear(); + hw_int_useindexedcolortextures = false; } matrixArray.Resize(1); } @@ -243,37 +246,6 @@ void PolymostRenderState::Apply(FRenderState& state, GLState& oldState) state.SetNpotEmulation(NPOTEmulation.Y, NPOTEmulation.X); state.AlphaFunc(Alpha_Greater, AlphaTest ? AlphaThreshold : -1.f); - FVector4 addcol(0, 0, 0, 0); - FVector4 modcol(fullscreenTint.r / 255.f, fullscreenTint.g / 255.f, fullscreenTint.b / 255.f, 1); - FVector4 blendcol(0, 0, 0, 0); - int flags = 0; - - if (fullscreenTint != 0xffffff) flags |= 16; - if (hictint_flags != -1) - { - flags |= TextureManipulation::ActiveBit; - if (hictint_flags & TINTF_COLORIZE) - { - modcol.X *= hictint.r / 64.f; - modcol.Y *= hictint.g / 64.f; - modcol.Z *= hictint.b / 64.f; - } - if (hictint_flags & TINTF_GRAYSCALE) - modcol.W = 1.f; - - if (hictint_flags & TINTF_INVERT) - flags |= TextureManipulation::InvertBit; - - if (hictint_flags & TINTF_BLENDMASK) - { - blendcol = modcol; // WTF???, but the tinting code really uses the same color for both! - flags |= (((hictint_flags & TINTF_BLENDMASK) >> 6) + 1) & TextureManipulation::BlendMask; - } - } - addcol.W = flags; - if (Flags & RF_ShadeInterpolate) addcol.W += 16384; // hijack a free bit in here. - state.SetTextureColors(&modcol.X, &addcol.X, &blendcol.X); - if (matrixIndex[Matrix_Model] != -1) { state.EnableModelMatrix(true); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 36ab6cb31..9fec3bf7d 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -293,12 +293,6 @@ public: renderState.NPOTEmulation.X = xOffset; } - void SetShadeInterpolate(int32_t yes) - { - if (yes) renderState.Flags |= RF_ShadeInterpolate; - else renderState.Flags &= ~RF_ShadeInterpolate; - } - void SetFadeDisable(bool yes) { if (yes) renderState.Flags |= RF_FogDisabled; @@ -324,18 +318,6 @@ public: renderState.Flags &= ~RF_MapFog; } - void SetTinting(int flags, PalEntry color, PalEntry overlayColor) - { - renderState.hictint = color; - renderState.hictint_overlay = overlayColor; - renderState.hictint_flags = flags; - } - - void SetBasepalTint(PalEntry color) - { - renderState.fullscreenTint = color; - } - void EnableAlphaTest(bool on) { renderState.AlphaTest = on; @@ -346,7 +328,7 @@ public: renderState.AlphaThreshold = al; } - bool SetTexture(int globalpicnum, FGameTexture* tex, int palette, int sampleroverride, bool notindexed = false); + bool SetTexture(FGameTexture* tex, int palette, int sampleroverride, bool notindexed = false); }; extern GLInstance GLInterface; diff --git a/source/glbackend/pm_renderstate.h b/source/glbackend/pm_renderstate.h index 5708a1ec0..a21389b9b 100644 --- a/source/glbackend/pm_renderstate.h +++ b/source/glbackend/pm_renderstate.h @@ -16,7 +16,6 @@ enum EMatrixType enum PRSFlags { RF_ColorOnly = 1, - RF_ShadeInterpolate = 64, RF_FogDisabled = 128, RF_MapFog = 256, // RRRA E2L1. @@ -78,8 +77,6 @@ struct PolymostRenderState bool AlphaTest = true; float Color[4] = { 1,1,1,1 }; short matrixIndex[NUMMATRICES] = { -1 }; - PalEntry fullscreenTint = 0xffffff, hictint = 0xffffff, hictint_overlay = 0xffffff; - int hictint_flags = -1; FDepthBiasState mBias{ }; PolymostTextureState mMaterial;