From 3879b7753eaa209f8e279430e69af9c8228bb474 Mon Sep 17 00:00:00 2001 From: lordhavoc Date: Tue, 31 Oct 2000 03:31:02 +0000 Subject: [PATCH 1/1] lighthalf related transpoly cleanup major cleanup of surface rendering code for readability sake SV_ChangeTeam added for sake of QC in mods (allows the mod to review all color changes and decide what to do with them, setcolor is useful for this) minor light chunk loader cleanup (including a questionable bugfix relating to .lit files for maps without light data) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@73 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_poly.c | 35 ++------------ gl_poly.h | 28 +++++++++-- gl_rmain.c | 26 +++------- gl_rsurf.c | 128 ++++++++++++++++++++++++-------------------------- host_cmd.c | 30 ++++++++---- model_brush.c | 5 +- 6 files changed, 121 insertions(+), 131 deletions(-) diff --git a/gl_poly.c b/gl_poly.c index d312335e..3947bbd8 100644 --- a/gl_poly.c +++ b/gl_poly.c @@ -59,6 +59,8 @@ void transpolyclear() transviewdist = DotProduct(r_refdef.vieworg, vpn); } +// turned into a #define +/* void transpolybegin(int texnum, int glowtexnum, int fogtexnum, int transpolytype) { if (currenttranspoly >= MAX_TRANSPOLYS || currenttransvert >= MAX_TRANSVERTS) @@ -71,6 +73,7 @@ void transpolybegin(int texnum, int glowtexnum, int fogtexnum, int transpolytype transpoly[currenttranspoly].verts = 0; // transpoly[currenttranspoly].ndist = 0; // clear the normal } +*/ // turned into a #define /* @@ -367,10 +370,6 @@ void transpolyrender() glEnable(GL_ALPHA_TEST); else glDisable(GL_ALPHA_TEST); - // later note: wasn't working on my TNT drivers... strangely... used a cheaper hack in transpolyvert - //// offset by 16 depth units so decal sprites appear infront of walls - //glPolygonOffset(1, -16); - //glEnable(GL_POLYGON_OFFSET_FILL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); tpolytype = TPOLYTYPE_ALPHA; texnum = -1; @@ -538,39 +537,11 @@ void transpolyrender() glEnd(); } - //glDisable(GL_POLYGON_OFFSET_FILL); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthMask(1); // enable zbuffer updates glDisable(GL_ALPHA_TEST); } -/* -void lightpolybegin(int texnum) -{ - if (currentlightpoly >= MAX_LIGHTPOLYS || currentlightvert >= MAX_LIGHTVERTS) - return; - lightpoly[currentlightpoly].texnum = (unsigned short) texnum; - lightpoly[currentlightpoly].firstvert = currentlightvert; - lightpoly[currentlightpoly].verts = 0; -} - -// lightpolyvert is a #define - -void lightpolyend() -{ - if (currentlightpoly >= MAX_LIGHTPOLYS) - return; - if (lightpoly[currentlightpoly].verts < 3) // skip invalid polygons - { - currentlightvert = lightpoly[currentlightpoly].firstvert; // reset vert pointer - return; - } - if (currentlightvert >= MAX_LIGHTVERTS) - return; - currentlightpoly++; -} -*/ - extern qboolean isG200; void wallpolyclear() diff --git a/gl_poly.h b/gl_poly.h index 48cd0754..53d6d813 100644 --- a/gl_poly.h +++ b/gl_poly.h @@ -85,15 +85,37 @@ extern unsigned short currentwallvert; extern unsigned short currentskypoly; extern unsigned short currentskyvert; +#define transpolybegin(ttexnum, tglowtexnum, tfogtexnum, ttranspolytype)\ +{\ + if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\ + {\ + transpoly[currenttranspoly].texnum = (unsigned short) (ttexnum);\ + transpoly[currenttranspoly].glowtexnum = (unsigned short) (tglowtexnum);\ + transpoly[currenttranspoly].fogtexnum = (unsigned short) (tfogtexnum);\ + transpoly[currenttranspoly].transpolytype = (unsigned short) (ttranspolytype);\ + transpoly[currenttranspoly].firstvert = currenttransvert;\ + transpoly[currenttranspoly].verts = 0;\ + }\ +} + #define transpolyvert(vx,vy,vz,vs,vt,vr,vg,vb,va) \ {\ if (currenttranspoly < MAX_TRANSPOLYS && currenttransvert < MAX_TRANSVERTS)\ {\ transvert[currenttransvert].s = (vs);\ transvert[currenttransvert].t = (vt);\ - transvert[currenttransvert].r = (byte) (bound(0, (int) (vr), 255));\ - transvert[currenttransvert].g = (byte) (bound(0, (int) (vg), 255));\ - transvert[currenttransvert].b = (byte) (bound(0, (int) (vb), 255));\ + if (lighthalf)\ + {\ + transvert[currenttransvert].r = (byte) (bound(0, (int) (vr) >> 1, 255));\ + transvert[currenttransvert].g = (byte) (bound(0, (int) (vg) >> 1, 255));\ + transvert[currenttransvert].b = (byte) (bound(0, (int) (vb) >> 1, 255));\ + }\ + else\ + {\ + transvert[currenttransvert].r = (byte) (bound(0, (int) (vr), 255));\ + transvert[currenttransvert].g = (byte) (bound(0, (int) (vg), 255));\ + transvert[currenttransvert].b = (byte) (bound(0, (int) (vb), 255));\ + }\ transvert[currenttransvert].a = (byte) (bound(0, (int) (va), 255));\ transvert[currenttransvert].v[0] = (vx);\ transvert[currenttransvert].v[1] = (vy);\ diff --git a/gl_rmain.c b/gl_rmain.c index f7d2e004..753f34e7 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -513,29 +513,14 @@ void R_DrawSpriteModel (entity_t *e) if (e->model->flags & EF_FULLBRIGHT || e->effects & EF_FULLBRIGHT) { - if (lighthalf) - { - shadecolor[0] = e->colormod[0] * 128; - shadecolor[1] = e->colormod[1] * 128; - shadecolor[2] = e->colormod[2] * 128; - } - else - { - shadecolor[0] = e->colormod[0] * 255; - shadecolor[1] = e->colormod[1] * 255; - shadecolor[2] = e->colormod[2] * 255; - } + shadecolor[0] = e->colormod[0] * 255; + shadecolor[1] = e->colormod[1] * 255; + shadecolor[2] = e->colormod[2] * 255; } else { R_LightPoint (shadecolor, e->origin); R_DynamicLightPointNoMask(shadecolor, e->origin); - if (lighthalf) - { - shadecolor[0] *= e->colormod[0] * 0.5; - shadecolor[1] *= e->colormod[1] * 0.5; - shadecolor[2] *= e->colormod[2] * 0.5; - } } // LordHavoc: interpolated sprite rendering @@ -1612,13 +1597,14 @@ void R_RenderView (void) if (skyname[0] && skyisvisible && !fogenabled) R_Sky(); // does not affect depth, draws over the sky polys + UploadLightmaps(); + wallpolyrender(); + R_DrawEntitiesOnList2 (); // other models // R_RenderDlights (); R_DrawViewModel (); R_DrawParticles (); - UploadLightmaps(); - wallpolyrender(); transpolyrender(); FOG_frameend(); diff --git a/gl_rsurf.c b/gl_rsurf.c index 4d1402e8..fe5bb6ca 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -48,6 +48,7 @@ cvar_t gl_nosubimagefragments = {"gl_nosubimagefragments", "0"}; cvar_t gl_nosubimage = {"gl_nosubimage", "0"}; cvar_t r_ambient = {"r_ambient", "0"}; cvar_t gl_vertex = {"gl_vertex", "0"}; +cvar_t gl_texsort = {"gl_texsort", "1"}; //cvar_t gl_funnywalls = {"gl_funnywalls", "0"}; // LordHavoc: see BuildSurfaceDisplayList qboolean lightmaprgba, nosubimagefragments, nosubimage; @@ -70,6 +71,7 @@ void glrsurf_init() Cvar_RegisterVariable(&r_ambient); // Cvar_RegisterVariable(&gl_funnywalls); Cvar_RegisterVariable(&gl_vertex); + Cvar_RegisterVariable(&gl_texsort); // check if it's the glquake minigl driver if (strncasecmp(gl_vendor,"3Dfx",4)==0) if (!gl_arrays) @@ -430,7 +432,7 @@ void R_WaterSurf(msurface_t *s, texture_t *t, qboolean transform, int alpha) int i; float os = turbsin[(int)(realtime * TURBSCALE) & 255], ot = turbsin[(int)(realtime * TURBSCALE + 96.0) & 255]; glpoly_t *p; - float wvert[64*6], *wv, *v; + float wvert[1024*6], *wv, *v; wv = wvert; for (p = s->polys;p;p = p->next) { @@ -441,7 +443,7 @@ void R_WaterSurf(msurface_t *s, texture_t *t, qboolean transform, int alpha) else VectorCopy(v, wv); if (r_waterripple.value) - wv[2] += r_waterripple.value * turbsin[(int)((wv[0]*0.125f+realtime) * TURBSCALE) & 255] * turbsin[(int)((wv[1]*0.125f+realtime) * TURBSCALE) & 255] * (1.0f / 64.0f); + wv[2] += r_waterripple.value * turbsin[(int)((wv[0]*(1.0f/32.0f)+realtime) * TURBSCALE) & 255] * turbsin[(int)((wv[1]*(1.0f/32.0f)+realtime) * TURBSCALE) & 255] * (1.0f / 64.0f); wv[3] = wv[4] = wv[5] = 128.0f; wv += 6; } @@ -450,25 +452,12 @@ void R_WaterSurf(msurface_t *s, texture_t *t, qboolean transform, int alpha) R_LightSurface(s->dlightbits, s->polys, wvert); wv = wvert; // FIXME: make fog texture if water texture is transparent? - if (lighthalf) - { - for (p=s->polys ; p ; p=p->next) - { - transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA); - for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) - transpolyvert(wv[0], wv[1], wv[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), (int) wv[3] >> 1,(int) wv[4] >> 1,(int) wv[5] >> 1,alpha); - transpolyend(); - } - } - else + for (p=s->polys ; p ; p=p->next) { - for (p=s->polys ; p ; p=p->next) - { - transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA); - for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) - transpolyvert(wv[0], wv[1], wv[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), (int) wv[3],(int) wv[4],(int) wv[5],alpha); - transpolyend(); - } + transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA); + for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) + transpolyvert(wv[0], wv[1], wv[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), wv[3], wv[4], wv[5], alpha); + transpolyend(); } } @@ -606,52 +595,24 @@ void R_WallSurfVertex(msurface_t *s, texture_t *t, qboolean transform, qboolean wv = wvert; if (isbmodel && (currententity->colormod[0] != 1 || currententity->colormod[1] != 1 || currententity->colormod[2] != 1)) { - if (lighthalf) + for (p = s->polys;p;p = p->next) { - for (p = s->polys;p;p = p->next) - { - v = p->verts[0]; - transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); - for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) - transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], (int) (wv[3] * currententity->colormod[0]) >> 1,(int) (wv[4] * currententity->colormod[1]) >> 1,(int) (wv[5] * currententity->colormod[0]) >> 1,alpha); - transpolyend(); - } - } - else - { - for (p = s->polys;p;p = p->next) - { - v = p->verts[0]; - transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); - for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) - transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], (int) (wv[3] * currententity->colormod[0]),(int) (wv[4] * currententity->colormod[1]),(int) (wv[5] * currententity->colormod[2]),alpha); - transpolyend(); - } + v = p->verts[0]; + transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); + for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) + transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], wv[3] * currententity->colormod[0], wv[4] * currententity->colormod[1], wv[5] * currententity->colormod[2], alpha); + transpolyend(); } } else { - if (lighthalf) + for (p = s->polys;p;p = p->next) { - for (p = s->polys;p;p = p->next) - { - v = p->verts[0]; - transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); - for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) - transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], (int) wv[3] >> 1,(int) wv[4] >> 1,(int) wv[5] >> 1,alpha); - transpolyend(); - } - } - else - { - for (p = s->polys;p;p = p->next) - { - v = p->verts[0]; - transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); - for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) - transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], (int) wv[3],(int) wv[4],(int) wv[5],alpha); - transpolyend(); - } + v = p->verts[0]; + transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA); + for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE, wv += 6) + transpolyvert(wv[0], wv[1], wv[2], v[3], v[4], wv[3], wv[4], wv[5], alpha); + transpolyend(); } } } @@ -664,6 +625,28 @@ DrawTextureChains extern qboolean hlbsp; extern char skyname[]; //extern qboolean SV_TestLine (hull_t *hull, int num, vec3_t p1, vec3_t p2); +void R_DrawSurf(msurface_t *s, qboolean isbmodel, qboolean vertexlit) +{ + texture_t *t; + if (s->flags & SURF_DRAWSKY) + { + skyisvisible = true; + if (!hlbsp) // LordHavoc: HalfLife maps have freaky skypolys... + R_SkySurf(s, false); + return; + } + t = R_TextureAnimation (s->texinfo->texture); + if (s->flags & SURF_DRAWTURB) + { + R_WaterSurf(s, t, false, s->flags & SURF_DRAWNOALPHA ? 255 : r_wateralpha.value*255.0f); + return; + } + if (vertexlit) + R_WallSurfVertex(s, t, false, false); + else + R_WallSurf(s, t, false); +} + void DrawTextureChains (void) { int n; @@ -674,9 +657,10 @@ void DrawTextureChains (void) { if (!cl.worldmodel->textures[n] || !(s = cl.worldmodel->textures[n]->texturechain)) continue; - // LordHavoc: decide the render type only once, because the surface properties were determined by texture anyway cl.worldmodel->textures[n]->texturechain = NULL; - t = R_TextureAnimation (cl.worldmodel->textures[n]); +// for (;s;s = s->texturechain) +// R_DrawSurf(s, false, gl_vertex.value); + // LordHavoc: decide the render type only once, because the surface properties were determined by texture anyway // sky if (s->flags & SURF_DRAWSKY) { @@ -686,6 +670,7 @@ void DrawTextureChains (void) R_SkySurf(s, false); continue; } + t = R_TextureAnimation (cl.worldmodel->textures[n]); // subdivided water surface warp if (s->flags & SURF_DRAWTURB) { @@ -779,6 +764,7 @@ e->angles[0] = -e->angles[0]; // stupid quake bug { if (((s->flags & SURF_PLANEBACK) == 0) == (PlaneDiff(modelorg, s->plane) >= 0)) { +// R_DrawSurf(s, true, vertexlit || s->texinfo->texture->transparent); if (s->flags & SURF_DRAWSKY) { R_SkySurf(s, true); @@ -894,8 +880,13 @@ loc0: { if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK)) { - surf->texturechain = surf->texinfo->texture->texturechain; - surf->texinfo->texture->texturechain = surf; + if (gl_texsort.value) + { + surf->texturechain = surf->texinfo->texture->texturechain; + surf->texinfo->texture->texturechain = surf; + } + else + R_DrawSurf(surf, false, gl_vertex.value); } } } @@ -905,8 +896,13 @@ loc0: { if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK)) { - surf->texturechain = surf->texinfo->texture->texturechain; - surf->texinfo->texture->texturechain = surf; + if (gl_texsort.value) + { + surf->texturechain = surf->texinfo->texture->texturechain; + surf->texinfo->texture->texturechain = surf; + } + else + R_DrawSurf(surf, false, gl_vertex.value); } } } diff --git a/host_cmd.c b/host_cmd.c index 5f0ab5fb..c08e9212 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -26,6 +26,8 @@ int current_skill; void Mod_Print (void); +dfunction_t *ED_FindFunction (char *name); + /* ================== Host_Quit_f @@ -848,6 +850,8 @@ void Host_Color_f(void) { int top, bottom; int playercolor; + dfunction_t *f; + func_t SV_ChangeTeam; if (Cmd_Argc() == 1) { @@ -883,13 +887,25 @@ void Host_Color_f(void) return; } - host_client->colors = playercolor; - host_client->edict->v.team = bottom + 1; + // void(float color) SV_ChangeTeam; + if ((f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions))) + { + Con_DPrintf("Calling SV_ChangeTeam\n"); + pr_global_struct->time = sv.time; + pr_globals[0] = playercolor; + pr_global_struct->self = EDICT_TO_PROG(host_client->edict); + PR_ExecuteProgram (SV_ChangeTeam); + } + else + { + host_client->colors = playercolor; + host_client->edict->v.team = bottom + 1; -// send notification to all clients - MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors); - MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients); - MSG_WriteByte (&sv.reliable_datagram, host_client->colors); + // send notification to all clients + MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors); + MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients); + MSG_WriteByte (&sv.reliable_datagram, host_client->colors); + } } /* @@ -979,8 +995,6 @@ void Host_PreSpawn_f (void) host_client->sendsignon = true; } -dfunction_t *ED_FindFunction (char *name); - /* ================== Host_Spawn_f diff --git a/model_brush.c b/model_brush.c index 82c2eb34..03f9dc92 100644 --- a/model_brush.c +++ b/model_brush.c @@ -340,8 +340,6 @@ void Mod_LoadLighting (lump_t *l) byte d; char litfilename[1024]; loadmodel->lightdata = NULL; - if (!l->filelen) - return; if (hlbsp) // LordHavoc: load the colored lighting data straight { loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname); @@ -361,6 +359,7 @@ void Mod_LoadLighting (lump_t *l) i = LittleLong(((int *)data)[1]); if (i == 1) { + Con_DPrintf("%s loaded", litfilename); loadmodel->lightdata = data + 8; return; } @@ -371,6 +370,8 @@ void Mod_LoadLighting (lump_t *l) Con_Printf("Corrupt .lit file (old version?), ignoring\n"); } // LordHavoc: oh well, expand the white lighting data + if (!l->filelen) + return; loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename); in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write out = loadmodel->lightdata; -- 2.39.2