renders: Support embeded image use

This commit is contained in:
Denis Pauk 2023-12-28 09:31:04 +02:00
parent abce26bdff
commit f89ea15d14
13 changed files with 103 additions and 23 deletions

View File

@ -376,6 +376,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
*skins = Hunk_Alloc((*numskins) * sizeof(struct image_s *));
/* copy back all values */
memset(pheader, 0, sizeof(*pheader));
pheader->skinwidth = skinwidth;
pheader->skinheight = skinheight;
pheader->framesize = framesize;
@ -648,6 +649,7 @@ Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen,
*skins = Hunk_Alloc((*numskins) * sizeof(struct image_s *));
/* Copy values as we have mostly same data format */
memset(pheader, 0, sizeof(*pheader));
pheader->skinwidth = pinmodel.skinwidth;
pheader->skinheight = pinmodel.skinheight;
pheader->framesize = pinmodel.framesize;
@ -802,6 +804,7 @@ Mod_LoadModel_Flex(const char *mod_name, const void *buffer, int modfilelen,
}
/* copy back all values */
memset(&dmdxheader, 0, sizeof(dmdxheader));
dmdxheader.skinwidth = LittleLong(header->skinwidth);
dmdxheader.skinheight = LittleLong(header->skinheight);
dmdxheader.framesize = LittleLong(header->framesize);
@ -1080,6 +1083,7 @@ Mod_LoadModel_DKM(const char *mod_name, const void *buffer, int modfilelen,
}
/* copy back all values */
memset(&dmdxheader, 0, sizeof(dmdxheader));
dmdxheader.skinwidth = 256;
dmdxheader.skinheight = 256;
if (header.version != DKM2_VERSION)
@ -1212,7 +1216,7 @@ Mod_LoadModel
void *
Mod_LoadModel(const char *mod_name, const void *buffer, int modfilelen,
vec3_t mins, vec3_t maxs, struct image_s ***skins, int *numskins,
findimage_t find_image, modtype_t *type)
findimage_t find_image, loadimage_t load_image, modtype_t *type)
{
void *extradata = NULL;
@ -1246,7 +1250,7 @@ Mod_LoadModel(const char *mod_name, const void *buffer, int modfilelen,
if (extradata)
{
Mod_ReLoadSkins(*skins, find_image, extradata, *type);
Mod_ReLoadSkins(*skins, find_image, load_image, extradata, *type);
}
return extradata;
@ -1395,8 +1399,8 @@ Reload images in SP2/MD2 (mark registration_sequence)
=================
*/
int
Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata,
modtype_t type)
Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, loadimage_t load_image,
void *extradata, modtype_t type)
{
if (type == mod_sprite)
{
@ -1425,9 +1429,26 @@ Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata,
int i;
pheader = (dmdx_t *)extradata;
for (i=0; i < pheader->num_skins; i++)
if (pheader->ofs_imgbit && load_image)
{
skins[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
byte* images = (byte *)pheader + pheader->ofs_imgbit;
for (i = 0; i < pheader->num_skins; i++)
{
skins[i] = load_image(
(char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
images, pheader->skinwidth, pheader->skinwidth,
pheader->skinheight, pheader->skinheight,
pheader->skinheight * pheader->skinwidth,
it_skin, pheader->num_imgbit);
images += (pheader->skinheight * pheader->skinwidth * pheader->ofs_imgbit / 8);
}
}
else
{
for (i=0; i < pheader->num_skins; i++)
{
skins[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
}
}
return pheader->num_frames;
}

View File

@ -881,6 +881,13 @@ R_LoadPic(const char *name, byte *pic, int width, int realwidth,
{
break;
}
if (!strcmp(image->name, name))
{
/* we already have such image */
image->registration_sequence = registration_sequence;
return image;
}
}
if (i == numgltextures)

View File

@ -831,7 +831,8 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)R_FindImage, &(mod->type));
(findimage_t)R_FindImage, (loadimage_t)R_LoadPic,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -936,7 +937,8 @@ RI_RegisterModel(const char *name)
{
/* numframes is unused for SP2 but lets set it also */
mod->numframes = Mod_ReLoadSkins((struct image_s **)mod->skins,
(findimage_t)R_FindImage, mod->extradata, mod->type);
(findimage_t)R_FindImage, (loadimage_t)R_LoadPic,
mod->extradata, mod->type);
}
}

View File

@ -401,6 +401,13 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
{
break;
}
if (!strcmp(image->name, name))
{
/* we already have such image */
image->registration_sequence = registration_sequence;
return image;
}
}
if (i == numgl3textures)

View File

@ -832,7 +832,8 @@ Mod_ForName(const char *name, gl3model_t *parent_model, qboolean crash)
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)GL3_FindImage, &(mod->type));
(findimage_t)GL3_FindImage, (loadimage_t)GL3_LoadPic,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -939,7 +940,8 @@ GL3_RegisterModel(const char *name)
{
/* numframes is unused for SP2 but lets set it also */
mod->numframes = Mod_ReLoadSkins((struct image_s **)mod->skins,
(findimage_t)GL3_FindImage, mod->extradata, mod->type);
(findimage_t)GL3_FindImage, (loadimage_t)GL3_LoadPic,
mod->extradata, mod->type);
}
}

View File

@ -402,6 +402,13 @@ GL4_LoadPic(char *name, byte *pic, int width, int realwidth,
{
break;
}
if (!strcmp(image->name, name))
{
/* we already have such image */
image->registration_sequence = registration_sequence;
return image;
}
}
if (i == numgl4textures)

