- int i, lit = false, polys = 0, verts = 0;
- float *v, *wv;
- glpoly_t *p;
- wallpoly_t *wp;
- wallvert_t *out;
- // check for lightmap modification
- if (r_dynamic.value)
- {
- if (s->cached_dlight
- || (r_dlightmap.value && s->dlightframe == r_dlightframecount)
- || r_ambient.value != s->cached_ambient
- || lighthalf != s->cached_lighthalf
- || (s->styles[0] != 255 && d_lightstylevalue[s->styles[0]] != s->cached_light[0])
- || (s->styles[1] != 255 && d_lightstylevalue[s->styles[1]] != s->cached_light[1])
- || (s->styles[2] != 255 && d_lightstylevalue[s->styles[2]] != s->cached_light[2])
- || (s->styles[3] != 255 && d_lightstylevalue[s->styles[3]] != s->cached_light[3]))
- R_UpdateLightmap(s, s->lightmaptexturenum);
- }
- wv = wvert;
- for (p = s->polys;p;p = p->next)
- {
- for (i = 0, v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
- {
- if (transform)
- softwaretransform(v, wv);
- else
- VectorCopy(v, wv);
- wv[3] = wv[4] = wv[5] = 0.0f;
- wv += 6;
- }
- verts += p->numverts;
- polys++;
- }
- if ((currentwallpoly + polys > MAX_WALLPOLYS) || (currentwallvert+verts > MAX_WALLVERTS))
- return;
- if ((!r_dlightmap.value) && s->dlightframe == r_dlightframecount)
- lit = RSurf_Light(s->dlightbits, s->polys);
- wv = wvert;
- wp = &wallpoly[currentwallpoly];
- out = &wallvert[currentwallvert];
- currentwallpoly += polys;
- for (p = s->polys;p;p = p->next)
- {
- v = p->verts[0];
- wp->texnum = (unsigned short) t->gl_texturenum;
- wp->lighttexnum = (unsigned short) (lightmap_textures + s->lightmaptexturenum);
- wp->glowtexnum = (unsigned short) t->gl_glowtexturenum;
- wp->firstvert = currentwallvert;
- wp->numverts = p->numverts;
- wp->lit = lit;
- wp++;
- currentwallvert += p->numverts;
- for (i = 0;i < p->numverts;i++, v += VERTEXSIZE, wv += 6, out++)
- {
- if (lit)
- {
- if (lighthalf)
- {
- out->r = (byte) (bound(0, (int) wv[3] >> 1, 255));
- out->g = (byte) (bound(0, (int) wv[4] >> 1, 255));
- out->b = (byte) (bound(0, (int) wv[5] >> 1, 255));
- out->a = 255;
- }
- else
- {
- out->r = (byte) (bound(0, (int) wv[3], 255));
- out->g = (byte) (bound(0, (int) wv[4], 255));
- out->b = (byte) (bound(0, (int) wv[5], 255));
- out->a = 255;
- }
- }
- out->vert[0] = wv[0];
- out->vert[1] = wv[1];
- out->vert[2] = wv[2];
- out->s = v[3];
- out->t = v[4];
- out->u = v[5];
- out->v = v[6];
- }