IQM skin support and print limit info, make other limit info consistent, patch by Zack Middleton (#4978)

This commit is contained in:
Thilo Schulz 2011-05-06 11:43:07 +00:00
parent 45824008d9
commit 2ae1bf3dcd
4 changed files with 54 additions and 15 deletions

View file

@ -1423,12 +1423,12 @@ Q3OBJ = \
$(B)/client/tr_image_tga.o \ $(B)/client/tr_image_tga.o \
$(B)/client/tr_image_pcx.o \ $(B)/client/tr_image_pcx.o \
$(B)/client/tr_init.o \ $(B)/client/tr_init.o \
$(B)/client/tr_model_iqm.o \
$(B)/client/tr_light.o \ $(B)/client/tr_light.o \
$(B)/client/tr_main.o \ $(B)/client/tr_main.o \
$(B)/client/tr_marks.o \ $(B)/client/tr_marks.o \
$(B)/client/tr_mesh.o \ $(B)/client/tr_mesh.o \
$(B)/client/tr_model.o \ $(B)/client/tr_model.o \
$(B)/client/tr_model_iqm.o \
$(B)/client/tr_noise.o \ $(B)/client/tr_noise.o \
$(B)/client/tr_scene.o \ $(B)/client/tr_scene.o \
$(B)/client/tr_shade.o \ $(B)/client/tr_shade.o \

View file

@ -668,6 +668,7 @@ typedef struct {
// inter-quake-model surface // inter-quake-model surface
typedef struct srfIQModel_s { typedef struct srfIQModel_s {
surfaceType_t surfaceType; surfaceType_t surfaceType;
char name[MAX_QPATH];
shader_t *shader; shader_t *shader;
iqmData_t *data; iqmData_t *data;
int first_vertex, num_vertexes; int first_vertex, num_vertexes;

View file

@ -466,12 +466,14 @@ static qboolean R_LoadMD3 (model_t *mod, int lod, void *buffer, const char *mod_
LL(surf->ofsEnd); LL(surf->ofsEnd);
if ( surf->numVerts > SHADER_MAX_VERTEXES ) { if ( surf->numVerts > SHADER_MAX_VERTEXES ) {
ri.Error (ERR_DROP, "R_LoadMD3: %s has more than %i verts on a surface (%i)", ri.Printf(PRINT_WARNING, "R_LoadMD3: %s has more than %i verts on a surface (%i).\n",
mod_name, SHADER_MAX_VERTEXES, surf->numVerts ); mod_name, SHADER_MAX_VERTEXES, surf->numVerts );
return qfalse;
} }
if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) { if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) {
ri.Error (ERR_DROP, "R_LoadMD3: %s has more than %i triangles on a surface (%i)", ri.Printf(PRINT_WARNING, "R_LoadMD3: %s has more than %i triangles on a surface (%i).\n",
mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles ); mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles );
return qfalse;
} }
// change to surface identifier // change to surface identifier
@ -742,13 +744,13 @@ static qboolean R_LoadMDR( model_t *mod, void *buffer, int filesize, const char
// now do the checks that may fail. // now do the checks that may fail.
if ( surf->numVerts > SHADER_MAX_VERTEXES ) if ( surf->numVerts > SHADER_MAX_VERTEXES )
{ {
ri.Printf(PRINT_WARNING, "R_LoadMDR: %s has more than %i verts on a surface (%i)", ri.Printf(PRINT_WARNING, "R_LoadMDR: %s has more than %i verts on a surface (%i).\n",
mod_name, SHADER_MAX_VERTEXES, surf->numVerts ); mod_name, SHADER_MAX_VERTEXES, surf->numVerts );
return qfalse; return qfalse;
} }
if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) if ( surf->numTriangles*3 > SHADER_MAX_INDEXES )
{ {
ri.Printf(PRINT_WARNING, "R_LoadMDR: %s has more than %i triangles on a surface (%i)", ri.Printf(PRINT_WARNING, "R_LoadMDR: %s has more than %i triangles on a surface (%i).\n",
mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles ); mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles );
return qfalse; return qfalse;
} }
@ -957,12 +959,14 @@ static qboolean R_LoadMD4( model_t *mod, void *buffer, const char *mod_name ) {
LL(surf->ofsEnd); LL(surf->ofsEnd);
if ( surf->numVerts > SHADER_MAX_VERTEXES ) { if ( surf->numVerts > SHADER_MAX_VERTEXES ) {
ri.Error (ERR_DROP, "R_LoadMD3: %s has more than %i verts on a surface (%i)", ri.Printf(PRINT_WARNING, "R_LoadMD4: %s has more than %i verts on a surface (%i).\n",
mod_name, SHADER_MAX_VERTEXES, surf->numVerts ); mod_name, SHADER_MAX_VERTEXES, surf->numVerts );
return qfalse;
} }
if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) { if ( surf->numTriangles*3 > SHADER_MAX_INDEXES ) {
ri.Error (ERR_DROP, "R_LoadMD3: %s has more than %i triangles on a surface (%i)", ri.Printf(PRINT_WARNING, "R_LoadMD4: %s has more than %i triangles on a surface (%i).\n",
mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles ); mod_name, SHADER_MAX_INDEXES / 3, surf->numTriangles );
return qfalse;
} }
// change to surface identifier // change to surface identifier

View file

@ -193,6 +193,13 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na
LL( header->num_extensions ); LL( header->num_extensions );
LL( header->ofs_extensions ); LL( header->ofs_extensions );
// check ioq3 joint limit
if ( header->num_joints > IQM_MAX_JOINTS ) {
ri.Printf(PRINT_WARNING, "R_LoadIQM: %s has more than %d joints (%d).\n",
mod_name, IQM_MAX_JOINTS, header->num_joints);
return qfalse;
}
// check and swap vertex arrays // check and swap vertex arrays
if( IQM_CheckRange( header, header->ofs_vertexarrays, if( IQM_CheckRange( header, header->ofs_vertexarrays,
header->num_vertexarrays, header->num_vertexarrays,
@ -306,6 +313,20 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na
LL( mesh->first_triangle ); LL( mesh->first_triangle );
LL( mesh->num_triangles ); LL( mesh->num_triangles );
// check ioq3 limits
if ( mesh->num_vertexes > SHADER_MAX_VERTEXES )
{
ri.Printf(PRINT_WARNING, "R_LoadIQM: %s has more than %i verts on a surface (%i).\n",
mod_name, SHADER_MAX_VERTEXES, mesh->num_vertexes );
return qfalse;
}
if ( mesh->num_triangles*3 > SHADER_MAX_INDEXES )
{
ri.Printf(PRINT_WARNING, "R_LoadIQM: %s has more than %i triangles on a surface (%i).\n",
mod_name, SHADER_MAX_INDEXES / 3, mesh->num_triangles );
return qfalse;
}
if( mesh->first_vertex >= header->num_vertexes || if( mesh->first_vertex >= header->num_vertexes ||
mesh->first_vertex + mesh->num_vertexes > header->num_vertexes || mesh->first_vertex + mesh->num_vertexes > header->num_vertexes ||
mesh->first_triangle >= header->num_triangles || mesh->first_triangle >= header->num_triangles ||
@ -319,8 +340,7 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na
} }
// check and swap joints // check and swap joints
if( header->num_joints > IQM_MAX_JOINTS || if( IQM_CheckRange( header, header->ofs_joints,
IQM_CheckRange( header, header->ofs_joints,
header->num_joints, sizeof(iqmJoint_t) ) ) { header->num_joints, sizeof(iqmJoint_t) ) ) {
return qfalse; return qfalse;
} }
@ -542,6 +562,7 @@ qboolean R_LoadIQM( model_t *mod, void *buffer, int filesize, const char *mod_na
str = (char *)header + header->ofs_text; str = (char *)header + header->ofs_text;
for( i = 0; i < header->num_meshes; i++, mesh++, surface++ ) { for( i = 0; i < header->num_meshes; i++, mesh++, surface++ ) {
surface->surfaceType = SF_IQM; surface->surfaceType = SF_IQM;
Q_strncpyz(surface->name, str + mesh->name, sizeof (surface->name));
surface->shader = R_FindShader( str + mesh->material, LIGHTMAP_NONE, qtrue ); surface->shader = R_FindShader( str + mesh->material, LIGHTMAP_NONE, qtrue );
if( surface->shader->defaultShader ) if( surface->shader->defaultShader )
surface->shader = tr.defaultShader; surface->shader = tr.defaultShader;
@ -734,11 +755,12 @@ Add all surfaces of this model
void R_AddIQMSurfaces( trRefEntity_t *ent ) { void R_AddIQMSurfaces( trRefEntity_t *ent ) {
iqmData_t *data; iqmData_t *data;
srfIQModel_t *surface; srfIQModel_t *surface;
int i; int i, j;
qboolean personalModel; qboolean personalModel;
int cull; int cull;
int fogNum; int fogNum;
shader_t *shader; shader_t *shader;
skin_t *skin;
data = tr.currentModel->modelData; data = tr.currentModel->modelData;
surface = data->surfaces; surface = data->surfaces;
@ -790,8 +812,21 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) {
fogNum = R_ComputeIQMFogNum( data, ent ); fogNum = R_ComputeIQMFogNum( data, ent );
for ( i = 0 ; i < data->num_surfaces ; i++ ) { for ( i = 0 ; i < data->num_surfaces ; i++ ) {
if( ent->e.customShader ) { if(ent->e.customShader)
shader = R_GetShaderByHandle( ent->e.customShader ); shader = R_GetShaderByHandle( ent->e.customShader );
else if(ent->e.customSkin > 0 && ent->e.customSkin < tr.numSkins)
{
skin = R_GetSkinByHandle(ent->e.customSkin);
shader = tr.defaultShader;
for(j = 0; j < skin->numSurfaces; j++)
{
if (!strcmp(skin->surfaces[j]->name, surface->name))
{
shader = skin->surfaces[j]->shader;
break;
}
}
} else { } else {
shader = surface->shader; shader = surface->shader;
} }
@ -816,8 +851,7 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) {
} }
if( !personalModel ) { if( !personalModel ) {
R_AddDrawSurf( &surface->surfaceType, R_AddDrawSurf( (void *)surface, shader, fogNum, 0 );
shader, fogNum, 0 );
} }
surface++; surface++;