diff --git a/src/client/refresh/files/stb.c b/src/client/refresh/files/stb.c index f898238f..8467bd99 100644 --- a/src/client/refresh/files/stb.c +++ b/src/client/refresh/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/client/refresh/gl1/gl1_image.c b/src/client/refresh/gl1/gl1_image.c index 04b05157..838d1741 100644 --- a/src/client/refresh/gl1/gl1_image.c +++ b/src/client/refresh/gl1/gl1_image.c @@ -854,7 +854,7 @@ R_Upload8(byte *data, int width, int height, qboolean mipmap, qboolean is_sky) * This is also used as an entry point for the generated r_notexture */ image_t * -R_LoadPic(char *name, byte *pic, int width, int realwidth, +R_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 *image; @@ -1028,10 +1028,10 @@ R_LoadPic(char *name, byte *pic, int width, int realwidth, } /* - * Finds or loads the given image + * Finds or loads the given image or null */ image_t * -R_FindImage(char *name, imagetype_t type) +R_FindImageUnsafe(const char *name, imagetype_t type) { image_t *image; int i, len; @@ -1084,6 +1084,19 @@ R_FindImage(char *name, imagetype_t type) image = (image_t *)LoadImage(name, namewe, ext, type, r_retexturing->value, (loadimage_t)R_LoadPic); + return image; +} + +/* + * Finds or loads the given image or notexture + */ +image_t * +R_FindImage(const char *name, imagetype_t type) +{ + image_t *image; + + image = R_FindImageUnsafe(name, type); + if (!image) { R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index 164dd8f1..3c013958 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -1263,7 +1263,7 @@ R_Register(void) gl_anisotropic = ri.Cvar_Get("r_anisotropic", "0", CVAR_ARCHIVE); r_lockpvs = ri.Cvar_Get("r_lockpvs", "0", 0); - gl1_palettedtexture = ri.Cvar_Get("gl1_palettedtexture", "0", CVAR_ARCHIVE); + gl1_palettedtexture = ri.Cvar_Get("r_palettedtextures", "0", CVAR_ARCHIVE); gl1_pointparameters = ri.Cvar_Get("gl1_pointparameters", "1", CVAR_ARCHIVE); gl_drawbuffer = ri.Cvar_Get("gl_drawbuffer", "GL_BACK", 0); diff --git a/src/client/refresh/gl1/gl1_warp.c b/src/client/refresh/gl1/gl1_warp.c index 498aba8d..7e1d77d5 100644 --- a/src/client/refresh/gl1/gl1_warp.c +++ b/src/client/refresh/gl1/gl1_warp.c @@ -31,7 +31,6 @@ #define ON_EPSILON 0.1 /* point on plane side epsilon */ #define MAX_CLIP_VERTS 64 -char skyname[MAX_QPATH]; float skyrotate; vec3_t skyaxis; image_t *sky_images[6]; @@ -740,8 +739,8 @@ R_DrawSkyBox(void) void RI_SetSky(char *name, float rotate, vec3_t axis) { - int i; - char pathname[MAX_QPATH]; + char skyname[MAX_QPATH]; + int i; Q_strlcpy(skyname, name, sizeof(skyname)); skyrotate = rotate; @@ -749,33 +748,22 @@ RI_SetSky(char *name, float rotate, vec3_t axis) for (i = 0; i < 6; i++) { - if (gl_config.palettedtexture) + image_t *image; + + image = (image_t *)GetSkyImage(skyname, suf[i], + gl_config.palettedtexture, (findimage_t)R_FindImageUnsafe); + + if (!image) { - Com_sprintf(pathname, sizeof(pathname), "env/%s%s.pcx", - skyname, suf[i]); - } - else - { - Com_sprintf(pathname, sizeof(pathname), "env/%s%s.tga", - skyname, suf[i]); + R_Printf(PRINT_ALL, "%s: can't load %s:%s sky\n", + __func__, skyname, suf[i]); + image = r_notexture; } - sky_images[i] = R_FindImage(pathname, it_sky); - - if (!sky_images[i] || sky_images[i] == r_notexture) - { - Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m8", - skyname, suf[i]); - sky_images[i] = R_FindImage(pathname, it_sky); - } - - if (!sky_images[i]) - { - sky_images[i] = r_notexture; - } - - sky_min = 1.0 / 512; - sky_max = 511.0 / 512; + sky_images[i] = image; } + + sky_min = 1.0 / 512; + sky_max = 511.0 / 512; } diff --git a/src/client/refresh/gl1/header/local.h b/src/client/refresh/gl1/header/local.h index d3934c2b..055ad23d 100644 --- a/src/client/refresh/gl1/header/local.h +++ b/src/client/refresh/gl1/header/local.h @@ -281,9 +281,10 @@ void COM_StripExtension(char *in, char *out); void R_SwapBuffers(int); -image_t *R_LoadPic(char *name, byte *pic, int width, int realwidth, +image_t *R_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 *R_FindImage(char *name, imagetype_t type); +image_t *R_FindImageUnsafe(const char *name, imagetype_t type); +image_t *R_FindImage(const char *name, imagetype_t type); void R_TextureMode(char *string); void R_ImageList_f(void); diff --git a/src/client/refresh/gl3/gl3_image.c b/src/client/refresh/gl3/gl3_image.c index 3f6409b5..b4c4ec0b 100644 --- a/src/client/refresh/gl3/gl3_image.c +++ b/src/client/refresh/gl3/gl3_image.c @@ -598,10 +598,10 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth, } /* - * Finds or loads the given image + * Finds or loads the given image or NULL */ gl3image_t * -GL3_FindImage(char *name, imagetype_t type) +GL3_FindImageUnsafe(const char *name, imagetype_t type) { gl3image_t *image; int i, len; @@ -654,6 +654,18 @@ GL3_FindImage(char *name, imagetype_t type) image = (gl3image_t *)LoadImage(name, namewe, ext, type, r_retexturing->value, (loadimage_t)GL3_LoadPic); + return image; +} + +/* + * Finds or loads the given image or notexture + */ +gl3image_t * +GL3_FindImage(const char *name, imagetype_t type) +{ + gl3image_t *image; + + image = GL3_FindImageUnsafe(name, type); if (!image) { R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index 5753a5b4..eb819871 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -129,6 +129,7 @@ cvar_t *gl_shadows; cvar_t *gl3_debugcontext; cvar_t *gl3_usebigvbo; cvar_t *r_fixsurfsky; +cvar_t *r_palettedtexture; cvar_t *gl3_usefbo; // Yaw-Pitch-Roll @@ -228,6 +229,7 @@ GL3_Register(void) r_drawworld = ri.Cvar_Get("r_drawworld", "1", 0); r_fullbright = ri.Cvar_Get("r_fullbright", "0", 0); r_fixsurfsky = ri.Cvar_Get("r_fixsurfsky", "0", CVAR_ARCHIVE); + r_palettedtexture = ri.Cvar_Get("r_palettedtexture", "0", 0); /* don't bilerp characters and crosshairs */ gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", CVAR_ARCHIVE); diff --git a/src/client/refresh/gl3/gl3_warp.c b/src/client/refresh/gl3/gl3_warp.c index 59673155..ee5bd720 100644 --- a/src/client/refresh/gl3/gl3_warp.c +++ b/src/client/refresh/gl3/gl3_warp.c @@ -313,9 +313,8 @@ int vec_to_st[6][3] = { void GL3_SetSky(char *name, float rotate, vec3_t axis) { - int i; - char pathname[MAX_QPATH]; - char skyname[MAX_QPATH]; + char skyname[MAX_QPATH]; + int i; Q_strlcpy(skyname, name, sizeof(skyname)); skyrotate = rotate; @@ -323,27 +322,23 @@ GL3_SetSky(char *name, float rotate, vec3_t axis) for (i = 0; i < 6; i++) { - // NOTE: there might be a paletted .pcx version, which was only used - // if gl_config.palettedtexture so it *shouldn't* be relevant for he GL3 renderer - Com_sprintf(pathname, sizeof(pathname), "env/%s%s.tga", skyname, suf[i]); + gl3image_t *image; - sky_images[i] = GL3_FindImage(pathname, it_sky); + image = (gl3image_t *)GetSkyImage(skyname, suf[i], + r_palettedtexture->value, (findimage_t)GL3_FindImageUnsafe); - if (sky_images[i] == NULL || sky_images[i] == gl3_notexture) + if (!image) { - Com_sprintf(pathname, sizeof(pathname), "pics/Skies/%s%s.m8", skyname, suf[i]); - - sky_images[i] = GL3_FindImage(pathname, it_sky); + R_Printf(PRINT_ALL, "%s: can't load %s:%s sky\n", + __func__, skyname, suf[i]); + image = gl3_notexture; } - if (sky_images[i] == NULL) - { - sky_images[i] = gl3_notexture; - } - - sky_min = 1.0 / 512; - sky_max = 511.0 / 512; + sky_images[i] = image; } + + sky_min = 1.0 / 512; + sky_max = 511.0 / 512; } static void diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index d3fbf0db..d09e2d0c 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -442,7 +442,8 @@ extern void GL3_BindLightmap(int lightmapnum); extern gl3image_t *GL3_LoadPic(char *name, byte *pic, int width, int realwidth, int height, int realheight, size_t data_size, imagetype_t type, int bits); -extern gl3image_t *GL3_FindImage(char *name, imagetype_t type); +extern gl3image_t *GL3_FindImageUnsafe(const char *name, imagetype_t type); +extern gl3image_t *GL3_FindImage(const char *name, imagetype_t type); extern gl3image_t *GL3_RegisterSkin(char *name); extern void GL3_ShutdownImages(void); extern void GL3_FreeUnusedImages(void); @@ -548,6 +549,7 @@ extern cvar_t *r_modulate; extern cvar_t *gl_lightmap; extern cvar_t *gl_shadows; extern cvar_t *r_fixsurfsky; +extern cvar_t *r_palettedtexture; extern cvar_t *gl3_debugcontext; diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index a88f481e..4ddfa4f2 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -105,12 +105,14 @@ extern const byte* Mod_DecompressVis(const byte *in, int row); /* Shared models load */ typedef struct image_s* (*findimage_t)(char *name, imagetype_t type); -void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen, +extern void *Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen, vec3_t mins, vec3_t maxs, struct image_s **skins, findimage_t find_image, modtype_t *type); extern void *Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen, 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/client/refresh/soft/header/local.h b/src/client/refresh/soft/header/local.h index 27ccc32f..ef67ab7a 100644 --- a/src/client/refresh/soft/header/local.h +++ b/src/client/refresh/soft/header/local.h @@ -588,7 +588,8 @@ void RE_Draw_FadeScreen (void); extern byte d_8to24table[256 * 4]; void R_InitImages(void); void R_ShutdownImages(void); -image_t *R_FindImage(char *name, imagetype_t type); +image_t *R_FindImageUnsafe(const char *name, imagetype_t type); +image_t *R_FindImage(const char *name, imagetype_t type); byte *Get_BestImageSize(const image_t *image, int *req_width, int *req_height); void R_FreeUnusedImages(void); qboolean R_ImageHasFreeSpace(void); diff --git a/src/client/refresh/soft/sw_image.c b/src/client/refresh/soft/sw_image.c index 5ee070ed..db657bf2 100644 --- a/src/client/refresh/soft/sw_image.c +++ b/src/client/refresh/soft/sw_image.c @@ -476,13 +476,13 @@ R_ApplyLight(pixel_t pix, const light3_t light) /* =============== -R_FindImage +R_FindImageUnsafe -Finds or loads the given image +Finds or loads the given image or NULL =============== */ image_t * -R_FindImage(char *name, imagetype_t type) +R_FindImageUnsafe(const char *name, imagetype_t type) { image_t *image; int i, len; @@ -541,6 +541,22 @@ R_FindImage(char *name, imagetype_t type) image = (image_t *)LoadImage(name, namewe, ext, type, r_retexturing->value, (loadimage_t)R_LoadPic); + return image; +} + +/* +=============== +R_FindImage + +Finds or loads the given image or no_texture +=============== +*/ +image_t * +R_FindImage(const char *name, imagetype_t type) +{ + image_t *image; + + image = R_FindImageUnsafe(name, type); if (!image) { R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name); diff --git a/src/client/refresh/soft/sw_main.c b/src/client/refresh/soft/sw_main.c index 8169a8d0..dc5e1db5 100644 --- a/src/client/refresh/soft/sw_main.c +++ b/src/client/refresh/soft/sw_main.c @@ -54,7 +54,6 @@ refimport_t ri; byte d_8to24table[256 * 4]; -char skyname[MAX_QPATH]; vec3_t skyaxis; refdef_t r_newrefdef; @@ -173,6 +172,7 @@ static cvar_t *vid_fullscreen; static cvar_t *vid_gamma; static cvar_t *r_lockpvs; +static cvar_t *r_palettedtexture; // sw_vars.c @@ -411,6 +411,7 @@ R_RegisterVariables (void) r_customwidth = ri.Cvar_Get("r_customwidth", "1024", CVAR_ARCHIVE); r_customheight = ri.Cvar_Get("r_customheight", "768", CVAR_ARCHIVE); r_fixsurfsky = ri.Cvar_Get("r_fixsurfsky", "0", CVAR_ARCHIVE); + r_palettedtexture = ri.Cvar_Get("r_palettedtexture", "0", 0); vid_fullscreen = ri.Cvar_Get( "vid_fullscreen", "0", CVAR_ARCHIVE ); vid_gamma = ri.Cvar_Get( "vid_gamma", "1.0", CVAR_ARCHIVE ); @@ -1723,26 +1724,32 @@ RE_SetSky // 3dstudio environment map names static const char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; static const int r_skysideimage[6] = {5, 2, 4, 1, 0, 3}; -extern mtexinfo_t r_skytexinfo[6]; +extern mtexinfo_t r_skytexinfo[6]; static void RE_SetSky (char *name, float rotate, vec3_t axis) { + char skyname[MAX_QPATH]; int i; - char pathname[MAX_QPATH]; Q_strlcpy (skyname, name, sizeof(skyname)); VectorCopy (axis, skyaxis); for (i=0 ; i<6 ; i++) { - Com_sprintf (pathname, sizeof(pathname), "env/%s%s.pcx", skyname, suf[r_skysideimage[i]]); - r_skytexinfo[i].image = R_FindImage (pathname, it_sky); - if (!r_skytexinfo[i].image) + image_t *image; + + image = (image_t *)GetSkyImage(skyname, suf[r_skysideimage[i]], + r_palettedtexture->value, (findimage_t)R_FindImageUnsafe); + + if (!image) { - Com_sprintf (pathname, sizeof(pathname), "pics/Skies/%s%s.m8", skyname, suf[r_skysideimage[i]]); - r_skytexinfo[i].image = R_FindImage (pathname, it_sky); + R_Printf(PRINT_ALL, "%s: can't load %s:%s sky\n", + __func__, skyname, suf[r_skysideimage[i]]); + image = r_notexture_mip; } + + r_skytexinfo[i].image = image; } } diff --git a/src/common/cvar.c b/src/common/cvar.c index 06d56db6..14bc61fb 100644 --- a/src/common/cvar.c +++ b/src/common/cvar.c @@ -62,7 +62,8 @@ replacement_t replacements[] = { {"gl_mode", "r_mode"}, {"gl_modulate", "r_modulate"}, {"gl_overbrightbits", "gl1_overbrightbits"}, - {"gl_palettedtextures", "gl1_palettedtextures"}, + {"gl_palettedtextures", "r_palettedtextures"}, + {"gl1_palettedtextures", "r_palettedtextures"}, {"gl_particle_min_size", "gl1_particle_min_size"}, {"gl_particle_max_size", "gl1_particle_max_size"}, {"gl_particle_size", "gl1_particle_size"},