From 547ed4e41542697aa45a9a6fd37402ef97470cb9 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 18 Mar 2021 17:18:03 +0100 Subject: [PATCH] - route everything through the full backend, now completely bypassing the intermediate GLInstance layer. --- source/build/src/engine.cpp | 4 +- source/build/src/voxmodel.cpp | 1 - source/core/rendering/hw_entrypoint.cpp | 7 +- .../core/rendering/scene/hw_bunchdrawer.cpp | 4 +- source/core/rendering/scene/hw_bunchdrawer.h | 6 +- source/core/rendering/scene/hw_drawinfo.cpp | 15 +-- source/core/rendering/scene/hw_drawinfo.h | 10 -- .../core/rendering/scene/hw_drawlistadd.cpp | 4 +- source/core/rendering/scene/hw_drawstructs.h | 4 +- source/core/rendering/scene/hw_walls.cpp | 113 ++++++++---------- source/games/duke/src/render.cpp | 6 + source/glbackend/glbackend.h | 6 - 12 files changed, 78 insertions(+), 102 deletions(-) diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index d2c6383e2..a7176bae2 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -981,8 +981,8 @@ int32_t renderDrawRoomsQ16(int32_t daposx, int32_t daposy, int32_t daposz, else { vec3_t pos = { daposx, daposy, daposz }; - if (!testnewinterface) render_drawrooms_(pos, globalcursectnum, daang, dahoriz, rollang, r_fov, false, false); - else render_drawrooms(pos, globalcursectnum, daang, dahoriz, rollang, false, false); + //if (!testnewinterface) render_drawrooms_(pos, globalcursectnum, daang, dahoriz, rollang, r_fov, false, false); + /*else*/ render_drawrooms(pos, globalcursectnum, daang, dahoriz, rollang, false, false); } return inpreparemirror; diff --git a/source/build/src/voxmodel.cpp b/source/build/src/voxmodel.cpp index 5aea13d1c..f234a34f7 100644 --- a/source/build/src/voxmodel.cpp +++ b/source/build/src/voxmodel.cpp @@ -190,7 +190,6 @@ int32_t polymost_voxdraw(voxmodel_t* m, tspriteptr_t const tspr) GLInterface.SetDepthFunc(DF_Less); } GLInterface.SetIdentityMatrix(Matrix_Model); - GLInterface.SetFadeDisable(false); return 1; } diff --git a/source/core/rendering/hw_entrypoint.cpp b/source/core/rendering/hw_entrypoint.cpp index ce3c8e765..da7a7a3bc 100644 --- a/source/core/rendering/hw_entrypoint.cpp +++ b/source/core/rendering/hw_entrypoint.cpp @@ -60,6 +60,10 @@ EXTERN_CVAR(Bool, cl_capfps) bool NoInterpolateView; +PalEntry GlobalMapFog; +float GlobalFogDensity; + + #if 0 void CollectLights(FLevelLocals* Level) { @@ -267,7 +271,6 @@ static void CheckTimer(FRenderState &state, uint64_t ShaderStartTime) void render_drawrooms(vec3_t& position, int sectnum, fixed_t q16angle, fixed_t q16horizon, float rollang, bool mirror, bool planemirror) { - int retsec = 0; auto RenderState = screen->RenderState(); RenderState->SetVertexBuffer(screen->mVertexData); screen->mVertexData->Reset(); @@ -311,7 +314,7 @@ void render_drawrooms(vec3_t& position, int sectnum, fixed_t q16angle, fixed_t q // now render the main view float fovratio; - float ratio = ActiveRatio(windowxy2.x - windowxy1.x + 1, windowxy2.y - windowxy1.y); + float ratio = ActiveRatio(windowxy2.x - windowxy1.x + 1, windowxy2.y - windowxy1.y + 1); if (ratio >= 1.33f) { fovratio = 1.33f; diff --git a/source/core/rendering/scene/hw_bunchdrawer.cpp b/source/core/rendering/scene/hw_bunchdrawer.cpp index 3781c2790..6c40c3217 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.cpp +++ b/source/core/rendering/scene/hw_bunchdrawer.cpp @@ -47,7 +47,7 @@ // //========================================================================== -void BunchDrawer::Init(FDrawInfo *_di, Clipper* c, vec2_t& view) +void BunchDrawer::Init(HWDrawInfo *_di, Clipper* c, vec2_t& view) { di = _di; clipper = c; @@ -230,7 +230,7 @@ void BunchDrawer::ProcessBunch(int bnch) HWWall hwwall; //Printf("Rendering wall %d\n", i); - hwwall.Process(nullptr, &wall[i], §or[bunch->sectnum], wall[i].nextsector<0? nullptr : §or[wall[i].nextsector]); + hwwall.Process(di, &wall[i], §or[bunch->sectnum], wall[i].nextsector<0? nullptr : §or[wall[i].nextsector]); rendered_lines++; SetupWall.Unclock(); diff --git a/source/core/rendering/scene/hw_bunchdrawer.h b/source/core/rendering/scene/hw_bunchdrawer.h index f1a40e359..9cff89973 100644 --- a/source/core/rendering/scene/hw_bunchdrawer.h +++ b/source/core/rendering/scene/hw_bunchdrawer.h @@ -3,7 +3,7 @@ #include "tarray.h" #include "basics.h" -class FDrawInfo; +struct HWDrawInfo; class Clipper; struct FBunch @@ -17,7 +17,7 @@ struct FBunch class BunchDrawer { - FDrawInfo *di; + HWDrawInfo *di; Clipper *clipper; int LastBunch; int StartTime; @@ -49,6 +49,6 @@ private: void ProcessSector(int sectnum); public: - void Init(FDrawInfo* _di, Clipper* c, vec2_t& view); + void Init(HWDrawInfo* _di, Clipper* c, vec2_t& view); void RenderScene(int viewsector); }; diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index e99897852..34cc77f95 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -38,6 +38,7 @@ #include "hw_vrmodes.h" #include "hw_clipper.h" #include "v_draw.h" +#include "gamecvars.h" EXTERN_CVAR(Float, r_visibility) CVAR(Bool, gl_bandedswlight, false, CVAR_ARCHIVE) @@ -136,7 +137,7 @@ void HWDrawInfo::StartScene(FRenderViewpoint &parentvp, HWViewpointUniforms *uni VPUniforms.mViewMatrix.loadIdentity(); VPUniforms.mNormalViewMatrix.loadIdentity(); //VPUniforms.mViewHeight = viewheight; - VPUniforms.mGlobVis = 1 / 64.f; + VPUniforms.mGlobVis = (2 / 65536.f) * g_visibility / r_ambientlight; VPUniforms.mPalLightLevels = numshades | (static_cast(gl_fogmode) << 8) | (5 << 16); VPUniforms.mClipLine.X = -10000000.0f; @@ -184,15 +185,9 @@ HWDrawInfo *HWDrawInfo::EndDrawInfo() void HWDrawInfo::ClearBuffers() { - HandledSubsectors.Clear(); spriteindex = 0; - - sector_renderflags.Resize(numsectors); - memset(§or_renderflags[0], 0, numsectors * sizeof(sector_renderflags[0])); - Decals[0].Clear(); Decals[1].Clear(); - mClipPortal = nullptr; mCurrentPortal = nullptr; } @@ -296,7 +291,7 @@ HWDecal* HWDrawInfo::AddDecal(bool onmirror) void HWDrawInfo::CreateScene() { - const auto &vp = Viewpoint; + const auto& vp = Viewpoint; angle_t a1 = FrustumAngle(); mClipper->SafeAddClipRangeRealAngles(vp.RotAngle + a1, vp.RotAngle - a1); @@ -312,7 +307,9 @@ void HWDrawInfo::CreateScene() screen->mVertexData->Map(); screen->mLights->Map(); - //RenderBSP(Level->HeadNode(), drawpsprites); + vec2_t view = { int(vp.Pos.X * 16), int(vp.Pos.Y * -16) }; + mDrawer.Init(this, mClipper, view); + mDrawer.RenderScene(vp.SectNum); // And now the crappy hacks that have to be done to avoid rendering anomalies. // These cannot be multithreaded when the time comes because all these depend diff --git a/source/core/rendering/scene/hw_drawinfo.h b/source/core/rendering/scene/hw_drawinfo.h index ac7eda6a0..c86e908dd 100644 --- a/source/core/rendering/scene/hw_drawinfo.h +++ b/source/core/rendering/scene/hw_drawinfo.h @@ -105,10 +105,6 @@ struct HWDrawInfo TArray Portals; TArray Decals[2]; // the second slot is for mirrors which get rendered in a separate pass. - TArray HandledSubsectors; - - TArray sector_renderflags; - // This is needed by the BSP traverser. 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; @@ -128,12 +124,6 @@ private: //void RenderThings(sectortype * sub, sectortype * sector); //void RenderParticles(sectortype *sub, sectortype *front); void SetColor(FRenderState &state, int sectorlightlevel, int rellight, bool fullbright, const FColormap &cm, float alpha, bool weapon = false); - void SetFog(FRenderState &state, int lightlevel, int rellight, bool fullbright, const FColormap *cmap, bool isadditive); - void SetShaderLight(FRenderState &state, float level, float olight); - int CalcLightLevel(int lightlevel, int rellight, bool weapon, int blendfactor); - PalEntry CalcLightColor(int light, PalEntry pe, int blendfactor); - float GetFogDensity(int lightlevel, PalEntry fogcolor, int sectorfogdensity, int blendfactor); - bool CheckFog(sectortype *frontsector, sectortype *backsector); public: void SetCameraPos(const DVector3 &pos) diff --git a/source/core/rendering/scene/hw_drawlistadd.cpp b/source/core/rendering/scene/hw_drawlistadd.cpp index 2b3b3f0ec..50473b49c 100644 --- a/source/core/rendering/scene/hw_drawlistadd.cpp +++ b/source/core/rendering/scene/hw_drawlistadd.cpp @@ -40,7 +40,6 @@ EXTERN_CVAR(Bool, gl_seamless) void HWDrawInfo::AddWall(HWWall *wall) { -#if 0 if (wall->flags & HWWall::HWF_TRANSLUCENT) { auto newwall = drawlists[GLDL_TRANSLUCENT].NewWall(); @@ -48,7 +47,7 @@ void HWDrawInfo::AddWall(HWWall *wall) } else { - bool masked = HWWall::passflag[wall->type] == 1 ? false : (wall->texture && wall->texture->isMasked()); + bool masked = wall->type != RENDERWALL_M2S ? false : (wall->texture && wall->texture->isMasked()); int list; if (wall->flags & HWWall::HWF_SKYHACK && wall->type == RENDERWALL_M2S) @@ -62,7 +61,6 @@ void HWDrawInfo::AddWall(HWWall *wall) auto newwall = drawlists[list].NewWall(); *newwall = *wall; } -#endif } //========================================================================== diff --git a/source/core/rendering/scene/hw_drawstructs.h b/source/core/rendering/scene/hw_drawstructs.h index 56fe42c85..4bf17ce2c 100644 --- a/source/core/rendering/scene/hw_drawstructs.h +++ b/source/core/rendering/scene/hw_drawstructs.h @@ -154,7 +154,9 @@ public: float ViewDistance; float visibility; - short shade, palette, floorpal; + short shade, palette; + + PalEntry fade; uint16_t flags; uint8_t type; diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index a5550c86c..bffd46d75 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -26,8 +26,7 @@ #include "hw_cvars.h" #include "hw_clock.h" //#include "hw_lighting.h" -//#include "hwrenderer/scene/hw_drawinfo.h" -//#include "hwrenderer/scene/hw_drawstructs.h" +#include "hw_drawinfo.h" //#include "hwrenderer/scene/hw_portal.h" #include "hw_lightbuffer.h" #include "hw_renderstate.h" @@ -40,6 +39,8 @@ #include "flatvertices.h" #include "glbackend/glbackend.h" +extern PalEntry GlobalMapFog; +extern float GlobalFogDensity; //========================================================================== // @@ -171,12 +172,10 @@ void HWWall::RenderMirrorSurface(HWDrawInfo *di, FRenderState &state) void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) { -#if 0 - int tmode = state.GetTextureMode(); + //int tmode = state.GetTextureMode(); - state.SetMaterial(texture, UF_Texture, 0, flags & 3, 0, -1); + state.SetMaterial(texture, UF_Texture, 0, 0/*flags & 3*/, TRANSLATION(Translation_Remap + curbasepal, palette), -1); - int32_t size = xs_CRoundToInt(texture->GetDisplayHeight()); int32_t size2; for (size2 = 1; size2 < size; size2 += size2) {} @@ -188,13 +187,48 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) state.SetNpotEmulation((1.f * size2) / size, xOffset); } - float absalpha = fabsf(alpha); - if (type != RENDERWALL_M2SNF) di->SetFog(state, lightlevel, rel, di->isFullbrightScene(), &Colormap, RenderStyle == STYLE_Add); - di->SetColor(state, lightlevel, rel, di->isFullbrightScene(), Colormap, absalpha); + + // Fog must be done before the texture so that the texture selector can override it. + bool foggy = (GlobalMapFog || (fade & 0xffffff)); + auto ShadeDiv = lookups.tables[palette].ShadeFactor; + // Disable brightmaps if non-black fog is used. + if (ShadeDiv >= 1 / 1000.f && foggy) + { + state.EnableFog(1); + float density = GlobalMapFog ? GlobalFogDensity : 350.f - Scale(numshades - shade, 150, numshades); + state.SetFog((GlobalMapFog) ? GlobalMapFog : fade, density); + state.SetSoftLightLevel(255); + state.SetLightParms(128.f, 1 / 1000.f); + } + else + { + state.EnableFog(0); + state.SetFog(0, 0); + state.SetSoftLightLevel(ShadeDiv >= 1 / 1000.f ? 255 - Scale(shade, 255, numshades) : 255); + state.SetLightParms(visibility, ShadeDiv / (numshades - 2)); + } + + // The shade rgb from the tint is ignored here. + state.SetColor(PalEntry(255, globalr, globalg, globalb)); + + int h = texture->GetTexelHeight(); + int h2 = 1 << sizeToBits(h); + if (h2 < h) h2 *= 2; + if (h != h2) + { + float xOffset = 1.f / texture->GetTexelWidth(); + state.SetNpotEmulation(float(h2) / h, xOffset); + } + else + { + state.SetNpotEmulation(0.f, 0.f); + } + RenderWall(di, state, rflags); state.SetNpotEmulation(0.f, 0.f); + /* none of these functions is in use. state.SetObjectColor(0xffffffff); state.SetObjectColor2(0); state.SetAddColor(0); @@ -202,7 +236,7 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags) state.EnableGlow(false); state.EnableGradient(false); state.ApplyTextureManipulation(nullptr); -#endif + */ } //========================================================================== @@ -229,16 +263,16 @@ void HWWall::RenderTranslucentWall(HWDrawInfo *di, FRenderState &state) //========================================================================== void HWWall::DrawWall(HWDrawInfo *di, FRenderState &state, bool translucent) { - /* if (screen->BuffersArePersistent()) { + /* if (di->Level->HasDynamicLights && !di->isFullbrightScene() && texture != nullptr) { SetupLights(di, lightdata); } + */ MakeVertices(di, !!(flags & HWWall::HWF_TRANSLUCENT)); } - */ state.SetNormal(glseg.Normal()); if (!translucent) @@ -379,16 +413,18 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent) //ViewDistance = (di->Viewpoint.Pos - (seg->linedef->v1->fPos() + seg->linedef->Delta() / 2)).XY().LengthSquared(); } - /* if (!screen->BuffersArePersistent()) { + /* if (di->Level->HasDynamicLights && !di->isFullbrightScene() && texture != nullptr) { SetupLights(di, lightdata); } + */ MakeVertices(di, translucent); } + /* bool hasDecals = type != RENDERWALL_M2S && seg->sidedef->AttachedDecals; if (hasDecals) { @@ -404,56 +440,7 @@ void HWWall::PutWall(HWDrawInfo *di, bool translucent) } */ -#if 0 di->AddWall(this); -#else - // route it through the GLInterface for now for easier testing - int palid = TRANSLATION(Translation_Remap + curbasepal, globalpal); - GLInterface.SetFade(globalfloorpal); - GLInterface.SetTexture(texture, TRANSLATION(Translation_Remap + curbasepal, palette), 0); - - GLInterface.SetShade(shade, numshades); - - int h = texture->GetTexelHeight(); - int h2 = 1 << sizeToBits(h); - if (h2 < h) h2 *= 2; - if (h != h2) - { - float xOffset = 1.f / texture->GetTexelWidth(); - GLInterface.SetNpotEmulation(float(h2) / h, xOffset); - } - else - { - GLInterface.SetNpotEmulation(0.f, 0.f); - } - GLInterface.SetTextureMode(TM_OPAQUE); - GLInterface.SetVisibility(visibility); - - // The shade rgb from the tint is ignored here. - float pc[4]; - pc[0] = (float)globalr * (1.f / 255.f); - pc[1] = (float)globalg * (1.f / 255.f); - pc[2] = (float)globalb * (1.f / 255.f); - pc[3] = alpha; - GLInterface.SetColor(pc[0], pc[1], pc[2], pc[3]); - - auto data = screen->mVertexData->AllocVertices(4); - auto vt = data.first; - vt[0].SetTexCoord(tcs[LOLFT].u, tcs[LOLFT].v); - vt[0].SetVertex(glseg.x1, zbottom[0], glseg.y1); - vt[1].SetTexCoord(tcs[UPLFT].u, tcs[UPLFT].v); - vt[1].SetVertex(glseg.x1, ztop[0], glseg.y1); - vt[2].SetTexCoord(tcs[UPRGT].u, tcs[UPRGT].v); - vt[2].SetVertex(glseg.x2, ztop[1], glseg.y2); - vt[3].SetTexCoord(tcs[LORGT].u, tcs[LORGT].v); - vt[3].SetVertex(glseg.x2, zbottom[1], glseg.y2); - - GLInterface.Draw(DT_TriangleFan, data.second, 4); - - GLInterface.SetNpotEmulation(0.f, 0.f); - GLInterface.SetTextureMode(TM_NORMAL); - -#endif // make sure that following parts of the same linedef do not get this one's vertex and lighting info. vertcount = 0; dynlightindex = -1; @@ -1000,7 +987,7 @@ void HWWall::Process(HWDrawInfo *di, walltype *wal, sectortype* frontsector, sec dynlightindex = -1; shade = wal->shade; palette = wal->pal; - floorpal = frontsector->floorpal; + fade = lookups.getFade(frontsector->floorpal); // fog is per sector. visibility = sectorVisibility(frontsector); alpha = 1.0f; diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 321e2bc31..c3c3101cb 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -34,6 +34,10 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au) #include "dukeactor.h" #include "interpolate.h" +// temporary hack to pass along RRRA's global fog. Needs to be done better later. +extern PalEntry GlobalMapFog; +extern float GlobalFogDensity; + BEGIN_DUKE_NS @@ -491,6 +495,8 @@ void displayrooms(int snum, double smoothratio) sect = p->cursectnum; if (sect < 0 || sect >= MAXSECTORS) return; + GlobalMapFog = fogactive ? 0x999999 : 0; + GlobalFogDensity = fogactive ? 350.f : 0.f; GLInterface.SetMapFog(fogactive != 0); DoInterpolations(smoothratio / 65536.); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 518a7503e..ced1e8885 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -287,12 +287,6 @@ public: renderState.NPOTEmulation.X = xOffset; } - void SetFadeDisable(bool yes) - { - if (yes) renderState.Flags |= RF_FogDisabled; - else renderState.Flags &= ~RF_FogDisabled; - } - // Hack... bool useMapFog = false;