X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=model_shared.c;h=12bcad7b6f5ad6c1246aba6f9c0acd62877c3144;hb=1f38eee898a31c94cd3b9931ea3af6e83d51c2c4;hp=c376d4afa3ab3d2f527f59088d55859023b8ba45;hpb=1f1fd33511055b6fbca7cc13d508180d56695a9a;p=xonotic%2Fdarkplaces.git diff --git a/model_shared.c b/model_shared.c index c376d4af..12bcad7b 100644 --- a/model_shared.c +++ b/model_shared.c @@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. cvar_t r_mipskins = {CVAR_SAVE, "r_mipskins", "0", "mipmaps model skins so they render faster in the distance and do not display noise artifacts, can cause discoloration of skins if they contain undesirable border colors"}; -model_t *loadmodel; +dp_model_t *loadmodel; static mempool_t *mod_mempool; static memexpandablearray_t models; @@ -52,7 +52,7 @@ static void mod_start(void) { int i; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; // parse the Q3 shader files Mod_LoadQ3Shaders(); @@ -67,7 +67,7 @@ static void mod_shutdown(void) { int i; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; for (i = 0;i < nummodels;i++) if ((mod = Mem_ExpandableArray_RecordAtIndex(&models, i)) && (mod->loaded || mod->mempool)) @@ -81,7 +81,7 @@ static void mod_newmap(void) msurface_t *surface; int i, j, k, surfacenum, ssize, tsize; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; R_SkinFrame_PrepareForPurge(); for (i = 0;i < nummodels;i++) @@ -113,7 +113,7 @@ static void mod_newmap(void) ssize = (surface->lightmapinfo->extents[0] >> 4) + 1; tsize = (surface->lightmapinfo->extents[1] >> 4) + 1; memset(surface->lightmapinfo->stainsamples, 255, ssize * tsize * 3); - surface->cached_dlight = true; + mod->brushq1.lightmapupdateflags[surfacenum] = true; } } } @@ -131,7 +131,7 @@ static void Mod_BuildVBOs(void); void Mod_Init (void) { mod_mempool = Mem_AllocPool("modelinfo", 0, NULL); - Mem_ExpandableArray_NewArray(&models, mod_mempool, sizeof(model_t), 16); + Mem_ExpandableArray_NewArray(&models, mod_mempool, sizeof(dp_model_t), 16); Mod_BrushInit(); Mod_AliasInit(); @@ -147,23 +147,29 @@ void Mod_RenderInit(void) R_RegisterModule("Models", mod_start, mod_shutdown, mod_newmap); } -void Mod_UnloadModel (model_t *mod) +void Mod_UnloadModel (dp_model_t *mod) { char name[MAX_QPATH]; qboolean isworldmodel; qboolean used; + + if (developer_loading.integer) + Con_Printf("unloading model %s\n", mod->name); + strlcpy(name, mod->name, sizeof(name)); isworldmodel = mod->isworldmodel; used = mod->used; - if (mod->surfmesh.ebo) - R_Mesh_DestroyBufferObject(mod->surfmesh.ebo); + if (mod->surfmesh.ebo3i) + R_Mesh_DestroyBufferObject(mod->surfmesh.ebo3i); + if (mod->surfmesh.ebo3s) + R_Mesh_DestroyBufferObject(mod->surfmesh.ebo3s); if (mod->surfmesh.vbo) R_Mesh_DestroyBufferObject(mod->surfmesh.vbo); // free textures/memory attached to the model R_FreeTexturePool(&mod->texturepool); Mem_FreePool(&mod->mempool); // clear the struct to make it available - memset(mod, 0, sizeof(model_t)); + memset(mod, 0, sizeof(dp_model_t)); // restore the fields we want to preserve strlcpy(mod->name, name, sizeof(mod->name)); mod->isworldmodel = isworldmodel; @@ -178,7 +184,7 @@ Mod_LoadModel Loads a model ================== */ -model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolean isworldmodel) +dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk, qboolean isworldmodel) { int num; unsigned int crc; @@ -224,7 +230,9 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea return mod; } - Con_DPrintf("loading model %s\n", mod->name); + if (developer_loading.integer) + Con_Printf("loading model %s\n", mod->name); + // LordHavoc: unload the existing model in this slot (if there is one) if (mod->loaded || mod->mempool) Mod_UnloadModel(mod); @@ -245,11 +253,17 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea VectorSet(mod->rotatedmins, -mod->radius, -mod->radius, -mod->radius); VectorSet(mod->rotatedmaxs, mod->radius, mod->radius, mod->radius); - // if we're loading a worldmodel, then this is a level change, and we - // should reload all q3 shaders to make sure they are current (which will - // also be used by any other models loaded after this world model) + // if we're loading a worldmodel, then this is a level change if (mod->isworldmodel) + { + // clear out any stale submodels or worldmodels lying around + // if we did this clear before now, an error might abort loading and + // leave things in a bad state + Mod_RemoveStaleWorldModels(mod); + // reload q3 shaders, to make sure they are ready to go for this level + // (including any models loaded for this level) Mod_LoadQ3Shaders(); + } if (buf) { @@ -270,8 +284,7 @@ model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolea else if (!memcmp(buf, "ZYMOTICMODEL", 12)) Mod_ZYMOTICMODEL_Load(mod, buf, bufend); else if (!memcmp(buf, "DARKPLACESMODEL", 16)) Mod_DARKPLACESMODEL_Load(mod, buf, bufend); else if (!memcmp(buf, "ACTRHEAD", 8)) Mod_PSKMODEL_Load(mod, buf, bufend); - else if (strlen(mod->name) >= 4 && !strcmp(mod->name - 4, ".map")) Mod_MAP_Load(mod, buf, bufend); - else if (!memcmp(buf, "MCBSPpad", 8)) Mod_Q1BSP_Load(mod, buf, bufend); + else if (strlen(mod->name) >= 4 && !strcmp(mod->name + strlen(mod->name) - 4, ".map")) Mod_MAP_Load(mod, buf, bufend); else if (num == BSPVERSION || num == 30) Mod_Q1BSP_Load(mod, buf, bufend); else Con_Printf("Mod_LoadModel: model \"%s\" is of unknown/unsupported type\n", mod->name); Mem_Free(buf); @@ -293,7 +306,7 @@ void Mod_ClearUsed(void) { int i; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; for (i = 0;i < nummodels;i++) if ((mod = Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->name[0]) mod->used = false; @@ -303,7 +316,7 @@ void Mod_PurgeUnused(void) { int i; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; for (i = 0;i < nummodels;i++) { if ((mod = Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->name[0] && !mod->used) @@ -315,11 +328,11 @@ void Mod_PurgeUnused(void) } // only used during loading! -void Mod_RemoveStaleWorldModels(model_t *skip) +void Mod_RemoveStaleWorldModels(dp_model_t *skip) { int i; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; for (i = 0;i < nummodels;i++) { if ((mod = Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->isworldmodel && mod->loaded && skip != mod) @@ -337,11 +350,11 @@ Mod_FindName ================== */ -model_t *Mod_FindName(const char *name) +dp_model_t *Mod_FindName(const char *name) { int i; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; if (!name[0]) Host_Error ("Mod_ForName: NULL name"); @@ -371,9 +384,9 @@ Mod_ForName Loads in a model for the given name ================== */ -model_t *Mod_ForName(const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel) +dp_model_t *Mod_ForName(const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel) { - model_t *model; + dp_model_t *model; model = Mod_FindName(name); if (model->name[0] != '*' && (!model->loaded || checkdisk)) Mod_LoadModel(model, crash, checkdisk, isworldmodel); @@ -391,7 +404,7 @@ void Mod_Reload(void) { int i; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; for (i = 0;i < nummodels;i++) if ((mod = Mem_ExpandableArray_RecordAtIndex(&models, i)) && mod->name[0] && mod->name[0] != '*' && mod->used) Mod_LoadModel(mod, true, true, mod->isworldmodel); @@ -411,7 +424,7 @@ static void Mod_Print(void) { int i; int nummodels = Mem_ExpandableArray_IndexRange(&models); - model_t *mod; + dp_model_t *mod; Con_Print("Loaded models:\n"); for (i = 0;i < nummodels;i++) @@ -741,7 +754,7 @@ void Mod_BuildTextureVectorsFromNormals(int firstvertex, int numvertices, int nu void Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean lightmapoffsets, qboolean vertexcolors, qboolean neighbors) { unsigned char *data; - data = (unsigned char *)Mem_Alloc(mempool, numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + (neighbors ? 3 : 0)) * sizeof(int)); + data = (unsigned char *)Mem_Alloc(mempool, numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + (neighbors ? 3 : 0)) * sizeof(int) + (numvertices <= 65536 ? numtriangles * sizeof(unsigned short[3]) : 0)); loadmodel->surfmesh.num_vertices = numvertices; loadmodel->surfmesh.num_triangles = numtriangles; if (loadmodel->surfmesh.num_vertices) @@ -762,6 +775,8 @@ void Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qb loadmodel->surfmesh.data_element3i = (int *)data, data += sizeof(int[3]) * loadmodel->surfmesh.num_triangles; if (neighbors) loadmodel->surfmesh.data_neighbor3i = (int *)data, data += sizeof(int[3]) * loadmodel->surfmesh.num_triangles; + if (loadmodel->surfmesh.num_vertices <= 65536) + loadmodel->surfmesh.data_element3s = (unsigned short *)data, data += sizeof(unsigned short[3]) * loadmodel->surfmesh.num_triangles; } } @@ -775,6 +790,8 @@ shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts, int maxtria if (light) size += maxverts * sizeof(float[11]); size += maxtriangles * sizeof(int[3]); + if (maxverts <= 65536) + size += maxtriangles * sizeof(unsigned short[3]); if (neighbors) size += maxtriangles * sizeof(int[3]); if (expandable) @@ -807,6 +824,8 @@ shadowmesh_t *Mod_ShadowMesh_Alloc(mempool_t *mempool, int maxverts, int maxtria newmesh->vertexhashtable = (shadowmeshvertexhash_t **)data;data += SHADOWMESHVERTEXHASH * sizeof(shadowmeshvertexhash_t *); newmesh->vertexhashentries = (shadowmeshvertexhash_t *)data;data += maxverts * sizeof(shadowmeshvertexhash_t); } + if (maxverts <= 65536) + newmesh->element3s = (unsigned short *)data;data += maxtriangles * sizeof(unsigned short[3]); return newmesh; } @@ -937,7 +956,12 @@ static void Mod_ShadowMesh_CreateVBOs(shadowmesh_t *mesh) // element buffer is easy because it's just one array if (mesh->numtriangles) - mesh->ebo = R_Mesh_CreateStaticBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB, mesh->element3i, mesh->numtriangles * sizeof(int[3]), "shadowmesh"); + { + if (mesh->element3s) + mesh->ebo3s = R_Mesh_CreateStaticBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB, mesh->element3s, mesh->numtriangles * sizeof(unsigned short[3]), "shadowmesh"); + else + mesh->ebo3i = R_Mesh_CreateStaticBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB, mesh->element3i, mesh->numtriangles * sizeof(unsigned int[3]), "shadowmesh"); + } // vertex buffer is several arrays and we put them in the same buffer // @@ -977,6 +1001,12 @@ shadowmesh_t *Mod_ShadowMesh_Finish(mempool_t *mempool, shadowmesh_t *firstmesh, newmesh = Mod_ShadowMesh_ReAlloc(mempool, mesh, light, neighbors); newmesh->next = firstmesh; firstmesh = newmesh; + if (newmesh->element3s) + { + int i; + for (i = 0;i < newmesh->numtriangles*3;i++) + newmesh->element3s[i] = newmesh->element3i[i]; + } if (createvbo) Mod_ShadowMesh_CreateVBOs(newmesh); } @@ -1039,8 +1069,10 @@ void Mod_ShadowMesh_Free(shadowmesh_t *mesh) shadowmesh_t *nextmesh; for (;mesh;mesh = nextmesh) { - if (mesh->ebo) - R_Mesh_DestroyBufferObject(mesh->ebo); + if (mesh->ebo3i) + R_Mesh_DestroyBufferObject(mesh->ebo3i); + if (mesh->ebo3s) + R_Mesh_DestroyBufferObject(mesh->ebo3s); if (mesh->vbo) R_Mesh_DestroyBufferObject(mesh->vbo); nextmesh = mesh->next; @@ -1131,7 +1163,7 @@ static void Q3Shaders_Clear() q3shaders_mem = Mem_AllocPool("q3shaders", 0, NULL); q3shader_data = (q3shader_data_t*)Mem_Alloc (q3shaders_mem, sizeof (q3shader_data_t)); - Mem_ExpandableArray_NewArray (&q3shader_data->hash_entries, + Mem_ExpandableArray_NewArray (&q3shader_data->hash_entries, q3shaders_mem, sizeof (q3shader_hash_entry_t), 256); Mem_ExpandableArray_NewArray (&q3shader_data->char_ptrs, q3shaders_mem, sizeof (char**), 256); @@ -1139,7 +1171,7 @@ static void Q3Shaders_Clear() static void Q3Shader_AddToHash (q3shaderinfo_t* shader) { - unsigned short hash = CRC_Block ((const unsigned char *)shader->name, strlen (shader->name)); + unsigned short hash = CRC_Block_CaseInsensitive ((const unsigned char *)shader->name, strlen (shader->name)); q3shader_hash_entry_t* entry = q3shader_data->hash + (hash % Q3SHADER_HASH_SIZE); q3shader_hash_entry_t* lastEntry = NULL; while (entry != NULL) @@ -1159,7 +1191,7 @@ static void Q3Shader_AddToHash (q3shaderinfo_t* shader) /* Add to chain */ q3shader_hash_entry_t* newEntry = (q3shader_hash_entry_t*) Mem_ExpandableArray_AllocRecord (&q3shader_data->hash_entries); - + while (lastEntry->chain != NULL) lastEntry = lastEntry->chain; lastEntry->chain = newEntry; newEntry->chain = NULL; @@ -1171,6 +1203,7 @@ static void Q3Shader_AddToHash (q3shaderinfo_t* shader) memcpy (&entry->shader, shader, sizeof (q3shaderinfo_t)); } +extern cvar_t r_picmipworld; void Mod_LoadQ3Shaders(void) { int j; @@ -1202,6 +1235,7 @@ void Mod_LoadQ3Shaders(void) Vector4Set(shader.refractcolor4f, 1, 1, 1, 1); shader.reflectfactor = 1; Vector4Set(shader.reflectcolor4f, 1, 1, 1, 1); + shader.r_water_wateralpha = 1; strlcpy(shader.name, com_token, sizeof(shader.name)); if (!COM_ParseToken_QuakeC(&text, false) || strcasecmp(com_token, "{")) @@ -1413,6 +1447,7 @@ void Mod_LoadQ3Shaders(void) else if (!strcasecmp(parameter[1], "rotate")) layer->tcmods[tcmodindex].tcmod = Q3TCMOD_ROTATE; else if (!strcasecmp(parameter[1], "scale")) layer->tcmods[tcmodindex].tcmod = Q3TCMOD_SCALE; else if (!strcasecmp(parameter[1], "scroll")) layer->tcmods[tcmodindex].tcmod = Q3TCMOD_SCROLL; + else if (!strcasecmp(parameter[1], "page")) layer->tcmods[tcmodindex].tcmod = Q3TCMOD_PAGE; else if (!strcasecmp(parameter[1], "stretch")) { layer->tcmods[tcmodindex].tcmod = Q3TCMOD_STRETCH; @@ -1446,6 +1481,13 @@ void Mod_LoadQ3Shaders(void) shader.textureblendalpha = true; } } + layer->texflags = TEXF_ALPHA | TEXF_PRECACHE; + if (!(shader.surfaceparms & Q3SURFACEPARM_NOMIPMAPS)) + layer->texflags |= TEXF_MIPMAP; + if (!(shader.textureflags & Q3TEXTUREFLAG_NOPICMIP)) + layer->texflags |= TEXF_PICMIP | TEXF_COMPRESS; + if (layer->clampmap) + layer->texflags |= TEXF_CLAMP; continue; } numparameters = 0; @@ -1541,6 +1583,10 @@ void Mod_LoadQ3Shaders(void) else Con_DPrintf("%s parsing warning: unknown surfaceparm \"%s\"\n", search->filenames[fileindex], parameter[1]); } + else if (!strcasecmp(parameter[0], "dpshadow")) + shader.dpshadow = true; + else if (!strcasecmp(parameter[0], "dpnoshadow")) + shader.dpnoshadow = true; else if (!strcasecmp(parameter[0], "sky") && numparameters >= 2) { // some q3 skies don't have the sky parm set @@ -1577,7 +1623,7 @@ void Mod_LoadQ3Shaders(void) shader.reflectfactor = atof(parameter[1]); Vector4Set(shader.reflectcolor4f, atof(parameter[2]), atof(parameter[3]), atof(parameter[4]), atof(parameter[5])); } - else if (!strcasecmp(parameter[0], "dp_water") && numparameters >= 11) + else if (!strcasecmp(parameter[0], "dp_water") && numparameters >= 12) { shader.textureflags |= Q3TEXTUREFLAG_WATERSHADER; shader.reflectmin = atof(parameter[1]); @@ -1586,6 +1632,7 @@ void Mod_LoadQ3Shaders(void) shader.reflectfactor = atof(parameter[4]); Vector4Set(shader.refractcolor4f, atof(parameter[5]), atof(parameter[6]), atof(parameter[7]), 1); Vector4Set(shader.reflectcolor4f, atof(parameter[8]), atof(parameter[9]), atof(parameter[10]), 1); + shader.r_water_wateralpha = atof(parameter[11]); } else if (!strcasecmp(parameter[0], "deformvertexes") && numparameters >= 2) { @@ -1627,26 +1674,29 @@ void Mod_LoadQ3Shaders(void) } } } - // identify if this is a blended terrain shader or similar + // pick the primary layer to render with if (shader.numlayers) { shader.backgroundlayer = -1; shader.primarylayer = 0; - if ((shader.layers[0].blendfunc[0] == GL_ONE && shader.layers[0].blendfunc[1] == GL_ZERO && !shader.layers[0].alphatest) - && ((shader.layers[1].blendfunc[0] == GL_SRC_ALPHA && shader.layers[1].blendfunc[1] == GL_ONE_MINUS_SRC_ALPHA && !shader.layers[0].alphatest) - || (shader.layers[1].blendfunc[0] == GL_ONE && shader.layers[1].blendfunc[1] == GL_ZERO && shader.layers[1].alphatest))) - { - // terrain blending or other effects - shader.backgroundlayer = 0; - shader.primarylayer = 1; - } - // now see if the lightmap came first, and if so choose the second texture instead + // if lightmap comes first this is definitely an ordinary texture + // if the first two layers have the correct blendfuncs and use vertex alpha, it is a blended terrain shader if ((shader.layers[shader.primarylayer].texturename != NULL) && !strcasecmp(shader.layers[shader.primarylayer].texturename[0], "$lightmap")) { shader.backgroundlayer = -1; shader.primarylayer = 1; } + else if (shader.numlayers >= 2 + && shader.layers[1].alphagen.alphagen == Q3ALPHAGEN_VERTEX + && (shader.layers[0].blendfunc[0] == GL_ONE && shader.layers[0].blendfunc[1] == GL_ZERO && !shader.layers[0].alphatest) + && ((shader.layers[1].blendfunc[0] == GL_SRC_ALPHA && shader.layers[1].blendfunc[1] == GL_ONE_MINUS_SRC_ALPHA) + || (shader.layers[1].blendfunc[0] == GL_ONE && shader.layers[1].blendfunc[1] == GL_ZERO && shader.layers[1].alphatest))) + { + // terrain blending or other effects + shader.backgroundlayer = 0; + shader.primarylayer = 1; + } } // fix up multiple reflection types if(shader.textureflags & Q3TEXTUREFLAG_WATERSHADER) @@ -1660,7 +1710,7 @@ void Mod_LoadQ3Shaders(void) q3shaderinfo_t *Mod_LookupQ3Shader(const char *name) { - unsigned short hash = CRC_Block ((const unsigned char *)name, strlen (name)); + unsigned short hash = CRC_Block_CaseInsensitive ((const unsigned char *)name, strlen (name)); q3shader_hash_entry_t* entry = q3shader_data->hash + (hash % Q3SHADER_HASH_SIZE); while (entry != NULL) { @@ -1671,25 +1721,32 @@ q3shaderinfo_t *Mod_LookupQ3Shader(const char *name) return NULL; } -extern cvar_t r_picmipworld; -qboolean Mod_LoadTextureFromQ3Shader(texture_t *texture, const char *name, qboolean q1bsp, qboolean q3bsp, qboolean md3) +qboolean Mod_LoadTextureFromQ3Shader(texture_t *texture, const char *name, qboolean warnmissing, qboolean fallback, int defaulttexflags) { int j; - int texflags; qboolean success = true; q3shaderinfo_t *shader; + if (!name) + name = ""; strlcpy(texture->name, name, sizeof(texture->name)); shader = name[0] ? Mod_LookupQ3Shader(name) : NULL; if (shader) { - if (developer.integer >= 100) - Con_DPrintf("%s: loaded shader for %s\n", loadmodel->name, name); + if (developer_loading.integer) + Con_Printf("%s: loaded shader for %s\n", loadmodel->name, name); texture->surfaceparms = shader->surfaceparms; texture->textureflags = shader->textureflags; + + // allow disabling of picmip or compression by defaulttexflags + if(!(defaulttexflags & TEXF_PICMIP)) + texture->textureflags &= ~TEXF_PICMIP; + if(!(defaulttexflags & TEXF_COMPRESS)) + texture->textureflags &= ~TEXF_COMPRESS; + texture->basematerialflags = 0; if (shader->surfaceparms & Q3SURFACEPARM_SKY) { - texture->basematerialflags |= MATERIALFLAG_SKY | MATERIALFLAG_NOSHADOW; + texture->basematerialflags = MATERIALFLAG_SKY | MATERIALFLAG_NOSHADOW; if (shader->skyboxname[0]) { // quake3 seems to append a _ to the skybox name, so this must do so as well @@ -1697,21 +1754,15 @@ qboolean Mod_LoadTextureFromQ3Shader(texture_t *texture, const char *name, qbool } } else if ((texture->surfaceflags & Q3SURFACEFLAG_NODRAW) || shader->numlayers == 0) - texture->basematerialflags |= MATERIALFLAG_NODRAW | MATERIALFLAG_NOSHADOW; - else if (shader->surfaceparms & Q3SURFACEPARM_LAVA) - texture->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES | MATERIALFLAG_FULLBRIGHT | MATERIALFLAG_NOSHADOW; - else if (shader->surfaceparms & Q3SURFACEPARM_SLIME) - texture->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES | MATERIALFLAG_WATERALPHA | MATERIALFLAG_NOSHADOW; - else if (shader->surfaceparms & Q3SURFACEPARM_WATER) - texture->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES | MATERIALFLAG_WATERALPHA | MATERIALFLAG_NOSHADOW; + texture->basematerialflags = MATERIALFLAG_NODRAW | MATERIALFLAG_NOSHADOW; else - texture->basematerialflags |= MATERIALFLAG_WALL; + texture->basematerialflags = MATERIALFLAG_WALL; if (shader->layers[0].alphatest) texture->basematerialflags |= MATERIALFLAG_ALPHATEST | MATERIALFLAG_NOSHADOW; if (shader->textureflags & Q3TEXTUREFLAG_TWOSIDED) texture->basematerialflags |= MATERIALFLAG_NOSHADOW | MATERIALFLAG_NOCULLFACE; if (shader->textureflags & Q3TEXTUREFLAG_POLYGONOFFSET) - texture->basepolygonoffset -= 2; + texture->biaspolygonoffset -= 2; if (shader->textureflags & Q3TEXTUREFLAG_REFRACTION) texture->basematerialflags |= MATERIALFLAG_REFRACTION; if (shader->textureflags & Q3TEXTUREFLAG_REFLECTION) @@ -1772,14 +1823,11 @@ nothing GL_ZERO GL_ONE texture->skinframerate = primarylayer->framerate; for (j = 0;j < primarylayer->numframes;j++) { - texflags = TEXF_ALPHA | TEXF_PRECACHE; - if (!(shader->surfaceparms & Q3SURFACEPARM_NOMIPMAPS)) - texflags |= TEXF_MIPMAP; - if (!(shader->textureflags & Q3TEXTUREFLAG_NOPICMIP) && ((!q1bsp && !q3bsp) || r_picmipworld.integer)) - texflags |= TEXF_PICMIP | TEXF_COMPRESS; - if (primarylayer->clampmap) - texflags |= TEXF_CLAMP; - if (!(texture->skinframes[j] = R_SkinFrame_LoadExternal(primarylayer->texturename[j], texflags, false))) + if(cls.state == ca_dedicated) + { + texture->skinframes[j] = NULL; + } + else if (!(texture->skinframes[j] = R_SkinFrame_LoadExternal(primarylayer->texturename[j], primarylayer->texflags, false))) { Con_Printf("^1%s:^7 could not load texture ^3\"%s\"^7 (frame %i) for shader ^2\"%s\"\n", loadmodel->name, primarylayer->texturename[j], j, texture->name); texture->skinframes[j] = R_SkinFrame_LoadMissing(); @@ -1793,13 +1841,21 @@ nothing GL_ZERO GL_ONE texture->backgroundskinframerate = backgroundlayer->framerate; for (j = 0;j < backgroundlayer->numframes;j++) { - if (!(texture->backgroundskinframes[j] = R_SkinFrame_LoadExternal(backgroundlayer->texturename[j], ((shader->surfaceparms & Q3SURFACEPARM_NOMIPMAPS) ? 0 : TEXF_MIPMAP) | TEXF_ALPHA | TEXF_PRECACHE | ((!r_picmipworld.integer || (shader->textureflags & Q3TEXTUREFLAG_NOPICMIP)) ? 0 : (TEXF_PICMIP | TEXF_COMPRESS)) | (backgroundlayer->clampmap ? TEXF_CLAMP : 0), false))) + if(cls.state == ca_dedicated) + { + texture->skinframes[j] = NULL; + } + else if (!(texture->backgroundskinframes[j] = R_SkinFrame_LoadExternal(backgroundlayer->texturename[j], backgroundlayer->texflags, false))) { - Con_Printf("^1%s:^7 could not load texture ^3\"%s\"^7 (frame %i) for shader ^2\"%s\"\n", loadmodel->name, backgroundlayer->texturename[j], j, texture->name); + Con_Printf("^1%s:^7 could not load texture ^3\"%s\"^7 (background frame %i) for shader ^2\"%s\"\n", loadmodel->name, backgroundlayer->texturename[j], j, texture->name); texture->backgroundskinframes[j] = R_SkinFrame_LoadMissing(); } } } + if (shader->dpshadow) + texture->basematerialflags &= ~MATERIALFLAG_NOSHADOW; + if (shader->dpnoshadow) + texture->basematerialflags |= MATERIALFLAG_NOSHADOW; memcpy(texture->deforms, shader->deforms, sizeof(texture->deforms)); texture->reflectmin = shader->reflectmin; texture->reflectmax = shader->reflectmax; @@ -1807,18 +1863,25 @@ nothing GL_ZERO GL_ONE Vector4Copy(shader->refractcolor4f, texture->refractcolor4f); texture->reflectfactor = shader->reflectfactor; Vector4Copy(shader->reflectcolor4f, texture->reflectcolor4f); + texture->r_water_wateralpha = shader->r_water_wateralpha; + } + else if (!strcmp(texture->name, "noshader") || !texture->name[0]) + { + if (developer.integer >= 100) + Con_Printf("^1%s:^7 using fallback noshader material for ^3\"%s\"\n", loadmodel->name, name); + texture->surfaceparms = 0; } - else if (!strcmp(texture->name, "noshader")) + else if (!strcmp(texture->name, "common/nodraw") || !strcmp(texture->name, "textures/common/nodraw")) { if (developer.integer >= 100) - Con_DPrintf("%s: using default handler for %s\n", loadmodel->name, name); + Con_Printf("^1%s:^7 using fallback nodraw material for ^3\"%s\"\n", loadmodel->name, name); texture->surfaceparms = 0; + texture->basematerialflags = MATERIALFLAG_NODRAW | MATERIALFLAG_NOSHADOW; } else { - success = false; - if (developer.integer >= 100 || loadmodel->type == mod_brushq3) - Con_DPrintf("%s: No shader found for texture \"%s\"\n", loadmodel->name, texture->name); + if (developer.integer >= 100) + Con_Printf("^1%s:^7 No shader found for texture ^3\"%s\"\n", loadmodel->name, texture->name); texture->surfaceparms = 0; if (texture->surfaceflags & Q3SURFACEFLAG_NODRAW) texture->basematerialflags |= MATERIALFLAG_NODRAW | MATERIALFLAG_NOSHADOW; @@ -1827,9 +1890,28 @@ nothing GL_ZERO GL_ONE else texture->basematerialflags |= MATERIALFLAG_WALL; texture->numskinframes = 1; - if (!(texture->skinframes[0] = R_SkinFrame_LoadExternal(texture->name, TEXF_MIPMAP | TEXF_ALPHA | TEXF_PRECACHE | (r_picmipworld.integer ? TEXF_PICMIP : 0) | TEXF_COMPRESS, false))) - if(developer.integer || q3bsp) // only the Q3BSP path provides no alternative (like loading image directly, or internal texture) - Con_Printf("^1%s:^7 could not load texture for missing shader ^3\"%s\"\n", loadmodel->name, texture->name); + if(cls.state == ca_dedicated) + { + texture->skinframes[0] = NULL; + } + else + { + if (fallback) + { + qboolean has_alpha; + if ((texture->skinframes[0] = R_SkinFrame_LoadExternal_CheckAlpha(texture->name, defaulttexflags, false, &has_alpha))) + { + if(has_alpha && (defaulttexflags & TEXF_ALPHA)) + texture->basematerialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW; + } + else + success = false; + } + else + success = false; + if (!success && warnmissing) + Con_Printf("^1%s:^7 could not load texture ^3\"%s\"\n", loadmodel->name, texture->name); + } } // init the animation variables texture->currentframe = texture; @@ -1844,14 +1926,12 @@ nothing GL_ZERO GL_ONE skinfile_t *Mod_LoadSkinFiles(void) { - int i, words, numtags, line, tagsetsused = false, wordsoverflow; + int i, words, line, wordsoverflow; char *text; const char *data; skinfile_t *skinfile = NULL, *first = NULL; skinfileitem_t *skinfileitem; char word[10][MAX_QPATH]; - overridetagnameset_t tagsets[MAX_SKINS]; - overridetagname_t tags[256]; /* sample file: @@ -1868,12 +1948,9 @@ tag_head, tag_weapon, tag_torso, */ - memset(tagsets, 0, sizeof(tagsets)); memset(word, 0, sizeof(word)); for (i = 0;i < MAX_SKINS && (data = text = (char *)FS_LoadFile(va("%s_%i.skin", loadmodel->name, i), tempmempool, true, NULL));i++) { - numtags = 0; - // If it's the first file we parse if (skinfile == NULL) { @@ -1914,7 +1991,8 @@ tag_torso, { if (words == 3) { - Con_DPrintf("Mod_LoadSkinFiles: parsed mesh \"%s\" shader replacement \"%s\"\n", word[1], word[2]); + if (developer_loading.integer) + Con_Printf("Mod_LoadSkinFiles: parsed mesh \"%s\" shader replacement \"%s\"\n", word[1], word[2]); skinfileitem = (skinfileitem_t *)Mem_Alloc(loadmodel->mempool, sizeof(skinfileitem_t)); skinfileitem->next = skinfile->items; skinfile->items = skinfileitem; @@ -1924,18 +2002,16 @@ tag_torso, else Con_Printf("Mod_LoadSkinFiles: parsing error in file \"%s_%i.skin\" on line #%i: wrong number of parameters to command \"%s\", see documentation in DP_GFX_SKINFILES extension in dpextensions.qc\n", loadmodel->name, i, line, word[0]); } - else if (words == 2 && !strcmp(word[1], ",")) + else if (words >= 2 && !strncmp(word[0], "tag_", 4)) { // tag name, like "tag_weapon," - Con_DPrintf("Mod_LoadSkinFiles: parsed tag #%i \"%s\"\n", numtags, word[0]); - memset(tags + numtags, 0, sizeof(tags[numtags])); - strlcpy (tags[numtags].name, word[0], sizeof (tags[numtags].name)); - numtags++; + // not used for anything (not even in Quake3) } - else if (words == 3 && !strcmp(word[1], ",")) + else if (words >= 2 && !strcmp(word[1], ",")) { // mesh shader name, like "U_RArm,models/players/Legoman/BikerA1.tga" - Con_DPrintf("Mod_LoadSkinFiles: parsed mesh \"%s\" shader replacement \"%s\"\n", word[0], word[2]); + if (developer_loading.integer) + Con_Printf("Mod_LoadSkinFiles: parsed mesh \"%s\" shader replacement \"%s\"\n", word[0], word[2]); skinfileitem = (skinfileitem_t *)Mem_Alloc(loadmodel->mempool, sizeof(skinfileitem_t)); skinfileitem->next = skinfile->items; skinfile->items = skinfileitem; @@ -1946,21 +2022,6 @@ tag_torso, Con_Printf("Mod_LoadSkinFiles: parsing error in file \"%s_%i.skin\" on line #%i: does not look like tag or mesh specification, or replace command, see documentation in DP_GFX_SKINFILES extension in dpextensions.qc\n", loadmodel->name, i, line); } Mem_Free(text); - - if (numtags) - { - overridetagnameset_t *t; - t = tagsets + i; - t->num_overridetagnames = numtags; - t->data_overridetagnames = (overridetagname_t *)Mem_Alloc(loadmodel->mempool, t->num_overridetagnames * sizeof(overridetagname_t)); - memcpy(t->data_overridetagnames, tags, t->num_overridetagnames * sizeof(overridetagname_t)); - tagsetsused = true; - } - } - if (tagsetsused) - { - loadmodel->data_overridetagnamesforskin = (overridetagnameset_t *)Mem_Alloc(loadmodel->mempool, i * sizeof(overridetagnameset_t)); - memcpy(loadmodel->data_overridetagnamesforskin, tagsets, i * sizeof(overridetagnameset_t)); } if (i) loadmodel->numskins = i; @@ -2054,7 +2115,17 @@ static void Mod_BuildVBOs(void) // element buffer is easy because it's just one array if (loadmodel->surfmesh.num_triangles) - loadmodel->surfmesh.ebo = R_Mesh_CreateStaticBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles * sizeof(int[3]), loadmodel->name); + { + if (loadmodel->surfmesh.data_element3s) + { + int i; + for (i = 0;i < loadmodel->surfmesh.num_triangles*3;i++) + loadmodel->surfmesh.data_element3s[i] = loadmodel->surfmesh.data_element3i[i]; + loadmodel->surfmesh.ebo3s = R_Mesh_CreateStaticBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB, loadmodel->surfmesh.data_element3s, loadmodel->surfmesh.num_triangles * sizeof(unsigned short[3]), loadmodel->name); + } + else + loadmodel->surfmesh.ebo3i = R_Mesh_CreateStaticBufferObject(GL_ELEMENT_ARRAY_BUFFER_ARB, loadmodel->surfmesh.data_element3i, loadmodel->surfmesh.num_triangles * sizeof(unsigned int[3]), loadmodel->name); + } // vertex buffer is several arrays and we put them in the same buffer //