render: Save original name of requested image

This commit is contained in:
Denis Pauk 2023-11-26 23:50:29 +02:00
parent 8d35e72606
commit 888e9bac9d
7 changed files with 93 additions and 56 deletions

View file

@ -5951,7 +5951,6 @@ PlayerConfig_MenuDraw(void)
{
entity_t entity;
char scratch[MAX_QPATH];
struct image_s *skin;
char* mdlname = s_modelname.data[s_player_model_box.curvalue];
char* imgname = s_skinnames[s_player_model_box.curvalue].data[s_player_skin_box.curvalue];
@ -5960,22 +5959,9 @@ PlayerConfig_MenuDraw(void)
Com_sprintf(scratch, sizeof(scratch), "players/%s/tris.md2", mdlname);
entity.model = R_RegisterModel(scratch);
Com_sprintf(scratch, sizeof(scratch), "players/%s/%s.png", mdlname,
Com_sprintf(scratch, sizeof(scratch), "players/%s/%s.pcx", mdlname,
imgname);
skin = R_RegisterSkin(scratch);
if (!skin)
{
Com_sprintf(scratch, sizeof(scratch), "players/%s/%s.pcx", mdlname,
imgname);
skin = R_RegisterSkin(scratch);
}
if (!skin)
{
Com_sprintf(scratch, sizeof(scratch), "players/%s/%s.m8", mdlname,
imgname);
skin = R_RegisterSkin(scratch);
}
entity.skin = skin;
entity.skin = R_RegisterSkin(scratch);
entity.flags = RF_FULLBRIGHT;
entity.origin[0] = 80;

View file

@ -2054,7 +2054,7 @@ Mod_LoadBSPX(int filesize, const byte *mod_base)
int i, numlumps, xofs;
bspx_lump_t *lump;
// find end of last lump
/* find end of last lump */
header = (dheader_t*)mod_base;
xofs = 0;

View file

@ -491,8 +491,8 @@ LoadHiColorImage(const char *name, const char* namewe, const char *ext,
return image;
}
struct image_s *
R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type,
static struct image_s *
LoadImage_Ext(const char *name, const char* namewe, const char *ext, imagetype_t type,
qboolean r_retexturing, loadimage_t load_image)
{
struct image_s *image = NULL;
@ -556,15 +556,15 @@ R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t t
}
else if (!strcmp(ext, "wal"))
{
image = LoadWal(namewe, type, load_image);
image = LoadWal(name, namewe, type, load_image);
}
else if (!strcmp(ext, "m8"))
{
image = LoadM8(namewe, type, load_image);
image = LoadM8(name, namewe, type, load_image);
}
else if (!strcmp(ext, "m32"))
{
image = LoadM32(namewe, type, load_image);
image = LoadM32(name, namewe, type, load_image);
}
else if (!strcmp(ext, "tga") ||
!strcmp(ext, "png") ||
@ -589,6 +589,38 @@ R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t t
return image;
}
struct image_s *
R_LoadImage(const char *name, const char* namewe, const char *ext, imagetype_t type,
qboolean r_retexturing, loadimage_t load_image)
{
struct image_s *image = NULL;
/* original name */
image = LoadImage_Ext(name, namewe, ext, type, r_retexturing, load_image);
/* pcx check */
if (!image)
{
image = LoadImage_Ext(name, namewe, "pcx", type, r_retexturing, load_image);
}
/* png check */
if (!image)
{
image = LoadImage_Ext(name, namewe, "png", type, r_retexturing, load_image);
}
/* m32 check */
if (!image)
{
image = LoadImage_Ext(name, namewe, "m32", type, r_retexturing, load_image);
}
/* m8 check */
if (!image)
{
image = LoadImage_Ext(name, namewe, "m8", type, r_retexturing, load_image);
}
return image;
}
struct image_s*
GetSkyImage(const char *skyname, const char* surfname, qboolean palettedtexture,
findimage_t find_image)

View file

@ -27,7 +27,8 @@
#include "../ref_shared.h"
struct image_s *
LoadWalQ2(const char *name, const byte *data, size_t size, imagetype_t type, loadimage_t load_image)
LoadWalQ2(const char *origname, const char *name, const byte *data, size_t size,
imagetype_t type, loadimage_t load_image)
{
int width, height, ofs;
miptex_t *mt;
@ -51,14 +52,15 @@ LoadWalQ2(const char *name, const byte *data, size_t size, imagetype_t type, loa
return NULL;
}
return load_image(name, (byte *)data + ofs,
return load_image(origname, (byte *)data + ofs,
width, 0,
height, 0,
(size - ofs), type, 8);
}
struct image_s *
LoadWalDKM(const char *name, const byte *data, size_t size, imagetype_t type, loadimage_t load_image)
LoadWalDKM(const char *origname, const char *name, const byte *data, size_t size,
imagetype_t type, loadimage_t load_image)
{
byte *image_buffer = NULL;
int width, height, ofs, i;
@ -100,7 +102,7 @@ LoadWalDKM(const char *name, const byte *data, size_t size, imagetype_t type, lo
image_buffer[i * 4 + 3] = value == 255 ? 0 : 255;
}
image = load_image(name, image_buffer,
image = load_image(origname, image_buffer,
width, 0,
height, 0,
(size - ofs), type, 32);
@ -110,14 +112,15 @@ LoadWalDKM(const char *name, const byte *data, size_t size, imagetype_t type, lo
}
struct image_s *
LoadWal(const char *origname, imagetype_t type, loadimage_t load_image)
LoadWal(const char *origname, const char *namewe, imagetype_t type,
loadimage_t load_image)
{
struct image_s *image;
char name[256];
byte *data;
size_t size;
FixFileExt(origname, "wal", name, sizeof(name));
FixFileExt(namewe, "wal", name, sizeof(name));
size = ri.FS_LoadFile(name, (void **)&data);
@ -128,11 +131,11 @@ LoadWal(const char *origname, imagetype_t type, loadimage_t load_image)
if (*data == DKM_WAL_VERSION)
{
image = LoadWalDKM(name, data, size, type, load_image);
image = LoadWalDKM(origname, name, data, size, type, load_image);
}
else
{
image = LoadWalQ2(name, data, size, type, load_image);
image = LoadWalQ2(origname, name, data, size, type, load_image);
}
ri.FS_FreeFile((void *)data);
@ -141,7 +144,8 @@ LoadWal(const char *origname, imagetype_t type, loadimage_t load_image)
}
struct image_s *
LoadM8(const char *origname, imagetype_t type, loadimage_t load_image)
LoadM8(const char *origname, const char *namewe, imagetype_t type,
loadimage_t load_image)
{
int width, height, ofs, size, i;
byte *image_buffer = NULL;
@ -149,7 +153,7 @@ LoadM8(const char *origname, imagetype_t type, loadimage_t load_image)
char name[256];
m8tex_t *mt;
FixFileExt(origname, "m8", name, sizeof(name));
FixFileExt(namewe, "m8", name, sizeof(name));
size = ri.FS_LoadFile(name, (void **)&mt);
@ -194,7 +198,7 @@ LoadM8(const char *origname, imagetype_t type, loadimage_t load_image)
image_buffer[i * 4 + 3] = value == 255 ? 0 : 255;
}
image = load_image(name, image_buffer,
image = load_image(origname, image_buffer,
width, 0,
height, 0,
(size - ofs), type, 32);
@ -206,14 +210,15 @@ LoadM8(const char *origname, imagetype_t type, loadimage_t load_image)
}
struct image_s *
LoadM32(const char *origname, imagetype_t type, loadimage_t load_image)
LoadM32(const char *origname, const char *namewe, imagetype_t type,
loadimage_t load_image)
{
m32tex_t *mt;
int width, height, ofs, size;
struct image_s *image;
char name[256];
FixFileExt(origname, "m32", name, sizeof(name));
FixFileExt(namewe, "m32", name, sizeof(name));
size = ri.FS_LoadFile(name, (void **)&mt);
@ -248,7 +253,7 @@ LoadM32(const char *origname, imagetype_t type, loadimage_t load_image)
return NULL;
}
image = load_image(name, (byte *)mt + ofs,
image = load_image(origname, (byte *)mt + ofs,
width, 0,
height, 0,
(size - ofs) / 4, type, 32);

View file

@ -863,8 +863,10 @@ R_LoadPic(const char *name, byte *pic, int width, int realwidth,
qboolean nolerp = false;
if (r_2D_unfiltered->value && type == it_pic)
{
// if r_2D_unfiltered is true(ish), nolerp should usually be true,
// *unless* the texture is on the r_lerp_list
/*
* if r_2D_unfiltered is true(ish), nolerp should usually be true,
* *unless* the texture is on the r_lerp_list
*/
nolerp = (r_lerp_list->string == NULL) || (strstr(r_lerp_list->string, name) == NULL);
}
else if (r_nolerp_list != NULL && r_nolerp_list->string != NULL)
@ -885,7 +887,8 @@ R_LoadPic(const char *name, byte *pic, int width, int realwidth,
{
if (numgltextures == MAX_GLTEXTURES)
{
Com_Error(ERR_DROP, "MAX_GLTEXTURES");
Com_Error(ERR_DROP, "%s: load %s is failed MAX_GLTEXTURES",
__func__, name);
}
numgltextures++;

View file

@ -93,9 +93,12 @@ extern void R_Printf(int level, const char* msg, ...) PRINTF_ATTR(2, 3);
/* Shared images load */
typedef struct image_s* (*loadimage_t)(const char *name, byte *pic, int width, int realwidth,
int height, int realheight, size_t data_size, imagetype_t type, int bits);
extern struct image_s* LoadWal(const char *origname, imagetype_t type, loadimage_t load_image);
extern struct image_s* LoadM8(const char *origname, imagetype_t type, loadimage_t load_image);
extern struct image_s* LoadM32(const char *origname, imagetype_t type, loadimage_t load_image);
extern struct image_s* LoadWal(const char *origname, const char *namewe, imagetype_t type,
loadimage_t load_image);
extern struct image_s* LoadM8(const char *origname, const char *namewe, imagetype_t type,
loadimage_t load_image);
extern struct image_s* LoadM32(const char *origname, const char *namewe, imagetype_t type,
loadimage_t load_image);
extern void FixFileExt(const char *origname, const char *ext, char *filename, size_t size);
extern void GetPCXPalette(byte **colormap, unsigned *d_8to24table);
extern void GetPCXPalette24to8(byte *d_8to24table, byte** d_16to8table);

View file

@ -949,7 +949,8 @@ Returns number of mip levels and scales to nearest power of 2.
===============
*/
#if 0
static uint32_t Vk_Upload32 (byte *data, int width, int height, imagetype_t type,
static uint32_t
Vk_Upload32(byte *data, int width, int height, imagetype_t type,
byte **texBuffer, int *upload_width, int *upload_height)
{
int scaled_width, scaled_height;
@ -1018,7 +1019,6 @@ Vk_Upload8
Returns number of mip levels
===============
*/
static uint32_t
Vk_Upload8(const byte *data, int width, int height, imagetype_t type,
byte **texBuffer, int *upload_width, int *upload_height)
@ -1246,7 +1246,7 @@ Finds or loads the given image or NULL
===============
*/
image_t *
Vk_FindImage (const char *name, imagetype_t type)
Vk_FindImage(const char *name, imagetype_t type)
{
image_t *image;
int i, len;
@ -1282,7 +1282,7 @@ Vk_FindImage (const char *name, imagetype_t type)
*ptr = '/';
}
// look for it
/* look for it */
for (i=0, image=vktextures ; i<numvktextures ; i++,image++)
{
if (!strcmp(name, image->name))
@ -1292,9 +1292,9 @@ Vk_FindImage (const char *name, imagetype_t type)
}
}
//
// load the pic from disk
//
/*
* load the pic from disk
*/
image = (image_t *)R_LoadImage(name, namewe, ext, type,
r_retexturing->value, (loadimage_t)Vk_LoadPic);
@ -1311,12 +1311,14 @@ Vk_FindImage (const char *name, imagetype_t type)
RE_RegisterSkin
===============
*/
struct image_s *RE_RegisterSkin (const char *name)
struct image_s *
RE_RegisterSkin (const char *name)
{
return Vk_FindImage (name, it_skin);
}
qboolean Vk_ImageHasFreeSpace(void)
qboolean
Vk_ImageHasFreeSpace(void)
{
int i, used;
image_t *image;
@ -1338,7 +1340,7 @@ qboolean Vk_ImageHasFreeSpace(void)
image_max = used;
}
// should same size of free slots as currently used
/* should same size of free slots as currently used */
return (img_loaded + used) < MAX_VKTEXTURES;
}
@ -1357,11 +1359,11 @@ void Vk_FreeUnusedImages (void)
if (Vk_ImageHasFreeSpace())
{
// should be enough space for load next images
/* should be enough space for load next images */
return;
}
// never free r_notexture or particle texture
/* never free r_notexture or particle texture */
r_notexture->registration_sequence = registration_sequence;
r_particletexture->registration_sequence = registration_sequence;
r_squaretexture->registration_sequence = registration_sequence;
@ -1369,18 +1371,24 @@ void Vk_FreeUnusedImages (void)
for (i = 0, image = vktextures; i < numvktextures; i++, image++)
{
if (image->registration_sequence == registration_sequence)
{
continue; // used this sequence
}
if (!image->registration_sequence)
{
continue; // free image_t slot
}
if (image->type == it_pic)
{
continue; // don't free pics
}
if (r_validation->value > 0)
{
R_Printf(PRINT_ALL, "%s: Unload %s[%d]\n", __func__, image->name, img_loaded);
}
// free it
/* free it */
QVk_ReleaseTexture(&image->vk_texture);
memset(image, 0, sizeof(*image));
@ -1391,7 +1399,7 @@ void Vk_FreeUnusedImages (void)
}
}
// free all unused blocks
/* free all unused blocks */
vulkan_memory_free_unused();
}