added coronas (glow) to dynamic lights
[xonotic/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         R_Decals_Init();
327         ui_init();
328         R_Modules_Start();
329 }
330
331 /*
332 ===============
333 GL_Init
334 ===============
335 */
336 extern char *ENGINE_EXTENSIONS;
337 void GL_Init (void)
338 {
339         gl_vendor = glGetString (GL_VENDOR);
340         Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
341         gl_renderer = glGetString (GL_RENDERER);
342         Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
343
344         gl_version = glGetString (GL_VERSION);
345         Con_Printf ("GL_VERSION: %s\n", gl_version);
346         gl_extensions = glGetString (GL_EXTENSIONS);
347         Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
348
349 //      Con_Printf ("%s %s\n", gl_renderer, gl_version);
350
351         VID_CheckExtensions();
352
353         // LordHavoc: report supported extensions
354         Con_Printf ("\nengine extensions: %s\n", ENGINE_EXTENSIONS);
355
356         glCullFace(GL_FRONT);
357         glEnable(GL_TEXTURE_2D);
358
359 //      glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
360 }
361
362
363 //==================================================================================
364
365 void R_Entity_Callback(void *data, void *junk)
366 {
367         ((entity_render_t *)data)->visframe = r_framecount;
368 }
369
370 static void R_MarkEntities (void)
371 {
372         int             i;
373         vec3_t  v;
374
375         if (!r_drawentities.integer)
376                 return;
377
378         for (i = 0;i < r_refdef.numentities;i++)
379         {
380                 currentrenderentity = r_refdef.entities[i];
381                 Mod_CheckLoaded(currentrenderentity->model);
382
383                 // move view-relative models to where they should be
384                 if (currentrenderentity->flags & RENDER_VIEWMODEL)
385                 {
386                         // remove flag so it will not be repeated incase RelinkEntities is not called again for a while
387                         currentrenderentity->flags -= RENDER_VIEWMODEL;
388                         // transform origin
389                         VectorCopy(currentrenderentity->origin, v);
390                         currentrenderentity->origin[0] = v[0] * vpn[0] + v[1] * vright[0] + v[2] * vup[0] + r_origin[0];
391                         currentrenderentity->origin[1] = v[0] * vpn[1] + v[1] * vright[1] + v[2] * vup[1] + r_origin[1];
392                         currentrenderentity->origin[2] = v[0] * vpn[2] + v[1] * vright[2] + v[2] * vup[2] + r_origin[2];
393                         // adjust angles
394                         VectorAdd(currentrenderentity->angles, r_refdef.viewangles, currentrenderentity->angles);
395                 }
396
397                 if (currentrenderentity->angles[0] || currentrenderentity->angles[2])
398                 {
399                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->rotatedmins, currentrenderentity->mins);
400                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->rotatedmaxs, currentrenderentity->maxs);
401                 }
402                 else if (currentrenderentity->angles[1])
403                 {
404                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->yawmins, currentrenderentity->mins);
405                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->yawmaxs, currentrenderentity->maxs);
406                 }
407                 else
408                 {
409                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->normalmins, currentrenderentity->mins);
410                         VectorMA(currentrenderentity->origin, currentrenderentity->scale, currentrenderentity->model->normalmaxs, currentrenderentity->maxs);
411                 }
412                 if (R_VisibleCullBox(currentrenderentity->mins, currentrenderentity->maxs))
413                         continue;
414
415                 R_LerpAnimation(currentrenderentity);
416                 if (r_ser.integer)
417                         currentrenderentity->model->SERAddEntity();
418                 else
419                         currentrenderentity->visframe = r_framecount;
420         }
421 }
422
423 // only used if skyrendermasked, and normally returns false
424 int R_DrawBModelSky (void)
425 {
426         int             i, sky = false;
427
428         if (!r_drawentities.integer)
429                 return false;
430
431         for (i = 0;i < r_refdef.numentities;i++)
432         {
433                 currentrenderentity = r_refdef.entities[i];
434                 if (currentrenderentity->visframe == r_framecount && currentrenderentity->model->DrawSky)
435                 {
436                         currentrenderentity->model->DrawSky();
437                         sky = true;
438                 }
439         }
440         return sky;
441 }
442
443 void R_DrawModels (void)
444 {
445         int             i;
446
447         if (!r_drawentities.integer)
448                 return;
449
450         for (i = 0;i < r_refdef.numentities;i++)
451         {
452                 currentrenderentity = r_refdef.entities[i];
453                 if (currentrenderentity->visframe == r_framecount && currentrenderentity->model->Draw)
454                         currentrenderentity->model->Draw();
455         }
456 }
457
458 /*
459 =============
460 R_DrawViewModel
461 =============
462 */
463 void R_DrawViewModel (void)
464 {
465         // FIXME: move these checks to client
466         if (!r_drawviewmodel.integer || chase_active.integer || envmap || !r_drawentities.integer || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.render.model)
467                 return;
468
469         currentrenderentity = &cl.viewent.render;
470         Mod_CheckLoaded(currentrenderentity->model);
471
472         R_LerpAnimation(currentrenderentity);
473
474         // hack the depth range to prevent view model from poking into walls
475         if (gl_viewmodeldepthhack.integer)
476         {
477                 R_Mesh_Render();
478                 glDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin));
479         }
480         currentrenderentity->model->Draw();
481         if (gl_viewmodeldepthhack.integer)
482         {
483                 R_Mesh_Render();
484                 glDepthRange (gldepthmin, gldepthmax);
485         }
486 }
487
488 static void R_SetFrustum (void)
489 {
490         int             i;
491
492         // LordHavoc: note to all quake engine coders, the special case for 90
493         // degrees assumed a square view (wrong), so I removed it, Quake2 has it
494         // disabled as well.
495         // rotate VPN right by FOV_X/2 degrees
496         RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
497         // rotate VPN left by FOV_X/2 degrees
498         RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
499         // rotate VPN up by FOV_X/2 degrees
500         RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
501         // rotate VPN down by FOV_X/2 degrees
502         RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
503
504
505         for (i=0 ; i<4 ; i++)
506         {
507                 frustum[i].type = PLANE_ANYZ;
508                 frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
509                 PlaneClassify(&frustum[i]);
510         }
511 }
512
513 /*
514 ===============
515 R_SetupFrame
516 ===============
517 */
518 static void R_SetupFrame (void)
519 {
520 // don't allow cheats in multiplayer
521         if (cl.maxclients > 1)
522         {
523                 if (r_fullbright.integer != 0)
524                         Cvar_Set ("r_fullbright", "0");
525                 if (r_ambient.value != 0)
526                         Cvar_Set ("r_ambient", "0");
527         }
528         if (r_multitexture.integer && gl_textureunits < 2)
529                 Cvar_SetValue("r_multitexture", 0);
530
531         r_framecount++;
532
533 // build the transformation matrix for the given view angles
534         VectorCopy (r_refdef.vieworg, r_origin);
535
536         AngleVectors (r_refdef.viewangles, vpn, vright, vup);
537
538 // current viewleaf
539         r_oldviewleaf = r_viewleaf;
540         r_viewleaf = Mod_PointInLeaf (r_origin, cl.worldmodel);
541
542 //      r_cache_thrash = false;
543
544         R_AnimateLight ();
545 }
546
547
548 static void MYgluPerspective(GLdouble fovx, GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar )
549 {
550         GLdouble xmax, ymax;
551
552         xmax = zNear * tan( fovx * M_PI / 360.0 ) * aspect;
553         ymax = zNear * tan( fovy * M_PI / 360.0 );
554
555         if (r_viewleaf->contents != CONTENTS_EMPTY && r_viewleaf->contents != CONTENTS_SOLID)
556         {
557                 xmax *= (sin(cl.time * 4.7) * 0.03 + 0.97);
558                 ymax *= (sin(cl.time * 3.0) * 0.03 + 0.97);
559         }
560
561         glFrustum(-xmax, xmax, -ymax, ymax, zNear, zFar );
562 }
563
564
565 /*
566 =============
567 R_SetupGL
568 =============
569 */
570 static void R_SetupGL (void)
571 {
572         if (!r_render.integer)
573                 return;
574
575 //      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: moved to SCR_UpdateScreen
576         gldepthmin = 0;
577         gldepthmax = 1;
578         glDepthFunc (GL_LEQUAL);
579
580         glDepthRange (gldepthmin, gldepthmax);
581
582         // update farclip based on previous frame
583         r_farclip = r_newfarclip;
584
585         // set up viewpoint
586         glMatrixMode(GL_PROJECTION);
587         glLoadIdentity ();
588
589         // y is weird beause OpenGL is bottom to top, we use top to bottom
590         glViewport(r_refdef.x, vid.realheight - (r_refdef.y + r_refdef.height), r_refdef.width, r_refdef.height);
591 //      yfov = 2*atan((float)r_refdef.height/r_refdef.width)*180/M_PI;
592         MYgluPerspective (r_refdef.fov_x, r_refdef.fov_y, r_refdef.width/r_refdef.height, 4, r_farclip);
593
594         glCullFace(GL_FRONT);
595
596         glMatrixMode(GL_MODELVIEW);
597         glLoadIdentity ();
598
599         glRotatef (-90,  1, 0, 0);          // put Z going up
600         glRotatef (90,  0, 0, 1);           // put Z going up
601         glRotatef (-r_refdef.viewangles[2],  1, 0, 0);
602         glRotatef (-r_refdef.viewangles[0],  0, 1, 0);
603         glRotatef (-r_refdef.viewangles[1],  0, 0, 1);
604         glTranslatef (-r_refdef.vieworg[0],  -r_refdef.vieworg[1],  -r_refdef.vieworg[2]);
605
606 //      glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
607
608         //
609         // set drawing parms
610         //
611 //      if (gl_cull.integer)
612                 glEnable(GL_CULL_FACE);
613 //      else
614 //              glDisable(GL_CULL_FACE);
615
616         glEnable(GL_BLEND); // was Disable
617         glEnable(GL_DEPTH_TEST);
618         glDepthMask(1);
619 }
620
621 static void R_BlendView(void)
622 {
623         if (!r_render.integer)
624                 return;
625
626         if (r_refdef.viewblend[3] < 0.01f)
627                 return;
628
629         glMatrixMode(GL_PROJECTION);
630         glLoadIdentity ();
631         glOrtho  (0, 1, 1, 0, -99999, 99999);
632         glMatrixMode(GL_MODELVIEW);
633         glLoadIdentity ();
634         glDisable (GL_DEPTH_TEST);
635         glDisable (GL_CULL_FACE);
636         glDisable(GL_TEXTURE_2D);
637         glEnable(GL_BLEND);
638         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
639         glBegin (GL_TRIANGLES);
640         if (lighthalf)
641                 glColor4f (r_refdef.viewblend[0] * 0.5f, r_refdef.viewblend[1] * 0.5f, r_refdef.viewblend[2] * 0.5f, r_refdef.viewblend[3]);
642         else
643                 glColor4fv (r_refdef.viewblend);
644         glVertex2f (-5, -5);
645         glVertex2f (10, -5);
646         glVertex2f (-5, 10);
647         glEnd ();
648
649         glEnable (GL_CULL_FACE);
650         glEnable (GL_DEPTH_TEST);
651         glDisable(GL_BLEND);
652         glEnable(GL_TEXTURE_2D);
653 }
654
655 /*
656 ================
657 R_RenderView
658
659 r_refdef must be set before the first call
660 ================
661 */
662 void R_RenderView (void)
663 {
664         if (!cl.worldmodel)
665                 Host_Error ("R_RenderView: NULL worldmodel");
666
667         // FIXME: move to client
668         R_MoveExplosions();
669         R_TimeReport("mexplosion");
670
671         R_SetupFrame();
672         R_SetFrustum();
673         R_SetupGL();
674         R_SetupFog();
675         R_SkyStartFrame();
676         R_Mesh_Clear();
677         if (r_ser.integer)
678                 R_Clip_StartFrame();
679         R_BuildLightList();
680
681         R_TimeReport("setup");
682
683         R_DrawWorld();
684         R_TimeReport("worldnode");
685
686         R_MarkEntities();
687         R_TimeReport("markentity");
688
689         if (r_ser.integer)
690         {
691                 R_Clip_EndFrame();
692                 R_TimeReport("hiddensurf");
693         }
694
695         R_MarkWorldLights();
696         R_TimeReport("marklights");
697
698         if (skyrendermasked && R_DrawBModelSky())
699         {
700                 R_TimeReport("bmodelsky");
701         }
702
703         R_SetupForWorldRendering();
704         R_PrepareSurfaces();
705         R_TimeReport("surfprep");
706
707         R_DrawSurfacesAll();
708         R_TimeReport("surfdraw");
709
710         if (r_drawportals.integer)
711         {
712                 R_DrawPortals();
713                 R_TimeReport("portals");
714         }
715
716         // don't let sound skip if going slow
717         if (!intimerefresh && !r_speeds.integer)
718                 S_ExtraUpdate ();
719
720         R_DrawViewModel();
721         R_DrawModels();
722         R_TimeReport("models");
723
724         R_DrawDecals();
725         R_TimeReport("decals");
726
727         R_DrawParticles();
728         R_TimeReport("particles");
729
730         R_DrawExplosions();
731         R_TimeReport("explosions");
732
733         // draw transparent meshs
734         R_Mesh_AddTransparent();
735         R_TimeReport("addtrans");
736
737         R_DrawCoronas();
738         R_TimeReport("coronas");
739
740         // render any queued meshs
741         R_Mesh_Render();
742         R_TimeReport("meshrender");
743
744         R_BlendView();
745         R_TimeReport("blendview");
746
747         //Mem_CheckSentinelsGlobal();
748         //R_TimeReport("memtest");
749 }