State change cleanup, but saner code!

This commit is contained in:
Zephaniah E. Hull 2000-09-28 00:22:24 +00:00
parent 86f87122c0
commit f6bfcfc82d
9 changed files with 46 additions and 133 deletions

View file

@ -329,6 +329,13 @@ void AddLightBlend (float, float, float, float);
//
void R_StoreEfrags (efrag_t **ppefrag);
//
// gl_screen.c
//
extern qboolean lighthalf;
extern unsigned char lighthalf_v[3];
//
// gl_mesh.c
//

View file

@ -62,7 +62,6 @@ static int GL_LoadPicTexture (qpic_t *pic);
extern byte *host_basepal;
extern unsigned char d_15to8table[65536];
extern cvar_t *crosshair, *cl_crossx, *cl_crossy, *crosshaircolor;
extern qboolean lighthalf;
cvar_t *gl_nobind;
cvar_t *gl_max_size;
@ -431,6 +430,11 @@ void Draw_Init (void)
if (!strncasecmp ((char *)gl_renderer, "3dfx",4))
Cvar_Set (gl_lightmode, "0");
lighthalf = gl_lightmode->value != 0; // to avoid re-rendering all lightmaps on first frame
if (lighthalf) {
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 128;
} else {
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 255;
}
Cmd_AddCommand ("gl_texturemode", &Draw_TextureMode_f);
@ -504,10 +508,6 @@ void Draw_Character8 (int x, int y, int num)
glBindTexture (GL_TEXTURE_2D, char_texture);
if (lighthalf)
glColor3f(0.5,0.5,0.5);
else
glColor3f(1,1,1);
glBegin (GL_QUADS);
glTexCoord2f (fcol, frow);
glVertex2f (x, y);
@ -586,6 +586,7 @@ void Draw_Crosshair(void)
glTexCoord2f (0, 1);
glVertex2f (x - 4, y+12);
glEnd ();
glColor3ubv(lighthalf_v);
break;
}
}
@ -619,6 +620,7 @@ void Draw_Pic (int x, int y, qpic_t *pic)
glTexCoord2f (gl->sl, gl->th);
glVertex2f (x, y+pic->height);
glEnd ();
glColor3ubv(lighthalf_v);
}
void Draw_SubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int height)
@ -657,6 +659,7 @@ void Draw_SubPic(int x, int y, qpic_t *pic, int srcx, int srcy, int width, int h
glTexCoord2f (newsl, newth);
glVertex2f (x, y+height);
glEnd ();
glColor3ubv(lighthalf_v);
}
/*
@ -728,6 +731,7 @@ void Draw_TransPicTranslate (int x, int y, qpic_t *pic, byte *translation)
glTexCoord2f (0, 1);
glVertex2f (x, y+pic->height);
glEnd ();
glColor3ubv(lighthalf_v);
}
@ -822,6 +826,7 @@ Draw_ConsoleBackground ( int lines )
if (!cls.download)
Draw_AltString8 (vid.conwidth - strlen(cl_verstring->string)*8 - 11,
lines-14, cl_verstring->string);
glColor3ubv(lighthalf_v);
}
@ -850,6 +855,7 @@ void Draw_TileClear (int x, int y, int w, int h)
glTexCoord2f ( x/64.0, (y+h)/64.0 );
glVertex2f (x, y+h);
glEnd ();
glColor3ubv(lighthalf_v);
}
@ -876,10 +882,7 @@ void Draw_Fill (int x, int y, int w, int h, int c)
glVertex2f (x, y+h);
glEnd ();
if (lighthalf)
glColor3f(0.5,0.5,0.5);
else
glColor3f(1,1,1);
glColor3ubv(lighthalf_v);
glEnable (GL_TEXTURE_2D);
}
//=============================================================================
@ -902,10 +905,7 @@ void Draw_FadeScreen (void)
glVertex2f (0, vid.height);
glEnd ();
if (lighthalf)
glColor3f(0.5,0.5,0.5);
else
glColor3f(1,1,1);
glColor3ubv(lighthalf_v);
glEnable (GL_TEXTURE_2D);
Sbar_Changed();
@ -963,10 +963,7 @@ void GL_Set2D (void)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
if (lighthalf)
glColor3f(0.5,0.5,0.5);
else
glColor3f(1,1,1);
glColor3ubv(lighthalf_v);
}
//====================================================================

View file

@ -160,10 +160,6 @@ void R_NetGraph (void)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
x = 8;
if (lighthalf)
glColor3f(0.5,0.5,0.5);
else
glColor3f(1,1,1);
glBegin (GL_QUADS);
glTexCoord2f (0, 0);
glVertex2f (x, y);

View file

@ -650,6 +650,7 @@ void R_DrawParticles (void)
}
glEnd ();
glColor3ubv(lighthalf_v);
if (alphaTestEnabled)
glEnable(GL_ALPHA_TEST);
glDepthMask(1);
@ -793,6 +794,7 @@ R_DrawFire (fire_t *f)
b_cos+=2;
}
glEnd ();
glColor3ubv(lighthalf_v);
}
/*
@ -823,7 +825,6 @@ R_UpdateFires (void)
R_DrawFire (f);
}
glColor3f (1.0, 1.0, 1.0);
glEnable (GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask (1);

View file

@ -145,8 +145,6 @@ void R_RenderDlight (dlight_t *light)
}
glBegin (GL_TRIANGLE_FAN);
// glColor3f (0.2,0.1,0.0);
// glColor3f (0.2,0.1,0.05); // changed dimlight effect
if (lighthalf)
glColor3f(light->color[0]*0.5,light->color[1]*0.5,light->color[2]*0.5);
else
@ -166,6 +164,9 @@ void R_RenderDlight (dlight_t *light)
glVertex3fv (v);
}
glEnd ();
// No, we don't reset here, we reset in the function which calls this one.
// Largely because this is called in a big loop.
// glColor3ubv(lighthalf_v);
}
/*
@ -196,7 +197,7 @@ void R_RenderDlights (void)
R_RenderDlight (l);
}
glColor3f (1,1,1);
glColor3ubv(lighthalf_v);
glEnable (GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask (1);

View file

@ -300,11 +300,6 @@ static void R_DrawSpriteModel (entity_t *e)
right = vright;
}
if (lighthalf)
glColor4f(0.5,0.5,0.5,1);
else
glColor4f(1,1,1,1);
glBindTexture (GL_TEXTURE_2D, frame->gl_texturenum);
glEnable (GL_ALPHA_TEST);
@ -423,6 +418,7 @@ static void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum, qboolean fb)
if (modelalpha != 1.0)
glDepthMask(1);
glColor3ubv(lighthalf_v);
}
@ -685,7 +681,7 @@ static void R_DrawAliasModel (entity_t *e)
glColor4f (0,0,0,0.5);
GL_DrawAliasShadow (paliashdr, lastposenum);
glEnable (GL_TEXTURE_2D);
glColor4f (0.5, 0.5, 0.5, 1);
glColor3ubv(lighthalf_v);
glPopMatrix ();
}
@ -1001,74 +997,6 @@ static void R_Clear (void)
glDepthRange (gldepthmin, gldepthmax);
}
#if 0 //!!! FIXME, Zoid, mirror is disabled for now
/*
=============
R_Mirror
=============
*/
void R_Mirror (void)
{
float d;
msurface_t *s;
entity_t *ent;
if (!mirror)
return;
memcpy (r_base_world_matrix, r_world_matrix, sizeof(r_base_world_matrix));
d = DotProduct (r_refdef.vieworg, mirror_plane->normal) - mirror_plane->dist;
VectorMA (r_refdef.vieworg, -2*d, mirror_plane->normal, r_refdef.vieworg);
d = DotProduct (vpn, mirror_plane->normal);
VectorMA (vpn, -2*d, mirror_plane->normal, vpn);
r_refdef.viewangles[0] = -asin (vpn[2])/M_PI*180;
r_refdef.viewangles[1] = atan2 (vpn[1], vpn[0])/M_PI*180;
r_refdef.viewangles[2] = -r_refdef.viewangles[2];
ent = &cl_entities[cl.viewentity];
if (cl_numvisedicts < MAX_VISEDICTS)
{
cl_visedicts[cl_numvisedicts] = ent;
cl_numvisedicts++;
}
gldepthmin = 0.5;
gldepthmax = 1;
glDepthRange (gldepthmin, gldepthmax);
glDepthFunc (GL_LEQUAL);
R_RenderScene ();
R_DrawWaterSurfaces ();
gldepthmin = 0;
gldepthmax = 0.5;
glDepthRange (gldepthmin, gldepthmax);
glDepthFunc (GL_LEQUAL);
// blend on top
glMatrixMode(GL_PROJECTION);
if (mirror_plane->normal[2])
glScalef (1,-1,1);
else
glScalef (-1,1,1);
glCullFace(GL_FRONT);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf (r_base_world_matrix);
glColor4f (1,1,1,r_mirroralpha->value);
s = cl.worldmodel->textures[mirrortexturenum]->texturechain;
for ( ; s ; s=s->texturechain)
R_RenderBrushPoly (s);
cl.worldmodel->textures[mirrortexturenum]->texturechain = NULL;
glColor4f (1,1,1,1);
}
#endif
/*
================
R_RenderView

View file

@ -473,6 +473,7 @@ dynamic:
s->polys->fb_chain = fullbright_polys[texture->gl_fb_texturenum];
fullbright_polys[texture->gl_fb_texturenum] = s->polys;
}
glColor3ubv(lighthalf_v);
}
/*
@ -489,6 +490,7 @@ void R_BlendLightmaps (void)
glDepthMask (0); // don't bother writing Z
glBlendFunc (GL_ZERO, GL_SRC_COLOR);
glColor3f(1,1,1);
for (i=0 ; i<MAX_LIGHTMAPS ; i++)
{
@ -515,6 +517,7 @@ void R_BlendLightmaps (void)
}
// Return to normal blending --KB
glColor3ubv(lighthalf_v);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask (1); // back to normal Z buffering
@ -533,7 +536,6 @@ R_RenderFullbrights (void)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBlendFunc(GL_ONE, GL_ONE);
glColor3f(1,1,1);
for (i=1; i<MAX_GLTEXTURES; i++) {
if (!fullbright_polys[i])
@ -570,6 +572,7 @@ void R_RenderBrushPoly (msurface_t *fa)
c_brush_polys++;
glColor3f(1, 1, 1);
glBindTexture (GL_TEXTURE_2D, texture->gl_texturenum);
glBegin (GL_POLYGON);
@ -625,16 +628,13 @@ dynamic:
R_BuildLightMap (fa, base, BLOCK_WIDTH*lightmap_bytes);
}
}
glColor3ubv(lighthalf_v);
}
void GL_WaterSurface(msurface_t *s)
{
int i;
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
if (lighthalf)
glColor4f(0.5,0.5,0.5, r_wateralpha->value);
else
glColor4f(1,1,1, r_wateralpha->value);
i = s->texinfo->texture->gl_texturenum;
glBindTexture (GL_TEXTURE_2D, i);
if (r_wateralpha->value < 1.0)
@ -666,10 +666,6 @@ void R_DrawWaterSurfaces (void)
glLoadMatrixf (r_world_matrix);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
if (lighthalf)
glColor4f(0.5,0.5,0.5, r_wateralpha->value);
else
glColor4f(1,1,1, r_wateralpha->value);
if (r_wateralpha->value < 1.0)
glDepthMask(0);
@ -686,7 +682,6 @@ void R_DrawWaterSurfaces (void)
waterchain = NULL;
glColor3f(1,1,1);
if (r_wateralpha->value < 1.0)
glDepthMask(1);
}
@ -716,7 +711,6 @@ void DrawTextureChains (void)
}
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
}
@ -759,8 +753,6 @@ void R_DrawBrushModel (entity_t *e)
if (R_CullBox (mins, maxs))
return;
glColor3f (1, 1, 1);
memset (lightmap_polys, 0, sizeof(lightmap_polys));
memset (fullbright_polys, 0, sizeof(fullbright_polys));
@ -834,7 +826,6 @@ void R_DrawBrushModel (entity_t *e)
}
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if (gl_texsort->value)
R_BlendLightmaps ();
@ -989,7 +980,6 @@ void R_DrawWorld (void)
if (!gl_mtexable)
Cvar_SetValue (gl_texsort, 1);
glColor3f (1.0, 1.0, 1.0);
memset (lightmap_polys, 0, sizeof(lightmap_polys));
memset (fullbright_polys, 0, sizeof(fullbright_polys));
// Be sure to clear the skybox --KB

View file

@ -1101,6 +1101,7 @@ void SCR_TileClear (void)
float oldsbar = 0;
extern void R_ForceLightUpdate();
qboolean lighthalf;
unsigned char lighthalf_v[3];
extern cvar_t *gl_lightmode, *brightness, *contrast;
/*
@ -1176,6 +1177,11 @@ void SCR_UpdateScreen (void)
if (lighthalf != (gl_lightmode->value != 0))
{
lighthalf = gl_lightmode->value != 0;
if (lighthalf) {
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 128;
} else {
lighthalf_v[0] = lighthalf_v[1] = lighthalf_v[2] = 255;
}
R_ForceLightUpdate();
}
@ -1255,8 +1261,9 @@ void SCR_UpdateScreen (void)
f *= 0.5;
}
glEnd ();
glColor3ubv(lighthalf_v);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Cvar_SetValue (contrast, bound (0.1, contrast->value, 1));
if ((gl_polyblend->value && v_blend[3]) || contrast->value < 1)
{
@ -1277,6 +1284,7 @@ void SCR_UpdateScreen (void)
glVertex2f (0, vid.height);
}
glEnd ();
glColor3ubv(lighthalf_v);
}
glEnable(GL_TEXTURE_2D);

View file

@ -650,14 +650,8 @@ R_DrawSkyBox (void)
{
int i, j;
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_ALWAYS);
glDisable (GL_DEPTH_TEST);
glDepthRange (gldepthmax, gldepthmax);
if (lighthalf)
glColor3f(0.5,0.5,0.5);
else
glColor3f(1,1,1);
for (i = 0; i < 6; i++)
{
glBindTexture(GL_TEXTURE_2D, SKY_TEX + i);
@ -667,8 +661,6 @@ R_DrawSkyBox (void)
glEnd();
}
glColor3f (1,1,1);
glDepthFunc (GL_LEQUAL);
glEnable (GL_DEPTH_TEST);
glDepthRange(gldepthmin, gldepthmax);
}
@ -729,15 +721,10 @@ R_DrawSkyLayer (float s)
void
R_DrawSkyDome (void)
{
glEnable (GL_DEPTH_TEST);
glDepthFunc (GL_ALWAYS);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable (GL_DEPTH_TEST);
glDepthRange (gldepthmax, gldepthmax);
glDisable (GL_BLEND);
if (lighthalf)
glColor3f(0.5,0.5,0.5);
else
glColor3f(1,1,1);
// base sky
glBindTexture (GL_TEXTURE_2D, solidskytexture);
@ -760,8 +747,6 @@ R_DrawSkyDome (void)
R_DrawSkyLayer (speedscale);
}
glColor3f (1,1,1);
glDepthFunc (GL_LEQUAL);
glEnable (GL_DEPTH_TEST);
glDepthRange (gldepthmin, gldepthmax);
}