+//static char *suffix[6] = {"ft", "bk", "rt", "lf", "up", "dn"};
+typedef struct suffixinfo
+{
+ char *suffix;
+ int flipx, flipy, flipdiagonal;
+}
+suffixinfo_t;
+static suffixinfo_t suffix[3][6] =
+{
+ {
+ {"posx", false, false, false},
+ {"negx", false, false, false},
+ {"posy", false, false, false},
+ {"negy", false, false, false},
+ {"posz", false, false, false},
+ {"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}
+ },
+ {
+ {"ft", true, false, true},
+ {"bk", false, true, true},
+ {"lf", true, true, false},
+ {"rt", false, false, false},
+ {"up", false, false, false},
+ {"dn", false, false, false}
+ }
+};
+
+static int componentorder[4] = {0, 1, 2, 3};
+
+rtexture_t *R_Shadow_LoadCubemap(const char *basename)
+{
+ int i, j, cubemapsize;
+ qbyte *cubemappixels, *image_rgba;
+ rtexture_t *cubemaptexture;
+ char name[256];
+ // must start 0 so the first loadimagepixels has no requested width/height
+ cubemapsize = 0;
+ cubemappixels = NULL;
+ cubemaptexture = NULL;
+ for (j = 0;j < 3 && !cubemappixels;j++)
+ {
+ for (i = 0;i < 6;i++)
+ {
+ snprintf(name, sizeof(name), "%s%s", basename, suffix[j][i].suffix);
+ if ((image_rgba = loadimagepixels(name, true, cubemapsize, cubemapsize)))
+ {
+ if (image_width == image_height)
+ {
+ if (!cubemappixels && image_width >= 1)
+ {
+ cubemapsize = image_width;
+ // note this clears to black, so unavailable sizes are black
+ cubemappixels = Mem_Alloc(tempmempool, 6*cubemapsize*cubemapsize*4);
+ }
+ 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);
+ Mem_Free(image_rgba);
+ }
+ }
+ }
+ if (cubemappixels)
+ {
+ if (!r_shadow_filters_texturepool)
+ r_shadow_filters_texturepool = R_AllocTexturePool();
+ cubemaptexture = R_LoadTextureCubeMap(r_shadow_filters_texturepool, basename, cubemapsize, cubemappixels, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
+ Mem_Free(cubemappixels);
+ }
+ else
+ Con_Printf("Failed to load Cubemap \"%s\"\n", basename);
+ return cubemaptexture;
+}
+
+void R_Shadow_FreeCubemaps(void)
+{
+ R_FreeTexturePool(&r_shadow_filters_texturepool);
+}