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 cvar_t r_ambient = {0, "r_ambient", "0"};
28 cvar_t r_drawportals = {0, "r_drawportals", "0"};
29 cvar_t r_testvis = {0, "r_testvis", "0"};
30 cvar_t r_detailtextures = {CVAR_SAVE, "r_detailtextures", "1"};
31 cvar_t r_surfaceworldnode = {0, "r_surfaceworldnode", "0"};
32 cvar_t r_drawcollisionbrushes_polygonfactor = {0, "r_drawcollisionbrushes_polygonfactor", "-1"};
33 cvar_t r_drawcollisionbrushes_polygonoffset = {0, "r_drawcollisionbrushes_polygonoffset", "0"};
34 cvar_t r_q3bsp_renderskydepth = {0, "r_q3bsp_renderskydepth", "0"};
35 cvar_t gl_lightmaps = {0, "gl_lightmaps", "0"};
37 // flag arrays used for visibility checking on world model
38 // (all other entities have no per-surface/per-leaf visibility checks)
39 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_clusters
40 qbyte r_pvsbits[(32768+7)>>3];
41 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_leafs
42 qbyte r_worldleafvisible[32768];
43 // TODO: dynamic resize according to r_refdef.worldmodel->brush.num_surfaces
44 qbyte r_worldsurfacevisible[262144];
50 Combine and scale multiple lightmaps into the 8.8 format in blocklights
53 static void R_BuildLightMap (const entity_render_t *ent, msurface_t *surface)
55 int smax, tmax, i, j, size, size3, maps, stride, l;
56 unsigned int *bl, scale;
57 qbyte *lightmap, *out, *stain;
58 static unsigned int intblocklights[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*3]; // LordHavoc: *3 for colored lighting
59 static qbyte templight[MAX_LIGHTMAP_SIZE*MAX_LIGHTMAP_SIZE*4];
61 // update cached lighting info
62 surface->cached_dlight = 0;
64 smax = (surface->extents[0]>>4)+1;
65 tmax = (surface->extents[1]>>4)+1;
68 lightmap = surface->samples;
70 // set to full bright if no light data
72 if (!ent->model->brushq1.lightdata)
74 for (i = 0;i < size3;i++)
80 memset(bl, 0, size*3*sizeof(unsigned int));
82 // add all the lightmaps
86 for (maps = 0;maps < MAXLIGHTMAPS && surface->styles[maps] != 255;maps++, lightmap += size3)
87 for (scale = d_lightstylevalue[surface->styles[maps]], i = 0;i < size3;i++)
88 bl[i] += lightmap[i] * scale;
92 stain = surface->stainsamples;
95 // the >> 16 shift adjusts down 8 bits to account for the stainmap
96 // scaling, and remaps the 0-65536 (2x overbright) to 0-256, it will
97 // be doubled during rendering to achieve 2x overbright
98 // (0 = 0.0, 128 = 1.0, 256 = 2.0)
99 if (ent->model->brushq1.lightmaprgba)
101 stride = (surface->lightmaptexturestride - smax) * 4;
102 for (i = 0;i < tmax;i++, out += stride)
104 for (j = 0;j < smax;j++)
106 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
107 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
108 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
115 stride = (surface->lightmaptexturestride - smax) * 3;
116 for (i = 0;i < tmax;i++, out += stride)
118 for (j = 0;j < smax;j++)
120 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
121 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
122 l = (*bl++ * *stain++) >> 16;*out++ = min(l, 255);
127 R_UpdateTexture(surface->lightmaptexture, templight);
130 void R_StainNode (mnode_t *node, model_t *model, const vec3_t origin, float radius, const float fcolor[8])
132 float ndist, a, ratio, maxdist, maxdist2, maxdist3, invradius, sdtable[256], td, dist2;
133 msurface_t *surface, *endsurface;
134 int i, s, t, smax, tmax, smax3, impacts, impactt, stained;
138 maxdist = radius * radius;
139 invradius = 1.0f / radius;
144 ndist = PlaneDiff(origin, node->plane);
147 node = node->children[0];
152 node = node->children[1];
156 dist2 = ndist * ndist;
157 maxdist3 = maxdist - dist2;
159 if (node->plane->type < 3)
161 VectorCopy(origin, impact);
162 impact[node->plane->type] -= ndist;
166 impact[0] = origin[0] - node->plane->normal[0] * ndist;
167 impact[1] = origin[1] - node->plane->normal[1] * ndist;
168 impact[2] = origin[2] - node->plane->normal[2] * ndist;
171 for (surface = model->brush.data_surfaces + node->firstsurface, endsurface = surface + node->numsurfaces;surface < endsurface;surface++)
173 if (surface->stainsamples)
175 smax = (surface->extents[0] >> 4) + 1;
176 tmax = (surface->extents[1] >> 4) + 1;
178 impacts = DotProduct (impact, surface->texinfo->vecs[0]) + surface->texinfo->vecs[0][3] - surface->texturemins[0];
179 impactt = DotProduct (impact, surface->texinfo->vecs[1]) + surface->texinfo->vecs[1][3] - surface->texturemins[1];
181 s = bound(0, impacts, smax * 16) - impacts;
182 t = bound(0, impactt, tmax * 16) - impactt;
183 i = s * s + t * t + dist2;
187 // reduce calculations
188 for (s = 0, i = impacts; s < smax; s++, i -= 16)
189 sdtable[s] = i * i + dist2;
191 bl = surface->stainsamples;
196 for (t = 0;t < tmax;t++, i -= 16)
199 // make sure some part of it is visible on this line
202 maxdist2 = maxdist - td;
203 for (s = 0;s < smax;s++)
205 if (sdtable[s] < maxdist2)
207 ratio = lhrandom(0.0f, 1.0f);
208 a = (fcolor[3] + ratio * fcolor[7]) * (1.0f - sqrt(sdtable[s] + td) * invradius);
209 if (a >= (1.0f / 64.0f))
213 bl[0] = (qbyte) ((float) bl[0] + a * ((fcolor[0] + ratio * fcolor[4]) - (float) bl[0]));
214 bl[1] = (qbyte) ((float) bl[1] + a * ((fcolor[1] + ratio * fcolor[5]) - (float) bl[1]));
215 bl[2] = (qbyte) ((float) bl[2] + a * ((fcolor[2] + ratio * fcolor[6]) - (float) bl[2]));
225 // force lightmap upload
227 surface->cached_dlight = true;
231 if (node->children[0]->plane)
233 if (node->children[1]->plane)
235 R_StainNode(node->children[0], model, origin, radius, fcolor);
236 node = node->children[1];
241 node = node->children[0];
245 else if (node->children[1]->plane)
247 node = node->children[1];
252 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)
256 entity_render_t *ent;
259 if (r_refdef.worldmodel == NULL || !r_refdef.worldmodel->brush.data_nodes)
264 fcolor[3] = ca1 * (1.0f / 64.0f);
265 fcolor[4] = cr2 - cr1;
266 fcolor[5] = cg2 - cg1;
267 fcolor[6] = cb2 - cb1;
268 fcolor[7] = (ca2 - ca1) * (1.0f / 64.0f);
270 R_StainNode(r_refdef.worldmodel->brush.data_nodes + r_refdef.worldmodel->brushq1.hulls[0].firstclipnode, r_refdef.worldmodel, origin, radius, fcolor);
272 // look for embedded bmodels
273 for (n = 0;n < cl_num_brushmodel_entities;n++)
275 ent = cl_brushmodel_entities[n];
277 if (model && model->name[0] == '*')
279 Mod_CheckLoaded(model);
280 if (model->brush.data_nodes)
282 Matrix4x4_Transform(&ent->inversematrix, origin, org);
283 R_StainNode(model->brush.data_nodes + model->brushq1.hulls[0].firstclipnode, model, org, radius, fcolor);
291 =============================================================
295 =============================================================
298 static void RSurf_DeformVertices(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t modelorg)
301 float center[3], forward[3], right[3], up[3], v[4][3];
302 matrix4x4_t matrix1, imatrix1;
303 if (texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE2)
305 // a single autosprite surface can contain multiple sprites...
306 VectorClear(forward);
308 VectorSet(up, 0, 0, 1);
309 for (j = 0;j < surface->mesh.num_vertices - 3;j += 4)
312 for (i = 0;i < 4;i++)
313 VectorAdd(center, surface->mesh.data_vertex3f + (j+i) * 3, center);
314 VectorScale(center, 0.25f, center);
315 // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
316 Matrix4x4_FromVectors(&matrix1, surface->mesh.data_normal3f + j*3, surface->mesh.data_svector3f + j*3, surface->mesh.data_tvector3f + j*3, center);
317 Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
318 for (i = 0;i < 4;i++)
319 Matrix4x4_Transform(&imatrix1, surface->mesh.data_vertex3f + (j+i)*3, v[i]);
320 forward[0] = modelorg[0] - center[0];
321 forward[1] = modelorg[1] - center[1];
322 VectorNormalize(forward);
323 right[0] = forward[1];
324 right[1] = -forward[0];
325 for (i = 0;i < 4;i++)
326 VectorMAMAMAM(1, center, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (i+j) * 3);
329 else if (texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE)
331 Matrix4x4_Transform(&ent->inversematrix, r_viewforward, forward);
332 Matrix4x4_Transform(&ent->inversematrix, r_viewright, right);
333 Matrix4x4_Transform(&ent->inversematrix, r_viewup, up);
334 // a single autosprite surface can contain multiple sprites...
335 for (j = 0;j < surface->mesh.num_vertices - 3;j += 4)
338 for (i = 0;i < 4;i++)
339 VectorAdd(center, surface->mesh.data_vertex3f + (j+i) * 3, center);
340 VectorScale(center, 0.25f, center);
341 // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
342 Matrix4x4_FromVectors(&matrix1, surface->mesh.data_normal3f + j*3, surface->mesh.data_svector3f + j*3, surface->mesh.data_tvector3f + j*3, center);
343 Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
344 for (i = 0;i < 4;i++)
345 Matrix4x4_Transform(&imatrix1, surface->mesh.data_vertex3f + (j+i)*3, v[i]);
346 for (i = 0;i < 4;i++)
347 VectorMAMAMAM(1, center, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (i+j) * 3);
351 memcpy(varray_vertex3f, surface->mesh.data_vertex3f, sizeof(float[3]) * surface->mesh.num_vertices);
354 // any sort of deformvertices call is *VERY* rare, so this must be optimized
355 // to skip deformvertices quickly!
357 #define RSurf_GetVertexPointer(ent, texture, surface, modelorg) ((texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2)) ? (RSurf_DeformVertices(ent, texture, surface, modelorg), varray_vertex3f) : surface->mesh.data_vertex3f)
359 static float *RSurf_GetVertexPointer(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t modelorg)
361 if (texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
363 RSurf_DeformVertices(ent, texture, surface, modelorg);
364 return varray_vertex3f;
367 return surface->mesh.data_vertex3f;
371 void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t)
373 // we don't need to set currentframe if t->animated is false because
374 // it was already set up by the texture loader for non-animating
377 t->currentframe = t->anim_frames[ent->frame != 0][(t->anim_total[ent->frame != 0] >= 2) ? ((int)(r_refdef.time * 5.0f) % t->anim_total[ent->frame != 0]) : 0];
380 t->currentmaterialflags = t->basematerialflags;
381 t->currentalpha = ent->alpha;
382 if (t->basematerialflags & MATERIALFLAG_WATERALPHA)
383 t->currentalpha *= r_wateralpha.value;
384 if (!(ent->flags & RENDER_LIGHT))
385 t->currentmaterialflags |= MATERIALFLAG_FULLBRIGHT;
386 if (ent->effects & EF_ADDITIVE)
387 t->currentmaterialflags |= MATERIALFLAG_ADD | MATERIALFLAG_TRANSPARENT;
388 else if (t->currentalpha < 1)
389 t->currentmaterialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_TRANSPARENT;
392 matrix4x4_t r_surf_waterscrollmatrix;
394 void R_UpdateAllTextureInfo(entity_render_t *ent)
397 Matrix4x4_CreateTranslate(&r_surf_waterscrollmatrix, sin(r_refdef.time) * 0.025 * r_waterscroll.value, sin(r_refdef.time * 0.8f) * 0.025 * r_waterscroll.value, 0);
399 for (i = 0;i < ent->model->brush.num_textures;i++)
400 R_UpdateTextureInfo(ent, ent->model->brush.data_textures + i);
403 static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, int texturenumsurfaces, const msurface_t **texturesurfacelist, const vec3_t modelorg)
406 int texturesurfaceindex;
407 const float *v, *vertex3f;
410 float f, r, g, b, a, base, colorscale;
411 const msurface_t *surface;
418 qboolean fogallpasses;
419 qboolean waterscrolling;
421 texture = texture->currentframe;
422 if (texture->currentmaterialflags & MATERIALFLAG_NODRAW)
424 c_faces += texturenumsurfaces;
425 // gl_lightmaps debugging mode skips normal texturing
426 if (gl_lightmaps.integer)
428 GL_BlendFunc(GL_ONE, GL_ZERO);
431 qglDisable(GL_CULL_FACE);
432 GL_Color(1, 1, 1, 1);
433 memset(&m, 0, sizeof(m));
435 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
437 surface = texturesurfacelist[texturesurfaceindex];
438 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
439 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
440 R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : surface->mesh.data_lightmapcolor4f);
441 R_Mesh_VertexPointer(surface->mesh.data_vertex3f);
442 GL_LockArrays(0, surface->mesh.num_vertices);
443 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
446 qglEnable(GL_CULL_FACE);
449 GL_DepthTest(!(texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST));
450 GL_DepthMask(!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT));
451 if (texture->currentmaterialflags & MATERIALFLAG_ADD)
452 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
453 else if (texture->currentmaterialflags & MATERIALFLAG_ALPHA)
454 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
456 GL_BlendFunc(GL_ONE, GL_ZERO);
457 // water waterscrolling in texture matrix
458 waterscrolling = (texture->currentmaterialflags & MATERIALFLAG_WATER) && r_waterscroll.value != 0;
459 if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
460 qglDisable(GL_CULL_FACE);
461 if (texture->currentmaterialflags & MATERIALFLAG_SKY)
465 skyrendernow = false;
469 // LordHavoc: HalfLife maps have freaky skypolys...
470 if (!ent->model->brush.ishlbsp)
472 R_Mesh_Matrix(&ent->matrix);
473 GL_Color(fogcolor[0], fogcolor[1], fogcolor[2], 1);
476 // depth-only (masking)
477 GL_ColorMask(0,0,0,0);
478 // just to make sure that braindead drivers don't draw anything
479 // despite that colormask...
480 GL_BlendFunc(GL_ZERO, GL_ONE);
485 GL_BlendFunc(GL_ONE, GL_ZERO);
489 memset(&m, 0, sizeof(m));
491 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
493 surface = texturesurfacelist[texturesurfaceindex];
494 R_Mesh_VertexPointer(surface->mesh.data_vertex3f);
495 GL_LockArrays(0, surface->mesh.num_vertices);
496 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
499 GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
502 else if ((texture->currentmaterialflags & MATERIALFLAG_WATER) && r_watershader.value && gl_textureshader && !texture->skin.glow && !fogenabled && ent->colormod[0] == 1 && ent->colormod[1] == 1 && ent->colormod[2] == 1)
504 // NVIDIA Geforce3 distortion texture shader on water
505 float args[4] = {0.05f,0,0,0.04f};
506 memset(&m, 0, sizeof(m));
507 m.tex[0] = R_GetTexture(mod_shared_distorttexture[(int)(r_refdef.time * 16)&63]);
508 m.tex[1] = R_GetTexture(texture->skin.base);
509 m.texcombinergb[0] = GL_REPLACE;
510 m.texcombinergb[1] = GL_REPLACE;
511 Matrix4x4_CreateFromQuakeEntity(&m.texmatrix[0], 0, 0, 0, 0, 0, 0, r_watershader.value);
512 m.texmatrix[1] = r_surf_waterscrollmatrix;
515 GL_Color(1, 1, 1, texture->currentalpha);
517 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
519 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV);
520 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB);
521 qglTexEnvfv(GL_TEXTURE_SHADER_NV, GL_OFFSET_TEXTURE_MATRIX_NV, &args[0]);
522 qglEnable(GL_TEXTURE_SHADER_NV);
524 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
526 surface = texturesurfacelist[texturesurfaceindex];
527 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
528 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
529 R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
530 GL_LockArrays(0, surface->mesh.num_vertices);
531 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
535 qglDisable(GL_TEXTURE_SHADER_NV);
536 qglTexEnvi(GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);
539 else if (texture->currentmaterialflags & (MATERIALFLAG_WATER | MATERIALFLAG_WALL))
541 // normal surface (wall or water)
543 dolightmap = !(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT);
544 doambient = r_ambient.value >= (1/64.0f);
545 dodetail = r_detailtextures.integer && texture->skin.detail != NULL && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT);
546 doglow = texture->skin.glow != NULL;
547 dofogpass = fogenabled && !(texture->currentmaterialflags & MATERIALFLAG_ADD);
548 fogallpasses = fogenabled && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT);
549 if (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT)
551 if (dobase && dolightmap && gl_combine.integer)
554 memset(&m, 0, sizeof(m));
555 m.tex[1] = R_GetTexture(texture->skin.base);
557 m.texmatrix[1] = r_surf_waterscrollmatrix;
558 m.texrgbscale[1] = 2;
559 m.pointer_color = varray_color4f;
562 r = ent->colormod[0] * colorscale;
563 g = ent->colormod[1] * colorscale;
564 b = ent->colormod[2] * colorscale;
565 a = texture->currentalpha;
566 base = r_ambient.value * (1.0f / 64.0f);
567 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
569 surface = texturesurfacelist[texturesurfaceindex];
570 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
571 R_Mesh_VertexPointer(vertex3f);
572 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
573 R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
574 if (surface->lightmaptexture)
576 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
579 R_Mesh_ColorPointer(varray_color4f);
580 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
582 VectorSubtract(v, modelorg, diff);
583 f = 1 - exp(fogdensity/DotProduct(diff, diff));
592 R_Mesh_ColorPointer(NULL);
593 GL_Color(r, g, b, a);
598 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
599 R_Mesh_ColorPointer(varray_color4f);
600 if (surface->styles[0] != 255)
602 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
607 if (surface->styles[0] != 255)
609 if (surface->mesh.data_lightmapcolor4f)
611 float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 128.0f);
612 VectorMA(c, scale, surface->mesh.data_lightmapcolor4f + i*4, c);
614 else if (surface->mesh.data_lightmapoffsets)
616 const qbyte *lm = surface->samples + surface->mesh.data_lightmapoffsets[i];
617 float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 32768.0f);
618 VectorMA(c, scale, lm, c);
619 if (surface->styles[1] != 255)
621 int size3 = ((surface->extents[0]>>4)+1)*((surface->extents[1]>>4)+1)*3;
623 scale = d_lightstylevalue[surface->styles[1]] * (1.0f / 32768.0f);
624 VectorMA(c, scale, lm, c);
625 if (surface->styles[2] != 255)
628 scale = d_lightstylevalue[surface->styles[2]] * (1.0f / 32768.0f);
629 VectorMA(c, scale, lm, c);
630 if (surface->styles[3] != 255)
633 scale = d_lightstylevalue[surface->styles[3]] * (1.0f / 32768.0f);
634 VectorMA(c, scale, lm, c);
645 VectorSubtract(v, modelorg, diff);
646 f = 1 - exp(fogdensity/DotProduct(diff, diff));
647 VectorScale(c, f, c);
649 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
650 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
657 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
659 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
664 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
669 R_Mesh_ColorPointer(NULL);
670 GL_Color(0, 0, 0, a);
674 GL_LockArrays(0, surface->mesh.num_vertices);
675 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
682 memset(&m, 0, sizeof(m));
683 m.tex[0] = R_GetTexture(texture->skin.base);
685 m.texmatrix[0] = r_surf_waterscrollmatrix;
686 m.texmatrix[0] = r_surf_waterscrollmatrix;
687 m.pointer_color = varray_color4f;
689 if (gl_combine.integer)
691 m.texrgbscale[0] = 4;
695 r = ent->colormod[0] * colorscale;
696 g = ent->colormod[1] * colorscale;
697 b = ent->colormod[2] * colorscale;
698 a = texture->currentalpha;
701 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
703 surface = texturesurfacelist[texturesurfaceindex];
704 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
705 R_Mesh_VertexPointer(vertex3f);
706 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
707 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
712 if (surface->styles[0] != 255)
714 if (surface->mesh.data_lightmapcolor4f)
716 float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 128.0f);
717 VectorMA(c, scale, surface->mesh.data_lightmapcolor4f + i*4, c);
719 else if (surface->mesh.data_lightmapoffsets)
721 const qbyte *lm = surface->samples + surface->mesh.data_lightmapoffsets[i];
722 float scale = d_lightstylevalue[surface->styles[0]] * (1.0f / 32768.0f);
723 VectorMA(c, scale, lm, c);
724 if (surface->styles[1] != 255)
726 int size3 = ((surface->extents[0]>>4)+1)*((surface->extents[1]>>4)+1)*3;
728 scale = d_lightstylevalue[surface->styles[1]] * (1.0f / 32768.0f);
729 VectorMA(c, scale, lm, c);
730 if (surface->styles[2] != 255)
733 scale = d_lightstylevalue[surface->styles[2]] * (1.0f / 32768.0f);
734 VectorMA(c, scale, lm, c);
735 if (surface->styles[3] != 255)
738 scale = d_lightstylevalue[surface->styles[3]] * (1.0f / 32768.0f);
739 VectorMA(c, scale, lm, c);
750 VectorSubtract(v, modelorg, diff);
751 f = 1 - exp(fogdensity/DotProduct(diff, diff));
752 VectorScale(c, f, c);
754 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
755 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
759 GL_LockArrays(0, surface->mesh.num_vertices);
760 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
768 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
770 surface = texturesurfacelist[texturesurfaceindex];
771 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
772 R_Mesh_VertexPointer(vertex3f);
773 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
774 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
776 R_Mesh_ColorPointer(varray_color4f);
777 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
779 VectorSubtract(v, modelorg, diff);
780 f = 1 - exp(fogdensity/DotProduct(diff, diff));
784 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
789 R_Mesh_ColorPointer(varray_color4f);
790 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
792 VectorSubtract(v, modelorg, diff);
793 f = 1 - exp(fogdensity/DotProduct(diff, diff));
800 GL_LockArrays(0, surface->mesh.num_vertices);
801 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
807 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
809 surface = texturesurfacelist[texturesurfaceindex];
810 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
811 R_Mesh_VertexPointer(vertex3f);
812 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
813 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
815 R_Mesh_ColorPointer(varray_color4f);
816 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
821 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
826 R_Mesh_ColorPointer(NULL);
827 GL_Color(r, g, b, a);
829 GL_LockArrays(0, surface->mesh.num_vertices);
830 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
839 if (!dolightmap && dobase)
843 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
844 memset(&m, 0, sizeof(m));
845 m.tex[0] = R_GetTexture(texture->skin.base);
847 m.texmatrix[0] = r_surf_waterscrollmatrix;
849 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
851 surface = texturesurfacelist[texturesurfaceindex];
852 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
853 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
854 GL_LockArrays(0, surface->mesh.num_vertices);
855 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
859 if (r_lightmapintensity <= 0 && dolightmap && dobase)
863 GL_Color(0, 0, 0, 1);
864 memset(&m, 0, sizeof(m));
866 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
868 surface = texturesurfacelist[texturesurfaceindex];
869 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
870 GL_LockArrays(0, surface->mesh.num_vertices);
871 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
875 if (r_textureunits.integer >= 2 && gl_combine.integer && dolightmap && dobase)
877 // dualtexture combine
878 GL_BlendFunc(GL_ONE, GL_ZERO);
882 memset(&m, 0, sizeof(m));
883 m.tex[1] = R_GetTexture(texture->skin.base);
885 m.texmatrix[1] = r_surf_waterscrollmatrix;
886 m.texrgbscale[1] = 2;
888 r = ent->colormod[0] * r_lightmapintensity;
889 g = ent->colormod[1] * r_lightmapintensity;
890 b = ent->colormod[2] * r_lightmapintensity;
891 GL_Color(r, g, b, 1);
892 if (texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
894 R_Mesh_VertexPointer(varray_vertex3f);
895 if (r == 1 && g == 1 && b == 1)
897 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
899 surface = texturesurfacelist[texturesurfaceindex];
900 RSurf_DeformVertices(ent, texture, surface, modelorg);
901 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
902 R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
903 if (surface->lightmaptexture)
905 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
906 R_Mesh_ColorPointer(NULL);
908 else //if (r == 1 && g == 1 && b == 1)
910 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
911 R_Mesh_ColorPointer(surface->mesh.data_lightmapcolor4f);
913 GL_LockArrays(0, surface->mesh.num_vertices);
914 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
920 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
922 surface = texturesurfacelist[texturesurfaceindex];
923 RSurf_DeformVertices(ent, texture, surface, modelorg);
924 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
925 R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
926 if (surface->lightmaptexture)
928 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
929 R_Mesh_ColorPointer(NULL);
933 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
934 R_Mesh_ColorPointer(varray_color4f);
935 for (i = 0;i < surface->mesh.num_vertices;i++)
937 varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * r;
938 varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * g;
939 varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * b;
940 varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3];
943 GL_LockArrays(0, surface->mesh.num_vertices);
944 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
951 if (r == 1 && g == 1 && b == 1)
954 // experimental direct state calls for measuring
955 // R_Mesh_ call overhead, do not use!
956 R_Mesh_VertexPointer(varray_vertex3f);
957 R_Mesh_TexCoordPointer(0, 2, varray_texcoord2f[0]);
958 R_Mesh_TexCoordPointer(1, 2, varray_texcoord2f[1]);
959 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
960 R_Mesh_ColorPointer(varray_color4f);
961 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
963 surface = texturesurfacelist[texturesurfaceindex];
964 qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), surface->mesh.data_vertex3f);
965 qglClientActiveTexture(GL_TEXTURE0_ARB);
966 qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), surface->mesh.data_texcoordlightmap2f);
967 qglClientActiveTexture(GL_TEXTURE1_ARB);
968 qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), surface->mesh.data_texcoordtexture2f);
969 if (surface->lightmaptexture)
971 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
972 qglDisableClientState(GL_COLOR_ARRAY);
973 qglColor4f(r, g, b, 1);
975 else //if (r == 1 && g == 1 && b == 1)
977 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
978 qglEnableClientState(GL_COLOR_ARRAY);
979 qglColorPointer(4, GL_FLOAT, sizeof(float[4]), surface->mesh.data_lightmapcolor4f);
981 qglLockArraysEXT(0, surface->mesh.num_vertices);
982 qglDrawRangeElements(GL_TRIANGLES, 0, surface->mesh.num_vertices, surface->mesh.num_triangles * 3, GL_UNSIGNED_INT, surface->mesh.data_element3i);
983 qglUnlockArraysEXT();
986 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
988 surface = texturesurfacelist[texturesurfaceindex];
989 R_Mesh_VertexPointer(surface->mesh.data_vertex3f);
990 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
991 R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
992 if (surface->lightmaptexture)
994 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
995 R_Mesh_ColorPointer(NULL);
997 else //if (r == 1 && g == 1 && b == 1)
999 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
1000 R_Mesh_ColorPointer(surface->mesh.data_lightmapcolor4f);
1002 GL_LockArrays(0, surface->mesh.num_vertices);
1003 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1004 GL_LockArrays(0, 0);
1010 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1012 surface = texturesurfacelist[texturesurfaceindex];
1013 R_Mesh_VertexPointer(surface->mesh.data_vertex3f);
1014 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
1015 R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
1016 if (surface->lightmaptexture)
1018 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
1019 R_Mesh_ColorPointer(NULL);
1023 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
1024 R_Mesh_ColorPointer(varray_color4f);
1025 for (i = 0;i < surface->mesh.num_vertices;i++)
1027 varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * r;
1028 varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * g;
1029 varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * b;
1030 varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3];
1033 GL_LockArrays(0, surface->mesh.num_vertices);
1034 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1035 GL_LockArrays(0, 0);
1043 GL_BlendFunc(GL_ONE, GL_ZERO);
1045 GL_Color(1, 1, 1, 1);
1046 memset(&m, 0, sizeof(m));
1048 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1050 surface = texturesurfacelist[texturesurfaceindex];
1051 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
1052 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
1053 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
1054 R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : surface->mesh.data_lightmapcolor4f);
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);
1062 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1063 GL_DepthMask(false);
1064 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1065 memset(&m, 0, sizeof(m));
1066 m.tex[0] = R_GetTexture(texture->skin.base);
1068 m.texmatrix[0] = r_surf_waterscrollmatrix;
1070 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1072 surface = texturesurfacelist[texturesurfaceindex];
1073 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
1074 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
1075 GL_LockArrays(0, surface->mesh.num_vertices);
1076 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1077 GL_LockArrays(0, 0);
1084 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1085 GL_DepthMask(false);
1086 memset(&m, 0, sizeof(m));
1087 m.tex[0] = R_GetTexture(texture->skin.base);
1089 m.texmatrix[0] = r_surf_waterscrollmatrix;
1090 m.pointer_color = varray_color4f;
1092 if (gl_combine.integer)
1094 m.texrgbscale[0] = 4;
1095 colorscale *= 0.25f;
1098 base = r_ambient.value * (1.0f / 64.0f);
1099 r = ent->colormod[0] * colorscale * base;
1100 g = ent->colormod[1] * colorscale * base;
1101 b = ent->colormod[2] * colorscale * base;
1102 a = texture->currentalpha;
1103 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1105 surface = texturesurfacelist[texturesurfaceindex];
1106 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
1107 R_Mesh_VertexPointer(vertex3f);
1108 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
1109 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
1116 VectorSubtract(v, modelorg, diff);
1117 f = 1 - exp(fogdensity/DotProduct(diff, diff));
1118 VectorScale(c, f, c);
1120 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
1121 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
1125 GL_LockArrays(0, surface->mesh.num_vertices);
1126 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1127 GL_LockArrays(0, 0);
1132 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1133 GL_DepthMask(false);
1134 GL_Color(1, 1, 1, 1);
1135 memset(&m, 0, sizeof(m));
1136 m.tex[0] = R_GetTexture(texture->skin.detail);
1138 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1140 surface = texturesurfacelist[texturesurfaceindex];
1141 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
1142 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoorddetail2f);
1143 GL_LockArrays(0, surface->mesh.num_vertices);
1144 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1145 GL_LockArrays(0, 0);
1150 // if glow was not already done using multitexture, do it now.
1151 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1152 GL_DepthMask(false);
1153 memset(&m, 0, sizeof(m));
1154 m.tex[0] = R_GetTexture(texture->skin.glow);
1156 m.texmatrix[0] = r_surf_waterscrollmatrix;
1157 m.pointer_color = varray_color4f;
1160 r = ent->colormod[0] * colorscale;
1161 g = ent->colormod[1] * colorscale;
1162 b = ent->colormod[2] * colorscale;
1163 a = texture->currentalpha;
1166 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1168 surface = texturesurfacelist[texturesurfaceindex];
1169 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
1170 R_Mesh_VertexPointer(vertex3f);
1171 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
1172 R_Mesh_ColorPointer(varray_color4f);
1173 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
1175 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
1177 VectorSubtract(v, modelorg, diff);
1178 f = 1 - exp(fogdensity/DotProduct(diff, diff));
1182 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
1187 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
1189 VectorSubtract(v, modelorg, diff);
1190 f = 1 - exp(fogdensity/DotProduct(diff, diff));
1197 GL_LockArrays(0, surface->mesh.num_vertices);
1198 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1199 GL_LockArrays(0, 0);
1204 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1206 surface = texturesurfacelist[texturesurfaceindex];
1207 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
1208 R_Mesh_VertexPointer(vertex3f);
1209 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
1210 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
1212 R_Mesh_ColorPointer(varray_color4f);
1213 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
1218 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
1223 R_Mesh_ColorPointer(NULL);
1224 GL_Color(r, g, b, a);
1226 GL_LockArrays(0, surface->mesh.num_vertices);
1227 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1228 GL_LockArrays(0, 0);
1234 // if this is opaque use alpha blend which will darken the earlier
1237 // if this is an alpha blended material, all the earlier passes
1238 // were darkened by fog already, so we only need to add the fog
1239 // color ontop through the fog mask texture
1241 // if this is an additive blended material, all the earlier passes
1242 // were darkened by fog already, and we should not add fog color
1243 // (because the background was not darkened, there is no fog color
1244 // that was lost behind it).
1246 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1248 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1249 GL_DepthMask(false);
1250 memset(&m, 0, sizeof(m));
1251 m.tex[0] = R_GetTexture(texture->skin.fog);
1253 m.texmatrix[0] = r_surf_waterscrollmatrix;
1258 a = texture->currentalpha;
1259 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1261 surface = texturesurfacelist[texturesurfaceindex];
1262 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
1263 R_Mesh_VertexPointer(vertex3f);
1264 R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
1265 R_Mesh_ColorPointer(varray_color4f);
1266 //RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], texture->currentalpha, 1, surface->mesh.num_vertices, modelorg);
1267 if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
1269 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
1271 VectorSubtract(v, modelorg, diff);
1272 f = exp(fogdensity/DotProduct(diff, diff));
1276 c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * f * a;
1281 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
1283 VectorSubtract(v, modelorg, diff);
1284 f = exp(fogdensity/DotProduct(diff, diff));
1291 GL_LockArrays(0, surface->mesh.num_vertices);
1292 R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
1293 GL_LockArrays(0, 0);
1297 if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1298 qglEnable(GL_CULL_FACE);
1301 static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata2)
1303 const entity_render_t *ent = calldata1;
1304 const msurface_t *surface = ent->model->brush.data_surfaces + calldata2;
1308 texture = surface->texture;
1309 if (texture->basematerialflags & MATERIALFLAG_SKY)
1310 return; // transparent sky is too difficult
1311 R_UpdateTextureInfo(ent, texture);
1313 R_Mesh_Matrix(&ent->matrix);
1314 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1315 R_DrawSurfaceList(ent, texture, 1, &surface, modelorg);
1318 void R_QueueSurfaceList(entity_render_t *ent, texture_t *texture, int texturenumsurfaces, const msurface_t **texturesurfacelist, const vec3_t modelorg)
1320 int texturesurfaceindex;
1321 const msurface_t *surface;
1322 vec3_t tempcenter, center;
1323 if (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT)
1325 // drawing sky transparently would be too difficult
1326 if (!(texture->currentmaterialflags & MATERIALFLAG_SKY))
1328 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1330 surface = texturesurfacelist[texturesurfaceindex];
1331 tempcenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
1332 tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
1333 tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
1334 Matrix4x4_Transform(&ent->matrix, tempcenter, center);
1335 R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->brush.data_surfaces);
1340 R_DrawSurfaceList(ent, texture, texturenumsurfaces, texturesurfacelist, modelorg);
1343 void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
1345 int i, j, f, flagsmask;
1346 msurface_t *surface, **surfacechain;
1347 texture_t *t, *texture;
1348 model_t *model = ent->model;
1350 const int maxsurfacelist = 1024;
1351 int numsurfacelist = 0;
1352 const msurface_t *surfacelist[1024];
1355 R_Mesh_Matrix(&ent->matrix);
1356 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1358 // update light styles
1359 if (!skysurfaces && model->brushq1.light_styleupdatechains)
1361 for (i = 0;i < model->brushq1.light_styles;i++)
1363 if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
1365 model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
1366 if ((surfacechain = model->brushq1.light_styleupdatechains[i]))
1367 for (;(surface = *surfacechain);surfacechain++)
1368 surface->cached_dlight = true;
1373 R_UpdateAllTextureInfo(ent);
1374 flagsmask = skysurfaces ? MATERIALFLAG_SKY : (MATERIALFLAG_WATER | MATERIALFLAG_WALL);
1379 if (ent == r_refdef.worldentity)
1381 for (i = 0, j = model->firstmodelsurface, surface = model->brush.data_surfaces + j;i < model->nummodelsurfaces;i++, j++, surface++)
1383 if (!r_worldsurfacevisible[j])
1385 if (t != surface->texture)
1389 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1392 t = surface->texture;
1393 f = t->currentmaterialflags & flagsmask;
1394 texture = t->currentframe;
1396 if (f && surface->mesh.num_triangles)
1398 // if lightmap parameters changed, rebuild lightmap texture
1399 if (surface->cached_dlight && surface->samples)
1400 R_BuildLightMap(ent, surface);
1401 // add face to draw list
1402 surfacelist[numsurfacelist++] = surface;
1403 if (numsurfacelist >= maxsurfacelist)
1405 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1413 for (i = 0, j = model->firstmodelsurface, surface = model->brush.data_surfaces + j;i < model->nummodelsurfaces;i++, j++, surface++)
1415 if (t != surface->texture)
1419 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1422 t = surface->texture;
1423 f = t->currentmaterialflags & flagsmask;
1424 texture = t->currentframe;
1426 if (f && surface->mesh.num_triangles)
1428 // if lightmap parameters changed, rebuild lightmap texture
1429 if (surface->cached_dlight && surface->samples)
1430 R_BuildLightMap(ent, surface);
1431 // add face to draw list
1432 surfacelist[numsurfacelist++] = surface;
1433 if (numsurfacelist >= maxsurfacelist)
1435 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1442 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1445 static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
1450 const mportal_t *portal = calldata1;
1451 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1452 GL_DepthMask(false);
1454 R_Mesh_Matrix(&r_identitymatrix);
1456 memset(&m, 0, sizeof(m));
1457 m.pointer_vertex = varray_vertex3f;
1461 GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f),
1462 ((i & 0x0038) >> 3) * (1.0f / 7.0f),
1463 ((i & 0x01C0) >> 6) * (1.0f / 7.0f),
1465 if (PlaneDiff(r_vieworigin, (&portal->plane)) < 0)
1467 for (i = portal->numpoints - 1, v = varray_vertex3f;i >= 0;i--, v += 3)
1468 VectorCopy(portal->points[i].position, v);
1471 for (i = 0, v = varray_vertex3f;i < portal->numpoints;i++, v += 3)
1472 VectorCopy(portal->points[i].position, v);
1473 GL_LockArrays(0, portal->numpoints);
1474 R_Mesh_Draw(portal->numpoints, portal->numpoints - 2, polygonelements);
1475 GL_LockArrays(0, 0);
1478 // LordHavoc: this is just a nice debugging tool, very slow
1479 static void R_DrawPortals(void)
1484 model_t *model = r_refdef.worldmodel;
1487 for (portalnum = 0, portal = model->brush.data_portals;portalnum < model->brush.num_portals;portalnum++, portal++)
1489 if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
1490 if (!R_CullBox(portal->mins, portal->maxs))
1492 VectorClear(center);
1493 for (i = 0;i < portal->numpoints;i++)
1494 VectorAdd(center, portal->points[i].position, center);
1495 f = ixtable[portal->numpoints];
1496 VectorScale(center, f, center);
1497 R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, portalnum);
1502 static void R_DrawCollisionBrush(colbrushf_t *brush)
1506 memset(&m, 0, sizeof(m));
1507 m.pointer_vertex = brush->points->v;
1509 i = (int)(((size_t)brush) / sizeof(colbrushf_t));
1510 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1511 GL_LockArrays(0, brush->numpoints);
1512 R_Mesh_Draw(brush->numpoints, brush->numtriangles, brush->elements);
1513 GL_LockArrays(0, 0);
1516 static void R_DrawCollisionSurface(entity_render_t *ent, msurface_t *surface)
1520 if (!surface->mesh.num_collisiontriangles)
1522 memset(&m, 0, sizeof(m));
1523 m.pointer_vertex = surface->mesh.data_collisionvertex3f;
1525 i = (int)(((size_t)surface) / sizeof(msurface_t));
1526 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1527 GL_LockArrays(0, surface->mesh.num_collisionvertices);
1528 R_Mesh_Draw(surface->mesh.num_collisionvertices, surface->mesh.num_collisiontriangles, surface->mesh.data_collisionelement3i);
1529 GL_LockArrays(0, 0);
1532 void R_WorldVisibility(void)
1537 model_t *model = r_refdef.worldmodel;
1542 // if possible find the leaf the view origin is in
1543 viewleaf = model->brushq1.PointInLeaf ? model->brushq1.PointInLeaf(model, r_vieworigin) : NULL;
1544 // if possible fetch the visible cluster bits
1545 if (model->brush.FatPVS)
1546 model->brush.FatPVS(model, r_vieworigin, 2, r_pvsbits, sizeof(r_pvsbits));
1548 // clear the visible surface and leaf flags arrays
1549 memset(r_worldsurfacevisible, 0, model->brush.num_surfaces);
1550 memset(r_worldleafvisible, 0, model->brush.num_leafs);
1552 // if the user prefers surfaceworldnode (testing?) or the viewleaf could
1553 // not be found, or the viewleaf is not part of the visible world
1554 // (floating around in the void), use the pvs method
1555 if (r_surfaceworldnode.integer || !viewleaf || viewleaf->clusterindex < 0)
1558 // similar to quake's RecursiveWorldNode but without cache misses
1559 for (j = 0, leaf = model->brush.data_leafs;j < model->brush.num_leafs;j++, leaf++)
1561 // if leaf is in current pvs and on the screen, mark its surfaces
1562 if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
1565 r_worldleafvisible[j] = true;
1566 if (leaf->numleafsurfaces)
1567 for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
1568 r_worldsurfacevisible[*mark] = true;
1576 mleaf_t *leafstack[8192];
1578 // follows portals leading outward from viewleaf, does not venture
1579 // offscreen or into leafs that are not visible, faster than Quake's
1580 // RecursiveWorldNode and vastly better in unvised maps, often culls a
1581 // lot of surface that pvs alone would miss
1582 leafstack[0] = viewleaf;
1584 while (leafstackpos)
1587 leaf = leafstack[--leafstackpos];
1588 r_worldleafvisible[leaf - model->brush.data_leafs] = true;
1589 // mark any surfaces bounding this leaf
1590 if (leaf->numleafsurfaces)
1591 for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
1592 r_worldsurfacevisible[*mark] = true;
1593 // follow portals into other leafs
1595 // if viewer is behind portal (portal faces outward into the scene)
1596 // and the portal polygon's bounding box is on the screen
1597 // and the leaf has not been visited yet
1598 // and the leaf is visible in the pvs
1599 // (the first two checks won't cause as many cache misses as the leaf checks)
1600 for (p = leaf->portals;p;p = p->next)
1601 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))
1602 leafstack[leafstackpos++] = p->past;
1606 if (r_drawportals.integer)
1610 void R_Q1BSP_DrawSky(entity_render_t *ent)
1612 if (ent->model == NULL)
1614 if (r_drawcollisionbrushes.integer < 2)
1615 R_DrawSurfaces(ent, true);
1618 void R_Q1BSP_Draw(entity_render_t *ent)
1620 if (ent->model == NULL)
1623 if (r_drawcollisionbrushes.integer < 2)
1624 R_DrawSurfaces(ent, false);
1625 if (r_drawcollisionbrushes.integer >= 1 && ent->model->brush.num_brushes)
1628 model_t *model = ent->model;
1629 msurface_t *surface;
1631 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1632 GL_DepthMask(false);
1634 qglPolygonOffset(r_drawcollisionbrushes_polygonfactor.value, r_drawcollisionbrushes_polygonoffset.value);
1635 for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
1636 if (brush->colbrushf && brush->colbrushf->numtriangles)
1637 R_DrawCollisionBrush(brush->colbrushf);
1638 for (i = 0, surface = model->brush.data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
1639 if (surface->mesh.num_collisiontriangles)
1640 R_DrawCollisionSurface(ent, surface);
1641 qglPolygonOffset(0, 0);
1645 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)
1647 model_t *model = ent->model;
1648 vec3_t lightmins, lightmaxs;
1649 int t, leafindex, leafsurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
1652 msurface_t *surface;
1655 lightmins[0] = relativelightorigin[0] - lightradius;
1656 lightmins[1] = relativelightorigin[1] - lightradius;
1657 lightmins[2] = relativelightorigin[2] - lightradius;
1658 lightmaxs[0] = relativelightorigin[0] + lightradius;
1659 lightmaxs[1] = relativelightorigin[1] + lightradius;
1660 lightmaxs[2] = relativelightorigin[2] + lightradius;
1661 *outnumclusterspointer = 0;
1662 *outnumsurfacespointer = 0;
1663 memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
1664 memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
1667 VectorCopy(lightmins, outmins);
1668 VectorCopy(lightmaxs, outmaxs);
1671 VectorCopy(relativelightorigin, outmins);
1672 VectorCopy(relativelightorigin, outmaxs);
1673 if (model->brush.GetPVS)
1674 pvs = model->brush.GetPVS(model, relativelightorigin);
1677 R_UpdateAllTextureInfo(ent);
1678 // FIXME: use BSP recursion as lights are often small
1679 for (leafindex = 0, leaf = model->brush.data_leafs;leafindex < model->brush.num_leafs;leafindex++, leaf++)
1681 if (BoxesOverlap(lightmins, lightmaxs, leaf->mins, leaf->maxs) && (pvs == NULL || CHECKPVSBIT(pvs, leaf->clusterindex)))
1683 outmins[0] = min(outmins[0], leaf->mins[0]);
1684 outmins[1] = min(outmins[1], leaf->mins[1]);
1685 outmins[2] = min(outmins[2], leaf->mins[2]);
1686 outmaxs[0] = max(outmaxs[0], leaf->maxs[0]);
1687 outmaxs[1] = max(outmaxs[1], leaf->maxs[1]);
1688 outmaxs[2] = max(outmaxs[2], leaf->maxs[2]);
1691 if (!CHECKPVSBIT(outclusterpvs, leaf->clusterindex))
1693 SETPVSBIT(outclusterpvs, leaf->clusterindex);
1694 outclusterlist[outnumclusters++] = leaf->clusterindex;
1699 for (leafsurfaceindex = 0;leafsurfaceindex < leaf->numleafsurfaces;leafsurfaceindex++)
1701 surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
1702 if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
1704 surface = model->brush.data_surfaces + surfaceindex;
1705 if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs))
1706 if ((surface->texture->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT)) == MATERIALFLAG_WALL)
1708 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
1710 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
1711 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
1712 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
1713 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])))
1715 SETPVSBIT(outsurfacepvs, surfaceindex);
1716 outsurfacelist[outnumsurfaces++] = surfaceindex;
1727 // limit combined leaf box to light boundaries
1728 outmins[0] = max(outmins[0], lightmins[0]);
1729 outmins[1] = max(outmins[1], lightmins[1]);
1730 outmins[2] = max(outmins[2], lightmins[2]);
1731 outmaxs[0] = min(outmaxs[0], lightmaxs[0]);
1732 outmaxs[1] = min(outmaxs[1], lightmaxs[1]);
1733 outmaxs[2] = min(outmaxs[2], lightmaxs[2]);
1735 *outnumclusterspointer = outnumclusters;
1736 *outnumsurfacespointer = outnumsurfaces;
1739 void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist, const vec3_t lightmins, const vec3_t lightmaxs)
1741 model_t *model = ent->model;
1742 msurface_t *surface;
1743 int surfacelistindex;
1744 if (r_drawcollisionbrushes.integer < 2)
1746 R_Mesh_Matrix(&ent->matrix);
1747 R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
1748 if (!r_shadow_compilingrtlight)
1749 R_UpdateAllTextureInfo(ent);
1750 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1752 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
1753 if ((surface->texture->currentmaterialflags & (MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT | MATERIALFLAG_WALL)) != MATERIALFLAG_WALL)
1755 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1757 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);
1759 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);
1763 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)
1765 model_t *model = ent->model;
1766 msurface_t *surface;
1768 int surfacelistindex;
1769 if (r_drawcollisionbrushes.integer < 2)
1771 R_Mesh_Matrix(&ent->matrix);
1772 if (!r_shadow_compilingrtlight)
1773 R_UpdateAllTextureInfo(ent);
1774 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1776 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
1777 if (surface->texture->basematerialflags & MATERIALFLAG_NODRAW || !surface->mesh.num_triangles)
1779 if (r_shadow_compilingrtlight)
1781 // if compiling an rtlight, capture the mesh
1782 t = surface->texture;
1783 if ((t->basematerialflags & (MATERIALFLAG_WALL | MATERIALFLAG_TRANSPARENT)) == MATERIALFLAG_WALL)
1784 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);
1786 else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surfacelist[surfacelistindex]])
1788 t = surface->texture->currentframe;
1789 // FIXME: transparent surfaces need to be lit later
1790 if ((t->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_TRANSPARENT)) == MATERIALFLAG_WALL)
1792 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1793 qglDisable(GL_CULL_FACE);
1794 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);
1795 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1796 qglEnable(GL_CULL_FACE);
1804 static void gl_surf_start(void)
1808 static void gl_surf_shutdown(void)
1812 static void gl_surf_newmap(void)
1817 void GL_Surf_Init(void)
1820 Cvar_RegisterVariable(&r_ambient);
1821 Cvar_RegisterVariable(&r_drawportals);
1822 Cvar_RegisterVariable(&r_testvis);
1823 Cvar_RegisterVariable(&r_detailtextures);
1824 Cvar_RegisterVariable(&r_surfaceworldnode);
1825 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor);
1826 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);
1827 Cvar_RegisterVariable(&r_q3bsp_renderskydepth);
1828 Cvar_RegisterVariable(&gl_lightmaps);
1830 //R_RegisterModule("GL_Surf", gl_surf_start, gl_surf_shutdown, gl_surf_newmap);