From c91dc0b9b21413cf595af5ffbbeeca81afa12c9b Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sat, 14 Oct 2023 02:08:30 +0300 Subject: [PATCH] Share R_PushDlights between all renders --- doc/040_cvarlist.md | 2 +- src/client/refresh/files/light.c | 17 ++++++++++++++++- src/client/refresh/gl1/gl1_light.c | 14 +++----------- src/client/refresh/gl1/gl1_main.c | 2 +- src/client/refresh/gl1/gl1_surf.c | 13 ++----------- src/client/refresh/gl1/header/local.h | 2 +- src/client/refresh/gl3/gl3_light.c | 6 +++--- src/client/refresh/gl3/gl3_surf.c | 10 ++-------- src/client/refresh/gl4/gl4_light.c | 6 +++--- src/client/refresh/gl4/gl4_surf.c | 11 ++--------- src/client/refresh/ref_shared.h | 4 ++-- src/client/refresh/soft/header/local.h | 2 +- src/client/refresh/soft/sw_light.c | 15 ++++----------- src/client/refresh/soft/sw_main.c | 4 ++-- src/client/refresh/vk/header/local.h | 2 +- src/client/refresh/vk/vk_light.c | 14 +++----------- src/client/refresh/vk/vk_main.c | 2 +- src/client/refresh/vk/vk_surf.c | 13 ++----------- 18 files changed, 50 insertions(+), 89 deletions(-) diff --git a/doc/040_cvarlist.md b/doc/040_cvarlist.md index 2544dee3..fabb0c6c 100644 --- a/doc/040_cvarlist.md +++ b/doc/040_cvarlist.md @@ -422,7 +422,7 @@ Set `0` by default. * **r_dynamic**: Enamble dynamic light in gl1 and vk renders. -* **r_flashblend**: Flah blend enable in gl1, gl3 and vulkan. +* **r_flashblend**: Flash blend enable in gl1, gl3 and vulkan. ## Graphics (GL renderers only) diff --git a/src/client/refresh/files/light.c b/src/client/refresh/files/light.c index c97038ee..6b9a06bd 100644 --- a/src/client/refresh/files/light.c +++ b/src/client/refresh/files/light.c @@ -643,7 +643,7 @@ bit: 1 << i for light number i, will be or'ed into msurface_t::dlightbits if surface is affected by this light ============= */ -void +static void R_MarkLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount, msurface_t *surfaces) { @@ -682,3 +682,18 @@ R_MarkLights(dlight_t *light, int bit, mnode_t *node, int r_dlightframecount, R_MarkLights(light, bit, node->children[1], r_dlightframecount, surfaces); } + +void R_PushDlights(refdef_t *r_newrefdef, mnode_t *nodes, int r_dlightframecount, + msurface_t *surfaces) +{ + dlight_t *l; + int i; + + l = r_newrefdef->dlights; + + for (i = 0; i < r_newrefdef->num_dlights; i++, l++) + { + R_MarkLights(l, 1 << i, nodes, r_dlightframecount, surfaces); + } + +} diff --git a/src/client/refresh/gl1/gl1_light.c b/src/client/refresh/gl1/gl1_light.c index f71b6e0e..d8438a63 100644 --- a/src/client/refresh/gl1/gl1_light.c +++ b/src/client/refresh/gl1/gl1_light.c @@ -116,11 +116,8 @@ R_RenderDlights(void) } void -R_PushDlights(void) +RI_PushDlights(void) { - dlight_t *l; - int i; - if (r_flashblend->value) { return; @@ -129,13 +126,8 @@ R_PushDlights(void) /* because the count hasn't advanced yet for this frame */ r_dlightframecount = r_framecount + 1; - l = r_newrefdef.dlights; - - for (i = 0; i < r_newrefdef.num_dlights; i++, l++) - { - R_MarkLights(l, 1 << i, r_worldmodel->nodes, r_dlightframecount, - r_worldmodel->surfaces); - } + R_PushDlights(&r_newrefdef, r_worldmodel->nodes, r_dlightframecount, + r_worldmodel->surfaces); } float *s_blocklights = NULL, *s_blocklights_max = NULL; diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index a7c7b05c..220097bc 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -1045,7 +1045,7 @@ R_RenderView(refdef_t *fd) c_alias_polys = 0; } - R_PushDlights(); + RI_PushDlights(); if (gl_finish->value) { diff --git a/src/client/refresh/gl1/gl1_surf.c b/src/client/refresh/gl1/gl1_surf.c index 90c7f488..fa251654 100644 --- a/src/client/refresh/gl1/gl1_surf.c +++ b/src/client/refresh/gl1/gl1_surf.c @@ -637,17 +637,8 @@ R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel) /* calculate dynamic lighting for bmodel */ if (!r_flashblend->value) { - dlight_t *lt; - int k; - - lt = r_newrefdef.dlights; - - for (k = 0; k < r_newrefdef.num_dlights; k++, lt++) - { - R_MarkLights(lt, 1 << k, - currentmodel->nodes + currentmodel->firstnode, - r_dlightframecount, currentmodel->surfaces); - } + R_PushDlights(&r_newrefdef, currentmodel->nodes + currentmodel->firstnode, + r_dlightframecount, currentmodel->surfaces); } psurf = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index 68d8e1bd..557e6781 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -233,7 +233,7 @@ void R_Bind(int texnum); void R_TexEnv(GLenum value); -void R_PushDlights(void); +void RI_PushDlights(void); extern float *s_blocklights, *s_blocklights_max; extern model_t *r_worldmodel; diff --git a/src/client/refresh/gl3/gl3_light.c b/src/client/refresh/gl3/gl3_light.c index f2912322..372b9137 100644 --- a/src/client/refresh/gl3/gl3_light.c +++ b/src/client/refresh/gl3/gl3_light.c @@ -41,6 +41,9 @@ GL3_PushDlights(void) /* because the count hasn't advanced yet for this frame */ r_dlightframecount = gl3_framecount + 1; + R_PushDlights(&gl3_newrefdef, gl3_worldmodel->nodes, r_dlightframecount, + gl3_worldmodel->surfaces); + l = gl3_newrefdef.dlights; gl3state.uniLightsData.numDynLights = gl3_newrefdef.num_dlights; @@ -48,9 +51,6 @@ GL3_PushDlights(void) for (i = 0; i < gl3_newrefdef.num_dlights; i++, l++) { gl3UniDynLight* udl = &gl3state.uniLightsData.dynLights[i]; - R_MarkLights(l, 1 << i, gl3_worldmodel->nodes, r_dlightframecount, - gl3_worldmodel->surfaces); - VectorCopy(l->origin, udl->origin); VectorCopy(l->color, udl->color); udl->intensity = l->intensity; diff --git a/src/client/refresh/gl3/gl3_surf.c b/src/client/refresh/gl3/gl3_surf.c index e6db657e..c099ecf5 100644 --- a/src/client/refresh/gl3/gl3_surf.c +++ b/src/client/refresh/gl3/gl3_surf.c @@ -480,20 +480,14 @@ RenderLightmappedPoly(entity_t *currententity, msurface_t *surf) static void DrawInlineBModel(entity_t *currententity, gl3model_t *currentmodel) { - int i, k; + int i; cplane_t *pplane; float dot; msurface_t *psurf; - dlight_t *lt; /* calculate dynamic lighting for bmodel */ - lt = gl3_newrefdef.dlights; - - for (k = 0; k < gl3_newrefdef.num_dlights; k++, lt++) - { - R_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode, + R_PushDlights(&gl3_newrefdef, currentmodel->nodes + currentmodel->firstnode, r_dlightframecount, currentmodel->surfaces); - } psurf = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; diff --git a/src/client/refresh/gl4/gl4_light.c b/src/client/refresh/gl4/gl4_light.c index dcefa024..0e5dee21 100644 --- a/src/client/refresh/gl4/gl4_light.c +++ b/src/client/refresh/gl4/gl4_light.c @@ -41,6 +41,9 @@ GL4_PushDlights(void) /* because the count hasn't advanced yet for this frame */ r_dlightframecount = gl4_framecount + 1; + R_PushDlights(&gl4_newrefdef, gl4_worldmodel->nodes, r_dlightframecount, + gl4_worldmodel->surfaces); + l = gl4_newrefdef.dlights; gl4state.uniLightsData.numDynLights = gl4_newrefdef.num_dlights; @@ -48,9 +51,6 @@ GL4_PushDlights(void) for (i = 0; i < gl4_newrefdef.num_dlights; i++, l++) { gl4UniDynLight* udl = &gl4state.uniLightsData.dynLights[i]; - R_MarkLights(l, 1 << i, gl4_worldmodel->nodes, r_dlightframecount, - gl4_worldmodel->surfaces); - VectorCopy(l->origin, udl->origin); VectorCopy(l->color, udl->color); udl->intensity = l->intensity; diff --git a/src/client/refresh/gl4/gl4_surf.c b/src/client/refresh/gl4/gl4_surf.c index 484f1b35..08ecea4a 100644 --- a/src/client/refresh/gl4/gl4_surf.c +++ b/src/client/refresh/gl4/gl4_surf.c @@ -480,20 +480,13 @@ RenderLightmappedPoly(entity_t *currententity, msurface_t *surf) static void DrawInlineBModel(entity_t *currententity, gl4model_t *currentmodel) { - int i, k; + int i; cplane_t *pplane; float dot; msurface_t *psurf; - dlight_t *lt; - /* calculate dynamic lighting for bmodel */ - lt = gl4_newrefdef.dlights; - - for (k = 0; k < gl4_newrefdef.num_dlights; k++, lt++) - { - R_MarkLights(lt, 1 << k, currentmodel->nodes + currentmodel->firstnode, + R_PushDlights(&gl4_newrefdef, currentmodel->nodes + currentmodel->firstnode, r_dlightframecount, currentmodel->surfaces); - } psurf = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index fbdba28e..ce053cd6 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -362,8 +362,8 @@ extern int Mod_LoadFile(char *name, void **buffer); /* Surface logic */ #define DLIGHT_CUTOFF 64 -extern void R_MarkLights (dlight_t *light, int bit, mnode_t *node, int r_dlightframecount, - msurface_t *surfaces); +extern void R_PushDlights(refdef_t *r_newrefdef, mnode_t *nodes, int r_dlightframecount, + msurface_t *surfaces); extern struct image_s *R_TextureAnimation(const entity_t *currententity, const mtexinfo_t *tex); extern qboolean R_AreaVisible(const byte *areabits, mleaf_t *pleaf); diff --git a/src/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 23750250..d68d5d92 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -451,7 +451,7 @@ void R_DrawSolidClippedSubmodelPolygons(entity_t *currententity, const model_t * void R_AliasDrawModel(entity_t *currententity, const model_t *currentmodel); void R_BeginEdgeFrame(void); void R_ScanEdges(entity_t *currententity, surf_t *surface); -void R_PushDlights(const model_t *model); +void RI_PushDlights(const model_t *model); void R_RotateBmodel(const entity_t *currententity); extern int c_faceclip; diff --git a/src/client/refresh/soft/sw_light.c b/src/client/refresh/soft/sw_light.c index 1defcb90..43efb655 100644 --- a/src/client/refresh/soft/sw_light.c +++ b/src/client/refresh/soft/sw_light.c @@ -34,21 +34,14 @@ DYNAMIC LIGHTS /* ============= -R_PushDlights +RI_PushDlights ============= */ void -R_PushDlights(const model_t *model) +RI_PushDlights(const model_t *model) { - int i; - dlight_t *l; - - for (i=0, l = r_newrefdef.dlights ; inodes + model->firstnode, - r_framecount, model->surfaces); - } + R_PushDlights(&r_newrefdef, model->nodes + model->firstnode, + r_framecount, model->surfaces); } static void diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index a9cf9e81..855ce40a 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -1128,7 +1128,7 @@ R_DrawBEntitiesOnList (void) R_RotateBmodel(currententity); // calculate dynamic lighting for bmodel - R_PushDlights (currentmodel); + RI_PushDlights (currentmodel); if (topnode->contents == CONTENTS_NODE) { @@ -1369,7 +1369,7 @@ RE_RenderFrame (refdef_t *fd) R_MarkLeaves (); // done here so we know if we're in water // For each dlight_t* passed via r_newrefdef.dlights, mark polygons affected by a light. - R_PushDlights (r_worldmodel); + RI_PushDlights (r_worldmodel); // TODO: rearrange code same as in GL*_DrawWorld? /* auto cycle the world frame for texture animation */ diff --git a/src/client/refresh/vk/header/local.h b/src/client/refresh/vk/header/local.h index 7e3b2174..c9dfed08 100644 --- a/src/client/refresh/vk/header/local.h +++ b/src/client/refresh/vk/header/local.h @@ -185,7 +185,7 @@ void Vk_ScreenShot_f (void); void Vk_Strings_f(void); void Vk_Mem_f(void); -void R_PushDlights(void); +void RI_PushDlights(void); void R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel); void R_DrawBrushModel(entity_t *currententity, const model_t *currentmodel); diff --git a/src/client/refresh/vk/vk_light.c b/src/client/refresh/vk/vk_light.c index 19e11008..e567b33d 100644 --- a/src/client/refresh/vk/vk_light.c +++ b/src/client/refresh/vk/vk_light.c @@ -106,11 +106,8 @@ R_RenderDlights(void) } void -R_PushDlights(void) +RI_PushDlights(void) { - dlight_t *l; - int i; - if (r_flashblend->value) { return; @@ -119,13 +116,8 @@ R_PushDlights(void) /* because the count hasn't advanced yet for this frame */ r_dlightframecount = r_framecount + 1; - l = r_newrefdef.dlights; - - for (i = 0; i < r_newrefdef.num_dlights; i++, l++) - { - R_MarkLights(l, 1 << i, r_worldmodel->nodes, r_dlightframecount, - r_worldmodel->surfaces); - } + R_PushDlights(&r_newrefdef, r_worldmodel->nodes, + r_dlightframecount, r_worldmodel->surfaces); } float *s_blocklights = NULL, *s_blocklights_max = NULL; diff --git a/src/client/refresh/vk/vk_main.c b/src/client/refresh/vk/vk_main.c index 96a38590..0ecb0a60 100644 --- a/src/client/refresh/vk/vk_main.c +++ b/src/client/refresh/vk/vk_main.c @@ -936,7 +936,7 @@ RE_RenderView(refdef_t *fd) vkCmdSetScissor(vk_activeCmdbuffer, 0, 1, &scissor); - R_PushDlights(); + RI_PushDlights(); // added for compatibility sake with OpenGL implementation - don't use it! if (vk_finish->value) diff --git a/src/client/refresh/vk/vk_surf.c b/src/client/refresh/vk/vk_surf.c index 020d7d7c..a4997110 100644 --- a/src/client/refresh/vk/vk_surf.c +++ b/src/client/refresh/vk/vk_surf.c @@ -603,17 +603,8 @@ R_DrawInlineBModel(entity_t *currententity, const model_t *currentmodel, float * /* calculate dynamic lighting for bmodel */ if (!r_flashblend->value) { - dlight_t *lt; - int k; - - lt = r_newrefdef.dlights; - - for (k = 0; k < r_newrefdef.num_dlights; k++, lt++) - { - R_MarkLights(lt, 1 << k, - currentmodel->nodes + currentmodel->firstnode, - r_dlightframecount, currentmodel->surfaces); - } + R_PushDlights(&r_newrefdef, currentmodel->nodes + currentmodel->firstnode, + r_dlightframecount, currentmodel->surfaces); } psurf = ¤tmodel->surfaces[currentmodel->firstmodelsurface];