]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_sky.c
colormod values above 1 1 1 should work properly with r_glsl now
[xonotic/darkplaces.git] / r_sky.c
diff --git a/r_sky.c b/r_sky.c
index 51caa6cecb4cfb926f8744dabb02c5087b50b050..0933f939127decf48e38a0756a9f82288af1b295 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -16,11 +16,11 @@ static char skyname[MAX_QPATH];
 
 typedef struct suffixinfo_s
 {
-       char *suffix;
+       const char *suffix;
        qboolean flipx, flipy, flipdiagonal;
 }
 suffixinfo_t;
-static suffixinfo_t suffix[3][6] =
+static const suffixinfo_t suffix[3][6] =
 {
        {
                {"px",   false, false, false},
@@ -56,7 +56,7 @@ void R_SkyStartFrame(void)
        skyrendersphere = false;
        skyrenderbox = false;
        skyrendermasked = false;
-       if (r_sky.integer && !r_refdef.fogenabled)
+       if (r_sky.integer && !(r_refdef.fogenabled && r_refdef.fogmasktable[FOGMASKTABLEWIDTH-1] < (1.0f / 256.0f)))
        {
                if (skyboxside[0] || skyboxside[1] || skyboxside[2] || skyboxside[3] || skyboxside[4] || skyboxside[5])
                        skyrenderbox = true;
@@ -89,7 +89,7 @@ int R_LoadSkyBox(void)
        int i, j, success;
        int indices[4] = {0,1,2,3};
        char name[MAX_INPUTLINE];
-       unsigned char *image_rgba;
+       unsigned char *image_buffer;
        unsigned char *temp;
 
        R_UnloadSkyBox();
@@ -102,21 +102,21 @@ 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_rgba = loadimagepixels(name, false, 0, 0)))
+                       if (dpsnprintf(name, sizeof(name), "%s_%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false)))
                        {
-                               if (dpsnprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0)))
+                               if (dpsnprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false)))
                                {
-                                       if (dpsnprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0)))
+                                       if (dpsnprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false)))
                                        {
-                                               if (dpsnprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_rgba = loadimagepixels(name, false, 0, 0)))
+                                               if (dpsnprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false)))
                                                        continue;
                                        }
                                }
                        }
                        temp = (unsigned char *)Mem_Alloc(tempmempool, image_width*image_height*4);
-                       Image_CopyMux (temp, image_rgba, image_width, image_height, suffix[j][i].flipx, suffix[j][i].flipy, suffix[j][i].flipdiagonal, 4, 4, indices);
-                       skyboxside[i] = R_LoadTexture2D(skytexturepool, va("skyboxside%d", i), image_width, image_height, temp, TEXTYPE_RGBA, TEXF_CLAMP | TEXF_PRECACHE, NULL);
-                       Mem_Free(image_rgba);
+                       Image_CopyMux (temp, image_buffer, image_width, image_height, suffix[j][i].flipx, suffix[j][i].flipy, suffix[j][i].flipdiagonal, 4, 4, indices);
+                       skyboxside[i] = R_LoadTexture2D(skytexturepool, va("skyboxside%d", i), image_width, image_height, temp, TEXTYPE_BGRA, TEXF_CLAMP | TEXF_PRECACHE | (gl_texturecompression_sky.integer ? TEXF_COMPRESS : 0), NULL);
+                       Mem_Free(image_buffer);
                        Mem_Free(temp);
                        success++;
                }
@@ -175,7 +175,7 @@ void LoadSky_f (void)
        }
 }
 
-float skyboxvertex3f[6*4*3] =
+static const float skyboxvertex3f[6*4*3] =
 {
        // skyside[0]
         16, -16,  16,
@@ -209,7 +209,7 @@ float skyboxvertex3f[6*4*3] =
         16,  16, -16
 };
 
-float skyboxtexcoord2f[6*4*2] =
+static const float skyboxtexcoord2f[6*4*2] =
 {
        // skyside[0]
        0, 1,
@@ -243,7 +243,7 @@ float skyboxtexcoord2f[6*4*2] =
        0, 0
 };
 
-int skyboxelements[6*2*3] =
+static const int skyboxelements[6*2*3] =
 {
        // skyside[3]
         0,  1,  2,
@@ -271,6 +271,7 @@ static void R_SkyBox(void)
        // FIXME: fixed function path can't properly handle r_view.colorscale > 1
        GL_Color(1 * r_view.colorscale, 1 * r_view.colorscale, 1 * r_view.colorscale, 1);
        GL_BlendFunc(GL_ONE, GL_ZERO);
+       GL_CullFace(GL_NONE);
        GL_DepthMask(false);
        GL_DepthRange(0, 1);
        GL_PolygonOffset(0, 0);
@@ -285,6 +286,18 @@ static void R_SkyBox(void)
                R_Mesh_TexBind(0, R_GetTexture(skyboxside[i]));
                R_Mesh_Draw(0, 6*4, 2, skyboxelements + i * 6, 0, 0);
        }
+
+       if(r_refdef.fogenabled)
+       {
+               GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+               GL_Color(r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2], 1 - r_refdef.fogmasktable[FOGMASKTABLEWIDTH-1]);
+               for (i = 0;i < 6;i++)
+               {
+                       R_Mesh_TexBind(0, 0);
+                       R_Mesh_Draw(0, 6*4, 2, skyboxelements + i * 6, 0, 0);
+               }
+       }
+
        GL_LockArrays(0, 0);
 }
 
@@ -371,6 +384,7 @@ static void R_SkySphere(void)
        // FIXME: fixed function path can't properly handle r_view.colorscale > 1
        GL_Color(1 * r_view.colorscale, 1 * r_view.colorscale, 1 * r_view.colorscale, 1);
        GL_BlendFunc(GL_ONE, GL_ZERO);
+       GL_CullFace(GL_NONE);
        GL_DepthMask(true);
        GL_DepthRange(0, 1);
        GL_PolygonOffset(0, 0);
@@ -391,6 +405,7 @@ static void R_SkySphere(void)
                GL_LockArrays(0, skysphere_numverts);
                R_Mesh_Draw(0, skysphere_numverts, skysphere_numtriangles, skysphere_element3i, 0, 0);
                GL_LockArrays(0, 0);
+               R_Mesh_TexBind(1, 0);
        }
        else
        {
@@ -405,6 +420,16 @@ static void R_SkySphere(void)
                R_Mesh_Draw(0, skysphere_numverts, skysphere_numtriangles, skysphere_element3i, 0, 0);
                GL_LockArrays(0, 0);
        }
+
+       if(r_refdef.fogenabled)
+       {
+               R_Mesh_TexBind(0, 0);
+               GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+               GL_Color(r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2], 1 - r_refdef.fogmasktable[FOGMASKTABLEWIDTH-1]);
+               GL_LockArrays(0, skysphere_numverts);
+               R_Mesh_Draw(0, skysphere_numverts, skysphere_numtriangles, skysphere_element3i, 0, 0);
+               GL_LockArrays(0, 0);
+       }
 }
 
 void R_Sky(void)