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->lightmapinfo->extents[0]>>4)+1;
65 tmax = (surface->lightmapinfo->extents[1]>>4)+1;
68 lightmap = surface->lightmapinfo->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->lightmapinfo->styles[maps] != 255;maps++, lightmap += size3)
87 for (scale = d_lightstylevalue[surface->lightmapinfo->styles[maps]], i = 0;i < size3;i++)
88 bl[i] += lightmap[i] * scale;
92 stain = surface->lightmapinfo->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->lightmapinfo->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->lightmapinfo->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->lightmapinfo->stainsamples)
175 smax = (surface->lightmapinfo->extents[0] >> 4) + 1;
176 tmax = (surface->lightmapinfo->extents[1] >> 4) + 1;
178 impacts = DotProduct (impact, surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3] - surface->lightmapinfo->texturemins[0];
179 impactt = DotProduct (impact, surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3] - surface->lightmapinfo->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->lightmapinfo->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 || !r_refdef.worldmodel->brushq1.lightdata)
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->num_vertices - 3;j += 4)
312 for (i = 0;i < 4;i++)
313 VectorAdd(center, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (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->groupmesh->data_normal3f + 3 * surface->num_firstvertex) + j*3, (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex) + j*3, (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex) + j*3, center);
317 Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
318 for (i = 0;i < 4;i++)
319 Matrix4x4_Transform(&imatrix1, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (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->num_vertices - 3;j += 4)
338 for (i = 0;i < 4;i++)
339 VectorAdd(center, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (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->groupmesh->data_normal3f + 3 * surface->num_firstvertex) + j*3, (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex) + j*3, (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex) + j*3, center);
343 Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
344 for (i = 0;i < 4;i++)
345 Matrix4x4_Transform(&imatrix1, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), sizeof(float[3]) * surface->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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex))
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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex);
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->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
440 R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
441 R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
442 GL_LockArrays(0, surface->num_vertices);
443 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
495 GL_LockArrays(0, surface->num_vertices);
496 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
529 R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
530 GL_LockArrays(0, surface->num_vertices);
531 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
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 // q3bsp has no lightmap updates, so the lightstylevalue that
568 // would normally be baked into the lightmaptexture must be
569 // applied to the color
570 if (ent->model->brushq1.lightdata)
572 float scale = d_lightstylevalue[0] * (1.0f / 128.0f);
577 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
579 surface = texturesurfacelist[texturesurfaceindex];
580 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
581 R_Mesh_VertexPointer(vertex3f);
582 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
583 R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
584 if (surface->lightmaptexture)
586 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
589 R_Mesh_ColorPointer(varray_color4f);
590 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
592 VectorSubtract(v, modelorg, diff);
593 f = 1 - exp(fogdensity/DotProduct(diff, diff));
602 R_Mesh_ColorPointer(NULL);
603 GL_Color(r, g, b, a);
608 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
609 R_Mesh_ColorPointer(varray_color4f);
610 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex))
612 for (i = 0, c = varray_color4f;i < surface->num_vertices;i++, c += 4)
614 c[0] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+0] * r;
615 c[1] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+1] * g;
616 c[2] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+2] * b;
617 c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
621 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
623 VectorSubtract(v, modelorg, diff);
624 f = 1 - exp(fogdensity/DotProduct(diff, diff));
625 VectorScale(c, f, c);
631 R_Mesh_ColorPointer(NULL);
632 GL_Color(0, 0, 0, a);
635 GL_LockArrays(0, surface->num_vertices);
636 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
643 memset(&m, 0, sizeof(m));
644 m.tex[0] = R_GetTexture(texture->skin.base);
646 m.texmatrix[0] = r_surf_waterscrollmatrix;
647 m.texmatrix[0] = r_surf_waterscrollmatrix;
648 m.pointer_color = varray_color4f;
650 if (gl_combine.integer)
652 m.texrgbscale[0] = 4;
656 r = ent->colormod[0] * colorscale;
657 g = ent->colormod[1] * colorscale;
658 b = ent->colormod[2] * colorscale;
659 a = texture->currentalpha;
662 // q3bsp has no lightmap updates, so the lightstylevalue that
663 // would normally be baked into the lightmaptexture must be
664 // applied to the color
665 if (!ent->model->brushq1.lightdata)
667 float scale = d_lightstylevalue[0] * (1.0f / 128.0f);
672 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
674 surface = texturesurfacelist[texturesurfaceindex];
675 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
676 R_Mesh_VertexPointer(vertex3f);
677 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
678 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
683 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex))
684 VectorCopy((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) + i*4, c);
685 else if (surface->lightmapinfo)
687 const qbyte *lm = surface->lightmapinfo->samples + (surface->groupmesh->data_lightmapoffsets + surface->num_firstvertex)[i];
688 float scale = d_lightstylevalue[surface->lightmapinfo->styles[0]] * (1.0f / 32768.0f);
689 VectorMA(c, scale, lm, c);
690 if (surface->lightmapinfo->styles[1] != 255)
692 int size3 = ((surface->lightmapinfo->extents[0]>>4)+1)*((surface->lightmapinfo->extents[1]>>4)+1)*3;
694 scale = d_lightstylevalue[surface->lightmapinfo->styles[1]] * (1.0f / 32768.0f);
695 VectorMA(c, scale, lm, c);
696 if (surface->lightmapinfo->styles[2] != 255)
699 scale = d_lightstylevalue[surface->lightmapinfo->styles[2]] * (1.0f / 32768.0f);
700 VectorMA(c, scale, lm, c);
701 if (surface->lightmapinfo->styles[3] != 255)
704 scale = d_lightstylevalue[surface->lightmapinfo->styles[3]] * (1.0f / 32768.0f);
705 VectorMA(c, scale, lm, c);
715 VectorSubtract(v, modelorg, diff);
716 f = 1 - exp(fogdensity/DotProduct(diff, diff));
717 VectorScale(c, f, c);
719 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
720 c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
724 GL_LockArrays(0, surface->num_vertices);
725 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
733 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
735 surface = texturesurfacelist[texturesurfaceindex];
736 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
737 R_Mesh_VertexPointer(vertex3f);
738 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
739 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
741 R_Mesh_ColorPointer(varray_color4f);
742 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
744 VectorSubtract(v, modelorg, diff);
745 f = 1 - exp(fogdensity/DotProduct(diff, diff));
749 c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
754 R_Mesh_ColorPointer(varray_color4f);
755 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
757 VectorSubtract(v, modelorg, diff);
758 f = 1 - exp(fogdensity/DotProduct(diff, diff));
765 GL_LockArrays(0, surface->num_vertices);
766 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
772 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
774 surface = texturesurfacelist[texturesurfaceindex];
775 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
776 R_Mesh_VertexPointer(vertex3f);
777 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
778 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
780 R_Mesh_ColorPointer(varray_color4f);
781 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
786 c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
791 R_Mesh_ColorPointer(NULL);
792 GL_Color(r, g, b, a);
794 GL_LockArrays(0, surface->num_vertices);
795 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
804 if (!dolightmap && dobase)
808 GL_Color(ent->colormod[0], ent->colormod[1], ent->colormod[2], 1);
809 memset(&m, 0, sizeof(m));
810 m.tex[0] = R_GetTexture(texture->skin.base);
812 m.texmatrix[0] = r_surf_waterscrollmatrix;
814 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
816 surface = texturesurfacelist[texturesurfaceindex];
817 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
818 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
819 GL_LockArrays(0, surface->num_vertices);
820 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
824 if (r_lightmapintensity <= 0 && dolightmap && dobase)
828 GL_Color(0, 0, 0, 1);
829 memset(&m, 0, sizeof(m));
831 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
833 surface = texturesurfacelist[texturesurfaceindex];
834 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
835 GL_LockArrays(0, surface->num_vertices);
836 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
840 if (r_textureunits.integer >= 2 && gl_combine.integer && dolightmap && dobase)
842 // dualtexture combine
843 GL_BlendFunc(GL_ONE, GL_ZERO);
847 memset(&m, 0, sizeof(m));
848 m.tex[1] = R_GetTexture(texture->skin.base);
850 m.texmatrix[1] = r_surf_waterscrollmatrix;
851 m.texrgbscale[1] = 2;
853 r = ent->colormod[0] * r_lightmapintensity;
854 g = ent->colormod[1] * r_lightmapintensity;
855 b = ent->colormod[2] * r_lightmapintensity;
856 GL_Color(r, g, b, 1);
857 if (texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
859 R_Mesh_VertexPointer(varray_vertex3f);
860 if (r == 1 && g == 1 && b == 1)
862 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
864 surface = texturesurfacelist[texturesurfaceindex];
865 RSurf_DeformVertices(ent, texture, surface, modelorg);
866 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
867 R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
868 if (surface->lightmaptexture)
870 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
871 R_Mesh_ColorPointer(NULL);
873 else //if (r == 1 && g == 1 && b == 1)
875 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
876 R_Mesh_ColorPointer((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
878 GL_LockArrays(0, surface->num_vertices);
879 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
885 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
887 surface = texturesurfacelist[texturesurfaceindex];
888 RSurf_DeformVertices(ent, texture, surface, modelorg);
889 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
890 R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
891 if (surface->lightmaptexture)
893 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
894 R_Mesh_ColorPointer(NULL);
898 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
899 R_Mesh_ColorPointer(varray_color4f);
900 for (i = 0;i < surface->num_vertices;i++)
902 varray_color4f[i*4+0] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+0] * r;
903 varray_color4f[i*4+1] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+1] * g;
904 varray_color4f[i*4+2] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+2] * b;
905 varray_color4f[i*4+3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3];
908 GL_LockArrays(0, surface->num_vertices);
909 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
916 if (r == 1 && g == 1 && b == 1)
919 // experimental direct state calls for measuring
920 // R_Mesh_ call overhead, do not use!
921 R_Mesh_VertexPointer(varray_vertex3f);
922 R_Mesh_TexCoordPointer(0, 2, varray_texcoord2f[0]);
923 R_Mesh_TexCoordPointer(1, 2, varray_texcoord2f[1]);
924 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
925 R_Mesh_ColorPointer(varray_color4f);
926 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
928 surface = texturesurfacelist[texturesurfaceindex];
929 qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
930 qglClientActiveTexture(GL_TEXTURE0_ARB);
931 qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
932 qglClientActiveTexture(GL_TEXTURE1_ARB);
933 qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
934 if (surface->lightmaptexture)
936 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
937 qglDisableClientState(GL_COLOR_ARRAY);
938 qglColor4f(r, g, b, 1);
940 else //if (r == 1 && g == 1 && b == 1)
942 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
943 qglEnableClientState(GL_COLOR_ARRAY);
944 qglColorPointer(4, GL_FLOAT, sizeof(float[4]), (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
946 qglLockArraysEXT(0, surface->num_vertices);
947 qglDrawRangeElements(GL_TRIANGLES, 0, surface->num_vertices, surface->num_triangles * 3, GL_UNSIGNED_INT, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
948 qglUnlockArraysEXT();
951 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
953 surface = texturesurfacelist[texturesurfaceindex];
954 R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
955 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
956 R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
957 if (surface->lightmaptexture)
959 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
960 R_Mesh_ColorPointer(NULL);
962 else //if (r == 1 && g == 1 && b == 1)
964 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
965 R_Mesh_ColorPointer((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
967 GL_LockArrays(0, surface->num_vertices);
968 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
975 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
977 surface = texturesurfacelist[texturesurfaceindex];
978 R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
979 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
980 R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
981 if (surface->lightmaptexture)
983 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
984 R_Mesh_ColorPointer(NULL);
988 R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
989 R_Mesh_ColorPointer(varray_color4f);
990 for (i = 0;i < surface->num_vertices;i++)
992 varray_color4f[i*4+0] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+0] * r;
993 varray_color4f[i*4+1] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+1] * g;
994 varray_color4f[i*4+2] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+2] * b;
995 varray_color4f[i*4+3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3];
998 GL_LockArrays(0, surface->num_vertices);
999 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1000 GL_LockArrays(0, 0);
1008 GL_BlendFunc(GL_ONE, GL_ZERO);
1010 GL_Color(1, 1, 1, 1);
1011 memset(&m, 0, sizeof(m));
1013 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1015 surface = texturesurfacelist[texturesurfaceindex];
1016 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
1017 R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
1018 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
1019 R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
1020 GL_LockArrays(0, surface->num_vertices);
1021 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1022 GL_LockArrays(0, 0);
1027 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1028 GL_DepthMask(false);
1029 GL_Color(r_lightmapintensity * ent->colormod[0], r_lightmapintensity * ent->colormod[1], r_lightmapintensity * ent->colormod[2], 1);
1030 memset(&m, 0, sizeof(m));
1031 m.tex[0] = R_GetTexture(texture->skin.base);
1033 m.texmatrix[0] = r_surf_waterscrollmatrix;
1035 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1037 surface = texturesurfacelist[texturesurfaceindex];
1038 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
1039 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
1040 GL_LockArrays(0, surface->num_vertices);
1041 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1042 GL_LockArrays(0, 0);
1049 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1050 GL_DepthMask(false);
1051 memset(&m, 0, sizeof(m));
1052 m.tex[0] = R_GetTexture(texture->skin.base);
1054 m.texmatrix[0] = r_surf_waterscrollmatrix;
1055 m.pointer_color = varray_color4f;
1057 if (gl_combine.integer)
1059 m.texrgbscale[0] = 4;
1060 colorscale *= 0.25f;
1063 base = r_ambient.value * (1.0f / 64.0f);
1064 r = ent->colormod[0] * colorscale * base;
1065 g = ent->colormod[1] * colorscale * base;
1066 b = ent->colormod[2] * colorscale * base;
1067 a = texture->currentalpha;
1068 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1070 surface = texturesurfacelist[texturesurfaceindex];
1071 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
1072 R_Mesh_VertexPointer(vertex3f);
1073 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
1074 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
1081 VectorSubtract(v, modelorg, diff);
1082 f = 1 - exp(fogdensity/DotProduct(diff, diff));
1083 VectorScale(c, f, c);
1085 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
1086 c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
1090 GL_LockArrays(0, surface->num_vertices);
1091 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1092 GL_LockArrays(0, 0);
1097 GL_BlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
1098 GL_DepthMask(false);
1099 GL_Color(1, 1, 1, 1);
1100 memset(&m, 0, sizeof(m));
1101 m.tex[0] = R_GetTexture(texture->skin.detail);
1103 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1105 surface = texturesurfacelist[texturesurfaceindex];
1106 R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
1107 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoorddetail2f + 2 * surface->num_firstvertex));
1108 GL_LockArrays(0, surface->num_vertices);
1109 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1110 GL_LockArrays(0, 0);
1115 // if glow was not already done using multitexture, do it now.
1116 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1117 GL_DepthMask(false);
1118 memset(&m, 0, sizeof(m));
1119 m.tex[0] = R_GetTexture(texture->skin.glow);
1121 m.texmatrix[0] = r_surf_waterscrollmatrix;
1122 m.pointer_color = varray_color4f;
1125 r = ent->colormod[0] * colorscale;
1126 g = ent->colormod[1] * colorscale;
1127 b = ent->colormod[2] * colorscale;
1128 a = texture->currentalpha;
1131 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1133 surface = texturesurfacelist[texturesurfaceindex];
1134 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
1135 R_Mesh_VertexPointer(vertex3f);
1136 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
1137 R_Mesh_ColorPointer(varray_color4f);
1138 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
1140 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
1142 VectorSubtract(v, modelorg, diff);
1143 f = 1 - exp(fogdensity/DotProduct(diff, diff));
1147 c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
1152 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
1154 VectorSubtract(v, modelorg, diff);
1155 f = 1 - exp(fogdensity/DotProduct(diff, diff));
1162 GL_LockArrays(0, surface->num_vertices);
1163 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1164 GL_LockArrays(0, 0);
1169 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1171 surface = texturesurfacelist[texturesurfaceindex];
1172 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
1173 R_Mesh_VertexPointer(vertex3f);
1174 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
1175 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
1177 R_Mesh_ColorPointer(varray_color4f);
1178 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
1183 c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
1188 R_Mesh_ColorPointer(NULL);
1189 GL_Color(r, g, b, a);
1191 GL_LockArrays(0, surface->num_vertices);
1192 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1193 GL_LockArrays(0, 0);
1199 // if this is opaque use alpha blend which will darken the earlier
1202 // if this is an alpha blended material, all the earlier passes
1203 // were darkened by fog already, so we only need to add the fog
1204 // color ontop through the fog mask texture
1206 // if this is an additive blended material, all the earlier passes
1207 // were darkened by fog already, and we should not add fog color
1208 // (because the background was not darkened, there is no fog color
1209 // that was lost behind it).
1211 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1213 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1214 GL_DepthMask(false);
1215 memset(&m, 0, sizeof(m));
1216 m.tex[0] = R_GetTexture(texture->skin.fog);
1218 m.texmatrix[0] = r_surf_waterscrollmatrix;
1223 a = texture->currentalpha;
1224 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1226 surface = texturesurfacelist[texturesurfaceindex];
1227 vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
1228 R_Mesh_VertexPointer(vertex3f);
1229 R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
1230 R_Mesh_ColorPointer(varray_color4f);
1231 //RSurf_FogPassColors_Vertex3f_Color4f((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], texture->currentalpha, 1, surface->num_vertices, modelorg);
1232 if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
1234 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
1236 VectorSubtract(v, modelorg, diff);
1237 f = exp(fogdensity/DotProduct(diff, diff));
1241 c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * f * a;
1246 for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
1248 VectorSubtract(v, modelorg, diff);
1249 f = exp(fogdensity/DotProduct(diff, diff));
1256 GL_LockArrays(0, surface->num_vertices);
1257 R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1258 GL_LockArrays(0, 0);
1262 if (texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1263 qglEnable(GL_CULL_FACE);
1266 static void RSurfShader_Transparent_Callback(const void *calldata1, int calldata2)
1268 const entity_render_t *ent = calldata1;
1269 const msurface_t *surface = ent->model->brush.data_surfaces + calldata2;
1273 texture = surface->texture;
1274 if (texture->basematerialflags & MATERIALFLAG_SKY)
1275 return; // transparent sky is too difficult
1276 R_UpdateTextureInfo(ent, texture);
1278 R_Mesh_Matrix(&ent->matrix);
1279 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1280 R_DrawSurfaceList(ent, texture, 1, &surface, modelorg);
1283 void R_QueueSurfaceList(entity_render_t *ent, texture_t *texture, int texturenumsurfaces, const msurface_t **texturesurfacelist, const vec3_t modelorg)
1285 int texturesurfaceindex;
1286 const msurface_t *surface;
1287 vec3_t tempcenter, center;
1288 if (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT)
1290 // drawing sky transparently would be too difficult
1291 if (!(texture->currentmaterialflags & MATERIALFLAG_SKY))
1293 for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
1295 surface = texturesurfacelist[texturesurfaceindex];
1296 tempcenter[0] = (surface->mins[0] + surface->maxs[0]) * 0.5f;
1297 tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
1298 tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
1299 Matrix4x4_Transform(&ent->matrix, tempcenter, center);
1300 R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_vieworigin : center, RSurfShader_Transparent_Callback, ent, surface - ent->model->brush.data_surfaces);
1305 R_DrawSurfaceList(ent, texture, texturenumsurfaces, texturesurfacelist, modelorg);
1308 void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
1310 int i, j, f, flagsmask;
1311 msurface_t *surface, **surfacechain;
1312 texture_t *t, *texture;
1313 model_t *model = ent->model;
1315 const int maxsurfacelist = 1024;
1316 int numsurfacelist = 0;
1317 const msurface_t *surfacelist[1024];
1320 R_Mesh_Matrix(&ent->matrix);
1321 Matrix4x4_Transform(&ent->inversematrix, r_vieworigin, modelorg);
1323 // update light styles
1324 if (!skysurfaces && model->brushq1.light_styleupdatechains)
1326 for (i = 0;i < model->brushq1.light_styles;i++)
1328 if (model->brushq1.light_stylevalue[i] != d_lightstylevalue[model->brushq1.light_style[i]])
1330 model->brushq1.light_stylevalue[i] = d_lightstylevalue[model->brushq1.light_style[i]];
1331 if ((surfacechain = model->brushq1.light_styleupdatechains[i]))
1332 for (;(surface = *surfacechain);surfacechain++)
1333 surface->cached_dlight = true;
1338 R_UpdateAllTextureInfo(ent);
1339 flagsmask = skysurfaces ? MATERIALFLAG_SKY : (MATERIALFLAG_WATER | MATERIALFLAG_WALL);
1344 if (ent == r_refdef.worldentity)
1346 for (i = 0, j = model->firstmodelsurface, surface = model->brush.data_surfaces + j;i < model->nummodelsurfaces;i++, j++, surface++)
1348 if (!r_worldsurfacevisible[j])
1350 if (t != surface->texture)
1354 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1357 t = surface->texture;
1358 f = t->currentmaterialflags & flagsmask;
1359 texture = t->currentframe;
1361 if (f && surface->num_triangles)
1363 // if lightmap parameters changed, rebuild lightmap texture
1364 if (surface->cached_dlight && surface->lightmapinfo->samples)
1365 R_BuildLightMap(ent, surface);
1366 // add face to draw list
1367 surfacelist[numsurfacelist++] = surface;
1368 if (numsurfacelist >= maxsurfacelist)
1370 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1378 for (i = 0, j = model->firstmodelsurface, surface = model->brush.data_surfaces + j;i < model->nummodelsurfaces;i++, j++, surface++)
1380 if (t != surface->texture)
1384 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1387 t = surface->texture;
1388 f = t->currentmaterialflags & flagsmask;
1389 texture = t->currentframe;
1391 if (f && surface->num_triangles)
1393 // if lightmap parameters changed, rebuild lightmap texture
1394 if (surface->cached_dlight && surface->lightmapinfo->samples)
1395 R_BuildLightMap(ent, surface);
1396 // add face to draw list
1397 surfacelist[numsurfacelist++] = surface;
1398 if (numsurfacelist >= maxsurfacelist)
1400 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1407 R_QueueSurfaceList(ent, texture, numsurfacelist, surfacelist, modelorg);
1410 static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
1415 const mportal_t *portal = calldata1;
1416 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1417 GL_DepthMask(false);
1419 R_Mesh_Matrix(&r_identitymatrix);
1421 memset(&m, 0, sizeof(m));
1422 m.pointer_vertex = varray_vertex3f;
1426 GL_Color(((i & 0x0007) >> 0) * (1.0f / 7.0f),
1427 ((i & 0x0038) >> 3) * (1.0f / 7.0f),
1428 ((i & 0x01C0) >> 6) * (1.0f / 7.0f),
1430 if (PlaneDiff(r_vieworigin, (&portal->plane)) < 0)
1432 for (i = portal->numpoints - 1, v = varray_vertex3f;i >= 0;i--, v += 3)
1433 VectorCopy(portal->points[i].position, v);
1436 for (i = 0, v = varray_vertex3f;i < portal->numpoints;i++, v += 3)
1437 VectorCopy(portal->points[i].position, v);
1438 GL_LockArrays(0, portal->numpoints);
1439 R_Mesh_Draw(0, portal->numpoints, portal->numpoints - 2, polygonelements);
1440 GL_LockArrays(0, 0);
1443 // LordHavoc: this is just a nice debugging tool, very slow
1444 static void R_DrawPortals(void)
1449 model_t *model = r_refdef.worldmodel;
1452 for (portalnum = 0, portal = model->brush.data_portals;portalnum < model->brush.num_portals;portalnum++, portal++)
1454 if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
1455 if (!R_CullBox(portal->mins, portal->maxs))
1457 VectorClear(center);
1458 for (i = 0;i < portal->numpoints;i++)
1459 VectorAdd(center, portal->points[i].position, center);
1460 f = ixtable[portal->numpoints];
1461 VectorScale(center, f, center);
1462 R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, portalnum);
1467 static void R_DrawCollisionBrush(colbrushf_t *brush)
1471 memset(&m, 0, sizeof(m));
1472 m.pointer_vertex = brush->points->v;
1474 i = (int)(((size_t)brush) / sizeof(colbrushf_t));
1475 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1476 GL_LockArrays(0, brush->numpoints);
1477 R_Mesh_Draw(0, brush->numpoints, brush->numtriangles, brush->elements);
1478 GL_LockArrays(0, 0);
1481 static void R_DrawCollisionSurface(entity_render_t *ent, msurface_t *surface)
1485 if (!surface->num_collisiontriangles)
1487 memset(&m, 0, sizeof(m));
1488 m.pointer_vertex = surface->data_collisionvertex3f;
1490 i = (int)(((size_t)surface) / sizeof(msurface_t));
1491 GL_Color((i & 31) * (1.0f / 32.0f), ((i >> 5) & 31) * (1.0f / 32.0f), ((i >> 10) & 31) * (1.0f / 32.0f), 0.2f);
1492 GL_LockArrays(0, surface->num_collisionvertices);
1493 R_Mesh_Draw(0, surface->num_collisionvertices, surface->num_collisiontriangles, surface->data_collisionelement3i);
1494 GL_LockArrays(0, 0);
1497 void R_WorldVisibility(void)
1502 model_t *model = r_refdef.worldmodel;
1507 // if possible find the leaf the view origin is in
1508 viewleaf = model->brushq1.PointInLeaf ? model->brushq1.PointInLeaf(model, r_vieworigin) : NULL;
1509 // if possible fetch the visible cluster bits
1510 if (model->brush.FatPVS)
1511 model->brush.FatPVS(model, r_vieworigin, 2, r_pvsbits, sizeof(r_pvsbits));
1513 // clear the visible surface and leaf flags arrays
1514 memset(r_worldsurfacevisible, 0, model->brush.num_surfaces);
1515 memset(r_worldleafvisible, 0, model->brush.num_leafs);
1517 // if the user prefers surfaceworldnode (testing?) or the viewleaf could
1518 // not be found, or the viewleaf is not part of the visible world
1519 // (floating around in the void), use the pvs method
1520 if (r_surfaceworldnode.integer || !viewleaf || viewleaf->clusterindex < 0)
1523 // similar to quake's RecursiveWorldNode but without cache misses
1524 for (j = 0, leaf = model->brush.data_leafs;j < model->brush.num_leafs;j++, leaf++)
1526 // if leaf is in current pvs and on the screen, mark its surfaces
1527 if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
1530 r_worldleafvisible[j] = true;
1531 if (leaf->numleafsurfaces)
1532 for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
1533 r_worldsurfacevisible[*mark] = true;
1541 mleaf_t *leafstack[8192];
1543 // follows portals leading outward from viewleaf, does not venture
1544 // offscreen or into leafs that are not visible, faster than Quake's
1545 // RecursiveWorldNode and vastly better in unvised maps, often culls a
1546 // lot of surface that pvs alone would miss
1547 leafstack[0] = viewleaf;
1549 while (leafstackpos)
1552 leaf = leafstack[--leafstackpos];
1553 r_worldleafvisible[leaf - model->brush.data_leafs] = true;
1554 // mark any surfaces bounding this leaf
1555 if (leaf->numleafsurfaces)
1556 for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
1557 r_worldsurfacevisible[*mark] = true;
1558 // follow portals into other leafs
1560 // if viewer is behind portal (portal faces outward into the scene)
1561 // and the portal polygon's bounding box is on the screen
1562 // and the leaf has not been visited yet
1563 // and the leaf is visible in the pvs
1564 // (the first two checks won't cause as many cache misses as the leaf checks)
1565 for (p = leaf->portals;p;p = p->next)
1566 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))
1567 leafstack[leafstackpos++] = p->past;
1571 if (r_drawportals.integer)
1575 void R_Q1BSP_DrawSky(entity_render_t *ent)
1577 if (ent->model == NULL)
1579 if (r_drawcollisionbrushes.integer < 2)
1580 R_DrawSurfaces(ent, true);
1583 void R_Q1BSP_Draw(entity_render_t *ent)
1585 if (ent->model == NULL)
1588 if (r_drawcollisionbrushes.integer < 2)
1589 R_DrawSurfaces(ent, false);
1590 if (r_drawcollisionbrushes.integer >= 1 && ent->model->brush.num_brushes)
1593 model_t *model = ent->model;
1594 msurface_t *surface;
1596 GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
1597 GL_DepthMask(false);
1599 qglPolygonOffset(r_drawcollisionbrushes_polygonfactor.value, r_drawcollisionbrushes_polygonoffset.value);
1600 for (i = 0, brush = model->brush.data_brushes + model->firstmodelbrush;i < model->nummodelbrushes;i++, brush++)
1601 if (brush->colbrushf && brush->colbrushf->numtriangles)
1602 R_DrawCollisionBrush(brush->colbrushf);
1603 for (i = 0, surface = model->brush.data_surfaces + model->firstmodelsurface;i < model->nummodelsurfaces;i++, surface++)
1604 if (surface->num_collisiontriangles)
1605 R_DrawCollisionSurface(ent, surface);
1606 qglPolygonOffset(0, 0);
1610 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)
1612 model_t *model = ent->model;
1613 vec3_t lightmins, lightmaxs;
1614 int t, leafindex, leafsurfaceindex, surfaceindex, triangleindex, outnumclusters = 0, outnumsurfaces = 0;
1617 msurface_t *surface;
1620 lightmins[0] = relativelightorigin[0] - lightradius;
1621 lightmins[1] = relativelightorigin[1] - lightradius;
1622 lightmins[2] = relativelightorigin[2] - lightradius;
1623 lightmaxs[0] = relativelightorigin[0] + lightradius;
1624 lightmaxs[1] = relativelightorigin[1] + lightradius;
1625 lightmaxs[2] = relativelightorigin[2] + lightradius;
1626 *outnumclusterspointer = 0;
1627 *outnumsurfacespointer = 0;
1628 memset(outclusterpvs, 0, model->brush.num_pvsclusterbytes);
1629 memset(outsurfacepvs, 0, (model->nummodelsurfaces + 7) >> 3);
1632 VectorCopy(lightmins, outmins);
1633 VectorCopy(lightmaxs, outmaxs);
1636 VectorCopy(relativelightorigin, outmins);
1637 VectorCopy(relativelightorigin, outmaxs);
1638 if (model->brush.GetPVS)
1639 pvs = model->brush.GetPVS(model, relativelightorigin);
1642 R_UpdateAllTextureInfo(ent);
1643 // FIXME: use BSP recursion as lights are often small
1644 for (leafindex = 0, leaf = model->brush.data_leafs;leafindex < model->brush.num_leafs;leafindex++, leaf++)
1646 if (BoxesOverlap(lightmins, lightmaxs, leaf->mins, leaf->maxs) && (pvs == NULL || CHECKPVSBIT(pvs, leaf->clusterindex)))
1648 outmins[0] = min(outmins[0], leaf->mins[0]);
1649 outmins[1] = min(outmins[1], leaf->mins[1]);
1650 outmins[2] = min(outmins[2], leaf->mins[2]);
1651 outmaxs[0] = max(outmaxs[0], leaf->maxs[0]);
1652 outmaxs[1] = max(outmaxs[1], leaf->maxs[1]);
1653 outmaxs[2] = max(outmaxs[2], leaf->maxs[2]);
1656 if (!CHECKPVSBIT(outclusterpvs, leaf->clusterindex))
1658 SETPVSBIT(outclusterpvs, leaf->clusterindex);
1659 outclusterlist[outnumclusters++] = leaf->clusterindex;
1664 for (leafsurfaceindex = 0;leafsurfaceindex < leaf->numleafsurfaces;leafsurfaceindex++)
1666 surfaceindex = leaf->firstleafsurface[leafsurfaceindex];
1667 if (!CHECKPVSBIT(outsurfacepvs, surfaceindex))
1669 surface = model->brush.data_surfaces + surfaceindex;
1670 if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs))
1671 if ((surface->texture->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT)) == MATERIALFLAG_WALL)
1673 for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->num_triangles;triangleindex++, t++, e += 3)
1675 v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
1676 v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
1677 v[2] = model->brush.shadowmesh->vertex3f + e[2] * 3;
1678 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])))
1680 SETPVSBIT(outsurfacepvs, surfaceindex);
1681 outsurfacelist[outnumsurfaces++] = surfaceindex;
1692 // limit combined leaf box to light boundaries
1693 outmins[0] = max(outmins[0], lightmins[0]);
1694 outmins[1] = max(outmins[1], lightmins[1]);
1695 outmins[2] = max(outmins[2], lightmins[2]);
1696 outmaxs[0] = min(outmaxs[0], lightmaxs[0]);
1697 outmaxs[1] = min(outmaxs[1], lightmaxs[1]);
1698 outmaxs[2] = min(outmaxs[2], lightmaxs[2]);
1700 *outnumclusterspointer = outnumclusters;
1701 *outnumsurfacespointer = outnumsurfaces;
1704 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)
1706 model_t *model = ent->model;
1707 msurface_t *surface;
1708 int surfacelistindex;
1709 if (r_drawcollisionbrushes.integer < 2)
1711 R_Mesh_Matrix(&ent->matrix);
1712 R_Shadow_PrepareShadowMark(model->brush.shadowmesh->numtriangles);
1713 if (!r_shadow_compilingrtlight)
1714 R_UpdateAllTextureInfo(ent);
1715 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1717 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
1718 if ((surface->texture->currentmaterialflags & (MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT | MATERIALFLAG_WALL)) != MATERIALFLAG_WALL)
1720 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1722 R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
1724 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);
1728 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)
1730 model_t *model = ent->model;
1731 msurface_t *surface;
1733 int surfacelistindex;
1734 if (r_drawcollisionbrushes.integer < 2)
1736 R_Mesh_Matrix(&ent->matrix);
1737 if (!r_shadow_compilingrtlight)
1738 R_UpdateAllTextureInfo(ent);
1739 for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
1741 surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
1742 if (surface->texture->basematerialflags & MATERIALFLAG_NODRAW || !surface->num_triangles)
1744 if (r_shadow_compilingrtlight)
1746 // if compiling an rtlight, capture the mesh
1747 t = surface->texture;
1748 if ((t->basematerialflags & (MATERIALFLAG_WALL | MATERIALFLAG_TRANSPARENT)) == MATERIALFLAG_WALL)
1749 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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_normal3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex), surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
1751 else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surfacelist[surfacelistindex]])
1753 t = surface->texture->currentframe;
1754 // FIXME: transparent surfaces need to be lit later
1755 if ((t->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_TRANSPARENT)) == MATERIALFLAG_WALL)
1757 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1758 qglDisable(GL_CULL_FACE);
1759 R_Shadow_RenderLighting(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_normal3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex), relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, t->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
1760 if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
1761 qglEnable(GL_CULL_FACE);
1769 static void gl_surf_start(void)
1773 static void gl_surf_shutdown(void)
1777 static void gl_surf_newmap(void)
1782 void GL_Surf_Init(void)
1785 Cvar_RegisterVariable(&r_ambient);
1786 Cvar_RegisterVariable(&r_drawportals);
1787 Cvar_RegisterVariable(&r_testvis);
1788 Cvar_RegisterVariable(&r_detailtextures);
1789 Cvar_RegisterVariable(&r_surfaceworldnode);
1790 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonfactor);
1791 Cvar_RegisterVariable(&r_drawcollisionbrushes_polygonoffset);
1792 Cvar_RegisterVariable(&r_q3bsp_renderskydepth);
1793 Cvar_RegisterVariable(&gl_lightmaps);
1795 //R_RegisterModule("GL_Surf", gl_surf_start, gl_surf_shutdown, gl_surf_newmap);