]> icculus.org git repositories - divverent/darkplaces.git/blob - gl_rmain.c
removed decals
[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  gl_lightmode = {CVAR_SAVE, "gl_lightmode", "1"}; // LordHavoc: overbright lighting
72 //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...
73
74 cvar_t  gl_fogenable = {0, "gl_fogenable", "0"};
75 cvar_t  gl_fogdensity = {0, "gl_fogdensity", "0.25"};
76 cvar_t  gl_fogred = {0, "gl_fogred","0.3"};
77 cvar_t  gl_foggreen = {0, "gl_foggreen","0.3"};
78 cvar_t  gl_fogblue = {0, "gl_fogblue","0.3"};
79 cvar_t  gl_fogstart = {0, "gl_fogstart", "0"};
80 cvar_t  gl_fogend = {0, "gl_fogend","0"};
81
82 cvar_t  r_ser = {CVAR_SAVE, "r_ser", "1"};
83 cvar_t  gl_viewmodeldepthhack = {0, "gl_viewmodeldepthhack", "1"};
84
85 cvar_t r_multitexture = {0, "r_multitexture", "1"};
86
87 /*
88 ====================
89 R_TimeRefresh_f
90
91 For program optimization
92 ====================
93 */
94 qboolean intimerefresh = 0;
95 static void R_TimeRefresh_f (void)
96 {
97         int                     i;
98         float           start, stop, time;
99
100         intimerefresh = 1;
101         start = Sys_DoubleTime ();
102         glDrawBuffer (GL_FRONT);
103         for (i = 0;i < 128;i++)
104         {
105                 r_refdef.viewangles[0] = 0;
106                 r_refdef.viewangles[1] = i/128.0*360.0;
107                 r_refdef.viewangles[2] = 0;
108                 R_RenderView();
109         }
110         glDrawBuffer  (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 qboolean lighthalf;
165
166 vec3_t fogcolor;
167 vec_t fogdensity;
168 float fog_density, fog_red, fog_green, fog_blue;
169 qboolean fogenabled;
170 qboolean oldgl_fogenable;
171 void R_SetupFog(void)
172 {
173         if (gamemode == GAME_NEHAHRA)
174         {
175                 if (gl_fogenable.integer)
176                 {
177                         oldgl_fogenable = true;
178                         fog_density = gl_fogdensity.value;
179                         fog_red = gl_fogred.value;
180                         fog_green = gl_foggreen.value;
181                         fog_blue = gl_fogblue.value;
182                 }
183                 else if (oldgl_fogenable)
184                 {
185                         oldgl_fogenable = false;
186                         fog_density = 0;
187                         fog_red = 0;
188                         fog_green = 0;
189                         fog_blue = 0;
190                 }
191         }
192         if (fog_density)
193         {
194                 fogcolor[0] = fog_red   = bound(0.0f, fog_red  , 1.0f);
195                 fogcolor[1] = fog_green = bound(0.0f, fog_green, 1.0f);
196                 fogcolor[2] = fog_blue  = bound(0.0f, fog_blue , 1.0f);
197         }
198         if (fog_density)
199         {
200                 fogenabled = true;
201                 fogdensity = -4000.0f / (fog_density * fog_density);
202                 // fog color was already set
203         }
204         else
205                 fogenabled = false;
206 }
207
208 // FIXME: move this to client?
209 void FOG_clear(void)
210 {
211         if (gamemode == GAME_NEHAHRA)
212         {
213                 Cvar_Set("gl_fogenable", "0");
214                 Cvar_Set("gl_fogdensity", "0.2");
215                 Cvar_Set("gl_fogred", "0.3");
216                 Cvar_Set("gl_foggreen", "0.3");
217                 Cvar_Set("gl_fogblue", "0.3");
218         }
219         fog_density = fog_red = fog_green = fog_blue = 0.0f;
220 }
221
222 // FIXME: move this to client?
223 void FOG_registercvars(void)
224 {
225         if (gamemode == GAME_NEHAHRA)
226         {
227                 Cvar_RegisterVariable (&gl_fogenable);
228                 Cvar_RegisterVariable (&gl_fogdensity);
229                 Cvar_RegisterVariable (&gl_fogred);
230                 Cvar_RegisterVariable (&gl_foggreen);
231                 Cvar_RegisterVariable (&gl_fogblue);
232                 Cvar_RegisterVariable (&gl_fogstart);
233                 Cvar_RegisterVariable (&gl_fogend);
234         }
235 }
236
237 void gl_main_start(void)
238 {
239 }
240
241 void gl_main_shutdown(void)
242 {
243 }
244
245 void gl_main_newmap(void)
246 {
247         r_framecount = 1;
248 }
249
250 void GL_Main_Init(void)
251 {
252 // FIXME: move this to client?
253         FOG_registercvars();
254         Cmd_AddCommand ("timerefresh", R_TimeRefresh_f);
255         Cvar_RegisterVariable (&r_drawentities);
256         Cvar_RegisterVariable (&r_drawviewmodel);
257         Cvar_RegisterVariable (&r_speeds);
258         Cvar_RegisterVariable (&gl_lightmode);
259 //      Cvar_RegisterVariable (&r_dynamicwater);
260 //      Cvar_RegisterVariable (&r_dynamicbothsides);
261         Cvar_RegisterVariable (&r_fullbrights);
262         Cvar_RegisterVariable (&r_wateralpha);
263         Cvar_RegisterVariable (&r_dynamic);
264         Cvar_RegisterVariable (&r_waterripple);
265         Cvar_RegisterVariable (&r_fullbright);
266         Cvar_RegisterVariable (&r_ser);
267         Cvar_RegisterVariable (&gl_viewmodeldepthhack);
268         Cvar_RegisterVariable (&r_multitexture);
269         if (gamemode == GAME_NEHAHRA)
270                 Cvar_SetValue("r_fullbrights", 0);
271         R_RegisterModule("GL_Main", gl_main_start, gl_main_shutdown, gl_main_newmap);
272 }
273
274 /*
275 ===============
276 R_NewMap
277 ===============
278 */
279 void CL_ParseEntityLump(char *entitystring);
280 void R_NewMap (void)
281 {
282         int             i;
283
284         for (i=0 ; i<256 ; i++)
285                 d_lightstylevalue[i] = 264;             // normal light value
286
287         r_viewleaf = NULL;
288         if (cl.worldmodel->entities)
289                 CL_ParseEntityLump(cl.worldmodel->entities);
290         R_Modules_NewMap();
291 }
292
293 extern void R_Textures_Init(void);
294 extern void Mod_RenderInit(void);
295 extern void GL_Draw_Init(void);
296 extern void GL_Main_Init(void);
297 extern void GL_Models_Init(void);
298 extern void R_Sky_Init(void);
299 extern void GL_Surf_Init(void);
300 extern void GL_Screen_Init(void);
301 extern void R_Crosshairs_Init(void);
302 extern void R_Light_Init(void);
303 extern void R_Particles_Init(void);
304 extern void R_Explosion_Init(void);
305 extern void R_Clip_Init(void);
306 extern void ui_init(void);
307 extern void gl_backend_init(void);
308
309 void Render_Init(void)
310 {
311         R_Modules_Shutdown();
312         R_Textures_Init();
313         Mod_RenderInit();
314         gl_backend_init();
315         R_Clip_Init();
316         GL_Draw_Init();
317         GL_Main_Init();
318         GL_Models_Init();
319         R_Sky_Init();
320         GL_Surf_Init();
321         GL_Screen_Init();
322         R_Crosshairs_Init();
323         R_Light_Init();
324         R_Particles_Init();
325         R_Explosion_Init();
326         ui_init();
327         R_Modules_Start();
328 }
329
330 /*
331 ===============
332 GL_Init
333 ===============
334 */
335 extern char *ENGINE_EXTENSIONS;
336 void GL_Init (void)
337 {
338         gl_vendor = glGetString (GL_VENDOR);
339         Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
340         gl_renderer = glGetString (GL_RENDERER);
341         Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
342
343         gl_version = glGetString (GL_VERSION);
344         Con_Printf ("GL_VERSION: %s\n", gl_version);
345         gl_extensions = glGetString (GL_EXTENSIONS);
346         Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
347
348 //      Con_Printf ("%s %s\n", gl_renderer, gl_version);
349
350         VID_CheckExtensions();
351
352         // LordHavoc: report supported extensions
353         Con_Printf ("\nengine extensions: %s\n", ENGINE_EXTENSIONS);
354
355         glCullFace(GL_FRONT);
356         glEnable(GL_TEXTURE_2D);
357
358 //      glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
359 }
360
361
362 //==================================================================================
363
364 void R_Entity_Callback(void *data, void *junk)
365 {
366         ((entity_render_t *)data)->visframe = r_framecount;
367 }
368
369 static void R_MarkEntities (void)
370 {
371         int             i;
372         vec3_t  v;
373
374         if (!r_drawentities.integer)
375                 return;
376
377         for (i = 0;i < r_refdef.numentities;i++)
378         {
379                 currentrenderentity = r_refdef.entities[i];
380                 Mod_CheckLoaded(currentrenderentity->model);
381
382                 // move view-relative models to where they should be
383                 if (currentrenderentity->flags & RENDER_VIEWMODEL)
384                 {
385                         // remove flag so it will not be repeated incase RelinkEntities is not called again for a while
386                         currentrenderentity->flags -= RENDER_VIEWMODEL;
387                         // transform origin
388                         VectorCopy(currentrenderentity->origin, v);
389                         currentrenderentity->origin[0] = v[0] * vpn[0] + v[1] * vright[0] + v[2] * vup[0] + r_origin[0];
390                         currentrenderentity->origin[1] = v[0] * vpn[1] + v[1] * vright[1] + v[2] * vup[1] + r_origin[1];
391                         currentrenderentity->origin[2] = v[0] * vpn[2] + v[1] * vright[2] + v[2] * vup[2] + r_origin[2];
392                         // adjust angles
393                         VectorAdd(currentrenderentity->angles, r_refdef.viewangles, currentrenderentity->angles);
394                 }
395
396                 if (currentrenderentity->angles[0] || currentrenderentity->angles[2])
397                 {
398                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->rotatedmins, currentrenderentity->mins);
399                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->rotatedmaxs, currentrenderentity->maxs);
400                 }
401                 else if (currentrenderentity->angles[1])
402                 {
403                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->yawmins, currentrenderentity->mins);
404                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->yawmaxs, currentrenderentity->maxs);
405                 }
406                 else
407                 {
408                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->normalmins, currentrenderentity->mins);
409                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->normalmaxs, currentrenderentity->maxs);
410                 }
411                 if (R_VisibleCullBox(currentrenderentity->mins, currentrenderentity->maxs))
412                         continue;
413
414                 R_LerpAnimation(currentrenderentity);
415                 if (r_ser.integer)
416                         currentrenderentity->model->SERAddEntity();
417                 else
418                         currentrenderentity->visframe = r_framecount;
419         }
420 }
421
422 // only used if skyrendermasked, and normally returns false
423 int R_DrawBModelSky (void)
424 {
425         int             i, sky = false;
426
427         if (!r_drawentities.integer)
428                 return false;
429
430         for (i = 0;i < r_refdef.numentities;i++)
431         {
432                 currentrenderentity = r_refdef.entities[i];
433                 if (currentrenderentity->visframe == r_framecount && currentrenderentity->model->DrawSky)
434                 {
435                         currentrenderentity->model->DrawSky();
436                         sky = true;
437                 }
438         }
439         return sky;
440 }
441
442 void R_DrawModels (void)
443 {
444         int             i;
445
446         if (!r_drawentities.integer)
447                 return;
448
449         for (i = 0;i < r_refdef.numentities;i++)
450         {
451                 currentrenderentity = r_refdef.entities[i];
452                 if (currentrenderentity->visframe == r_framecount && currentrenderentity->model->Draw)
453                         currentrenderentity->model->Draw();
454         }
455 }
456
457 /*
458 =============
459 R_DrawViewModel
460 =============
461 */
462 void R_DrawViewModel (void)
463 {
464         // FIXME: move these checks to client
465         if (!r_drawviewmodel.integer || chase_active.integer || envmap || !r_drawentities.integer || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.render.model)
466                 return;
467
468         currentrenderentity = &cl.viewent.render;
469         Mod_CheckLoaded(currentrenderentity->model);
470
471         R_LerpAnimation(currentrenderentity);
472
473         // hack the depth range to prevent view model from poking into walls
474         if (gl_viewmodeldepthhack.integer)
475         {
476                 R_Mesh_Render();
477                 glDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin));
478         }
479         currentrenderentity->model->Draw();
480         if (gl_viewmodeldepthhack.integer)
481         {
482                 R_Mesh_Render();
483                 glDepthRange (gldepthmin, gldepthmax);
484         }
485 }
486
487 static void R_SetFrustum (void)
488 {
489         int             i;
490
491         // LordHavoc: note to all quake engine coders, the special case for 90
492         // degrees assumed a square view (wrong), so I removed it, Quake2 has it
493         // disabled as well.
494         // rotate VPN right by FOV_X/2 degrees
495         RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
496         // rotate VPN left by FOV_X/2 degrees
497         RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
498         // rotate VPN up by FOV_X/2 degrees
499         RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
500         // rotate VPN down by FOV_X/2 degrees
501         RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
502
503
504         for (i=0 ; i<4 ; i++)
505         {
506                 frustum[i].type = PLANE_ANYZ;
507                 frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
508                 PlaneClassify(&frustum[i]);
509         }
510 }
511
512 /*
513 ===============
514 R_SetupFrame
515 ===============
516 */
517 static void R_SetupFrame (void)
518 {
519 // don't allow cheats in multiplayer
520         if (cl.maxclients > 1)
521         {
522                 if (r_fullbright.integer != 0)
523                         Cvar_Set ("r_fullbright", "0");
524                 if (r_ambient.value != 0)
525                         Cvar_Set ("r_ambient", "0");
526         }
527         if (r_multitexture.integer && gl_textureunits < 2)
528                 Cvar_SetValue("r_multitexture", 0);
529
530         r_framecount++;
531
532 // build the transformation matrix for the given view angles
533         VectorCopy (r_refdef.vieworg, r_origin);
534
535         AngleVectors (r_refdef.viewangles, vpn, vright, vup);
536
537 // current viewleaf
538         r_oldviewleaf = r_viewleaf;
539         r_viewleaf = Mod_PointInLeaf (r_origin, cl.worldmodel);
540
541 //      r_cache_thrash = false;
542
543         R_AnimateLight ();
544 }
545
546
547 static void MYgluPerspective(GLdouble fovx, GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar )
548 {
549         GLdouble xmax, ymax;
550
551         xmax = zNear * tan( fovx * M_PI / 360.0 ) * aspect;
552         ymax = zNear * tan( fovy * M_PI / 360.0 );
553
554         if (r_viewleaf->contents != CONTENTS_EMPTY && r_viewleaf->contents != CONTENTS_SOLID)
555         {
556                 xmax *= (sin(cl.time * 4.7) * 0.03 + 0.97);
557                 ymax *= (sin(cl.time * 3.0) * 0.03 + 0.97);
558         }
559
560         glFrustum(-xmax, xmax, -ymax, ymax, zNear, zFar );
561 }
562
563
564 /*
565 =============
566 R_SetupGL
567 =============
568 */
569 static void R_SetupGL (void)
570 {
571         if (!r_render.integer)
572                 return;
573
574 //      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: moved to SCR_UpdateScreen
575         gldepthmin = 0;
576         gldepthmax = 1;
577         glDepthFunc (GL_LEQUAL);
578
579         glDepthRange (gldepthmin, gldepthmax);
580
581         // update farclip based on previous frame
582         r_farclip = r_newfarclip;
583
584         // set up viewpoint
585         glMatrixMode(GL_PROJECTION);
586         glLoadIdentity ();
587
588         // y is weird beause OpenGL is bottom to top, we use top to bottom
589         glViewport(r_refdef.x, vid.realheight - (r_refdef.y + r_refdef.height), r_refdef.width, r_refdef.height);
590 //      yfov = 2*atan((float)r_refdef.height/r_refdef.width)*180/M_PI;
591         MYgluPerspective (r_refdef.fov_x, r_refdef.fov_y, r_refdef.width/r_refdef.height, 4, r_farclip);
592
593         glCullFace(GL_FRONT);
594
595         glMatrixMode(GL_MODELVIEW);
596         glLoadIdentity ();
597
598         glRotatef (-90,  1, 0, 0);          // put Z going up
599         glRotatef (90,  0, 0, 1);           // put Z going up
600         glRotatef (-r_refdef.viewangles[2],  1, 0, 0);
601         glRotatef (-r_refdef.viewangles[0],  0, 1, 0);
602         glRotatef (-r_refdef.viewangles[1],  0, 0, 1);
603         glTranslatef (-r_refdef.vieworg[0],  -r_refdef.vieworg[1],  -r_refdef.vieworg[2]);
604
605 //      glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
606
607         //
608         // set drawing parms
609         //
610 //      if (gl_cull.integer)
611                 glEnable(GL_CULL_FACE);
612 //      else
613 //              glDisable(GL_CULL_FACE);
614
615         glEnable(GL_BLEND); // was Disable
616         glEnable(GL_DEPTH_TEST);
617         glDepthMask(1);
618 }
619
620 static void R_BlendView(void)
621 {
622         if (!r_render.integer)
623                 return;
624
625         if (r_refdef.viewblend[3] < 0.01f)
626                 return;
627
628         glMatrixMode(GL_PROJECTION);
629         glLoadIdentity ();
630         glOrtho  (0, 1, 1, 0, -99999, 99999);
631         glMatrixMode(GL_MODELVIEW);
632         glLoadIdentity ();
633         glDisable (GL_DEPTH_TEST);
634         glDisable (GL_CULL_FACE);
635         glDisable(GL_TEXTURE_2D);
636         glEnable(GL_BLEND);
637         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
638         glBegin (GL_TRIANGLES);
639         if (lighthalf)
640                 glColor4f (r_refdef.viewblend[0] * 0.5f, r_refdef.viewblend[1] * 0.5f, r_refdef.viewblend[2] * 0.5f, r_refdef.viewblend[3]);
641         else
642                 glColor4fv (r_refdef.viewblend);
643         glVertex2f (-5, -5);
644         glVertex2f (10, -5);
645         glVertex2f (-5, 10);
646         glEnd ();
647
648         glEnable (GL_CULL_FACE);
649         glEnable (GL_DEPTH_TEST);
650         glDisable(GL_BLEND);
651         glEnable(GL_TEXTURE_2D);
652 }
653
654 /*
655 ================
656 R_RenderView
657
658 r_refdef must be set before the first call
659 ================
660 */
661 void R_RenderView (void)
662 {
663         if (!cl.worldmodel)
664                 Host_Error ("R_RenderView: NULL worldmodel");
665
666         // FIXME: move to client
667         R_MoveExplosions();
668         R_TimeReport("mexplosion");
669
670         R_SetupFrame();
671         R_SetFrustum();
672         R_SetupGL();
673         R_SetupFog();
674         R_SkyStartFrame();
675         R_Mesh_Clear();
676         if (r_ser.integer)
677                 R_Clip_StartFrame();
678         R_BuildLightList();
679
680         R_TimeReport("setup");
681
682         R_DrawWorld();
683         R_TimeReport("worldnode");
684
685         R_MarkEntities();
686         R_TimeReport("markentity");
687
688         if (r_ser.integer)
689         {
690                 R_Clip_EndFrame();
691                 R_TimeReport("hiddensurf");
692         }
693
694         R_MarkWorldLights();
695         R_TimeReport("marklights");
696
697         if (skyrendermasked)
698         {
699                 if (R_DrawBModelSky())
700                         R_TimeReport("bmodelsky");
701         }
702         else
703         {
704                 R_DrawViewModel();
705                 R_TimeReport("viewmodel");
706         }
707
708         R_SetupForWorldRendering();
709         R_PrepareSurfaces();
710         R_TimeReport("surfprep");
711
712         R_DrawSurfaces(SHADERSTAGE_SKY);
713         R_DrawSurfaces(SHADERSTAGE_NORMAL);
714         R_DrawSurfaces(SHADERSTAGE_FOG);
715         R_TimeReport("surfdraw");
716
717         if (r_drawportals.integer)
718         {
719                 R_DrawPortals();
720                 R_TimeReport("portals");
721         }
722
723         // don't let sound skip if going slow
724         if (!intimerefresh && !r_speeds.integer)
725                 S_ExtraUpdate ();
726
727         if (skyrendermasked)
728         {
729                 R_DrawViewModel();
730                 R_TimeReport("viewmodel");
731         }
732
733         R_DrawModels();
734         R_TimeReport("models");
735
736         R_DrawParticles();
737         R_TimeReport("particles");
738
739         R_DrawExplosions();
740         R_TimeReport("explosions");
741
742         // draw transparent meshs
743         R_Mesh_AddTransparent();
744         R_TimeReport("addtrans");
745
746         R_DrawCoronas();
747         R_TimeReport("coronas");
748
749         // render any queued meshs
750         R_Mesh_Render();
751         R_TimeReport("meshrender");
752
753         R_BlendView();
754         R_TimeReport("blendview");
755
756         //Mem_CheckSentinelsGlobal();
757         //R_TimeReport("memtest");
758 }