models: Use flex mesh type insteaad list of short

This commit is contained in:
Denis Pauk 2023-12-27 00:54:30 +02:00
parent be95a149dc
commit 531dc2f872
5 changed files with 45 additions and 36 deletions

View file

@ -801,9 +801,11 @@ Mod_LoadModel_Flex(const char *mod_name, const void *buffer, int modfilelen,
dmdxheader.num_tris = LittleLong(header->num_tris);
dmdxheader.num_glcmds = LittleLong(header->num_glcmds);
dmdxheader.num_frames = LittleLong(header->num_frames);
dmdxheader.num_meshes = LittleLong(header->num_mesh_nodes);
// just skip header and meshes
dmdxheader.ofs_skins = sizeof(dmdxheader) + sizeof(short) * 2 * LittleLong(header->num_mesh_nodes);
dmdxheader.ofs_meshes = sizeof(dmdxheader);
dmdxheader.ofs_skins = dmdxheader.ofs_meshes + sizeof(dmdxmesh_t) * dmdxheader.num_meshes;
dmdxheader.ofs_st = dmdxheader.ofs_skins + dmdxheader.num_skins * MAX_SKINNAME;
dmdxheader.ofs_tris = dmdxheader.ofs_st + dmdxheader.num_st * sizeof(dstvert_t);
dmdxheader.ofs_frames = dmdxheader.ofs_tris + dmdxheader.num_tris * sizeof(dtriangle_t);
@ -974,11 +976,11 @@ Mod_LoadModel_Flex(const char *mod_name, const void *buffer, int modfilelen,
if (num_mesh_nodes > 0)
{
short *mesh_nodes;
dmdxmesh_t *mesh_nodes;
char *in_mesh = src;
int i;
mesh_nodes = (short *)((char*)pheader + sizeof(*pheader));
mesh_nodes = (dmdxmesh_t *)((char*)pheader + sizeof(*pheader));
for (i = 0; i < num_mesh_nodes; i++)
{
/* 256 bytes of tri data */
@ -986,9 +988,9 @@ Mod_LoadModel_Flex(const char *mod_name, const void *buffer, int modfilelen,
/* 2 bytes of start */
/* 2 bytes of number commands */
in_mesh += 512;
mesh_nodes[i * 2] = LittleShort(*(short *)in_mesh);
mesh_nodes[i].start = LittleShort(*(short *)in_mesh);
in_mesh += 2;
mesh_nodes[i * 2 + 1] = LittleShort(*(short *)in_mesh);
mesh_nodes[i].num = LittleShort(*(short *)in_mesh);
in_mesh += 2;
}
}

View file

@ -187,7 +187,7 @@ R_DrawAliasFrameLerp(entity_t *currententity, dmdx_t *paliashdr, float backlerp)
int i;
float *lerp;
int num_mesh_nodes;
short *mesh_nodes;
dmdxmesh_t *mesh_nodes;
qboolean colorOnly = 0 != (currententity->flags &
(RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE |
RF_SHELL_HALF_DAM));
@ -243,8 +243,8 @@ R_DrawAliasFrameLerp(entity_t *currententity, dmdx_t *paliashdr, float backlerp)
R_LerpVerts(colorOnly, paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv);
num_mesh_nodes = (paliashdr->ofs_skins - sizeof(dmdx_t)) / sizeof(short) / 2;
mesh_nodes = (short *)((char*)paliashdr + sizeof(dmdx_t));
num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0)
{
@ -252,9 +252,9 @@ R_DrawAliasFrameLerp(entity_t *currententity, dmdx_t *paliashdr, float backlerp)
for (i = 0; i < num_mesh_nodes; i++)
{
R_DrawAliasDrawCommands(currententity,
order + mesh_nodes[i * 2],
order + mesh_nodes[i].start,
order + Q_min(
paliashdr->num_glcmds, mesh_nodes[i * 2] + mesh_nodes[i * 2 + 1]),
paliashdr->num_glcmds, mesh_nodes[i].start + mesh_nodes[i].num),
alpha, verts);
}
}
@ -360,7 +360,7 @@ R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum)
int *order;
float height = 0, lheight;
int num_mesh_nodes;
short *mesh_nodes;
dmdxmesh_t *mesh_nodes;
lheight = currententity->origin[2] - lightspot[2];
order = (int *)((byte *)paliashdr + paliashdr->ofs_glcmds);
@ -374,8 +374,8 @@ R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum)
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
}
num_mesh_nodes = (paliashdr->ofs_skins - sizeof(dmdx_t)) / sizeof(short) / 2;
mesh_nodes = (short *)((char*)paliashdr + sizeof(dmdx_t));
num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0)
{
@ -383,8 +383,8 @@ R_DrawAliasShadow(entity_t *currententity, dmdx_t *paliashdr, int posenum)
for (i = 0; i < num_mesh_nodes; i++)
{
R_DrawAliasShadowCommand(currententity,
order + mesh_nodes[i * 2],
order + Q_min(paliashdr->num_glcmds, mesh_nodes[i * 2] + mesh_nodes[i * 2 + 1]),
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds, mesh_nodes[i].start + mesh_nodes[i].num),
height, lheight);
}
}

View file

