lighthalf related transpoly cleanup
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 31 Oct 2000 03:31:02 +0000 (03:31 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 31 Oct 2000 03:31:02 +0000 (03:31 +0000)
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
gl_poly.h
gl_rmain.c
gl_rsurf.c
host_cmd.c
model_brush.c

index d312335ec68ccf8397c19bcb0acee54e616fd662..3947bbd80fabb9dfc3e6c48b6fed04b987beddd5 100644 (file)
--- 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()
index 48cd07543f8029b1fc303c2aee8f95a3a3ad701c..53d6d81327bbf1b0efdbc32ac63f087e5a3198b3 100644 (file)
--- 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);\
index f7d2e0046c99216b2b73c26d6b0081c0374e23d4..753f34e798945f2013c83e5384646dc5d78ca2a4 100644 (file)
@@ -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();
index 4d1402e87842120aa50fae256eeb0a22d3a67a54..fe5bb6ca9f6127fa2a02f3fabbf080803c911b05 100644 (file)
@@ -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);
                                        }
                                }
                        }
index 5f0ab5fb2a0d428bab9eb7fc6593faae3b76a0e7..c08e92125405bcbb31a682cc5b70a47858a8d28f 100644 (file)
@@ -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
index 82c2eb342b88738c392cf90db67890ad04ffd059..03f9dc924accca934e7dac81a0d1701a7a66f711 100644 (file)
@@ -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;