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"};
43 // flag arrays used for visibility checking on world model
44 // (all other entities have no per-surface/per-leaf visibility checks)
45 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_clusters
46 qbyte r_pvsbits[(32768+7)>>3];
47 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_leafs
48 qbyte r_worldleafvisible[32768];
49 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_surfaces
50 qbyte r_worldsurfacevisible[262144];
52 static int dlightdivtable[32768];
54 static int R_IntAddDynamicLights (const matrix4x4_t *matrix, msurface_t *surface)
56 int sdtable[256], lnum, td, maxdist, maxdist2, maxdist3, i, s, t, smax, tmax, smax3, red, green, blue, lit, dist2, impacts, impactt, subtract, k;
58 float dist, impact[3], local[3];
63 smax = (surface->extents[0] >> 4) + 1;
64 tmax = (surface->extents[1] >> 4) + 1;
67 for (lnum = 0, light = r_dlight;lnum < r_numdlights;lnum++, light++)
69 if (!(surface->dlightbits[lnum >> 5] & (1 << (lnum & 31))))
70 continue; // not lit by this light
72 Matrix4x4_Transform(matrix, light->origin, local);
73 dist = DotProduct (local, surface->plane->normal) - surface->plane->dist;
75 // for comparisons to minimum acceptable light
76 // compensate for LIGHTOFFSET
77 maxdist = (int) light->rtlight.lightmap_cullradius2 + LIGHTOFFSET;
84 if (surface->plane->type < 3)
86 VectorCopy(local, impact);
87 impact[surface->plane->type] -= dist;
91 impact[0] = local[0] - surface->plane->normal[0] * dist;
92 impact[1] = local[1] - surface->plane->normal[1] * dist;
93 impact[2] = local[2] - surface->plane->normal[2] * dist;
96 impacts = DotProduct (impact, surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3] - surface->texturemins[0];
97 impactt = DotProduct (impact, surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3] - surface->texturemins[1];
99 s = bound(0, impacts, smax * 16) - impacts;
100 t = bound(0, impactt, tmax * 16) - impactt;
101 i = s * s + t * t + dist2;
105 // reduce calculations
106 for (s = 0, i = impacts; s < smax; s++, i -= 16)
107 sdtable[s] = i * i + dist2;
109 maxdist3 = maxdist - dist2;
111 // convert to 8.8 blocklights format
112 red = light->rtlight.lightmap_light[0] * (1.0f / 128.0f);
113 green = light->rtlight.lightmap_light[1] * (1.0f / 128.0f);
114 blue = light->rtlight.lightmap_light[2] * (1.0f / 128.0f);
115 subtract = (int) (light->rtlight.lightmap_subtract * 4194304.0f);
119 for (t = 0;t < tmax;t++, i -= 16)
122 // make sure some part of it is visible on this line
125 maxdist2 = maxdist - td;
126 for (s = 0;s < smax;s++)
128 if (sdtable[s] < maxdist2)
130 k = dlightdivtable[(sdtable[s] + td) >> 7] - subtract;
134 bl[1] += (green * k);
149 static int R_FloatAddDynamicLights (const matrix4x4_t *matrix, msurface_t *surface)
151 int lnum, s, t, smax, tmax, smax3, lit, impacts, impactt;
152 float sdtable[256], *bl, k, dist, dist2, maxdist, maxdist2, maxdist3, td1, td, red, green, blue, impact[3], local[3], subtract;
157 smax = (surface->extents[0] >> 4) + 1;
158 tmax = (surface->extents[1] >> 4) + 1;
161 for (lnum = 0, light = r_dlight;lnum < r_numdlights;lnum++, light++)
163 if (!(surface->dlightbits[lnum >> 5] & (1 << (lnum & 31))))
164 continue; // not lit by this light
166 Matrix4x4_Transform(matrix, light->origin, local);
167 dist = DotProduct (local, surface->plane->normal) - surface->plane->dist;
169 // for comparisons to minimum acceptable light
170 // compensate for LIGHTOFFSET
171 maxdist = (int) light->rtlight.lightmap_cullradius2 + LIGHTOFFSET;
174 dist2 += LIGHTOFFSET;
175 if (dist2 >= maxdist)
178 if (surface->plane->type < 3)
180 VectorCopy(local, impact);
181 impact[surface->plane->type] -= dist;
185 impact[0] = local[0] - surface->plane->normal[0] * dist;
186 impact[1] = local[1] - surface->plane->normal[1] * dist;
187 impact[2] = local[2] - surface->plane->normal[2] * dist;
190 impacts = DotProduct (impact, surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3] - surface->texturemins[0];
191 impactt = DotProduct (impact, surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3] - surface->texturemins[1];
193 td = bound(0, impacts, smax * 16) - impacts;
194 td1 = bound(0, impactt, tmax * 16) - impactt;
195 td = td * td + td1 * td1 + dist2;
199 // reduce calculations
200 for (s = 0, td1 = impacts; s < smax; s++, td1 -= 16.0f)
201 sdtable[s] = td1 * td1 + dist2;
203 maxdist3 = maxdist - dist2;
205 // convert to 8.8 blocklights format
206 red = light->rtlight.lightmap_light[0];
207 green = light->rtlight.lightmap_light[1];
208 blue = light->rtlight.lightmap_light[2];
209 subtract = light->rtlight.lightmap_subtract * 32768.0f;
210 bl = floatblocklights;
213 for (t = 0;t < tmax;t++, td1 -= 16.0f)
216 // make sure some part of it is visible on this line
219 maxdist2 = maxdist - td;
220 for (s = 0;s < smax;s++)
222 if (sdtable[s] < maxdist2)
224 k = (32768.0f / (sdtable[s] + td)) - subtract;
244 Combine and scale multiple lightmaps into the 8.8 format in blocklights
247 static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
249 if (!r_floatbuildlightmap.integer)
251 int smax, tmax, i, j, size, size3, maps, stride, l;
252 unsigned int *bl, scale;
253 qbyte *lightmap, *out, *stain;
255 // update cached lighting info
256 surface->cached_dlight = 0;
258 smax = (surface->extents[0]>>4)+1;
259 tmax = (surface->extents[1]>>4)+1;
262 lightmap = surface->samples;
264 // set to full bright if no light data
266 if (!ent->model->brushq1.lightdata)
268 for (i = 0;i < size3;i++)
274 memset(bl, 0, size*3*sizeof(unsigned int));
276 if (surface->dlightframe == r_framecount)
278 surface->cached_dlight = R_IntAddDynamicLights(&ent->inversematrix, surface);
279 if (surface->cached_dlight)
283 // add all the lightmaps
287 for (maps = 0;maps < MAXLIGHTMAPS && surface->styles[maps] != 255;maps++, lightmap += size3)
288 for (scale = d_lightstylevalue[surface->styles[maps]], i = 0;i < size3;i++)
289 bl[i] += lightmap[i] * scale;
293 stain = surface->stainsamples;
296 // the >> 16 shift adjusts down 8 bits to account for the stainmap
297 // scaling, and remaps the 0-65536 (2x overbright) to 0-256, it will
298 // be doubled during rendering to achieve 2x overbright
299 // (0 = 0.0, 128 = 1.0, 256 = 2.0)
300 if (ent->model->brushq1.lightmaprgba)
302 stride = (surface->lightmaptexturestride - smax) * 4;
303 for (i = 0;i < tmax;i++, out += stride)
305 for (j = 0;j < smax;j++)
307 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
308 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
309 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
316 stride = (surface->lightmaptexturestride - smax) * 3;
317 for (i = 0;i < tmax;i++, out += stride)
319 for (j = 0;j < smax;j++)
321 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
322 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
323 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
328 R_UpdateTexture(surface->lightmaptexture, templight);
332 int smax, tmax, i, j, size, size3, maps, stride, l;
334 qbyte *lightmap, *out, *stain;
336 // update cached lighting info
337 surface->cached_dlight = 0;
339 smax = (surface->extents[0]>>4)+1;
340 tmax = (surface->extents[1]>>4)+1;
343 lightmap = surface->samples;
345 // set to full bright if no light data
346 bl = floatblocklights;
347 if (!ent->model->brushq1.lightdata)
349 for (i = 0;i < size3;i++)
354 memset(bl, 0, size*3*sizeof(float));
356 if (surface->dlightframe == r_framecount)
358 surface->cached_dlight = R_FloatAddDynamicLights(&ent->inversematrix, surface);
359 if (surface->cached_dlight)
363 // add all the lightmaps
366 bl = floatblocklights;
367 for (maps = 0;maps < MAXLIGHTMAPS && surface->styles[maps] != 255;maps++, lightmap += size3)
368 for (scale = d_lightstylevalue[surface->styles[maps]], i = 0;i < size3;i++)
369 bl[i] += lightmap[i] * scale;
373 stain = surface->stainsamples;
374 bl = floatblocklights;
376 // this scaling adjusts down 8 bits to account for the stainmap
377 // scaling, and remaps the 0.0-2.0 (2x overbright) to 0-256, it will
378 // be doubled during rendering to achieve 2x overbright
379 // (0 = 0.0, 128 = 1.0, 256 = 2.0)
380 scale = 1.0f / (1 << 16);
381 if (ent->model->brushq1.lightmaprgba)
383 stride = (surface->lightmaptexturestride - smax) * 4;
384 for (i = 0;i < tmax;i++, out += stride)
386 for (j = 0;j < smax;j++)
388 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
389 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
390 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
397 stride = (surface->lightmaptexturestride - smax) * 3;
398 for (i = 0;i < tmax;i++, out += stride)
400 for (j = 0;j < smax;j++)
402 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
403 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
404 l = *bl++ * *stain++ * scale;*out++ = min(l, 255);
409 R_UpdateTexture(surface->lightmaptexture, templight);
413 void R_StainNode (mnode_t *node, model_t *model, const vec3_t origin, float radius, const float fcolor[8])
415 float ndist, a, ratio, maxdist, maxdist2, maxdist3, invradius, sdtable[256], td, dist2;
416 msurface_t *surface, *endsurface;
417 int i, s, t, smax, tmax, smax3, impacts, impactt, stained;
421 maxdist = radius * radius;
422 invradius = 1.0f / radius;
427 ndist = PlaneDiff(origin, node->plane);
430 node = node->children[0];
435 node = node->children[1];
439 dist2 = ndist * ndist;
440 maxdist3 = maxdist - dist2;
442 if (node->plane->type < 3)
444 VectorCopy(origin, impact);
445 impact[node->plane->type] -= ndist;
449 impact[0] = origin[0] - node->plane->normal[0] * ndist;
450 impact[1] = origin[1] - node->plane->normal[1] * ndist;
451 impact[2] = origin[2] - node->plane->normal[2] * ndist;
454 for (surface = model->brush.data_surfaces + node->firstsurface, endsurface = surface + node->numsurfaces;surface < endsurface;surface++)
456 if (surface->stainsamples)
458 smax = (surface->extents[0] >> 4) + 1;
459 tmax = (surface->extents[1] >> 4) + 1;
461 impacts = DotProduct (impact, surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3] - surface->texturemins[0];
462 impactt = DotProduct (impact, surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3] - surface->texturemins[1];
464 s = bound(0, impacts, smax * 16) - impacts;
465 t = bound(0, impactt, tmax * 16) - impactt;
466 i = s * s + t * t + dist2;
470 // reduce calculations
471 for (s = 0, i = impacts; s < smax; s++, i -= 16)
472 sdtable[s] = i * i + dist2;
474 bl = surface->stainsamples;
479 for (t = 0;t < tmax;t++, i -= 16)
482 // make sure some part of it is visible on this line
485 maxdist2 = maxdist - td;
486 for (s = 0;s < smax;s++)
488 if (sdtable[s] < maxdist2)
490 ratio = lhrandom(0.0f, 1.0f);
491 a = (fcolor[3] + ratio * fcolor[7]) * (1.0f - sqrt(sdtable[s] + td) * invradius);
492 if (a >= (1.0f / 64.0f))
496 bl[0] = (qbyte) ((float) bl[0] + a * ((fcolor[0] + ratio * fcolor[4]) - (float) bl[0]));
497 bl[1] = (qbyte) ((float) bl[1] + a * ((fcolor[1] + ratio * fcolor[5]) - (float) bl[1]));
498 bl[2] = (qbyte) ((float) bl[2] + a * ((fcolor[2] + ratio * fcolor[6]) - (float) bl[2]));
508 // force lightmap upload
510 surface->cached_dlight = true;
514 if (node->children[0]->plane)
516 if (node->children[1]->plane)
518 R_StainNode(node->children[0], model, origin, radius, fcolor);
519 node = node->children[1];
524 node = node->children[0];
528 else if (node->children[1]->plane)
530 node = node->children[1];
535 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)
539 entity_render_t *ent;
542 if (r_refdef.worldmodel == NULL || !r_refdef.worldmodel->brush.data_nodes)
547 fcolor[3] = ca1 * (1.0f / 64.0f);
548 fcolor[4] = cr2 - cr1;
549 fcolor[5] = cg2 - cg1;
550 fcolor[6] = cb2 - cb1;
551 fcolor[7] = (ca2 - ca1) * (1.0f / 64.0f);
553 R_StainNode(r_refdef.worldmodel->brush.data_nodes + r_refdef.worldmodel->brushq1.hulls[0].firstclipnode, r_refdef.worldmodel, origin, radius, fcolor);
555 // look for embedded bmodels
556 for (n = 0;n < cl_num_brushmodel_entities;n++)
558 ent = cl_brushmodel_entities[n];
560 if (model && model->name[0] == '*')
562 Mod_CheckLoaded(model);
563 if (model->brush.data_nodes)
565 Matrix4x4_Transform(&ent->inversematrix, origin, org);
566 R_StainNode(model->brush.data_nodes + model->brushq1.hulls[0].firstclipnode, model, org, radius, fcolor);
574 =============================================================
578 =============================================================
581 static void RSurf_AddLightmapToVertexColors_Color4f(const int *lightmapoffsets, float *c, int numverts, const qbyte *samples, int size3, const qbyte *styles)
586 if (styles[0] != 255)
588 for (i = 0;i < numverts;i++, c += 4)
590 lm = samples + lightmapoffsets[i];
591 scale = d_lightstylevalue[styles[0]] * (1.0f / 32768.0f);
592 VectorMA(c, scale, lm, c);
593 if (styles[1] != 255)
596 scale = d_lightstylevalue[styles[1]] * (1.0f / 32768.0f);
597 VectorMA(c, scale, lm, c);
598 if (styles[2] != 255)
601 scale = d_lightstylevalue[styles[2]] * (1.0f / 32768.0f);
602 VectorMA(c, scale, lm, c);
603 if (styles[3] != 255)
606 scale = d_lightstylevalue[styles[3]] * (1.0f / 32768.0f);
607 VectorMA(c, scale, lm, c);
615 static void RSurf_FogColors_Vertex3f_Color4f(const float *v, float *c, float colorscale, int numverts, const float *modelorg)
621 for (i = 0;i < numverts;i++, v += 3, c += 4)
623 VectorSubtract(v, modelorg, diff);
624 f = colorscale * (1 - exp(fogdensity/DotProduct(diff, diff)));
625 VectorScale(c, f, c);
628 else if (colorscale != 1)
629 for (i = 0;i < numverts;i++, c += 4)
630 VectorScale(c, colorscale, c);
633 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)
642 for (i = 0;i < numverts;i++, v += 3, c += 4)
644 VectorSubtract(v, modelorg, diff);
645 f = 1 - exp(fogdensity/DotProduct(diff, diff));
654 for (i = 0;i < numverts;i++, c += 4)
664 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)
671 for (i = 0;i < numverts;i++, v += 3, c += 4)
673 VectorSubtract(v, modelorg, diff);
674 f = exp(fogdensity/DotProduct(diff, diff));
682 static int RSurf_LightSeparate_Vertex3f_Color4f(const matrix4x4_t *matrix, const int *dlightbits, int numverts, const float *vert, float *color, float scale)
687 int i, l, lit = false;
688 const dlight_t *light;
690 for (l = 0;l < r_numdlights;l++)
692 if (dlightbits[l >> 5] & (1 << (l & 31)))
694 light = &r_dlight[l];
695 Matrix4x4_Transform(matrix, light->origin, lightorigin);
696 for (i = 0, v = vert, c = color;i < numverts;i++, v += 3, c += 4)
698 f = VectorDistance2(v, lightorigin) + LIGHTOFFSET;
699 if (f < light->rtlight.lightmap_cullradius2)
701 f = ((1.0f / f) - light->rtlight.lightmap_subtract) * scale;
702 VectorMA(c, f, light->rtlight.lightmap_light, c);
711 static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata2)
713 const entity_render_t *ent = calldata1;
714 const msurface_t *surface = ent->model->brush.data_surfaces + calldata2;
717 float base, colorscale;
720 float args[4] = {0.05f,0,0,0.04f};
721 int rendertype, turb, fullbright;
723 R_Mesh_Matrix(&ent->matrix);
724 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
726 texture = surface->texture;
727 if (texture->animated)
728 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];
729 currentalpha = ent->alpha;
730 if (texture->flags & SURF_WATERALPHA)
731 currentalpha *= r_wateralpha.value;
733 GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
734 if (ent->effects & EF_ADDITIVE)
736 rendertype = SURFRENDER_ADD;
737 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
740 else if (currentalpha < 1 || texture->skin.fog != NULL)
742 rendertype = SURFRENDER_ALPHA;
743 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
748 rendertype = SURFRENDER_OPAQUE;
749 GL_BlendFunc(GL_ONE, GL_ZERO);
750 GL_DepthMask(!(ent->effects & EF_NODEPTHTEST));
753 turb = (texture->flags & SURF_DRAWTURB) && r_waterscroll.value;
754 fullbright = !(ent->flags & RENDER_LIGHT) || (texture->flags & SURF_DRAWFULLBRIGHT) || !surface->samples;
755 base = fullbright ? 2.0f : r_ambient.value * (1.0f / 64.0f);
756 if (texture->flags & SURF_DRAWTURB)
758 if ((texture->flags & SURF_DRAWTURB) && gl_textureshader && r_watershader.value && !fogenabled && fullbright && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
760 // NVIDIA Geforce3 distortion texture shader on water
761 GL_Color(1, 1, 1, currentalpha);
762 memset(&m, 0, sizeof(m));
763 m.pointer_vertex = surface->mesh.data_vertex3f;
764 m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(r_refdef.time * 16)&63]);
765 m.tex[1] = R_GetTexture(texture->skin.base);
766 m.texcombinergb[0] = GL_REPLACE;
767 m.texcombinergb[1] = GL_REPLACE;
768 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
769 m.pointer_texcoord[1] = surface->mesh.data_texcoordtexture2f;
770 Matrix4x4_CreateFromQuakeEntity(&m.texmatrix[0], 0, 0, 0, 0, 0, 0, r_watershader.value);
771 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);
775 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
777 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
778 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
779 qglTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, &args[0]);
780 qglEnable(GL_TEXTURE_SHADER_NV);
782 GL_LockArrays(0, surface->mesh.num_vertices);
783 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
786 qglDisable(GL_TEXTURE_SHADER_NV);
787 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
792 memset(&m, 0, sizeof(m));
793 m.pointer_vertex = surface->mesh.data_vertex3f;
794 m.pointer_color = varray_color4f;
795 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
796 m.tex[0] = R_GetTexture(texture->skin.base);
799 // scrolling in texture matrix
800 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);
803 if (gl_combine.integer)
805 m.texrgbscale[0] = 4;
808 R_FillColors(varray_color4f, surface->mesh.num_vertices, base * ent->colormod[0], base * ent->colormod[1], base * ent->colormod[2], currentalpha);
811 if (surface->dlightframe == r_framecount)
812 RSurf_LightSeparate_Vertex3f_Color4f(&ent->inversematrix, surface->dlightbits, surface->mesh.num_vertices, surface->mesh.data_vertex3f, varray_color4f, 1);
813 if (surface->samples)
814 RSurf_AddLightmapToVertexColors_Color4f(surface->mesh.data_lightmapoffsets, varray_color4f,surface->mesh.num_vertices, surface->samples, ((surface->extents[0]>>4)+1)*((surface->extents[1]>>4)+1)*3, surface->styles);
816 RSurf_FogColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, colorscale, surface->mesh.num_vertices, modelorg);
818 GL_LockArrays(0, surface->mesh.num_vertices);
819 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
821 if (texture->skin.glow)
823 memset(&m, 0, sizeof(m));
824 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
826 m.pointer_color = varray_color4f;
827 m.tex[0] = R_GetTexture(texture->skin.glow);
828 m.pointer_vertex = surface->mesh.data_vertex3f;
831 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
834 // scrolling in texture matrix
835 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);
839 RSurf_FoggedColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, 1, 1, 1, currentalpha, 1, surface->mesh.num_vertices, modelorg);
840 GL_LockArrays(0, surface->mesh.num_vertices);
841 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
844 if (fogenabled && rendertype != SURFRENDER_ADD)
846 memset(&m, 0, sizeof(m));
847 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
849 m.pointer_color = varray_color4f;
850 m.tex[0] = R_GetTexture(texture->skin.fog);
851 m.pointer_vertex = surface->mesh.data_vertex3f;
854 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
857 // scrolling in texture matrix
858 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);
862 RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], currentalpha, 1, surface->mesh.num_vertices, modelorg);
863 GL_LockArrays(0, surface->mesh.num_vertices);
864 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
870 void R_UpdateTextureInfo(entity_render_t *ent)
872 int i, texframe, alttextures;
878 alttextures = ent->frame != 0;
879 texframe = (int)(r_refdef.time * 5.0f);
880 for (i = 0;i < ent->model->brush.num_textures;i++)
882 t = ent->model->brush.data_textures + i;
883 t->currentalpha = ent->alpha;
884 if (t->flags & SURF_WATERALPHA)
885 t->currentalpha *= r_wateralpha.value;
886 if (ent->effects & EF_ADDITIVE)
887 t->rendertype = SURFRENDER_ADD;
888 else if (t->currentalpha < 1 || t->skin.fog != NULL)
889 t->rendertype = SURFRENDER_ALPHA;
891 t->rendertype = SURFRENDER_OPAQUE;
892 // we don't need to set currentframe if t->animated is false because
893 // it was already set up by the texture loader for non-animating
895 t->currentframe = t->anim_frames[alttextures][(t->anim_total[alttextures] >= 2) ? (texframe % t->anim_total[alttextures]) : 0];
899 void R_DrawSurfaceList(entity_render_t *ent, texture_t *texture, int texturenumsurfaces, msurface_t **texturesurfacelist)
901 int texturesurfaceindex;
902 vec3_t tempcenter, center, modelorg;
905 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
906 if (gl_lightmaps.integer)
908 GL_BlendFunc(GL_ONE, GL_ZERO);
911 GL_Color(1, 1, 1, 1);
912 memset(&m, 0, sizeof(m));
913 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
915 surface = texturesurfacelist[texturesurfaceindex];
916 m.tex[0] = R_GetTexture(surface->lightmaptexture);
917 m.pointer_vertex = surface->mesh.data_vertex3f;
918 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
920 GL_LockArrays(0, surface->mesh.num_vertices);
921 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
925 else if (texture->rendertype != SURFRENDER_OPAQUE)
927 // transparent vertex shaded from lightmap
928 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
930 surface = texturesurfacelist[texturesurfaceindex];
931 tempcenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
932 tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
933 tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
934 Matrix4x4_Transform(&ent->matrix, tempcenter, center);
935 R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->brush.data_surfaces);
938 else if (texture->flags & SURF_LIGHTMAP)
940 qboolean dolightmap = (ent->flags & RENDER_LIGHT);
941 qboolean dobase = true;
942 qboolean doambient = r_ambient.value > 0;
943 qboolean dodetail = r_detailtextures.integer != 0;
944 qboolean doglow = texture->skin.glow != NULL;
945 qboolean dofog = fogenabled;
946 // multitexture cases
947 if (r_textureunits.integer >= 2 && gl_combine.integer && dobase && dolightmap)
951 GL_BlendFunc(GL_ONE, GL_ZERO);
954 GL_Color(1, 1, 1, 1);
955 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
956 memset(&m, 0, sizeof(m));
957 m.tex[0] = R_GetTexture(texture->skin.base);
958 m.texrgbscale[1] = 2;
959 if (r_textureunits.integer >= 3 && !doambient && dodetail)
961 m.tex[2] = R_GetTexture(texture->skin.detail);
962 m.texrgbscale[2] = 2;
964 if (r_textureunits.integer >= 3 && texture->skin.glow)
966 m.tex[3] = R_GetTexture(texture->skin.glow);
967 m.texcombinergb[3] = GL_ADD;
969 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
971 surface = texturesurfacelist[texturesurfaceindex];
972 m.tex[1] = R_GetTexture(surface->lightmaptexture);
973 m.pointer_vertex = surface->mesh.data_vertex3f;
974 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
975 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
976 m.pointer_texcoord[2] = surface->mesh.data_texcoorddetail2f;
977 m.pointer_texcoord[3] = surface->mesh.data_texcoordtexture2f;
979 GL_LockArrays(0, surface->mesh.num_vertices);
980 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
986 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
988 surface = texturesurfacelist[texturesurfaceindex];
989 m.tex[1] = R_GetTexture(surface->lightmaptexture);
990 m.pointer_vertex = surface->mesh.data_vertex3f;
991 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
992 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
993 m.pointer_texcoord[2] = surface->mesh.data_texcoorddetail2f;
995 GL_LockArrays(0, surface->mesh.num_vertices);
996 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1001 else if (r_textureunits.integer >= 3 && !doambient && !dodetail && doglow)
1003 m.tex[2] = R_GetTexture(texture->skin.glow);
1004 m.texcombinergb[2] = GL_ADD;
1006 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1008 surface = texturesurfacelist[texturesurfaceindex];
1009 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1010 m.pointer_vertex = surface->mesh.data_vertex3f;
1011 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1012 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1013 m.pointer_texcoord[2] = surface->mesh.data_texcoordtexture2f;
1015 GL_LockArrays(0, surface->mesh.num_vertices);
1016 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1017 GL_LockArrays(0, 0);
1021 // anything not handled above
1024 GL_BlendFunc(GL_ONE, GL_ZERO);
1027 GL_Color(1, 1, 1, 1);
1028 if (ent->flags & RENDER_LIGHT)
1029 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1031 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
1032 memset(&m, 0, sizeof(m));
1033 m.tex[0] = R_GetTexture(texture->skin.base);
1034 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1036 surface = texturesurfacelist[texturesurfaceindex];
1037 m.pointer_vertex = surface->mesh.data_vertex3f;
1038 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1040 GL_LockArrays(0, surface->mesh.num_vertices);
1041 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1042 GL_LockArrays(0, 0);
1045 GL_DepthMask(false);
1048 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1049 GL_DepthMask(false);
1051 GL_Color(1, 1, 1, 1);
1052 memset(&m, 0, sizeof(m));
1053 m.tex[0] = R_GetTexture(texture->skin.base);
1054 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1056 surface = texturesurfacelist[texturesurfaceindex];
1057 m.tex[0] = R_GetTexture(surface->lightmaptexture);
1058 m.pointer_vertex = surface->mesh.data_vertex3f;
1059 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
1061 GL_LockArrays(0, surface->mesh.num_vertices);
1062 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1063 GL_LockArrays(0, 0);
1068 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1069 GL_DepthMask(false);
1071 memset(&m, 0, sizeof(m));
1072 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);
1073 m.tex[0] = R_GetTexture(texture->skin.base);
1074 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1076 surface = texturesurfacelist[texturesurfaceindex];
1077 m.pointer_vertex = surface->mesh.data_vertex3f;
1078 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1080 GL_LockArrays(0, surface->mesh.num_vertices);
1081 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1082 GL_LockArrays(0, 0);
1087 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1088 GL_DepthMask(false);
1090 GL_Color(1, 1, 1, 1);
1091 memset(&m, 0, sizeof(m));
1092 m.tex[0] = R_GetTexture(texture->skin.detail);
1093 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1095 surface = texturesurfacelist[texturesurfaceindex];
1096 m.pointer_vertex = surface->mesh.data_vertex3f;
1097 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1099 GL_LockArrays(0, surface->mesh.num_vertices);
1100 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1101 GL_LockArrays(0, 0);
1106 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1107 GL_DepthMask(false);
1109 GL_Color(1, 1, 1, 1);
1110 memset(&m, 0, sizeof(m));
1111 m.tex[0] = R_GetTexture(texture->skin.glow);
1112 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1114 surface = texturesurfacelist[texturesurfaceindex];
1115 m.pointer_vertex = surface->mesh.data_vertex3f;
1116 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1118 GL_LockArrays(0, surface->mesh.num_vertices);
1119 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1120 GL_LockArrays(0, 0);
1125 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1126 GL_DepthMask(false);
1128 memset(&m, 0, sizeof(m));
1129 m.pointer_color = varray_color4f;
1130 m.tex[0] = R_GetTexture(texture->skin.glow);
1131 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1133 surface = texturesurfacelist[texturesurfaceindex];
1134 m.pointer_vertex = surface->mesh.data_vertex3f;
1136 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1138 RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], 1, 1, surface->mesh.num_vertices, modelorg);
1139 GL_LockArrays(0, surface->mesh.num_vertices);
1140 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1141 GL_LockArrays(0, 0);
1145 else if (texture->flags & SURF_DRAWTURB)
1147 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1149 surface = texturesurfacelist[texturesurfaceindex];
1150 RSurfShader_Transparent_Callback(ent, surface - ent->model->brush.data_surfaces);
1153 else if (texture->flags & SURF_DRAWSKY)
1157 skyrendernow = false;
1158 if (skyrendermasked)
1161 // LordHavoc: HalfLife maps have freaky skypolys...
1162 if (!ent->model->brush.ishlbsp)
1164 R_Mesh_Matrix(&ent->matrix);
1165 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
1166 if (skyrendermasked)
1168 // depth-only (masking)
1169 GL_ColorMask(0,0,0,0);
1170 // just to make sure that braindead drivers don't draw anything
1171 // despite that colormask...
1172 GL_BlendFunc(GL_ZERO, GL_ONE);
1177 GL_BlendFunc(GL_ONE, GL_ZERO);
1181 memset(&m, 0, sizeof(m));
1182 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1184 surface = texturesurfacelist[texturesurfaceindex];
1185 m.pointer_vertex = surface->mesh.data_vertex3f;
1187 GL_LockArrays(0, surface->mesh.num_vertices);
1188 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1189 GL_LockArrays(0, 0);
1191 GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
1196 void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
1198 int i, j, f, flagsmask;
1199 msurface_t *surface, **surfacechain;
1200 texture_t *t, *texture;
1201 model_t *model = ent->model;
1203 const int maxsurfacelist = 1024;
1204 int numsurfacelist = 0;
1205 msurface_t *surfacelist[1024];
1208 R_Mesh_Matrix(&ent->matrix);
1209 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1211 if (ent != r_refdef.worldentity)
1213 // because bmodels can be reused, we have to clear dlightframe every time
1214 surface = model->brush.data_surfaces + model->firstmodelsurface;
1215 for (i = 0;i < model->nummodelsurfaces;i++, surface++)
1216 surface->dlightframe = -1;
1219 // update light styles
1222 if (r_dynamic.integer && !r_rtdlight)
1224 for (i = 0;i < model->brushq1.light_styles;i++)
1226 if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
1228 model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
1229 if ((surfacechain = model->brushq1.light_styleupdatechains[i]))
1230 for (;(surface = *surfacechain);surfacechain++)
1231 surface->cached_dlight = true;
1236 R_UpdateTextureInfo(ent);
1237 flagsmask = skysurfaces ? SURF_DRAWSKY : (SURF_DRAWTURB | SURF_LIGHTMAP);
1241 for (i = 0, j = model->firstmodelsurface;i < model->nummodelsurfaces;i++, j++)
1243 if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
1245 surface = model->brush.data_surfaces + j;
1246 if (t != surface->texture)
1250 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1253 t = surface->texture;
1254 f = t->flags & flagsmask;
1255 texture = t->currentframe;
1259 // add face to draw list and update lightmap if necessary
1261 if (surface->cached_dlight && surface->lightmaptexture != NULL)
1262 R_BuildLightMap(ent, surface);
1263 surfacelist[numsurfacelist++] = surface;
1264 if (numsurfacelist >= maxsurfacelist)
1266 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1273 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1276 static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
1281 const mportal_t *portal = calldata1;
1282 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1283 GL_DepthMask(false);
1285 R_Mesh_Matrix(&r_identitymatrix);
1287 memset(&m, 0, sizeof(m));
1288 m.pointer_vertex = varray_vertex3f;
1292 GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f),
1293 ((i & 0x0038) >> 3) * (1.0f / 7.0f),
1294 ((i & 0x01C0) >> 6) * (1.0f / 7.0f),
1296 if (PlaneDiff(r_vieworigin, (&portal->plane)) < 0)
1298 for (i = portal->numpoints - 1, v = varray_vertex3f;i >= 0;i--, v += 3)
1299 VectorCopy(portal->points[i].position, v);
1302 for (i = 0, v = varray_vertex3f;i < portal->numpoints;i++, v += 3)
1303 VectorCopy(portal->points[i].position, v);
1304 GL_LockArrays(0, portal->numpoints);
1305 R_Mesh_Draw(portal->numpoints, portal->numpoints - 2, polygonelements);
1306 GL_LockArrays(0, 0);
1309 // LordHavoc: this is just a nice debugging tool, very slow
1310 static void R_DrawPortals(void)
1315 model_t *model = r_refdef.worldmodel;
1318 for (portalnum = 0, portal = model->brush.data_portals;portalnum < model->brush.num_portals;portalnum++, portal++)
1320 if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
1321 if (!R_CullBox(portal->mins, portal->maxs))
1323 VectorClear(center);
1324 for (i = 0;i < portal->numpoints;i++)
1325 VectorAdd(center, portal->points[i].position, center);
1326 f = ixtable[portal->numpoints];
1327 VectorScale(center, f, center);
1328 R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, portalnum);
1333 void R_WorldVisibility(void)
1338 model_t *model = r_refdef.worldmodel;
1343 // if possible find the leaf the view origin is in
1344 viewleaf = model->brushq1.PointInLeaf ? model->brushq1.PointInLeaf(model, r_vieworigin) : NULL;
1345 // if possible fetch the visible cluster bits
1346 if (model->brush.FatPVS)
1347 model->brush.FatPVS(model, r_vieworigin, 2, r_pvsbits, sizeof(r_pvsbits));
1349 // clear the visible surface and leaf flags arrays
1350 memset(r_worldsurfacevisible, 0, model->brush.num_surfaces);
1351 memset(r_worldleafvisible, 0, model->brush.num_leafs);
1353 // if the user prefers surfaceworldnode (testing?) or the viewleaf could
1354 // not be found, or the viewleaf is not part of the visible world
1355 // (floating around in the void), use the pvs method
1356 if (r_surfaceworldnode.integer || !viewleaf || viewleaf->clusterindex < 0)
1359 // similar to quake's RecursiveWorldNode but without cache misses
1360 for (j = 0, leaf = model->brush.data_leafs;j < model->brush.num_leafs;j++, leaf++)
1362 // if leaf is in current pvs and on the screen, mark its surfaces
1363 if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
1366 r_worldleafvisible[j] = true;
1367 if (leaf->numleafsurfaces)
1368 for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
1369 r_worldsurfacevisible[*mark] = true;
1377 mleaf_t *leafstack[8192];
1379 // follows portals leading outward from viewleaf, does not venture
1380 // offscreen or into leafs that are not visible, faster than Quake's
1381 // RecursiveWorldNode and vastly better in unvised maps, often culls a
1382 // lot of surface that pvs alone would miss
1383 leafstack[0] = viewleaf;
1385 while (leafstackpos)
1388 leaf = leafstack[--leafstackpos];
1389 r_worldleafvisible[leaf - model->brush.data_leafs] = true;
1390 // mark any surfaces bounding this leaf
1391 if (leaf->numleafsurfaces)
1392 for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
1393 r_worldsurfacevisible[*mark] = true;
1394 // follow portals into other leafs
1396 // if viewer is behind portal (portal faces outward into the scene)
1397 // and the portal polygon's bounding box is on the screen
1398 // and the leaf has not been visited yet
1399 // and the leaf is visible in the pvs
1400 // (the first two checks won't cause as many cache misses as the leaf checks)
1401 for (p = leaf->portals;p;p = p->next)
1402 if (DotProduct(r_vieworigin, p->plane.normal) < (p->plane.dist + 1) && !R_CullBox(p->mins, p->maxs) && !r_worldleafvisible[p->past - model->brush.data_leafs] && CHECKPVSBIT(r_pvsbits, p->past->clusterindex))
1403 leafstack[leafstackpos++] = p->past;
1407 if (r_drawportals.integer)
1411 void R_Q1BSP_DrawSky(entity_render_t *ent)
1413 if (ent->model == NULL)
1415 R_DrawSurfaces(ent, true);
1418 void R_Q1BSP_Draw(entity_render_t *ent)
1420 if (ent->model == NULL)
1423 R_DrawSurfaces(ent, false);
1426 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)
1428 model_t *model = ent->model;
1429 vec3_t lightmins, lightmaxs;
1430 int t, leafindex, leafsurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
1433 msurface_t *surface;
1436 lightmins[0] = relativelightorigin[0] - lightradius;
1437 lightmins[1] = relativelightorigin[1] - lightradius;
1438 lightmins[2] = relativelightorigin[2] - lightradius;
1439 lightmaxs[0] = relativelightorigin[0] + lightradius;
1440 lightmaxs[1] = relativelightorigin[1] + lightradius;
1441 lightmaxs[2] = relativelightorigin[2] + lightradius;
1442 *outnumclusterspointer = 0;
1443 *outnumsurfacespointer = 0;
1444 memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
1445 memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
1448 VectorCopy(lightmins, outmins);
1449 VectorCopy(lightmaxs, outmaxs);
1452 VectorCopy(relativelightorigin, outmins);
1453 VectorCopy(relativelightorigin, outmaxs);
1454 if (model->brush.GetPVS)
1455 pvs = model->brush.GetPVS(model, relativelightorigin);
1458 // FIXME: use BSP recursion as lights are often small
1459 for (leafindex = 0, leaf = model->brush.data_leafs;leafindex < model->brush.num_leafs;leafindex++, leaf++)
1461 if (BoxesOverlap(lightmins, lightmaxs, leaf->mins, leaf->maxs) && (pvs == NULL || CHECKPVSBIT(pvs, leaf->clusterindex)))
1463 outmins[0] = min(outmins[0], leaf->mins[0]);
1464 outmins[1] = min(outmins[1], leaf->mins[1]);
1465 outmins[2] = min(outmins[2], leaf->mins[2]);
1466 outmaxs[0] = max(outmaxs[0], leaf->maxs[0]);
1467 outmaxs[1] = max(outmaxs[1], leaf->maxs[1]);
1468 outmaxs[2] = max(outmaxs[2], leaf->maxs[2]);
1471 if (!CHECKPVSBIT(outclusterpvs, leaf->clusterindex))
1473 SETPVSBIT(outclusterpvs, leaf->clusterindex);
1474 outclusterlist[outnumclusters++] = leaf->clusterindex;
1479 for (leafsurfaceindex = 0;leafsurfaceindex < leaf->numleafsurfaces;leafsurfaceindex++)
1481 surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
1482 if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
1484 surface = model->brush.data_surfaces + surfaceindex;
1485 if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && (surface->texture->flags & SURF_LIGHTMAP) && !surface->texture->skin.fog)
1487 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
1489 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
1490 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
1491 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
1492 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])))
1494 SETPVSBIT(outsurfacepvs, surfaceindex);
1495 outsurfacelist[outnumsurfaces++] = surfaceindex;
1506 // limit combined leaf box to light boundaries
1507 outmins[0] = max(outmins[0], lightmins[0]);
1508 outmins[1] = max(outmins[1], lightmins[1]);
1509 outmins[2] = max(outmins[2], lightmins[2]);
1510 outmaxs[0] = min(outmaxs[0], lightmaxs[0]);
1511 outmaxs[1] = min(outmaxs[1], lightmaxs[1]);
1512 outmaxs[2] = min(outmaxs[2], lightmaxs[2]);
1514 *outnumclusterspointer = outnumclusters;
1515 *outnumsurfacespointer = outnumsurfaces;
1518 void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
1520 model_t *model = ent->model;
1521 vec3_t lightmins, lightmaxs;
1522 msurface_t *surface;
1523 int surfacelistindex;
1524 if (r_drawcollisionbrushes.integer < 2)
1526 lightmins[0] = relativelightorigin[0] - lightradius;
1527 lightmins[1] = relativelightorigin[1] - lightradius;
1528 lightmins[2] = relativelightorigin[2] - lightradius;
1529 lightmaxs[0] = relativelightorigin[0] + lightradius;
1530 lightmaxs[1] = relativelightorigin[1] + lightradius;
1531 lightmaxs[2] = relativelightorigin[2] + lightradius;
1532 R_Mesh_Matrix(&ent->matrix);
1533 R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
1534 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1536 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
1537 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);
1539 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);
1543 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)
1545 model_t *model = ent->model;
1546 vec3_t lightmins, lightmaxs, modelorg;
1547 msurface_t *surface;
1549 int surfacelistindex;
1550 if (r_drawcollisionbrushes.integer < 2)
1552 lightmins[0] = relativelightorigin[0] - lightradius;
1553 lightmins[1] = relativelightorigin[1] - lightradius;
1554 lightmins[2] = relativelightorigin[2] - lightradius;
1555 lightmaxs[0] = relativelightorigin[0] + lightradius;
1556 lightmaxs[1] = relativelightorigin[1] + lightradius;
1557 lightmaxs[2] = relativelightorigin[2] + lightradius;
1558 R_Mesh_Matrix(&ent->matrix);
1559 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1560 R_UpdateTextureInfo(ent);
1561 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1563 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
1564 if (r_shadow_compilingrtlight)
1566 // if compiling an rtlight, capture the mesh
1567 t = surface->texture;
1568 if (t->flags & SURF_LIGHTMAP && t->skin.fog == NULL)
1569 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);
1571 else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surfacelist[surfacelistindex]])
1573 t = surface->texture->currentframe;
1574 // FIXME: transparent surfaces need to be lit later
1575 if (t->flags & SURF_LIGHTMAP && t->rendertype == SURFRENDER_OPAQUE)
1576 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);
1582 void R_DrawCollisionBrush(colbrushf_t *brush)
1586 memset(&m, 0, sizeof(m));
1587 m.pointer_vertex = brush->points->v;
1589 i = (int)(((size_t)brush) / sizeof(colbrushf_t));
1590 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1591 GL_LockArrays(0, brush->numpoints);
1592 R_Mesh_Draw(brush->numpoints, brush->numtriangles, brush->elements);
1593 GL_LockArrays(0, 0);
1596 void R_Q3BSP_DrawCollisionSurface(entity_render_t *ent, msurface_t *surface)
1600 if (!surface->mesh.num_collisiontriangles)
1602 memset(&m, 0, sizeof(m));
1603 m.pointer_vertex = surface->mesh.data_collisionvertex3f;
1605 i = (int)(((size_t)surface) / sizeof(msurface_t));
1606 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1607 GL_LockArrays(0, surface->mesh.num_collisionvertices);
1608 R_Mesh_Draw(surface->mesh.num_collisionvertices, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i);
1609 GL_LockArrays(0, 0);
1612 void R_Q3BSP_DrawFace_TransparentCallback(const void *voident, int surfacenumber)
1614 const entity_render_t *ent = voident;
1615 msurface_t *surface = ent->model->brush.data_surfaces + surfacenumber;
1617 R_Mesh_Matrix(&ent->matrix);
1618 memset(&m, 0, sizeof(m));
1619 if ((ent->effects & EF_ADDITIVE) || (surface->texture->textureflags & Q3TEXTUREFLAG_ADDITIVE))
1620 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1622 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1623 GL_DepthMask(false);
1624 GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
1625 m.tex[0] = R_GetTexture(surface->texture->skin.base);
1626 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1627 // LordHavoc: quake3 was not able to do this; lit transparent surfaces
1628 if (gl_combine.integer)
1630 m.texrgbscale[0] = 2;
1631 if (r_textureunits.integer >= 2)
1633 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1634 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1635 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], ent->alpha);
1639 if (ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1 && ent->alpha == 1)
1640 m.pointer_color = surface->mesh.data_lightmapcolor4f;
1644 for (i = 0;i < surface->mesh.num_vertices;i++)
1646 varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0];
1647 varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1];
1648 varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2];
1649 varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3] * ent->alpha;
1651 m.pointer_color = varray_color4f;
1658 for (i = 0;i < surface->mesh.num_vertices;i++)
1660 varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0] * 2.0f;
1661 varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1] * 2.0f;
1662 varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2] * 2.0f;
1663 varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3] * ent->alpha;
1665 m.pointer_color = varray_color4f;
1667 if (surface->texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
1670 float center[3], center2[3], forward[3], right[3], up[3], v[4][3];
1671 matrix4x4_t matrix1, imatrix1;
1672 R_Mesh_Matrix(&r_identitymatrix);
1673 // a single autosprite surface can contain multiple sprites...
1674 for (j = 0;j < surface->mesh.num_vertices - 3;j += 4)
1676 VectorClear(center);
1677 for (i = 0;i < 4;i++)
1678 VectorAdd(center, surface->mesh.data_vertex3f + (j+i) * 3, center);
1679 VectorScale(center, 0.25f, center);
1680 Matrix4x4_Transform(&ent->matrix, center, center2);
1681 // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
1682 Matrix4x4_FromVectors(&matrix1, surface->mesh.data_normal3f + j*3, surface->mesh.data_svector3f + j*3, surface->mesh.data_tvector3f + j*3, center);
1683 Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
1684 for (i = 0;i < 4;i++)
1685 Matrix4x4_Transform(&imatrix1, surface->mesh.data_vertex3f + (j+i)*3, v[i]);
1686 if (surface->texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE2)
1688 forward[0] = r_vieworigin[0] - center2[0];
1689 forward[1] = r_vieworigin[1] - center2[1];
1691 VectorNormalize(forward);
1692 right[0] = forward[1];
1693 right[1] = -forward[0];
1701 VectorCopy(r_viewforward, forward);
1702 VectorCopy(r_viewright, right);
1703 VectorCopy(r_viewup, up);
1705 for (i = 0;i < 4;i++)
1706 VectorMAMAMAM(1, center2, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (i+j) * 3);
1708 m.pointer_vertex = varray_vertex3f;
1711 m.pointer_vertex = surface->mesh.data_vertex3f;
1713 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1714 qglDisable(GL_CULL_FACE);
1715 GL_LockArrays(0, surface->mesh.num_vertices);
1716 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1717 GL_LockArrays(0, 0);
1718 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1719 qglEnable(GL_CULL_FACE);
1722 void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurfaces, msurface_t **texturesurfacelist)
1724 int i, texturesurfaceindex;
1725 msurface_t *surface;
1726 qboolean dolightmap;
1732 if (!texturenumsurfaces)
1734 c_faces += texturenumsurfaces;
1735 // gl_lightmaps debugging mode skips normal texturing
1736 if (gl_lightmaps.integer)
1740 GL_BlendFunc(GL_ONE, GL_ZERO);
1741 qglDisable(GL_CULL_FACE);
1742 memset(&m, 0, sizeof(m));
1743 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1745 surface = texturesurfacelist[texturesurfaceindex];
1746 m.tex[0] = R_GetTexture(surface->lightmaptexture);
1747 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
1748 if (surface->lightmaptexture)
1750 GL_Color(1, 1, 1, 1);
1751 m.pointer_color = NULL;
1754 m.pointer_color = surface->mesh.data_lightmapcolor4f;
1755 m.pointer_vertex = surface->mesh.data_vertex3f;
1757 GL_LockArrays(0, surface->mesh.num_vertices);
1758 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1759 GL_LockArrays(0, 0);
1761 qglEnable(GL_CULL_FACE);
1764 // transparent surfaces get sorted for later drawing
1765 if ((t->surfaceparms & Q3SURFACEPARM_TRANS) || ent->alpha < 1 || (ent->effects & EF_ADDITIVE))
1767 vec3_t facecenter, center;
1768 // drawing sky transparently would be too difficult
1769 if (t->surfaceparms & Q3SURFACEPARM_SKY)
1771 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1773 surface = texturesurfacelist[texturesurfaceindex];
1774 facecenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
1775 facecenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
1776 facecenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
1777 Matrix4x4_Transform(&ent->matrix, facecenter, center);
1778 R_MeshQueue_AddTransparent(center, R_Q3BSP_DrawFace_TransparentCallback, ent, surface - ent->model->brush.data_surfaces);
1782 // sky surfaces draw sky if needed and render themselves as a depth mask
1783 if (t->surfaceparms & Q3SURFACEPARM_SKY)
1787 skyrendernow = false;
1788 if (skyrendermasked)
1791 if (!r_q3bsp_renderskydepth.integer)
1794 R_Mesh_Matrix(&ent->matrix);
1796 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
1797 if (skyrendermasked)
1799 // depth-only (masking)
1800 GL_ColorMask(0,0,0,0);
1801 // just to make sure that braindead drivers don't draw anything
1802 // despite that colormask...
1803 GL_BlendFunc(GL_ZERO, GL_ONE);
1808 GL_BlendFunc(GL_ONE, GL_ZERO);
1813 memset(&m, 0, sizeof(m));
1814 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1816 surface = texturesurfacelist[texturesurfaceindex];
1817 m.pointer_vertex = surface->mesh.data_vertex3f;
1819 GL_LockArrays(0, surface->mesh.num_vertices);
1820 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1821 GL_LockArrays(0, 0);
1823 GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
1826 // anything else is a typical wall, lightmap * texture + glow
1827 dolightmap = (ent->flags & RENDER_LIGHT);
1829 doambient = r_ambient.value > 0;
1830 doglow = t->skin.glow != NULL;
1832 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1833 qglDisable(GL_CULL_FACE);
1834 if (!dolightmap && dobase)
1840 GL_BlendFunc(GL_ONE, GL_ZERO);
1841 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
1842 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1843 qglDisable(GL_CULL_FACE);
1844 memset(&m, 0, sizeof(m));
1845 m.tex[0] = R_GetTexture(t->skin.base);
1846 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1848 surface = texturesurfacelist[texturesurfaceindex];
1849 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1850 m.pointer_vertex = surface->mesh.data_vertex3f;
1852 GL_LockArrays(0, surface->mesh.num_vertices);
1853 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1854 GL_LockArrays(0, 0);
1857 if (r_lightmapintensity <= 0 && dolightmap && dobase)
1863 GL_BlendFunc(GL_ONE, GL_ZERO);
1864 GL_Color(0, 0, 0, 1);
1865 memset(&m, 0, sizeof(m));
1866 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1868 surface = texturesurfacelist[texturesurfaceindex];
1869 m.pointer_vertex = surface->mesh.data_vertex3f;
1871 GL_LockArrays(0, surface->mesh.num_vertices);
1872 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1873 GL_LockArrays(0, 0);
1876 if (r_textureunits.integer >= 2 && gl_combine.integer && dolightmap && dobase)
1878 // dualtexture combine
1883 GL_BlendFunc(GL_ONE, GL_ZERO);
1884 memset(&m, 0, sizeof(m));
1885 m.tex[0] = R_GetTexture(t->skin.base);
1886 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1887 m.pointer_color = NULL;
1888 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1890 surface = texturesurfacelist[texturesurfaceindex];
1891 if (!surface->lightmaptexture)
1893 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1894 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1895 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1896 m.texrgbscale[1] = 2;
1897 m.pointer_vertex = surface->mesh.data_vertex3f;
1899 GL_LockArrays(0, surface->mesh.num_vertices);
1900 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1901 GL_LockArrays(0, 0);
1903 if (r_lightmapintensity == 1 && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
1905 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1907 surface = texturesurfacelist[texturesurfaceindex];
1908 if (surface->lightmaptexture)
1910 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1911 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1912 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1913 m.texrgbscale[1] = 2;
1914 m.pointer_color = surface->mesh.data_lightmapcolor4f;
1915 m.pointer_vertex = surface->mesh.data_vertex3f;
1917 GL_LockArrays(0, surface->mesh.num_vertices);
1918 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1919 GL_LockArrays(0, 0);
1924 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1926 surface = texturesurfacelist[texturesurfaceindex];
1927 if (surface->lightmaptexture)
1929 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1930 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1931 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1932 m.texrgbscale[1] = 2;
1933 m.pointer_color = varray_color4f;
1934 for (i = 0;i < surface->mesh.num_vertices;i++)
1936 varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0] * r_lightmapintensity;
1937 varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1] * r_lightmapintensity;
1938 varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2] * r_lightmapintensity;
1939 varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3];
1941 m.pointer_vertex = surface->mesh.data_vertex3f;
1943 GL_LockArrays(0, surface->mesh.num_vertices);
1944 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1945 GL_LockArrays(0, 0);
1954 GL_BlendFunc(GL_ONE, GL_ZERO);
1955 memset(&m, 0, sizeof(m));
1956 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1958 surface = texturesurfacelist[texturesurfaceindex];
1959 m.tex[0] = R_GetTexture(surface->lightmaptexture);
1960 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
1961 if (surface->lightmaptexture)
1962 m.pointer_color = NULL;
1964 m.pointer_color = surface->mesh.data_lightmapcolor4f;
1965 m.pointer_vertex = surface->mesh.data_vertex3f;
1967 GL_LockArrays(0, surface->mesh.num_vertices);
1968 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1969 GL_LockArrays(0, 0);
1974 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1975 GL_DepthMask(false);
1977 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1978 memset(&m, 0, sizeof(m));
1979 m.tex[0] = R_GetTexture(t->skin.base);
1980 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1982 surface = texturesurfacelist[texturesurfaceindex];
1983 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1984 m.pointer_vertex = surface->mesh.data_vertex3f;
1986 GL_LockArrays(0, surface->mesh.num_vertices);
1987 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1988 GL_LockArrays(0, 0);
1993 GL_BlendFunc(GL_ONE, GL_ONE);
1994 GL_DepthMask(false);
1996 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);
1997 memset(&m, 0, sizeof(m));
1998 m.tex[0] = R_GetTexture(t->skin.base);
1999 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
2001 surface = texturesurfacelist[texturesurfaceindex];
2002 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
2003 m.pointer_vertex = surface->mesh.data_vertex3f;
2005 GL_LockArrays(0, surface->mesh.num_vertices);
2006 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
2007 GL_LockArrays(0, 0);
2012 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
2013 GL_DepthMask(false);
2015 GL_Color(1, 1, 1, 1);
2016 memset(&m, 0, sizeof(m));
2017 m.tex[0] = R_GetTexture(t->skin.glow);
2018 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
2020 surface = texturesurfacelist[texturesurfaceindex];
2021 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
2022 m.pointer_vertex = surface->mesh.data_vertex3f;
2024 GL_LockArrays(0, surface->mesh.num_vertices);
2025 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
2026 GL_LockArrays(0, 0);
2032 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
2033 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2034 GL_DepthMask(false);
2036 GL_Color(1, 1, 1, 1);
2037 memset(&m, 0, sizeof(m));
2038 m.tex[0] = R_GetTexture(t->skin.fog);
2039 m.pointer_color = varray_color4f;
2040 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
2042 surface = texturesurfacelist[texturesurfaceindex];
2044 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
2045 m.pointer_vertex = surface->mesh.data_vertex3f;
2047 RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], 1, 1, surface->mesh.num_vertices, modelorg);
2048 GL_LockArrays(0, surface->mesh.num_vertices);
2049 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
2050 GL_LockArrays(0, 0);
2053 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2054 qglEnable(GL_CULL_FACE);
2057 void R_Q3BSP_DrawFaces(entity_render_t *ent, int skyfaces)
2059 int i, j, f, flagsmask, flags;
2060 msurface_t *surface;
2061 model_t *model = ent->model;
2063 const int maxfaces = 1024;
2064 int numsurfaces = 0;
2065 msurface_t *surfacelist[1024];
2066 R_Mesh_Matrix(&ent->matrix);
2067 flagsmask = Q3SURFACEFLAG_NODRAW | Q3SURFACEFLAG_SKY;
2069 flags = Q3SURFACEFLAG_SKY;
2075 for (i = 0, j = model->firstmodelsurface;i < model->nummodelsurfaces;i++, j++)
2077 if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
2079 surface = model->brush.data_surfaces + j;
2080 if (t != surface->texture)
2084 R_Q3BSP_DrawFaceList(ent, t, numsurfaces, surfacelist);
2087 t = surface->texture;
2088 f = t->surfaceflags & flagsmask;
2092 if (!surface->mesh.num_triangles)
2094 surfacelist[numsurfaces++] = surface;
2095 if (numsurfaces >= maxfaces)
2097 R_Q3BSP_DrawFaceList(ent, t, numsurfaces, surfacelist);
2104 R_Q3BSP_DrawFaceList(ent, t, numsurfaces, surfacelist);
2107 void R_Q3BSP_DrawSky(entity_render_t *ent)
2109 if (r_drawcollisionbrushes.integer < 2)
2110 R_Q3BSP_DrawFaces(ent, true);
2113 void R_Q3BSP_Draw(entity_render_t *ent)
2115 if (r_drawcollisionbrushes.integer < 2)
2116 R_Q3BSP_DrawFaces(ent, false);
2117 if (r_drawcollisionbrushes.integer >= 1)
2120 model_t *model = ent->model;
2121 msurface_t *surface;
2123 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
2124 GL_DepthMask(false);
2126 qglPolygonOffset(r_drawcollisionbrushes_polygonfactor.value, r_drawcollisionbrushes_polygonoffset.value);
2127 for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
2128 if (brush->colbrushf && brush->colbrushf->numtriangles)
2129 R_DrawCollisionBrush(brush->colbrushf);
2130 for (i = 0, surface = model->brush.data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
2131 if (surface->mesh.num_collisiontriangles)
2132 R_Q3BSP_DrawCollisionSurface(ent, surface);
2133 qglPolygonOffset(0, 0);
2137 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)
2139 model_t *model = ent->model;
2140 vec3_t lightmins, lightmaxs;
2141 int t, leafindex, leafsurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
2144 msurface_t *surface;
2147 lightmins[0] = relativelightorigin[0] - lightradius;
2148 lightmins[1] = relativelightorigin[1] - lightradius;
2149 lightmins[2] = relativelightorigin[2] - lightradius;
2150 lightmaxs[0] = relativelightorigin[0] + lightradius;
2151 lightmaxs[1] = relativelightorigin[1] + lightradius;
2152 lightmaxs[2] = relativelightorigin[2] + lightradius;
2153 *outnumclusterspointer = 0;
2154 *outnumsurfacespointer = 0;
2155 memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
2156 memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
2159 VectorCopy(lightmins, outmins);
2160 VectorCopy(lightmaxs, outmaxs);
2163 VectorCopy(relativelightorigin, outmins);
2164 VectorCopy(relativelightorigin, outmaxs);
2165 if (model->brush.GetPVS)
2166 pvs = model->brush.GetPVS(model, relativelightorigin);
2169 // FIXME: use BSP recursion as lights are often small
2170 for (leafindex = 0, leaf = model->brush.data_leafs;leafindex < model->brush.num_leafs;leafindex++, leaf++)
2172 if (BoxesOverlap(lightmins, lightmaxs, leaf->mins, leaf->maxs) && (pvs == NULL || CHECKPVSBIT(pvs, leaf->clusterindex)))
2174 outmins[0] = min(outmins[0], leaf->mins[0]);
2175 outmins[1] = min(outmins[1], leaf->mins[1]);
2176 outmins[2] = min(outmins[2], leaf->mins[2]);
2177 outmaxs[0] = max(outmaxs[0], leaf->maxs[0]);
2178 outmaxs[1] = max(outmaxs[1], leaf->maxs[1]);
2179 outmaxs[2] = max(outmaxs[2], leaf->maxs[2]);
2182 if (!CHECKPVSBIT(outclusterpvs, leaf->clusterindex))
2184 SETPVSBIT(outclusterpvs, leaf->clusterindex);
2185 outclusterlist[outnumclusters++] = leaf->clusterindex;
2190 for (leafsurfaceindex = 0;leafsurfaceindex < leaf->numleafsurfaces;leafsurfaceindex++)
2192 surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
2193 surface = model->brush.data_surfaces + surfaceindex;
2194 if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
2196 if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS) && !(surface->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)) && surface->mesh.num_triangles)
2198 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2200 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
2202 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
2203 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
2204 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
2205 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])))
2207 SETPVSBIT(outsurfacepvs, surfaceindex);
2208 outsurfacelist[outnumsurfaces++] = surfaceindex;
2215 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
2217 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
2218 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
2219 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
2220 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])))
2222 SETPVSBIT(outsurfacepvs, surfaceindex);
2223 outsurfacelist[outnumsurfaces++] = surfaceindex;
2235 // limit combined leaf box to light boundaries
2236 outmins[0] = max(outmins[0], lightmins[0]);
2237 outmins[1] = max(outmins[1], lightmins[1]);
2238 outmins[2] = max(outmins[2], lightmins[2]);
2239 outmaxs[0] = min(outmaxs[0], lightmaxs[0]);
2240 outmaxs[1] = min(outmaxs[1], lightmaxs[1]);
2241 outmaxs[2] = min(outmaxs[2], lightmaxs[2]);
2243 *outnumclusterspointer = outnumclusters;
2244 *outnumsurfacespointer = outnumsurfaces;
2247 void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
2249 model_t *model = ent->model;
2250 vec3_t lightmins, lightmaxs;
2251 msurface_t *surface;
2252 int surfacelistindex;
2253 if (r_drawcollisionbrushes.integer < 2)
2255 lightmins[0] = relativelightorigin[0] - lightradius;
2256 lightmins[1] = relativelightorigin[1] - lightradius;
2257 lightmins[2] = relativelightorigin[2] - lightradius;
2258 lightmaxs[0] = relativelightorigin[0] + lightradius;
2259 lightmaxs[1] = relativelightorigin[1] + lightradius;
2260 lightmaxs[2] = relativelightorigin[2] + lightradius;
2261 R_Mesh_Matrix(&ent->matrix);
2262 R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
2263 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
2265 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
2266 // FIXME: check some manner of surface->rendermode here?
2267 if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && !(surface->texture->surfaceparms & (Q3SURFACEPARM_SKY | Q3SURFACEPARM_TRANS)) && !(surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED))
2268 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);
2270 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);
2274 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)
2276 model_t *model = ent->model;
2277 vec3_t lightmins, lightmaxs, modelorg;
2278 msurface_t *surface;
2279 int surfacelistindex;
2280 if (r_drawcollisionbrushes.integer < 2)
2282 lightmins[0] = relativelightorigin[0] - lightradius;
2283 lightmins[1] = relativelightorigin[1] - lightradius;
2284 lightmins[2] = relativelightorigin[2] - lightradius;
2285 lightmaxs[0] = relativelightorigin[0] + lightradius;
2286 lightmaxs[1] = relativelightorigin[1] + lightradius;
2287 lightmaxs[2] = relativelightorigin[2] + lightradius;
2288 R_Mesh_Matrix(&ent->matrix);
2289 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
2290 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
2292 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
2293 if (r_shadow_compilingrtlight)
2295 // if compiling an rtlight, capture the mesh
2296 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);
2298 else if ((ent != r_refdef.worldentity || r_worldsurfacevisible[surfacelist[surfacelistindex]]) && !(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && surface->mesh.num_triangles)
2300 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2301 qglDisable(GL_CULL_FACE);
2302 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);
2303 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2304 qglEnable(GL_CULL_FACE);
2311 static void gl_surf_start(void)
2315 static void gl_surf_shutdown(void)
2319 static void gl_surf_newmap(void)
2324 void GL_Surf_Init(void)
2327 dlightdivtable[0] = 4194304;
2328 for (i = 1;i < 32768;i++)
2329 dlightdivtable[i] = 4194304 / (i << 7);
2331 Cvar_RegisterVariable(&r_ambient);
2332 Cvar_RegisterVariable(&r_drawportals);
2333 Cvar_RegisterVariable(&r_testvis);
2334 Cvar_RegisterVariable(&r_floatbuildlightmap);
2335 Cvar_RegisterVariable(&r_detailtextures);
2336 Cvar_RegisterVariable(&r_surfaceworldnode);
2337 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor);
2338 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);
2339 Cvar_RegisterVariable(&r_q3bsp_renderskydepth);
2340 Cvar_RegisterVariable(&gl_lightmaps);
2342 //R_RegisterModule("GL_Surf", gl_surf_start, gl_surf_shutdown, gl_surf_newmap);