2006-04-13 20:47:06 +00:00
|
|
|
//------------------------------------- MD2/MD3 LIBRARY BEGINS -------------------------------------
|
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
#ifdef USE_OPENGL
|
2008-12-04 00:31:16 +00:00
|
|
|
|
2008-12-02 10:44:39 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "build.h"
|
2018-02-16 06:38:21 +00:00
|
|
|
#include "glad/glad.h"
|
2008-12-02 10:44:39 +00:00
|
|
|
#include "pragmas.h"
|
|
|
|
#include "baselayer.h"
|
|
|
|
#include "engine_priv.h"
|
|
|
|
#include "hightile.h"
|
|
|
|
#include "polymost.h"
|
2013-05-15 02:17:17 +00:00
|
|
|
#include "texcache.h"
|
2008-05-05 09:05:07 +00:00
|
|
|
#include "mdsprite.h"
|
2008-12-02 10:44:39 +00:00
|
|
|
#include "cache1d.h"
|
|
|
|
#include "kplib.h"
|
2014-10-25 03:27:35 +00:00
|
|
|
#include "common.h"
|
2016-06-21 00:33:06 +00:00
|
|
|
#include "palette.h"
|
2008-12-02 10:44:39 +00:00
|
|
|
|
2012-01-12 20:48:38 +00:00
|
|
|
static int32_t curextra=MAXTILES;
|
2007-12-20 19:14:38 +00:00
|
|
|
|
2011-09-28 20:30:24 +00:00
|
|
|
#define MIN_CACHETIME_PRINT 10
|
2011-01-30 11:02:28 +00:00
|
|
|
|
|
|
|
|
2012-01-07 17:48:55 +00:00
|
|
|
static int32_t addtileP(int32_t model,int32_t tile,int32_t pallet)
|
2007-12-20 19:14:38 +00:00
|
|
|
{
|
2012-01-19 21:57:22 +00:00
|
|
|
// tile >= 0 && tile < MAXTILES
|
|
|
|
|
2008-03-22 10:23:57 +00:00
|
|
|
UNREFERENCED_PARAMETER(model);
|
2012-01-19 21:57:22 +00:00
|
|
|
if (curextra==MAXTILES+EXTRATILES-1)
|
2012-01-19 21:58:06 +00:00
|
|
|
{
|
|
|
|
initprintf("warning: max EXTRATILES reached\n");
|
2012-01-19 21:57:22 +00:00
|
|
|
return curextra;
|
2012-01-19 21:58:06 +00:00
|
|
|
}
|
2012-01-19 21:57:22 +00:00
|
|
|
|
|
|
|
if (tile2model[tile].modelid==-1)
|
|
|
|
{
|
|
|
|
tile2model[tile].pal=pallet;
|
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tile2model[tile].pal==pallet)
|
|
|
|
return tile;
|
|
|
|
|
2015-03-24 00:40:48 +00:00
|
|
|
while (tile2model[tile].nexttile!=-1)
|
2008-01-04 01:04:35 +00:00
|
|
|
{
|
2015-03-24 00:40:48 +00:00
|
|
|
tile=tile2model[tile].nexttile;
|
2012-01-19 21:57:22 +00:00
|
|
|
if (tile2model[tile].pal==pallet)
|
|
|
|
return tile;
|
2008-01-04 01:04:35 +00:00
|
|
|
}
|
2012-01-19 21:57:22 +00:00
|
|
|
|
2015-03-24 00:40:48 +00:00
|
|
|
tile2model[tile].nexttile=curextra;
|
2007-12-20 19:14:38 +00:00
|
|
|
tile2model[curextra].pal=pallet;
|
2012-01-19 21:57:22 +00:00
|
|
|
|
2007-12-20 19:14:38 +00:00
|
|
|
return curextra++;
|
|
|
|
}
|
2015-03-24 00:40:48 +00:00
|
|
|
|
|
|
|
int32_t Ptile2tile(int32_t tile,int32_t palette)
|
2007-12-20 19:14:38 +00:00
|
|
|
{
|
2015-03-24 00:40:48 +00:00
|
|
|
int t = tile;
|
|
|
|
while ((tile = tile2model[tile].nexttile) != -1)
|
|
|
|
if (tile2model[tile].pal == palette)
|
|
|
|
{
|
|
|
|
t = tile;
|
|
|
|
break;
|
|
|
|
}
|
2007-12-20 19:14:38 +00:00
|
|
|
return t;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#define MODELALLOCGROUP 256
|
2012-01-19 21:57:22 +00:00
|
|
|
static int32_t nummodelsalloced = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t maxmodelverts = 0, allocmodelverts = 0;
|
|
|
|
static int32_t maxmodeltris = 0, allocmodeltris = 0;
|
2014-09-30 04:18:43 +00:00
|
|
|
static vec3f_t *vertlist = NULL; //temp array to store interpolated vertices for drawing
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t allocvbos = 0, curvbo = 0;
|
2011-01-16 02:50:27 +00:00
|
|
|
static GLuint *vertvbos = NULL;
|
|
|
|
static GLuint *indexvbos = NULL;
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2014-11-25 23:46:28 +00:00
|
|
|
#ifdef POLYMER
|
2014-09-30 04:18:43 +00:00
|
|
|
static int32_t *tribuf = NULL;
|
|
|
|
static int32_t tribufverts = 0;
|
2014-11-25 23:46:28 +00:00
|
|
|
#endif
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2012-01-10 23:45:34 +00:00
|
|
|
static mdmodel_t *mdload(const char *);
|
2012-01-07 17:48:55 +00:00
|
|
|
static void mdfree(mdmodel_t *);
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t globalnoeffect=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
extern int32_t timerticspersec;
|
2006-10-05 07:39:37 +00:00
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2014-09-30 04:18:43 +00:00
|
|
|
void md_freevbos()
|
2009-06-13 21:06:45 +00:00
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i=0; i<nextmodelid; i++)
|
|
|
|
if (models[i]->mdnum == 3)
|
|
|
|
{
|
|
|
|
md3model_t *m = (md3model_t *)models[i];
|
|
|
|
if (m->vbos)
|
|
|
|
{
|
|
|
|
// OSD_Printf("freeing model %d vbo\n",i);
|
2018-02-16 06:38:21 +00:00
|
|
|
glDeleteBuffers(m->head.numsurfs, m->vbos);
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(m->vbos);
|
2009-06-13 21:06:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (allocvbos)
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glDeleteBuffers(allocvbos, indexvbos);
|
|
|
|
glDeleteBuffers(allocvbos, vertvbos);
|
2009-06-24 08:20:10 +00:00
|
|
|
allocvbos = 0;
|
|
|
|
}
|
2009-06-13 21:06:45 +00:00
|
|
|
}
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2009-06-13 21:06:45 +00:00
|
|
|
|
2008-12-02 10:44:39 +00:00
|
|
|
void freeallmodels()
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (models)
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<nextmodelid; i++) mdfree(models[i]);
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(models);
|
2006-04-13 20:47:06 +00:00
|
|
|
nummodelsalloced = 0;
|
|
|
|
nextmodelid = 0;
|
|
|
|
}
|
|
|
|
|
2015-03-24 00:40:48 +00:00
|
|
|
Bmemset(tile2model,-1,sizeof(tile2model));
|
|
|
|
for (i=0; i<MAXTILES; i++)
|
|
|
|
Bmemset(tile2model[i].hudmem, 0, sizeof(tile2model[i].hudmem));
|
|
|
|
|
2007-12-20 19:14:38 +00:00
|
|
|
curextra=MAXTILES;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (vertlist)
|
|
|
|
{
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(vertlist);
|
2006-04-13 20:47:06 +00:00
|
|
|
allocmodelverts = maxmodelverts = 0;
|
2007-03-08 03:07:10 +00:00
|
|
|
allocmodeltris = maxmodeltris = 0;
|
|
|
|
}
|
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2014-09-30 04:18:43 +00:00
|
|
|
md_freevbos();
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2014-11-25 23:46:28 +00:00
|
|
|
#ifdef POLYMER
|
2014-09-30 04:18:43 +00:00
|
|
|
DO_FREE_AND_NULL(tribuf);
|
2014-11-25 23:46:28 +00:00
|
|
|
#endif
|
2009-01-04 22:22:33 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 20:54:52 +00:00
|
|
|
|
|
|
|
// Skin texture names can be aliased! This is ugly, but at least correct.
|
|
|
|
static void nullskintexids(GLuint texid)
|
|
|
|
{
|
|
|
|
int32_t i, j;
|
|
|
|
|
|
|
|
for (i=0; i<nextmodelid; i++)
|
|
|
|
{
|
|
|
|
mdmodel_t *m = models[i];
|
|
|
|
|
|
|
|
if (m->mdnum == 2 || m->mdnum == 3)
|
|
|
|
{
|
|
|
|
mdskinmap_t *sk;
|
|
|
|
md2model_t *m2 = (md2model_t *)m;
|
|
|
|
|
2017-06-21 13:46:36 +00:00
|
|
|
for (j=0; j < m2->numskins * HICTINT_MEMORY_COMBINATIONS; j++)
|
2012-04-29 20:54:52 +00:00
|
|
|
if (m2->texid[j] == texid)
|
|
|
|
m2->texid[j] = 0;
|
|
|
|
|
|
|
|
for (sk=m2->skinmap; sk; sk=sk->next)
|
2017-06-21 13:46:36 +00:00
|
|
|
for (j=0; j < HICTINT_MEMORY_COMBINATIONS; j++)
|
2012-04-29 20:54:52 +00:00
|
|
|
if (sk->texid[j] == texid)
|
|
|
|
sk->texid[j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-26 15:42:09 +00:00
|
|
|
void clearskins(int32_t type)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<nextmodelid; i++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-04-29 20:54:52 +00:00
|
|
|
mdmodel_t *m = models[i];
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (m->mdnum == 1)
|
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
voxmodel_t *v = (voxmodel_t *)m;
|
2012-04-29 20:54:52 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<MAXPALOOKUPS; j++)
|
2012-04-29 20:54:52 +00:00
|
|
|
if (v->texid[j])
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glDeleteTextures(1, &v->texid[j]);
|
2012-04-29 20:54:52 +00:00
|
|
|
v->texid[j] = 0;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2015-12-26 15:42:09 +00:00
|
|
|
else if ((m->mdnum == 2 || m->mdnum == 3) && type == INVALIDATE_ALL)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
mdskinmap_t *sk;
|
2012-04-29 20:54:52 +00:00
|
|
|
md2model_t *m2 = (md2model_t *)m;
|
|
|
|
|
2017-06-21 13:46:36 +00:00
|
|
|
for (j=0; j < m2->numskins * HICTINT_MEMORY_COMBINATIONS; j++)
|
2012-04-29 20:54:52 +00:00
|
|
|
if (m2->texid[j])
|
|
|
|
{
|
|
|
|
GLuint otexid = m2->texid[j];
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glDeleteTextures(1, &m2->texid[j]);
|
2012-04-29 20:54:52 +00:00
|
|
|
m2->texid[j] = 0;
|
|
|
|
|
|
|
|
nullskintexids(otexid);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (sk=m2->skinmap; sk; sk=sk->next)
|
2017-06-21 13:46:36 +00:00
|
|
|
for (j=0; j < HICTINT_MEMORY_COMBINATIONS; j++)
|
2012-04-29 20:54:52 +00:00
|
|
|
if (sk->texid[j])
|
|
|
|
{
|
|
|
|
GLuint otexid = sk->texid[j];
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glDeleteTextures(1, &sk->texid[j]);
|
2012-04-29 20:54:52 +00:00
|
|
|
sk->texid[j] = 0;
|
|
|
|
|
|
|
|
nullskintexids(otexid);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<MAXVOXELS; i++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-04-29 20:54:52 +00:00
|
|
|
voxmodel_t *v = voxmodels[i];
|
|
|
|
if (!v) continue;
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<MAXPALOOKUPS; j++)
|
2012-04-29 20:54:52 +00:00
|
|
|
if (v->texid[j])
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glDeleteTextures(1, &v->texid[j]);
|
2012-04-29 20:54:52 +00:00
|
|
|
v->texid[j] = 0;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-02 10:44:39 +00:00
|
|
|
void mdinit()
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
freeallmodels();
|
|
|
|
mdinited = 1;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t md_loadmodel(const char *fn)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
mdmodel_t *vm, **ml;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (!mdinited) mdinit();
|
|
|
|
|
|
|
|
if (nextmodelid >= nummodelsalloced)
|
|
|
|
{
|
2014-05-30 00:02:19 +00:00
|
|
|
ml = (mdmodel_t **)Xrealloc(models,(nummodelsalloced+MODELALLOCGROUP)*sizeof(void *));
|
2006-04-13 20:47:06 +00:00
|
|
|
models = ml; nummodelsalloced += MODELALLOCGROUP;
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
vm = mdload(fn); if (!vm) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
models[nextmodelid++] = vm;
|
2016-06-21 00:34:41 +00:00
|
|
|
return nextmodelid-1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 04:31:59 +00:00
|
|
|
int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, float yoffset, int32_t flags)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
mdmodel_t *m;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (!mdinited) mdinit();
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)modelid >= (uint32_t)nextmodelid) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
m = models[modelid];
|
|
|
|
m->bscale = scale;
|
|
|
|
m->shadeoff = shadeoff;
|
|
|
|
m->zadd = zadd;
|
2012-01-17 04:31:59 +00:00
|
|
|
m->yoffset = yoffset;
|
2007-12-20 19:14:38 +00:00
|
|
|
m->flags = flags;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
static int32_t framename2index(mdmodel_t *vm, const char *nam)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
switch (vm->mdnum)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
case 2:
|
2006-11-13 23:12:47 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
md2model_t *m = (md2model_t *)vm;
|
2006-11-13 23:12:47 +00:00
|
|
|
md2frame_t *fr;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<m->numframes; i++)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
fr = (md2frame_t *)&m->frames[i*m->framebytes];
|
|
|
|
if (!Bstrcmp(fr->name, nam)) break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-11-13 23:12:47 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
case 3:
|
2006-11-13 23:12:47 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
md3model_t *m = (md3model_t *)vm;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<m->numframes; i++)
|
2006-11-13 23:12:47 +00:00
|
|
|
if (!Bstrcmp(m->head.frames[i].nam,nam)) break;
|
|
|
|
}
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2016-06-21 00:34:41 +00:00
|
|
|
return i;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t md_defineframe(int32_t modelid, const char *framename, int32_t tilenume, int32_t skinnum, float smoothduration, int32_t pal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
md2model_t *m;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (!mdinited) mdinit();
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
if ((uint32_t)modelid >= (uint32_t)nextmodelid) return -1;
|
|
|
|
if ((uint32_t)tilenume >= (uint32_t)MAXTILES) return -2;
|
|
|
|
if (!framename) return -3;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-20 19:14:38 +00:00
|
|
|
tilenume=addtileP(modelid,tilenume,pal);
|
2009-01-10 07:38:50 +00:00
|
|
|
m = (md2model_t *)models[modelid];
|
2007-12-12 17:42:14 +00:00
|
|
|
if (m->mdnum == 1)
|
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
tile2model[tilenume].modelid = modelid;
|
|
|
|
tile2model[tilenume].framenum = tile2model[tilenume].skinnum = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
i = framename2index((mdmodel_t *)m,framename);
|
2016-06-21 00:34:41 +00:00
|
|
|
if (i == m->numframes) return -3; // frame name invalid
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
tile2model[tilenume].modelid = modelid;
|
|
|
|
tile2model[tilenume].framenum = i;
|
|
|
|
tile2model[tilenume].skinnum = skinnum;
|
2015-03-24 00:40:48 +00:00
|
|
|
tile2model[tilenume].smoothduration = Blrintf((float)UINT16_MAX * smoothduration);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-06-19 18:30:32 +00:00
|
|
|
return i;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t md_defineanimation(int32_t modelid, const char *framestart, const char *frameend, int32_t fpssc, int32_t flags)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
md2model_t *m;
|
2006-04-13 20:47:06 +00:00
|
|
|
mdanim_t ma, *map;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (!mdinited) mdinit();
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
if ((uint32_t)modelid >= (uint32_t)nextmodelid) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
Bmemset(&ma, 0, sizeof(ma));
|
2009-01-10 07:38:50 +00:00
|
|
|
m = (md2model_t *)models[modelid];
|
2006-04-13 20:47:06 +00:00
|
|
|
if (m->mdnum < 2) return 0;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//find index of start frame
|
2011-01-16 02:50:27 +00:00
|
|
|
i = framename2index((mdmodel_t *)m,framestart);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (i == m->numframes) return -2;
|
|
|
|
ma.startframe = i;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//find index of finish frame which must trail start frame
|
2011-01-16 02:50:27 +00:00
|
|
|
i = framename2index((mdmodel_t *)m,frameend);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (i == m->numframes) return -3;
|
|
|
|
ma.endframe = i;
|
|
|
|
|
|
|
|
ma.fpssc = fpssc;
|
|
|
|
ma.flags = flags;
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
map = (mdanim_t *)Xmalloc(sizeof(mdanim_t));
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(map, &ma, sizeof(ma));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
map->next = m->animations;
|
|
|
|
m->animations = map;
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 20:48:38 +00:00
|
|
|
#if 0
|
|
|
|
// FIXME: CURRENTLY DISABLED: interpolation may access frames we consider 'unused'?
|
2011-06-19 18:30:32 +00:00
|
|
|
int32_t md_thinoutmodel(int32_t modelid, uint8_t *usedframebitmap)
|
|
|
|
{
|
|
|
|
md3model_t *m;
|
|
|
|
md3surf_t *s;
|
|
|
|
mdanim_t *anm;
|
|
|
|
int32_t i, surfi, sub, usedframes;
|
|
|
|
static int16_t otonframe[1024];
|
|
|
|
|
|
|
|
if ((uint32_t)modelid >= (uint32_t)nextmodelid) return -1;
|
|
|
|
m = (md3model_t *)models[modelid];
|
|
|
|
if (m->mdnum != 3) return -2;
|
|
|
|
|
|
|
|
for (anm=m->animations; anm; anm=anm->next)
|
|
|
|
{
|
|
|
|
if (anm->endframe <= anm->startframe)
|
|
|
|
{
|
|
|
|
// initprintf("backward anim %d-%d\n", anm->startframe, anm->endframe);
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=anm->startframe; i<anm->endframe; i++)
|
|
|
|
usedframebitmap[i>>3] |= (1<<(i&7));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub = 0;
|
|
|
|
for (i=0; i<m->numframes; i++)
|
|
|
|
{
|
|
|
|
if (!(usedframebitmap[i>>3]&(1<<(i&7))))
|
|
|
|
{
|
|
|
|
sub++;
|
|
|
|
otonframe[i] = -1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
otonframe[i] = i-sub;
|
|
|
|
}
|
|
|
|
|
|
|
|
usedframes = m->numframes - sub;
|
|
|
|
if (usedframes==0 || usedframes==m->numframes)
|
|
|
|
return usedframes;
|
|
|
|
|
|
|
|
//// THIN OUT! ////
|
|
|
|
|
|
|
|
for (i=0; i<m->numframes; i++)
|
|
|
|
{
|
|
|
|
if (otonframe[i]>=0 && otonframe[i] != i)
|
|
|
|
{
|
|
|
|
if (m->muladdframes)
|
2014-09-30 04:18:43 +00:00
|
|
|
Bmemcpy(&m->muladdframes[2*otonframe[i]], &m->muladdframes[2*i], 2*sizeof(vec3f_t));
|
2011-06-19 18:30:32 +00:00
|
|
|
Bmemcpy(&m->head.frames[otonframe[i]], &m->head.frames[i], sizeof(md3frame_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (surfi=0; surfi < m->head.numsurfs; surfi++)
|
|
|
|
{
|
|
|
|
s = &m->head.surfs[surfi];
|
|
|
|
|
|
|
|
for (i=0; i<m->numframes; i++)
|
|
|
|
if (otonframe[i]>=0 && otonframe[i] != i)
|
|
|
|
Bmemcpy(&s->xyzn[otonframe[i]*s->numverts], &s->xyzn[i*s->numverts], s->numverts*sizeof(md3xyzn_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
////// tweak frame indices in various places
|
|
|
|
|
|
|
|
for (anm=m->animations; anm; anm=anm->next)
|
|
|
|
{
|
|
|
|
if (otonframe[anm->startframe]==-1 || otonframe[anm->endframe-1]==-1)
|
|
|
|
initprintf("md %d WTF: anm %d %d\n", modelid, anm->startframe, anm->endframe);
|
|
|
|
|
|
|
|
anm->startframe = otonframe[anm->startframe];
|
|
|
|
anm->endframe = otonframe[anm->endframe-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<MAXTILES+EXTRATILES; i++)
|
|
|
|
if (tile2model[i].modelid == modelid)
|
|
|
|
{
|
|
|
|
if (otonframe[tile2model[i].framenum]==-1)
|
|
|
|
initprintf("md %d WTF: tile %d, fr %d\n", modelid, i, tile2model[i].framenum);
|
|
|
|
tile2model[i].framenum = otonframe[tile2model[i].framenum];
|
|
|
|
}
|
|
|
|
|
|
|
|
////// realloc & change "numframes" everywhere
|
|
|
|
|
|
|
|
if (m->muladdframes)
|
2014-09-30 04:18:43 +00:00
|
|
|
m->muladdframes = Xrealloc(m->muladdframes, 2*sizeof(vec3f_t)*usedframes);
|
2014-05-30 00:02:19 +00:00
|
|
|
m->head.frames = Xrealloc(m->head.frames, sizeof(md3frame_t)*usedframes);
|
2011-06-19 18:30:32 +00:00
|
|
|
|
|
|
|
for (surfi=0; surfi < m->head.numsurfs; surfi++)
|
|
|
|
{
|
|
|
|
m->head.surfs[surfi].numframes = usedframes;
|
|
|
|
// CAN'T do that because xyzn is offset from a larger block when loaded from md3:
|
2014-05-30 00:02:19 +00:00
|
|
|
// m->head.surfs[surfi].xyzn = Xrealloc(m->head.surfs[surfi].xyzn, s->numverts*usedframes*sizeof(md3xyzn_t));
|
2011-06-19 18:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m->head.numframes = usedframes;
|
|
|
|
m->numframes = usedframes;
|
|
|
|
|
|
|
|
////////////
|
|
|
|
return usedframes;
|
|
|
|
}
|
2012-01-12 20:48:38 +00:00
|
|
|
#endif
|
2011-06-19 18:30:32 +00:00
|
|
|
|
2015-03-28 09:49:11 +00:00
|
|
|
int32_t md_defineskin(int32_t modelid, const char *skinfn, int32_t palnum, int32_t skinnum, int32_t surfnum, float param, float specpower, float specfactor, int32_t flags)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
mdskinmap_t *sk, *skl;
|
2009-01-10 07:38:50 +00:00
|
|
|
md2model_t *m;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (!mdinited) mdinit();
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)modelid >= (uint32_t)nextmodelid) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!skinfn) return -2;
|
|
|
|
if ((unsigned)palnum >= (unsigned)MAXPALOOKUPS) return -3;
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
m = (md2model_t *)models[modelid];
|
2006-04-13 20:47:06 +00:00
|
|
|
if (m->mdnum < 2) return 0;
|
|
|
|
if (m->mdnum == 2) surfnum = 0;
|
|
|
|
|
|
|
|
skl = NULL;
|
|
|
|
for (sk = m->skinmap; sk; skl = sk, sk = sk->next)
|
2012-04-29 20:54:52 +00:00
|
|
|
if (sk->palette == (uint8_t)palnum && skinnum == sk->skinnum && surfnum == sk->surfnum)
|
|
|
|
break;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!sk)
|
|
|
|
{
|
2014-05-30 00:02:19 +00:00
|
|
|
sk = (mdskinmap_t *)Xcalloc(1,sizeof(mdskinmap_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (!skl) m->skinmap = sk;
|
|
|
|
else skl->next = sk;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2015-09-23 17:55:31 +00:00
|
|
|
else Bfree(sk->fn);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
sk->palette = (uint8_t)palnum;
|
2015-03-28 09:49:11 +00:00
|
|
|
sk->flags = (uint8_t)flags;
|
2006-04-13 20:47:06 +00:00
|
|
|
sk->skinnum = skinnum;
|
|
|
|
sk->surfnum = surfnum;
|
2007-02-16 01:34:41 +00:00
|
|
|
sk->param = param;
|
2009-03-28 15:19:44 +00:00
|
|
|
sk->specpower = specpower;
|
|
|
|
sk->specfactor = specfactor;
|
2014-05-30 00:02:19 +00:00
|
|
|
sk->fn = Xstrdup(skinfn);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-24 00:40:48 +00:00
|
|
|
int32_t md_definehud(int32_t modelid, int32_t tilex, vec3f_t add, int32_t angadd, int32_t flags, int32_t fov)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
if (!mdinited) mdinit();
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)modelid >= (uint32_t)nextmodelid) return -1;
|
|
|
|
if ((uint32_t)tilex >= (uint32_t)MAXTILES) return -2;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2015-03-24 00:40:48 +00:00
|
|
|
tile2model[tilex].hudmem[(flags>>2)&1] = (hudtyp *)Xmalloc(sizeof(hudtyp));
|
|
|
|
|
|
|
|
hudtyp * const hud = tile2model[tilex].hudmem[(flags>>2)&1];
|
|
|
|
|
|
|
|
hud->add = add;
|
|
|
|
hud->angadd = ((int16_t)angadd)|2048;
|
|
|
|
hud->flags = (int16_t)flags;
|
|
|
|
hud->fov = (int16_t)fov;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t md_undefinetile(int32_t tile)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
if (!mdinited) return 0;
|
|
|
|
if ((unsigned)tile >= (unsigned)MAXTILES) return -1;
|
|
|
|
|
|
|
|
tile2model[tile].modelid = -1;
|
2015-03-24 00:40:48 +00:00
|
|
|
tile2model[tile].nexttile = -1;
|
2015-03-28 09:48:21 +00:00
|
|
|
DO_FREE_AND_NULL(tile2model[tile].hudmem[0]);
|
|
|
|
DO_FREE_AND_NULL(tile2model[tile].hudmem[1]);
|
2006-04-13 20:47:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-07 17:48:55 +00:00
|
|
|
/* this function is problematic, it leaves NULL holes in model[]
|
|
|
|
* (which runs from 0 to nextmodelid-1) */
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t md_undefinemodel(int32_t modelid)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!mdinited) return 0;
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)modelid >= (uint32_t)nextmodelid) return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-20 19:14:38 +00:00
|
|
|
for (i=MAXTILES+EXTRATILES-1; i>=0; i--)
|
2006-04-13 20:47:06 +00:00
|
|
|
if (tile2model[i].modelid == modelid)
|
2015-03-24 00:40:48 +00:00
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
tile2model[i].modelid = -1;
|
2015-03-24 00:40:48 +00:00
|
|
|
DO_FREE_AND_NULL(tile2model[i].hudmem[0]);
|
|
|
|
DO_FREE_AND_NULL(tile2model[i].hudmem[1]);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (models)
|
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
mdfree(models[modelid]);
|
|
|
|
models[modelid] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-21 13:46:36 +00:00
|
|
|
static inline int32_t hicfxmask(size_t pal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-21 13:46:36 +00:00
|
|
|
return globalnoeffect ? 0 : (hictinting[pal].f & HICTINT_IN_MEMORY);
|
|
|
|
}
|
|
|
|
static inline int32_t hicfxid(size_t pal)
|
|
|
|
{
|
|
|
|
return globalnoeffect ? 0 : ((hictinting[pal].f & (HICTINT_GRAYSCALE|HICTINT_INVERT|HICTINT_COLORIZE)) | ((hictinting[pal].f & HICTINT_BLENDMASK)<<3));
|
2016-03-04 19:24:54 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
static int32_t mdloadskin_notfound(char * const skinfile, char const * const fn)
|
|
|
|
{
|
|
|
|
OSD_Printf("Skin \"%s\" not found.\n", fn);
|
2011-01-09 18:53:06 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
skinfile[0] = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
static int32_t mdloadskin_failed(char * const skinfile, char const * const fn)
|
2012-04-29 20:54:22 +00:00
|
|
|
{
|
2016-03-04 19:24:54 +00:00
|
|
|
OSD_Printf("Failed loading skin file \"%s\".\n", fn);
|
|
|
|
|
|
|
|
skinfile[0] = 0;
|
|
|
|
return 0;
|
2012-04-29 20:54:22 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Note: even though it says md2model, it works for both md2model&md3model
|
2009-01-10 07:38:50 +00:00
|
|
|
int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2016-03-04 19:24:54 +00:00
|
|
|
int32_t i;
|
|
|
|
char *skinfile, fn[BMAX_PATH];
|
2006-04-24 19:04:22 +00:00
|
|
|
GLuint *texidx = NULL;
|
|
|
|
mdskinmap_t *sk, *skzero = NULL;
|
2016-03-04 19:24:54 +00:00
|
|
|
int32_t doalloc = 1;
|
2011-01-09 18:53:06 +00:00
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
if (m->mdnum == 2)
|
|
|
|
surf = 0;
|
|
|
|
|
|
|
|
if ((unsigned)pal >= (unsigned)MAXPALOOKUPS)
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
i = -1;
|
|
|
|
for (sk = m->skinmap; sk; sk = sk->next)
|
|
|
|
{
|
2012-04-29 20:54:22 +00:00
|
|
|
if (sk->palette == pal && sk->skinnum == number && sk->surfnum == surf)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
skinfile = sk->fn;
|
2017-06-21 13:46:36 +00:00
|
|
|
texidx = &sk->texid[hicfxid(pal)];
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(fn, skinfile, BMAX_PATH);
|
2006-04-13 20:47:06 +00:00
|
|
|
//OSD_Printf("Using exact match skin (pal=%d,skinnum=%d,surfnum=%d) %s\n",pal,number,surf,skinfile);
|
|
|
|
break;
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
//If no match, give highest priority to number, then pal.. (Parkar's request, 02/27/2005)
|
2012-04-29 20:54:22 +00:00
|
|
|
else if ((sk->palette == 0) && (sk->skinnum == number) && (sk->surfnum == surf) && (i < 5)) { i = 5; skzero = sk; }
|
|
|
|
else if ((sk->palette == pal) && (sk->skinnum == 0) && (sk->surfnum == surf) && (i < 4)) { i = 4; skzero = sk; }
|
|
|
|
else if ((sk->palette == 0) && (sk->skinnum == 0) && (sk->surfnum == surf) && (i < 3)) { i = 3; skzero = sk; }
|
|
|
|
else if ((sk->palette == 0) && (sk->skinnum == number) && (i < 2)) { i = 2; skzero = sk; }
|
|
|
|
else if ((sk->palette == pal) && (sk->skinnum == 0) && (i < 1)) { i = 1; skzero = sk; }
|
|
|
|
else if ((sk->palette == 0) && (sk->skinnum == 0) && (i < 0)) { i = 0; skzero = sk; }
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!sk)
|
|
|
|
{
|
2007-02-15 22:26:50 +00:00
|
|
|
if (pal >= (MAXPALOOKUPS - RESERVEDPALS))
|
2016-06-21 00:34:41 +00:00
|
|
|
return 0;
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
if (skzero)
|
|
|
|
{
|
|
|
|
skinfile = skzero->fn;
|
2017-06-21 13:46:36 +00:00
|
|
|
texidx = &skzero->texid[hicfxid(pal)];
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(fn, skinfile, BMAX_PATH);
|
2006-04-13 20:47:06 +00:00
|
|
|
//OSD_Printf("Using def skin 0,0 as fallback, pal=%d\n", pal);
|
|
|
|
}
|
|
|
|
else
|
2012-11-15 06:42:57 +00:00
|
|
|
return 0;
|
|
|
|
#if 0
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-11-15 06:42:57 +00:00
|
|
|
// fall back to the model-defined texture
|
2012-04-29 20:54:22 +00:00
|
|
|
if ((unsigned)number >= (unsigned)m->numskins)
|
|
|
|
number = 0;
|
|
|
|
|
2012-11-15 06:42:57 +00:00
|
|
|
// m->skinfn is undefined when md3model_t is cast to md2model_t --> crash
|
2006-04-13 20:47:06 +00:00
|
|
|
skinfile = m->skinfn + number*64;
|
2017-06-21 13:46:36 +00:00
|
|
|
texidx = &m->texid[number * HICTINT_MEMORY_COMBINATIONS + hicfxid(pal)];
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(fn, m->basepath, BMAX_PATH);
|
2009-07-12 01:55:34 +00:00
|
|
|
if ((Bstrlen(fn) + Bstrlen(skinfile)) < BMAX_PATH)
|
2012-04-29 20:54:22 +00:00
|
|
|
Bstrcat(fn,skinfile);
|
2006-04-13 20:47:06 +00:00
|
|
|
//OSD_Printf("Using MD2/MD3 skin (%d) %s, pal=%d\n",number,skinfile,pal);
|
|
|
|
}
|
2012-11-15 06:42:57 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2012-01-10 23:44:35 +00:00
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
if (!skinfile[0])
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
if (*texidx)
|
|
|
|
return *texidx;
|
2007-02-15 22:26:50 +00:00
|
|
|
|
2012-07-11 04:39:01 +00:00
|
|
|
// possibly fetch an already loaded multitexture :_)
|
|
|
|
if (pal >= (MAXPALOOKUPS - RESERVEDPALS))
|
2012-07-02 04:51:24 +00:00
|
|
|
for (i=0; i<nextmodelid; i++)
|
|
|
|
for (skzero = ((md2model_t *)models[i])->skinmap; skzero; skzero = skzero->next)
|
2017-06-21 13:46:36 +00:00
|
|
|
if (!Bstrcasecmp(skzero->fn, sk->fn) && skzero->texid[hicfxid(pal)])
|
2012-07-02 04:51:24 +00:00
|
|
|
{
|
2017-06-21 13:46:36 +00:00
|
|
|
size_t f = hicfxid(pal);
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2012-07-02 04:51:24 +00:00
|
|
|
sk->texid[f] = skzero->texid[f];
|
|
|
|
return sk->texid[f];
|
|
|
|
}
|
2007-02-15 22:26:50 +00:00
|
|
|
|
2015-03-30 05:56:06 +00:00
|
|
|
// for sk->flags below
|
|
|
|
if (!sk)
|
|
|
|
sk = skzero;
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
*texidx = 0;
|
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
int32_t filh;
|
2007-12-12 17:42:14 +00:00
|
|
|
if ((filh = kopen4load(fn, 0)) < 0)
|
2016-03-04 19:24:54 +00:00
|
|
|
return mdloadskin_notfound(skinfile, fn);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
int32_t picfillen = kfilelength(filh);
|
2006-04-24 19:04:22 +00:00
|
|
|
kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c
|
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t startticks = timerGetTicks(), willprint = 0;
|
2011-01-09 18:53:06 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
char hasalpha;
|
|
|
|
texcacheheader cachead;
|
2016-05-04 00:25:02 +00:00
|
|
|
char texcacheid[BMAX_PATH];
|
|
|
|
texcache_calcid(texcacheid, fn, picfillen, pal<<8, hicfxmask(pal));
|
|
|
|
int32_t gotcache = texcache_readtexheader(texcacheid, &cachead, 1);
|
2016-03-04 19:24:54 +00:00
|
|
|
vec2_t siz = { 0, 0 }, tsiz = { 0, 0 };
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
if (gotcache && !texcache_loadskin(&cachead, &doalloc, texidx, &siz))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2016-03-04 19:24:54 +00:00
|
|
|
tsiz.x = cachead.xdim;
|
|
|
|
tsiz.y = cachead.ydim;
|
2016-02-29 06:34:20 +00:00
|
|
|
hasalpha = !!(cachead.flags & CACHEAD_HASALPHA);
|
2016-03-04 19:24:54 +00:00
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
if (pal < (MAXPALOOKUPS - RESERVEDPALS))
|
|
|
|
m->usesalpha = hasalpha;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-21 13:46:44 +00:00
|
|
|
polytintflags_t const effect = hicfxmask(pal);
|
2016-03-04 19:24:54 +00:00
|
|
|
|
|
|
|
// CODEDUP: gloadtile_hi
|
|
|
|
|
|
|
|
int32_t isart = 0;
|
2011-01-30 11:02:28 +00:00
|
|
|
|
2013-05-15 02:17:17 +00:00
|
|
|
gotcache = 0; // the compressed version will be saved to disk
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
int32_t const length = kpzbufload(fn);
|
|
|
|
if (length == 0)
|
|
|
|
return mdloadskin_notfound(skinfile, fn);
|
|
|
|
|
|
|
|
// tsizx/y = replacement texture's natural size
|
|
|
|
// xsiz/y = 2^x size of replacement
|
|
|
|
|
|
|
|
#ifdef WITHKPLIB
|
|
|
|
kpgetdim(kpzbuf,picfillen,&tsiz.x,&tsiz.y);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (tsiz.x == 0 || tsiz.y == 0)
|
|
|
|
{
|
|
|
|
if (E_CheckUnitArtFileHeader((uint8_t *)kpzbuf, picfillen))
|
|
|
|
return mdloadskin_failed(skinfile, fn);
|
|
|
|
|
|
|
|
tsiz.x = B_LITTLE16(B_UNBUF16(&kpzbuf[16]));
|
|
|
|
tsiz.y = B_LITTLE16(B_UNBUF16(&kpzbuf[18]));
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
if (tsiz.x == 0 || tsiz.y == 0)
|
|
|
|
return mdloadskin_failed(skinfile, fn);
|
|
|
|
|
|
|
|
isart = 1;
|
|
|
|
}
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
if (!glinfo.texnpot)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2016-03-04 19:24:54 +00:00
|
|
|
for (siz.x=1; siz.x<tsiz.x; siz.x+=siz.x) { }
|
|
|
|
for (siz.y=1; siz.y<tsiz.y; siz.y+=siz.y) { }
|
|
|
|
}
|
|
|
|
else
|
|
|
|
siz = tsiz;
|
2011-01-30 11:02:28 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
if (isart)
|
|
|
|
{
|
|
|
|
if (tsiz.x * tsiz.y + ARTv1_UNITOFFSET > picfillen)
|
|
|
|
return mdloadskin_failed(skinfile, fn);
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2011-01-09 18:53:06 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
int32_t const bytesperline = siz.x * sizeof(coltype);
|
|
|
|
coltype *pic = (coltype *)Xcalloc(siz.y, bytesperline);
|
|
|
|
|
|
|
|
static coltype *lastpic = NULL;
|
|
|
|
static char *lastfn = NULL;
|
|
|
|
static int32_t lastsize = 0;
|
|
|
|
|
|
|
|
if (lastpic && lastfn && !Bstrcmp(lastfn,fn))
|
|
|
|
{
|
|
|
|
willprint=1;
|
|
|
|
Bmemcpy(pic, lastpic, siz.x*siz.y*sizeof(coltype));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (isart)
|
|
|
|
{
|
|
|
|
E_RenderArtDataIntoBuffer((palette_t *)pic, (uint8_t *)&kpzbuf[ARTv1_UNITOFFSET], siz.x, tsiz.x, tsiz.y);
|
|
|
|
}
|
|
|
|
#ifdef WITHKPLIB
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (kprender(kpzbuf,picfillen,(intptr_t)pic,bytesperline,siz.x,siz.y))
|
|
|
|
{
|
|
|
|
Bfree(pic);
|
|
|
|
return mdloadskin_failed(skinfile, fn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
willprint=2;
|
|
|
|
|
|
|
|
if (hicprecaching)
|
|
|
|
{
|
|
|
|
lastfn = fn; // careful...
|
|
|
|
if (!lastpic)
|
|
|
|
{
|
|
|
|
lastpic = (coltype *)Bmalloc(siz.x*siz.y*sizeof(coltype));
|
|
|
|
lastsize = siz.x*siz.y;
|
|
|
|
}
|
|
|
|
else if (lastsize < siz.x*siz.y)
|
|
|
|
{
|
|
|
|
Bfree(lastpic);
|
|
|
|
lastpic = (coltype *)Bmalloc(siz.x*siz.y*sizeof(coltype));
|
|
|
|
}
|
|
|
|
if (lastpic)
|
|
|
|
Bmemcpy(lastpic, pic, siz.x*siz.y*sizeof(coltype));
|
|
|
|
}
|
|
|
|
else if (lastpic)
|
|
|
|
{
|
|
|
|
DO_FREE_AND_NULL(lastpic);
|
|
|
|
lastfn = NULL;
|
|
|
|
lastsize = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *cptr = britable[gammabrightness ? 0 : curbrightness];
|
|
|
|
|
2017-06-21 13:46:50 +00:00
|
|
|
polytint_t const & tint = hictinting[pal];
|
|
|
|
int32_t r = (glinfo.bgra) ? tint.r : tint.b;
|
|
|
|
int32_t g = tint.g;
|
|
|
|
int32_t b = (glinfo.bgra) ? tint.b : tint.r;
|
2016-03-04 19:24:54 +00:00
|
|
|
|
|
|
|
char al = 255;
|
2016-03-07 11:22:02 +00:00
|
|
|
char onebitalpha = 1;
|
2016-03-04 19:24:54 +00:00
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t y = 0, j = 0; y < tsiz.y; ++y, j += siz.x)
|
2016-03-04 19:24:54 +00:00
|
|
|
{
|
|
|
|
coltype tcol, *rpptr = &pic[j];
|
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t x = 0; x < tsiz.x; ++x)
|
2016-03-04 19:24:54 +00:00
|
|
|
{
|
|
|
|
tcol.b = cptr[rpptr[x].b];
|
|
|
|
tcol.g = cptr[rpptr[x].g];
|
|
|
|
tcol.r = cptr[rpptr[x].r];
|
2016-03-07 11:22:02 +00:00
|
|
|
al &= tcol.a = rpptr[x].a;
|
|
|
|
onebitalpha &= tcol.a == 0 || tcol.a == 255;
|
2016-03-04 19:24:54 +00:00
|
|
|
|
|
|
|
if (effect & HICTINT_GRAYSCALE)
|
|
|
|
{
|
|
|
|
tcol.g = tcol.r = tcol.b = (uint8_t) ((tcol.b * GRAYSCALE_COEFF_RED) +
|
|
|
|
(tcol.g * GRAYSCALE_COEFF_GREEN) +
|
|
|
|
(tcol.r * GRAYSCALE_COEFF_BLUE));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (effect & HICTINT_INVERT)
|
|
|
|
{
|
|
|
|
tcol.b = 255 - tcol.b;
|
|
|
|
tcol.g = 255 - tcol.g;
|
|
|
|
tcol.r = 255 - tcol.r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (effect & HICTINT_COLORIZE)
|
|
|
|
{
|
|
|
|
tcol.b = min((int32_t)((tcol.b) * r) >> 6, 255);
|
|
|
|
tcol.g = min((int32_t)((tcol.g) * g) >> 6, 255);
|
|
|
|
tcol.r = min((int32_t)((tcol.r) * b) >> 6, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (effect & HICTINT_BLENDMASK)
|
|
|
|
{
|
|
|
|
case HICTINT_BLEND_SCREEN:
|
|
|
|
tcol.b = 255 - (((255 - tcol.b) * (255 - r)) >> 8);
|
|
|
|
tcol.g = 255 - (((255 - tcol.g) * (255 - g)) >> 8);
|
|
|
|
tcol.r = 255 - (((255 - tcol.r) * (255 - b)) >> 8);
|
|
|
|
break;
|
|
|
|
case HICTINT_BLEND_OVERLAY:
|
|
|
|
tcol.b = tcol.b < 128 ? (tcol.b * r) >> 7 : 255 - (((255 - tcol.b) * (255 - r)) >> 7);
|
|
|
|
tcol.g = tcol.g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
|
|
|
|
tcol.r = tcol.r < 128 ? (tcol.r * b) >> 7 : 255 - (((255 - tcol.r) * (255 - b)) >> 7);
|
|
|
|
break;
|
|
|
|
case HICTINT_BLEND_HARDLIGHT:
|
|
|
|
tcol.b = r < 128 ? (tcol.b * r) >> 7 : 255 - (((255 - tcol.b) * (255 - r)) >> 7);
|
|
|
|
tcol.g = g < 128 ? (tcol.g * g) >> 7 : 255 - (((255 - tcol.g) * (255 - g)) >> 7);
|
|
|
|
tcol.r = b < 128 ? (tcol.r * b) >> 7 : 255 - (((255 - tcol.r) * (255 - b)) >> 7);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rpptr[x] = tcol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hasalpha = (al != 255);
|
|
|
|
|
|
|
|
// mdloadskin doesn't duplicate npow2 texture pixels
|
|
|
|
|
|
|
|
if (!glinfo.bgra)
|
|
|
|
{
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t j = siz.x*siz.y - 1; j >= 0; j--)
|
2016-03-04 19:24:54 +00:00
|
|
|
swapchar(&pic[j].r, &pic[j].b);
|
|
|
|
}
|
2011-01-09 18:53:06 +00:00
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
if (pal < (MAXPALOOKUPS - RESERVEDPALS))
|
|
|
|
m->usesalpha = hasalpha;
|
|
|
|
if ((doalloc&3)==1)
|
2018-02-16 06:38:21 +00:00
|
|
|
glGenTextures(1, texidx);
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, *texidx);
|
2008-02-02 16:38:30 +00:00
|
|
|
|
|
|
|
//gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,xsiz,ysiz,GL_BGRA_EXT,GL_UNSIGNED_BYTE,(char *)fptr);
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2016-02-29 06:34:20 +00:00
|
|
|
int32_t const texfmt = glinfo.bgra ? GL_BGRA : GL_RGBA;
|
|
|
|
|
2016-05-02 18:29:28 +00:00
|
|
|
uploadtexture((doalloc&1), siz, texfmt, pic, tsiz,
|
2016-03-07 11:21:46 +00:00
|
|
|
DAMETH_HI | DAMETH_MASK |
|
2016-02-29 06:34:20 +00:00
|
|
|
TO_DAMETH_NODOWNSIZE(sk->flags) |
|
|
|
|
TO_DAMETH_NOTEXCOMPRESS(sk->flags) |
|
2016-03-07 11:21:55 +00:00
|
|
|
TO_DAMETH_ARTIMMUNITY(sk->flags) |
|
2016-03-07 11:22:02 +00:00
|
|
|
(onebitalpha ? DAMETH_ONEBITALPHA : 0) |
|
2016-02-29 06:34:20 +00:00
|
|
|
(hasalpha ? DAMETH_HASALPHA : 0));
|
2012-04-29 20:54:22 +00:00
|
|
|
|
2016-03-04 19:24:54 +00:00
|
|
|
Bfree(pic);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m->skinloaded)
|
|
|
|
{
|
2016-03-04 19:24:54 +00:00
|
|
|
if (siz.x != tsiz.x || siz.y != tsiz.y)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
float fx, fy;
|
2016-03-04 19:24:54 +00:00
|
|
|
fx = ((float)tsiz.x)/((float)siz.x);
|
|
|
|
fy = ((float)tsiz.y)/((float)siz.y);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (m->mdnum == 2)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t *lptr;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (lptr=m->glcmds; (i=*lptr++);)
|
|
|
|
for (i=labs(i); i>0; i--,lptr+=3)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
((float *)lptr)[0] *= fx;
|
|
|
|
((float *)lptr)[1] *= fy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m->mdnum == 3)
|
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
md3model_t *m3 = (md3model_t *)m;
|
2006-04-24 19:04:22 +00:00
|
|
|
md3surf_t *s;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t surfi;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (surfi=0; surfi<m3->head.numsurfs; surfi++)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
s = &m3->head.surfs[surfi];
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numverts-1; i>=0; i--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
s->uv[i].u *= fx;
|
|
|
|
s->uv[i].v *= fy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m->skinloaded = 1+number;
|
|
|
|
}
|
|
|
|
|
2015-03-28 09:49:37 +00:00
|
|
|
int32_t const filter = sk->flags & HICR_FORCEFILTER ? TEXFILTER_ON : gltexfiltermode;
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[filter].mag);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[filter].min);
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2006-04-24 19:04:22 +00:00
|
|
|
if (glinfo.maxanisotropy > 1.0)
|
2018-02-16 06:38:21 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy);
|
2015-02-11 05:23:04 +00:00
|
|
|
#endif
|
2018-02-16 06:38:21 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2016-05-04 00:25:06 +00:00
|
|
|
#if defined USE_GLEXT && !defined EDUKE32_GLES
|
2016-03-07 11:21:58 +00:00
|
|
|
if (!gotcache && glinfo.texcompr && glusetexcache && !(sk->flags & HICR_NOTEXCOMPRESS) &&
|
|
|
|
(glusetexcompr == 2 || (glusetexcompr && !(sk->flags & HICR_ARTIMMUNITY))))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2015-03-24 00:40:33 +00:00
|
|
|
const int32_t nonpow2 = check_nonpow2(siz.x) || check_nonpow2(siz.y);
|
2014-05-28 22:40:19 +00:00
|
|
|
|
2008-10-20 04:00:00 +00:00
|
|
|
// save off the compressed version
|
2016-03-07 11:21:55 +00:00
|
|
|
cachead.quality = (sk->flags & (HICR_NODOWNSIZE|HICR_ARTIMMUNITY)) ? 0 : r_downsize;
|
2016-03-04 19:24:54 +00:00
|
|
|
cachead.xdim = tsiz.x>>cachead.quality;
|
|
|
|
cachead.ydim = tsiz.y>>cachead.quality;
|
2008-10-20 04:00:00 +00:00
|
|
|
|
2015-03-28 09:49:11 +00:00
|
|
|
cachead.flags = nonpow2*CACHEAD_NONPOW2 | (hasalpha ? CACHEAD_HASALPHA : 0) |
|
2016-03-07 11:21:55 +00:00
|
|
|
(sk->flags & (HICR_NODOWNSIZE|HICR_ARTIMMUNITY) ? CACHEAD_NODOWNSIZE : 0);
|
2014-05-28 22:40:16 +00:00
|
|
|
|
2011-01-09 18:53:06 +00:00
|
|
|
/// OSD_Printf("Caching \"%s\"\n",fn);
|
2016-05-04 00:25:06 +00:00
|
|
|
texcache_writetex_fromdriver(texcacheid, &cachead);
|
2011-01-09 18:53:06 +00:00
|
|
|
|
|
|
|
if (willprint)
|
|
|
|
{
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t etime = timerGetTicks()-startticks;
|
2011-01-30 11:02:28 +00:00
|
|
|
if (etime>=MIN_CACHETIME_PRINT)
|
2012-04-29 20:54:22 +00:00
|
|
|
OSD_Printf("Load skin: p%d-e%d \"%s\"... cached... %d ms\n", pal, hicfxmask(pal), fn, etime);
|
2011-01-09 18:53:06 +00:00
|
|
|
willprint = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
OSD_Printf("Cached skin \"%s\"\n", fn);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2016-05-04 00:25:06 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2011-01-09 18:53:06 +00:00
|
|
|
if (willprint)
|
2011-01-30 11:02:28 +00:00
|
|
|
{
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t etime = timerGetTicks()-startticks;
|
2011-01-30 11:02:28 +00:00
|
|
|
if (etime>=MIN_CACHETIME_PRINT)
|
2012-04-29 20:54:22 +00:00
|
|
|
OSD_Printf("Load skin: p%d-e%d \"%s\"... %d ms\n", pal, hicfxmask(pal), fn, etime);
|
2011-01-30 11:02:28 +00:00
|
|
|
}
|
2011-01-09 18:53:06 +00:00
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return (*texidx);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Note: even though it says md2model, it works for both md2model&md3model
|
2016-06-21 00:33:58 +00:00
|
|
|
void updateanimation(md2model_t *m, const uspritetype *tspr, uint8_t lpal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
const mdanim_t *anim;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, k;
|
|
|
|
int32_t fps;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-02-13 21:37:46 +00:00
|
|
|
int32_t tile, smoothdurationp;
|
|
|
|
spritesmooth_t *smooth;
|
|
|
|
spriteext_t *sprext;
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
if (m->numframes < 2)
|
2008-12-01 13:44:46 +00:00
|
|
|
{
|
|
|
|
m->interpol = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:37:46 +00:00
|
|
|
tile = Ptile2tile(tspr->picnum,lpal);
|
|
|
|
m->cframe = m->nframe = tile2model[tile].framenum;
|
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
if (m->cframe >= m->numframes)
|
|
|
|
OSD_Printf("1: c > n\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
smoothdurationp = (r_animsmoothing && (tile2model[tile].smoothduration != 0));
|
|
|
|
|
|
|
|
smooth = ((unsigned)tspr->owner < MAXSPRITES+MAXUNIQHUDID) ? &spritesmooth[tspr->owner] : NULL;
|
|
|
|
sprext = ((unsigned)tspr->owner < MAXSPRITES+MAXUNIQHUDID) ? &spriteext[tspr->owner] : NULL;
|
|
|
|
|
|
|
|
for (anim = m->animations; anim && anim->startframe != m->cframe; anim = anim->next)
|
|
|
|
{
|
|
|
|
/* do nothing */;
|
|
|
|
}
|
2006-11-15 01:14:27 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!anim)
|
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
if (!smoothdurationp || ((smooth->mdoldframe == m->cframe) && (smooth->mdcurframe == m->cframe)))
|
2007-03-30 18:02:00 +00:00
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
m->interpol = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// assert(smoothdurationp && ((smooth->mdoldframe != m->cframe) || (smooth->mdcurframe != m->cframe)))
|
|
|
|
|
|
|
|
if (smooth->mdoldframe != m->cframe)
|
|
|
|
{
|
|
|
|
if (smooth->mdsmooth == 0)
|
2007-03-30 18:02:00 +00:00
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
sprext->mdanimtims = mdtims;
|
2007-03-30 18:02:00 +00:00
|
|
|
m->interpol = 0;
|
2012-02-13 21:37:46 +00:00
|
|
|
smooth->mdsmooth = 1;
|
|
|
|
smooth->mdcurframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
}
|
2012-02-13 21:37:46 +00:00
|
|
|
|
|
|
|
if (smooth->mdcurframe != m->cframe)
|
2007-03-30 18:02:00 +00:00
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
sprext->mdanimtims = mdtims;
|
2007-03-30 18:02:00 +00:00
|
|
|
m->interpol = 0;
|
2012-02-13 21:37:46 +00:00
|
|
|
smooth->mdsmooth = 1;
|
|
|
|
smooth->mdoldframe = smooth->mdcurframe;
|
|
|
|
smooth->mdcurframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-13 21:37:46 +00:00
|
|
|
else // if (smooth->mdcurframe != m->cframe)
|
2007-03-30 18:02:00 +00:00
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
sprext->mdanimtims = mdtims;
|
2007-03-30 18:02:00 +00:00
|
|
|
m->interpol = 0;
|
2012-02-13 21:37:46 +00:00
|
|
|
smooth->mdsmooth = 1;
|
|
|
|
smooth->mdoldframe = smooth->mdcurframe;
|
|
|
|
smooth->mdcurframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-13 21:37:46 +00:00
|
|
|
else if (/* anim && */ sprext->mdanimcur != anim->startframe)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
//if (sprext->flags & SPREXT_NOMDANIM) OSD_Printf("SPREXT_NOMDANIM\n");
|
|
|
|
//OSD_Printf("smooth launched ! oldanim %i new anim %i\n", sprext->mdanimcur, anim->startframe);
|
|
|
|
sprext->mdanimcur = (int16_t)anim->startframe;
|
|
|
|
sprext->mdanimtims = mdtims;
|
2006-04-13 20:47:06 +00:00
|
|
|
m->interpol = 0;
|
2012-02-13 21:37:46 +00:00
|
|
|
|
|
|
|
if (!smoothdurationp)
|
2007-03-22 18:28:41 +00:00
|
|
|
{
|
|
|
|
m->cframe = m->nframe = anim->startframe;
|
2012-02-13 21:37:46 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
if (m->cframe >= m->numframes)
|
|
|
|
OSD_Printf("2: c > n\n");
|
|
|
|
#endif
|
2015-06-07 09:55:40 +00:00
|
|
|
goto prep_return;
|
2007-03-22 18:28:41 +00:00
|
|
|
}
|
2012-02-13 21:37:46 +00:00
|
|
|
|
2007-03-30 18:02:00 +00:00
|
|
|
m->nframe = anim->startframe;
|
2012-02-13 21:37:46 +00:00
|
|
|
m->cframe = smooth->mdoldframe;
|
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
if (m->cframe >= m->numframes)
|
|
|
|
OSD_Printf("3: c > n\n");
|
|
|
|
#endif
|
|
|
|
smooth->mdsmooth = 1;
|
2015-06-07 09:55:40 +00:00
|
|
|
goto prep_return;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 00:40:48 +00:00
|
|
|
fps = smooth->mdsmooth ?
|
|
|
|
Blrintf((1.0f / ((float)tile2model[tile].smoothduration * (1.f / (float)UINT16_MAX))) * 66.f) :
|
|
|
|
anim->fpssc;
|
2007-03-22 18:28:41 +00:00
|
|
|
|
2012-02-13 21:37:46 +00:00
|
|
|
i = (mdtims - sprext->mdanimtims)*((fps*timerticspersec)/120);
|
2007-03-30 18:02:00 +00:00
|
|
|
|
2012-02-13 21:37:46 +00:00
|
|
|
if (smooth->mdsmooth)
|
2007-04-12 03:09:41 +00:00
|
|
|
j = 65536;
|
2007-03-30 18:02:00 +00:00
|
|
|
else
|
2007-04-12 03:09:41 +00:00
|
|
|
j = ((anim->endframe+1-anim->startframe)<<16);
|
2012-02-13 21:37:46 +00:00
|
|
|
// XXX: Just in case you play the game for a VERY long time...
|
|
|
|
if (i < 0) { i = 0; sprext->mdanimtims = mdtims; }
|
2006-04-24 19:04:22 +00:00
|
|
|
//compare with j*2 instead of j to ensure i stays > j-65536 for MDANIM_ONESHOT
|
2012-02-13 21:37:46 +00:00
|
|
|
if (anim && (i >= j+j) && (fps) && !mdpause) //Keep mdanimtims close to mdtims to avoid the use of MOD
|
|
|
|
sprext->mdanimtims += j/((fps*timerticspersec)/120);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-03-30 18:02:00 +00:00
|
|
|
k = i;
|
|
|
|
|
|
|
|
if (anim && (anim->flags&MDANIM_ONESHOT))
|
2007-12-12 17:42:14 +00:00
|
|
|
{ if (i > j-65536) i = j-65536; }
|
|
|
|
else { if (i >= j) { i -= j; if (i >= j) i %= j; } }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-02-13 21:37:46 +00:00
|
|
|
if (r_animsmoothing && smooth->mdsmooth)
|
2007-03-22 18:28:41 +00:00
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
m->nframe = anim ? anim->startframe : smooth->mdcurframe;
|
|
|
|
m->cframe = smooth->mdoldframe;
|
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
if (m->cframe >= m->numframes)
|
|
|
|
OSD_Printf("4: c > n\n");
|
|
|
|
#endif
|
2007-03-30 18:02:00 +00:00
|
|
|
//OSD_Printf("smoothing... cframe %i nframe %i\n", m->cframe, m->nframe);
|
|
|
|
if (k > 65535)
|
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
sprext->mdanimtims = mdtims;
|
2007-03-30 18:02:00 +00:00
|
|
|
m->interpol = 0;
|
2012-02-13 21:37:46 +00:00
|
|
|
smooth->mdsmooth = 0;
|
|
|
|
m->cframe = m->nframe; // = anim ? anim->startframe : smooth->mdcurframe;
|
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
if (m->cframe >= m->numframes)
|
|
|
|
OSD_Printf("5: c > n\n");
|
|
|
|
#endif
|
|
|
|
smooth->mdoldframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
//OSD_Printf("smooth stopped !\n");
|
2015-06-07 09:55:40 +00:00
|
|
|
goto prep_return;
|
2007-03-30 18:02:00 +00:00
|
|
|
}
|
2007-03-22 18:28:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m->cframe = (i>>16)+anim->startframe;
|
2012-02-13 21:37:46 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
if (m->cframe >= m->numframes)
|
|
|
|
OSD_Printf("6: c > n\n");
|
|
|
|
#endif
|
|
|
|
m->nframe = m->cframe+1;
|
|
|
|
if (m->nframe > anim->endframe) // VERIFY: (!(r_animsmoothing && smooth->mdsmooth)) implies (anim!=NULL) ?
|
|
|
|
m->nframe = anim->startframe;
|
|
|
|
|
|
|
|
smooth->mdoldframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
//OSD_Printf("not smoothing... cframe %i nframe %i\n", m->cframe, m->nframe);
|
2007-03-22 18:28:41 +00:00
|
|
|
}
|
2012-02-13 21:37:46 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
m->interpol = ((float)(i&65535))/65536.f;
|
2007-03-30 18:02:00 +00:00
|
|
|
//OSD_Printf("interpol %f\n", m->interpol);
|
2015-06-07 09:55:40 +00:00
|
|
|
|
|
|
|
prep_return:
|
|
|
|
if (m->cframe >= m->numframes)
|
|
|
|
m->cframe = 0;
|
|
|
|
if (m->nframe >= m->numframes)
|
|
|
|
m->nframe = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2007-03-08 03:07:10 +00:00
|
|
|
// VBO generation and allocation
|
2009-01-10 07:38:50 +00:00
|
|
|
static void mdloadvbos(md3model_t *m)
|
2007-03-08 03:07:10 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m->vbos = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint));
|
2018-02-16 06:38:21 +00:00
|
|
|
glGenBuffers(m->head.numsurfs, m->vbos);
|
2007-03-08 03:07:10 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < m->head.numsurfs)
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m->vbos[i]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, m->head.surfs[i].numverts * sizeof(md3uv_t), m->head.surfs[i].uv, GL_STATIC_DRAW);
|
2007-03-08 03:07:10 +00:00
|
|
|
i++;
|
|
|
|
}
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2007-03-08 03:07:10 +00:00
|
|
|
}
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//--------------------------------------- MD2 LIBRARY BEGINS ---------------------------------------
|
2009-01-10 07:38:50 +00:00
|
|
|
static md2model_t *md2load(int32_t fil, const char *filnam)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
md2model_t *m;
|
|
|
|
md3model_t *m3;
|
2006-08-12 07:47:02 +00:00
|
|
|
md3surf_t *s;
|
|
|
|
md2frame_t *f;
|
2006-04-13 20:47:06 +00:00
|
|
|
md2head_t head;
|
2008-03-22 10:23:57 +00:00
|
|
|
char st[BMAX_PATH];
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, k;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-11-25 09:49:40 +00:00
|
|
|
int32_t ournumskins, ournumglcmds;
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m = (md2model_t *)Xcalloc(1,sizeof(md2model_t));
|
2008-11-26 22:51:56 +00:00
|
|
|
m->mdnum = 2; m->scale = .01f;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
kread(fil,(char *)&head,sizeof(md2head_t));
|
2014-09-30 04:18:43 +00:00
|
|
|
#if B_BIG_ENDIAN != 0
|
2006-04-24 19:04:22 +00:00
|
|
|
head.id = B_LITTLE32(head.id); head.vers = B_LITTLE32(head.vers);
|
|
|
|
head.skinxsiz = B_LITTLE32(head.skinxsiz); head.skinysiz = B_LITTLE32(head.skinysiz);
|
|
|
|
head.framebytes = B_LITTLE32(head.framebytes); head.numskins = B_LITTLE32(head.numskins);
|
|
|
|
head.numverts = B_LITTLE32(head.numverts); head.numuv = B_LITTLE32(head.numuv);
|
|
|
|
head.numtris = B_LITTLE32(head.numtris); head.numglcmds = B_LITTLE32(head.numglcmds);
|
|
|
|
head.numframes = B_LITTLE32(head.numframes); head.ofsskins = B_LITTLE32(head.ofsskins);
|
|
|
|
head.ofsuv = B_LITTLE32(head.ofsuv); head.ofstris = B_LITTLE32(head.ofstris);
|
|
|
|
head.ofsframes = B_LITTLE32(head.ofsframes); head.ofsglcmds = B_LITTLE32(head.ofsglcmds);
|
|
|
|
head.ofseof = B_LITTLE32(head.ofseof);
|
2014-09-30 04:18:43 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
if ((head.id != IDP2_MAGIC) || (head.vers != 8)) { Bfree(m); return 0; } //"IDP2"
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2011-11-25 09:49:40 +00:00
|
|
|
ournumskins = head.numskins ? head.numskins : 1;
|
|
|
|
ournumglcmds = head.numglcmds ? head.numglcmds : 1;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
m->numskins = head.numskins;
|
|
|
|
m->numframes = head.numframes;
|
|
|
|
m->numverts = head.numverts;
|
|
|
|
m->numglcmds = head.numglcmds;
|
|
|
|
m->framebytes = head.framebytes;
|
2006-08-12 07:47:02 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m->frames = (char *)Xmalloc(m->numframes*m->framebytes);
|
|
|
|
m->glcmds = (int32_t *)Xmalloc(ournumglcmds*sizeof(int32_t));
|
|
|
|
m->tris = (md2tri_t *)Xmalloc(head.numtris*sizeof(md2tri_t));
|
|
|
|
m->uv = (md2uv_t *)Xmalloc(head.numuv*sizeof(md2uv_t));
|
2006-08-12 07:47:02 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
klseek(fil,head.ofsframes,SEEK_SET);
|
|
|
|
if (kread(fil,(char *)m->frames,m->numframes*m->framebytes) != m->numframes*m->framebytes)
|
2016-06-21 00:34:41 +00:00
|
|
|
{ Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return 0; }
|
2006-08-12 07:47:02 +00:00
|
|
|
|
2011-11-25 09:49:40 +00:00
|
|
|
if (m->numglcmds > 0)
|
|
|
|
{
|
|
|
|
klseek(fil,head.ofsglcmds,SEEK_SET);
|
|
|
|
if (kread(fil,(char *)m->glcmds,m->numglcmds*sizeof(int32_t)) != (int32_t)(m->numglcmds*sizeof(int32_t)))
|
2016-06-21 00:34:41 +00:00
|
|
|
{ Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return 0; }
|
2011-11-25 09:49:40 +00:00
|
|
|
}
|
2006-08-12 07:47:02 +00:00
|
|
|
|
|
|
|
klseek(fil,head.ofstris,SEEK_SET);
|
2009-01-09 09:29:17 +00:00
|
|
|
if (kread(fil,(char *)m->tris,head.numtris*sizeof(md2tri_t)) != (int32_t)(head.numtris*sizeof(md2tri_t)))
|
2016-06-21 00:34:41 +00:00
|
|
|
{ Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return 0; }
|
2006-08-12 07:47:02 +00:00
|
|
|
|
|
|
|
klseek(fil,head.ofsuv,SEEK_SET);
|
2009-01-09 09:29:17 +00:00
|
|
|
if (kread(fil,(char *)m->uv,head.numuv*sizeof(md2uv_t)) != (int32_t)(head.numuv*sizeof(md2uv_t)))
|
2016-06-21 00:34:41 +00:00
|
|
|
{ Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return 0; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#if B_BIG_ENDIAN != 0
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
char *f = (char *)m->frames;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t *l,j;
|
2006-04-24 19:04:22 +00:00
|
|
|
md2frame_t *fr;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (i = m->numframes-1; i>=0; i--)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
fr = (md2frame_t *)f;
|
2009-01-09 09:29:17 +00:00
|
|
|
l = (int32_t *)&fr->mul;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=5; j>=0; j--) l[j] = B_LITTLE32(l[j]);
|
2006-04-24 19:04:22 +00:00
|
|
|
f += m->framebytes;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (i = m->numglcmds-1; i>=0; i--)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
m->glcmds[i] = B_LITTLE32(m->glcmds[i]);
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
for (i = head.numtris-1; i>=0; i--)
|
|
|
|
{
|
|
|
|
m->tris[i].v[0] = B_LITTLE16(m->tris[i].v[0]);
|
|
|
|
m->tris[i].v[1] = B_LITTLE16(m->tris[i].v[1]);
|
|
|
|
m->tris[i].v[2] = B_LITTLE16(m->tris[i].v[2]);
|
|
|
|
m->tris[i].u[0] = B_LITTLE16(m->tris[i].u[0]);
|
|
|
|
m->tris[i].u[1] = B_LITTLE16(m->tris[i].u[1]);
|
|
|
|
m->tris[i].u[2] = B_LITTLE16(m->tris[i].u[2]);
|
|
|
|
}
|
|
|
|
for (i = head.numuv-1; i>=0; i--)
|
|
|
|
{
|
|
|
|
m->uv[i].u = B_LITTLE16(m->uv[i].u);
|
|
|
|
m->uv[i].v = B_LITTLE16(m->uv[i].v);
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
Bstrcpy(st,filnam);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=strlen(st)-1; i>0; i--)
|
2007-12-12 17:42:14 +00:00
|
|
|
if ((st[i] == '/') || (st[i] == '\\')) { i++; break; }
|
2006-04-13 20:47:06 +00:00
|
|
|
if (i<0) i=0;
|
|
|
|
st[i] = 0;
|
2014-05-30 00:02:19 +00:00
|
|
|
m->basepath = (char *)Xmalloc(i+1);
|
2012-04-29 20:54:22 +00:00
|
|
|
Bstrcpy(m->basepath, st);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m->skinfn = (char *)Xmalloc(ournumskins*64);
|
2011-11-25 09:49:40 +00:00
|
|
|
if (m->numskins > 0)
|
|
|
|
{
|
|
|
|
klseek(fil,head.ofsskins,SEEK_SET);
|
|
|
|
if (kread(fil,m->skinfn,64*m->numskins) != 64*m->numskins)
|
2016-06-21 00:34:41 +00:00
|
|
|
{ Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return 0; }
|
2011-11-25 09:49:40 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-06-21 13:46:36 +00:00
|
|
|
m->texid = (GLuint *)Xcalloc(ournumskins, sizeof(GLuint) * HICTINT_MEMORY_COMBINATIONS);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-30 23:32:39 +00:00
|
|
|
maxmodelverts = max(maxmodelverts, m->numverts);
|
2007-03-08 03:07:10 +00:00
|
|
|
maxmodeltris = max(maxmodeltris, head.numtris);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
//return m;
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
// the MD2 is now loaded internally - let's begin the MD3 conversion process
|
|
|
|
//OSD_Printf("Beginning md3 conversion.\n");
|
2014-05-30 00:02:19 +00:00
|
|
|
m3 = (md3model_t *)Xcalloc(1, sizeof(md3model_t));
|
2006-08-12 07:47:02 +00:00
|
|
|
m3->mdnum = 3; m3->texid = 0; m3->scale = m->scale;
|
2014-09-30 04:18:43 +00:00
|
|
|
m3->head.id = IDP3_MAGIC; m3->head.vers = 15;
|
2013-03-21 10:20:01 +00:00
|
|
|
|
2014-10-25 03:26:46 +00:00
|
|
|
m3->head.flags = 0;
|
2013-03-21 10:20:01 +00:00
|
|
|
|
2008-06-01 09:41:56 +00:00
|
|
|
m3->head.numframes = m->numframes;
|
2006-08-12 07:47:02 +00:00
|
|
|
m3->head.numtags = 0; m3->head.numsurfs = 1;
|
|
|
|
m3->head.numskins = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
m3->numskins = m3->head.numskins;
|
|
|
|
m3->numframes = m3->head.numframes;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m3->head.frames = (md3frame_t *)Xcalloc(m3->head.numframes, sizeof(md3frame_t));
|
2014-09-30 04:18:43 +00:00
|
|
|
m3->muladdframes = (vec3f_t *)Xcalloc(m->numframes * 2, sizeof(vec3f_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
f = (md2frame_t *)(m->frames);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
// frames converting
|
|
|
|
i = 0;
|
|
|
|
while (i < m->numframes)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2006-08-12 07:47:02 +00:00
|
|
|
f = (md2frame_t *)&m->frames[i*m->framebytes];
|
2012-04-29 20:54:22 +00:00
|
|
|
Bstrcpy(m3->head.frames[i].nam, f->name);
|
2006-08-12 07:47:02 +00:00
|
|
|
//OSD_Printf("Copied frame %s.\n", m3->head.frames[i].nam);
|
2006-09-17 20:16:20 +00:00
|
|
|
m3->muladdframes[i*2] = f->mul;
|
|
|
|
m3->muladdframes[i*2+1] = f->add;
|
2006-08-12 07:47:02 +00:00
|
|
|
i++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
m3->head.tags = NULL;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m3->head.surfs = (md3surf_t *)Xcalloc(1, sizeof(md3surf_t));
|
2006-08-12 07:47:02 +00:00
|
|
|
s = m3->head.surfs;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
// model converting
|
2014-09-30 04:18:43 +00:00
|
|
|
s->id = IDP3_MAGIC; s->flags = 0;
|
2006-08-12 07:47:02 +00:00
|
|
|
s->numframes = m->numframes; s->numshaders = 0;
|
|
|
|
s->numtris = head.numtris;
|
|
|
|
s->numverts = head.numtris * 3; // oh man talk about memory effectiveness :((((
|
|
|
|
// MD2 is actually more accurate than MD3 in term of uv-mapping, because each triangle has a triangle counterpart on the UV-map.
|
|
|
|
// In MD3, each vertex unique UV coordinates, meaning that you have to duplicate vertices if you need non-seamless UV-mapping.
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
maxmodelverts = max(maxmodelverts, s->numverts);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
Bstrcpy(s->nam, "Dummy surface from MD2");
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
s->shaders = NULL;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
s->tris = (md3tri_t *)Xcalloc(head.numtris, sizeof(md3tri_t));
|
|
|
|
s->uv = (md3uv_t *)Xcalloc(s->numverts, sizeof(md3uv_t));
|
|
|
|
s->xyzn = (md3xyzn_t *)Xcalloc(s->numverts * m->numframes, sizeof(md3xyzn_t));
|
2006-09-17 20:16:20 +00:00
|
|
|
|
2006-08-30 23:32:39 +00:00
|
|
|
//memoryusage += (s->numverts * m->numframes * sizeof(md3xyzn_t));
|
|
|
|
//OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
//OSD_Printf("Number of frames : %i\n", m->numframes);
|
|
|
|
//OSD_Printf("Number of triangles : %i\n", head.numtris);
|
|
|
|
//OSD_Printf("Number of vertices : %i\n", s->numverts);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
// triangle converting
|
|
|
|
i = 0;
|
|
|
|
while (i < head.numtris)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-08-12 07:47:02 +00:00
|
|
|
j = 0;
|
|
|
|
//OSD_Printf("Triangle : %i\n", i);
|
|
|
|
while (j < 3)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-08-12 07:47:02 +00:00
|
|
|
// triangle vertex indexes
|
|
|
|
s->tris[i].i[j] = i*3 + j;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
// uv coords
|
|
|
|
s->uv[i*3+j].u = (float)(m->uv[m->tris[i].u[j]].u) / (float)(head.skinxsiz);
|
|
|
|
s->uv[i*3+j].v = (float)(m->uv[m->tris[i].u[j]].v) / (float)(head.skinysiz);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
// vertices for each frame
|
|
|
|
k = 0;
|
|
|
|
while (k < m->numframes)
|
|
|
|
{
|
|
|
|
f = (md2frame_t *)&m->frames[k*m->framebytes];
|
2014-10-25 03:26:46 +00:00
|
|
|
s->xyzn[(k*s->numverts) + (i*3) + j].x = (int16_t) (((f->verts[m->tris[i].v[j]].v[0] * f->mul.x) + f->add.x) * 64.f);
|
|
|
|
s->xyzn[(k*s->numverts) + (i*3) + j].y = (int16_t) (((f->verts[m->tris[i].v[j]].v[1] * f->mul.y) + f->add.y) * 64.f);
|
|
|
|
s->xyzn[(k*s->numverts) + (i*3) + j].z = (int16_t) (((f->verts[m->tris[i].v[j]].v[2] * f->mul.z) + f->add.z) * 64.f);
|
2008-06-01 09:41:56 +00:00
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
j++;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2006-08-12 07:47:02 +00:00
|
|
|
//OSD_Printf("End triangle.\n");
|
|
|
|
i++;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2006-08-12 07:47:02 +00:00
|
|
|
//OSD_Printf("Finished md3 conversion.\n");
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-08-15 03:32:34 +00:00
|
|
|
{
|
|
|
|
mdskinmap_t *sk;
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
sk = (mdskinmap_t *)Xcalloc(1,sizeof(mdskinmap_t));
|
2006-08-15 03:32:34 +00:00
|
|
|
sk->palette = 0;
|
|
|
|
sk->skinnum = 0;
|
|
|
|
sk->surfnum = 0;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (m->numskins > 0)
|
|
|
|
{
|
2014-05-30 00:02:19 +00:00
|
|
|
sk->fn = (char *)Xmalloc(strlen(m->basepath)+strlen(m->skinfn)+1);
|
2012-04-29 20:54:22 +00:00
|
|
|
Bstrcpy(sk->fn, m->basepath);
|
|
|
|
Bstrcat(sk->fn, m->skinfn);
|
2006-11-20 04:56:22 +00:00
|
|
|
}
|
2006-08-15 03:32:34 +00:00
|
|
|
m3->skinmap = sk;
|
|
|
|
}
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m3->indexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * s->numtris);
|
|
|
|
m3->vindexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * s->numtris * 3);
|
|
|
|
m3->maxdepths = (float *)Xmalloc(sizeof(float) * s->numtris);
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2007-03-08 03:07:10 +00:00
|
|
|
m3->vbos = NULL;
|
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
// die MD2 ! DIE !
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(m->texid); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return ((md2model_t *)m3);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
//---------------------------------------- MD2 LIBRARY ENDS ----------------------------------------
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
// DICHOTOMIC RECURSIVE SORTING - USED BY MD3DRAW
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t partition(uint16_t *indexes, float *depths, int32_t f, int32_t l)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
int32_t up = f, down = l;
|
2006-04-13 20:47:06 +00:00
|
|
|
float piv = depths[f];
|
2009-01-09 09:29:17 +00:00
|
|
|
uint16_t piv2 = indexes[f];
|
2007-12-12 17:42:14 +00:00
|
|
|
do
|
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
while ((depths[up] <= piv) && (up < l))
|
|
|
|
up++;
|
|
|
|
while ((depths[down] > piv) && (down > f))
|
|
|
|
down--;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (up < down)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
swapfloat(&depths[up], &depths[down]);
|
|
|
|
swapshort(&indexes[up], &indexes[down]);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
while (down > up);
|
2017-07-22 04:00:33 +00:00
|
|
|
depths[f] = depths[down];
|
|
|
|
depths[down] = piv;
|
|
|
|
indexes[f] = indexes[down];
|
|
|
|
indexes[down] = piv2;
|
2006-04-13 20:47:06 +00:00
|
|
|
return down;
|
|
|
|
}
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
static inline void quicksort(uint16_t *indexes, float *depths, int32_t first, int32_t last)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
int32_t pivIndex;
|
|
|
|
if (first >= last) return;
|
|
|
|
pivIndex = partition(indexes, depths, first, last);
|
|
|
|
if (first < (pivIndex-1)) quicksort(indexes, depths, first, (pivIndex-1));
|
|
|
|
if ((pivIndex+1) >= last) return;
|
|
|
|
quicksort(indexes, depths, (pivIndex+1), last);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
// END OF QUICKSORT LIB
|
|
|
|
|
|
|
|
//--------------------------------------- MD3 LIBRARY BEGINS ---------------------------------------
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
static md3model_t *md3load(int32_t fil)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, surfi, ofsurf, offs[4], leng[4];
|
|
|
|
int32_t maxtrispersurf;
|
2009-01-10 07:38:50 +00:00
|
|
|
md3model_t *m;
|
2006-04-24 19:04:22 +00:00
|
|
|
md3surf_t *s;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m = (md3model_t *)Xcalloc(1,sizeof(md3model_t));
|
2009-07-09 02:29:48 +00:00
|
|
|
m->mdnum = 3; m->texid = 0; m->scale = .01f;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-09-17 20:16:20 +00:00
|
|
|
m->muladdframes = NULL;
|
|
|
|
|
2008-05-24 06:53:56 +00:00
|
|
|
kread(fil,&m->head,SIZEOF_MD3HEAD_T);
|
2014-09-30 04:18:43 +00:00
|
|
|
|
|
|
|
#if B_BIG_ENDIAN != 0
|
2006-04-24 19:04:22 +00:00
|
|
|
m->head.id = B_LITTLE32(m->head.id); m->head.vers = B_LITTLE32(m->head.vers);
|
|
|
|
m->head.flags = B_LITTLE32(m->head.flags); m->head.numframes = B_LITTLE32(m->head.numframes);
|
|
|
|
m->head.numtags = B_LITTLE32(m->head.numtags); m->head.numsurfs = B_LITTLE32(m->head.numsurfs);
|
2008-05-24 06:53:56 +00:00
|
|
|
m->head.numskins = B_LITTLE32(m->head.numskins); m->head.ofsframes = B_LITTLE32(m->head.ofsframes);
|
|
|
|
m->head.ofstags = B_LITTLE32(m->head.ofstags); m->head.ofssurfs = B_LITTLE32(m->head.ofssurfs);
|
2006-04-24 19:04:22 +00:00
|
|
|
m->head.eof = B_LITTLE32(m->head.eof);
|
2014-09-30 04:18:43 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
if ((m->head.id != IDP3_MAGIC) && (m->head.vers != 15)) { Bfree(m); return 0; } //"IDP3"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
m->numskins = m->head.numskins; //<- dead code?
|
|
|
|
m->numframes = m->head.numframes;
|
|
|
|
|
2008-05-24 07:58:21 +00:00
|
|
|
ofsurf = m->head.ofssurfs;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-05-24 06:53:56 +00:00
|
|
|
klseek(fil,m->head.ofsframes,SEEK_SET); i = m->head.numframes*sizeof(md3frame_t);
|
2014-05-30 00:02:19 +00:00
|
|
|
m->head.frames = (md3frame_t *)Xmalloc(i);
|
2006-04-13 20:47:06 +00:00
|
|
|
kread(fil,m->head.frames,i);
|
|
|
|
|
|
|
|
if (m->head.numtags == 0) m->head.tags = NULL;
|
2007-12-12 17:42:14 +00:00
|
|
|
else
|
|
|
|
{
|
2008-05-24 06:53:56 +00:00
|
|
|
klseek(fil,m->head.ofstags,SEEK_SET); i = m->head.numtags*sizeof(md3tag_t);
|
2014-05-30 00:02:19 +00:00
|
|
|
m->head.tags = (md3tag_t *)Xmalloc(i);
|
2006-04-13 20:47:06 +00:00
|
|
|
kread(fil,m->head.tags,i);
|
|
|
|
}
|
|
|
|
|
2015-02-10 19:51:15 +00:00
|
|
|
klseek(fil,m->head.ofssurfs,SEEK_SET);
|
|
|
|
m->head.surfs = (md3surf_t *)Xcalloc(m->head.numsurfs, sizeof(md3surf_t));
|
|
|
|
// NOTE: We assume that NULL is represented by all-zeros.
|
|
|
|
// surfs[0].geometry is for POLYMER_MD_PROCESS_CHECK (else: crashes).
|
|
|
|
// surfs[i].geometry is for FREE_SURFS_GEOMETRY.
|
|
|
|
Bassert(m->head.surfs[0].geometry == NULL);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#if B_BIG_ENDIAN != 0
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2011-06-15 10:38:12 +00:00
|
|
|
int32_t j, *l;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (i = m->head.numframes-1; i>=0; i--)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
l = (int32_t *)&m->head.frames[i].min;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=3+3+3+1-1; j>=0; j--) l[j] = B_LITTLE32(l[j]);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (i = m->head.numtags-1; i>=0; i--)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
l = (int32_t *)&m->head.tags[i].p;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=3+3+3+3-1; j>=0; j--) l[j] = B_LITTLE32(l[j]);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-03 23:09:40 +00:00
|
|
|
maxtrispersurf = 0;
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (surfi=0; surfi<m->head.numsurfs; surfi++)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
s = &m->head.surfs[surfi];
|
2008-05-24 06:53:56 +00:00
|
|
|
klseek(fil,ofsurf,SEEK_SET); kread(fil,s,SIZEOF_MD3SURF_T);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#if B_BIG_ENDIAN != 0
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2011-06-15 10:38:12 +00:00
|
|
|
int32_t j, *l;
|
2006-04-24 19:04:22 +00:00
|
|
|
s->id = B_LITTLE32(s->id);
|
2009-01-09 09:29:17 +00:00
|
|
|
l = (int32_t *)&s->flags;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=1+1+1+1+1+1+1+1+1+1-1; j>=0; j--) l[j] = B_LITTLE32(l[j]);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
offs[0] = ofsurf+s->ofstris;
|
|
|
|
offs[1] = ofsurf+s->ofsshaders;
|
|
|
|
offs[2] = ofsurf+s->ofsuv;
|
|
|
|
offs[3] = ofsurf+s->ofsxyzn;
|
|
|
|
|
|
|
|
leng[0] = s->numtris*sizeof(md3tri_t);
|
|
|
|
leng[1] = s->numshaders*sizeof(md3shader_t);
|
|
|
|
leng[2] = s->numverts*sizeof(md3uv_t);
|
|
|
|
leng[3] = s->numframes*s->numverts*sizeof(md3xyzn_t);
|
|
|
|
|
2006-08-30 23:32:39 +00:00
|
|
|
//memoryusage += (s->numverts * s->numframes * sizeof(md3xyzn_t));
|
|
|
|
//OSD_Printf("Current model geometry memory usage : %i.\n", memoryusage);
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
s->tris = (md3tri_t *)Xmalloc((leng[0] + leng[1]) + (leng[2] + leng[3]));
|
2014-05-30 00:02:19 +00:00
|
|
|
|
2008-05-24 08:21:53 +00:00
|
|
|
s->shaders = (md3shader_t *)(((intptr_t)s->tris)+leng[0]);
|
2011-01-16 02:50:27 +00:00
|
|
|
s->uv = (md3uv_t *)(((intptr_t)s->shaders)+leng[1]);
|
|
|
|
s->xyzn = (md3xyzn_t *)(((intptr_t)s->uv)+leng[2]);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
klseek(fil,offs[0],SEEK_SET); kread(fil,s->tris ,leng[0]);
|
|
|
|
klseek(fil,offs[1],SEEK_SET); kread(fil,s->shaders,leng[1]);
|
|
|
|
klseek(fil,offs[2],SEEK_SET); kread(fil,s->uv ,leng[2]);
|
|
|
|
klseek(fil,offs[3],SEEK_SET); kread(fil,s->xyzn ,leng[3]);
|
|
|
|
|
|
|
|
#if B_BIG_ENDIAN != 0
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2011-06-15 10:38:12 +00:00
|
|
|
int32_t j, *l;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numtris-1; i>=0; i--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=2; j>=0; j--) s->tris[i].i[j] = B_LITTLE32(s->tris[i].i[j]);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numshaders-1; i>=0; i--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
s->shaders[i].i = B_LITTLE32(s->shaders[i].i);
|
|
|
|
}
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numverts-1; i>=0; i--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
l = (int32_t *)&s->uv[i].u;
|
2006-04-24 19:04:22 +00:00
|
|
|
l[0] = B_LITTLE32(l[0]);
|
|
|
|
l[1] = B_LITTLE32(l[1]);
|
|
|
|
}
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numframes*s->numverts-1; i>=0; i--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
s->xyzn[i].x = (int16_t)B_LITTLE16((uint16_t)s->xyzn[i].x);
|
|
|
|
s->xyzn[i].y = (int16_t)B_LITTLE16((uint16_t)s->xyzn[i].y);
|
|
|
|
s->xyzn[i].z = (int16_t)B_LITTLE16((uint16_t)s->xyzn[i].z);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
maxmodelverts = max(maxmodelverts, s->numverts);
|
2007-03-08 03:07:10 +00:00
|
|
|
maxmodeltris = max(maxmodeltris, s->numtris);
|
2007-03-03 23:09:40 +00:00
|
|
|
maxtrispersurf = max(maxtrispersurf, s->numtris);
|
2006-04-24 19:04:22 +00:00
|
|
|
ofsurf += s->ofsend;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m->indexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * maxtrispersurf);
|
|
|
|
m->vindexes = (uint16_t *)Xmalloc(sizeof(uint16_t) * maxtrispersurf * 3);
|
|
|
|
m->maxdepths = (float *)Xmalloc(sizeof(float) * maxtrispersurf);
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2007-03-08 03:07:10 +00:00
|
|
|
m->vbos = NULL;
|
|
|
|
|
2016-06-21 00:34:41 +00:00
|
|
|
return m;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2015-10-10 06:57:49 +00:00
|
|
|
#ifdef POLYMER
|
2011-01-16 02:50:27 +00:00
|
|
|
static inline void invertmatrix(float *m, float *out)
|
2010-01-24 05:57:43 +00:00
|
|
|
{
|
|
|
|
float det;
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
det = (m[0] * (m[4]*m[8] - m[5] * m[7]))
|
|
|
|
- (m[1] * (m[3]*m[8] - m[5] * m[6]))
|
|
|
|
+ (m[2] * (m[3]*m[7] - m[4] * m[6]));
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
if (det == 0.0f)
|
2011-09-06 17:45:39 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
Bmemset(out, 0, sizeof(float) * 9);
|
|
|
|
out[8] = out[4] = out[0] = 1.f;
|
|
|
|
return;
|
|
|
|
}
|
2010-08-21 07:39:12 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
det = 1.0f / det;
|
2010-08-21 07:39:12 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
out[0] = det * (m[4] * m[8] - m[5] * m[7]);
|
|
|
|
out[1] = det * (m[2] * m[7] - m[1] * m[8]);
|
|
|
|
out[2] = det * (m[1] * m[5] - m[2] * m[4]);
|
|
|
|
out[3] = det * (m[5] * m[6] - m[3] * m[8]);
|
|
|
|
out[4] = det * (m[0] * m[8] - m[2] * m[6]);
|
|
|
|
out[5] = det * (m[2] * m[3] - m[0] * m[5]);
|
|
|
|
out[6] = det * (m[3] * m[7] - m[1] * m[6]);
|
|
|
|
out[7] = det * (m[1] * m[6] - m[0] * m[7]);
|
|
|
|
out[8] = det * (m[0] * m[4] - m[1] * m[3]);
|
2010-01-24 05:57:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
static inline void normalize(float *vec)
|
2010-01-24 05:57:43 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
float norm;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
if ((norm = vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]) == 0.f)
|
|
|
|
return;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2015-03-24 00:40:33 +00:00
|
|
|
norm = polymost_invsqrt_approximation(norm);
|
2014-09-30 04:18:43 +00:00
|
|
|
vec[0] *= norm;
|
|
|
|
vec[1] *= norm;
|
|
|
|
vec[2] *= norm;
|
2010-01-24 05:57:43 +00:00
|
|
|
}
|
2015-10-10 06:57:49 +00:00
|
|
|
#endif
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
static void md3postload_common(md3model_t *m)
|
2009-03-10 09:26:25 +00:00
|
|
|
{
|
2010-12-24 15:44:37 +00:00
|
|
|
int framei, surfi, verti;
|
2010-01-24 05:57:43 +00:00
|
|
|
md3frame_t *frame;
|
2009-03-10 09:26:25 +00:00
|
|
|
md3xyzn_t *frameverts;
|
2017-07-22 04:00:33 +00:00
|
|
|
float dist, vec1[3];
|
2009-03-10 09:26:25 +00:00
|
|
|
|
|
|
|
// apparently we can't trust loaded models bounding box/sphere information,
|
|
|
|
// so let's compute it ourselves
|
|
|
|
|
|
|
|
framei = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
while (framei < m->head.numframes)
|
2009-03-10 09:26:25 +00:00
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
frame = &m->head.frames[framei];
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
Bmemset(&frame->min, 0, sizeof(vec3f_t));
|
|
|
|
Bmemset(&frame->max, 0, sizeof(vec3f_t));
|
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
frame->r = 0.0f;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
|
|
|
surfi = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (surfi < m->head.numsurfs)
|
2009-03-10 09:26:25 +00:00
|
|
|
{
|
|
|
|
frameverts = &m->head.surfs[surfi].xyzn[framei * m->head.surfs[surfi].numverts];
|
|
|
|
|
|
|
|
verti = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (verti < m->head.surfs[surfi].numverts)
|
2009-03-10 09:26:25 +00:00
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
if (!verti && !surfi)
|
|
|
|
{
|
|
|
|
md3xyzn_t const & framevert = frameverts[0];
|
2009-03-10 09:26:25 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
frame->min.x = framevert.x;
|
|
|
|
frame->min.y = framevert.y;
|
|
|
|
frame->min.z = framevert.z;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
frame->max = frame->min;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
md3xyzn_t const & framevert = frameverts[verti];
|
|
|
|
|
|
|
|
if (frame->min.x > framevert.x)
|
|
|
|
frame->min.x = framevert.x;
|
|
|
|
if (frame->max.x < framevert.x)
|
|
|
|
frame->max.x = framevert.x;
|
|
|
|
|
|
|
|
if (frame->min.y > framevert.y)
|
|
|
|
frame->min.y = framevert.y;
|
|
|
|
if (frame->max.y < framevert.y)
|
|
|
|
frame->max.y = framevert.y;
|
|
|
|
|
|
|
|
if (frame->min.z > framevert.z)
|
|
|
|
frame->min.z = framevert.z;
|
|
|
|
if (frame->max.z < framevert.z)
|
|
|
|
frame->max.z = framevert.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
++verti;
|
2009-03-10 09:26:25 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++surfi;
|
2009-03-10 09:26:25 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
frame->cen.x = (frame->min.x + frame->max.x) * .5f;
|
|
|
|
frame->cen.y = (frame->min.y + frame->max.y) * .5f;
|
|
|
|
frame->cen.z = (frame->min.z + frame->max.z) * .5f;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
|
|
|
surfi = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (surfi < m->head.numsurfs)
|
2009-03-10 09:26:25 +00:00
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
md3surf_t const & surf = m->head.surfs[surfi];
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
frameverts = &surf.xyzn[framei * surf.numverts];
|
2009-03-10 09:26:25 +00:00
|
|
|
|
|
|
|
verti = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (verti < surf.numverts)
|
2009-03-10 09:26:25 +00:00
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
md3xyzn_t const & framevert = frameverts[verti];
|
|
|
|
|
|
|
|
vec1[0] = framevert.x - frame->cen.x;
|
|
|
|
vec1[1] = framevert.y - frame->cen.y;
|
|
|
|
vec1[2] = framevert.z - frame->cen.z;
|
2009-03-10 17:49:34 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
dist = vec1[0] * vec1[0] + vec1[1] * vec1[1] + vec1[2] * vec1[2];
|
2009-03-10 09:26:25 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
if (dist > frame->r)
|
|
|
|
frame->r = dist;
|
|
|
|
|
|
|
|
++verti;
|
2009-03-10 09:26:25 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++surfi;
|
2009-03-10 09:26:25 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
frame->r = Bsqrtf(frame->r);
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++framei;
|
2009-03-10 09:26:25 +00:00
|
|
|
}
|
2010-12-24 15:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef POLYMER
|
|
|
|
// pre-check success of conversion since it must not fail later.
|
|
|
|
// keep in sync with md3postload_polymer!
|
|
|
|
static int md3postload_polymer_check(md3model_t *m)
|
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
ssize_t surfi, trii;
|
2010-12-24 15:44:37 +00:00
|
|
|
md3surf_t *s;
|
|
|
|
|
|
|
|
surfi = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (surfi < m->head.numsurfs)
|
2010-12-24 15:44:37 +00:00
|
|
|
{
|
|
|
|
s = &m->head.surfs[surfi];
|
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
uint32_t const numverts = s->numverts;
|
|
|
|
|
2010-12-24 15:44:37 +00:00
|
|
|
trii = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (trii < s->numtris)
|
2010-12-24 15:44:37 +00:00
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
uint32_t const * const u = (uint32_t const *)s->tris[trii].i;
|
|
|
|
|
2010-12-24 15:44:37 +00:00
|
|
|
// let the vertices know they're being referenced by a triangle
|
2017-07-22 04:00:33 +00:00
|
|
|
if (u[0] >= numverts || u[1] >= numverts || u[2] >= numverts)
|
2011-01-16 02:50:27 +00:00
|
|
|
{
|
2010-12-24 15:44:37 +00:00
|
|
|
// corrupt model
|
2011-09-06 17:45:39 +00:00
|
|
|
OSD_Printf("%s: Triangle index out of bounds!\n", m->head.nam);
|
2014-09-30 04:18:43 +00:00
|
|
|
return 1;
|
2010-12-24 15:44:37 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++trii;
|
2010-12-24 15:44:37 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++surfi;
|
2010-12-24 15:44:37 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
return 0;
|
2010-12-24 15:44:37 +00:00
|
|
|
}
|
2013-09-13 20:23:56 +00:00
|
|
|
|
|
|
|
// Precalculated cos/sin arrays.
|
2014-09-30 04:18:43 +00:00
|
|
|
static float g_mdcos[256], g_mdsin[256];
|
|
|
|
static int32_t mdtrig_init = 0;
|
2013-09-13 20:23:56 +00:00
|
|
|
|
|
|
|
static void init_mdtrig_arrays(void)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
for (i=0; i<256; i++)
|
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
float ang = i * (2.f * fPI) * (1.f/255.f);
|
2014-09-30 04:18:43 +00:00
|
|
|
g_mdcos[i] = cosf(ang);
|
|
|
|
g_mdsin[i] = sinf(ang);
|
2013-09-13 20:23:56 +00:00
|
|
|
}
|
2014-09-30 04:18:43 +00:00
|
|
|
|
|
|
|
mdtrig_init = 1;
|
2013-09-13 20:23:56 +00:00
|
|
|
}
|
2010-12-24 15:44:37 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
int md3postload_polymer(md3model_t *m)
|
2010-12-24 15:44:37 +00:00
|
|
|
{
|
|
|
|
#ifdef POLYMER
|
2017-07-22 04:00:33 +00:00
|
|
|
int framei, surfi, verti, trii;
|
2013-09-13 20:23:56 +00:00
|
|
|
float vec1[5], vec2[5], mat[9], r;
|
2009-03-10 12:08:33 +00:00
|
|
|
|
2015-02-05 16:30:09 +00:00
|
|
|
// POLYMER_MD_PROCESS_CHECK
|
2011-06-19 18:30:32 +00:00
|
|
|
if (m->head.surfs[0].geometry)
|
|
|
|
return -1; // already postprocessed
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
if (!mdtrig_init)
|
|
|
|
init_mdtrig_arrays();
|
2013-09-13 20:23:56 +00:00
|
|
|
|
2009-03-10 12:08:33 +00:00
|
|
|
// let's also repack the geometry to more usable formats
|
|
|
|
|
|
|
|
surfi = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (surfi < m->head.numsurfs)
|
2009-03-10 12:08:33 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
handleevents();
|
|
|
|
|
2015-02-05 16:30:09 +00:00
|
|
|
md3surf_t *const s = &m->head.surfs[surfi];
|
2011-06-19 18:30:32 +00:00
|
|
|
#ifdef DEBUG_MODEL_MEM
|
|
|
|
i = (m->head.numframes * s->numverts * sizeof(float) * 15);
|
|
|
|
if (i > 1<<20)
|
|
|
|
initprintf("size %d (%d fr, %d v): md %s surf %d/%d\n", i, m->head.numframes, s->numverts,
|
2011-09-06 17:45:39 +00:00
|
|
|
m->head.nam, surfi, m->head.numsurfs);
|
2011-06-19 18:30:32 +00:00
|
|
|
#endif
|
2014-09-30 04:18:43 +00:00
|
|
|
s->geometry = (float *)Xcalloc(m->head.numframes * s->numverts * 15, sizeof(float));
|
2009-03-10 12:08:33 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
if (s->numverts > tribufverts)
|
|
|
|
{
|
|
|
|
tribuf = (int32_t *) Xrealloc(tribuf, s->numverts * sizeof(int32_t));
|
|
|
|
tribufverts = s->numverts;
|
|
|
|
}
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2017-07-28 11:29:16 +00:00
|
|
|
Bmemset(tribuf, 0, s->numverts * sizeof(int32_t));
|
|
|
|
|
2009-03-10 12:08:33 +00:00
|
|
|
verti = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (verti < (m->head.numframes * s->numverts))
|
2009-03-10 12:08:33 +00:00
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
md3xyzn_t const & xyzn = s->xyzn[verti];
|
|
|
|
|
2013-09-13 20:23:56 +00:00
|
|
|
// normal extraction from packed spherical coordinates
|
|
|
|
// FIXME: swapping lat and lng because of npherno's compiler
|
2017-07-22 04:00:33 +00:00
|
|
|
uint8_t lat = xyzn.nlng;
|
|
|
|
uint8_t lng = xyzn.nlat;
|
|
|
|
size_t verti15 = (size_t)verti * 15;
|
2013-09-13 20:23:56 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
s->geometry[verti15 + 0] = xyzn.x;
|
|
|
|
s->geometry[verti15 + 1] = xyzn.y;
|
|
|
|
s->geometry[verti15 + 2] = xyzn.z;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
s->geometry[verti15 + 3] = g_mdcos[lat] * g_mdsin[lng];
|
|
|
|
s->geometry[verti15 + 4] = g_mdsin[lat] * g_mdsin[lng];
|
|
|
|
s->geometry[verti15 + 5] = g_mdcos[lng];
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++verti;
|
2010-01-24 05:57:43 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
uint32_t numverts = s->numverts;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
|
|
|
trii = 0;
|
2017-07-28 11:29:12 +00:00
|
|
|
while (trii < s->numtris)
|
2010-01-24 05:57:43 +00:00
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
int32_t const * const i = s->tris[trii].i;
|
|
|
|
uint32_t const * const u = (uint32_t const *)i;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
// let the vertices know they're being referenced by a triangle
|
2017-07-22 04:00:33 +00:00
|
|
|
if (u[0] >= numverts ||u[1] >= numverts || u[2] >= numverts)
|
2011-01-16 02:50:27 +00:00
|
|
|
{
|
2010-04-26 00:51:44 +00:00
|
|
|
// corrupt model
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
tribuf[u[0]]++;
|
|
|
|
tribuf[u[1]]++;
|
|
|
|
tribuf[u[2]]++;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
uint32_t const tris15[] = { u[0] * 15, u[1] * 15, u[2] * 15 };
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2009-03-10 14:30:34 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
framei = 0;
|
2017-07-22 04:00:33 +00:00
|
|
|
while (framei < m->head.numframes)
|
2010-01-24 05:57:43 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
const uint32_t verti15 = framei * s->numverts * 15;
|
|
|
|
|
|
|
|
vec1[0] = s->geometry[verti15 + tris15[1]] - s->geometry[verti15 + tris15[0]];
|
|
|
|
vec1[1] = s->geometry[verti15 + tris15[1] + 1] - s->geometry[verti15 + tris15[0] + 1];
|
|
|
|
vec1[2] = s->geometry[verti15 + tris15[1] + 2] - s->geometry[verti15 + tris15[0] + 2];
|
2017-07-22 04:00:33 +00:00
|
|
|
vec1[3] = s->uv[u[1]].u - s->uv[u[0]].u;
|
|
|
|
vec1[4] = s->uv[u[1]].v - s->uv[u[0]].v;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
vec2[0] = s->geometry[verti15 + tris15[2]] - s->geometry[verti15 + tris15[1]];
|
2014-09-30 04:18:43 +00:00
|
|
|
vec2[1] = s->geometry[verti15 + tris15[2] + 1] - s->geometry[verti15 + tris15[1] + 1];
|
|
|
|
vec2[2] = s->geometry[verti15 + tris15[2] + 2] - s->geometry[verti15 + tris15[1] + 2];
|
2017-07-22 04:00:33 +00:00
|
|
|
vec2[3] = s->uv[u[2]].u - s->uv[u[1]].u;
|
|
|
|
vec2[4] = s->uv[u[2]].v - s->uv[u[1]].v;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2011-09-06 17:45:39 +00:00
|
|
|
r = (vec1[3] * vec2[4] - vec2[3] * vec1[4]);
|
|
|
|
if (r != 0.0f)
|
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
r = 1.f/r;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2011-09-06 17:45:39 +00:00
|
|
|
// tangent
|
|
|
|
mat[0] = (vec2[4] * vec1[0] - vec1[4] * vec2[0]) * r;
|
|
|
|
mat[1] = (vec2[4] * vec1[1] - vec1[4] * vec2[1]) * r;
|
|
|
|
mat[2] = (vec2[4] * vec1[2] - vec1[4] * vec2[2]) * r;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2011-09-06 17:45:39 +00:00
|
|
|
normalize(&mat[0]);
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2011-09-06 17:45:39 +00:00
|
|
|
// bitangent
|
|
|
|
mat[3] = (vec1[3] * vec2[0] - vec2[3] * vec1[0]) * r;
|
|
|
|
mat[4] = (vec1[3] * vec2[1] - vec2[3] * vec1[1]) * r;
|
|
|
|
mat[5] = (vec1[3] * vec2[2] - vec2[3] * vec1[2]) * r;
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2011-09-06 17:45:39 +00:00
|
|
|
normalize(&mat[3]);
|
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
else
|
|
|
|
Bmemset(mat, 0, sizeof(float) * 6);
|
2010-01-24 05:57:43 +00:00
|
|
|
|
|
|
|
// T and B are shared for the three vertices in that triangle
|
2017-07-22 04:00:33 +00:00
|
|
|
size_t const offs = (framei * numverts * 15) + 6;
|
|
|
|
size_t j = 0;
|
2014-09-30 04:18:43 +00:00
|
|
|
do
|
2010-01-24 05:57:43 +00:00
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
size_t const offsi = offs + j;
|
|
|
|
s->geometry[offsi + tris15[0]] += mat[j];
|
|
|
|
s->geometry[offsi + tris15[1]] += mat[j];
|
|
|
|
s->geometry[offsi + tris15[2]] += mat[j];
|
2014-09-30 04:18:43 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
while (++j < 6);
|
|
|
|
|
|
|
|
++framei;
|
2010-01-24 05:57:43 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++trii;
|
2010-01-24 05:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now that we accumulated the TBNs, average and invert them for each vertex
|
2017-07-28 11:29:12 +00:00
|
|
|
int verti_end = m->head.numframes * s->numverts;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
verti = 0;
|
|
|
|
while (verti < verti_end)
|
2010-01-24 05:57:43 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
const int32_t curnumtris = tribuf[verti % s->numverts];
|
2017-07-22 04:00:33 +00:00
|
|
|
uint32_t const verti15 = verti * 15;
|
2011-09-06 17:45:39 +00:00
|
|
|
|
|
|
|
if (curnumtris > 0)
|
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
const float rfcurnumtris = 1.f/(float)curnumtris;
|
2017-07-22 04:00:33 +00:00
|
|
|
size_t i = 6;
|
|
|
|
do
|
|
|
|
s->geometry[i + verti15] *= rfcurnumtris;
|
|
|
|
while (++i < 12);
|
2011-09-06 17:45:39 +00:00
|
|
|
}
|
|
|
|
#ifdef DEBUG_MODEL_MEM
|
|
|
|
else if (verti == verti%s->numverts)
|
2010-01-24 05:57:43 +00:00
|
|
|
{
|
2011-09-06 17:45:39 +00:00
|
|
|
OSD_Printf("%s: vert %d is unused\n", m->head.nam, verti);
|
2010-01-24 05:57:43 +00:00
|
|
|
}
|
2011-09-06 17:45:39 +00:00
|
|
|
#endif
|
2010-01-24 05:57:43 +00:00
|
|
|
// copy N over
|
2014-09-30 04:18:43 +00:00
|
|
|
Bmemcpy(&s->geometry[verti15 + 12], &s->geometry[verti15 + 3], sizeof(float) * 3);
|
|
|
|
invertmatrix(&s->geometry[verti15 + 6], mat);
|
|
|
|
Bmemcpy(&s->geometry[verti15 + 6], mat, sizeof(float) * 9);
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++verti;
|
2009-03-10 12:08:33 +00:00
|
|
|
}
|
2017-07-22 04:00:33 +00:00
|
|
|
|
|
|
|
++surfi;
|
2009-03-10 12:08:33 +00:00
|
|
|
}
|
2010-04-26 00:51:44 +00:00
|
|
|
|
2011-02-27 21:07:37 +00:00
|
|
|
#else
|
|
|
|
UNREFERENCED_PARAMETER(m);
|
2010-12-24 15:44:37 +00:00
|
|
|
#endif
|
2011-02-27 21:07:37 +00:00
|
|
|
|
|
|
|
return 1;
|
2009-03-10 09:26:25 +00:00
|
|
|
}
|
|
|
|
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2016-06-21 00:33:58 +00:00
|
|
|
void md3_vox_calcmat_common(const uspritetype *tspr, const vec3f_t *a0, float f, float mat[16])
|
2012-08-19 12:52:10 +00:00
|
|
|
{
|
|
|
|
float g;
|
|
|
|
float k0, k1, k2, k3, k4, k5, k6, k7;
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
k0 = ((float)(tspr->x-globalposx))*f*(1.f/1024.f);
|
|
|
|
k1 = ((float)(tspr->y-globalposy))*f*(1.f/1024.f);
|
2012-08-19 12:52:10 +00:00
|
|
|
f = gcosang2*gshang;
|
|
|
|
g = gsinang2*gshang;
|
2014-09-30 04:18:43 +00:00
|
|
|
k4 = (float)sintable[(tspr->ang+spriteext[tspr->owner].angoff+1024)&2047] * (1.f/16384.f);
|
|
|
|
k5 = (float)sintable[(tspr->ang+spriteext[tspr->owner].angoff+ 512)&2047] * (1.f/16384.f);
|
2012-08-19 12:52:10 +00:00
|
|
|
k2 = k0*(1-k4)+k1*k5;
|
|
|
|
k3 = k1*(1-k4)-k0*k5;
|
|
|
|
k6 = f*gstang - gsinang*gctang; k7 = g*gstang + gcosang*gctang;
|
|
|
|
mat[0] = k4*k6 + k5*k7; mat[4] = gchang*gstang; mat[ 8] = k4*k7 - k5*k6; mat[12] = k2*k6 + k3*k7;
|
|
|
|
k6 = f*gctang + gsinang*gstang; k7 = g*gctang - gcosang*gstang;
|
|
|
|
mat[1] = k4*k6 + k5*k7; mat[5] = gchang*gctang; mat[ 9] = k4*k7 - k5*k6; mat[13] = k2*k6 + k3*k7;
|
|
|
|
k6 = gcosang2*gchang; k7 = gsinang2*gchang;
|
|
|
|
mat[2] = k4*k6 + k5*k7; mat[6] =-gshang; mat[10] = k4*k7 - k5*k6; mat[14] = k2*k6 + k3*k7;
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
mat[12] = (mat[12] + a0->y*mat[0]) + (a0->z*mat[4] + a0->x*mat[ 8]);
|
|
|
|
mat[13] = (mat[13] + a0->y*mat[1]) + (a0->z*mat[5] + a0->x*mat[ 9]);
|
|
|
|
mat[14] = (mat[14] + a0->y*mat[2]) + (a0->z*mat[6] + a0->x*mat[10]);
|
2012-08-19 12:52:10 +00:00
|
|
|
}
|
|
|
|
|
2014-10-25 03:26:46 +00:00
|
|
|
static void md3draw_handle_triangles(const md3surf_t *s, uint16_t *indexhandle,
|
2013-03-21 10:19:41 +00:00
|
|
|
int32_t texunits, const md3model_t *M)
|
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
int32_t i;
|
2013-03-21 10:19:41 +00:00
|
|
|
|
|
|
|
if (r_vertexarrays)
|
|
|
|
{
|
|
|
|
int32_t k = 0;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2014-10-25 03:26:31 +00:00
|
|
|
if (M == NULL)
|
2013-03-21 10:19:41 +00:00
|
|
|
{
|
2014-10-25 03:26:31 +00:00
|
|
|
for (i=s->numtris-1; i>=0; i--, k+=3)
|
|
|
|
{
|
|
|
|
indexhandle[k] = s->tris[i].i[0];
|
|
|
|
indexhandle[k+1] = s->tris[i].i[1];
|
|
|
|
indexhandle[k+2] = s->tris[i].i[2];
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (i=s->numtris-1; i>=0; i--, k+=3)
|
|
|
|
{
|
|
|
|
uint16_t tri = M->indexes[i];
|
2013-03-21 10:19:41 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
indexhandle[k] = s->tris[tri].i[0];
|
|
|
|
indexhandle[k+1] = s->tris[tri].i[1];
|
|
|
|
indexhandle[k+2] = s->tris[tri].i[2];
|
2013-03-21 10:19:41 +00:00
|
|
|
}
|
2014-09-30 04:18:43 +00:00
|
|
|
return;
|
2013-03-21 10:19:41 +00:00
|
|
|
}
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
2014-09-30 04:18:43 +00:00
|
|
|
for (i=s->numtris-1; i>=0; i--)
|
2013-03-21 10:19:41 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
uint16_t tri = M ? M->indexes[i] : i;
|
|
|
|
int32_t j;
|
|
|
|
|
|
|
|
for (j=0; j<3; j++)
|
2013-03-21 10:19:41 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
int32_t k = s->tris[tri].i[j];
|
2013-03-21 10:19:41 +00:00
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2018-02-16 06:38:21 +00:00
|
|
|
if (texunits > GL_TEXTURE0)
|
2013-03-21 10:19:41 +00:00
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
int32_t l = GL_TEXTURE0;
|
2014-09-30 04:18:43 +00:00
|
|
|
while (l <= texunits)
|
2018-02-16 06:38:21 +00:00
|
|
|
glMultiTexCoord2f(l++, s->uv[k].u, s->uv[k].v);
|
2013-03-21 10:19:41 +00:00
|
|
|
}
|
2014-09-30 04:18:43 +00:00
|
|
|
else
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2018-02-16 06:38:21 +00:00
|
|
|
glTexCoord2f(s->uv[k].u, s->uv[k].v);
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glVertex3fv((float *) &vertlist[k]);
|
2013-03-21 10:19:41 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-16 06:38:21 +00:00
|
|
|
glEnd();
|
2016-01-08 01:33:20 +00:00
|
|
|
|
|
|
|
#ifndef USE_GLEXT
|
|
|
|
UNREFERENCED_PARAMETER(texunits);
|
|
|
|
#endif
|
2013-03-21 10:19:41 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 00:33:58 +00:00
|
|
|
static int32_t polymost_md3draw(md3model_t *m, const uspritetype *tspr)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
vec3f_t m0, m1, a0;
|
2006-04-24 19:04:22 +00:00
|
|
|
md3xyzn_t *v0, *v1;
|
2013-03-21 10:19:41 +00:00
|
|
|
int32_t i, surfi;
|
2012-08-19 13:02:47 +00:00
|
|
|
float f, g, k0, k1, k2=0, k3=0, mat[16]; // inits: compiler-happy
|
2008-03-22 10:23:57 +00:00
|
|
|
GLfloat pc[4];
|
2018-02-16 06:38:21 +00:00
|
|
|
int32_t texunits = GL_TEXTURE0;
|
2013-03-21 10:19:41 +00:00
|
|
|
|
2013-03-21 10:19:55 +00:00
|
|
|
const int32_t owner = tspr->owner;
|
|
|
|
// PK: XXX: These owner bound checks are redundant because sext is
|
|
|
|
// dereferenced unconditionally below anyway.
|
|
|
|
const spriteext_t *const sext = ((unsigned)owner < MAXSPRITES+MAXUNIQHUDID) ? &spriteext[owner] : NULL;
|
|
|
|
const uint8_t lpal = ((unsigned)owner < MAXSPRITES) ? sprite[tspr->owner].pal : tspr->pal;
|
2014-09-30 04:14:21 +00:00
|
|
|
const int32_t sizyrep = tilesiz[tspr->picnum].y*tspr->yrepeat;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vbos && (m->vbos == NULL))
|
|
|
|
mdloadvbos(m);
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// if ((tspr->cstat&48) == 32) return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-01-22 17:18:49 +00:00
|
|
|
updateanimation((md2model_t *)m, tspr, lpal);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//create current&next frame's vertex list from whole list
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
f = m->interpol; g = 1.f - f;
|
2006-09-17 20:16:20 +00:00
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
if (m->interpol < 0.f || m->interpol > 1.f ||
|
|
|
|
(unsigned)m->cframe >= (unsigned)m->numframes ||
|
|
|
|
(unsigned)m->nframe >= (unsigned)m->numframes)
|
2008-08-12 06:13:10 +00:00
|
|
|
{
|
2012-02-13 21:37:46 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
2012-01-12 20:48:38 +00:00
|
|
|
OSD_Printf("%s: mdframe oob: c:%d n:%d total:%d interpol:%.02f\n",
|
|
|
|
m->head.nam, m->cframe, m->nframe, m->numframes, m->interpol);
|
2012-02-13 21:37:46 +00:00
|
|
|
#endif
|
2014-09-30 04:18:43 +00:00
|
|
|
|
|
|
|
m->interpol = fclamp(m->interpol, 0.f, 1.f);
|
|
|
|
m->cframe = clamp(m->cframe, 0, m->numframes-1);
|
|
|
|
m->nframe = clamp(m->nframe, 0, m->numframes-1);
|
2008-08-12 06:13:10 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 04:00:33 +00:00
|
|
|
m0.z = m0.y = m0.x = g *= m->scale * (1.f/64.f);
|
|
|
|
m1.z = m1.y = m1.x = f *= m->scale * (1.f/64.f);
|
2006-09-17 20:16:20 +00:00
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
a0.x = a0.y = 0;
|
|
|
|
a0.z = m->zadd * m->scale;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// Parkar: Moved up to be able to use k0 for the y-flipping code
|
2009-07-09 02:29:48 +00:00
|
|
|
k0 = (float)tspr->z;
|
2013-09-13 20:23:45 +00:00
|
|
|
if ((globalorientation&128) && !((globalorientation&48)==32))
|
|
|
|
k0 += (float)(sizyrep<<1);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// Parkar: Changed to use the same method as centeroriented sprites
|
2006-04-24 19:04:22 +00:00
|
|
|
if (globalorientation&8) //y-flipping
|
|
|
|
{
|
|
|
|
m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z;
|
2013-09-13 20:23:45 +00:00
|
|
|
k0 -= (float)(sizyrep<<2);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
if (globalorientation&4) { m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y; } //x-flipping
|
|
|
|
|
2012-01-17 04:31:59 +00:00
|
|
|
// yoffset differs from zadd in that it does not follow cstat&8 y-flipping
|
|
|
|
a0.z += m->yoffset*m->scale;
|
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
f = ((float)tspr->xrepeat) * (1.f/64.f) * m->bscale;
|
|
|
|
m0.x *= f; m0.y *= -f;
|
|
|
|
m1.x *= f; m1.y *= -f;
|
|
|
|
a0.x *= f; a0.y *= -f;
|
|
|
|
f = ((float)tspr->yrepeat) * (1.f/64.f) * m->bscale;
|
2006-04-13 20:47:06 +00:00
|
|
|
m0.z *= f; m1.z *= f; a0.z *= f;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// floor aligned
|
2009-07-09 02:29:48 +00:00
|
|
|
k1 = (float)tspr->y;
|
2006-11-13 23:12:47 +00:00
|
|
|
if ((globalorientation&48)==32)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
m0.z = -m0.z; m1.z = -m1.z; a0.z = -a0.z;
|
|
|
|
m0.y = -m0.y; m1.y = -m1.y; a0.y = -a0.y;
|
|
|
|
f = a0.x; a0.x = a0.z; a0.z = f;
|
2013-09-13 20:23:45 +00:00
|
|
|
k1 += (float)(sizyrep>>3);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2013-09-13 20:23:45 +00:00
|
|
|
// Note: These SCREEN_FACTORS will be neutralized in axes offset
|
|
|
|
// calculations below again, but are needed for the base offsets.
|
2014-10-25 03:27:35 +00:00
|
|
|
f = (65536.f*512.f)/(fxdimen*fviewingrange);
|
|
|
|
g = 32.f/(fxdimen*gxyaspect);
|
2014-09-30 04:18:43 +00:00
|
|
|
m0.y *= f; m1.y *= f; a0.y = (((float)(tspr->x-globalposx))* (1.f/1024.f) + a0.y)*f;
|
2014-10-25 03:27:35 +00:00
|
|
|
m0.x *=-f; m1.x *=-f; a0.x = ((k1 -fglobalposy) * -(1.f/1024.f) + a0.x)*-f;
|
|
|
|
m0.z *= g; m1.z *= g; a0.z = ((k0 -fglobalposz) * -(1.f/16384.f) + a0.z)*g;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-08-19 12:52:10 +00:00
|
|
|
md3_vox_calcmat_common(tspr, &a0, f, mat);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// floor aligned
|
2006-11-13 23:12:47 +00:00
|
|
|
if ((globalorientation&48)==32)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
f = mat[4]; mat[4] = mat[8]*16.f; mat[8] = -f*(1.f/16.f);
|
|
|
|
f = mat[5]; mat[5] = mat[9]*16.f; mat[9] = -f*(1.f/16.f);
|
|
|
|
f = mat[6]; mat[6] = mat[10]*16.f; mat[10] = -f*(1.f/16.f);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Mirrors
|
|
|
|
if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; }
|
|
|
|
|
|
|
|
//------------
|
2015-10-23 23:00:21 +00:00
|
|
|
// TSPR_EXTRA_MDHACK is an ugly hack in game.c:G_DoSpriteAnimations() telling md2sprite
|
|
|
|
// to use Z-buffer hacks to hide overdraw problems with the flat-tsprite-on-floor shadows,
|
|
|
|
// also disabling detail, glow, normal, and specular maps.
|
2014-10-25 03:27:35 +00:00
|
|
|
|
2015-10-21 19:54:14 +00:00
|
|
|
if (tspr->extra&TSPR_EXTRA_MDHACK)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-10-25 03:27:35 +00:00
|
|
|
#ifdef __arm__ // GL ES has a glDepthRangef and the loss of precision is OK there
|
|
|
|
float f = (float) (tspr->owner + 1) * (FLT_EPSILON * 8.0);
|
|
|
|
if (f != 0.0) f *= 1.f/(float) (sepldist(globalposx - tspr->x, globalposy - tspr->y)>>5);
|
|
|
|
#else
|
|
|
|
double f = (double) (tspr->owner + 1) * (FLT_EPSILON * 8.0);
|
|
|
|
if (f != 0.0) f *= 1.0/(double) (sepldist(globalposx - tspr->x, globalposy - tspr->y)>>5);
|
2018-02-16 06:38:21 +00:00
|
|
|
// glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
|
2014-10-25 03:27:35 +00:00
|
|
|
#endif
|
2018-02-16 06:38:21 +00:00
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
// glDepthRange(0.0 - f, 1.0 - f);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-10-25 03:27:35 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
// glPushAttrib(GL_POLYGON_BIT);
|
|
|
|
if ((grhalfxdown10x >= 0) ^((globalorientation&8) != 0) ^((globalorientation&4) != 0)) glFrontFace(GL_CW); else glFrontFace(GL_CCW);
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glCullFace(GL_BACK);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
// tinting
|
2012-03-20 18:32:00 +00:00
|
|
|
pc[0] = pc[1] = pc[2] = ((float)(numshades-min(max((globalshade * shadescale)+m->shadeoff,0),numshades)))/((float)numshades);
|
2017-06-21 13:46:50 +00:00
|
|
|
polytintflags_t const tintflags = hictinting[globalpal].f;
|
|
|
|
if (!(tintflags & HICTINT_PRECOMPUTED))
|
2008-03-27 21:32:23 +00:00
|
|
|
{
|
2015-04-14 08:07:08 +00:00
|
|
|
if (!(m->flags&1))
|
2014-05-28 22:40:17 +00:00
|
|
|
hictinting_apply(pc, globalpal);
|
2008-04-07 00:43:09 +00:00
|
|
|
else globalnoeffect=1;
|
2008-03-27 21:32:23 +00:00
|
|
|
}
|
2006-12-05 20:39:29 +00:00
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
// global tinting
|
|
|
|
if (have_basepal_tint())
|
|
|
|
hictinting_apply(pc, MAXPALOOKUPS-1);
|
|
|
|
|
2016-10-09 07:55:23 +00:00
|
|
|
pc[3] = (tspr->cstat&2) ? glblend[tspr->blend].def[!!(tspr->cstat&512)].alpha : 1.0f;
|
2013-03-21 10:19:55 +00:00
|
|
|
pc[3] *= 1.0f - sext->alpha;
|
2016-10-09 07:55:13 +00:00
|
|
|
|
2016-10-09 07:55:23 +00:00
|
|
|
handle_blend(!!(tspr->cstat & 2), tspr->blend, !!(tspr->cstat & 512));
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
if (m->usesalpha) //Sprites with alpha in texture
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
// glEnable(GL_BLEND);// glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
// glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER,0.32);
|
2006-04-24 19:04:22 +00:00
|
|
|
// float al = 0.32;
|
2006-04-13 20:47:06 +00:00
|
|
|
// PLAG : default cutoff removed
|
2006-04-24 19:04:22 +00:00
|
|
|
float al = 0.0;
|
2006-04-13 20:47:06 +00:00
|
|
|
if (alphahackarray[globalpicnum] != 0)
|
2015-03-24 00:40:33 +00:00
|
|
|
al=alphahackarray[globalpicnum] * (1.f/255.f);
|
2018-02-16 06:38:21 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glEnable(GL_ALPHA_TEST);
|
|
|
|
glAlphaFunc(GL_GREATER,al);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-09 07:55:13 +00:00
|
|
|
if ((tspr->cstat&2) || sext->alpha > 0.f || pc[3] < 1.0f)
|
2018-02-16 06:38:21 +00:00
|
|
|
glEnable(GL_BLEND); //else glDisable(GL_BLEND);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2018-02-16 06:38:21 +00:00
|
|
|
glColor4f(pc[0],pc[1],pc[2],pc[3]);
|
2013-03-21 10:20:01 +00:00
|
|
|
//if (MFLAGS_NOCONV(m))
|
2018-02-16 06:38:21 +00:00
|
|
|
// glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
2006-04-24 19:04:22 +00:00
|
|
|
//------------
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
// PLAG: Cleaner model rotation code
|
2014-10-25 03:26:46 +00:00
|
|
|
if (sext->pitch || sext->roll)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-07-22 04:00:33 +00:00
|
|
|
float f = 1.f/(fxdimen * fviewingrange) * (256.f/(65536.f*128.f)) * (m0.x+m1.x);
|
2014-09-30 04:18:43 +00:00
|
|
|
Bmemset(&a0, 0, sizeof(a0));
|
|
|
|
|
2014-10-25 03:36:34 +00:00
|
|
|
if (sext->offset.x)
|
|
|
|
a0.x = (float) sext->offset.x * f;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2014-10-25 03:36:34 +00:00
|
|
|
if (sext->offset.y) // Compare with SCREEN_FACTORS above
|
|
|
|
a0.y = (float) sext->offset.y * f;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2015-10-21 19:54:14 +00:00
|
|
|
if ((sext->offset.z) && !(tspr->extra&TSPR_EXTRA_MDHACK)) // Compare with SCREEN_FACTORS above
|
2017-07-22 04:00:33 +00:00
|
|
|
a0.z = (float)sext->offset.z / (gxyaspect * fxdimen * (65536.f/128.f) * (m0.z+m1.z));
|
2014-09-30 04:18:43 +00:00
|
|
|
|
|
|
|
k0 = (float)sintable[(sext->pitch+512)&2047] * (1.f/16384.f);
|
|
|
|
k1 = (float)sintable[sext->pitch&2047] * (1.f/16384.f);
|
|
|
|
k2 = (float)sintable[(sext->roll+512)&2047] * (1.f/16384.f);
|
|
|
|
k3 = (float)sintable[sext->roll&2047] * (1.f/16384.f);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2012-02-13 21:37:46 +00:00
|
|
|
|
2015-11-25 12:07:36 +00:00
|
|
|
float const xpanning = (float)sext->xpanning * (1.f/256.f);
|
|
|
|
float const ypanning = (float)sext->ypanning * (1.f/256.f);
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (surfi=0; surfi<m->head.numsurfs; surfi++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2013-03-21 10:19:41 +00:00
|
|
|
//PLAG : sorting stuff
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2013-03-21 10:19:41 +00:00
|
|
|
void *vbotemp;
|
2014-09-30 04:18:43 +00:00
|
|
|
vec3f_t *vertexhandle = NULL;
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2014-10-25 03:26:31 +00:00
|
|
|
uint16_t *indexhandle;
|
2014-10-25 03:26:46 +00:00
|
|
|
vec3f_t fp;
|
2013-03-21 10:19:41 +00:00
|
|
|
|
2013-04-13 03:50:57 +00:00
|
|
|
const md3surf_t *const s = &m->head.surfs[surfi];
|
2013-03-21 10:19:41 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
v0 = &s->xyzn[m->cframe*s->numverts];
|
|
|
|
v1 = &s->xyzn[m->nframe*s->numverts];
|
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
{
|
|
|
|
if (++curvbo >= r_vbocount)
|
|
|
|
curvbo = 0;
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vertvbos[curvbo]);
|
|
|
|
vbotemp = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
|
2014-09-30 04:18:43 +00:00
|
|
|
vertexhandle = (vec3f_t *)vbotemp;
|
2007-03-08 03:07:10 +00:00
|
|
|
}
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2014-10-25 03:26:46 +00:00
|
|
|
if (sext->pitch || sext->roll)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-10-25 03:26:46 +00:00
|
|
|
vec3f_t fp1, fp2;
|
2013-03-21 10:20:01 +00:00
|
|
|
|
2014-10-25 03:26:46 +00:00
|
|
|
for (i=s->numverts-1; i>=0; i--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-10-25 03:26:46 +00:00
|
|
|
fp.z = v0[i].x + a0.x;
|
|
|
|
fp.x = v0[i].y + a0.y;
|
|
|
|
fp.y = v0[i].z + a0.z;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2014-10-25 03:26:46 +00:00
|
|
|
fp1.x = fp.x*k2 + fp.y*k3;
|
|
|
|
fp1.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1);
|
|
|
|
fp1.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2014-10-25 03:26:46 +00:00
|
|
|
fp.z = v1[i].x + a0.x;
|
|
|
|
fp.x = v1[i].y + a0.y;
|
|
|
|
fp.y = v1[i].z + a0.z;
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
fp2.x = fp.x*k2 + fp.y*k3;
|
|
|
|
fp2.y = fp.x*k0*(-k3) + fp.y*k0*k2 + fp.z*(-k1);
|
|
|
|
fp2.z = fp.x*k1*(-k3) + fp.y*k1*k2 + fp.z*k0;
|
|
|
|
fp.z = (fp1.z - a0.x)*m0.x + (fp2.z - a0.x)*m1.x;
|
|
|
|
fp.x = (fp1.x - a0.y)*m0.y + (fp2.x - a0.y)*m1.y;
|
|
|
|
fp.y = (fp1.y - a0.z)*m0.z + (fp2.y - a0.z)*m1.z;
|
2014-10-25 03:26:46 +00:00
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2014-10-25 03:26:46 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
vertexhandle[i] = fp;
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2014-10-25 03:26:46 +00:00
|
|
|
|
|
|
|
vertlist[i] = fp;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-10-25 03:26:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i=s->numverts-1; i>=0; i--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
fp.z = v0[i].x*m0.x + v1[i].x*m1.x;
|
|
|
|
fp.y = v0[i].z*m0.z + v1[i].z*m1.z;
|
|
|
|
fp.x = v0[i].y*m0.y + v1[i].y*m1.y;
|
2013-03-21 10:20:01 +00:00
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2014-10-25 03:26:46 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
vertexhandle[i] = fp;
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2014-10-25 03:26:46 +00:00
|
|
|
vertlist[i] = fp;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glUnmapBuffer(GL_ARRAY_BUFFER);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2007-03-08 03:07:10 +00:00
|
|
|
}
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation
|
|
|
|
mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; glLoadMatrixf(mat);
|
2006-04-24 19:04:22 +00:00
|
|
|
// PLAG: End
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-04-29 20:54:22 +00:00
|
|
|
i = mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,globalpal,surfi);
|
|
|
|
if (!i)
|
|
|
|
continue;
|
2008-05-27 15:47:24 +00:00
|
|
|
//i = mdloadskin((md2model *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,surfi); //hack for testing multiple surfaces per MD3
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, i);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef(xpanning, ypanning, 1.0f);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2015-11-25 12:07:36 +00:00
|
|
|
|
2015-10-21 19:54:14 +00:00
|
|
|
if (!(tspr->extra&TSPR_EXTRA_MDHACK))
|
2007-02-15 01:35:34 +00:00
|
|
|
{
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2018-03-21 20:41:26 +00:00
|
|
|
//POGOTODO: if we add support for palette indexing on model skins, the texture for the palswap could be setup here
|
|
|
|
texunits += 4;
|
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
i = r_detailmapping ? mdloadskin((md2model_t *) m, tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum, DETAILPAL, surfi) : 0;
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
mdskinmap_t *sk;
|
2013-03-21 10:19:41 +00:00
|
|
|
|
2018-03-21 20:41:26 +00:00
|
|
|
polymost_useDetailMapping(true);
|
|
|
|
polymost_setupdetailtexture(GL_TEXTURE3, i);
|
2007-02-15 01:35:34 +00:00
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
for (sk = m->skinmap; sk; sk = sk->next)
|
|
|
|
if ((int32_t) sk->palette == DETAILPAL && sk->skinnum == tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum && sk->surfnum == surfi)
|
|
|
|
f = sk->param;
|
2007-02-15 01:35:34 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef(xpanning, ypanning, 1.0f);
|
|
|
|
glScalef(f, f, 1.0f);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2014-10-25 03:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = r_glowmapping ? mdloadskin((md2model_t *) m, tile2model[Ptile2tile(tspr->picnum, lpal)].skinnum, GLOWPAL, surfi) : 0;
|
2007-02-15 01:35:34 +00:00
|
|
|
|
2014-09-30 04:14:21 +00:00
|
|
|
if (i)
|
2015-11-25 12:07:36 +00:00
|
|
|
{
|
2018-03-21 20:41:26 +00:00
|
|
|
polymost_useGlowMapping(true);
|
|
|
|
polymost_setupglowtexture(GL_TEXTURE4, i);
|
2015-11-25 12:07:36 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef(xpanning, ypanning, 1.0f);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2015-11-25 12:07:36 +00:00
|
|
|
}
|
2007-02-15 01:35:34 +00:00
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbos[curvbo]);
|
|
|
|
vbotemp = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
2014-10-25 03:27:35 +00:00
|
|
|
indexhandle = (uint16_t *) vbotemp;
|
|
|
|
}
|
|
|
|
else
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2014-10-25 03:27:35 +00:00
|
|
|
indexhandle = m->vindexes;
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
//PLAG: delayed polygon-level sorted rendering
|
2014-10-25 03:26:31 +00:00
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
if (m->usesalpha)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2016-10-09 00:15:01 +00:00
|
|
|
for (i=0; i<=s->numtris-1; ++i)
|
2014-10-25 03:27:35 +00:00
|
|
|
{
|
2016-10-09 00:15:01 +00:00
|
|
|
vec3f_t const vlt[3] = { vertlist[s->tris[i].i[0]], vertlist[s->tris[i].i[1]], vertlist[s->tris[i].i[2]] };
|
2014-10-25 03:27:35 +00:00
|
|
|
|
|
|
|
// Matrix multiplication - ugly but clear
|
2016-10-09 00:15:01 +00:00
|
|
|
vec3f_t const fp[3] = { { (vlt[0].x * mat[0]) + (vlt[0].y * mat[4]) + (vlt[0].z * mat[8]) + mat[12],
|
|
|
|
(vlt[0].x * mat[1]) + (vlt[0].y * mat[5]) + (vlt[0].z * mat[9]) + mat[13],
|
|
|
|
(vlt[0].x * mat[2]) + (vlt[0].y * mat[6]) + (vlt[0].z * mat[10]) + mat[14] },
|
2014-10-25 03:27:35 +00:00
|
|
|
|
2016-10-09 00:15:01 +00:00
|
|
|
{ (vlt[1].x * mat[0]) + (vlt[1].y * mat[4]) + (vlt[1].z * mat[8]) + mat[12],
|
|
|
|
(vlt[1].x * mat[1]) + (vlt[1].y * mat[5]) + (vlt[1].z * mat[9]) + mat[13],
|
|
|
|
(vlt[1].x * mat[2]) + (vlt[1].y * mat[6]) + (vlt[1].z * mat[10]) + mat[14] },
|
2014-10-25 03:27:35 +00:00
|
|
|
|
2016-10-09 00:15:01 +00:00
|
|
|
{ (vlt[2].x * mat[0]) + (vlt[2].y * mat[4]) + (vlt[2].z * mat[8]) + mat[12],
|
|
|
|
(vlt[2].x * mat[1]) + (vlt[2].y * mat[5]) + (vlt[2].z * mat[9]) + mat[13],
|
|
|
|
(vlt[2].x * mat[2]) + (vlt[2].y * mat[6]) + (vlt[2].z * mat[10]) + mat[14] } };
|
2014-10-25 03:27:35 +00:00
|
|
|
|
2016-10-09 00:15:01 +00:00
|
|
|
f = (fp[0].x * fp[0].x) + (fp[0].y * fp[0].y) + (fp[0].z * fp[0].z);
|
|
|
|
g = (fp[1].x * fp[1].x) + (fp[1].y * fp[1].y) + (fp[1].z * fp[1].z);
|
2014-10-25 03:27:35 +00:00
|
|
|
|
|
|
|
if (f > g)
|
|
|
|
f = g;
|
2016-10-09 00:15:01 +00:00
|
|
|
|
|
|
|
g = (fp[2].x * fp[2].x) + (fp[2].y * fp[2].y) + (fp[2].z * fp[2].z);
|
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
if (f > g)
|
|
|
|
f = g;
|
|
|
|
|
|
|
|
m->maxdepths[i] = f;
|
2016-10-09 00:15:01 +00:00
|
|
|
m->indexes[i] = i;
|
2014-10-25 03:27:35 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-10-25 03:27:35 +00:00
|
|
|
// dichotomic recursive sorting - about 100x less iterations than bubblesort
|
|
|
|
quicksort(m->indexes, m->maxdepths, 0, s->numtris - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
md3draw_handle_triangles(s, indexhandle, texunits, m->usesalpha ? m : NULL);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2014-10-25 03:27:35 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbos[curvbo]);
|
|
|
|
vbotemp = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
|
2014-10-25 03:27:35 +00:00
|
|
|
indexhandle = (uint16_t *) vbotemp;
|
|
|
|
}
|
|
|
|
else
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2014-10-25 03:27:35 +00:00
|
|
|
indexhandle = m->vindexes;
|
|
|
|
|
2013-03-21 10:19:41 +00:00
|
|
|
md3draw_handle_triangles(s, indexhandle, texunits, NULL);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2007-02-15 01:35:34 +00:00
|
|
|
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vertexarrays)
|
|
|
|
{
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2013-03-21 10:19:41 +00:00
|
|
|
int32_t l;
|
2014-10-25 03:26:46 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (r_vbos)
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m->vbos[surfi]);
|
2014-10-25 03:26:46 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
l = GL_TEXTURE0;
|
2014-10-25 03:26:46 +00:00
|
|
|
do
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glClientActiveTexture(l++);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, 0);
|
2014-10-25 03:26:46 +00:00
|
|
|
} while (l <= texunits);
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vertvbos[curvbo]);
|
|
|
|
glVertexPointer(3, GL_FLOAT, 0, 0);
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbos[curvbo]);
|
|
|
|
glDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_SHORT, 0);
|
2007-12-12 17:42:14 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2014-10-25 03:26:46 +00:00
|
|
|
else // r_vbos
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
l = GL_TEXTURE0;
|
2014-10-25 03:26:46 +00:00
|
|
|
do
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glClientActiveTexture(l++);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, &(s->uv[0].u));
|
2014-10-25 03:26:46 +00:00
|
|
|
} while (l <= texunits);
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glVertexPointer(3, GL_FLOAT, 0, &(vertlist[0].x));
|
2014-10-25 03:26:46 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_SHORT, m->vindexes);
|
2014-10-25 03:26:46 +00:00
|
|
|
} // r_vbos
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
while (texunits > GL_TEXTURE0)
|
2007-02-15 01:35:34 +00:00
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glClientActiveTexture(texunits - 1);
|
|
|
|
glActiveTexture(--texunits);
|
2007-02-15 01:35:34 +00:00
|
|
|
}
|
2016-01-08 01:33:20 +00:00
|
|
|
#else
|
2018-02-16 06:38:21 +00:00
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
glTexCoordPointer(2, GL_FLOAT, 0, &(s->uv[0].u));
|
2016-01-08 01:33:20 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glVertexPointer(3, GL_FLOAT, 0, &(vertlist[0].x));
|
2016-01-08 01:33:20 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_SHORT, m->vindexes);
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2014-10-25 03:26:46 +00:00
|
|
|
else // r_vertexarrays
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
while (texunits > GL_TEXTURE0)
|
2014-10-25 03:26:46 +00:00
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.0f);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glActiveTexture(--texunits);
|
2014-10-25 03:26:46 +00:00
|
|
|
}
|
|
|
|
} // r_vertexarrays
|
2018-03-21 20:41:26 +00:00
|
|
|
|
|
|
|
polymost_useDetailMapping(false);
|
|
|
|
polymost_useGlowMapping(false);
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
//------------
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
if (m->usesalpha) glDisable(GL_ALPHA_TEST);
|
2014-10-25 03:26:31 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
// glPopAttrib();
|
2015-11-25 12:07:36 +00:00
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2018-02-26 14:46:36 +00:00
|
|
|
|
2018-02-16 06:37:58 +00:00
|
|
|
polymost_resetVertexPointers();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-20 19:14:38 +00:00
|
|
|
globalnoeffect=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
static void md3free(md3model_t *m)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
mdanim_t *anim, *nanim = NULL;
|
|
|
|
mdskinmap_t *sk, *nsk = NULL;
|
|
|
|
|
|
|
|
if (!m) return;
|
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
for (anim=m->animations; anim; anim=nanim)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
nanim = anim->next;
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(anim);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2006-11-13 23:12:47 +00:00
|
|
|
for (sk=m->skinmap; sk; sk=nsk)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
nsk = sk->next;
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(sk->fn);
|
|
|
|
Bfree(sk);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m->head.surfs)
|
|
|
|
{
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t surfi=m->head.numsurfs-1; surfi>=0; surfi--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2015-02-05 16:30:09 +00:00
|
|
|
md3surf_t *s = &m->head.surfs[surfi];
|
|
|
|
Bfree(s->tris);
|
2015-02-10 19:51:15 +00:00
|
|
|
Bfree(s->geometry); // FREE_SURFS_GEOMETRY
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(m->head.surfs);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2015-09-23 17:55:31 +00:00
|
|
|
Bfree(m->head.tags);
|
|
|
|
Bfree(m->head.frames);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2015-09-23 17:55:31 +00:00
|
|
|
Bfree(m->texid);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2015-09-23 17:55:31 +00:00
|
|
|
Bfree(m->muladdframes);
|
2006-09-17 20:16:20 +00:00
|
|
|
|
2015-09-23 17:55:31 +00:00
|
|
|
Bfree(m->indexes);
|
|
|
|
Bfree(m->vindexes);
|
|
|
|
Bfree(m->maxdepths);
|
2007-03-03 23:09:40 +00:00
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2009-01-04 22:22:33 +00:00
|
|
|
if (m->vbos)
|
2007-03-08 03:07:10 +00:00
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glDeleteBuffers(m->head.numsurfs, m->vbos);
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(m->vbos);
|
2007-03-08 03:07:10 +00:00
|
|
|
}
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(m);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------- MD3 LIBRARY ENDS ----------------------------------------
|
|
|
|
//--------------------------------------- MD LIBRARY BEGINS ---------------------------------------
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
mdmodel_t *mdload(const char *filnam)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
mdmodel_t *vm;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t fil;
|
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
vm = (mdmodel_t *)voxload(filnam);
|
|
|
|
if (vm) return vm;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2016-01-11 05:05:38 +00:00
|
|
|
fil = kopen4load(filnam,0);
|
2014-09-30 04:18:43 +00:00
|
|
|
|
|
|
|
if (fil < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
kread(fil,&i,4);
|
|
|
|
klseek(fil,0,SEEK_SET);
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2006-11-13 23:12:47 +00:00
|
|
|
switch (B_LITTLE32(i))
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
case IDP2_MAGIC:
|
2012-03-26 05:05:57 +00:00
|
|
|
// initprintf("Warning: model \"%s\" is version IDP2; wanted version IDP3\n",filnam);
|
2011-01-16 02:50:27 +00:00
|
|
|
vm = (mdmodel_t *)md2load(fil,filnam);
|
2009-03-10 09:26:25 +00:00
|
|
|
break; //IDP2
|
2014-09-30 04:18:43 +00:00
|
|
|
case IDP3_MAGIC:
|
2011-01-16 02:50:27 +00:00
|
|
|
vm = (mdmodel_t *)md3load(fil);
|
2009-03-10 09:26:25 +00:00
|
|
|
break; //IDP3
|
2006-11-13 23:12:47 +00:00
|
|
|
default:
|
2014-09-30 04:18:43 +00:00
|
|
|
vm = NULL;
|
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
kclose(fil);
|
2010-12-24 15:44:37 +00:00
|
|
|
|
|
|
|
if (vm)
|
|
|
|
{
|
2011-09-06 17:45:39 +00:00
|
|
|
md3model_t *vm3 = (md3model_t *)vm;
|
|
|
|
|
|
|
|
// smuggle the file name into the model struct.
|
|
|
|
// head.nam is unused as far as I can tell
|
2012-03-28 19:43:21 +00:00
|
|
|
Bstrncpyz(vm3->head.nam, filnam, sizeof(vm3->head.nam));
|
2011-09-06 17:45:39 +00:00
|
|
|
|
|
|
|
md3postload_common(vm3);
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2011-06-19 18:30:32 +00:00
|
|
|
#ifdef POLYMER
|
2013-05-17 03:44:09 +00:00
|
|
|
if (glrendmode != REND_POLYMER)
|
2014-09-30 04:18:43 +00:00
|
|
|
if (md3postload_polymer_check(vm3))
|
2011-06-19 18:30:32 +00:00
|
|
|
{
|
|
|
|
mdfree(vm);
|
2014-09-30 04:18:43 +00:00
|
|
|
vm = NULL;
|
2011-06-19 18:30:32 +00:00
|
|
|
}
|
2010-12-24 15:44:37 +00:00
|
|
|
#endif
|
2010-04-26 00:51:44 +00:00
|
|
|
}
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
return vm;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2014-09-30 04:18:43 +00:00
|
|
|
void md_allocvbos(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
indexvbos = (GLuint *) Xrealloc(indexvbos, sizeof(GLuint) * r_vbocount);
|
|
|
|
vertvbos = (GLuint *) Xrealloc(vertvbos, sizeof(GLuint) * r_vbocount);
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2014-09-30 04:18:43 +00:00
|
|
|
if (r_vbocount != allocvbos)
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glGenBuffers(r_vbocount - allocvbos, &(indexvbos[allocvbos]));
|
|
|
|
glGenBuffers(r_vbocount - allocvbos, &(vertvbos[allocvbos]));
|
2007-03-08 03:07:10 +00:00
|
|
|
|
|
|
|
i = allocvbos;
|
|
|
|
while (i < r_vbocount)
|
|
|
|
{
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexvbos[i]);
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, maxmodeltris * 3 * sizeof(uint16_t), NULL, GL_STREAM_DRAW);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, vertvbos[i]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, maxmodelverts * sizeof(vec3f_t), NULL, GL_STREAM_DRAW);
|
2007-03-08 03:07:10 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2018-02-16 06:38:21 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
2007-03-08 03:07:10 +00:00
|
|
|
|
|
|
|
allocvbos = r_vbocount;
|
|
|
|
}
|
2014-09-30 04:18:43 +00:00
|
|
|
}
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2014-09-30 04:18:43 +00:00
|
|
|
|
2016-06-21 00:33:58 +00:00
|
|
|
int32_t polymost_mddraw(const uspritetype *tspr)
|
2014-09-30 04:18:43 +00:00
|
|
|
{
|
2016-01-08 01:33:20 +00:00
|
|
|
#ifdef USE_GLEXT
|
2014-09-30 04:18:43 +00:00
|
|
|
if (r_vbos && (r_vbocount > allocvbos))
|
|
|
|
md_allocvbos();
|
2016-01-08 01:33:20 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (maxmodelverts > allocmodelverts)
|
|
|
|
{
|
2014-09-30 04:18:43 +00:00
|
|
|
vertlist = (vec3f_t *) Xrealloc(vertlist, sizeof(vec3f_t)*maxmodelverts);
|
2007-03-08 03:07:10 +00:00
|
|
|
allocmodelverts = maxmodelverts;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2016-06-05 04:46:28 +00:00
|
|
|
mdmodel_t *const vm = models[tile2model[Ptile2tile(tspr->picnum,
|
2015-03-24 00:40:48 +00:00
|
|
|
(tspr->owner >= MAXSPRITES) ? tspr->pal : sprite[tspr->owner].pal)].modelid];
|
2018-03-21 20:41:26 +00:00
|
|
|
if (vm->mdnum == 1)
|
|
|
|
{
|
|
|
|
polymost_usePaletteIndexing(false);
|
|
|
|
int ret = polymost_voxdraw((voxmodel_t *)vm,tspr);
|
|
|
|
polymost_usePaletteIndexing(true);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (vm->mdnum == 3)
|
|
|
|
{
|
|
|
|
polymost_usePaletteIndexing(false);
|
|
|
|
int ret = polymost_md3draw((md3model_t *)vm,tspr);
|
|
|
|
polymost_usePaletteIndexing(true);
|
|
|
|
return ret;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
void mdfree(mdmodel_t *vm)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
if (vm->mdnum == 1) { voxfree((voxmodel_t *)vm); return; }
|
2010-06-26 08:51:42 +00:00
|
|
|
if (vm->mdnum == 2 || vm->mdnum == 3) { md3free((md3model_t *)vm); return; }
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 00:31:16 +00:00
|
|
|
#endif
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//---------------------------------------- MD LIBRARY ENDS ----------------------------------------
|