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_tilehasmodel(int tilenume);
int md_defineframe(int modelid, const char *framename, int tilenume, int skinnum); 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_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_definehud (int modelid, int tilex, double xadd, double yadd, double zadd, double angadd, int flags);
int md_undefinetile(int tile); int md_undefinetile(int tile);
int md_undefinemodel(int modelid); int md_undefinemodel(int modelid);

View file

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

View file

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

View file

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