Make alias model caching optional.

For now, only the glsl loader disables caching, but it stores the frame
vertices in GL memory, so its hunk usage is relatively lower (and will be
lower still when I get skins sorted out).
This commit is contained in:
Bill Currie 2012-01-17 11:44:28 +09:00
parent fb428f8067
commit 3669e3aa2e
9 changed files with 53 additions and 26 deletions

View file

@ -347,6 +347,7 @@ typedef enum {mod_brush, mod_sprite, mod_alias} modtype_t;
typedef struct model_s { typedef struct model_s {
char name[MAX_QPATH]; char name[MAX_QPATH];
qboolean needload; // bmodels and sprites don't cache normally qboolean needload; // bmodels and sprites don't cache normally
aliashdr_t *aliashdr; // if not null, alias model is not cached
qboolean hasfullbrights; qboolean hasfullbrights;
modtype_t type; modtype_t type;
@ -420,7 +421,7 @@ typedef struct model_s {
unsigned int checksum2; unsigned int checksum2;
// additional model data // additional model data
cache_user_t cache; // access only through Mod_Extradata cache_user_t cache;
} model_t; } model_t;
// ============================================================================ // ============================================================================

View file

@ -31,8 +31,7 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] = "$Id$";
"$Id$";
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
# include <string.h> # include <string.h>
@ -54,6 +53,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "compat.h" #include "compat.h"
VISIBLE byte player_8bit_texels[640 * 400]; VISIBLE byte player_8bit_texels[640 * 400];
int alias_cache = 1;
void * void *
Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group,

View file

@ -52,6 +52,8 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include "r_shared.h" #include "r_shared.h"
int alias_cache = 0;
static vec3_t vertex_normals[NUMVERTEXNORMALS] = { static vec3_t vertex_normals[NUMVERTEXNORMALS] = {
#include "anorms.h" #include "anorms.h"
}; };

View file

@ -52,6 +52,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "d_iface.h" #include "d_iface.h"
#include "r_local.h" #include "r_local.h"
extern int alias_cache; //FIXME extern
aliashdr_t *pheader; aliashdr_t *pheader;
stvert_t *stverts; stvert_t *stverts;
@ -377,6 +378,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
Mod_LoadExternalSkins (mod); Mod_LoadExternalSkins (mod);
// move the complete, relocatable alias model to the cache // move the complete, relocatable alias model to the cache
if (alias_cache) {
end = Hunk_LowMark (); end = Hunk_LowMark ();
total = end - start; total = end - start;
@ -385,4 +387,8 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
memcpy (mem, pheader, total); memcpy (mem, pheader, total);
Hunk_FreeToLowMark (start); Hunk_FreeToLowMark (start);
mod->aliashdr = 0;
} else {
mod->aliashdr = pheader;
}
} }

View file

@ -31,8 +31,7 @@
# include "config.h" # include "config.h"
#endif #endif
static __attribute__ ((used)) const char rcsid[] = static __attribute__ ((used)) const char rcsid[] = "$Id$";
"$Id$";
#ifdef HAVE_STRING_H #ifdef HAVE_STRING_H
# include <string.h> # include <string.h>
@ -48,6 +47,8 @@ static __attribute__ ((used)) const char rcsid[] =
#include "compat.h" #include "compat.h"
#include "d_iface.h" #include "d_iface.h"
int alias_cache = 1;
// a pose is a single set of vertexes. a frame may be // a pose is a single set of vertexes. a frame may be
// an animating sequence of poses // an animating sequence of poses

View file

@ -516,6 +516,7 @@ R_DrawAliasModel (entity_t *e)
} }
// locate the proper data // locate the proper data
if (!(paliashdr = e->model->aliashdr))
paliashdr = Cache_Get (&e->model->cache); paliashdr = Cache_Get (&e->model->cache);
c_alias_polys += paliashdr->mdl.numtris; c_alias_polys += paliashdr->mdl.numtris;
@ -686,5 +687,6 @@ R_DrawAliasModel (entity_t *e)
qfglDisable (GL_LIGHT0 + used_lights); qfglDisable (GL_LIGHT0 + used_lights);
} }
if (!e->model->aliashdr)
Cache_Release (&e->model->cache); Cache_Release (&e->model->cache);
} }

View file

@ -205,6 +205,7 @@ R_DrawAlias (void)
aliasvrt_t *pose1 = 0; // VBO's are null based aliasvrt_t *pose1 = 0; // VBO's are null based
aliasvrt_t *pose2 = 0; // VBO's are null based aliasvrt_t *pose2 = 0; // VBO's are null based
if (!(hdr = model->aliashdr))
hdr = Cache_Get (&model->cache); hdr = Cache_Get (&model->cache);
calc_lighting (ent, &ambient, &shadelight, lightvec); calc_lighting (ent, &ambient, &shadelight, lightvec);
@ -264,6 +265,8 @@ R_DrawAlias (void)
sizeof (debug_indices) / sizeof (debug_indices[0]), sizeof (debug_indices) / sizeof (debug_indices[0]),
GL_UNSIGNED_SHORT, debug_indices); GL_UNSIGNED_SHORT, debug_indices);
#endif #endif
if (!model->aliashdr)
Cache_Release (&model->cache);
} }
// All alias models are drawn in a batch, so avoid thrashing the gl state // All alias models are drawn in a batch, so avoid thrashing the gl state

