diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index d7f1128ad..611efdff4 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -236,7 +236,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) // This function organizes the geometry collected by HWR_ProcessPolygon calls into batches and uses // the rendering backend to draw them. -void HWR_RenderBatches(void) +void HWR_RenderBatches(boolean sort) { int finalVertexWritePos = 0; // position in finalVertexArray int finalIndexWritePos = 0; // position in finalVertexIndexArray @@ -287,10 +287,15 @@ void HWR_RenderBatches(void) polygonArraySorted[i] = &polygonArray[i]; } - // sort polygons - PS_START_TIMING(ps_hw_batchsorttime); - qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), (useshader ? comparePolygons : comparePolygonsNoShaders)); - PS_STOP_TIMING(ps_hw_batchsorttime); + if (sort) + { + // sort polygons + PS_START_TIMING(ps_hw_batchsorttime); + qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), (useshader ? comparePolygons : comparePolygonsNoShaders)); + PS_STOP_TIMING(ps_hw_batchsorttime); + } + else + ps_hw_batchsorttime.value.p = 0; // sort order // 1. shader @@ -299,7 +304,9 @@ void HWR_RenderBatches(void) // 4. colors + light level // not sure about what order of the last 2 should be, or if it even matters - PS_START_TIMING(ps_hw_batchdrawtime); + // dont overwrite this on consecutive calls + if (!sort) + PS_START_TIMING(ps_hw_batchdrawtime); currentShader = polygonArraySorted[0]->shader; currentTexture = polygonArraySorted[0]->texture; @@ -494,7 +501,8 @@ void HWR_RenderBatches(void) polygonArraySize = 0; unsortedVertexArraySize = 0; - PS_STOP_TIMING(ps_hw_batchdrawtime); + if (!sort) + PS_STOP_TIMING(ps_hw_batchdrawtime); } #endif // HWRENDER diff --git a/src/hardware/hw_batching.h b/src/hardware/hw_batching.h index 984f0d159..adfc2ad10 100644 --- a/src/hardware/hw_batching.h +++ b/src/hardware/hw_batching.h @@ -37,7 +37,7 @@ typedef struct void HWR_StartBatching(void); void HWR_SetCurrentTexture(GLMipmap_t *texture); void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial); -void HWR_RenderBatches(void); +void HWR_RenderBatches(boolean sort); #ifdef __cplusplus } // extern "C" diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 3eb680413..8b6b2abfe 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -4383,6 +4383,9 @@ static void HWR_RenderDrawNodes(void) // Okay! Let's draw it all! Woo! GL_SetTransform(&atransform); + if (LIKELY(cv_glbatching.value)) + HWR_StartBatching(); + for (i = 0; i < numdrawnodes; i++) { gl_drawnode_t *drawnode = &drawnodes[sortindex[i]]; @@ -4434,6 +4437,9 @@ static void HWR_RenderDrawNodes(void) } } + if (LIKELY(cv_glbatching.value)) + HWR_RenderBatches(false); + PS_STOP_TIMING(ps_hw_nodedrawtime); drawnodes.clear(); // clear so our size is 0 again! @@ -5390,6 +5396,7 @@ void HWR_SetTransform(float fpov) void HWR_ClearClipper(void) { const angle_t a1 = gld_FrustumAngle(gl_aimingangle); + gld_clipper_Clear(); gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); #ifdef HAVE_SPHEREFRUSTRUM @@ -5472,7 +5479,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ { if (allow_portals && rootportal) { - HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search + HWR_PortalFrame(rootportal); // for portalclipsector, it could have gone null from search HWR_PortalClipping(rootportal); } } @@ -5522,7 +5529,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ PS_STOP_TIMING(ps_bsptime); if (LIKELY(cv_glbatching.value)) - HWR_RenderBatches(); + HWR_RenderBatches(true); if constexpr (Type == RenderViewpointType::kPortal) { @@ -5546,10 +5553,14 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_ HWR_SortVisSprites(); PS_STOP_TIMING(ps_hw_spritesorttime); PS_START_TIMING(ps_hw_spritedrawtime); + if (LIKELY(cv_glbatching.value)) + HWR_StartBatching(); if (UNLIKELY(cv_glmdls.value)) HWR_DrawSprites(); else HWR_DrawSprites(); + if (LIKELY(cv_glbatching.value)) + HWR_RenderBatches(false); PS_STOP_TIMING(ps_hw_spritedrawtime); ps_numdrawnodes.value.i = 0;