]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_shadow.c
Tomaz changed skybox rendering/loading to flip skyboxes and use cubemaps directly...
[xonotic/darkplaces.git] / r_shadow.c
index 646fac0e65f1b918d3cb907013d85eb45045e8b7..20c95578f552bda8c248e6499e3921826feabb88 100644 (file)
@@ -2252,6 +2252,14 @@ typedef struct suffixinfo_s
 suffixinfo_t;
 static suffixinfo_t suffix[3][6] =
 {
+       {
+               {"px",   false, false, false},
+               {"nx",   false, false, false},
+               {"py",   false, false, false},
+               {"ny",   false, false, false},
+               {"pz",   false, false, false},
+               {"nz",   false, false, false}
+       },
        {
                {"posx", false, false, false},
                {"negx", false, false, false},
@@ -2261,20 +2269,12 @@ static suffixinfo_t suffix[3][6] =
                {"negz", false, false, false}
        },
        {
-               {"px", false, false, false},
-               {"nx", false, false, false},
-               {"py", false, false, false},
-               {"ny", false, false, false},
-               {"pz", false, false, false},
-               {"nz", false, false, false}
-       },
-       {
-               {"rt",  true, false,  true},
-               {"lf", false,  true,  true},
-               {"ft",  true,  true, false},
-               {"bk", false, false, false},
-               {"up",  true, false,  true},
-               {"dn",  true, false,  true}
+               {"rt",    true, false,  true},
+               {"lf",   false,  true,  true},
+               {"ft",    true,  true, false},
+               {"bk",   false, false, false},
+               {"up",    true, false,  true},
+               {"dn",    true, false,  true}
        }
 };
 
@@ -2290,30 +2290,39 @@ rtexture_t *R_Shadow_LoadCubemap(const char *basename)
        cubemapsize = 0;
        cubemappixels = NULL;
        cubemaptexture = NULL;
+       // keep trying different suffix groups (posx, px, rt) until one loads
        for (j = 0;j < 3 && !cubemappixels;j++)
        {
+               // load the 6 images in the suffix group
                for (i = 0;i < 6;i++)
                {
+                       // generate an image name based on the base and and suffix
                        snprintf(name, sizeof(name), "%s%s", basename, suffix[j][i].suffix);
+                       // load it
                        if ((image_rgba = loadimagepixels(name, false, cubemapsize, cubemapsize)))
                        {
+                               // an image loaded, make sure width and height are equal
                                if (image_width == image_height)
                                {
+                                       // if this is the first image to load successfully, allocate the cubemap memory
                                        if (!cubemappixels && image_width >= 1)
                                        {
                                                cubemapsize = image_width;
-                                               // note this clears to black, so unavailable sizes are black
+                                               // note this clears to black, so unavailable sides are black
                                                cubemappixels = Mem_Alloc(tempmempool, 6*cubemapsize*cubemapsize*4);
                                        }
+                                       // copy the image with any flipping needed by the suffix (px and posx types don't need flipping)
                                        if (cubemappixels)
                                                Image_CopyMux(cubemappixels+i*cubemapsize*cubemapsize*4, image_rgba, cubemapsize, cubemapsize, suffix[j][i].flipx, suffix[j][i].flipy, suffix[j][i].flipdiagonal, 4, 4, componentorder);
                                }
                                else
                                        Con_Printf("Cubemap image \"%s\" (%ix%i) is not square, OpenGL requires square cubemaps.\n", name, image_width, image_height);
+                               // free the image
                                Mem_Free(image_rgba);
                        }
                }
        }
+       // if a cubemap loaded, upload it
        if (cubemappixels)
        {
                if (!r_shadow_filters_texturepool)