VID_CheckMultiTexture case was wrong (now VID_CheckMultitexture)
[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 entity_t        r_worldentity;
25
26 qboolean        r_cache_thrash;         // compatability
27
28 vec3_t          modelorg, r_entorigin;
29 entity_t        *currententity;
30
31 int                     r_visframecount;        // bumped when going to a new PVS
32 int                     r_framecount;           // used for dlight push checking
33
34 mplane_t        frustum[4];
35
36 int                     c_brush_polys, c_alias_polys, c_light_polys, c_nodes, c_leafs;
37
38 qboolean        envmap;                         // true during envmap command capture 
39
40 // LordHavoc: moved all code related to particles into r_part.c
41 //int                   particletexture;        // little dot for particles
42 //int                   playertextures;         // up to 16 color translated skins
43
44 //
45 // view origin
46 //
47 vec3_t  vup;
48 vec3_t  vpn;
49 vec3_t  vright;
50 vec3_t  r_origin;
51
52 float   r_world_matrix[16];
53 float   r_base_world_matrix[16];
54
55 //
56 // screen size info
57 //
58 refdef_t        r_refdef;
59
60 mleaf_t         *r_viewleaf, *r_oldviewleaf;
61
62 texture_t       *r_notexture_mip;
63
64 unsigned short  d_lightstylevalue[256]; // 8.8 fraction of base light value
65
66
67 void R_MarkLeaves (void);
68
69 //cvar_t        r_norefresh = {"r_norefresh","0"};
70 cvar_t  r_drawentities = {"r_drawentities","1"};
71 cvar_t  r_drawviewmodel = {"r_drawviewmodel","1"};
72 cvar_t  r_speeds = {"r_speeds","0"};
73 cvar_t  r_speeds2 = {"r_speeds2","0"};
74 cvar_t  r_fullbright = {"r_fullbright","0"};
75 //cvar_t        r_lightmap = {"r_lightmap","0"};
76 cvar_t  r_shadows = {"r_shadows","0"};
77 cvar_t  r_wateralpha = {"r_wateralpha","1"};
78 cvar_t  r_dynamic = {"r_dynamic","1"};
79 cvar_t  r_novis = {"r_novis","0"};
80 cvar_t  r_waterripple = {"r_waterripple","0"};
81 cvar_t  r_fullbrights = {"r_fullbrights", "1"};
82
83 cvar_t  contrast = {"contrast", "1.0", TRUE}; // LordHavoc: a method of operating system independent color correction
84 cvar_t  brightness = {"brightness", "1.0", TRUE}; // LordHavoc: a method of operating system independent color correction
85 cvar_t  gl_lightmode = {"gl_lightmode", "1", TRUE}; // LordHavoc: overbright lighting
86 //cvar_t        r_dynamicbothsides = {"r_dynamicbothsides", "1"}; // LordHavoc: can disable dynamic lighting of backfaces, but quake maps are weird so it doesn't always work right...
87 cvar_t  r_farclip = {"r_farclip", "6144"};
88
89 cvar_t  gl_fogenable = {"gl_fogenable", "0"};
90 cvar_t  gl_fogdensity = {"gl_fogdensity", "0.25"};
91 cvar_t  gl_fogred = {"gl_fogred","0.3"};
92 cvar_t  gl_foggreen = {"gl_foggreen","0.3"};
93 cvar_t  gl_fogblue = {"gl_fogblue","0.3"};
94 cvar_t  gl_fogstart = {"gl_fogstart", "0"};
95 cvar_t  gl_fogend = {"gl_fogend","0"};
96 cvar_t  glfog = {"glfog", "0"};
97
98 qboolean lighthalf;
99
100 vec3_t fogcolor;
101 vec_t fogdensity;
102 float fog_density, fog_red, fog_green, fog_blue;
103 qboolean fogenabled;
104 qboolean oldgl_fogenable;
105 void FOG_framebegin()
106 {
107         if (nehahra)
108         {
109 //              if (!Nehahrademcompatibility)
110 //                      gl_fogenable.value = 0;
111                 if (gl_fogenable.value)
112                 {
113                         oldgl_fogenable = true;
114                         fog_density = gl_fogdensity.value;
115                         fog_red = gl_fogred.value;
116                         fog_green = gl_foggreen.value;
117                         fog_blue = gl_fogblue.value;
118                 }
119                 else if (oldgl_fogenable)
120                 {
121                         oldgl_fogenable = false;
122                         fog_density = 0;
123                         fog_red = 0;
124                         fog_green = 0;
125                         fog_blue = 0;
126                 }
127         }
128         if (fog_density)
129         {
130                         fogcolor[0] = fog_red   = bound(0.0f, fog_red  , 1.0f);
131                         fogcolor[1] = fog_green = bound(0.0f, fog_green, 1.0f);
132                         fogcolor[2] = fog_blue  = bound(0.0f, fog_blue , 1.0f);
133                         if (lighthalf)
134                         {
135                                 fogcolor[0] *= 0.5f;
136                                 fogcolor[1] *= 0.5f;
137                                 fogcolor[2] *= 0.5f;
138                         }
139         }
140         if (glfog.value)
141         {
142                 if (!r_render.value)
143                         return;
144                 if(fog_density)
145                 {
146                         // LordHavoc: Borland C++ 5.0 was choking on this line, stupid compiler...
147                         //GLfloat colors[4] = {(GLfloat) gl_fogred.value, (GLfloat) gl_foggreen.value, (GLfloat) gl_fogblue.value, (GLfloat) 1};
148                         GLfloat colors[4];
149                         colors[0] = fog_red;
150                         colors[1] = fog_green;
151                         colors[2] = fog_blue;
152                         colors[3] = 1;
153                         if (lighthalf)
154                         {
155                                 colors[0] *= 0.5f;
156                                 colors[1] *= 0.5f;
157                                 colors[2] *= 0.5f;
158                         }
159
160                         glFogi (GL_FOG_MODE, GL_EXP2);
161                         glFogf (GL_FOG_DENSITY, (GLfloat) fog_density / 100); 
162                         glFogfv (GL_FOG_COLOR, colors);
163                         glEnable (GL_FOG);
164                 }
165                 else
166                         glDisable(GL_FOG);
167         }
168         else
169         {
170                 if (fog_density)
171                 {
172                         fogenabled = true;
173                         fogdensity = -4000.0f / (fog_density * fog_density);
174                         // fog color was already set
175                 }
176                 else
177                         fogenabled = false;
178         }
179 }
180
181 void FOG_frameend()
182 {
183         if (glfog.value)
184                 glDisable(GL_FOG);
185 }
186
187 void FOG_clear()
188 {
189         if (nehahra)
190         {
191                 Cvar_Set("gl_fogenable", "0");
192                 Cvar_Set("gl_fogdensity", "0.2");
193                 Cvar_Set("gl_fogred", "0.3");
194                 Cvar_Set("gl_foggreen", "0.3");
195                 Cvar_Set("gl_fogblue", "0.3");
196         }
197         fog_density = fog_red = fog_green = fog_blue = 0.0f;
198 }
199
200 void FOG_registercvars()
201 {
202         Cvar_RegisterVariable (&glfog);
203         if (nehahra)
204         {
205                 Cvar_RegisterVariable (&gl_fogenable);
206                 Cvar_RegisterVariable (&gl_fogdensity);
207                 Cvar_RegisterVariable (&gl_fogred);
208                 Cvar_RegisterVariable (&gl_foggreen); 
209                 Cvar_RegisterVariable (&gl_fogblue);
210                 Cvar_RegisterVariable (&gl_fogstart);
211                 Cvar_RegisterVariable (&gl_fogend);
212         }
213 }
214
215 void glmain_start()
216 {
217 }
218
219 void glmain_shutdown()
220 {
221 }
222
223 void GL_Main_Init()
224 {
225         FOG_registercvars();
226         Cvar_RegisterVariable (&r_speeds2);
227         Cvar_RegisterVariable (&contrast);
228         Cvar_RegisterVariable (&brightness);
229         Cvar_RegisterVariable (&gl_lightmode);
230 //      Cvar_RegisterVariable (&r_dynamicwater);
231 //      Cvar_RegisterVariable (&r_dynamicbothsides);
232         Cvar_RegisterVariable (&r_fullbrights);
233         if (nehahra)
234                 Cvar_SetValue("r_fullbrights", 0);
235 //      if (gl_vendor && strstr(gl_vendor, "3Dfx"))
236 //              gl_lightmode.value = 0;
237         Cvar_RegisterVariable (&r_fullbright);
238         R_RegisterModule("GL_Main", glmain_start, glmain_shutdown);
239 }
240
241 extern void GL_Draw_Init();
242 extern void GL_Main_Init();
243 extern void GL_Models_Init();
244 extern void GL_Poly_Init();
245 extern void GL_Surf_Init();
246 extern void GL_Screen_Init();
247 extern void GL_Misc_Init();
248 extern void R_Crosshairs_Init();
249 extern void R_Light_Init();
250 extern void R_Particles_Init();
251
252 void Render_Init()
253 {
254         R_ShutdownModules();
255         GL_Draw_Init();
256         GL_Main_Init();
257         GL_Models_Init();
258         GL_Poly_Init();
259         GL_Surf_Init();
260         GL_Screen_Init();
261         GL_Misc_Init();
262         R_Crosshairs_Init();
263         R_Light_Init();
264         R_Particles_Init();
265         R_StartModules();
266 }
267
268 /*
269 ===============
270 GL_Init
271 ===============
272 */
273 extern char *QSG_EXTENSIONS;
274 void GL_Init (void)
275 {
276         gl_vendor = glGetString (GL_VENDOR);
277         Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
278         gl_renderer = glGetString (GL_RENDERER);
279         Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
280
281         gl_version = glGetString (GL_VERSION);
282         Con_Printf ("GL_VERSION: %s\n", gl_version);
283         gl_extensions = glGetString (GL_EXTENSIONS);
284         Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
285
286 //      Con_Printf ("%s %s\n", gl_renderer, gl_version);
287
288         VID_CheckMultitexture();
289         VID_CheckVertexArrays();
290
291         // LordHavoc: report supported extensions
292         Con_Printf ("\nQSG extensions: %s\n", QSG_EXTENSIONS);
293
294         glCullFace(GL_FRONT);
295         glEnable(GL_TEXTURE_2D);
296 //      glDisable(GL_ALPHA_TEST);
297         glAlphaFunc(GL_GREATER, 0.5);
298
299 //      glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
300
301         Palette_Init();
302 }
303
304
305 /*
306 void R_RotateForEntity (entity_t *e)
307 {
308         glTranslatef (e->origin[0],  e->origin[1],  e->origin[2]);
309
310         glRotatef (e->angles[1],  0, 0, 1);
311         glRotatef (-e->angles[0],  0, 1, 0);
312         glRotatef (e->angles[2],  1, 0, 0);
313
314         glScalef (e->scale, e->scale, e->scale); // LordHavoc: model scale
315 }
316 */
317
318 // LordHavoc: if not for the fact BRIGHTFIELD particles require this, it would be removed...
319 #define NUMVERTEXNORMALS        162
320
321 float   r_avertexnormals[NUMVERTEXNORMALS][3] = {
322 #include "anorms.h"
323 };
324
325 // LordHavoc: shading stuff
326 vec3_t  shadevector;
327 vec3_t  shadecolor;
328
329 float   modelalpha;
330
331 //==================================================================================
332
333 void R_DrawBrushModel (entity_t *e);
334 void R_DrawSpriteModel (entity_t *e);
335
336 /*
337 =============
338 R_DrawEntitiesOnList
339 =============
340 */
341 // LordHavoc: split so bmodels are rendered before any other objects
342 void R_DrawEntitiesOnList1 (void)
343 {
344         int             i;
345
346         if (!r_drawentities.value)
347                 return;
348
349         for (i=0 ; i<cl_numvisedicts ; i++)
350         {
351                 if (cl_visedicts[i]->model->type != mod_brush)
352                         continue;
353                 currententity = cl_visedicts[i];
354                 modelalpha = currententity->alpha;
355
356                 R_DrawBrushModel (currententity);
357         }
358 }
359
360 void R_DrawEntitiesOnList2 (void)
361 {
362         int             i;
363
364         if (!r_drawentities.value)
365                 return;
366
367         for (i=0 ; i<cl_numvisedicts ; i++)
368         {
369                 currententity = cl_visedicts[i];
370                 modelalpha = currententity->alpha;
371
372                 switch (currententity->model->type)
373                 {
374                 case mod_alias:
375                         R_DrawAliasModel (currententity, true, modelalpha, currententity->model, currententity->frame, currententity->skinnum, currententity->origin, currententity->effects, currententity->model->flags, currententity->colormap);
376                         break;
377
378                 case mod_sprite:
379                         R_DrawSpriteModel (currententity);
380                         break;
381
382                 default:
383                         break;
384                 }
385         }
386 }
387
388 /*
389 =============
390 R_DrawViewModel
391 =============
392 */
393 void R_DrawViewModel (void)
394 {
395         if (!r_drawviewmodel.value || chase_active.value || envmap || !r_drawentities.value || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.model)
396                 return;
397
398         currententity = &cl.viewent;
399         currententity->alpha = modelalpha = cl_entities[cl.viewentity].alpha; // LordHavoc: if the player is transparent, so is his gun
400         currententity->effects = cl_entities[cl.viewentity].effects;
401         currententity->scale = 1;
402         VectorCopy(cl_entities[cl.viewentity].colormod, currententity->colormod);
403
404         // hack the depth range to prevent view model from poking into walls
405         glDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin));
406         R_DrawAliasModel (currententity, FALSE, modelalpha, currententity->model, currententity->frame, currententity->skinnum, currententity->origin, currententity->effects, currententity->model->flags, currententity->colormap);
407         glDepthRange (gldepthmin, gldepthmax);
408 }
409
410 void R_DrawBrushModel (entity_t *e);
411
412 void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
413
414 void R_SetFrustum (void)
415 {
416         int             i;
417
418         if (r_refdef.fov_x == 90) 
419         {
420                 // front side is visible
421
422                 VectorAdd (vpn, vright, frustum[0].normal);
423                 VectorSubtract (vpn, vright, frustum[1].normal);
424
425                 VectorAdd (vpn, vup, frustum[2].normal);
426                 VectorSubtract (vpn, vup, frustum[3].normal);
427         }
428         else
429         {
430                 // rotate VPN right by FOV_X/2 degrees
431                 RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
432                 // rotate VPN left by FOV_X/2 degrees
433                 RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
434                 // rotate VPN up by FOV_X/2 degrees
435                 RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
436                 // rotate VPN down by FOV_X/2 degrees
437                 RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
438         }
439
440         for (i=0 ; i<4 ; i++)
441         {
442                 frustum[i].type = PLANE_ANYZ;
443                 frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
444 //              frustum[i].signbits = SignbitsForPlane (&frustum[i]);
445                 BoxOnPlaneSideClassify(&frustum[i]);
446         }
447 }
448
449 void R_AnimateLight (void);
450 void V_CalcBlend (void);
451
452 /*
453 ===============
454 R_SetupFrame
455 ===============
456 */
457 void R_SetupFrame (void)
458 {
459 // don't allow cheats in multiplayer
460         if (cl.maxclients > 1)
461         {
462                 Cvar_Set ("r_fullbright", "0");
463                 Cvar_Set ("r_ambient", "0");
464         }
465
466         R_AnimateLight ();
467
468         r_framecount++;
469
470 // build the transformation matrix for the given view angles
471         VectorCopy (r_refdef.vieworg, r_origin);
472
473         AngleVectors (r_refdef.viewangles, vpn, vright, vup);
474
475 // current viewleaf
476         r_oldviewleaf = r_viewleaf;
477         r_viewleaf = Mod_PointInLeaf (r_origin, cl.worldmodel);
478
479         V_SetContentsColor (r_viewleaf->contents);
480         V_CalcBlend ();
481
482         r_cache_thrash = false;
483
484         c_brush_polys = 0;
485         c_alias_polys = 0;
486         c_light_polys = 0;
487         c_nodes = 0;
488         c_leafs = 0;
489
490 }
491
492
493 void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar )
494 {
495    GLdouble xmin, xmax, ymin, ymax;
496
497    ymax = zNear * tan( fovy * M_PI / 360.0 );
498    ymin = -ymax;
499
500    xmin = ymin * aspect;
501    xmax = ymax * aspect;
502
503    glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
504 }
505
506
507 extern char skyname[];
508
509 /*
510 =============
511 R_SetupGL
512 =============
513 */
514 void R_SetupGL (void)
515 {
516         float   screenaspect;
517         extern  int glwidth, glheight;
518         int             x, x2, y2, y, w, h;
519
520         if (!r_render.value)
521                 return;
522         //
523         // set up viewpoint
524         //
525         glMatrixMode(GL_PROJECTION);
526     glLoadIdentity ();
527         x = r_refdef.vrect.x * glwidth/vid.width;
528         x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth/vid.width;
529         y = (vid.height-r_refdef.vrect.y) * glheight/vid.height;
530         y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) * glheight/vid.height;
531
532         // fudge around because of frac screen scale
533         if (x > 0)
534                 x--;
535         if (x2 < glwidth)
536                 x2++;
537         if (y2 < 0)
538                 y2--;
539         if (y < glheight)
540                 y++;
541
542         w = x2 - x;
543         h = y - y2;
544
545         if (envmap)
546         {
547                 x = y2 = 0;
548                 w = h = 256;
549         }
550
551         glViewport (glx + x, gly + y2, w, h);
552     screenaspect = (float)r_refdef.vrect.width/r_refdef.vrect.height;
553 //      yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*180/M_PI;
554 //      if (skyname[0]) // skybox enabled?
555 //              MYgluPerspective (r_refdef.fov_y,  screenaspect,  4,  r_skyboxsize.value*1.732050807569 + 256); // this is size*sqrt(3) + 256
556 //      else
557                 MYgluPerspective (r_refdef.fov_y,  screenaspect,  4,  r_farclip.value);
558
559         glCullFace(GL_FRONT);
560
561         glMatrixMode(GL_MODELVIEW);
562     glLoadIdentity ();
563
564     glRotatef (-90,  1, 0, 0);      // put Z going up
565     glRotatef (90,  0, 0, 1);       // put Z going up
566     glRotatef (-r_refdef.viewangles[2],  1, 0, 0);
567     glRotatef (-r_refdef.viewangles[0],  0, 1, 0);
568     glRotatef (-r_refdef.viewangles[1],  0, 0, 1);
569     glTranslatef (-r_refdef.vieworg[0],  -r_refdef.vieworg[1],  -r_refdef.vieworg[2]);
570
571         glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
572
573         //
574         // set drawing parms
575         //
576 //      if (gl_cull.value)
577                 glEnable(GL_CULL_FACE);
578 //      else
579 //              glDisable(GL_CULL_FACE);
580
581         glEnable(GL_BLEND); // was Disable
582         glDisable(GL_ALPHA_TEST);
583         glAlphaFunc(GL_GREATER, 0.5);
584         glEnable(GL_DEPTH_TEST);
585         glDepthMask(1);
586         glShadeModel(GL_SMOOTH);
587 }
588
589 void R_DrawWorld (void);
590 //void R_RenderDlights (void);
591 void R_DrawParticles (void);
592
593 /*
594 =============
595 R_Clear
596 =============
597 */
598 void R_Clear (void)
599 {
600         if (!r_render.value)
601                 return;
602 //      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: moved to SCR_UpdateScreen
603         gldepthmin = 0;
604         gldepthmax = 1;
605         glDepthFunc (GL_LEQUAL);
606
607         glDepthRange (gldepthmin, gldepthmax);
608 }
609
610 // LordHavoc: my trick to *FIX* GLQuake lighting once and for all :)
611 void GL_Brighten()
612 {
613         if (!r_render.value)
614                 return;
615         glMatrixMode(GL_PROJECTION);
616     glLoadIdentity ();
617         glOrtho  (0, vid.width, vid.height, 0, -99999, 99999);
618         glMatrixMode(GL_MODELVIEW);
619     glLoadIdentity ();
620         glDisable (GL_DEPTH_TEST);
621         glDisable (GL_CULL_FACE);
622         glDisable(GL_TEXTURE_2D);
623         glEnable(GL_BLEND);
624         glBlendFunc (GL_DST_COLOR, GL_ONE);
625         glBegin (GL_TRIANGLES);
626         glColor3f (1, 1, 1);
627         glVertex2f (-5000, -5000);
628         glVertex2f (10000, -5000);
629         glVertex2f (-5000, 10000);
630         glEnd ();
631         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
632         glDisable(GL_BLEND);
633         glEnable(GL_TEXTURE_2D);
634         glEnable (GL_DEPTH_TEST);
635         glEnable (GL_CULL_FACE);
636 }
637
638 extern cvar_t contrast;
639 extern cvar_t brightness;
640 extern cvar_t gl_lightmode;
641
642 void GL_BlendView()
643 {
644         if (!r_render.value)
645                 return;
646         glMatrixMode(GL_PROJECTION);
647     glLoadIdentity ();
648         glOrtho  (0, vid.width, vid.height, 0, -99999, 99999);
649         glMatrixMode(GL_MODELVIEW);
650     glLoadIdentity ();
651         glDisable (GL_DEPTH_TEST);
652         glDisable (GL_CULL_FACE);
653         glDisable(GL_TEXTURE_2D);
654         glEnable(GL_BLEND);
655         if (lighthalf)
656         {
657                 glBlendFunc (GL_DST_COLOR, GL_ONE);
658                 glBegin (GL_TRIANGLES);
659                 glColor3f (1, 1, 1);
660                 glVertex2f (-5000, -5000);
661                 glVertex2f (10000, -5000);
662                 glVertex2f (-5000, 10000);
663                 glEnd ();
664         }
665         glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
666         contrast.value = bound(0.2, contrast.value, 1.0);
667         if (/*gl_polyblend.value && */v_blend[3])
668         {
669                 glBegin (GL_TRIANGLES);
670                 glColor4fv (v_blend);
671                 glVertex2f (-5000, -5000);
672                 glVertex2f (10000, -5000);
673                 glVertex2f (-5000, 10000);
674                 glEnd ();
675         }
676
677         glEnable (GL_CULL_FACE);
678         glEnable (GL_DEPTH_TEST);
679         glDisable(GL_BLEND);
680         glEnable(GL_TEXTURE_2D);
681 }
682
683 #define TIMEREPORT(DESC) \
684         if (r_speeds2.value)\
685         {\
686                 temptime = -currtime;\
687                 currtime = Sys_FloatTime();\
688                 temptime += currtime;\
689                 Con_Printf(DESC " %.4fms ", temptime * 1000.0);\
690         }
691
692 /*
693 ================
694 R_RenderView
695
696 r_refdef must be set before the first call
697 ================
698 */
699 extern qboolean intimerefresh;
700 extern qboolean skyisvisible;
701 extern void R_Sky();
702 extern void UploadLightmaps();
703 void R_RenderView (void)
704 {
705 //      double currtime, temptime;
706 //      if (r_norefresh.value)
707 //              return;
708
709         if (!r_worldentity.model || !cl.worldmodel)
710                 Sys_Error ("R_RenderView: NULL worldmodel");
711
712         lighthalf = gl_lightmode.value;
713
714         FOG_framebegin();
715
716 //      if (r_speeds2.value)
717 //      {
718 //              currtime = Sys_FloatTime();
719 //              Con_Printf("render time: ");
720 //      }
721         R_Clear();
722 //      TIMEREPORT("R_Clear")
723
724         // render normal view
725
726         R_SetupFrame ();
727         R_SetFrustum ();
728         R_SetupGL ();
729
730         skypolyclear();
731         wallpolyclear();
732         transpolyclear();
733         skyisvisible = false;
734
735         R_MarkLeaves ();        // done here so we know if we're in water
736         R_DrawWorld ();         // adds static entities to the list
737         if (!intimerefresh)
738                 S_ExtraUpdate ();       // don't let sound get messed up if going slow
739         R_DrawEntitiesOnList1 (); // BSP models
740
741         skypolyrender(); // fogged sky polys, affects depth
742         if (skyname[0] && skyisvisible && !fogenabled)
743                 R_Sky(); // does not affect depth, draws over the sky polys
744
745         UploadLightmaps();
746         wallpolyrender();
747
748         R_DrawEntitiesOnList2 (); // other models
749 //      R_RenderDlights ();
750         R_DrawViewModel ();
751         R_DrawParticles ();
752
753         transpolyrender();
754
755         FOG_frameend();
756         GL_BlendView();
757 //      if (r_speeds2.value)
758 //              Con_Printf("\n");
759 }