]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_screen.c
minor redesign of console loading/drawing, cruft removal, change to Draw_GenericPic...
[xonotic/darkplaces.git] / gl_screen.c
index a7a03d4fc5813fff1ce416381101c33e1e2c8aba..fed3a177523daa7190799c335eb73aa2bf09768e 100644 (file)
@@ -88,7 +88,8 @@ cvar_t                scr_showram = {"showram","1"};
 cvar_t         scr_showturtle = {"showturtle","0"};
 cvar_t         scr_showpause = {"showpause","1"};
 cvar_t         scr_printspeed = {"scr_printspeed","8"};
-cvar_t         gl_triplebuffer = {"gl_triplebuffer", "1", true };
+cvar_t         showfps = {"showfps", "0", true};
+cvar_t         r_render = {"r_render", "1"};
 
 extern cvar_t  crosshair;
 
@@ -103,11 +104,9 @@ int                        scr_fullupdate;
 int                    clearconsole;
 int                    clearnotify;
 
-int                    sb_lines;
+extern int                     sb_lines;
 
-viddef_t       vid;                            // global video state
-
-vrect_t                scr_vrect;
+extern viddef_t        vid;                            // global video state
 
 qboolean       scr_disabled_for_loading;
 qboolean       scr_drawloading;
@@ -339,8 +338,6 @@ static void SCR_CalcRefdef (void)
 
        r_refdef.fov_x = scr_fov.value;
        r_refdef.fov_y = CalcFov (r_refdef.fov_x, r_refdef.vrect.width, r_refdef.vrect.height);
-
-       scr_vrect = r_refdef.vrect;
 }
 
 
@@ -373,12 +370,23 @@ void SCR_SizeDown_f (void)
 
 //============================================================================
 
+void gl_screen_start()
+{
+       scr_ram = Draw_PicFromWad ("ram");
+       scr_net = Draw_PicFromWad ("net");
+       scr_turtle = Draw_PicFromWad ("turtle");
+}
+
+void gl_screen_shutdown()
+{
+}
+
 /*
 ==================
 SCR_Init
 ==================
 */
-void SCR_Init (void)
+void GL_Screen_Init (void)
 {
 
        Cvar_RegisterVariable (&scr_fov);
@@ -389,7 +397,11 @@ void SCR_Init (void)
        Cvar_RegisterVariable (&scr_showpause);
        Cvar_RegisterVariable (&scr_centertime);
        Cvar_RegisterVariable (&scr_printspeed);
-       Cvar_RegisterVariable (&gl_triplebuffer);
+       Cvar_RegisterVariable (&showfps);
+       Cvar_RegisterVariable (&r_render);
+#ifdef NORENDER
+       r_render.value = 0;
+#endif
 
 //
 // register our commands
@@ -398,11 +410,9 @@ void SCR_Init (void)
        Cmd_AddCommand ("sizeup",SCR_SizeUp_f);
        Cmd_AddCommand ("sizedown",SCR_SizeDown_f);
 
-       scr_ram = Draw_PicFromWad ("ram");
-       scr_net = Draw_PicFromWad ("net");
-       scr_turtle = Draw_PicFromWad ("turtle");
-
        scr_initialized = true;
+
+       R_RegisterModule("GL_Screen", gl_screen_start, gl_screen_shutdown);
 }
 
 
@@ -420,7 +430,7 @@ void SCR_DrawRam (void)
        if (!r_cache_thrash)
                return;
 
