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)
949 GL_BlendFunc(GL_ONE, GL_ZERO);
952 GL_Color(1, 1, 1, 1);
953 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
954 memset(&m, 0, sizeof(m));
955 m.tex[0] = R_GetTexture(texture->skin.base);
957 m.texrgbscale[1] = 2;
959 if (r_textureunits.integer >= 4 && !doambient && dodetail && doglow)
961 m.tex[2] = R_GetTexture(texture->skin.detail);
962 m.texrgbscale[2] = 2;
964 m.tex[3] = R_GetTexture(texture->skin.glow);
965 m.texcombinergb[3] = GL_ADD;
967 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
969 surface = texturesurfacelist[texturesurfaceindex];
970 m.tex[1] = R_GetTexture(surface->lightmaptexture);
971 m.pointer_vertex = surface->mesh.data_vertex3f;
972 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
973 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
974 m.pointer_texcoord[2] = surface->mesh.data_texcoorddetail2f;
975 m.pointer_texcoord[3] = surface->mesh.data_texcoordtexture2f;
977 GL_LockArrays(0, surface->mesh.num_vertices);
978 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
982 else if (r_textureunits.integer >= 3 && !doambient && dodetail)
984 m.tex[2] = R_GetTexture(texture->skin.detail);
985 m.texrgbscale[2] = 2;
987 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
989 surface = texturesurfacelist[texturesurfaceindex];
990 m.tex[1] = R_GetTexture(surface->lightmaptexture);
991 m.pointer_vertex = surface->mesh.data_vertex3f;
992 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
993 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
994 m.pointer_texcoord[2] = surface->mesh.data_texcoorddetail2f;
996 GL_LockArrays(0, surface->mesh.num_vertices);
997 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);
1022 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1024 surface = texturesurfacelist[texturesurfaceindex];
1025 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1026 m.pointer_vertex = surface->mesh.data_vertex3f;
1027 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1028 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1030 GL_LockArrays(0, surface->mesh.num_vertices);
1031 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1032 GL_LockArrays(0, 0);
1036 // anything not handled above
1039 GL_BlendFunc(GL_ONE, GL_ZERO);
1042 GL_Color(1, 1, 1, 1);
1043 if (ent->flags & RENDER_LIGHT)
1044 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1046 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
1047 memset(&m, 0, sizeof(m));
1048 m.tex[0] = R_GetTexture(texture->skin.base);
1049 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1051 surface = texturesurfacelist[texturesurfaceindex];
1052 m.pointer_vertex = surface->mesh.data_vertex3f;
1053 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1055 GL_LockArrays(0, surface->mesh.num_vertices);
1056 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1057 GL_LockArrays(0, 0);
1060 GL_DepthMask(false);
1063 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1064 GL_DepthMask(false);
1066 GL_Color(1, 1, 1, 1);
1067 memset(&m, 0, sizeof(m));
1068 m.tex[0] = R_GetTexture(texture->skin.base);
1069 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1071 surface = texturesurfacelist[texturesurfaceindex];
1072 m.tex[0] = R_GetTexture(surface->lightmaptexture);
1073 m.pointer_vertex = surface->mesh.data_vertex3f;
1074 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
1076 GL_LockArrays(0, surface->mesh.num_vertices);
1077 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1078 GL_LockArrays(0, 0);
1083 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1084 GL_DepthMask(false);
1086 memset(&m, 0, sizeof(m));
1087 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);
1088 m.tex[0] = R_GetTexture(texture->skin.base);
1089 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1091 surface = texturesurfacelist[texturesurfaceindex];
1092 m.pointer_vertex = surface->mesh.data_vertex3f;
1093 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1095 GL_LockArrays(0, surface->mesh.num_vertices);
1096 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1097 GL_LockArrays(0, 0);
1102 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1103 GL_DepthMask(false);
1105 GL_Color(1, 1, 1, 1);
1106 memset(&m, 0, sizeof(m));
1107 m.tex[0] = R_GetTexture(texture->skin.detail);
1108 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1110 surface = texturesurfacelist[texturesurfaceindex];
1111 m.pointer_vertex = surface->mesh.data_vertex3f;
1112 m.pointer_texcoord[0] = surface->mesh.data_texcoorddetail2f;
1114 GL_LockArrays(0, surface->mesh.num_vertices);
1115 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1116 GL_LockArrays(0, 0);
1121 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1122 GL_DepthMask(false);
1124 GL_Color(1, 1, 1, 1);
1125 memset(&m, 0, sizeof(m));
1126 m.tex[0] = R_GetTexture(texture->skin.glow);
1127 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1129 surface = texturesurfacelist[texturesurfaceindex];
1130 m.pointer_vertex = surface->mesh.data_vertex3f;
1131 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1133 GL_LockArrays(0, surface->mesh.num_vertices);
1134 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1135 GL_LockArrays(0, 0);
1140 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1141 GL_DepthMask(false);
1143 memset(&m, 0, sizeof(m));
1144 m.pointer_color = varray_color4f;
1145 m.tex[0] = R_GetTexture(texture->skin.glow);
1146 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1148 surface = texturesurfacelist[texturesurfaceindex];
1149 m.pointer_vertex = surface->mesh.data_vertex3f;
1151 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1153 RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], 1, 1, surface->mesh.num_vertices, modelorg);
1154 GL_LockArrays(0, surface->mesh.num_vertices);
1155 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1156 GL_LockArrays(0, 0);
1160 else if (texture->flags & SURF_DRAWTURB)
1162 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1164 surface = texturesurfacelist[texturesurfaceindex];
1165 RSurfShader_Transparent_Callback(ent, surface - ent->model->brush.data_surfaces);
1168 else if (texture->flags & SURF_DRAWSKY)
1172 skyrendernow = false;
1173 if (skyrendermasked)
1176 // LordHavoc: HalfLife maps have freaky skypolys...
1177 if (!ent->model->brush.ishlbsp)
1179 R_Mesh_Matrix(&ent->matrix);
1180 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
1181 if (skyrendermasked)
1183 // depth-only (masking)
1184 GL_ColorMask(0,0,0,0);
1185 // just to make sure that braindead drivers don't draw anything
1186 // despite that colormask...
1187 GL_BlendFunc(GL_ZERO, GL_ONE);
1192 GL_BlendFunc(GL_ONE, GL_ZERO);
1196 memset(&m, 0, sizeof(m));
1197 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1199 surface = texturesurfacelist[texturesurfaceindex];
1200 m.pointer_vertex = surface->mesh.data_vertex3f;
1202 GL_LockArrays(0, surface->mesh.num_vertices);
1203 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1204 GL_LockArrays(0, 0);
1206 GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
1211 void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
1213 int i, j, f, flagsmask;
1214 msurface_t *surface, **surfacechain;
1215 texture_t *t, *texture;
1216 model_t *model = ent->model;
1218 const int maxsurfacelist = 1024;
1219 int numsurfacelist = 0;
1220 msurface_t *surfacelist[1024];
1223 R_Mesh_Matrix(&ent->matrix);
1224 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1226 if (ent != r_refdef.worldentity)
1228 // because bmodels can be reused, we have to clear dlightframe every time
1229 surface = model->brush.data_surfaces + model->firstmodelsurface;
1230 for (i = 0;i < model->nummodelsurfaces;i++, surface++)
1231 surface->dlightframe = -1;
1234 // update light styles
1237 if (r_dynamic.integer && !r_rtdlight)
1239 for (i = 0;i < model->brushq1.light_styles;i++)
1241 if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
1243 model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
1244 if ((surfacechain = model->brushq1.light_styleupdatechains[i]))
1245 for (;(surface = *surfacechain);surfacechain++)
1246 surface->cached_dlight = true;
1251 R_UpdateTextureInfo(ent);
1252 flagsmask = skysurfaces ? SURF_DRAWSKY : (SURF_DRAWTURB | SURF_LIGHTMAP);
1256 for (i = 0, j = model->firstmodelsurface;i < model->nummodelsurfaces;i++, j++)
1258 if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
1260 surface = model->brush.data_surfaces + j;
1261 if (t != surface->texture)
1265 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1268 t = surface->texture;
1269 f = t->flags & flagsmask;
1270 texture = t->currentframe;
1274 // add face to draw list and update lightmap if necessary
1276 if (surface->cached_dlight && surface->lightmaptexture != NULL)
1277 R_BuildLightMap(ent, surface);
1278 surfacelist[numsurfacelist++] = surface;
1279 if (numsurfacelist >= maxsurfacelist)
1281 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1288 R_DrawSurfaceList(ent, texture, numsurfacelist, surfacelist);
1291 static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
1296 const mportal_t *portal = calldata1;
1297 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1298 GL_DepthMask(false);
1300 R_Mesh_Matrix(&r_identitymatrix);
1302 memset(&m, 0, sizeof(m));
1303 m.pointer_vertex = varray_vertex3f;
1307 GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f),
1308 ((i & 0x0038) >> 3) * (1.0f / 7.0f),
1309 ((i & 0x01C0) >> 6) * (1.0f / 7.0f),
1311 if (PlaneDiff(r_vieworigin, (&portal->plane)) < 0)
1313 for (i = portal->numpoints - 1, v = varray_vertex3f;i >= 0;i--, v += 3)
1314 VectorCopy(portal->points[i].position, v);
1317 for (i = 0, v = varray_vertex3f;i < portal->numpoints;i++, v += 3)
1318 VectorCopy(portal->points[i].position, v);
1319 GL_LockArrays(0, portal->numpoints);
1320 R_Mesh_Draw(portal->numpoints, portal->numpoints - 2, polygonelements);
1321 GL_LockArrays(0, 0);
1324 // LordHavoc: this is just a nice debugging tool, very slow
1325 static void R_DrawPortals(void)
1330 model_t *model = r_refdef.worldmodel;
1333 for (portalnum = 0, portal = model->brush.data_portals;portalnum < model->brush.num_portals;portalnum++, portal++)
1335 if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
1336 if (!R_CullBox(portal->mins, portal->maxs))
1338 VectorClear(center);
1339 for (i = 0;i < portal->numpoints;i++)
1340 VectorAdd(center, portal->points[i].position, center);
1341 f = ixtable[portal->numpoints];
1342 VectorScale(center, f, center);
1343 R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, portalnum);
1348 void R_WorldVisibility(void)
1353 model_t *model = r_refdef.worldmodel;
1358 // if possible find the leaf the view origin is in
1359 viewleaf = model->brushq1.PointInLeaf ? model->brushq1.PointInLeaf(model, r_vieworigin) : NULL;
1360 // if possible fetch the visible cluster bits
1361 if (model->brush.FatPVS)
1362 model->brush.FatPVS(model, r_vieworigin, 2, r_pvsbits, sizeof(r_pvsbits));
1364 // clear the visible surface and leaf flags arrays
1365 memset(r_worldsurfacevisible, 0, model->brush.num_surfaces);
1366 memset(r_worldleafvisible, 0, model->brush.num_leafs);
1368 // if the user prefers surfaceworldnode (testing?) or the viewleaf could
1369 // not be found, or the viewleaf is not part of the visible world
1370 // (floating around in the void), use the pvs method
1371 if (r_surfaceworldnode.integer || !viewleaf || viewleaf->clusterindex < 0)
1374 // similar to quake's RecursiveWorldNode but without cache misses
1375 for (j = 0, leaf = model->brush.data_leafs;j < model->brush.num_leafs;j++, leaf++)
1377 // if leaf is in current pvs and on the screen, mark its surfaces
1378 if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
1381 r_worldleafvisible[j] = true;
1382 if (leaf->numleafsurfaces)
1383 for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
1384 r_worldsurfacevisible[*mark] = true;
1392 mleaf_t *leafstack[8192];
1394 // follows portals leading outward from viewleaf, does not venture
1395 // offscreen or into leafs that are not visible, faster than Quake's
1396 // RecursiveWorldNode and vastly better in unvised maps, often culls a
1397 // lot of surface that pvs alone would miss
1398 leafstack[0] = viewleaf;
1400 while (leafstackpos)
1403 leaf = leafstack[--leafstackpos];
1404 r_worldleafvisible[leaf - model->brush.data_leafs] = true;
1405 // mark any surfaces bounding this leaf
1406 if (leaf->numleafsurfaces)
1407 for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
1408 r_worldsurfacevisible[*mark] = true;
1409 // follow portals into other leafs
1411 // if viewer is behind portal (portal faces outward into the scene)
1412 // and the portal polygon's bounding box is on the screen
1413 // and the leaf has not been visited yet
1414 // and the leaf is visible in the pvs
1415 // (the first two checks won't cause as many cache misses as the leaf checks)
1416 for (p = leaf->portals;p;p = p->next)
1417 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))
1418 leafstack[leafstackpos++] = p->past;
1422 if (r_drawportals.integer)
1426 void R_Q1BSP_DrawSky(entity_render_t *ent)
1428 if (ent->model == NULL)
1430 R_DrawSurfaces(ent, true);
1433 void R_Q1BSP_Draw(entity_render_t *ent)
1435 if (ent->model == NULL)
1438 R_DrawSurfaces(ent, false);
1441 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)
1443 model_t *model = ent->model;
1444 vec3_t lightmins, lightmaxs;
1445 int t, leafindex, leafsurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
1448 msurface_t *surface;
1451 lightmins[0] = relativelightorigin[0] - lightradius;
1452 lightmins[1] = relativelightorigin[1] - lightradius;
1453 lightmins[2] = relativelightorigin[2] - lightradius;
1454 lightmaxs[0] = relativelightorigin[0] + lightradius;
1455 lightmaxs[1] = relativelightorigin[1] + lightradius;
1456 lightmaxs[2] = relativelightorigin[2] + lightradius;
1457 *outnumclusterspointer = 0;
1458 *outnumsurfacespointer = 0;
1459 memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
1460 memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
1463 VectorCopy(lightmins, outmins);
1464 VectorCopy(lightmaxs, outmaxs);
1467 VectorCopy(relativelightorigin, outmins);
1468 VectorCopy(relativelightorigin, outmaxs);
1469 if (model->brush.GetPVS)
1470 pvs = model->brush.GetPVS(model, relativelightorigin);
1473 // FIXME: use BSP recursion as lights are often small
1474 for (leafindex = 0, leaf = model->brush.data_leafs;leafindex < model->brush.num_leafs;leafindex++, leaf++)
1476 if (BoxesOverlap(lightmins, lightmaxs, leaf->mins, leaf->maxs) && (pvs == NULL || CHECKPVSBIT(pvs, leaf->clusterindex)))
1478 outmins[0] = min(outmins[0], leaf->mins[0]);
1479 outmins[1] = min(outmins[1], leaf->mins[1]);
1480 outmins[2] = min(outmins[2], leaf->mins[2]);
1481 outmaxs[0] = max(outmaxs[0], leaf->maxs[0]);
1482 outmaxs[1] = max(outmaxs[1], leaf->maxs[1]);
1483 outmaxs[2] = max(outmaxs[2], leaf->maxs[2]);
1486 if (!CHECKPVSBIT(outclusterpvs, leaf->clusterindex))
1488 SETPVSBIT(outclusterpvs, leaf->clusterindex);
1489 outclusterlist[outnumclusters++] = leaf->clusterindex;
1494 for (leafsurfaceindex = 0;leafsurfaceindex < leaf->numleafsurfaces;leafsurfaceindex++)
1496 surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
1497 if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
1499 surface = model->brush.data_surfaces + surfaceindex;
1500 if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && (surface->texture->flags & SURF_LIGHTMAP) && !surface->texture->skin.fog)
1502 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
1504 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
1505 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
1506 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
1507 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])))
1509 SETPVSBIT(outsurfacepvs, surfaceindex);
1510 outsurfacelist[outnumsurfaces++] = surfaceindex;
1521 // limit combined leaf box to light boundaries
1522 outmins[0] = max(outmins[0], lightmins[0]);
1523 outmins[1] = max(outmins[1], lightmins[1]);
1524 outmins[2] = max(outmins[2], lightmins[2]);
1525 outmaxs[0] = min(outmaxs[0], lightmaxs[0]);
1526 outmaxs[1] = min(outmaxs[1], lightmaxs[1]);
1527 outmaxs[2] = min(outmaxs[2], lightmaxs[2]);
1529 *outnumclusterspointer = outnumclusters;
1530 *outnumsurfacespointer = outnumsurfaces;
1533 void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
1535 model_t *model = ent->model;
1536 vec3_t lightmins, lightmaxs;
1537 msurface_t *surface;
1538 int surfacelistindex;
1539 if (r_drawcollisionbrushes.integer < 2)
1541 lightmins[0] = relativelightorigin[0] - lightradius;
1542 lightmins[1] = relativelightorigin[1] - lightradius;
1543 lightmins[2] = relativelightorigin[2] - lightradius;
1544 lightmaxs[0] = relativelightorigin[0] + lightradius;
1545 lightmaxs[1] = relativelightorigin[1] + lightradius;
1546 lightmaxs[2] = relativelightorigin[2] + lightradius;
1547 R_Mesh_Matrix(&ent->matrix);
1548 R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
1549 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1551 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
1552 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);
1554 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);
1558 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)
1560 model_t *model = ent->model;
1561 vec3_t lightmins, lightmaxs, modelorg;
1562 msurface_t *surface;
1564 int surfacelistindex;
1565 if (r_drawcollisionbrushes.integer < 2)
1567 lightmins[0] = relativelightorigin[0] - lightradius;
1568 lightmins[1] = relativelightorigin[1] - lightradius;
1569 lightmins[2] = relativelightorigin[2] - lightradius;
1570 lightmaxs[0] = relativelightorigin[0] + lightradius;
1571 lightmaxs[1] = relativelightorigin[1] + lightradius;
1572 lightmaxs[2] = relativelightorigin[2] + lightradius;
1573 R_Mesh_Matrix(&ent->matrix);
1574 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1575 R_UpdateTextureInfo(ent);
1576 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1578 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
1579 if (r_shadow_compilingrtlight)
1581 // if compiling an rtlight, capture the mesh
1582 t = surface->texture;
1583 if (t->flags & SURF_LIGHTMAP && t->skin.fog == NULL)
1584 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);
1586 else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surfacelist[surfacelistindex]])
1588 t = surface->texture->currentframe;
1589 // FIXME: transparent surfaces need to be lit later
1590 if (t->flags & SURF_LIGHTMAP && t->rendertype == SURFRENDER_OPAQUE)
1591 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);
1597 void R_DrawCollisionBrush(colbrushf_t *brush)
1601 memset(&m, 0, sizeof(m));
1602 m.pointer_vertex = brush->points->v;
1604 i = (int)(((size_t)brush) / sizeof(colbrushf_t));
1605 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1606 GL_LockArrays(0, brush->numpoints);
1607 R_Mesh_Draw(brush->numpoints, brush->numtriangles, brush->elements);
1608 GL_LockArrays(0, 0);
1611 void R_Q3BSP_DrawCollisionSurface(entity_render_t *ent, msurface_t *surface)
1615 if (!surface->mesh.num_collisiontriangles)
1617 memset(&m, 0, sizeof(m));
1618 m.pointer_vertex = surface->mesh.data_collisionvertex3f;
1620 i = (int)(((size_t)surface) / sizeof(msurface_t));
1621 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1622 GL_LockArrays(0, surface->mesh.num_collisionvertices);
1623 R_Mesh_Draw(surface->mesh.num_collisionvertices, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i);
1624 GL_LockArrays(0, 0);
1627 void R_Q3BSP_DrawFace_TransparentCallback(const void *voident, int surfacenumber)
1629 const entity_render_t *ent = voident;
1630 msurface_t *surface = ent->model->brush.data_surfaces + surfacenumber;
1632 R_Mesh_Matrix(&ent->matrix);
1633 memset(&m, 0, sizeof(m));
1634 if ((ent->effects & EF_ADDITIVE) || (surface->texture->textureflags & Q3TEXTUREFLAG_ADDITIVE))
1635 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1637 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1638 GL_DepthMask(false);
1639 GL_DepthTest(!(ent->effects & EF_NODEPTHTEST));
1640 m.tex[0] = R_GetTexture(surface->texture->skin.base);
1641 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1642 // LordHavoc: quake3 was not able to do this; lit transparent surfaces
1643 if (gl_combine.integer)
1645 m.texrgbscale[0] = 2;
1646 if (r_textureunits.integer >= 2)
1648 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1649 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1650 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], ent->alpha);
1654 if (ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1 && ent->alpha == 1)
1655 m.pointer_color = surface->mesh.data_lightmapcolor4f;
1659 for (i = 0;i < surface->mesh.num_vertices;i++)
1661 varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0];
1662 varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1];
1663 varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2];
1664 varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3] * ent->alpha;
1666 m.pointer_color = varray_color4f;
1673 for (i = 0;i < surface->mesh.num_vertices;i++)
1675 varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0] * 2.0f;
1676 varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1] * 2.0f;
1677 varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2] * 2.0f;
1678 varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3] * ent->alpha;
1680 m.pointer_color = varray_color4f;
1682 if (surface->texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
1685 float center[3], center2[3], forward[3], right[3], up[3], v[4][3];
1686 matrix4x4_t matrix1, imatrix1;
1687 R_Mesh_Matrix(&r_identitymatrix);
1688 // a single autosprite surface can contain multiple sprites...
1689 for (j = 0;j < surface->mesh.num_vertices - 3;j += 4)
1691 VectorClear(center);
1692 for (i = 0;i < 4;i++)
1693 VectorAdd(center, surface->mesh.data_vertex3f + (j+i) * 3, center);
1694 VectorScale(center, 0.25f, center);
1695 Matrix4x4_Transform(&ent->matrix, center, center2);
1696 // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
1697 Matrix4x4_FromVectors(&matrix1, surface->mesh.data_normal3f + j*3, surface->mesh.data_svector3f + j*3, surface->mesh.data_tvector3f + j*3, center);
1698 Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
1699 for (i = 0;i < 4;i++)
1700 Matrix4x4_Transform(&imatrix1, surface->mesh.data_vertex3f + (j+i)*3, v[i]);
1701 if (surface->texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE2)
1703 forward[0] = r_vieworigin[0] - center2[0];
1704 forward[1] = r_vieworigin[1] - center2[1];
1706 VectorNormalize(forward);
1707 right[0] = forward[1];
1708 right[1] = -forward[0];
1716 VectorCopy(r_viewforward, forward);
1717 VectorCopy(r_viewright, right);
1718 VectorCopy(r_viewup, up);
1720 for (i = 0;i < 4;i++)
1721 VectorMAMAMAM(1, center2, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (i+j) * 3);
1723 m.pointer_vertex = varray_vertex3f;
1726 m.pointer_vertex = surface->mesh.data_vertex3f;
1728 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1729 qglDisable(GL_CULL_FACE);
1730 GL_LockArrays(0, surface->mesh.num_vertices);
1731 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1732 GL_LockArrays(0, 0);
1733 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1734 qglEnable(GL_CULL_FACE);
1737 void R_Q3BSP_DrawFaceList(entity_render_t *ent, texture_t *t, int texturenumsurfaces, msurface_t **texturesurfacelist)
1739 int i, texturesurfaceindex;
1740 msurface_t *surface;
1741 qboolean dolightmap;
1747 if (!texturenumsurfaces)
1749 c_faces += texturenumsurfaces;
1750 // gl_lightmaps debugging mode skips normal texturing
1751 if (gl_lightmaps.integer)
1755 GL_BlendFunc(GL_ONE, GL_ZERO);
1756 qglDisable(GL_CULL_FACE);
1757 memset(&m, 0, sizeof(m));
1758 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1760 surface = texturesurfacelist[texturesurfaceindex];
1761 m.tex[0] = R_GetTexture(surface->lightmaptexture);
1762 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
1763 if (surface->lightmaptexture)
1765 GL_Color(1, 1, 1, 1);
1766 m.pointer_color = NULL;
1769 m.pointer_color = surface->mesh.data_lightmapcolor4f;
1770 m.pointer_vertex = surface->mesh.data_vertex3f;
1772 GL_LockArrays(0, surface->mesh.num_vertices);
1773 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1774 GL_LockArrays(0, 0);
1776 qglEnable(GL_CULL_FACE);
1779 // transparent surfaces get sorted for later drawing
1780 if ((t->surfaceparms & Q3SURFACEPARM_TRANS) || ent->alpha < 1 || (ent->effects & EF_ADDITIVE))
1782 vec3_t facecenter, center;
1783 // drawing sky transparently would be too difficult
1784 if (t->surfaceparms & Q3SURFACEPARM_SKY)
1786 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1788 surface = texturesurfacelist[texturesurfaceindex];
1789 facecenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
1790 facecenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
1791 facecenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
1792 Matrix4x4_Transform(&ent->matrix, facecenter, center);
1793 R_MeshQueue_AddTransparent(center, R_Q3BSP_DrawFace_TransparentCallback, ent, surface - ent->model->brush.data_surfaces);
1797 // sky surfaces draw sky if needed and render themselves as a depth mask
1798 if (t->surfaceparms & Q3SURFACEPARM_SKY)
1802 skyrendernow = false;
1803 if (skyrendermasked)
1806 if (!r_q3bsp_renderskydepth.integer)
1809 R_Mesh_Matrix(&ent->matrix);
1811 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
1812 if (skyrendermasked)
1814 // depth-only (masking)
1815 GL_ColorMask(0,0,0,0);
1816 // just to make sure that braindead drivers don't draw anything
1817 // despite that colormask...
1818 GL_BlendFunc(GL_ZERO, GL_ONE);
1823 GL_BlendFunc(GL_ONE, GL_ZERO);
1828 memset(&m, 0, sizeof(m));
1829 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1831 surface = texturesurfacelist[texturesurfaceindex];
1832 m.pointer_vertex = surface->mesh.data_vertex3f;
1834 GL_LockArrays(0, surface->mesh.num_vertices);
1835 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1836 GL_LockArrays(0, 0);
1838 GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
1841 // anything else is a typical wall, lightmap * texture + glow
1842 dolightmap = (ent->flags & RENDER_LIGHT);
1844 doambient = r_ambient.value > 0;
1845 doglow = t->skin.glow != NULL;
1847 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1848 qglDisable(GL_CULL_FACE);
1849 if (!dolightmap && dobase)
1855 GL_BlendFunc(GL_ONE, GL_ZERO);
1856 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
1857 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1858 qglDisable(GL_CULL_FACE);
1859 memset(&m, 0, sizeof(m));
1860 m.tex[0] = R_GetTexture(t->skin.base);
1861 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1863 surface = texturesurfacelist[texturesurfaceindex];
1864 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1865 m.pointer_vertex = surface->mesh.data_vertex3f;
1867 GL_LockArrays(0, surface->mesh.num_vertices);
1868 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1869 GL_LockArrays(0, 0);
1872 if (r_lightmapintensity <= 0 && dolightmap && dobase)
1878 GL_BlendFunc(GL_ONE, GL_ZERO);
1879 GL_Color(0, 0, 0, 1);
1880 memset(&m, 0, sizeof(m));
1881 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1883 surface = texturesurfacelist[texturesurfaceindex];
1884 m.pointer_vertex = surface->mesh.data_vertex3f;
1886 GL_LockArrays(0, surface->mesh.num_vertices);
1887 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1888 GL_LockArrays(0, 0);
1891 if (r_textureunits.integer >= 2 && gl_combine.integer && dolightmap && dobase)
1893 // dualtexture combine
1898 GL_BlendFunc(GL_ONE, GL_ZERO);
1899 memset(&m, 0, sizeof(m));
1900 m.tex[0] = R_GetTexture(t->skin.base);
1901 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1902 m.pointer_color = NULL;
1903 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1905 surface = texturesurfacelist[texturesurfaceindex];
1906 if (!surface->lightmaptexture)
1908 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1909 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1910 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1911 m.texrgbscale[1] = 2;
1912 m.pointer_vertex = surface->mesh.data_vertex3f;
1914 GL_LockArrays(0, surface->mesh.num_vertices);
1915 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1916 GL_LockArrays(0, 0);
1918 if (r_lightmapintensity == 1 && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
1920 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1922 surface = texturesurfacelist[texturesurfaceindex];
1923 if (surface->lightmaptexture)
1925 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1926 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1927 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1928 m.texrgbscale[1] = 2;
1929 m.pointer_color = surface->mesh.data_lightmapcolor4f;
1930 m.pointer_vertex = surface->mesh.data_vertex3f;
1932 GL_LockArrays(0, surface->mesh.num_vertices);
1933 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1934 GL_LockArrays(0, 0);
1939 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1941 surface = texturesurfacelist[texturesurfaceindex];
1942 if (surface->lightmaptexture)
1944 m.tex[1] = R_GetTexture(surface->lightmaptexture);
1945 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1946 m.pointer_texcoord[1] = surface->mesh.data_texcoordlightmap2f;
1947 m.texrgbscale[1] = 2;
1948 m.pointer_color = varray_color4f;
1949 for (i = 0;i < surface->mesh.num_vertices;i++)
1951 varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * ent->colormod[0] * r_lightmapintensity;
1952 varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * ent->colormod[1] * r_lightmapintensity;
1953 varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * ent->colormod[2] * r_lightmapintensity;
1954 varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3];
1956 m.pointer_vertex = surface->mesh.data_vertex3f;
1958 GL_LockArrays(0, surface->mesh.num_vertices);
1959 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1960 GL_LockArrays(0, 0);
1969 GL_BlendFunc(GL_ONE, GL_ZERO);
1970 memset(&m, 0, sizeof(m));
1971 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1973 surface = texturesurfacelist[texturesurfaceindex];
1974 m.tex[0] = R_GetTexture(surface->lightmaptexture);
1975 m.pointer_texcoord[0] = surface->mesh.data_texcoordlightmap2f;
1976 if (surface->lightmaptexture)
1977 m.pointer_color = NULL;
1979 m.pointer_color = surface->mesh.data_lightmapcolor4f;
1980 m.pointer_vertex = surface->mesh.data_vertex3f;
1982 GL_LockArrays(0, surface->mesh.num_vertices);
1983 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1984 GL_LockArrays(0, 0);
1989 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1990 GL_DepthMask(false);
1992 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1993 memset(&m, 0, sizeof(m));
1994 m.tex[0] = R_GetTexture(t->skin.base);
1995 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1997 surface = texturesurfacelist[texturesurfaceindex];
1998 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
1999 m.pointer_vertex = surface->mesh.data_vertex3f;
2001 GL_LockArrays(0, surface->mesh.num_vertices);
2002 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
2003 GL_LockArrays(0, 0);
2008 GL_BlendFunc(GL_ONE, GL_ONE);
2009 GL_DepthMask(false);
2011 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);
2012 memset(&m, 0, sizeof(m));
2013 m.tex[0] = R_GetTexture(t->skin.base);
2014 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
2016 surface = texturesurfacelist[texturesurfaceindex];
2017 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
2018 m.pointer_vertex = surface->mesh.data_vertex3f;
2020 GL_LockArrays(0, surface->mesh.num_vertices);
2021 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
2022 GL_LockArrays(0, 0);
2027 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
2028 GL_DepthMask(false);
2030 GL_Color(1, 1, 1, 1);
2031 memset(&m, 0, sizeof(m));
2032 m.tex[0] = R_GetTexture(t->skin.glow);
2033 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
2035 surface = texturesurfacelist[texturesurfaceindex];
2036 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
2037 m.pointer_vertex = surface->mesh.data_vertex3f;
2039 GL_LockArrays(0, surface->mesh.num_vertices);
2040 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
2041 GL_LockArrays(0, 0);
2047 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
2048 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2049 GL_DepthMask(false);
2051 GL_Color(1, 1, 1, 1);
2052 memset(&m, 0, sizeof(m));
2053 m.tex[0] = R_GetTexture(t->skin.fog);
2054 m.pointer_color = varray_color4f;
2055 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
2057 surface = texturesurfacelist[texturesurfaceindex];
2059 m.pointer_texcoord[0] = surface->mesh.data_texcoordtexture2f;
2060 m.pointer_vertex = surface->mesh.data_vertex3f;
2062 RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], 1, 1, surface->mesh.num_vertices, modelorg);
2063 GL_LockArrays(0, surface->mesh.num_vertices);
2064 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
2065 GL_LockArrays(0, 0);
2068 if (t->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2069 qglEnable(GL_CULL_FACE);
2072 void R_Q3BSP_DrawFaces(entity_render_t *ent, int skyfaces)
2074 int i, j, f, flagsmask, flags;
2075 msurface_t *surface;
2076 model_t *model = ent->model;
2078 const int maxfaces = 1024;
2079 int numsurfaces = 0;
2080 msurface_t *surfacelist[1024];
2081 R_Mesh_Matrix(&ent->matrix);
2082 flagsmask = Q3SURFACEFLAG_NODRAW | Q3SURFACEFLAG_SKY;
2084 flags = Q3SURFACEFLAG_SKY;
2090 for (i = 0, j = model->firstmodelsurface;i < model->nummodelsurfaces;i++, j++)
2092 if (ent != r_refdef.worldentity || r_worldsurfacevisible[j])
2094 surface = model->brush.data_surfaces + j;
2095 if (t != surface->texture)
2099 R_Q3BSP_DrawFaceList(ent, t, numsurfaces, surfacelist);
2102 t = surface->texture;
2103 f = t->surfaceflags & flagsmask;
2107 if (!surface->mesh.num_triangles)
2109 surfacelist[numsurfaces++] = surface;
2110 if (numsurfaces >= maxfaces)
2112 R_Q3BSP_DrawFaceList(ent, t, numsurfaces, surfacelist);
2119 R_Q3BSP_DrawFaceList(ent, t, numsurfaces, surfacelist);
2122 void R_Q3BSP_DrawSky(entity_render_t *ent)
2124 if (r_drawcollisionbrushes.integer < 2)
2125 R_Q3BSP_DrawFaces(ent, true);
2128 void R_Q3BSP_Draw(entity_render_t *ent)
2130 if (r_drawcollisionbrushes.integer < 2)
2131 R_Q3BSP_DrawFaces(ent, false);
2132 if (r_drawcollisionbrushes.integer >= 1)
2135 model_t *model = ent->model;
2136 msurface_t *surface;
2138 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
2139 GL_DepthMask(false);
2141 qglPolygonOffset(r_drawcollisionbrushes_polygonfactor.value, r_drawcollisionbrushes_polygonoffset.value);
2142 for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
2143 if (brush->colbrushf && brush->colbrushf->numtriangles)
2144 R_DrawCollisionBrush(brush->colbrushf);
2145 for (i = 0, surface = model->brush.data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
2146 if (surface->mesh.num_collisiontriangles)
2147 R_Q3BSP_DrawCollisionSurface(ent, surface);
2148 qglPolygonOffset(0, 0);
2152 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)
2154 model_t *model = ent->model;
2155 vec3_t lightmins, lightmaxs;
2156 int t, leafindex, leafsurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
2159 msurface_t *surface;
2162 lightmins[0] = relativelightorigin[0] - lightradius;
2163 lightmins[1] = relativelightorigin[1] - lightradius;
2164 lightmins[2] = relativelightorigin[2] - lightradius;
2165 lightmaxs[0] = relativelightorigin[0] + lightradius;
2166 lightmaxs[1] = relativelightorigin[1] + lightradius;
2167 lightmaxs[2] = relativelightorigin[2] + lightradius;
2168 *outnumclusterspointer = 0;
2169 *outnumsurfacespointer = 0;
2170 memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
2171 memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
2174 VectorCopy(lightmins, outmins);
2175 VectorCopy(lightmaxs, outmaxs);
2178 VectorCopy(relativelightorigin, outmins);
2179 VectorCopy(relativelightorigin, outmaxs);
2180 if (model->brush.GetPVS)
2181 pvs = model->brush.GetPVS(model, relativelightorigin);
2184 // FIXME: use BSP recursion as lights are often small
2185 for (leafindex = 0, leaf = model->brush.data_leafs;leafindex < model->brush.num_leafs;leafindex++, leaf++)
2187 if (BoxesOverlap(lightmins, lightmaxs, leaf->mins, leaf->maxs) && (pvs == NULL || CHECKPVSBIT(pvs, leaf->clusterindex)))
2189 outmins[0] = min(outmins[0], leaf->mins[0]);
2190 outmins[1] = min(outmins[1], leaf->mins[1]);
2191 outmins[2] = min(outmins[2], leaf->mins[2]);
2192 outmaxs[0] = max(outmaxs[0], leaf->maxs[0]);
2193 outmaxs[1] = max(outmaxs[1], leaf->maxs[1]);
2194 outmaxs[2] = max(outmaxs[2], leaf->maxs[2]);
2197 if (!CHECKPVSBIT(outclusterpvs, leaf->clusterindex))
2199 SETPVSBIT(outclusterpvs, leaf->clusterindex);
2200 outclusterlist[outnumclusters++] = leaf->clusterindex;
2205 for (leafsurfaceindex = 0;leafsurfaceindex < leaf->numleafsurfaces;leafsurfaceindex++)
2207 surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
2208 surface = model->brush.data_surfaces + surfaceindex;
2209 if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
2211 if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs) && !(surface->texture->surfaceparms & Q3SURFACEPARM_TRANS) && !(surface->texture->surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NODRAW)) && surface->mesh.num_triangles)
2213 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
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 (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;
2230 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
2232 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
2233 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
2234 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
2235 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])))
2237 SETPVSBIT(outsurfacepvs, surfaceindex);
2238 outsurfacelist[outnumsurfaces++] = surfaceindex;
2250 // limit combined leaf box to light boundaries
2251 outmins[0] = max(outmins[0], lightmins[0]);
2252 outmins[1] = max(outmins[1], lightmins[1]);
2253 outmins[2] = max(outmins[2], lightmins[2]);
2254 outmaxs[0] = min(outmaxs[0], lightmaxs[0]);
2255 outmaxs[1] = min(outmaxs[1], lightmaxs[1]);
2256 outmaxs[2] = min(outmaxs[2], lightmaxs[2]);
2258 *outnumclusterspointer = outnumclusters;
2259 *outnumsurfacespointer = outnumsurfaces;
2262 void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist)
2264 model_t *model = ent->model;
2265 vec3_t lightmins, lightmaxs;
2266 msurface_t *surface;
2267 int surfacelistindex;
2268 if (r_drawcollisionbrushes.integer < 2)
2270 lightmins[0] = relativelightorigin[0] - lightradius;
2271 lightmins[1] = relativelightorigin[1] - lightradius;
2272 lightmins[2] = relativelightorigin[2] - lightradius;
2273 lightmaxs[0] = relativelightorigin[0] + lightradius;
2274 lightmaxs[1] = relativelightorigin[1] + lightradius;
2275 lightmaxs[2] = relativelightorigin[2] + lightradius;
2276 R_Mesh_Matrix(&ent->matrix);
2277 R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
2278 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
2280 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
2281 // FIXME: check some manner of surface->rendermode here?
2282 if (!(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && !(surface->texture->surfaceparms & (Q3SURFACEPARM_SKY | Q3SURFACEPARM_TRANS)) && !(surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED))
2283 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);
2285 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);
2289 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)
2291 model_t *model = ent->model;
2292 vec3_t lightmins, lightmaxs, modelorg;
2293 msurface_t *surface;
2294 int surfacelistindex;
2295 if (r_drawcollisionbrushes.integer < 2)
2297 lightmins[0] = relativelightorigin[0] - lightradius;
2298 lightmins[1] = relativelightorigin[1] - lightradius;
2299 lightmins[2] = relativelightorigin[2] - lightradius;
2300 lightmaxs[0] = relativelightorigin[0] + lightradius;
2301 lightmaxs[1] = relativelightorigin[1] + lightradius;
2302 lightmaxs[2] = relativelightorigin[2] + lightradius;
2303 R_Mesh_Matrix(&ent->matrix);
2304 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
2305 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
2307 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
2308 if (r_shadow_compilingrtlight)
2310 // if compiling an rtlight, capture the mesh
2311 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);
2313 else if ((ent != r_refdef.worldentity || r_worldsurfacevisible[surfacelist[surfacelistindex]]) && !(surface->texture->surfaceflags & Q3SURFACEFLAG_NODRAW) && surface->mesh.num_triangles)
2315 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2316 qglDisable(GL_CULL_FACE);
2317 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);
2318 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
2319 qglEnable(GL_CULL_FACE);
2326 static void gl_surf_start(void)
2330 static void gl_surf_shutdown(void)
2334 static void gl_surf_newmap(void)
2339 void GL_Surf_Init(void)
2342 dlightdivtable[0] = 4194304;
2343 for (i = 1;i < 32768;i++)
2344 dlightdivtable[i] = 4194304 / (i << 7);
2346 Cvar_RegisterVariable(&r_ambient);
2347 Cvar_RegisterVariable(&r_drawportals);
2348 Cvar_RegisterVariable(&r_testvis);
2349 Cvar_RegisterVariable(&r_floatbuildlightmap);
2350 Cvar_RegisterVariable(&r_detailtextures);
2351 Cvar_RegisterVariable(&r_surfaceworldnode);
2352 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor);
2353 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);
2354 Cvar_RegisterVariable(&r_q3bsp_renderskydepth);
2355 Cvar_RegisterVariable(&gl_lightmaps);
2357 //R_RegisterModule("GL_Surf", gl_surf_start, gl_surf_shutdown, gl_surf_newmap);