2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // r_surf.c: surface-related refresh code
26 int lightmap_textures;
28 signed blocklights[18*18*3]; // LordHavoc: *3 for colored lighting
30 // LordHavoc: skinny but tall lightmaps for quicker subimage uploads
31 #define BLOCK_WIDTH 128
32 #define BLOCK_HEIGHT 128
33 // LordHavoc: increased lightmap limit from 64 to 1024
34 #define MAX_LIGHTMAPS 1024
35 #define LIGHTMAPSIZE (BLOCK_WIDTH*BLOCK_HEIGHT*3)
39 short allocated[MAX_LIGHTMAPS][BLOCK_WIDTH];
41 byte *lightmaps[MAX_LIGHTMAPS];
43 int lightmapalign, lightmapalignmask; // LordHavoc: NVIDIA's broken subimage fix, see BuildLightmaps for notes
44 cvar_t gl_lightmapalign = {"gl_lightmapalign", "4"};
45 cvar_t gl_lightmaprgba = {"gl_lightmaprgba", "1"};
46 cvar_t gl_nosubimagefragments = {"gl_nosubimagefragments", "0"};
48 qboolean lightmaprgba, nosubimagefragments;
51 qboolean skyisvisible;
52 extern qboolean gl_arrays;
57 for (i = 0;i < MAX_LIGHTMAPS;i++)
58 lightmaps[i] = (byte *) NULL;
59 Cvar_RegisterVariable(&gl_lightmapalign);
60 Cvar_RegisterVariable(&gl_lightmaprgba);
61 Cvar_RegisterVariable(&gl_nosubimagefragments);
62 // check if it's the glquake minigl driver
63 if (strnicmp(gl_vendor,"3Dfx",4)==0)
66 Cvar_SetValue("gl_nosubimagefragments", 1);
67 Cvar_SetValue("gl_lightmode", 0);
71 int dlightdivtable[8192];
72 int dlightdivtableinitialized = 0;
79 void R_AddDynamicLights (msurface_t *surf)
81 int sdtable[18], lnum, td, maxdist, maxdist2, maxdist3, i, s, t, smax, tmax, red, green, blue, j;
85 // use 64bit integer... shame it's not very standardized...
92 if (!dlightdivtableinitialized)
94 dlightdivtable[0] = 1048576 >> 7;
95 for (s = 1;s < 8192;s++)
96 dlightdivtable[s] = 1048576 / (s << 7);
97 dlightdivtableinitialized = 1;
100 smax = (surf->extents[0]>>4)+1;
101 tmax = (surf->extents[1]>>4)+1;
103 for (lnum=0 ; lnum<MAX_DLIGHTS ; lnum++)
105 if ( !(surf->dlightbits[lnum >> 5] & (1<<(lnum&31)) ) )
106 continue; // not lit by this light
108 VectorSubtract(cl_dlights[lnum].origin, currententity->origin, local);
109 dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
110 for (i=0 ; i<3 ; i++)
111 impact[i] = cl_dlights[lnum].origin[i] - surf->plane->normal[i]*dist;
113 f = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
116 // reduce calculations
118 for (s = 0;s < smax;s++, i -= 16)
119 sdtable[s] = i*i + t;
121 f = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
124 maxdist = (int) (cl_dlights[lnum].radius*cl_dlights[lnum].radius); // for comparisons to minimum acceptable light
125 // clamp radius to avoid exceeding 8192 entry division table
126 if (maxdist > 1048576)
128 maxdist3 = maxdist - (int) (dist*dist);
129 // convert to 8.8 blocklights format
130 if (!cl_dlights[lnum].dark)
132 f = cl_dlights[lnum].color[0] * maxdist;red = f;
133 f = cl_dlights[lnum].color[1] * maxdist;green = f;
134 f = cl_dlights[lnum].color[2] * maxdist;blue = f;
136 else // negate for darklight
138 f = cl_dlights[lnum].color[0] * -maxdist;red = f;
139 f = cl_dlights[lnum].color[1] * -maxdist;green = f;
140 f = cl_dlights[lnum].color[2] * -maxdist;blue = f;
143 for (t = 0;t < tmax;t++,i -= 16)
146 if (td < maxdist3) // make sure some part of it is visible on this line
148 maxdist2 = maxdist - td;
149 for (s = 0;s < smax;s++)
151 if (sdtable[s] < maxdist2)
153 j = dlightdivtable[(sdtable[s]+td) >> 7];
154 k = (red * j) >> 8;bl[0] += k;
155 k = (green * j) >> 8;bl[1] += k;
156 k = (blue * j) >> 8;bl[2] += k;
162 bl+=smax*3; // skip line
167 extern qboolean lighthalf;
172 Combine and scale multiple lightmaps into the 8.8 format in blocklights
175 void R_BuildLightMap (msurface_t *surf, byte *dest, int stride)
185 surf->cached_dlight = (surf->dlightframe == r_framecount);
186 surf->cached_lighthalf = lighthalf;
188 smax = (surf->extents[0]>>4)+1;
189 tmax = (surf->extents[1]>>4)+1;
191 lightmap = surf->samples;
193 // set to full bright if no light data
194 if (currententity->effects & EF_FULLBRIGHT || !cl.worldmodel->lightdata)
197 for (i=0 ; i<size ; i++)
208 for (i=0 ; i<size ; i++)
215 // add all the lightmaps
217 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++)
219 scale = d_lightstylevalue[surf->styles[maps]];
220 surf->cached_light[maps] = scale; // 8.8 fraction
222 for (i=0 ; i<size ; i++)
224 *bl++ += *lightmap++ * scale;
225 *bl++ += *lightmap++ * scale;
226 *bl++ += *lightmap++ * scale;
230 // add all the dynamic lights
231 if (surf->dlightframe == r_framecount)
232 R_AddDynamicLights (surf);
234 stride -= (smax*lightmapbytes);
238 // LordHavoc: I shift down by 8 unlike GLQuake's 7,
239 // the image is brightened as a processing pass
242 for (i=0 ; i<tmax ; i++, dest += stride)
244 for (j=0 ; j<smax ; j++)
246 t = *bl++ >> 8;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
247 t = *bl++ >> 8;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
248 t = *bl++ >> 8;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
255 for (i=0 ; i<tmax ; i++, dest += stride)
257 for (j=0 ; j<smax ; j++)
259 t = *bl++ >> 8;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
260 t = *bl++ >> 8;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
261 t = *bl++ >> 8;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
270 for (i=0 ; i<tmax ; i++, dest += stride)
272 for (j=0 ; j<smax ; j++)
274 t = *bl++ >> 7;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
275 t = *bl++ >> 7;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
276 t = *bl++ >> 7;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
283 for (i=0 ; i<tmax ; i++, dest += stride)
285 for (j=0 ; j<smax ; j++)
287 t = *bl++ >> 7;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
288 t = *bl++ >> 7;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
289 t = *bl++ >> 7;if (t > 255) t = 255;else if (t < 0) t = 0;*dest++ = t;
296 byte templight[32*32*4];
298 void R_UpdateLightmap(msurface_t *s, int lnum)
301 // upload the new lightmap texture fragment
302 glBindTexture(GL_TEXTURE_2D, lightmap_textures + lnum);
303 if (nosubimagefragments)
305 smax = (s->extents[0]>>4)+1;
306 tmax = (s->extents[1]>>4)+1;
309 R_BuildLightMap (s, lightmaps[s->lightmaptexturenum] + (s->light_t * BLOCK_WIDTH + s->light_s) * 4, BLOCK_WIDTH * 4);
310 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, s->light_t, BLOCK_WIDTH, tmax, GL_RGBA, GL_UNSIGNED_BYTE, lightmaps[s->lightmaptexturenum] + s->light_t * (BLOCK_WIDTH * 4));
314 R_BuildLightMap (s, lightmaps[s->lightmaptexturenum] + (s->light_t * BLOCK_WIDTH + s->light_s) * 3, BLOCK_WIDTH * 3);
315 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, s->light_t, BLOCK_WIDTH, tmax, GL_RGB , GL_UNSIGNED_BYTE, lightmaps[s->lightmaptexturenum] + s->light_t * (BLOCK_WIDTH * 3));
320 smax = ((s->extents[0]>>4)+lightmapalign) & lightmapalignmask;
321 tmax = (s->extents[1]>>4)+1;
324 R_BuildLightMap (s, templight, smax * 4);
325 glTexSubImage2D(GL_TEXTURE_2D, 0, s->light_s, s->light_t, smax, tmax, GL_RGBA, GL_UNSIGNED_BYTE, templight);
329 R_BuildLightMap (s, templight, smax * 3);
330 glTexSubImage2D(GL_TEXTURE_2D, 0, s->light_s, s->light_t, smax, tmax, GL_RGB , GL_UNSIGNED_BYTE, templight);
340 Returns the proper texture for a given time and base texture
343 texture_t *R_TextureAnimation (texture_t *base)
349 if (currententity->frame)
351 if (base->alternate_anims)
352 base = base->alternate_anims;
355 if (!base->anim_total)
360 relative = (int)(cl.time*10) % base->anim_total;
363 while (base->anim_min > relative || base->anim_max <= relative)
365 base = base->anim_next;
368 Con_Printf("R_TextureAnimation: broken cycle");
373 Con_Printf("R_TextureAnimation: infinite cycle");
383 =============================================================
387 =============================================================
391 extern int solidskytexture;
392 extern int alphaskytexture;
393 extern float speedscale; // for top sky and bottom sky
395 qboolean mtexenabled = false;
397 extern char skyname[];
399 void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits);
400 //extern cvar_t r_dynamicwater;
401 extern int r_dlightframecount;
404 #include "gl_warp_sin.h"
406 #define TURBSCALE (256.0 / (2 * M_PI))
414 extern qboolean hlbsp;
415 void DrawTextureChains (void)
422 float os = turbsin[(int)(realtime * TURBSCALE) & 255], ot = turbsin[(int)(realtime * TURBSCALE + 96.0) & 255];
424 for (j = 0;j < cl.worldmodel->numtextures;j++)
426 if (!cl.worldmodel->textures[j] || !(s = cl.worldmodel->textures[j]->texturechain))
428 cl.worldmodel->textures[j]->texturechain = NULL;
429 t = R_TextureAnimation (cl.worldmodel->textures[j]);
430 // LordHavoc: decide the render type only once, because the surface properties were determined by texture anyway
431 // subdivided water surface warp
432 if (s->flags & SURF_DRAWTURB)
434 int light, alpha, r, g, b;
435 vec3_t nv, shadecolor;
436 alpha = s->flags & SURF_DRAWNOALPHA ? 255 : r_wateralpha.value*255.0f;
438 if (s->flags & SURF_DRAWFULLBRIGHT)
439 r = g = b = lighthalf ? 128 : 255;
440 else if (s->dlightframe == r_dlightframecount/* && r_dynamicwater.value*/)
443 r = g = b = lighthalf ? 64 : 128;
444 if (r_waterripple.value)
450 for (;s;s = s->texturechain)
452 for (p=s->polys ; p ; p=p->next)
454 // FIXME: could be a transparent water texture
455 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA);
456 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
460 nv[2] = v[2] + r_waterripple.value * turbsin[(int)((v[3]*0.125f+realtime) * TURBSCALE) & 255] * turbsin[(int)((v[4]*0.125f+realtime) * TURBSCALE) & 255] * (1.0f / 64.0f);
461 shadecolor[0] = shadecolor[1] = shadecolor[2] = 128;
462 R_DynamicLightPoint(shadecolor, nv, s->dlightbits);
463 transpolyvert(nv[0], nv[1], nv[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), (int) shadecolor[0] >> 1,(int) shadecolor[1] >> 1,(int) shadecolor[2] >> 1,alpha);
471 for (;s;s = s->texturechain)
473 for (p=s->polys ; p ; p=p->next)
475 // FIXME: could be a transparent water texture
476 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA);
477 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
481 nv[2] = v[2] + r_waterripple.value * turbsin[(int)((v[3]*0.125f+realtime) * TURBSCALE) & 255] * turbsin[(int)((v[4]*0.125f+realtime) * TURBSCALE) & 255] * (1.0f / 64.0f);
482 transpolyvert(nv[0], nv[1], nv[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), r,g,b,alpha);
493 for (;s;s = s->texturechain)
495 for (p=s->polys ; p ; p=p->next)
497 // FIXME: could be a transparent water texture
498 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA);
499 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
503 nv[2] = v[2] + r_waterripple.value * turbsin[(int)((v[3]*0.125f+realtime) * TURBSCALE) & 255] * turbsin[(int)((v[4]*0.125f+realtime) * TURBSCALE) & 255] * (1.0f / 64.0f);
504 shadecolor[0] = shadecolor[1] = shadecolor[2] = 128;
505 R_DynamicLightPoint(shadecolor, nv, s->dlightbits);
506 transpolyvert(nv[0], nv[1], nv[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), shadecolor[0],shadecolor[1],shadecolor[2],alpha);
514 for (;s;s = s->texturechain)
516 for (p=s->polys ; p ; p=p->next)
518 // FIXME: could be a transparent water texture
519 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA);
520 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
524 nv[2] = v[2] + r_waterripple.value * turbsin[(int)((v[3]*0.125f+realtime) * TURBSCALE) & 255] * turbsin[(int)((v[4]*0.125f+realtime) * TURBSCALE) & 255] * (1.0f / 64.0f);
525 transpolyvert(nv[0], nv[1], nv[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), r,g,b,alpha);
539 for (;s;s = s->texturechain)
541 for (p=s->polys ; p ; p=p->next)
543 // FIXME: could be a transparent water texture
544 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA);
545 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
547 shadecolor[0] = shadecolor[1] = shadecolor[2] = 128;
548 R_DynamicLightPoint(shadecolor, v, s->dlightbits);
549 transpolyvert(v[0], v[1], v[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), (int) shadecolor[0] >> 1,(int) shadecolor[1] >> 1,(int) shadecolor[2] >> 1,alpha);
557 for (;s;s = s->texturechain)
559 for (p=s->polys ; p ; p=p->next)
561 // FIXME: could be a transparent water texture
562 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA);
563 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
565 transpolyvert(v[0], v[1], v[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), r,g,b,alpha);
576 for (;s;s = s->texturechain)
578 for (p=s->polys ; p ; p=p->next)
580 // FIXME: could be a transparent water texture
581 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA);
582 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
584 shadecolor[0] = shadecolor[1] = shadecolor[2] = 128;
585 R_DynamicLightPoint(shadecolor, v, s->dlightbits);
586 transpolyvert(v[0], v[1], v[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), shadecolor[0],shadecolor[1],shadecolor[2],alpha);
594 for (;s;s = s->texturechain)
596 for (p=s->polys ; p ; p=p->next)
598 // FIXME: could be a transparent water texture
599 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, TPOLYTYPE_ALPHA);
600 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
602 transpolyvert(v[0], v[1], v[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), r,g,b,alpha);
611 else if (s->flags & SURF_DRAWSKY)
614 if (!hlbsp) // LordHavoc: HalfLife maps have freaky skypolys...
616 for (;s;s = s->texturechain)
618 for (p=s->polys ; p ; p=p->next)
620 if (currentskypoly < MAX_SKYPOLYS && currentskyvert + p->numverts <= MAX_SKYVERTS)
622 skypoly[currentskypoly].firstvert = currentskyvert;
623 skypoly[currentskypoly++].verts = p->numverts;
624 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
626 skyvert[currentskyvert].v[0] = v[0];
627 skyvert[currentskyvert].v[1] = v[1];
628 skyvert[currentskyvert++].v[2] = v[2];
638 for (;s;s = s->texturechain)
640 if (currentwallpoly < MAX_WALLPOLYS && currentwallvert < MAX_WALLVERTS && (currentwallvert + s->polys->numverts) <= MAX_WALLVERTS)
642 // check for lightmap modification
643 // if (r_dynamic.value)
645 if (s->dlightframe == r_framecount || s->cached_dlight || lighthalf != s->cached_lighthalf) // dynamic this frame or previously, or lighthalf changed
646 R_UpdateLightmap(s, s->lightmaptexturenum);
648 for (maps = 0 ; maps < MAXLIGHTMAPS && s->styles[maps] != 255 ; maps++)
649 if (d_lightstylevalue[s->styles[maps]] != s->cached_light[maps])
651 R_UpdateLightmap(s, s->lightmaptexturenum);
655 wallpoly[currentwallpoly].texnum = (unsigned short) t->gl_texturenum;
656 wallpoly[currentwallpoly].lighttexnum = (unsigned short) lightmap_textures + s->lightmaptexturenum;
657 wallpoly[currentwallpoly].glowtexnum = (unsigned short) t->gl_glowtexturenum;
658 wallpoly[currentwallpoly].firstvert = currentwallvert;
659 wallpoly[currentwallpoly++].verts = s->polys->numverts;
660 for (i = 0,v = s->polys->verts[0];i<s->polys->numverts;i++, v += VERTEXSIZE)
662 wallvert[currentwallvert].vert[0] = v[0];
663 wallvert[currentwallvert].vert[1] = v[1];
664 wallvert[currentwallvert].vert[2] = v[2];
665 wallvert[currentwallvert].s = v[3];
666 wallvert[currentwallvert].t = v[4];
667 wallvert[currentwallvert].u = v[5];
668 wallvert[currentwallvert++].v = v[6];
676 // LordHavoc: transparent brush models
677 extern int r_dlightframecount;
678 extern float modelalpha;
679 extern vec3_t shadecolor;
680 //qboolean R_CullBox (vec3_t mins, vec3_t maxs);
681 void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits);
682 void R_DynamicLightPointNoMask(vec3_t color, vec3_t org);
683 void EmitWaterPolys (msurface_t *fa);
684 void R_MarkLights (vec3_t lightorigin, dlight_t *light, int bit, int bitindex, mnode_t *node);
691 void R_DrawBrushModel (entity_t *e)
693 int i, j, k, smax, tmax, size3, maps;
694 vec3_t mins, maxs, nv;
698 qboolean rotated, vertexlit = false;
699 float dot, *v, scale;
702 float os = turbsin[(int)(realtime * TURBSCALE) & 255], ot = turbsin[(int)(realtime * TURBSCALE + 96.0) & 255];
708 if (e->angles[0] || e->angles[1] || e->angles[2])
711 for (i=0 ; i<3 ; i++)
713 mins[i] = e->origin[i] - clmodel->radius;
714 maxs[i] = e->origin[i] + clmodel->radius;
720 VectorAdd (e->origin, clmodel->mins, mins);
721 VectorAdd (e->origin, clmodel->maxs, maxs);
724 if (R_CullBox (mins, maxs))
727 VectorSubtract (r_refdef.vieworg, e->origin, modelorg);
731 vec3_t forward, right, up;
733 VectorCopy (modelorg, temp);
734 AngleVectors (e->angles, forward, right, up);
735 modelorg[0] = DotProduct (temp, forward);
736 modelorg[1] = -DotProduct (temp, right);
737 modelorg[2] = DotProduct (temp, up);
740 s = &clmodel->surfaces[clmodel->firstmodelsurface];
742 // calculate dynamic lighting for bmodel if it's not an
744 if (modelalpha == 1 && clmodel->firstmodelsurface != 0 && !(currententity->effects & EF_FULLBRIGHT) && currententity->colormod[0] == 1 && currententity->colormod[2] == 1 && currententity->colormod[2] == 1)
746 // if (!gl_flashblend.value)
749 for (k=0 ; k<MAX_DLIGHTS ; k++)
751 if ((cl_dlights[k].die < cl.time) || (!cl_dlights[k].radius))
754 VectorSubtract(cl_dlights[k].origin, currententity->origin, org);
755 R_MarkLights (org, &cl_dlights[k], 1<<(k&31), k >> 5, clmodel->nodes + clmodel->hulls[0].firstclipnode);
762 e->angles[0] = -e->angles[0]; // stupid quake bug
763 softwaretransformforentity (e);
764 e->angles[0] = -e->angles[0]; // stupid quake bug
767 for (j = 0;j < clmodel->nummodelsurfaces;j++, s++)
769 // find which side of the node we are on
772 dot = DotProduct (modelorg, pplane->normal) - pplane->dist;
775 if (((s->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
776 (!(s->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON)))
778 if (s->flags & SURF_DRAWSKY)
780 if (s->flags & SURF_DRAWTURB)
783 int light, alpha, r, g, b;
786 if (s->flags & SURF_DRAWNOALPHA)
787 alpha = modelalpha*255.0f;
789 alpha = r_wateralpha.value*modelalpha*255.0f;
791 if (s->flags & SURF_DRAWFULLBRIGHT || currententity->effects & EF_FULLBRIGHT)
795 r = 128.0f * currententity->colormod[0];
796 g = 128.0f * currententity->colormod[1];
797 b = 128.0f * currententity->colormod[2];
801 r = 255.0f * currententity->colormod[0];
802 g = 255.0f * currententity->colormod[1];
803 b = 255.0f * currententity->colormod[2];
806 else if (s->dlightframe == r_dlightframecount/* && r_dynamicwater.value*/)
812 r = 64.0f * currententity->colormod[0];
813 g = 64.0f * currententity->colormod[1];
814 b = 64.0f * currententity->colormod[2];
818 r = 128.0f * currententity->colormod[0];
819 g = 128.0f * currententity->colormod[1];
820 b = 128.0f * currententity->colormod[2];
823 for (p=s->polys ; p ; p=p->next)
825 // FIXME: could be a transparent water texture
826 transpolybegin(s->texinfo->texture->gl_texturenum, s->texinfo->texture->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA);
827 for (i = 0,v = p->verts[0];i < p->numverts;i++, v += VERTEXSIZE)
829 softwaretransform(v, nv);
830 if (r_waterripple.value)
831 nv[2] += r_waterripple.value * turbsin[(int)((v[3]*0.125f+realtime) * TURBSCALE) & 255] * turbsin[(int)((v[4]*0.125f+realtime) * TURBSCALE) & 255] * (1.0f / 64.0f);
834 shadecolor[0] = shadecolor[1] = shadecolor[2] = 128;
835 R_DynamicLightPoint(shadecolor, nv, s->dlightbits);
838 r = (int) ((float) (shadecolor[0] * currententity->colormod[0])) >> 1;
839 g = (int) ((float) (shadecolor[1] * currententity->colormod[1])) >> 1;
840 b = (int) ((float) (shadecolor[2] * currententity->colormod[2])) >> 1;
844 r = (int) ((float) (shadecolor[0] * currententity->colormod[0]));
845 g = (int) ((float) (shadecolor[1] * currententity->colormod[1]));
846 b = (int) ((float) (shadecolor[2] * currententity->colormod[2]));
849 transpolyvert(nv[0], nv[1], nv[2], (v[3] + os) * (1.0f/64.0f), (v[4] + ot) * (1.0f/64.0f), r,g,b,alpha);
856 t = R_TextureAnimation (s->texinfo->texture);
857 v = s->polys->verts[0];
858 if (vertexlit || s->texinfo->texture->transparent)
860 // FIXME: could be a transparent water texture
861 transpolybegin(t->gl_texturenum, t->gl_glowtexturenum, 0, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA);
862 if ((currententity->effects & EF_FULLBRIGHT) || !s->samples)
864 for (i = 0;i < s->polys->numverts;i++, v += VERTEXSIZE)
866 softwaretransform(v, nv);
867 transpolyvert(nv[0], nv[1], nv[2], v[3], v[4], 255,255,255,modelalpha*255.0f);
872 smax = (s->extents[0]>>4)+1;
873 tmax = (s->extents[1]>>4)+1;
874 size3 = smax*tmax*3; // *3 for colored lighting
875 for (i = 0;i < s->polys->numverts;i++, v += VERTEXSIZE)
877 shadecolor[0] = shadecolor[1] = shadecolor[2] = 0;
878 lm = (byte *)((long) s->samples + ((int) v[8] * smax + (int) v[7]) * 3); // LordHavoc: *3 for colored lighting
879 for (maps = 0;maps < MAXLIGHTMAPS && s->styles[maps] != 255;maps++)
881 scale = d_lightstylevalue[s->styles[maps]] * (1.0 / 128.0);
882 shadecolor[0] += lm[0] * scale;
883 shadecolor[1] += lm[1] * scale;
884 shadecolor[2] += lm[2] * scale;
885 lm += size3; // LordHavoc: *3 for colored lighting
887 softwaretransform(v, nv);
888 R_DynamicLightPointNoMask(shadecolor, nv); // LordHavoc: dynamic lighting
891 transpolyvert(nv[0], nv[1], nv[2], v[3], v[4], (int) shadecolor[0] >> 1, (int) shadecolor[1] >> 1, (int) shadecolor[2] >> 1, modelalpha*255.0f);
895 transpolyvert(nv[0], nv[1], nv[2], v[3], v[4], shadecolor[0], shadecolor[1], shadecolor[2], modelalpha*255.0f);
903 // check for lightmap modification
904 // if (r_dynamic.value)
906 if (s->dlightframe == r_framecount || s->cached_dlight || lighthalf != s->cached_lighthalf) // dynamic this frame or previously, or lighthalf changed
907 R_UpdateLightmap(s, s->lightmaptexturenum);
909 for (maps = 0 ; maps < MAXLIGHTMAPS && s->styles[maps] != 255 ; maps++)
910 if (d_lightstylevalue[s->styles[maps]] != s->cached_light[maps])
912 R_UpdateLightmap(s, s->lightmaptexturenum);
916 if (currentwallpoly < MAX_WALLPOLYS && (currentwallvert + s->polys->numverts) <= MAX_WALLVERTS)
918 wallpoly[currentwallpoly].texnum = (unsigned short) t->gl_texturenum;
919 wallpoly[currentwallpoly].lighttexnum = (unsigned short) lightmap_textures + s->lightmaptexturenum;
920 wallpoly[currentwallpoly].glowtexnum = (unsigned short) t->gl_glowtexturenum;
921 wallpoly[currentwallpoly].firstvert = currentwallvert;
922 wallpoly[currentwallpoly++].verts = s->polys->numverts;
923 for (i = 0;i<s->polys->numverts;i++, v += VERTEXSIZE)
925 softwaretransform(v, wallvert[currentwallvert].vert);
926 wallvert[currentwallvert].s = v[3];
927 wallvert[currentwallvert].t = v[4];
928 wallvert[currentwallvert].u = v[5];
929 wallvert[currentwallvert++].v = v[6];
938 =============================================================
942 =============================================================
945 void R_StoreEfrags (efrag_t **ppefrag);
952 //extern qboolean R_CullBox (vec3_t mins, vec3_t maxs);
954 void R_RecursiveWorldNode (mnode_t *node)
960 // if a leaf node, draw stuff
961 if (node->contents < 0)
964 pleaf = (mleaf_t *)node;
966 if (c = pleaf->nummarksurfaces)
969 mark = pleaf->firstmarksurface;
972 (*mark)->visframe = r_framecount;
977 // deal with model fragments in this leaf
979 R_StoreEfrags (&pleaf->efrags);
984 // node is just a decision point, so go down the apropriate sides
986 // find which side of the node we are on
987 dot = (node->plane->type < 3 ? modelorg[node->plane->type] : DotProduct (modelorg, node->plane->normal)) - node->plane->dist;
989 // recurse down the children, front side first
991 // LordHavoc: save a stack frame by avoiding a call
992 // if (node->children[side]->contents != CONTENTS_SOLID && node->children[side]->visframe == r_visframecount && !R_CullBox (node->children[side]->minmaxs, node->children[side]->minmaxs+3))
993 // LordHavoc: inlined further to reduce conditions
994 if (node->children[side]->contents != CONTENTS_SOLID
995 && node->children[side]->visframe == r_visframecount
996 && frustum[0].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[0]) != 2
997 && frustum[1].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[1]) != 2
998 && frustum[2].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[2]) != 2
999 && frustum[3].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[3]) != 2)
1000 R_RecursiveWorldNode (node->children[side]);
1005 if (c = node->numsurfaces)
1008 surf = cl.worldmodel->surfaces + node->firstsurface;
1010 // LordHavoc: caused a crash due to texsort (it could render twice...)
1012 //side = dot >= -BACKFACE_EPSILON;
1015 for (;c;c--, surf++)
1017 if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK))
1019 surf->texturechain = surf->texinfo->texture->texturechain;
1020 surf->texinfo->texture->texturechain = surf;
1026 for (;c;c--, surf++)
1028 if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK))
1030 surf->texturechain = surf->texinfo->texture->texturechain;
1031 surf->texinfo->texture->texturechain = surf;
1037 // recurse down the back side
1038 // LordHavoc: save a stack frame by avoiding a call
1039 // if (node->children[side]->contents != CONTENTS_SOLID && node->children[side]->visframe == r_visframecount && !R_CullBox (node->children[side]->minmaxs, node->children[side]->minmaxs+3))
1040 // LordHavoc: inlined further to reduce conditions
1041 if (node->children[side]->contents != CONTENTS_SOLID
1042 && node->children[side]->visframe == r_visframecount
1043 && frustum[0].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[0]) != 2
1044 && frustum[1].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[1]) != 2
1045 && frustum[2].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[2]) != 2
1046 && frustum[3].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[3]) != 2)
1048 node = node->children[side];
1051 // R_RecursiveWorldNode (node->children[side]);
1068 if (!(node = cl.worldmodel->nodes))
1073 // if a leaf node, draw stuff
1075 if (node->contents < 0)
1077 if (node->contents != CONTENTS_SOLID)
1080 pleaf = (mleaf_t *)node;
1082 if (c = pleaf->nummarksurfaces)
1085 mark = pleaf->firstmarksurface;
1088 (*mark)->visframe = r_framecount;
1093 // deal with model fragments in this leaf
1095 R_StoreEfrags (&pleaf->efrags);
1100 node = nodestack[--s].node;
1101 dot = nodestack[s].dot;
1105 // node is just a decision point, so go down the apropriate sides
1107 // find which side of the node we are on
1108 dot = (node->plane->type < 3 ? modelorg[node->plane->type] : DotProduct (modelorg, node->plane->normal)) - node->plane->dist;
1110 // recurse down the children, front side first
1112 if (node->children[side]->visframe == r_visframecount
1113 && frustum[0].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[0]) != 2
1114 && frustum[1].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[1]) != 2
1115 && frustum[2].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[2]) != 2
1116 && frustum[3].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[3]) != 2)
1118 nodestack[s].node = node;
1119 nodestack[s++].dot = dot;
1120 node = node->children[side];
1128 if (c = node->numsurfaces)
1131 surf = cl.worldmodel->surfaces + node->firstsurface;
1135 for (;c;c--, surf++)
1137 if (surf->visframe == r_framecount && !(surf->flags & SURF_PLANEBACK))
1139 surf->texturechain = surf->texinfo->texture->texturechain;
1140 surf->texinfo->texture->texturechain = surf;
1146 for (;c;c--, surf++)
1148 if (surf->visframe == r_framecount && (surf->flags & SURF_PLANEBACK))
1150 surf->texturechain = surf->texinfo->texture->texturechain;
1151 surf->texinfo->texture->texturechain = surf;
1157 // recurse down the back side
1158 if (node->children[side]->visframe == r_visframecount
1159 && frustum[0].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[0]) != 2
1160 && frustum[1].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[1]) != 2
1161 && frustum[2].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[2]) != 2
1162 && frustum[3].BoxOnPlaneSideFunc(node->children[side]->minmaxs, node->children[side]->minmaxs+3, &frustum[3]) != 2)
1164 node = node->children[side];
1170 node = nodestack[--s].node;
1171 dot = nodestack[s].dot;
1182 extern void R_Sky();
1183 void R_DrawWorld (void)
1187 memset (&ent, 0, sizeof(ent));
1188 ent.model = cl.worldmodel;
1189 ent.colormod[0] = ent.colormod[1] = ent.colormod[2] = 1;
1190 modelalpha = ent.alpha = 1;
1193 VectorCopy (r_refdef.vieworg, modelorg);
1195 currententity = &ent;
1197 softwaretransformidentity(); // LordHavoc: clear transform
1199 skyisvisible = false;
1204 DrawTextureChains ();
1206 glClear (GL_DEPTH_BUFFER_BIT);
1208 skypolyrender(); // fogged sky polys, affects depth
1210 if (skyisvisible && !fogenabled)
1211 R_Sky(); // does not affect depth, draws over the sky polys
1213 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1214 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1223 void R_MarkLeaves (void)
1229 if (r_oldviewleaf == r_viewleaf && !r_novis.value)
1233 r_oldviewleaf = r_viewleaf;
1237 for (i=0 ; i<cl.worldmodel->numleafs ; i++)
1239 node = (mnode_t *)&cl.worldmodel->leafs[i+1];
1242 if (node->visframe == r_visframecount)
1244 node->visframe = r_visframecount;
1245 node = node->parent;
1251 vis = Mod_LeafPVS (r_viewleaf, cl.worldmodel);
1253 for (i=0 ; i<cl.worldmodel->numleafs ; i++)
1255 if (vis[i>>3] & (1<<(i&7)))
1257 node = (mnode_t *)&cl.worldmodel->leafs[i+1];
1260 if (node->visframe == r_visframecount)
1262 node->visframe = r_visframecount;
1263 node = node->parent;
1273 =============================================================================
1277 =============================================================================
1280 // returns a texture number and the position inside it
1281 int AllocBlock (int w, int h, int *x, int *y)
1287 for (texnum=0 ; texnum<MAX_LIGHTMAPS ; texnum++)
1289 best = BLOCK_HEIGHT;
1291 for (i=0 ; i<BLOCK_WIDTH-w ; i+=lightmapalign) // LordHavoc: NVIDIA has broken subimage, so align the lightmaps
1295 for (j=0 ; j<w ; j++)
1297 if (allocated[texnum][i+j] >= best)
1299 if (allocated[texnum][i+j] > best2)
1300 best2 = allocated[texnum][i+j];
1303 { // this is a valid spot
1309 if (best + h > BLOCK_HEIGHT)
1312 if (gl_nosubimagefragments.value)
1313 if (!lightmaps[texnum])
1314 lightmaps[texnum] = calloc(BLOCK_WIDTH*BLOCK_HEIGHT*4, 1);
1315 // LordHavoc: clear texture to blank image, fragments are uploaded using subimage
1316 if (!allocated[texnum][0])
1318 byte blank[BLOCK_WIDTH*BLOCK_HEIGHT*3];
1319 memset(blank, 0, sizeof(blank));
1320 glBindTexture(GL_TEXTURE_2D, lightmap_textures + texnum);
1321 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1322 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1324 glTexImage2D (GL_TEXTURE_2D, 0, 4, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, blank);
1326 glTexImage2D (GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, blank);
1329 for (i=0 ; i<w ; i++)
1330 allocated[texnum][*x + i] = best + h;
1335 Sys_Error ("AllocBlock: full");
1339 mvertex_t *r_pcurrentvertbase;
1340 model_t *currentmodel;
1346 BuildSurfaceDisplayList
1349 void BuildSurfaceDisplayList (msurface_t *fa)
1351 int i, lindex, lnumverts;
1352 medge_t *pedges, *r_pedge;
1358 // reconstruct the polygon
1359 pedges = currentmodel->edges;
1360 lnumverts = fa->numedges;
1366 poly = Hunk_Alloc (sizeof(glpoly_t) + (lnumverts-4) * VERTEXSIZE*sizeof(float));
1367 poly->next = fa->polys;
1368 poly->flags = fa->flags;
1370 poly->numverts = lnumverts;
1372 for (i=0 ; i<lnumverts ; i++)
1374 lindex = currentmodel->surfedges[fa->firstedge + i];
1378 r_pedge = &pedges[lindex];
1379 vec = r_pcurrentvertbase[r_pedge->v[0]].position;
1383 r_pedge = &pedges[-lindex];
1384 vec = r_pcurrentvertbase[r_pedge->v[1]].position;
1386 s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
1387 s /= fa->texinfo->texture->width;
1389 t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
1390 t /= fa->texinfo->texture->height;
1392 VectorCopy (vec, poly->verts[i]);
1393 poly->verts[i][3] = s;
1394 poly->verts[i][4] = t;
1397 // lightmap texture coordinates
1399 s = DotProduct (vec, fa->texinfo->vecs[0]) + fa->texinfo->vecs[0][3];
1400 s -= fa->texturemins[0];
1401 poly->verts[i][7] = bound(0l, ((int)s>>4), (fa->extents[0]>>4)); // LordHavoc: raw lightmap coordinates
1402 s += fa->light_s*16;
1404 s /= BLOCK_WIDTH*16; //fa->texinfo->texture->width;
1406 t = DotProduct (vec, fa->texinfo->vecs[1]) + fa->texinfo->vecs[1][3];
1407 t -= fa->texturemins[1];
1408 poly->verts[i][8] = bound(0l, ((int)t>>4), (fa->extents[1]>>4)); // LordHavoc: raw lightmap coordinates
1409 t += fa->light_t*16;
1411 t /= BLOCK_HEIGHT*16; //fa->texinfo->texture->height;
1413 poly->verts[i][5] = s;
1414 poly->verts[i][6] = t;
1418 // remove co-linear points - Ed
1421 if (!gl_keeptjunctions.value)
1423 for (i = 0 ; i < lnumverts ; ++i)
1426 float *prev, *this, *next;
1428 prev = poly->verts[(i + lnumverts - 1) % lnumverts];
1429 this = poly->verts[i];
1430 next = poly->verts[(i + 1) % lnumverts];
1432 VectorSubtract( this, prev, v1 );
1433 VectorNormalize( v1 );
1434 VectorSubtract( next, prev, v2 );
1435 VectorNormalize( v2 );
1437 // skip co-linear points
1438 #define COLINEAR_EPSILON 0.001
1439 if ((fabs( v1[0] - v2[0] ) <= COLINEAR_EPSILON) &&
1440 (fabs( v1[1] - v2[1] ) <= COLINEAR_EPSILON) &&
1441 (fabs( v1[2] - v2[2] ) <= COLINEAR_EPSILON))
1444 for (j = i + 1; j < lnumverts; ++j)
1447 for (k = 0; k < VERTEXSIZE; ++k)
1448 poly->verts[j - 1][k] = poly->verts[j][k];
1452 // retry next vertex next time, which is now current vertex
1458 poly->numverts = lnumverts;
1463 ========================
1464 GL_CreateSurfaceLightmap
1465 ========================
1467 void GL_CreateSurfaceLightmap (msurface_t *surf)
1471 if (surf->flags & (SURF_DRAWSKY|SURF_DRAWTURB))
1474 smax = (surf->extents[0]>>4)+1;
1475 tmax = (surf->extents[1]>>4)+1;
1477 surf->lightmaptexturenum = AllocBlock (smax, tmax, &surf->light_s, &surf->light_t);
1478 glBindTexture(GL_TEXTURE_2D, lightmap_textures + surf->lightmaptexturenum);
1479 if (nosubimagefragments)
1483 R_BuildLightMap (surf, lightmaps[surf->lightmaptexturenum] + (surf->light_t * BLOCK_WIDTH + surf->light_s) * 4, BLOCK_WIDTH * 4);
1484 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, surf->light_t, BLOCK_WIDTH, tmax, GL_RGBA, GL_UNSIGNED_BYTE, lightmaps[surf->lightmaptexturenum] + surf->light_t * (BLOCK_WIDTH * 4));
1488 R_BuildLightMap (surf, lightmaps[surf->lightmaptexturenum] + (surf->light_t * BLOCK_WIDTH + surf->light_s) * 3, BLOCK_WIDTH * 3);
1489 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, surf->light_t, BLOCK_WIDTH, tmax, GL_RGB , GL_UNSIGNED_BYTE, lightmaps[surf->lightmaptexturenum] + surf->light_t * (BLOCK_WIDTH * 3));
1494 smax = ((surf->extents[0]>>4)+lightmapalign) & lightmapalignmask;
1497 R_BuildLightMap (surf, templight, smax * 4);
1498 glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t, smax, tmax, GL_RGBA, GL_UNSIGNED_BYTE, templight);
1502 R_BuildLightMap (surf, templight, smax * 3);
1503 glTexSubImage2D(GL_TEXTURE_2D, 0, surf->light_s, surf->light_t, smax, tmax, GL_RGB , GL_UNSIGNED_BYTE, templight);
1513 Builds the lightmap texture
1514 with all the surfaces from all brush models
1517 void GL_BuildLightmaps (void)
1522 memset (allocated, 0, sizeof(allocated));
1524 r_framecount = 1; // no dlightcache
1526 if (gl_nosubimagefragments.value)
1527 nosubimagefragments = 1;
1529 nosubimagefragments = 0;
1531 if (gl_lightmaprgba.value)
1533 lightmaprgba = true;
1538 lightmaprgba = false;
1542 // LordHavoc: NVIDIA seems to have a broken glTexSubImage2D,
1543 // it needs to be aligned on 4 pixel boundaries...
1544 // so I implemented an adjustable lightmap alignment
1545 if (gl_lightmapalign.value < 1)
1546 gl_lightmapalign.value = 1;
1547 if (gl_lightmapalign.value > 16)
1548 gl_lightmapalign.value = 16;
1550 while (lightmapalign < gl_lightmapalign.value)
1551 lightmapalign <<= 1;
1552 gl_lightmapalign.value = lightmapalign;
1553 lightmapalignmask = ~(lightmapalign - 1);
1554 if (nosubimagefragments)
1557 lightmapalignmask = ~0;
1560 if (!lightmap_textures)
1562 lightmap_textures = texture_extension_number;
1563 texture_extension_number += MAX_LIGHTMAPS;
1566 for (j=1 ; j<MAX_MODELS ; j++)
1568 m = cl.model_precache[j];
1571 if (m->name[0] == '*')
1573 r_pcurrentvertbase = m->vertexes;
1575 for (i=0 ; i<m->numsurfaces ; i++)
1577 if ( m->surfaces[i].flags & SURF_DRAWTURB )
1579 if ( m->surfaces[i].flags & SURF_DRAWSKY )
1581 GL_CreateSurfaceLightmap (m->surfaces + i);
1582 BuildSurfaceDisplayList (m->surfaces + i);