[renderer] Clean up most uses of currententity

Just some brush model related code in the software renderer remaining.
This commit is contained in:
Bill Currie 2022-03-11 15:07:38 +09:00
parent 3bdec49587
commit 64666cfa5b
7 changed files with 63 additions and 73 deletions

View file

@ -38,11 +38,12 @@ struct vulkan_ctx_s;
struct model_s;
struct mod_brush_s;
struct msurface_s;
struct transform_s;
void Vulkan_lightmap_init (struct vulkan_ctx_s *ctx);
void Vulkan_BuildLightmaps (struct model_s **models, int num_models, struct vulkan_ctx_s *ctx);
void Vulkan_CalcLightmaps (struct vulkan_ctx_s *ctx);
void Vulkan_BuildLightMap (struct mod_brush_s *brush, struct msurface_s *surf, struct vulkan_ctx_s *ctx);
void Vulkan_BuildLightMap (const struct transform_s *transform, struct mod_brush_s *brush, struct msurface_s *surf, struct vulkan_ctx_s *ctx);
VkImageView Vulkan_LightmapImageView (struct vulkan_ctx_s *ctx) __attribute__((pure));
void Vulkan_FlushLightmaps (struct vulkan_ctx_s *ctx);

View file

@ -143,7 +143,7 @@ void R_SetFrustum (void);
void R_SpriteBegin (void);
void R_SpriteEnd (void);
void R_DrawSprite (const vec3_t relvieworg);
void R_DrawSprite (entity_t *ent);
void R_RenderFace (msurface_t *fa, int clipflags);
void R_RenderPoly (msurface_t *fa, int clipflags);
void R_RenderBmodelFace (bedge_t *pedges, msurface_t *psurf);
@ -160,8 +160,8 @@ void R_DrawSolidClippedSubmodelPolygons (model_t *pmodel);
void R_AddPolygonEdges (emitpoint_t *pverts, int numverts, int miplevel);
surf_t *R_GetSurf (void);
void R_AliasClipAndProjectFinalVert (finalvert_t *fv, auxvert_t *av);
void R_AliasDrawModel (const vec3_t relvieworg, alight_t *plighting);
void R_IQMDrawModel (const vec3_t relvieworg, alight_t *plighting);
void R_AliasDrawModel (entity_t *ent, alight_t *plighting);
void R_IQMDrawModel (entity_t *ent, alight_t *plighting);
maliasskindesc_t *R_AliasGetSkindesc (animation_t *animation, int skinnum, aliashdr_t *hdr);
maliasframedesc_t *R_AliasGetFramedesc (animation_t *animation, aliashdr_t *hdr);
float R_AliasGetLerpedFrames (animation_t *animation, aliashdr_t *hdr);
@ -237,7 +237,7 @@ extern auxvert_t *pauxverts;
extern float ziscale;
extern float aliastransform[3][4];
qboolean R_AliasCheckBBox (const vec3_t relvieworg);
qboolean R_AliasCheckBBox (entity_t *ent);
// turbulence stuff =======================================
@ -328,7 +328,6 @@ void R_Alias_clip_bottom (finalvert_t *pfv0, finalvert_t *pfv1,
finalvert_t *out);
void R_Alias_clip_top (finalvert_t *pfv0, finalvert_t *pfv1, finalvert_t *out);
void R_AliasSetUpTransform (const vec3_t relvieworg, int trivial_accept);
void R_AliasTransformVector (vec3_t in, vec3_t out);
void R_AliasTransformFinalVert (finalvert_t *fv, trivertx_t *pverts,
stvert_t *pstverts);

View file