View file

@ -104,6 +104,7 @@ R_AliasCheckBBox (void)
// expand, rotate, and translate points into worldspace // expand, rotate, and translate points into worldspace
currententity->trivial_accept = 0; currententity->trivial_accept = 0;
pmodel = currententity->model; pmodel = currententity->model;
if (!(paliashdr = pmodel->aliashdr))
pahdr = Cache_Get (&pmodel->cache); pahdr = Cache_Get (&pmodel->cache);
pmdl = (mdl_t *) ((byte *) pahdr + pahdr->model); pmdl = (mdl_t *) ((byte *) pahdr + pahdr->model);
@ -157,6 +158,7 @@ R_AliasCheckBBox (void)
} }
if (zfullyclipped) { if (zfullyclipped) {
if (!pmodel->aliashdr)
Cache_Release (&pmodel->cache); Cache_Release (&pmodel->cache);
return false; // everything was near-z-clipped return false; // everything was near-z-clipped
} }
@ -219,6 +221,7 @@ R_AliasCheckBBox (void)
} }
if (allclip) { if (allclip) {
if (!pmodel->aliashdr)
Cache_Release (&pmodel->cache); Cache_Release (&pmodel->cache);
return false; // trivial reject off one side return false; // trivial reject off one side
} }
@ -231,6 +234,7 @@ R_AliasCheckBBox (void)
} }
} }
if (!pmodel->aliashdr)
Cache_Release (&pmodel->cache); Cache_Release (&pmodel->cache);
return true; return true;
} }
@ -628,6 +632,7 @@ R_AliasDrawModel (alight_t *plighting)
r_amodels_drawn++; r_amodels_drawn++;
if (!(paliashdr = currententity->model->aliashdr))
paliashdr = Cache_Get (&currententity->model->cache); paliashdr = Cache_Get (&currententity->model->cache);
pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model);
@ -674,5 +679,6 @@ R_AliasDrawModel (alight_t *plighting)
else else
R_AliasPreparePoints (); R_AliasPreparePoints ();
if (!currententity->model->aliashdr)
Cache_Release (&currententity->model->cache); Cache_Release (&currententity->model->cache);
} }

View file

@ -104,6 +104,7 @@ R_AliasCheckBBox (void)
// expand, rotate, and translate points into worldspace // expand, rotate, and translate points into worldspace
currententity->trivial_accept = 0; currententity->trivial_accept = 0;
pmodel = currententity->model; pmodel = currententity->model;
if (!(pahdr = pmodel->aliashdr))
pahdr = Cache_Get (&pmodel->cache); pahdr = Cache_Get (&pmodel->cache);
pmdl = (mdl_t *) ((byte *) pahdr + pahdr->model); pmdl = (mdl_t *) ((byte *) pahdr + pahdr->model);
@ -157,6 +158,7 @@ R_AliasCheckBBox (void)
} }
if (zfullyclipped) { if (zfullyclipped) {
if (!pmodel->aliashdr)
Cache_Release (&pmodel->cache); Cache_Release (&pmodel->cache);
return false; // everything was near-z-clipped return false; // everything was near-z-clipped
} }
@ -219,6 +221,7 @@ R_AliasCheckBBox (void)
} }
if (allclip) { if (allclip) {
if (!pmodel->aliashdr)
Cache_Release (&pmodel->cache); Cache_Release (&pmodel->cache);
return false; // trivial reject off one side return false; // trivial reject off one side
} }
@ -231,6 +234,7 @@ R_AliasCheckBBox (void)
} }
} }
if (!pmodel->aliashdr)
Cache_Release (&pmodel->cache); Cache_Release (&pmodel->cache);
return true; return true;
} }
@ -621,6 +625,7 @@ R_AliasDrawModel (alight_t *plighting)
r_amodels_drawn++; r_amodels_drawn++;
if (!(paliashdr = currententity->model->aliashdr))
paliashdr = Cache_Get (&currententity->model->cache); paliashdr = Cache_Get (&currententity->model->cache);
pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model); pmdl = (mdl_t *) ((byte *) paliashdr + paliashdr->model);
@ -666,5 +671,6 @@ R_AliasDrawModel (alight_t *plighting)
else else
R_AliasPreparePoints (); R_AliasPreparePoints ();
if (!currententity->model->aliashdr)
Cache_Release (&currententity->model->cache); Cache_Release (&currententity->model->cache);
} }