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
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2018-08-19 15:05:00 +00:00
|
|
|
#include "QF/dstring.h"
|
2003-09-04 18:46:59 +00:00
|
|
|
#include "QF/image.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
|
|
|
|
2012-02-14 12:25:19 +00:00
|
|
|
#include "mod_internal.h"
|
|
|
|
|
2002-03-03 06:03:51 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2022-04-04 08:47:21 +00:00
|
|
|
static void
|
|
|
|
gl_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *texels,
|
|
|
|
int snum, int gnum, maliasskindesc_t *skindesc)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
aliashdr_t *header = alias_ctx->header;
|
2018-08-19 15:05:00 +00:00
|
|
|
char modname[MAX_QPATH + 4];
|
2002-08-22 20:06:30 +00:00
|
|
|
int fb_texnum = 0, texnum = 0;
|
2018-08-19 15:05:00 +00:00
|
|
|
dstring_t *name = dstring_new ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-04-04 08:47:21 +00:00
|
|
|
Mod_FloodFillSkin (texels, header->mdl.skinwidth, header->mdl.skinheight);
|
2001-02-19 21:15:25 +00:00
|
|
|
// save 8 bit texels for the player model to remap
|
2012-01-26 03:50:37 +00:00
|
|
|
// FIXME remove model restriction
|
2021-02-01 12:11:45 +00:00
|
|
|
if (strequal (alias_ctx->mod->path, "progs/player.mdl"))
|
|
|
|
gl_Skin_SetPlayerSkin (header->mdl.skinwidth, header->mdl.skinheight,
|
2022-04-04 08:47:21 +00:00
|
|
|
texels);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
QFS_StripExtension (alias_ctx->mod->path, modname);
|
2003-12-28 05:25:06 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
if (!alias_ctx->mod->fullbright) {
|
2022-04-04 08:47:21 +00:00
|
|
|
if (gnum != -1) {
|
2018-08-19 15:05:00 +00:00
|
|
|
dsprintf (name, "fb_%s_%i_%i", modname, snum, gnum);
|
2001-11-21 08:14:05 +00:00
|
|
|
} else {
|
2018-08-19 15:05:00 +00:00
|
|
|
dsprintf (name, "fb_%s_%i", modname, snum);
|
2001-11-21 08:14:05 +00:00
|
|
|
}
|
2022-04-04 08:47:21 +00:00
|
|
|
fb_texnum = Mod_Fullbright (texels, header->mdl.skinwidth,
|
2021-02-01 12:11:45 +00:00
|
|
|
header->mdl.skinheight, name->str);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_glt, "%s %d\n", name->str, fb_texnum);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2022-04-04 08:47:21 +00:00
|
|
|
if (gnum != -1) {
|
2018-08-19 15:05:00 +00:00
|
|
|
dsprintf (name, "%s_%i_%i", modname, snum, gnum);
|
2001-02-19 21:15:25 +00:00
|
|
|
} else {
|
2018-08-19 15:05:00 +00:00
|
|
|
dsprintf (name, "%s_%i", modname, snum);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2021-02-01 12:11:45 +00:00
|
|
|
texnum = GL_LoadTexture (name->str, header->mdl.skinwidth,
|
2022-04-04 08:47:21 +00:00
|
|
|
header->mdl.skinheight, texels, true, false, 1);
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_glt, "%s %d\n", name->str, texnum);
|
2001-11-21 08:14:05 +00:00
|
|
|
skindesc->texnum = texnum;
|
|
|
|
skindesc->fb_texnum = fb_texnum;
|
2021-02-01 12:11:45 +00:00
|
|
|
alias_ctx->mod->hasfullbrights = fb_texnum;
|
2018-08-19 15:05:00 +00:00
|
|
|
dstring_delete (name);
|
2001-02-19 21:15:25 +00:00
|
|
|
// alpha param was true for non group skins
|
|
|
|
}
|
|
|
|
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
void
|
|
|
|
gl_Mod_LoadAllSkins (mod_alias_ctx_t *alias_ctx)
|
|
|
|
{
|
|
|
|
aliashdr_t *header = alias_ctx->header;
|
|
|
|
int skinsize = header->mdl.skinwidth * header->mdl.skinheight;
|
2022-04-04 08:47:21 +00:00
|
|
|
int num_skins = alias_ctx->skins.size;
|
|
|
|
byte *texel_block = Hunk_AllocName (0, skinsize * num_skins,
|
|
|
|
alias_ctx->mod->name);
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
|
2022-04-04 08:47:21 +00:00
|
|
|
for (int i = 0; i < num_skins; i++) {
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
__auto_type skin = alias_ctx->skins.a + i;
|
2022-04-04 08:47:21 +00:00
|
|
|
byte *texels = texel_block + i * skinsize;
|
|
|
|
|
|
|
|
skin->skindesc->skin = texels - (byte *) header;
|
|
|
|
memcpy (texels, skin->texels, skinsize);
|
|
|
|
gl_Mod_LoadSkin (alias_ctx, texels, skin->skin_num, skin->group_num,
|
|
|
|
skin->skindesc);
|
[model] Make alias skin loading a batch operation
Really, this won't make all that much difference because alias models
with more than one skin are quite rare, and those with animated skin
groups are even rarer. However, for those models that do have more than
one skin, it will allow for reduced allocation overheads, and when
supported (glsl, vulkan, maybe gl), loading all the skins into an array
texture (since all skins are the same size, though external skins may
vary), but that's not implemented yet, this just wraps the old one skin
at a time code.
2022-04-04 06:38:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-20 08:02:35 +00:00
|
|
|
void
|
2021-02-01 12:11:45 +00:00
|
|
|
gl_Mod_FinalizeAliasModel (mod_alias_ctx_t *alias_ctx)
|
2001-11-20 08:02:35 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
aliashdr_t *header = alias_ctx->header;
|
|
|
|
|
|
|
|
if (strequal (alias_ctx->mod->path, "progs/eyes.mdl")) {
|
|
|
|
header->mdl.scale_origin[2] -= (22 + 8);
|
|
|
|
VectorScale (header->mdl.scale, 2, header->mdl.scale);
|
2001-11-20 08:02:35 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2021-01-19 01:15:57 +00:00
|
|
|
tex = LoadImage (filename, 1);
|
2003-09-04 18:46:59 +00:00
|
|
|
if (!tex)
|
2021-01-31 07:01:20 +00:00
|
|
|
tex = LoadImage (va (0, "textures/%s", ptr + 1), 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;
|
|
|
|
|
2021-01-31 07:01:20 +00:00
|
|
|
glow = LoadImage (va (0, "%s_luma", filename), 1);
|
2004-01-04 01:20:20 +00:00
|
|
|
if (!glow)
|
2021-01-31 07:01:20 +00:00
|
|
|
glow = LoadImage (va (0, "%s_glow", filename), 1);
|
2004-01-04 01:20:20 +00:00
|
|
|
if (!glow)
|
2021-01-31 07:01:20 +00:00
|
|
|
glow = LoadImage (va (0, "textures/%s_luma", ptr + 1), 1);
|
2003-12-28 05:25:06 +00:00
|
|
|
if (!glow)
|
2021-01-31 07:01:20 +00:00
|
|
|
glow = LoadImage (va (0, "textures/%s_glow", ptr + 1), 1);
|
2003-12-28 05:25:06 +00:00
|
|
|
if (glow)
|
2004-01-04 01:20:20 +00:00
|
|
|
pskindesc->fb_texnum =
|
2021-01-31 07:01:20 +00:00
|
|
|
GL_LoadTexture (va (0, "fb_%s", filename), glow->width,
|
2004-01-04 01:20:20 +00:00
|
|
|
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,
|
2021-01-31 07:01:20 +00:00
|
|
|
va (0, "fb_%s", filename));
|
2002-01-16 20:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-02-01 12:11:45 +00:00
|
|
|
gl_Mod_LoadExternalSkins (mod_alias_ctx_t *alias_ctx)
|
2002-01-16 20:32:39 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
aliashdr_t *header = alias_ctx->header;
|
2018-08-19 15:05:00 +00:00
|
|
|
char 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;
|
2018-08-19 15:05:00 +00:00
|
|
|
dstring_t *filename = dstring_new ();
|
2002-01-16 20:32:39 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
QFS_StripExtension (alias_ctx->mod->path, modname);
|
2003-12-28 05:25:06 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
for (i = 0; i < header->mdl.numskins; i++) {
|
2002-01-16 20:32:39 +00:00
|
|
|
pskindesc = ((maliasskindesc_t *)
|
2021-02-01 12:11:45 +00:00
|
|
|
((byte *) header + header->skindesc)) + i;
|
2002-01-16 20:32:39 +00:00
|
|
|
if (pskindesc->type == ALIAS_SKIN_SINGLE) {
|
2018-08-19 15:05:00 +00:00
|
|
|
dsprintf (filename, "%s_%i", modname, i);
|
|
|
|
Mod_LoadExternalSkin (pskindesc, filename->str);
|
2002-01-16 20:32:39 +00:00
|
|
|
} else {
|
|
|
|
pskingroup = (maliasskingroup_t *)
|
2021-02-01 12:11:45 +00:00
|
|
|
((byte *) header + 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++) {
|
2018-08-19 15:05:00 +00:00
|
|
|
dsprintf (filename, "%s_%i_%i", modname, i, j);
|
|
|
|
Mod_LoadExternalSkin (pskingroup->skindescs + j, filename->str);
|
2002-01-16 20:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|