X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=r_sky.c;h=17754782640d899399fe729128c639de793cb2ac;hp=6ab1f25a4ba00dc4a780c94855854b9b646a20bf;hb=46964b3848eb7471d2f0e2284ae389b4b53337c1;hpb=9f0345dcadf3d619bb98991ee2dd051787654bf5 diff --git a/r_sky.c b/r_sky.c index 6ab1f25a..17754782 100644 --- a/r_sky.c +++ b/r_sky.c @@ -1,35 +1,74 @@ #include "quakedef.h" - -cvar_t r_sky = {CVAR_SAVE, "r_sky", "1"}; -qboolean skyavailable_quake; -qboolean skyavailable_box; -int skyrendernow; +#include "image.h" + +// FIXME: fix skybox after vid_restart +cvar_t r_sky = {CVAR_SAVE, "r_sky", "1", "enables sky rendering (black otherwise)"}; +cvar_t r_skyscroll1 = {CVAR_SAVE, "r_skyscroll1", "1", "speed at which upper clouds layer scrolls in quake sky"}; +cvar_t r_skyscroll2 = {CVAR_SAVE, "r_skyscroll2", "2", "speed at which lower clouds layer scrolls in quake sky"}; +cvar_t r_sky_scissor = {0, "r_sky_scissor", "1", "limit rendering of sky to approximately the area of the sky surfaces"}; +int skyrenderlater; int skyrendermasked; +int skyscissor[4]; -static rtexture_t *solidskytexture; -static rtexture_t *alphaskytexture; static int skyrendersphere; static int skyrenderbox; static rtexturepool_t *skytexturepool; -static char skyname[256]; -static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; -static rtexture_t *skyboxside[6]; +static char skyname[MAX_QPATH]; +static matrix4x4_t skymatrix; +static matrix4x4_t skyinversematrix; + +typedef struct suffixinfo_s +{ + const char *suffix; + qboolean flipx, flipy, flipdiagonal; +} +suffixinfo_t; +static const 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}, + {"posy", false, false, false}, + {"negy", false, false, false}, + {"posz", false, false, false}, + {"negz", false, false, false} + }, + { + {"rt", false, false, true}, + {"lf", true, true, true}, + {"bk", false, true, false}, + {"ft", true, false, false}, + {"up", false, false, true}, + {"dn", false, false, true} + } +}; + +static skinframe_t *skyboxskinframe[6]; void R_SkyStartFrame(void) { - skyrendernow = false; skyrendersphere = false; skyrenderbox = false; skyrendermasked = false; - if (r_sky.integer && !fogenabled) + // for depth-masked sky, we need to know whether any sky was rendered + skyrenderlater = false; + // we can scissor the sky to just the relevant area + Vector4Clear(skyscissor); + if (r_sky.integer) { - if (skyavailable_box) + if (skyboxskinframe[0] || skyboxskinframe[1] || skyboxskinframe[2] || skyboxskinframe[3] || skyboxskinframe[4] || skyboxskinframe[5]) skyrenderbox = true; - else if (skyavailable_quake) + else if (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.solidskyskinframe) skyrendersphere = true; - // for depth-masked sky, render the sky on the first sky surface encountered - skyrendernow = true; skyrendermasked = true; } } @@ -39,55 +78,92 @@ void R_SkyStartFrame(void) R_SetSkyBox ================== */ -int R_SetSkyBox(const char *sky) +static void R_UnloadSkyBox(void) { int i; - char name[1024]; - qbyte *image_rgba; + int c = 0; + for (i = 0;i < 6;i++) + { + if (skyboxskinframe[i]) + { + // TODO: make a R_SkinFrame_Purge for single skins... + c++; + } + skyboxskinframe[i] = NULL; + } + if (c && developer_loading.integer) + Con_Printf("unloading skybox\n"); +} - if (strcmp(sky, skyname) == 0) // no change - return true; +static int R_LoadSkyBox(void) +{ + int i, j, success; + int indices[4] = {0,1,2,3}; + char name[MAX_INPUTLINE]; + unsigned char *image_buffer; + unsigned char *temp; + char vabuf[1024]; - skyboxside[0] = skyboxside[1] = skyboxside[2] = skyboxside[3] = skyboxside[4] = skyboxside[5] = NULL; - skyavailable_box = false; - skyname[0] = 0; + R_UnloadSkyBox(); - if (!sky[0]) + if (!skyname[0]) return true; - if (strlen(sky) > 1000) + for (j=0; j<3; j++) { - Con_Printf ("sky name too long (%i, max is 1000)\n", strlen(sky)); - return false; - } - - for (i = 0;i < 6;i++) - { - sprintf (name, "env/%s%s", sky, suf[i]); - if (!(image_rgba = loadimagepixels(name, false, 0, 0))) + success = 0; + for (i=0; i<6; i++) { - sprintf (name, "gfx/env/%s%s", sky, suf[i]); - if (!(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, false, NULL))) { - Con_Printf ("Couldn't load env/%s%s or gfx/env/%s%s\n", sky, suf[i], sky, suf[i]); - continue; + if (dpsnprintf(name, sizeof(name), "%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, false, NULL))) + { + if (dpsnprintf(name, sizeof(name), "env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, false, NULL))) + { + if (dpsnprintf(name, sizeof(name), "gfx/env/%s%s", skyname, suffix[j][i].suffix) < 0 || !(image_buffer = loadimagepixelsbgra(name, false, false, false, NULL))) + continue; + } + } } + temp = (unsigned char *)Mem_Alloc(tempmempool, image_width*image_height*4); + Image_CopyMux (temp, image_buffer, image_width, image_height, suffix[j][i].flipx, suffix[j][i].flipy, suffix[j][i].flipdiagonal, 4, 4, indices); + skyboxskinframe[i] = R_SkinFrame_LoadInternalBGRA(va(vabuf, sizeof(vabuf), "skyboxside%d", i), TEXF_CLAMP | (gl_texturecompression_sky.integer ? TEXF_COMPRESS : 0), temp, image_width, image_height, vid.sRGB3D); + Mem_Free(image_buffer); + Mem_Free(temp); + success++; } - skyboxside[i] = R_LoadTexture(skytexturepool, va("skyboxside%d", i), image_width, image_height, image_rgba, TEXTYPE_RGBA, TEXF_PRECACHE); - Mem_Free(image_rgba); + + if (success) + break; } - if (skyboxside[0] || skyboxside[1] || skyboxside[2] || skyboxside[3] || skyboxside[4] || skyboxside[5]) - { - skyavailable_box = true; - strcpy(skyname, sky); + if (j == 3) + return false; + + if (developer_loading.integer) + Con_Printf("loading skybox \"%s\"\n", name); + + return true; +} + +int R_SetSkyBox(const char *sky) +{ + if (strcmp(sky, skyname) == 0) // no change return true; + + if (strlen(sky) > 1000) + { + Con_Printf("sky name too long (%i, max is 1000)\n", (int)strlen(sky)); + return false; } - return false; + + strlcpy(skyname, sky, sizeof(skyname)); + + return R_LoadSkyBox(); } // LordHavoc: added LoadSky console command -void LoadSky_f (void) +static void LoadSky_f (void) { switch (Cmd_Argc()) { @@ -95,7 +171,7 @@ void LoadSky_f (void) if (skyname[0]) Con_Printf("current sky: %s\n", skyname); else - Con_Printf("no skybox has been set\n"); + Con_Print("no skybox has been set\n"); break; case 2: if (R_SetSkyBox(Cmd_Argv(1))) @@ -103,108 +179,136 @@ void LoadSky_f (void) if (skyname[0]) Con_Printf("skybox set to %s\n", skyname); else - Con_Printf("skybox disabled\n"); + Con_Print("skybox disabled\n"); } else Con_Printf("failed to load skybox %s\n", Cmd_Argv(1)); break; default: - Con_Printf("usage: loadsky skyname\n"); + Con_Print("usage: loadsky skyname\n"); break; } } -int skyboxindex[6] = {0, 1, 2, 0, 2, 3}; +static const float skyboxvertex3f[6*4*3] = +{ + // skyside[0] + 16, -16, 16, + 16, -16, -16, + 16, 16, -16, + 16, 16, 16, + // skyside[1] + -16, 16, 16, + -16, 16, -16, + -16, -16, -16, + -16, -16, 16, + // skyside[2] + 16, 16, 16, + 16, 16, -16, + -16, 16, -16, + -16, 16, 16, + // skyside[3] + -16, -16, 16, + -16, -16, -16, + 16, -16, -16, + 16, -16, 16, + // skyside[4] + -16, -16, 16, + 16, -16, 16, + 16, 16, 16, + -16, 16, 16, + // skyside[5] + 16, -16, -16, + -16, -16, -16, + -16, 16, -16, + 16, 16, -16 +}; + +static const float skyboxtexcoord2f[6*4*2] = +{ + // skyside[0] + 0, 1, + 1, 1, + 1, 0, + 0, 0, + // skyside[1] + 1, 0, + 0, 0, + 0, 1, + 1, 1, + // skyside[2] + 1, 1, + 1, 0, + 0, 0, + 0, 1, + // skyside[3] + 0, 0, + 0, 1, + 1, 1, + 1, 0, + // skyside[4] + 0, 1, + 1, 1, + 1, 0, + 0, 0, + // skyside[5] + 0, 1, + 1, 1, + 1, 0, + 0, 0 +}; + +static const int skyboxelement3i[6*2*3] = +{ + // skyside[3] + 0, 1, 2, + 0, 2, 3, + // skyside[1] + 4, 5, 6, + 4, 6, 7, + // skyside[0] + 8, 9, 10, + 8, 10, 11, + // skyside[2] + 12, 13, 14, + 12, 14, 15, + // skyside[4] + 16, 17, 18, + 16, 18, 19, + // skyside[5] + 20, 21, 22, + 20, 22, 23 +}; + +static const unsigned short skyboxelement3s[6*2*3] = +{ + // skyside[3] + 0, 1, 2, + 0, 2, 3, + // skyside[1] + 4, 5, 6, + 4, 6, 7, + // skyside[0] + 8, 9, 10, + 8, 10, 11, + // skyside[2] + 12, 13, 14, + 12, 14, 15, + // skyside[4] + 16, 17, 18, + 16, 18, 19, + // skyside[5] + 20, 21, 22, + 20, 22, 23 +}; static void R_SkyBox(void) { - rmeshstate_t m; - -#define R_SkyBoxPolyVec(i,s,t,x,y,z) \ - varray_vertex[i * 4 + 0] = (x) * 16.0f;\ - varray_vertex[i * 4 + 1] = (y) * 16.0f;\ - varray_vertex[i * 4 + 2] = (z) * 16.0f;\ - varray_texcoord[0][i * 2 + 0] = (s) * (254.0f/256.0f) + (1.0f/256.0f);\ - varray_texcoord[0][i * 2 + 1] = (t) * (254.0f/256.0f) + (1.0f/256.0f); - - memset(&m, 0, sizeof(m)); - m.blendfunc1 = GL_ONE; - m.blendfunc2 = GL_ZERO; - m.wantoverbright = false; - m.depthdisable = true; // don't modify or read zbuffer - m.tex[0] = R_GetTexture(skyboxside[3]); // front - R_Mesh_State(&m); - - memcpy(varray_element, skyboxindex, sizeof(int[6])); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = mesh_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = mesh_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = mesh_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = 1; - R_SkyBoxPolyVec(0, 1, 0, 1, -1, 1); - R_SkyBoxPolyVec(1, 1, 1, 1, -1, -1); - R_SkyBoxPolyVec(2, 0, 1, 1, 1, -1); - R_SkyBoxPolyVec(3, 0, 0, 1, 1, 1); - R_Mesh_Draw(4, 2); - m.tex[0] = R_GetTexture(skyboxside[1]); // back - R_Mesh_State(&m); - memcpy(varray_element, skyboxindex, sizeof(int[6])); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = mesh_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = mesh_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = mesh_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = 1; - R_SkyBoxPolyVec(0, 1, 0, -1, 1, 1); - R_SkyBoxPolyVec(1, 1, 1, -1, 1, -1); - R_SkyBoxPolyVec(2, 0, 1, -1, -1, -1); - R_SkyBoxPolyVec(3, 0, 0, -1, -1, 1); - R_Mesh_Draw(4, 2); - m.tex[0] = R_GetTexture(skyboxside[0]); // right - R_Mesh_State(&m); - memcpy(varray_element, skyboxindex, sizeof(int[6])); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = mesh_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = mesh_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = mesh_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = 1; - R_SkyBoxPolyVec(0, 1, 0, 1, 1, 1); - R_SkyBoxPolyVec(1, 1, 1, 1, 1, -1); - R_SkyBoxPolyVec(2, 0, 1, -1, 1, -1); - R_SkyBoxPolyVec(3, 0, 0, -1, 1, 1); - R_Mesh_Draw(4, 2); - m.tex[0] = R_GetTexture(skyboxside[2]); // left - R_Mesh_State(&m); - memcpy(varray_element, skyboxindex, sizeof(int[6])); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = mesh_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = mesh_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = mesh_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = 1; - R_SkyBoxPolyVec(0, 1, 0, -1, -1, 1); - R_SkyBoxPolyVec(1, 1, 1, -1, -1, -1); - R_SkyBoxPolyVec(2, 0, 1, 1, -1, -1); - R_SkyBoxPolyVec(3, 0, 0, 1, -1, 1); - R_Mesh_Draw(4, 2); - m.tex[0] = R_GetTexture(skyboxside[4]); // up - R_Mesh_State(&m); - memcpy(varray_element, skyboxindex, sizeof(int[6])); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = mesh_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = mesh_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = mesh_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = 1; - R_SkyBoxPolyVec(0, 1, 0, 1, -1, 1); - R_SkyBoxPolyVec(1, 1, 1, 1, 1, 1); - R_SkyBoxPolyVec(2, 0, 1, -1, 1, 1); - R_SkyBoxPolyVec(3, 0, 0, -1, -1, 1); - R_Mesh_Draw(4, 2); - m.tex[0] = R_GetTexture(skyboxside[5]); // down - R_Mesh_State(&m); - memcpy(varray_element, skyboxindex, sizeof(int[6])); - varray_color[0] = varray_color[4] = varray_color[8] = varray_color[12] = mesh_colorscale; - varray_color[1] = varray_color[5] = varray_color[9] = varray_color[13] = mesh_colorscale; - varray_color[2] = varray_color[6] = varray_color[10] = varray_color[14] = mesh_colorscale; - varray_color[3] = varray_color[7] = varray_color[11] = varray_color[15] = 1; - R_SkyBoxPolyVec(0, 1, 0, 1, 1, -1); - R_SkyBoxPolyVec(1, 1, 1, 1, -1, -1); - R_SkyBoxPolyVec(2, 0, 1, -1, -1, -1); - R_SkyBoxPolyVec(3, 0, 0, -1, 1, -1); - R_Mesh_Draw(4, 2); + int i; + RSurf_ActiveCustomEntity(&skymatrix, &skyinversematrix, 0, 0, 1, 1, 1, 1, 6*4, skyboxvertex3f, skyboxtexcoord2f, NULL, NULL, NULL, NULL, 6*2, skyboxelement3i, skyboxelement3s, false, false); + for (i = 0;i < 6;i++) + if(skyboxskinframe[i]) + R_DrawCustomSurface(skyboxskinframe[i], &identitymatrix, MATERIALFLAG_SKY | MATERIALFLAG_FULLBRIGHT | MATERIALFLAG_NOCULLFACE | MATERIALFLAG_NODEPTHTEST, i*4, 4, i*2, 2, false, false); } #define skygridx 32 @@ -213,13 +317,24 @@ static void R_SkyBox(void) #define skygridy 32 #define skygridy1 (skygridy + 1) #define skygridyrecip (1.0f / (skygridy)) - -static float skysphere[skygridx1*skygridy1*5]; -static int skysphereindices[skygridx*skygridy*6]; -static void skyspherecalc(float *sphere, float dx, float dy, float dz) +#define skysphere_numverts (skygridx1 * skygridy1) +#define skysphere_numtriangles (skygridx * skygridy * 2) +static float skysphere_vertex3f[skysphere_numverts * 3]; +static float skysphere_texcoord2f[skysphere_numverts * 2]; +static int skysphere_element3i[skysphere_numtriangles * 3]; +static unsigned short skysphere_element3s[skysphere_numtriangles * 3]; + +static void skyspherecalc(void) { - float a, b, x, ax, ay, v[3], length; - int i, j, *index; + int i, j; + unsigned short *e; + float a, b, x, ax, ay, v[3], length, *vertex3f, *texcoord2f; + float dx, dy, dz; + dx = 16.0f; + dy = 16.0f; + dz = 16.0f / 3.0f; + vertex3f = skysphere_vertex3f; + texcoord2f = skysphere_texcoord2f; for (j = 0;j <= skygridy;j++) { a = j * skygridyrecip; @@ -228,241 +343,133 @@ static void skyspherecalc(float *sphere, float dx, float dy, float dz) for (i = 0;i <= skygridx;i++) { b = i * skygridxrecip; - x = cos(b * M_PI * 2); + x = cos((b + 0.5) * M_PI); v[0] = ax*x * dx; v[1] = ay*x * dy; - v[2] = -sin(b * M_PI * 2) * dz; + v[2] = -sin((b + 0.5) * M_PI) * dz; length = 3.0f / sqrt(v[0]*v[0]+v[1]*v[1]+(v[2]*v[2]*9)); - *sphere++ = v[0] * length; - *sphere++ = v[1] * length; - *sphere++ = v[0]; - *sphere++ = v[1]; - *sphere++ = v[2]; + *texcoord2f++ = v[0] * length; + *texcoord2f++ = v[1] * length; + *vertex3f++ = v[0]; + *vertex3f++ = v[1]; + *vertex3f++ = v[2]; } } - index = skysphereindices; + e = skysphere_element3s; for (j = 0;j < skygridy;j++) { for (i = 0;i < skygridx;i++) { - *index++ = j * skygridx1 + i; - *index++ = j * skygridx1 + i + 1; - *index++ = (j + 1) * skygridx1 + i; + *e++ = j * skygridx1 + i; + *e++ = j * skygridx1 + i + 1; + *e++ = (j + 1) * skygridx1 + i; - *index++ = j * skygridx1 + i + 1; - *index++ = (j + 1) * skygridx1 + i + 1; - *index++ = (j + 1) * skygridx1 + i; + *e++ = j * skygridx1 + i + 1; + *e++ = (j + 1) * skygridx1 + i + 1; + *e++ = (j + 1) * skygridx1 + i; } - i++; - } -} - -static void skyspherearrays(float *v, float *t, float *c, float *source, float s, float colorscale) -{ - int i; - for (i = 0;i < (skygridx1*skygridy1);i++, c += 4, t += 2, v += 4, source += 5) - { - c[0] = colorscale; - c[1] = colorscale; - c[2] = colorscale; - c[3] = 1; - t[0] = source[0] + s; - t[1] = source[1] + s; - v[0] = source[2]; - v[1] = source[3]; - v[2] = source[4]; } + for (i = 0;i < skysphere_numtriangles*3;i++) + skysphere_element3i[i] = skysphere_element3s[i]; } static void R_SkySphere(void) { - int numverts, numtriangles; - float speedscale, speedscale2; + double speedscale; static qboolean skysphereinitialized = false; - rmeshstate_t m; + matrix4x4_t scroll1matrix, scroll2matrix; if (!skysphereinitialized) { skysphereinitialized = true; - skyspherecalc(skysphere, 16, 16, 16 / 3); + skyspherecalc(); } - speedscale = cl.time*8.0/128.0; - speedscale -= (int)speedscale; - speedscale2 = cl.time*16.0/128.0; - speedscale2 -= (int)speedscale2; - - numverts = skygridx1*skygridy1; - numtriangles = skygridx*skygridy*2; - - R_Mesh_ResizeCheck(numverts, numtriangles); + // wrap the scroll values just to be extra kind to float accuracy - memset(&m, 0, sizeof(m)); - m.blendfunc1 = GL_ONE; - m.blendfunc2 = GL_ZERO; - m.wantoverbright = false; - m.depthdisable = true; // don't modify or read zbuffer - m.tex[0] = R_GetTexture(solidskytexture); - R_Mesh_State(&m); + // scroll speed for upper layer + speedscale = r_refdef.scene.time*r_skyscroll1.value*8.0/128.0; + speedscale -= floor(speedscale); + Matrix4x4_CreateTranslate(&scroll1matrix, speedscale, speedscale, 0); + // scroll speed for lower layer (transparent layer) + speedscale = r_refdef.scene.time*r_skyscroll2.value*8.0/128.0; + speedscale -= floor(speedscale); + Matrix4x4_CreateTranslate(&scroll2matrix, speedscale, speedscale, 0); - memcpy(varray_element, skysphereindices, numtriangles * sizeof(int[3])); - skyspherearrays(varray_vertex, varray_texcoord[0], varray_color, skysphere, speedscale, mesh_colorscale); - R_Mesh_Draw(numverts, numtriangles); - - m.blendfunc1 = GL_SRC_ALPHA; - m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA; - m.tex[0] = R_GetTexture(alphaskytexture); - R_Mesh_State(&m); - - memcpy(varray_element, skysphereindices, numtriangles * sizeof(int[3])); - skyspherearrays(varray_vertex, varray_texcoord[0], varray_color, skysphere, speedscale2, mesh_colorscale); - R_Mesh_Draw(numverts, numtriangles); + RSurf_ActiveCustomEntity(&skymatrix, &skyinversematrix, 0, 0, 1, 1, 1, 1, skysphere_numverts, skysphere_vertex3f, skysphere_texcoord2f, NULL, NULL, NULL, NULL, skysphere_numtriangles, skysphere_element3i, skysphere_element3s, false, false); + R_DrawCustomSurface(r_refdef.scene.worldmodel->brush.solidskyskinframe, &scroll1matrix, MATERIALFLAG_SKY | MATERIALFLAG_FULLBRIGHT | MATERIALFLAG_NOCULLFACE | MATERIALFLAG_NODEPTHTEST , 0, skysphere_numverts, 0, skysphere_numtriangles, false, false); + R_DrawCustomSurface(r_refdef.scene.worldmodel->brush.alphaskyskinframe, &scroll2matrix, MATERIALFLAG_SKY | MATERIALFLAG_FULLBRIGHT | MATERIALFLAG_NOCULLFACE | MATERIALFLAG_NODEPTHTEST | MATERIALFLAG_ALPHA | MATERIALFLAG_BLENDED, 0, skysphere_numverts, 0, skysphere_numtriangles, false, false); } void R_Sky(void) { - matrix4x4_t skymatrix; - if (skyrendermasked) - { - Matrix4x4_CreateTranslate(&skymatrix, r_origin[0], r_origin[1], r_origin[2]); - R_Mesh_Matrix(&skymatrix); - if (skyrendersphere) - { - // this does not modify depth buffer - R_SkySphere(); - } - else if (skyrenderbox) - { - // this does not modify depth buffer - R_SkyBox(); - } - /* this will be skyroom someday - else - { - // this modifies the depth buffer so we have to clear it afterward - //R_SkyRoom(); - // clear the depthbuffer that was used while rendering the skyroom - //R_Mesh_ClearDepth(); - } - */ - } -} - -//=============================================================== - -/* -============= -R_InitSky - -A sky texture is 256*128, with the right side being a masked overlay -============== -*/ -void R_InitSky (qbyte *src, int bytesperpixel) -{ - int i, j, p, r, g, b; - qbyte skyupperlayerpixels[128*128*4], skylowerlayerpixels[128*128*4]; - unsigned trans[128*128], transpix, *rgba; + Matrix4x4_CreateFromQuakeEntity(&skymatrix, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], 0, 0, 0, r_refdef.farclip * (0.5f / 16.0f)); + Matrix4x4_Invert_Simple(&skyinversematrix, &skymatrix); - skyavailable_quake = true; - - // flush skytexturepool so we won't build up a leak from uploading textures multiple times - R_FreeTexturePool(&skytexturepool); - skytexturepool = R_AllocTexturePool(); - solidskytexture = NULL; - alphaskytexture = NULL; - - if (bytesperpixel == 4) + if (r_sky_scissor.integer) { - for (i = 0;i < 128;i++) - for (j = 0;j < 128;j++) - trans[(i*128) + j] = src[i*256+j+128]; + // if the scissor is empty just return + if (skyscissor[2] == 0 || skyscissor[3] == 0) + return; + GL_Scissor(skyscissor[0], skyscissor[1], skyscissor[2], skyscissor[3]); + GL_ScissorTest(true); } - else + if (skyrendersphere) { - // make an average value for the back to avoid - // a fringe on the top level - r = g = b = 0; - for (i=0 ; i<128 ; i++) - { - for (j=0 ; j<128 ; j++) - { - p = src[i*256 + j + 128]; - rgba = &d_8to24table[p]; - trans[(i*128) + j] = *rgba; - r += ((qbyte *)rgba)[0]; - g += ((qbyte *)rgba)[1]; - b += ((qbyte *)rgba)[2]; - } - } - - ((qbyte *)&transpix)[0] = r/(128*128); - ((qbyte *)&transpix)[1] = g/(128*128); - ((qbyte *)&transpix)[2] = b/(128*128); - ((qbyte *)&transpix)[3] = 0; + // this does not modify depth buffer + R_SkySphere(); } - - memcpy(skyupperlayerpixels, trans, 128*128*4); - - solidskytexture = R_LoadTexture (skytexturepool, "sky_solidtexture", 128, 128, (qbyte *) trans, TEXTYPE_RGBA, TEXF_PRECACHE); - - if (bytesperpixel == 4) + else if (skyrenderbox) { - for (i = 0;i < 128;i++) - for (j = 0;j < 128;j++) - trans[(i*128) + j] = src[i*256+j]; + // this does not modify depth buffer + R_SkyBox(); } + /* this will be skyroom someday else { - for (i=0 ; i<128 ; i++) - { - for (j=0 ; j<128 ; j++) - { - p = src[i*256 + j]; - if (p == 0) - trans[(i*128) + j] = transpix; - else - trans[(i*128) + j] = d_8to24table[p]; - } - } + // this modifies the depth buffer so we have to clear it afterward + //R_SkyRoom(); + // clear the depthbuffer that was used while rendering the skyroom + //GL_Clear(GL_DEPTH_BUFFER_BIT); } - - memcpy(skylowerlayerpixels, trans, 128*128*4); - - alphaskytexture = R_LoadTexture (skytexturepool, "sky_alphatexture", 128, 128, (qbyte *) trans, TEXTYPE_RGBA, TEXF_ALPHA | TEXF_PRECACHE); + */ + GL_Scissor(0, 0, vid.width, vid.height); } -void R_ResetQuakeSky(void) -{ - skyavailable_quake = false; -} +//=============================================================== void R_ResetSkyBox(void) { - skyboxside[0] = skyboxside[1] = skyboxside[2] = skyboxside[3] = skyboxside[4] = skyboxside[5] = NULL; + R_UnloadSkyBox(); skyname[0] = 0; - skyavailable_box = false; + R_LoadSkyBox(); } static void r_sky_start(void) { skytexturepool = R_AllocTexturePool(); - solidskytexture = NULL; - alphaskytexture = NULL; + R_LoadSkyBox(); } static void r_sky_shutdown(void) { + R_UnloadSkyBox(); R_FreeTexturePool(&skytexturepool); - solidskytexture = NULL; - alphaskytexture = NULL; } static void r_sky_newmap(void) { } + void R_Sky_Init(void) { - Cmd_AddCommand ("loadsky", &LoadSky_f); + Cmd_AddCommand ("loadsky", &LoadSky_f, "load a skybox by basename (for example loadsky mtnsun_ loads mtnsun_ft.tga and so on)"); Cvar_RegisterVariable (&r_sky); - R_RegisterModule("R_Sky", r_sky_start, r_sky_shutdown, r_sky_newmap); + Cvar_RegisterVariable (&r_skyscroll1); + Cvar_RegisterVariable (&r_skyscroll2); + Cvar_RegisterVariable (&r_sky_scissor); + memset(&skyboxskinframe, 0, sizeof(skyboxskinframe)); + skyname[0] = 0; + R_RegisterModule("R_Sky", r_sky_start, r_sky_shutdown, r_sky_newmap, NULL, NULL); } +