From 075a0fe32625eacfc7f898d043b8130006a1f429 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 8 Mar 2022 03:47:36 +0900 Subject: [PATCH] [renderer] Clean up r_origin and modelorg So far, in gl and glsl, but viewposition is much clearer than r_origin (despite being the same thing), and modelorg is just confusing (I think it's the view position relative to the current model). --- include/QF/plugin/vid_render.h | 4 ---- libs/video/renderer/gl/gl_dyn_lights.c | 3 +-- libs/video/renderer/gl/gl_mod_alias.c | 2 -- libs/video/renderer/gl/gl_mod_sprite.c | 3 +-- libs/video/renderer/gl/gl_rmain.c | 17 ++++++----------- libs/video/renderer/gl/gl_rsurf.c | 19 +++++++++---------- libs/video/renderer/gl/gl_sky_clip.c | 3 ++- libs/video/renderer/glsl/glsl_bsp.c | 7 ++++--- libs/video/renderer/glsl/glsl_main.c | 5 ++--- libs/video/renderer/glsl/glsl_sprite.c | 3 +-- libs/video/renderer/r_graph.c | 2 +- libs/video/renderer/r_main.c | 3 ++- libs/video/renderer/vid_common.c | 1 - 13 files changed, 29 insertions(+), 43 deletions(-) diff --git a/include/QF/plugin/vid_render.h b/include/QF/plugin/vid_render.h index 0def162d1..c3dbc62e6 100644 --- a/include/QF/plugin/vid_render.h +++ b/include/QF/plugin/vid_render.h @@ -135,10 +135,6 @@ typedef struct vid_render_data_s { double frametime; double realtime; lightstyle_t *lightstyle; - vec_t *origin; - vec_t *vpn; - vec_t *vright; - vec_t *vup; } vid_render_data_t; #endif // __QF_plugin_vid_render_h diff --git a/libs/video/renderer/gl/gl_dyn_lights.c b/libs/video/renderer/gl/gl_dyn_lights.c index a430f95bc..d29737d2a 100644 --- a/libs/video/renderer/gl/gl_dyn_lights.c +++ b/libs/video/renderer/gl/gl_dyn_lights.c @@ -81,7 +81,7 @@ R_RenderDlight (dlight_t *light) bub_cos = gl_bubble_costable; rad = light->radius * 0.35; - VectorSubtract (light->origin, r_origin, v); + VectorSubtract (r_refdef.viewposition, light->origin, v); if (VectorLength (v) < rad) // view is inside the dlight return; @@ -89,7 +89,6 @@ R_RenderDlight (dlight_t *light) qfglColor4fv (light->color); - VectorSubtract (r_origin, light->origin, v); VectorNormalize (v); for (i = 0; i < 3; i++) diff --git a/libs/video/renderer/gl/gl_mod_alias.c b/libs/video/renderer/gl/gl_mod_alias.c index e968586cb..7934b1332 100644 --- a/libs/video/renderer/gl/gl_mod_alias.c +++ b/libs/video/renderer/gl/gl_mod_alias.c @@ -440,8 +440,6 @@ gl_R_DrawAliasModel (entity_t *e) return; } - VectorSubtract (r_origin, origin, modelorg); - gl_modelalpha = e->renderer.colormod[3]; is_fullbright = (model->fullbright || e->renderer.fullbright); diff --git a/libs/video/renderer/gl/gl_mod_sprite.c b/libs/video/renderer/gl/gl_mod_sprite.c index 583f518dc..fd5599857 100644 --- a/libs/video/renderer/gl/gl_mod_sprite.c +++ b/libs/video/renderer/gl/gl_mod_sprite.c @@ -68,8 +68,7 @@ R_DrawSpriteModel_f (entity_t *e) mspriteframe_t *frame; origin = Transform_GetWorldPosition (e->transform); - VectorCopy (r_origin, cameravec); - cameravec -= origin; + cameravec = r_refdef.viewposition - origin; // don't bother culling, it's just a single polygon without a surface cache frame = R_GetSpriteFrame (sprite, &e->animation); diff --git a/libs/video/renderer/gl/gl_rmain.c b/libs/video/renderer/gl/gl_rmain.c index 554d13e46..4b6806f4b 100644 --- a/libs/video/renderer/gl/gl_rmain.c +++ b/libs/video/renderer/gl/gl_rmain.c @@ -331,20 +331,15 @@ gl_R_SetupFrame (void) EntQueue_Clear (r_ent_queue); r_framecount++; - // build the transformation matrix for the given view angles - VectorCopy (r_refdef.viewposition, r_origin); - - VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); - VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, -1, 0, 0 }), vright); - VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, 0, 1, 0 }), vup); - + vec4f_t position = r_refdef.viewposition; + vec4f_t rotation = r_refdef.viewrotation; + VectorCopy (qvmulf (rotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); + VectorCopy (qvmulf (rotation, (vec4f_t) { 0, -1, 0, 0 }), vright); + VectorCopy (qvmulf (rotation, (vec4f_t) { 0, 0, 1, 0 }), vup); R_SetFrustum (); - // current viewleaf - r_viewleaf = Mod_PointInLeaf (r_origin, r_worldentity.renderer.model); - - r_cache_thrash = false; + r_viewleaf = Mod_PointInLeaf (&position[0], r_worldentity.renderer.model); } static void diff --git a/libs/video/renderer/gl/gl_rsurf.c b/libs/video/renderer/gl/gl_rsurf.c index 53a0b5142..280d5d626 100644 --- a/libs/video/renderer/gl/gl_rsurf.c +++ b/libs/video/renderer/gl/gl_rsurf.c @@ -565,13 +565,13 @@ gl_R_DrawBrushModel (entity_t *e) return; } - VectorSubtract (r_refdef.viewposition, worldMatrix[3], modelorg); + vec4f_t relviewpos = r_refdef.viewposition - worldMatrix[3]; if (rotated) { - vec4f_t temp = { modelorg[0], modelorg[1], modelorg[2], 0 }; + vec4f_t temp = relviewpos; - modelorg[0] = dotf (temp, worldMatrix[0])[0]; - modelorg[1] = dotf (temp, worldMatrix[1])[0]; - modelorg[2] = dotf (temp, worldMatrix[2])[0]; + relviewpos[0] = dotf (temp, worldMatrix[0])[0]; + relviewpos[1] = dotf (temp, worldMatrix[1])[0]; + relviewpos[2] = dotf (temp, worldMatrix[2])[0]; } // calculate dynamic lighting for bmodel if it's not an instanced model @@ -601,7 +601,7 @@ gl_R_DrawBrushModel (entity_t *e) // find which side of the node we are on plane_t *plane = surf->plane; - dot = DotProduct (modelorg, plane->normal) - plane->dist; + dot = DotProduct (relviewpos, plane->normal) - plane->dist; // draw the polygon if (((surf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) || @@ -626,10 +626,11 @@ get_side (mnode_t *node) { // find which side of the node we are on plane_t *plane = node->plane; + vec4f_t org = r_refdef.viewposition; if (plane->type < 3) - return (modelorg[plane->type] - plane->dist) < 0; - return (DotProduct (modelorg, plane->normal) - plane->dist) < 0; + return (org[plane->type] - plane->dist) < 0; + return (DotProduct (org, plane->normal) - plane->dist) < 0; } static inline void @@ -728,8 +729,6 @@ gl_R_DrawWorld (void) memset (&worldent, 0, sizeof (worldent)); worldent.renderer.model = r_worldentity.renderer.model; - VectorCopy (r_refdef.viewposition, modelorg); - sky_chain = 0; sky_chain_tail = &sky_chain; if (!gl_sky_clip->int_val) { diff --git a/libs/video/renderer/gl/gl_sky_clip.c b/libs/video/renderer/gl/gl_sky_clip.c index 0ac4d2dde..89f521ebd 100644 --- a/libs/video/renderer/gl/gl_sky_clip.c +++ b/libs/video/renderer/gl/gl_sky_clip.c @@ -645,12 +645,13 @@ EmitSkyPolys (float speedscale, const instsurf_t *sc) glpoly_t *p; vec3_t dir; msurface_t *surf = sc->surface; + vec4f_t origin = r_refdef.viewposition; //FIXME transform/color for (p = surf->polys; p; p = p->next) { qfglBegin (GL_POLYGON); for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE) { - VectorSubtract (v, r_origin, dir); + VectorSubtract (v, origin, dir); dir[2] *= 3.0; // flatten the sphere length = DotProduct (dir, dir); diff --git a/libs/video/renderer/glsl/glsl_bsp.c b/libs/video/renderer/glsl/glsl_bsp.c index 82fe7ca39..40e7d5911 100644 --- a/libs/video/renderer/glsl/glsl_bsp.c +++ b/libs/video/renderer/glsl/glsl_bsp.c @@ -744,10 +744,11 @@ get_side (mnode_t *node) { // find the node side on which we are plane_t *plane = node->plane; + vec4f_t org = r_refdef.viewposition; if (plane->type < 3) - return (r_origin[plane->type] - plane->dist) < 0; - return (DotProduct (r_origin, plane->normal) - plane->dist) < 0; + return (org[plane->type] - plane->dist) < 0; + return (DotProduct (org, plane->normal) - plane->dist) < 0; } static inline void @@ -1000,7 +1001,7 @@ spin (mat4_t mat) QuatBlend (sky_rotation[0], sky_rotation[1], blend, q); QuatMult (sky_fix, q, q); Mat4Identity (mat); - VectorNegate (r_origin, mat + 12); + VectorNegate (r_refdef.viewposition, mat + 12); QuatToMatrix (q, m, 1, 1); Mat4Mult (m, mat, mat); } diff --git a/libs/video/renderer/glsl/glsl_main.c b/libs/video/renderer/glsl/glsl_main.c index f4a0bfc88..e1313ed1c 100644 --- a/libs/video/renderer/glsl/glsl_main.c +++ b/libs/video/renderer/glsl/glsl_main.c @@ -100,16 +100,15 @@ glsl_R_SetupFrame (void) EntQueue_Clear (r_ent_queue); r_framecount++; - VectorCopy (r_refdef.viewposition, r_origin); + vec4f_t position = r_refdef.viewposition; vec4f_t rotation = r_refdef.viewrotation; VectorCopy (qvmulf (rotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); VectorCopy (qvmulf (rotation, (vec4f_t) { 0,-1, 0, 0 }), vright); VectorCopy (qvmulf (rotation, (vec4f_t) { 0, 0, 1, 0 }), vup); - R_SetFrustum (); - r_viewleaf = Mod_PointInLeaf (r_origin, r_worldentity.renderer.model); + r_viewleaf = Mod_PointInLeaf (&position[0], r_worldentity.renderer.model); } static void diff --git a/libs/video/renderer/glsl/glsl_sprite.c b/libs/video/renderer/glsl/glsl_sprite.c index de1d00185..61ab28937 100644 --- a/libs/video/renderer/glsl/glsl_sprite.c +++ b/libs/video/renderer/glsl/glsl_sprite.c @@ -229,8 +229,7 @@ glsl_R_DrawSprite (entity_t *ent) }; vec4f_t origin = Transform_GetWorldPosition (ent->transform); - VectorCopy (r_origin, cameravec); - cameravec -= origin; + cameravec = r_refdef.viewposition - origin; if (!R_BillboardFrame (ent, sprite->type, &cameravec[0], &svup[0], &svright[0], &svpn[0])) { diff --git a/libs/video/renderer/r_graph.c b/libs/video/renderer/r_graph.c index 4ca80c262..81c92169c 100644 --- a/libs/video/renderer/r_graph.c +++ b/libs/video/renderer/r_graph.c @@ -95,7 +95,7 @@ R_ZGraph (void) else w = 256; - height[r_framecount & 255] = ((int) r_origin[2]) & 31; + height[r_framecount & 255] = ((int) r_refdef.viewposition[2]) & 31; x = 0; vr_funcs->R_LineGraph (x, r_refdef.vrect.height - 2, height, diff --git a/libs/video/renderer/r_main.c b/libs/video/renderer/r_main.c index 4bb57c720..dd9860c4c 100644 --- a/libs/video/renderer/r_main.c +++ b/libs/video/renderer/r_main.c @@ -115,9 +115,10 @@ R_SetFrustum (void) RotatePointAroundVector (frustum[3].normal, vright, vpn, -(90 - r_refdef.fov_y / 2)); + vec4f_t origin = r_refdef.viewposition; for (i = 0; i < 4; i++) { frustum[i].type = PLANE_ANYZ; - frustum[i].dist = DotProduct (r_origin, frustum[i].normal); + frustum[i].dist = DotProduct (origin, frustum[i].normal); frustum[i].signbits = SignbitsForPlane (&frustum[i]); } } diff --git a/libs/video/renderer/vid_common.c b/libs/video/renderer/vid_common.c index 149cf85fb..004410c58 100644 --- a/libs/video/renderer/vid_common.c +++ b/libs/video/renderer/vid_common.c @@ -51,7 +51,6 @@ vid_render_data_t vid_render_data = { 0, 0.0, 0.0, 0, - r_origin, vpn, vright, vup }; vid_render_funcs_t *vid_render_funcs;