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

View file

@ -31,8 +31,7 @@
# include "config.h"
#endif
static __attribute__ ((used)) const char rcsid[] =
"$Id$";
static __attribute__ ((used)) const char rcsid[] = "$Id$";
#ifdef HAVE_STRING_H
# include <string.h>
@ -54,6 +53,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "compat.h"
VISIBLE byte player_8bit_texels[640 * 400];
int alias_cache = 1;
void *
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"
int alias_cache = 0;
static vec3_t vertex_normals[NUMVERTEXNORMALS] = {
#include "anorms.h"
};

View file

@ -52,6 +52,7 @@ static __attribute__ ((used)) const char rcsid[] =
#include "d_iface.h"
#include "r_local.h"
extern int alias_cache; //FIXME extern
aliashdr_t *pheader;
stvert_t *stverts;
@ -377,12 +378,17 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
Mod_LoadExternalSkins (mod);
// move the complete, relocatable alias model to the cache
end = Hunk_LowMark ();
total = end - start;
if (alias_cache) {
end = Hunk_LowMark ();
total = end - start;
mem = allocator (&mod->cache, total, loadname);
if (mem)
memcpy (mem, pheader, total);
mem = allocator (&mod->cache, total, loadname);
if (mem)
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"
#endif
static __attribute__ ((used)) const char rcsid[] =
"$Id$";
static __attribute__ ((used)) const char rcsid[] = "$Id$";
#ifdef HAVE_STRING_H
# include <string.h>
@ -48,6 +47,8 @@ static __attribute__ ((used)) const char rcsid[] =
#include "compat.h"
#include "d_iface.h"
int alias_cache = 1;
// a pose is a single set of vertexes. a frame may be
// an animating sequence of poses

View file

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

View file

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

View file

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

View file

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