Don't allow shortcuts with Ctrl+Alt because on Windows they can be used as the AltGr...
[xonotic/darkplaces.git] / r_sky.c
diff --git a/r_sky.c b/r_sky.c
index e49ab57..7f941b4 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -6,8 +6,10 @@
 cvar_t r_sky = {CVAR_SAVE, "r_sky", "1", "enables sky rendering (black otherwise)"};
 cvar_t r_skyscroll1 = {CVAR_SAVE, "r_skyscroll1", "1", "speed at which upper clouds layer scrolls in quake sky"};
 cvar_t r_skyscroll2 = {CVAR_SAVE, "r_skyscroll2", "2", "speed at which lower clouds layer scrolls in quake sky"};
+cvar_t r_sky_scissor = {0, "r_sky_scissor", "1", "limit rendering of sky to approximately the area of the sky surfaces"};
 int skyrenderlater;
 int skyrendermasked;
+int skyscissor[4];
 
 static int skyrendersphere;
 static int skyrenderbox;
@@ -59,6 +61,8 @@ void R_SkyStartFrame(void)
        skyrendermasked = false;
        // for depth-masked sky, we need to know whether any sky was rendered
        skyrenderlater = false;
+       // we can scissor the sky to just the relevant area
+       Vector4Clear(skyscissor);
        if (r_sky.integer)
        {
                if (skyboxskinframe[0] || skyboxskinframe[1] || skyboxskinframe[2] || skyboxskinframe[3] || skyboxskinframe[4] || skyboxskinframe[5])
@@ -74,7 +78,7 @@ void R_SkyStartFrame(void)
 R_SetSkyBox
 ==================
 */
-void R_UnloadSkyBox(void)
+static void R_UnloadSkyBox(void)
 {
        int i;
        int c = 0;
@@ -91,13 +95,14 @@ void R_UnloadSkyBox(void)
                Con_Printf("unloading skybox\n");
 }
 
-int R_LoadSkyBox(void)
+static int R_LoadSkyBox(void)
 {
        int i, j, success;
        int indices[4] = {0,1,2,3};
        char name[MAX_INPUTLINE];
        unsigned char *image_buffer;
        unsigned char *temp;
+       char vabuf[1024];
 
        R_UnloadSkyBox();
 
@@ -109,20 +114,20 @@ int R_LoadSkyBox(void)
                success = 0;
                for (i=0; i<6; i++)
                {
-                       if (dpsnprintf(name, sizeof(name), "%s_%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, r_texture_convertsRGB_skybox.integer != 0, NULL)))
+                       if (dpsnprintf(name, sizeof(name), "%s_%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, false, NULL)))
                        {
-                               if (dpsnprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, r_texture_convertsRGB_skybox.integer != 0, NULL)))
+                               if (dpsnprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, false, NULL)))
                                {
-                                       if (dpsnprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, r_texture_convertsRGB_skybox.integer != 0, NULL)))
+                                       if (dpsnprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, false, NULL)))
                                        {
-                                               if (dpsnprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, r_texture_convertsRGB_skybox.integer != 0, NULL)))
+                                               if (dpsnprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, false, NULL)))
                                                        continue;
                                        }
                                }
                        }
                        temp = (unsigned char *)Mem_Alloc(tempmempool, image_width*image_height*4);
                        Image_CopyMux (temp, image_buffer, image_width, image_height, suffix[j][i].flipx, suffix[j][i].flipy, suffix[j][i].flipdiagonal, 4, 4, indices);
-                       skyboxskinframe[i] = R_SkinFrame_LoadInternalBGRA(va("skyboxside%d", i), TEXF_CLAMP | (gl_texturecompression_sky.integer ? TEXF_COMPRESS : 0), temp, image_width, image_height);
+                       skyboxskinframe[i] = R_SkinFrame_LoadInternalBGRA(va(vabuf, sizeof(vabuf), "skyboxside%d", i), TEXF_CLAMP | (gl_texturecompression_sky.integer ? TEXF_COMPRESS : 0), temp, image_width, image_height, 0, 0, 0, vid.sRGB3D);
                        Mem_Free(image_buffer);
                        Mem_Free(temp);
                        success++;
@@ -158,7 +163,7 @@ int R_SetSkyBox(const char *sky)
 }
 
 // LordHavoc: added LoadSky console command
-void LoadSky_f (void)
+static void LoadSky_f (void)
 {
        switch (Cmd_Argc())
        {
@@ -302,7 +307,8 @@ static void R_SkyBox(void)
        int i;
        RSurf_ActiveCustomEntity(&skymatrix, &skyinversematrix, 0, 0, 1, 1, 1, 1, 6*4, skyboxvertex3f, skyboxtexcoord2f, NULL, NULL, NULL, NULL, 6*2, skyboxelement3i, skyboxelement3s, false, false);
        for (i = 0;i < 6;i++)
-               R_DrawCustomSurface(skyboxskinframe[i], &identitymatrix, MATERIALFLAG_SKY | MATERIALFLAG_FULLBRIGHT | MATERIALFLAG_NOCULLFACE | MATERIALFLAG_NODEPTHTEST, i*4, 4, i*2, 2, false, false);
+               if(skyboxskinframe[i])
+                       R_DrawCustomSurface(skyboxskinframe[i], &identitymatrix, MATERIALFLAG_SKY | MATERIALFLAG_FULLBRIGHT | MATERIALFLAG_NOCULLFACE | MATERIALFLAG_NODEPTHTEST, i*4, 4, i*2, 2, false, false);
 }
 
 #define skygridx 32
@@ -399,6 +405,14 @@ void R_Sky(void)
        Matrix4x4_CreateFromQuakeEntity(&skymatrix, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], 0, 0, 0, r_refdef.farclip * (0.5f / 16.0f));
        Matrix4x4_Invert_Simple(&skyinversematrix, &skymatrix);
 
+       if (r_sky_scissor.integer)
+       {
+               // if the scissor is empty just return
+               if (skyscissor[2] == 0 || skyscissor[3] == 0)
+                       return;
+               GL_Scissor(skyscissor[0], skyscissor[1], skyscissor[2], skyscissor[3]);
+               GL_ScissorTest(true);
+       }
        if (skyrendersphere)
        {
                // this does not modify depth buffer
@@ -418,6 +432,7 @@ void R_Sky(void)
                //GL_Clear(GL_DEPTH_BUFFER_BIT);
        }
        */
+       GL_Scissor(0, 0, vid.width, vid.height);
 }
 
 //===============================================================
@@ -452,8 +467,9 @@ void R_Sky_Init(void)
        Cvar_RegisterVariable (&r_sky);
        Cvar_RegisterVariable (&r_skyscroll1);
        Cvar_RegisterVariable (&r_skyscroll2);
+       Cvar_RegisterVariable (&r_sky_scissor);
        memset(&skyboxskinframe, 0, sizeof(skyboxskinframe));
        skyname[0] = 0;
-       R_RegisterModule("R_Sky", r_sky_start, r_sky_shutdown, r_sky_newmap);
+       R_RegisterModule("R_Sky", r_sky_start, r_sky_shutdown, r_sky_newmap, NULL, NULL);
 }