Factor out fogcalc() issuing and application of the computed values.

git-svn-id: https://svn.eduke32.com/eduke32@3288 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-12-14 19:28:09 +00:00
parent 92dabb3694
commit 4cc5c431ae
3 changed files with 43 additions and 83 deletions

View file

@ -75,10 +75,7 @@ typedef struct cacheitem_t texcacheindex;
#define TEXCACHEMAGIC "QLZ1"
//extern texcacheindex *firstcacheindex;
//extern texcacheindex *curcacheindex;
extern texcacheindex *cacheptrs[MAXTILES<<1];
//extern int32_t numcacheentries;
int32_t dxtfilter(int32_t fil, const texcachepicture *pict, const char *pic, void *midbuf, char *packbuf, uint32_t miplen);
int32_t dedxtfilter(int32_t fil, const texcachepicture *pict, char *pic, void *midbuf, char *packbuf, int32_t ispacked);
@ -121,13 +118,14 @@ pthtyp *gltexcache(int32_t dapicnum, int32_t dapalnum, int32_t dameth);
extern int32_t globalnoeffect;
extern int32_t drawingskybox;
extern double gyxscale, gxyaspect, /*gviewxrange,*/ ghalfx, grhalfxdown10 /*, ghoriz*/;
extern double gyxscale, gxyaspect, ghalfx, grhalfxdown10;
#define FOGSCALE 0.0000768
extern char nofog; // in windows/SDL layers
extern float fogresult, fogcol[4], fogtable[4*MAXPALOOKUPS];
static inline void fogcalc(const int32_t shade, const int32_t vis, const int32_t pal)
static inline void fogcalc(int32_t shade, int32_t vis, int32_t pal)
{
float f;
@ -154,7 +152,25 @@ static inline void fogcalc(const int32_t shade, const int32_t vis, const int32_t
Bmemcpy(fogcol, &fogtable[pal<<2], sizeof(fogcol));
}
static inline void calc_and_apply_fog(int32_t shade, int32_t vis, int32_t pal)
{
if (!nofog)
{
fogcalc(shade, vis, pal);
bglFogf(GL_FOG_DENSITY, fogresult);
bglFogfv(GL_FOG_COLOR, fogcol);
}
}
static inline void calc_and_apply_fog_factor(int32_t shade, int32_t vis, int32_t pal, float factor)
{
if (!nofog)
{
fogcalc(shade, vis, pal);
bglFogf(GL_FOG_DENSITY, fogresult*factor);
bglFogfv(GL_FOG_COLOR, fogcol);
}
}
#endif
#endif

View file

@ -1311,9 +1311,7 @@ void polymer_drawmaskwall(int32_t damaskwallcnt)
w->mask.material.diffusemodulation[2] = ((GLubyte *)(&maskwall[damaskwallcnt]))[1];
w->mask.material.diffusemodulation[3] = 0xFF;
} else {
fogcalc(wal->shade, sec->visibility, sec->floorpal);
bglFogf(GL_FOG_DENSITY, fogresult);
bglFogfv(GL_FOG_COLOR, fogcol);
calc_and_apply_fog(wal->shade, sec->visibility, sec->floorpal);
}
polymer_drawplane(&w->mask);
@ -1342,10 +1340,8 @@ void polymer_drawsprite(int32_t snum)
if ((tspr->cstat & 16384) && (!depth || mirrors[depth-1].plane))
return;
fogcalc(tspr->shade, sector[tspr->sectnum].visibility,
calc_and_apply_fog(tspr->shade, sector[tspr->sectnum].visibility,
sector[tspr->sectnum].floorpal);
bglFogf(GL_FOG_DENSITY, fogresult);
bglFogfv(GL_FOG_COLOR, fogcol);
if (usemodels && tile2model[Ptile2tile(tspr->picnum,tspr->pal)].modelid >= 0 &&
tile2model[Ptile2tile(tspr->picnum,tspr->pal)].framenum >= 0 &&
@ -2621,9 +2617,7 @@ static void polymer_drawsector(int16_t sectnum, int32_t domasks)
s->floor.material.diffusemodulation[2] = ((GLubyte *)(&sectnum))[1];
s->floor.material.diffusemodulation[3] = 0xFF;
} else {
fogcalc(sec->floorshade, sec->visibility, sec->floorpal);
bglFogf(GL_FOG_DENSITY, fogresult);
bglFogfv(GL_FOG_COLOR, fogcol);
calc_and_apply_fog(sec->floorshade, sec->visibility, sec->floorpal);
}
polymer_drawplane(&s->floor);
@ -2658,9 +2652,7 @@ static void polymer_drawsector(int16_t sectnum, int32_t domasks)
s->ceil.material.diffusemodulation[2] = ((GLubyte *)(&sectnum))[1];
s->ceil.material.diffusemodulation[3] = 0xFF;
} else {
fogcalc(sec->ceilingshade, sec->visibility, sec->ceilingpal);
bglFogf(GL_FOG_DENSITY, fogresult);
bglFogfv(GL_FOG_COLOR, fogcol);
calc_and_apply_fog(sec->ceilingshade, sec->visibility, sec->ceilingpal);
}
polymer_drawplane(&s->ceil);
@ -3174,9 +3166,7 @@ static void polymer_drawwall(int16_t sectnum, int16_t wallnum)
(sector[wal->nextsector].ceilingstat & 1))
parallaxedceiling = 1;
fogcalc(wal->shade,sec->visibility,sec->floorpal);
bglFogf(GL_FOG_DENSITY,fogresult);
bglFogfv(GL_FOG_COLOR,fogcol);
calc_and_apply_fog(wal->shade, sec->visibility, sec->floorpal);
if ((w->underover & 1) && (!parallaxedfloor || (searchit == 2)))
{

View file

@ -161,7 +161,6 @@ int32_t glpolygonmode = 0; // 0:GL_FILL,1:GL_LINE,2:GL_POINT //FUK
int32_t glwidescreen = 0;
int32_t glprojectionhacks = 1;
static GLuint polymosttext = 0;
extern char nofog;
int32_t glrendmode = 3;
// This variable, and 'shadeforfullbrightpass' control the drawing of
@ -3303,14 +3302,9 @@ static void polymost_internal_nonparallaxed(double nx0, double ny0, double nx1,
{
if (globalposz <= getceilzofslope(sectnum,globalposx,globalposy)) domostpolymethod = -1; //Back-face culling
}
#ifdef USE_OPENGL
if (!nofog)
{
fogcalc(global_cf_shade,sec->visibility,global_cf_pal);
bglFogf(GL_FOG_DENSITY,fogresult);
bglFogfv(GL_FOG_COLOR,fogcol);
}
#endif
calc_and_apply_fog(global_cf_shade, sec->visibility, global_cf_pal);
pow2xsplit = 0;
if (have_floor)
domost(x0,cf_y0,x1,cf_y1); //flor
@ -3466,12 +3460,7 @@ static void polymost_drawalls(int32_t bunch)
#ifdef USE_OPENGL
if (rendmode >= 3)
{
if (!nofog)
{
fogcalc(sec->floorshade,sec->visibility,sec->floorpal);
bglFogf(GL_FOG_DENSITY,fogresult * 0.005);
bglFogfv(GL_FOG_COLOR,fogcol);
}
calc_and_apply_fog_factor(sec->floorshade, sec->visibility, sec->floorpal, 0.005);
//Use clamping for tiled sky textures
for (i=(1<<dapskybits)-1; i>0; i--)
@ -3747,12 +3736,8 @@ static void polymost_drawalls(int32_t bunch)
#ifdef USE_OPENGL
if (rendmode >= 3)
{
if (!nofog)
{
fogcalc(sec->ceilingshade,sec->visibility,sec->ceilingpal);
bglFogf(GL_FOG_DENSITY,fogresult * 0.005);
bglFogfv(GL_FOG_COLOR,fogcol);
}
calc_and_apply_fog_factor(sec->ceilingshade, sec->visibility, sec->ceilingpal, 0.005);
//Use clamping for tiled sky textures
for (i=(1<<dapskybits)-1; i>0; i--)
if (dapskyoff[i] != dapskyoff[i-1])
@ -4064,14 +4049,9 @@ static void polymost_drawalls(int32_t bunch)
guo = gdo*t - guo;
}
if (wal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip
#ifdef USE_OPENGL
if (!nofog)
{
fogcalc(wal->shade,sec->visibility,sec->floorpal);
bglFogf(GL_FOG_DENSITY,fogresult);
bglFogfv(GL_FOG_COLOR,fogcol);
}
#endif
calc_and_apply_fog(wal->shade, sec->visibility, sec->floorpal);
pow2xsplit = 1; domost(x1,ocy1,x0,ocy0);
if (wal->cstat&8) { gux = ogux; guy = oguy; guo = oguo; }
}
@ -4101,14 +4081,9 @@ static void polymost_drawalls(int32_t bunch)
guo = gdo*t - guo;
}
if (nwal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip
#ifdef USE_OPENGL
if (!nofog)
{
fogcalc(nwal->shade,sec->visibility,sec->floorpal);
bglFogf(GL_FOG_DENSITY,fogresult);
bglFogfv(GL_FOG_COLOR,fogcol);
}
#endif
calc_and_apply_fog(nwal->shade, sec->visibility, sec->floorpal);
pow2xsplit = 1; domost(x0,ofy0,x1,ofy1);
if (wal->cstat&(2+8)) { guo = oguo; gux = ogux; guy = oguy; }
}
@ -4134,14 +4109,9 @@ static void polymost_drawalls(int32_t bunch)
guo = gdo*t - guo;
}
if (wal->cstat&256) { gvx = -gvx; gvy = -gvy; gvo = -gvo; } //yflip
#ifdef USE_OPENGL
if (!nofog)
{
fogcalc(wal->shade,sec->visibility,sec->floorpal);
bglFogf(GL_FOG_DENSITY,fogresult);
bglFogfv(GL_FOG_COLOR,fogcol);
}
#endif
calc_and_apply_fog(wal->shade, sec->visibility, sec->floorpal);
pow2xsplit = 1; domost(x0,-10000,x1,-10000);
}
@ -4706,17 +4676,7 @@ void polymost_drawmaskwall(int32_t damaskwallcnt)
method = 1; pow2xsplit = 1;
if (wal->cstat&128) { if (!(wal->cstat&512)) method = 2; else method = 3; }
#ifdef USE_OPENGL
if (!nofog)
{
if (rendmode >= 3)
{
fogcalc(wal->shade,sec->visibility,sec->floorpal);
bglFogf(GL_FOG_DENSITY,fogresult);
bglFogfv(GL_FOG_COLOR,fogcol);
}
}
#endif
calc_and_apply_fog(wal->shade, sec->visibility, sec->floorpal);
for (i=0; i<2; i++)
{
@ -4870,13 +4830,7 @@ void polymost_drawsprite(int32_t snum)
if (tspr->cstat&2) { if (!(tspr->cstat&512)) method = 2+4; else method = 3+4; }
#ifdef USE_OPENGL
if (!nofog && rendmode >= 3)
{
fogcalc(globalshade,sector[tspr->sectnum].visibility,sector[tspr->sectnum].floorpal);
bglFogf(GL_FOG_DENSITY,fogresult);
bglFogfv(GL_FOG_COLOR,fogcol);
}
calc_and_apply_fog(globalshade, sector[tspr->sectnum].visibility, sector[tspr->sectnum].floorpal);
while (rendmode >= 3 && !(spriteext[tspr->owner].flags&SPREXT_NOTMD))
{