View File

@ -830,7 +830,8 @@ Mod_ForName(const char *name, gl4model_t *parent_model, qboolean crash)
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)GL4_FindImage, &(mod->type));
(findimage_t)GL4_FindImage, (loadimage_t)GL4_LoadPic,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -937,7 +938,8 @@ GL4_RegisterModel(const char *name)
{
/* numframes is unused for SP2 but lets set it also */
mod->numframes = Mod_ReLoadSkins((struct image_s **)mod->skins,
(findimage_t)GL4_FindImage, mod->extradata, mod->type);
(findimage_t)GL4_FindImage, (loadimage_t)GL4_LoadPic,
mod->extradata, mod->type);
}
}

View File

@ -324,9 +324,9 @@ typedef struct
typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type);
extern void *Mod_LoadModel(const char *mod_name, const void *buffer, int modfilelen,
vec3_t mins, vec3_t maxs, struct image_s ***skins, int *numskins,
findimage_t find_image, modtype_t *type);
findimage_t find_image, loadimage_t load_image, modtype_t *type);
extern int Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image,
void *extradata, modtype_t type);
loadimage_t load_image, void *extradata, modtype_t type);
extern struct image_s *GetSkyImage(const char *skyname, const char* surfname,
qboolean palettedtexture, findimage_t find_image);
extern struct image_s *GetTexImage(const char *name, findimage_t find_image);

View File

@ -564,6 +564,8 @@ extern byte d_8to24table[256 * 4];
void R_InitImages(void);
void R_ShutdownImages(void);
image_t *R_FindImage(const char *name, imagetype_t type);
image_t *R_LoadPic(char *name, byte *pic, int width, int realwidth, int height, int realheight,
size_t data_size, imagetype_t type, int bits);
byte *Get_BestImageSize(const image_t *image, int *req_width, int *req_height);
void R_FreeUnusedImages(void);
qboolean R_ImageHasFreeSpace(void);

View File

@ -88,7 +88,7 @@ R_ImageList_f (void)
//=======================================================
static image_t *
R_FindFreeImage (void)
R_FindFreeImage(char *name)
{
image_t *image;
int i;
@ -97,8 +97,18 @@ R_FindFreeImage (void)
for (i=0, image=r_images ; i<numr_images ; i++,image++)
{
if (!image->registration_sequence)
{
break;
}
if (!strcmp(image->name, name))
{
/* we already have such image */
image->registration_sequence = registration_sequence;
return image;
}
}
if (i == numr_images)
{
if (numr_images == MAX_RIMAGES)
@ -241,7 +251,7 @@ R_Convert32To8bit(const unsigned char* pic_in, pixel_t* pic_out, size_t size,
/*
================
R_LoadPic
R_LoadPic8
================
*/
@ -256,11 +266,17 @@ R_LoadPic8 (char *name, byte *pic, int width, int realwidth, int height, int rea
/* data_size/size are unsigned */
if (!pic || data_size == 0 || width <= 0 || height <= 0 || size == 0)
{
return NULL;
}
image = R_FindFreeImage(name);
image = R_FindFreeImage();
if (strlen(name) >= sizeof(image->name))
{
Com_Error(ERR_DROP, "%s: '%s' is too long", __func__, name);
}
strcpy (image->name, name);
image->registration_sequence = registration_sequence;
@ -314,8 +330,8 @@ R_LoadPic8 (char *name, byte *pic, int width, int realwidth, int height, int rea
return image;
}
static image_t *
R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int realheight,
image_t *
R_LoadPic(char *name, byte *pic, int width, int realwidth, int height, int realheight,
size_t data_size, imagetype_t type, int bits)
{
if (!realwidth || !realheight)

View File

@ -655,7 +655,8 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)R_FindImage, &(mod->type));
(findimage_t)R_FindImage, (loadimage_t)R_LoadPic,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -761,7 +762,8 @@ RE_RegisterModel(const char *name)
{
/* numframes is unused for SP2 but lets set it also */
mod->numframes = Mod_ReLoadSkins((struct image_s **)mod->skins,
(findimage_t)R_FindImage, mod->extradata, mod->type);
(findimage_t)R_FindImage, (loadimage_t)R_LoadPic,
mod->extradata, mod->type);
}
}

View File

@ -1067,8 +1067,18 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth,
for (i = 0, image = vktextures; i<numvktextures; i++, image++)
{
if (image->vk_texture.resource.image == VK_NULL_HANDLE)
{
break;
}
if (!strcmp(image->name, name))
{
/* we already have such image */
image->registration_sequence = registration_sequence;
return image;
}
}
if (i == numvktextures)
{
if (numvktextures == MAX_VKTEXTURES)

View File

@ -822,7 +822,8 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)Vk_FindImage, &(mod->type));
(findimage_t)Vk_FindImage, (loadimage_t)Vk_LoadPic,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -960,7 +961,8 @@ RE_RegisterModel(const char *name)
{
/* numframes is unused for SP2 but lets set it also */
mod->numframes = Mod_ReLoadSkins((struct image_s **)mod->skins,
(findimage_t)Vk_FindImage, mod->extradata, mod->type);
(findimage_t)Vk_FindImage, (loadimage_t)Vk_LoadPic,
mod->extradata, mod->type);
}
}