render: remove skin count limit

This commit is contained in:
Denis Pauk 2023-12-25 14:00:31 +02:00
parent d4aa45d6cb
commit 06ee407efa
21 changed files with 168 additions and 234 deletions

View File

@ -275,9 +275,9 @@ Mod_LoadMDL
=================
*/
static void *
Mod_LoadMDL (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)
Mod_LoadMDL(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)
{
const mdl_header_t *pinmodel;
int version;
@ -371,8 +371,10 @@ Mod_LoadMDL (const char *mod_name, const void *buffer, int modfilelen,
return NULL;
}
extradata = Hunk_Begin(ofs_end);
*numskins = num_skins;
extradata = Hunk_Begin(ofs_end + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
pheader = Hunk_Alloc(ofs_end);
*skins = Hunk_Alloc((*numskins) * sizeof(struct image_s *));
/* copy back all values */
pheader->ident = IDALIASHEADER;
@ -579,9 +581,9 @@ Mod_LoadMD2
=================
*/
static 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)
Mod_LoadMD2(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)
{
vec3_t translate = {0, 0, 0};
dmdl_t *pinmodel, *pheader;
@ -591,7 +593,7 @@ Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
void *extradata;
int version;
int ofs_end;
int i;
int i, num_skins;
pinmodel = (dmdl_t *)buffer;
@ -611,8 +613,18 @@ Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
return NULL;
}
extradata = Hunk_Begin(modfilelen);
num_skins = LittleLong(pinmodel->num_skins);
if (num_skins < 0)
{
R_Printf(PRINT_ALL, "%s: model %s file has incorrect skins count %d",
__func__, mod_name, num_skins);
return NULL;
}
*numskins = num_skins;
extradata = Hunk_Begin(modfilelen + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
pheader = Hunk_Alloc(ofs_end);
*skins = Hunk_Alloc((*numskins) * sizeof(struct image_s *));
// byte swap the header fields and sanity check
for (i=0 ; i<sizeof(dmdl_t)/sizeof(int) ; i++)
@ -660,14 +672,6 @@ Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
return NULL;
}
if (pheader->num_skins > MAX_MD2SKINS)
{
R_Printf(PRINT_ALL, "%s has too many skins (%i > %i), "
"extra sprites will be ignored\n",
mod_name, pheader->num_skins, MAX_MD2SKINS);
pheader->num_skins = MAX_MD2SKINS;
}
//
// load base s and t vertices (not used in gl version)
//
@ -698,7 +702,7 @@ Mod_LoadMD2 (const char *mod_name, const void *buffer, int modfilelen,
// Load in our skins.
for (i=0; i < pheader->num_skins; i++)
{
skins[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
(*skins)[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
it_skin);
}
@ -722,8 +726,8 @@ Mod_LoadFlexModel
*/
static void *
Mod_LoadFlexModel(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)
vec3_t mins, vec3_t maxs, struct image_s ***skins, int *numskins,
findimage_t find_image, modtype_t *type)
{
char *src = (char *)buffer;
int version, size, i;
@ -825,8 +829,10 @@ Mod_LoadFlexModel(const char *mod_name, const void *buffer, int modfilelen,
return NULL;
}
extradata = Hunk_Begin(dmdlheader.ofs_end);
*numskins = dmdlheader.num_skins;
extradata = Hunk_Begin(dmdlheader.ofs_end + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
pheader = Hunk_Alloc(dmdlheader.ofs_end);
*skins = Hunk_Alloc((*numskins) * sizeof(struct image_s *));
memcpy(pheader, &dmdlheader, sizeof(dmdl_t));
}
@ -983,18 +989,10 @@ Mod_LoadFlexModel(const char *mod_name, const void *buffer, int modfilelen,
src += size;
}
if (pheader->num_skins > MAX_MD2SKINS)
{
R_Printf(PRINT_ALL, "%s has too many skins (%i > %i), "
"extra skins will be ignored\n",
mod_name, pheader->num_skins, MAX_MD2SKINS);
pheader->num_skins = MAX_MD2SKINS;
}
// Load in our skins.
for (i=0; i < pheader->num_skins; i++)
{
skins[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
(*skins)[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
it_skin);
}
@ -1012,8 +1010,8 @@ Mod_LoadFlexModel(const char *mod_name, const void *buffer, int modfilelen,
static void *
Mod_LoadDKMModel(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)
vec3_t mins, vec3_t maxs, struct image_s ***skins, int *numskins,
findimage_t find_image, modtype_t *type)
{
dmdl_t dmdlheader, *pheader = NULL;
dkm_header_t header = {0};
@ -1026,7 +1024,7 @@ Mod_LoadDKMModel(const char *mod_name, const void *buffer, int modfilelen,
__func__, mod_name, modfilelen);
}
// byte swap the header fields and sanity check
/* byte swap the header fields and sanity check */
for (i=0 ; i<sizeof(dkm_header_t)/sizeof(int) ; i++)
((int *)&header)[i] = LittleLong(((int *)buffer)[i]);
@ -1082,8 +1080,11 @@ Mod_LoadDKMModel(const char *mod_name, const void *buffer, int modfilelen,
dmdlheader.ofs_glcmds = dmdlheader.ofs_frames + dmdlheader.num_frames * dmdlheader.framesize;
dmdlheader.ofs_end = dmdlheader.ofs_glcmds + dmdlheader.num_glcmds * sizeof(int);
extradata = Hunk_Begin(dmdlheader.ofs_end);
*numskins = dmdlheader.num_skins;
extradata = Hunk_Begin(dmdlheader.ofs_end + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
pheader = Hunk_Alloc(dmdlheader.ofs_end);
*skins = Hunk_Alloc((*numskins) * sizeof(struct image_s *));
memcpy(pheader, &dmdlheader, sizeof(dmdl_t));
memcpy ((byte*)pheader + pheader->ofs_skins, (byte *)buffer + header.ofs_skins,
@ -1106,18 +1107,10 @@ Mod_LoadDKMModel(const char *mod_name, const void *buffer, int modfilelen,
Mod_LoadDkmTriangleList (pheader,
(dkmtriangle_t *)((byte *)buffer + header.ofs_tris));
if (pheader->num_skins > MAX_MD2SKINS)
{
R_Printf(PRINT_ALL, "%s has too many skins (%i > %i), "
"extra skins will be ignored\n",
mod_name, pheader->num_skins, MAX_MD2SKINS);
pheader->num_skins = MAX_MD2SKINS;
}
// Load in our skins.
/* Load in our skins. */
for (i=0; i < pheader->num_skins; i++)
{
skins[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
(*skins)[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME,
it_skin);
}
@ -1133,47 +1126,6 @@ Mod_LoadDKMModel(const char *mod_name, const void *buffer, int modfilelen,
return extradata;
}
/*
=================
Mod_LoadAliasModel
=================
*/
void *
Mod_LoadAliasModel(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)
{
switch (LittleLong(*(unsigned *)buffer))
{
case DKMHEADER:
return Mod_LoadDKMModel(mod_name, buffer, modfilelen, mins, maxs, skins,
find_image, type);
case RAVENFMHEADER:
return Mod_LoadFlexModel(mod_name, buffer, modfilelen, mins, maxs, skins,
find_image, type);
case IDALIASHEADER:
return Mod_LoadMD2(mod_name, buffer, modfilelen, mins, maxs, skins,
find_image, type);
case IDMDLHEADER:
return Mod_LoadMDL(mod_name, buffer, modfilelen, mins, maxs, skins,
find_image, type);
}
return NULL;
}
/*
==============================================================================
SPRITE MODELS
==============================================================================
*/
/*
=================
Mod_LoadSP2
@ -1181,21 +1133,26 @@ Mod_LoadSP2
support for .sp2 sprites
=================
*/
void *
static void *
Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen,
struct image_s **skins, findimage_t find_image, modtype_t *type)
struct image_s ***skins, int *numskins,
findimage_t find_image, modtype_t *type)
{
dsprite_t *sprin, *sprout;
void *extradata;
int i;
int i, numframes;
sprin = (dsprite_t *)buffer;
extradata = Hunk_Begin(modfilelen);
numframes = LittleLong(sprin->numframes);
*numskins = numframes;
extradata = Hunk_Begin(modfilelen + Q_max(*numskins, MAX_MD2SKINS) * sizeof(struct image_s *));
sprout = Hunk_Alloc(modfilelen);
*skins = Hunk_Alloc((*numskins) * sizeof(struct image_s *));
sprout->ident = LittleLong(sprin->ident);
sprout->version = LittleLong(sprin->version);
sprout->numframes = LittleLong(sprin->numframes);
sprout->numframes = numframes;
if (sprout->version != SPRITE_VERSION)
{
@ -1204,14 +1161,6 @@ Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen,
return NULL;
}
if (sprout->numframes > MAX_MD2SKINS)
{
R_Printf(PRINT_ALL, "%s has too many frames (%i > %i), "
"extra frames will be ignored\n",
mod_name, sprout->numframes, MAX_MD2SKINS);
sprout->numframes = MAX_MD2SKINS;
}
/* byte swap everything */
for (i = 0; i < sprout->numframes; i++)
{
@ -1221,13 +1170,13 @@ Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen,
sprout->frames[i].origin_y = LittleLong(sprin->frames[i].origin_y);
memcpy(sprout->frames[i].name, sprin->frames[i].name, MAX_SKINNAME);
skins[i] = find_image((char *)sprout->frames[i].name, it_sprite);
if (!skins[i])
(*skins)[i] = find_image((char *)sprout->frames[i].name, it_sprite);
if (!(*skins)[i])
{
/* heretic2 sprites have no "sprites/" prefix */
snprintf(sprout->frames[i].name, MAX_SKINNAME,
"sprites/%s", sprin->frames[i].name);
skins[i] = find_image(sprout->frames[i].name, it_sprite);
(*skins)[i] = find_image(sprout->frames[i].name, it_sprite);
}
}
@ -1236,6 +1185,42 @@ Mod_LoadSP2 (const char *mod_name, const void *buffer, int modfilelen,
return extradata;
}
/*
=================
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)
{
switch (LittleLong(*(unsigned *)buffer))
{
case DKMHEADER:
return Mod_LoadDKMModel(mod_name, buffer, modfilelen, mins, maxs,
skins, numskins, find_image, type);
case RAVENFMHEADER:
return Mod_LoadFlexModel(mod_name, buffer, modfilelen, mins, maxs,
skins, numskins, find_image, type);
case IDALIASHEADER:
return Mod_LoadMD2(mod_name, buffer, modfilelen, mins, maxs,
skins, numskins, find_image, type);
case IDMDLHEADER:
return Mod_LoadMDL(mod_name, buffer, modfilelen, mins, maxs,
skins, numskins, find_image, type);
case IDSPRITEHEADER:
return Mod_LoadSP2(mod_name, buffer, modfilelen,
skins, numskins, find_image, type);
}
return NULL;
}
static int
Mod_LoadFileWithoutExt(const char *namewe, void **buffer, const char* ext)
{
@ -1392,7 +1377,7 @@ Mod_ReLoadSkins(struct image_s **skins, findimage_t find_image, void *extradata,
pheader = (dmdl_t *)extradata;
for (i=0; i < pheader->num_skins; i++)
{
skins[i] = find_image ((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
skins[i] = find_image((char *)pheader + pheader->ofs_skins + i*MAX_SKINNAME, it_skin);
}
return pheader->num_frames;
}

View File

@ -607,7 +607,7 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
dmdl_t *paliashdr;
float an;
vec3_t bbox[8];
image_t *skin;
image_t *skin = NULL;
if (!(currententity->flags & RF_WEAPONMODEL))
{
@ -832,18 +832,14 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
}
else
{
if (currententity->skinnum >= MAX_MD2SKINS)
{
skin = currentmodel->skins[0];
}
else
if (currententity->skinnum < currentmodel->numskins)
{
skin = currentmodel->skins[currententity->skinnum];
}
if (!skin)
{
skin = currentmodel->skins[0];
}
if (!skin)
{
skin = currentmodel->skins[0];
}
}

View File

@ -823,11 +823,13 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadAliasModel(mod->name, buf, modfilelen,
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s **)mod->skins, (findimage_t)R_FindImage,
&(mod->type));
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)R_FindImage, &(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -836,19 +838,6 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
};
break;
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen,
(struct image_s **)mod->skins, (findimage_t)R_FindImage,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
}
break;
case IDBSPHEADER:
/* fall through */
case QBSPHEADER:

View File

@ -90,7 +90,8 @@ typedef struct model_s
int numlightdata;
/* for alias models and skins */
image_t *skins[MAX_MD2SKINS];
struct image_s **skins;
int numskins;
int extradatasize;
void *extradata;

View File

@ -853,7 +853,7 @@ GL3_DrawSpriteModel(entity_t *e, gl3model_t *currentmodel)
dsprframe_t *frame;
float *up, *right;
dsprite_t *psprite;
gl3image_t *skin;
gl3image_t *skin = NULL;
/* don't even bother culling, because it's just
a single polygon without a surface cache */

View File

@ -708,7 +708,7 @@ GL3_DrawAliasModel(entity_t *entity)
vec3_t bbox[8];
vec3_t shadelight;
vec3_t shadevector;
gl3image_t *skin;
gl3image_t *skin = NULL;
hmm_mat4 origProjViewMat = {0}; // use for left-handed rendering
// used to restore ModelView matrix after changing it for this entities position/rotation
hmm_mat4 origModelMat = {0};
@ -933,18 +933,14 @@ GL3_DrawAliasModel(entity_t *entity)
}
else
{
if (entity->skinnum >= MAX_MD2SKINS)
{
skin = model->skins[0];
}
else
if (entity->skinnum < model->numskins)
{
skin = model->skins[entity->skinnum];
}
if (!skin)
{
skin = model->skins[0];
}
if (!skin)
{
skin = model->skins[0];
}
}

View File

@ -824,11 +824,13 @@ Mod_ForName(const char *name, gl3model_t *parent_model, qboolean crash)
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadAliasModel(mod->name, buf, modfilelen,
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s **)mod->skins, (findimage_t)GL3_FindImage,
&(mod->type));
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)GL3_FindImage, &(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -837,19 +839,6 @@ Mod_ForName(const char *name, gl3model_t *parent_model, qboolean crash)
};
break;
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen,
(struct image_s **)mod->skins, (findimage_t)GL3_FindImage,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
}
break;
case IDBSPHEADER:
/* fall through */
case QBSPHEADER:

View File

@ -101,7 +101,8 @@ typedef struct model_s
int numlightdata;
/* for alias models and skins */
gl3image_t *skins[MAX_MD2SKINS];
struct image_s **skins;
int numskins;
int extradatasize;
void *extradata;

View File

@ -836,7 +836,7 @@ GL4_DrawSpriteModel(entity_t *e, gl4model_t *currentmodel)
dsprframe_t *frame;
float *up, *right;
dsprite_t *psprite;
gl4image_t *skin;
gl4image_t *skin = NULL;
/* don't even bother culling, because it's just
a single polygon without a surface cache */

View File

@ -648,7 +648,7 @@ GL4_DrawAliasModel(entity_t *entity)
vec3_t bbox[8];
vec3_t shadelight;
vec3_t shadevector;
gl4image_t *skin;
gl4image_t *skin = NULL;
hmm_mat4 origProjViewMat = {0}; // use for left-handed rendering
// used to restore ModelView matrix after changing it for this entities position/rotation
hmm_mat4 origModelMat = {0};
@ -872,18 +872,14 @@ GL4_DrawAliasModel(entity_t *entity)
}
else
{
if (entity->skinnum >= MAX_MD2SKINS)
{
skin = model->skins[0];
}
else
if (entity->skinnum < model->numskins)
{
skin = model->skins[entity->skinnum];
}
if (!skin)
{
skin = model->skins[0];
}
if (!skin)
{
skin = model->skins[0];
}
}

View File

@ -822,11 +822,13 @@ Mod_ForName(const char *name, gl4model_t *parent_model, qboolean crash)
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadAliasModel(mod->name, buf, modfilelen,
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s **)mod->skins, (findimage_t)GL4_FindImage,
&(mod->type));
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)GL4_FindImage, &(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -835,19 +837,6 @@ Mod_ForName(const char *name, gl4model_t *parent_model, qboolean crash)
};
break;
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen,
(struct image_s **)mod->skins, (findimage_t)GL4_FindImage,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
}
break;
case IDBSPHEADER:
/* fall through */
case QBSPHEADER:

