mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[renderer] Clean up R_MarkLeaves
Really? More to clean up before (vulkan) bsp rendering is thread-safe? However, R_MarkLeaves was pretty close: just oldviewleaf and visframecount, but that's still too much. Also, the reliance on r_refdef.worldmodel irked me.
This commit is contained in:
parent
ecb9a15946
commit
585f1161db
15 changed files with 67 additions and 64 deletions
|
@ -45,7 +45,6 @@ typedef enum {
|
|||
|
||||
struct entity_s;
|
||||
|
||||
void R_PushDlights (const vec3_t entorigin);
|
||||
void R_MaxDlightsCheck (int max_dlights);
|
||||
void R_Particles_Init_Cvars (void);
|
||||
void R_InitBubble (void);
|
||||
|
|
|
@ -50,8 +50,19 @@ void R_RunParticles (float dT);
|
|||
struct scene_s;
|
||||
void R_NewScene (struct scene_s *scene);
|
||||
|
||||
typedef struct visstate_s {
|
||||
const struct mleaf_s *viewleaf;
|
||||
int *node_visframes;
|
||||
int *leaf_visframes;
|
||||
int *face_visframes;
|
||||
int visframecount;
|
||||
struct mod_brush_s *brush;
|
||||
} visstate_t;
|
||||
|
||||
extern visstate_t r_visstate;//FIXME
|
||||
|
||||
// LordHavoc: relative bmodel lighting
|
||||
void R_PushDlights (const vec3_t entorigin);
|
||||
void R_PushDlights (const vec3_t entorigin, const visstate_t *visstate);
|
||||
void R_DrawWaterSurfaces (void);
|
||||
|
||||
void *D_SurfaceCacheAddress (void) __attribute__((pure));
|
||||
|
@ -77,11 +88,7 @@ struct animation_s;
|
|||
struct transform_s;
|
||||
void R_DrawAliasModel (struct entity_s *e);
|
||||
|
||||
void R_MarkLeaves (struct mleaf_s *viewleaf, int *node_visframes,
|
||||
int *leaf_visframes, int *face_visframes);
|
||||
extern int *r_node_visframes;
|
||||
extern int *r_leaf_visframes;
|
||||
extern int *r_face_visframes;
|
||||
void R_MarkLeaves (visstate_t *state, const struct mleaf_s *viewleaf);
|
||||
|
||||
void GL_SetPalette (void *data, const byte *palette);
|
||||
void GLSL_SetPalette (void *data, const byte *palette);
|
||||
|
|
|
@ -120,8 +120,6 @@ extern plane_t screenedge[4];
|
|||
|
||||
extern vec4f_t r_entorigin;
|
||||
|
||||
extern int r_visframecount;
|
||||
|
||||
//=============================================================================
|
||||
|
||||
extern int vstartscan;
|
||||
|
|
|
@ -168,9 +168,6 @@ gl_R_NewScene (scene_t *scene)
|
|||
r_refdef.worldmodel = scene->worldmodel;
|
||||
brush = &scene->worldmodel->brush;
|
||||
|
||||
// Force a vis update
|
||||
R_MarkLeaves (0, 0, 0, 0);
|
||||
|
||||
R_ClearParticles ();
|
||||
|
||||
GL_BuildLightmaps (scene->models, scene->num_models);
|
||||
|
|
|
@ -617,7 +617,7 @@ visit_node (glbspctx_t *bctx, mnode_t *node, int side)
|
|||
int surf_id = node->firstsurface;
|
||||
surf = bctx->brush->surfaces + surf_id;
|
||||
for (; c; c--, surf++, surf_id++) {
|
||||
if (r_face_visframes[surf_id] != r_visframecount)
|
||||
if (r_visstate.face_visframes[surf_id] != r_visstate.visframecount)
|
||||
continue;
|
||||
|
||||
// side is either 0 or SURF_PLANEBACK
|
||||
|
@ -634,7 +634,7 @@ test_node (glbspctx_t *bctx, int node_id)
|
|||
{
|
||||
if (node_id < 0)
|
||||
return 0;
|
||||
if (r_node_visframes[node_id] != r_visframecount)
|
||||
if (r_visstate.node_visframes[node_id] != r_visstate.visframecount)
|
||||
return 0;
|
||||
mnode_t *node = bctx->brush->nodes + node_id;
|
||||
if (R_CullBox (r_refdef.frustum, node->minmaxs, node->minmaxs + 3))
|
||||
|
|
|
@ -758,7 +758,7 @@ visit_node (glslbspctx_t *bctx, mnode_t *node, int side)
|
|||
int surf_id = node->firstsurface;
|
||||
surf = bctx->brush->surfaces + surf_id;
|
||||
for (; c; c--, surf++, surf_id++) {
|
||||
if (r_face_visframes[surf_id] != r_visframecount)
|
||||
if (r_visstate.face_visframes[surf_id] != r_visstate.visframecount)
|
||||
continue;
|
||||
|
||||
// side is either 0 or SURF_PLANEBACK
|
||||
|
@ -777,7 +777,7 @@ test_node (glslbspctx_t *bctx, int node_id)
|
|||
{
|
||||
if (node_id < 0)
|
||||
return 0;
|
||||
if (r_node_visframes[node_id] != r_visframecount)
|
||||
if (r_visstate.node_visframes[node_id] != r_visstate.visframecount)
|
||||
return 0;
|
||||
mnode_t *node = bctx->brush->nodes + node_id;
|
||||
if (R_CullBox (r_refdef.frustum, node->minmaxs, node->minmaxs + 3))
|
||||
|
|
|
@ -213,9 +213,6 @@ glsl_R_NewScene (scene_t *scene)
|
|||
|
||||
r_refdef.worldmodel = scene->worldmodel;
|
||||
|
||||
// Force a vis update
|
||||
R_MarkLeaves (0, 0, 0, 0);
|
||||
|
||||
R_ClearParticles ();
|
||||
glsl_R_RegisterTextures (scene->models, scene->num_models);
|
||||
glsl_R_BuildLightmaps (scene->models, scene->num_models);
|
||||
|
|
|
@ -43,37 +43,39 @@
|
|||
|
||||
#include "r_internal.h"
|
||||
|
||||
static mleaf_t *r_oldviewleaf;
|
||||
static set_t *solid;
|
||||
|
||||
void
|
||||
R_MarkLeaves (mleaf_t *viewleaf, int *node_visframes, int *leaf_visframes,
|
||||
int *face_visframes)
|
||||
R_MarkLeaves (visstate_t *visstate, const mleaf_t *viewleaf)
|
||||
{
|
||||
set_t *vis;
|
||||
int c;
|
||||
mleaf_t *leaf;
|
||||
msurface_t **mark;
|
||||
mod_brush_t *brush = &r_refdef.worldmodel->brush;
|
||||
auto node_visframes = visstate->node_visframes;
|
||||
auto leaf_visframes = visstate->leaf_visframes;
|
||||
auto face_visframes = visstate->face_visframes;
|
||||
auto brush = visstate->brush;
|
||||
|
||||
if (r_oldviewleaf == viewleaf && !r_novis)
|
||||
if (visstate->viewleaf == viewleaf && !r_novis)
|
||||
return;
|
||||
|
||||
r_visframecount++;
|
||||
r_oldviewleaf = viewleaf;
|
||||
int visframecount = ++visstate->visframecount;
|
||||
visstate->viewleaf = viewleaf;
|
||||
if (!viewleaf)
|
||||
return;
|
||||
|
||||
if (r_novis) {
|
||||
r_oldviewleaf = 0; // so vis will be recalcualted when novis gets
|
||||
// turned off
|
||||
// so vis will be recalculated when novis gets turned off
|
||||
visstate->viewleaf = 0;
|
||||
if (!solid) {
|
||||
solid = set_new ();
|
||||
set_everything (solid);
|
||||
}
|
||||
vis = solid;
|
||||
} else
|
||||
} else {
|
||||
vis = Mod_LeafPVS (viewleaf, brush);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < brush->visleafs; i++) {
|
||||
if (set_is_member (vis, i)) {
|
||||
|
@ -81,16 +83,16 @@ R_MarkLeaves (mleaf_t *viewleaf, int *node_visframes, int *leaf_visframes,
|
|||
if ((c = leaf->nummarksurfaces)) {
|
||||
mark = brush->marksurfaces + leaf->firstmarksurface;
|
||||
do {
|
||||
face_visframes[*mark - brush->surfaces] = r_visframecount;
|
||||
face_visframes[*mark - brush->surfaces] = visframecount;
|
||||
mark++;
|
||||
} while (--c);
|
||||
}
|
||||
leaf_visframes[i + 1] = r_visframecount;
|
||||
leaf_visframes[i + 1] = visframecount;
|
||||
int node_id = brush->leaf_parents[leaf - brush->leafs];
|
||||
while (node_id >= 0) {
|
||||
if (node_visframes[node_id] == r_visframecount)
|
||||
if (node_visframes[node_id] == visframecount)
|
||||
break;
|
||||
node_visframes[node_id] = r_visframecount;
|
||||
node_visframes[node_id] = visframecount;
|
||||
node_id = brush->node_parents[node_id];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -261,10 +261,13 @@ loc0:
|
|||
|
||||
static void
|
||||
R_MarkLights (vec4f_t lightorigin, dlight_t *light, int lightnum,
|
||||
model_t *model)
|
||||
const visstate_t *visstate)
|
||||
{
|
||||
mod_brush_t *brush = &model->brush;
|
||||
mleaf_t *pvsleaf = Mod_PointInLeaf (lightorigin, brush);
|
||||
const auto leaf_visframes = visstate->leaf_visframes;
|
||||
const auto face_visframes = visstate->face_visframes;
|
||||
const auto visframecount = visstate->visframecount;
|
||||
const auto brush = visstate->brush;
|
||||
const auto pvsleaf = Mod_PointInLeaf (lightorigin, brush);
|
||||
|
||||
if (!pvsleaf->compressed_vis) {
|
||||
int node_id = brush->hulls[0].firstclipnode;
|
||||
|
@ -294,7 +297,7 @@ R_MarkLights (vec4f_t lightorigin, dlight_t *light, int lightnum,
|
|||
mleaf_t *leaf = &brush->leafs[leafnum + 1];
|
||||
if (!(vis_bits & b))
|
||||
continue;
|
||||
if (r_leaf_visframes[leafnum + 1] != r_visframecount)
|
||||
if (leaf_visframes[leafnum + 1] != visframecount)
|
||||
continue;
|
||||
if (leaf->mins[0] > maxs[0] || leaf->maxs[0] < mins[0]
|
||||
|| leaf->mins[1] > maxs[1] || leaf->maxs[1] < mins[1]
|
||||
|
@ -304,7 +307,7 @@ R_MarkLights (vec4f_t lightorigin, dlight_t *light, int lightnum,
|
|||
for (m = 0; m < leaf->nummarksurfaces; m++) {
|
||||
msurface_t *surf = *msurf++;
|
||||
int surf_id = surf - brush->surfaces;
|
||||
if (r_face_visframes[surf_id] != r_visframecount)
|
||||
if (face_visframes[surf_id] != visframecount)
|
||||
continue;
|
||||
mark_surfaces (surf, lightorigin, light, lightnum);
|
||||
}
|
||||
|
@ -314,7 +317,7 @@ R_MarkLights (vec4f_t lightorigin, dlight_t *light, int lightnum,
|
|||
}
|
||||
|
||||
void
|
||||
R_PushDlights (const vec3_t entorigin)
|
||||
R_PushDlights (const vec3_t entorigin, const visstate_t *visstate)
|
||||
{
|
||||
unsigned int i;
|
||||
dlight_t *l;
|
||||
|
@ -332,7 +335,7 @@ R_PushDlights (const vec3_t entorigin)
|
|||
vec4f_t lightorigin;
|
||||
VectorSubtract (l->origin, entorigin, lightorigin);
|
||||
lightorigin[3] = 1;
|
||||
R_MarkLights (lightorigin, l, i, r_refdef.worldmodel);
|
||||
R_MarkLights (lightorigin, l, i, visstate);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ int r_lineadj;
|
|||
bool r_active;
|
||||
int r_init;
|
||||
|
||||
int r_visframecount; // bumped when going to a new PVS
|
||||
int r_framecount = 1; // so frame counts initialized to 0 don't match
|
||||
|
||||
vec3_t modelorg; // modelorg is the viewpoint relative to
|
||||
|
|
|
@ -60,9 +60,8 @@
|
|||
int scr_copytop;
|
||||
byte *draw_chars; // 8*8 graphic characters FIXME location
|
||||
bool r_cache_thrash; // set if surface cache is thrashing
|
||||
int *r_node_visframes; //FIXME per renderer
|
||||
int *r_leaf_visframes; //FIXME per renderer
|
||||
int *r_face_visframes; //FIXME per renderer
|
||||
|
||||
visstate_t r_visstate; //FIXME per renderer
|
||||
|
||||
bool scr_skipupdate;
|
||||
static bool scr_initialized;// ready to draw
|
||||
|
@ -322,11 +321,10 @@ SCR_UpdateScreen (transform_t camera, double realtime, SCR_Func *scr_funcs)
|
|||
if (r_waterwarp) {
|
||||
r_dowarp = scr_scene->viewleaf->contents <= CONTENTS_WATER;
|
||||
}
|
||||
R_MarkLeaves (scr_scene->viewleaf, r_node_visframes, r_leaf_visframes,
|
||||
r_face_visframes);
|
||||
R_MarkLeaves (&r_visstate, scr_scene->viewleaf);
|
||||
}
|
||||
r_framecount++;
|
||||
R_PushDlights (vec3_origin);
|
||||
R_PushDlights (vec3_origin, &r_visstate);
|
||||
r_funcs->UpdateScreen (camera, realtime, scr_funcs);
|
||||
}
|
||||
|
||||
|
@ -495,12 +493,19 @@ SCR_NewScene (scene_t *scene)
|
|||
int count = brush->numnodes + brush->modleafs
|
||||
+ brush->numsurfaces;
|
||||
int size = count * sizeof (int);
|
||||
r_node_visframes = Hunk_AllocName (0, size, "visframes");
|
||||
r_leaf_visframes = r_node_visframes + brush->numnodes;
|
||||
r_face_visframes = r_leaf_visframes + brush->modleafs;
|
||||
int *node_visframes = Hunk_AllocName (0, size, "visframes");
|
||||
int *leaf_visframes = node_visframes + brush->numnodes;
|
||||
int *face_visframes = leaf_visframes + brush->modleafs;
|
||||
r_visstate = (visstate_t) {
|
||||
.brush = brush,
|
||||
.node_visframes = node_visframes,
|
||||
.leaf_visframes = leaf_visframes,
|
||||
.face_visframes = face_visframes,
|
||||
};
|
||||
r_funcs->set_fov (tan_fov_x, tan_fov_y);
|
||||
r_funcs->R_NewScene (scene);
|
||||
} else {
|
||||
r_visstate = (visstate_t) {};
|
||||
r_funcs->R_ClearState ();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -232,13 +232,15 @@ R_RecursiveClipBPoly (uint32_t render_id, bedge_t *pedges, mnode_t *pnode,
|
|||
// we're done with this branch if the node or leaf isn't in the PVS
|
||||
if (child_id < 0) {
|
||||
mleaf_t *leaf = r_refdef.worldmodel->brush.leafs + ~child_id;
|
||||
if (r_leaf_visframes[~child_id] == r_visframecount
|
||||
if (r_visstate.leaf_visframes[~child_id]
|
||||
== r_visstate.visframecount
|
||||
&& leaf->contents != CONTENTS_SOLID) {
|
||||
r_currentbkey = leaf->key;
|
||||
R_RenderBmodelFace (render_id, psideedges[i], psurf);
|
||||
}
|
||||
} else {
|
||||
if (r_node_visframes[child_id] == r_visframecount) {
|
||||
if (r_visstate.node_visframes[child_id]
|
||||
== r_visstate.visframecount) {
|
||||
R_RecursiveClipBPoly (render_id, psideedges[i], pn, psurf);
|
||||
}
|
||||
}
|
||||
|
@ -383,7 +385,7 @@ visit_node (swbspctx_t *bctx, mnode_t *node, int side, int clipflags)
|
|||
int surf_id = node->firstsurface;
|
||||
surf = brush->surfaces + surf_id;
|
||||
for (; c; c--, surf++, surf_id++) {
|
||||
if (r_face_visframes[surf_id] != r_visframecount)
|
||||
if (r_visstate.face_visframes[surf_id] != r_visstate.visframecount)
|
||||
continue;
|
||||
|
||||
// side is either 0 or SURF_PLANEBACK
|
||||
|
@ -418,7 +420,7 @@ test_node (swbspctx_t *bctx, int node_id, int *clipflags)
|
|||
|
||||
if (node_id < 0)
|
||||
return 0;
|
||||
if (r_node_visframes[node_id] != r_visframecount)
|
||||
if (r_visstate.node_visframes[node_id] != r_visstate.visframecount)
|
||||
return 0;
|
||||
// cull the clipping planes if not trivial accept
|
||||
// FIXME: the compiler is doing a lousy job of optimizing here; it could be
|
||||
|
|
|
@ -203,9 +203,6 @@ R_NewScene (scene_t *scene)
|
|||
if (brush->skytexture)
|
||||
R_InitSky (brush->skytexture);
|
||||
|
||||
// Force a vis update
|
||||
R_MarkLeaves (0, 0, 0, 0);
|
||||
|
||||
R_ClearParticles ();
|
||||
|
||||
r_cnumsurfs = r_maxsurfs;
|
||||
|
|
|
@ -1147,10 +1147,10 @@ bsp_visit_world (const exprval_t **params, exprval_t *result, exprctx_t *ectx)
|
|||
bctx->main_pass.bsp_context = bctx;
|
||||
bctx->main_pass.entqueue = r_ent_queue;
|
||||
bctx->main_pass.position = r_refdef.frame.position;
|
||||
bctx->main_pass.vis_frame = r_visframecount;
|
||||
bctx->main_pass.face_frames = r_face_visframes;
|
||||
bctx->main_pass.leaf_frames = r_leaf_visframes;
|
||||
bctx->main_pass.node_frames = r_node_visframes;
|
||||
bctx->main_pass.vis_frame = r_visstate.visframecount;
|
||||
bctx->main_pass.face_frames = r_visstate.face_visframes;
|
||||
bctx->main_pass.leaf_frames = r_visstate.leaf_visframes;
|
||||
bctx->main_pass.node_frames = r_visstate.node_visframes;
|
||||
bctx->main_pass.entid_data = bframe->entid_data;
|
||||
bctx->main_pass.entid_count = 0;
|
||||
|
||||
|
|
|
@ -79,9 +79,6 @@ Vulkan_NewScene (scene_t *scene, vulkan_ctx_t *ctx)
|
|||
r_refdef.worldmodel = scene->worldmodel;
|
||||
EntQueue_Clear (r_ent_queue);
|
||||
|
||||
// Force a vis update
|
||||
R_MarkLeaves (0, 0, 0, 0);
|
||||
|
||||
R_ClearParticles ();
|
||||
Vulkan_RegisterTextures (scene->models, scene->num_models, ctx);
|
||||
//Vulkan_BuildLightmaps (scene->models, scene->num_models, ctx);
|
||||
|
|
Loading…
Reference in a new issue