gl3: preserve cache on free slots in image and models list(aa6032f0)

This commit is contained in:
Denis Pauk 2021-09-20 11:50:44 +03:00
parent 330830fc38
commit 423c3fa299
3 changed files with 99 additions and 7 deletions

View File

@ -46,7 +46,8 @@ int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST;
int gl_filter_max = GL_LINEAR;
gl3image_t gl3textures[MAX_GL3TEXTURES];
int numgl3textures;
int numgl3textures = 0;
static int image_max = 0;
void
GL3_TextureMode(char *string)
@ -948,6 +949,33 @@ GL3_FreeUnusedImages(void)
}
}
qboolean
GL3_ImageHasFreeSpace(void)
{
int i, used;
gl3image_t *image;
used = 0;
for (i = 0, image = gl3textures; i < numgl3textures; i++, image++)
{
if (!image->name[0])
continue;
if (image->registration_sequence == registration_sequence)
{
used ++;
}
}
if (image_max < used)
{
image_max = used;
}
// should same size of free slots as currently used
return (numgl3textures + used) < MAX_GL3TEXTURES;
}
void
GL3_ShutdownImages(void)
{
@ -986,7 +1014,8 @@ static qboolean IsNPOT(int v)
void
GL3_ImageList_f(void)
{
int i, texels=0;
int i, used, texels;
qboolean freeup;
gl3image_t *image;
const char *formatstrings[2] = {
"RGB ",
@ -998,15 +1027,25 @@ GL3_ImageList_f(void)
};
R_Printf(PRINT_ALL, "------------------\n");
texels = 0;
used = 0;
for (i = 0, image = gl3textures; i < numgl3textures; i++, image++)
{
int w, h;
char *in_use = "";
qboolean isNPOT = false;
if (image->texnum == 0)
{
continue;
}
if (image->registration_sequence == registration_sequence)
{
in_use = "*";
used++;
}
w = image->width;
h = image->height;
@ -1036,9 +1075,11 @@ GL3_ImageList_f(void)
break;
}
R_Printf(PRINT_ALL, " %3i %3i %s %s: %s\n", w, h,
formatstrings[image->has_alpha], potstrings[isNPOT], image->name);
R_Printf(PRINT_ALL, " %3i %3i %s %s: %s %s\n", w, h,
formatstrings[image->has_alpha], potstrings[isNPOT], image->name, in_use);
}
R_Printf(PRINT_ALL, "Total texel count (not counting mipmaps): %i\n", texels);
freeup = GL3_ImageHasFreeSpace();
R_Printf(PRINT_ALL, "Used %d of %d images%s.\n", used, image_max, freeup ? ", has free space" : "");
}

View File

@ -33,12 +33,42 @@ static gl3model_t *loadmodel;
YQ2_ALIGNAS_TYPE(int) static byte mod_novis[MAX_MAP_LEAFS / 8];
gl3model_t mod_known[MAX_MOD_KNOWN];
static int mod_numknown;
static int mod_max = 0;
int registration_sequence;
static byte *mod_base;
/* the inline * models from the current map are kept seperate */
gl3model_t mod_inline[MAX_MOD_KNOWN];
//===============================================================================
static qboolean
Mod_HasFreeSpace(void)
{
int i, used;
gl3model_t *mod;
used = 0;
for (i=0, mod=mod_known ; i < mod_numknown ; i++, mod++)
{
if (!mod->name[0])
continue;
if (mod->registration_sequence == registration_sequence)
{
used ++;
}
}
if (mod_max < used)
{
mod_max = used;
}
// should same size of free slots as currently used
return (mod_numknown + mod_max) < MAX_MOD_KNOWN;
}
mleaf_t *
GL3_Mod_PointInLeaf(vec3_t p, gl3model_t *model)
{
@ -92,30 +122,44 @@ GL3_Mod_ClusterPVS(int cluster, const gl3model_t *model)
void
GL3_Mod_Modellist_f(void)
{
int i;
int i, total, used;
gl3model_t *mod;
int total;
qboolean freeup;
total = 0;
used = 0;
R_Printf(PRINT_ALL, "Loaded models:\n");
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
{
char *in_use = "";
if (mod->registration_sequence == registration_sequence)
{
in_use = "*";
used ++;
}
if (!mod->name[0])
{
continue;
}
R_Printf(PRINT_ALL, "%8i : %s\n", mod->extradatasize, mod->name);
R_Printf(PRINT_ALL, "%8i : %s %s\n",
mod->extradatasize, mod->name, in_use);
total += mod->extradatasize;
}
R_Printf(PRINT_ALL, "Total resident: %i\n", total);
// update statistics
freeup = Mod_HasFreeSpace();
R_Printf(PRINT_ALL, "Used %d of %d models%s.\n", used, mod_max, freeup ? ", has free space" : "");
}
void
GL3_Mod_Init(void)
{
mod_max = 0;
memset(mod_novis, 0xff, sizeof(mod_novis));
}
@ -1133,6 +1177,12 @@ GL3_EndRegistration(void)
int i;
gl3model_t *mod;
if (Mod_HasFreeSpace() && GL3_ImageHasFreeSpace())
{
// should be enough space for load next maps
return;
}
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
{
if (!mod->name[0])

View File

@ -421,6 +421,7 @@ extern gl3image_t *GL3_FindImage(char *name, imagetype_t type);
extern gl3image_t *GL3_RegisterSkin(char *name);
extern void GL3_ShutdownImages(void);
extern void GL3_FreeUnusedImages(void);
extern qboolean GL3_ImageHasFreeSpace(void);
extern void GL3_ImageList_f(void);
// gl3_light.c