models: save triangles ofs/num in each mesh

soft has some issues with md3 model example texture render
This commit is contained in:
Denis Pauk 2024-03-11 00:06:38 +02:00
parent 006d8cbc32
commit 3df48ef64e
8 changed files with 174 additions and 94 deletions

View file

@ -557,8 +557,10 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
/* create single mesh */
mesh_nodes = (dmdxmesh_t *)((char *)pheader + pheader->ofs_meshes);
mesh_nodes[0].start = 0;
mesh_nodes[0].num = num_glcmds;
mesh_nodes[0].ofs_tris = 0;
mesh_nodes[0].num_tris = num_tris;
mesh_nodes[0].ofs_glcmds = 0;
mesh_nodes[0].num_glcmds = num_glcmds;
{
int i;
@ -625,7 +627,7 @@ Mod_LoadModel_MDL(const char *mod_name, const void *buffer, int modfilelen,
triangles = (mdl_triangle_t *) curr_pos;
curr_pos += sizeof(mdl_triangle_t) * num_tris;
for (i=0 ; i<num_tris ; i++)
for (i = 0; i < num_tris; i++)
{
int j;
@ -1188,7 +1190,9 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
/* load triangles */
p = (const int*)((byte*)buffer + meshofs + LittleLong(md3_mesh->ofs_tris));
mesh_nodes[i].start = pglcmds - baseglcmds;
mesh_nodes[i].ofs_glcmds = pglcmds - baseglcmds;
mesh_nodes[i].ofs_tris = num_tris;
mesh_nodes[i].num_tris = num_tris + LittleLong(md3_mesh->num_tris);
for (j = 0; j < LittleLong(md3_mesh->num_tris); j++)
{
@ -1206,14 +1210,14 @@ Mod_LoadModel_MD3(const char *mod_name, const void *buffer, int modfilelen,
}
/* write glcmds */
mesh_nodes[i].num = Mod_LoadCmdCompress(
mesh_nodes[i].num_glcmds = Mod_LoadCmdCompress(
(dstvert_t*)((byte *)pheader + pheader->ofs_st),
(dtriangle_t*)((byte *)pheader + pheader->ofs_tris) + num_tris,
LittleLong(md3_mesh->num_tris),
pglcmds,
pheader->skinwidth, pheader->skinheight);
pglcmds += mesh_nodes[i].num;
pglcmds += mesh_nodes[i].num_glcmds;
md3_vertex = (md3_vertex_t*)((byte*)buffer + meshofs + LittleLong(md3_mesh->ofs_verts));
@ -1404,8 +1408,10 @@ Mod_LoadModel_MD2Anox(const char *mod_name, const void *buffer, int modfilelen,
/* create single mesh */
mesh_nodes = (dmdxmesh_t *)((char *)pheader + pheader->ofs_meshes);
mesh_nodes[0].start = 0;
mesh_nodes[0].num = pheader->num_glcmds;
mesh_nodes[0].ofs_tris = 0;
mesh_nodes[0].num_tris = pheader->num_tris;
mesh_nodes[0].ofs_glcmds = 0;
mesh_nodes[0].num_glcmds = pheader->num_glcmds;
//
// load base s and t vertices (not used in gl version)
@ -1541,8 +1547,10 @@ Mod_LoadModel_MD2(const char *mod_name, const void *buffer, int modfilelen,
/* create single mesh */
mesh_nodes = (dmdxmesh_t *)((char *)pheader + pheader->ofs_meshes);
mesh_nodes[0].start = 0;
mesh_nodes[0].num = pheader->num_glcmds;
mesh_nodes[0].ofs_tris = 0;
mesh_nodes[0].num_tris = pheader->num_tris;
mesh_nodes[0].ofs_glcmds = 0;
mesh_nodes[0].num_glcmds = pheader->num_glcmds;
if (pheader->num_xyz <= 0)
{
@ -1905,14 +1913,58 @@ Mod_LoadModel_Flex(const char *mod_name, const void *buffer, int modfilelen,
mesh_nodes = (dmdxmesh_t *)((char*)pheader + sizeof(*pheader));
for (i = 0; i < num_mesh_nodes; i++)
{
int j, min = 256 * 8, max = 0;
for (j = 0; j < 256; j++)
{
if (in_mesh[j])
{
if (min > (j * 8))
{
int k, v = in_mesh[j];
for (k = 0; k < 8; k ++)
{
if ((v & 1))
{
min = j * 8 + k;
break;
}
v >>= 1;
}
}
break;
}
}
for (j = (min / 8) - 1; j < 256; j++)
{
if (in_mesh[j])
{
int v = in_mesh[j];
max = j * 8;
while (v)
{
max ++;
v >>= 1;
}
}
}
/* save mesh triangle */
mesh_nodes[i].ofs_tris = min;
mesh_nodes[i].num_tris = max - min;
/* 256 bytes of tri data */
/* 256 bytes of vert data */
/* 2 bytes of start */
/* 2 bytes of number commands */
in_mesh += 512;
mesh_nodes[i].start = LittleShort(*(short *)in_mesh);
mesh_nodes[i].ofs_glcmds = LittleShort(*(short *)in_mesh);
in_mesh += 2;
mesh_nodes[i].num = LittleShort(*(short *)in_mesh);
mesh_nodes[i].num_glcmds = LittleShort(*(short *)in_mesh);
in_mesh += 2;
}
}
@ -2039,8 +2091,10 @@ Mod_LoadModel_DKM(const char *mod_name, const void *buffer, int modfilelen,
/* create single mesh */
mesh_nodes = (dmdxmesh_t *)((char *)pheader + pheader->ofs_meshes);
mesh_nodes[0].start = 0;
mesh_nodes[0].num = pheader->num_glcmds;
mesh_nodes[0].ofs_tris = 0;
mesh_nodes[0].num_tris = pheader->num_tris;
mesh_nodes[0].ofs_glcmds = 0;
mesh_nodes[0].num_glcmds = pheader->num_glcmds;
memcpy((byte*)pheader + pheader->ofs_skins, (byte *)buffer + header.ofs_skins,
pheader->num_skins * MAX_SKINNAME);
@ -2155,9 +2209,9 @@ Mod_LoadLimits(const char *mod_name, void *extradata, modtype_t type)
for (i = 0; i < num_mesh_nodes; i++)
{
R_Printf(PRINT_DEVELOPER, "%s: model %s mesh #%d: %d commands\n",
__func__, mod_name, i, mesh_nodes[i].num);
num_glcmds += mesh_nodes[i].num;
R_Printf(PRINT_DEVELOPER, "%s: model %s mesh #%d: %d commands, %d tris\n",
__func__, mod_name, i, mesh_nodes[i].num_glcmds, mesh_nodes[i].num_tris);
num_glcmds += mesh_nodes[i].num_tris;
}
R_Printf(PRINT_DEVELOPER,
"%s: model %s num tris %d / num vert %d / commands %d of %d\n",

View file

@ -1361,7 +1361,9 @@ Mod_LoadModel_MD5(const char *mod_name, const void *buffer, int modfilelen,
{
int j;
mesh_nodes[i].start = pglcmds - baseglcmds;
mesh_nodes[i].ofs_glcmds = pglcmds - baseglcmds;
mesh_nodes[i].ofs_tris = num_tris;
mesh_nodes[i].num_tris = num_tris + md5file->meshes[i].num_tris;
for (j = 0; j < md5file->meshes[i].num_tris; j++)
{
@ -1402,18 +1404,18 @@ Mod_LoadModel_MD5(const char *mod_name, const void *buffer, int modfilelen,
*pglcmds = 0;
pglcmds++;
mesh_nodes[i].num = pglcmds - baseglcmds - mesh_nodes[i].start;
mesh_nodes[i].num_glcmds = pglcmds - baseglcmds - mesh_nodes[i].ofs_glcmds;
/*
Comressed version is much slower
mesh_nodes[i].num = Mod_LoadCmdCompress(
mesh_nodes[i].num_glcmds = Mod_LoadCmdCompress(
(dstvert_t*)((byte *)pheader + pheader->ofs_st),
(dtriangle_t*)((byte *)pheader + pheader->ofs_tris) + num_tris,
md5file->meshes[i].num_tris,
pglcmds,
pheader->skinwidth, pheader->skinheight);
pglcmds += mesh_nodes[i].num;
pglcmds += mesh_nodes[i].num_glcmds;
*/
num_verts += md5file->meshes[i].num_verts;

View file

@ -249,9 +249,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].start,
order + mesh_nodes[i].ofs_glcmds,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
mesh_nodes[i].ofs_glcmds + mesh_nodes[i].num_glcmds),
alpha, verts, s_lerped);
}
@ -370,9 +370,9 @@ 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].start,
order + mesh_nodes[i].ofs_glcmds,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
mesh_nodes[i].ofs_glcmds + mesh_nodes[i].num_glcmds),
height, lheight, s_lerped);
}

View file

@ -305,9 +305,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].start,
order + mesh_nodes[i].ofs_glcmds,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
mesh_nodes[i].ofs_glcmds + mesh_nodes[i].num_glcmds),
shadedots, alpha, colorOnly, verts, s_lerped);
}
}
@ -488,9 +488,9 @@ DrawAliasShadow(gl3_shadowinfo_t* shadowInfo)
for (i = 0; i < num_mesh_nodes; i++)
{
DrawAliasShadowCommands(
order + mesh_nodes[i].start,
order + mesh_nodes[i].ofs_glcmds,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
mesh_nodes[i].ofs_glcmds + mesh_nodes[i].num_glcmds),
shadevector, height, lheight, s_lerped);
}
}

