better external skin handling from Grievre

This commit is contained in:
Bill Currie 2003-12-28 05:25:06 +00:00
parent 9dbb8335f6
commit 40b8974c33
6 changed files with 64 additions and 31 deletions

View file

@ -132,7 +132,7 @@ Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc) maliasskindesc_t *skindesc)
{ {
byte *pskin; byte *pskin;
char name[32]; char name[32], modname[MAX_QPATH + 4];
int fb_texnum = 0, texnum = 0; int fb_texnum = 0, texnum = 0;
pskin = Hunk_AllocName (skinsize, loadname); pskin = Hunk_AllocName (skinsize, loadname);
@ -148,21 +148,23 @@ Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group,
memcpy (player_8bit_texels, pskin, skinsize); memcpy (player_8bit_texels, pskin, skinsize);
} }
QFS_StripExtension (loadmodel->name, modname);
if (!loadmodel->fullbright) { if (!loadmodel->fullbright) {
if (group) { if (group) {
snprintf (name, sizeof (name), "fb_%s_%i_%i", loadmodel->name, snprintf (name, sizeof (name), "fb_%s_%i_%i", modname,
snum, gnum); snum, gnum);
} else { } else {
snprintf (name, sizeof (name), "fb_%s_%i", loadmodel->name, snum); snprintf (name, sizeof (name), "fb_%s_%i", modname, snum);
} }
fb_texnum = Mod_Fullbright (pskin, pheader->mdl.skinwidth, fb_texnum = Mod_Fullbright (pskin, pheader->mdl.skinwidth,
pheader->mdl.skinheight, name); pheader->mdl.skinheight, name);
} }
if (group) { if (group) {
snprintf (name, sizeof (name), "%s_%i_%i", loadmodel->name, snum, snprintf (name, sizeof (name), "%s_%i_%i", modname, snum,
gnum); gnum);
} else { } else {
snprintf (name, sizeof (name), "%s_%i", loadmodel->name, snum); snprintf (name, sizeof (name), "%s_%i", modname, snum);
} }
texnum = GL_LoadTexture (name, pheader->mdl.skinwidth, texnum = GL_LoadTexture (name, pheader->mdl.skinwidth,
pheader->mdl.skinheight, pskin, true, false, 1); pheader->mdl.skinheight, pskin, true, false, 1);
@ -267,41 +269,61 @@ Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr)
static void static void
Mod_LoadExternalSkin (maliasskindesc_t *pskindesc, char *filename) Mod_LoadExternalSkin (maliasskindesc_t *pskindesc, char *filename)
{ {
tex_t *tex; tex_t *tex, *glow;
char *ptr;
tex = LoadImage (va ("progs/%s", filename)); ptr = strrchr (filename, '/');
if (!ptr)
ptr = filename;
tex = LoadImage (filename);
if (!tex) if (!tex)
tex = LoadImage (va ("textures/%s", filename)); tex = LoadImage (va ("textures/%s", ptr));
if (tex) { if (tex) {
if (tex->format < 4) pskindesc->texnum = GL_LoadTexture (filename, tex->width, tex->height,
pskindesc->texnum = GL_LoadTexture tex->data, true, false,
(filename, tex->width, tex->height, tex->data, true, false, 3); tex->format > 2 ? tex->format : 1);
else
pskindesc->texnum = GL_LoadTexture pskindesc->fb_texnum = 0;
(filename, tex->width, tex->height, tex->data, true, false, 4);
glow = LoadImage (va ("%s_glow", filename));
if (!glow)
glow = LoadImage (va ("textures/%s_glow", ptr));
if (glow)
pskindesc->fb_texnum = GL_LoadTexture (va ("fb_%s", filename),
glow->width, glow->height,
glow->data, true, true,
glow->format > 2 ? glow->format : 1);
else if (tex->format < 3)
pskindesc->fb_texnum = Mod_Fullbright (tex->data, tex->width,
tex->height,
va ("fb_%s", filename));
} }
} }
void void
Mod_LoadExternalSkins (model_t *mod) Mod_LoadExternalSkins (model_t *mod)
{ {
char filename[MAX_QPATH + 4]; char filename[MAX_QPATH + 4], modname[MAX_QPATH + 4];
int i, j; int i, j;
maliasskindesc_t *pskindesc; maliasskindesc_t *pskindesc;
maliasskingroup_t *pskingroup; maliasskingroup_t *pskingroup;
QFS_StripExtension (mod->name, modname);
for (i = 0; i < pheader->mdl.numskins; i++) { for (i = 0; i < pheader->mdl.numskins; i++) {
pskindesc = ((maliasskindesc_t *) pskindesc = ((maliasskindesc_t *)
((byte *) pheader + pheader->skindesc)) + i; ((byte *) pheader + pheader->skindesc)) + i;
if (pskindesc->type == ALIAS_SKIN_SINGLE) { if (pskindesc->type == ALIAS_SKIN_SINGLE) {
snprintf (filename, sizeof (filename), "%s_%i", mod->name, i); snprintf (filename, sizeof (filename), "%s_%i", modname, i);
Mod_LoadExternalSkin (pskindesc, filename); Mod_LoadExternalSkin (pskindesc, filename);
} else { } else {
pskingroup = (maliasskingroup_t *) pskingroup = (maliasskingroup_t *)
((byte *) pheader + pskindesc->skin); ((byte *) pheader + pskindesc->skin);
for (j = 0; j < pskingroup->numskins; j++) { for (j = 0; j < pskingroup->numskins; j++) {
snprintf (filename, sizeof (filename), "%s_%i_%i", snprintf (filename, sizeof (filename), "%s_%i_%i",
mod->name, i, j); modname, i, j);
Mod_LoadExternalSkin (pskingroup->skindescs + j, filename); Mod_LoadExternalSkin (pskingroup->skindescs + j, filename);
} }
} }

View file

@ -291,6 +291,8 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
Mod_FinalizeAliasModel (mod, pheader); Mod_FinalizeAliasModel (mod, pheader);
Mod_LoadExternalSkins (mod);
// move the complete, relocatable alias model to the cache // move the complete, relocatable alias model to the cache
end = Hunk_LowMark (); end = Hunk_LowMark ();
total = end - start; total = end - start;

View file

@ -111,7 +111,8 @@ Mod_LoadExternalTextures (model_t *mod)
if ((base = Mod_LoadAnExternalTexture (tx->name, mod->name))) { if ((base = Mod_LoadAnExternalTexture (tx->name, mod->name))) {
tx->gl_texturenum = tx->gl_texturenum =
GL_LoadTexture (tx->name, base->width, base->height, GL_LoadTexture (tx->name, base->width, base->height,
base->data, true, false, base->format); base->data, true, false,
base->format > 2 ? base->format : 1);
luma = Mod_LoadAnExternalTexture (va ("%s_luma", tx->name), luma = Mod_LoadAnExternalTexture (va ("%s_luma", tx->name),
mod->name); mod->name);
@ -120,14 +121,15 @@ Mod_LoadExternalTextures (model_t *mod)
mod->name); mod->name);
tx->gl_fb_texturenum = 0; tx->gl_fb_texturenum = 0;
if (luma) { if (luma) {
tx->gl_fb_texturenum = tx->gl_fb_texturenum =
GL_LoadTexture (va ("fb_%s", tx->name), luma->width, GL_LoadTexture (va ("fb_%s", tx->name), luma->width,
luma->height, luma->data, true, true, luma->height, luma->data, true, true,
luma->format); luma->format > 2 ? luma->format : 1);
} else if (base->format == 1) { } else if (base->format < 3) {
tx->gl_fb_texturenum = tx->gl_fb_texturenum =
Mod_Fullbright (luma->data, luma->width, luma->height, Mod_Fullbright (base->data, base->width, base->height,
va ("fb_%s", tx->name)); va ("fb_%s", tx->name));
} }
} }

View file

@ -200,7 +200,6 @@ Mod_RealLoadModel (model_t *mod, qboolean crash, cache_allocator_t allocator)
case IDPOLYHEADER: case IDPOLYHEADER:
case POLYHEADER16: case POLYHEADER16:
Mod_LoadAliasModel (mod, buf, allocator); Mod_LoadAliasModel (mod, buf, allocator);
Mod_LoadExternalSkins (mod);
break; break;
case IDSPRITEHEADER: case IDSPRITEHEADER:

View file

@ -1222,16 +1222,22 @@ QFS_SkipPath (const char *pathname)
void void
QFS_StripExtension (const char *in, char *out) QFS_StripExtension (const char *in, char *out)
{ {
while (*in && *in != '.') char *tmp;
*out++ = *in++;
*out = 0; strcpy (out, in);
if ((tmp = strrchr (out, '.')))
*tmp = 0;
} }
const char * const char *
QFS_FileExtension (const char *in) QFS_FileExtension (const char *in)
{ {
while (*in && *in != '.') char *tmp;
in++;
if ((tmp = strrchr (in, '.')))
return tmp;
return in; return in;
} }

View file

@ -127,7 +127,7 @@ R_LoadSkys (const char *skyname)
qfglBindTexture (GL_TEXTURE_2D, SKY_TEX + i); qfglBindTexture (GL_TEXTURE_2D, SKY_TEX + i);
targa = LoadImage (name = va ("env/%s%s", skyname, suf[i])); targa = LoadImage (name = va ("env/%s%s", skyname, suf[i]));
if (!targa) { if (!targa || targa->format < 3) { // FIXME Can't do PCX right now
Con_DPrintf ("Couldn't load %s\n", name); Con_DPrintf ("Couldn't load %s\n", name);
// also look in gfx/env, where Darkplaces looks for skies // also look in gfx/env, where Darkplaces looks for skies
targa = LoadImage (name = va ("gfx/env/%s%s", skyname, suf[i])); targa = LoadImage (name = va ("gfx/env/%s%s", skyname, suf[i]));
@ -138,9 +138,11 @@ R_LoadSkys (const char *skyname)
} }
} }
// FIXME need better texture loading
qfglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, targa->width, qfglTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, targa->width,
targa->height, 0, targa->format, GL_UNSIGNED_BYTE, targa->height, 0,
&targa->data); targa->format == 3 ? GL_RGB : GL_RGBA,
GL_UNSIGNED_BYTE, &targa->data);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);