From 385b95f87c7ca70a133ff604f55f68ae046e0e4c Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 2 Jul 2026 18:09:20 +0200 Subject: [PATCH] use viewsin and viewcos for spherefrustum checks in gl dont need all those yaw vars, since they effectively map to gl_viewsin and -gl_viewcos respectively while those are less accurate due to being fixed point, there appears to be no visual issues from this and seems to even slightly improve performance in some cases --- src/hardware/hw_batching.c | 1 + src/hardware/hw_main.cpp | 30 +++++++++--------------------- src/hardware/r_opengl/r_opengl.c | 6 +++--- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/hardware/hw_batching.c b/src/hardware/hw_batching.c index 8bf7f7375..9b1699029 100644 --- a/src/hardware/hw_batching.c +++ b/src/hardware/hw_batching.c @@ -183,6 +183,7 @@ static int comparePolygons(const void *p1, const void *p2) UINT32 downloaded1 = poly1->texture ? poly1->texture->downloaded : 0; // there should be a opengl texture name here, usable for comparisons UINT32 downloaded2 = poly2->texture ? poly2->texture->downloaded : 0; + diff64 = downloaded1 - downloaded2; if (diff64 != 0) return diff64; diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index c224f8af6..01433edd0 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -84,11 +84,6 @@ float gl_viewsin = 0.0f, gl_viewcos = 0.0f; static float gl_viewludsin, gl_viewludcos; static angle_t gl_aimingangle; -static float yaw = 0.0f; -static float inv_yaw = 0.0f; -static float cos_inv_yaw = 0.0f; -static float sin_inv_yaw = 0.0f; - static constexpr float deg2radians = (M_PIf / 180.0f); seg_t *gl_curline = NULL; @@ -4803,9 +4798,9 @@ static void HWR_ProjectSprite(mobj_t *thing) // if the sprite is out of our view, dont need to draw it X) if (!gld_SphereInFrustum( - (FixedToFloat(interp.x)) + cos_inv_yaw * (x1 + x2) / 2.0f, + (FixedToFloat(interp.x)) + gl_viewsin * (x1 + x2) / 2.0f, FixedToFloat(interp.z) + (y1 + y2) / 2.0f, - FixedToFloat(interp.y) - sin_inv_yaw * (x1 + x2) / 2.0f, + FixedToFloat(interp.y) - (-gl_viewcos) * (x1 + x2) / 2.0f, //1.5 == sqrt(2) + small delta for MF_FOREGROUND std::max(FixedToFloat(spr_width) * spritexscale, FixedToFloat(spr_height) * spriteyscale) / 2.0f * 1.5f)) @@ -5023,9 +5018,9 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) y2 *= thing_scale; if (!gld_SphereInFrustum( - (FixedToFloat(interp.x)) + cos_inv_yaw * (x1 + x2) / 2.0f, + (FixedToFloat(interp.x)) + gl_viewsin * (x1 + x2) / 2.0f, FixedToFloat(interp.z) + (y1 + y2) / 2.0f, - FixedToFloat(interp.y) - sin_inv_yaw * (x1 + x2) / 2.0f, + FixedToFloat(interp.y) - (-gl_viewcos) * (x1 + x2) / 2.0f, //1.5 == sqrt(2) + small delta for MF_FOREGROUND std::max(FixedToFloat(spr_width) * thing_scale, FixedToFloat(spr_height) * thing_scale) / 2.0f * 1.5f)) @@ -5155,24 +5150,22 @@ void HWR_BuildSkyDome(void) int c, r; signed char yflip; static constexpr int row_count = 4; - int col_count = 4; + static constexpr int col_count = (4 * 16); float delta; gl_sky_t *sky = &gl_sky; gl_skyvertex_t *vertex_p; const texture_t *texture = textures[texturetranslation[skytexture]]; - col_count *= 16; - if ((sky->columns != col_count) || (sky->rows != row_count)) HWR_ClearSkyDome(); sky->columns = col_count; sky->rows = row_count; - sky->vertex_count = 2 * sky->rows * (sky->columns * 2 + 2) + sky->columns * 2; + sky->vertex_count = 2 * row_count * (col_count * 2 + 2) + col_count * 2; if (!sky->loops) - sky->loops = static_cast(malloc((sky->rows * 2 + 2) * sizeof(sky->loops[0]))); + sky->loops = static_cast(malloc((row_count * 2 + 2) * sizeof(sky->loops[0]))); // create vertex array if (!sky->data) @@ -5436,12 +5429,6 @@ void HWR_SetTransform(float fpov) HWR_SetTransformAiming(&atransform); atransform.angley = static_cast(viewangle >> ANGLETOFINESHIFT)*(FINEDEGREE); - yaw = 270.0f - atransform.angley; - inv_yaw = 180.0f - yaw; - const float inv_yaw_radians = inv_yaw * deg2radians; - cos_inv_yaw = cosf(inv_yaw_radians); - sin_inv_yaw = sinf(inv_yaw_radians); - // only needed for sprite billboarding if (cv_glspritebillboarding.value && !cv_glshearing.value) { @@ -5579,7 +5566,8 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool if constexpr (Type == RenderViewpointType::kPortal) { - 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 + // if portals have been drawn in the main view, then render skywalls differently + gl_collect_skywalls = (allow_portals && !rootportal && portallist.base && (!skyboxmo[0] || !cv_skybox.value)); // 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. diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index adc355df9..5eb0b9f9c 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2503,7 +2503,7 @@ void GL_RenderSkyDome(gl_sky_t *sky) GL_Shader_SetUniforms(NULL, NULL, NULL, NULL); // Build the sky dome! Yes! - if (sky->rebuild) + if (sky->rebuild || !sky->vbo) { // delete VBO when already exists if (sky->vbo) @@ -3221,8 +3221,8 @@ void GL_SetTransform(FTransform *stransform) { float dy = stransform->viewaiming * 2; - if (stransform->fliptype == TRANSFORM_FLIP - || stransform->fliptype == TRANSFORM_MIRRORFLIP) + if (stransform->fliptype == TRANSFORM_FLIP || + stransform->fliptype == TRANSFORM_MIRRORFLIP) dy *= -1.0f; pglTranslatef(0.0f, -dy/BASEVIDHEIGHT, 0.0f);