2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-11-21 19:13:53 +00:00
|
|
|
sw_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 the software renderer
|
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
|
2001-08-25 02:47:11 +00:00
|
|
|
# include <string.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
2001-08-25 02:47:11 +00:00
|
|
|
# include <strings.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/qendian.h"
|
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-31 18:11:05 +00:00
|
|
|
#include "compat.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
#include "d_iface.h"
|
2012-02-14 12:25:19 +00:00
|
|
|
#include "mod_internal.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// a pose is a single set of vertexes. a frame may be
|
|
|
|
// an animating sequence of poses
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
|
[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
|
|
|
static void *
|
2021-02-01 12:11:45 +00:00
|
|
|
sw_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin,
|
|
|
|
int skinsize, int snum, int gnum,
|
2012-02-23 03:55:50 +00:00
|
|
|
qboolean group, maliasskindesc_t *skindesc)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2002-08-25 14:25:38 +00:00
|
|
|
byte *pskin;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
pskin = Hunk_AllocName (0, skinsize, alias_ctx->mod->name);
|
2021-02-01 12:11:45 +00:00
|
|
|
skindesc->skin = (byte *) pskin - (byte *) alias_ctx->header;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-21 19:13:53 +00:00
|
|
|
memcpy (pskin, skin, skinsize);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-21 19:13:53 +00:00
|
|
|
return skin + skinsize;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
[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
|
|
|
|
sw_Mod_LoadAllSkins (mod_alias_ctx_t *alias_ctx)
|
|
|
|
{
|
|
|
|
aliashdr_t *header = alias_ctx->header;
|
|
|
|
int skinsize = header->mdl.skinwidth * header->mdl.skinheight;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < alias_ctx->skins.size; i++) {
|
|
|
|
__auto_type skin = alias_ctx->skins.a + i;
|
|
|
|
sw_Mod_LoadSkin (alias_ctx, skin->texels, skinsize,
|
|
|
|
skin->skin_num, skin->group_num,
|
|
|
|
skin->group_num != -1, skin->skindesc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-25 01:31:35 +00:00
|
|
|
static void
|
2021-02-01 12:11:45 +00:00
|
|
|
process_frame (mod_alias_ctx_t *alias_ctx, maliasframedesc_t *frame,
|
|
|
|
int posenum, int extra)
|
2011-12-25 01:31:35 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
aliashdr_t *header = alias_ctx->header;
|
|
|
|
int size = header->mdl.numverts * sizeof (trivertx_t);
|
2011-12-25 01:31:35 +00:00
|
|
|
trivertx_t *frame_verts;
|
|
|
|
|
|
|
|
if (extra)
|
|
|
|
size *= 2;
|
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
frame_verts = Hunk_AllocName (0, size, alias_ctx->mod->name);
|
2021-02-01 12:11:45 +00:00
|
|
|
frame->frame = (byte *) frame_verts - (byte *) header;
|
2011-12-25 01:31:35 +00:00
|
|
|
|
2012-01-05 03:48:15 +00:00
|
|
|
// The low-order 8 bits (actually, fractional) are completely separate
|
|
|
|
// from the high-order bits (see R_AliasTransformFinalVert16 in
|
|
|
|
// sw_ralias.c), but in adjacant arrays. This means we can get away with
|
2012-04-24 05:12:54 +00:00
|
|
|
// just one memcpy as there are no endian issues.
|
2021-02-01 12:11:45 +00:00
|
|
|
memcpy (frame_verts, alias_ctx->poseverts.a[posenum], size);
|
2011-12-25 01:31:35 +00:00
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2021-02-01 12:11:45 +00:00
|
|
|
sw_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
|
2012-02-23 03:55:50 +00:00
|
|
|
int _s, int extra)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-02-01 12:11:45 +00:00
|
|
|
aliashdr_t *header = alias_ctx->header;
|
2002-08-25 14:25:38 +00:00
|
|
|
int i, j;
|
2011-12-25 01:31:35 +00:00
|
|
|
int posenum = 0;
|
2021-02-01 12:11:45 +00:00
|
|
|
int numv = header->mdl.numverts, numt = header->mdl.numtris;
|
|
|
|
stvert_t *stverts;
|
|
|
|
mtriangle_t *tris;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
stverts = (stvert_t *) Hunk_AllocName (0, numv * sizeof (stvert_t),
|
2021-02-01 12:11:45 +00:00
|
|
|
alias_ctx->mod->name);
|
2021-07-28 06:01:45 +00:00
|
|
|
tris = (mtriangle_t *) Hunk_AllocName (0, numt * sizeof (mtriangle_t),
|
2021-02-01 12:11:45 +00:00
|
|
|
alias_ctx->mod->name);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
header->stverts = (byte *) stverts - (byte *) header;
|
|
|
|
header->triangles = (byte *) tris - (byte *) header;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < numv; i++) {
|
2021-02-01 12:11:45 +00:00
|
|
|
stverts[i].onseam = alias_ctx->stverts.a[i].onseam;
|
|
|
|
stverts[i].s = alias_ctx->stverts.a[i].s << 16;
|
|
|
|
stverts[i].t = alias_ctx->stverts.a[i].t << 16;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < numt; i++) {
|
2021-02-01 12:11:45 +00:00
|
|
|
tris[i].facesfront = alias_ctx->triangles.a[i].facesfront;
|
|
|
|
VectorCopy (alias_ctx->triangles.a[i].vertindex, tris[i].vertindex);
|
2011-12-25 01:31:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 12:11:45 +00:00
|
|
|
for (i = 0; i < header->mdl.numframes; i++) {
|
|
|
|
maliasframedesc_t *frame = header->frames + i;
|
2011-12-25 01:31:35 +00:00
|
|
|
if (frame->type) {
|
|
|
|
maliasgroup_t *group;
|
2021-02-01 12:11:45 +00:00
|
|
|
group = (maliasgroup_t *) ((byte *) header + frame->frame);
|
|
|
|
for (j = 0; j < group->numframes; j++) {
|
|
|
|
__auto_type frame = (maliasframedesc_t *) &group->frames[j];
|
|
|
|
process_frame (alias_ctx, frame, posenum++, extra);
|
|
|
|
}
|
2011-12-25 01:31:35 +00:00
|
|
|
} else {
|
2021-02-01 12:11:45 +00:00
|
|
|
process_frame (alias_ctx, frame, posenum++, extra);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|