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
25 #define MAX_LIGHTMAP_SIZE 256
27 static unsigned int intblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting
28 static float floatblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting
30 static qbyte templight[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*4];
32 cvar_t r_ambient = {0, "r_ambient", "0"};
33 cvar_t r_drawportals = {0, "r_drawportals", "0"};
34 cvar_t r_testvis = {0, "r_testvis", "0"};
35 cvar_t r_floatbuildlightmap = {0, "r_floatbuildlightmap", "0"};
36 cvar_t r_detailtextures = {CVAR_SAVE, "r_detailtextures", "1"};
37 cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "0"};
38 cvar_t r_drawcollisionbrushes_polygonfactor = {0, "r_drawcollisionbrushes_polygonfactor", "-1"};
39 cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "0"};
40 cvar_t r_q3bsp_renderskydepth = {0, "r_q3bsp_renderskydepth", "0"};
41 cvar_t gl_lightmaps = {0, "gl_lightmaps", "0"};
44 // FIXME: these arrays are huge!
45 int r_q1bsp_maxmarkleafs;
46 int r_q1bsp_nummarkleafs;
47 mleaf_t *r_q1bsp_maxleaflist[65536];
48 int r_q1bsp_maxmarksurfaces;
49 int r_q1bsp_nummarksurfaces;
50 msurface_t *r_q1bsp_maxsurfacelist[65536];
52 // FIXME: these arrays are huge!
53 int r_q3bsp_maxmarkleafs;
54 int r_q3bsp_nummarkleafs;
55 q3mleaf_t *r_q3bsp_maxleaflist[65536];
56 int r_q3bsp_maxmarksurfaces;
57 int r_q3bsp_nummarksurfaces;
58 q3msurface_t *r_q3bsp_maxsurfacelist[65536];
61 static int dlightdivtable[32768];
63 static int R_IntAddDynamicLights (const matrix4x4_t *matrix, msurface_t *surf)
65 int sdtable[256], lnum, td, maxdist, maxdist2, maxdist3, i, s, t, smax, tmax, smax3, red, green, blue, lit, dist2, impacts, impactt, subtract, k;
67 float dist, impact[3], local[3];
72 smax = (surf->extents[0] >> 4) + 1;
73 tmax = (surf->extents[1] >> 4) + 1;
76 for (lnum = 0, light = r_dlight;lnum < r_numdlights;lnum++, light++)
78 if (!(surf->dlightbits[lnum >> 5] & (1 << (lnum & 31))))
79 continue; // not lit by this light
81 Matrix4x4_Transform(matrix, light->origin, local);
82 dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
84 // for comparisons to minimum acceptable light
85 // compensate for LIGHTOFFSET
86 maxdist = (int) light->rtlight.lightmap_cullradius2 + LIGHTOFFSET;
93 if (surf->plane->type < 3)
95 VectorCopy(local, impact);
96 impact[surf->plane->type] -= dist;
100 impact[0] = local[0] - surf->plane->normal[0] * dist;
101 impact[1] = local[1] - surf->plane->normal[1] * dist;
102 impact[2] = local[2] - surf->plane->normal[2] * dist;
105 impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
106 impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
108 s = bound(0, impacts, smax * 16) - impacts;
109 t = bound(0, impactt, tmax * 16) - impactt;
110 i = s * s + t * t + dist2;
114 // reduce calculations
115 for (s = 0, i = impacts; s < smax; s++, i -= 16)
116 sdtable[s] = i * i + dist2;
118 maxdist3 = maxdist - dist2;
120 // convert to 8.8 blocklights format
121 red = light->rtlight.lightmap_light[0] * (1.0f / 128.0f);
122 green = light->rtlight.lightmap_light[1] * (1.0f / 128.0f);
123 blue = light->rtlight.lightmap_light[2] * (1.0f / 128.0f);
124 subtract = (int) (light->rtlight.lightmap_subtract * 4194304.0f);
128 for (t = 0;t < tmax;t++, i -= 16)
131 // make sure some part of it is visible on this line
134 maxdist2 = maxdist - td;
135 for (s = 0;s < smax;s++)
137 if (sdtable[s] < maxdist2)
139 k = dlightdivtable[(sdtable[s] + td) >> 7] - subtract;
143 bl[1] += (green * k);
158 static int R_FloatAddDynamicLights (const matrix4x4_t *matrix, msurface_t *surf)
160 int lnum, s, t, smax, tmax, smax3, lit, impacts, impactt;
161 float sdtable[256], *bl, k, dist, dist2, maxdist, maxdist2, maxdist3, td1, td, red, green, blue, impact[3], local[3], subtract;
166 smax = (surf->extents[0] >> 4) + 1;
167 tmax = (surf->extents[1] >> 4) + 1;
170 for (lnum = 0, light = r_dlight;lnum < r_numdlights;lnum++, light++)
172 if (!(surf->dlightbits[lnum >> 5] & (1 << (lnum & 31))))
173 continue; // not lit by this light
175 Matrix4x4_Transform(matrix, light->origin, local);
176 dist = DotProduct (local, surf->plane->normal) - surf->plane->dist;
178 // for comparisons to minimum acceptable light
179 // compensate for LIGHTOFFSET
180 maxdist = (int) light->rtlight.lightmap_cullradius2 + LIGHTOFFSET;
183 dist2 += LIGHTOFFSET;
184 if (dist2 >= maxdist)
187 if (surf->plane->type < 3)
189 VectorCopy(local, impact);
190 impact[surf->plane->type] -= dist;
194 impact[0] = local[0] - surf->plane->normal[0] * dist;
195 impact[1] = local[1] - surf->plane->normal[1] * dist;
196 impact[2] = local[2] - surf->plane->normal[2] * dist;
199 impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
200 impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
202 td = bound(0, impacts, smax * 16) - impacts;
203 td1 = bound(0, impactt, tmax * 16) - impactt;
204 td = td * td + td1 * td1 + dist2;
208 // reduce calculations
209 for (s = 0, td1 = impacts; s < smax; s++, td1 -= 16.0f)
210 sdtable[s] = td1 * td1 + dist2;
212 maxdist3 = maxdist - dist2;
214 // convert to 8.8 blocklights format
215 red = light->rtlight.lightmap_light[0];
216 green = light->rtlight.lightmap_light[1];
217 blue = light->rtlight.lightmap_light[2];
218 subtract = light->rtlight.lightmap_subtract * 32768.0f;
219 bl = floatblocklights;
222 for (t = 0;t < tmax;t++, td1 -= 16.0f)
225 // make sure some part of it is visible on this line
228 maxdist2 = maxdist - td;
229 for (s = 0;s < smax;s++)
231 if (sdtable[s] < maxdist2)
233 k = (32768.0f / (sdtable[s] + td)) - subtract;
253 Combine and scale multiple lightmaps into the 8.8 format in blocklights
256 static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surf)
258 if (!r_floatbuildlightmap.integer)
260 int smax, tmax, i, j, size, size3, maps, stride, l;
261 unsigned int *bl, scale;
262 qbyte *lightmap, *out, *stain;
264 // update cached lighting info
265 surf->cached_dlight = 0;
267 smax = (surf->extents[0]>>4)+1;
268 tmax = (surf->extents[1]>>4)+1;
271 lightmap = surf->samples;
273 // set to full bright if no light data
275 if (!ent->model->brushq1.lightdata)
277 for (i = 0;i < size3;i++)
283 memset(bl, 0, size*3*sizeof(unsigned int));
285 if (surf->dlightframe == r_framecount)
287 surf->cached_dlight = R_IntAddDynamicLights(&ent->inversematrix, surf);
288 if (surf->cached_dlight)
292 // add all the lightmaps
296 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++, lightmap += size3)
297 for (scale = d_lightstylevalue[surf->styles[maps]], i = 0;i < size3;i++)
298 bl[i] += lightmap[i] * scale;
302 stain = surf->stainsamples;
305 // the >> 16 shift adjusts down 8 bits to account for the stainmap
306 // scaling, and remaps the 0-65536 (2x overbright) to 0-256, it will
307 // be doubled during rendering to achieve 2x overbright
308 // (0 = 0.0, 128 = 1.0, 256 = 2.0)
309 if (ent->model->brushq1.lightmaprgba)
311 stride = (surf->lightmaptexturestride - smax) * 4;
312 for (i = 0;i < tmax;i++, out += stride)
314 for (j = 0;j < smax;j++)
316 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
317 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
318 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
325 stride = (surf->lightmaptexturestride - smax) * 3;
326 for (i = 0;i < tmax;i++, out += stride)
328 for (j = 0;j < smax;j++)
330 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
331 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
332 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
337 R_UpdateTexture(surf->lightmaptexture, templight);
341 int smax, tmax, i, j, size, size3, maps, stride, l;
343 qbyte *lightmap, *out, *stain;
345 // update cached lighting info
346 surf->cached_dlight = 0;
348 smax = (surf->extents[0]>>4)+1;
349 tmax = (surf->extents[1]>>4)+1;
352 lightmap = surf->samples;
354 // set to full bright if no light data
355 bl = floatblocklights;
356 if (!ent->model->brushq1.lightdata)
358 for (i = 0;i < size3;i++)
363 memset(bl, 0, size*3*sizeof(float));
365 if (surf->dlightframe == r_framecount)
367 surf->cached_dlight = R_FloatAddDynamicLights(&ent->inversematrix, surf);
368 if (surf->cached_dlight)
372 // add all the lightmaps
375 bl = floatblocklights;
376 for (maps = 0;maps < MAXLIGHTMAPS && surf->styles[maps] != 255;maps++, lightmap += size3)
377 for (scale = d_lightstylevalue[surf->styles[maps]], i = 0;i < size3;i++)
378 bl[i] += lightmap[i] * scale;
382 stain = surf->stainsamples;
383 bl = floatblocklights;
385 // this scaling adjusts down 8 bits to account for the stainmap
386 // scaling, and remaps the 0.0-2.0 (2x overbright) to 0-256, it will
387 // be doubled during rendering to achieve 2x overbright
388 // (0 = 0.0, 128 = 1.0, 256 = 2.0)
389 scale = 1.0f / (1 << 16);
390 if (ent->model->brushq1.lightmaprgba)
392 stride = (surf->lightmaptexturestride - smax) * 4;
393 for (i = 0;i < tmax;i++, out += stride)
395 for (j = 0;j < smax;j++)
397 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
398 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
399 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
406 stride = (surf->lightmaptexturestride - smax) * 3;
407 for (i = 0;i < tmax;i++, out += stride)
409 for (j = 0;j < smax;j++)
411 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
412 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
413 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
418 R_UpdateTexture(surf->lightmaptexture, templight);
422 void R_StainNode (mnode_t *node, model_t *model, const vec3_t origin, float radius, const float fcolor[8])
424 float ndist, a, ratio, maxdist, maxdist2, maxdist3, invradius, sdtable[256], td, dist2;
425 msurface_t *surf, *endsurf;
426 int i, s, t, smax, tmax, smax3, impacts, impactt, stained;
430 maxdist = radius * radius;
431 invradius = 1.0f / radius;
436 ndist = PlaneDiff(origin, node->plane);
439 node = node->children[0];
444 node = node->children[1];
448 dist2 = ndist * ndist;
449 maxdist3 = maxdist - dist2;
451 if (node->plane->type < 3)
453 VectorCopy(origin, impact);
454 impact[node->plane->type] -= ndist;
458 impact[0] = origin[0] - node->plane->normal[0] * ndist;
459 impact[1] = origin[1] - node->plane->normal[1] * ndist;
460 impact[2] = origin[2] - node->plane->normal[2] * ndist;
463 for (surf = model->brushq1.surfaces + node->firstsurface, endsurf = surf + node->numsurfaces;surf < endsurf;surf++)
465 if (surf->stainsamples)
467 smax = (surf->extents[0] >> 4) + 1;
468 tmax = (surf->extents[1] >> 4) + 1;
470 impacts = DotProduct (impact, surf->texinfo->vecs[0]) + surf->texinfo->vecs[0][3] - surf->texturemins[0];
471 impactt = DotProduct (impact, surf->texinfo->vecs[1]) + surf->texinfo->vecs[1][3] - surf->texturemins[1];
473 s = bound(0, impacts, smax * 16) - impacts;
474 t = bound(0, impactt, tmax * 16) - impactt;
475 i = s * s + t * t + dist2;
479 // reduce calculations
480 for (s = 0, i = impacts; s < smax; s++, i -= 16)
481 sdtable[s] = i * i + dist2;
483 bl = surf->stainsamples;
488 for (t = 0;t < tmax;t++, i -= 16)
491 // make sure some part of it is visible on this line
494 maxdist2 = maxdist - td;
495 for (s = 0;s < smax;s++)
497 if (sdtable[s] < maxdist2)
499 ratio = lhrandom(0.0f, 1.0f);
500 a = (fcolor[3] + ratio * fcolor[7]) * (1.0f - sqrt(sdtable[s] + td) * invradius);
501 if (a >= (1.0f / 64.0f))
505 bl[0] = (qbyte) ((float) bl[0] + a * ((fcolor[0] + ratio * fcolor[4]) - (float) bl[0]));
506 bl[1] = (qbyte) ((float) bl[1] + a * ((fcolor[1] + ratio * fcolor[5]) - (float) bl[1]));
507 bl[2] = (qbyte) ((float) bl[2] + a * ((fcolor[2] + ratio * fcolor[6]) - (float) bl[2]));
517 // force lightmap upload
519 surf->cached_dlight = true;
523 if (node->children[0]->plane)
525 if (node->children[1]->plane)
527 R_StainNode(node->children[0], model, origin, radius, fcolor);
528 node = node->children[1];
533 node = node->children[0];
537 else if (node->children[1]->plane)
539 node = node->children[1];
544 void R_Stain (const vec3_t origin, float radius, int cr1, int cg1, int cb1, int ca1, int cr2, int cg2, int cb2, int ca2)
548 entity_render_t *ent;
551 if (r_refdef.worldmodel == NULL || !r_refdef.worldmodel->brushq1.nodes)
556 fcolor[3] = ca1 * (1.0f / 64.0f);
557 fcolor[4] = cr2 - cr1;
558 fcolor[5] = cg2 - cg1;
559 fcolor[6] = cb2 - cb1;
560 fcolor[7] = (ca2 - ca1) * (1.0f / 64.0f);
562 R_StainNode(r_refdef.worldmodel->brushq1.nodes + r_refdef.worldmodel->brushq1.hulls[0].firstclipnode, r_refdef.worldmodel, origin, radius, fcolor);
564 // look for embedded bmodels
565 for (n = 0;n < cl_num_brushmodel_entities;n++)
567 ent = cl_brushmodel_entities[n];
569 if (model && model->name[0] == '*')
571 Mod_CheckLoaded(model);
572 if (model->brushq1.nodes)
574 Matrix4x4_Transform(&ent->inversematrix, origin, org);
575 R_StainNode(model->brushq1.nodes + model->brushq1.hulls[0].firstclipnode, model, org, radius, fcolor);
583 =============================================================
587 =============================================================
590 static void RSurf_AddLightmapToVertexColors_Color4f(const int *lightmapoffsets, float *c, int numverts, const qbyte *samples, int size3, const qbyte *styles)
595 if (styles[0] != 255)
597 for (i = 0;i < numverts;i++, c += 4)
599 lm = samples + lightmapoffsets[i];
600 scale = d_lightstylevalue[styles[0]] * (1.0f / 32768.0f);
601 VectorMA(c, scale, lm, c);
602 if (styles[1] != 255)
605 scale = d_lightstylevalue[styles[1]] * (1.0f / 32768.0f);
606 VectorMA(c, scale, lm, c);
607 if (styles[2] != 255)
610 scale = d_lightstylevalue[styles[2]] * (1.0f / 32768.0f);
611 VectorMA(c, scale, lm, c);
612 if (styles[3] != 255)
615 scale = d_lightstylevalue[styles[3]] * (1.0f / 32768.0f);
616 VectorMA(c, scale, lm, c);
624 static void RSurf_FogColors_Vertex3f_Color4f(const float *v, float *c, float colorscale, int numverts, const float *modelorg)
630 for (i = 0;i < numverts;i++, v += 3, c += 4)
632 VectorSubtract(v, modelorg, diff);
633 f = colorscale * (1 - exp(fogdensity/DotProduct(diff, diff)));
634 VectorScale(c, f, c);
637 else if (colorscale != 1)
638 for (i = 0;i < numverts;i++, c += 4)
639 VectorScale(c, colorscale, c);
642 static void RSurf_FoggedColors_Vertex3f_Color4f(const float *v, float *c, float r, float g, float b, float a, float colorscale, int numverts, const float *modelorg)
651 for (i = 0;i < numverts;i++, v += 3, c += 4)
653 VectorSubtract(v, modelorg, diff);
654 f = 1 - exp(fogdensity/DotProduct(diff, diff));
663 for (i = 0;i < numverts;i++, c += 4)
673 static void RSurf_FogPassColors_Vertex3f_Color4f(const float *v, float *c, float r, float g, float b, float a, float colorscale, int numverts, const float *modelorg)
680 for (i = 0;i < numverts;i++, v += 3, c += 4)
682 VectorSubtract(v, modelorg, diff);
683 f = exp(fogdensity/DotProduct(diff, diff));
691 static int RSurf_LightSeparate_Vertex3f_Color4f(const matrix4x4_t *matrix, const int *dlightbits, int numverts, const float *vert, float *color, float scale)
696 int i, l, lit = false;
697 const dlight_t *light;
699 for (l = 0;l < r_numdlights;l++)
701 if (dlightbits[l >> 5] & (1 << (l & 31)))
703 light = &r_dlight[l];
704 Matrix4x4_Transform(matrix, light->origin, lightorigin);
705 for (i = 0, v = vert, c = color;i < numverts;i++, v += 3, c += 4)
707 f = VectorDistance2(v, lightorigin) + LIGHTOFFSET;
708 if (f < light->rtlight.lightmap_cullradius2)
710 f = ((1.0f / f) - light->rtlight.lightmap_subtract) * scale;
711 VectorMA(c, f, light->rtlight.lightmap_light, c);
720 static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata2)
722 const entity_render_t *ent = calldata1;
723 const msurface_t *surf = ent->model->brushq1.surfaces + calldata2;
726 float base, colorscale;
729 float args[4] = {0.05f,0,0,0.04f};
730 int rendertype, turb, fullbright;
732 R_Mesh_Matrix(&ent->matrix);
733 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
735 texture = surf->texinfo->texture;
736 if (texture->animated)
737 texture = texture->anim_frames[ent->frame != 0][(texture->anim_total[ent->frame != 0] >= 2) ? ((int) (r_refdef.time * 5.0f) % texture->anim_total[ent->frame != 0]) : 0];
738 currentalpha = ent->alpha;
739 if (surf->flags & SURF_WATERALPHA)
740 currentalpha *= r_wateralpha.value;
742 GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
743 if (ent->effects & EF_ADDITIVE)
745 rendertype = SURFRENDER_ADD;
746 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
749 else if (currentalpha < 1 || texture->skin.fog != NULL)
751 rendertype = SURFRENDER_ALPHA;
752 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
757 rendertype = SURFRENDER_OPAQUE;
758 GL_BlendFunc(GL_ONE, GL_ZERO);
759 GL_DepthMask(!(ent->effects & EF_NODEPTHTEST));
762 turb = (surf->flags & SURF_DRAWTURB) && r_waterscroll.value;
763 fullbright = !(ent->flags & RENDER_LIGHT) || (surf->flags & SURF_DRAWFULLBRIGHT) || !surf->samples;
764 base = fullbright ? 2.0f : r_ambient.value * (1.0f / 64.0f);
765 if (surf->flags & SURF_DRAWTURB)
767 if ((surf->flags & SURF_DRAWTURB) && gl_textureshader && r_watershader.value && !fogenabled && fullbright && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
769 // NVIDIA Geforce3 distortion texture shader on water
770 GL_Color(1, 1, 1, currentalpha);
771 memset(&m, 0, sizeof(m));
772 m.pointer_vertex = surf->mesh.data_vertex3f;
773 m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(r_refdef.time * 16)&63]);
774 m.tex[1] = R_GetTexture(texture->skin.base);
775 m.texcombinergb[0] = GL_REPLACE;
776 m.texcombinergb[1] = GL_REPLACE;
777 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
778 m.pointer_texcoord[1] = surf->mesh.data_texcoordtexture2f;
779 Matrix4x4_CreateFromQuakeEntity(&m.texmatrix[0], 0, 0, 0, 0, 0, 0, r_watershader.value);
780 Matrix4x4_CreateTranslate(&m.texmatrix[1], sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
784 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
786 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
787 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
788 qglTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, &args[0]);
789 qglEnable(GL_TEXTURE_SHADER_NV);
791 GL_LockArrays(0, surf->mesh.num_vertices);
792 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
795 qglDisable(GL_TEXTURE_SHADER_NV);
796 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
801 memset(&m, 0, sizeof(m));
802 m.pointer_vertex = surf->mesh.data_vertex3f;
803 m.pointer_color = varray_color4f;
804 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
805 m.tex[0] = R_GetTexture(texture->skin.base);
808 // scrolling in texture matrix
809 Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
812 if (gl_combine.integer)
814 m.texrgbscale[0] = 4;
817 R_FillColors(varray_color4f, surf->mesh.num_vertices, base * ent->colormod[0], base * ent->colormod[1], base * ent->colormod[2], currentalpha);
820 if (surf->dlightframe == r_framecount)
821 RSurf_LightSeparate_Vertex3f_Color4f(&ent->inversematrix, surf->dlightbits, surf->mesh.num_vertices, surf->mesh.data_vertex3f, varray_color4f, 1);
823 RSurf_AddLightmapToVertexColors_Color4f(surf->mesh.data_lightmapoffsets, varray_color4f,surf->mesh.num_vertices, surf->samples, ((surf->extents[0]>>4)+1)*((surf->extents[1]>>4)+1)*3, surf->styles);
825 RSurf_FogColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, colorscale, surf->mesh.num_vertices, modelorg);
827 GL_LockArrays(0, surf->mesh.num_vertices);
828 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
830 if (texture->skin.glow)
832 memset(&m, 0, sizeof(m));
833 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
835 m.pointer_color = varray_color4f;
836 m.tex[0] = R_GetTexture(texture->skin.glow);
837 m.pointer_vertex = surf->mesh.data_vertex3f;
840 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
843 // scrolling in texture matrix
844 Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
848 RSurf_FoggedColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, 1, 1, 1, currentalpha, 1, surf->mesh.num_vertices, modelorg);
849 GL_LockArrays(0, surf->mesh.num_vertices);
850 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
853 if (fogenabled && rendertype != SURFRENDER_ADD)
855 memset(&m, 0, sizeof(m));
856 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
858 m.pointer_color = varray_color4f;
859 m.tex[0] = R_GetTexture(texture->skin.fog);
860 m.pointer_vertex = surf->mesh.data_vertex3f;
863 m.pointer_texcoord[0] = surf->mesh.data_texcoordtexture2f;
866 // scrolling in texture matrix
867 Matrix4x4_CreateTranslate(&m.texmatrix[0], sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
871 RSurf_FogPassColors_Vertex3f_Color4f(surf->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], currentalpha, 1, surf->mesh.num_vertices, modelorg);
872 GL_LockArrays(0, surf->mesh.num_vertices);
873 R_Mesh_Draw(surf->mesh.num_vertices, surf->mesh.num_triangles, surf->mesh.data_element3i);
879 void R_UpdateTextureInfo(entity_render_t *ent)
881 int i, texframe, alttextures;
887 alttextures = ent->frame != 0;
888 texframe = (int)(r_refdef.time * 5.0f);
889 for (i = 0;i < ent->model->brushq1.numtextures;i++)
891 t = ent->model->brushq1.textures + i;
892 t->currentalpha = ent->alpha;
893 if (t->flags & SURF_WATERALPHA)
894 t->currentalpha *= r_wateralpha.value;
895 if (ent->effects & EF_ADDITIVE)
896 t->rendertype = SURFRENDER_ADD;
897 else if (t->currentalpha < 1 || t->skin.fog != NULL)
898 t->rendertype = SURFRENDER_ALPHA;
900 t->rendertype = SURFRENDER_OPAQUE;
901 // we don't need to set currentframe if t->animated is false because
902 // it was already set up by the texture loader for non-animating
904 t->currentframe = t->anim_frames[alttextures][(t->anim_total[alttextures] >= 2) ? (texframe % t->anim_total[alttextures]) : 0];
908 void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenumsurfaces, msurface_t **texturesurfacelist)
910 int texturesurfaceindex;
911 vec3_t center, modelorg;
913 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
914 if (gl_lightmaps.integer)
916 GL_BlendFunc(GL_ONE, GL_ZERO);
919 GL_Color(1, 1, 1, 1);
920 memset(&m, 0, sizeof(m));
921 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
923 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
924 m.tex[0] = R_GetTexture(surface->lightmaptexture);
925 m.pointer_vertex = surface->mesh.data_vertex3f;
926 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
928 GL_LockArrays(0, surface->mesh.num_vertices);
929 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
933 else if (texture->rendertype != SURFRENDER_OPAQUE)
935 // transparent vertex shaded from lightmap
936 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
938 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
939 Matrix4x4_Transform(&ent->matrix, surface->poly_center, center);
940 R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->brushq1.surfaces);
943 else if (texture->flags & SURF_LIGHTMAP)
945 qboolean dolightmap = (ent->flags & RENDER_LIGHT);
946 qboolean dobase = true;
947 qboolean doambient = r_ambient.value > 0;
948 qboolean dodetail = r_detailtextures.integer != 0;
949 qboolean doglow = texture->skin.glow != NULL;
950 qboolean dofog = fogenabled;
951 // multitexture cases
952 if (r_textureunits.integer >= 2 && gl_combine.integer && dobase && dolightmap)
956 GL_BlendFunc(GL_ONE, GL_ZERO);
959 GL_Color(1, 1, 1, 1);
960 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
961 memset(&m, 0, sizeof(m));
962 m.tex[0] = R_GetTexture(texture->skin.base);
963 m.texrgbscale[1] = 2;
964 if (r_textureunits.integer >= 3 && !doambient && dodetail)
966 m.tex[2] = R_GetTexture(texture->skin.detail);
967 m.texrgbscale[2] = 2;
969 if (r_textureunits.integer >= 3 && texture->skin.glow)
971 m.tex[3] = R_GetTexture(texture->skin.glow);
972 m.texcombinergb[3] = GL_ADD;
974 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
976 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
977 m.tex[1] = R_GetTexture(surface->lightmaptexture);
978 m.pointer_vertex = surface->mesh.data_vertex3f;
979 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
980 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
981 m.pointer_texcoord[2] = surface->mesh.data_texcoorddetail2f;
982 m.pointer_texcoord[3] = surface->mesh.data_texcoordtexture2f;
984 GL_LockArrays(0, surface->mesh.num_vertices);
985 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
991 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
993 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
994 m.tex[1] = R_GetTexture(surface->lightmaptexture);
995 m.pointer_vertex = surface->mesh.data_vertex3f;
996 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
997 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
998 m.pointer_texcoord[2] = surface->mesh.data_texcoorddetail2f;
1000 GL_LockArrays(0, surface->mesh.num_vertices);
1001 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1002 GL_LockArrays(0, 0);
1006 else if (r_textureunits.integer >= 3 && !doambient && !dodetail && doglow)
1008 m.tex[2] = R_GetTexture(texture->skin.glow);
1009 m.texcombinergb[2] = GL_ADD;
1011 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1013 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1014 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1015 m.pointer_vertex = surface->mesh.data_vertex3f;
1016 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1017 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1018 m.pointer_texcoord[2] = surface->mesh.data_texcoordtexture2f;
1020 GL_LockArrays(0, surface->mesh.num_vertices);
1021 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1022 GL_LockArrays(0, 0);
1026 // anything not handled above
1029 GL_BlendFunc(GL_ONE, GL_ZERO);
1032 GL_Color(1, 1, 1, 1);
1033 if (ent->flags & RENDER_LIGHT)
1034 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1036 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
1037 memset(&m, 0, sizeof(m));
1038 m.tex[0] = R_GetTexture(texture->skin.base);
1039 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1041 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1042 m.pointer_vertex = surface->mesh.data_vertex3f;
1043 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1045 GL_LockArrays(0, surface->mesh.num_vertices);
1046 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1047 GL_LockArrays(0, 0);
1050 GL_DepthMask(false);
1053 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1054 GL_DepthMask(false);
1056 GL_Color(1, 1, 1, 1);
1057 memset(&m, 0, sizeof(m));
1058 m.tex[0] = R_GetTexture(texture->skin.base);
1059 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1061 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1062 m.tex[0] = R_GetTexture(surface->lightmaptexture);
1063 m.pointer_vertex = surface->mesh.data_vertex3f;
1064 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
1066 GL_LockArrays(0, surface->mesh.num_vertices);
1067 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1068 GL_LockArrays(0, 0);
1073 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1074 GL_DepthMask(false);
1076 memset(&m, 0, sizeof(m));
1077 GL_Color(r_ambient.value * (1.0f / 128.0f) * ent->colormod[0], r_ambient.value * (1.0f / 128.0f) * ent->colormod[1], r_ambient.value * (1.0f / 128.0f) * ent->colormod[2], 1);
1078 m.tex[0] = R_GetTexture(texture->skin.base);
1079 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1081 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1082 m.pointer_vertex = surface->mesh.data_vertex3f;
1083 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1085 GL_LockArrays(0, surface->mesh.num_vertices);
1086 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1087 GL_LockArrays(0, 0);
1092 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1093 GL_DepthMask(false);
1095 GL_Color(1, 1, 1, 1);
1096 memset(&m, 0, sizeof(m));
1097 m.tex[0] = R_GetTexture(texture->skin.detail);
1098 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1100 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1101 m.pointer_vertex = surface->mesh.data_vertex3f;
1102 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1104 GL_LockArrays(0, surface->mesh.num_vertices);
1105 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1106 GL_LockArrays(0, 0);
1111 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1112 GL_DepthMask(false);
1114 GL_Color(1, 1, 1, 1);
1115 memset(&m, 0, sizeof(m));
1116 m.tex[0] = R_GetTexture(texture->skin.glow);
1117 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1119 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1120 m.pointer_vertex = surface->mesh.data_vertex3f;
1121 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1123 GL_LockArrays(0, surface->mesh.num_vertices);
1124 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1125 GL_LockArrays(0, 0);
1130 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1131 GL_DepthMask(false);
1133 memset(&m, 0, sizeof(m));
1134 m.pointer_color = varray_color4f;
1135 m.tex[0] = R_GetTexture(texture->skin.glow);
1136 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1138 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1139 m.pointer_vertex = surface->mesh.data_vertex3f;
1141 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1143 RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], 1, 1, surface->mesh.num_vertices, modelorg);
1144 GL_LockArrays(0, surface->mesh.num_vertices);
1145 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1146 GL_LockArrays(0, 0);
1150 else if (texture->flags & SURF_DRAWTURB)
1152 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1154 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1155 RSurfShader_Transparent_Callback(ent, surface - ent->model->brushq1.surfaces);
1158 else if (texture->flags & SURF_DRAWSKY)
1162 skyrendernow = false;
1163 if (skyrendermasked)
1166 // LordHavoc: HalfLife maps have freaky skypolys...
1167 if (!ent->model->brush.ishlbsp)
1169 R_Mesh_Matrix(&ent->matrix);
1170 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
1171 if (skyrendermasked)
1173 // depth-only (masking)
1174 GL_ColorMask(0,0,0,0);
1175 // just to make sure that braindead drivers don't draw anything
1176 // despite that colormask...
1177 GL_BlendFunc(GL_ZERO, GL_ONE);
1182 GL_BlendFunc(GL_ONE, GL_ZERO);
1186 memset(&m, 0, sizeof(m));
1187 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1189 msurface_t *surface = texturesurfacelist[texturesurfaceindex];
1190 m.pointer_vertex = surface->mesh.data_vertex3f;
1192 GL_LockArrays(0, surface->mesh.num_vertices);
1193 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1194 GL_LockArrays(0, 0);
1196 GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
1201 void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
1203 int i, j, f, flagsmask;
1204 msurface_t *surface, **surfacechain;
1205 texture_t *t, *texture;
1206 model_t *model = ent->model;
1208 const int maxsurfacelist = 1024;
1209 int numsurfacelist = 0;
1210 msurface_t *surfacelist[1024];
1213 R_Mesh_Matrix(&ent->matrix);
1214 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1216 if (ent != r_refdef.worldentity)
1218 // because bmodels can be reused, we have to clear dlightframe every time
1219 surface = model->brushq1.surfaces + model->firstmodelsurface;
1220 for (i = 0;i < model->nummodelsurfaces;i++, surface++)
1221 surface->dlightframe = -1;
1224 // update light styles
1227 if (r_dynamic.integer && !r_rtdlight)
1229 for (i = 0;i < model->brushq1.light_styles;i++)
1231 if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
1233 model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
1234 if ((surfacechain = model->brushq1.light_styleupdatechains[i]))
1235 for (;(surface = *surfacechain);surfacechain++)
1236 surface->cached_dlight = true;
1241 R_UpdateTextureInfo(ent);
1242 flagsmask = skysurfaces ? SURF_DRAWSKY : (SURF_DRAWTURB | SURF_LIGHTMAP);
1246 for (i = 0, j = model->firstmodelsurface;i < model->nummodelsurfaces;i++, j++)
1248 if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
1250 surface = model->brushq1.surfaces + j;
1251 if (t != surface->texinfo->texture)
1255 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1258 t = surface->texinfo->texture;
1259 f = t->flags & flagsmask;
1260 texture = t->currentframe;
1264 // add face to draw list and update lightmap if necessary
1266 if (surface->cached_dlight && surface->lightmaptexture != NULL)
1267 R_BuildLightMap(ent, surface);
1268 surfacelist[numsurfacelist++] = surface;
1269 if (numsurfacelist >= maxsurfacelist)
1271 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1278 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1281 static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
1286 const mportal_t *portal = calldata1;
1287 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1288 GL_DepthMask(false);
1290 R_Mesh_Matrix(&r_identitymatrix);
1292 memset(&m, 0, sizeof(m));
1293 m.pointer_vertex = varray_vertex3f;
1297 GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f),
1298 ((i & 0x0038) >> 3) * (1.0f / 7.0f),
1299 ((i & 0x01C0) >> 6) * (1.0f / 7.0f),
1301 if (PlaneDiff(r_vieworigin, (&portal->plane)) < 0)
1303 for (i = portal->numpoints - 1, v = varray_vertex3f;i >= 0;i--, v += 3)
1304 VectorCopy(portal->points[i].position, v);
1307 for (i = 0, v = varray_vertex3f;i < portal->numpoints;i++, v += 3)
1308 VectorCopy(portal->points[i].position, v);
1309 GL_LockArrays(0, portal->numpoints);
1310 R_Mesh_Draw(portal->numpoints, portal->numpoints - 2, polygonelements);
1311 GL_LockArrays(0, 0);
1314 // LordHavoc: this is just a nice debugging tool, very slow
1315 static void R_DrawPortals(void)
1320 model_t *model = r_refdef.worldmodel;
1323 for (portalnum = 0, portal = model->brushq1.portals;portalnum < model->brushq1.numportals;portalnum++, portal++)
1325 if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
1326 if (!R_CullBox(portal->mins, portal->maxs))
1328 VectorClear(center);
1329 for (i = 0;i < portal->numpoints;i++)
1330 VectorAdd(center, portal->points[i].position, center);
1331 f = ixtable[portal->numpoints];
1332 VectorScale(center, f, center);
1333 R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, portalnum);
1338 void R_WorldVisibility(void)
1340 model_t *model = r_refdef.worldmodel;
1345 if (model->type == mod_brushq3)
1349 memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brushq3.num_faces);
1350 for (j = 0, leaf = r_refdef.worldmodel->brushq3.data_leafs;j < r_refdef.worldmodel->brushq3.num_leafs;j++, leaf++)
1352 if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
1355 for (i = 0;i < leaf->numleaffaces;i++)
1356 r_worldsurfacevisible[leaf->firstleafface[i]] = 1;
1360 else if (model->type == mod_brushq1)
1367 mleaf_t *leafstack[8192];
1368 qbyte leafvisited[32768];
1370 viewleaf = model->brushq1.PointInLeaf(model, r_vieworigin);
1374 memset(r_worldsurfacevisible, 0, r_refdef.worldmodel->brushq1.numsurfaces);
1375 if (viewleaf->clusterindex < 0 || r_surfaceworldnode.integer)
1377 // equivilant to quake's RecursiveWorldNode but faster and more effective
1378 for (j = 0, leaf = model->brushq1.data_leafs;j < model->brushq1.num_leafs;j++, leaf++)
1380 if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox (leaf->mins, leaf->maxs))
1383 if (leaf->nummarksurfaces)
1384 for (i = 0, mark = leaf->firstmarksurface;i < leaf->nummarksurfaces;i++, mark++)
1385 r_worldsurfacevisible[*mark] = true;
1391 // LordHavoc: portal-passage worldnode with PVS;
1392 // follows portals leading outward from viewleaf, does not venture
1393 // offscreen or into leafs that are not visible, faster than Quake's
1394 // RecursiveWorldNode
1395 leafstack[0] = viewleaf;
1397 memset(leafvisited, 0, r_refdef.worldmodel->brushq1.num_leafs);
1398 while (leafstackpos)
1401 leaf = leafstack[--leafstackpos];
1402 leafvisited[leaf - r_refdef.worldmodel->brushq1.data_leafs] = 1;
1403 // draw any surfaces bounding this leaf
1404 if (leaf->nummarksurfaces)
1405 for (i = 0, mark = leaf->firstmarksurface;i < leaf->nummarksurfaces;i++, mark++)
1406 r_worldsurfacevisible[*mark] = true;
1407 // follow portals into other leafs
1408 for (p = leaf->portals;p;p = p->next)
1409 if (DotProduct(r_vieworigin, p->plane.normal) < (p->plane.dist + 1) && !leafvisited[p->past - r_refdef.worldmodel->brushq1.data_leafs] && CHECKPVSBIT(r_pvsbits, p->past->clusterindex) && !R_CullBox(p->mins, p->maxs))
1410 leafstack[leafstackpos++] = p->past;
1414 if (r_drawportals.integer)
1419 void R_Q1BSP_DrawSky(entity_render_t *ent)
1421 if (ent->model == NULL)
1423 R_DrawSurfaces(ent, true);
1426 void R_Q1BSP_Draw(entity_render_t *ent)
1428 if (ent->model == NULL)
1431 R_DrawSurfaces(ent, false);
1434 void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer)
1436 model_t *model = ent->model;
1437 vec3_t lightmins, lightmaxs;
1438 int t, leafindex, marksurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
1441 msurface_t *surface;
1444 lightmins[0] = relativelightorigin[0] - lightradius;
1445 lightmins[1] = relativelightorigin[1] - lightradius;
1446 lightmins[2] = relativelightorigin[2] - lightradius;
1447 lightmaxs[0] = relativelightorigin[0] + lightradius;
1448 lightmaxs[1] = relativelightorigin[1] + lightradius;
1449 lightmaxs[2] = relativelightorigin[2] + lightradius;
1450 *outnumclusterspointer = 0;
1451 *outnumsurfacespointer = 0;
1452 memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
1453 memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
1456 VectorCopy(lightmins, outmins);
1457 VectorCopy(lightmaxs, outmaxs);
1460 VectorCopy(relativelightorigin, outmins);
1461 VectorCopy(relativelightorigin, outmaxs);
1462 if (model->brush.GetPVS)
1463 pvs = model->brush.GetPVS(model, relativelightorigin);
1466 // FIXME: use BSP recursion as lights are often small
1467 for (leafindex = 0, leaf = model->brushq1.data_leafs;leafindex < model->brushq1.num_leafs;leafindex++, leaf++)
1469 if (BoxesOverlap(lightmins, lightmaxs, leaf->mins, leaf->maxs) && (pvs == NULL || CHECKPVSBIT(pvs, leaf->clusterindex)))
1471 outmins[0] = min(outmins[0], leaf->mins[0]);
1472 outmins[1] = min(outmins[1], leaf->mins[1]);
1473 outmins[2] = min(outmins[2], leaf->mins[2]);
1474 outmaxs[0] = max(outmaxs[0], leaf->maxs[0]);
1475 outmaxs[1] = max(outmaxs[1], leaf->maxs[1]);
1476 outmaxs[2] = max(outmaxs[2], leaf->maxs[2]);
1479 if (!CHECKPVSBIT(outclusterpvs, leaf->clusterindex))
1481 SETPVSBIT(outclusterpvs, leaf->clusterindex);
1482 outclusterlist[outnumclusters++] = leaf->clusterindex;
1487 for (marksurfaceindex = 0;marksurfaceindex < leaf->nummarksurfaces;marksurfaceindex++)
1489 surfaceindex = leaf->firstmarksurface[marksurfaceindex];
1490 if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
1492 surface = model->brushq1.surfaces + surfaceindex;
1493 if (BoxesOverlap(lightmins, lightmaxs, surface->poly_mins, surface->poly_maxs) && (surface->flags & SURF_LIGHTMAP) && !surface->texinfo->texture->skin.fog)
1495 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
1497 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
1498 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
1499 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
1500 if (PointInfrontOfTriangle(relativelightorigin, v[0], v[1], v[2]) && lightmaxs[0] > min(v[0][0], min(v[1][0], v[2][0])) && lightmins[0] < max(v[0][0], max(v[1][0], v[2][0])) && lightmaxs[1] > min(v[0][1], min(v[1][1], v[2][1])) && lightmins[1] < max(v[0][1], max(v[1][1], v[2][1])) && lightmaxs[2] > min(v[0][2], min(v[1][2], v[2][2])) && lightmins[2] < max(v[0][2], max(v[1][2], v[2][2])))
1502 SETPVSBIT(outsurfacepvs, surfaceindex);
1503 outsurfacelist[outnumsurfaces++] = surfaceindex;
1514 // limit combined leaf box to light boundaries
1515 outmins[0] = max(outmins[0], lightmins[0]);
1516 outmins[1] = max(outmins[1], lightmins[1]);
1517 outmins[2] = max(outmins[2], lightmins[2]);
1518 outmaxs[0] = min(outmaxs[0], lightmaxs[0]);
1519 outmaxs[1] = min(outmaxs[1], lightmaxs[1]);
1520 outmaxs[2] = min(outmaxs[2], lightmaxs[2]);
1522 *outnumclusterspointer = outnumclusters;
1523 *outnumsurfacespointer = outnumsurfaces;
1526 void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
1528 model_t *model = ent->model;
1529 vec3_t lightmins, lightmaxs;
1530 msurface_t *surface;
1531 int surfacelistindex;
1532 if (r_drawcollisionbrushes.integer < 2)
1534 lightmins[0] = relativelightorigin[0] - lightradius;
1535 lightmins[1] = relativelightorigin[1] - lightradius;
1536 lightmins[2] = relativelightorigin[2] - lightradius;
1537 lightmaxs[0] = relativelightorigin[0] + lightradius;
1538 lightmaxs[1] = relativelightorigin[1] + lightradius;
1539 lightmaxs[2] = relativelightorigin[2] + lightradius;
1540 R_Mesh_Matrix(&ent->matrix);
1541 R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
1542 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1544 surface = model->brushq1.surfaces + surfacelist[surfacelistindex];
1545 R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->mesh.num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->poly_mins, surface->poly_maxs);
1547 R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
1551 void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist)
1553 model_t *model = ent->model;
1554 vec3_t lightmins, lightmaxs, modelorg;
1555 msurface_t *surface;
1557 int surfacelistindex;
1558 if (r_drawcollisionbrushes.integer < 2)
1560 lightmins[0] = relativelightorigin[0] - lightradius;
1561 lightmins[1] = relativelightorigin[1] - lightradius;
1562 lightmins[2] = relativelightorigin[2] - lightradius;
1563 lightmaxs[0] = relativelightorigin[0] + lightradius;
1564 lightmaxs[1] = relativelightorigin[1] + lightradius;
1565 lightmaxs[2] = relativelightorigin[2] + lightradius;
1566 R_Mesh_Matrix(&ent->matrix);
1567 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1568 R_UpdateTextureInfo(ent);
1569 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1571 surface = model->brushq1.surfaces + surfacelist[surfacelistindex];
1572 if (r_shadow_compilingrtlight)
1574 // if compiling an rtlight, capture the mesh
1575 t = surface->texinfo->texture;
1576 if (t->flags & SURF_LIGHTMAP && t->skin.fog == NULL)
1577 Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texinfo->texture->skin.base, surface->texinfo->texture->skin.gloss, surface->texinfo->texture->skin.nmap, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, surface->mesh.num_triangles, surface->mesh.data_element3i);
1579 else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surface - ent->model->brushq1.surfaces])
1581 t = surface->texinfo->texture->currentframe;
1582 // FIXME: transparent surfaces need to be lit later
1583 if (t->flags & SURF_LIGHTMAP && t->rendertype == SURFRENDER_OPAQUE)
1584 R_Shadow_RenderLighting(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, t->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
1590 void R_DrawCollisionBrush(colbrushf_t *brush)
1594 memset(&m, 0, sizeof(m));
1595 m.pointer_vertex = brush->points->v;
1597 i = (int)(((size_t)brush) / sizeof(colbrushf_t));
1598 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1599 GL_LockArrays(0, brush->numpoints);
1600 R_Mesh_Draw(brush->numpoints, brush->numtriangles, brush->elements);
1601 GL_LockArrays(0, 0);
1604 void R_Q3BSP_DrawCollisionFace(entity_render_t *ent, q3msurface_t *face)
1608 if (!face->mesh.num_collisiontriangles)
1610 memset(&m, 0, sizeof(m));
1611 m.pointer_vertex = face->mesh.data_collisionvertex3f;
1613 i = (int)(((size_t)face) / sizeof(q3msurface_t));
1614 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1615 GL_LockArrays(0, face->mesh.num_collisionvertices);
1616 R_Mesh_Draw(face->mesh.num_collisionvertices, face->mesh.num_collisiontriangles, face->mesh.data_collisionelement3i);
1617 GL_LockArrays(0, 0);
1620 void R_Q3BSP_DrawFace_TransparentCallback(const void *voident, int facenumber)
1622 const entity_render_t *ent = voident;
1623 q3msurface_t *face = ent->model->brushq3.data_faces + facenumber;
1625 R_Mesh_Matrix(&ent->matrix);
1626 memset(&m, 0, sizeof(m));
1627 if ((ent->effects & EF_ADDITIVE) || (face->texture->textureflags & Q3TEXTUREFLAG_ADDITIVE))
1628 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1630 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1631 GL_DepthMask(false);
1632 GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
1633 m.tex[0] = R_GetTexture(face->texture->skin.base);
1634 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
1635 // LordHavoc: quake3 was not able to do this; lit transparent surfaces
1636 if (gl_combine.integer)
1638 m.texrgbscale[0] = 2;
1639 if (r_textureunits.integer >= 2)
1641 m.tex[1] = R_GetTexture(face->lightmaptexture);
1642 m.pointer_texcoord[1] = face->mesh.data_texcoordlightmap2f;
1643 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], ent->alpha);
1647 if (ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1 && ent->alpha == 1)
1648 m.pointer_color = face->mesh.data_lightmapcolor4f;
1652 for (i = 0;i < face->mesh.num_vertices;i++)
1654 varray_color4f[i*4+0] = face->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0];
1655 varray_color4f[i*4+1] = face->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1];
1656 varray_color4f[i*4+2] = face->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2];
1657 varray_color4f[i*4+3] = face->mesh.data_lightmapcolor4f[i*4+3] * ent->alpha;
1659 m.pointer_color = varray_color4f;
1666 for (i = 0;i < face->mesh.num_vertices;i++)
1668 varray_color4f[i*4+0] = face->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0] * 2.0f;
1669 varray_color4f[i*4+1] = face->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1] * 2.0f;
1670 varray_color4f[i*4+2] = face->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2] * 2.0f;
1671 varray_color4f[i*4+3] = face->mesh.data_lightmapcolor4f[i*4+3] * ent->alpha;
1673 m.pointer_color = varray_color4f;
1675 if (face->texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
1678 float center[3], center2[3], forward[3], right[3], up[3], v[4][3];
1679 matrix4x4_t matrix1, imatrix1;
1680 R_Mesh_Matrix(&r_identitymatrix);
1681 // a single autosprite surface can contain multiple sprites...
1682 for (j = 0;j < face->mesh.num_vertices - 3;j += 4)
1684 VectorClear(center);
1685 for (i = 0;i < 4;i++)
1686 VectorAdd(center, face->mesh.data_vertex3f + (j+i) * 3, center);
1687 VectorScale(center, 0.25f, center);
1688 Matrix4x4_Transform(&ent->matrix, center, center2);
1689 // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
1690 Matrix4x4_FromVectors(&matrix1, face->mesh.data_normal3f + j*3, face->mesh.data_svector3f + j*3, face->mesh.data_tvector3f + j*3, center);
1691 Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
1692 for (i = 0;i < 4;i++)
1693 Matrix4x4_Transform(&imatrix1, face->mesh.data_vertex3f + (j+i)*3, v[i]);
1694 if (face->texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE2)
1696 forward[0] = r_vieworigin[0] - center2[0];
1697 forward[1] = r_vieworigin[1] - center2[1];
1699 VectorNormalize(forward);
1700 right[0] = forward[1];
1701 right[1] = -forward[0];
1709 VectorCopy(r_viewforward, forward);
1710 VectorCopy(r_viewright, right);
1711 VectorCopy(r_viewup, up);
1713 for (i = 0;i < 4;i++)
1714 VectorMAMAMAM(1, center2, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (i+j) * 3);
1716 m.pointer_vertex = varray_vertex3f;
1719 m.pointer_vertex = face->mesh.data_vertex3f;
1721 if (face->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1722 qglDisable(GL_CULL_FACE);
1723 GL_LockArrays(0, face->mesh.num_vertices);
1724 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1725 GL_LockArrays(0, 0);
1726 if (face->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1727 qglEnable(GL_CULL_FACE);
1730 void R_Q3BSP_DrawFaceList(entity_render_t *ent, q3mtexture_t *t, int texturenumfaces, q3msurface_t **texturefacelist)
1732 int i, texturefaceindex;
1733 qboolean dolightmap;
1739 if (!texturenumfaces)
1741 c_faces += texturenumfaces;
1742 // gl_lightmaps debugging mode skips normal texturing
1743 if (gl_lightmaps.integer)
1747 GL_BlendFunc(GL_ONE, GL_ZERO);
1748 qglDisable(GL_CULL_FACE);
1749 memset(&m, 0, sizeof(m));
1750 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1752 q3msurface_t *face = texturefacelist[texturefaceindex];
1753 m.tex[0] = R_GetTexture(face->lightmaptexture);
1754 m.pointer_texcoord[0] = face->mesh.data_texcoordlightmap2f;
1755 if (face->lightmaptexture)
1757 GL_Color(1, 1, 1, 1);
1758 m.pointer_color = NULL;
1761 m.pointer_color = face->mesh.data_lightmapcolor4f;
1762 m.pointer_vertex = face->mesh.data_vertex3f;
1764 GL_LockArrays(0, face->mesh.num_vertices);
1765 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1766 GL_LockArrays(0, 0);
1768 qglEnable(GL_CULL_FACE);
1771 // transparent surfaces get sorted for later drawing
1772 if ((t->surfaceparms & Q3SURFACEPARM_TRANS) || ent->alpha < 1 || (ent->effects & EF_ADDITIVE))
1774 vec3_t facecenter, center;
1775 // drawing sky transparently would be too difficult
1776 if (t->surfaceparms & Q3SURFACEPARM_SKY)
1778 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1780 q3msurface_t *face = texturefacelist[texturefaceindex];
1781 facecenter[0] = (face->mins[0] + face->maxs[0]) * 0.5f;
1782 facecenter[1] = (face->mins[1] + face->maxs[1]) * 0.5f;
1783 facecenter[2] = (face->mins[2] + face->maxs[2]) * 0.5f;
1784 Matrix4x4_Transform(&ent->matrix, facecenter, center);
1785 R_MeshQueue_AddTransparent(center, R_Q3BSP_DrawFace_TransparentCallback, ent, face - ent->model->brushq3.data_faces);
1789 // sky surfaces draw sky if needed and render themselves as a depth mask
1790 if (t->surfaceparms & Q3SURFACEPARM_SKY)
1794 skyrendernow = false;
1795 if (skyrendermasked)
1798 if (!r_q3bsp_renderskydepth.integer)
1801 R_Mesh_Matrix(&ent->matrix);
1803 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
1804 if (skyrendermasked)
1806 // depth-only (masking)
1807 GL_ColorMask(0,0,0,0);
1808 // just to make sure that braindead drivers don't draw anything
1809 // despite that colormask...
1810 GL_BlendFunc(GL_ZERO, GL_ONE);
1815 GL_BlendFunc(GL_ONE, GL_ZERO);
1820 memset(&m, 0, sizeof(m));
1821 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1823 q3msurface_t *face = texturefacelist[texturefaceindex];
1824 m.pointer_vertex = face->mesh.data_vertex3f;
1826 GL_LockArrays(0, face->mesh.num_vertices);
1827 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1828 GL_LockArrays(0, 0);
1830 GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
1833 // anything else is a typical wall, lightmap * texture + glow
1834 dolightmap = (ent->flags & RENDER_LIGHT);
1836 doambient = r_ambient.value > 0;
1837 doglow = t->skin.glow != NULL;
1839 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1840 qglDisable(GL_CULL_FACE);
1841 if (!dolightmap && dobase)
1847 GL_BlendFunc(GL_ONE, GL_ZERO);
1848 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
1849 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1850 qglDisable(GL_CULL_FACE);
1851 memset(&m, 0, sizeof(m));
1852 m.tex[0] = R_GetTexture(t->skin.base);
1853 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1855 q3msurface_t *face = texturefacelist[texturefaceindex];
1856 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
1857 m.pointer_vertex = face->mesh.data_vertex3f;
1859 GL_LockArrays(0, face->mesh.num_vertices);
1860 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1861 GL_LockArrays(0, 0);
1864 if (r_lightmapintensity <= 0 && dolightmap && dobase)
1870 GL_BlendFunc(GL_ONE, GL_ZERO);
1871 GL_Color(0, 0, 0, 1);
1872 memset(&m, 0, sizeof(m));
1873 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1875 q3msurface_t *face = texturefacelist[texturefaceindex];
1876 m.pointer_vertex = face->mesh.data_vertex3f;
1878 GL_LockArrays(0, face->mesh.num_vertices);
1879 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1880 GL_LockArrays(0, 0);
1883 if (r_textureunits.integer >= 2 && gl_combine.integer && dolightmap && dobase)
1885 // dualtexture combine
1890 GL_BlendFunc(GL_ONE, GL_ZERO);
1891 memset(&m, 0, sizeof(m));
1892 m.tex[0] = R_GetTexture(t->skin.base);
1893 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1894 m.pointer_color = NULL;
1895 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1897 q3msurface_t *face = texturefacelist[texturefaceindex];
1898 if (!face->lightmaptexture)
1900 m.tex[1] = R_GetTexture(face->lightmaptexture);
1901 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
1902 m.pointer_texcoord[1] = face->mesh.data_texcoordlightmap2f;
1903 m.texrgbscale[1] = 2;
1904 m.pointer_vertex = face->mesh.data_vertex3f;
1906 GL_LockArrays(0, face->mesh.num_vertices);
1907 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1908 GL_LockArrays(0, 0);
1910 if (r_lightmapintensity == 1 && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
1912 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1914 q3msurface_t *face = texturefacelist[texturefaceindex];
1915 if (face->lightmaptexture)
1917 m.tex[1] = R_GetTexture(face->lightmaptexture);
1918 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
1919 m.pointer_texcoord[1] = face->mesh.data_texcoordlightmap2f;
1920 m.texrgbscale[1] = 2;
1921 m.pointer_color = face->mesh.data_lightmapcolor4f;
1922 m.pointer_vertex = face->mesh.data_vertex3f;
1924 GL_LockArrays(0, face->mesh.num_vertices);
1925 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1926 GL_LockArrays(0, 0);
1931 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1933 q3msurface_t *face = texturefacelist[texturefaceindex];
1934 if (face->lightmaptexture)
1936 m.tex[1] = R_GetTexture(face->lightmaptexture);
1937 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
1938 m.pointer_texcoord[1] = face->mesh.data_texcoordlightmap2f;
1939 m.texrgbscale[1] = 2;
1940 m.pointer_color = varray_color4f;
1941 for (i = 0;i < face->mesh.num_vertices;i++)
1943 varray_color4f[i*4+0] = face->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0] * r_lightmapintensity;
1944 varray_color4f[i*4+1] = face->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1] * r_lightmapintensity;
1945 varray_color4f[i*4+2] = face->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2] * r_lightmapintensity;
1946 varray_color4f[i*4+3] = face->mesh.data_lightmapcolor4f[i*4+3];
1948 m.pointer_vertex = face->mesh.data_vertex3f;
1950 GL_LockArrays(0, face->mesh.num_vertices);
1951 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1952 GL_LockArrays(0, 0);
1961 GL_BlendFunc(GL_ONE, GL_ZERO);
1962 memset(&m, 0, sizeof(m));
1963 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1965 q3msurface_t *face = texturefacelist[texturefaceindex];
1966 m.tex[0] = R_GetTexture(face->lightmaptexture);
1967 m.pointer_texcoord[0] = face->mesh.data_texcoordlightmap2f;
1968 if (face->lightmaptexture)
1969 m.pointer_color = NULL;
1971 m.pointer_color = face->mesh.data_lightmapcolor4f;
1972 m.pointer_vertex = face->mesh.data_vertex3f;
1974 GL_LockArrays(0, face->mesh.num_vertices);
1975 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1976 GL_LockArrays(0, 0);
1981 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1982 GL_DepthMask(false);
1984 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1985 memset(&m, 0, sizeof(m));
1986 m.tex[0] = R_GetTexture(t->skin.base);
1987 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
1989 q3msurface_t *face = texturefacelist[texturefaceindex];
1990 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
1991 m.pointer_vertex = face->mesh.data_vertex3f;
1993 GL_LockArrays(0, face->mesh.num_vertices);
1994 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
1995 GL_LockArrays(0, 0);
2000 GL_BlendFunc(GL_ONE, GL_ONE);
2001 GL_DepthMask(false);
2003 GL_Color(r_ambient.value * (1.0f / 128.0f) * ent->colormod[0], r_ambient.value * (1.0f / 128.0f) * ent->colormod[1], r_ambient.value * (1.0f / 128.0f) * ent->colormod[2], 1);
2004 memset(&m, 0, sizeof(m));
2005 m.tex[0] = R_GetTexture(t->skin.base);
2006 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
2008 q3msurface_t *face = texturefacelist[texturefaceindex];
2009 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
2010 m.pointer_vertex = face->mesh.data_vertex3f;
2012 GL_LockArrays(0, face->mesh.num_vertices);
2013 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
2014 GL_LockArrays(0, 0);
2019 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
2020 GL_DepthMask(false);
2022 GL_Color(1, 1, 1, 1);
2023 memset(&m, 0, sizeof(m));
2024 m.tex[0] = R_GetTexture(t->skin.glow);
2025 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
2027 q3msurface_t *face = texturefacelist[texturefaceindex];
2028 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
2029 m.pointer_vertex = face->mesh.data_vertex3f;
2031 GL_LockArrays(0, face->mesh.num_vertices);
2032 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
2033 GL_LockArrays(0, 0);
2039 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
2040 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2041 GL_DepthMask(false);
2043 GL_Color(1, 1, 1, 1);
2044 memset(&m, 0, sizeof(m));
2045 m.tex[0] = R_GetTexture(t->skin.fog);
2046 m.pointer_color = varray_color4f;
2047 for (texturefaceindex = 0;texturefaceindex < texturenumfaces;texturefaceindex++)
2049 q3msurface_t *face = texturefacelist[texturefaceindex];
2051 m.pointer_texcoord[0] = face->mesh.data_texcoordtexture2f;
2052 m.pointer_vertex = face->mesh.data_vertex3f;
2054 RSurf_FogPassColors_Vertex3f_Color4f(face->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], 1, 1, face->mesh.num_vertices, modelorg);
2055 GL_LockArrays(0, face->mesh.num_vertices);
2056 R_Mesh_Draw(face->mesh.num_vertices, face->mesh.num_triangles, face->mesh.data_element3i);
2057 GL_LockArrays(0, 0);
2060 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2061 qglEnable(GL_CULL_FACE);
2064 void R_Q3BSP_DrawFaces(entity_render_t *ent, int skyfaces)
2066 int i, j, f, flagsmask, flags;
2068 model_t *model = ent->model;
2070 const int maxfaces = 1024;
2072 q3msurface_t *facelist[1024];
2073 R_Mesh_Matrix(&ent->matrix);
2074 flagsmask = Q3SURFACEFLAG_NODRAW | Q3SURFACEFLAG_SKY;
2076 flags = Q3SURFACEFLAG_SKY;
2082 for (i = 0, j = model->firstmodelsurface;i < model->nummodelsurfaces;i++, j++)
2084 if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
2086 face = model->brushq3.data_faces + j;
2087 if (t != face->texture)
2091 R_Q3BSP_DrawFaceList(ent, t, numfaces, facelist);
2095 f = t->surfaceflags & flagsmask;
2099 if (!face->mesh.num_triangles)
2101 facelist[numfaces++] = face;
2102 if (numfaces >= maxfaces)
2104 R_Q3BSP_DrawFaceList(ent, t, numfaces, facelist);
2111 R_Q3BSP_DrawFaceList(ent, t, numfaces, facelist);
2114 void R_Q3BSP_DrawSky(entity_render_t *ent)
2116 if (r_drawcollisionbrushes.integer < 2)
2117 R_Q3BSP_DrawFaces(ent, true);
2120 void R_Q3BSP_Draw(entity_render_t *ent)
2122 if (r_drawcollisionbrushes.integer < 2)
2123 R_Q3BSP_DrawFaces(ent, false);
2124 if (r_drawcollisionbrushes.integer >= 1)
2127 model_t *model = ent->model;
2129 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
2130 GL_DepthMask(false);
2132 qglPolygonOffset(r_drawcollisionbrushes_polygonfactor.value, r_drawcollisionbrushes_polygonoffset.value);
2133 for (i = 0;i < model->brushq3.data_thismodel->numbrushes;i++)
2134 if (model->brushq3.data_thismodel->firstbrush[i].colbrushf && model->brushq3.data_thismodel->firstbrush[i].colbrushf->numtriangles)
2135 R_DrawCollisionBrush(model->brushq3.data_thismodel->firstbrush[i].colbrushf);
2136 for (i = 0, face = model->brushq3.data_thismodel->firstface;i < model->brushq3.data_thismodel->numfaces;i++, face++)
2137 if (face->mesh.num_collisiontriangles)
2138 R_Q3BSP_DrawCollisionFace(ent, face);
2139 qglPolygonOffset(0, 0);
2143 void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer)
2145 model_t *model = ent->model;
2146 vec3_t lightmins, lightmaxs;
2147 int t, leafindex, marksurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
2150 q3msurface_t *surface;
2153 lightmins[0] = relativelightorigin[0] - lightradius;
2154 lightmins[1] = relativelightorigin[1] - lightradius;
2155 lightmins[2] = relativelightorigin[2] - lightradius;
2156 lightmaxs[0] = relativelightorigin[0] + lightradius;
2157 lightmaxs[1] = relativelightorigin[1] + lightradius;
2158 lightmaxs[2] = relativelightorigin[2] + lightradius;
2159 *outnumclusterspointer = 0;
2160 *outnumsurfacespointer = 0;
2161 memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
2162 memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
2165 VectorCopy(lightmins, outmins);
2166 VectorCopy(lightmaxs, outmaxs);
2169 VectorCopy(relativelightorigin, outmins);
2170 VectorCopy(relativelightorigin, outmaxs);
2171 if (model->brush.GetPVS)
2172 pvs = model->brush.GetPVS(model, relativelightorigin);
2175 // FIXME: use BSP recursion as lights are often small
2176 for (leafindex = 0, leaf = model->brushq3.data_leafs;leafindex < model->brushq3.num_leafs;leafindex++, leaf++)
2178 if (BoxesOverlap(lightmins, lightmaxs, leaf->mins, leaf->maxs) && (pvs == NULL || CHECKPVSBIT(pvs, leaf->clusterindex)))
2180 outmins[0] = min(outmins[0], leaf->mins[0]);
2181 outmins[1] = min(outmins[1], leaf->mins[1]);
2182 outmins[2] = min(outmins[2], leaf->mins[2]);
2183 outmaxs[0] = max(outmaxs[0], leaf->maxs[0]);
2184 outmaxs[1] = max(outmaxs[1], leaf->maxs[1]);
2185 outmaxs[2] = max(outmaxs[2], leaf->maxs[2]);
2188 if (!CHECKPVSBIT(outclusterpvs, leaf->clusterindex))
2190 SETPVSBIT(outclusterpvs, leaf->clusterindex);
2191 outclusterlist[outnumclusters++] = leaf->clusterindex;
2196 for (marksurfaceindex = 0;marksurfaceindex < leaf->numleaffaces;marksurfaceindex++)
2198 surfaceindex = leaf->firstleafface[marksurfaceindex];
2199 surface = model->brushq3.data_faces + surfaceindex;
2200 if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
2202 if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS) && !(surface->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)) && surface->mesh.num_triangles)
2204 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2206 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
2208 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
2209 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
2210 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
2211 if (lightmaxs[0] > min(v[0][0], min(v[1][0], v[2][0])) && lightmins[0] < max(v[0][0], max(v[1][0], v[2][0])) && lightmaxs[1] > min(v[0][1], min(v[1][1], v[2][1])) && lightmins[1] < max(v[0][1], max(v[1][1], v[2][1])) && lightmaxs[2] > min(v[0][2], min(v[1][2], v[2][2])) && lightmins[2] < max(v[0][2], max(v[1][2], v[2][2])))
2213 SETPVSBIT(outsurfacepvs, surfaceindex);
2214 outsurfacelist[outnumsurfaces++] = surfaceindex;
2221 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
2223 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
2224 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
2225 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
2226 if (PointInfrontOfTriangle(relativelightorigin, v[0], v[1], v[2]) && lightmaxs[0] > min(v[0][0], min(v[1][0], v[2][0])) && lightmins[0] < max(v[0][0], max(v[1][0], v[2][0])) && lightmaxs[1] > min(v[0][1], min(v[1][1], v[2][1])) && lightmins[1] < max(v[0][1], max(v[1][1], v[2][1])) && lightmaxs[2] > min(v[0][2], min(v[1][2], v[2][2])) && lightmins[2] < max(v[0][2], max(v[1][2], v[2][2])))
2228 SETPVSBIT(outsurfacepvs, surfaceindex);
2229 outsurfacelist[outnumsurfaces++] = surfaceindex;
2241 // limit combined leaf box to light boundaries
2242 outmins[0] = max(outmins[0], lightmins[0]);
2243 outmins[1] = max(outmins[1], lightmins[1]);
2244 outmins[2] = max(outmins[2], lightmins[2]);
2245 outmaxs[0] = min(outmaxs[0], lightmaxs[0]);
2246 outmaxs[1] = min(outmaxs[1], lightmaxs[1]);
2247 outmaxs[2] = min(outmaxs[2], lightmaxs[2]);
2249 *outnumclusterspointer = outnumclusters;
2250 *outnumsurfacespointer = outnumsurfaces;
2253 void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
2255 model_t *model = ent->model;
2256 vec3_t lightmins, lightmaxs;
2257 q3msurface_t *surface;
2258 int surfacelistindex;
2259 if (r_drawcollisionbrushes.integer < 2)
2261 lightmins[0] = relativelightorigin[0] - lightradius;
2262 lightmins[1] = relativelightorigin[1] - lightradius;
2263 lightmins[2] = relativelightorigin[2] - lightradius;
2264 lightmaxs[0] = relativelightorigin[0] + lightradius;
2265 lightmaxs[1] = relativelightorigin[1] + lightradius;
2266 lightmaxs[2] = relativelightorigin[2] + lightradius;
2267 R_Mesh_Matrix(&ent->matrix);
2268 R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
2269 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
2271 surface = model->brushq3.data_faces + surfacelist[surfacelistindex];
2272 // FIXME: check some manner of face->rendermode here?
2273 if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && !(surface->texture->surfaceparms & (Q3SURFACEPARM_SKY | Q3SURFACEPARM_TRANS)) && !(surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED))
2274 R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->mesh.num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
2276 R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
2280 void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale, int numsurfaces, const int *surfacelist)
2282 model_t *model = ent->model;
2283 vec3_t lightmins, lightmaxs, modelorg;
2284 q3msurface_t *surface;
2285 int surfacelistindex;
2286 if (r_drawcollisionbrushes.integer < 2)
2288 lightmins[0] = relativelightorigin[0] - lightradius;
2289 lightmins[1] = relativelightorigin[1] - lightradius;
2290 lightmins[2] = relativelightorigin[2] - lightradius;
2291 lightmaxs[0] = relativelightorigin[0] + lightradius;
2292 lightmaxs[1] = relativelightorigin[1] + lightradius;
2293 lightmaxs[2] = relativelightorigin[2] + lightradius;
2294 R_Mesh_Matrix(&ent->matrix);
2295 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
2296 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
2298 surface = model->brushq3.data_faces + surfacelist[surfacelistindex];
2299 if (r_shadow_compilingrtlight)
2301 // if compiling an rtlight, capture the mesh
2302 Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texture->skin.base, surface->texture->skin.gloss, surface->texture->skin.nmap, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, surface->mesh.num_triangles, surface->mesh.data_element3i);
2304 else if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && surface->mesh.num_triangles)
2306 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2307 qglDisable(GL_CULL_FACE);
2308 R_Shadow_RenderLighting(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, surface->texture->skin.base, surface->texture->skin.nmap, surface->texture->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
2309 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2310 qglEnable(GL_CULL_FACE);
2317 static void gl_surf_start(void)
2321 static void gl_surf_shutdown(void)
2325 static void gl_surf_newmap(void)
2330 void GL_Surf_Init(void)
2333 dlightdivtable[0] = 4194304;
2334 for (i = 1;i < 32768;i++)
2335 dlightdivtable[i] = 4194304 / (i << 7);
2337 Cvar_RegisterVariable(&r_ambient);
2338 Cvar_RegisterVariable(&r_drawportals);
2339 Cvar_RegisterVariable(&r_testvis);
2340 Cvar_RegisterVariable(&r_floatbuildlightmap);
2341 Cvar_RegisterVariable(&r_detailtextures);
2342 Cvar_RegisterVariable(&r_surfaceworldnode);
2343 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor);
2344 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);
2345 Cvar_RegisterVariable(&r_q3bsp_renderskydepth);
2346 Cvar_RegisterVariable(&gl_lightmaps);
2348 //R_RegisterModule("GL_Surf", gl_surf_start, gl_surf_shutdown, gl_surf_newmap);