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"
|
|
|
|
#include "glbuild.h"
|
|
|
|
#include "pragmas.h"
|
|
|
|
#include "baselayer.h"
|
|
|
|
#include "engine_priv.h"
|
|
|
|
#include "hightile.h"
|
|
|
|
#include "polymost.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"
|
|
|
|
#include "md4.h"
|
|
|
|
|
2009-03-14 02:55:39 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
voxmodel_t *voxmodels[MAXVOXELS];
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t curextra=MAXTILES;
|
2009-10-07 06:47:35 +00:00
|
|
|
// nedpool *model_data_pool;
|
|
|
|
// #define MODEL_POOL_SIZE 20971520
|
|
|
|
#define model_data_pool (nedpool *) 0 // take it out of the system pool
|
2007-12-20 19:14:38 +00:00
|
|
|
|
2011-01-30 11:02:28 +00:00
|
|
|
#define MIN_CACHETIME_PRINT 5
|
|
|
|
|
|
|
|
static void QuitOnFatalError(const char *msg)
|
|
|
|
{
|
|
|
|
if (msg)
|
|
|
|
initprintf("%s\n", msg);
|
|
|
|
uninitengine();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t addtileP(int32_t model,int32_t tile,int32_t pallet)
|
2007-12-20 19:14:38 +00:00
|
|
|
{
|
2008-03-22 10:23:57 +00:00
|
|
|
UNREFERENCED_PARAMETER(model);
|
2007-12-20 19:14:38 +00:00
|
|
|
if (curextra==MAXTILES+EXTRATILES-2)return curextra;
|
2009-02-19 16:47:54 +00:00
|
|
|
if (tile2model[tile].modelid==-1) {tile2model[tile].pal=pallet; return tile;}
|
2008-01-04 01:04:35 +00:00
|
|
|
if (tile2model[tile].pal==pallet)return tile;
|
2008-02-01 03:36:54 +00:00
|
|
|
while (tile2model[tile].next!=-1)
|
2008-01-04 01:04:35 +00:00
|
|
|
{
|
|
|
|
tile=tile2model[tile].next;
|
2008-02-01 03:36:54 +00:00
|
|
|
if (tile2model[tile].pal==pallet)return tile;
|
2008-01-04 01:04:35 +00:00
|
|
|
}
|
2007-12-20 19:14:38 +00:00
|
|
|
tile2model[tile].next=curextra;
|
|
|
|
tile2model[curextra].pal=pallet;
|
|
|
|
return curextra++;
|
|
|
|
}
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t Ptile2tile(int32_t tile,int32_t pallet)
|
2007-12-20 19:14:38 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t t=tile;
|
2007-12-20 19:14:38 +00:00
|
|
|
// if(tile>=1550&&tile<=1589){initprintf("(%d, %d)\n",tile,pallet);pallet=0;}
|
|
|
|
while ((tile=tile2model[tile].next)!=-1)
|
|
|
|
if (tile2model[tile].pal==pallet)
|
|
|
|
return tile;
|
|
|
|
return t;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t mdinited=0;
|
|
|
|
int32_t mdpause=0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#define MODELALLOCGROUP 256
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t nummodelsalloced = 0, nextmodelid = 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;
|
2006-04-13 20:47:06 +00:00
|
|
|
static point3d *vertlist = NULL; //temp array to store interpolated vertices for drawing
|
|
|
|
|
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;
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
mdmodel_t *mdload(const char *);
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t mddraw(spritetype *);
|
2009-01-10 07:38:50 +00:00
|
|
|
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
|
|
|
|
2009-06-13 21:06:45 +00:00
|
|
|
void freevbos()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
bglDeleteBuffersARB(m->head.numsurfs, m->vbos);
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(m->vbos);
|
2009-06-13 21:06:45 +00:00
|
|
|
m->vbos = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (allocvbos)
|
|
|
|
{
|
|
|
|
bglDeleteBuffersARB(allocvbos, indexvbos);
|
|
|
|
bglDeleteBuffersARB(allocvbos, vertvbos);
|
|
|
|
allocvbos = 0;
|
|
|
|
}
|
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]);
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(models); models = NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
nummodelsalloced = 0;
|
|
|
|
nextmodelid = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(tile2model,-1,sizeof(tile2model));
|
2007-12-20 19:14:38 +00:00
|
|
|
curextra=MAXTILES;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (vertlist)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(vertlist);
|
2006-04-13 20:47:06 +00:00
|
|
|
vertlist = NULL;
|
|
|
|
allocmodelverts = maxmodelverts = 0;
|
2007-03-08 03:07:10 +00:00
|
|
|
allocmodeltris = maxmodeltris = 0;
|
|
|
|
}
|
2009-06-13 21:06:45 +00:00
|
|
|
freevbos();
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
/*
|
|
|
|
if (model_data_pool)
|
|
|
|
{
|
|
|
|
neddestroypool(model_data_pool);
|
|
|
|
model_data_pool = NULL;
|
|
|
|
}
|
|
|
|
*/
|
2009-01-04 22:22:33 +00:00
|
|
|
}
|
|
|
|
|
2008-12-02 10:44:39 +00:00
|
|
|
void clearskins()
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-10 07:38:50 +00:00
|
|
|
mdmodel_t *m;
|
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
|
|
|
{
|
|
|
|
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;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<MAXPALOOKUPS; j++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
if (v->texid[j]) bglDeleteTextures(1,(GLuint *)&v->texid[j]);
|
2006-04-13 20:47:06 +00:00
|
|
|
v->texid[j] = 0;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (m->mdnum == 2 || m->mdnum == 3)
|
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
md2model_t *m2 = (md2model_t *)m;
|
2006-04-13 20:47:06 +00:00
|
|
|
mdskinmap_t *sk;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<m2->numskins*(HICEFFECTMASK+1); j++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
if (m2->texid[j]) bglDeleteTextures(1,(GLuint *)&m2->texid[j]);
|
2006-04-13 20:47:06 +00:00
|
|
|
m2->texid[j] = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (sk=m2->skinmap; sk; sk=sk->next)
|
|
|
|
for (j=0; j<(HICEFFECTMASK+1); j++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
if (sk->texid[j]) bglDeleteTextures(1,(GLuint *)&sk->texid[j]);
|
2006-04-13 20:47:06 +00:00
|
|
|
sk->texid[j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<MAXVOXELS; i++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
voxmodel_t *v = (voxmodel_t *)voxmodels[i]; if (!v) continue;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<MAXPALOOKUPS; j++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
if (v->texid[j]) bglDeleteTextures(1,(GLuint *)&v->texid[j]);
|
2006-04-13 20:47:06 +00:00
|
|
|
v->texid[j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-02 10:44:39 +00:00
|
|
|
void mdinit()
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
memset(hudmem,0,sizeof(hudmem));
|
|
|
|
freeallmodels();
|
2009-10-07 06:47:35 +00:00
|
|
|
// if (!model_data_pool)
|
|
|
|
// model_data_pool = nedcreatepool(MODEL_POOL_SIZE, 0);
|
2006-04-13 20:47:06 +00:00
|
|
|
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)
|
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
ml = (mdmodel_t **)Brealloc(models,(nummodelsalloced+MODELALLOCGROUP)*sizeof(void *)); if (!ml) return(-1);
|
2006-04-13 20:47:06 +00:00
|
|
|
models = ml; nummodelsalloced += MODELALLOCGROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm = mdload(fn); if (!vm) return(-1);
|
|
|
|
models[nextmodelid++] = vm;
|
|
|
|
return(nextmodelid-1);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t md_setmisc(int32_t modelid, float scale, int32_t shadeoff, float zadd, 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;
|
2007-12-20 19:14:38 +00:00
|
|
|
m->flags = flags;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-28 07:44:54 +00:00
|
|
|
/*
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t md_tilehasmodel(int32_t tilenume,int32_t pal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
if (!mdinited) return -1;
|
2007-12-20 19:14:38 +00:00
|
|
|
return tile2model[Ptile2tile(tilenume,pal)].modelid;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2009-02-28 07:44:54 +00:00
|
|
|
*/
|
2006-04-13 20:47:06 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)modelid >= (uint32_t)nextmodelid) return(-1);
|
|
|
|
if ((uint32_t)tilenume >= (uint32_t)MAXTILES) return(-2);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!framename) return(-3);
|
|
|
|
|
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);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (i == m->numframes) return(-3); // frame name invalid
|
|
|
|
|
|
|
|
tile2model[tilenume].modelid = modelid;
|
|
|
|
tile2model[tilenume].framenum = i;
|
|
|
|
tile2model[tilenume].skinnum = skinnum;
|
2007-04-12 03:09:41 +00:00
|
|
|
tile2model[tilenume].smoothduration = smoothduration;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
|
|
|
|
memset(&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;
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
map = (mdanim_t *)Bcalloc(1,sizeof(mdanim_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!map) return(-4);
|
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;
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2009-03-28 15:19:44 +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)
|
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)
|
2009-01-09 09:29:17 +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)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
sk = (mdskinmap_t *)Bcalloc(1,sizeof(mdskinmap_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!sk) return -4;
|
|
|
|
|
|
|
|
if (!skl) m->skinmap = sk;
|
|
|
|
else skl->next = sk;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2010-05-18 00:30:30 +00:00
|
|
|
else if (sk->fn) Bfree(sk->fn);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
sk->palette = (uint8_t)palnum;
|
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;
|
2010-05-20 06:05:46 +00:00
|
|
|
sk->fn = (char *)Bmalloc(strlen(skinfn)+1);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!sk->fn) return(-4);
|
|
|
|
strcpy(sk->fn, skinfn);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-01 05:52:33 +00:00
|
|
|
int32_t md_definehud(int32_t modelid, int32_t tilex, double xadd, double yadd, double zadd, double 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
|
|
|
|
|
|
|
hudmem[(flags>>2)&1][tilex].xadd = xadd;
|
|
|
|
hudmem[(flags>>2)&1][tilex].yadd = yadd;
|
|
|
|
hudmem[(flags>>2)&1][tilex].zadd = zadd;
|
2009-01-09 09:29:17 +00:00
|
|
|
hudmem[(flags>>2)&1][tilex].angadd = ((int16_t)angadd)|2048;
|
|
|
|
hudmem[(flags>>2)&1][tilex].flags = (int16_t)flags;
|
2011-03-01 05:52:33 +00:00
|
|
|
hudmem[(flags>>2)&1][tilex].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;
|
2007-12-20 19:14:38 +00:00
|
|
|
tile2model[tile].next=-1;
|
2006-04-13 20:47:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
tile2model[i].modelid = -1;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
md2model_t *modelhead;
|
2007-12-20 19:14:38 +00:00
|
|
|
mdskinmap_t *skhead;
|
|
|
|
|
2009-04-14 22:55:32 +00:00
|
|
|
static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t *sizx, int32_t *sizy, int32_t *osizx, int32_t *osizy, char *hasalpha, int32_t pal, char effect)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t picfillen, j,y,x;
|
2006-04-24 19:04:22 +00:00
|
|
|
char *picfil,*cptr,al=255;
|
|
|
|
coltype *pic;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t xsiz, ysiz, tsizx, tsizy;
|
|
|
|
int32_t r, g, b;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
picfillen = kfilelength(filh);
|
2010-05-20 06:05:46 +00:00
|
|
|
picfil = (char *)Bmalloc(picfillen+1); if (!picfil) { return -1; }
|
2006-04-24 19:04:22 +00:00
|
|
|
kread(filh, picfil, picfillen);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// tsizx/y = replacement texture's natural size
|
|
|
|
// xsiz/y = 2^x size of replacement
|
|
|
|
|
|
|
|
kpgetdim(picfil,picfillen,&tsizx,&tsizy);
|
2011-03-19 18:01:13 +00:00
|
|
|
if (tsizx == 0 || tsizy == 0) { Bfree(picfil); return -2; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!glinfo.texnpot)
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (xsiz=1; xsiz<tsizx; xsiz+=xsiz);
|
|
|
|
for (ysiz=1; ysiz<tsizy; ysiz+=ysiz);
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
xsiz = tsizx;
|
|
|
|
ysiz = tsizy;
|
|
|
|
}
|
|
|
|
*osizx = tsizx; *osizy = tsizy;
|
2010-05-20 06:05:46 +00:00
|
|
|
pic = (coltype *)Bmalloc(xsiz*ysiz*sizeof(coltype));
|
2010-05-18 00:30:30 +00:00
|
|
|
if (!pic) { Bfree(picfil); return -1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
memset(pic,0,xsiz*ysiz*sizeof(coltype));
|
|
|
|
|
2008-05-24 07:58:21 +00:00
|
|
|
if (kprender(picfil,picfillen,(intptr_t)pic,xsiz*sizeof(coltype),xsiz,ysiz,0,0))
|
2011-01-30 11:02:28 +00:00
|
|
|
{ Bfree(picfil); Bfree(pic); return -2; }
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(picfil);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
cptr = &britable[gammabrightness ? 0 : curbrightness][0];
|
2008-03-27 21:32:23 +00:00
|
|
|
r=(glinfo.bgra)?hictinting[pal].b:hictinting[pal].r;
|
|
|
|
g=hictinting[pal].g;
|
|
|
|
b=(glinfo.bgra)?hictinting[pal].r:hictinting[pal].b;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (y=0,j=0; y<tsizy; y++,j+=xsiz)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
coltype *rpptr = &pic[j], tcol;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (x=0; x<tsizx; x++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
tcol.b = cptr[rpptr[x].b];
|
|
|
|
tcol.g = cptr[rpptr[x].g];
|
|
|
|
tcol.r = cptr[rpptr[x].r];
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (effect & 1)
|
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
// greyscale
|
|
|
|
tcol.b = max(tcol.b, max(tcol.g, tcol.r));
|
|
|
|
tcol.g = tcol.r = tcol.b;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
if (effect & 2)
|
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
// invert
|
|
|
|
tcol.b = 255-tcol.b;
|
|
|
|
tcol.g = 255-tcol.g;
|
|
|
|
tcol.r = 255-tcol.r;
|
|
|
|
}
|
2008-03-27 21:32:23 +00:00
|
|
|
if (effect & 4)
|
|
|
|
{
|
|
|
|
// colorize
|
2009-01-09 09:29:17 +00:00
|
|
|
tcol.b = min((int32_t)(tcol.b)*b/64,255);
|
|
|
|
tcol.g = min((int32_t)(tcol.g)*g/64,255);
|
|
|
|
tcol.r = min((int32_t)(tcol.r)*r/64,255);
|
2008-03-27 21:32:23 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
rpptr[x].b = tcol.b;
|
|
|
|
rpptr[x].g = tcol.g;
|
|
|
|
rpptr[x].r = tcol.r;
|
|
|
|
al &= rpptr[x].a;
|
|
|
|
}
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!glinfo.bgra)
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=xsiz*ysiz-1; j>=0; j--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
swapchar(&pic[j].r, &pic[j].b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*sizx = xsiz;
|
|
|
|
*sizy = ysiz;
|
|
|
|
*bpl = xsiz;
|
2008-05-24 07:58:21 +00:00
|
|
|
*fptr = (intptr_t)pic;
|
2006-04-13 20:47:06 +00:00
|
|
|
*hasalpha = (al != 255);
|
2011-01-09 18:53:06 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// JONOF'S COMPRESSED TEXTURE CACHE STUFF ---------------------------------------------------
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t mdloadskin_trytexcache(char *fn, int32_t len, int32_t pal, char effect, texcacheheader *head)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2011-01-09 18:53:06 +00:00
|
|
|
int32_t fp, err=0;
|
2006-04-24 19:04:22 +00:00
|
|
|
char cachefn[BMAX_PATH], *cp;
|
2009-01-09 09:29:17 +00:00
|
|
|
uint8_t mdsum[16];
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-11-25 14:35:33 +00:00
|
|
|
if (!glinfo.texcompr || !glusetexcompr || !glusetexcache || !cacheindexptr || cachefilehandle < 0) return -1;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!bglCompressedTexImage2DARB || !bglGetCompressedTexImageARB)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// lacking the necessary extensions to do this
|
2008-07-30 02:51:32 +00:00
|
|
|
OSD_Printf("Warning: the GL driver lacks necessary functions to use caching\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
glusetexcache = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
md4once((uint8_t *)fn, strlen(fn), mdsum);
|
2008-11-26 22:51:56 +00:00
|
|
|
// for (cp = cachefn, fp = 0; (*cp = TEXCACHEFILE[fp]); cp++,fp++);
|
2008-11-25 13:06:36 +00:00
|
|
|
// *(cp++) = '/';
|
|
|
|
cp = cachefn;
|
2006-04-24 19:04:22 +00:00
|
|
|
for (fp = 0; fp < 16; phex(mdsum[fp++], cp), cp+=2);
|
2009-02-02 01:49:14 +00:00
|
|
|
Bsprintf(cp, "-%x-%x%x", len, pal, effect);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-11-25 13:06:36 +00:00
|
|
|
// fil = kopen4load(cachefn, 0);
|
|
|
|
// if (fil < 0) return -1;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-11-25 13:06:36 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t offset = 0;
|
|
|
|
int32_t len = 0;
|
|
|
|
int32_t i;
|
2009-02-19 16:47:54 +00:00
|
|
|
/*
|
|
|
|
texcacheindex *cacheindexptr = &firstcacheindex;
|
2008-11-25 13:06:36 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
// initprintf("checking %s against %s\n",cachefn,cacheindexptr->name);
|
|
|
|
if (!Bstrcmp(cachefn,cacheindexptr->name))
|
|
|
|
{
|
|
|
|
offset = cacheindexptr->offset;
|
|
|
|
len = cacheindexptr->len;
|
|
|
|
// initprintf("got a match for %s offset %d\n",cachefn,offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cacheindexptr = cacheindexptr->next;
|
|
|
|
}
|
|
|
|
while (cacheindexptr->next);
|
|
|
|
*/
|
2010-05-02 23:27:30 +00:00
|
|
|
i = hash_find(&h_texcache,cachefn);
|
2008-11-25 14:35:33 +00:00
|
|
|
if (i != -1)
|
|
|
|
{
|
|
|
|
texcacheindex *cacheindexptr = cacheptrs[i];
|
|
|
|
len = cacheindexptr->len;
|
|
|
|
offset = cacheindexptr->offset;
|
2010-05-25 10:56:00 +00:00
|
|
|
// initprintf("got a match for %s offset %d\n",cachefn,offset);
|
2008-11-25 14:35:33 +00:00
|
|
|
}
|
2008-11-25 13:06:36 +00:00
|
|
|
if (len == 0) return -1; // didn't find it
|
2010-05-25 10:56:00 +00:00
|
|
|
cachepos = offset;
|
2008-11-25 13:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// initprintf("Loading cached skin: %s\n", cachefn);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
if (memcachedata && memcachesize >= (signed)(cachepos + sizeof(texcacheheader)))
|
|
|
|
{
|
|
|
|
// initprintf("using memcache!\n");
|
|
|
|
Bmemcpy(head, memcachedata + cachepos, sizeof(texcacheheader));
|
|
|
|
cachepos += sizeof(texcacheheader);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Blseek(cachefilehandle, cachepos, BSEEK_SET);
|
|
|
|
if (Bread(cachefilehandle, head, sizeof(texcacheheader)) < (int32_t)sizeof(texcacheheader))
|
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
cachepos += sizeof(texcacheheader);
|
2011-01-09 18:53:06 +00:00
|
|
|
err = 1;
|
2010-05-25 10:56:00 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
cachepos += sizeof(texcacheheader);
|
|
|
|
}
|
|
|
|
|
2011-01-09 18:53:06 +00:00
|
|
|
if (memcmp(head->magic, TEXCACHEMAGIC, 4)) { err=2; goto failure; }
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
head->xdim = B_LITTLE32(head->xdim);
|
|
|
|
head->ydim = B_LITTLE32(head->ydim);
|
|
|
|
head->flags = B_LITTLE32(head->flags);
|
2008-07-29 05:43:47 +00:00
|
|
|
head->quality = B_LITTLE32(head->quality);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2011-01-09 18:53:06 +00:00
|
|
|
if (head->quality != r_downsize) { err=3; goto failure; }
|
|
|
|
if ((head->flags & 4) && glusetexcache != 2) { err=4; goto failure; }
|
|
|
|
if (!(head->flags & 4) && glusetexcache == 2) { err=5; goto failure; }
|
|
|
|
if (gltexmaxsize && (head->xdim > (1<<gltexmaxsize) || head->ydim > (1<<gltexmaxsize))) { err=6; goto failure; }
|
|
|
|
if (!glinfo.texnpot && (head->flags & 1)) { err=7; goto failure; }
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-11-25 14:35:33 +00:00
|
|
|
return cachefilehandle;
|
2006-04-13 20:47:06 +00:00
|
|
|
failure:
|
2008-11-25 13:06:36 +00:00
|
|
|
// kclose(fil);
|
2011-01-09 18:53:06 +00:00
|
|
|
initprintf("skin cache miss: %d\n", err);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t mdloadskin_cached(int32_t fil, texcacheheader *head, int32_t *doalloc, GLuint *glpic, int32_t *xsiz, int32_t *ysiz, int32_t pal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t level, r;
|
2006-04-24 19:04:22 +00:00
|
|
|
texcachepicture pict;
|
|
|
|
void *pic = NULL, *packbuf = NULL;
|
|
|
|
void *midbuf = NULL;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t alloclen=0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-03-22 10:23:57 +00:00
|
|
|
UNREFERENCED_PARAMETER(pal);
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (*doalloc&1)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
bglGenTextures(1,glpic); //# of textures (make OpenGL allocate structure)
|
|
|
|
*doalloc |= 2; // prevents bglGenTextures being called again if we fail in here
|
|
|
|
}
|
|
|
|
bglBindTexture(GL_TEXTURE_2D,*glpic);
|
|
|
|
|
|
|
|
bglGetError();
|
|
|
|
|
|
|
|
// load the mipmaps
|
2007-12-12 17:42:14 +00:00
|
|
|
for (level = 0; level==0 || (pict.xdim > 1 || pict.ydim > 1); level++)
|
|
|
|
{
|
2010-05-25 10:56:00 +00:00
|
|
|
Blseek(fil, cachepos, BSEEK_SET);
|
2008-11-25 13:06:36 +00:00
|
|
|
r = Bread(fil, &pict, sizeof(texcachepicture));
|
2010-05-25 10:56:00 +00:00
|
|
|
cachepos += sizeof(texcachepicture);
|
2009-01-09 09:29:17 +00:00
|
|
|
if (r < (int32_t)sizeof(texcachepicture)) goto failure;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
pict.size = B_LITTLE32(pict.size);
|
|
|
|
pict.format = B_LITTLE32(pict.format);
|
|
|
|
pict.xdim = B_LITTLE32(pict.xdim);
|
|
|
|
pict.ydim = B_LITTLE32(pict.ydim);
|
|
|
|
pict.border = B_LITTLE32(pict.border);
|
|
|
|
pict.depth = B_LITTLE32(pict.depth);
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (level == 0) { *xsiz = pict.xdim; *ysiz = pict.ydim; }
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (alloclen < pict.size)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
void *picc = Brealloc(pic, pict.size);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!picc) goto failure; else pic = picc;
|
|
|
|
alloclen = pict.size;
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
picc = Brealloc(packbuf, alloclen+16);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!picc) goto failure; else packbuf = picc;
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
picc = Brealloc(midbuf, pict.size);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!picc) goto failure; else midbuf = picc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dedxtfilter(fil, &pict, pic, midbuf, packbuf, (head->flags&4)==4)) goto failure;
|
|
|
|
|
|
|
|
bglCompressedTexImage2DARB(GL_TEXTURE_2D,level,pict.format,pict.xdim,pict.ydim,pict.border,
|
|
|
|
pict.size,pic);
|
|
|
|
if (bglGetError() != GL_NO_ERROR) goto failure;
|
|
|
|
}
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (midbuf) Bfree(midbuf);
|
|
|
|
if (pic) Bfree(pic);
|
|
|
|
if (packbuf) Bfree(packbuf);
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
failure:
|
2010-05-18 00:30:30 +00:00
|
|
|
if (midbuf) Bfree(midbuf);
|
|
|
|
if (pic) Bfree(pic);
|
|
|
|
if (packbuf) Bfree(packbuf);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
// --------------------------------------------------- JONOF'S COMPRESSED TEXTURE CACHE STUFF
|
|
|
|
|
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
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i,j, bpl, xsiz=0, ysiz=0, osizx, osizy, texfmt = GL_RGBA, intexfmt = GL_RGBA;
|
2008-05-24 07:58:21 +00:00
|
|
|
intptr_t fptr=0;
|
2009-07-12 01:55:34 +00:00
|
|
|
char *skinfile, hasalpha, fn[BMAX_PATH];
|
2006-04-24 19:04:22 +00:00
|
|
|
GLuint *texidx = NULL;
|
|
|
|
mdskinmap_t *sk, *skzero = NULL;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t doalloc = 1, filh;
|
|
|
|
int32_t cachefil = -1, picfillen;
|
2006-04-24 19:04:22 +00:00
|
|
|
texcacheheader cachead;
|
|
|
|
|
2011-01-09 18:53:06 +00:00
|
|
|
int32_t startticks, willprint=0;
|
|
|
|
|
2007-12-28 20:04:58 +00:00
|
|
|
modelhead=m; // for palmaps
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (m->mdnum == 2) surf = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if ((unsigned)pal >= (unsigned)MAXPALOOKUPS) return 0;
|
|
|
|
i = -1;
|
|
|
|
for (sk = m->skinmap; sk; sk = sk->next)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((int32_t)sk->palette == pal && sk->skinnum == number && sk->surfnum == surf)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
skinfile = sk->fn;
|
2008-10-20 04:00:00 +00:00
|
|
|
texidx = &sk->texid[(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)];
|
2009-07-12 01:55:34 +00:00
|
|
|
strncpy(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)
|
2009-01-09 09:29:17 +00:00
|
|
|
else if (((int32_t)sk->palette == 0) && (sk->skinnum == number) && (sk->surfnum == surf) && (i < 5)) { i = 5; skzero = sk; }
|
|
|
|
else if (((int32_t)sk->palette == pal) && (sk->skinnum == 0) && (sk->surfnum == surf) && (i < 4)) { i = 4; skzero = sk; }
|
|
|
|
else if (((int32_t)sk->palette == 0) && (sk->skinnum == 0) && (sk->surfnum == surf) && (i < 3)) { i = 3; skzero = sk; }
|
|
|
|
else if (((int32_t)sk->palette == 0) && (sk->skinnum == number) && (i < 2)) { i = 2; skzero = sk; }
|
|
|
|
else if (((int32_t)sk->palette == pal) && (sk->skinnum == 0) && (i < 1)) { i = 1; skzero = sk; }
|
|
|
|
else if (((int32_t)sk->palette == 0) && (sk->skinnum == 0) && (i < 0)) { i = 0; skzero = sk; }
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
if (!sk)
|
|
|
|
{
|
2007-02-15 22:26:50 +00:00
|
|
|
if (pal >= (MAXPALOOKUPS - RESERVEDPALS))
|
2007-02-15 01:35:34 +00:00
|
|
|
return (0);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (skzero)
|
|
|
|
{
|
|
|
|
skinfile = skzero->fn;
|
2008-10-20 04:00:00 +00:00
|
|
|
texidx = &skzero->texid[(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)];
|
2009-07-12 01:55:34 +00:00
|
|
|
strncpy(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
|
|
|
|
{
|
|
|
|
if ((unsigned)number >= (unsigned)m->numskins) number = 0;
|
|
|
|
skinfile = m->skinfn + number*64;
|
2008-10-20 04:00:00 +00:00
|
|
|
texidx = &m->texid[ number * (HICEFFECTMASK+1) + (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)];
|
2009-07-12 01:55:34 +00:00
|
|
|
strncpy(fn,m->basepath,BMAX_PATH);
|
|
|
|
if ((Bstrlen(fn) + Bstrlen(skinfile)) < BMAX_PATH)
|
|
|
|
strcat(fn,skinfile);
|
2006-04-13 20:47:06 +00:00
|
|
|
//OSD_Printf("Using MD2/MD3 skin (%d) %s, pal=%d\n",number,skinfile,pal);
|
|
|
|
}
|
|
|
|
}
|
2007-12-20 19:14:38 +00:00
|
|
|
skhead=sk; // for palmaps
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!skinfile[0]) return 0;
|
|
|
|
|
|
|
|
if (*texidx) return *texidx;
|
2007-02-15 22:26:50 +00:00
|
|
|
|
|
|
|
// possibly fetch an already loaded multitexture :_)
|
|
|
|
if (pal >= (MAXPALOOKUPS - RESERVEDPALS))
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<nextmodelid; i++)
|
2009-01-10 07:38:50 +00:00
|
|
|
for (skzero = ((md2model_t *)models[i])->skinmap; skzero; skzero = skzero->next)
|
2008-10-14 08:40:59 +00:00
|
|
|
if (!Bstrcasecmp(skzero->fn, sk->fn) && skzero->texid[(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)])
|
2007-02-15 22:26:50 +00:00
|
|
|
{
|
2008-10-14 08:40:59 +00:00
|
|
|
sk->texid[(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)] = skzero->texid[(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)];
|
|
|
|
return sk->texid[(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK)];
|
2007-02-15 22:26:50 +00:00
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
*texidx = 0;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if ((filh = kopen4load(fn, 0)) < 0)
|
|
|
|
{
|
2008-07-30 02:51:32 +00:00
|
|
|
OSD_Printf("Skin %s not found.\n",fn);
|
2006-04-24 19:04:22 +00:00
|
|
|
skinfile[0] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
picfillen = kfilelength(filh);
|
|
|
|
kclose(filh); // FIXME: shouldn't have to do this. bug in cache1d.c
|
|
|
|
|
2011-01-09 18:53:06 +00:00
|
|
|
startticks = getticks();
|
|
|
|
|
2008-10-14 08:40:59 +00:00
|
|
|
cachefil = mdloadskin_trytexcache(fn, picfillen, pal<<8, (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK), &cachead);
|
2007-12-20 19:14:38 +00:00
|
|
|
if (cachefil >= 0 && !mdloadskin_cached(cachefil, &cachead, &doalloc, texidx, &xsiz, &ysiz, pal))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
osizx = cachead.xdim;
|
|
|
|
osizy = cachead.ydim;
|
2008-04-07 00:43:09 +00:00
|
|
|
hasalpha = (cachead.flags & 2) ? 1 : 0;
|
|
|
|
if (pal < (MAXPALOOKUPS - RESERVEDPALS))m->usesalpha = hasalpha;
|
2008-11-25 13:06:36 +00:00
|
|
|
// kclose(cachefil);
|
2006-04-24 19:04:22 +00:00
|
|
|
//kclose(filh); // FIXME: uncomment when cache1d.c is fixed
|
|
|
|
// cachefil >= 0, so it won't be rewritten
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-30 11:02:28 +00:00
|
|
|
int32_t ret;
|
|
|
|
|
2008-11-25 13:06:36 +00:00
|
|
|
// if (cachefil >= 0) kclose(cachefil);
|
2006-04-24 19:04:22 +00:00
|
|
|
cachefil = -1; // the compressed version will be saved to disk
|
|
|
|
|
|
|
|
if ((filh = kopen4load(fn, 0)) < 0) return -1;
|
2011-01-30 11:02:28 +00:00
|
|
|
ret=daskinloader(filh,&fptr,&bpl,&xsiz,&ysiz,&osizx,&osizy,&hasalpha,pal,(globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK));
|
|
|
|
if (ret)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
kclose(filh);
|
2011-01-30 11:02:28 +00:00
|
|
|
OSD_Printf("Failed loading skin file \"%s\": error %d\n", fn, ret);
|
|
|
|
if (ret==-1)
|
|
|
|
QuitOnFatalError("OUT OF MEMORY in daskinloader!");
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
skinfile[0] = 0;
|
|
|
|
return(0);
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else kclose(filh);
|
2011-01-09 18:53:06 +00:00
|
|
|
|
|
|
|
willprint = 1;
|
|
|
|
|
2009-04-16 06:41:24 +00:00
|
|
|
if (pal < (MAXPALOOKUPS - RESERVEDPALS)) m->usesalpha = hasalpha;
|
2011-01-16 02:50:27 +00:00
|
|
|
if ((doalloc&3)==1) bglGenTextures(1,(GLuint *)texidx);
|
2008-02-02 16:38:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D,*texidx);
|
|
|
|
|
|
|
|
//gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,xsiz,ysiz,GL_BGRA_EXT,GL_UNSIGNED_BYTE,(char *)fptr);
|
|
|
|
if (glinfo.texcompr && glusetexcompr) intexfmt = hasalpha ? GL_COMPRESSED_RGBA_ARB : GL_COMPRESSED_RGB_ARB;
|
|
|
|
else if (!hasalpha) intexfmt = GL_RGB;
|
|
|
|
if (glinfo.bgra) texfmt = GL_BGRA;
|
2011-01-16 02:50:27 +00:00
|
|
|
uploadtexture((doalloc&1), xsiz, ysiz, intexfmt, texfmt, (coltype *)fptr, xsiz, ysiz, 0|8192);
|
|
|
|
Bfree((void *)fptr);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!m->skinloaded)
|
|
|
|
{
|
|
|
|
if (xsiz != osizx || ysiz != osizy)
|
|
|
|
{
|
|
|
|
float fx, fy;
|
|
|
|
fx = ((float)osizx)/((float)xsiz);
|
|
|
|
fy = ((float)osizy)/((float)ysiz);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,glfiltermodes[gltexfiltermode].mag);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,glfiltermodes[gltexfiltermode].min);
|
|
|
|
if (glinfo.maxanisotropy > 1.0)
|
2009-07-09 02:29:48 +00:00
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_ANISOTROPY_EXT,glanisotropy);
|
2006-04-24 19:04:22 +00:00
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
|
|
|
|
2008-09-01 21:59:53 +00:00
|
|
|
if (glinfo.texcompr && glusetexcompr && glusetexcache)
|
2008-10-20 04:00:00 +00:00
|
|
|
if (cachefil < 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-10-20 04:00:00 +00:00
|
|
|
// save off the compressed version
|
|
|
|
cachead.quality = r_downsize;
|
|
|
|
cachead.xdim = osizx>>cachead.quality;
|
|
|
|
cachead.ydim = osizy>>cachead.quality;
|
|
|
|
|
|
|
|
i = 0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<31; j++)
|
2008-10-20 04:00:00 +00:00
|
|
|
{
|
|
|
|
if (xsiz == pow2long[j]) { i |= 1; }
|
|
|
|
if (ysiz == pow2long[j]) { i |= 2; }
|
|
|
|
}
|
|
|
|
cachead.flags = (i!=3) | (hasalpha ? 2 : 0);
|
2011-01-09 18:53:06 +00:00
|
|
|
/// OSD_Printf("Caching \"%s\"\n",fn);
|
2008-10-20 04:00:00 +00:00
|
|
|
writexcache(fn, picfillen, pal<<8, (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK), &cachead);
|
2011-01-09 18:53:06 +00:00
|
|
|
|
|
|
|
if (willprint)
|
|
|
|
{
|
2011-01-30 11:02:28 +00:00
|
|
|
int32_t etime = getticks()-startticks;
|
|
|
|
if (etime>=MIN_CACHETIME_PRINT)
|
|
|
|
OSD_Printf("Load skin: p%d-e%d \"%s\"... cached... %d ms\n", pal, (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK), 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
|
|
|
}
|
|
|
|
|
2011-01-09 18:53:06 +00:00
|
|
|
if (willprint)
|
2011-01-30 11:02:28 +00:00
|
|
|
{
|
|
|
|
int32_t etime = getticks()-startticks;
|
|
|
|
if (etime>=MIN_CACHETIME_PRINT)
|
|
|
|
OSD_Printf("Load skin: p%d-e%d \"%s\"... %d ms\n", pal, (globalnoeffect)?0:(hictinting[pal].f&HICEFFECTMASK), fn, etime);
|
|
|
|
}
|
2011-01-09 18:53:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +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
|
2009-01-10 07:38:50 +00:00
|
|
|
void updateanimation(md2model_t *m, spritetype *tspr)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
mdanim_t *anim;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, k;
|
|
|
|
int32_t fps;
|
2008-05-27 15:47:24 +00:00
|
|
|
char lpal = (tspr->owner >= MAXSPRITES) ? tspr->pal : sprite[tspr->owner].pal;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
if (m->numframes < 2)
|
2008-12-01 13:44:46 +00:00
|
|
|
{
|
|
|
|
m->interpol = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-27 15:47:24 +00:00
|
|
|
m->cframe = m->nframe = tile2model[Ptile2tile(tspr->picnum,lpal)].framenum;
|
2006-11-15 01:14:27 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
for (anim = m->animations;
|
2006-04-24 19:04:22 +00:00
|
|
|
anim && anim->startframe != m->cframe;
|
|
|
|
anim = anim->next) ;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!anim)
|
|
|
|
{
|
2008-05-27 15:47:24 +00:00
|
|
|
if (r_animsmoothing && (tile2model[Ptile2tile(tspr->picnum,lpal)].smoothduration != 0) && (spritesmooth[tspr->owner].mdoldframe != m->cframe))
|
2007-03-30 18:02:00 +00:00
|
|
|
{
|
2007-04-12 03:09:41 +00:00
|
|
|
if (spritesmooth[tspr->owner].mdsmooth == 0)
|
2007-03-30 18:02:00 +00:00
|
|
|
{
|
2008-02-02 16:38:30 +00:00
|
|
|
spriteext[tspr->owner].mdanimtims = mdtims;
|
2007-03-30 18:02:00 +00:00
|
|
|
m->interpol = 0;
|
2007-04-12 03:09:41 +00:00
|
|
|
spritesmooth[tspr->owner].mdsmooth = 1;
|
|
|
|
spritesmooth[tspr->owner].mdcurframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
}
|
2008-05-27 15:47:24 +00:00
|
|
|
if (r_animsmoothing && (tile2model[Ptile2tile(tspr->picnum,lpal)].smoothduration != 0) && (spritesmooth[tspr->owner].mdcurframe != m->cframe))
|
2007-03-30 18:02:00 +00:00
|
|
|
{
|
2008-02-02 16:38:30 +00:00
|
|
|
spriteext[tspr->owner].mdanimtims = mdtims;
|
2007-03-30 18:02:00 +00:00
|
|
|
m->interpol = 0;
|
2007-04-12 03:09:41 +00:00
|
|
|
spritesmooth[tspr->owner].mdsmooth = 1;
|
|
|
|
spritesmooth[tspr->owner].mdoldframe = spritesmooth[tspr->owner].mdcurframe;
|
|
|
|
spritesmooth[tspr->owner].mdcurframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-27 15:47:24 +00:00
|
|
|
else if (r_animsmoothing && (tile2model[Ptile2tile(tspr->picnum,lpal)].smoothduration != 0) && (spritesmooth[tspr->owner].mdcurframe != m->cframe))
|
2007-03-30 18:02:00 +00:00
|
|
|
{
|
2008-02-02 16:38:30 +00:00
|
|
|
spriteext[tspr->owner].mdanimtims = mdtims;
|
2007-03-30 18:02:00 +00:00
|
|
|
m->interpol = 0;
|
2007-04-12 03:09:41 +00:00
|
|
|
spritesmooth[tspr->owner].mdsmooth = 1;
|
|
|
|
spritesmooth[tspr->owner].mdoldframe = spritesmooth[tspr->owner].mdcurframe;
|
|
|
|
spritesmooth[tspr->owner].mdcurframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m->interpol = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
if (anim && (((int32_t)spriteext[tspr->owner].mdanimcur) != anim->startframe))
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2007-04-12 03:09:41 +00:00
|
|
|
//if (spriteext[tspr->owner].flags & SPREXT_NOMDANIM) OSD_Printf("SPREXT_NOMDANIM\n");
|
|
|
|
//OSD_Printf("smooth launched ! oldanim %i new anim %i\n", spriteext[tspr->owner].mdanimcur, anim->startframe);
|
2009-01-09 09:29:17 +00:00
|
|
|
spriteext[tspr->owner].mdanimcur = (int16_t)anim->startframe;
|
2008-02-02 16:38:30 +00:00
|
|
|
spriteext[tspr->owner].mdanimtims = mdtims;
|
2006-04-13 20:47:06 +00:00
|
|
|
m->interpol = 0;
|
2008-05-27 15:47:24 +00:00
|
|
|
if (!r_animsmoothing || (tile2model[Ptile2tile(tspr->picnum,lpal)].smoothduration == 0))
|
2007-03-22 18:28:41 +00:00
|
|
|
{
|
|
|
|
m->cframe = m->nframe = anim->startframe;
|
|
|
|
return;
|
|
|
|
}
|
2007-03-30 18:02:00 +00:00
|
|
|
m->nframe = anim->startframe;
|
2007-04-12 03:09:41 +00:00
|
|
|
m->cframe = spritesmooth[tspr->owner].mdoldframe;
|
|
|
|
spritesmooth[tspr->owner].mdsmooth = 1;
|
2007-03-30 18:02:00 +00:00
|
|
|
return;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2007-04-12 03:09:41 +00:00
|
|
|
if (spritesmooth[tspr->owner].mdsmooth)
|
2009-07-09 02:29:48 +00:00
|
|
|
ftol((1.0f / (float)(tile2model[Ptile2tile(tspr->picnum,lpal)].smoothduration)) * 66.f, &fps);
|
2007-03-22 18:28:41 +00:00
|
|
|
else
|
|
|
|
fps = anim->fpssc;
|
|
|
|
|
2008-02-02 16:38:30 +00:00
|
|
|
i = (mdtims-spriteext[tspr->owner].mdanimtims)*((fps*timerticspersec)/120);
|
2007-03-30 18:02:00 +00:00
|
|
|
|
2007-04-12 03:09:41 +00:00
|
|
|
if (spritesmooth[tspr->owner].mdsmooth)
|
|
|
|
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);
|
2009-01-09 09:29:17 +00:00
|
|
|
//Just in case you play the game for a VERY int32_t time...
|
2009-02-19 16:47:54 +00:00
|
|
|
if (i < 0) { i = 0; spriteext[tspr->owner].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
|
2008-02-01 03:36:54 +00:00
|
|
|
if ((anim) && (i >= j+j) && (fps) && !mdpause) //Keep mdanimtims close to mdtims to avoid the use of MOD
|
2007-03-22 18:28:41 +00:00
|
|
|
spriteext[tspr->owner].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
|
|
|
|
2007-04-12 03:09:41 +00:00
|
|
|
if (r_animsmoothing && spritesmooth[tspr->owner].mdsmooth)
|
2007-03-22 18:28:41 +00:00
|
|
|
{
|
2007-04-12 03:09:41 +00:00
|
|
|
m->nframe = (anim) ? anim->startframe : spritesmooth[tspr->owner].mdcurframe;
|
|
|
|
m->cframe = spritesmooth[tspr->owner].mdoldframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
//OSD_Printf("smoothing... cframe %i nframe %i\n", m->cframe, m->nframe);
|
|
|
|
if (k > 65535)
|
|
|
|
{
|
2008-02-02 16:38:30 +00:00
|
|
|
spriteext[tspr->owner].mdanimtims = mdtims;
|
2007-03-30 18:02:00 +00:00
|
|
|
m->interpol = 0;
|
2007-04-12 03:09:41 +00:00
|
|
|
spritesmooth[tspr->owner].mdsmooth = 0;
|
|
|
|
m->cframe = m->nframe = (anim) ? anim->startframe : spritesmooth[tspr->owner].mdcurframe;
|
|
|
|
spritesmooth[tspr->owner].mdoldframe = m->cframe;
|
2007-03-30 18:02:00 +00:00
|
|
|
//OSD_Printf("smooth stopped !\n");
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 18:28:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m->cframe = (i>>16)+anim->startframe;
|
|
|
|
m->nframe = m->cframe+1; if (m->nframe > anim->endframe) m->nframe = anim->startframe;
|
2007-04-12 03:09:41 +00:00
|
|
|
spritesmooth[tspr->owner].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
|
|
|
}
|
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);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
m->vbos = Bmalloc(m->head.numsurfs * sizeof(GLuint));
|
2007-03-08 03:07:10 +00:00
|
|
|
bglGenBuffersARB(m->head.numsurfs, m->vbos);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < m->head.numsurfs)
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, m->vbos[i]);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, m->head.surfs[i].numverts * sizeof(md3uv_t), m->head.surfs[i].uv, GL_STATIC_DRAW_ARB);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
m = (md2model_t *)Bcalloc(1,sizeof(md2model_t)); if (!m) return(0);
|
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));
|
|
|
|
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);
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if ((head.id != 0x32504449) || (head.vers != 8)) { Bfree(m); return(0); } //"IDP2"
|
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
|
|
|
|
2010-12-24 15:44:37 +00:00
|
|
|
m->frames = (char *)Bmalloc(m->numframes*m->framebytes); if (!m->frames) { Bfree(m); return(0); }
|
|
|
|
m->glcmds = (int32_t *)Bmalloc(m->numglcmds*sizeof(int32_t)); if (!m->glcmds) { Bfree(m->frames); Bfree(m); return(0); }
|
|
|
|
m->tris = (md2tri_t *)Bmalloc(head.numtris*sizeof(md2tri_t)); if (!m->tris) { Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
|
|
|
m->uv = (md2uv_t *)Bmalloc(head.numuv*sizeof(md2uv_t)); if (!m->uv) { Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
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)
|
2010-05-18 00:30:30 +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
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
klseek(fil,head.ofsglcmds,SEEK_SET);
|
2009-01-09 09:29:17 +00:00
|
|
|
if (kread(fil,(char *)m->glcmds,m->numglcmds*sizeof(int32_t)) != (int32_t)(m->numglcmds*sizeof(int32_t)))
|
2010-05-18 00:30:30 +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.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)))
|
2010-05-18 00:30:30 +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)))
|
2010-05-18 00:30:30 +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
|
|
|
|
|
|
|
|
strcpy(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;
|
2010-05-20 06:05:46 +00:00
|
|
|
m->basepath = (char *)Bmalloc(i+1); if (!m->basepath) { Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
strcpy(m->basepath, st);
|
|
|
|
|
2010-12-24 15:44:37 +00:00
|
|
|
m->skinfn = (char *)Bmalloc(m->numskins*64); if (!m->skinfn) { Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
2006-04-24 19:04:22 +00:00
|
|
|
klseek(fil,head.ofsskins,SEEK_SET);
|
|
|
|
if (kread(fil,m->skinfn,64*m->numskins) != 64*m->numskins)
|
2010-05-18 00:30:30 +00:00
|
|
|
{ Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
m->texid = (GLuint *)Bcalloc(m->numskins, sizeof(GLuint) * (HICEFFECTMASK+1));
|
|
|
|
if (!m->texid) { Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
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
|
|
|
|
|
|
|
//return(m);
|
|
|
|
|
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");
|
2010-05-18 00:30:30 +00:00
|
|
|
m3 = (md3model_t *)Bcalloc(1, sizeof(md3model_t)); if (!m3) { Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
2006-08-12 07:47:02 +00:00
|
|
|
m3->mdnum = 3; m3->texid = 0; m3->scale = m->scale;
|
|
|
|
m3->head.id = 0x33504449; m3->head.vers = 15;
|
2008-06-01 09:41:56 +00:00
|
|
|
// this changes the conversion code to do real MD2->MD3 conversion
|
|
|
|
// it breaks HRP MD2 oozfilter, change the flags to 1337 to revert
|
|
|
|
// to the old, working code
|
|
|
|
m3->head.flags = 0;
|
|
|
|
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
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
m3->head.frames = (md3frame_t *)Bcalloc(m3->head.numframes, sizeof(md3frame_t)); if (!m3->head.frames) { Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
|
|
|
m3->muladdframes = (point3d *)Bcalloc(m->numframes * 2, sizeof(point3d));
|
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];
|
|
|
|
strcpy(m3->head.frames[i].nam, f->name);
|
|
|
|
//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
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
m3->head.surfs = (md3surf_t *)Bcalloc(1, sizeof(md3surf_t)); if (!m3->head.surfs) { Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
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
|
|
|
|
s->id = 0x33504449; s->flags = 0;
|
|
|
|
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
|
|
|
|
2006-08-12 07:47:02 +00:00
|
|
|
strcpy(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
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
s->tris = (md3tri_t *)Bcalloc(head.numtris, sizeof(md3tri_t)); if (!s->tris) { Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
|
|
|
s->uv = (md3uv_t *)Bcalloc(s->numverts, sizeof(md3uv_t)); if (!s->uv) { Bfree(s->tris); Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
|
|
|
s->xyzn = (md3xyzn_t *)Bcalloc(s->numverts * m->numframes, sizeof(md3xyzn_t)); if (!s->xyzn) { Bfree(s->uv); Bfree(s->tris); Bfree(s); Bfree(m3->head.frames); Bfree(m3); Bfree(m->skinfn); Bfree(m->basepath); Bfree(m->uv); Bfree(m->tris); Bfree(m->glcmds); Bfree(m->frames); Bfree(m); return(0); }
|
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];
|
2008-06-01 09:41:56 +00:00
|
|
|
if (m3->head.flags == 1337)
|
|
|
|
{
|
|
|
|
s->xyzn[(k*s->numverts) + (i*3) + j].x = f->verts[m->tris[i].v[j]].v[0];
|
|
|
|
s->xyzn[(k*s->numverts) + (i*3) + j].y = f->verts[m->tris[i].v[j]].v[1];
|
|
|
|
s->xyzn[(k*s->numverts) + (i*3) + j].z = f->verts[m->tris[i].v[j]].v[2];
|
2008-06-05 02:29:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-09 02:29:48 +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;
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
sk = (mdskinmap_t *)Bcalloc(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)
|
|
|
|
{
|
2010-05-20 06:05:46 +00:00
|
|
|
sk->fn = (char *)Bmalloc(strlen(m->basepath)+strlen(m->skinfn)+1);
|
2006-11-20 04:56:22 +00:00
|
|
|
strcpy(sk->fn, m->basepath);
|
|
|
|
strcat(sk->fn, m->skinfn);
|
|
|
|
}
|
2006-08-15 03:32:34 +00:00
|
|
|
m3->skinmap = sk;
|
|
|
|
}
|
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
m3->indexes = Bmalloc(sizeof(uint16_t) * s->numtris);
|
|
|
|
m3->vindexes = Bmalloc(sizeof(uint16_t) * s->numtris * 3);
|
|
|
|
m3->maxdepths = Bmalloc(sizeof(float) * s->numtris);
|
2007-03-03 23:09:40 +00:00
|
|
|
|
2010-12-24 15:44:37 +00:00
|
|
|
if (!m3->indexes || !m3->vindexes || !m3->maxdepths)
|
2011-01-30 11:02:28 +00:00
|
|
|
QuitOnFatalError("OUT OF MEMORY in md2load!");
|
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
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
return((md2model_t *)m3);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
//---------------------------------------- MD2 LIBRARY ENDS ----------------------------------------
|
|
|
|
|
|
|
|
// DICHOTOMIC RECURSIVE SORTING - USED BY MD3DRAW - MAY PUT IT IN ITS OWN SOURCE FILE LATER
|
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
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t up,down;
|
2006-04-13 20:47:06 +00:00
|
|
|
float tempf;
|
2009-01-09 09:29:17 +00:00
|
|
|
uint16_t tempus;
|
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];
|
2006-04-13 20:47:06 +00:00
|
|
|
up = f;
|
|
|
|
down = l;
|
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
|
|
|
{
|
|
|
|
tempf = depths[up];
|
|
|
|
depths[up] = depths[down];
|
|
|
|
depths[down] = tempf;
|
|
|
|
tempus = indexes[up];
|
|
|
|
indexes[up] = indexes[down];
|
|
|
|
indexes[down] = tempus;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
while (down > up);
|
2006-04-13 20:47:06 +00:00
|
|
|
depths[f] = depths[down];
|
|
|
|
depths[down] = piv;
|
|
|
|
indexes[f] = indexes[down];
|
|
|
|
indexes[down] = piv2;
|
|
|
|
return down;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void quicksort(uint16_t *indexes, float *depths, int32_t first, int32_t last)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t pivIndex = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (first < last)
|
|
|
|
{
|
2006-04-13 20:47:06 +00:00
|
|
|
pivIndex = partition(indexes,depths,first, last);
|
|
|
|
quicksort(indexes,depths,first,(pivIndex-1));
|
|
|
|
quicksort(indexes,depths,(pivIndex+1),last);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
m = (md3model_t *)Bcalloc(1,sizeof(md3model_t)); if (!m) return(0);
|
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);
|
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);
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if ((m->head.id != 0x33504449) && (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);
|
2010-05-20 06:05:46 +00:00
|
|
|
m->head.frames = (md3frame_t *)Bmalloc(i); if (!m->head.frames) { Bfree(m); return(0); }
|
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);
|
2010-05-20 06:05:46 +00:00
|
|
|
m->head.tags = (md3tag_t *)Bmalloc(i); if (!m->head.tags) { Bfree(m->head.frames); Bfree(m); return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
kread(fil,m->head.tags,i);
|
|
|
|
}
|
|
|
|
|
2008-05-24 06:53:56 +00:00
|
|
|
klseek(fil,m->head.ofssurfs,SEEK_SET); i = m->head.numsurfs*sizeof(md3surf_t);
|
2010-05-20 06:05:46 +00:00
|
|
|
m->head.surfs = (md3surf_t *)Bmalloc(i); if (!m->head.surfs) { if (m->head.tags) Bfree(m->head.tags); Bfree(m->head.frames); Bfree(m); return(0); }
|
2011-01-01 18:35:59 +00:00
|
|
|
m->head.surfs[0].geometry = NULL; // for deferred polymer model postprocessing (else: crashes)
|
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
|
|
|
|
|
2008-05-24 06:53:56 +00:00
|
|
|
offs[0] = ofsurf+s->ofstris; leng[0] = s->numtris*sizeof(md3tri_t);
|
|
|
|
offs[1] = ofsurf+s->ofsshaders; leng[1] = s->numshaders*sizeof(md3shader_t);
|
|
|
|
offs[2] = ofsurf+s->ofsuv; leng[2] = s->numverts*sizeof(md3uv_t);
|
|
|
|
offs[3] = ofsurf+s->ofsxyzn; 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);
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
s->tris = (md3tri_t *)Bmalloc(leng[0]+leng[1]+leng[2]+leng[3]);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!s->tris)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
for (surfi--; surfi>=0; surfi--) Bfree(m->head.surfs[surfi].tris);
|
|
|
|
if (m->head.tags) Bfree(m->head.tags); Bfree(m->head.frames); Bfree(m); return(0);
|
2006-04-13 20:47:06 +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
|
|
|
|
|
|
|
#if 0
|
2008-03-22 10:23:57 +00:00
|
|
|
{
|
2008-04-07 00:43:09 +00:00
|
|
|
char *buf, st[BMAX_PATH+2], bst[BMAX_PATH+2];
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t j, bsc;
|
2008-04-07 00:43:09 +00:00
|
|
|
|
|
|
|
strcpy(st,filnam);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0,j=0; st[i]; i++) if ((st[i] == '/') || (st[i] == '\\')) j = i+1;
|
2008-04-07 00:43:09 +00:00
|
|
|
st[j] = '*'; st[j+1] = 0;
|
|
|
|
kzfindfilestart(st); bsc = -1;
|
|
|
|
while (kzfindfile(st))
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-04-07 00:43:09 +00:00
|
|
|
if (st[0] == '\\') continue;
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0,j=0; st[i]; i++) if (st[i] == '.') j = i+1;
|
2008-04-07 00:43:09 +00:00
|
|
|
if ((!stricmp(&st[j],"JPG")) || (!stricmp(&st[j],"PNG")) || (!stricmp(&st[j],"GIF")) ||
|
|
|
|
(!stricmp(&st[j],"PCX")) || (!stricmp(&st[j],"TGA")) || (!stricmp(&st[j],"BMP")) ||
|
|
|
|
(!stricmp(&st[j],"CEL")))
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; st[i]; i++) if (st[i] != filnam[i]) break;
|
2008-04-07 00:43:09 +00:00
|
|
|
if (i > bsc) { bsc = i; strcpy(bst,st); }
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2008-04-07 00:43:09 +00:00
|
|
|
if (!mdloadskin(&m->texid,&m->usesalpha,bst)) ;//bad!
|
2008-03-22 10:23:57 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
m->indexes = Bmalloc(sizeof(uint16_t) * maxtrispersurf);
|
|
|
|
m->vindexes = Bmalloc(sizeof(uint16_t) * maxtrispersurf * 3);
|
|
|
|
m->maxdepths = Bmalloc(sizeof(float) * maxtrispersurf);
|
2007-03-03 23:09:40 +00:00
|
|
|
|
2010-12-24 15:44:37 +00:00
|
|
|
if (!m->indexes || !m->vindexes || !m->maxdepths)
|
2011-01-30 11:02:28 +00:00
|
|
|
QuitOnFatalError("OUT OF MEMORY in md3load!");
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2007-03-08 03:07:10 +00:00
|
|
|
m->vbos = NULL;
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
return(m);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2010-08-21 07:39:12 +00:00
|
|
|
det = m[0] * (m[4]*m[8] - m[5] * m[7]);
|
|
|
|
det -= m[1] * (m[3]*m[8] - m[5] * m[6]);
|
2010-01-24 05:57:43 +00:00
|
|
|
det += m[2] * (m[3]*m[7] - m[4] * m[6]);
|
|
|
|
|
|
|
|
det = 1.0f / det;
|
|
|
|
|
2010-08-21 07:39:12 +00:00
|
|
|
out[0] = det * (m[4] * m[8] - m[5] * m[7]);
|
|
|
|
out[3] = det * (m[5] * m[6] - m[3] * m[8]);
|
|
|
|
out[6] = det * (m[3] * m[7] - m[1] * m[6]);
|
|
|
|
|
|
|
|
out[1] = det * (m[2] * m[7] - m[1] * m[8]);
|
|
|
|
out[4] = det * (m[0] * m[8] - m[2] * m[6]);
|
|
|
|
out[7] = det * (m[1] * m[6] - m[0] * m[7]);
|
|
|
|
|
|
|
|
out[2] = det * (m[1] * m[5] - m[2] * m[4]);
|
|
|
|
out[5] = det * (m[2] * m[3] - m[0] * m[5]);
|
|
|
|
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
|
|
|
{
|
|
|
|
double norm;
|
|
|
|
|
|
|
|
norm = vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2];
|
|
|
|
|
|
|
|
norm = sqrt(norm);
|
|
|
|
norm = 1.0 / norm;
|
|
|
|
vec[0] *= norm;
|
|
|
|
vec[1] *= norm;
|
|
|
|
vec[2] *= norm;
|
|
|
|
}
|
|
|
|
|
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;
|
2010-12-24 15:44:37 +00:00
|
|
|
float dist, vec1[5];
|
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;
|
|
|
|
|
|
|
|
while (framei < m->head.numframes)
|
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
frame = &m->head.frames[framei];
|
|
|
|
|
|
|
|
frame->min.x = 0.0f;
|
|
|
|
frame->min.y = 0.0f;
|
|
|
|
frame->min.z = 0.0f;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
frame->max.x = 0.0f;
|
|
|
|
frame->max.y = 0.0f;
|
|
|
|
frame->max.z = 0.0f;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
frame->r = 0.0f;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
|
|
|
surfi = 0;
|
|
|
|
while (surfi < m->head.numsurfs)
|
|
|
|
{
|
|
|
|
frameverts = &m->head.surfs[surfi].xyzn[framei * m->head.surfs[surfi].numverts];
|
|
|
|
|
|
|
|
verti = 0;
|
|
|
|
while (verti < m->head.surfs[surfi].numverts)
|
|
|
|
{
|
|
|
|
if (!verti && !surfi)
|
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
frame->min.x = frameverts[verti].x;
|
|
|
|
frame->min.y = frameverts[verti].y;
|
|
|
|
frame->min.z = frameverts[verti].z;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
frame->max.x = frameverts[verti].x;
|
|
|
|
frame->max.y = frameverts[verti].y;
|
|
|
|
frame->max.z = frameverts[verti].z;
|
2009-06-24 08:20:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
if (frame->min.x > frameverts[verti].x)
|
|
|
|
frame->min.x = frameverts[verti].x;
|
|
|
|
if (frame->max.x < frameverts[verti].x)
|
|
|
|
frame->max.x = frameverts[verti].x;
|
|
|
|
|
|
|
|
if (frame->min.y > frameverts[verti].y)
|
|
|
|
frame->min.y = frameverts[verti].y;
|
|
|
|
if (frame->max.y < frameverts[verti].y)
|
|
|
|
frame->max.y = frameverts[verti].y;
|
|
|
|
|
|
|
|
if (frame->min.z > frameverts[verti].z)
|
|
|
|
frame->min.z = frameverts[verti].z;
|
|
|
|
if (frame->max.z < frameverts[verti].z)
|
|
|
|
frame->max.z = frameverts[verti].z;
|
2009-03-10 09:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
verti++;
|
|
|
|
}
|
|
|
|
surfi++;
|
|
|
|
}
|
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
frame->cen.x = (frame->min.x + frame->max.x) / 2.0f;
|
|
|
|
frame->cen.y = (frame->min.y + frame->max.y) / 2.0f;
|
|
|
|
frame->cen.z = (frame->min.z + frame->max.z) / 2.0f;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
|
|
|
surfi = 0;
|
|
|
|
while (surfi < m->head.numsurfs)
|
|
|
|
{
|
|
|
|
frameverts = &m->head.surfs[surfi].xyzn[framei * m->head.surfs[surfi].numverts];
|
|
|
|
|
|
|
|
verti = 0;
|
|
|
|
while (verti < m->head.surfs[surfi].numverts)
|
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
vec1[0] = frameverts[verti].x - frame->cen.x;
|
|
|
|
vec1[1] = frameverts[verti].y - frame->cen.y;
|
|
|
|
vec1[2] = frameverts[verti].z - frame->cen.z;
|
2009-03-10 17:49:34 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
dist = vec1[0] * vec1[0] + vec1[1] * vec1[1] + vec1[2] * vec1[2];
|
2009-03-10 09:26:25 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
if (dist > frame->r)
|
|
|
|
frame->r = dist;
|
2009-03-10 09:26:25 +00:00
|
|
|
|
|
|
|
verti++;
|
|
|
|
}
|
|
|
|
surfi++;
|
|
|
|
}
|
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
frame->r = sqrt(frame->r);
|
2009-03-10 09:26:25 +00:00
|
|
|
|
|
|
|
framei++;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
int surfi, trii;
|
|
|
|
md3surf_t *s;
|
|
|
|
|
|
|
|
surfi = 0;
|
|
|
|
while (surfi < m->head.numsurfs)
|
|
|
|
{
|
|
|
|
s = &m->head.surfs[surfi];
|
|
|
|
|
|
|
|
trii = 0;
|
|
|
|
while (trii < s->numtris)
|
|
|
|
{
|
|
|
|
// let the vertices know they're being referenced by a triangle
|
|
|
|
if (s->tris[trii].i[0] >= s->numverts || s->tris[trii].i[0] < 0 ||
|
2011-01-16 02:50:27 +00:00
|
|
|
s->tris[trii].i[1] >= s->numverts || s->tris[trii].i[1] < 0 ||
|
|
|
|
s->tris[trii].i[2] >= s->numverts || s->tris[trii].i[2] < 0)
|
|
|
|
{
|
2010-12-24 15:44:37 +00:00
|
|
|
// corrupt model
|
|
|
|
OSD_Printf("Triangle index out of bounds!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
trii++;
|
|
|
|
}
|
|
|
|
|
|
|
|
surfi++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#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
|
|
|
|
int framei, surfi, verti, trii, i;
|
|
|
|
md3surf_t *s;
|
|
|
|
int *numtris;
|
|
|
|
float lat, lng, vec1[5], vec2[5], mat[9], r;
|
2009-03-10 12:08:33 +00:00
|
|
|
|
|
|
|
// let's also repack the geometry to more usable formats
|
|
|
|
|
|
|
|
surfi = 0;
|
|
|
|
while (surfi < m->head.numsurfs)
|
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
s = &m->head.surfs[surfi];
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
s->geometry = Bcalloc(m->head.numframes * s->numverts * sizeof(float), 15);
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
numtris = Bcalloc(s->numverts, sizeof(int));
|
2009-03-10 12:08:33 +00:00
|
|
|
|
2010-12-24 15:44:37 +00:00
|
|
|
if (!s->geometry || !numtris)
|
2011-01-30 11:02:28 +00:00
|
|
|
QuitOnFatalError("OUT OF MEMORY in md3postload_polymer!");
|
2010-12-24 15:44:37 +00:00
|
|
|
|
2009-03-10 12:08:33 +00:00
|
|
|
verti = 0;
|
2010-01-24 05:57:43 +00:00
|
|
|
while (verti < (m->head.numframes * s->numverts))
|
2009-03-10 12:08:33 +00:00
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
s->geometry[(verti * 15) + 0] = s->xyzn[verti].x;
|
|
|
|
s->geometry[(verti * 15) + 1] = s->xyzn[verti].y;
|
|
|
|
s->geometry[(verti * 15) + 2] = s->xyzn[verti].z;
|
2009-03-10 12:08:33 +00:00
|
|
|
|
2009-03-10 14:30:34 +00:00
|
|
|
// normal extraction from packed spherical coordinates
|
|
|
|
// FIXME: swapping lat and lng because of npherno's compiler
|
2010-01-24 05:57:43 +00:00
|
|
|
lat = s->xyzn[verti].nlng * (2 * PI) / 255.0f;
|
|
|
|
lng = s->xyzn[verti].nlat * (2 * PI) / 255.0f;
|
|
|
|
|
|
|
|
s->geometry[(verti * 15) + 3] = cos(lat) * sin(lng);
|
|
|
|
s->geometry[(verti * 15) + 4] = sin(lat) * sin(lng);
|
|
|
|
s->geometry[(verti * 15) + 5] = cos(lng);
|
|
|
|
|
|
|
|
verti++;
|
|
|
|
}
|
|
|
|
|
|
|
|
trii = 0;
|
|
|
|
while (trii < s->numtris)
|
|
|
|
{
|
|
|
|
// let the vertices know they're being referenced by a triangle
|
2010-04-26 00:51:44 +00:00
|
|
|
if (s->tris[trii].i[0] >= s->numverts || s->tris[trii].i[0] < 0 ||
|
2011-01-16 02:50:27 +00:00
|
|
|
s->tris[trii].i[1] >= s->numverts || s->tris[trii].i[1] < 0 ||
|
|
|
|
s->tris[trii].i[2] >= s->numverts || s->tris[trii].i[2] < 0)
|
|
|
|
{
|
2010-04-26 00:51:44 +00:00
|
|
|
// corrupt model
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(numtris);
|
2010-04-26 00:51:44 +00:00
|
|
|
OSD_Printf("Triangle index out of bounds!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2010-01-24 05:57:43 +00:00
|
|
|
numtris[s->tris[trii].i[0]]++;
|
|
|
|
numtris[s->tris[trii].i[1]]++;
|
|
|
|
numtris[s->tris[trii].i[2]]++;
|
2009-03-10 14:30:34 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
framei = 0;
|
|
|
|
while (framei < m->head.numframes)
|
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
vec1[0] = s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[1] * 15) + 0] -
|
2010-01-24 05:57:43 +00:00
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[0] * 15) + 0];
|
2011-01-16 02:50:27 +00:00
|
|
|
vec1[1] = s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[1] * 15) + 1] -
|
2010-01-24 05:57:43 +00:00
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[0] * 15) + 1];
|
2011-01-16 02:50:27 +00:00
|
|
|
vec1[2] = s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[1] * 15) + 2] -
|
2010-01-24 05:57:43 +00:00
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[0] * 15) + 2];
|
|
|
|
vec1[3] = s->uv[s->tris[trii].i[1]].u - s->uv[s->tris[trii].i[0]].u;
|
|
|
|
vec1[4] = s->uv[s->tris[trii].i[1]].v - s->uv[s->tris[trii].i[0]].v;
|
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
vec2[0] = s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[2] * 15) + 0] -
|
2010-01-24 05:57:43 +00:00
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[1] * 15) + 0];
|
2011-01-16 02:50:27 +00:00
|
|
|
vec2[1] = s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[2] * 15) + 1] -
|
2010-01-24 05:57:43 +00:00
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[1] * 15) + 1];
|
2011-01-16 02:50:27 +00:00
|
|
|
vec2[2] = s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[2] * 15) + 2] -
|
2010-01-24 05:57:43 +00:00
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[1] * 15) + 2];
|
|
|
|
vec2[3] = s->uv[s->tris[trii].i[2]].u - s->uv[s->tris[trii].i[1]].u;
|
|
|
|
vec2[4] = s->uv[s->tris[trii].i[2]].v - s->uv[s->tris[trii].i[1]].v;
|
|
|
|
|
|
|
|
r = 1.0 / (vec1[3] * vec2[4] - vec2[3] * vec1[4]);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
normalize(&mat[0]);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
normalize(&mat[3]);
|
|
|
|
|
|
|
|
// T and B are shared for the three vertices in that triangle
|
|
|
|
i = 0;
|
|
|
|
while (i < 6)
|
|
|
|
{
|
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[0] * 15) + 6 + i] += mat[i];
|
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[1] * 15) + 6 + i] += mat[i];
|
|
|
|
s->geometry[(framei * s->numverts * 15) + (s->tris[trii].i[2] * 15) + 6 + i] += mat[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
framei++;
|
|
|
|
}
|
|
|
|
|
|
|
|
trii++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now that we accumulated the TBNs, average and invert them for each vertex
|
|
|
|
verti = 0;
|
|
|
|
while (verti < (m->head.numframes * s->numverts))
|
|
|
|
{
|
|
|
|
i = 6;
|
|
|
|
while (i < 12)
|
|
|
|
{
|
|
|
|
s->geometry[(verti * 15) + i] /= numtris[verti % s->numverts];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
// copy N over
|
|
|
|
s->geometry[(verti * 15) + 12] = s->geometry[(verti * 15) + 3];
|
|
|
|
s->geometry[(verti * 15) + 13] = s->geometry[(verti * 15) + 4];
|
|
|
|
s->geometry[(verti * 15) + 14] = s->geometry[(verti * 15) + 5];
|
|
|
|
|
|
|
|
invertmatrix(&s->geometry[(verti * 15) + 6], mat);
|
|
|
|
memcpy(&s->geometry[(verti * 15) + 6], mat, sizeof(float) * 9);
|
2009-03-10 14:30:34 +00:00
|
|
|
|
2009-03-10 12:08:33 +00:00
|
|
|
verti++;
|
|
|
|
}
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(numtris);
|
2010-01-24 05:57:43 +00:00
|
|
|
|
2009-03-10 12:08:33 +00:00
|
|
|
surfi++;
|
|
|
|
}
|
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
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
static int32_t md3draw(md3model_t *m, spritetype *tspr)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-03-22 10:23:57 +00:00
|
|
|
point3d fp, fp1, fp2, m0, m1, a0;
|
2006-04-24 19:04:22 +00:00
|
|
|
md3xyzn_t *v0, *v1;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, k, l, surfi;
|
2008-03-22 10:23:57 +00:00
|
|
|
float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16];
|
2006-04-24 19:04:22 +00:00
|
|
|
md3surf_t *s;
|
2008-03-22 10:23:57 +00:00
|
|
|
GLfloat pc[4];
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t texunits = GL_TEXTURE0_ARB;
|
2007-02-16 01:34:41 +00:00
|
|
|
mdskinmap_t *sk;
|
2006-04-24 19:04:22 +00:00
|
|
|
//PLAG : sorting stuff
|
2011-01-16 02:50:27 +00:00
|
|
|
void *vbotemp;
|
|
|
|
point3d *vertexhandle = NULL;
|
|
|
|
uint16_t *indexhandle;
|
2008-05-27 15:47:24 +00:00
|
|
|
char lpal = (tspr->owner >= MAXSPRITES) ? tspr->pal : sprite[tspr->owner].pal;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vbos && (m->vbos == NULL))
|
|
|
|
mdloadvbos(m);
|
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
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
updateanimation((md2model_t *)m,tspr);
|
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
|
|
|
|
2006-09-17 20:16:20 +00:00
|
|
|
f = m->interpol; g = 1-f;
|
|
|
|
|
2008-08-12 06:13:10 +00:00
|
|
|
if (m->interpol < 0 || m->interpol > 1 ||
|
2008-10-20 04:00:00 +00:00
|
|
|
m->cframe < 0 || m->cframe >= m->numframes ||
|
|
|
|
m->nframe < 0 || m->nframe >= m->numframes)
|
2008-08-12 06:13:10 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("Model frame out of bounds!\n");
|
|
|
|
if (m->interpol < 0)
|
|
|
|
m->interpol = 0;
|
|
|
|
if (m->interpol > 1)
|
|
|
|
m->interpol = 1;
|
|
|
|
if (m->cframe < 0)
|
|
|
|
m->cframe = 0;
|
|
|
|
if (m->cframe >= m->numframes)
|
|
|
|
m->cframe = m->numframes - 1;
|
|
|
|
if (m->nframe < 0)
|
|
|
|
m->nframe = 0;
|
|
|
|
if (m->nframe >= m->numframes)
|
|
|
|
m->nframe = m->numframes - 1;
|
|
|
|
}
|
|
|
|
|
2006-08-30 23:32:39 +00:00
|
|
|
if (m->head.flags == 1337)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
// md2
|
2006-12-21 15:18:50 +00:00
|
|
|
m0.x = m->scale * g; m1.x = m->scale *f;
|
|
|
|
m0.y = m->scale * g; m1.y = m->scale *f;
|
|
|
|
m0.z = m->scale * g; m1.z = m->scale *f;
|
2007-12-20 19:14:38 +00:00
|
|
|
a0.x = a0.y = 0; a0.z = ((globalorientation&8)?-m->zadd:m->zadd)*m->scale;
|
2006-09-17 20:16:20 +00:00
|
|
|
}
|
2006-08-30 23:32:39 +00:00
|
|
|
else
|
2006-09-17 20:16:20 +00:00
|
|
|
{
|
|
|
|
m0.x = (1.0/64.0) * m->scale * g; m1.x = (1.0/64.0) * m->scale *f;
|
|
|
|
m0.y = (1.0/64.0) * m->scale * g; m1.y = (1.0/64.0) * m->scale *f;
|
|
|
|
m0.z = (1.0/64.0) * m->scale * g; m1.z = (1.0/64.0) * m->scale *f;
|
2007-12-20 19:14:38 +00:00
|
|
|
a0.x = a0.y = 0; a0.z = ((globalorientation&8)?-m->zadd:m->zadd)*m->scale;
|
2006-09-17 20:16:20 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2006-04-24 19:04:22 +00:00
|
|
|
if ((globalorientation&128) && !((globalorientation&48)==32)) k0 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<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;
|
|
|
|
k0 -= (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<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
|
|
|
|
|
|
|
|
f = ((float)tspr->xrepeat)/64*m->bscale;
|
|
|
|
m0.x *= f; m1.x *= f; a0.x *= f; f = -f; // 20040610: backwards models aren't cool
|
|
|
|
m0.y *= f; m1.y *= f; a0.y *= f;
|
|
|
|
f = ((float)tspr->yrepeat)/64*m->bscale;
|
|
|
|
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;
|
|
|
|
k1 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)>>3);
|
|
|
|
}
|
|
|
|
|
|
|
|
f = (65536.0*512.0)/((float)xdimen*viewingrange);
|
|
|
|
g = 32.0/((float)xdimen*gxyaspect);
|
|
|
|
m0.y *= f; m1.y *= f; a0.y = (((float)(tspr->x-globalposx))/ 1024.0 + a0.y)*f;
|
|
|
|
m0.x *=-f; m1.x *=-f; a0.x = (((float)(k1 -globalposy))/ -1024.0 + a0.x)*-f;
|
|
|
|
m0.z *= g; m1.z *= g; a0.z = (((float)(k0 -globalposz))/-16384.0 + a0.z)*g;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
k0 = ((float)(tspr->x-globalposx))*f/1024.0;
|
|
|
|
k1 = ((float)(tspr->y-globalposy))*f/1024.0;
|
|
|
|
f = gcosang2*gshang;
|
|
|
|
g = gsinang2*gshang;
|
|
|
|
k4 = (float)sintable[(tspr->ang+spriteext[tspr->owner].angoff+1024)&2047] / 16384.0;
|
|
|
|
k5 = (float)sintable[(tspr->ang+spriteext[tspr->owner].angoff+ 512)&2047] / 16384.0;
|
|
|
|
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;
|
|
|
|
|
|
|
|
mat[12] += a0.y*mat[0] + a0.z*mat[4] + a0.x*mat[ 8];
|
|
|
|
mat[13] += a0.y*mat[1] + a0.z*mat[5] + a0.x*mat[ 9];
|
|
|
|
mat[14] += a0.y*mat[2] + a0.z*mat[6] + a0.x*mat[10];
|
|
|
|
|
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
|
|
|
{
|
|
|
|
f = mat[4]; mat[4] = mat[8]*16.0; mat[8] = -f*(1.0/16.0);
|
|
|
|
f = mat[5]; mat[5] = mat[9]*16.0; mat[9] = -f*(1.0/16.0);
|
|
|
|
f = mat[6]; mat[6] = mat[10]*16.0; mat[10] = -f*(1.0/16.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Mirrors
|
|
|
|
if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; }
|
|
|
|
|
|
|
|
//------------
|
2006-04-13 20:47:06 +00:00
|
|
|
//bit 10 is an ugly hack in game.c\animatesprites telling MD2SPRITE
|
|
|
|
//to use Z-buffer hacks to hide overdraw problems with the shadows
|
|
|
|
if (tspr->cstat&1024)
|
|
|
|
{
|
|
|
|
bglDepthFunc(GL_LESS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS
|
|
|
|
bglDepthRange(0.0,0.9999);
|
|
|
|
}
|
|
|
|
bglPushAttrib(GL_POLYGON_BIT);
|
2007-12-12 17:42:14 +00:00
|
|
|
if ((grhalfxdown10x >= 0) ^((globalorientation&8) != 0) ^((globalorientation&4) != 0)) bglFrontFace(GL_CW); else bglFrontFace(GL_CCW);
|
2006-04-13 20:47:06 +00:00
|
|
|
bglEnable(GL_CULL_FACE);
|
|
|
|
bglCullFace(GL_BACK);
|
|
|
|
|
|
|
|
bglEnable(GL_TEXTURE_2D);
|
|
|
|
|
2006-12-04 04:08:14 +00:00
|
|
|
pc[0] = pc[1] = pc[2] = ((float)(numpalookups-min(max((globalshade * shadescale)+m->shadeoff,0),numpalookups)))/((float)numpalookups);
|
2008-03-27 21:32:23 +00:00
|
|
|
if (!(hictinting[globalpal].f&4))
|
|
|
|
{
|
2008-06-05 02:29:18 +00:00
|
|
|
if (!(m->flags&1) || (!(tspr->owner >= MAXSPRITES) && sector[sprite[tspr->owner].sectnum].floorpal!=0))
|
2007-12-20 19:14:38 +00:00
|
|
|
{
|
2008-04-07 00:43:09 +00:00
|
|
|
pc[0] *= (float)hictinting[globalpal].r / 255.0;
|
|
|
|
pc[1] *= (float)hictinting[globalpal].g / 255.0;
|
|
|
|
pc[2] *= (float)hictinting[globalpal].b / 255.0;
|
|
|
|
if (hictinting[MAXPALOOKUPS-1].r != 255 || hictinting[MAXPALOOKUPS-1].g != 255 || hictinting[MAXPALOOKUPS-1].b != 255)
|
|
|
|
{
|
2009-07-09 02:29:48 +00:00
|
|
|
pc[0] *= (float)hictinting[MAXPALOOKUPS-1].r / 255.0f;
|
|
|
|
pc[1] *= (float)hictinting[MAXPALOOKUPS-1].g / 255.0f;
|
|
|
|
pc[2] *= (float)hictinting[MAXPALOOKUPS-1].b / 255.0f;
|
2008-04-07 00:43:09 +00:00
|
|
|
}
|
2007-12-20 19:14:38 +00:00
|
|
|
}
|
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
|
|
|
|
2009-07-09 02:29:48 +00:00
|
|
|
if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66f; else pc[3] = 0.33f; }
|
2007-12-12 17:42:14 +00:00
|
|
|
else pc[3] = 1.0;
|
2006-04-13 20:47:06 +00:00
|
|
|
if (m->usesalpha) //Sprites with alpha in texture
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// bglEnable(GL_BLEND);// bglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
// bglEnable(GL_ALPHA_TEST); bglAlphaFunc(GL_GREATER,0.32);
|
|
|
|
// 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)
|
|
|
|
al=alphahackarray[globalpicnum];
|
2009-02-19 16:47:54 +00:00
|
|
|
bglEnable(GL_BLEND);
|
2006-04-13 20:47:06 +00:00
|
|
|
bglEnable(GL_ALPHA_TEST);
|
|
|
|
bglAlphaFunc(GL_GREATER,al);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-25 10:56:00 +00:00
|
|
|
if (tspr->cstat&2) bglEnable(GL_BLEND); //else bglDisable(GL_BLEND);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
bglColor4f(pc[0],pc[1],pc[2],pc[3]);
|
2006-09-17 20:16:20 +00:00
|
|
|
//if (m->head.flags == 1337)
|
|
|
|
// bglColor4f(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
|
2006-12-21 15:18:50 +00:00
|
|
|
if (spriteext[tspr->owner].pitch || spriteext[tspr->owner].roll || m->head.flags == 1337)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (spriteext[tspr->owner].xoff)
|
2009-07-09 02:29:48 +00:00
|
|
|
a0.x = (float)(spriteext[tspr->owner].xoff / (2560 * (m0.x+m1.x)));
|
2006-04-24 19:04:22 +00:00
|
|
|
else
|
|
|
|
a0.x = 0;
|
|
|
|
if (spriteext[tspr->owner].yoff)
|
2009-07-09 02:29:48 +00:00
|
|
|
a0.y = (float)(spriteext[tspr->owner].yoff / (2560 * (m0.x+m1.x)));
|
2006-04-24 19:04:22 +00:00
|
|
|
else
|
|
|
|
a0.y = 0;
|
|
|
|
if ((spriteext[tspr->owner].zoff) && !(tspr->cstat&1024))
|
2009-07-09 02:29:48 +00:00
|
|
|
a0.z = (float)(spriteext[tspr->owner].zoff / (655360 * (m0.z+m1.z)));
|
2006-04-24 19:04:22 +00:00
|
|
|
else
|
|
|
|
a0.z = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
k0 = (float)sintable[(spriteext[tspr->owner].pitch+512)&2047] / 16384.0;
|
|
|
|
k1 = (float)sintable[spriteext[tspr->owner].pitch&2047] / 16384.0;
|
|
|
|
k2 = (float)sintable[(spriteext[tspr->owner].roll+512)&2047] / 16384.0;
|
|
|
|
k3 = (float)sintable[spriteext[tspr->owner].roll&2047] / 16384.0;
|
|
|
|
}
|
2009-02-19 16:47:54 +00:00
|
|
|
for (surfi=0; surfi<m->head.numsurfs; surfi++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
s = &m->head.surfs[surfi];
|
|
|
|
v0 = &s->xyzn[m->cframe*s->numverts];
|
|
|
|
v1 = &s->xyzn[m->nframe*s->numverts];
|
|
|
|
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
{
|
|
|
|
if (++curvbo >= r_vbocount)
|
|
|
|
curvbo = 0;
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, vertvbos[curvbo]);
|
|
|
|
vbotemp = bglMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
|
|
|
|
vertexhandle = (point3d *)vbotemp;
|
|
|
|
}
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numverts-1; i>=0; i--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-12-21 15:18:50 +00:00
|
|
|
if (spriteext[tspr->owner].pitch || spriteext[tspr->owner].roll || m->head.flags == 1337)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-12-21 15:18:50 +00:00
|
|
|
fp.z = ((m->head.flags == 1337) ? (v0[i].x * m->muladdframes[m->cframe*2].x) + m->muladdframes[m->cframe*2+1].x : v0[i].x) + a0.x;
|
|
|
|
fp.x = ((m->head.flags == 1337) ? (v0[i].y * m->muladdframes[m->cframe*2].y) + m->muladdframes[m->cframe*2+1].y : v0[i].y) + a0.y;
|
|
|
|
fp.y = ((m->head.flags == 1337) ? (v0[i].z * m->muladdframes[m->cframe*2].z) + m->muladdframes[m->cframe*2+1].z : v0[i].z) + a0.z;
|
2006-04-13 20:47:06 +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;
|
2006-12-21 15:18:50 +00:00
|
|
|
fp.z = ((m->head.flags == 1337) ? (v1[i].x * m->muladdframes[m->nframe*2].x) + m->muladdframes[m->nframe*2+1].x : v1[i].x) + a0.x;
|
|
|
|
fp.x = ((m->head.flags == 1337) ? (v1[i].y * m->muladdframes[m->nframe*2].y) + m->muladdframes[m->nframe*2+1].y : v1[i].y) + a0.y;
|
|
|
|
fp.y = ((m->head.flags == 1337) ? (v1[i].z * m->muladdframes[m->nframe*2].z) + m->muladdframes[m->nframe*2+1].z : v1[i].z) + a0.z;
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
{
|
|
|
|
vertexhandle[i].x = fp.x;
|
|
|
|
vertexhandle[i].y = fp.y;
|
|
|
|
vertexhandle[i].z = fp.z;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
vertlist[i].x = fp.x;
|
|
|
|
vertlist[i].y = fp.y;
|
|
|
|
vertlist[i].z = fp.z;
|
|
|
|
}
|
2007-03-08 03:07:10 +00:00
|
|
|
|
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
{
|
|
|
|
bglUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
bglMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation
|
|
|
|
mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f; bglLoadMatrixf(mat);
|
2006-04-24 19:04:22 +00:00
|
|
|
// PLAG: End
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-10 07:38:50 +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
|
2006-04-13 20:47:06 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, i);
|
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
if (r_detailmapping && !(tspr->cstat&1024))
|
2009-01-10 07:38:50 +00:00
|
|
|
i = mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,DETAILPAL,surfi);
|
2007-02-15 01:35:34 +00:00
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
bglActiveTextureARB(++texunits);
|
|
|
|
|
|
|
|
bglEnable(GL_TEXTURE_2D);
|
|
|
|
bglBindTexture(GL_TEXTURE_2D, i);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
2007-12-12 17:42:14 +00:00
|
|
|
|
2007-02-15 01:35:34 +00:00
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2.0f);
|
|
|
|
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
|
|
|
|
2007-02-16 01:34:41 +00:00
|
|
|
for (sk = m->skinmap; sk; sk = sk->next)
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((int32_t)sk->palette == DETAILPAL && sk->skinnum == tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum && sk->surfnum == surfi)
|
2007-02-16 01:34:41 +00:00
|
|
|
f = sk->param;
|
2007-02-15 01:35:34 +00:00
|
|
|
|
|
|
|
bglMatrixMode(GL_TEXTURE);
|
|
|
|
bglLoadIdentity();
|
|
|
|
bglScalef(f, f, 1.0f);
|
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
2007-02-16 01:34:41 +00:00
|
|
|
}
|
2007-02-15 01:35:34 +00:00
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
if (r_glowmapping && !(tspr->cstat&1024))
|
2009-01-10 07:38:50 +00:00
|
|
|
i = mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,GLOWPAL,surfi);
|
2007-02-15 01:35:34 +00:00
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
bglActiveTextureARB(++texunits);
|
|
|
|
|
|
|
|
bglEnable(GL_TEXTURE_2D);
|
|
|
|
bglBindTexture(GL_TEXTURE_2D, i);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_TEXTURE);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
|
|
|
|
}
|
|
|
|
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vertexarrays && r_vbos)
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexvbos[curvbo]);
|
|
|
|
vbotemp = bglMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
|
2009-01-09 09:29:17 +00:00
|
|
|
indexhandle = (uint16_t *)vbotemp;
|
2007-03-08 03:07:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
indexhandle = m->vindexes;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//PLAG: delayed polygon-level sorted rendering
|
2010-05-25 10:56:00 +00:00
|
|
|
if (m->usesalpha && !(tspr->cstat & 1024))
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numtris-1; i>=0; i--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
// Matrix multiplication - ugly but clear
|
|
|
|
fp.x = (vertlist[s->tris[i].i[0]].x * mat[0]) + (vertlist[s->tris[i].i[0]].y * mat[4]) + (vertlist[s->tris[i].i[0]].z * mat[8]) + mat[12];
|
|
|
|
fp.y = (vertlist[s->tris[i].i[0]].x * mat[1]) + (vertlist[s->tris[i].i[0]].y * mat[5]) + (vertlist[s->tris[i].i[0]].z * mat[9]) + mat[13];
|
|
|
|
fp.z = (vertlist[s->tris[i].i[0]].x * mat[2]) + (vertlist[s->tris[i].i[0]].y * mat[6]) + (vertlist[s->tris[i].i[0]].z * mat[10]) + mat[14];
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
fp1.x = (vertlist[s->tris[i].i[1]].x * mat[0]) + (vertlist[s->tris[i].i[1]].y * mat[4]) + (vertlist[s->tris[i].i[1]].z * mat[8]) + mat[12];
|
|
|
|
fp1.y = (vertlist[s->tris[i].i[1]].x * mat[1]) + (vertlist[s->tris[i].i[1]].y * mat[5]) + (vertlist[s->tris[i].i[1]].z * mat[9]) + mat[13];
|
|
|
|
fp1.z = (vertlist[s->tris[i].i[1]].x * mat[2]) + (vertlist[s->tris[i].i[1]].y * mat[6]) + (vertlist[s->tris[i].i[1]].z * mat[10]) + mat[14];
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
fp2.x = (vertlist[s->tris[i].i[2]].x * mat[0]) + (vertlist[s->tris[i].i[2]].y * mat[4]) + (vertlist[s->tris[i].i[2]].z * mat[8]) + mat[12];
|
|
|
|
fp2.y = (vertlist[s->tris[i].i[2]].x * mat[1]) + (vertlist[s->tris[i].i[2]].y * mat[5]) + (vertlist[s->tris[i].i[2]].z * mat[9]) + mat[13];
|
|
|
|
fp2.z = (vertlist[s->tris[i].i[2]].x * mat[2]) + (vertlist[s->tris[i].i[2]].y * mat[6]) + (vertlist[s->tris[i].i[2]].z * mat[10]) + mat[14];
|
|
|
|
|
|
|
|
f = (fp.x * fp.x) + (fp.y * fp.y) + (fp.z * fp.z);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
g = (fp1.x * fp1.x) + (fp1.y * fp1.y) + (fp1.z * fp1.z);
|
|
|
|
if (f > g)
|
|
|
|
f = g;
|
|
|
|
g = (fp2.x * fp2.x) + (fp2.y * fp2.y) + (fp2.z * fp2.z);
|
|
|
|
if (f > g)
|
|
|
|
f = g;
|
|
|
|
|
2007-03-03 23:09:40 +00:00
|
|
|
m->maxdepths[i] = f;
|
|
|
|
m->indexes[i] = i;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// dichotomic recursive sorting - about 100x less iterations than bubblesort
|
2007-03-03 23:09:40 +00:00
|
|
|
quicksort(m->indexes, m->maxdepths, 0, s->numtris - 1);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2007-03-03 23:09:40 +00:00
|
|
|
if (r_vertexarrays)
|
|
|
|
{
|
|
|
|
k = 0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numtris-1; i>=0; i--)
|
|
|
|
for (j=0; j<3; j++)
|
2007-03-08 03:07:10 +00:00
|
|
|
indexhandle[k++] = s->tris[m->indexes[i]].i[j];
|
2007-03-03 23:09:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bglBegin(GL_TRIANGLES);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numtris-1; i>=0; i--)
|
|
|
|
for (j=0; j<3; j++)
|
2007-02-15 01:35:34 +00:00
|
|
|
{
|
2007-03-03 23:09:40 +00:00
|
|
|
k = s->tris[m->indexes[i]].i[j];
|
|
|
|
if (texunits > GL_TEXTURE0_ARB)
|
|
|
|
{
|
|
|
|
l = GL_TEXTURE0_ARB;
|
|
|
|
while (l <= texunits)
|
|
|
|
bglMultiTexCoord2fARB(l++, s->uv[k].u,s->uv[k].v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bglTexCoord2f(s->uv[k].u,s->uv[k].v);
|
|
|
|
bglVertex3fv((float *)&vertlist[k]);
|
2007-02-15 01:35:34 +00:00
|
|
|
}
|
2007-03-03 23:09:40 +00:00
|
|
|
bglEnd();
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-03 23:09:40 +00:00
|
|
|
if (r_vertexarrays)
|
|
|
|
{
|
|
|
|
k = 0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numtris-1; i>=0; i--)
|
|
|
|
for (j=0; j<3; j++)
|
2007-03-08 03:07:10 +00:00
|
|
|
indexhandle[k++] = s->tris[i].i[j];
|
2007-03-03 23:09:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bglBegin(GL_TRIANGLES);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=s->numtris-1; i>=0; i--)
|
|
|
|
for (j=0; j<3; j++)
|
2007-02-15 01:35:34 +00:00
|
|
|
{
|
2007-03-03 23:09:40 +00:00
|
|
|
k = s->tris[i].i[j];
|
|
|
|
if (texunits > GL_TEXTURE0_ARB)
|
|
|
|
{
|
|
|
|
l = GL_TEXTURE0_ARB;
|
|
|
|
while (l <= texunits)
|
|
|
|
bglMultiTexCoord2fARB(l++, s->uv[k].u,s->uv[k].v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bglTexCoord2f(s->uv[k].u,s->uv[k].v);
|
|
|
|
bglVertex3fv((float *)&vertlist[k]);
|
2007-02-15 01:35:34 +00:00
|
|
|
}
|
2007-03-03 23:09:40 +00:00
|
|
|
bglEnd();
|
|
|
|
}
|
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 && r_vbos)
|
|
|
|
{
|
|
|
|
bglUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB);
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r_vertexarrays)
|
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
if (r_vbos)
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, m->vbos[surfi]);
|
|
|
|
l = GL_TEXTURE0_ARB;
|
|
|
|
while (l <= texunits)
|
|
|
|
{
|
|
|
|
bglClientActiveTextureARB(l++);
|
|
|
|
bglEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2007-03-08 03:07:10 +00:00
|
|
|
if (r_vbos)
|
2007-12-12 17:42:14 +00:00
|
|
|
bglTexCoordPointer(2, GL_FLOAT, 0, 0);
|
2007-03-08 03:07:10 +00:00
|
|
|
else
|
2007-12-12 17:42:14 +00:00
|
|
|
bglTexCoordPointer(2, GL_FLOAT, 0, &(s->uv[0].u));
|
|
|
|
}
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (r_vbos)
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, vertvbos[curvbo]);
|
|
|
|
bglVertexPointer(3, GL_FLOAT, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bglVertexPointer(3, GL_FLOAT, 0, &(vertlist[0].x));
|
2007-03-08 03:07:10 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (r_vbos)
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexvbos[curvbo]);
|
|
|
|
bglDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_SHORT, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bglDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_SHORT, m->vindexes);
|
|
|
|
|
|
|
|
if (r_vbos)
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
2007-03-08 03:07:10 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
while (texunits > GL_TEXTURE0_ARB)
|
|
|
|
{
|
|
|
|
bglMatrixMode(GL_TEXTURE);
|
|
|
|
bglLoadIdentity();
|
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.0f);
|
|
|
|
bglDisable(GL_TEXTURE_2D);
|
|
|
|
if (r_vertexarrays)
|
2007-02-15 01:35:34 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
bglDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
bglClientActiveTextureARB(texunits - 1);
|
2007-02-15 01:35:34 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
bglActiveTextureARB(--texunits);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
//------------
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
if (m->usesalpha) bglDisable(GL_ALPHA_TEST);
|
|
|
|
bglDisable(GL_CULL_FACE);
|
|
|
|
bglPopAttrib();
|
|
|
|
if (tspr->cstat&1024)
|
|
|
|
{
|
2007-01-06 01:29:45 +00:00
|
|
|
bglDepthFunc(GL_LESS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS
|
2006-04-13 20:47:06 +00:00
|
|
|
bglDepthRange(0.0,0.99999);
|
|
|
|
}
|
|
|
|
bglLoadIdentity();
|
|
|
|
|
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;
|
|
|
|
md3surf_t *s;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t surfi;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (surfi=m->head.numsurfs-1; surfi>=0; surfi--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
s = &m->head.surfs[surfi];
|
2010-05-18 00:30:30 +00:00
|
|
|
if (s->tris) Bfree(s->tris);
|
2006-12-16 23:18:11 +00:00
|
|
|
if (m->head.flags == 1337)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
if (s->shaders) Bfree(s->shaders);
|
|
|
|
if (s->uv) Bfree(s->uv);
|
|
|
|
if (s->xyzn) Bfree(s->xyzn);
|
2010-06-26 08:51:42 +00:00
|
|
|
if (s->geometry) Bfree(s->geometry);
|
2008-06-13 14:40:28 +00:00
|
|
|
}
|
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
|
|
|
}
|
2010-05-18 00:30:30 +00:00
|
|
|
if (m->head.tags) Bfree(m->head.tags);
|
|
|
|
if (m->head.frames) Bfree(m->head.frames);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (m->texid) Bfree(m->texid);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (m->muladdframes) Bfree(m->muladdframes);
|
2006-09-17 20:16:20 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
if (m->indexes) Bfree(m->indexes);
|
|
|
|
if (m->vindexes) Bfree(m->vindexes);
|
|
|
|
if (m->maxdepths) Bfree(m->maxdepths);
|
2007-03-03 23:09:40 +00:00
|
|
|
|
2009-01-04 22:22:33 +00:00
|
|
|
if (m->vbos)
|
2007-03-08 03:07:10 +00:00
|
|
|
{
|
|
|
|
bglDeleteBuffersARB(m->head.numsurfs, m->vbos);
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(m->vbos);
|
2009-01-04 22:22:33 +00:00
|
|
|
m->vbos = NULL;
|
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 ----------------------------------------
|
|
|
|
//--------------------------------------- VOX LIBRARY BEGINS ---------------------------------------
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//For loading/conversion only
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t xsiz, ysiz, zsiz, yzsiz, *vbit = 0; //vbit: 1 bit per voxel: 0=air,1=solid
|
2006-04-13 20:47:06 +00:00
|
|
|
static float xpiv, ypiv, zpiv; //Might want to use more complex/unique names!
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t *vcolhashead = 0, vcolhashsizm1;
|
|
|
|
typedef struct { int32_t p, c, n; } voxcol_t;
|
|
|
|
static voxcol_t *vcol = 0; int32_t vnum = 0, vmax = 0;
|
|
|
|
typedef struct { int16_t x, y; } spoint2d;
|
2006-04-13 20:47:06 +00:00
|
|
|
static spoint2d *shp;
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t *shcntmal, *shcnt = 0, shcntp;
|
|
|
|
static int32_t mytexo5, *zbit, gmaxx, gmaxy, garea, pow2m1[33];
|
2009-01-10 07:38:50 +00:00
|
|
|
static voxmodel_t *gvox;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//pitch must equal xsiz*4
|
2009-06-05 20:09:13 +00:00
|
|
|
uint32_t gloadtex(int32_t *picbuf, int32_t xsiz, int32_t ysiz, int32_t is8bit, int32_t dapal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-06-05 20:09:13 +00:00
|
|
|
uint32_t rtexid;
|
2006-04-13 20:47:06 +00:00
|
|
|
coltype *pic, *pic2;
|
2009-01-09 09:29:17 +00:00
|
|
|
char *cptr;
|
|
|
|
int32_t i;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
pic = (coltype *)picbuf; //Correct for GL's RGB order; also apply gamma here..
|
2010-05-20 06:05:46 +00:00
|
|
|
pic2 = (coltype *)Bmalloc(xsiz*ysiz*sizeof(int32_t)); if (!pic2) return((unsigned)-1);
|
2011-01-16 02:50:27 +00:00
|
|
|
cptr = (char *)&britable[gammabrightness ? 0 : curbrightness][0];
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!is8bit)
|
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=xsiz*ysiz-1; i>=0; i--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
pic2[i].b = cptr[pic[i].r];
|
|
|
|
pic2[i].g = cptr[pic[i].g];
|
|
|
|
pic2[i].r = cptr[pic[i].b];
|
|
|
|
pic2[i].a = 255;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-20 04:56:22 +00:00
|
|
|
if (palookup[dapal] == NULL) dapal = 0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=xsiz*ysiz-1; i>=0; i--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
pic2[i].b = cptr[palette[(int32_t)palookup[dapal][pic[i].a]*3+2]*4];
|
|
|
|
pic2[i].g = cptr[palette[(int32_t)palookup[dapal][pic[i].a]*3+1]*4];
|
|
|
|
pic2[i].r = cptr[palette[(int32_t)palookup[dapal][pic[i].a]*3+0]*4];
|
2006-04-24 19:04:22 +00:00
|
|
|
pic2[i].a = 255;
|
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
bglGenTextures(1,(GLuint *)&rtexid);
|
2006-04-13 20:47:06 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D,rtexid);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
2009-01-09 09:29:17 +00:00
|
|
|
bglTexImage2D(GL_TEXTURE_2D,0,4,xsiz,ysiz,0,GL_RGBA,GL_UNSIGNED_BYTE,(char *)pic2);
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(pic2);
|
2006-04-13 20:47:06 +00:00
|
|
|
return(rtexid);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t getvox(int32_t x, int32_t y, int32_t z)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
z += x*yzsiz + y*zsiz;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (x=vcolhashead[(z*214013)&vcolhashsizm1]; x>=0; x=vcol[x].n)
|
2006-04-13 20:47:06 +00:00
|
|
|
if (vcol[x].p == z) return(vcol[x].c);
|
|
|
|
return(0x808080);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void putvox(int32_t x, int32_t y, int32_t z, int32_t col)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
if (vnum >= vmax) { vmax = max(vmax<<1,4096); vcol = (voxcol_t *)Brealloc(vcol,vmax*sizeof(voxcol_t)); }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
z += x*yzsiz + y*zsiz;
|
|
|
|
vcol[vnum].p = z; z = ((z*214013)&vcolhashsizm1);
|
|
|
|
vcol[vnum].c = col;
|
|
|
|
vcol[vnum].n = vcolhashead[z]; vcolhashead[z] = vnum++;
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Set all bits in vbit from (x,y,z0) to (x,y,z1-1) to 0's
|
2008-03-22 10:23:57 +00:00
|
|
|
#if 0
|
2009-01-09 09:29:17 +00:00
|
|
|
static void setzrange0(int32_t *lptr, int32_t z0, int32_t z1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t z, ze;
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!((z0^z1)&~31)) { lptr[z0>>5] &= ((~(-1<<SHIFTMOD32(z0)))|(-1<<SHIFTMOD32(z1))); return; }
|
|
|
|
z = (z0>>5); ze = (z1>>5);
|
2009-02-19 16:47:54 +00:00
|
|
|
lptr[z] &=~(-1<<SHIFTMOD32(z0)); for (z++; z<ze; z++) lptr[z] = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
lptr[z] &= (-1<<SHIFTMOD32(z1));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2008-03-22 10:23:57 +00:00
|
|
|
#endif
|
2006-04-24 19:04:22 +00:00
|
|
|
//Set all bits in vbit from (x,y,z0) to (x,y,z1-1) to 1's
|
2009-01-09 09:29:17 +00:00
|
|
|
static void setzrange1(int32_t *lptr, int32_t z0, int32_t z1)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t z, ze;
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!((z0^z1)&~31)) { lptr[z0>>5] |= ((~(-1<<SHIFTMOD32(z1)))&(-1<<SHIFTMOD32(z0))); return; }
|
|
|
|
z = (z0>>5); ze = (z1>>5);
|
2009-02-19 16:47:54 +00:00
|
|
|
lptr[z] |= (-1<<SHIFTMOD32(z0)); for (z++; z<ze; z++) lptr[z] = -1;
|
2006-04-24 19:04:22 +00:00
|
|
|
lptr[z] |=~(-1<<SHIFTMOD32(z1));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t isrectfree(int32_t x0, int32_t y0, int32_t dx, int32_t dy)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
#if 0
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, x;
|
2006-04-24 19:04:22 +00:00
|
|
|
i = y0*gvox->mytexx + x0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (dy=0; dy; dy--,i+=gvox->mytexx)
|
|
|
|
for (x=0; x<dx; x++) { j = i+x; if (zbit[j>>5]&(1<<SHIFTMOD32(j))) return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
#else
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, c, m, m1, x;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
i = y0*mytexo5 + (x0>>5); dx += x0-1; c = (dx>>5) - (x0>>5);
|
|
|
|
m = ~pow2m1[x0&31]; m1 = pow2m1[(dx&31)+1];
|
2009-02-19 16:47:54 +00:00
|
|
|
if (!c) { for (m&=m1; dy; dy--,i+=mytexo5) if (zbit[i]&m) return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
else
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (; dy; dy--,i+=mytexo5)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
if (zbit[i]&m) return(0);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (x=1; x<c; x++) if (zbit[i+x]) return(0);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (zbit[i+x]&m1) return(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void setrect(int32_t x0, int32_t y0, int32_t dx, int32_t dy)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
#if 0
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, y;
|
2006-04-24 19:04:22 +00:00
|
|
|
i = y0*gvox->mytexx + x0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (y=0; y<dy; y++,i+=gvox->mytexx)
|
|
|
|
for (x=0; x<dx; x++) { j = i+x; zbit[j>>5] |= (1<<SHIFTMOD32(j)); }
|
2006-04-13 20:47:06 +00:00
|
|
|
#else
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, c, m, m1, x;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
i = y0*mytexo5 + (x0>>5); dx += x0-1; c = (dx>>5) - (x0>>5);
|
|
|
|
m = ~pow2m1[x0&31]; m1 = pow2m1[(dx&31)+1];
|
2009-02-19 16:47:54 +00:00
|
|
|
if (!c) { for (m&=m1; dy; dy--,i+=mytexo5) zbit[i] |= m; }
|
2006-04-13 20:47:06 +00:00
|
|
|
else
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-02-19 16:47:54 +00:00
|
|
|
for (; dy; dy--,i+=mytexo5)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
zbit[i] |= m;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (x=1; x<c; x++) zbit[i+x] = -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
zbit[i+x] |= m1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void cntquad(int32_t x0, int32_t y0, int32_t z0, int32_t x1, int32_t y1, int32_t z1, int32_t x2, int32_t y2, int32_t z2, int32_t face)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t x, y, z;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-03-22 10:23:57 +00:00
|
|
|
UNREFERENCED_PARAMETER(x1);
|
|
|
|
UNREFERENCED_PARAMETER(y1);
|
|
|
|
UNREFERENCED_PARAMETER(z1);
|
|
|
|
UNREFERENCED_PARAMETER(face);
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
x = labs(x2-x0); y = labs(y2-y0); z = labs(z2-z0);
|
|
|
|
if (!x) x = z; else if (!y) y = z;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (x < y) { z = x; x = y; y = z; }
|
2006-04-13 20:47:06 +00:00
|
|
|
shcnt[y*shcntp+x]++;
|
|
|
|
if (x > gmaxx) gmaxx = x;
|
|
|
|
if (y > gmaxy) gmaxy = y;
|
|
|
|
garea += (x+(VOXBORDWIDTH<<1))*(y+(VOXBORDWIDTH<<1));
|
|
|
|
gvox->qcnt++;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void addquad(int32_t x0, int32_t y0, int32_t z0, int32_t x1, int32_t y1, int32_t z1, int32_t x2, int32_t y2, int32_t z2, int32_t face)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, x, y, z, xx, yy, nx = 0, ny = 0, nz = 0, *lptr;
|
2006-04-13 20:47:06 +00:00
|
|
|
voxrect_t *qptr;
|
|
|
|
|
|
|
|
x = labs(x2-x0); y = labs(y2-y0); z = labs(z2-z0);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!x) { x = y; y = z; i = 0; }
|
|
|
|
else if (!y) { y = z; i = 1; }
|
|
|
|
else i = 2;
|
|
|
|
if (x < y) { z = x; x = y; y = z; i += 3; }
|
2006-04-13 20:47:06 +00:00
|
|
|
z = shcnt[y*shcntp+x]++;
|
|
|
|
lptr = &gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+(shp[z].x+VOXBORDWIDTH)];
|
2006-11-13 23:12:47 +00:00
|
|
|
switch (face)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
case 0:
|
|
|
|
ny = y1; x2 = x0; x0 = x1; x1 = x2; break;
|
|
|
|
case 1:
|
|
|
|
ny = y0; y0++; y1++; y2++; break;
|
|
|
|
case 2:
|
|
|
|
nz = z1; y0 = y2; y2 = y1; y1 = y0; z0++; z1++; z2++; break;
|
|
|
|
case 3:
|
|
|
|
nz = z0; break;
|
|
|
|
case 4:
|
|
|
|
nx = x1; y2 = y0; y0 = y1; y1 = y2; x0++; x1++; x2++; break;
|
|
|
|
case 5:
|
|
|
|
nx = x0; break;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2009-02-19 16:47:54 +00:00
|
|
|
for (yy=0; yy<y; yy++,lptr+=gvox->mytexx)
|
|
|
|
for (xx=0; xx<x; xx++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
switch (face)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
case 0:
|
2007-12-12 17:42:14 +00:00
|
|
|
if (i < 3) { nx = x1+x-1-xx; nz = z1+yy; } //back
|
|
|
|
else { nx = x1+y-1-yy; nz = z1+xx; }
|
|
|
|
break;
|
2006-11-13 23:12:47 +00:00
|
|
|
case 1:
|
2007-12-12 17:42:14 +00:00
|
|
|
if (i < 3) { nx = x0+xx; nz = z0+yy; } //front
|
|
|
|
else { nx = x0+yy; nz = z0+xx; }
|
|
|
|
break;
|
2006-11-13 23:12:47 +00:00
|
|
|
case 2:
|
2007-12-12 17:42:14 +00:00
|
|
|
if (i < 3) { nx = x1-x+xx; ny = y1-1-yy; } //bot
|
|
|
|
else { nx = x1-1-yy; ny = y1-1-xx; }
|
|
|
|
break;
|
2006-11-13 23:12:47 +00:00
|
|
|
case 3:
|
2007-12-12 17:42:14 +00:00
|
|
|
if (i < 3) { nx = x0+xx; ny = y0+yy; } //top
|
|
|
|
else { nx = x0+yy; ny = y0+xx; }
|
|
|
|
break;
|
2006-11-13 23:12:47 +00:00
|
|
|
case 4:
|
2007-12-12 17:42:14 +00:00
|
|
|
if (i < 3) { ny = y1+x-1-xx; nz = z1+yy; } //right
|
|
|
|
else { ny = y1+y-1-yy; nz = z1+xx; }
|
|
|
|
break;
|
2006-11-13 23:12:47 +00:00
|
|
|
case 5:
|
2007-12-12 17:42:14 +00:00
|
|
|
if (i < 3) { ny = y0+xx; nz = z0+yy; } //left
|
|
|
|
else { ny = y0+yy; nz = z0+xx; }
|
|
|
|
break;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
lptr[xx] = getvox(nx,ny,nz);
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Extend borders horizontally
|
2009-02-19 16:47:54 +00:00
|
|
|
for (yy=VOXBORDWIDTH; yy<y+VOXBORDWIDTH; yy++)
|
|
|
|
for (xx=0; xx<VOXBORDWIDTH; xx++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
lptr = &gvox->mytex[(shp[z].y+yy)*gvox->mytexx+shp[z].x];
|
|
|
|
lptr[xx] = lptr[VOXBORDWIDTH]; lptr[xx+x+VOXBORDWIDTH] = lptr[x-1+VOXBORDWIDTH];
|
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
//Extend borders vertically
|
2009-02-19 16:47:54 +00:00
|
|
|
for (yy=0; yy<VOXBORDWIDTH; yy++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(&gvox->mytex[(shp[z].y+yy)*gvox->mytexx+shp[z].x],
|
2009-06-24 08:20:10 +00:00
|
|
|
&gvox->mytex[(shp[z].y+VOXBORDWIDTH)*gvox->mytexx+shp[z].x],
|
|
|
|
(x+(VOXBORDWIDTH<<1))<<2);
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(&gvox->mytex[(shp[z].y+y+yy+VOXBORDWIDTH)*gvox->mytexx+shp[z].x],
|
2009-06-24 08:20:10 +00:00
|
|
|
&gvox->mytex[(shp[z].y+y-1+VOXBORDWIDTH)*gvox->mytexx+shp[z].x],
|
|
|
|
(x+(VOXBORDWIDTH<<1))<<2);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qptr = &gvox->quad[gvox->qcnt];
|
|
|
|
qptr->v[0].x = x0; qptr->v[0].y = y0; qptr->v[0].z = z0;
|
|
|
|
qptr->v[1].x = x1; qptr->v[1].y = y1; qptr->v[1].z = z1;
|
|
|
|
qptr->v[2].x = x2; qptr->v[2].y = y2; qptr->v[2].z = z2;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<3; j++) { qptr->v[j].u = shp[z].x+VOXBORDWIDTH; qptr->v[j].v = shp[z].y+VOXBORDWIDTH; }
|
2006-04-13 20:47:06 +00:00
|
|
|
if (i < 3) qptr->v[1].u += x; else qptr->v[1].v += y;
|
|
|
|
qptr->v[2].u += x; qptr->v[2].v += y;
|
|
|
|
|
|
|
|
qptr->v[3].u = qptr->v[0].u - qptr->v[1].u + qptr->v[2].u;
|
|
|
|
qptr->v[3].v = qptr->v[0].v - qptr->v[1].v + qptr->v[2].v;
|
|
|
|
qptr->v[3].x = qptr->v[0].x - qptr->v[1].x + qptr->v[2].x;
|
|
|
|
qptr->v[3].y = qptr->v[0].y - qptr->v[1].y + qptr->v[2].y;
|
|
|
|
qptr->v[3].z = qptr->v[0].z - qptr->v[1].z + qptr->v[2].z;
|
|
|
|
if (gvox->qfacind[face] < 0) gvox->qfacind[face] = gvox->qcnt;
|
|
|
|
gvox->qcnt++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t isolid(int32_t x, int32_t y, int32_t z)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((uint32_t)x >= (uint32_t)xsiz) return(0);
|
|
|
|
if ((uint32_t)y >= (uint32_t)ysiz) return(0);
|
|
|
|
if ((uint32_t)z >= (uint32_t)zsiz) return(0);
|
2006-04-24 19:04:22 +00:00
|
|
|
z += x*yzsiz + y*zsiz; return(vbit[z>>5]&(1<<SHIFTMOD32(z)));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
static voxmodel_t *vox2poly()
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, x, y, z, v, ov, oz = 0, cnt, sc, x0, y0, dx, dy,*bx0, *by0;
|
|
|
|
void (*daquad)(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
gvox = (voxmodel_t *)Bmalloc(sizeof(voxmodel_t)); if (!gvox) return(0);
|
2009-01-10 07:38:50 +00:00
|
|
|
memset(gvox,0,sizeof(voxmodel_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//x is largest dimension, y is 2nd largest dimension
|
2006-04-13 20:47:06 +00:00
|
|
|
x = xsiz; y = ysiz; z = zsiz;
|
|
|
|
if ((x < y) && (x < z)) x = z; else if (y < z) y = z;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (x < y) { z = x; x = y; y = z; }
|
2009-01-09 09:29:17 +00:00
|
|
|
shcntp = x; i = x*y*sizeof(int32_t);
|
2010-05-20 06:05:46 +00:00
|
|
|
shcntmal = (int32_t *)Bmalloc(i); if (!shcntmal) { Bfree(gvox); return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
memset(shcntmal,0,i); shcnt = &shcntmal[-shcntp-1];
|
|
|
|
gmaxx = gmaxy = garea = 0;
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
if (pow2m1[32] != -1) { for (i=0; i<32; i++) pow2m1[i] = (1<<i)-1; pow2m1[32] = -1; }
|
|
|
|
for (i=0; i<7; i++) gvox->qfacind[i] = -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
i = ((max(ysiz,zsiz)+1)<<2);
|
2010-05-20 06:05:46 +00:00
|
|
|
bx0 = (int32_t *)Bmalloc(i<<1); if (!bx0) { Bfree(gvox); return(0); }
|
2009-01-09 09:29:17 +00:00
|
|
|
by0 = (int32_t *)(((intptr_t)bx0)+i);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (cnt=0; cnt<2; cnt++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
if (!cnt) daquad = cntquad;
|
2006-04-24 19:04:22 +00:00
|
|
|
else daquad = addquad;
|
2006-04-13 20:47:06 +00:00
|
|
|
gvox->qcnt = 0;
|
|
|
|
|
|
|
|
memset(by0,-1,(max(ysiz,zsiz)+1)<<2); v = 0;
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=-1; i<=1; i+=2)
|
|
|
|
for (y=0; y<ysiz; y++)
|
|
|
|
for (x=0; x<=xsiz; x++)
|
|
|
|
for (z=0; z<=zsiz; z++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
ov = v; v = (isolid(x,y,z) && (!isolid(x,y+i,z)));
|
|
|
|
if ((by0[z] >= 0) && ((by0[z] != oz) || (v >= ov)))
|
2007-12-12 17:42:14 +00:00
|
|
|
{ daquad(bx0[z],y,by0[z],x,y,by0[z],x,y,z,i>=0); by0[z] = -1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
if (v > ov) oz = z; else if ((v < ov) && (by0[z] != oz)) { bx0[z] = x; by0[z] = oz; }
|
|
|
|
}
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=-1; i<=1; i+=2)
|
|
|
|
for (z=0; z<zsiz; z++)
|
|
|
|
for (x=0; x<=xsiz; x++)
|
|
|
|
for (y=0; y<=ysiz; y++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
ov = v; v = (isolid(x,y,z) && (!isolid(x,y,z-i)));
|
|
|
|
if ((by0[y] >= 0) && ((by0[y] != oz) || (v >= ov)))
|
2007-12-12 17:42:14 +00:00
|
|
|
{ daquad(bx0[y],by0[y],z,x,by0[y],z,x,y,z,(i>=0)+2); by0[y] = -1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
if (v > ov) oz = y; else if ((v < ov) && (by0[y] != oz)) { bx0[y] = x; by0[y] = oz; }
|
|
|
|
}
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=-1; i<=1; i+=2)
|
|
|
|
for (x=0; x<xsiz; x++)
|
|
|
|
for (y=0; y<=ysiz; y++)
|
|
|
|
for (z=0; z<=zsiz; z++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
ov = v; v = (isolid(x,y,z) && (!isolid(x-i,y,z)));
|
|
|
|
if ((by0[z] >= 0) && ((by0[z] != oz) || (v >= ov)))
|
2007-12-12 17:42:14 +00:00
|
|
|
{ daquad(x,bx0[z],by0[z],x,y,by0[z],x,y,z,(i>=0)+4); by0[z] = -1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
if (v > ov) oz = z; else if ((v < ov) && (by0[z] != oz)) { bx0[z] = y; by0[z] = oz; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cnt)
|
|
|
|
{
|
2010-05-20 06:05:46 +00:00
|
|
|
shp = (spoint2d *)Bmalloc(gvox->qcnt*sizeof(spoint2d));
|
2010-05-18 00:30:30 +00:00
|
|
|
if (!shp) { Bfree(bx0); Bfree(gvox); return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
sc = 0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (y=gmaxy; y; y--)
|
|
|
|
for (x=gmaxx; x>=y; x--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
i = shcnt[y*shcntp+x]; shcnt[y*shcntp+x] = sc; //shcnt changes from counter to head index
|
2009-02-19 16:47:54 +00:00
|
|
|
for (; i>0; i--) { shp[sc].x = x; shp[sc].y = y; sc++; }
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (gvox->mytexx=32; gvox->mytexx<(gmaxx+(VOXBORDWIDTH<<1)); gvox->mytexx<<=1);
|
|
|
|
for (gvox->mytexy=32; gvox->mytexy<(gmaxy+(VOXBORDWIDTH<<1)); gvox->mytexy<<=1);
|
2006-04-13 20:47:06 +00:00
|
|
|
while (gvox->mytexx*gvox->mytexy*8 < garea*9) //This should be sufficient to fit most skins...
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
skindidntfit:
|
|
|
|
;
|
2006-04-13 20:47:06 +00:00
|
|
|
if (gvox->mytexx <= gvox->mytexy) gvox->mytexx <<= 1; else gvox->mytexy <<= 1;
|
|
|
|
}
|
|
|
|
mytexo5 = (gvox->mytexx>>5);
|
|
|
|
|
|
|
|
i = (((gvox->mytexx*gvox->mytexy+31)>>5)<<2);
|
2010-05-20 06:05:46 +00:00
|
|
|
zbit = (int32_t *)Bmalloc(i); if (!zbit) { Bfree(bx0); Bfree(gvox); Bfree(shp); return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
memset(zbit,0,i);
|
|
|
|
|
|
|
|
v = gvox->mytexx*gvox->mytexy;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (z=0; z<sc; z++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
dx = shp[z].x+(VOXBORDWIDTH<<1); dy = shp[z].y+(VOXBORDWIDTH<<1); i = v;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
#if (VOXUSECHAR != 0)
|
|
|
|
x0 = (((rand()&32767)*(min(gvox->mytexx,255)-dx))>>15);
|
|
|
|
y0 = (((rand()&32767)*(min(gvox->mytexy,255)-dy))>>15);
|
|
|
|
#else
|
|
|
|
x0 = (((rand()&32767)*(gvox->mytexx+1-dx))>>15);
|
|
|
|
y0 = (((rand()&32767)*(gvox->mytexy+1-dy))>>15);
|
|
|
|
#endif
|
|
|
|
i--;
|
|
|
|
if (i < 0) //Time-out! Very slow if this happens... but at least it still works :P
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(zbit);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Re-generate shp[].x/y (box sizes) from shcnt (now head indices) for next pass :/
|
2006-04-13 20:47:06 +00:00
|
|
|
j = 0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (y=gmaxy; y; y--)
|
|
|
|
for (x=gmaxx; x>=y; x--)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
i = shcnt[y*shcntp+x];
|
2009-02-19 16:47:54 +00:00
|
|
|
for (; j<i; j++) { shp[j].x = x0; shp[j].y = y0; }
|
2006-04-13 20:47:06 +00:00
|
|
|
x0 = x; y0 = y;
|
|
|
|
}
|
2009-02-19 16:47:54 +00:00
|
|
|
for (; j<sc; j++) { shp[j].x = x0; shp[j].y = y0; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
goto skindidntfit;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
while (!isrectfree(x0,y0,dx,dy));
|
2006-04-13 20:47:06 +00:00
|
|
|
while ((y0) && (isrectfree(x0,y0-1,dx,1))) y0--;
|
|
|
|
while ((x0) && (isrectfree(x0-1,y0,1,dy))) x0--;
|
|
|
|
setrect(x0,y0,dx,dy);
|
|
|
|
shp[z].x = x0; shp[z].y = y0; //Overwrite size with top-left location
|
|
|
|
}
|
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
gvox->quad = (voxrect_t *)Bmalloc(gvox->qcnt*sizeof(voxrect_t));
|
2010-05-18 00:30:30 +00:00
|
|
|
if (!gvox->quad) { Bfree(zbit); Bfree(shp); Bfree(bx0); Bfree(gvox); return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
gvox->mytex = (int32_t *)Bmalloc(gvox->mytexx*gvox->mytexy*sizeof(int32_t));
|
2010-05-18 00:30:30 +00:00
|
|
|
if (!gvox->mytex) { Bfree(gvox->quad); Bfree(zbit); Bfree(shp); Bfree(bx0); Bfree(gvox); return(0); }
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(shp); Bfree(zbit); Bfree(bx0);
|
2006-04-13 20:47:06 +00:00
|
|
|
return(gvox);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t loadvox(const char *filnam)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, k, x, y, z, pal[256], fil;
|
|
|
|
char c[3], *tbuf;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
fil = kopen4load((char *)filnam,0); if (fil < 0) return(-1);
|
|
|
|
kread(fil,&xsiz,4); xsiz = B_LITTLE32(xsiz);
|
|
|
|
kread(fil,&ysiz,4); ysiz = B_LITTLE32(ysiz);
|
|
|
|
kread(fil,&zsiz,4); zsiz = B_LITTLE32(zsiz);
|
|
|
|
xpiv = ((float)xsiz)*.5;
|
|
|
|
ypiv = ((float)ysiz)*.5;
|
|
|
|
zpiv = ((float)zsiz)*.5;
|
|
|
|
|
|
|
|
klseek(fil,-768,SEEK_END);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<256; i++)
|
2009-01-09 09:29:17 +00:00
|
|
|
{ kread(fil,c,3); pal[i] = (((int32_t)c[0])<<18)+(((int32_t)c[1])<<10)+(((int32_t)c[2])<<2)+(i<<24); }
|
2006-04-13 20:47:06 +00:00
|
|
|
pal[255] = -1;
|
|
|
|
|
|
|
|
vcolhashsizm1 = 8192-1;
|
2010-05-20 06:05:46 +00:00
|
|
|
vcolhashead = (int32_t *)Bmalloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { kclose(fil); return(-1); }
|
2009-01-09 09:29:17 +00:00
|
|
|
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
|
2010-05-20 06:05:46 +00:00
|
|
|
vbit = (int32_t *)Bmalloc(i); if (!vbit) { kclose(fil); return(-1); }
|
2006-04-13 20:47:06 +00:00
|
|
|
memset(vbit,0,i);
|
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
tbuf = (char *)Bmalloc(zsiz*sizeof(uint8_t)); if (!tbuf) { kclose(fil); return(-1); }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
klseek(fil,12,SEEK_SET);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (x=0; x<xsiz; x++)
|
|
|
|
for (y=0,j=x*yzsiz; y<ysiz; y++,j+=zsiz)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
kread(fil,tbuf,zsiz);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (z=zsiz-1; z>=0; z--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{ if (tbuf[z] != 255) { i = j+z; vbit[i>>5] |= (1<<SHIFTMOD32(i)); } }
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
klseek(fil,12,SEEK_SET);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (x=0; x<xsiz; x++)
|
|
|
|
for (y=0,j=x*yzsiz; y<ysiz; y++,j+=zsiz)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
kread(fil,tbuf,zsiz);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (z=0; z<zsiz; z++)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
if (tbuf[z] == 255) continue;
|
|
|
|
if ((!x) || (!y) || (!z) || (x == xsiz-1) || (y == ysiz-1) || (z == zsiz-1))
|
2007-12-12 17:42:14 +00:00
|
|
|
{ putvox(x,y,z,pal[tbuf[z]]); continue; }
|
2006-04-24 19:04:22 +00:00
|
|
|
k = j+z;
|
|
|
|
if ((!(vbit[(k-yzsiz)>>5]&(1<<SHIFTMOD32(k-yzsiz)))) ||
|
|
|
|
(!(vbit[(k+yzsiz)>>5]&(1<<SHIFTMOD32(k+yzsiz)))) ||
|
|
|
|
(!(vbit[(k- zsiz)>>5]&(1<<SHIFTMOD32(k- zsiz)))) ||
|
|
|
|
(!(vbit[(k+ zsiz)>>5]&(1<<SHIFTMOD32(k+ zsiz)))) ||
|
|
|
|
(!(vbit[(k- 1)>>5]&(1<<SHIFTMOD32(k- 1)))) ||
|
|
|
|
(!(vbit[(k+ 1)>>5]&(1<<SHIFTMOD32(k+ 1)))))
|
2007-12-12 17:42:14 +00:00
|
|
|
{ putvox(x,y,z,pal[tbuf[z]]); continue; }
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(tbuf); kclose(fil); return(0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t loadkvx(const char *filnam)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, k, x, y, z, pal[256], z0, z1, mip1leng, ysizp1, fil;
|
|
|
|
uint16_t *xyoffs;
|
|
|
|
char c[3], *tbuf, *cptr;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
fil = kopen4load((char *)filnam,0); if (fil < 0) return(-1);
|
|
|
|
kread(fil,&mip1leng,4); mip1leng = B_LITTLE32(mip1leng);
|
|
|
|
kread(fil,&xsiz,4); xsiz = B_LITTLE32(xsiz);
|
|
|
|
kread(fil,&ysiz,4); ysiz = B_LITTLE32(ysiz);
|
|
|
|
kread(fil,&zsiz,4); zsiz = B_LITTLE32(zsiz);
|
|
|
|
kread(fil,&i,4); xpiv = ((float)B_LITTLE32(i))/256.0;
|
|
|
|
kread(fil,&i,4); ypiv = ((float)B_LITTLE32(i))/256.0;
|
|
|
|
kread(fil,&i,4); zpiv = ((float)B_LITTLE32(i))/256.0;
|
|
|
|
klseek(fil,(xsiz+1)<<2,SEEK_CUR);
|
|
|
|
ysizp1 = ysiz+1;
|
2009-01-09 09:29:17 +00:00
|
|
|
i = xsiz*ysizp1*sizeof(int16_t);
|
2010-05-20 06:05:46 +00:00
|
|
|
xyoffs = (uint16_t *)Bmalloc(i); if (!xyoffs) { kclose(fil); return(-1); }
|
2009-01-09 09:29:17 +00:00
|
|
|
kread(fil,xyoffs,i); for (i=i/sizeof(int16_t)-1; i>=0; i--) xyoffs[i] = B_LITTLE16(xyoffs[i]);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
klseek(fil,-768,SEEK_END);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<256; i++)
|
2009-01-09 09:29:17 +00:00
|
|
|
{ kread(fil,c,3); pal[i] = B_LITTLE32((((int32_t)c[0])<<18)+(((int32_t)c[1])<<10)+(((int32_t)c[2])<<2)+(i<<24)); }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
|
2010-05-20 06:05:46 +00:00
|
|
|
vbit = (int32_t *)Bmalloc(i); if (!vbit) { Bfree(xyoffs); kclose(fil); return(-1); }
|
2006-04-13 20:47:06 +00:00
|
|
|
memset(vbit,0,i);
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (vcolhashsizm1=4096; vcolhashsizm1<(mip1leng>>1); vcolhashsizm1<<=1); vcolhashsizm1--; //approx to numvoxs!
|
2010-05-20 06:05:46 +00:00
|
|
|
vcolhashead = (int32_t *)Bmalloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { Bfree(xyoffs); kclose(fil); return(-1); }
|
2009-01-09 09:29:17 +00:00
|
|
|
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
klseek(fil,28+((xsiz+1)<<2)+((ysizp1*xsiz)<<1),SEEK_SET);
|
|
|
|
|
|
|
|
i = kfilelength(fil)-ktell(fil);
|
2010-05-20 06:05:46 +00:00
|
|
|
tbuf = (char *)Bmalloc(i); if (!tbuf) { Bfree(xyoffs); kclose(fil); return(-1); }
|
2006-04-13 20:47:06 +00:00
|
|
|
kread(fil,tbuf,i); kclose(fil);
|
|
|
|
|
|
|
|
cptr = tbuf;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (x=0; x<xsiz; x++) //Set surface voxels to 1 else 0
|
|
|
|
for (y=0,j=x*yzsiz; y<ysiz; y++,j+=zsiz)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
i = xyoffs[x*ysizp1+y+1] - xyoffs[x*ysizp1+y]; if (!i) continue;
|
|
|
|
z1 = 0;
|
|
|
|
while (i)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
z0 = (int32_t)cptr[0]; k = (int32_t)cptr[1]; cptr += 3;
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!(cptr[-1]&16)) setzrange1(vbit,j+z1,j+z0);
|
|
|
|
i -= k+3; z1 = z0+k;
|
|
|
|
setzrange1(vbit,j+z0,j+z1);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (z=z0; z<z1; z++) putvox(x,y,z,pal[*cptr++]);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(tbuf); Bfree(xyoffs); return(0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t loadkv6(const char *filnam)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, x, y, numvoxs, z0, z1, fil;
|
|
|
|
uint16_t *ylen;
|
|
|
|
char c[8];
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
fil = kopen4load((char *)filnam,0); if (fil < 0) return(-1);
|
2007-12-12 17:42:14 +00:00
|
|
|
kread(fil,&i,4); if (B_LITTLE32(i) != 0x6c78764b) { kclose(fil); return(-1); } //Kvxl
|
2006-04-13 20:47:06 +00:00
|
|
|
kread(fil,&xsiz,4); xsiz = B_LITTLE32(xsiz);
|
|
|
|
kread(fil,&ysiz,4); ysiz = B_LITTLE32(ysiz);
|
|
|
|
kread(fil,&zsiz,4); zsiz = B_LITTLE32(zsiz);
|
2006-07-01 01:40:18 +00:00
|
|
|
kread(fil,&i,4); xpiv = (float)(B_LITTLE32(i));
|
|
|
|
kread(fil,&i,4); ypiv = (float)(B_LITTLE32(i));
|
|
|
|
kread(fil,&i,4); zpiv = (float)(B_LITTLE32(i));
|
2006-04-13 20:47:06 +00:00
|
|
|
kread(fil,&numvoxs,4); numvoxs = B_LITTLE32(numvoxs);
|
|
|
|
|
2010-05-20 06:05:46 +00:00
|
|
|
ylen = (uint16_t *)Bmalloc(xsiz*ysiz*sizeof(int16_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!ylen) { kclose(fil); return(-1); }
|
|
|
|
|
|
|
|
klseek(fil,32+(numvoxs<<3)+(xsiz<<2),SEEK_SET);
|
2009-01-09 09:29:17 +00:00
|
|
|
kread(fil,ylen,xsiz*ysiz*sizeof(int16_t)); for (i=xsiz*ysiz-1; i>=0; i--) ylen[i] = B_LITTLE16(ylen[i]);
|
2006-04-13 20:47:06 +00:00
|
|
|
klseek(fil,32,SEEK_SET);
|
|
|
|
|
|
|
|
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
|
2010-05-20 06:05:46 +00:00
|
|
|
vbit = (int32_t *)Bmalloc(i); if (!vbit) { Bfree(ylen); kclose(fil); return(-1); }
|
2006-04-13 20:47:06 +00:00
|
|
|
memset(vbit,0,i);
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (vcolhashsizm1=4096; vcolhashsizm1<numvoxs; vcolhashsizm1<<=1); vcolhashsizm1--;
|
2010-05-20 06:05:46 +00:00
|
|
|
vcolhashead = (int32_t *)Bmalloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { Bfree(ylen); kclose(fil); return(-1); }
|
2009-01-09 09:29:17 +00:00
|
|
|
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (x=0; x<xsiz; x++)
|
|
|
|
for (y=0,j=x*yzsiz; y<ysiz; y++,j+=zsiz)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
z1 = zsiz;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=ylen[x*ysiz+y]; i>0; i--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
kread(fil,c,8); //b,g,r,a,z_lo,z_hi,vis,dir
|
2009-01-09 09:29:17 +00:00
|
|
|
z0 = B_LITTLE16(*(uint16_t *)&c[4]);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!(c[6]&16)) setzrange1(vbit,j+z1,j+z0);
|
|
|
|
vbit[(j+z0)>>5] |= (1<<SHIFTMOD32(j+z0));
|
2009-01-09 09:29:17 +00:00
|
|
|
putvox(x,y,z0,B_LITTLE32(*(int32_t *)&c[0])&0xffffff);
|
2006-04-24 19:04:22 +00:00
|
|
|
z1 = z0+1;
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(ylen); kclose(fil); return(0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2006-04-24 19:04:22 +00:00
|
|
|
//While this code works, it's way too slow and can only cause trouble.
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t loadvxl(const char *filnam)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, x, y, z, fil;
|
|
|
|
char *v, *vbuf;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
fil = kopen4load((char *)filnam,0); if (fil < 0) return(-1);
|
|
|
|
kread(fil,&i,4);
|
|
|
|
kread(fil,&xsiz,4);
|
|
|
|
kread(fil,&ysiz,4);
|
2007-12-12 17:42:14 +00:00
|
|
|
if ((i != 0x09072000) || (xsiz != 1024) || (ysiz != 1024)) { kclose(fil); return(-1); }
|
2006-04-13 20:47:06 +00:00
|
|
|
zsiz = 256;
|
|
|
|
klseek(fil,96,SEEK_CUR); //skip pos&orient
|
|
|
|
xpiv = ((float)xsiz)*.5;
|
|
|
|
ypiv = ((float)ysiz)*.5;
|
|
|
|
zpiv = ((float)zsiz)*.5;
|
|
|
|
|
|
|
|
yzsiz = ysiz*zsiz; i = ((xsiz*yzsiz+31)>>3);
|
2010-05-20 06:05:46 +00:00
|
|
|
vbit = (int32_t *)Bmalloc(i); if (!vbit) { kclose(fil); return(-1); }
|
2006-04-13 20:47:06 +00:00
|
|
|
memset(vbit,-1,i);
|
|
|
|
|
|
|
|
vcolhashsizm1 = 1048576-1;
|
2010-05-20 06:05:46 +00:00
|
|
|
vcolhashead = (int32_t *)Bmalloc((vcolhashsizm1+1)*sizeof(int32_t)); if (!vcolhashead) { kclose(fil); return(-1); }
|
2009-01-09 09:29:17 +00:00
|
|
|
memset(vcolhashead,-1,(vcolhashsizm1+1)*sizeof(int32_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Allocate huge buffer and load rest of file into it...
|
2006-04-13 20:47:06 +00:00
|
|
|
i = kfilelength(fil)-ktell(fil);
|
2010-05-20 06:05:46 +00:00
|
|
|
vbuf = (char *)Bmalloc(i); if (!vbuf) { kclose(fil); return(-1); }
|
2006-04-13 20:47:06 +00:00
|
|
|
kread(fil,vbuf,i);
|
|
|
|
kclose(fil);
|
|
|
|
|
|
|
|
v = vbuf;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (y=0; y<ysiz; y++)
|
|
|
|
for (x=0,j=y*zsiz; x<xsiz; x++,j+=yzsiz)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
z = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
setzrange0(vbit,j+z,j+v[1]);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (z=v[1]; z<=v[2]; z++) putvox(x,y,z,(*(int32_t *)&v[(z-v[1]+1)<<2])&0xffffff);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!v[0]) break; z = v[2]-v[1]-v[0]+2; v += v[0]*4;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (z+=v[3]; z<v[3]; z++) putvox(x,y,z,(*(int32_t *)&v[(z-v[3])<<2])&0xffffff);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2009-01-09 09:29:17 +00:00
|
|
|
v += ((((int32_t)v[2])-((int32_t)v[1])+2)<<2);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2010-05-18 00:30:30 +00:00
|
|
|
Bfree(vbuf); return(0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
void voxfree(voxmodel_t *m)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
if (!m) return;
|
2010-05-18 00:30:30 +00:00
|
|
|
if (m->mytex) Bfree(m->mytex);
|
|
|
|
if (m->quad) Bfree(m->quad);
|
|
|
|
if (m->texid) Bfree(m->texid);
|
|
|
|
Bfree(m);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
voxmodel_t *voxload(const char *filnam)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, is8bit, ret;
|
2009-01-10 07:38:50 +00:00
|
|
|
voxmodel_t *vm;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
i = strlen(filnam)-4; if (i < 0) return(0);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!Bstrcasecmp(&filnam[i],".vox")) { ret = loadvox(filnam); is8bit = 1; }
|
2006-04-13 20:47:06 +00:00
|
|
|
else if (!Bstrcasecmp(&filnam[i],".kvx")) { ret = loadkvx(filnam); is8bit = 1; }
|
|
|
|
else if (!Bstrcasecmp(&filnam[i],".kv6")) { ret = loadkv6(filnam); is8bit = 0; }
|
2006-04-24 19:04:22 +00:00
|
|
|
//else if (!Bstrcasecmp(&filnam[i],".vxl")) { ret = loadvxl(filnam); is8bit = 0; }
|
2006-04-13 20:47:06 +00:00
|
|
|
else return(0);
|
|
|
|
if (ret >= 0) vm = vox2poly(); else vm = 0;
|
|
|
|
if (vm)
|
|
|
|
{
|
|
|
|
vm->mdnum = 1; //VOXel model id
|
|
|
|
vm->scale = vm->bscale = 1.0;
|
|
|
|
vm->xsiz = xsiz; vm->ysiz = ysiz; vm->zsiz = zsiz;
|
|
|
|
vm->xpiv = xpiv; vm->ypiv = ypiv; vm->zpiv = zpiv;
|
|
|
|
vm->is8bit = is8bit;
|
|
|
|
|
2010-05-18 00:30:30 +00:00
|
|
|
vm->texid = (uint32_t *)Bcalloc(MAXPALOOKUPS,sizeof(uint32_t));
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!vm->texid) { voxfree(vm); vm = 0; }
|
|
|
|
}
|
2010-05-18 00:30:30 +00:00
|
|
|
if (shcntmal) { Bfree(shcntmal); shcntmal = 0; }
|
|
|
|
if (vbit) { Bfree(vbit); vbit = 0; }
|
|
|
|
if (vcol) { Bfree(vcol); vcol = 0; vnum = 0; vmax = 0; }
|
|
|
|
if (vcolhashead) { Bfree(vcolhashead); vcolhashead = 0; }
|
2006-04-13 20:47:06 +00:00
|
|
|
return(vm);
|
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Draw voxel model as perfect cubes
|
2009-01-10 07:38:50 +00:00
|
|
|
int32_t voxdraw(voxmodel_t *m, spritetype *tspr)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
point3d fp, m0, a0;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j, fi, xx, yy, zz;
|
2008-03-22 10:23:57 +00:00
|
|
|
float ru, rv, phack[2], clut[6] = {1,1,1,1,1,1}; //1.02,1.02,0.94,1.06,0.98,0.98};
|
2006-04-13 20:47:06 +00:00
|
|
|
float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16], omat[16], pc[4];
|
|
|
|
vert_t *vptr;
|
|
|
|
|
2008-06-10 19:23:13 +00:00
|
|
|
if ((intptr_t)m == (intptr_t)(-1)) // hackhackhack
|
2006-04-13 20:47:06 +00:00
|
|
|
return 0;
|
|
|
|
if ((tspr->cstat&48)==32) return 0;
|
|
|
|
|
|
|
|
//updateanimation((md2model *)m,tspr);
|
|
|
|
|
|
|
|
m0.x = m->scale;
|
|
|
|
m0.y = m->scale;
|
|
|
|
m0.z = m->scale;
|
2007-12-20 19:14:38 +00:00
|
|
|
a0.x = a0.y = 0; a0.z = ((globalorientation&8)?-m->zadd:m->zadd)*m->scale;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//if (globalorientation&8) //y-flipping
|
|
|
|
//{
|
|
|
|
// m0.z = -m0.z; a0.z = -a0.z;
|
|
|
|
// //Add height of 1st frame (use same frame to prevent animation bounce)
|
|
|
|
// a0.z += m->zsiz*m->scale;
|
|
|
|
//}
|
|
|
|
//if (globalorientation&4) { m0.y = -m0.y; a0.y = -a0.y; } //x-flipping
|
|
|
|
|
|
|
|
f = ((float)tspr->xrepeat)*(256.0/320.0)/64.0*m->bscale;
|
2011-06-18 13:02:08 +00:00
|
|
|
if ((sprite[tspr->owner].cstat&48)==16)
|
|
|
|
f *= 1.25f;
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
m0.x *= f; a0.x *= f; f = -f;
|
|
|
|
m0.y *= f; a0.y *= f;
|
|
|
|
f = ((float)tspr->yrepeat)/64.0*m->bscale;
|
|
|
|
m0.z *= f; a0.z *= f;
|
|
|
|
|
2009-07-09 02:29:48 +00:00
|
|
|
k0 = (float)tspr->z;
|
2006-04-13 20:47:06 +00:00
|
|
|
if (globalorientation&128) k0 += (float)((tilesizy[tspr->picnum]*tspr->yrepeat)<<1);
|
|
|
|
|
|
|
|
f = (65536.0*512.0)/((float)xdimen*viewingrange);
|
|
|
|
g = 32.0/((float)xdimen*gxyaspect);
|
|
|
|
m0.y *= f; a0.y = (((float)(tspr->x-globalposx))/ 1024.0 + a0.y)*f;
|
|
|
|
m0.x *=-f; a0.x = (((float)(tspr->y-globalposy))/ -1024.0 + a0.x)*-f;
|
|
|
|
m0.z *= g; a0.z = (((float)(k0 -globalposz))/-16384.0 + a0.z)*g;
|
|
|
|
|
|
|
|
k0 = ((float)(tspr->x-globalposx))*f/1024.0;
|
|
|
|
k1 = ((float)(tspr->y-globalposy))*f/1024.0;
|
|
|
|
f = gcosang2*gshang;
|
|
|
|
g = gsinang2*gshang;
|
|
|
|
k4 = (float)sintable[(tspr->ang+spriteext[tspr->owner].angoff+1024)&2047] / 16384.0;
|
|
|
|
k5 = (float)sintable[(tspr->ang+spriteext[tspr->owner].angoff+ 512)&2047] / 16384.0;
|
|
|
|
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;
|
|
|
|
|
|
|
|
mat[12] += a0.y*mat[0] + a0.z*mat[4] + a0.x*mat[ 8];
|
|
|
|
mat[13] += a0.y*mat[1] + a0.z*mat[5] + a0.x*mat[ 9];
|
|
|
|
mat[14] += a0.y*mat[2] + a0.z*mat[6] + a0.x*mat[10];
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Mirrors
|
2007-12-12 17:42:14 +00:00
|
|
|
if (grhalfxdown10x < 0) { mat[0] = -mat[0]; mat[4] = -mat[4]; mat[8] = -mat[8]; mat[12] = -mat[12]; }
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//------------
|
2006-04-13 20:47:06 +00:00
|
|
|
//bit 10 is an ugly hack in game.c\animatesprites telling MD2SPRITE
|
|
|
|
//to use Z-buffer hacks to hide overdraw problems with the shadows
|
|
|
|
if (tspr->cstat&1024)
|
|
|
|
{
|
|
|
|
bglDepthFunc(GL_LESS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS
|
|
|
|
bglDepthRange(0.0,0.9999);
|
|
|
|
}
|
|
|
|
bglPushAttrib(GL_POLYGON_BIT);
|
|
|
|
if ((grhalfxdown10x >= 0) /*^ ((globalorientation&8) != 0) ^ ((globalorientation&4) != 0)*/) bglFrontFace(GL_CW); else bglFrontFace(GL_CCW);
|
|
|
|
bglEnable(GL_CULL_FACE);
|
|
|
|
bglCullFace(GL_BACK);
|
|
|
|
|
|
|
|
bglEnable(GL_TEXTURE_2D);
|
|
|
|
|
2006-12-04 04:08:14 +00:00
|
|
|
pc[0] = pc[1] = pc[2] = ((float)(numpalookups-min(max((globalshade * shadescale)+m->shadeoff,0),numpalookups)))/((float)numpalookups);
|
2006-04-13 20:47:06 +00:00
|
|
|
pc[0] *= (float)hictinting[globalpal].r / 255.0;
|
|
|
|
pc[1] *= (float)hictinting[globalpal].g / 255.0;
|
|
|
|
pc[2] *= (float)hictinting[globalpal].b / 255.0;
|
2009-07-09 02:29:48 +00:00
|
|
|
if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66f; else pc[3] = 0.33f; }
|
2007-12-12 17:42:14 +00:00
|
|
|
else pc[3] = 1.0;
|
2010-05-25 10:56:00 +00:00
|
|
|
if (tspr->cstat&2) bglEnable(GL_BLEND); //else bglDisable(GL_BLEND);
|
2006-04-24 19:04:22 +00:00
|
|
|
//------------
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//transform to Build coords
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(omat,mat,sizeof(omat));
|
2006-04-13 20:47:06 +00:00
|
|
|
f = 1.f/64.f;
|
|
|
|
g = m0.x*f; mat[0] *= g; mat[1] *= g; mat[2] *= g;
|
|
|
|
g = m0.y*f; mat[4] = omat[8]*g; mat[5] = omat[9]*g; mat[6] = omat[10]*g;
|
|
|
|
g =-m0.z*f; mat[8] = omat[4]*g; mat[9] = omat[5]*g; mat[10] = omat[6]*g;
|
|
|
|
mat[12] -= (m->xpiv*mat[0] + m->ypiv*mat[4] + (m->zpiv+m->zsiz*.5)*mat[ 8]);
|
|
|
|
mat[13] -= (m->xpiv*mat[1] + m->ypiv*mat[5] + (m->zpiv+m->zsiz*.5)*mat[ 9]);
|
|
|
|
mat[14] -= (m->xpiv*mat[2] + m->ypiv*mat[6] + (m->zpiv+m->zsiz*.5)*mat[10]);
|
|
|
|
bglMatrixMode(GL_MODELVIEW); //Let OpenGL (and perhaps hardware :) handle the matrix rotation
|
|
|
|
mat[3] = mat[7] = mat[11] = 0.f; mat[15] = 1.f;
|
|
|
|
|
|
|
|
bglLoadMatrixf(mat);
|
|
|
|
|
|
|
|
ru = 1.f/((float)m->mytexx);
|
|
|
|
rv = 1.f/((float)m->mytexy);
|
|
|
|
#if (VOXBORDWIDTH == 0)
|
|
|
|
uhack[0] = ru*.125; uhack[1] = -uhack[0];
|
|
|
|
vhack[0] = rv*.125; vhack[1] = -vhack[0];
|
|
|
|
#endif
|
|
|
|
phack[0] = 0; phack[1] = 1.f/256.f;
|
|
|
|
|
|
|
|
if (!m->texid[globalpal]) m->texid[globalpal] = gloadtex(m->mytex,m->mytexx,m->mytexy,m->is8bit,globalpal);
|
2006-04-24 19:04:22 +00:00
|
|
|
else bglBindTexture(GL_TEXTURE_2D,m->texid[globalpal]);
|
2006-04-13 20:47:06 +00:00
|
|
|
bglBegin(GL_QUADS);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0,fi=0; i<m->qcnt; i++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
if (i == m->qfacind[fi]) { f = clut[fi++]; bglColor4f(pc[0]*f,pc[1]*f,pc[2]*f,pc[3]*f); }
|
|
|
|
vptr = &m->quad[i].v[0];
|
|
|
|
|
|
|
|
xx = vptr[0].x+vptr[2].x;
|
|
|
|
yy = vptr[0].y+vptr[2].y;
|
|
|
|
zz = vptr[0].z+vptr[2].z;
|
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (j=0; j<4; j++)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
|
|
|
#if (VOXBORDWIDTH == 0)
|
|
|
|
bglTexCoord2f(((float)vptr[j].u)*ru+uhack[vptr[j].u!=vptr[0].u],
|
2006-04-24 19:04:22 +00:00
|
|
|
((float)vptr[j].v)*rv+vhack[vptr[j].v!=vptr[0].v]);
|
2006-04-13 20:47:06 +00:00
|
|
|
#else
|
|
|
|
bglTexCoord2f(((float)vptr[j].u)*ru,((float)vptr[j].v)*rv);
|
|
|
|
#endif
|
|
|
|
fp.x = ((float)vptr[j].x) - phack[xx>vptr[j].x*2] + phack[xx<vptr[j].x*2];
|
|
|
|
fp.y = ((float)vptr[j].y) - phack[yy>vptr[j].y*2] + phack[yy<vptr[j].y*2];
|
|
|
|
fp.z = ((float)vptr[j].z) - phack[zz>vptr[j].z*2] + phack[zz<vptr[j].z*2];
|
|
|
|
bglVertex3fv((float *)&fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bglEnd();
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//------------
|
2006-04-13 20:47:06 +00:00
|
|
|
bglDisable(GL_CULL_FACE);
|
|
|
|
bglPopAttrib();
|
|
|
|
if (tspr->cstat&1024)
|
|
|
|
{
|
2007-01-06 01:29:45 +00:00
|
|
|
bglDepthFunc(GL_LESS); //NEVER,LESS,(,L)EQUAL,GREATER,(NOT,G)EQUAL,ALWAYS
|
2006-04-13 20:47:06 +00:00
|
|
|
bglDepthRange(0.0,0.99999);
|
|
|
|
}
|
|
|
|
bglLoadIdentity();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------- VOX 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
|
|
|
|
2011-01-16 02:50:27 +00:00
|
|
|
vm = (mdmodel_t *)voxload(filnam); if (vm) return(vm);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
fil = kopen4load((char *)filnam,0); if (fil < 0) return(0);
|
|
|
|
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
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
case 0x32504449:
|
2006-12-05 20:39:29 +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
|
2006-11-13 23:12:47 +00:00
|
|
|
case 0x33504449:
|
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:
|
2011-01-16 02:50:27 +00:00
|
|
|
vm = (mdmodel_t *)0; break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
kclose(fil);
|
2010-12-24 15:44:37 +00:00
|
|
|
|
|
|
|
if (vm)
|
|
|
|
{
|
2011-01-16 02:50:27 +00:00
|
|
|
md3postload_common((md3model_t *)vm);
|
2010-12-24 15:44:37 +00:00
|
|
|
#ifdef POLYMER
|
|
|
|
// implies defined(POLYMOST) && defined(USE_OPENGL)?
|
|
|
|
if (glrendmode==4)
|
2011-01-16 02:50:27 +00:00
|
|
|
i = md3postload_polymer((md3model_t *)vm);
|
2010-12-24 15:44:37 +00:00
|
|
|
else
|
2011-01-16 02:50:27 +00:00
|
|
|
i = md3postload_polymer_check((md3model_t *)vm);
|
2010-12-24 15:44:37 +00:00
|
|
|
|
|
|
|
if (!i)
|
|
|
|
{
|
|
|
|
mdfree(vm);
|
2011-01-16 02:50:27 +00:00
|
|
|
vm = (mdmodel_t *)0;
|
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
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return(vm);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t mddraw(spritetype *tspr)
|
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 i;
|
2007-03-08 03:07:10 +00:00
|
|
|
|
|
|
|
if (r_vbos && (r_vbocount > allocvbos))
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
indexvbos = Brealloc(indexvbos, sizeof(GLuint) * r_vbocount);
|
|
|
|
vertvbos = Brealloc(vertvbos, sizeof(GLuint) * r_vbocount);
|
2007-03-08 03:07:10 +00:00
|
|
|
|
|
|
|
bglGenBuffersARB(r_vbocount - allocvbos, &(indexvbos[allocvbos]));
|
|
|
|
bglGenBuffersARB(r_vbocount - allocvbos, &(vertvbos[allocvbos]));
|
|
|
|
|
|
|
|
i = allocvbos;
|
|
|
|
while (i < r_vbocount)
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexvbos[i]);
|
2009-01-09 09:29:17 +00:00
|
|
|
bglBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, maxmodeltris * 3 * sizeof(uint16_t), NULL, GL_STREAM_DRAW_ARB);
|
2007-03-08 03:07:10 +00:00
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, vertvbos[i]);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, maxmodelverts * sizeof(point3d), NULL, GL_STREAM_DRAW_ARB);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
|
|
|
|
allocvbos = r_vbocount;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
if (maxmodelverts > allocmodelverts)
|
|
|
|
{
|
2010-05-18 00:30:30 +00:00
|
|
|
point3d *vl = (point3d *)Brealloc(vertlist,sizeof(point3d)*maxmodelverts);
|
2006-04-13 20:47:06 +00:00
|
|
|
if (!vl) { OSD_Printf("ERROR: Not enough memory to allocate %d vertices!\n",maxmodelverts); return 0; }
|
2007-03-08 03:07:10 +00:00
|
|
|
vertlist = vl;
|
|
|
|
allocmodelverts = maxmodelverts;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-05-27 15:47:24 +00:00
|
|
|
vm = models[tile2model[Ptile2tile(tspr->picnum,(tspr->owner >= MAXSPRITES) ? tspr->pal : sprite[tspr->owner].pal)].modelid];
|
2009-01-10 07:38:50 +00:00
|
|
|
if (vm->mdnum == 1) { return voxdraw((voxmodel_t *)vm,tspr); }
|
|
|
|
if (vm->mdnum == 3) { return md3draw((md3model_t *)vm,tspr); }
|
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 ----------------------------------------
|