From 65af7fb4a463963a03a887d0cb6018e77498fc6a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 19 Mar 2022 12:33:12 +0900 Subject: [PATCH] [mathlib] Remove frustum global It should never have been there and is now in the refdef (not its final home: it should probably be part of the camera). --- include/QF/mathlib.h | 11 +++++------ include/QF/render.h | 1 + include/r_local.h | 3 ++- libs/util/mathlib.c | 4 +--- libs/video/renderer/gl/gl_mod_alias.c | 2 +- libs/video/renderer/gl/gl_rsurf.c | 6 +++--- libs/video/renderer/glsl/glsl_bsp.c | 6 +++--- libs/video/renderer/r_light.c | 2 +- libs/video/renderer/r_main.c | 3 ++- libs/video/renderer/r_screen.c | 3 ++- libs/video/renderer/vulkan/vulkan_bsp.c | 6 +++--- 11 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/QF/mathlib.h b/include/QF/mathlib.h index ef65f6aa8..a0e7b8103 100644 --- a/include/QF/mathlib.h +++ b/include/QF/mathlib.h @@ -141,7 +141,7 @@ void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, void AngleQuat (const vec3_t angles, quat_t q); void VectorVectors (const vec3_t forward, vec3_t right, vec3_t up); int BoxOnPlaneSide (const vec3_t emins, const vec3_t emaxs, - struct plane_s *plane) __attribute__((pure)); + const plane_t *plane) __attribute__((pure)); float anglemod (float a) __attribute__((const)); void RotatePointAroundVector (vec3_t dst, const vec3_t axis, @@ -175,9 +175,8 @@ void RotatePointAroundVector (vec3_t dst, const vec3_t axis, VectorNegate ((sp)->normal, (dp)->normal); \ } while (0) -extern plane_t * const frustum; -GNU89INLINE inline qboolean R_CullBox (const vec3_t mins, const vec3_t maxs) __attribute__((pure)); -GNU89INLINE inline qboolean R_CullSphere (const vec3_t origin, const float radius); +GNU89INLINE inline qboolean R_CullBox (const plane_t *frustum, const vec3_t mins, const vec3_t maxs) __attribute__((pure)); +GNU89INLINE inline qboolean R_CullSphere (const plane_t *frustum, const vec3_t origin, const float radius); #ifndef IMPLEMENT_R_Cull GNU89INLINE inline @@ -185,7 +184,7 @@ GNU89INLINE inline VISIBLE #endif qboolean -R_CullBox (const vec3_t mins, const vec3_t maxs) +R_CullBox (const plane_t *frustum, const vec3_t mins, const vec3_t maxs) { int i; @@ -203,7 +202,7 @@ GNU89INLINE inline VISIBLE #endif qboolean -R_CullSphere (const vec3_t origin, const float radius) +R_CullSphere (const plane_t *frustum, const vec3_t origin, const float radius) { int i; float r; diff --git a/include/QF/render.h b/include/QF/render.h index 61bde87db..bffec3a85 100644 --- a/include/QF/render.h +++ b/include/QF/render.h @@ -214,6 +214,7 @@ typedef struct { float yOrigin; // between be around 0.3 to 0.5 refframe_t frame; + plane_t frustum[4]; mat4f_t camera; mat4f_t camera_inverse; diff --git a/include/r_local.h b/include/r_local.h index 469baca0b..0c7a7129e 100644 --- a/include/r_local.h +++ b/include/r_local.h @@ -142,7 +142,8 @@ extern mat4f_t glsl_projection; extern mat4f_t glsl_view; union refframe_s; -void R_SetFrustum (const union refframe_s *frame, float fov_x, float fov_y); +void R_SetFrustum (plane_t *frustum, const union refframe_s *frame, + float fov_x, float fov_y); void R_SpriteBegin (void); void R_SpriteEnd (void); diff --git a/libs/util/mathlib.c b/libs/util/mathlib.c index e047fca89..9f8aa2def 100644 --- a/libs/util/mathlib.c +++ b/libs/util/mathlib.c @@ -48,8 +48,6 @@ #include "QF/sys.h" VISIBLE int nanmask = 255 << 23; -static plane_t _frustum[4]; -VISIBLE plane_t *const frustum = _frustum; static vec3_t _vec3_origin = { 0, 0, 0 }; VISIBLE const vec_t * const vec3_origin = _vec3_origin; static quat_t _quat_origin = { 0, 0, 0, 0 }; @@ -393,7 +391,7 @@ BOPS_Error (void) Returns 1, 2, or 1 + 2 */ VISIBLE int -BoxOnPlaneSide (const vec3_t emins, const vec3_t emaxs, plane_t *p) +BoxOnPlaneSide (const vec3_t emins, const vec3_t emaxs, const plane_t *p) { float dist1, dist2; int sides; diff --git a/libs/video/renderer/gl/gl_mod_alias.c b/libs/video/renderer/gl/gl_mod_alias.c index 307410f53..1ba1f64ab 100644 --- a/libs/video/renderer/gl/gl_mod_alias.c +++ b/libs/video/renderer/gl/gl_mod_alias.c @@ -434,7 +434,7 @@ gl_R_DrawAliasModel (entity_t *e) if (scale[0] != 1.0) { radius *= scale[0]; } - if (R_CullSphere (&origin[0], radius)) {//FIXME + if (R_CullSphere (r_refdef.frustum, &origin[0], radius)) {//FIXME return; } diff --git a/libs/video/renderer/gl/gl_rsurf.c b/libs/video/renderer/gl/gl_rsurf.c index d2b0aff68..75e42ff5a 100644 --- a/libs/video/renderer/gl/gl_rsurf.c +++ b/libs/video/renderer/gl/gl_rsurf.c @@ -544,7 +544,7 @@ gl_R_DrawBrushModel (entity_t *e) if (e->scale != 1.0) radius *= e->scale; #endif - if (R_CullSphere (&worldMatrix[3][0], radius)) {//FIXME + if (R_CullSphere (r_refdef.frustum, &worldMatrix[3][0], radius)) {//FIXME return; } } else { @@ -557,7 +557,7 @@ gl_R_DrawBrushModel (entity_t *e) VectorScale (maxs, e->scale, maxs); } #endif - if (R_CullBox (mins, maxs)) + if (R_CullBox (r_refdef.frustum, mins, maxs)) return; } @@ -660,7 +660,7 @@ test_node (mnode_t *node) return 0; if (node->visframe != r_visframecount) return 0; - if (R_CullBox (node->minmaxs, node->minmaxs + 3)) + if (R_CullBox (r_refdef.frustum, node->minmaxs, node->minmaxs + 3)) return 0; return 1; } diff --git a/libs/video/renderer/glsl/glsl_bsp.c b/libs/video/renderer/glsl/glsl_bsp.c index aced41a62..eb8fdab4b 100644 --- a/libs/video/renderer/glsl/glsl_bsp.c +++ b/libs/video/renderer/glsl/glsl_bsp.c @@ -677,14 +677,14 @@ R_DrawBrushModel (entity_t *e) if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) { rotated = true; radius = model->radius; - if (R_CullSphere (&mat[3][0], radius)) { // FIXME + if (R_CullSphere (r_refdef.frustum, &mat[3][0], radius)) { // FIXME return; } } else { rotated = false; VectorAdd (mat[3], model->mins, mins); VectorAdd (mat[3], model->maxs, maxs); - if (R_CullBox (mins, maxs)) + if (R_CullBox (r_refdef.frustum, mins, maxs)) return; } @@ -779,7 +779,7 @@ test_node (mnode_t *node) return 0; if (node->visframe != r_visframecount) return 0; - if (R_CullBox (node->minmaxs, node->minmaxs + 3)) + if (R_CullBox (r_refdef.frustum, node->minmaxs, node->minmaxs + 3)) return 0; return 1; } diff --git a/libs/video/renderer/r_light.c b/libs/video/renderer/r_light.c index 0b32a6f6d..6356d4c2b 100644 --- a/libs/video/renderer/r_light.c +++ b/libs/video/renderer/r_light.c @@ -297,7 +297,7 @@ R_MarkLights (const vec3_t lightorigin, dlight_t *light, int lightnum, || leaf->mins[1] > maxs[1] || leaf->maxs[1] < mins[1] || leaf->mins[2] > maxs[2] || leaf->maxs[2] < mins[2]) continue; - if (R_CullBox (leaf->mins, leaf->maxs)) + if (R_CullBox (r_refdef.frustum, leaf->mins, leaf->maxs)) continue; for (m = 0; m < leaf->nummarksurfaces; m++) { msurface_t *surf = leaf->firstmarksurface[m]; diff --git a/libs/video/renderer/r_main.c b/libs/video/renderer/r_main.c index b9cafb9a1..e9184c80f 100644 --- a/libs/video/renderer/r_main.c +++ b/libs/video/renderer/r_main.c @@ -89,7 +89,8 @@ SignbitsForPlane (plane_t *out) } void -R_SetFrustum (const refframe_t *frame, float fov_x, float fov_y) +R_SetFrustum (plane_t *frustum, const refframe_t *frame, + float fov_x, float fov_y) { int i; vec4f_t right = frame->right; diff --git a/libs/video/renderer/r_screen.c b/libs/video/renderer/r_screen.c index bb2ce0b21..77fdeb411 100644 --- a/libs/video/renderer/r_screen.c +++ b/libs/video/renderer/r_screen.c @@ -177,7 +177,8 @@ SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs) refdef->frame.mat[1] = refdef->camera[0]; refdef->frame.mat[2] = refdef->camera[2]; refdef->frame.mat[3] = refdef->camera[3]; - R_SetFrustum (&refdef->frame, refdef->fov_x, refdef->fov_y); + R_SetFrustum (refdef->frustum, &refdef->frame, + refdef->fov_x, refdef->fov_y); //FIXME breaks fisheye as it calls the view render many times EntQueue_Clear (r_ent_queue); diff --git a/libs/video/renderer/vulkan/vulkan_bsp.c b/libs/video/renderer/vulkan/vulkan_bsp.c index 40dee2f61..53c4d65a3 100644 --- a/libs/video/renderer/vulkan/vulkan_bsp.c +++ b/libs/video/renderer/vulkan/vulkan_bsp.c @@ -604,14 +604,14 @@ R_DrawBrushModel (entity_t *e, vulkan_ctx_t *ctx) if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) { rotated = true; radius = model->radius; - if (R_CullSphere (&mat[3][0], radius)) { //FIXME + if (R_CullSphere (r_refdef.frustum, &mat[3][0], radius)) { //FIXME return; } } else { rotated = false; VectorAdd (mat[3], model->mins, mins); VectorAdd (mat[3], model->maxs, maxs); - if (R_CullBox (mins, maxs)) + if (R_CullBox (r_refdef.frustum, mins, maxs)) return; } @@ -691,7 +691,7 @@ test_node (mnode_t *node) return 0; if (node->visframe != r_visframecount) return 0; - if (R_CullBox (node->minmaxs, node->minmaxs + 3)) + if (R_CullBox (r_refdef.frustum, node->minmaxs, node->minmaxs + 3)) return 0; return 1; }