]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_screen.c
honor alpha in showsurfaces 3
[xonotic/darkplaces.git] / cl_screen.c
index 3da12a252d65d560406f3e7f7720d8046d2daaeb..546e34de3cf41e78fdfaa920c0dd885a93f7a8d3 100644 (file)
@@ -41,6 +41,7 @@ cvar_t cl_capturevideo_fps = {CVAR_SAVE, "cl_capturevideo_fps", "30", "how many
 cvar_t cl_capturevideo_nameformat = {CVAR_SAVE, "cl_capturevideo_nameformat", "dpvideo", "prefix for saved videos (the date is encoded using strftime escapes)"};
 cvar_t cl_capturevideo_number = {CVAR_SAVE, "cl_capturevideo_number", "1", "number to append to video filename, incremented each time a capture begins"};
 cvar_t cl_capturevideo_ogg = {CVAR_SAVE, "cl_capturevideo_ogg", "1", "save captured video data as Ogg/Vorbis/Theora streams"};
+cvar_t cl_capturevideo_framestep = {CVAR_SAVE, "cl_capturevideo_framestep", "1", "when set to n >= 1, render n frames to capture one (useful for motion blur like effects)"};
 cvar_t r_letterbox = {0, "r_letterbox", "0", "reduces vertical height of view to simulate a letterboxed movie effect (can be used by mods for cutscenes)"};
 cvar_t r_stereo_separation = {0, "r_stereo_separation", "4", "separation distance of eyes in the world (negative values are only useful for cross-eyed viewing)"};
 cvar_t r_stereo_sidebyside = {0, "r_stereo_sidebyside", "0", "side by side views for those who can't afford glasses but can afford eye strain (note: use a negative r_stereo_separation if you want cross-eyed viewing)"};
@@ -59,6 +60,7 @@ cvar_t cl_demo_mousegrab = {0, "cl_demo_mousegrab", "0", "Allows reading the mou
 
 extern cvar_t r_glsl;
 extern cvar_t v_glslgamma;
+extern cvar_t sbar_info_pos;
 #define WANT_SCREENSHOT_HWGAMMA (scr_screenshot_hwgamma.integer && !(r_glsl.integer && v_glslgamma.integer))
 
 int jpeg_supported = false;
@@ -305,7 +307,7 @@ void SCR_DrawNetGraph (void)
 
        index = 0;
        netgraph_x = (vid_conwidth.integer + separator2) - (1 + (index % netgraphsperrow)) * (barwidth * NETGRAPH_PACKETS * 2 + separator1 + separator2);
-       netgraph_y = (vid_conheight.integer - 48 + separator2) - (1 + (index / netgraphsperrow)) * (barheight + textsize + separator2);
+       netgraph_y = (vid_conheight.integer - 48 - sbar_info_pos.integer + separator2) - (1 + (index / netgraphsperrow)) * (barheight + textsize + separator2);
        SCR_DrawNetGraph_DrawConnection_Client(cls.netcon, netgraph_x, netgraph_y, barwidth, barheight, bardivide, "incoming", separator1, "outgoing", textsize);
        index++;
 
@@ -743,6 +745,7 @@ void R_TimeReport_EndFrame(void)
        int i, j, lines, y;
        cl_locnode_t *loc;
        char string[1024+4096];
+       mleaf_t *viewleaf;
 
        string[0] = 0;
        if (r_speeds.integer && cls.signon == SIGNONS && cls.state == ca_connected)
@@ -750,12 +753,13 @@ void R_TimeReport_EndFrame(void)
                // put the location name in the r_speeds display as it greatly helps
                // when creating loc files
                loc = CL_Locs_FindNearest(cl.movement_origin);
+               viewleaf = (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.PointInLeaf) ? r_refdef.scene.worldmodel->brush.PointInLeaf(r_refdef.scene.worldmodel, r_refdef.view.origin) : NULL;
                dpsnprintf(string, sizeof(string),
 "%s%s\n"
 "%3i renders org:'%+8.2f %+8.2f %+8.2f' dir:'%+2.3f %+2.3f %+2.3f'\n"
 "%7i surfaces%7i triangles %5i entities (%7i surfaces%7i triangles)\n"
 "%5i leafs%5i portals%6i/%6i particles%6i/%6i decals %3i%% quality\n"
-"%7i lightmap updates (%7i pixels)\n"
+"%7i lightmap updates (%7i pixels)%s\n"
 "%4i lights%4i clears%4i scissored%7i light%7i shadow%7i dynamic\n"
 "rendered%6i meshes%8i triangles bloompixels%8i copied%8i drawn\n"
 "%s"
@@ -763,7 +767,7 @@ void R_TimeReport_EndFrame(void)
 , r_refdef.stats.renders, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], r_refdef.view.forward[0], r_refdef.view.forward[1], r_refdef.view.forward[2]
 , r_refdef.stats.world_surfaces, r_refdef.stats.world_triangles, r_refdef.stats.entities, r_refdef.stats.entities_surfaces, r_refdef.stats.entities_triangles
 , r_refdef.stats.world_leafs, r_refdef.stats.world_portals, r_refdef.stats.particles, cl.num_particles, r_refdef.stats.decals, cl.num_decals, (int)(100 * r_refdef.view.quality)
-, r_refdef.stats.lightmapupdates, r_refdef.stats.lightmapupdatepixels
+, r_refdef.stats.lightmapupdates, r_refdef.stats.lightmapupdatepixels, viewleaf ? va(" clusterindex%6i", viewleaf->clusterindex) : ""
 , r_refdef.stats.lights, r_refdef.stats.lights_clears, r_refdef.stats.lights_scissored, r_refdef.stats.lights_lighttriangles, r_refdef.stats.lights_shadowtriangles, r_refdef.stats.lights_dynamicshadowtriangles
 , r_refdef.stats.meshes, r_refdef.stats.meshes_elements / 3, r_refdef.stats.bloom_copypixels, r_refdef.stats.bloom_drawpixels
 , r_speeds_timestring);
@@ -867,6 +871,7 @@ void CL_Screen_Init(void)
        Cvar_RegisterVariable (&cl_capturevideo_nameformat);
        Cvar_RegisterVariable (&cl_capturevideo_number);
        Cvar_RegisterVariable (&cl_capturevideo_ogg);
+       Cvar_RegisterVariable (&cl_capturevideo_framestep);
        Cvar_RegisterVariable (&r_letterbox);
        Cvar_RegisterVariable(&r_stereo_separation);
        Cvar_RegisterVariable(&r_stereo_sidebyside);
@@ -975,7 +980,8 @@ void SCR_CaptureVideo_BeginVideo(void)
        cls.capturevideo.width = width;
        cls.capturevideo.height = height;
        cls.capturevideo.active = true;
-       cls.capturevideo.framerate = bound(1, cl_capturevideo_fps.value, 1001);
+       cls.capturevideo.framerate = bound(1, cl_capturevideo_fps.value, 1001) * bound(1, cl_capturevideo_framestep.integer, 64);
+       cls.capturevideo.framestep = cl_capturevideo_framestep.integer;
        cls.capturevideo.soundrate = S_GetSoundRate();
        cls.capturevideo.soundchannels = S_GetSoundChannels();
        cls.capturevideo.startrealtime = realtime;
@@ -1029,22 +1035,23 @@ Cr = R *  .500 + G * -.419 + B * -.0813 + 128.;
                r = 255*cls.capturevideo.vidramp[i]/65535.0;
                g = 255*cls.capturevideo.vidramp[i+256]/65535.0;
                b = 255*cls.capturevideo.vidramp[i+512]/65535.0;
+               // NOTE: we have to round DOWN here, or integer overflows happen. Sorry for slightly wrong looking colors sometimes...
                // Y weights from RGB
-               cls.capturevideo.rgbtoyuvscaletable[0][0][i] = (short)(r *  0.299 + 0.5);
-               cls.capturevideo.rgbtoyuvscaletable[0][1][i] = (short)(g *  0.587 + 0.5);
-               cls.capturevideo.rgbtoyuvscaletable[0][2][i] = (short)(b *  0.114 + 0.5);
+               cls.capturevideo.rgbtoyuvscaletable[0][0][i] = (short)(r *  0.299);
+               cls.capturevideo.rgbtoyuvscaletable[0][1][i] = (short)(g *  0.587);
+               cls.capturevideo.rgbtoyuvscaletable[0][2][i] = (short)(b *  0.114);
                // Cb weights from RGB
-               cls.capturevideo.rgbtoyuvscaletable[1][0][i] = (short)(r * -0.169 + 0.5);
-               cls.capturevideo.rgbtoyuvscaletable[1][1][i] = (short)(g * -0.332 + 0.5);
-               cls.capturevideo.rgbtoyuvscaletable[1][2][i] = (short)(b *  0.500 + 0.5);
+               cls.capturevideo.rgbtoyuvscaletable[1][0][i] = (short)(r * -0.169);
+               cls.capturevideo.rgbtoyuvscaletable[1][1][i] = (short)(g * -0.332);
+               cls.capturevideo.rgbtoyuvscaletable[1][2][i] = (short)(b *  0.500);
                // Cr weights from RGB
-               cls.capturevideo.rgbtoyuvscaletable[2][0][i] = (short)(r *  0.500 + 0.5);
-               cls.capturevideo.rgbtoyuvscaletable[2][1][i] = (short)(g * -0.419 + 0.5);
-               cls.capturevideo.rgbtoyuvscaletable[2][2][i] = (short)(b * -0.0813 + 0.5);
+               cls.capturevideo.rgbtoyuvscaletable[2][0][i] = (short)(r *  0.500);
+               cls.capturevideo.rgbtoyuvscaletable[2][1][i] = (short)(g * -0.419);
+               cls.capturevideo.rgbtoyuvscaletable[2][2][i] = (short)(b * -0.0813);
                // range reduction of YCbCr to valid signal range
-               cls.capturevideo.yuvnormalizetable[0][i] = 16 + i * (236-16) / 256 + 0.5;
-               cls.capturevideo.yuvnormalizetable[1][i] = 16 + i * (240-16) / 256 + 0.5;
-               cls.capturevideo.yuvnormalizetable[2][i] = 16 + i * (240-16) / 256 + 0.5;
+               cls.capturevideo.yuvnormalizetable[0][i] = 16 + i * (236-16) / 256;
+               cls.capturevideo.yuvnormalizetable[1][i] = 16 + i * (240-16) / 256;
+               cls.capturevideo.yuvnormalizetable[2][i] = 16 + i * (240-16) / 256;
        }
 
        if (cl_capturevideo_ogg.integer)
