changed Length() call to VectorLength() macro... inside a comment... yes pointless...
[divverent/darkplaces.git] / gl_rmain.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20 // r_main.c
21
22 #include "quakedef.h"
23
24 //static qboolean       r_cache_thrash;         // compatability
25
26 entity_render_t *currentrenderentity;
27
28 int                     r_framecount;           // used for dlight push checking
29
30 mplane_t        frustum[4];
31
32 int                     c_brush_polys, c_alias_polys, c_light_polys, c_faces, c_nodes, c_leafs, c_models, c_bmodels, c_sprites, c_particles, c_dlights;
33
34 qboolean        envmap;                         // true during envmap command capture
35
36 // LordHavoc: moved all code related to particles into r_part.c
37 //int                   particletexture;        // little dot for particles
38 //int                   playertextures;         // up to 16 color translated skins
39
40 //
41 // view origin
42 //
43 vec3_t  vup;
44 vec3_t  vpn;
45 vec3_t  vright;
46 vec3_t  r_origin;
47
48 //float r_world_matrix[16];
49 //float r_base_world_matrix[16];
50
51 //
52 // screen size info
53 //
54 refdef_t        r_refdef;
55
56 mleaf_t         *r_viewleaf, *r_oldviewleaf;
57
58 unsigned short  d_lightstylevalue[256]; // 8.8 fraction of base light value
59
60 //cvar_t        r_norefresh = {0, "r_norefresh","0"};
61 cvar_t  r_drawentities = {0, "r_drawentities","1"};
62 cvar_t  r_drawviewmodel = {0, "r_drawviewmodel","1"};
63 cvar_t  r_speeds = {0, "r_speeds","0"};
64 cvar_t  r_fullbright = {0, "r_fullbright","0"};
65 //cvar_t        r_lightmap = {0, "r_lightmap","0"};
66 cvar_t  r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
67 cvar_t  r_dynamic = {CVAR_SAVE, "r_dynamic","1"};
68 cvar_t  r_waterripple = {CVAR_SAVE, "r_waterripple","0"};
69 cvar_t  r_fullbrights = {CVAR_SAVE, "r_fullbrights", "1"};
70
71 //cvar_t        r_dynamicbothsides = {CVAR_SAVE, "r_dynamicbothsides", "1"}; // LordHavoc: can disable dynamic lighting of backfaces, but quake maps are weird so it doesn't always work right...
72
73 cvar_t  gl_fogenable = {0, "gl_fogenable", "0"};
74 cvar_t  gl_fogdensity = {0, "gl_fogdensity", "0.25"};
75 cvar_t  gl_fogred = {0, "gl_fogred","0.3"};
76 cvar_t  gl_foggreen = {0, "gl_foggreen","0.3"};
77 cvar_t  gl_fogblue = {0, "gl_fogblue","0.3"};
78 cvar_t  gl_fogstart = {0, "gl_fogstart", "0"};
79 cvar_t  gl_fogend = {0, "gl_fogend","0"};
80
81 cvar_t  r_ser = {CVAR_SAVE, "r_ser", "1"};
82 //cvar_t        gl_viewmodeldepthhack = {0, "gl_viewmodeldepthhack", "1"};
83
84 cvar_t r_multitexture = {0, "r_multitexture", "1"};
85
86 /*
87 ====================
88 R_TimeRefresh_f
89
90 For program optimization
91 ====================
92 */
93 qboolean intimerefresh = 0;
94 static void R_TimeRefresh_f (void)
95 {
96         int                     i;
97         float           start, stop, time;
98
99         intimerefresh = 1;
100         start = Sys_DoubleTime ();
101         //qglDrawBuffer (GL_FRONT);
102         for (i = 0;i < 128;i++)
103         {
104                 r_refdef.viewangles[0] = 0;
105                 r_refdef.viewangles[1] = i/128.0*360.0;
106                 r_refdef.viewangles[2] = 0;
107                 CL_UpdateScreen();
108                 //R_RenderView();
109         }
110         //qglDrawBuffer  (GL_BACK);
111
112         stop = Sys_DoubleTime ();
113         intimerefresh = 0;
114         time = stop-start;
115         Con_Printf ("%f seconds (%f fps)\n", time, 128/time);
116 }
117
118 extern cvar_t r_drawportals;
119
120 int R_VisibleCullBox (vec3_t mins, vec3_t maxs)
121 {
122         int sides;
123         mnode_t *nodestack[8192], *node;
124         int stack = 0;
125
126         if (R_CullBox(mins, maxs))
127                 return true;
128
129         node = cl.worldmodel->nodes;
130 loc0:
131         if (node->contents < 0)
132         {
133                 if (((mleaf_t *)node)->visframe == r_framecount)
134                         return false;
135                 if (!stack)
136                         return true;
137                 node = nodestack[--stack];
138                 goto loc0;
139         }
140
141         sides = BOX_ON_PLANE_SIDE(mins, maxs, node->plane);
142
143 // recurse down the contacted sides
144         if (sides & 1)
145         {
146                 if (sides & 2) // 3
147                 {
148                         // put second child on the stack for later examination
149                         nodestack[stack++] = node->children[1];
150                         node = node->children[0];
151                         goto loc0;
152                 }
153                 else // 1
154                 {
155                         node = node->children[0];
156                         goto loc0;
157                 }
158         }
159         // 2
160         node = node->children[1];
161         goto loc0;
162 }
163
164 vec3_t fogcolor;
165 vec_t fogdensity;
166 float fog_density, fog_red, fog_green, fog_blue;
167 qboolean fogenabled;
168 qboolean oldgl_fogenable;
169 void R_SetupFog(void)
170 {
171         if (gamemode == GAME_NEHAHRA)
172         {
173                 if (gl_fogenable.integer)
174                 {
175                         oldgl_fogenable = true;
176                         fog_density = gl_fogdensity.value;
177                         fog_red = gl_fogred.value;
178                         fog_green = gl_foggreen.value;
179                         fog_blue = gl_fogblue.value;
180                 }
181                 else if (oldgl_fogenable)
182                 {
183                         oldgl_fogenable = false;
184                         fog_density = 0;
185                         fog_red = 0;
186                         fog_green = 0;
187                         fog_blue = 0;
188                 }
189         }
190         if (fog_density)
191         {
192                 fogcolor[0] = fog_red   = bound(0.0f, fog_red  , 1.0f);
193                 fogcolor[1] = fog_green = bound(0.0f, fog_green, 1.0f);
194                 fogcolor[2] = fog_blue  = bound(0.0f, fog_blue , 1.0f);
195         }
196         if (fog_density)
197         {
198                 fogenabled = true;
199                 fogdensity = -4000.0f / (fog_density * fog_density);
200                 // fog color was already set
201         }
202         else
203                 fogenabled = false;
204 }
205
206 // FIXME: move this to client?
207 void FOG_clear(void)
208 {
209         if (gamemode == GAME_NEHAHRA)
210         {
211                 Cvar_Set("gl_fogenable", "0");
212                 Cvar_Set("gl_fogdensity", "0.2");
213                 Cvar_Set("gl_fogred", "0.3");
214                 Cvar_Set("gl_foggreen", "0.3");
215                 Cvar_Set("gl_fogblue", "0.3");
216         }
217         fog_density = fog_red = fog_green = fog_blue = 0.0f;
218 }
219
220 // FIXME: move this to client?
221 void FOG_registercvars(void)
222 {
223         if (gamemode == GAME_NEHAHRA)
224         {
225                 Cvar_RegisterVariable (&gl_fogenable);
226                 Cvar_RegisterVariable (&gl_fogdensity);
227                 Cvar_RegisterVariable (&gl_fogred);
228                 Cvar_RegisterVariable (&gl_foggreen);
229                 Cvar_RegisterVariable (&gl_fogblue);
230                 Cvar_RegisterVariable (&gl_fogstart);
231                 Cvar_RegisterVariable (&gl_fogend);
232         }
233 }
234
235 void gl_main_start(void)
236 {
237 }
238
239 void gl_main_shutdown(void)
240 {
241 }
242
243 void gl_main_newmap(void)
244 {
245         r_framecount = 1;
246 }
247
248 void GL_Main_Init(void)
249 {
250 // FIXME: move this to client?
251         FOG_registercvars();
252         Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
253         Cvar_RegisterVariable (&r_drawentities);
254         Cvar_RegisterVariable (&r_drawviewmodel);
255         Cvar_RegisterVariable (&r_speeds);
256 //      Cvar_RegisterVariable (&r_dynamicwater);
257 //      Cvar_RegisterVariable (&r_dynamicbothsides);
258         Cvar_RegisterVariable (&r_fullbrights);
259         Cvar_RegisterVariable (&r_wateralpha);
260         Cvar_RegisterVariable (&r_dynamic);
261         Cvar_RegisterVariable (&r_waterripple);
262         Cvar_RegisterVariable (&r_fullbright);
263         Cvar_RegisterVariable (&r_ser);
264 //      Cvar_RegisterVariable (&gl_viewmodeldepthhack);
265         Cvar_RegisterVariable (&r_multitexture);
266         if (gamemode == GAME_NEHAHRA)
267                 Cvar_SetValue("r_fullbrights", 0);
268         R_RegisterModule("GL_Main", gl_main_start, gl_main_shutdown, gl_main_newmap);
269 }
270
271 /*
272 ===============
273 R_NewMap
274 ===============
275 */
276 void CL_ParseEntityLump(char *entitystring);
277 void R_NewMap (void)
278 {
279         int             i;
280
281         for (i=0 ; i<256 ; i++)
282                 d_lightstylevalue[i] = 264;             // normal light value
283
284         r_viewleaf = NULL;
285         if (cl.worldmodel->entities)
286                 CL_ParseEntityLump(cl.worldmodel->entities);
287         R_Modules_NewMap();
288 }
289
290 extern void R_Textures_Init(void);
291 extern void Mod_RenderInit(void);
292 extern void GL_Draw_Init(void);
293 extern void GL_Main_Init(void);
294 extern void GL_Models_Init(void);
295 extern void R_Sky_Init(void);
296 extern void GL_Surf_Init(void);
297 extern void R_Crosshairs_Init(void);
298 extern void R_Light_Init(void);
299 extern void R_Particles_Init(void);
300 extern void R_Explosion_Init(void);
301 extern void R_Clip_Init(void);
302 extern void ui_init(void);
303 extern void gl_backend_init(void);
304
305 void Render_Init(void)
306 {
307         R_Modules_Shutdown();
308         R_Textures_Init();
309         Mod_RenderInit();
310         gl_backend_init();
311         R_Clip_Init();
312         GL_Draw_Init();
313         GL_Main_Init();
314         GL_Models_Init();
315         R_Sky_Init();
316         GL_Surf_Init();
317         R_Crosshairs_Init();
318         R_Light_Init();
319         R_Particles_Init();
320         R_Explosion_Init();
321         ui_init();
322         R_Modules_Start();
323 }
324
325 /*
326 ===============
327 GL_Init
328 ===============
329 */
330 extern char *ENGINE_EXTENSIONS;
331 void GL_Init (void)
332 {
333         gl_vendor = glGetString (GL_VENDOR);
334         Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
335         gl_renderer = glGetString (GL_RENDERER);
336         Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
337
338         gl_version = glGetString (GL_VERSION);
339         Con_Printf ("GL_VERSION: %s\n", gl_version);
340         gl_extensions = glGetString (GL_EXTENSIONS);
341         Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
342
343 //      Con_Printf ("%s %s\n", gl_renderer, gl_version);
344
345         VID_CheckExtensions();
346
347         // LordHavoc: report supported extensions
348         Con_Printf ("\nengine extensions: %s\n", ENGINE_EXTENSIONS);
349
350         qglCullFace(GL_FRONT);
351         qglEnable(GL_TEXTURE_2D);
352
353 //      qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
354 }
355
356
357 //==================================================================================
358
359 void R_Entity_Callback(void *data, void *junk)
360 {
361         ((entity_render_t *)data)->visframe = r_framecount;
362 }
363
364 static void R_MarkEntities (void)
365 {
366         int             i;
367         vec3_t  v;
368
369         if (!r_drawentities.integer)
370                 return;
371
372         for (i = 0;i < r_refdef.numentities;i++)
373         {
374                 currentrenderentity = r_refdef.entities[i];
375                 Mod_CheckLoaded(currentrenderentity->model);
376
377                 // move view-relative models to where they should be
378                 if (currentrenderentity->flags & RENDER_VIEWMODEL)
379                 {
380                         // remove flag so it will not be repeated incase RelinkEntities is not called again for a while
381                         currentrenderentity->flags -= RENDER_VIEWMODEL;
382                         // transform origin
383                         VectorCopy(currentrenderentity->origin, v);
384                         currentrenderentity->origin[0] = v[0] * vpn[0] + v[1] * vright[0] + v[2] * vup[0] + r_origin[0];
385                         currentrenderentity->origin[1] = v[0] * vpn[1] + v[1] * vright[1] + v[2] * vup[1] + r_origin[1];
386                         currentrenderentity->origin[2] = v[0] * vpn[2] + v[1] * vright[2] + v[2] * vup[2] + r_origin[2];
387                         // adjust angles
388                         VectorAdd(currentrenderentity->angles, r_refdef.viewangles, currentrenderentity->angles);
389                 }
390
391                 if (currentrenderentity->angles[0] || currentrenderentity->angles[2])
392                 {
393                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->rotatedmins, currentrenderentity->mins);
394                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->rotatedmaxs, currentrenderentity->maxs);
395                 }
396                 else if (currentrenderentity->angles[1])
397                 {
398                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->yawmins, currentrenderentity->mins);
399                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->yawmaxs, currentrenderentity->maxs);
400                 }
401                 else
402                 {
403                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->normalmins, currentrenderentity->mins);
404                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->normalmaxs, currentrenderentity->maxs);
405                 }
406                 if (R_VisibleCullBox(currentrenderentity->mins, currentrenderentity->maxs))
407                         continue;
408
409                 R_LerpAnimation(currentrenderentity);
410                 if (r_ser.integer)
411                         currentrenderentity->model->SERAddEntity();
412                 else
413                         currentrenderentity->visframe = r_framecount;
414         }
415 }
416
417 // only used if skyrendermasked, and normally returns false
418 int R_DrawBModelSky (void)
419 {
420         int             i, sky = false;
421
422         if (!r_drawentities.integer)
423                 return false;
424
425         for (i = 0;i < r_refdef.numentities;i++)
426         {
427                 currentrenderentity = r_refdef.entities[i];
428                 if (currentrenderentity->visframe == r_framecount && currentrenderentity->model->DrawSky)
429                 {
430                         currentrenderentity->model->DrawSky();
431                         sky = true;
432                 }
433         }
434         return sky;
435 }
436
437 void R_DrawModels (void)
438 {
439         int             i;
440
441         if (!r_drawentities.integer)
442                 return;
443
444         for (i = 0;i < r_refdef.numentities;i++)
445         {
446                 currentrenderentity = r_refdef.entities[i];
447                 if (currentrenderentity->visframe == r_framecount && currentrenderentity->model->Draw)
448                         currentrenderentity->model->Draw();
449         }
450 }
451
452 /*
453 =============
454 R_DrawViewModel
455 =============
456 */
457 void R_DrawViewModel (void)
458 {
459         // FIXME: move these checks to client
460         if (!r_drawviewmodel.integer || chase_active.integer || envmap || !r_drawentities.integer || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.render.model)
461                 return;
462
463         currentrenderentity = &cl.viewent.render;
464         Mod_CheckLoaded(currentrenderentity->model);
465
466         R_LerpAnimation(currentrenderentity);
467
468         // hack the depth range to prevent view model from poking into walls
469 //      if (gl_viewmodeldepthhack.integer)
470 //      {
471 //              R_Mesh_Render();
472 //              qglDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin));
473 //      }
474         currentrenderentity->model->Draw();
475 //      if (gl_viewmodeldepthhack.integer)
476 //      {
477 //              R_Mesh_Render();
478 //              qglDepthRange (gldepthmin, gldepthmax);
479 //      }
480 }
481
482 static void R_SetFrustum (void)
483 {
484         int             i;
485
486         // LordHavoc: note to all quake engine coders, the special case for 90
487         // degrees assumed a square view (wrong), so I removed it, Quake2 has it
488         // disabled as well.
489         // rotate VPN right by FOV_X/2 degrees
490         RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
491         // rotate VPN left by FOV_X/2 degrees
492         RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
493         // rotate VPN up by FOV_X/2 degrees
494         RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
495         // rotate VPN down by FOV_X/2 degrees
496         RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
497
498
499         for (i=0 ; i<4 ; i++)
500         {
501                 frustum[i].type = PLANE_ANYZ;
502                 frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
503                 PlaneClassify(&frustum[i]);
504         }
505 }
506
507 /*
508 ===============
509 R_SetupFrame
510 ===============
511 */
512 static void R_SetupFrame (void)
513 {
514 // don't allow cheats in multiplayer
515         if (cl.maxclients > 1)
516         {
517                 if (r_fullbright.integer != 0)
518                         Cvar_Set ("r_fullbright", "0");
519                 if (r_ambient.value != 0)
520                         Cvar_Set ("r_ambient", "0");
521         }
522         if (r_multitexture.integer && gl_textureunits < 2)
523                 Cvar_SetValue("r_multitexture", 0);
524
525         r_framecount++;
526
527 // build the transformation matrix for the given view angles
528         VectorCopy (r_refdef.vieworg, r_origin);
529
530         AngleVectors (r_refdef.viewangles, vpn, vright, vup);
531
532 // current viewleaf
533         r_oldviewleaf = r_viewleaf;
534         r_viewleaf = Mod_PointInLeaf (r_origin, cl.worldmodel);
535
536 //      r_cache_thrash = false;
537
538         R_AnimateLight ();
539 }
540
541
542 static int blendviewpolyindex[3] = {0, 1, 2};
543
544 static void R_BlendView(void)
545 {
546         rmeshinfo_t m;
547         float tvxyz[3][4], r;
548
549         if (!r_render.integer)
550                 return;
551
552         if (r_refdef.viewblend[3] < 0.01f)
553                 return;
554
555         memset(&m, 0, sizeof(m));
556         m.transparent = false;
557         m.blendfunc1 = GL_SRC_ALPHA;
558         m.blendfunc2 = GL_ONE;
559         m.depthdisable = true; // magic
560         m.numtriangles = 1;
561         m.numverts = 3;
562         m.index = blendviewpolyindex;
563         m.vertex = &tvxyz[0][0];
564         m.vertexstep = sizeof(float[4]);
565         m.cr = r_refdef.viewblend[0];
566         m.cg = r_refdef.viewblend[1];
567         m.cb = r_refdef.viewblend[2];
568         m.ca = r_refdef.viewblend[3];
569         r = 64000;
570         tvxyz[0][0] = r_origin[0] + vpn[0] * 1.5 - vright[0] * r - vup[0] * r;
571         tvxyz[0][1] = r_origin[1] + vpn[1] * 1.5 - vright[1] * r - vup[1] * r;
572         tvxyz[0][2] = r_origin[2] + vpn[2] * 1.5 - vright[2] * r - vup[2] * r;
573         r *= 3;
574         tvxyz[1][0] = tvxyz[0][0] + vup[0] * r;
575         tvxyz[1][1] = tvxyz[0][1] + vup[1] * r;
576         tvxyz[1][2] = tvxyz[0][2] + vup[2] * r;
577         tvxyz[2][0] = tvxyz[0][0] + vright[0] * r;
578         tvxyz[2][1] = tvxyz[0][1] + vright[1] * r;
579         tvxyz[2][2] = tvxyz[0][2] + vright[2] * r;
580         R_Mesh_Draw(&m);
581
582         /*
583         qglMatrixMode(GL_PROJECTION);
584         qglLoadIdentity ();
585         qglOrtho  (0, 1, 1, 0, -99999, 99999);
586         qglMatrixMode(GL_MODELVIEW);
587         qglLoadIdentity ();
588         qglDisable (GL_DEPTH_TEST);
589         qglDisable (GL_CULL_FACE);
590         qglDisable(GL_TEXTURE_2D);
591         qglEnable(GL_BLEND);
592         qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
593         qglBegin (GL_TRIANGLES);
594         qglColor4f (r_refdef.viewblend[0] * overbrightscale, r_refdef.viewblend[1] * overbrightscale, r_refdef.viewblend[2] * overbrightscale, r_refdef.viewblend[3]);
595         qglVertex2f (-5, -5);
596         qglVertex2f (10, -5);
597         qglVertex2f (-5, 10);
598         qglEnd ();
599
600         qglEnable (GL_CULL_FACE);
601         qglEnable (GL_DEPTH_TEST);
602         qglDisable(GL_BLEND);
603         qglEnable(GL_TEXTURE_2D);
604         */
605 }
606
607 /*
608 ================
609 R_RenderView
610
611 r_refdef must be set before the first call
612 ================
613 */
614 void R_RenderView (void)
615 {
616         if (!cl.worldmodel)
617                 return; //Host_Error ("R_RenderView: NULL worldmodel");
618
619         // FIXME: move to client
620         R_MoveExplosions();
621         R_TimeReport("mexplosion");
622
623         R_SetupFrame();
624         R_SetFrustum();
625         R_SetupFog();
626         R_SkyStartFrame();
627         if (r_ser.integer)
628                 R_Clip_StartFrame();
629         R_BuildLightList();
630
631         R_Mesh_Start();
632
633         R_TimeReport("setup");
634
635         R_DrawWorld();
636         R_TimeReport("worldnode");
637
638         R_MarkEntities();
639         R_TimeReport("markentity");
640
641         if (r_ser.integer)
642         {
643                 R_Clip_EndFrame();
644                 R_TimeReport("hiddensurf");
645         }
646
647         R_MarkWorldLights();
648         R_TimeReport("marklights");
649
650         if (skyrendermasked)
651         {
652                 if (R_DrawBModelSky())
653                         R_TimeReport("bmodelsky");
654         }
655         else
656         {
657                 R_DrawViewModel();
658                 R_TimeReport("viewmodel");
659         }
660
661         R_SetupForWorldRendering();
662         R_PrepareSurfaces();
663         R_TimeReport("surfprep");
664
665         R_DrawSurfaces(SHADERSTAGE_SKY);
666         R_DrawSurfaces(SHADERSTAGE_NORMAL);
667         R_TimeReport("surfdraw");
668
669         if (r_drawportals.integer)
670         {
671                 R_DrawPortals();
672                 R_TimeReport("portals");
673         }
674
675         // don't let sound skip if going slow
676         if (!intimerefresh && !r_speeds.integer)
677                 S_ExtraUpdate ();
678
679         if (skyrendermasked)
680         {
681                 R_DrawViewModel();
682                 R_TimeReport("viewmodel");
683         }
684
685         R_DrawModels();
686         R_TimeReport("models");
687
688         R_DrawParticles();
689         R_TimeReport("particles");
690
691         R_DrawExplosions();
692         R_TimeReport("explosions");
693
694         // draw transparent meshs
695         R_Mesh_AddTransparent();
696         R_TimeReport("addtrans");
697
698         R_DrawCoronas();
699         R_TimeReport("coronas");
700
701         R_BlendView();
702         R_TimeReport("blendview");
703
704         // render any queued meshs
705         R_Mesh_Finish();
706         R_TimeReport("meshfinish");
707
708         //Mem_CheckSentinelsGlobal();
709         //R_TimeReport("memtest");
710 }