+ // first the sky
+ skypolyclear();
+ for (j = 0;j < cl.worldmodel->numtextures;j++)
+ {
+ if (!cl.worldmodel->textures[j] || !(s = cl.worldmodel->textures[j]->texturechain))
+ continue;
+ // LordHavoc: decide the render type only once, because the surface properties were determined by texture anyway
+ // subdivided water surface warp
+ if (s->flags & SURF_DRAWSKY)
+ {
+ cl.worldmodel->textures[j]->texturechain = NULL;
+ t = R_TextureAnimation (cl.worldmodel->textures[j]);
+ skyisvisible = true;
+ if (!hlbsp) // LordHavoc: HalfLife maps have freaky skypolys...
+ {
+ for (;s;s = s->texturechain)
+ {
+ for (p=s->polys ; p ; p=p->next)
+ {
+ if (currentskypoly < MAX_SKYPOLYS && currentskyvert + p->numverts <= MAX_SKYVERTS)
+ {
+ skypoly[currentskypoly].firstvert = currentskyvert;
+ skypoly[currentskypoly++].verts = p->numverts;
+ for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
+ {
+ skyvert[currentskyvert].v[0] = v[0];
+ skyvert[currentskyvert].v[1] = v[1];
+ skyvert[currentskyvert++].v[2] = v[2];
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ skypolyrender(); // fogged sky polys, affects depth
+
+ if (skyname[0] && skyisvisible && !fogenabled)
+ R_Sky(); // does not affect depth, draws over the sky polys
+
+ // then walls
+ wallpolyclear();
+ for (j = 0;j < cl.worldmodel->numtextures;j++)
+ {
+ if (!cl.worldmodel->textures[j] || !(s = cl.worldmodel->textures[j]->texturechain))
+ continue;
+ if (!(s->flags & SURF_DRAWTURB))
+ {
+ cl.worldmodel->textures[j]->texturechain = NULL;
+ t = R_TextureAnimation (cl.worldmodel->textures[j]);
+ c_brush_polys++;
+ for (;s;s = s->texturechain)
+ {
+ if (currentwallpoly < MAX_WALLPOLYS && currentwallvert < MAX_WALLVERTS && (currentwallvert + s->polys->numverts) <= MAX_WALLVERTS)
+ {
+ // check for lightmap modification
+// if (r_dynamic.value)
+// {
+ if (s->dlightframe == r_framecount || s->cached_dlight || lighthalf != s->cached_lighthalf) // dynamic this frame or previously, or lighthalf changed
+ R_UpdateLightmap(s, s->lightmaptexturenum);
+ else
+ for (maps = 0 ; maps < MAXLIGHTMAPS && s->styles[maps] != 255 ; maps++)
+ if (d_lightstylevalue[s->styles[maps]] != s->cached_light[maps])
+ {
+ R_UpdateLightmap(s, s->lightmaptexturenum);
+ break;
+ }
+// }
+ wallpoly[currentwallpoly].texnum = (unsigned short) t->gl_texturenum;
+ wallpoly[currentwallpoly].lighttexnum = (unsigned short) lightmap_textures + s->lightmaptexturenum;
+ wallpoly[currentwallpoly].glowtexnum = (unsigned short) t->gl_glowtexturenum;
+ wallpoly[currentwallpoly].firstvert = currentwallvert;
+ wallpoly[currentwallpoly++].verts = s->polys->numverts;
+ for (i = 0,v = s->polys->verts[0];i<s->polys->numverts;i++, v += VERTEXSIZE)
+ {
+ wallvert[currentwallvert].vert[0] = v[0];
+ wallvert[currentwallvert].vert[1] = v[1];
+ wallvert[currentwallvert].vert[2] = v[2];
+ wallvert[currentwallvert].s = v[3];
+ wallvert[currentwallvert].t = v[4];
+ wallvert[currentwallvert].u = v[5];
+ wallvert[currentwallvert++].v = v[6];
+ }
+ }
+ }
+ }
+ }
+ UploadLightmaps();
+ wallpolyrender();
+
+ // then water (water gets diverted to transpoly list)