[renderer] move r_worldentity and r_viewleaf into refdef

More cleanup of globals that seem to be quake specific.
This commit is contained in:
Bill Currie 2022-03-14 15:27:43 +09:00
parent 2641fe3241
commit 7402fcfd0c
22 changed files with 78 additions and 73 deletions

View file

@ -219,6 +219,9 @@ typedef struct {
int drawflat;
float fov_x, fov_y;
struct model_s *worldmodel;
struct mleaf_s *viewleaf;
} refdef_t;
// color shifts =============================================================
@ -240,8 +243,6 @@ typedef struct {
extern struct texture_s *r_notexture_mip;
extern entity_t r_worldentity;
void R_Init (void);
struct vid_internal_s;
void R_LoadModule (struct vid_internal_s *vid_internal);

View file

@ -286,8 +286,6 @@ extern int r_frustum_indexes[4*6];
extern int r_maxsurfsseen, r_maxedgesseen;
extern qboolean r_dowarpold, r_viewchanged;
extern mleaf_t *r_viewleaf;
extern int r_clipflags;
extern int r_dlightframecount;

View file

@ -598,7 +598,7 @@ gl_overbright_f (cvar_t *var)
}
}
brush = &r_worldentity.renderer.model->brush;
brush = &r_refdef.worldmodel->brush;
for (unsigned i = 0; i < brush->numsurfaces; i++) {
msurface_t *surf = brush->surfaces + i;

View file

@ -449,7 +449,7 @@ gl_R_DrawAliasModel (entity_t *e)
float lightadj;
// get lighting information
R_LightPoint (&r_worldentity.renderer.model->brush, &origin[0]);//FIXME
R_LightPoint (&r_refdef.worldmodel->brush, &origin[0]);//FIXME
lightadj = (ambientcolor[0] + ambientcolor[1] + ambientcolor[2]) / 765.0;

View file

@ -332,7 +332,7 @@ gl_R_SetupFrame (void)
R_SetFrustum ();
r_viewleaf = Mod_PointInLeaf (&position[0], r_worldentity.renderer.model);
r_refdef.viewleaf = Mod_PointInLeaf (&position[0], r_refdef.worldmodel);
}
static void
@ -456,7 +456,7 @@ R_RenderView_ (void)
if (r_norefresh->int_val) {
return;
}
if (!r_worldentity.renderer.model) {
if (!r_refdef.worldmodel) {
return;
}
@ -784,7 +784,7 @@ R_RenderViewFishEye (void)
void
gl_R_ClearState (void)
{
r_worldentity.renderer.model = 0;
r_refdef.worldmodel = 0;
R_ClearEfrags ();
R_ClearDlights ();
R_ClearParticles ();

View file

@ -219,8 +219,7 @@ gl_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
for (int i = 0; i < 256; i++)
d_lightstylevalue[i] = 264; // normal light value
memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.renderer.model = worldmodel;
r_refdef.worldmodel = worldmodel;
brush = &worldmodel->brush;
// clear out efrags in case the level hasn't been reloaded
@ -228,7 +227,7 @@ gl_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
brush->leafs[i].efrags = NULL;
// Force a vis update
r_viewleaf = NULL;
r_refdef.viewleaf = NULL;
R_MarkLeaves ();
R_ClearParticles ();
@ -257,7 +256,7 @@ gl_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
continue;
if (*models[i]->path == '*')
continue;
if (models[i] != r_worldentity.renderer.model
if (models[i] != r_refdef.worldmodel
&& models[i]->type == mod_brush)
register_textures (&models[i]->brush);
}

View file

@ -723,7 +723,7 @@ gl_R_DrawWorld (void)
glbspctx_t bctx = { };
memset (&worldent, 0, sizeof (worldent));
worldent.renderer.model = r_worldentity.renderer.model;
worldent.renderer.model = r_refdef.worldmodel;
sky_chain = 0;
sky_chain_tail = &sky_chain;
@ -732,7 +732,7 @@ gl_R_DrawWorld (void)
}
bctx.brush = &worldent.renderer.model->brush;
bctx.entity = &r_worldentity;
bctx.entity = &worldent;
R_VisitWorldNodes (&bctx);

View file

@ -161,7 +161,7 @@ calc_lighting (entity_t *ent, float *ambient, float *shadelight,
entorigin = Transform_GetWorldPosition (ent->transform);
VectorSet ( -1, 0, 0, lightvec); //FIXME
light = R_LightPoint (&r_worldentity.renderer.model->brush, &entorigin[0]);
light = R_LightPoint (&r_refdef.worldmodel->brush, &entorigin[0]);
*ambient = max (light, max (ent->renderer.model->min_light,
ent->renderer.min_light) * 128);
*shadelight = *ambient;

View file

@ -433,9 +433,9 @@ glsl_R_RegisterTextures (model_t **models, int num_models)
mod_brush_t *brush;
glsl_R_ClearTextures ();
glsl_R_InitSurfaceChains (&r_worldentity.renderer.model->brush);
glsl_R_InitSurfaceChains (&r_refdef.worldmodel->brush);
glsl_R_AddTexture (r_notexture_mip);
register_textures (&r_worldentity.renderer.model->brush);
register_textures (&r_refdef.worldmodel->brush);
for (i = 0; i < num_models; i++) {
m = models[i];
if (!m)
@ -444,7 +444,7 @@ glsl_R_RegisterTextures (model_t **models, int num_models)
if (*m->path == '*')
continue;
// world has already been done, not interested in non-brush models
if (m == r_worldentity.renderer.model || m->type != mod_brush)
if (m == r_refdef.worldmodel || m->type != mod_brush)
continue;
brush = &m->brush;
brush->numsubmodels = 1; // no support for submodels in non-world model
@ -489,7 +489,7 @@ build_surf_displist (model_t **models, msurface_t *surf, int base,
if (surf->model_index < 0) {
brush = &models[-surf->model_index - 1]->brush;
} else {
brush = &r_worldentity.renderer.model->brush;
brush = &r_refdef.worldmodel->brush;
}
vertices = brush->vertexes;
edges = brush->edges;
@ -588,7 +588,7 @@ glsl_R_BuildDisplayLists (model_t **models, int num_models)
}
surf = brush->surfaces + j;
surf->model_index = dm - brush->submodels;
if (!surf->model_index && m != r_worldentity.renderer.model)
if (!surf->model_index && m != r_refdef.worldmodel)
surf->model_index = -1 - i; // instanced model
tex = surf->texinfo->texture->render;
CHAIN_SURF_F2B (surf, tex->tex_chain);
@ -1140,10 +1140,10 @@ glsl_R_DrawWorld (void)
clear_texture_chains (); // do this first for water and skys
memset (&worldent, 0, sizeof (worldent));
worldent.renderer.model = r_worldentity.renderer.model;
worldent.renderer.model = r_refdef.worldmodel;
bctx.brush = &worldent.renderer.model->brush;
bctx.entity = &r_worldentity;
bctx.entity = &worldent;
R_VisitWorldNodes (&bctx);
if (r_drawentities->int_val) {

View file

@ -225,7 +225,7 @@ glsl_R_DrawIQM (entity_t *ent)
entorigin = mat[3];
mmulf (mvp_mat, iqm_vp, mat);
R_LightPoint (&r_worldentity.renderer.model->brush, &entorigin[0]);//FIXME min_light?
R_LightPoint (&r_refdef.worldmodel->brush, &entorigin[0]);//FIXME min_light?
VectorScale (ambientcolor, 1/255.0, ambientcolor);
R_FindNearLights (&entorigin[0], MAX_IQM_LIGHTS, lights);//FIXME

View file

@ -104,7 +104,7 @@ glsl_R_SetupFrame (void)
R_SetFrustum ();
r_viewleaf = Mod_PointInLeaf (&position[0], r_worldentity.renderer.model);
r_refdef.viewleaf = Mod_PointInLeaf (&position[0], r_refdef.worldmodel);
}
static void
@ -182,7 +182,7 @@ glsl_R_RenderView (void)
double t[10] = {};
int speeds = r_speeds->int_val;
if (!r_worldentity.renderer.model) {
if (!r_refdef.worldmodel) {
return;
}
@ -275,11 +275,10 @@ glsl_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
for (i = 0; i < 256; i++)
d_lightstylevalue[i] = 264; // normal light value
memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.renderer.model = worldmodel;
r_refdef.worldmodel = worldmodel;
// Force a vis update
r_viewleaf = NULL;
r_refdef.viewleaf = NULL;
R_MarkLeaves ();
R_ClearParticles ();
@ -296,7 +295,7 @@ glsl_R_LineGraph (int x, int y, int *h_vals, int count, int height)
void
glsl_R_ClearState (void)
{
r_worldentity.renderer.model = 0;
r_refdef.worldmodel = 0;
R_ClearEfrags ();
R_ClearDlights ();
R_ClearParticles ();

View file

@ -42,7 +42,6 @@
#include "r_internal.h"
mvertex_t *r_pcurrentvertbase;
mleaf_t *r_viewleaf;
static mleaf_t *r_oldviewleaf;
static set_t *solid;
@ -54,14 +53,14 @@ R_MarkLeaves (void)
mleaf_t *leaf;
mnode_t *node;
msurface_t **mark;
mod_brush_t *brush = &r_worldentity.renderer.model->brush;
mod_brush_t *brush = &r_refdef.worldmodel->brush;
if (r_oldviewleaf == r_viewleaf && !r_novis->int_val)
if (r_oldviewleaf == r_refdef.viewleaf && !r_novis->int_val)
return;
r_visframecount++;
r_oldviewleaf = r_viewleaf;
if (!r_viewleaf)
r_oldviewleaf = r_refdef.viewleaf;
if (!r_refdef.viewleaf)
return;
if (r_novis->int_val) {
@ -73,7 +72,7 @@ R_MarkLeaves (void)
}
vis = solid;
} else
vis = Mod_LeafPVS (r_viewleaf, r_worldentity.renderer.model);
vis = Mod_LeafPVS (r_refdef.viewleaf, r_refdef.worldmodel);
for (unsigned i = 0; i < brush->visleafs; i++) {
if (set_is_member (vis, i)) {

View file

@ -326,7 +326,7 @@ R_PushDlights (const vec3_t entorigin)
if (l->die < r_data->realtime || !l->radius)
continue;
VectorSubtract (l->origin, entorigin, lightorigin);
R_MarkLights (lightorigin, l, i, r_worldentity.renderer.model);
R_MarkLights (lightorigin, l, i, r_refdef.worldmodel);
}
}

View file

@ -65,8 +65,6 @@ vec3_t modelorg; // modelorg is the viewpoint relative to
vec3_t base_modelorg;
vec3_t r_entorigin; // the currently rendering entity in world
// coordinates
entity_t r_worldentity;
// screen size info
refdef_t r_refdef;

View file

@ -40,6 +40,11 @@
#include "r_internal.h"
typedef struct glbspctx_s {
mod_brush_t *brush;
entity_t *entity;
} swbspctx_t;
// current entity info
qboolean insubmodel;
vec3_t r_worldmodelorg;
@ -368,11 +373,12 @@ get_side (mnode_t *node)
}
static void
visit_node (mod_brush_t *brush, mnode_t *node, int side, int clipflags)
visit_node (swbspctx_t *bctx, mnode_t *node, int side, int clipflags)
{
int c;
msurface_t *surf;
entity_t *ent = &r_worldentity;
entity_t *ent = bctx->entity;
mod_brush_t *brush = &ent->renderer.model->brush;
// sneaky hack for side = side ? SURF_PLANEBACK : 0;
side = (~side + 1) & SURF_PLANEBACK;
@ -455,7 +461,7 @@ test_node (mnode_t *node, int *clipflags)
}
static void
R_VisitWorldNodes (mod_brush_t *brush, int clipflags)
R_VisitWorldNodes (swbspctx_t *bctx, int clipflags)
{
typedef struct {
mnode_t *node;
@ -466,6 +472,7 @@ R_VisitWorldNodes (mod_brush_t *brush, int clipflags)
mnode_t *node;
mnode_t *front;
int side, cf;
mod_brush_t *brush = &bctx->entity->renderer.model->brush;
node = brush->nodes;
// +2 for paranoia
@ -489,7 +496,7 @@ R_VisitWorldNodes (mod_brush_t *brush, int clipflags)
}
if (front->contents < 0 && front->contents != CONTENTS_SOLID)
visit_leaf ((mleaf_t *) front);
visit_node (brush, node, side, clipflags);
visit_node (bctx, node, side, clipflags);
node = node->children[!side];
}
if (node->contents < 0 && node->contents != CONTENTS_SOLID)
@ -499,7 +506,7 @@ R_VisitWorldNodes (mod_brush_t *brush, int clipflags)
node = node_ptr->node;
side = node_ptr->side;
clipflags = node_ptr->clipflags;
visit_node (brush, node, side, clipflags);
visit_node (bctx, node, side, clipflags);
node = node->children[!side];
continue;
}
@ -514,15 +521,21 @@ R_RenderWorld (void)
{
int i;
btofpoly_t btofpolys[MAX_BTOFPOLYS];
mod_brush_t *brush;
entity_t *ent = &r_worldentity;
entity_t worldent = {};
entity_t *ent = &worldent;
mod_brush_t *brush = &r_refdef.worldmodel->brush;
swbspctx_t bspctx = {
brush,
ent,
};
worldent.renderer.model = r_refdef.worldmodel;
pbtofpolys = btofpolys;
brush = &r_worldentity.renderer.model->brush;
brush = &r_refdef.worldmodel->brush;
r_pcurrentvertbase = brush->vertexes;
R_VisitWorldNodes (brush, 15);
R_VisitWorldNodes (&bspctx, 15);
// if the driver wants the polygons back to front, play the visible ones
// back in that order

View file

@ -171,8 +171,7 @@ R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
{
mod_brush_t *brush = &worldmodel->brush;
memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.renderer.model = worldmodel;
r_refdef.worldmodel = worldmodel;
// clear out efrags in case the level hasn't been reloaded
for (unsigned i = 0; i < brush->modleafs; i++)
@ -182,7 +181,7 @@ R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
R_InitSky (brush->skytexture);
// Force a vis update
r_viewleaf = NULL;
r_refdef.viewleaf = NULL;
R_MarkLeaves ();
R_ClearParticles ();
@ -364,7 +363,7 @@ setup_lighting (entity_t *ent, alight_t *lighting)
minlight = max (ent->renderer.model->min_light, ent->renderer.min_light);
// 128 instead of 255 due to clamping below
j = max (R_LightPoint (&r_worldentity.renderer.model->brush, r_entorigin),
j = max (R_LightPoint (&r_refdef.worldmodel->brush, r_entorigin),
minlight * 128);
lighting->ambientlight = j;
@ -466,7 +465,7 @@ R_DrawViewModel (void)
minlight = max (viewent->renderer.min_light,
viewent->renderer.model->min_light);
j = max (R_LightPoint (&r_worldentity.renderer.model->brush,
j = max (R_LightPoint (&r_refdef.worldmodel->brush,
r_entorigin), minlight * 128);
r_viewlighting.ambientlight = j;
@ -741,7 +740,7 @@ R_RenderView_ (void)
if (r_norefresh->int_val)
return;
if (!r_worldentity.renderer.model) {
if (!r_refdef.worldmodel) {
return;
}
@ -1153,7 +1152,7 @@ R_RenderViewFishEye (void)
void
R_ClearState (void)
{
r_worldentity.renderer.model = 0;
r_refdef.worldmodel = 0;
R_ClearEfrags ();
R_ClearDlights ();
R_ClearParticles ();

View file

@ -192,10 +192,10 @@ R_SetupFrame (void)
R_SetFrustum ();
// current viewleaf
r_viewleaf = Mod_PointInLeaf (&position[0], r_worldentity.renderer.model);
r_refdef.viewleaf = Mod_PointInLeaf (&position[0], r_refdef.worldmodel);
r_dowarpold = r_dowarp;
r_dowarp = r_waterwarp->int_val && (r_viewleaf->contents <=
r_dowarp = r_waterwarp->int_val && (r_refdef.viewleaf->contents <=
CONTENTS_WATER);
if ((r_dowarp != r_dowarpold) || r_viewchanged) {

View file

@ -161,7 +161,7 @@ R_BuildLightMap (transform_t *transform)
size = smax * tmax;
lightmap = surf->samples;
if (!r_worldentity.renderer.model->brush.lightdata) {
if (!r_refdef.worldmodel->brush.lightdata) {
for (i = 0; i < size; i++)
blocklights[i] = 0;
return;

View file

@ -104,7 +104,7 @@ vulkan_R_Init (void)
static void
vulkan_R_ClearState (void)
{
r_worldentity.renderer.model = 0;
r_refdef.worldmodel = 0;
R_ClearEfrags ();
R_ClearDlights ();
R_ClearParticles ();

View file

@ -275,7 +275,7 @@ Vulkan_RegisterTextures (model_t **models, int num_models, vulkan_ctx_t *ctx)
{
int i;
model_t *m;
mod_brush_t *brush = &r_worldentity.renderer.model->brush;
mod_brush_t *brush = &r_refdef.worldmodel->brush;
clear_textures (ctx);
init_surface_chains (brush, ctx);
@ -289,7 +289,7 @@ Vulkan_RegisterTextures (model_t **models, int num_models, vulkan_ctx_t *ctx)
if (*m->path == '*')
continue;
// world has already been done, not interested in non-brush models
if (m == r_worldentity.renderer.model || m->type != mod_brush)
if (m == r_refdef.worldmodel || m->type != mod_brush)
continue;
brush = &m->brush;
brush->numsubmodels = 1; // no support for submodels in non-world model
@ -342,7 +342,7 @@ build_surf_displist (model_t **models, msurface_t *surf, int base,
brush = &models[~surf->model_index]->brush;
} else {
// main or sub model
brush = &r_worldentity.renderer.model->brush;
brush = &r_refdef.worldmodel->brush;
}
vertices = brush->vertexes;
edges = brush->edges;
@ -441,7 +441,7 @@ Vulkan_BuildDisplayLists (model_t **models, int num_models, vulkan_ctx_t *ctx)
}
surf = brush->surfaces + j;
surf->model_index = dm - brush->submodels;
if (!surf->model_index && m != r_worldentity.renderer.model) {
if (!surf->model_index && m != r_refdef.worldmodel) {
surf->model_index = -1 - i; // instanced model
}
tex = surf->texinfo->texture->render;
@ -1031,10 +1031,10 @@ Vulkan_DrawWorld (qfv_renderframe_t *rFrame)
bframe->index_count = 0;
memset (&worldent, 0, sizeof (worldent));
worldent.renderer.model = r_worldentity.renderer.model;
brush = &r_worldentity.renderer.model->brush;
worldent.renderer.model = r_refdef.worldmodel;
brush = &r_refdef.worldmodel->brush;
bctx->entity = &r_worldentity;
bctx->entity = &worldent;
bctx->transform = 0;
bctx->color = 0;

View file

@ -90,8 +90,8 @@ find_visible_lights (vulkan_ctx_t *ctx)
lightingctx_t *lctx = ctx->lighting_context;
lightingframe_t *lframe = &lctx->frames.a[ctx->curFrame];
mleaf_t *leaf = r_viewleaf;
model_t *model = r_worldentity.renderer.model;
mleaf_t *leaf = r_refdef.viewleaf;
model_t *model = r_refdef.worldmodel;
if (!leaf || !model) {
return;

View file

@ -73,7 +73,7 @@ setup_frame (vulkan_ctx_t *ctx)
R_SetFrustum ();
vec4f_t position = r_refdef.frame.position;
r_viewleaf = Mod_PointInLeaf (&position[0], r_worldentity.renderer.model);
r_refdef.viewleaf = Mod_PointInLeaf (&position[0], r_refdef.worldmodel);
}
static void
@ -131,7 +131,7 @@ Vulkan_RenderView (qfv_renderframe_t *rFrame)
double t[10] = {};
int speeds = r_speeds->int_val;
if (!r_worldentity.renderer.model) {
if (!r_refdef.worldmodel) {
return;
}
@ -187,11 +187,10 @@ Vulkan_NewMap (model_t *worldmodel, struct model_s **models, int num_models,
d_lightstylevalue[i] = 264; // normal light value
}
memset (&r_worldentity, 0, sizeof (r_worldentity));
r_worldentity.renderer.model = worldmodel;
r_refdef.worldmodel = worldmodel;
// Force a vis update
r_viewleaf = NULL;
r_refdef.viewleaf = NULL;
R_MarkLeaves ();
R_ClearParticles ();