X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=r_sky.c;h=7fd1463dbc7239c60c998ea3124db9ca861234a5;hb=d9c5bc4c35de0ae4d64f0d710673ad73d221a727;hp=bf338240cf30290fa05bc800aea7f0a43dbd18b9;hpb=d6eabf6e35a6bda7d47b2acb87e3c5d2f5bde567;p=xonotic%2Fdarkplaces.git diff --git a/r_sky.c b/r_sky.c index bf338240..7fd1463d 100644 --- a/r_sky.c +++ b/r_sky.c @@ -3,15 +3,13 @@ #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"}; +cvar_t r_sky = {CF_CLIENT | CF_ARCHIVE, "r_sky", "1", "enables sky rendering (black otherwise)"}; +cvar_t r_skyscroll1 = {CF_CLIENT | CF_ARCHIVE, "r_skyscroll1", "1", "speed at which upper clouds layer scrolls in quake sky"}; +cvar_t r_skyscroll2 = {CF_CLIENT | CF_ARCHIVE, "r_skyscroll2", "2", "speed at which lower clouds layer scrolls in quake sky"}; +cvar_t r_sky_scissor = {CF_CLIENT, "r_sky_scissor", "1", "limit rendering of sky to approximately the area of the sky surfaces"}; int skyrenderlater; int skyrendermasked; -int skyscissor; -float skyscissormins[3]; -float skyscissormaxs[3]; +int skyscissor[4]; static int skyrendersphere; static int skyrenderbox; @@ -23,7 +21,7 @@ static matrix4x4_t skyinversematrix; typedef struct suffixinfo_s { const char *suffix; - qboolean flipx, flipy, flipdiagonal; + qbool flipx, flipy, flipdiagonal; } suffixinfo_t; static const suffixinfo_t suffix[3][6] = @@ -64,9 +62,7 @@ void R_SkyStartFrame(void) // 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 - skyscissor = false; - VectorClear(skyscissormins); - VectorClear(skyscissormaxs); + Vector4Clear(skyscissor); if (r_sky.integer) { if (skyboxskinframe[0] || skyboxskinframe[1] || skyboxskinframe[2] || skyboxskinframe[3] || skyboxskinframe[4] || skyboxskinframe[5]) @@ -90,7 +86,7 @@ static void R_UnloadSkyBox(void) { if (skyboxskinframe[i]) { - // TODO: make a R_SkinFrame_Purge for single skins... + R_SkinFrame_PurgeSkinFrame(skyboxskinframe[i]); c++; } skyboxskinframe[i] = NULL; @@ -131,7 +127,7 @@ static int R_LoadSkyBox(void) } 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); + 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, 0, 0, 0, vid.sRGB3D); Mem_Free(image_buffer); Mem_Free(temp); success++; @@ -166,10 +162,10 @@ int R_SetSkyBox(const char *sky) return R_LoadSkyBox(); } -// LordHavoc: added LoadSky console command -static void LoadSky_f (void) +// LadyHavoc: added LoadSky console command +static void LoadSky_f(cmd_state_t *cmd) { - switch (Cmd_Argc()) + switch (Cmd_Argc(cmd)) { case 1: if (skyname[0]) @@ -178,7 +174,7 @@ static void LoadSky_f (void) Con_Print("no skybox has been set\n"); break; case 2: - if (R_SetSkyBox(Cmd_Argv(1))) + if (R_SetSkyBox(Cmd_Argv(cmd, 1))) { if (skyname[0]) Con_Printf("skybox set to %s\n", skyname); @@ -186,7 +182,7 @@ static void LoadSky_f (void) Con_Print("skybox disabled\n"); } else - Con_Printf("failed to load skybox %s\n", Cmd_Argv(1)); + Con_Printf(CON_ERROR "failed to load skybox %s\n", Cmd_Argv(cmd, 1)); break; default: Con_Print("usage: loadsky skyname\n"); @@ -312,7 +308,7 @@ static void R_SkyBox(void) 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); + R_DrawCustomSurface(skyboxskinframe[i], &identitymatrix, MATERIALFLAG_SKY | MATERIALFLAG_FULLBRIGHT | MATERIALFLAG_NOCULLFACE | MATERIALFLAG_NODEPTHTEST, i*4, 4, i*2, 2, false, false, false); } #define skygridx 32 @@ -380,7 +376,7 @@ static void skyspherecalc(void) static void R_SkySphere(void) { double speedscale; - static qboolean skysphereinitialized = false; + static qbool skysphereinitialized = false; matrix4x4_t scroll1matrix, scroll2matrix; if (!skysphereinitialized) { @@ -400,22 +396,21 @@ static void R_SkySphere(void) Matrix4x4_CreateTranslate(&scroll2matrix, speedscale, speedscale, 0); 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); + 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, 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, false); } void R_Sky(void) { - int scissor[4]; 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); - if (r_sky_scissor.integer && skyscissor) + if (r_sky_scissor.integer) { - // compute the scissor, if it's offscreen just return - if (R_ScissorForBBox(skyscissormins, skyscissormaxs, scissor)) + // if the scissor is empty just return + if (skyscissor[2] == 0 || skyscissor[3] == 0) return; - GL_Scissor(scissor[0], scissor[1], scissor[2], scissor[3]); + GL_Scissor(skyscissor[0], skyscissor[1], skyscissor[2], skyscissor[3]); GL_ScissorTest(true); } if (skyrendersphere) @@ -437,7 +432,7 @@ void R_Sky(void) //GL_Clear(GL_DEPTH_BUFFER_BIT); } */ - GL_Scissor(0, 0, vid.width, vid.height); + GL_Scissor(0, 0, r_fb.screentexturewidth, r_fb.screentextureheight); } //=============================================================== @@ -445,7 +440,7 @@ void R_Sky(void) void R_ResetSkyBox(void) { R_UnloadSkyBox(); - skyname[0] = 0; + memset(skyname,0,MAX_QPATH); R_LoadSkyBox(); } @@ -468,7 +463,7 @@ static void r_sky_newmap(void) void R_Sky_Init(void) { - Cmd_AddCommand ("loadsky", &LoadSky_f, "load a skybox by basename (for example loadsky mtnsun_ loads mtnsun_ft.tga and so on)"); + Cmd_AddCommand(CF_CLIENT, "loadsky", &LoadSky_f, "load a skybox by basename (for example loadsky mtnsun_ loads mtnsun_ft.tga and so on)"); Cvar_RegisterVariable (&r_sky); Cvar_RegisterVariable (&r_skyscroll1); Cvar_RegisterVariable (&r_skyscroll2);