]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_sky.c
oops... fog is now colorscaled, so handle this correctly. Now fog + HDR works again.
[xonotic/darkplaces.git] / r_sky.c
diff --git a/r_sky.c b/r_sky.c
index 837dde9f540d30fc2896510f6753fe660cf0d868..b870bdaaf83ef9fe362b9859df3e8c252d1c2c81 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -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.fog_end >= 1000000000))
        {
                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++;
                }
@@ -271,7 +271,10 @@ 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);
        GL_DepthTest(false); // don't modify or read zbuffer
        R_Mesh_VertexPointer(skyboxvertex3f, 0, 0);
        R_Mesh_ColorPointer(NULL, 0, 0);
@@ -283,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 - FogForDistance(r_refdef.fog_end));
+               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);
 }
 
@@ -369,7 +384,10 @@ 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);
        GL_DepthTest(false); // don't modify or read zbuffer
        R_Mesh_VertexPointer(skysphere_vertex3f, 0, 0);
        R_Mesh_ColorPointer(NULL, 0, 0);
@@ -387,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
        {
@@ -401,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 - FogForDistance(r_refdef.fog_end));
+               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)
@@ -429,6 +458,7 @@ void R_Sky(void)
                        //GL_Clear(GL_DEPTH_BUFFER_BIT);
                }
                */
+               GL_DepthRange(0, 1);
                GL_DepthTest(true);
                GL_DepthMask(true);
        }