View file

@ -357,7 +357,8 @@ General clipped case
static void
R_AliasPreparePoints(const entity_t *currententity, finalvert_t *verts, const finalvert_t *verts_max)
{
int i;
int i, m, num_mesh_nodes;
dmdxmesh_t *mesh_nodes;
dstvert_t *pstverts;
dtriangle_t *ptri;
finalvert_t *pfv[3];
@ -389,67 +390,78 @@ R_AliasPreparePoints(const entity_t *currententity, finalvert_t *verts, const fi
pstverts = (dstvert_t *)((byte *)s_pmdl + s_pmdl->ofs_st);
ptri = (dtriangle_t *)((byte *)s_pmdl + s_pmdl->ofs_tris);
if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) )
num_mesh_nodes = s_pmdl->num_meshes;
mesh_nodes = (dmdxmesh_t *)((char*)s_pmdl + s_pmdl->ofs_meshes);
for (m = 0; m < num_mesh_nodes; m++)
{
for (i=0 ; i<s_pmdl->num_tris ; i++, ptri++)
int ofs_tris, num_tris;
ofs_tris = Q_max(mesh_nodes[m].ofs_tris, 0);
num_tris = Q_min(ofs_tris + mesh_nodes[m].num_tris, s_pmdl->num_tris);
if ( ( currententity->flags & RF_WEAPONMODEL ) && ( r_lefthand->value == 1.0F ) )
{
pfv[0] = &verts[ptri->index_xyz[0]];
pfv[1] = &verts[ptri->index_xyz[1]];
pfv[2] = &verts[ptri->index_xyz[2]];
if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags )
continue; // completely clipped
// insert s/t coordinates
pfv[0]->cv.s = pstverts[ptri->index_st[0]].s << SHIFT16XYZ;
pfv[0]->cv.t = pstverts[ptri->index_st[0]].t << SHIFT16XYZ;
pfv[1]->cv.s = pstverts[ptri->index_st[1]].s << SHIFT16XYZ;
pfv[1]->cv.t = pstverts[ptri->index_st[1]].t << SHIFT16XYZ;
pfv[2]->cv.s = pstverts[ptri->index_st[2]].s << SHIFT16XYZ;
pfv[2]->cv.t = pstverts[ptri->index_st[2]].t << SHIFT16XYZ;
if ( ! (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) )
for (i = ofs_tris; i < num_tris; i++, ptri++)
{
// totally unclipped
R_DrawTriangle(currententity, pfv[2], pfv[1], pfv[0]);
}
else
{
R_AliasClipTriangle(currententity, pfv[2], pfv[1], pfv[0]);
pfv[0] = &verts[ptri->index_xyz[0]];
pfv[1] = &verts[ptri->index_xyz[1]];
pfv[2] = &verts[ptri->index_xyz[2]];
if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags )
continue; // completely clipped
// insert s/t coordinates
pfv[0]->cv.s = pstverts[ptri->index_st[0]].s << SHIFT16XYZ;
pfv[0]->cv.t = pstverts[ptri->index_st[0]].t << SHIFT16XYZ;
pfv[1]->cv.s = pstverts[ptri->index_st[1]].s << SHIFT16XYZ;
pfv[1]->cv.t = pstverts[ptri->index_st[1]].t << SHIFT16XYZ;
pfv[2]->cv.s = pstverts[ptri->index_st[2]].s << SHIFT16XYZ;
pfv[2]->cv.t = pstverts[ptri->index_st[2]].t << SHIFT16XYZ;
if ( ! (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) )
{
// totally unclipped
R_DrawTriangle(currententity, pfv[2], pfv[1], pfv[0]);
}
else
{
R_AliasClipTriangle(currententity, pfv[2], pfv[1], pfv[0]);
}
}
}
}
else
{
for (i=0 ; i<s_pmdl->num_tris ; i++, ptri++)
else
{
pfv[0] = &verts[ptri->index_xyz[0]];
pfv[1] = &verts[ptri->index_xyz[1]];
pfv[2] = &verts[ptri->index_xyz[2]];
if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags )
continue; // completely clipped
// insert s/t coordinates
pfv[0]->cv.s = pstverts[ptri->index_st[0]].s << SHIFT16XYZ;
pfv[0]->cv.t = pstverts[ptri->index_st[0]].t << SHIFT16XYZ;
pfv[1]->cv.s = pstverts[ptri->index_st[1]].s << SHIFT16XYZ;
pfv[1]->cv.t = pstverts[ptri->index_st[1]].t << SHIFT16XYZ;
pfv[2]->cv.s = pstverts[ptri->index_st[2]].s << SHIFT16XYZ;
pfv[2]->cv.t = pstverts[ptri->index_st[2]].t << SHIFT16XYZ;
if ( ! (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) )
for (i = ofs_tris; i < num_tris; i++, ptri++)
{
// totally unclipped
R_DrawTriangle(currententity, pfv[0], pfv[1], pfv[2]);
}
else
{ // partially clipped
R_AliasClipTriangle(currententity, pfv[0], pfv[1], pfv[2]);
pfv[0] = &verts[ptri->index_xyz[0]];
pfv[1] = &verts[ptri->index_xyz[1]];
pfv[2] = &verts[ptri->index_xyz[2]];
if ( pfv[0]->flags & pfv[1]->flags & pfv[2]->flags )
continue; // completely clipped
// insert s/t coordinates
pfv[0]->cv.s = pstverts[ptri->index_st[0]].s << SHIFT16XYZ;
pfv[0]->cv.t = pstverts[ptri->index_st[0]].t << SHIFT16XYZ;
pfv[1]->cv.s = pstverts[ptri->index_st[1]].s << SHIFT16XYZ;
pfv[1]->cv.t = pstverts[ptri->index_st[1]].t << SHIFT16XYZ;
pfv[2]->cv.s = pstverts[ptri->index_st[2]].s << SHIFT16XYZ;
pfv[2]->cv.t = pstverts[ptri->index_st[2]].t << SHIFT16XYZ;
if ( ! (pfv[0]->flags | pfv[1]->flags | pfv[2]->flags) )
{
// totally unclipped
R_DrawTriangle(currententity, pfv[0], pfv[1], pfv[2]);
}
else
{ // partially clipped
R_AliasClipTriangle(currententity, pfv[0], pfv[1], pfv[2]);
}
}
}
}

