From: havoc Date: Tue, 18 May 2004 21:04:59 +0000 (+0000) Subject: Tomaz added support for loading a cubemap as skybox X-Git-Tag: xonotic-v0.1.0preview~5858 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6f9648053b91bc82a2d0ae0e982ddd9f764b4f75;p=xonotic%2Fdarkplaces.git Tomaz added support for loading a cubemap as skybox git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4192 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/r_sky.c b/r_sky.c index f70477e5..5e76d2a1 100644 --- a/r_sky.c +++ b/r_sky.c @@ -15,7 +15,33 @@ static int skyrendersphere; static int skyrenderbox; static rtexturepool_t *skytexturepool; static char skyname[256]; -static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; + +typedef struct suffixinfo_s +{ + char *suffix; + qboolean flipx, flipy, flipdiagonal; +} +suffixinfo_t; +static suffixinfo_t suffix[2][6] = +{ + { + {"rt", false, false, false}, + {"bk", false, false, false}, + {"lf", false, false, false}, + {"ft", false, false, false}, + {"up", false, false, false}, + {"dn", false, false, false}, + }, + { + {"px", false, true, true}, + {"ny", false, false, false}, + {"nx", true, false, true}, + {"py", true, true, false}, + {"pz", false, true, true}, + {"nz", false, true, true} + } +}; + static rtexture_t *skyboxside[6]; void R_SkyStartFrame(void) @@ -48,36 +74,54 @@ void R_UnloadSkyBox(void) { if (skyboxside[i]) R_FreeTexture(skyboxside[i]); - skyboxside[i] = NULL;; + skyboxside[i] = NULL; } } void R_LoadSkyBox(void) { - int i; + int i, j; + int indices[4] = {0,1,2,3}; char name[1024]; qbyte *image_rgba; + qbyte *temp; R_UnloadSkyBox(); if (!skyname[0]) return; - for (i = 0;i < 6;i++) + + for (j=0; j<2; j++) { - if (snprintf(name, sizeof(name), "%s_%s", skyname, suf[i]) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + for (i=0; i<6; i++) { - if (snprintf(name, sizeof(name), "%s%s", skyname, suf[i]) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + if (snprintf(name, sizeof(name), "%s_%s", skyname, suffix[j][i].suffix) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) { - if (snprintf(name, sizeof(name), "env/%s%s", skyname, suf[i]) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + if (snprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) { - if (snprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suf[i]) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + if (snprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) { - Con_Printf("Couldn't load %s_%s or %s%s or env/%s%s or gfx/env/%s%s\n", skyname, suf[i], skyname, suf[i], skyname, suf[i], skyname, suf[i]); - continue; + if (snprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) >= (int)sizeof(name) || !(image_rgba = loadimagepixels(name, false, 0, 0))) + continue; } } } + temp = 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); + Mem_Free(temp); } - skyboxside[i] = R_LoadTexture2D(skytexturepool, va("skyboxside%d", i), image_width, image_height, image_rgba, TEXTYPE_RGBA, TEXF_CLAMP | TEXF_PRECACHE, NULL); - Mem_Free(image_rgba); + + for (i=0; i<6; i++) + { + if (skyboxside[i] == NULL) + { + R_UnloadSkyBox(); + break; + } + } + + if (skyboxside[0] != NULL) + return; } }