2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2002-08-25 14:25:38 +00:00
|
|
|
gl_model_alias.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-25 14:25:38 +00:00
|
|
|
alias model loading and caching for gl
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
// models are the only shared resource between a client and server running
|
|
|
|
// on the same machine.
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2005-08-04 15:27:09 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] =
|
2003-01-15 15:31:36 +00:00
|
|
|
"$Id$";
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2003-09-04 18:46:59 +00:00
|
|
|
#include "QF/image.h"
|
2001-04-10 06:55:28 +00:00
|
|
|
#include "QF/model.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/qendian.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
2001-05-09 18:28:08 +00:00
|
|
|
#include "QF/skin.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
#include "QF/sys.h"
|
2003-03-20 19:58:18 +00:00
|
|
|
#include "QF/va.h"
|
2001-10-28 04:23:37 +00:00
|
|
|
#include "QF/vid.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_textures.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
|
2002-03-03 06:03:51 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2007-03-10 12:00:59 +00:00
|
|
|
VISIBLE byte player_8bit_texels[640 * 400];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-21 19:13:53 +00:00
|
|
|
void *
|
2001-11-21 08:14:05 +00:00
|
|
|
Mod_LoadSkin (byte * skin, int skinsize, int snum, int gnum, qboolean group,
|
|
|
|
maliasskindesc_t *skindesc)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-22 20:06:30 +00:00
|
|
|
byte *pskin;
|
2003-12-28 05:25:06 +00:00
|
|
|
char name[32], modname[MAX_QPATH + 4];
|
2002-08-22 20:06:30 +00:00
|
|
|
int fb_texnum = 0, texnum = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-21 08:14:05 +00:00
|
|
|
pskin = Hunk_AllocName (skinsize, loadname);
|
|
|
|
skindesc->skin = (byte *) pskin - (byte *) pheader;
|
|
|
|
|
|
|
|
memcpy (pskin, skin, skinsize);
|
|
|
|
|
|
|
|
Mod_FloodFillSkin (pskin, pheader->mdl.skinwidth, pheader->mdl.skinheight);
|
2001-02-19 21:15:25 +00:00
|
|
|
// save 8 bit texels for the player model to remap
|
2001-11-21 08:14:05 +00:00
|
|
|
if (strequal (loadmodel->name, "progs/player.mdl")) {
|
2003-04-17 00:01:48 +00:00
|
|
|
if (skinsize > (int) sizeof (player_8bit_texels))
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("Player skin too large");
|
2001-11-21 08:14:05 +00:00
|
|
|
memcpy (player_8bit_texels, pskin, skinsize);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2003-12-28 05:25:06 +00:00
|
|
|
QFS_StripExtension (loadmodel->name, modname);
|
|
|
|
|
2001-11-21 08:14:05 +00:00
|
|
|
if (!loadmodel->fullbright) {
|
|
|
|
if (group) {
|
2003-12-28 05:25:06 +00:00
|
|
|
snprintf (name, sizeof (name), "fb_%s_%i_%i", modname,
|
2001-11-21 08:14:05 +00:00
|
|
|
snum, gnum);
|
|
|
|
} else {
|
2003-12-28 05:25:06 +00:00
|
|
|
snprintf (name, sizeof (name), "fb_%s_%i", modname, snum);
|
2001-11-21 08:14:05 +00:00
|
|
|
}
|
|
|
|
fb_texnum = Mod_Fullbright (pskin, pheader->mdl.skinwidth,
|
|
|
|
pheader->mdl.skinheight, name);
|
2011-09-26 01:50:45 +00:00
|
|
|
Sys_MaskPrintf (SYS_GLT, "%s %d\n", name, fb_texnum);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
if (group) {
|
2003-12-28 05:25:06 +00:00
|
|
|
snprintf (name, sizeof (name), "%s_%i_%i", modname, snum,
|
2002-08-19 06:00:31 +00:00
|
|
|
gnum);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2003-12-28 05:25:06 +00:00
|
|
|
snprintf (name, sizeof (name), "%s_%i", modname, snum);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-11-21 08:14:05 +00:00
|
|
|
texnum = GL_LoadTexture (name, pheader->mdl.skinwidth,
|
|
|
|
pheader->mdl.skinheight, pskin, true, false, 1);
|
2011-09-26 01:50:45 +00:00
|
|
|
Sys_MaskPrintf (SYS_GLT, "%s %d\n", name, texnum);
|
2001-11-21 08:14:05 +00:00
|
|
|
skindesc->texnum = texnum;
|
|
|
|
skindesc->fb_texnum = fb_texnum;
|
|
|
|
loadmodel->hasfullbrights = fb_texnum;
|
2001-02-19 21:15:25 +00:00
|
|
|
// alpha param was true for non group skins
|
|
|
|
return skin + skinsize;
|
|
|
|
}
|
|
|
|
|
2001-11-20 08:02:35 +00:00
|
|
|
void
|
|
|
|
Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr)
|
|
|
|
{
|
|
|
|
if (strequal (m->name, "progs/eyes.mdl")) {
|
|
|
|
hdr->mdl.scale_origin[2] -= (22 + 8);
|
|
|
|
VectorScale (hdr->mdl.scale, 2, hdr->mdl.scale);
|
|
|
|
}
|
|
|
|
}
|
2002-01-16 20:32:39 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-01-16 20:32:39 +00:00
|
|
|
Mod_LoadExternalSkin (maliasskindesc_t *pskindesc, char *filename)
|
|
|
|
{
|
2003-12-28 05:25:06 +00:00
|
|
|
tex_t *tex, *glow;
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
ptr = strrchr (filename, '/');
|
|
|
|
if (!ptr)
|
|
|
|
ptr = filename;
|
2002-01-16 20:32:39 +00:00
|
|
|
|
2003-12-28 05:25:06 +00:00
|
|
|
tex = LoadImage (filename);
|
2003-09-04 18:46:59 +00:00
|
|
|
if (!tex)
|
2004-01-08 03:33:45 +00:00
|
|
|
tex = LoadImage (va ("textures/%s", ptr + 1));
|
2003-09-04 18:46:59 +00:00
|
|
|
if (tex) {
|
2003-12-28 05:25:06 +00:00
|
|
|
pskindesc->texnum = GL_LoadTexture (filename, tex->width, tex->height,
|
|
|
|
tex->data, true, false,
|
|
|
|
tex->format > 2 ? tex->format : 1);
|
|
|
|
|
|
|
|
pskindesc->fb_texnum = 0;
|
|
|
|
|
2004-01-04 01:20:20 +00:00
|
|
|
glow = LoadImage (va ("%s_luma", filename));
|
|
|
|
if (!glow)
|
|
|
|
glow = LoadImage (va ("%s_glow", filename));
|
|
|
|
if (!glow)
|
2004-01-08 03:33:45 +00:00
|
|
|
glow = LoadImage (va ("textures/%s_luma", ptr + 1));
|
2003-12-28 05:25:06 +00:00
|
|
|
if (!glow)
|
2004-01-08 03:33:45 +00:00
|
|
|
glow = LoadImage (va ("textures/%s_glow", ptr + 1));
|
2003-12-28 05:25:06 +00:00
|
|
|
if (glow)
|
2004-01-04 01:20:20 +00:00
|
|
|
pskindesc->fb_texnum =
|
|
|
|
GL_LoadTexture (va ("fb_%s", filename), glow->width,
|
|
|
|
glow->height, glow->data, true, true,
|
|
|
|
glow->format > 2 ? glow->format : 1);
|
2003-12-28 05:25:06 +00:00
|
|
|
else if (tex->format < 3)
|
|
|
|
pskindesc->fb_texnum = Mod_Fullbright (tex->data, tex->width,
|
|
|
|
tex->height,
|
|
|
|
va ("fb_%s", filename));
|
2002-01-16 20:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Mod_LoadExternalSkins (model_t *mod)
|
|
|
|
{
|
2003-12-28 05:25:06 +00:00
|
|
|
char filename[MAX_QPATH + 4], modname[MAX_QPATH + 4];
|
2002-08-22 20:06:30 +00:00
|
|
|
int i, j;
|
|
|
|
maliasskindesc_t *pskindesc;
|
2002-01-16 20:32:39 +00:00
|
|
|
maliasskingroup_t *pskingroup;
|
|
|
|
|
2003-12-28 05:25:06 +00:00
|
|
|
QFS_StripExtension (mod->name, modname);
|
|
|
|
|
2002-01-17 02:10:06 +00:00
|
|
|
for (i = 0; i < pheader->mdl.numskins; i++) {
|
2002-01-16 20:32:39 +00:00
|
|
|
pskindesc = ((maliasskindesc_t *)
|
2002-08-22 20:06:30 +00:00
|
|
|
((byte *) pheader + pheader->skindesc)) + i;
|
2002-01-16 20:32:39 +00:00
|
|
|
if (pskindesc->type == ALIAS_SKIN_SINGLE) {
|
2003-12-28 05:25:06 +00:00
|
|
|
snprintf (filename, sizeof (filename), "%s_%i", modname, i);
|
2002-01-16 20:32:39 +00:00
|
|
|
Mod_LoadExternalSkin (pskindesc, filename);
|
|
|
|
} else {
|
|
|
|
pskingroup = (maliasskingroup_t *)
|
2002-01-17 02:10:06 +00:00
|
|
|
((byte *) pheader + pskindesc->skin);
|
2003-12-28 05:25:06 +00:00
|
|
|
|
2002-01-16 20:32:39 +00:00
|
|
|
for (j = 0; j < pskingroup->numskins; j++) {
|
2003-09-04 18:46:59 +00:00
|
|
|
snprintf (filename, sizeof (filename), "%s_%i_%i",
|
2003-12-28 05:25:06 +00:00
|
|
|
modname, i, j);
|
2002-01-16 20:32:39 +00:00
|
|
|
Mod_LoadExternalSkin (pskingroup->skindescs + j, filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|