From 20360c5ad6ccae4604bd89b1a03d5fd9e2cb8276 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Tue, 13 Dec 2022 22:45:59 +0200 Subject: [PATCH] Image: Share loadSky textures Add support of `r_palettedtextures` to all renders. --- src/common/header/ref_shared.h | 2 ++ src/files/stb.c | 38 ++++++++++++++++++++++++++++++++++ src/vk/header/local.h | 5 +++-- src/vk/vk_image.c | 22 ++++++++++++++++++-- src/vk/vk_rmain.c | 4 ++-- src/vk/vk_warp.c | 38 ++++++++++++---------------------- 6 files changed, 78 insertions(+), 31 deletions(-) diff --git a/src/common/header/ref_shared.h b/src/common/header/ref_shared.h index 98df990..a0a152b 100644 --- a/src/common/header/ref_shared.h +++ b/src/common/header/ref_shared.h @@ -95,5 +95,7 @@ extern void *Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilel struct image_s **skins, findimage_t find_image, modtype_t *type); extern int Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata, modtype_t type); +extern struct image_s *GetSkyImage(const char *skyname, const char* surfname, + qboolean palettedtexture, findimage_t find_image); #endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */ diff --git a/src/files/stb.c b/src/files/stb.c index 27098fd..5a942cb 100644 --- a/src/files/stb.c +++ b/src/files/stb.c @@ -560,3 +560,41 @@ LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t typ return image; } + +struct image_s* +GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture, + findimage_t find_image) +{ + struct image_s *image = NULL; + char pathname[MAX_QPATH]; + + if (palettedtexture) + { + Com_sprintf(pathname, sizeof(pathname), "env/%s%s.pcx", + skyname, surfname); + image = find_image(pathname, it_sky); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "env/%s%s.tga", + skyname, surfname); + image = find_image(pathname, it_sky); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m32", + skyname, surfname); + image = find_image(pathname, it_sky); + } + + if (!image) + { + Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m8", + skyname, surfname); + image = find_image(pathname, it_sky); + } + + return image; +} diff --git a/src/vk/header/local.h b/src/vk/header/local.h index 2d38c81..c7120ce 100644 --- a/src/vk/header/local.h +++ b/src/vk/header/local.h @@ -136,7 +136,7 @@ extern cvar_t *r_farsee; extern cvar_t *vk_overbrightbits; extern cvar_t *r_validation; extern cvar_t *vk_picmip; -extern cvar_t *vk_skymip; +extern cvar_t *r_palettedtexture; extern cvar_t *vk_flashblend; extern cvar_t *vk_finish; extern cvar_t *vk_shadows; @@ -240,7 +240,8 @@ struct image_s *RE_RegisterSkin (char *name); image_t *Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, int height, int realheight, size_t data_size, imagetype_t type, int bits); -image_t *Vk_FindImage (char *name, imagetype_t type); +image_t *Vk_FindImageUnsafe (const char *name, imagetype_t type); +image_t *Vk_FindImage (const char *name, imagetype_t type); void Vk_TextureMode( char *string ); void Vk_LmapTextureMode( char *string ); void Vk_ImageList_f (void); diff --git a/src/vk/vk_image.c b/src/vk/vk_image.c index ee6cc32..41c10c8 100644 --- a/src/vk/vk_image.c +++ b/src/vk/vk_image.c @@ -1220,12 +1220,13 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth, /* =============== -Vk_FindImage +Vk_FindImageUnsafe Finds or loads the given image or NULL =============== */ -image_t *Vk_FindImage (char *name, imagetype_t type) +image_t * +Vk_FindImageUnsafe (const char *name, imagetype_t type) { image_t *image; int i, len; @@ -1277,6 +1278,23 @@ image_t *Vk_FindImage (char *name, imagetype_t type) image = (image_t *)LoadImage(name, namewe, ext, type, r_retexturing->value, (loadimage_t)Vk_LoadPic); + return image; +} + +/* +=============== +Vk_FindImage + +Finds or loads the given image or no texture. +=============== +*/ +image_t * +Vk_FindImage (const char *name, imagetype_t type) +{ + image_t *image; + + image = Vk_FindImageUnsafe (name, type); + if (!image && r_validation->value > 0) { R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); diff --git a/src/vk/vk_rmain.c b/src/vk/vk_rmain.c index 38e5ccf..e714c30 100644 --- a/src/vk/vk_rmain.c +++ b/src/vk/vk_rmain.c @@ -94,7 +94,7 @@ cvar_t *r_lightlevel; // FIXME: This is a HACK to get the client's light level cvar_t *vk_overbrightbits; cvar_t *r_validation; cvar_t *vk_picmip; -cvar_t *vk_skymip; +cvar_t *r_palettedtexture; cvar_t *vk_flashblend; cvar_t *vk_finish; #if defined(__APPLE__) @@ -1176,7 +1176,7 @@ R_Register( void ) vk_overbrightbits = ri.Cvar_Get("vk_overbrightbits", "1.0", CVAR_ARCHIVE); r_validation = ri.Cvar_Get("r_validation", "0", CVAR_ARCHIVE); vk_picmip = ri.Cvar_Get("vk_picmip", "0", 0); - vk_skymip = ri.Cvar_Get("vk_skymip", "0", 0); + r_palettedtexture = ri.Cvar_Get("r_palettedtexture", "0", 0); vk_flashblend = ri.Cvar_Get("vk_flashblend", "0", 0); vk_finish = ri.Cvar_Get("vk_finish", "0", CVAR_ARCHIVE); r_clear = ri.Cvar_Get("r_clear", "0", CVAR_ARCHIVE); diff --git a/src/vk/vk_warp.c b/src/vk/vk_warp.c index 5c8c875..f22859a 100644 --- a/src/vk/vk_warp.c +++ b/src/vk/vk_warp.c @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // vk_warp.c -- sky and water polygons #include "header/local.h" -static char skyname[MAX_QPATH]; static float skyrotate; static vec3_t skyaxis; static image_t *sky_images[6]; @@ -683,7 +682,6 @@ void R_DrawSkyBox (void) } } - /* ============ RE_SetSky_s @@ -693,8 +691,8 @@ RE_SetSky_s static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; void RE_SetSky_s (const char *name, float rotate, const vec3_t axis) { + char skyname[MAX_QPATH]; int i; - char pathname[MAX_QPATH]; strncpy(skyname, name, sizeof(skyname) - 1); skyrotate = rotate; @@ -702,31 +700,21 @@ void RE_SetSky_s (const char *name, float rotate, const vec3_t axis) for (i = 0; i<6; i++) { - // chop down rotating skies for less memory - if (vk_skymip->value || skyrotate) - vk_picmip->value++; + image_t *image; - Com_sprintf(pathname, sizeof(pathname), "env/%s%s.tga", skyname, suf[i]); + image = (image_t *)GetSkyImage(skyname, suf[i], + r_palettedtexture->value, (findimage_t)Vk_FindImageUnsafe); - sky_images[i] = Vk_FindImage(pathname, it_sky); - if (!sky_images[i]) { - Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m8", skyname, suf[i]); - sky_images[i] = Vk_FindImage(pathname, it_sky); - } - - if (!sky_images[i]) - sky_images[i] = r_notexture; - - if (vk_skymip->value || skyrotate) - { // take less memory - vk_picmip->value--; - sky_min = 1.0 / 256; - sky_max = 255.0 / 256; - } - else + if (!image) { - sky_min = 1.0 / 512; - sky_max = 511.0 / 512; + R_Printf(PRINT_ALL, "%s: can't load %s:%s sky\n", + __func__, skyname, suf[i]); + image = r_notexture; } + + sky_images[i] = image; } + + sky_min = 1.0 / 512; + sky_max = 511.0 / 512; }