From a09bde5364067255384840b665bf0534df3239ff Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 19 Nov 2024 17:28:36 +0100 Subject: [PATCH] use actual view to clip segs in ogl instead of calculated fov thx dsda-doom! basically better performance in alot of cases and technically should fix any future issues if someone plays on weird aspect ratios --- src/hardware/hw_clip.c | 23 ++++++++++------------- src/hardware/hw_clip.h | 2 +- src/hardware/hw_main.c | 31 ++++++++++++++----------------- src/hardware/r_opengl/r_opengl.c | 2 +- src/hardware/r_opengl/r_opengl.h | 2 ++ 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 54883433b..c09a4e301 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -79,12 +79,6 @@ #include "r_opengl/r_opengl.h" #include "../r_main.h" // for cv_fov -#ifdef HAVE_SPHEREFRUSTRUM -static GLdouble viewMatrix[16]; -static GLdouble projMatrix[16]; -float frustum[6][4]; -#endif - typedef struct clipnode_s { struct clipnode_s *prev, *next; @@ -322,16 +316,14 @@ void gld_clipper_Clear(void) #define RMUL (1.6f/1.333333f) -angle_t gld_FrustumAngle(float render_fov, angle_t tiltangle) +angle_t gld_FrustumAngle(angle_t tiltangle) { + double clipfov; double floatangle; angle_t a1; float tilt = (float)fabs(((double)(int)tiltangle) / ANG1); - float render_fovratio = (float)BASEVIDWIDTH / (float)BASEVIDHEIGHT; // SRB2CBTODO: NEWCLIPTODO: Is this right? - float render_multiplier = 64.0f / render_fovratio / RMUL; - if (tilt > 90.0f) tilt = 90.0f; @@ -341,10 +333,11 @@ angle_t gld_FrustumAngle(float render_fov, angle_t tiltangle) // ok, this is a gross hack that barely works... // but at least it doesn't overestimate too much... - floatangle = 2.0f + (45.0f + (tilt / 1.9f)) * (float)render_fov * 48.0f / render_multiplier / 90.0f; - a1 = ANG1 * (int)floatangle; - if (a1 >= ANGLE_180) + clipfov = atan(1 / projMatrix[0]) * 360 / M_PI; // use the actual view of the scene + floatangle = 2.0f + (45.0f + (tilt / 1.9f)) * clipfov / 90.0f; + if (floatangle >= ANGLE_180) return 0xffffffff; + a1 = (angle_t)(ANG1 * (int)floatangle); return a1; } @@ -357,6 +350,10 @@ angle_t gld_FrustumAngle(float render_fov, angle_t tiltangle) // gld_FrustrumSetup // +static GLdouble viewMatrix[16]; +static GLdouble projMatrix[16]; +float frustum[6][4]; + #define CALCMATRIX(a, b, c, d, e, f, g, h)\ (float)(viewMatrix[a] * projMatrix[b] + \ viewMatrix[c] * projMatrix[d] + \ diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index 33c6d1185..58d788c90 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -24,7 +24,7 @@ extern "C" { boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); void gld_clipper_Clear(void); -angle_t gld_FrustumAngle(float render_fov, angle_t tiltangle); +angle_t gld_FrustumAngle(angle_t tiltangle); #ifdef HAVE_SPHEREFRUSTRUM void gld_FrustrumSetup(void); boolean gld_SphereInFrustum(float x, float y, float z, float radius); diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f260e0bdc..fff97df24 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5901,6 +5901,16 @@ static void HWR_SetShaderState(void) HWD.pfnSetShader(SHADER_DEFAULT); } +static void HWR_ClearClipper(void) +{ + angle_t a1 = gld_FrustumAngle(gl_aimingangle); + gld_clipper_Clear(); + gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); +#ifdef HAVE_SPHEREFRUSTRUM + gld_FrustrumSetup(); +#endif +} + // ========================================================================== // Same as rendering the player view, but from the skybox object // ========================================================================== @@ -5985,19 +5995,12 @@ void HWR_RenderSkyboxView(player_t *player) drawcount = 0; - { - angle_t a1 = gld_FrustumAngle(fpov, gl_aimingangle); - gld_clipper_Clear(); - gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); -#ifdef HAVE_SPHEREFRUSTRUM - gld_FrustrumSetup(); -#endif - } - //04/01/2000: Hurdler: added for T&L // Actually it only works on Walls and Planes HWD.pfnSetTransform(&atransform); + HWR_ClearClipper(); + // Reset the shader state. HWR_SetShaderState(); @@ -6167,18 +6170,12 @@ void HWR_RenderPlayerView(void) drawcount = 0; - { - angle_t a1 = gld_FrustumAngle(fpov, gl_aimingangle); - gld_clipper_Clear(); - gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); -#ifdef HAVE_SPHEREFRUSTRUM - gld_FrustrumSetup(); -#endif - } //04/01/2000: Hurdler: added for T&L // Actually it only works on Walls and Planes HWD.pfnSetTransform(&atransform); + HWR_ClearClipper(); + // Reset the shader state. HWR_SetShaderState(); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 1c43606e9..7bd7988a7 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -86,7 +86,7 @@ const GLubyte *gl_extensions = NULL; //Hurdler: 04/10/2000: added for the kick ass coronas as Boris wanted;-) static GLfloat modelMatrix[16]; -static GLfloat projMatrix[16]; +GLfloat projMatrix[16]; static GLint viewport[4]; // Sryder: NextTexAvail is broken for these because palette changes or changes to the texture filter or antialiasing diff --git a/src/hardware/r_opengl/r_opengl.h b/src/hardware/r_opengl/r_opengl.h index e600ca247..24586b4a2 100644 --- a/src/hardware/r_opengl/r_opengl.h +++ b/src/hardware/r_opengl/r_opengl.h @@ -73,6 +73,8 @@ extern "C" { extern FILE *gllogstream; #endif +extern GLfloat projMatrix[16]; + // ========================================================================== // PROTOS // ==========================================================================