diff --git a/engine/client/render.h b/engine/client/render.h index 2616ccada..c497f579c 100644 --- a/engine/client/render.h +++ b/engine/client/render.h @@ -341,6 +341,7 @@ int Mod_SkinNumForName(struct model_s *model, char *name); int Mod_FrameNumForName(struct model_s *model, char *name); float Mod_FrameDuration(struct model_s *model, int frameno); +void RMod_ResortShaders(void); void RMod_ClearAll (void); struct model_s *RMod_ForName (char *name, qboolean crash); struct model_s *RMod_FindName (char *name); diff --git a/engine/common/gl_q2bsp.c b/engine/common/gl_q2bsp.c index 07a939d13..2b4705ecf 100644 --- a/engine/common/gl_q2bsp.c +++ b/engine/common/gl_q2bsp.c @@ -127,6 +127,7 @@ void ClearBounds (vec3_t mins, vec3_t maxs) void Mod_SortShaders(void) { + //surely this isn't still needed? texture_t *textemp; int i, j; @@ -2565,6 +2566,9 @@ void CModRBSP_BuildSurfMesh(model_t *mod, msurface_t *out, void *cookie) Vector4Copy(mesh->colors4b_array[0], mesh->colors4b_array[3]); */ } + + Mod_AccumulateMeshTextureVectors(out->mesh); + Mod_NormaliseTextureVectors(out->mesh->normals_array, out->mesh->snormals_array, out->mesh->tnormals_array, out->mesh->numvertexes); } void CModQ3_BuildSurfMesh(model_t *mod, msurface_t *out, void *cookie) @@ -2575,15 +2579,7 @@ void CModQ3_BuildSurfMesh(model_t *mod, msurface_t *out, void *cookie) if (LittleLong(in->facetype) == MST_PATCH) { -// out->mesh->numindexes = 0; -// out->mesh->numvertexes = 0; - //FIXME GL_CreateMeshForPatch(loadmodel, out->mesh, LittleLong(in->patchwidth), LittleLong(in->patchheight), LittleLong(in->num_vertices), LittleLong(in->firstvertex)); -// if (out->mesh) -// { -// Mod_AccumulateMeshTextureVectors(out->mesh); -// Mod_NormaliseTextureVectors(out->mesh->normals_array, out->mesh->snormals_array, out->mesh->tnormals_array, out->mesh->numvertexes); -// } } else if (LittleLong(in->facetype) == MST_PLANAR || LittleLong(in->facetype) == MST_TRIANGLE_SOUP) { @@ -2602,35 +2598,6 @@ void CModQ3_BuildSurfMesh(model_t *mod, msurface_t *out, void *cookie) { out->mesh->indexes[i] = map_surfindexes[fv + i]; } - -/* numindexes = LittleLong(in->num_indexes); - numverts = LittleLong(in->num_vertices); - if (numindexes%3 || numindexes < 0 || numverts < 0) - { - Con_Printf(CON_ERROR "mesh indexes should be multiples of 3\n"); - return false; - } - - out->mesh = Hunk_Alloc(sizeof(mesh_t)); - out->mesh->normals_array= map_normals_array + LittleLong(in->firstvertex); - out->mesh->snormals_array = map_svector_array + LittleLong(in->firstvertex); - out->mesh->tnormals_array = map_tvector_array + LittleLong(in->firstvertex); - - out->mesh->colors4f_array = map_colors4f_array + LittleLong(in->firstvertex); - out->mesh->indexes = map_surfindexes + LittleLong(in->firstindex); - out->mesh->xyz_array = map_verts + LittleLong(in->firstvertex); - out->mesh->st_array = map_vertstmexcoords + LittleLong(in->firstvertex); - out->mesh->lmst_array = map_vertlstmexcoords + LittleLong(in->firstvertex); - - out->mesh->numindexes = numindexes; - out->mesh->numvertexes = numverts; - - if (LittleLong(in->facetype) == MST_PLANAR) - if (out->mesh->numindexes == (out->mesh->numvertexes-2)*3) - out->mesh->istrifan = true; - - Mod_AccumulateMeshTextureVectors(out->mesh); -*/ } else { @@ -2669,7 +2636,8 @@ void CModQ3_BuildSurfMesh(model_t *mod, msurface_t *out, void *cookie) */ } - + Mod_AccumulateMeshTextureVectors(out->mesh); + Mod_NormaliseTextureVectors(out->mesh->normals_array, out->mesh->snormals_array, out->mesh->tnormals_array, out->mesh->numvertexes); } qboolean CModQ3_LoadRFaces (lump_t *l) @@ -2783,10 +2751,7 @@ qboolean CModQ3_LoadRFaces (lump_t *l) } } - Mod_NormaliseTextureVectors(map_normals_array, map_svector_array, map_tvector_array, numvertexes); - Mod_SortShaders(); - return true; } @@ -2900,7 +2865,8 @@ qboolean CModRBSP_LoadRFaces (lump_t *l) out->mesh->numvertexes = 4; } } - + + Mod_SortShaders(); return true; } #endif diff --git a/engine/gl/gl_model.c b/engine/gl/gl_model.c index fdd602ef1..fc36c7a3a 100644 --- a/engine/gl/gl_model.c +++ b/engine/gl/gl_model.c @@ -365,6 +365,35 @@ void Mod_RebuildLightmaps (void) } } +void RMod_ResortShaders(void) +{ + //called when some shader changed its sort key. + //this means we have to hunt down all models and update their batches. + //really its only bsps that need this. + batch_t *oldlists[SHADER_SORT_COUNT], *b; + int i, j, bs; + model_t *mod; + for (i=0, mod=mod_known ; ineedload) + continue; + + memcpy(oldlists, mod->batches, sizeof(oldlists)); + memset(mod->batches, 0, sizeof(oldlists)); + + for (j = 0; j < SHADER_SORT_COUNT; j++) + { + while((b=oldlists[j])) + { + oldlists[j] = b->next; + bs = b->shader?b->shader->sort:j; + + b->next = mod->batches[bs]; + mod->batches[bs] = b; + } + } + } +} /* =================== Mod_ClearAll diff --git a/engine/gl/gl_shader.c b/engine/gl/gl_shader.c index 1487ca216..f133bf454 100644 --- a/engine/gl/gl_shader.c +++ b/engine/gl/gl_shader.c @@ -4194,7 +4194,6 @@ char *Shader_DefaultBSPWater(char *shortname) case -1: //invisible return ( "{\n" - "sort blend\n" "surfaceparm nodraw\n" "surfaceparm nodlight\n" "}\n" @@ -4202,7 +4201,6 @@ char *Shader_DefaultBSPWater(char *shortname) case 0: //fastturb return ( "{\n" - "sort blend\n" "{\n" "map $whiteimage\n" "rgbgen const $r_fastturbcolour\n" @@ -4214,7 +4212,6 @@ char *Shader_DefaultBSPWater(char *shortname) case 1: //vanilla style return ( "{\n" - "sort blend\n" /*make sure it always has the same sort order, so switching on/off wateralpha doesn't break stuff*/ "program defaultwarp\n" "{\n" "map $diffuse\n" @@ -4231,7 +4228,6 @@ char *Shader_DefaultBSPWater(char *shortname) case 2: //refraction of the underwater surface, with a fresnel return ( "{\n" - "sort blend\n" /*make sure it always has the same sort order, so switching on/off wateralpha doesn't break stuff*/ "surfaceparm nodlight\n" "{\n" "map $refraction\n" @@ -4248,7 +4244,6 @@ char *Shader_DefaultBSPWater(char *shortname) case 3: //reflections return ( "{\n" - "sort blend\n" /*make sure it always has the same sort order, so switching on/off wateralpha doesn't break stuff*/ "surfaceparm nodlight\n" "{\n" "map $refraction\n" @@ -4265,7 +4260,6 @@ char *Shader_DefaultBSPWater(char *shortname) case 4: //ripples return ( "{\n" - "sort blend\n" /*make sure it always has the same sort order, so switching on/off wateralpha doesn't break stuff*/ "surfaceparm nodlight\n" "{\n" "map $refraction\n" @@ -4285,7 +4279,6 @@ char *Shader_DefaultBSPWater(char *shortname) case 5: //ripples+reflections return ( "{\n" - "sort blend\n" /*make sure it always has the same sort order, so switching on/off wateralpha doesn't break stuff*/ "surfaceparm nodlight\n" "{\n" "map $refraction\n" @@ -4931,6 +4924,8 @@ void Shader_DoReload(void) shader_t *s; unsigned int i; char shortname[MAX_QPATH]; + int oldsort; + qboolean resort = false; if (shader_rescan_needed && ruleset_allow_shaders.ival) { @@ -4973,11 +4968,20 @@ void Shader_DoReload(void) } if (s->generator) { + oldsort = s->sort; Shader_Reset(s); s->generator(shortname, s, s->genargs); + + if (s->sort != oldsort) + resort = true; } } + + if (resort) + { + RMod_ResortShaders(); + } } void Shader_NeedReload(qboolean rescanfs)