From cbdbfdd12f8380a831f438cb4efcddd4e63a7ac7 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 23 Feb 2012 12:55:50 +0900 Subject: [PATCH] Fix the alias model loader for plugins. --- include/QF/model.h | 6 ---- include/QF/plugin/vid_render.h | 7 +++++ include/mod_internal.h | 40 ++++++++++++++++++++++++--- libs/models/alias/gl_mesh.c | 33 +++++++++++----------- libs/models/alias/gl_model_alias.c | 10 +++---- libs/models/alias/glsl_model_alias.c | 14 ++++------ libs/models/alias/model_alias.c | 18 ++++++------ libs/models/alias/sw_model_alias.c | 14 ++++------ libs/models/brush/gl_model_brush.c | 8 +++--- libs/models/brush/glsl_model_brush.c | 8 +++--- libs/models/brush/sw_model_brush.c | 8 +++--- libs/video/renderer/vid_render_gl.c | 15 +++++++--- libs/video/renderer/vid_render_glsl.c | 15 +++++++--- libs/video/renderer/vid_render_sw.c | 15 +++++++--- libs/video/renderer/vid_render_sw32.c | 15 +++++++--- 15 files changed, 141 insertions(+), 85 deletions(-) diff --git a/include/QF/model.h b/include/QF/model.h index 759a6a81f..531c98be8 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -440,7 +440,6 @@ void Mod_TouchModel (const char *name); mleaf_t *Mod_PointInLeaf (const vec3_t p, model_t *model); byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model); model_t *Mod_FindName (const char *name); -void Mod_LoadExternalSkins (model_t * mod); int Mod_CalcFullbright (byte *in, byte *out, int pixels); int Mod_Fullbright (byte * skin, int width, int height, char *name); @@ -448,11 +447,6 @@ void *Mod_LoadAliasFrame (void *pin, int *posenum, maliasframedesc_t *frame, int extra); void *Mod_LoadAliasGroup (void *pin, int *posenum, maliasframedesc_t *frame, int extra); -void *Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, - qboolean group, maliasskindesc_t *skindesc); -void Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, - int _s, int extra); -void Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr); void Mod_SpriteLoadTexture (mspriteframe_t *pspriteframe, int framenum); void Mod_LoadBrushModel (model_t *mod, void *buffer); diff --git a/include/QF/plugin/vid_render.h b/include/QF/plugin/vid_render.h index 559127c7e..952490dcb 100644 --- a/include/QF/plugin/vid_render.h +++ b/include/QF/plugin/vid_render.h @@ -88,6 +88,13 @@ typedef struct vid_model_funcs_s { void (*Mod_LoadAliasModel) (model_t *mod, void *buffer, cache_allocator_t allocator); void (*Mod_LoadSpriteModel) (model_t *mod, void *buffer); + void (*Mod_MakeAliasModelDisplayLists) (model_t *m, aliashdr_t *hdr, + void *_m, int _s, int extra); + void *(*Mod_LoadSkin) (byte *skin, int skinsize, int snum, int gnum, + qboolean group, maliasskindesc_t *skindesc); + void (*Mod_FinalizeAliasModel) (model_t *m, aliashdr_t *hdr); + void (*Mod_LoadExternalSkins) (model_t * mod); + int alias_cache; struct skin_s *(*Skin_SetColormap) (struct skin_s *skin, int cmap); struct skin_s *(*Skin_SetSkin) (struct skin_s *skin, int cmap, diff --git a/include/mod_internal.h b/include/mod_internal.h index 0150e679c..3e484e3f6 100644 --- a/include/mod_internal.h +++ b/include/mod_internal.h @@ -7,10 +7,42 @@ extern vid_model_funcs_t *m_funcs; -void Mod_LoadExternalTextures (model_t *mod); -void Mod_LoadLighting (bsp_t *bsp); -void Mod_SubdivideSurface (msurface_t *fa); -void Mod_ProcessTexture(texture_t *tx); +void gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, + int _s, int extra); +void *gl_Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, + qboolean group, maliasskindesc_t *skindesc); +void gl_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr); +void gl_Mod_LoadExternalSkins (model_t * mod); + +void glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, + void *_m, int _s, int extra); +void *glsl_Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, + qboolean group, maliasskindesc_t *skindesc); +void glsl_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr); +void glsl_Mod_LoadExternalSkins (model_t * mod); + +void sw_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, + int _s, int extra); +void *sw_Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, + qboolean group, maliasskindesc_t *skindesc); +void sw_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr); +void sw_Mod_LoadExternalSkins (model_t * mod); + +void gl_Mod_LoadExternalTextures (model_t *mod); +void gl_Mod_LoadLighting (bsp_t *bsp); +void gl_Mod_SubdivideSurface (msurface_t *fa); +void gl_Mod_ProcessTexture(texture_t *tx); + +void glsl_Mod_LoadExternalTextures (model_t *mod); +void glsl_Mod_LoadLighting (bsp_t *bsp); +void glsl_Mod_SubdivideSurface (msurface_t *fa); +void glsl_Mod_ProcessTexture(texture_t *tx); + +void sw_Mod_LoadExternalTextures (model_t *mod); +void sw_Mod_LoadLighting (bsp_t *bsp); +void sw_Mod_SubdivideSurface (msurface_t *fa); +void sw_Mod_ProcessTexture(texture_t *tx); + void Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator); void Mod_LoadSpriteModel (model_t *mod, void *buffer); diff --git a/libs/models/alias/gl_mesh.c b/libs/models/alias/gl_mesh.c index 3267c5726..0ccc0b02b 100644 --- a/libs/models/alias/gl_mesh.c +++ b/libs/models/alias/gl_mesh.c @@ -52,29 +52,29 @@ static __attribute__ ((used)) const char rcsid[] = // ALIAS MODEL DISPLAY LIST GENERATION ======================================== -model_t *aliasmodel; -aliashdr_t *paliashdr; +static model_t *aliasmodel; +static aliashdr_t *paliashdr; -qboolean *used; -int used_size; +static qboolean *used; +static int used_size; // the command list holds counts and s/t values that are valid for every frame -int *commands; -int numcommands; -int commands_size; +static int *commands; +static int numcommands; +static int commands_size; // all frames will have their vertexes rearranged and expanded // so they are in the order expected by the command list -int *vertexorder; -int numorder; -int vertexorder_size; +static int *vertexorder; +static int numorder; +static int vertexorder_size; -int allverts, alltris; +static int allverts, alltris; -int *stripverts; -int *striptris; -int stripcount; -int strip_size; +static int *stripverts; +static int *striptris; +static int stripcount; +static int strip_size; static inline void @@ -336,7 +336,8 @@ BuildTris (void) } void -Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s, int extra) +gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, + int _s, int extra) { dstring_t *cache, *fullpath; unsigned char model_digest[MDFOUR_DIGEST_BYTES]; diff --git a/libs/models/alias/gl_model_alias.c b/libs/models/alias/gl_model_alias.c index 0e36ae289..5caaca02a 100644 --- a/libs/models/alias/gl_model_alias.c +++ b/libs/models/alias/gl_model_alias.c @@ -53,11 +53,9 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "compat.h" -int alias_cache = 1; - void * -Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, - maliasskindesc_t *skindesc) +gl_Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, + maliasskindesc_t *skindesc) { byte *pskin; char name[32], modname[MAX_QPATH + 4]; @@ -105,7 +103,7 @@ Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group, } void -Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) +gl_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) { if (strequal (m->name, "progs/eyes.mdl")) { hdr->mdl.scale_origin[2] -= (22 + 8); @@ -153,7 +151,7 @@ Mod_LoadExternalSkin (maliasskindesc_t *pskindesc, char *filename) } void -Mod_LoadExternalSkins (model_t *mod) +gl_Mod_LoadExternalSkins (model_t *mod) { char filename[MAX_QPATH + 4], modname[MAX_QPATH + 4]; int i, j; diff --git a/libs/models/alias/glsl_model_alias.c b/libs/models/alias/glsl_model_alias.c index f71d1b2eb..bccb3908e 100644 --- a/libs/models/alias/glsl_model_alias.c +++ b/libs/models/alias/glsl_model_alias.c @@ -52,8 +52,6 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "mod_internal.h" #include "r_shared.h" -int alias_cache = 0; - static vec3_t vertex_normals[NUMVERTEXNORMALS] = { #include "anorms.h" }; @@ -95,8 +93,8 @@ glsl_alias_clear (model_t *m) } void * -Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, qboolean group, - maliasskindesc_t *skindesc) +glsl_Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, + qboolean group, maliasskindesc_t *skindesc) { byte *tskin; const char *name; @@ -117,7 +115,7 @@ Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, qboolean group, } void -Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) +glsl_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) { if (hdr->mdl.ident == HEADER_MDL16) VectorScale (hdr->mdl.scale, 1/256.0, hdr->mdl.scale); @@ -125,13 +123,13 @@ Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) } void -Mod_LoadExternalSkins (model_t *mod) +glsl_Mod_LoadExternalSkins (model_t *mod) { } void -Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s, - int extra) +glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, + int _s, int extra) { mtriangle_t *tris; stvert_t *st; diff --git a/libs/models/alias/model_alias.c b/libs/models/alias/model_alias.c index ccc073a1f..11e272ab6 100644 --- a/libs/models/alias/model_alias.c +++ b/libs/models/alias/model_alias.c @@ -52,7 +52,6 @@ static __attribute__ ((used)) const char rcsid[] = #include "mod_internal.h" #include "r_local.h" -extern int alias_cache; //FIXME extern aliashdr_t *pheader; stvert_t *stverts; @@ -91,8 +90,8 @@ Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex) pskindesc[snum].type = pskintype->type; if (pskintype->type == ALIAS_SKIN_SINGLE) { skin = (byte *) (pskintype + 1); - skin = Mod_LoadSkin (skin, skinsize, snum, 0, false, - &pskindesc[snum]); + skin = m_funcs->Mod_LoadSkin (skin, skinsize, snum, 0, false, + &pskindesc[snum]); } else { pskintype++; pinskingroup = (daliasskingroup_t *) pskintype; @@ -123,8 +122,8 @@ Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int *pskinindex) for (gnum = 0; gnum < groupskins; gnum++) { paliasskingroup->skindescs[gnum].type = ALIAS_SKIN_SINGLE; - skin = Mod_LoadSkin (skin, skinsize, snum, gnum, true, - &paliasskingroup->skindescs[gnum]); + skin = mod_funcs->Mod_LoadSkin (skin, skinsize, snum, gnum, + true, &paliasskingroup->skindescs[gnum]); } } pskintype = (daliasskintype_t *) skin; @@ -371,14 +370,15 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator) mod->radius = RadiusFromBounds (mod->mins, mod->maxs); // build the draw lists - Mod_MakeAliasModelDisplayLists (mod, pheader, buffer, qfs_filesize, extra); + m_funcs->Mod_MakeAliasModelDisplayLists (mod, pheader, buffer, + qfs_filesize, extra); - Mod_FinalizeAliasModel (mod, pheader); + m_funcs->Mod_FinalizeAliasModel (mod, pheader); - Mod_LoadExternalSkins (mod); + m_funcs->Mod_LoadExternalSkins (mod); // move the complete, relocatable alias model to the cache - if (alias_cache) { + if (m_funcs->alias_cache) { end = Hunk_LowMark (); total = end - start; diff --git a/libs/models/alias/sw_model_alias.c b/libs/models/alias/sw_model_alias.c index 0b7b194a6..c52886adb 100644 --- a/libs/models/alias/sw_model_alias.c +++ b/libs/models/alias/sw_model_alias.c @@ -47,15 +47,13 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$"; #include "d_iface.h" #include "mod_internal.h" -int alias_cache = 1; - // a pose is a single set of vertexes. a frame may be // an animating sequence of poses void * -Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, - qboolean group, maliasskindesc_t *skindesc) +sw_Mod_LoadSkin (byte *skin, int skinsize, int snum, int gnum, + qboolean group, maliasskindesc_t *skindesc) { byte *pskin; @@ -87,8 +85,8 @@ process_frame (maliasframedesc_t *frame, int posenum, int extra) } void -Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s, - int extra) +sw_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, + int _s, int extra) { int i, j; int posenum = 0; @@ -130,11 +128,11 @@ Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m, int _s, } void -Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) +sw_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr) { } void -Mod_LoadExternalSkins (model_t *mod) +sw_Mod_LoadExternalSkins (model_t *mod) { } diff --git a/libs/models/brush/gl_model_brush.c b/libs/models/brush/gl_model_brush.c index ee5f0830d..cd55b2107 100644 --- a/libs/models/brush/gl_model_brush.c +++ b/libs/models/brush/gl_model_brush.c @@ -56,7 +56,7 @@ static __attribute__ ((used)) const char rcsid[] = void -Mod_ProcessTexture (texture_t *tx) +gl_Mod_ProcessTexture (texture_t *tx) { char name[32]; @@ -97,7 +97,7 @@ Mod_LoadAnExternalTexture (char * tname, char *mname) } void -Mod_LoadExternalTextures (model_t *mod) +gl_Mod_LoadExternalTextures (model_t *mod) { int i; tex_t *base, *luma; @@ -137,7 +137,7 @@ Mod_LoadExternalTextures (model_t *mod) } void -Mod_LoadLighting (bsp_t *bsp) +gl_Mod_LoadLighting (bsp_t *bsp) { byte d; byte *in, *out, *data; @@ -297,7 +297,7 @@ SubdividePolygon (int numverts, float *verts) can be done reasonably. */ void -Mod_SubdivideSurface (msurface_t *fa) +gl_Mod_SubdivideSurface (msurface_t *fa) { float *vec; int lindex, numverts, i; diff --git a/libs/models/brush/glsl_model_brush.c b/libs/models/brush/glsl_model_brush.c index 2d04a5a1f..7da84f74b 100644 --- a/libs/models/brush/glsl_model_brush.c +++ b/libs/models/brush/glsl_model_brush.c @@ -80,7 +80,7 @@ glsl_brush_clear (model_t *m) } void -Mod_ProcessTexture (texture_t *tx) +glsl_Mod_ProcessTexture (texture_t *tx) { if (!strncmp (tx->name, "sky", 3)) { // sky textures need to be loaded as two separate textures to allow @@ -109,12 +109,12 @@ Mod_ProcessTexture (texture_t *tx) } void -Mod_LoadExternalTextures (model_t *mod) +glsl_Mod_LoadExternalTextures (model_t *mod) { } void -Mod_LoadLighting (bsp_t *bsp) +glsl_Mod_LoadLighting (bsp_t *bsp) { // a big hacky, but it's as good a place as any loadmodel->clear = glsl_brush_clear; @@ -128,6 +128,6 @@ Mod_LoadLighting (bsp_t *bsp) } void -Mod_SubdivideSurface (msurface_t *fa) +glsl_Mod_SubdivideSurface (msurface_t *fa) { } diff --git a/libs/models/brush/sw_model_brush.c b/libs/models/brush/sw_model_brush.c index 15705340b..548010058 100644 --- a/libs/models/brush/sw_model_brush.c +++ b/libs/models/brush/sw_model_brush.c @@ -45,22 +45,22 @@ static __attribute__ ((used)) const char rcsid[] = void -Mod_SubdivideSurface (msurface_t *fa) +sw_Mod_SubdivideSurface (msurface_t *fa) { } void -Mod_ProcessTexture (texture_t *tx) +sw_Mod_ProcessTexture (texture_t *tx) { } void -Mod_LoadExternalTextures (model_t *mod) +sw_Mod_LoadExternalTextures (model_t *mod) { } void -Mod_LoadLighting (bsp_t *bsp) +sw_Mod_LoadLighting (bsp_t *bsp) { mod_lightmap_bytes = 1; if (!bsp->lightdatasize) { diff --git a/libs/video/renderer/vid_render_gl.c b/libs/video/renderer/vid_render_gl.c index 1c1f80d27..2db744a7a 100644 --- a/libs/video/renderer/vid_render_gl.c +++ b/libs/video/renderer/vid_render_gl.c @@ -40,13 +40,20 @@ #include "gl/namehack.h" static vid_model_funcs_t model_funcs = { - Mod_LoadExternalTextures, - Mod_LoadLighting, - Mod_SubdivideSurface, - Mod_ProcessTexture, + gl_Mod_LoadExternalTextures, + gl_Mod_LoadLighting, + gl_Mod_SubdivideSurface, + gl_Mod_ProcessTexture, + Mod_LoadAliasModel, Mod_LoadSpriteModel, + gl_Mod_MakeAliasModelDisplayLists, + gl_Mod_LoadSkin, + gl_Mod_FinalizeAliasModel, + gl_Mod_LoadExternalSkins, + 1, + Skin_SetColormap, Skin_SetSkin, gl_Skin_SetupSkin, diff --git a/libs/video/renderer/vid_render_glsl.c b/libs/video/renderer/vid_render_glsl.c index ac8081143..614e4813f 100644 --- a/libs/video/renderer/vid_render_glsl.c +++ b/libs/video/renderer/vid_render_glsl.c @@ -40,13 +40,20 @@ #include "glsl/namehack.h" static vid_model_funcs_t model_funcs = { - Mod_LoadExternalTextures, - Mod_LoadLighting, - Mod_SubdivideSurface, - Mod_ProcessTexture, + glsl_Mod_LoadExternalTextures, + glsl_Mod_LoadLighting, + glsl_Mod_SubdivideSurface, + glsl_Mod_ProcessTexture, + Mod_LoadAliasModel, Mod_LoadSpriteModel, + glsl_Mod_MakeAliasModelDisplayLists, + glsl_Mod_LoadSkin, + glsl_Mod_FinalizeAliasModel, + glsl_Mod_LoadExternalSkins, + 0, + Skin_SetColormap, Skin_SetSkin, glsl_Skin_SetupSkin, diff --git a/libs/video/renderer/vid_render_sw.c b/libs/video/renderer/vid_render_sw.c index d2d75f192..ea897dea3 100644 --- a/libs/video/renderer/vid_render_sw.c +++ b/libs/video/renderer/vid_render_sw.c @@ -35,13 +35,20 @@ #include "r_internal.h" static vid_model_funcs_t model_funcs = { - Mod_LoadExternalTextures, - Mod_LoadLighting, - Mod_SubdivideSurface, - Mod_ProcessTexture, + sw_Mod_LoadExternalTextures, + sw_Mod_LoadLighting, + sw_Mod_SubdivideSurface, + sw_Mod_ProcessTexture, + Mod_LoadAliasModel, Mod_LoadSpriteModel, + sw_Mod_MakeAliasModelDisplayLists, + sw_Mod_LoadSkin, + sw_Mod_FinalizeAliasModel, + sw_Mod_LoadExternalSkins, + 1, + Skin_SetColormap, Skin_SetSkin, sw_Skin_SetupSkin, diff --git a/libs/video/renderer/vid_render_sw32.c b/libs/video/renderer/vid_render_sw32.c index 2ba7db6e6..d41f93765 100644 --- a/libs/video/renderer/vid_render_sw32.c +++ b/libs/video/renderer/vid_render_sw32.c @@ -40,13 +40,20 @@ #include "sw32/namehack.h" static vid_model_funcs_t model_funcs = { - Mod_LoadExternalTextures, - Mod_LoadLighting, - Mod_SubdivideSurface, - Mod_ProcessTexture, + sw_Mod_LoadExternalTextures, + sw_Mod_LoadLighting, + sw_Mod_SubdivideSurface, + sw_Mod_ProcessTexture, + Mod_LoadAliasModel, Mod_LoadSpriteModel, + sw_Mod_MakeAliasModelDisplayLists, + sw_Mod_LoadSkin, + sw_Mod_FinalizeAliasModel, + sw_Mod_LoadExternalSkins, + 1, + Skin_SetColormap, Skin_SetSkin, sw_Skin_SetupSkin,