From 5dab7ccaf7377b449285fe26a2a76c29cf9a6f11 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 20 Nov 2001 08:02:35 +0000 Subject: [PATCH] precalculate smoe model specific info (wether the whole model is fullbright, if it should have shadows, whether it should be scaled/translated (gl eyes), and the minimum lighting (player)). give a 1.9% speedup in null renderer. --- include/QF/model.h | 18 ++++++------- libs/models/alias/gl_mesh.c | 2 +- libs/models/alias/gl_model_alias.c | 9 +++++++ libs/models/alias/model_alias.c | 4 ++- libs/models/alias/sw32_model_alias.c | 7 ++++- libs/models/alias/sw_model_alias.c | 7 ++++- libs/models/model.c | 19 ++++++++++++++ libs/video/renderer/gl/gl_mod_alias.c | 37 ++++++++------------------- 8 files changed, 63 insertions(+), 40 deletions(-) diff --git a/include/QF/model.h b/include/QF/model.h index 16318170b..4e4d9b837 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -379,21 +379,20 @@ typedef struct model_s int flags; -// +// lighting info + float min_light; + byte shadow_alpha; // 255 = 1.0 + byte fullbright; + // volume occupied by the model graphics -// vec3_t mins, maxs; float radius; -// // solid volume for clipping -// qboolean clipbox; vec3_t clipmins, clipmaxs; -// // brush model -// int firstmodelsurface, nummodelsurfaces; int numsubmodels; @@ -441,9 +440,7 @@ typedef struct model_s unsigned int checksum; unsigned int checksum2; -// // additional model data -// cache_user_t cache; // only access through Mod_Extradata } model_t; @@ -468,8 +465,9 @@ void *Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame); void *Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame); void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex); -void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, - int _s); +void Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, + int _s); +void Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr); diff --git a/libs/models/alias/gl_mesh.c b/libs/models/alias/gl_mesh.c index f32c5db12..903fd9f64 100644 --- a/libs/models/alias/gl_mesh.c +++ b/libs/models/alias/gl_mesh.c @@ -342,7 +342,7 @@ BuildTris (void) } void -GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) +Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) { int i, j; int *cmds; diff --git a/libs/models/alias/gl_model_alias.c b/libs/models/alias/gl_model_alias.c index 6c0ef9590..6fa7bf303 100644 --- a/libs/models/alias/gl_model_alias.c +++ b/libs/models/alias/gl_model_alias.c @@ -297,3 +297,12 @@ Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame) } return ptemp; } + +void +Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) +{ + if (strequal (m->name, "progs/eyes.mdl")) { + hdr->mdl.scale_origin[2] -= (22 + 8); + VectorScale (hdr->mdl.scale, 2, hdr->mdl.scale); + } +} diff --git a/libs/models/alias/model_alias.c b/libs/models/alias/model_alias.c index a8499f3ce..8b8fe9b5d 100644 --- a/libs/models/alias/model_alias.c +++ b/libs/models/alias/model_alias.c @@ -205,7 +205,9 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator) mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16; // build the draw lists - GL_MakeAliasModelDisplayLists (mod, pheader, buffer, com_filesize); + Mod_MakeAliasModelDisplayLists (mod, pheader, buffer, com_filesize); + + Mod_FinalizeAliasModel (mod, pheader); // move the complete, relocatable alias model to the cache end = Hunk_LowMark (); diff --git a/libs/models/alias/sw32_model_alias.c b/libs/models/alias/sw32_model_alias.c index c5d204bb7..c951504d2 100644 --- a/libs/models/alias/sw32_model_alias.c +++ b/libs/models/alias/sw32_model_alias.c @@ -159,7 +159,7 @@ Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex) } void -GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) +Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) { int i, j; stvert_t *pstverts; @@ -279,3 +279,8 @@ Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame) return ptemp; } + +void +Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) +{ +} diff --git a/libs/models/alias/sw_model_alias.c b/libs/models/alias/sw_model_alias.c index d77c26391..36cf7c145 100644 --- a/libs/models/alias/sw_model_alias.c +++ b/libs/models/alias/sw_model_alias.c @@ -155,7 +155,7 @@ Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex) } void -GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) +Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s) { int i, j; stvert_t *pstverts; @@ -274,3 +274,8 @@ Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame) return ptemp; } + +void +Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) +{ +} diff --git a/libs/models/model.c b/libs/models/model.c index e60509e75..317bcd207 100644 --- a/libs/models/model.c +++ b/libs/models/model.c @@ -48,6 +48,8 @@ static const char rcsid[] = #include "QF/sys.h" #include "QF/vfs.h" +#include "compat.h" + void Mod_LoadAliasModel (model_t *mod, void *buf, cache_allocator_t allocator); void Mod_LoadSpriteModel (model_t *mod, void *buf); void Mod_LoadBrushModel (model_t *mod, void *buf); @@ -189,6 +191,23 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator) loadmodel = mod; // fill it in + if (strequal (mod->name, "progs/grenade.mdl")) { + mod->shadow_alpha = 0; + } else { + mod->shadow_alpha = 255; + } + if (strnequal (mod->name, "progs/flame", 11) + || strnequal (mod->name, "progs/bolt", 10)) { + mod->fullbright = 1; + mod->shadow_alpha = 0; + } else { + mod->fullbright = 0; + } + if (strequal (mod->name, "progs/player.mdl")) { + mod->min_light = 8; + } else { + mod->min_light = 0; + } // call the apropriate loader mod->needload = false; diff --git a/libs/video/renderer/gl/gl_mod_alias.c b/libs/video/renderer/gl/gl_mod_alias.c index 964c52e45..74d8d9bed 100644 --- a/libs/video/renderer/gl/gl_mod_alias.c +++ b/libs/video/renderer/gl/gl_mod_alias.c @@ -387,7 +387,6 @@ R_DrawAliasModel (entity_t *e, qboolean cull) int fb_texture = 0; aliashdr_t *paliashdr; model_t *clmodel; - qboolean modelIsFullbright = false; vec3_t dist, mins, maxs; vert_order_t *vo; @@ -409,9 +408,7 @@ R_DrawAliasModel (entity_t *e, qboolean cull) VectorCopy (e->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); - if (strnequal (clmodel->name, "progs/flame", 11) - || strnequal (clmodel->name, "progs/bolt", 10)) { - modelIsFullbright = true; + if (clmodel->fullbright) { shadelight = 1.0; // make certain models full brightness always } else { // get lighting information @@ -436,9 +433,8 @@ R_DrawAliasModel (entity_t *e, qboolean cull) shadelight = min (shadelight, 100); // was 200 // never allow players to go totally black - if (strequal (clmodel->name, "progs/player.mdl")) { - shadelight = max (shadelight, 8); - } + shadelight = max (shadelight, clmodel->min_light); + shadelight *= 0.005; shadedots = r_avertexnormal_dots[(int) (e->angles[1] * @@ -459,20 +455,11 @@ R_DrawAliasModel (entity_t *e, qboolean cull) qfglPushMatrix (); R_RotateForEntity (e); - if (strequal (clmodel->name, "progs/eyes.mdl")) { - qfglTranslatef (paliashdr->mdl.scale_origin[0], - paliashdr->mdl.scale_origin[1], - paliashdr->mdl.scale_origin[2] - (22 + 8)); - // double size of eyes, since they are really hard to see in GL - qfglScalef (paliashdr->mdl.scale[0] * 2, paliashdr->mdl.scale[1] * 2, - paliashdr->mdl.scale[2] * 2); - } else { - qfglTranslatef (paliashdr->mdl.scale_origin[0], - paliashdr->mdl.scale_origin[1], - paliashdr->mdl.scale_origin[2]); - qfglScalef (paliashdr->mdl.scale[0], paliashdr->mdl.scale[1], - paliashdr->mdl.scale[2]); - } + qfglTranslatef (paliashdr->mdl.scale_origin[0], + paliashdr->mdl.scale_origin[1], + paliashdr->mdl.scale_origin[2]); + qfglScalef (paliashdr->mdl.scale[0], paliashdr->mdl.scale[1], + paliashdr->mdl.scale[2]); anim = (int) (r_realtime * 10) & 3; @@ -483,7 +470,7 @@ R_DrawAliasModel (entity_t *e, qboolean cull) } texture = paliashdr->gl_texturenum[skinnum][anim]; - if (gl_fb_models->int_val && !modelIsFullbright) + if (gl_fb_models->int_val && !clmodel->fullbright) fb_texture = paliashdr->gl_fb_texturenum[skinnum][anim]; // we can't dynamically colormap textures, so they are cached @@ -519,16 +506,14 @@ R_DrawAliasModel (entity_t *e, qboolean cull) if (r_shadows->int_val) { // torches, grenades, and lightning bolts do not have shadows - if (modelIsFullbright) - return; - if (strequal (clmodel->name, "progs/grenade.mdl")) + if (!clmodel->shadow_alpha) return; qfglPushMatrix (); R_RotateForEntity (e); qfglDisable (GL_TEXTURE_2D); - color_black[3] = 128; + color_black[3] = (clmodel->shadow_alpha + 1) / 2; qfglColor4ubv (color_black); if (gl_lerp_anim->int_val) {