View file

@ -1401,7 +1401,7 @@ RE_RenderFrame (refdef_t *fd)
}
// Draw enemies, barrel etc...
// Use Z-Buffer mostly in read mode only.
R_DrawEntitiesOnList ();
R_DrawEntitiesOnList();
if (r_dspeeds->value)
{
@ -1410,10 +1410,12 @@ RE_RenderFrame (refdef_t *fd)
}
// Duh !
R_DrawParticles ();
R_DrawParticles();
if (r_dspeeds->value)
{
dp_time2 = SDL_GetTicks();
}
// Perform pixel palette blending ia the pics/colormap.pcx lower part lookup table.
R_DrawAlphaSurfaces(&ent);
@ -1436,13 +1438,19 @@ RE_RenderFrame (refdef_t *fd)
R_CalcPalette ();
if (sw_aliasstats->value)
R_PrintAliasStats ();
{
R_PrintAliasStats();
}
if (r_speeds->value)
R_PrintTimes ();
{
R_PrintTimes();
}
if (r_dspeeds->value)
{
R_PrintDSpeeds ();
}
R_ReallocateMapBuffers();
}

View file

@ -464,9 +464,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].start,
order + mesh_nodes[i].ofs_glcmds,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
mesh_nodes[i].ofs_glcmds + mesh_nodes[i].num_glcmds),
alpha, skin,
modelMatrix, leftHandOffset, translucentIdx, verts,
s_lerped, paliashdr->num_xyz);
@ -894,9 +894,9 @@ R_DrawAliasModel(entity_t *currententity, const model_t *currentmodel)
for (i = 0; i < num_mesh_nodes; i++)
{
Vk_DrawAliasShadow (
order + mesh_nodes[i].start,
order + mesh_nodes[i].ofs_glcmds,
order + Q_min(paliashdr->num_glcmds,
mesh_nodes[i].start + mesh_nodes[i].num),
mesh_nodes[i].ofs_glcmds + mesh_nodes[i].num_glcmds),
currententity->frame, model, currententity,
s_lerped);
}

View file

@ -375,8 +375,12 @@ typedef struct
typedef struct
{
unsigned int start;
unsigned int num;
/* Used gl commands */
unsigned int ofs_glcmds;
unsigned int num_glcmds;
/* Used triangles in mesh */
unsigned int ofs_tris;
unsigned int num_tris;
} dmdxmesh_t;
typedef struct