View File

@ -101,7 +101,8 @@ typedef struct model_s
int numlightdata;
/* for alias models and skins */
gl4image_t *skins[MAX_MD2SKINS];
struct image_s **skins;
int numskins;
int extradatasize;
void *extradata;

View File

@ -322,18 +322,16 @@ typedef struct
/* Shared models func */
typedef struct image_s* (*findimage_t)(const char *name, imagetype_t type);
extern void *Mod_LoadAliasModel (const char *mod_name, const void *buffer, int modfilelen,
vec3_t mins, vec3_t maxs, struct image_s **skins,
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);
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);
extern struct image_s *GetTexImage(const char *name, findimage_t find_image);
extern struct image_s *R_FindPic(const char *name, findimage_t find_image);
extern struct image_s* R_LoadImage(const char *name, const char* namewe, const char *ext,
extern struct image_s *R_LoadImage(const char *name, const char* namewe, const char *ext,
imagetype_t type, qboolean r_retexturing, loadimage_t load_image);
extern void Mod_LoadQBSPMarksurfaces(const char *name, msurface_t ***marksurfaces,
unsigned int *nummarksurfaces, msurface_t *surfaces, int numsurfaces,

View File

@ -114,7 +114,9 @@ typedef struct model_s
int numlightdata;
// for alias models and sprites
image_t *skins[MAX_MD2SKINS];
struct image_s **skins;
int numskins;
void *extradata;
int extradatasize;

View File

@ -514,7 +514,8 @@ R_AliasSetupSkin(const entity_t *currententity, const model_t *currentmodel)
int skinnum;
skinnum = currententity->skinnum;
if ((skinnum >= s_pmdl->num_skins) || (skinnum < 0))
if ((skinnum >= s_pmdl->num_skins) || (skinnum < 0) ||
(skinnum >= currentmodel->numskins))
{
R_Printf(PRINT_ALL, "%s %s: no such skin # %d\n",
__func__, currentmodel->name, skinnum);

View File

@ -647,11 +647,13 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadAliasModel(mod->name, buf, modfilelen,
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s **)mod->skins, (findimage_t)R_FindImage,
&(mod->type));
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)R_FindImage, &(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -660,19 +662,6 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
};
break;
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen,
(struct image_s **)mod->skins, (findimage_t)R_FindImage,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
}
break;
case IDBSPHEADER:
/* fall through */
case QBSPHEADER:

