From 0b826825ec7f959c360f07cff8b5f370b627ebc7 Mon Sep 17 00:00:00 2001 From: Forest Hale Date: Fri, 30 Jun 2000 00:47:26 +0000 Subject: [PATCH] GL cleanup. (cleanup after Endy mainly) --- source/gl_rmain.c | 153 ++++++++++++++-------------------------------- source/gl_rmisc.c | 16 +++-- source/gl_rsurf.c | 46 ++++++++------ source/gl_view.c | 6 +- 4 files changed, 89 insertions(+), 132 deletions(-) diff --git a/source/gl_rmain.c b/source/gl_rmain.c index 083b99a..3b1dd42 100644 --- a/source/gl_rmain.c +++ b/source/gl_rmain.c @@ -371,13 +371,8 @@ void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum) verts += posenum * paliashdr->poseverts; order = (int *)((byte *)paliashdr + paliashdr->commands); - if (modelalpha != 1.0) - { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (modelalpha != 1.0) glEnable(GL_BLEND); - glDepthMask(0); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } while (1) { @@ -401,14 +396,9 @@ void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum) // normals and vertexes come from the frame list l = shadedots[verts->lightnormalindex] * shadelight; - -// Ender: Test (Colormod) [QSG Begin] - if (modelalpha) { - glColor4f(shadecolor[0] * l, shadecolor[1] * l, shadecolor[2] * l, modelalpha); - } else { - glColor3f(shadecolor[0] * l, shadecolor[1] * l, shadecolor[2] * l); - } -// Ender: Test (Colormod) [QSG End] + + // LordHavoc: cleanup after Endy + glColor4f(shadecolor[0] * l, shadecolor[1] * l, shadecolor[2] * l, modelalpha); glVertex3f (verts->v[0], verts->v[1], verts->v[2]); verts++; @@ -417,12 +407,8 @@ void GL_DrawAliasFrame (aliashdr_t *paliashdr, int posenum) glEnd (); } - if (modelalpha != 1.0) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // normal alpha blend - glDisable(GL_BLEND); - glDepthMask(1); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - } + if (modelalpha != 1.0) + glDepthMask(1); } @@ -546,6 +532,10 @@ void R_DrawAliasModel (entity_t *e) if (R_CullBox (mins, maxs)) return; + // FIXME: shadecolor is supposed to be the lighting for the model, not just colormod + shadecolor[0] = currententity->colormod[0]; + shadecolor[1] = currententity->colormod[1]; + shadecolor[2] = currententity->colormod[2]; VectorCopy (currententity->origin, r_entorigin); VectorSubtract (r_origin, r_entorigin, modelorg); @@ -569,7 +559,8 @@ void R_DrawAliasModel (entity_t *e) dist); add = (cl_dlights[lnum].radius * cl_dlights[lnum].radius * 8) / (Length(dist) * Length(dist)); // FIXME Deek - if (add > 0) { + if (add > 0) + { ambientlight += add; //ZOID models should be affected by dlights as well shadelight += add; @@ -584,11 +575,12 @@ void R_DrawAliasModel (entity_t *e) shadelight = 192 - ambientlight; // ZOID: never allow players to go totally black - if (!strcmp(clmodel->name, "progs/player.mdl")) { + if (!strcmp(clmodel->name, "progs/player.mdl")) + { if (ambientlight < 8) ambientlight = shadelight = 8; - - } else if (!strcmp (clmodel->name, "progs/flame2.mdl") + } + else if (!strcmp (clmodel->name, "progs/flame2.mdl") || !strcmp (clmodel->name, "progs/flame.mdl") ) // HACK HACK HACK -- no fullbright colors, so make torches full light ambientlight = shadelight = 256; @@ -618,11 +610,14 @@ void R_DrawAliasModel (entity_t *e) glPushMatrix (); R_RotateForEntity (e); - if (!strcmp (clmodel->name, "progs/eyes.mdl") ) { + if (!strcmp (clmodel->name, "progs/eyes.mdl") ) + { glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2] - (22 + 8)); // double size of eyes, since they are really hard to see in gl glScalef (paliashdr->scale[0]*2, paliashdr->scale[1]*2, paliashdr->scale[2]*2); - } else { + } + else + { glTranslatef (paliashdr->scale_origin[0], paliashdr->scale_origin[1], paliashdr->scale_origin[2]); glScalef (paliashdr->scale[0], paliashdr->scale[1], paliashdr->scale[2]); } @@ -635,7 +630,8 @@ void R_DrawAliasModel (entity_t *e) if (currententity->scoreboard && !gl_nocolors->value) { i = currententity->scoreboard - cl.players; - if (!currententity->scoreboard->skin) { + if (!currententity->scoreboard->skin) + { Skin_Find(currententity->scoreboard); R_TranslatePlayerSkin(i); } @@ -684,45 +680,35 @@ void R_DrawEntitiesOnList (void) if (!r_drawentities->value) return; - // Ender (Extend) - modelalpha = currententity->alpha; - shadecolor[0] = currententity->colormod[0]; - shadecolor[1] = currententity->colormod[1]; - shadecolor[2] = currententity->colormod[2]; - // draw sprites seperately, because of alpha blending + // LordHavoc: split into 3 loops to simplify state changes for (i=0 ; itype != mod_brush) + continue; currententity = &cl_visedicts[i]; + modelalpha = currententity->alpha; - switch (currententity->model->type) - { - case mod_alias: - R_DrawAliasModel (currententity); - break; - - case mod_brush: - R_DrawBrushModel (currententity); - break; - - default: - break; - } + R_DrawBrushModel (currententity); } for (i=0 ; itype != mod_brush) + continue; + currententity = &cl_visedicts[i]; + modelalpha = currententity->alpha; + + R_DrawAliasModel (currententity); + } + + for (i=0 ; itype != mod_sprite) + continue; currententity = &cl_visedicts[i]; - switch (currententity->model->type) - { - case mod_sprite: - R_DrawSpriteModel (currententity); - break; - - default : - break; - } + R_DrawSpriteModel (currententity); } } @@ -733,63 +719,18 @@ R_DrawViewModel */ void R_DrawViewModel (void) { - float ambient[4], diffuse[4]; - int j; - int lnum; - vec3_t dist; - float add; - dlight_t *dl; - int ambientlight, shadelight; - - if (!r_drawviewmodel->value || !Cam_DrawViewModel()) - return; - - if (envmap) - return; - - if (!r_drawentities->value) - return; - - if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY) - return; - - if (cl.stats[STAT_HEALTH] <= 0) + if (!r_drawviewmodel->value + || !Cam_DrawViewModel() + || envmap + || !r_drawentities->value + || (cl.stats[STAT_ITEMS] & IT_INVISIBILITY) + || cl.stats[STAT_HEALTH] <= 0) return; currententity = &cl.viewent; if (!currententity->model) return; - j = R_LightPoint (currententity->origin); - - if (j < 24) - j = 24; // allways give some light on gun - ambientlight = j; - shadelight = j; - - shadecolor[0] = shadecolor[1] = shadecolor[2] = 0; - -// add dynamic lights - for (lnum=0 ; lnumradius) - continue; - if (!dl->radius) - continue; - if (dl->die < cl.time) - continue; - - VectorSubtract (currententity->origin, dl->origin, dist); - add = (dl->radius * dl->radius * 8) / (Length(dist) * Length(dist)); // FIXME Deek -// add = dl->radius - Length(dist); - if (add > 0) - ambientlight += add; - } - - ambient[0] = ambient[1] = ambient[2] = ambient[3] = (float)ambientlight / 128; - diffuse[0] = diffuse[1] = diffuse[2] = diffuse[3] = (float)shadelight / 128; - // hack the depth range to prevent view model from poking into walls glDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin)); R_DrawAliasModel (currententity); diff --git a/source/gl_rmisc.c b/source/gl_rmisc.c index 1a1eac1..8aed2f9 100644 --- a/source/gl_rmisc.c +++ b/source/gl_rmisc.c @@ -512,28 +512,34 @@ R_TimeRefresh_f For program optimization ==================== */ +// LordHavoc: improved appearance and accuracy of timerefresh void R_TimeRefresh_f (void) { int i; - float start, stop, time; + double start, stop, time; - glDrawBuffer (GL_FRONT); +// glDrawBuffer (GL_FRONT); glFinish (); + GL_EndRendering (); start = Sys_DoubleTime (); for (i=0 ; i<128 ; i++) { + GL_BeginRendering(); r_refdef.viewangles[1] = i/128.0*360.0; R_RenderView (); + glFinish (); + GL_EndRendering (); } - glFinish (); +// glFinish (); stop = Sys_DoubleTime (); time = stop-start; Con_Printf ("%f seconds (%f fps)\n", time, 128/time); - glDrawBuffer (GL_BACK); - GL_EndRendering (); +// glDrawBuffer (GL_BACK); +// GL_EndRendering (); + GL_BeginRendering(); } void D_FlushCaches (void) diff --git a/source/gl_rsurf.c b/source/gl_rsurf.c index c2dd33a..b7086e2 100644 --- a/source/gl_rsurf.c +++ b/source/gl_rsurf.c @@ -257,7 +257,9 @@ store: t = (int) *bl++ >> 8; *dest++ = bound(0, t, 255); } - } else { + } + else + { stride -= smax; bl = blocklights; for (i = 0; i < tmax; i++, dest += stride) @@ -334,7 +336,8 @@ void GL_SelectTexture (GLenum target); void GL_DisableMultitexture(void) { - if (mtexenabled) { + if (mtexenabled) + { glDisable(GL_TEXTURE_2D); GL_SelectTexture(0); mtexenabled = false; @@ -343,7 +346,8 @@ void GL_DisableMultitexture(void) void GL_EnableMultitexture(void) { - if (gl_mtexable) { + if (gl_mtexable) + { GL_SelectTexture(1); glEnable(GL_TEXTURE_2D); mtexenabled = true; @@ -410,7 +414,9 @@ void R_DrawSequentialPoly (msurface_t *s) } glEnd (); return; - } else { + } + else + { p = s->polys; t = R_TextureAnimation (s->texinfo->texture); @@ -692,23 +698,29 @@ void R_DrawWaterSurfaces (void) glLoadMatrixf (r_world_matrix); - if (r_wateralpha->value < 1.0) { + if (r_wateralpha->value < 1.0) + { glColor4f (0.5, 0.5, 0.5, r_wateralpha->value); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } else - glColor3f (0.5, 0.5, 0.5); + } + else + glColor3f (0.5, 0.5, 0.5); - if (!gl_texsort->value) { + if (!gl_texsort->value) + { if (!waterchain) return; - for ( s = waterchain ; s ; s=s->texturechain) { + for ( s = waterchain ; s ; s=s->texturechain) + { glBindTexture (GL_TEXTURE_2D, s->texinfo->texture->gl_texturenum); EmitWaterPolys (s); } waterchain = NULL; - } else { + } + else + { for (i=0 ; inumtextures ; i++) { @@ -826,13 +838,7 @@ void R_DrawBrushModel (entity_t *e) if (R_CullBox (mins, maxs)) return; -// Ender: Extend (Alpha) [QSG - Begin] -// glEnable(GL_BLEND); -// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - -// Note: glColor4f and gl_texsort->value = 1 for alpha! :) - glColor3f (1, 1, 1); -// Ender: Extend (Alpha) [QSG - End] + glColor3f (1, 1, 1); memset (lightmap_polys, 0, sizeof(lightmap_polys)); @@ -1316,13 +1322,15 @@ void GL_BuildLightmaps (void) } gl_colorlights = Cvar_Get ("gl_colorlights", "1", CVAR_ROM, - "Whether to use RGBA lightmaps or not"); + "Whether to use RGB lightmaps or not"); if (gl_colorlights->value) { gl_lightmap_format = GL_RGB; lightmap_bytes = 3; - } else { + } + else + { gl_lightmap_format = GL_LUMINANCE; lightmap_bytes = 1; } diff --git a/source/gl_view.c b/source/gl_view.c index 1bd96ce..8c9321a 100644 --- a/source/gl_view.c +++ b/source/gl_view.c @@ -101,13 +101,15 @@ V_CalcBlend (void) a = 1.0 - a3; } - if (a > 1.0) + // LordHavoc: saturate color + if (a) { a2 = 1.0 / a; r *= a2; g *= a2; b *= a2; - a = 1.0; + if (a > 1) // clamp alpha blend too + a = 1; } v_blend[0] = min(r, 255.0)/255.0;