Various fixes and detail texturing on models.

git-svn-id: https://svn.eduke32.com/eduke32@501 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
Plagman 2007-02-16 01:34:41 +00:00
parent d3af85c064
commit b436f4fb71
4 changed files with 55 additions and 102 deletions

View file

@ -513,7 +513,7 @@ int md_setmisc(int modelid, float scale, int shadeoff, float zadd);
int md_tilehasmodel(int tilenume);
int md_defineframe(int modelid, const char *framename, int tilenume, int skinnum);
int md_defineanimation(int modelid, const char *framestart, const char *frameend, int fps, int flags);
int md_defineskin(int modelid, const char *skinfn, int palnum, int skinnum, int surfnum);
int md_defineskin(int modelid, const char *skinfn, int palnum, int skinnum, int surfnum, float param);
int md_definehud (int modelid, int tilex, double xadd, double yadd, double zadd, double angadd, int flags);
int md_undefinetile(int tile);
int md_undefinemodel(int modelid);

View file

@ -44,6 +44,7 @@ enum {
T_PAL,
T_DETAIL,
T_GLOW,
T_PARAM,
T_HUD,
T_XADD,
T_YADD,
@ -121,6 +122,7 @@ static tokenlist modeltokens[] = {
{ "anim", T_ANIM },
{ "skin", T_SKIN },
{ "glow", T_GLOW },
{ "detail", T_DETAIL },
{ "hud", T_HUD },
};
@ -140,10 +142,13 @@ static tokenlist modelanimtokens[] = {
};
static tokenlist modelskintokens[] = {
{ "pal", T_PAL },
{ "file", T_FILE },
{ "surf", T_SURF },
{ "surface",T_SURF },
{ "pal", T_PAL },
{ "file", T_FILE },
{ "surf", T_SURF },
{ "surface", T_SURF },
{ "intensity", T_PARAM },
{ "scale", T_PARAM },
{ "detailscale", T_PARAM },
};
static tokenlist modelhudtokens[] = {
@ -609,7 +614,7 @@ static int defsparser(scriptfile *script)
seenframe = 0;
#if defined(POLYMOST) && defined(USE_OPENGL)
switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), 0)) {
switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), 0, 0.0f)) {
case 0:
break;
case -1:
@ -709,7 +714,8 @@ static int defsparser(scriptfile *script)
#endif
if (scriptfile_getbraces(script,&modelend)) break;
while (script->textptr < modelend) {
switch (getatoken(script,modeltokens,sizeof(modeltokens)/sizeof(tokenlist))) {
int token = getatoken(script,modeltokens,sizeof(modeltokens)/sizeof(tokenlist));
switch (token) {
//case T_ERROR: initprintf("Error on line %s:%d in model tokens\n", script->filename,script->linenum); break;
case T_SCALE:
scriptfile_getdouble(script,&scale); break;
@ -825,17 +831,20 @@ static int defsparser(scriptfile *script)
}
#endif
} break;
case T_SKIN:
case T_SKIN: case T_DETAIL: case T_GLOW:
{
char *skintokptr = script->ltextptr;
char *skinend, *skinfn = 0;
int palnum = 0, surfnum = 0;
double param = 1.0;
if (scriptfile_getbraces(script,&skinend)) break;
while (script->textptr < skinend) {
switch (getatoken(script,modelskintokens,sizeof(modelskintokens)/sizeof(tokenlist))) {
case T_PAL:
scriptfile_getsymbol(script,&palnum); break;
case T_PARAM:
scriptfile_getdouble(script,&param); break;
case T_FILE:
scriptfile_getstring(script,&skinfn); break; //skin filename
case T_SURF:
@ -851,8 +860,16 @@ static int defsparser(scriptfile *script)
if (seenframe) { modelskin = ++lastmodelskin; }
seenframe = 0;
if (token == T_DETAIL)
{
palnum = DETAILPAL;
param = 1.0f / param;
}
else if (token == T_GLOW)
palnum = GLOWPAL;
#if defined(POLYMOST) && defined(USE_OPENGL)
switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), surfnum)) {
switch (md_defineskin(lastmodelid, skinfn, palnum, max(0,modelskin), surfnum, param)) {
case 0:
break;
case -1:
@ -870,51 +887,6 @@ static int defsparser(scriptfile *script)
script->filename, scriptfile_getlinum(script,skintokptr));
break;
}
#endif
} break;
case T_GLOW:
{
char *glowtokptr = script->ltextptr;
char *glowend, *glowfn = 0;
int surfnum = 0;
if (scriptfile_getbraces(script,&glowend)) break;
while (script->textptr < glowend) {
switch (getatoken(script,modelskintokens,sizeof(modelskintokens)/sizeof(tokenlist))) {
case T_FILE:
scriptfile_getstring(script,&glowfn); break; //skin filename
case T_SURF:
scriptfile_getnumber(script,&surfnum); break;
}
}
if (!glowfn) {
initprintf("Error: missing 'skin filename' for skin definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,glowtokptr));
break;
}
if (seenframe) { modelskin = ++lastmodelskin; }
seenframe = 0;
#if defined(POLYMOST) && defined(USE_OPENGL)
switch (md_defineskin(lastmodelid, glowfn, GLOWPAL, max(0,modelskin), surfnum)) {
case 0:
break;
case -1:
break; // invalid model id!?
case -2:
initprintf("Invalid skin filename on line %s:%d\n",
script->filename, scriptfile_getlinum(script,glowtokptr));
break;
case -3:
initprintf("Invalid palette number on line %s:%d\n",
script->filename, scriptfile_getlinum(script,glowtokptr));
break;
case -4:
initprintf("Out of memory on line %s:%d\n",
script->filename, scriptfile_getlinum(script,glowtokptr));
break;
}
#endif
} break;
case T_HUD:
@ -1127,12 +1099,13 @@ static int defsparser(scriptfile *script)
case T_TEXTURE:
{
char *texturetokptr = script->ltextptr, *textureend;
int tile=-1;
int tile=-1, token;
if (scriptfile_getsymbol(script,&tile)) break;
if (scriptfile_getbraces(script,&textureend)) break;
while (script->textptr < textureend) {
switch (getatoken(script,texturetokens,sizeof(texturetokens)/sizeof(tokenlist))) {
token = getatoken(script,texturetokens,sizeof(texturetokens)/sizeof(tokenlist));
switch (token) {
case T_PAL: {
char *paltokptr = script->ltextptr, *palend;
int pal=-1, i;
@ -1156,7 +1129,7 @@ static int defsparser(scriptfile *script)
}
if ((unsigned)tile > (unsigned)MAXTILES) break; // message is printed later
if ((unsigned)pal > ((unsigned)MAXPALOOKUPS - RESERVEDPALS)) {
if ((unsigned)pal >= ((unsigned)MAXPALOOKUPS - RESERVEDPALS)) {
initprintf("Error: missing or invalid 'palette number' for texture definition near "
"line %s:%d\n", script->filename, scriptfile_getlinum(script,paltokptr));
break;
@ -1173,11 +1146,11 @@ static int defsparser(scriptfile *script)
hicsetsubsttex(tile,pal,fn,alphacut,flags);
} break;
case T_DETAIL: {
case T_DETAIL: case T_GLOW: {
char *detailtokptr = script->ltextptr, *detailend;
int i;
int pal, i;
char *fn = NULL;
double detailscale = 1.0;
double param = 1.0;
char flags = 0;
if (scriptfile_getbraces(script,&detailend)) break;
@ -1186,7 +1159,7 @@ static int defsparser(scriptfile *script)
case T_FILE:
scriptfile_getstring(script,&fn); break;
case T_ALPHACUT:
scriptfile_getdouble(script,&detailscale); break;
scriptfile_getdouble(script,&param); break;
case T_NOCOMPRESS:
flags |= 1; break;
default:
@ -1205,41 +1178,15 @@ static int defsparser(scriptfile *script)
break;
} else kclose(i);
hicsetsubsttex(tile,DETAILPAL,fn,(1.0f / detailscale),flags);
} break;
case T_GLOW: {
char *glowtokptr = script->ltextptr, *glowend;
int i;
char *fn = NULL;
double glowintensity = 1.0;
char flags = 0;
if (scriptfile_getbraces(script,&glowend)) break;
while (script->textptr < glowend) {
switch (getatoken(script,texturetokens_pal,sizeof(texturetokens_pal)/sizeof(tokenlist))) {
case T_FILE:
scriptfile_getstring(script,&fn); break;
case T_ALPHACUT:
scriptfile_getdouble(script,&glowintensity); break;
case T_NOCOMPRESS:
flags |= 1; break;
default:
break;
}
if (token == T_DETAIL)
{
pal = DETAILPAL;
param = 1.0f / param;
}
else if (token == T_GLOW)
pal = GLOWPAL;
if ((unsigned)tile > (unsigned)MAXTILES) break; // message is printed later
if (!fn) {
initprintf("Error: missing 'file name' for texture definition near line %s:%d\n",
script->filename, scriptfile_getlinum(script,glowtokptr));
break;
}
if ((i = kopen4load(fn,0)) < 0) {
initprintf("Error: file '%s' does not exist\n",fn);
break;
} else kclose(i);
hicsetsubsttex(tile,GLOWPAL,fn,glowintensity,flags);
hicsetsubsttex(tile,pal,fn,param,flags);
} break;
default:
break;

View file

@ -30,6 +30,7 @@ typedef struct _mdskinmap_t
char *fn; // Skin filename
GLuint texid[HICEFFECTMASK+1]; // OpenGL texture numbers for effect variations
struct _mdskinmap_t *next;
float param;
} mdskinmap_t;
@ -403,7 +404,7 @@ int md_defineanimation (int modelid, const char *framestart, const char *frameen
return(0);
}
int md_defineskin (int modelid, const char *skinfn, int palnum, int skinnum, int surfnum)
int md_defineskin (int modelid, const char *skinfn, int palnum, int skinnum, int surfnum, float param)
{
mdskinmap_t *sk, *skl;
md2model *m;
@ -432,6 +433,7 @@ int md_defineskin (int modelid, const char *skinfn, int palnum, int skinnum, int
sk->palette = (unsigned char)palnum;
sk->skinnum = skinnum;
sk->surfnum = surfnum;
sk->param = param;
sk->fn = (char *)malloc(strlen(skinfn)+1);
if (!sk->fn) return(-4);
strcpy(sk->fn, skinfn);
@ -1288,11 +1290,12 @@ static int md3draw (md3model *m, spritetype *tspr)
long i, j, k, l, surfi, *lptr;
float f, g, k0, k1, k2, k3, k4, k5, k6, k7, mat[16], pc[4], mult;
md3surf_t *s;
int texunits = GL_TEXTURE0_ARB;
mdskinmap_t *sk;
//PLAG : sorting stuff
unsigned short *indexes;
float *maxdepths;
unsigned short tempus;
int texunits = GL_TEXTURE0_ARB;
// if ((tspr->cstat&48) == 32) return 0;
@ -1503,7 +1506,7 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; }
//i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,surfi); //hack for testing multiple surfaces per MD3
bglBindTexture(GL_TEXTURE_2D, i);
/*if (r_detailmapping && !r_depthpeeling && indrawroomsandmasks)
if (r_detailmapping && !r_depthpeeling && indrawroomsandmasks&& !(tspr->cstat&1024))
i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,DETAILPAL,surfi);
else
i = 0;
@ -1533,16 +1536,17 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; }
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
bglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
f = 0.5f;
for (sk = m->skinmap; sk; sk = sk->next)
if ((int)sk->palette == DETAILPAL && sk->skinnum == tile2model[tspr->picnum].skinnum && sk->surfnum == surfi)
f = sk->param;
bglMatrixMode(GL_TEXTURE);
bglLoadIdentity();
bglScalef(f, f, 1.0f);
bglMatrixMode(GL_MODELVIEW);
}*/
}
if (r_glowmapping && !r_depthpeeling && indrawroomsandmasks)
if (r_glowmapping && !r_depthpeeling && indrawroomsandmasks && !(tspr->cstat&1024))
i = mdloadskin((md2model *)m,tile2model[tspr->picnum].skinnum,GLOWPAL,surfi);
else
i = 0;
@ -1722,6 +1726,7 @@ if (tspr->cstat&2) { if (!(tspr->cstat&512)) pc[3] = 0.66; else pc[3] = 0.33; }
bglMatrixMode(GL_TEXTURE);
bglLoadIdentity();
bglMatrixMode(GL_MODELVIEW);
bglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.0f);
bglDisable(GL_TEXTURE_2D);
bglActiveTextureARB(--texunits);
}

View file

@ -1959,6 +1959,7 @@ void drawpoly (double *dpx, double *dpy, long n, long method)
bglMatrixMode(GL_TEXTURE);
bglLoadIdentity();
bglMatrixMode(GL_MODELVIEW);
bglTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.0f);
bglDisable(GL_TEXTURE_2D);
bglActiveTextureARB(--texunits);
}
@ -5421,7 +5422,7 @@ void polymost_precache(long dapicnum, long dapalnum, long datype)
if (rendmode < 3) return;
if (palookup[dapalnum] == NULL) return;//dapalnum = 0;
if ((palookup[dapalnum] == NULL) && (dapalnum < (MAXPALOOKUPS - RESERVEDPALS))) return;//dapalnum = 0;
//OSD_Printf("precached %d %d type %d\n", dapicnum, dapalnum, datype);
hicprecaching = 1;