-       Draw_Pic (scr_vrect.x+32, scr_vrect.y, scr_ram);
+       Draw_Pic (32, 0, scr_ram);
 }
 
 /*
@@ -445,7 +455,7 @@ void SCR_DrawTurtle (void)
        if (count < 3)
                return;
 
-       Draw_Pic (scr_vrect.x, scr_vrect.y, scr_turtle);
+       Draw_Pic (0, 0, scr_turtle);
 }
 
 /*
@@ -460,7 +470,7 @@ void SCR_DrawNet (void)
        if (cls.demoplayback)
                return;
 
-       Draw_Pic (scr_vrect.x+64, scr_vrect.y, scr_net);
+       Draw_Pic (64, 0, scr_net);
 }
 
 /*
@@ -545,18 +555,6 @@ void SCR_SetUpToDrawConsole (void)
                if (scr_conlines < scr_con_current)
                        scr_con_current = scr_conlines;
        }
-
-       /*
-       if (clearconsole++ < vid.numpages)
-       {
-               Sbar_Changed ();
-       }
-       else if (clearnotify++ < vid.numpages)
-       {
-       }
-       else
-               con_notifylines = 0;
-       */
 }
        
 /*
@@ -639,7 +637,8 @@ void SCR_ScreenShot_f (void)
        buffer[15] = glheight>>8;
        buffer[16] = 24;        // pixel size
 
-       glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer+18 ); 
+       if (r_render.value)
+               glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer+18 ); 
 
        // swap rgb to bgr
        c = 18+glwidth*glheight*3;
@@ -796,9 +795,9 @@ void SCR_BringDownConsole (void)
                SCR_UpdateScreen ();
 
        cl.cshifts[0].percent = 0;              // no area contents palette on next frame
-       VID_SetPalette (host_basepal);
 }
 
+void DrawCrosshair(int num);
 void GL_Set2D (void);
 
 extern void SHOWLMP_drawall();
@@ -809,14 +808,16 @@ extern cvar_t gl_lightmode;
 void GL_BrightenScreen()
 {
        float f;
+       if (!r_render.value)
+               return;
        glDisable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        f = brightness.value = bound(1.0f, brightness.value, 5.0f);
-       if (f > 1)
+       if (f >= 1.01f)
        {
                glBlendFunc (GL_DST_COLOR, GL_ONE);
                glBegin (GL_TRIANGLES);
-               while (f > 1)
+               while (f >= 1.01f)
                {
                        if (f >= 2)
                                glColor3f (1, 1, 1);
@@ -831,7 +832,7 @@ void GL_BrightenScreen()
        }
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        contrast.value = bound(0.2, contrast.value, 1.0);
-       if (contrast.value < 1.0f)
+       if (contrast.value < 0.99f)
        {
                glBegin (GL_TRIANGLES);
                glColor4f (1, 1, 1, 1-contrast.value);
@@ -854,32 +855,22 @@ SCR_UpdateScreen
 This is called every frame, and can also be called explicitly to flush
 text to the screen.
 
-WARNING: be very careful calling this from elsewhere, because the refresh
-needs almost the entire 256k of stack space!
+LordHavoc: due to my rewrite of R_WorldNode, it no longer takes 256k of stack space :)
 ==================
 */
 extern cvar_t gl_vertexarrays;
 extern qboolean gl_arrays;
 void GL_Finish();
-int c_nodes;
 void SCR_UpdateScreen (void)
 {
-       static float    oldscr_viewsize;
-       double  time1, time2;
+       double  time1 = 0, time2;
 
        if (r_speeds.value)
-       {
                time1 = Sys_FloatTime ();
-               c_brush_polys = 0;
-               c_alias_polys = 0;
-               c_nodes = 0;
-       }
 
        if (!gl_arrays)
                gl_vertexarrays.value = 0;
 
-       vid.numpages = 2 + gl_triplebuffer.value;
-
        scr_copytop = 0;
        scr_copyeverything = 0;
 
@@ -918,8 +909,11 @@ void SCR_UpdateScreen (void)
        if (vid.recalc_refdef)
                SCR_CalcRefdef ();
 
-       glClearColor(0,0,0,0);
-       glClear (GL_COLOR_BUFFER_BIT); // LordHavoc: clear the screen (around the view as well)
+       if (r_render.value)
+       {
+               glClearColor(0,0,0,0);
+               glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: clear the screen (around the view as well)
+       }
 
 //
 // do 3D refresh drawing, and then update the screen
@@ -954,7 +948,7 @@ void SCR_UpdateScreen (void)
        else
        {
                if (crosshair.value)
-                       Draw_Character (scr_vrect.x + scr_vrect.width/2, scr_vrect.y + scr_vrect.height/2, '+');
+                       DrawCrosshair(crosshair.value);
                
                SCR_DrawRam ();
                SCR_DrawNet ();
@@ -967,6 +961,19 @@ void SCR_UpdateScreen (void)
                M_Draw ();
        }
 
+       if (showfps.value)
+       {
+               static double currtime;
+               double newtime;
+               char temp[32];
+               int calc;
+               newtime = Sys_FloatTime();
+               calc = (int) (100.0 / (newtime - currtime));
+               sprintf(temp, "% 4i.%02i fps", calc / 100, calc % 100);
+               currtime = newtime;
+               Draw_String(vid.width - (12*8), 0, temp, 9999);
+       }
+
        V_UpdatePalette ();
 
        GL_BrightenScreen();
@@ -976,7 +983,7 @@ void SCR_UpdateScreen (void)
        if (r_speeds.value)
        {
                time2 = Sys_FloatTime ();
-               Con_Printf ("%3i ms  %4i wpoly %4i epoly %4i BSPnodes\n", (int)((time2-time1)*1000), c_brush_polys, c_alias_polys, c_nodes); 
+               Con_Printf ("%3i ms  %4i wpoly %4i epoly %4i transpoly %4i lightpoly %4i BSPnodes %4i BSPleafs\n", (int)((time2-time1)*1000), c_brush_polys, c_alias_polys, currenttranspoly, c_light_polys, c_nodes, c_leafs);
        }
        GL_EndRendering ();
 }
@@ -984,6 +991,8 @@ void SCR_UpdateScreen (void)
 // for profiling, this is seperated
 void GL_Finish()
 {
+       if (!r_render.value)
+               return;
        glFinish ();
 }