@ -82,8 +82,10 @@ static aedge_t aedges[12] = {
{0, 5}, {1, 4}, {2, 7}, {3, 6}
};
static void R_AliasSetUpTransform (entity_t *ent, int trivial_accept);
qboolean
R_AliasCheckBBox (const vec3_t relvieworg)
R_AliasCheckBBox (entity_t *ent)
{
int i, flags, frame, numv;
aliashdr_t *pahdr;
@ -96,16 +98,16 @@ R_AliasCheckBBox (const vec3_t relvieworg)
int minz;
// expand, rotate, and translate points into worldspace
currententity->visibility.trivial_accept = 0;
pmodel = currententity->renderer.model;
ent->visibility.trivial_accept = 0;
pmodel = ent->renderer.model;
if (!(pahdr = pmodel->aliashdr))
pahdr = Cache_Get (&pmodel->cache);
pmdl = (mdl_t *) ((byte *) pahdr + pahdr->model);
R_AliasSetUpTransform (relvieworg, 0);
R_AliasSetUpTransform (ent, 0);
// construct the base bounding box for this frame
frame = currententity->animation.frame;
frame = ent->animation.frame;
// TODO: don't repeat this check when drawing?
if ((frame >= pmdl->numframes) || (frame < 0)) {
Sys_MaskPrintf (SYS_dev, "No such frame %d %s\n", frame, pmodel->path);
@ -220,11 +222,11 @@ R_AliasCheckBBox (const vec3_t relvieworg)
return false; // trivial reject off one side
}
currententity->visibility.trivial_accept = !anyclip & !zclipped;
ent->visibility.trivial_accept = !anyclip & !zclipped;
if (currententity->visibility.trivial_accept) {
if (ent->visibility.trivial_accept) {
if (minz > (r_aliastransition + (pmdl->size * r_resfudge))) {
currententity->visibility.trivial_accept |= 2;
ent->visibility.trivial_accept |= 2;
}
}
@ -350,8 +352,8 @@ R_AliasPreparePoints (void)
}
}
void
R_AliasSetUpTransform (const vec3_t relvieworg, int trivial_accept)
static void
R_AliasSetUpTransform (entity_t *ent, int trivial_accept)
{
int i;
float rotationmatrix[3][4], t2matrix[3][4];
@ -359,7 +361,7 @@ R_AliasSetUpTransform (const vec3_t relvieworg, int trivial_accept)
static float viewmatrix[3][4];
mat4f_t mat;
Transform_GetWorldMatrix (currententity->transform, mat);
Transform_GetWorldMatrix (ent->transform, mat);
VectorCopy (mat[0], alias_forward);
VectorNegate (mat[1], alias_right);
VectorCopy (mat[2], alias_up);
@ -380,9 +382,9 @@ R_AliasSetUpTransform (const vec3_t relvieworg, int trivial_accept)
t2matrix[i][2] = alias_up[i];
}
t2matrix[0][3] = -relvieworg[0];
t2matrix[1][3] = -relvieworg[1];
t2matrix[2][3] = -relvieworg[2];
t2matrix[0][3] = r_entorigin[0] - r_refdef.viewposition[0];
t2matrix[1][3] = r_entorigin[1] - r_refdef.viewposition[1];
t2matrix[2][3] = r_entorigin[2] - r_refdef.viewposition[2];
// FIXME: can do more efficiently than full concatenation
R_ConcatTransforms (t2matrix, tmatrix, rotationmatrix);
@ -621,9 +623,8 @@ R_AliasSetupFrame (entity_t *ent)
void
R_AliasDrawModel (const vec3_t relvieworg, alight_t *plighting)
R_AliasDrawModel (entity_t *ent, alight_t *plighting)
{
entity_t *ent = currententity;
int size;
finalvert_t *finalverts;
@ -646,7 +647,7 @@ R_AliasDrawModel (const vec3_t relvieworg, alight_t *plighting)
pauxverts = (auxvert_t *) &pfinalverts[pmdl->numverts + 1];
R_AliasSetupSkin (ent);
R_AliasSetUpTransform (relvieworg, ent->visibility.trivial_accept);
R_AliasSetUpTransform (ent, ent->visibility.trivial_accept);
R_AliasSetupLighting (plighting);
R_AliasSetupFrame (ent);

View file

@ -242,7 +242,7 @@ R_IQMSetupLighting (entity_t *ent, alight_t *plighting)
}
static void
R_IQMSetUpTransform (const vec3_t relvieworg, int trivial_accept)
R_IQMSetUpTransform (entity_t *ent, int trivial_accept)
{
int i;
float rotationmatrix[3][4];
@ -250,7 +250,7 @@ R_IQMSetUpTransform (const vec3_t relvieworg, int trivial_accept)
vec3_t forward, left, up;
mat4f_t mat;
Transform_GetWorldMatrix (currententity->transform, mat);
Transform_GetWorldMatrix (ent->transform, mat);
VectorCopy (mat[0], forward);
VectorCopy (mat[1], left);
VectorCopy (mat[2], up);
@ -263,9 +263,9 @@ R_IQMSetUpTransform (const vec3_t relvieworg, int trivial_accept)
rotationmatrix[i][2] = up[i];
}
rotationmatrix[0][3] = -relvieworg[0];
rotationmatrix[1][3] = -relvieworg[1];
rotationmatrix[2][3] = -relvieworg[2];
rotationmatrix[0][3] = r_entorigin[0] - r_refdef.viewposition[0];
rotationmatrix[1][3] = r_entorigin[1] - r_refdef.viewposition[1];
rotationmatrix[2][3] = r_entorigin[2] - r_refdef.viewposition[2];
// TODO: should be global, set when vright, etc., set
VectorCopy (vright, viewmatrix[0]);
@ -297,9 +297,8 @@ R_IQMSetUpTransform (const vec3_t relvieworg, int trivial_accept)
}
void
R_IQMDrawModel (const vec3_t relvieworg, alight_t *plighting)
R_IQMDrawModel (entity_t *ent, alight_t *plighting)
{
entity_t *ent = currententity;
model_t *model = ent->renderer.model;
iqm_t *iqm = (iqm_t *) model->aliashdr;
swiqm_t *sw = (swiqm_t *) iqm->extra_data;
@ -320,7 +319,7 @@ R_IQMDrawModel (const vec3_t relvieworg, alight_t *plighting)
(((intptr_t) &pfinalverts[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
pauxverts = (auxvert_t *) &pfinalverts[iqm->num_verts + 1];
R_IQMSetUpTransform (relvieworg, ent->visibility.trivial_accept);
R_IQMSetUpTransform (ent, ent->visibility.trivial_accept);
R_IQMSetupLighting (ent, plighting);
r_affinetridesc.drawtype = (ent->visibility.trivial_accept == 3) &&

View file

@ -343,13 +343,11 @@ R_ViewChanged (void)
static inline void
draw_sprite_entity (entity_t *ent)
{
vec3_t org;
VectorSubtract (r_refdef.viewposition, r_entorigin, org);
R_DrawSprite (org);
R_DrawSprite (ent);
}
static inline void
setup_lighting (alight_t *lighting)
setup_lighting (entity_t *ent, alight_t *lighting)
{
float minlight = 0;
int j;
@ -358,8 +356,7 @@ setup_lighting (alight_t *lighting)
float add;
float lightvec[3] = { -1, 0, 0 };
minlight = max (currententity->renderer.model->min_light,
currententity->renderer.min_light);
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),
@ -390,32 +387,26 @@ setup_lighting (alight_t *lighting)
static inline void
draw_alias_entity (entity_t *ent)
{
vec3_t org;
VectorSubtract (r_refdef.viewposition, r_entorigin, org);
// see if the bounding box lets us trivially reject, also
// sets trivial accept status
currententity->visibility.trivial_accept = 0; //FIXME
if (R_AliasCheckBBox (org)) {
ent->visibility.trivial_accept = 0; //FIXME
if (R_AliasCheckBBox (ent)) {
alight_t lighting;
setup_lighting (&lighting);
R_AliasDrawModel (org, &lighting);
setup_lighting (ent, &lighting);
R_AliasDrawModel (ent, &lighting);
}
}
static inline void
draw_iqm_entity (entity_t *ent)
{
vec3_t org;
VectorSubtract (r_refdef.viewposition, r_entorigin, org);
// see if the bounding box lets us trivially reject, also
// sets trivial accept status
currententity->visibility.trivial_accept = 0; //FIXME
ent->visibility.trivial_accept = 0; //FIXME
alight_t lighting;
setup_lighting (&lighting);
R_IQMDrawModel (org, &lighting);
setup_lighting (ent, &lighting);
R_IQMDrawModel (ent, &lighting);
}
static void
@ -431,7 +422,6 @@ R_DrawEntitiesOnList (void)
entity_t *ent = r_ent_queue->ent_queues[mod_##type_name].a[i]; \
VectorCopy (Transform_GetWorldPosition (ent->transform), \
r_entorigin); \
currententity = ent; \
draw_##type_name##_entity (ent); \
} \
} while (0)
@ -452,24 +442,24 @@ R_DrawViewModel (void)
float add;
float minlight;
dlight_t *dl;
entity_t *viewent;
if (vr_data.inhibit_viewmodel
|| !r_drawviewmodel->int_val
|| !r_drawentities->int_val)
return;
currententity = vr_data.view_model;
if (!currententity->renderer.model)
viewent = vr_data.view_model;
if (!viewent->renderer.model)
return;
VectorCopy (Transform_GetWorldPosition (currententity->transform),
r_entorigin);
VectorCopy (Transform_GetWorldPosition (viewent->transform), r_entorigin);
VectorCopy (vup, viewlightvec);
VectorNegate (viewlightvec, viewlightvec);
minlight = max (currententity->renderer.min_light,
currententity->renderer.model->min_light);
minlight = max (viewent->renderer.min_light,
viewent->renderer.model->min_light);
j = max (R_LightPoint (&r_worldentity.renderer.model->brush,
r_entorigin), minlight * 128);
@ -501,9 +491,7 @@ R_DrawViewModel (void)
r_viewlighting.plightvec = lightvec;
vec3_t org;
VectorSubtract (r_refdef.viewposition, r_entorigin, org);
R_AliasDrawModel (org, &r_viewlighting);
R_AliasDrawModel (viewent, &r_viewlighting);
}
static int
@ -596,8 +584,6 @@ R_DrawBrushEntitiesOnList (void)
VectorCopy (origin, r_entorigin);
VectorSubtract (r_refdef.viewposition, r_entorigin, modelorg);
// FIXME: is this needed?
VectorCopy (modelorg, r_worldmodelorg);
r_pcurrentvertbase = brush->vertexes;
// FIXME: stop transforming twice

View file

@ -241,17 +241,19 @@ R_SetupAndDrawSprite (const vec3_t relvieworg)
}
void
R_DrawSprite (const vec3_t relvieworg)
R_DrawSprite (entity_t *ent)
{
msprite_t *sprite = currententity->renderer.model->cache.data;
msprite_t *sprite = ent->renderer.model->cache.data;
vec3_t relvieworg;
r_spritedesc.pspriteframe = R_GetSpriteFrame (sprite,
&currententity->animation);
VectorSubtract (r_refdef.viewposition, r_entorigin, relvieworg);
r_spritedesc.pspriteframe = R_GetSpriteFrame (sprite, &ent->animation);
sprite_width = r_spritedesc.pspriteframe->width;
sprite_height = r_spritedesc.pspriteframe->height;
if (!R_BillboardFrame (currententity, sprite->type, relvieworg,
if (!R_BillboardFrame (ent, sprite->type, relvieworg,
r_spritedesc.vup,
r_spritedesc.vright,
r_spritedesc.vpn)) {

View file

@ -57,7 +57,8 @@
#define LUXEL_SIZE 4
static inline void
add_dynamic_lights (msurface_t *surf, float *block)
add_dynamic_lights (const transform_t *transform, msurface_t *surf,
float *block)
{
unsigned lnum;
int sd, td;
@ -74,9 +75,9 @@ add_dynamic_lights (msurface_t *surf, float *block)
tex = surf->texinfo;
plane = surf->plane;
if (currententity->transform) {
if (transform) {
//FIXME give world entity a transform
entorigin = Transform_GetWorldPosition (currententity->transform);
entorigin = Transform_GetWorldPosition (transform);
}
for (lnum = 0; lnum < r_maxdlights; lnum++) {
@ -130,7 +131,8 @@ add_dynamic_lights (msurface_t *surf, float *block)
}
void
Vulkan_BuildLightMap (mod_brush_t *brush, msurface_t *surf, vulkan_ctx_t *ctx)
Vulkan_BuildLightMap (const transform_t *transform, mod_brush_t *brush,
msurface_t *surf, vulkan_ctx_t *ctx)
{
bspctx_t *bctx = ctx->bsp_context;
int smax, tmax, size;
@ -178,7 +180,7 @@ Vulkan_BuildLightMap (mod_brush_t *brush, msurface_t *surf, vulkan_ctx_t *ctx)
}
// add all the dynamic lights
if (surf->dlightframe == r_framecount) {
add_dynamic_lights (surf, block);
add_dynamic_lights (transform, surf, block);
}
}
@ -267,7 +269,7 @@ Vulkan_BuildLightmaps (model_t **models, int num_models, vulkan_ctx_t *ctx)
for (i = 0; i < brush->numsurfaces; i++) {
msurface_t *surf = brush->surfaces + i;
if (surf->lightpic) {
Vulkan_BuildLightMap (brush, surf, ctx);
Vulkan_BuildLightMap (0, brush, surf, ctx);
}
}
}