From 707dbab7e2f8157c5767b85e662ab84f2ebe5c59 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 30 Nov 2025 14:41:19 +0100 Subject: [PATCH] hw_main: cleanup HWR_RenderX stuff a bit --- src/hardware/hw_main.cpp | 152 ++++++++++++++++++++------------------- src/hardware/hw_main.h | 3 +- src/hardware/hw_portal.c | 4 +- src/hardware/hw_portal.h | 2 +- 4 files changed, 82 insertions(+), 79 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 3c2801b1c..91861e5d6 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -147,7 +147,7 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing); static void HWR_SetTransformAiming(FTransform *trans); static void HWR_RollTransform(FTransform *tr, angle_t roll); -static void HWR_DoPostProcessor(player_t *player); +static void HWR_DoPostProcessor(void); static void HWR_SetShaderState(void); static void HWR_TogglePaletteRendering(void); @@ -5371,8 +5371,6 @@ void HWR_BuildSkyDome(void) } } -static boolean drewsky = false; - // precompute to save a bit of division static constexpr float FINEDEGREE = (360.0f/(float)FINEANGLES); @@ -5380,7 +5378,7 @@ static void HWR_DrawSkyBackground(void) { FTransform dometransform; - if (drewsky || HWR_IsWireframeMode()) + if (HWR_IsWireframeMode()) return; GL_SetBlend(PF_Translucent|PF_NoDepthTest|PF_Modulated); @@ -5538,15 +5536,22 @@ namespace }; template -void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals) +static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, boolean allow_portals) { gl_portallist_t portallist; - const float fpov = FixedToFloat(R_GetPlayerFov(player)); - const boolean skybox = (skyboxmo[0] && cv_skybox.value); + player_t *viewplayer = &players[displayplayers[viewssnum]]; + const float fpov = FixedToFloat(R_GetPlayerFov(viewplayer)); + + auto reset_viewstate = [&](const float fpov) + { + HWR_SetTransform(fpov); + HWR_ClearSprites(); + HWR_ClearClipper(); + }; portallist.base = portallist.cap = NULL; - HWR_SetPortalState(GLPORTAL_OFF); // there may be portals and they need to be drawn as regural walls + HWR_SetPortalState(GLPORTAL_OFF); // there may be portals and they need to be drawn as regular walls if constexpr (Type == RenderViewpointType::kPortal) { @@ -5558,10 +5563,8 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ currentportallist = &portallist; HWR_SetPortalState(GLPORTAL_SEARCH); - HWR_SetTransform(fpov); + reset_viewstate(fpov); - HWR_ClearSprites(); - HWR_ClearClipper(); if (rootportal) { HWR_PortalClipping(rootportal); @@ -5576,7 +5579,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ // note: if necessary, could sort the portals here? for (portal = portallist.base; portal; portal = portal->next) { - HWR_RenderPortal(portal, rootportal, fpov, player, stencil_level); + HWR_RenderPortal(portal, rootportal, fpov, stencil_level); } HWR_SetPortalState(GLPORTAL_INSIDE); // when portal walls are encountered in following bsp traversal, nothing should be drawn @@ -5586,9 +5589,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ // draw normal things in current frame in current incremented stencil buffer area HWR_SetStencilState(HWR_STENCIL_NORMAL, stencil_level); - HWR_SetTransform(fpov); - HWR_ClearSprites(); - HWR_ClearClipper(); + reset_viewstate(fpov); if constexpr (Type == RenderViewpointType::kPortal) { @@ -5602,6 +5603,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ if (HWR_IsWireframeMode()) GL_SetSpecialState(HWD_SET_WIREFRAME, 1); + // FIXME: perfstats does not account for portal rendering! ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; PS_START_TIMING(ps_bsptime); @@ -5613,8 +5615,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ if constexpr (Type == RenderViewpointType::kPortal) { - if (allow_portals && !rootportal && portallist.base && !skybox) // if portals have been drawn in the main view, then render skywalls differently - gl_collect_skywalls = true; + gl_collect_skywalls = (allow_portals && !rootportal && portallist.base && (!skyboxmo[0] || !cv_skybox.value)); // if portals have been drawn in the main view, then render skywalls differently // HAYA: Save the old portal state, and turn portals off while normally rendering the BSP tree. // This fixes specific effects not working, such as horizon lines. @@ -5646,6 +5647,9 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ if (LIKELY(cv_glbatching.value)) HWR_RenderBatches(true); + // Check for new console commands. + NetUpdate(); + if constexpr (Type == RenderViewpointType::kPortal) { if (skyWallVertexArraySize) // if there are skywalls to draw using the alternate method @@ -5654,13 +5658,13 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ HWR_DrawSkyWallList(); HWR_SkyWallList_Clear(); HWR_SetStencilState(HWR_STENCIL_NORMAL, 1); - drewsky = false; HWR_DrawSkyBackground(); HWR_SetStencilState(HWR_STENCIL_NORMAL, 0); - GL_ClearBuffer(false, false, true, NULL);// clear skywall markings from the stencil buffer - HWR_SetTransform(fpov);// restore transform + GL_ClearBuffer(false, false, true, NULL); // clear skywall markings from the stencil buffer + HWR_SetTransform(fpov); // restore transform } } + gl_collect_skywalls = false; ps_numsprites.value.i = gl_visspritecount; @@ -5681,6 +5685,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ ps_numdrawnodes.value.i = 0; ps_hw_nodesorttime.value.p = 0; ps_hw_nodedrawtime.value.p = 0; + HWR_RenderDrawNodes(); if (HWR_IsWireframeMode()) @@ -5691,26 +5696,22 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ }; extern "C" { - void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals) { - HWR_RenderViewpoint(rootportal, player, stencil_level, allow_portals); + void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, int stencil_level, boolean allow_portals) { + HWR_RenderViewpoint(rootportal, stencil_level, allow_portals); } } // ========================================================================== // Render the current frame. // ========================================================================== -static void HWR_RenderFrame(player_t *player, boolean skybox) +static void HWR_RenderFrame(boolean skybox, boolean drawsky) { - // check for new console commands. - NetUpdate(); - // Clear view, set viewport (glViewport), set perspective... HWR_ClearView(); // Draw the sky background. - HWR_DrawSkyBackground(); - if (skybox) - drewsky = true; + if (drawsky) + HWR_DrawSkyBackground(); current_bsp_culling_distance = 0; @@ -5726,26 +5727,17 @@ static void HWR_RenderFrame(player_t *player, boolean skybox) current_bsp_culling_distance = bsp_culling_distances[renderdist- 1]; } - portalclipline = NULL; - if (UNLIKELY(HWR_UsePortals())) - HWR_RenderViewpoint(NULL, player, 0, !skybox); - else - HWR_RenderViewpoint(NULL, player, 0, !skybox); - - // Unset transform and shader - GL_SetTransform(NULL); - GL_UnSetShader(); - - // Run post processor effects - if (!skybox) - HWR_DoPostProcessor(player); - // Check for new console commands. NetUpdate(); - // added by Hurdler for correct splitscreen - // moved here by hurdler so it works with the new near clipping plane - GL_GClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); + portalclipline = NULL; + if (UNLIKELY(HWR_UsePortals())) + HWR_RenderViewpoint(NULL, 0, !skybox); + else + HWR_RenderViewpoint(NULL, 0, !skybox); + + // Check for new console commands. + NetUpdate(); } // ========================================================================== @@ -5795,22 +5787,31 @@ void HWR_RenderPlayerView(void) if (viewssnum > 3) return; - player_t * player = &players[displayplayers[viewssnum]]; const boolean skybox = (skyboxmo[0] && cv_skybox.value); // True if there's a skybox object and skyboxes are on // Render the skybox if there is one. PS_START_TIMING(ps_skyboxtime); - drewsky = false; if (skybox) { R_SkyboxFrame(viewssnum); - HWR_RenderFrame(player, true); + HWR_RenderFrame(true, true); } PS_STOP_TIMING(ps_skyboxtime); R_SetupFrame(viewssnum, false); // This can stay false because it is only used to set viewsky in r_main.c, which isn't used here framecount++; // for timedemo - HWR_RenderFrame(player, false); + HWR_RenderFrame(false, !skybox); + + // Unset transform and shader + GL_SetTransform(NULL); + GL_UnSetShader(); + + // Run post processor effects + HWR_DoPostProcessor(); + + // added by Hurdler for correct splitscreen + // moved here by hurdler so it works with the new near clipping plane + GL_GClipRect(0, 0, vid.width, vid.height, NZCLIP_PLANE, FAR_ZCLIP_DEFAULT); } void HWR_LoadLevel(void) @@ -6064,37 +6065,40 @@ static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD #endif } -static void HWR_DoPostProcessor(player_t *player) +static void HWR_DoPostProcessor(void) { - GL_UnSetShader(); - // Armageddon Blast Flash! // Could this even be considered postprocessor? - if (!HWR_PalRenderFlashpal() && player->flashcount) + if (!HWR_PalRenderFlashpal()) { - static FOutVector v[4] = { - {-4.0f, 4.0f, 4.0f, 0.0f, 0.0f}, - { 4.0f, 4.0f, 4.0f, 0.0f, 0.0f}, // 4.0 because of the same reason as with the sky, just after the screen is cleared so near clipping plane is 3.99 - { 4.0f, -4.0f, 4.0f, 0.0f, 0.0f}, - {-4.0f, -4.0f, 4.0f, 0.0f, 0.0f} - }; + const player_t *player = &players[displayplayers[viewssnum]]; - FSurfaceInfo Surf; - - // This won't change if the flash palettes are changed unfortunately, but it works for its purpose - if (player->flashpal == PAL_NUKE) + if (player->flashcount) { - Surf.PolyColor.s.red = 0xff; - Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0x7F; // The nuke palette is kind of pink-ish + static FOutVector v[4] = { + {-4.0f, 4.0f, 4.0f, 0.0f, 0.0f}, + { 4.0f, 4.0f, 4.0f, 0.0f, 0.0f}, // 4.0 because of the same reason as with the sky, just after the screen is cleared so near clipping plane is 3.99 + { 4.0f, -4.0f, 4.0f, 0.0f, 0.0f}, + {-4.0f, -4.0f, 4.0f, 0.0f, 0.0f} + }; + + FSurfaceInfo Surf; + + // This won't change if the flash palettes are changed unfortunately, but it works for its purpose + if (player->flashpal == PAL_NUKE) + { + Surf.PolyColor.s.red = 0xff; + Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0x7F; // The nuke palette is kind of pink-ish + } + else + Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; + + Surf.PolyColor.s.alpha = 0xc0; // match software mode + + V_CubeApply(&Surf.PolyColor); + + GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); } - else - Surf.PolyColor.s.red = Surf.PolyColor.s.green = Surf.PolyColor.s.blue = 0xff; - - Surf.PolyColor.s.alpha = 0xc0; // match software mode - - V_CubeApply(&Surf.PolyColor); - - GL_DrawPolygon(&Surf, v, 4, PF_Modulated|PF_Translucent|PF_NoTexture|PF_NoDepthTest); } if (cv_glscreentextures.value != 2) // screen textures are needed for the rest of the effects diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 30906b611..8b5284acb 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -102,8 +102,7 @@ void HWR_SetViewSize(void); void HWR_AddCommands(void); void HWR_RenderPlayerView(void); -void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals); -void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_level, boolean allow_portals); +void HWR_RenderPortalViewpoint(gl_portal_t *rootportal, int stencil_level, boolean allow_portals); void HWR_ClearSkyDome(void); void HWR_BuildSkyDome(void); diff --git a/src/hardware/hw_portal.c b/src/hardware/hw_portal.c index 952bd0e66..e588adea1 100644 --- a/src/hardware/hw_portal.c +++ b/src/hardware/hw_portal.c @@ -157,7 +157,7 @@ static void HWR_RenderPortalSeg(gl_portal_t* portal, SINT8 state) } // Renders a single portal from the current viewpoint. -void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, player_t *player, int stencil_level) +void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, int stencil_level) { // draw portal seg to stencil buffer with increment HWR_SetTransform(fpov); @@ -170,7 +170,7 @@ void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float HWR_PortalFrame(portal); // call HWR_RenderViewpoint - HWR_RenderPortalViewpoint(portal, player, stencil_level + 1, true); + HWR_RenderPortalViewpoint(portal, stencil_level + 1, true); // return to current frame if (rootportal) diff --git a/src/hardware/hw_portal.h b/src/hardware/hw_portal.h index 23876281c..db494e5f3 100644 --- a/src/hardware/hw_portal.h +++ b/src/hardware/hw_portal.h @@ -75,7 +75,7 @@ void HWR_PortalClipping(gl_portal_t *portal); void HWR_Portal_Add2Lines(const INT32 line1, const INT32 line2, seg_t *seg); void HWR_PortalFrame(gl_portal_t* portal); -void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, player_t *player, int stencil_level); +void HWR_RenderPortal(gl_portal_t* portal, gl_portal_t* rootportal, const float fpov, int stencil_level); void HWR_FreePortalList(gl_portallist_t portallist); boolean HWR_PortalCheckPointSide(fixed_t x, fixed_t y);