View File

@ -47,7 +47,11 @@ R_DrawSprite(entity_t *currententity, const model_t *currentmodel)
s_psprframe = &s_psprite->frames[currententity->frame];
skin = currentmodel->skins[currententity->frame];
if (currententity->frame < currentmodel->numskins)
{
skin = currentmodel->skins[currententity->frame];
}
if (!skin)
{
skin = r_notexture_mip;

View File

@ -110,7 +110,8 @@ typedef struct model_s
int numlightdata;
/* for alias models and skins */
image_t *skins[MAX_MD2SKINS];
struct image_s **skins;
int numskins;
int extradatasize;
void *extradata;

View File

@ -167,7 +167,7 @@ R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel)
dsprframe_t *frame;
float *up, *right;
dsprite_t *psprite;
image_t *skin;
image_t *skin = NULL;
/* don't even bother culling, because it's just
a single polygon without a surface cache */
@ -219,7 +219,11 @@ R_DrawSpriteModel(entity_t *currententity, const model_t *currentmodel)
vkCmdPushConstants(vk_activeCmdbuffer, vk_drawTexQuadPipeline[vk_state.current_renderpass].layout,
VK_SHADER_STAGE_FRAGMENT_BIT, 17 * sizeof(float), sizeof(gamma), &gamma);
skin = currentmodel->skins[currententity->frame];
if (currententity->frame < currentmodel->numskins)
{
skin = currentmodel->skins[currententity->frame];
}
if (!skin)
{
skin = r_notexture;

View File

@ -1004,7 +1004,7 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
currententity->angles[PITCH] = -currententity->angles[PITCH]; // sigh.
{
float model[16];
image_t *skin;
image_t *skin = NULL;
Mat_Identity(model);
R_RotateForEntity (currententity, model);
@ -1012,16 +1012,19 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
// select skin
if (currententity->skin)
{
skin = currententity->skin; // custom player skin
}
else
{
if (currententity->skinnum >= MAX_MD2SKINS)
skin = currentmodel->skins[0];
else
if (currententity->skinnum < currentmodel->numskins)
{
skin = currentmodel->skins[currententity->skinnum];
if (!skin)
skin = currentmodel->skins[0];
}
if (!skin)
{
skin = currentmodel->skins[0];
}
}
if (!skin)

View File

@ -814,11 +814,13 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
case IDALIASHEADER:
/* fall through */
case IDMDLHEADER:
/* fall through */
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadAliasModel(mod->name, buf, modfilelen,
mod->extradata = Mod_LoadModel(mod->name, buf, modfilelen,
mod->mins, mod->maxs,
(struct image_s **)mod->skins, (findimage_t)Vk_FindImage,
&(mod->type));
(struct image_s ***)&mod->skins, &mod->numskins,
(findimage_t)Vk_FindImage, &(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
@ -827,19 +829,6 @@ Mod_ForName(const char *name, model_t *parent_model, qboolean crash)
};
break;
case IDSPRITEHEADER:
{
mod->extradata = Mod_LoadSP2(mod->name, buf, modfilelen,
(struct image_s **)mod->skins, (findimage_t)Vk_FindImage,
&(mod->type));
if (!mod->extradata)
{
Com_Error(ERR_DROP, "%s: Failed to load %s",
__func__, mod->name);
}
}
break;
case IDBSPHEADER:
/* fall through */
case QBSPHEADER: