mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-01-21 23:50:58 +00:00
Proper cache checking for textures - thanks to LordHavoc for the fast and
cheap crc (which isn't a real crc, but does the job)
This commit is contained in:
parent
a4243ac120
commit
6168fcebcc
1 changed files with 28 additions and 17 deletions
|
@ -74,6 +74,9 @@ extern byte *draw_chars; // 8*8 graphic characters
|
||||||
qpic_t *draw_disc;
|
qpic_t *draw_disc;
|
||||||
qpic_t *draw_backtile;
|
qpic_t *draw_backtile;
|
||||||
|
|
||||||
|
int ltexcrctable[256]; // cache mismatch checking --KB
|
||||||
|
|
||||||
|
|
||||||
int translate_texture;
|
int translate_texture;
|
||||||
int char_texture;
|
int char_texture;
|
||||||
int cs_texture; // crosshair texture
|
int cs_texture; // crosshair texture
|
||||||
|
@ -112,6 +115,7 @@ typedef struct
|
||||||
char identifier[64];
|
char identifier[64];
|
||||||
int width, height;
|
int width, height;
|
||||||
qboolean mipmap;
|
qboolean mipmap;
|
||||||
|
int crc; // not really a standard CRC, but it works
|
||||||
} gltexture_t;
|
} gltexture_t;
|
||||||
|
|
||||||
#define MAX_GLTEXTURES 1024
|
#define MAX_GLTEXTURES 1024
|
||||||
|
@ -1334,8 +1338,18 @@ GL_LoadTexture
|
||||||
int GL_LoadTexture (char *identifier, int width, int height, byte *data, qboolean mipmap, qboolean alpha)
|
int GL_LoadTexture (char *identifier, int width, int height, byte *data, qboolean mipmap, qboolean alpha)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int s;
|
||||||
|
int lcrc;
|
||||||
gltexture_t *glt;
|
gltexture_t *glt;
|
||||||
|
|
||||||
|
// LordHavoc's cache check, not a standard crc but it works --KB
|
||||||
|
lcrc = 0;
|
||||||
|
s = width*height; // size
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
ltexcrctable[i] = i + 1;
|
||||||
|
for (i = 0; i < s; i++)
|
||||||
|
lcrc += (ltexcrctable[data[i] & 255]++);
|
||||||
|
|
||||||
// see if the texture is allready present
|
// see if the texture is allready present
|
||||||
if (identifier[0])
|
if (identifier[0])
|
||||||
{
|
{
|
||||||
|
@ -1343,37 +1357,34 @@ int GL_LoadTexture (char *identifier, int width, int height, byte *data, qboolea
|
||||||
{
|
{
|
||||||
if (!strcmp (identifier, glt->identifier))
|
if (!strcmp (identifier, glt->identifier))
|
||||||
{
|
{
|
||||||
if (width != glt->width || height != glt->height)
|
if (lcrc != glt->crc
|
||||||
{
|
|| width != glt->width
|
||||||
glt->width = width;
|
|| height != glt->height)
|
||||||
glt->height = height;
|
goto SetupTexture;
|
||||||
glt->mipmap = mipmap;
|
else
|
||||||
|
return gltextures[i].texnum;
|
||||||
GL_Bind (glt->texnum);
|
|
||||||
|
|
||||||
GL_Upload8 (data, width, height, mipmap, alpha);
|
|
||||||
}
|
|
||||||
return gltextures[i].texnum;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
glt = &gltextures[numgltextures];
|
glt = &gltextures[numgltextures];
|
||||||
numgltextures++;
|
numgltextures++;
|
||||||
|
|
||||||
strcpy (glt->identifier, identifier);
|
strcpy (glt->identifier, identifier);
|
||||||
glt->texnum = texture_extension_number;
|
glt->texnum = texture_extension_number;
|
||||||
|
texture_extension_number++;
|
||||||
|
|
||||||
|
SetupTexture:
|
||||||
|
glt->crc = lcrc;
|
||||||
glt->width = width;
|
glt->width = width;
|
||||||
glt->height = height;
|
glt->height = height;
|
||||||
glt->mipmap = mipmap;
|
glt->mipmap = mipmap;
|
||||||
|
|
||||||
GL_Bind(texture_extension_number );
|
GL_Bind(glt->texnum);
|
||||||
|
|
||||||
GL_Upload8 (data, width, height, mipmap, alpha);
|
GL_Upload8 (data, width, height, mipmap, alpha);
|
||||||
|
|
||||||
texture_extension_number++;
|
return glt->texnum;
|
||||||
|
|
||||||
return texture_extension_number-1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue