[model] Clean up the globals for alias models

This commit is contained in:
Bill Currie 2021-02-01 21:11:45 +09:00
parent 34dc7cf2df
commit ea72d0c60e
13 changed files with 350 additions and 320 deletions

View file

@ -102,14 +102,16 @@ typedef struct aliasctx_s {
struct vulkan_ctx_s;
struct entity_s;
void *Vulkan_Mod_LoadSkin (model_t *mod, byte *skin, int skinsize, int snum,
int gnum, qboolean group,
struct mod_alias_ctx_s;
void *Vulkan_Mod_LoadSkin (struct mod_alias_ctx_s *alias_ctx, byte *skin,
int skinsize, int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc,
struct vulkan_ctx_s *ctx);
void Vulkan_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr,
void Vulkan_Mod_FinalizeAliasModel (struct mod_alias_ctx_s *alias_ctx,
struct vulkan_ctx_s *ctx);
void Vulkan_Mod_LoadExternalSkins (model_t *mod, struct vulkan_ctx_s *ctx);
void Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr,
void Vulkan_Mod_LoadExternalSkins (struct mod_alias_ctx_s *alias_ctx,
struct vulkan_ctx_s *ctx);
void Vulkan_Mod_MakeAliasModelDisplayLists (struct mod_alias_ctx_s *alias_ctx,
void *_m, int _s, int extra,
struct vulkan_ctx_s *ctx);

View file

@ -28,7 +28,6 @@
#ifndef __QF_model_h
#define __QF_model_h
#include "QF/darray.h"
#include "QF/qtypes.h"
#include "QF/bspfile.h"
#include "QF/spritegn.h"
@ -372,16 +371,6 @@ typedef struct {
maliasframedesc_t frames[1];
} aliashdr_t;
typedef struct stvertset_s DARRAY_TYPE (stvert_t) stvertset_t;
typedef struct mtriangleset_s DARRAY_TYPE (mtriangle_t) mtriangleset_t;
typedef struct trivertxset_s DARRAY_TYPE (trivertx_t *) trivertxset_t;
extern aliashdr_t *pheader;
extern stvertset_t stverts;
extern mtriangleset_t triangles;
extern trivertxset_t poseverts;
extern int aliasbboxmins[3];
extern int aliasbboxmaxs[3];
// Whole model ================================================================
typedef enum {mod_brush, mod_sprite, mod_alias, mod_iqm} modtype_t;

View file

@ -37,6 +37,8 @@ struct plitem_s;
struct cvar_s;
struct skin_s;
struct mod_alias_ctx_s;
/*
All video plugins must export these functions
*/
@ -88,13 +90,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 (*Mod_MakeAliasModelDisplayLists) (struct mod_alias_ctx_s *alias_ctx,
void *_m, int _s, int extra);
void *(*Mod_LoadSkin) (model_t *mod, byte *skin, int skinsize, int snum,
int gnum,
void *(*Mod_LoadSkin) (struct mod_alias_ctx_s *alias_ctx, 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);
void (*Mod_FinalizeAliasModel) (struct mod_alias_ctx_s *alias_ctx);
void (*Mod_LoadExternalSkins) (struct mod_alias_ctx_s *alias_ctx);
void (*Mod_IQMFinish) (model_t *mod);
int alias_cache;
void (*Mod_SpriteLoadTexture) (model_t *mod, mspriteframe_t *pspriteframe,

View file

@ -1,11 +1,27 @@
#ifndef __mod_internal_h
#define __mod_internal_h
#include "QF/darray.h"
#include "QF/iqm.h"
#include "QF/model.h"
#include "QF/skin.h"
#include "QF/plugin/vid_render.h"
typedef struct stvertset_s DARRAY_TYPE (stvert_t) stvertset_t;
typedef struct mtriangleset_s DARRAY_TYPE (mtriangle_t) mtriangleset_t;
typedef struct trivertxset_s DARRAY_TYPE (trivertx_t *) trivertxset_t;
typedef struct mod_alias_ctx_s {
aliashdr_t *header;
model_t *mod;
stvertset_t stverts;
mtriangleset_t triangles;
trivertxset_t poseverts;
int aliasbboxmins[3];
int aliasbboxmaxs[3];
} mod_alias_ctx_t;
int Mod_CalcFullbright (const byte *in, byte *out, int pixels);
void Mod_ClearFullbright (const byte *in, byte *out, int pixels);
void Mod_FloodFillSkin (byte *skin, int skinwidth, int skinheight);
@ -22,28 +38,29 @@ struct vulkan_ctx_s;
extern vid_model_funcs_t *m_funcs;
void gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
void gl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
int _s, int extra);
void *gl_Mod_LoadSkin (model_t *mod, 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 *gl_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin, int skinsize,
int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc);
void gl_Mod_FinalizeAliasModel (mod_alias_ctx_t *alias_ctx);
void gl_Mod_LoadExternalSkins (mod_alias_ctx_t *alias_ctx);
void gl_Mod_IQMFinish (model_t *mod);
void glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr,
void glsl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx,
void *_m, int _s, int extra);
void *glsl_Mod_LoadSkin (model_t *mod, 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 *glsl_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin, int skinsize,
int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc);
void glsl_Mod_FinalizeAliasModel (mod_alias_ctx_t *alias_ctx);
void glsl_Mod_LoadExternalSkins (mod_alias_ctx_t *alias_ctx);
void glsl_Mod_IQMFinish (model_t *mod);
void sw_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
void sw_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
int _s, int extra);
void *sw_Mod_LoadSkin (model_t *mod, 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 *sw_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin, int skinsize,
int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc);
void sw_Mod_IQMFinish (model_t *mod);
void gl_Mod_LoadLighting (model_t *mod, bsp_t *bsp);

View file

@ -49,9 +49,6 @@
// ALIAS MODEL DISPLAY LIST GENERATION ========================================
static model_t *aliasmodel;
static aliashdr_t *paliashdr;
static qboolean *used;
static int used_size;
@ -126,14 +123,15 @@ add_strip (int vert, int tri)
}
static int
StripLength (int starttri, int startv)
StripLength (mod_alias_ctx_t *alias_ctx, int starttri, int startv)
{
aliashdr_t *header = alias_ctx->header;
int m1, m2, j, k;
mtriangle_t *last, *check;
used[starttri] = 2;
last = &triangles.a[starttri];
last = &alias_ctx->triangles.a[starttri];
stripcount = 0;
add_strip (last->vertindex[(startv) % 3], starttri);
@ -145,8 +143,8 @@ StripLength (int starttri, int startv)
// look for a matching triangle
nexttri:
for (j = starttri + 1, check = &triangles.a[starttri + 1];
j < pheader->mdl.numtris; j++, check++) {
for (j = starttri + 1, check = &alias_ctx->triangles.a[starttri + 1];
j < header->mdl.numtris; j++, check++) {
if (check->facesfront != last->facesfront)
continue;
for (k = 0; k < 3; k++) {
@ -176,7 +174,7 @@ nexttri:
done:
// clear the temp used flags
for (j = starttri + 1; j < pheader->mdl.numtris; j++)
for (j = starttri + 1; j < header->mdl.numtris; j++)
if (used[j] == 2)
used[j] = 0;
@ -184,14 +182,15 @@ done:
}
static int
FanLength (int starttri, int startv)
FanLength (mod_alias_ctx_t *alias_ctx, int starttri, int startv)
{
aliashdr_t *header = alias_ctx->header;
int m1, m2, j, k;
mtriangle_t *last, *check;
used[starttri] = 2;
last = &triangles.a[starttri];
last = &alias_ctx->triangles.a[starttri];
stripcount = 0;
add_strip (last->vertindex[(startv) % 3], starttri);
@ -204,8 +203,8 @@ FanLength (int starttri, int startv)
// look for a matching triangle
nexttri:
for (j = starttri + 1, check = &triangles.a[starttri + 1];
j < pheader->mdl.numtris; j++, check++) {
for (j = starttri + 1, check = &alias_ctx->triangles.a[starttri + 1];
j < header->mdl.numtris; j++, check++) {
if (check->facesfront != last->facesfront)
continue;
for (k = 0; k < 3; k++) {
@ -232,7 +231,7 @@ FanLength (int starttri, int startv)
done:
// clear the temp used flags
for (j = starttri + 1; j < pheader->mdl.numtris; j++)
for (j = starttri + 1; j < header->mdl.numtris; j++)
if (used[j] == 2)
used[j] = 0;
@ -246,8 +245,9 @@ FanLength (int starttri, int startv)
for the model, which holds for all frames
*/
static void
BuildTris (void)
BuildTris (mod_alias_ctx_t *alias_ctx)
{
aliashdr_t *header = alias_ctx->header;
float s, t;
int bestlen, len, startv, type, i, j, k;
int besttype = 0;
@ -257,10 +257,10 @@ BuildTris (void)
numorder = 0;
numcommands = 0;
stripcount = 0;
alloc_used (pheader->mdl.numtris);
alloc_used (header->mdl.numtris);
memset (used, 0, used_size * sizeof (used[0]));
for (i = 0; i < pheader->mdl.numtris; i++) {
for (i = 0; i < header->mdl.numtris; i++) {
// pick an unused triangle and start the trifan
if (used[i])
continue;
@ -270,9 +270,9 @@ BuildTris (void)
// type = 1;
for (startv = 0; startv < 3; startv++) {
if (type == 1)
len = StripLength (i, startv);
len = StripLength (alias_ctx, i, startv);
else
len = FanLength (i, startv);
len = FanLength (alias_ctx, i, startv);
if (len > bestlen) {
besttype = type;
bestlen = len;
@ -304,12 +304,13 @@ BuildTris (void)
add_vertex (k);
// emit s/t coords into the commands stream
s = stverts.a[k].s;
t = stverts.a[k].t;
if (!triangles.a[besttris[0]].facesfront && stverts.a[k].onseam)
s += pheader->mdl.skinwidth / 2; // on back side
s = (s + 0.5) / pheader->mdl.skinwidth;
t = (t + 0.5) / pheader->mdl.skinheight;
s = alias_ctx->stverts.a[k].s;
t = alias_ctx->stverts.a[k].t;
if (!alias_ctx->triangles.a[besttris[0]].facesfront
&& alias_ctx->stverts.a[k].onseam)
s += header->mdl.skinwidth / 2; // on back side
s = (s + 0.5) / header->mdl.skinwidth;
t = (t + 0.5) / header->mdl.skinheight;
memcpy (&tmp, &s, 4);
add_command (tmp);
@ -321,10 +322,10 @@ BuildTris (void)
add_command (0); // end of list marker
Sys_MaskPrintf (SYS_DEV, "%3i tri %3i vert %3i cmd\n",
pheader->mdl.numtris, numorder, numcommands);
header->mdl.numtris, numorder, numcommands);
allverts += numorder;
alltris += pheader->mdl.numtris;
alltris += header->mdl.numtris;
if (bestverts)
free (bestverts);
@ -333,9 +334,10 @@ BuildTris (void)
}
void
gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
gl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
int _s, int extra)
{
aliashdr_t *header = alias_ctx->header;
dstring_t *cache, *fullpath;
unsigned char model_digest[MDFOUR_DIGEST_BYTES];
unsigned char mesh_digest[MDFOUR_DIGEST_BYTES];
@ -345,24 +347,21 @@ gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
qboolean remesh = true;
qboolean do_cache = false;
aliasmodel = m;
paliashdr = hdr;
cache = dstring_new ();
fullpath = dstring_new ();
if (!gl_alias_render_tri->int_val) {
if (gl_mesh_cache->int_val
&& gl_mesh_cache->int_val <= paliashdr->mdl.numtris) {
&& gl_mesh_cache->int_val <= header->mdl.numtris) {
do_cache = true;
mdfour (model_digest, (unsigned char *) _m, _s);
// look for a cached version
dstring_copystr (cache, "glquake/");
dstring_appendstr (cache, m->path);
QFS_StripExtension (m->path + strlen ("progs/"),
dstring_appendstr (cache, alias_ctx->mod->path);
QFS_StripExtension (alias_ctx->mod->path + strlen ("progs/"),
cache->str + strlen ("glquake/"));
dstring_appendstr (cache, ".qfms");
@ -433,9 +432,9 @@ gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
}
if (remesh) {
// build it from scratch
Sys_MaskPrintf (SYS_DEV, "meshing %s...\n", m->path);
Sys_MaskPrintf (SYS_DEV, "meshing %s...\n", alias_ctx->mod->path);
BuildTris (); // trifans or lists
BuildTris (alias_ctx); // trifans or lists
if (do_cache) {
// save out the cached version
@ -474,35 +473,36 @@ gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
}
// save the data out
paliashdr->poseverts = numorder;
header->poseverts = numorder;
cmds = Hunk_Alloc (numcommands * sizeof (int));
paliashdr->commands = (byte *) cmds - (byte *) paliashdr;
header->commands = (byte *) cmds - (byte *) header;
memcpy (cmds, commands, numcommands * sizeof (int));
} else {
tex_coord_t *tex_coord;
numorder = 0;
for (i=0; i < pheader->mdl.numtris; i++) {
add_vertex(triangles.a[i].vertindex[0]);
add_vertex(triangles.a[i].vertindex[1]);
add_vertex(triangles.a[i].vertindex[2]);
for (i=0; i < header->mdl.numtris; i++) {
add_vertex(alias_ctx->triangles.a[i].vertindex[0]);
add_vertex(alias_ctx->triangles.a[i].vertindex[1]);
add_vertex(alias_ctx->triangles.a[i].vertindex[2]);
}
paliashdr->poseverts = numorder;
header->poseverts = numorder;
tex_coord = Hunk_Alloc (numorder * sizeof(tex_coord_t));
paliashdr->tex_coord = (byte *) tex_coord - (byte *) paliashdr;
header->tex_coord = (byte *) tex_coord - (byte *) header;
for (i=0; i < numorder; i++) {
float s, t;
int k;
k = vertexorder[i];
s = stverts.a[k].s;
t = stverts.a[k].t;
if (!triangles.a[i/3].facesfront && stverts.a[k].onseam)
s += pheader->mdl.skinwidth / 2; // on back side
s = (s + 0.5) / pheader->mdl.skinwidth;
t = (t + 0.5) / pheader->mdl.skinheight;
s = alias_ctx->stverts.a[k].s;
t = alias_ctx->stverts.a[k].t;
if (!alias_ctx->triangles.a[i/3].facesfront
&& alias_ctx->stverts.a[k].onseam)
s += header->mdl.skinwidth / 2; // on back side
s = (s + 0.5) / header->mdl.skinwidth;
t = (t + 0.5) / header->mdl.skinheight;
tex_coord[i].st[0] = s;
tex_coord[i].st[1] = t;
}
@ -510,11 +510,11 @@ gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
if (extra) {
trivertx16_t *verts;
verts = Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts
verts = Hunk_Alloc (header->numposes * header->poseverts
* sizeof (trivertx16_t));
paliashdr->posedata = (byte *) verts - (byte *) paliashdr;
for (i = 0; i < paliashdr->numposes; i++) {
trivertx_t *pv = poseverts.a[i];
header->posedata = (byte *) verts - (byte *) header;
for (i = 0; i < header->numposes; i++) {
trivertx_t *pv = alias_ctx->poseverts.a[i];
for (j = 0; j < numorder; j++) {
trivertx16_t v;
// convert MD16's split coordinates into something a little
@ -523,21 +523,21 @@ gl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
// fractional bits of the vertex, giving 8.8. However, it's
// easier for us to multiply everything by 256 and adjust the
// model scale appropriately
VectorMultAdd (pv[vertexorder[j] + hdr->mdl.numverts].v,
VectorMultAdd (pv[vertexorder[j] + header->mdl.numverts].v,
256, pv[vertexorder[j]].v, v.v);
v.lightnormalindex =
poseverts.a[i][vertexorder[j]].lightnormalindex;
alias_ctx->poseverts.a[i][vertexorder[j]].lightnormalindex;
*verts++ = v;
}
}
} else {
trivertx_t *verts;
verts = Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts
verts = Hunk_Alloc (header->numposes * header->poseverts
* sizeof (trivertx_t));
paliashdr->posedata = (byte *) verts - (byte *) paliashdr;
for (i = 0; i < paliashdr->numposes; i++) {
header->posedata = (byte *) verts - (byte *) header;
for (i = 0; i < header->numposes; i++) {
for (j = 0; j < numorder; j++)
*verts++ = poseverts.a[i][vertexorder[j]];
*verts++ = alias_ctx->poseverts.a[i][vertexorder[j]];
}
}
dstring_delete (cache);

View file

@ -53,36 +53,38 @@
#include "compat.h"
void *
gl_Mod_LoadSkin (model_t *mod, byte *skin, int skinsize, int snum, int gnum,
qboolean group, maliasskindesc_t *skindesc)
gl_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin, int skinsize,
int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc)
{
aliashdr_t *header = alias_ctx->header;
byte *pskin;
char modname[MAX_QPATH + 4];
int fb_texnum = 0, texnum = 0;
dstring_t *name = dstring_new ();
pskin = Hunk_AllocName (skinsize, mod->name);
skindesc->skin = (byte *) pskin - (byte *) pheader;
pskin = Hunk_AllocName (skinsize, alias_ctx->mod->name);
skindesc->skin = (byte *) pskin - (byte *) header;
memcpy (pskin, skin, skinsize);
Mod_FloodFillSkin (pskin, pheader->mdl.skinwidth, pheader->mdl.skinheight);
Mod_FloodFillSkin (pskin, header->mdl.skinwidth, header->mdl.skinheight);
// save 8 bit texels for the player model to remap
// FIXME remove model restriction
if (strequal (mod->path, "progs/player.mdl"))
gl_Skin_SetPlayerSkin (pheader->mdl.skinwidth, pheader->mdl.skinheight,
if (strequal (alias_ctx->mod->path, "progs/player.mdl"))
gl_Skin_SetPlayerSkin (header->mdl.skinwidth, header->mdl.skinheight,
pskin);
QFS_StripExtension (mod->path, modname);
QFS_StripExtension (alias_ctx->mod->path, modname);
if (!mod->fullbright) {
if (!alias_ctx->mod->fullbright) {
if (group) {
dsprintf (name, "fb_%s_%i_%i", modname, snum, gnum);
} else {
dsprintf (name, "fb_%s_%i", modname, snum);
}
fb_texnum = Mod_Fullbright (pskin, pheader->mdl.skinwidth,
pheader->mdl.skinheight, name->str);
fb_texnum = Mod_Fullbright (pskin, header->mdl.skinwidth,
header->mdl.skinheight, name->str);
Sys_MaskPrintf (SYS_GLT, "%s %d\n", name->str, fb_texnum);
}
if (group) {
@ -90,23 +92,25 @@ gl_Mod_LoadSkin (model_t *mod, byte *skin, int skinsize, int snum, int gnum,
} else {
dsprintf (name, "%s_%i", modname, snum);
}
texnum = GL_LoadTexture (name->str, pheader->mdl.skinwidth,
pheader->mdl.skinheight, pskin, true, false, 1);
texnum = GL_LoadTexture (name->str, header->mdl.skinwidth,
header->mdl.skinheight, pskin, true, false, 1);
Sys_MaskPrintf (SYS_GLT, "%s %d\n", name->str, texnum);
skindesc->texnum = texnum;
skindesc->fb_texnum = fb_texnum;
mod->hasfullbrights = fb_texnum;
alias_ctx->mod->hasfullbrights = fb_texnum;
dstring_delete (name);
// alpha param was true for non group skins
return skin + skinsize;
}
void
gl_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr)
gl_Mod_FinalizeAliasModel (mod_alias_ctx_t *alias_ctx)
{
if (strequal (m->path, "progs/eyes.mdl")) {
hdr->mdl.scale_origin[2] -= (22 + 8);
VectorScale (hdr->mdl.scale, 2, hdr->mdl.scale);
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);
}
}
@ -150,25 +154,26 @@ Mod_LoadExternalSkin (maliasskindesc_t *pskindesc, char *filename)
}
void
gl_Mod_LoadExternalSkins (model_t *mod)
gl_Mod_LoadExternalSkins (mod_alias_ctx_t *alias_ctx)
{
aliashdr_t *header = alias_ctx->header;
char modname[MAX_QPATH + 4];
int i, j;
maliasskindesc_t *pskindesc;
maliasskingroup_t *pskingroup;
dstring_t *filename = dstring_new ();
QFS_StripExtension (mod->path, modname);
QFS_StripExtension (alias_ctx->mod->path, modname);
for (i = 0; i < pheader->mdl.numskins; i++) {
for (i = 0; i < header->mdl.numskins; i++) {
pskindesc = ((maliasskindesc_t *)
((byte *) pheader + pheader->skindesc)) + i;
((byte *) header + header->skindesc)) + i;
if (pskindesc->type == ALIAS_SKIN_SINGLE) {
dsprintf (filename, "%s_%i", modname, i);
Mod_LoadExternalSkin (pskindesc, filename->str);
} else {
pskingroup = (maliasskingroup_t *)
((byte *) pheader + pskindesc->skin);
((byte *) header + pskindesc->skin);
for (j = 0; j < pskingroup->numskins; j++) {
dsprintf (filename, "%s_%i_%i", modname, i, j);

View file

@ -58,24 +58,24 @@ static void
glsl_alias_clear (model_t *m, void *data)
{
int i, j;
aliashdr_t *hdr;
aliashdr_t *header;
GLuint bufs[2];
maliasskindesc_t *skins;
maliasskingroup_t *group;
m->needload = true;
if (!(hdr = m->aliashdr))
hdr = Cache_Get (&m->cache);
if (!(header = m->aliashdr))
header = Cache_Get (&m->cache);
bufs[0] = hdr->posedata;
bufs[1] = hdr->commands;
bufs[0] = header->posedata;
bufs[1] = header->commands;
qfeglDeleteBuffers (2, bufs);
skins = ((maliasskindesc_t *) ((byte *) hdr + hdr->skindesc));
for (i = 0; i < hdr->mdl.numskins; i++) {
skins = ((maliasskindesc_t *) ((byte *) header + header->skindesc));
for (i = 0; i < header->mdl.numskins; i++) {
if (skins[i].type == ALIAS_SKIN_GROUP) {
group = (maliasskingroup_t *) ((byte *) hdr + skins[i].skin);
group = (maliasskingroup_t *) ((byte *) header + skins[i].skin);
for (j = 0; j < group->numskins; j++) {
GLSL_ReleaseTexture (group->skindescs[j].texnum);
}
@ -91,44 +91,49 @@ glsl_alias_clear (model_t *m, void *data)
}
void *
glsl_Mod_LoadSkin (model_t *mod, byte *skin, int skinsize, int snum, int gnum,
qboolean group, maliasskindesc_t *skindesc)
glsl_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin, int skinsize,
int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc)
{
aliashdr_t *header = alias_ctx->header;
byte *tskin;
const char *name;
int w, h;
w = pheader->mdl.skinwidth;
h = pheader->mdl.skinheight;
w = header->mdl.skinwidth;
h = header->mdl.skinheight;
tskin = malloc (skinsize);
memcpy (tskin, skin, skinsize);
Mod_FloodFillSkin (tskin, w, h);
if (group)
name = va (0, "%s_%i_%i", mod->path, snum, gnum);
name = va (0, "%s_%i_%i", alias_ctx->mod->path, snum, gnum);
else
name = va (0, "%s_%i", mod->path, snum);
name = va (0, "%s_%i", alias_ctx->mod->path, snum);
skindesc->texnum = GLSL_LoadQuakeTexture (name, w, h, tskin);
free (tskin);
return skin + skinsize;
}
void
glsl_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr)
glsl_Mod_FinalizeAliasModel (mod_alias_ctx_t *alias_ctx)
{
if (hdr->mdl.ident == HEADER_MDL16)
VectorScale (hdr->mdl.scale, 1/256.0, hdr->mdl.scale);
m->clear = glsl_alias_clear;
aliashdr_t *header = alias_ctx->header;
if (header->mdl.ident == HEADER_MDL16)
VectorScale (header->mdl.scale, 1/256.0, header->mdl.scale);
alias_ctx->mod->clear = glsl_alias_clear;
}
void
glsl_Mod_LoadExternalSkins (model_t *mod)
glsl_Mod_LoadExternalSkins (mod_alias_ctx_t *alias_ctx)
{
}
void
glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
glsl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
int _s, int extra)
{
aliashdr_t *header = alias_ctx->header;
mtriangle_t *tris;
stvert_t *st;
aliasvrt_t *verts;
@ -142,12 +147,12 @@ glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
int i, j;
int pose;
numverts = hdr->mdl.numverts;
numtris = hdr->mdl.numtris;
numverts = header->mdl.numverts;
numtris = header->mdl.numtris;
// copy triangles before editing them
tris = malloc (numtris * sizeof (mtriangle_t));
memcpy (tris, triangles.a, numtris * sizeof (mtriangle_t));
memcpy (tris, alias_ctx->triangles.a, numtris * sizeof (mtriangle_t));
// initialize indexmap to -1 (unduplicated). any other value indicates
// both that the vertex has been duplicated and the index of the
@ -157,7 +162,7 @@ glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
// copy stverts. need space for duplicates
st = malloc (2 * numverts * sizeof (stvert_t));
memcpy (st, stverts.a, numverts * sizeof (stvert_t));
memcpy (st, alias_ctx->stverts.a, numverts * sizeof (stvert_t));
// check for onseam verts, and duplicate any that are associated with
// back-facing triangles. the s coordinate is shifted right by half
@ -168,7 +173,7 @@ glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
if (st[vind].onseam && !tris[i].facesfront) {
if (indexmap[vind] == -1) {
st[numverts] = st[vind];
st[numverts].s += hdr->mdl.skinwidth / 2;
st[numverts].s += header->mdl.skinwidth / 2;
indexmap[vind] = numverts++;
}
tris[i].vertindex[j] = indexmap[vind];
@ -178,13 +183,13 @@ glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
// we now know exactly how many vertices we need, so built the vertex
// array
vertexsize = hdr->numposes * numverts * sizeof (aliasvrt_t);
vertexsize = header->numposes * numverts * sizeof (aliasvrt_t);
verts = malloc (vertexsize);
for (i = 0, pose = 0; i < hdr->numposes; i++, pose += numverts) {
for (j = 0; j < hdr->mdl.numverts; j++) {
pv = &poseverts.a[i][j];
for (i = 0, pose = 0; i < header->numposes; i++, pose += numverts) {
for (j = 0; j < header->mdl.numverts; j++) {
pv = &alias_ctx->poseverts.a[i][j];
if (extra) {
VectorMultAdd (pv[hdr->mdl.numverts].v, 256, pv->v,
VectorMultAdd (pv[header->mdl.numverts].v, 256, pv->v,
verts[pose + j].vertex);
} else {
VectorCopy (pv->v, verts[pose + j].vertex);
@ -218,14 +223,14 @@ glsl_Mod_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr, void *_m,
// finished with tris
free (tris);
hdr->poseverts = numverts;
header->poseverts = numverts;
// load the vertex data and indices into GL
qfeglGenBuffers (2, bnum);
hdr->posedata = bnum[0];
hdr->commands = bnum[1];
qfeglBindBuffer (GL_ARRAY_BUFFER, hdr->posedata);
qfeglBindBuffer (GL_ELEMENT_ARRAY_BUFFER, hdr->commands);
header->posedata = bnum[0];
header->commands = bnum[1];
qfeglBindBuffer (GL_ARRAY_BUFFER, header->posedata);
qfeglBindBuffer (GL_ELEMENT_ARRAY_BUFFER, header->commands);
qfeglBufferData (GL_ARRAY_BUFFER, vertexsize, verts, GL_STATIC_DRAW);
qfeglBufferData (GL_ELEMENT_ARRAY_BUFFER, indexsize, indices,
GL_STATIC_DRAW);

View file

@ -49,22 +49,11 @@
#include "mod_internal.h"
#include "r_local.h"
aliashdr_t *pheader;
stvertset_t stverts = { 0, 0, 256 };
mtriangleset_t triangles = { 0, 0, 256 };
// a pose is a single set of vertexes. a frame may be an animating
// sequence of poses
trivertxset_t poseverts = { 0, 0, 256 };;
int posenum = 0;
int aliasbboxmins[3], aliasbboxmaxs[3];
static void *
Mod_LoadAllSkins (model_t *mod, int numskins, daliasskintype_t *pskintype,
int *pskinindex)
Mod_LoadAllSkins (mod_alias_ctx_t *alias_ctx, int numskins,
daliasskintype_t *pskintype, int *pskinindex)
{
aliashdr_t *header = alias_ctx->header;
byte *skin;
float *poutskinintervals;
int groupskins, skinsize, gnum, snum, t;
@ -76,34 +65,34 @@ Mod_LoadAllSkins (model_t *mod, int numskins, daliasskintype_t *pskintype,
if (numskins < 1 || numskins > MAX_SKINS)
Sys_Error ("Mod_LoadAliasModel: Invalid # of skins: %d", numskins);
skinsize = pheader->mdl.skinwidth * pheader->mdl.skinheight;
skinsize = header->mdl.skinwidth * header->mdl.skinheight;
pskindesc = Hunk_AllocName (numskins * sizeof (maliasskindesc_t),
mod->name);
alias_ctx->mod->name);
*pskinindex = (byte *) pskindesc - (byte *) pheader;
*pskinindex = (byte *) pskindesc - (byte *) header;
for (snum = 0; snum < numskins; snum++) {
pskindesc[snum].type = pskintype->type;
if (pskintype->type == ALIAS_SKIN_SINGLE) {
skin = (byte *) (pskintype + 1);
skin = m_funcs->Mod_LoadSkin (mod, skin, skinsize, snum, 0, false,
&pskindesc[snum]);
skin = m_funcs->Mod_LoadSkin (alias_ctx, skin, skinsize, snum, 0,
false, &pskindesc[snum]);
} else {
pskintype++;
pinskingroup = (daliasskingroup_t *) pskintype;
groupskins = LittleLong (pinskingroup->numskins);
t = field_offset (maliasskingroup_t, skindescs[groupskins]);
paliasskingroup = Hunk_AllocName (t, mod->name);
paliasskingroup = Hunk_AllocName (t, alias_ctx->mod->name);
paliasskingroup->numskins = groupskins;
pskindesc[snum].skin = (byte *) paliasskingroup - (byte *) pheader;
pskindesc[snum].skin = (byte *) paliasskingroup - (byte *) header;
pinskinintervals = (daliasskininterval_t *) (pinskingroup + 1);
poutskinintervals = Hunk_AllocName (groupskins * sizeof (float),
mod->name);
alias_ctx->mod->name);
paliasskingroup->intervals =
(byte *) poutskinintervals - (byte *) pheader;
(byte *) poutskinintervals - (byte *) header;
for (gnum = 0; gnum < groupskins; gnum++) {
*poutskinintervals = LittleFloat (pinskinintervals->interval);
if (*poutskinintervals <= 0)
@ -118,8 +107,8 @@ Mod_LoadAllSkins (model_t *mod, int numskins, daliasskintype_t *pskintype,
for (gnum = 0; gnum < groupskins; gnum++) {
paliasskingroup->skindescs[gnum].type = ALIAS_SKIN_SINGLE;
skin = mod_funcs->Mod_LoadSkin (mod, skin, skinsize, snum,
gnum, true,
skin = mod_funcs->Mod_LoadSkin (alias_ctx, skin, skinsize,
snum, gnum, true,
&paliasskingroup->skindescs[gnum]);
}
}
@ -130,9 +119,10 @@ Mod_LoadAllSkins (model_t *mod, int numskins, daliasskintype_t *pskintype,
}
static void *
Mod_LoadAliasFrame (model_t *mod, void *pin, int *posenum,
Mod_LoadAliasFrame (mod_alias_ctx_t *alias_ctx, void *pin, int *posenum,
maliasframedesc_t *frame, int extra)
{
aliashdr_t *header = alias_ctx->header;
daliasframe_t *pdaliasframe;
trivertx_t *pinframe;
@ -146,25 +136,29 @@ Mod_LoadAliasFrame (model_t *mod, void *pin, int *posenum,
// byte values, don't worry about endianness
VectorCopy (pdaliasframe->bboxmin.v, frame->bboxmin.v);
VectorCopy (pdaliasframe->bboxmax.v, frame->bboxmax.v);
VectorCompMin (frame->bboxmin.v, aliasbboxmins, aliasbboxmins);
VectorCompMax (frame->bboxmax.v, aliasbboxmaxs, aliasbboxmaxs);
VectorCompMin (frame->bboxmin.v, alias_ctx->aliasbboxmins,
alias_ctx->aliasbboxmins);
VectorCompMax (frame->bboxmax.v, alias_ctx->aliasbboxmaxs,
alias_ctx->aliasbboxmaxs);
pinframe = (trivertx_t *) (pdaliasframe + 1);
DARRAY_APPEND (&poseverts, pinframe);
DARRAY_APPEND (&alias_ctx->poseverts, pinframe);
(*posenum)++;
pinframe += pheader->mdl.numverts;
pinframe += header->mdl.numverts;
if (extra)
pinframe += pheader->mdl.numverts;
pinframe += header->mdl.numverts;
return pinframe;
}
static void *
Mod_LoadAliasGroup (model_t *mod, void *pin, int *posenum,
Mod_LoadAliasGroup (mod_alias_ctx_t *alias_ctx, void *pin, int *posenum,
maliasframedesc_t *frame, int extra)
{
aliashdr_t *header = alias_ctx->header;
model_t *mod = alias_ctx->mod;
daliasgroup_t *pingroup;
daliasinterval_t *pin_intervals;
float *poutintervals;
@ -182,17 +176,19 @@ Mod_LoadAliasGroup (model_t *mod, void *pin, int *posenum,
paliasgroup = Hunk_AllocName (field_offset (maliasgroup_t,
frames[numframes]), mod->name);
paliasgroup->numframes = numframes;
frame->frame = (byte *) paliasgroup - (byte *) pheader;
frame->frame = (byte *) paliasgroup - (byte *) header;
// these are byte values, so we don't have to worry about endianness
VectorCopy (pingroup->bboxmin.v, frame->bboxmin.v);
VectorCopy (pingroup->bboxmax.v, frame->bboxmax.v);
VectorCompMin (frame->bboxmin.v, aliasbboxmins, aliasbboxmins);
VectorCompMax (frame->bboxmax.v, aliasbboxmaxs, aliasbboxmaxs);
VectorCompMin (frame->bboxmin.v, alias_ctx->aliasbboxmins,
alias_ctx->aliasbboxmins);
VectorCompMax (frame->bboxmax.v, alias_ctx->aliasbboxmaxs,
alias_ctx->aliasbboxmaxs);
pin_intervals = (daliasinterval_t *) (pingroup + 1);
poutintervals = Hunk_AllocName (numframes * sizeof (float), mod->name);
paliasgroup->intervals = (byte *) poutintervals - (byte *) pheader;
paliasgroup->intervals = (byte *) poutintervals - (byte *) header;
frame->interval = LittleFloat (pin_intervals->interval);
for (i = 0; i < numframes; i++) {
*poutintervals = LittleFloat (pin_intervals->interval);
@ -205,7 +201,8 @@ Mod_LoadAliasGroup (model_t *mod, void *pin, int *posenum,
ptemp = (void *) pin_intervals;
for (i = 0; i < numframes; i++) {
maliasframedesc_t temp_frame;
ptemp = Mod_LoadAliasFrame (mod, ptemp, posenum, &temp_frame, extra);
ptemp = Mod_LoadAliasFrame (alias_ctx, ptemp, posenum, &temp_frame,
extra);
memcpy (&paliasgroup->frames[i], &temp_frame,
sizeof (paliasgroup->frames[i]));
}
@ -225,6 +222,14 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
mdl_t *pinmodel, *pmodel;
unsigned short crc;
stvert_t *pinstverts;
mod_alias_ctx_t alias_ctx = {};
aliashdr_t *header;
alias_ctx.mod = mod;
//FIXME should be per batch rather than per model
DARRAY_INIT (&alias_ctx.poseverts, 256);
DARRAY_INIT (&alias_ctx.stverts, 256);
DARRAY_INIT (&alias_ctx.triangles, 256);
if (LittleLong (* (unsigned int *) buffer) == HEADER_MDL16)
extra = 1; // extra precision bytes
@ -244,12 +249,13 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
// allocate space for a working header, plus all the data except the
// frames, skin and group info
size = field_offset (aliashdr_t, frames[LittleLong (pinmodel->numframes)]);
pheader = Hunk_AllocName (size, mod->name);
memset (pheader, 0, size);
pmodel = &pheader->mdl;
pheader->model = (byte *) pmodel - (byte *) pheader;
header = Hunk_AllocName (size, mod->name);
memset (header, 0, size);
alias_ctx.header = header;
pmodel = &header->mdl;
header->model = (byte *) pmodel - (byte *) header;
pheader->crc = crc;
header->crc = crc;
mod->flags = LittleLong (pinmodel->flags);
@ -264,20 +270,20 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
Sys_Error ("model %s has a skin taller than %d", mod->name,
MAX_LBM_HEIGHT);
DARRAY_RESIZE (&poseverts, 0);
DARRAY_RESIZE (&alias_ctx.poseverts, 0);
pmodel->numverts = LittleLong (pinmodel->numverts);
if (pmodel->numverts <= 0)
Sys_Error ("model %s has no vertices", mod->name);
DARRAY_RESIZE (&stverts, pmodel->numverts);
DARRAY_RESIZE (&alias_ctx.stverts, pmodel->numverts);
pmodel->numtris = LittleLong (pinmodel->numtris);
if (pmodel->numtris <= 0)
Sys_Error ("model %s has no triangles", mod->name);
DARRAY_RESIZE (&triangles, pmodel->numtris);
DARRAY_RESIZE (&alias_ctx.triangles, pmodel->numtris);
pmodel->numframes = LittleLong (pinmodel->numframes);
numframes = pmodel->numframes;
@ -296,73 +302,76 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
// load the skins
pskintype = (daliasskintype_t *) &pinmodel[1];
pskintype = Mod_LoadAllSkins (mod, pheader->mdl.numskins, pskintype,
&pheader->skindesc);
pskintype = Mod_LoadAllSkins (&alias_ctx, header->mdl.numskins, pskintype,
&header->skindesc);
// load base s and t vertices
pinstverts = (stvert_t *) pskintype;
for (i = 0; i < pheader->mdl.numverts; i++) {
stverts.a[i].onseam = LittleLong (pinstverts[i].onseam);
stverts.a[i].s = LittleLong (pinstverts[i].s);
stverts.a[i].t = LittleLong (pinstverts[i].t);
for (i = 0; i < header->mdl.numverts; i++) {
alias_ctx.stverts.a[i].onseam = LittleLong (pinstverts[i].onseam);
alias_ctx.stverts.a[i].s = LittleLong (pinstverts[i].s);
alias_ctx.stverts.a[i].t = LittleLong (pinstverts[i].t);
}
// load triangle lists
pintriangles = (dtriangle_t *) &pinstverts[pheader->mdl.numverts];
pintriangles = (dtriangle_t *) &pinstverts[header->mdl.numverts];
for (i = 0; i < pheader->mdl.numtris; i++) {
triangles.a[i].facesfront = LittleLong (pintriangles[i].facesfront);
for (i = 0; i < header->mdl.numtris; i++) {
alias_ctx.triangles.a[i].facesfront =
LittleLong (pintriangles[i].facesfront);
for (j = 0; j < 3; j++) {
triangles.a[i].vertindex[j] =
alias_ctx.triangles.a[i].vertindex[j] =
LittleLong (pintriangles[i].vertindex[j]);
}
}
// load the frames
posenum = 0;
pframetype = (daliasframetype_t *) &pintriangles[pheader->mdl.numtris];
aliasbboxmins[0] = aliasbboxmins[1] = aliasbboxmins[2] = 99999;
aliasbboxmaxs[0] = aliasbboxmaxs[1] = aliasbboxmaxs[2] = -99999;
int posenum = 0;
pframetype = (daliasframetype_t *) &pintriangles[header->mdl.numtris];
VectorSet (99999, 99999, 99999, alias_ctx.aliasbboxmins);
VectorSet (-99999, -99999, -99999, alias_ctx.aliasbboxmaxs);
for (i = 0; i < numframes; i++) {
aliasframetype_t frametype;
frametype = LittleLong (pframetype->type);
pheader->frames[i].type = frametype;
header->frames[i].type = frametype;
if (frametype == ALIAS_SINGLE) {
pframetype = (daliasframetype_t *)
Mod_LoadAliasFrame (mod, pframetype + 1, &posenum,
&pheader->frames[i], extra);
Mod_LoadAliasFrame (&alias_ctx, pframetype + 1, &posenum,
&header->frames[i], extra);
} else {
pframetype = (daliasframetype_t *)
Mod_LoadAliasGroup (mod, pframetype + 1, &posenum,
&pheader->frames[i], extra);
Mod_LoadAliasGroup (&alias_ctx, pframetype + 1, &posenum,
&header->frames[i], extra);
}
}
pheader->numposes = posenum;
header->numposes = posenum;
mod->type = mod_alias;
for (i = 0; i < 3; i++) {
mod->mins[i] = aliasbboxmins[i] * pheader->mdl.scale[i] +
pheader->mdl.scale_origin[i];
mod->maxs[i] = aliasbboxmaxs[i] * pheader->mdl.scale[i] +
pheader->mdl.scale_origin[i];
}
VectorCompMultAdd (header->mdl.scale_origin, header->mdl.scale,
alias_ctx.aliasbboxmins, mod->mins);
VectorCompMultAdd (header->mdl.scale_origin, header->mdl.scale,
alias_ctx.aliasbboxmaxs, mod->maxs);
mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
// build the draw lists
m_funcs->Mod_MakeAliasModelDisplayLists (mod, pheader, buffer,
m_funcs->Mod_MakeAliasModelDisplayLists (&alias_ctx, buffer,
qfs_filesize, extra);
m_funcs->Mod_FinalizeAliasModel (mod, pheader);
if (m_funcs->Mod_FinalizeAliasModel) {
m_funcs->Mod_FinalizeAliasModel (&alias_ctx);
}
m_funcs->Mod_LoadExternalSkins (mod);
if (m_funcs->Mod_LoadExternalSkins) {
m_funcs->Mod_LoadExternalSkins (&alias_ctx);
}
// move the complete, relocatable alias model to the cache
if (m_funcs->alias_cache) {
@ -371,11 +380,11 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
mem = allocator (&mod->cache, total, mod->name);
if (mem)
memcpy (mem, pheader, total);
memcpy (mem, header, total);
Hunk_FreeToLowMark (start);
mod->aliashdr = 0;
} else {
mod->aliashdr = pheader;
mod->aliashdr = header;
}
}

View file

@ -50,13 +50,14 @@
void *
sw_Mod_LoadSkin (model_t *mod, byte *skin, int skinsize, int snum, int gnum,
sw_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin,
int skinsize, int snum, int gnum,
qboolean group, maliasskindesc_t *skindesc)
{
byte *pskin;
pskin = Hunk_AllocName (skinsize, mod->name);
skindesc->skin = (byte *) pskin - (byte *) pheader;
pskin = Hunk_AllocName (skinsize, alias_ctx->mod->name);
skindesc->skin = (byte *) pskin - (byte *) alias_ctx->header;
memcpy (pskin, skin, skinsize);
@ -64,73 +65,67 @@ sw_Mod_LoadSkin (model_t *mod, byte *skin, int skinsize, int snum, int gnum,
}
static void
process_frame (model_t *mod, maliasframedesc_t *frame, int posenum, int extra)
process_frame (mod_alias_ctx_t *alias_ctx, maliasframedesc_t *frame,
int posenum, int extra)
{
int size = pheader->mdl.numverts * sizeof (trivertx_t);
aliashdr_t *header = alias_ctx->header;
int size = header->mdl.numverts * sizeof (trivertx_t);
trivertx_t *frame_verts;
if (extra)
size *= 2;
frame_verts = Hunk_AllocName (size, mod->name);
frame->frame = (byte *) frame_verts - (byte *) pheader;
frame_verts = Hunk_AllocName (size, alias_ctx->mod->name);
frame->frame = (byte *) frame_verts - (byte *) header;
// 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
// just one memcpy as there are no endian issues.
memcpy (frame_verts, poseverts.a[posenum], size);
memcpy (frame_verts, alias_ctx->poseverts.a[posenum], size);
}
void
sw_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
sw_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
int _s, int extra)
{
aliashdr_t *header = alias_ctx->header;
int i, j;
int posenum = 0;
int numv = hdr->mdl.numverts, numt = hdr->mdl.numtris;
stvert_t *pstverts;
mtriangle_t *ptri;
int numv = header->mdl.numverts, numt = header->mdl.numtris;
stvert_t *stverts;
mtriangle_t *tris;
pstverts = (stvert_t *) Hunk_AllocName (numv * sizeof (stvert_t),
mod->name);
ptri = (mtriangle_t *) Hunk_AllocName (numt * sizeof (mtriangle_t),
mod->name);
stverts = (stvert_t *) Hunk_AllocName (numv * sizeof (stvert_t),
alias_ctx->mod->name);
tris = (mtriangle_t *) Hunk_AllocName (numt * sizeof (mtriangle_t),
alias_ctx->mod->name);
hdr->stverts = (byte *) pstverts - (byte *) hdr;
hdr->triangles = (byte *) ptri - (byte *) hdr;
header->stverts = (byte *) stverts - (byte *) header;
header->triangles = (byte *) tris - (byte *) header;
for (i = 0; i < numv; i++) {
pstverts[i].onseam = stverts.a[i].onseam;
pstverts[i].s = stverts.a[i].s << 16;
pstverts[i].t = stverts.a[i].t << 16;
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;
}
for (i = 0; i < numt; i++) {
ptri[i].facesfront = triangles.a[i].facesfront;
VectorCopy (triangles.a[i].vertindex, ptri[i].vertindex);
tris[i].facesfront = alias_ctx->triangles.a[i].facesfront;
VectorCopy (alias_ctx->triangles.a[i].vertindex, tris[i].vertindex);
}
for (i = 0; i < pheader->mdl.numframes; i++) {
maliasframedesc_t *frame = pheader->frames + i;
for (i = 0; i < header->mdl.numframes; i++) {
maliasframedesc_t *frame = header->frames + i;
if (frame->type) {
maliasgroup_t *group;
group = (maliasgroup_t *) ((byte *) pheader + frame->frame);
for (j = 0; j < group->numframes; j++)
process_frame (mod, (maliasframedesc_t *) &group->frames[j],
posenum++, extra);
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);
}
} else {
process_frame (mod, frame, posenum++, extra);
process_frame (alias_ctx, frame, posenum++, extra);
}
}
}
void
sw_Mod_FinalizeAliasModel (model_t *mod, aliashdr_t *hdr)
{
}
void
sw_Mod_LoadExternalSkins (model_t *mod)
{
}

View file

@ -110,19 +110,20 @@ vulkan_alias_clear (model_t *m, void *data)
}
void *
Vulkan_Mod_LoadSkin (model_t *mod, byte *skinpix, int skinsize, int snum,
int gnum, qboolean group, maliasskindesc_t *skindesc,
vulkan_ctx_t *ctx)
Vulkan_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skinpix, int skinsize,
int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc, vulkan_ctx_t *ctx)
{
aliashdr_t *header = alias_ctx->header;
aliasskin_t *skin;
byte *tskin;
int w, h;
skin = Hunk_Alloc (sizeof (aliasskin_t));
skindesc->skin = (byte *) skin - (byte *) pheader;//FIXME pheader global
skindesc->skin = (byte *) skin - (byte *) header;
//FIXME move all skins into arrays(?)
w = pheader->mdl.skinwidth;
h = pheader->mdl.skinheight;
w = header->mdl.skinwidth;
h = header->mdl.skinheight;
tskin = malloc (2 * skinsize);
memcpy (tskin, skinpix, skinsize);
Mod_FloodFillSkin (tskin, w, h);
@ -131,25 +132,25 @@ Vulkan_Mod_LoadSkin (model_t *mod, byte *skinpix, int skinsize, int snum,
if (Mod_CalcFullbright (tskin, tskin + skinsize, skinsize)) {
skin->glow = Vulkan_LoadTex (ctx, &skin_tex, 1,
va (ctx->va_ctx, "%s:%d:%d:glow",
mod->name, snum, gnum));
alias_ctx->mod->name, snum, gnum));
Mod_ClearFullbright (tskin, tskin, skinsize);
}
if (Skin_CalcTopColors (tskin, tskin + skinsize, skinsize)) {
skin->colora = Vulkan_LoadTex (ctx, &skin_tex, 1,
va (ctx->va_ctx, "%s:%d:%d:colora",
mod->name, snum, gnum));
alias_ctx->mod->name, snum, gnum));
Skin_ClearTopColors (tskin, tskin, skinsize);
}
if (Skin_CalcBottomColors (tskin, tskin + skinsize, skinsize)) {
skin->colorb = Vulkan_LoadTex (ctx, &skin_tex, 1,
va (ctx->va_ctx, "%s:%d:%d:colorb",
mod->name, snum, gnum));
alias_ctx->mod->name, snum, gnum));
Skin_ClearBottomColors (tskin, tskin, skinsize);
}
skin_tex.data = tskin;
skin->tex = Vulkan_LoadTex (ctx, &skin_tex, 1,
va (ctx->va_ctx, "%s:%d:%d:tex",
mod->name,
alias_ctx->mod->name,
snum, gnum));
free (tskin);
@ -158,14 +159,14 @@ Vulkan_Mod_LoadSkin (model_t *mod, byte *skinpix, int skinsize, int snum,
}
void
Vulkan_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr, vulkan_ctx_t *ctx)
Vulkan_Mod_FinalizeAliasModel (mod_alias_ctx_t *alias_ctx, vulkan_ctx_t *ctx)
{
m->clear = vulkan_alias_clear;
m->data = ctx;
alias_ctx->mod->clear = vulkan_alias_clear;
alias_ctx->mod->data = ctx;
}
void
Vulkan_Mod_LoadExternalSkins (model_t *mod, vulkan_ctx_t *ctx)
Vulkan_Mod_LoadExternalSkins (mod_alias_ctx_t *alias_ctx, vulkan_ctx_t *ctx)
{
}
@ -185,9 +186,10 @@ get_buffer_size (qfv_device_t *device, VkBuffer buffer)
}
void
Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
Vulkan_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m,
int _s, int extra, vulkan_ctx_t *ctx)
{
aliashdr_t *header = alias_ctx->header;
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
aliasvrt_t *verts;
@ -201,11 +203,11 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
int pose;
vec3_t pos;
if (hdr->mdl.ident == HEADER_MDL16)
VectorScale (hdr->mdl.scale, 1/256.0, hdr->mdl.scale);
if (header->mdl.ident == HEADER_MDL16)
VectorScale (header->mdl.scale, 1/256.0, header->mdl.scale);
numverts = hdr->mdl.numverts;
numtris = hdr->mdl.numtris;
numverts = header->mdl.numverts;
numtris = header->mdl.numtris;
// initialize indexmap to -1 (unduplicated). any other value indicates
// both that the vertex has been duplicated and the index of the
@ -217,8 +219,9 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
// back-facing triangles
for (i = 0; i < numtris; i++) {
for (j = 0; j < 3; j++) {
int vind = triangles.a[i].vertindex[j];
if (stverts.a[vind].onseam && !triangles.a[i].facesfront) {
int vind = alias_ctx->triangles.a[i].vertindex[j];
if (alias_ctx->stverts.a[vind].onseam
&& !alias_ctx->triangles.a[i].facesfront) {
// duplicate the vertex if it has not alreaddy been
// duplicated
if (indexmap[vind] == -1) {
@ -239,7 +242,7 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
// current and previous pose, uvbuff "statically" bound as uvs are not
// animated by pose, and the same for ibuf: indices will never change for
// the mesh
size_t vert_count = numverts * hdr->numposes;
size_t vert_count = numverts * header->numposes;
size_t vert_size = vert_count * sizeof (aliasvrt_t);
size_t uv_size = numverts * sizeof (aliasuv_t);
size_t ind_size = 3 * numtris * sizeof (uint32_t);
@ -255,13 +258,13 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
| VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
QFV_duSetObjectName (device, VK_OBJECT_TYPE_BUFFER, vbuff,
va (ctx->va_ctx, "buffer:alias:vertex:%s",
mod->name));
alias_ctx->mod->name));
QFV_duSetObjectName (device, VK_OBJECT_TYPE_BUFFER, uvbuff,
va (ctx->va_ctx, "buffer:alias:uv:%s",
mod->name));
alias_ctx->mod->name));
QFV_duSetObjectName (device, VK_OBJECT_TYPE_BUFFER, ibuff,
va (ctx->va_ctx, "buffer:alias:index:%s",
mod->name));
alias_ctx->mod->name));
size_t voffs = 0;
size_t uvoffs = voffs + get_buffer_size (device, vbuff);
size_t ioffs = uvoffs + get_buffer_size (device, uvbuff);
@ -272,7 +275,7 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
buff_size, 0);
QFV_duSetObjectName (device, VK_OBJECT_TYPE_DEVICE_MEMORY, mem,
va (ctx->va_ctx, "memory:alias:vuvi:%s",
mod->name));
alias_ctx->mod->name));
QFV_BindBufferMemory (device, vbuff, mem, voffs);
QFV_BindBufferMemory (device, uvbuff, mem, uvoffs);
QFV_BindBufferMemory (device, ibuff, mem, ioffs);
@ -280,7 +283,7 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
qfv_stagebuf_t *stage = QFV_CreateStagingBuffer (device,
va (ctx->va_ctx,
"alias:%s",
mod->name),
alias_ctx->mod->name),
buff_size, ctx->cmdpool);
qfv_packet_t *packet = QFV_PacketAcquire (stage);
verts = QFV_PacketExtend (packet, vert_size);
@ -291,10 +294,10 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
// and associated with back-facing triangles (marked by non-negative
// indexmap entry).
// the s coordinate is shifted right by half the skin width.
for (i = 0; i < hdr->mdl.numverts; i++) {
for (i = 0; i < header->mdl.numverts; i++) {
int vind = indexmap[i];
uv[i].u = (float) stverts.a[i].s / hdr->mdl.skinwidth;
uv[i].v = (float) stverts.a[i].t / hdr->mdl.skinheight;
uv[i].u = (float) alias_ctx->stverts.a[i].s / header->mdl.skinwidth;
uv[i].v = (float) alias_ctx->stverts.a[i].t / header->mdl.skinheight;
if (vind != -1) {
uv[vind] = uv[i];
uv[vind].u += 0.5;
@ -303,15 +306,15 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
// poputlate the vertex position and normal data, duplicating for
// back-facing on-seam verts (indicated by non-negative indexmap entry)
for (i = 0, pose = 0; i < hdr->numposes; i++, pose += numverts) {
for (j = 0; j < hdr->mdl.numverts; j++) {
pv = &poseverts.a[i][j];
for (i = 0, pose = 0; i < header->numposes; i++, pose += numverts) {
for (j = 0; j < header->mdl.numverts; j++) {
pv = &alias_ctx->poseverts.a[i][j];
if (extra) {
VectorMultAdd (pv[hdr->mdl.numverts].v, 256, pv->v, pos);
VectorMultAdd (pv[header->mdl.numverts].v, 256, pv->v, pos);
} else {
VectorCopy (pv->v, pos);
}
VectorCompMultAdd (hdr->mdl.scale_origin, hdr->mdl.scale,
VectorCompMultAdd (header->mdl.scale_origin, header->mdl.scale,
pos, verts[pose + j].vertex);
verts[pose + j].vertex[3] = 1;
VectorCopy (vertex_normals[pv->lightnormalindex],
@ -327,8 +330,9 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
// now build the indices for DrawElements
for (i = 0; i < numtris; i++) {
for (j = 0; j < 3; j++) {
int vind = triangles.a[i].vertindex[j];
if (stverts.a[vind].onseam && !triangles.a[i].facesfront) {
int vind = alias_ctx->triangles.a[i].vertindex[j];
if (alias_ctx->stverts.a[vind].onseam
&& !alias_ctx->triangles.a[i].facesfront) {
vind = indexmap[vind];
}
indices[3 * i + j] = vind;
@ -337,7 +341,7 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
// finished with indexmap
free (indexmap);
hdr->poseverts = numverts;
header->poseverts = numverts;
VkBufferMemoryBarrier wr_barriers[] = {
{ VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, 0,
@ -394,5 +398,5 @@ Vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr, void *_m,
mesh->uv_buffer = uvbuff;
mesh->index_buffer = ibuff;
mesh->memory = mem;
hdr->commands = (byte *) mesh - (byte *) hdr;
header->commands = (byte *) mesh - (byte *) header;
}

View file

@ -50,8 +50,8 @@ static vid_model_funcs_t model_funcs = {
sw_Mod_MakeAliasModelDisplayLists,
sw_Mod_LoadSkin,
sw_Mod_FinalizeAliasModel,
sw_Mod_LoadExternalSkins,
0,
0,
sw_Mod_IQMFinish,
1,
sw_Mod_SpriteLoadTexture,

View file

@ -55,8 +55,8 @@ static vid_model_funcs_t model_funcs = {
sw_Mod_MakeAliasModelDisplayLists,
sw_Mod_LoadSkin,
sw_Mod_FinalizeAliasModel,
sw_Mod_LoadExternalSkins,
0,
0,
sw_Mod_IQMFinish,
1,
sw_Mod_SpriteLoadTexture,

View file

@ -418,28 +418,30 @@ vulkan_Mod_ProcessTexture (model_t *mod, texture_t *tx)
}
static void
vulkan_Mod_MakeAliasModelDisplayLists (model_t *mod, aliashdr_t *hdr,
vulkan_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx,
void *_m, int _s, int extra)
{
Vulkan_Mod_MakeAliasModelDisplayLists (mod, hdr, _m, _s, extra, vulkan_ctx);
Vulkan_Mod_MakeAliasModelDisplayLists (alias_ctx, _m, _s, extra,
vulkan_ctx);
}
static void *
vulkan_Mod_LoadSkin (model_t *mod, byte *skin, int skinsize, int snum,
int gnum, qboolean group, maliasskindesc_t *skindesc)
vulkan_Mod_LoadSkin (mod_alias_ctx_t *alias_ctx, byte *skin, int skinsize,
int snum, int gnum, qboolean group,
maliasskindesc_t *skindesc)
{
return Vulkan_Mod_LoadSkin (mod, skin, skinsize, snum, gnum, group,
return Vulkan_Mod_LoadSkin (alias_ctx, skin, skinsize, snum, gnum, group,
skindesc, vulkan_ctx);
}
static void
vulkan_Mod_FinalizeAliasModel (model_t *m, aliashdr_t *hdr)
vulkan_Mod_FinalizeAliasModel (mod_alias_ctx_t *alias_ctx)
{
Vulkan_Mod_FinalizeAliasModel (m, hdr, vulkan_ctx);
Vulkan_Mod_FinalizeAliasModel (alias_ctx, vulkan_ctx);
}
static void
vulkan_Mod_LoadExternalSkins (model_t *mod)
vulkan_Mod_LoadExternalSkins (mod_alias_ctx_t *alias_ctx)
{
}