@ -229,7 +229,7 @@ DrawAliasFrameLerp(dmdx_t *paliashdr, entity_t* entity, vec3_t shadelight)
float frontlerp = 1.0 - backlerp;
float *lerp;
int num_mesh_nodes;
short *mesh_nodes;
dmdxmesh_t *mesh_nodes;
// draw without texture? used for quad damage effect etc, I think
qboolean colorOnly = 0 != (entity->flags &
(RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE |
@ -297,8 +297,8 @@ DrawAliasFrameLerp(dmdx_t *paliashdr, entity_t* entity, vec3_t shadelight)
YQ2_STATIC_ASSERT(sizeof(gl3_alias_vtx_t) == 9*sizeof(GLfloat), "invalid gl3_alias_vtx_t size");
num_mesh_nodes = (paliashdr->ofs_skins - sizeof(dmdx_t)) / sizeof(short) / 2;
mesh_nodes = (short *)((char*)paliashdr + sizeof(dmdx_t));
num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0)
{
@ -306,9 +306,9 @@ DrawAliasFrameLerp(dmdx_t *paliashdr, entity_t* entity, vec3_t shadelight)
for (i = 0; i < num_mesh_nodes; i++)
{
DrawAliasFrameLerpCommands(paliashdr, entity, shadelight,
order + mesh_nodes[i * 2],
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i * 2] + mesh_nodes[i * 2 + 1]),
mesh_nodes[i].start + mesh_nodes[i].num),
shadedots, alpha, colorOnly, verts);
}
}
@ -434,7 +434,7 @@ DrawAliasShadow(gl3_shadowinfo_t* shadowInfo)
int *order;
float height = 0, lheight;
int num_mesh_nodes;
short *mesh_nodes;
dmdxmesh_t *mesh_nodes;
dmdx_t* paliashdr = shadowInfo->paliashdr;
entity_t* entity = shadowInfo->entity;
@ -487,8 +487,8 @@ DrawAliasShadow(gl3_shadowinfo_t* shadowInfo)
order = (int *)((byte *)paliashdr + paliashdr->ofs_glcmds);
height = -lheight + 0.1f;
num_mesh_nodes = (paliashdr->ofs_skins - sizeof(dmdx_t)) / sizeof(short) / 2;
mesh_nodes = (short *)((char*)paliashdr + sizeof(dmdx_t));
num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0)
{
@ -496,9 +496,9 @@ DrawAliasShadow(gl3_shadowinfo_t* shadowInfo)
for (i = 0; i < num_mesh_nodes; i++)
{
DrawAliasShadowCommands(
order + mesh_nodes[i * 2],
order + Q_min(
paliashdr->num_glcmds, mesh_nodes[i * 2] + mesh_nodes[i * 2 + 1]),
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
shadevector, height, lheight);
}
}

View file

@ -427,7 +427,7 @@ Vk_DrawAliasFrameLerp(entity_t *currententity, dmdx_t *paliashdr, float backlerp
int i;
float *lerp;
int num_mesh_nodes;
short *mesh_nodes;
dmdxmesh_t *mesh_nodes;
qboolean colorOnly = 0 != (currententity->flags &
(RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE |
RF_SHELL_HALF_DAM));
@ -483,8 +483,8 @@ Vk_DrawAliasFrameLerp(entity_t *currententity, dmdx_t *paliashdr, float backlerp
R_LerpVerts(colorOnly, paliashdr->num_xyz, v, ov, verts, lerp, move, frontv, backv);
num_mesh_nodes = (paliashdr->ofs_skins - sizeof(dmdx_t)) / sizeof(short) / 2;
mesh_nodes = (short *)((char*)paliashdr + sizeof(dmdx_t));
num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0)
{
@ -492,9 +492,9 @@ Vk_DrawAliasFrameLerp(entity_t *currententity, dmdx_t *paliashdr, float backlerp
for (i = 0; i < num_mesh_nodes; i++)
{
Vk_DrawAliasFrameLerpCommands(currententity,
order + mesh_nodes[i * 2],
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i * 2] + mesh_nodes[i * 2 + 1]),
mesh_nodes[i].start + mesh_nodes[i].num),
alpha, skin,
modelMatrix, leftHandOffset, translucentIdx, verts);
}
@ -1032,7 +1032,7 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
if (vk_shadows->value && !(currententity->flags & (RF_TRANSLUCENT | RF_WEAPONMODEL)))
{
int num_mesh_nodes;
short *mesh_nodes;
dmdxmesh_t *mesh_nodes;
float model[16];
int *order;
@ -1041,8 +1041,8 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
order = (int *)((byte *)paliashdr + paliashdr->ofs_glcmds);
num_mesh_nodes = (paliashdr->ofs_skins - sizeof(dmdx_t)) / sizeof(short) / 2;
mesh_nodes = (short *)((char*)paliashdr + sizeof(dmdx_t));
num_mesh_nodes = paliashdr->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)paliashdr + paliashdr->ofs_meshes);
if (num_mesh_nodes > 0)
{
@ -1050,9 +1050,9 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
for (i = 0; i < num_mesh_nodes; i++)
{
Vk_DrawAliasShadow (
order + mesh_nodes[i * 2],
order + mesh_nodes[i].start,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i * 2] + mesh_nodes[i * 2 + 1]),
mesh_nodes[i].start + mesh_nodes[i].num),
currententity->frame, model, currententity);
}
}

View file

@ -245,6 +245,13 @@ typedef struct dkm_header_s
} dkm_header_t;
/* Internal model render format */
typedef struct
{
short start;
short num;
} dmdxmesh_t;
typedef struct
{
int skinwidth;