summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/console.c20
-rw-r--r--src/client/precache.c6
-rw-r--r--src/client/screen.c2
-rw-r--r--src/refresh/gl/draw.c19
-rw-r--r--src/refresh/gl/images.c85
-rw-r--r--src/refresh/gl/main.c4
-rw-r--r--src/refresh/gl/models.c4
-rw-r--r--src/refresh/gl/sky.c2
-rw-r--r--src/refresh/gl/surf.c2
-rw-r--r--src/refresh/images.c173
-rw-r--r--src/refresh/models.c2
-rw-r--r--src/refresh/sw/draw.c18
-rw-r--r--src/refresh/sw/image.c6
-rw-r--r--src/refresh/sw/model.c4
-rw-r--r--src/refresh/sw/sky.c2
15 files changed, 150 insertions, 199 deletions
diff --git a/src/client/console.c b/src/client/console.c
index 9f72be4..7725ad1 100644
--- a/src/client/console.c
+++ b/src/client/console.c
@@ -598,29 +598,29 @@ Con_RegisterMedia
*/
void Con_RegisterMedia(void)
{
- qerror_t ret;
+ qerror_t err;
- ret = _R_RegisterFont(con_font->string, &con.charsetImage);
+ con.charsetImage = R_RegisterImage(con_font->string, IT_FONT, IF_PERMANENT, &err);
if (!con.charsetImage) {
if (strcmp(con_font->string, "conchars")) {
- Com_WPrintf("Couldn't load console font: %s\n", Q_ErrorString(ret));
+ Com_WPrintf("Couldn't load %s: %s\n", con_font->string, Q_ErrorString(err));
Cvar_Reset(con_font);
- ret = _R_RegisterFont("conchars", &con.charsetImage);
+ con.charsetImage = R_RegisterImage("conchars", IT_FONT, IF_PERMANENT, &err);
}
if (!con.charsetImage) {
- Com_Error(ERR_FATAL, "Couldn't load pics/conchars.pcx: %s", Q_ErrorString(ret));
+ Com_Error(ERR_FATAL, "Couldn't load pics/conchars.pcx: %s", Q_ErrorString(err));
}
}
- ret = _R_RegisterPic(con_background->string, &con.backImage);
+ con.backImage = R_RegisterImage(con_background->string, IT_PIC, IF_PERMANENT, &err);
if (!con.backImage) {
if (strcmp(con_background->string, "conback")) {
- Com_WPrintf("Couldn't load console background: %s\n", Q_ErrorString(ret));
+ Com_WPrintf("Couldn't load %s: %s\n", con_background->string, Q_ErrorString(err));
Cvar_Reset(con_background);
- ret = _R_RegisterPic("conback", &con.backImage);
+ con.backImage = R_RegisterImage("conback", IT_PIC, IF_PERMANENT, &err);
}
- if (!con.charsetImage) {
- Com_EPrintf("Couldn't load pics/conback.pcx: %s\n", Q_ErrorString(ret));
+ if (!con.backImage) {
+ Com_EPrintf("Couldn't load pics/conback.pcx: %s\n", Q_ErrorString(err));
}
}
}
diff --git a/src/client/precache.c b/src/client/precache.c
index bf6447d..70fe5b0 100644
--- a/src/client/precache.c
+++ b/src/client/precache.c
@@ -170,7 +170,7 @@ void CL_LoadClientinfo(clientinfo_t *ci, const char *s)
// icon file
Q_concat(icon_filename, sizeof(icon_filename),
"/players/", model_name, "/", skin_name, "_i.pcx", NULL);
- ci->icon = R_RegisterPic(icon_filename);
+ ci->icon = R_RegisterPic2(icon_filename);
strcpy(ci->model_name, model_name);
strcpy(ci->skin_name, skin_name);
@@ -397,7 +397,7 @@ void CL_PrepRefresh(void)
if (!name[0]) {
break;
}
- cl.image_precache[i] = R_RegisterPic(name);
+ cl.image_precache[i] = R_RegisterPic2(name);
}
CL_LoadState(LOAD_CLIENTS);
@@ -486,7 +486,7 @@ void CL_UpdateConfigstring(int index)
}
if (index >= CS_IMAGES && index < CS_IMAGES + MAX_IMAGES) {
- cl.image_precache[index - CS_IMAGES] = R_RegisterPic(s);
+ cl.image_precache[index - CS_IMAGES] = R_RegisterPic2(s);
return;
}
diff --git a/src/client/screen.c b/src/client/screen.c
index 4cdaf33..efc3aea 100644
--- a/src/client/screen.c
+++ b/src/client/screen.c
@@ -1605,7 +1605,7 @@ static void draw_layout_string(const char *s)
if (!strcmp(token, "picn")) {
// draw a pic from a name
token = COM_Parse(&s);
- R_DrawPic(x, y, R_RegisterPic(token));
+ R_DrawPic(x, y, R_RegisterPic2(token));
continue;
}
diff --git a/src/refresh/gl/draw.c b/src/refresh/gl/draw.c
index f596d04..99dacdc 100644
--- a/src/refresh/gl/draw.c
+++ b/src/refresh/gl/draw.c
@@ -57,8 +57,8 @@ static inline void _GL_StretchPic(
dst_indices[4] = tess.numverts + 1;
dst_indices[5] = tess.numverts + 2;
- if (flags & if_transparent) {
- if ((flags & if_paletted) && draw.scale == 1) {
+ if (flags & IF_TRANSPARENT) {
+ if ((flags & IF_PALETTED) && draw.scale == 1) {
tess.flags |= 1;
} else {
tess.flags |= 2;
@@ -190,19 +190,6 @@ void R_SetScale(float *scale)
draw.scale = f;
}
-qboolean R_GetPicSize(int *w, int *h, qhandle_t pic)
-{
- image_t *image = IMG_ForHandle(pic);
-
- if (w) {
- *w = image->width;
- }
- if (h) {
- *h = image->height;
- }
- return image->flags & if_transparent;
-}
-
void R_DrawStretchPic(int x, int y, int w, int h, qhandle_t pic)
{
image_t *image = IMG_ForHandle(pic);
@@ -363,7 +350,7 @@ void Draw_Lightmaps(void)
void Draw_Scrap(void)
{
_GL_StretchPic(0, 0, 256, 256,
- 0, 0, 1, 1, U32_WHITE, TEXNUM_SCRAP, if_paletted | if_transparent);
+ 0, 0, 1, 1, U32_WHITE, TEXNUM_SCRAP, IF_PALETTED | IF_TRANSPARENT);
}
#endif
diff --git a/src/refresh/gl/images.c b/src/refresh/gl/images.c
index 10ae3a6..813c703 100644
--- a/src/refresh/gl/images.c
+++ b/src/refresh/gl/images.c
@@ -119,7 +119,7 @@ static void gl_texturemode_changed(cvar_t *self)
// change all the existing mipmap texture objects
for (i = 0, image = r_images; i < r_numImages; i++, image++) {
- if (image->type == it_wall || image->type == it_skin) {
+ if (image->type == IT_WALL || image->type == IT_SKIN) {
GL_BindTexture(image->texnum);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_min);
@@ -154,7 +154,7 @@ static void gl_anisotropy_changed(cvar_t *self)
// change all the existing mipmap texture objects
for (i = 0, image = r_images; i < r_numImages; i++, image++) {
- if (image->type == it_wall || image->type == it_skin) {
+ if (image->type == IT_WALL || image->type == IT_SKIN) {
GL_BindTexture(image->texnum);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
gl_filter_anisotropy);
@@ -170,7 +170,7 @@ static void gl_bilerp_chars_changed(cvar_t *self)
// change all the existing charset texture objects
for (i = 0, image = r_images; i < r_numImages; i++, image++) {
- if (image->type == it_charset) {
+ if (image->type == IT_FONT) {
GL_BindTexture(image->texnum);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param);
@@ -186,7 +186,7 @@ static void gl_bilerp_pics_changed(cvar_t *self)
// change all the existing pic texture objects
for (i = 0, image = r_images; i < r_numImages; i++, image++) {
- if (image->type == it_pic) {
+ if (image->type == IT_PIC) {
GL_BindTexture(image->texnum);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, param);
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param);
@@ -559,10 +559,10 @@ static inline qboolean is_nearest(void)
if (!upload_image) {
return qfalse;
}
- if (upload_image->type == it_charset) {
+ if (upload_image->type == IT_FONT) {
return !gl_bilerp_chars->integer;
}
- if (upload_image->type == it_pic) {
+ if (upload_image->type == IT_PIC) {
return !gl_bilerp_pics->integer;
}
return qfalse;
@@ -573,7 +573,7 @@ static inline qboolean is_wall(void)
if (!upload_image) {
return qfalse;
}
- if (upload_image->type != it_wall) {
+ if (upload_image->type != IT_WALL) {
return qfalse; // not a wall texture
}
if (!upload_texinfo) {
@@ -590,7 +590,7 @@ static inline qboolean is_downsample(void)
if (!upload_image) {
return qtrue;
}
- if (upload_image->type != it_skin) {
+ if (upload_image->type != IT_SKIN) {
return qtrue; // not a skin
}
return !!gl_downsample_skins->integer;
@@ -604,10 +604,10 @@ static inline qboolean is_clamp(void)
if (!upload_image) {
return qfalse;
}
- if (upload_image->type == it_charset) {
+ if (upload_image->type == IT_FONT) {
return qtrue;
}
- if (upload_image->type == it_pic) {
+ if (upload_image->type == IT_PIC) {
return !Q_stristr(upload_image->name, "backtile"); // hack for backtile
}
return qfalse;
@@ -850,51 +850,50 @@ void IMG_Load(image_t *image, byte *pic, int width, int height)
upload_image = image;
// load small 8-bit pics onto the scrap
- if (image->type == it_pic && (image->flags & if_paletted) &&
- width < 64 && height < 64 && !gl_noscrap->integer) {
- if (Scrap_AllocBlock(width, height, &s, &t)) {
- src = pic;
- dst = &scrap_data[t * SCRAP_BLOCK_WIDTH + s];
- for (i = 0; i < height; i++) {
- ptr = dst;
- for (j = 0; j < width; j++) {
- *ptr++ = *src++;
- }
- dst += SCRAP_BLOCK_WIDTH;
- }
-
- image->texnum = TEXNUM_SCRAP;
- image->upload_width = width;
- image->upload_height = height;
- image->flags |= if_scrap | if_transparent;
- image->sl = (s + 0.01f) / (float)SCRAP_BLOCK_WIDTH;
- image->sh = (s + width - 0.01f) / (float)SCRAP_BLOCK_WIDTH;
- image->tl = (t + 0.01f) / (float)SCRAP_BLOCK_HEIGHT;
- image->th = (t + height - 0.01f) / (float)SCRAP_BLOCK_HEIGHT;
-
- scrap_dirty = qtrue;
- if (!gl_static.registering) {
- Scrap_Upload();
+ if (image->type == IT_PIC && (image->flags & IF_PALETTED) &&
+ width < 64 && height < 64 && !gl_noscrap->integer &&
+ Scrap_AllocBlock(width, height, &s, &t)) {
+ src = pic;
+ dst = &scrap_data[t * SCRAP_BLOCK_WIDTH + s];
+ for (i = 0; i < height; i++) {
+ ptr = dst;
+ for (j = 0; j < width; j++) {
+ *ptr++ = *src++;
}
+ dst += SCRAP_BLOCK_WIDTH;
+ }
- upload_image = NULL;
- return;
+ image->texnum = TEXNUM_SCRAP;
+ image->upload_width = width;
+ image->upload_height = height;
+ image->flags |= IF_SCRAP | IF_TRANSPARENT;
+ image->sl = (s + 0.01f) / (float)SCRAP_BLOCK_WIDTH;
+ image->sh = (s + width - 0.01f) / (float)SCRAP_BLOCK_WIDTH;
+ image->tl = (t + 0.01f) / (float)SCRAP_BLOCK_HEIGHT;
+ image->th = (t + height - 0.01f) / (float)SCRAP_BLOCK_HEIGHT;
+
+ scrap_dirty = qtrue;
+ if (!gl_static.registering) {
+ Scrap_Upload();
}
+
+ upload_image = NULL;
+ return;
}
- if (image->type == it_skin && (image->flags & if_paletted))
+ if (image->type == IT_SKIN && (image->flags & IF_PALETTED))
R_FloodFillSkin(pic, width, height);
- mipmap = (image->type == it_wall || image->type == it_skin);
+ mipmap = (image->type == IT_WALL || image->type == IT_SKIN);
image->texnum = (image - r_images);
GL_BindTexture(image->texnum);
- if (image->flags & if_paletted) {
+ if (image->flags & IF_PALETTED) {
transparent = GL_Upload8(pic, width, height, mipmap);
} else {
transparent = GL_Upload32(pic, width, height, mipmap);
}
if (transparent) {
- image->flags |= if_transparent;
+ image->flags |= IF_TRANSPARENT;
}
image->upload_width = upload_width; // after power of 2 and scales
image->upload_height = upload_height;
@@ -909,6 +908,8 @@ void IMG_Load(image_t *image, byte *pic, int width, int height)
void IMG_Unload(image_t *image)
{
if (image->texnum > 0 && image->texnum < MAX_RIMAGES) {
+ if (gls.texnum[gls.tmu] == image->texnum)
+ gls.texnum[gls.tmu] = 0;
qglDeleteTextures(1, &image->texnum);
image->texnum = 0;
}
@@ -994,7 +995,7 @@ static void GL_InitDefaultTexture(void)
ntx = R_NOTEXTURE;
ntx->width = ntx->upload_width = 8;
ntx->height = ntx->upload_height = 8;
- ntx->type = it_wall;
+ ntx->type = IT_WALL;
ntx->flags = 0;
ntx->texnum = TEXNUM_DEFAULT;
ntx->sl = 0;
diff --git a/src/refresh/gl/main.c b/src/refresh/gl/main.c
index f4e9172..da830d2 100644
--- a/src/refresh/gl/main.c
+++ b/src/refresh/gl/main.c
@@ -337,8 +337,8 @@ static void GL_DrawSpriteModel(model_t *model)
vec3_t points[4];
if (alpha == 1) {
- if (image->flags & if_transparent) {
- if (image->flags & if_paletted) {
+ if (image->flags & IF_TRANSPARENT) {
+ if (image->flags & IF_PALETTED) {
bits |= GLS_ALPHATEST_ENABLE;
} else {
bits |= GLS_BLEND_BLEND;
diff --git a/src/refresh/gl/models.c b/src/refresh/gl/models.c
index f0cc8ba..cb1aa46 100644
--- a/src/refresh/gl/models.c
+++ b/src/refresh/gl/models.c
@@ -136,7 +136,7 @@ qerror_t MOD_LoadMD2(model_t *model, const void *rawdata, size_t length)
goto fail;
}
FS_NormalizePath(skinname, skinname);
- dst_mesh->skins[i] = IMG_Find(skinname, it_skin);
+ dst_mesh->skins[i] = IMG_Find(skinname, IT_SKIN);
src_skin += MD2_MAX_SKINNAME;
}
dst_mesh->numskins = header.num_skins;
@@ -341,7 +341,7 @@ qerror_t MOD_LoadMD3(model_t *model, const void *rawdata, size_t length)
goto fail;
}
FS_NormalizePath(skinname, skinname);
- dst_mesh->skins[j] = IMG_Find(skinname, it_skin);
+ dst_mesh->skins[j] = IMG_Find(skinname, IT_SKIN);
}
dst_mesh->numskins = numskins;
diff --git a/src/refresh/gl/sky.c b/src/refresh/gl/sky.c
index eea435d..bd40b79 100644
--- a/src/refresh/gl/sky.c
+++ b/src/refresh/gl/sky.c
@@ -390,7 +390,7 @@ void R_SetSky(const char *name, float rotate, vec3_t axis)
return;
}
FS_NormalizePath(pathname, pathname);
- image = IMG_Find(pathname, it_sky);
+ image = IMG_Find(pathname, IT_SKY);
if (image->texnum == TEXNUM_DEFAULT) {
R_UnsetSky();
return;
diff --git a/src/refresh/gl/surf.c b/src/refresh/gl/surf.c
index dc3f26c..14f3828 100644
--- a/src/refresh/gl/surf.c
+++ b/src/refresh/gl/surf.c
@@ -780,7 +780,7 @@ void GL_LoadWorld(const char *name)
Q_concat(buffer, sizeof(buffer), "textures/", info->name, ".wal", NULL);
FS_NormalizePath(buffer, buffer);
upload_texinfo = info;
- info->image = IMG_Find(buffer, it_wall);
+ info->image = IMG_Find(buffer, IT_WALL);
upload_texinfo = NULL;
}
diff --git a/src/refresh/images.c b/src/refresh/images.c
index 94f591d..ae2217f 100644
--- a/src/refresh/images.c
+++ b/src/refresh/images.c
@@ -1391,7 +1391,7 @@ int r_numImages;
uint32_t d_8to24table[256];
-static const imageloader_t img_loaders[im_unknown] = {
+static const imageloader_t img_loaders[IM_MAX] = {
{ "pcx", IMG_LoadPCX },
{ "wal", IMG_LoadWAL },
#if USE_TGA
@@ -1406,7 +1406,7 @@ static const imageloader_t img_loaders[im_unknown] = {
};
#if USE_PNG || USE_JPG || USE_TGA
-static imageformat_t img_search[im_unknown];
+static imageformat_t img_search[IM_MAX];
static int img_total;
static cvar_t *r_override_textures;
@@ -1420,7 +1420,7 @@ IMG_List_f
*/
static void IMG_List_f(void)
{
- static const char types[8] = "MSWPYC?";
+ static const char types[8] = "PFMSWY??";
int i;
image_t *image;
int texels, count;
@@ -1432,13 +1432,14 @@ static void IMG_List_f(void)
if (!image->registration_sequence)
continue;
- Com_Printf("%c%c%c %4i %4i %s: %s\n",
- types[image->type],
- (image->flags & if_transparent) ? 'T' : ' ',
- (image->flags & if_scrap) ? 'S' : ' ',
+ Com_Printf("%c%c%c%c %4i %4i %s: %s\n",
+ types[image->type > IT_MAX ? IT_MAX : image->type],
+ (image->flags & IF_TRANSPARENT) ? 'T' : ' ',
+ (image->flags & IF_SCRAP) ? 'S' : ' ',
+ (image->flags & IF_PERMANENT) ? '*' : ' ',
image->upload_width,
image->upload_height,
- (image->flags & if_paletted) ? "PAL" : "RGB",
+ (image->flags & IF_PALETTED) ? "PAL" : "RGB",
image->name);
texels += image->upload_width * image->upload_height;
@@ -1517,7 +1518,7 @@ static imageformat_t try_image_format(const imageloader_t *ldr,
// unless this is a WAL texture, raw image data is
// no longer needed, free it now
- if (ret != im_wal) {
+ if (ret != IM_WAL) {
FS_FreeFile(data);
*tmp = NULL;
} else {
@@ -1559,7 +1560,7 @@ static qerror_t try_other_formats(imageformat_t orig, imagetype_t type,
}
// fall back to 8-bit formats
- fmt = type == it_wall ? im_wal : im_pcx;
+ fmt = type == IT_WALL ? IM_WAL : IM_PCX;
if (fmt == orig) {
// don't retry twice
return Q_ERR_NOENT;
@@ -1581,7 +1582,7 @@ static void get_image_dimensions(image_t *image,
unsigned w, h;
w = h = 0;
- if (fmt == im_wal) {
+ if (fmt == IM_WAL) {
memcpy(ext, "wal", 4);
FS_FOpenFile(buffer, &f, FS_MODE_READ);
if (f) {
@@ -1625,19 +1626,19 @@ static void r_texture_formats_changed(cvar_t *self)
for (s = self->string; *s; s++) {
switch (*s) {
#if USE_TGA
- case 't': case 'T': i = im_tga; break;
+ case 't': case 'T': i = IM_TGA; break;
#endif
#if USE_JPG
- case 'j': case 'J': i = im_jpg; break;
+ case 'j': case 'J': i = IM_JPG; break;
#endif
#if USE_PNG
- case 'p': case 'P': i = im_png; break;
+ case 'p': case 'P': i = IM_PNG; break;
#endif
- default: continue;
+ default: continue;
}
img_search[img_total++] = i;
- if (img_total == im_unknown) {
+ if (img_total == IM_MAX) {
break;
}
}
@@ -1646,8 +1647,9 @@ static void r_texture_formats_changed(cvar_t *self)
#endif // USE_PNG || USE_JPG || USE_TGA
// finds or loads the given image, adding it to the hash table.
-static qerror_t find_or_load_image(const char *name,
- size_t len, imagetype_t type, image_t **image_p)
+static qerror_t find_or_load_image(const char *name, size_t len,
+ imagetype_t type, imageflags_t flags,
+ image_t **image_p)
{
image_t *image;
byte *pic, *tmp;
@@ -1672,6 +1674,7 @@ static qerror_t find_or_load_image(const char *name,
// look for it
if ((image = lookup_image(name, type, hash, len - 4)) != NULL) {
+ image->flags |= flags & IF_PERMANENT;
image->registration_sequence = registration_sequence;
*image_p = image;
return Q_ERR_SUCCESS;
@@ -1682,7 +1685,7 @@ static qerror_t find_or_load_image(const char *name,
ext = buffer + len - 3;
// find out original extension
- for (fmt = 0; fmt < im_unknown; fmt++) {
+ for (fmt = 0; fmt < IM_MAX; fmt++) {
ldr = &img_loaders[fmt];
if (!Q_stricmp(ext, ldr->ext)) {
break;
@@ -1692,9 +1695,9 @@ static qerror_t find_or_load_image(const char *name,
// load the pic from disk
pic = tmp = NULL;
#if USE_PNG || USE_JPG || USE_TGA
- if (fmt == im_unknown) {
+ if (fmt == IM_MAX) {
// unknown extension, but give it a chance to load anyway
- ret = try_other_formats(im_unknown, type,
+ ret = try_other_formats(IM_MAX, type,
buffer, ext, &pic, &tmp, &width, &height);
if (ret == Q_ERR_NOENT) {
// not found, change error to invalid path
@@ -1702,7 +1705,7 @@ static qerror_t find_or_load_image(const char *name,
}
} else if (r_override_textures->integer) {
// forcibly replace the extension
- ret = try_other_formats(im_unknown, type,
+ ret = try_other_formats(IM_MAX, type,
buffer, ext, &pic, &tmp, &width, &height);
} else {
// first try with original extension
@@ -1714,7 +1717,7 @@ static qerror_t find_or_load_image(const char *name,
}
}
#else
- if (fmt == im_unknown) {
+ if (fmt == IM_MAX) {
return Q_ERR_INVALID_PATH;
}
ret = try_image_format(ldr, buffer, &pic, &tmp, &width, &height);
@@ -1735,22 +1738,22 @@ static qerror_t find_or_load_image(const char *name,
memcpy(image->name, buffer, len + 1);
image->baselen = len - 4;
image->type = type;
- image->flags = 0;
+ image->flags = flags;
image->width = width;
image->height = height;
image->registration_sequence = registration_sequence;
List_Append(&r_imageHash[hash], &image->entry);
- if (ret <= im_wal) {
- image->flags |= if_paletted;
+ if (ret <= IM_WAL) {
+ image->flags |= IF_PALETTED;
}
#if USE_PNG || USE_JPG || USE_TGA
// if we are replacing 8-bit texture with a higher resolution 32-bit
// texture, we need to recover original image dimensions for proper
// texture alignment
- if (fmt <= im_wal && ret > im_wal) {
+ if (fmt <= IM_WAL && ret > IM_WAL) {
get_image_dimensions(image, fmt, buffer, ext);
}
#endif
@@ -1789,7 +1792,7 @@ image_t *IMG_Find(const char *name, imagetype_t type)
Com_Error(ERR_FATAL, "%s: oversize name", __func__);
}
- ret = find_or_load_image(name, len, type, &image);
+ ret = find_or_load_image(name, len, type, IF_NONE, &image);
if (image) {
return image;
}
@@ -1816,106 +1819,84 @@ image_t *IMG_ForHandle(qhandle_t h)
return &r_images[h];
}
-static qerror_t _register_image(const char *name, imagetype_t type, qhandle_t *handle)
+/*
+===============
+R_RegisterImage
+===============
+*/
+qhandle_t R_RegisterImage(const char *name, imagetype_t type,
+ imageflags_t flags, qerror_t *err_p)
{
image_t *image;
char fullname[MAX_QPATH];
size_t len;
- qerror_t ret;
+ qerror_t err;
- *handle = 0;
+ // empty names are legal, silently ignore them
+ if (!*name) {
+ if (err_p)
+ *err_p = Q_ERR_NAMETOOSHORT;
+ return 0;
+ }
+ // no images = not initialized
if (!r_numImages) {
- return Q_ERR_AGAIN;
+ err = Q_ERR_AGAIN;
+ goto fail;
}
- if (type == it_skin) {
+ if (type == IT_SKIN) {
len = FS_NormalizePathBuffer(fullname, name, sizeof(fullname));
- } else if (name[0] == '/' || name[0] == '\\') {
+ } else if (*name == '/' || *name == '\\') {
len = FS_NormalizePathBuffer(fullname, name + 1, sizeof(fullname));
} else {
len = Q_concat(fullname, sizeof(fullname), "pics/", name, NULL);
if (len >= sizeof(fullname)) {
- return Q_ERR_NAMETOOLONG;
+ err = Q_ERR_NAMETOOLONG;
+ goto fail;
}
FS_NormalizePath(fullname, fullname);
len = COM_DefaultExtension(fullname, ".pcx", sizeof(fullname));
}
if (len >= sizeof(fullname)) {
- return Q_ERR_NAMETOOLONG;
- }
-
- ret = find_or_load_image(fullname, len, type, &image);
-
- if (!image) {
- return ret;
+ err = Q_ERR_NAMETOOLONG;
+ goto fail;
}
- *handle = (image - r_images);
- return Q_ERR_SUCCESS;
-}
-
-static qhandle_t register_image(const char *name, imagetype_t type)
-{
- qhandle_t handle;
- qerror_t ret;
-
- // empty names are legal, silently ignore them
- if (!*name)
- return 0;
-
- ret = _register_image(name, type, &handle);
- if (handle) {
- return handle;
+ err = find_or_load_image(fullname, len, type, flags, &image);
+ if (image) {
+ if (err_p)
+ *err_p = Q_ERR_SUCCESS;
+ return image - r_images;
}
+fail:
// don't spam about missing images
- if (ret != Q_ERR_NOENT) {
- Com_EPrintf("Couldn't load %s: %s\n", name, Q_ErrorString(ret));
- }
+ if (err_p)
+ *err_p = err;
+ else if (err != Q_ERR_NOENT)
+ Com_EPrintf("Couldn't load %s: %s\n", name, Q_ErrorString(err));
return 0;
}
/*
-===============
-R_RegisterSkin
-===============
-*/
-qhandle_t R_RegisterSkin(const char *name)
-{
- return register_image(name, it_skin);
-}
-
-/*
-================
-R_RegisterPic
-================
-*/
-qhandle_t R_RegisterPic(const char *name)
-{
- return register_image(name, it_pic);
-}
-
-qerror_t _R_RegisterPic(const char *name, qhandle_t *handle)
-{
- return _register_image(name, it_pic, handle);
-}
-
-/*
-================
-R_RegisterFont
-================
+=============
+R_GetPicSize
+=============
*/
-qhandle_t R_RegisterFont(const char *name)
+qboolean R_GetPicSize(int *w, int *h, qhandle_t pic)
{
- return register_image(name, it_charset);
-}
+ image_t *image = IMG_ForHandle(pic);
-qerror_t _R_RegisterFont(const char *name, qhandle_t *handle)
-{
- return _register_image(name, it_charset, handle);
+ if (w) {
+ *w = image->width;
+ }
+ if (h) {
+ *h = image->height;
+ }
+ return !!(image->flags & IF_TRANSPARENT);
}
/*
@@ -1940,7 +1921,7 @@ void IMG_FreeUnused(void)
}
if (!image->registration_sequence)
continue; // free image_t slot
- if (image->type == it_pic || image->type == it_charset)
+ if (image->flags & (IF_PERMANENT | IF_SCRAP))
continue; // don't free pics
// delete it from hash table
diff --git a/src/refresh/models.c b/src/refresh/models.c
index 2b7a408..9c78c6a 100644
--- a/src/refresh/models.c
+++ b/src/refresh/models.c
@@ -268,7 +268,7 @@ static qerror_t MOD_LoadSP2(model_t *model, const void *rawdata, size_t length)
dst_frame->image = R_NOTEXTURE;
} else {
FS_NormalizePath(buffer, buffer);
- dst_frame->image = IMG_Find(buffer, it_sprite);
+ dst_frame->image = IMG_Find(buffer, IT_SPRITE);
}
src_frame++;
diff --git a/src/refresh/sw/draw.c b/src/refresh/sw/draw.c
index f2a5697..c13273a 100644
--- a/src/refresh/sw/draw.c
+++ b/src/refresh/sw/draw.c
@@ -168,24 +168,6 @@ void R_SetClipRect(int flags, const clipRect_t *clip)
/*
=============
-R_GetPicSize
-=============
-*/
-qboolean R_GetPicSize(int *w, int *h, qhandle_t pic)
-{
- image_t *image = IMG_ForHandle(pic);
-
- if (w) {
- *w = image->width;
- }
- if (h) {
- *h = image->height;
- }
- return image->flags & if_transparent;
-}
-
-/*
-=============
R_DrawStretchData
=============
*/
diff --git a/src/refresh/sw/image.c b/src/refresh/sw/image.c
index 6208d73..7bf30a3 100644
--- a/src/refresh/sw/image.c
+++ b/src/refresh/sw/image.c
@@ -44,7 +44,7 @@ void IMG_Load(image_t *image, byte *pic, int width, int height)
image->upload_height = height;
c = width * height;
- if (image->type == it_wall) {
+ if (image->type == IT_WALL) {
size_t size = MIPSIZE(c);
image->pixels[0] = R_Malloc(size);
@@ -59,7 +59,7 @@ void IMG_Load(image_t *image, byte *pic, int width, int height)
for (i = 0; i < c; i++) {
b = pic[i];
if (b == 255) {
- image->flags |= if_transparent;
+ image->flags |= IF_TRANSPARENT;
}
}
}
@@ -93,7 +93,7 @@ static void R_CreateNotexture(void)
// create a simple checkerboard texture for the default
ntx = R_NOTEXTURE;
- ntx->type = it_wall;
+ ntx->type = IT_WALL;
ntx->flags = 0;
ntx->width = ntx->height = NTX;
ntx->upload_width = ntx->upload_height = NTX;
diff --git a/src/refresh/sw/model.c b/src/refresh/sw/model.c
index 53ac955..ced0924 100644
--- a/src/refresh/sw/model.c
+++ b/src/refresh/sw/model.c
@@ -53,7 +53,7 @@ static void ProcessTexinfo(bsp_t *bsp)
Q_concat(name, sizeof(name), "textures/", tex->name, ".wal", NULL);
FS_NormalizePath(name, name);
- tex->image = IMG_Find(name, it_wall);
+ tex->image = IMG_Find(name, IT_WALL);
}
}
@@ -249,7 +249,7 @@ qerror_t MOD_LoadMD2(model_t *model, const void *rawdata, size_t length)
goto fail;
}
FS_NormalizePath(skinname, skinname);
- model->skins[i] = IMG_Find(skinname, it_skin);
+ model->skins[i] = IMG_Find(skinname, IT_SKIN);
src_skin += MD2_MAX_SKINNAME;
}
model->numskins = header.num_skins;
diff --git a/src/refresh/sw/sky.c b/src/refresh/sw/sky.c
index d378cfe..320464a 100644
--- a/src/refresh/sw/sky.c
+++ b/src/refresh/sw/sky.c
@@ -169,7 +169,7 @@ void R_SetSky(const char *name, float rotate, vec3_t axis)
Q_concat(path, sizeof(path), "env/", name,
r_skysidenames[r_skysideimage[i]], ".pcx", NULL);
FS_NormalizePath(path, path);
- r_skytexinfo[i].image = IMG_Find(path, it_sky);
+ r_skytexinfo[i].image = IMG_Find(path, IT_SKY);
}
}