Debian Codegraph @

code/renderergl1/tr_main.c

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22 // tr_main.c -- main control flow for each frame
23
24 #include "tr_local.h"
25
26 #include <string.h> // memcpy
27
28 trGlobals_t tr;
29
30 static float s_flipMatrix[16] = {
31 // convert from our coordinate system (looking down X)
32 // to OpenGL's coordinate system (looking down -Z)
33 0, 0, -1, 0,
34 -1, 0, 0, 0,
35 0, 1, 0, 0,
36 0, 0, 0, 1
37 };
38
39
40 refimport_t ri;
41
42 // entities that will have procedurally generated surfaces will just
43 // point at this for their sorting surface
44 surfaceType_t entitySurface = SF_ENTITY;
45
46 /*
47 =================
48 R_CullLocalBox
49
50 Returns CULL_IN, CULL_CLIP, or CULL_OUT
51 =================
52 */
53 int R_CullLocalBox (vec3_t bounds[2]) {
54 int i, j;
55 vec3_t transformed[8];
56 float dists[8];
57 vec3_t v;
58 cplane_t *frust;
59 int anyBack;
60 int front, back;
61
62 if ( r_nocull->integer ) {
63 return CULL_CLIP;
64 }
65
66 // transform into world space
67 for (i = 0 ; i < 8 ; i++) {
68 v[0] = bounds[i&1][0];
69 v[1] = bounds[(i>>1)&1][1];
70 v[2] = bounds[(i>>2)&1][2];
71
72 VectorCopy( tr.or.origin, transformed[i] );
73 VectorMA( transformed[i], v[0], tr.or.axis[0], transformed[i] );
74 VectorMA( transformed[i], v[1], tr.or.axis[1], transformed[i] );
75 VectorMA( transformed[i], v[2], tr.or.axis[2], transformed[i] );
76 }
77
78 // check against frustum planes
79 anyBack = 0;
80 for (i = 0 ; i < 4 ; i++) {
81 frust = &tr.viewParms.frustum[i];
82
83 front = back = 0;
84 for (j = 0 ; j < 8 ; j++) {
85 dists[j] = DotProduct(transformed[j], frust->normal);
86 if ( dists[j] > frust->dist ) {
87 front = 1;
88 if ( back ) {
89 break; // a point is in front
90 }
91 } else {
92 back = 1;
93 }
94 }
95 if ( !front ) {
96 // all points were behind one of the planes
97 return CULL_OUT;
98 }
99 anyBack |= back;
100 }
101
102 if ( !anyBack ) {
103 return CULL_IN; // completely inside frustum
104 }
105
106 return CULL_CLIP; // partially clipped
107 }
108
109 /*
110 ** R_CullLocalPointAndRadius
111 */
112 int R_CullLocalPointAndRadius( vec3_t pt, float radius )
113 {
114 vec3_t transformed;
115
116 R_LocalPointToWorld( pt, transformed );
117
118 return R_CullPointAndRadius( transformed, radius );
119 }
120
121 /*
122 ** R_CullPointAndRadius
123 */
124 int R_CullPointAndRadius( vec3_t pt, float radius )
125 {
126 int i;
127 float dist;
128 cplane_t *frust;
129 qboolean mightBeClipped = qfalse;
130
131 if ( r_nocull->integer ) {
132 return CULL_CLIP;
133 }
134
135 // check against frustum planes
136 for (i = 0 ; i < 4 ; i++)
137 {
138 frust = &tr.viewParms.frustum[i];
139
140 dist = DotProduct( pt, frust->normal) - frust->dist;
141 if ( dist < -radius )
142 {
143 return CULL_OUT;
144 }
145 else if ( dist <= radius )
146 {
147 mightBeClipped = qtrue;
148 }
149 }
150
151 if ( mightBeClipped )
152 {
153 return CULL_CLIP;
154 }
155
156 return CULL_IN; // completely inside frustum
157 }
158
159
160 /*
161 =================
162 R_LocalNormalToWorld
163
164 =================
165 */
166 void R_LocalNormalToWorld (vec3_t local, vec3_t world) {
167 world[0] = local[0] * tr.or.axis[0][0] + local[1] * tr.or.axis[1][0] + local[2] * tr.or.axis[2][0];
168 world[1] = local[0] * tr.or.axis[0][1] + local[1] * tr.or.axis[1][1] + local[2] * tr.or.axis[2][1];
169 world[2] = local[0] * tr.or.axis[0][2] + local[1] * tr.or.axis[1][2] + local[2] * tr.or.axis[2][2];
170 }
171
172 /*
173 =================
174 R_LocalPointToWorld
175
176 =================
177 */
178 void R_LocalPointToWorld (vec3_t local, vec3_t world) {
179 world[0] = local[0] * tr.or.axis[0][0] + local[1] * tr.or.axis[1][0] + local[2] * tr.or.axis[2][0] + tr.or.origin[0];
180 world[1] = local[0] * tr.or.axis[0][1] + local[1] * tr.or.axis[1][1] + local[2] * tr.or.axis[2][1] + tr.or.origin[1];
181 world[2] = local[0] * tr.or.axis[0][2] + local[1] * tr.or.axis[1][2] + local[2] * tr.or.axis[2][2] + tr.or.origin[2];
182 }
183
184 /*
185 =================
186 R_WorldToLocal
187
188 =================
189 */
190 void R_WorldToLocal (vec3_t world, vec3_t local) {
191 local[0] = DotProduct(world, tr.or.axis[0]);
192 local[1] = DotProduct(world, tr.or.axis[1]);
193 local[2] = DotProduct(world, tr.or.axis[2]);
194 }
195
196 /*
197 ==========================
198 R_TransformModelToClip
199
200 ==========================
201 */
202 void R_TransformModelToClip( const vec3_t src, const float *modelMatrix, const float *projectionMatrix,
203 vec4_t eye, vec4_t dst ) {
204 int i;
205
206 for ( i = 0 ; i < 4 ; i++ ) {
207 eye[i] =
208 src[0] * modelMatrix[ i + 0 * 4 ] +
209 src[1] * modelMatrix[ i + 1 * 4 ] +
210 src[2] * modelMatrix[ i + 2 * 4 ] +
211 1 * modelMatrix[ i + 3 * 4 ];
212 }
213
214 for ( i = 0 ; i < 4 ; i++ ) {
215 dst[i] =
216 eye[0] * projectionMatrix[ i + 0 * 4 ] +
217 eye[1] * projectionMatrix[ i + 1 * 4 ] +
218 eye[2] * projectionMatrix[ i + 2 * 4 ] +
219 eye[3] * projectionMatrix[ i + 3 * 4 ];
220 }
221 }
222
223 /*
224 ==========================
225 R_TransformClipToWindow
226
227 ==========================
228 */
229 void R_TransformClipToWindow( const vec4_t clip, const viewParms_t *view, vec4_t normalized, vec4_t window ) {
230 normalized[0] = clip[0] / clip[3];
231 normalized[1] = clip[1] / clip[3];
232 normalized[2] = ( clip[2] + clip[3] ) / ( 2 * clip[3] );
233
234 window[0] = 0.5f * ( 1.0f + normalized[0] ) * view->viewportWidth;
235 window[1] = 0.5f * ( 1.0f + normalized[1] ) * view->viewportHeight;
236 window[2] = normalized[2];
237
238 window[0] = (int) ( window[0] + 0.5 );
239 window[1] = (int) ( window[1] + 0.5 );
240 }
241
242
243 /*
244 ==========================
245 myGlMultMatrix
246
247 ==========================
248 */
249 void myGlMultMatrix( const float *a, const float *b, float *out ) {
250 int i, j;
251
252 for ( i = 0 ; i < 4 ; i++ ) {
253 for ( j = 0 ; j < 4 ; j++ ) {
254 out[ i * 4 + j ] =
255 a [ i * 4 + 0 ] * b [ 0 * 4 + j ]
256 + a [ i * 4 + 1 ] * b [ 1 * 4 + j ]
257 + a [ i * 4 + 2 ] * b [ 2 * 4 + j ]
258 + a [ i * 4 + 3 ] * b [ 3 * 4 + j ];
259 }
260 }
261 }
262
263 /*
264 =================
265 R_RotateForEntity
266
267 Generates an orientation for an entity and viewParms
268 Does NOT produce any GL calls
269 Called by both the front end and the back end
270 =================
271 */
272 void R_RotateForEntity( const trRefEntity_t *ent, const viewParms_t *viewParms,
273 orientationr_t *or ) {
274 float glMatrix[16];
275 vec3_t delta;
276 float axisLength;
277
278 if ( ent->e.reType != RT_MODEL ) {
279 *or = viewParms->world;
280 return;
281 }
282
283 VectorCopy( ent->e.origin, or->origin );
284
285 VectorCopy( ent->e.axis[0], or->axis[0] );
286 VectorCopy( ent->e.axis[1], or->axis[1] );
287 VectorCopy( ent->e.axis[2], or->axis[2] );
288
289 glMatrix[0] = or->axis[0][0];
290 glMatrix[4] = or->axis[1][0];
291 glMatrix[8] = or->axis[2][0];
292 glMatrix[12] = or->origin[0];
293
294 glMatrix[1] = or->axis[0][1];
295 glMatrix[5] = or->axis[1][1];
296 glMatrix[9] = or->axis[2][1];
297 glMatrix[13] = or->origin[1];
298
299 glMatrix[2] = or->axis[0][2];
300 glMatrix[6] = or->axis[1][2];
301 glMatrix[10] = or->axis[2][2];
302 glMatrix[14] = or->origin[2];
303
304 glMatrix[3] = 0;
305 glMatrix[7] = 0;
306 glMatrix[11] = 0;
307 glMatrix[15] = 1;
308
309 myGlMultMatrix( glMatrix, viewParms->world.modelMatrix, or->modelMatrix );
310
311 // calculate the viewer origin in the model's space
312 // needed for fog, specular, and environment mapping
313 VectorSubtract( viewParms->or.origin, or->origin, delta );
314
315 // compensate for scale in the axes if necessary
316 if ( ent->e.nonNormalizedAxes ) {
317 axisLength = VectorLength( ent->e.axis[0] );
318 if ( !axisLength ) {
319 axisLength = 0;
320 } else {
321 axisLength = 1.0f / axisLength;
322 }
323 } else {
324 axisLength = 1.0f;
325 }
326
327 or->viewOrigin[0] = DotProduct( delta, or->axis[0] ) * axisLength;
328 or->viewOrigin[1] = DotProduct( delta, or->axis[1] ) * axisLength;
329 or->viewOrigin[2] = DotProduct( delta, or->axis[2] ) * axisLength;
330 }
331
332 /*
333 =================
334 R_RotateForViewer
335
336 Sets up the modelview matrix for a given viewParm
337 =================
338 */
339 void R_RotateForViewer (void)
340 {
341 float viewerMatrix[16];
342 vec3_t origin;
343
344 Com_Memset (&tr.or, 0, sizeof(tr.or));
345 tr.or.axis[0][0] = 1;
346 tr.or.axis[1][1] = 1;
347 tr.or.axis[2][2] = 1;
348 VectorCopy (tr.viewParms.or.origin, tr.or.viewOrigin);
349
350 // transform by the camera placement
351 VectorCopy( tr.viewParms.or.origin, origin );
352
353 viewerMatrix[0] = tr.viewParms.or.axis[0][0];
354 viewerMatrix[4] = tr.viewParms.or.axis[0][1];
355 viewerMatrix[8] = tr.viewParms.or.axis[0][2];
356 viewerMatrix[12] = -origin[0] * viewerMatrix[0] + -origin[1] * viewerMatrix[4] + -origin[2] * viewerMatrix[8];
357
358 viewerMatrix[1] = tr.viewParms.or.axis[1][0];
359 viewerMatrix[5] = tr.viewParms.or.axis[1][1];
360 viewerMatrix[9] = tr.viewParms.or.axis[1][2];
361 viewerMatrix[13] = -origin[0] * viewerMatrix[1] + -origin[1] * viewerMatrix[5] + -origin[2] * viewerMatrix[9];
362
363 viewerMatrix[2] = tr.viewParms.or.axis[2][0];
364 viewerMatrix[6] = tr.viewParms.or.axis[2][1];
365 viewerMatrix[10] = tr.viewParms.or.axis[2][2];
366 viewerMatrix[14] = -origin[0] * viewerMatrix[2] + -origin[1] * viewerMatrix[6] + -origin[2] * viewerMatrix[10];
367
368 viewerMatrix[3] = 0;
369 viewerMatrix[7] = 0;
370 viewerMatrix[11] = 0;
371 viewerMatrix[15] = 1;
372
373 // convert from our coordinate system (looking down X)
374 // to OpenGL's coordinate system (looking down -Z)
375 myGlMultMatrix( viewerMatrix, s_flipMatrix, tr.or.modelMatrix );
376
377 tr.viewParms.world = tr.or;
378
379 }
380
381 /*
382 ** SetFarClip
383 */
384 static void R_SetFarClip( void )
385 {
386 float farthestCornerDistance = 0;
387 int i;
388
389 // if not rendering the world (icons, menus, etc)
390 // set a 2k far clip plane
391 if ( tr.refdef.rdflags & RDF_NOWORLDMODEL ) {
392 tr.viewParms.zFar = 2048;
393 return;
394 }
395
396 //
397 // set far clipping planes dynamically
398 //
399 farthestCornerDistance = 0;
400 for ( i = 0; i < 8; i++ )
401 {
402 vec3_t v;
403 vec3_t vecTo;
404 float distance;
405
406 if ( i & 1 )
407 {
408 v[0] = tr.viewParms.visBounds[0][0];
409 }
410 else
411 {
412 v[0] = tr.viewParms.visBounds[1][0];
413 }
414
415 if ( i & 2 )
416 {
417 v[1] = tr.viewParms.visBounds[0][1];
418 }
419 else
420 {
421 v[1] = tr.viewParms.visBounds[1][1];
422 }
423
424 if ( i & 4 )
425 {
426 v[2] = tr.viewParms.visBounds[0][2];
427 }
428 else
429 {
430 v[2] = tr.viewParms.visBounds[1][2];
431 }
432
433 VectorSubtract( v, tr.viewParms.or.origin, vecTo );
434
435 distance = vecTo[0] * vecTo[0] + vecTo[1] * vecTo[1] + vecTo[2] * vecTo[2];
436
437 if ( distance > farthestCornerDistance )
438 {
439 farthestCornerDistance = distance;
440 }
441 }
442 tr.viewParms.zFar = sqrt( farthestCornerDistance );
443 }
444
445 /*
446 =================
447 R_SetupFrustum
448
449 Set up the culling frustum planes for the current view using the results we got from computing the first two rows of
450 the projection matrix.
451 =================
452 */
453 void R_SetupFrustum (viewParms_t *dest, float xmin, float xmax, float ymax, float zProj, float stereoSep)
454 {
455 vec3_t ofsorigin;
456 float oppleg, adjleg, length;
457 int i;
458
459 if(stereoSep == 0 && xmin == -xmax)
460 {
461 // symmetric case can be simplified
462 VectorCopy(dest->or.origin, ofsorigin);
463
464 length = sqrt(xmax * xmax + zProj * zProj);
465 oppleg = xmax / length;
466 adjleg = zProj / length;
467
468 VectorScale(dest->or.axis[0], oppleg, dest->frustum[0].normal);
469 VectorMA(dest->frustum[0].normal, adjleg, dest->or.axis[1], dest->frustum[0].normal);
470
471 VectorScale(dest->or.axis[0], oppleg, dest->frustum[1].normal);
472 VectorMA(dest->frustum[1].normal, -adjleg, dest->or.axis[1], dest->frustum[1].normal);
473 }
474 else
475 {
476 // In stereo rendering, due to the modification of the projection matrix, dest->or.origin is not the
477 // actual origin that we're rendering so offset the tip of the view pyramid.
478 VectorMA(dest->or.origin, stereoSep, dest->or.axis[1], ofsorigin);
479
480 oppleg = xmax + stereoSep;
481 length = sqrt(oppleg * oppleg + zProj * zProj);
482 VectorScale(dest->or.axis[0], oppleg / length, dest->frustum[0].normal);
483 VectorMA(dest->frustum[0].normal, zProj / length, dest->or.axis[1], dest->frustum[0].normal);
484
485 oppleg = xmin + stereoSep;
486 length = sqrt(oppleg * oppleg + zProj * zProj);
487 VectorScale(dest->or.axis[0], -oppleg / length, dest->frustum[1].normal);
488 VectorMA(dest->frustum[1].normal, -zProj / length, dest->or.axis[1], dest->frustum[1].normal);
489 }
490
491 length = sqrt(ymax * ymax + zProj * zProj);
492 oppleg = ymax / length;
493 adjleg = zProj / length;
494
495 VectorScale(dest->or.axis[0], oppleg, dest->frustum[2].normal);
496 VectorMA(dest->frustum[2].normal, adjleg, dest->or.axis[2], dest->frustum[2].normal);
497
498 VectorScale(dest->or.axis[0], oppleg, dest->frustum[3].normal);
499 VectorMA(dest->frustum[3].normal, -adjleg, dest->or.axis[2], dest->frustum[3].normal);
500
501 for (i=0 ; i<4 ; i++) {
502 dest->frustum[i].type = PLANE_NON_AXIAL;
503 dest->frustum[i].dist = DotProduct (ofsorigin, dest->frustum[i].normal);
504 SetPlaneSignbits( &dest->frustum[i] );
505 }
506 }
507
508 /*
509 ===============
510 R_SetupProjection
511 ===============
512 */
513 void R_SetupProjection(viewParms_t *dest, float zProj, qboolean computeFrustum)
514 {
515 float xmin, xmax, ymin, ymax;
516 float width, height, stereoSep = r_stereoSeparation->value;
517
518 /*
519 * offset the view origin of the viewer for stereo rendering
520 * by setting the projection matrix appropriately.
521 */
522
523 if(stereoSep != 0)
524 {
525 if(dest->stereoFrame == STEREO_LEFT)
526 stereoSep = zProj / stereoSep;
527 else if(dest->stereoFrame == STEREO_RIGHT)
528 stereoSep = zProj / -stereoSep;
529 else
530 stereoSep = 0;
531 }
532
533 ymax = zProj * tan(dest->fovY * M_PI / 360.0f);
534 ymin = -ymax;
535
536 xmax = zProj * tan(dest->fovX * M_PI / 360.0f);
537 xmin = -xmax;
538
539 width = xmax - xmin;
540 height = ymax - ymin;
541
542 dest->projectionMatrix[0] = 2 * zProj / width;
543 dest->projectionMatrix[4] = 0;
544 dest->projectionMatrix[8] = (xmax + xmin + 2 * stereoSep) / width;
545 dest->projectionMatrix[12] = 2 * zProj * stereoSep / width;
546
547 dest->projectionMatrix[1] = 0;
548 dest->projectionMatrix[5] = 2 * zProj / height;
549 dest->projectionMatrix[9] = ( ymax + ymin ) / height; // normally 0
550 dest->projectionMatrix[13] = 0;
551
552 dest->projectionMatrix[3] = 0;
553 dest->projectionMatrix[7] = 0;
554 dest->projectionMatrix[11] = -1;
555 dest->projectionMatrix[15] = 0;
556
557 // Now that we have all the data for the projection matrix we can also setup the view frustum.
558 if(computeFrustum)
559 R_SetupFrustum(dest, xmin, xmax, ymax, zProj, stereoSep);
560 }
561
562 /*
563 ===============
564 R_SetupProjectionZ
565
566 Sets the z-component transformation part in the projection matrix
567 ===============
568 */
569 void R_SetupProjectionZ(viewParms_t *dest)
570 {
571 float zNear, zFar, depth;
572
573 zNear = r_znear->value;
574 zFar = dest->zFar;
575 depth = zFar - zNear;
576
577 dest->projectionMatrix[2] = 0;
578 dest->projectionMatrix[6] = 0;
579 dest->projectionMatrix[10] = -( zFar + zNear ) / depth;
580 dest->projectionMatrix[14] = -2 * zFar * zNear / depth;
581 }
582
583 /*
584 =================
585 R_MirrorPoint
586 =================
587 */
588 void R_MirrorPoint (vec3_t in, orientation_t *surface, orientation_t *camera, vec3_t out) {
589 int i;
590 vec3_t local;
591 vec3_t transformed;
592 float d;
593
594 VectorSubtract( in, surface->origin, local );
595
596 VectorClear( transformed );
597 for ( i = 0 ; i < 3 ; i++ ) {
598 d = DotProduct(local, surface->axis[i]);
599 VectorMA( transformed, d, camera->axis[i], transformed );
600 }
601
602 VectorAdd( transformed, camera->origin, out );
603 }
604
605 void R_MirrorVector (vec3_t in, orientation_t *surface, orientation_t *camera, vec3_t out) {
606 int i;
607 float d;
608
609 VectorClear( out );
610 for ( i = 0 ; i < 3 ; i++ ) {
611 d = DotProduct(in, surface->axis[i]);
612 VectorMA( out, d, camera->axis[i], out );
613 }
614 }
615
616
617 /*
618 =============
619 R_PlaneForSurface
620 =============
621 */
622 void R_PlaneForSurface (surfaceType_t *surfType, cplane_t *plane) {
623 srfTriangles_t *tri;
624 srfPoly_t *poly;
625 drawVert_t *v1, *v2, *v3;
626 vec4_t plane4;
627
628 if (!surfType) {
629 Com_Memset (plane, 0, sizeof(*plane));
630 plane->normal[0] = 1;
631 return;
632 }
633 switch (*surfType) {
634 case SF_FACE:
635 *plane = ((srfSurfaceFace_t *)surfType)->plane;
636 return;
637 case SF_TRIANGLES:
638 tri = (srfTriangles_t *)surfType;
639 v1 = tri->verts + tri->indexes[0];
640 v2 = tri->verts + tri->indexes[1];
641 v3 = tri->verts + tri->indexes[2];
642 PlaneFromPoints( plane4, v1->xyz, v2->xyz, v3->xyz );
643 VectorCopy( plane4, plane->normal );
644 plane->dist = plane4[3];
645 return;
646 case SF_POLY:
647 poly = (srfPoly_t *)surfType;
648 PlaneFromPoints( plane4, poly->verts[0].xyz, poly->verts[1].xyz, poly->verts[2].xyz );
649 VectorCopy( plane4, plane->normal );
650 plane->dist = plane4[3];
651 return;
652 default:
653 Com_Memset (plane, 0, sizeof(*plane));
654 plane->normal[0] = 1;
655 return;
656 }
657 }
658
659 /*
660 =================
661 R_GetPortalOrientation
662
663 entityNum is the entity that the portal surface is a part of, which may
664 be moving and rotating.
665
666 Returns qtrue if it should be mirrored
667 =================
668 */
669 qboolean R_GetPortalOrientations( drawSurf_t *drawSurf, int entityNum,
670 orientation_t *surface, orientation_t *camera,
671 vec3_t pvsOrigin, qboolean *mirror ) {
672 int i;
673 cplane_t originalPlane, plane;
674 trRefEntity_t *e;
675 float d;
676 vec3_t transformed;
677
678 // create plane axis for the portal we are seeing
679 R_PlaneForSurface( drawSurf->surface, &originalPlane );
680
681 // rotate the plane if necessary
682 if ( entityNum != REFENTITYNUM_WORLD ) {
683 tr.currentEntityNum = entityNum;
684 tr.currentEntity = &tr.refdef.entities[entityNum];
685
686 // get the orientation of the entity
687 R_RotateForEntity( tr.currentEntity, &tr.viewParms, &tr.or );
688
689 // rotate the plane, but keep the non-rotated version for matching
690 // against the portalSurface entities
691 R_LocalNormalToWorld( originalPlane.normal, plane.normal );
692 plane.dist = originalPlane.dist + DotProduct( plane.normal, tr.or.origin );
693
694 // translate the original plane
695 originalPlane.dist = originalPlane.dist + DotProduct( originalPlane.normal, tr.or.origin );
696 } else {
697 plane = originalPlane;
698 }
699
700 VectorCopy( plane.normal, surface->axis[0] );
701 PerpendicularVector( surface->axis[1], surface->axis[0] );
702 CrossProduct( surface->axis[0], surface->axis[1], surface->axis[2] );
703
704 // locate the portal entity closest to this plane.
705 // origin will be the origin of the portal, origin2 will be
706 // the origin of the camera
707 for ( i = 0 ; i < tr.refdef.num_entities ; i++ ) {
708 e = &tr.refdef.entities[i];
709 if ( e->e.reType != RT_PORTALSURFACE ) {
710 continue;
711 }
712
713 d = DotProduct( e->e.origin, originalPlane.normal ) - originalPlane.dist;
714 if ( d > 64 || d < -64) {
715 continue;
716 }
717
718 // get the pvsOrigin from the entity
719 VectorCopy( e->e.oldorigin, pvsOrigin );
720
721 // if the entity is just a mirror, don't use as a camera point
722 if ( e->e.oldorigin[0] == e->e.origin[0] &&
723 e->e.oldorigin[1] == e->e.origin[1] &&
724 e->e.oldorigin[2] == e->e.origin[2] ) {
725 VectorScale( plane.normal, plane.dist, surface->origin );
726 VectorCopy( surface->origin, camera->origin );
727 VectorSubtract( vec3_origin, surface->axis[0], camera->axis[0] );
728 VectorCopy( surface->axis[1], camera->axis[1] );
729 VectorCopy( surface->axis[2], camera->axis[2] );
730
731 *mirror = qtrue;
732 return qtrue;
733 }
734
735 // project the origin onto the surface plane to get
736 // an origin point we can rotate around
737 d = DotProduct( e->e.origin, plane.normal ) - plane.dist;
738 VectorMA( e->e.origin, -d, surface->axis[0], surface->origin );
739
740 // now get the camera origin and orientation
741 VectorCopy( e->e.oldorigin, camera->origin );
742 AxisCopy( e->e.axis, camera->axis );
743 VectorSubtract( vec3_origin, camera->axis[0], camera->axis[0] );
744 VectorSubtract( vec3_origin, camera->axis[1], camera->axis[1] );
745
746 // optionally rotate
747 if ( e->e.oldframe ) {
748 // if a speed is specified
749 if ( e->e.frame ) {
750 // continuous rotate
751 d = (tr.refdef.time/1000.0f) * e->e.frame;
752 VectorCopy( camera->axis[1], transformed );
753 RotatePointAroundVector( camera->axis[1], camera->axis[0], transformed, d );
754 CrossProduct( camera->axis[0], camera->axis[1], camera->axis[2] );
755 } else {
756 // bobbing rotate, with skinNum being the rotation offset
757 d = sin( tr.refdef.time * 0.003f );
758 d = e->e.skinNum + d * 4;
759 VectorCopy( camera->axis[1], transformed );
760 RotatePointAroundVector( camera->axis[1], camera->axis[0], transformed, d );
761 CrossProduct( camera->axis[0], camera->axis[1], camera->axis[2] );
762 }
763 }
764 else if ( e->e.skinNum ) {
765 d = e->e.skinNum;
766 VectorCopy( camera->axis[1], transformed );
767 RotatePointAroundVector( camera->axis[1], camera->axis[0], transformed, d );
768 CrossProduct( camera->axis[0], camera->axis[1], camera->axis[2] );
769 }
770 *mirror = qfalse;
771 return qtrue;
772 }
773
774 // if we didn't locate a portal entity, don't render anything.
775 // We don't want to just treat it as a mirror, because without a
776 // portal entity the server won't have communicated a proper entity set
777 // in the snapshot
778
779 // unfortunately, with local movement prediction it is easily possible
780 // to see a surface before the server has communicated the matching
781 // portal surface entity, so we don't want to print anything here...
782
783 //ri.Printf( PRINT_ALL, "Portal surface without a portal entity\n" );
784
785 return qfalse;
786 }
787
788 static qboolean IsMirror( const drawSurf_t *drawSurf, int entityNum )
789 {
790 int i;
791 cplane_t originalPlane, plane;
792 trRefEntity_t *e;
793 float d;
794
795 // create plane axis for the portal we are seeing
796 R_PlaneForSurface( drawSurf->surface, &originalPlane );
797
798 // rotate the plane if necessary
799 if ( entityNum != REFENTITYNUM_WORLD )
800 {
801 tr.currentEntityNum = entityNum;
802 tr.currentEntity = &tr.refdef.entities[entityNum];
803
804 // get the orientation of the entity
805 R_RotateForEntity( tr.currentEntity, &tr.viewParms, &tr.or );
806
807 // rotate the plane, but keep the non-rotated version for matching
808 // against the portalSurface entities
809 R_LocalNormalToWorld( originalPlane.normal, plane.normal );
810 plane.dist = originalPlane.dist + DotProduct( plane.normal, tr.or.origin );
811
812 // translate the original plane
813 originalPlane.dist = originalPlane.dist + DotProduct( originalPlane.normal, tr.or.origin );
814 }
815
816 // locate the portal entity closest to this plane.
817 // origin will be the origin of the portal, origin2 will be
818 // the origin of the camera
819 for ( i = 0 ; i < tr.refdef.num_entities ; i++ )
820 {
821 e = &tr.refdef.entities[i];
822 if ( e->e.reType != RT_PORTALSURFACE ) {
823 continue;
824 }
825
826 d = DotProduct( e->e.origin, originalPlane.normal ) - originalPlane.dist;
827 if ( d > 64 || d < -64) {
828 continue;
829 }
830
831 // if the entity is just a mirror, don't use as a camera point
832 if ( e->e.oldorigin[0] == e->e.origin[0] &&
833 e->e.oldorigin[1] == e->e.origin[1] &&
834 e->e.oldorigin[2] == e->e.origin[2] )
835 {
836 return qtrue;
837 }
838
839 return qfalse;
840 }
841 return qfalse;
842 }
843
844 /*
845 ** SurfIsOffscreen
846 **
847 ** Determines if a surface is completely offscreen.
848 */
849 static qboolean SurfIsOffscreen( const drawSurf_t *drawSurf, vec4_t clipDest[128] ) {
850 float shortest = 100000000;
851 int entityNum;
852 int numTriangles;
853 shader_t *shader;
854 int fogNum;
855 int dlighted;
856 vec4_t clip, eye;
857 int i;
858 unsigned int pointAnd = (unsigned int)~0;
859
860 R_RotateForViewer();
861
862 R_DecomposeSort( drawSurf->sort, &entityNum, &shader, &fogNum, &dlighted );
863 RB_BeginSurface( shader, fogNum );
864 rb_surfaceTable[ *drawSurf->surface ]( drawSurf->surface );
865
866 assert( tess.numVertexes < 128 );
867
868 for ( i = 0; i < tess.numVertexes; i++ )
869 {
870 int j;
871 unsigned int pointFlags = 0;
872
873 R_TransformModelToClip( tess.xyz[i], tr.or.modelMatrix, tr.viewParms.projectionMatrix, eye, clip );
874
875 for ( j = 0; j < 3; j++ )
876 {
877 if ( clip[j] >= clip[3] )
878 {
879 pointFlags |= (1 << (j*2));
880 }
881 else if ( clip[j] <= -clip[3] )
882 {
883 pointFlags |= ( 1 << (j*2+1));
884 }
885 }
886 pointAnd &= pointFlags;
887 }
888
889 // trivially reject
890 if ( pointAnd )
891 {
892 return qtrue;
893 }
894
895 // determine if this surface is backfaced and also determine the distance
896 // to the nearest vertex so we can cull based on portal range. Culling
897 // based on vertex distance isn't 100% correct (we should be checking for
898 // range to the surface), but it's good enough for the types of portals
899 // we have in the game right now.
900 numTriangles = tess.numIndexes / 3;
901
902 for ( i = 0; i < tess.numIndexes; i += 3 )
903 {
904 vec3_t normal;
905 float len;
906
907 VectorSubtract( tess.xyz[tess.indexes[i]], tr.viewParms.or.origin, normal );
908
909 len = VectorLengthSquared( normal ); // lose the sqrt
910 if ( len < shortest )
911 {
912 shortest = len;
913 }
914
915 if ( DotProduct( normal, tess.normal[tess.indexes[i]] ) >= 0 )
916 {
917 numTriangles--;
918 }
919 }
920 if ( !numTriangles )
921 {
922 return qtrue;
923 }
924
925 // mirrors can early out at this point, since we don't do a fade over distance
926 // with them (although we could)
927 if ( IsMirror( drawSurf, entityNum ) )
928 {
929 return qfalse;
930 }
931
932 if ( shortest > (tess.shader->portalRange*tess.shader->portalRange) )
933 {
934 return qtrue;
935 }
936
937 return qfalse;
938 }
939
940 /*
941 ========================
942 R_MirrorViewBySurface
943
944 Returns qtrue if another view has been rendered
945 ========================
946 */
947 qboolean R_MirrorViewBySurface (drawSurf_t *drawSurf, int entityNum) {
948 vec4_t clipDest[128];
949 viewParms_t newParms;
950 viewParms_t oldParms;
951 orientation_t surface, camera;
952
953 // don't recursively mirror
954 if (tr.viewParms.isPortal) {
955 ri.Printf( PRINT_DEVELOPER, "WARNING: recursive mirror/portal found\n" );
956 return qfalse;
957 }
958
959 if ( r_noportals->integer || (r_fastsky->integer == 1) ) {
960 return qfalse;
961 }
962
963 // trivially reject portal/mirror
964 if ( SurfIsOffscreen( drawSurf, clipDest ) ) {
965 return qfalse;
966 }
967
968 // save old viewParms so we can return to it after the mirror view
969 oldParms = tr.viewParms;
970
971 newParms = tr.viewParms;
972 newParms.isPortal = qtrue;
973 if ( !R_GetPortalOrientations( drawSurf, entityNum, &surface, &camera,
974 newParms.pvsOrigin, &newParms.isMirror ) ) {
975 return qfalse; // bad portal, no portalentity
976 }
977
978 R_MirrorPoint (oldParms.or.origin, &surface, &camera, newParms.or.origin );
979
980 VectorSubtract( vec3_origin, camera.axis[0], newParms.portalPlane.normal );
981 newParms.portalPlane.dist = DotProduct( camera.origin, newParms.portalPlane.normal );
982
983 R_MirrorVector (oldParms.or.axis[0], &surface, &camera, newParms.or.axis[0]);
984 R_MirrorVector (oldParms.or.axis[1], &surface, &camera, newParms.or.axis[1]);
985 R_MirrorVector (oldParms.or.axis[2], &surface, &camera, newParms.or.axis[2]);
986
987 // OPTIMIZE: restrict the viewport on the mirrored view
988
989 // render the mirror view
990 R_RenderView (&newParms);
991
992 tr.viewParms = oldParms;
993
994 return qtrue;
995 }
996
997 /*
998 =================
999 R_SpriteFogNum
1000
1001 See if a sprite is inside a fog volume
1002 =================
1003 */
1004 int R_SpriteFogNum( trRefEntity_t *ent ) {
1005 int i, j;
1006 fog_t *fog;
1007
1008 if ( tr.refdef.rdflags & RDF_NOWORLDMODEL ) {
1009 return 0;
1010 }
1011
1012 if ( ent->e.renderfx & RF_CROSSHAIR ) {
1013 return 0;
1014 }
1015
1016 for ( i = 1 ; i < tr.world->numfogs ; i++ ) {
1017 fog = &tr.world->fogs[i];
1018 for ( j = 0 ; j < 3 ; j++ ) {
1019 if ( ent->e.origin[j] - ent->e.radius >= fog->bounds[1][j] ) {
1020 break;
1021 }
1022 if ( ent->e.origin[j] + ent->e.radius <= fog->bounds[0][j] ) {
1023 break;
1024 }
1025 }
1026 if ( j == 3 ) {
1027 return i;
1028 }
1029 }
1030
1031 return 0;
1032 }
1033
1034 /*
1035 ==========================================================================================
1036
1037 DRAWSURF SORTING
1038
1039 ==========================================================================================
1040 */
1041
1042 /*
1043 ===============
1044 R_Radix
1045 ===============
1046 */
1047 static ID_INLINE void R_Radix( int offset, int size, drawSurf_t *source, drawSurf_t *dest )
1048 {
1049 int count[ 256 ] = { 0 };
1050 int index[ 256 ];
1051 int i;
1052 unsigned char *sortKey = NULL;
1053 unsigned char *end = NULL;
1054
1055 sortKey = ( (unsigned char *)&source[ 0 ].sort ) + offset;
1056 end = sortKey + ( size * sizeof( drawSurf_t ) );
1057 for( ; sortKey < end; sortKey += sizeof( drawSurf_t ) )
1058 ++count[ *sortKey ];
1059
1060 index[ 0 ] = 0;
1061
1062 for( i = 1; i < 256; ++i )
1063 index[ i ] = index[ i - 1 ] + count[ i - 1 ];
1064
1065 sortKey = ( (unsigned char *)&source[ 0 ].sort ) + offset;
1066 for( i = 0; i < size; ++i, sortKey += sizeof( drawSurf_t ) )
1067 dest[ index[ *sortKey ]++ ] = source[ i ];
1068 }
1069
1070 /*
1071 ===============
1072 R_RadixSort
1073
1074 Radix sort with 4 byte size buckets
1075 ===============
1076 */
1077 static void R_RadixSort( drawSurf_t *source, int size )
1078 {
1079 static drawSurf_t scratch[ MAX_DRAWSURFS ];
1080 #ifdef Q3_LITTLE_ENDIAN
1081 R_Radix( 0, size, source, scratch );
1082 R_Radix( 1, size, scratch, source );
1083 R_Radix( 2, size, source, scratch );
1084 R_Radix( 3, size, scratch, source );
1085 #else
1086 R_Radix( 3, size, source, scratch );
1087 R_Radix( 2, size, scratch, source );
1088 R_Radix( 1, size, source, scratch );
1089 R_Radix( 0, size, scratch, source );
1090 #endif //Q3_LITTLE_ENDIAN
1091 }
1092
1093 //==========================================================================================
1094
1095 /*
1096 =================
1097 R_AddDrawSurf
1098 =================
1099 */
1100 void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader,
1101 int fogIndex, int dlightMap ) {
1102 int index;
1103
1104 // instead of checking for overflow, we just mask the index
1105 // so it wraps around
1106 index = tr.refdef.numDrawSurfs & DRAWSURF_MASK;
1107 // the sort data is packed into a single 32 bit value so it can be
1108 // compared quickly during the qsorting process
1109 tr.refdef.drawSurfs[index].sort = (shader->sortedIndex << QSORT_SHADERNUM_SHIFT)
1110 | tr.shiftedEntityNum | ( fogIndex << QSORT_FOGNUM_SHIFT ) | (int)dlightMap;
1111 tr.refdef.drawSurfs[index].surface = surface;
1112 tr.refdef.numDrawSurfs++;
1113 }
1114
1115 /*
1116 =================
1117 R_DecomposeSort
1118 =================
1119 */
1120 void R_DecomposeSort( unsigned sort, int *entityNum, shader_t **shader,
1121 int *fogNum, int *dlightMap ) {
1122 *fogNum = ( sort >> QSORT_FOGNUM_SHIFT ) & 31;
1123 *shader = tr.sortedShaders[ ( sort >> QSORT_SHADERNUM_SHIFT ) & (MAX_SHADERS-1) ];
1124 *entityNum = ( sort >> QSORT_REFENTITYNUM_SHIFT ) & REFENTITYNUM_MASK;
1125 *dlightMap = sort & 3;
1126 }
1127
1128 /*
1129 =================
1130 R_SortDrawSurfs
1131 =================
1132 */
1133 void R_SortDrawSurfs( drawSurf_t *drawSurfs, int numDrawSurfs ) {
1134 shader_t *shader;
1135 int fogNum;
1136 int entityNum;
1137 int dlighted;
1138 int i;
1139
1140 // it is possible for some views to not have any surfaces
1141 if ( numDrawSurfs < 1 ) {
1142 // we still need to add it for hyperspace cases
1143 R_AddDrawSurfCmd( drawSurfs, numDrawSurfs );
1144 return;
1145 }
1146
1147 // sort the drawsurfs by sort type, then orientation, then shader
1148 R_RadixSort( drawSurfs, numDrawSurfs );
1149
1150 // check for any pass through drawing, which
1151 // may cause another view to be rendered first
1152 for ( i = 0 ; i < numDrawSurfs ; i++ ) {
1153 R_DecomposeSort( (drawSurfs+i)->sort, &entityNum, &shader, &fogNum, &dlighted );
1154
1155 if ( shader->sort > SS_PORTAL ) {
1156 break;
1157 }
1158
1159 // no shader should ever have this sort type
1160 if ( shader->sort == SS_BAD ) {
1161 ri.Error (ERR_DROP, "Shader '%s'with sort == SS_BAD", shader->name );
1162 }
1163
1164 // if the mirror was completely clipped away, we may need to check another surface
1165 if ( R_MirrorViewBySurface( (drawSurfs+i), entityNum) ) {
1166 // this is a debug option to see exactly what is being mirrored
1167 if ( r_portalOnly->integer ) {
1168 return;
1169 }
1170 break; // only one mirror view at a time
1171 }
1172 }
1173
1174 R_AddDrawSurfCmd( drawSurfs, numDrawSurfs );
1175 }
1176
1177 /*
1178 =============
1179 R_AddEntitySurfaces
1180 =============
1181 */
1182 void R_AddEntitySurfaces (void) {
1183 trRefEntity_t *ent;
1184 shader_t *shader;
1185
1186 if ( !r_drawentities->integer ) {
1187 return;
1188 }
1189
1190 for ( tr.currentEntityNum = 0;
1191 tr.currentEntityNum < tr.refdef.num_entities;
1192 tr.currentEntityNum++ ) {
1193 ent = tr.currentEntity = &tr.refdef.entities[tr.currentEntityNum];
1194
1195 ent->needDlights = qfalse;
1196
1197 // preshift the value we are going to OR into the drawsurf sort
1198 tr.shiftedEntityNum = tr.currentEntityNum << QSORT_REFENTITYNUM_SHIFT;
1199
1200 //
1201 // the weapon model must be handled special --
1202 // we don't want the hacked weapon position showing in
1203 // mirrors, because the true body position will already be drawn
1204 //
1205 if ( (ent->e.renderfx & RF_FIRST_PERSON) && tr.viewParms.isPortal) {
1206 continue;
1207 }
1208
1209 // simple generated models, like sprites and beams, are not culled
1210 switch ( ent->e.reType ) {
1211 case RT_PORTALSURFACE:
1212 break; // don't draw anything
1213 case RT_SPRITE:
1214 case RT_BEAM:
1215 case RT_LIGHTNING:
1216 case RT_RAIL_CORE:
1217 case RT_RAIL_RINGS:
1218 // self blood sprites, talk balloons, etc should not be drawn in the primary
1219 // view. We can't just do this check for all entities, because md3
1220 // entities may still want to cast shadows from them
1221 if ( (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal) {
1222 continue;
1223 }
1224 shader = R_GetShaderByHandle( ent->e.customShader );
1225 R_AddDrawSurf( &entitySurface, shader, R_SpriteFogNum( ent ), 0 );
1226 break;
1227
1228 case RT_MODEL:
1229 // we must set up parts of tr.or for model culling
1230 R_RotateForEntity( ent, &tr.viewParms, &tr.or );
1231
1232 tr.currentModel = R_GetModelByHandle( ent->e.hModel );
1233 if (!tr.currentModel) {
1234 R_AddDrawSurf( &entitySurface, tr.defaultShader, 0, 0 );
1235 } else {
1236 switch ( tr.currentModel->type ) {
1237 case MOD_MESH:
1238 R_AddMD3Surfaces( ent );
1239 break;
1240 case MOD_MDR:
1241 R_MDRAddAnimSurfaces( ent );
1242 break;
1243 case MOD_IQM:
1244 R_AddIQMSurfaces( ent );
1245 break;
1246 case MOD_BRUSH:
1247 R_AddBrushModelSurfaces( ent );
1248 break;
1249 case MOD_BAD: // null model axis
1250 if ( (ent->e.renderfx & RF_THIRD_PERSON) && !tr.viewParms.isPortal) {
1251 break;
1252 }
1253 R_AddDrawSurf( &entitySurface, tr.defaultShader, 0, 0 );
1254 break;
1255 default:
1256 ri.Error( ERR_DROP, "R_AddEntitySurfaces: Bad modeltype" );
1257 break;
1258 }
1259 }
1260 break;
1261 default:
1262 ri.Error( ERR_DROP, "R_AddEntitySurfaces: Bad reType" );
1263 }
1264 }
1265
1266 }
1267
1268
1269 /*
1270 ====================
1271 R_GenerateDrawSurfs
1272 ====================
1273 */
1274 void R_GenerateDrawSurfs( void ) {
1275 R_AddWorldSurfaces ();
1276
1277 R_AddPolygonSurfaces();
1278
1279 // set the projection matrix with the minimum zfar
1280 // now that we have the world bounded
1281 // this needs to be done before entities are
1282 // added, because they use the projection
1283 // matrix for lod calculation
1284
1285 // dynamically compute far clip plane distance
1286 R_SetFarClip();
1287
1288 // we know the size of the clipping volume. Now set the rest of the projection matrix.
1289 R_SetupProjectionZ (&tr.viewParms);
1290
1291 R_AddEntitySurfaces ();
1292 }
1293
1294 /*
1295 ================
1296 R_DebugPolygon
1297 ================
1298 */
1299 void R_DebugPolygon( int color, int numPoints, float *points ) {
1300 int i;
1301
1302 GL_State( GLS_DEPTHMASK_TRUE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
1303
1304 // draw solid shade
1305
1306 qglColor3f( color&1, (color>>1)&1, (color>>2)&1 );
1307 qglBegin( GL_POLYGON );
1308 for ( i = 0 ; i < numPoints ; i++ ) {
1309 qglVertex3fv( points + i * 3 );
1310 }
1311 qglEnd();
1312
1313 // draw wireframe outline
1314 GL_State( GLS_POLYMODE_LINE | GLS_DEPTHMASK_TRUE | GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE );
1315 qglDepthRange( 0, 0 );
1316 qglColor3f( 1, 1, 1 );
1317 qglBegin( GL_POLYGON );
1318 for ( i = 0 ; i < numPoints ; i++ ) {
1319 qglVertex3fv( points + i * 3 );
1320 }
1321 qglEnd();
1322 qglDepthRange( 0, 1 );
1323 }
1324
1325 /*
1326 ====================
1327 R_DebugGraphics
1328
1329 Visualization aid for movement clipping debugging
1330 ====================
1331 */
1332 void R_DebugGraphics( void ) {
1333 if ( tr.refdef.rdflags & RDF_NOWORLDMODEL ) {
1334 return;
1335 }
1336 if ( !r_debugSurface->integer ) {
1337 return;
1338 }
1339
1340 R_IssuePendingRenderCommands();
1341
1342 GL_Bind( tr.whiteImage);
1343 GL_Cull( CT_FRONT_SIDED );
1344 ri.CM_DrawDebugSurface( R_DebugPolygon );
1345 }
1346
1347
1348 /*
1349 ================
1350 R_RenderView
1351
1352 A view may be either the actual camera view,
1353 or a mirror / remote location
1354 ================
1355 */
1356 void R_RenderView (viewParms_t *parms) {
1357 int firstDrawSurf;
1358 int numDrawSurfs;
1359
1360 if ( parms->viewportWidth <= 0 || parms->viewportHeight <= 0 ) {
1361 return;
1362 }
1363
1364 tr.viewCount++;
1365
1366 tr.viewParms = *parms;
1367 tr.viewParms.frameSceneNum = tr.frameSceneNum;
1368 tr.viewParms.frameCount = tr.frameCount;
1369
1370 firstDrawSurf = tr.refdef.numDrawSurfs;
1371
1372 tr.viewCount++;
1373
1374 // set viewParms.world
1375 R_RotateForViewer ();
1376
1377 R_SetupProjection(&tr.viewParms, r_zproj->value, qtrue);
1378
1379 R_GenerateDrawSurfs();
1380
1381 // if we overflowed MAX_DRAWSURFS, the drawsurfs
1382 // wrapped around in the buffer and we will be missing
1383 // the first surfaces, not the last ones
1384 numDrawSurfs = tr.refdef.numDrawSurfs;
1385 if ( numDrawSurfs > MAX_DRAWSURFS ) {
1386 numDrawSurfs = MAX_DRAWSURFS;
1387 }
1388
1389 R_SortDrawSurfs( tr.refdef.drawSurfs + firstDrawSurf, numDrawSurfs - firstDrawSurf );
1390
1391 // draw main system development information (surface outlines, etc)
1392 R_DebugGraphics();
1393 }
1394
1395
1396