From 513984d7fd15f4a07edc8f10068f9e78b817400c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Apr 2026 13:29:58 +0500 Subject: [PATCH] ref: soft: save original viewpass and access viewport and fov through it --- ref/soft/r_local.h | 5 ++--- ref/soft/r_main.c | 16 ++++------------ ref/soft/r_misc.c | 12 ++++++------ ref/soft/r_sprite.c | 4 ++-- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index dc4cba8d..c8771052 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -122,18 +122,17 @@ extern viddef_t vid; typedef struct { + ref_viewpass_t rvp; + qboolean drawWorld; // ignore world for drawing PlayerModel qboolean isSkyVisible; // sky is visible qboolean onlyClientDraw; // disabled by client request qboolean drawOrtho; // draw world as orthogonal projection - float fov_x, fov_y; // current view fov - cl_entity_t *currententity; model_t *currentmodel; cl_entity_t *currentbeam; // same as above but for beams - int viewport[4]; // gl_frustum_t frustum; mleaf_t *viewleaf; diff --git a/ref/soft/r_main.c b/ref/soft/r_main.c index 77dfe52e..18d4bd66 100644 --- a/ref/soft/r_main.c +++ b/ref/soft/r_main.c @@ -423,10 +423,10 @@ static void R_SetupProjectionMatrix( matrix4x4 m ) zNear = 4.0f; zFar = Q_max( 256.0f, RI.farClip ); - yMax = zNear * tan( RI.fov_y * M_PI_F / 360.0f ); + yMax = zNear * tan( RI.rvp.fov_y * M_PI_F / 360.0f ); yMin = -yMax; - xMax = zNear * tan( RI.fov_x * M_PI_F / 360.0f ); + xMax = zNear * tan( RI.rvp.fov_x * M_PI_F / 360.0f ); xMin = -xMax; Matrix4x4_CreateProjection( m, xMax, xMin, yMax, yMin, zNear, zFar ); @@ -1157,6 +1157,8 @@ set initial params for renderer */ void R_SetupRefParams( const ref_viewpass_t *rvp ) { + RI.rvp = *rvp; + RI.drawWorld = FBitSet( rvp->flags, RF_DRAW_WORLD ); RI.onlyClientDraw = FBitSet( rvp->flags, RF_ONLY_CLIENTDRAW ); @@ -1165,16 +1167,6 @@ void R_SetupRefParams( const ref_viewpass_t *rvp ) else RI.drawOrtho = false; - // setup viewport - RI.viewport[0] = rvp->viewport[0]; - RI.viewport[1] = rvp->viewport[1]; - RI.viewport[2] = rvp->viewport[2]; - RI.viewport[3] = rvp->viewport[3]; - - // calc FOV - RI.fov_x = rvp->fov_x; - RI.fov_y = rvp->fov_y; - VectorCopy( rvp->vieworigin, RI.vieworg ); VectorCopy( rvp->viewangles, RI.viewangles ); VectorCopy( rvp->vieworigin, RI.pvsorigin ); diff --git a/ref/soft/r_misc.c b/ref/soft/r_misc.c index 7af67152..7aa1debc 100644 --- a/ref/soft/r_misc.c +++ b/ref/soft/r_misc.c @@ -184,8 +184,8 @@ static void R_ViewChanged( vrect_t *vr ) RI.vrect = *vr; - horizontalFieldOfView = 2 * tan((float)RI.fov_x / 360.0f * M_PI_F ); - verticalFieldOfView = 2 * tan((float)RI.fov_y / 360.0f * M_PI_F ); + horizontalFieldOfView = 2 * tan((float)RI.rvp.fov_x / 360.0f * M_PI_F ); + verticalFieldOfView = 2 * tan((float)RI.rvp.fov_y / 360.0f * M_PI_F ); RI.fvrectx = (float)RI.vrect.x; RI.fvrectx_adj = (float)RI.vrect.x - 0.5f; @@ -307,10 +307,10 @@ void R_SetupFrameQ( void ) vrect.y = 0;//r_newrefdef.y; vrect.width = gpGlobals->width; vrect.height = gpGlobals->height;*/ - vrect.x = RI.viewport[0]; - vrect.y = RI.viewport[1]; - vrect.width = RI.viewport[2]; - vrect.height = RI.viewport[3]; + vrect.x = RI.rvp.viewport[0]; + vrect.y = RI.rvp.viewport[1]; + vrect.width = RI.rvp.viewport[2]; + vrect.height = RI.rvp.viewport[3]; d_viewbuffer = (void *)vid.buffer; r_screenwidth = vid.rowbytes; diff --git a/ref/soft/r_sprite.c b/ref/soft/r_sprite.c index d74df2f4..dc04a868 100644 --- a/ref/soft/r_sprite.c +++ b/ref/soft/r_sprite.c @@ -98,9 +98,9 @@ static qboolean R_SpriteOccluded( cl_entity_t *e, vec3_t origin, float *pscale ) TriWorldToScreen( origin, v ); - if( v[0] < RI.viewport[0] || v[0] > RI.viewport[0] + RI.viewport[2] ) + if( v[0] < RI.rvp.viewport[0] || v[0] > RI.rvp.viewport[0] + RI.rvp.viewport[2] ) return true; // do scissor - if( v[1] < RI.viewport[1] || v[1] > RI.viewport[1] + RI.viewport[3] ) + if( v[1] < RI.rvp.viewport[1] || v[1] > RI.rvp.viewport[1] + RI.rvp.viewport[3] ) return true; // do scissor blend = R_SpriteGlowBlend( origin, e->curstate.rendermode, e->curstate.renderfx, pscale );