From 93783908b793eb2f1df1e705cc7d29489cf409b3 Mon Sep 17 00:00:00 2001 From: eihrul Date: Mon, 1 Feb 2010 10:15:46 +0000 Subject: [PATCH] check if a model's textures have deforms that need normals/tangents at load-time, and pass in appropriate flags to RSurf_ActiveModelEntity based on this when rendering models with depthonly (fixes Nexuiz flag z-fighting) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9918 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 14 +++++++++++++- model_shared.c | 27 +++++++++++++++++++++++++++ model_shared.h | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/gl_rmain.c b/gl_rmain.c index 04b58483..68ca03a4 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -12287,7 +12287,19 @@ void R_DrawModelSurfaces(entity_render_t *ent, qboolean skysurfaces, qboolean wr else if (prepass) RSurf_ActiveModelEntity(ent, true, true, true); else if (depthonly) - RSurf_ActiveModelEntity(ent, false, false, false); + { + switch (vid.renderpath) + { + case RENDERPATH_GL20: + case RENDERPATH_CGGL: + RSurf_ActiveModelEntity(ent, model->wantnormals, model->wanttangents, false); + break; + case RENDERPATH_GL13: + case RENDERPATH_GL11: + RSurf_ActiveModelEntity(ent, model->wantnormals, false, false); + break; + } + } else { switch (vid.renderpath) diff --git a/model_shared.c b/model_shared.c index 45fd3143..74485ec1 100644 --- a/model_shared.c +++ b/model_shared.c @@ -311,6 +311,31 @@ void Mod_FrameGroupify(dp_model_t *mod, const char *buf) Mod_FrameGroupify_ParseGroups(buf, Mod_FrameGroupify_ParseGroups_Store, mod); } +void Mod_FindPotentialDeforms(dp_model_t *mod) +{ + int i, j; + texture_t *texture; + mod->wantnormals = false; + mod->wanttangents = false; + for (i = 0;i < mod->num_textures;i++) + { + texture = mod->data_textures + i; + if (texture->tcgen.tcgen == Q3TCGEN_ENVIRONMENT) + mod->wantnormals = true; + for (j = 0;j < Q3MAXDEFORMS;j++) + { + if (texture->deforms[j].deform == Q3DEFORM_AUTOSPRITE) + { + mod->wanttangents = true; + mod->wantnormals = true; + break; + } + if (texture->deforms[j].deform != Q3DEFORM_NONE) + mod->wantnormals = true; + } + } +} + /* ================== Mod_LoadModel @@ -447,6 +472,8 @@ dp_model_t *Mod_LoadModel(dp_model_t *mod, qboolean crash, qboolean checkdisk) else Con_Printf("Mod_LoadModel: model \"%s\" is of unknown/unsupported type\n", mod->name); Mem_Free(buf); + Mod_FindPotentialDeforms(mod); + buf = FS_LoadFile (va("%s.framegroups", mod->name), tempmempool, false, &filesize); if(buf) { diff --git a/model_shared.h b/model_shared.h index 1e0c7794..8256dc71 100644 --- a/model_shared.h +++ b/model_shared.h @@ -882,6 +882,8 @@ typedef struct model_s int num_textures; int num_texturesperskin; texture_t *data_textures; + qboolean wantnormals; + qboolean wanttangents; // surfaces of this model int num_surfaces; msurface_t *data_surfaces; -- 2.39.2