@@ -1137,11 +1144,14 @@ static void SCR_ScaleDownBGRA(unsigned char *in, int inw, int inh, unsigned char
        }
 }
 
-void SCR_CaptureVideo_VideoFrame(int newframenum)
+void SCR_CaptureVideo_VideoFrame(int newframestepframenum)
 {
        int x = 0, y = 0;
        int width = cls.capturevideo.width, height = cls.capturevideo.height;
 
+       if(newframestepframenum == cls.capturevideo.framestepframe)
+               return;
+
        CHECKGLERROR
        //return SCR_ScreenShot(filename, cls.capturevideo.buffer, cls.capturevideo.buffer + vid.width * vid.height * 3, cls.capturevideo.buffer + vid.width * vid.height * 6, 0, 0, vid.width, vid.height, false, false, false, jpeg, true);
        // speed is critical here, so do saving as directly as possible
@@ -1149,8 +1159,8 @@ void SCR_CaptureVideo_VideoFrame(int newframenum)
        qglReadPixels (x, y, vid.width, vid.height, GL_BGRA, GL_UNSIGNED_BYTE, cls.capturevideo.screenbuffer);CHECKGLERROR
        SCR_ScaleDownBGRA (cls.capturevideo.screenbuffer, vid.width, vid.height, cls.capturevideo.outbuffer, width, height);
 
-       cls.capturevideo.videoframes(newframenum - cls.capturevideo.frame);
-       cls.capturevideo.frame = newframenum;
+       cls.capturevideo.videoframes(newframestepframenum - cls.capturevideo.framestepframe);
+       cls.capturevideo.framestepframe = newframestepframenum;
 
        if(cl_capturevideo_printfps.integer)
        {
@@ -1181,10 +1191,10 @@ void SCR_CaptureVideo(void)
        {
                if (!cls.capturevideo.active)
                        SCR_CaptureVideo_BeginVideo();
-               if (cls.capturevideo.framerate != cl_capturevideo_fps.value)
+               if (cls.capturevideo.framerate != cl_capturevideo_fps.value * cl_capturevideo_framestep.integer)
                {
                        Con_Printf("You can not change the video framerate while recording a video.\n");
-                       Cvar_SetValueQuick(&cl_capturevideo_fps, cls.capturevideo.framerate);
+                       Cvar_SetValueQuick(&cl_capturevideo_fps, cls.capturevideo.framerate / (double) cl_capturevideo_framestep.integer);
                }
                // for AVI saving we have to make sure that sound is saved before video
                if (cls.capturevideo.soundrate && !cls.capturevideo.soundsampleframe)
@@ -1205,7 +1215,8 @@ void SCR_CaptureVideo(void)
                        return;
                }
                // write frames
-               SCR_CaptureVideo_VideoFrame(newframenum);
+               SCR_CaptureVideo_VideoFrame(newframenum / cls.capturevideo.framestep);
+               cls.capturevideo.frame = newframenum;
                if (cls.capturevideo.error)
                {
                        Cvar_SetValueQuick(&cl_capturevideo, 0);
@@ -1619,7 +1630,63 @@ typedef struct loadingscreenstack_s
 }
 loadingscreenstack_t;
 static loadingscreenstack_t *loadingscreenstack = NULL;
-static double loadingscreentime;
+static double loadingscreentime = -1;
+static qboolean loadingscreencleared = false;
+static float loadingscreenheight = 0;
+rtexture_t *loadingscreentexture = NULL;
+static float loadingscreentexture_vertex3f[12];
+static float loadingscreentexture_texcoord2f[8];
+
+static void SCR_ClearLoadingScreenTexture()
+{
+       if(loadingscreentexture)
+               R_FreeTexture(loadingscreentexture);
+       loadingscreentexture = NULL;
+}
+
+extern rtexturepool_t *r_main_texturepool;
+static void SCR_SetLoadingScreenTexture()
+{
+       int w, h;
+       float loadingscreentexture_w;
+       float loadingscreentexture_h;
+
+       SCR_ClearLoadingScreenTexture();
+
+       if (gl_support_arb_texture_non_power_of_two)
+       {
+               w = vid.width; h = vid.height;
+               loadingscreentexture_w = loadingscreentexture_h = 1;
+       }
+       else
+       {
+               w = CeilPowerOf2(vid.width); h = CeilPowerOf2(vid.height);
+               loadingscreentexture_w = vid.width / (float) w;
+               loadingscreentexture_h = vid.height / (float) h;
+       }
+
+       loadingscreentexture = R_LoadTexture2D(r_main_texturepool, "loadingscreentexture", w, h, NULL, TEXTYPE_BGRA, TEXF_FORCENEAREST | TEXF_CLAMP | TEXF_ALWAYSPRECACHE, NULL);
+       R_Mesh_TexBind(0, R_GetTexture(loadingscreentexture));
+       GL_ActiveTexture(0);
+       CHECKGLERROR
+       qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, vid.width, vid.height);CHECKGLERROR
+
+       loadingscreentexture_vertex3f[2] = loadingscreentexture_vertex3f[5] = loadingscreentexture_vertex3f[8] = loadingscreentexture_vertex3f[11] = 0;
+       loadingscreentexture_vertex3f[0] = loadingscreentexture_vertex3f[9] = 0;
+       loadingscreentexture_vertex3f[1] = loadingscreentexture_vertex3f[4] = 0;
+       loadingscreentexture_vertex3f[3] = loadingscreentexture_vertex3f[6] = vid_conwidth.integer;
+       loadingscreentexture_vertex3f[7] = loadingscreentexture_vertex3f[10] = vid_conheight.integer;
+       loadingscreentexture_texcoord2f[0] = 0;loadingscreentexture_texcoord2f[1] = loadingscreentexture_h;
+       loadingscreentexture_texcoord2f[2] = loadingscreentexture_w;loadingscreentexture_texcoord2f[3] = loadingscreentexture_h;
+       loadingscreentexture_texcoord2f[4] = loadingscreentexture_w;loadingscreentexture_texcoord2f[5] = 0;
+       loadingscreentexture_texcoord2f[6] = 0;loadingscreentexture_texcoord2f[7] = 0;
+}
+
+void SCR_UpdateLoadingScreenIfShown()
+{
+       if(realtime == loadingscreentime)
+               SCR_UpdateLoadingScreen(loadingscreencleared);
+}
 
 void SCR_PushLoadingScreen (qboolean redraw, const char *msg, float len_in_parent)
 {
@@ -1643,20 +1710,33 @@ void SCR_PushLoadingScreen (qboolean redraw, const char *msg, float len_in_paren
                s->absolute_loading_amount_len = 1;
        }
 
-       if(redraw && realtime == loadingscreentime)
-               SCR_UpdateLoadingScreen(true);
+       if(redraw)
+               SCR_UpdateLoadingScreenIfShown();
 }
 
 void SCR_PopLoadingScreen (qboolean redraw)
 {
        loadingscreenstack_t *s = loadingscreenstack;
+
+       if(!s)
+       {
+               Con_DPrintf("Popping a loading screen item from an empty stack!\n");
+               return;
+       }
+
        loadingscreenstack = s->prev;
        if(s->prev)
                s->prev->relative_completion = (s->absolute_loading_amount_min + s->absolute_loading_amount_len - s->prev->absolute_loading_amount_min) / s->prev->absolute_loading_amount_len;
        Z_Free(s);
 
-       if(redraw && realtime == loadingscreentime)
-               SCR_UpdateLoadingScreen(true);
+       if(redraw)
+               SCR_UpdateLoadingScreenIfShown();
+}
+
+void SCR_ClearLoadingScreen (qboolean redraw)
+{
+       while(loadingscreenstack)
+               SCR_PopLoadingScreen(redraw && !loadingscreenstack->prev);
 }
 
 static float SCR_DrawLoadingStack_r(loadingscreenstack_t *s, float y)
@@ -1667,60 +1747,79 @@ static float SCR_DrawLoadingStack_r(loadingscreenstack_t *s, float y)
        float total;
 
        total = 0;
+#if 0
        if(s)
        {
+               total += SCR_DrawLoadingStack_r(s->prev, y);
+               y -= total;
                if(!s->prev || strcmp(s->msg, s->prev->msg))
                {
                        len = strlen(s->msg);
                        x = (vid_conwidth.integer - DrawQ_TextWidth_Font(s->msg, len, true, FONT_INFOBAR) * size) / 2;
                        y -= size;
+                       DrawQ_Fill(0, y, vid_conwidth.integer, size, 0, 0, 0, 1, 0);
                        DrawQ_String_Font(x, y, s->msg, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
                        total += size;
                }
-               total += SCR_DrawLoadingStack_r(s->prev, y);
        }
+#else
+       if(s)
+       {
+               len = strlen(s->msg);
+               x = (vid_conwidth.integer - DrawQ_TextWidth_Font(s->msg, len, true, FONT_INFOBAR) * size) / 2;
+               y -= size;
+               DrawQ_Fill(0, y, vid_conwidth.integer, size, 0, 0, 0, 1, 0);
+               DrawQ_String_Font(x, y, s->msg, len, size, size, 1, 1, 1, 1, 0, NULL, true, FONT_INFOBAR);
+               total += size;
+       }
+#endif
        return total;
 }
 
 static void SCR_DrawLoadingStack()
 {
-       float height;
        float verts[12];
        float colors[16];
-       height = SCR_DrawLoadingStack_r(loadingscreenstack, vid_conheight.integer);
+       int i;
+
+       loadingscreenheight = SCR_DrawLoadingStack_r(loadingscreenstack, vid_conheight.integer);
        if(loadingscreenstack)
        {
-               // height = 32; // sorry, using the normal one is ugly
-               //DrawQ_Fill((vid_conwidth.integer + 2) * loadingscreenstack->absolute_loading_amount_min - 2, vid_conheight.integer - height, 2, height, 1, 0, 0, 1, DRAWFLAG_ADDITIVE);
+               // height = 32; // sorry, using the actual one is ugly
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
-               GL_Color(1, 1, 1, 1);
+               GL_DepthRange(0, 1);
+               GL_PolygonOffset(0, 0);
+               GL_DepthTest(false);
                R_Mesh_VertexPointer(verts, 0, 0);
                R_Mesh_ColorPointer(colors, 0, 0);
                R_Mesh_ResetTextureState();
                R_SetupGenericShader(false);
                verts[2] = verts[5] = verts[8] = verts[11] = 0;
-               verts[0] = verts[9] = (vid_conwidth.integer + 2) * loadingscreenstack->absolute_loading_amount_min - 2;
-               verts[1] = verts[4] = vid_conheight.integer - 32;
-               verts[3] = verts[6] = (vid_conwidth.integer + 2) * loadingscreenstack->absolute_loading_amount_min;
+               verts[0] = verts[9] = 0;
+               verts[1] = verts[4] = vid_conheight.integer - 8;
+               verts[3] = verts[6] = vid_conwidth.integer * loadingscreenstack->absolute_loading_amount_min;
                verts[7] = verts[10] = vid_conheight.integer;
-               colors[0] = colors[1] = colors[2] = colors[4] = colors[5] = colors[6] = colors[8] = colors[9] = colors[10] = colors[11] = colors[12] = colors[13] = colors[14] = colors[15] = 1;
-               colors[3] = colors[7] = 0;
+
+               for(i = 0; i < 16; ++i)
+                       colors[i] = (i % 4 == 3) ? 1 : (i >= 8 && i % 4 == 2) ? 1 : 0;
+                       //                                        ^^^^^^^^^^ blue component
+                       //                              ^^^^^^ bottom row
+                       //          ^^^^^^^^^^^^ alpha is always on
                R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
+
+               // make sure everything is cleared, including the progress indicator
+               if(loadingscreenheight < 8)
+                       loadingscreenheight = 8;
        }
 }
 
-void SCR_UpdateLoadingScreen (qboolean clear)
+static cachepic_t *loadingscreenpic;
+static float loadingscreenpic_vertex3f[12];
+static float loadingscreenpic_texcoord2f[8];
+
+static void SCR_DrawLoadingScreen_SharedSetup (qboolean clear)
 {
        float x, y;
-       cachepic_t *pic;
-       float vertex3f[12];
-       float texcoord2f[8];
-
-       loadingscreentime = realtime;
-
-       // don't do anything if not initialized yet
-       if (vid_hidden || !scr_refresh.integer)
-               return;
        // release mouse grab while loading
        if (!vid.fullscreen)
                VID_SetMouse(false, false, false);
@@ -1732,61 +1831,108 @@ void SCR_UpdateLoadingScreen (qboolean clear)
        qglClearColor(0,0,0,0);CHECKGLERROR
        // when starting up a new video mode, make sure the screen is cleared to black
        if (clear)
-       {
                qglClear(GL_COLOR_BUFFER_BIT);CHECKGLERROR
-       }
-       //qglDisable(GL_CULL_FACE);CHECKGLERROR
-       //R_ClearScreen();
        R_Textures_Frame();
        GL_SetupView_Mode_Ortho(0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100);
        R_Mesh_Start();
        R_Mesh_Matrix(&identitymatrix);
        // draw the loading plaque
-       pic = Draw_CachePic ("gfx/loading");
-       x = (vid_conwidth.integer - pic->width)/2;
-       y = (vid_conheight.integer - pic->height)/2;
+       loadingscreenpic = Draw_CachePic ("gfx/loading");
+       x = (vid_conwidth.integer - loadingscreenpic->width)/2;
+       y = (vid_conheight.integer - loadingscreenpic->height)/2;
+       loadingscreenpic_vertex3f[2] = loadingscreenpic_vertex3f[5] = loadingscreenpic_vertex3f[8] = loadingscreenpic_vertex3f[11] = 0;
+       loadingscreenpic_vertex3f[0] = loadingscreenpic_vertex3f[9] = x;
+       loadingscreenpic_vertex3f[1] = loadingscreenpic_vertex3f[4] = y;
+       loadingscreenpic_vertex3f[3] = loadingscreenpic_vertex3f[6] = x + loadingscreenpic->width;
+       loadingscreenpic_vertex3f[7] = loadingscreenpic_vertex3f[10] = y + loadingscreenpic->height;
+       loadingscreenpic_texcoord2f[0] = 0;loadingscreenpic_texcoord2f[1] = 0;
+       loadingscreenpic_texcoord2f[2] = 1;loadingscreenpic_texcoord2f[3] = 0;
+       loadingscreenpic_texcoord2f[4] = 1;loadingscreenpic_texcoord2f[5] = 1;
+       loadingscreenpic_texcoord2f[6] = 0;loadingscreenpic_texcoord2f[7] = 1;
+}
+
+static void SCR_DrawLoadingScreen (qboolean clear)
+{
+       // we only need to draw the image if it isn't already there
        GL_Color(1,1,1,1);
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        GL_DepthRange(0, 1);
        GL_PolygonOffset(0, 0);
        GL_DepthTest(false);
-       R_Mesh_VertexPointer(vertex3f, 0, 0);
+       R_SetupGenericShader(true);
        R_Mesh_ColorPointer(NULL, 0, 0);
+       if(loadingscreentexture)
+       {
+               R_Mesh_VertexPointer(loadingscreentexture_vertex3f, 0, 0);
+               R_Mesh_ResetTextureState();
+               R_Mesh_TexBind(0, R_GetTexture(loadingscreentexture));
+               R_Mesh_TexCoordPointer(0, 2, loadingscreentexture_texcoord2f, 0, 0);
+               R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
+       }
+       R_Mesh_VertexPointer(loadingscreenpic_vertex3f, 0, 0);
        R_Mesh_ResetTextureState();
-       R_Mesh_TexBind(0, R_GetTexture(pic->tex));
-       R_Mesh_TexCoordPointer(0, 2, texcoord2f, 0, 0);
-       R_SetupGenericShader(true);
-       vertex3f[2] = vertex3f[5] = vertex3f[8] = vertex3f[11] = 0;
-       vertex3f[0] = vertex3f[9] = x;
-       vertex3f[1] = vertex3f[4] = y;
-       vertex3f[3] = vertex3f[6] = x + pic->width;
-       vertex3f[7] = vertex3f[10] = y + pic->height;
-       texcoord2f[0] = 0;texcoord2f[1] = 0;
-       texcoord2f[2] = 1;texcoord2f[3] = 0;
-       texcoord2f[4] = 1;texcoord2f[5] = 1;
-       texcoord2f[6] = 0;texcoord2f[7] = 1;
+       R_Mesh_TexBind(0, R_GetTexture(loadingscreenpic->tex));
+       R_Mesh_TexCoordPointer(0, 2, loadingscreenpic_texcoord2f, 0, 0);
+       R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
+       SCR_DrawLoadingStack();
+}
+
+static void SCR_DrawLoadingScreen_SharedFinish (qboolean clear)
+{
+       R_Mesh_Finish();
+       // refresh
+       VID_Finish();
+       // however this IS necessary on Windows Vista
+       qglFinish();
+}
+
+void SCR_UpdateLoadingScreen (qboolean clear)
+{
+       keydest_t       old_key_dest;
+       int                     old_key_consoleactive;
+
+       // don't do anything if not initialized yet
+       if (vid_hidden || !scr_refresh.integer || cls.state == ca_dedicated)
+               return;
+       
+       if(loadingscreentime == realtime)
+               clear |= loadingscreencleared;
+
+       if(clear)
+               SCR_ClearLoadingScreenTexture();
+       else if(loadingscreentime != realtime)
+               SCR_SetLoadingScreenTexture();
 
+       if(loadingscreentime != realtime)
+       {
+               loadingscreentime = realtime;
+               loadingscreenheight = 0;
+       }
+       loadingscreencleared = clear;
+
+       SCR_DrawLoadingScreen_SharedSetup(clear);
        if (vid.stereobuffer)
        {
-               qglDrawBuffer(GL_FRONT_LEFT);
-               R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
-               SCR_DrawLoadingStack();
-               qglDrawBuffer(GL_FRONT_RIGHT);
-               R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
-               SCR_DrawLoadingStack();
+               qglDrawBuffer(GL_BACK_LEFT);
+               SCR_DrawLoadingScreen(clear);
+               qglDrawBuffer(GL_BACK_RIGHT);
+               SCR_DrawLoadingScreen(clear);
        }
        else
        {
-               qglDrawBuffer(GL_FRONT);
-               R_Mesh_Draw(0, 4, 0, 2, NULL, polygonelements, 0, 0);
-               SCR_DrawLoadingStack();
+               qglDrawBuffer(GL_BACK);
+               SCR_DrawLoadingScreen(clear);
        }
-       R_Mesh_Finish();
-       // refresh
-       // not necessary when rendering to GL_FRONT buffers
-       //VID_Finish();
-       // however this IS necessary on Windows Vista
-       qglFinish();
+       SCR_DrawLoadingScreen_SharedFinish(clear);
+
+       // this goes into the event loop, and should prevent unresponsive cursor on vista
+       old_key_dest = key_dest;
+       old_key_consoleactive = key_consoleactive;
+       key_dest = key_void;
+       key_consoleactive = false;
+       Sys_SendKeyEvents();
+       key_dest = old_key_dest;
+       key_consoleactive = old_key_consoleactive;
 }
 
 extern cvar_t cl_minfps;
@@ -1823,8 +1969,8 @@ void CL_UpdateScreen(void)
 
        rendertime1 = Sys_DoubleTime();
 
-       conwidth = bound(320, vid_conwidth.value, 2048);
-       conheight = bound(200, vid_conheight.value, 1536);
+       conwidth = bound(160, vid_conwidth.value, 32768);
+       conheight = bound(90, vid_conheight.value, 24576);
        if (vid_conwidth.value != conwidth)
                Cvar_SetValue("vid_conwidth", conwidth);
        if (vid_conheight.value != conheight)