From 55dbce5a3bc342331fb93ad3691b7a0cbf3e2761 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sat, 17 Jul 2021 15:10:30 +0000 Subject: [PATCH] Arg completion for the 'sky' command, as requested by Bal... though he did ask it for QSS instead... git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5969 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/render.h | 1 + engine/client/renderer.c | 60 +----------- engine/gl/gl_warp.c | 136 ++++++++++++++++++++++++++-- engine/gl/r_bishaders.h | 2 +- engine/shaders/glsl/defaultsky.glsl | 2 +- 5 files changed, 134 insertions(+), 67 deletions(-) diff --git a/engine/client/render.h b/engine/client/render.h index c797052f0..89a270ff3 100644 --- a/engine/client/render.h +++ b/engine/client/render.h @@ -391,6 +391,7 @@ extern int numlightmaps; void QDECL Surf_RebuildLightmap_Callback (struct cvar_s *var, char *oldvalue); +void R_Sky_Register(void); void R_SkyShutdown(void); void R_SetSky(const char *skyname); texid_t R_GetDefaultEnvmap(void); diff --git a/engine/client/renderer.c b/engine/client/renderer.c index 5714c50cf..d2cbd3821 100644 --- a/engine/client/renderer.c +++ b/engine/client/renderer.c @@ -55,27 +55,6 @@ extern int gl_anisotropy_factor; void QDECL SCR_Viewsize_Callback (struct cvar_s *var, char *oldvalue); void QDECL SCR_Fov_Callback (struct cvar_s *var, char *oldvalue); void QDECL Image_TextureMode_Callback (struct cvar_s *var, char *oldvalue); -void QDECL R_SkyBox_Changed (struct cvar_s *var, char *oldvalue) -{ - R_SetSky(var->string); -// Shader_NeedReload(false); -} -void R_ForceSky_f(void) -{ - if (Cmd_Argc() < 2) - { - if (*r_skyboxname.string) - Con_Printf("Current user skybox is %s\n", r_skyboxname.string); - else if (*cl.skyname) - Con_Printf("Current per-map skybox is %s\n", cl.skyname); - else - Con_Printf("no skybox forced.\n"); - } - else - { - R_SetSky(Cmd_Argv(1)); - } -} static void QDECL R_Lightmap_Format_Changed(struct cvar_s *var, char *oldvalue) { if (qrenderer) @@ -177,11 +156,6 @@ cvar_t r_dynamic = CVARFD ("r_dynamic", IFMINIMAL("0","1"), extern cvar_t r_temporalscenecache; cvar_t r_fastturb = CVARF ("r_fastturb", "0", CVAR_SHADERSYSTEM); -cvar_t r_skycloudalpha = CVARFD ("r_skycloudalpha", "1", CVAR_RENDERERLATCH, "Controls how opaque the front layer of legacy scrolling skies should be."); -cvar_t r_fastsky = CVARF ("r_fastsky", "0", - CVAR_ARCHIVE); -cvar_t r_fastskycolour = CVARF ("r_fastskycolour", "0", - CVAR_RENDERERCALLBACK|CVAR_SHADERSYSTEM); cvar_t r_fb_bmodels = CVARAFD("r_fb_bmodels", "1", "gl_fb_bmodels", CVAR_SEMICHEAT|CVAR_RENDERERLATCH, "Enables loading lumas on the map, as well as any external bsp models."); cvar_t r_fb_models = CVARAFD ("r_fb_models", "1", @@ -238,9 +212,6 @@ cvar_t r_novis = CVARF ("r_novis", "0", CVAR_ARCHIVE); cvar_t r_part_rain = CVARFD ("r_part_rain", "0", CVAR_ARCHIVE, "Enable particle effects to emit off of surfaces. Mainly used for weather or lava/slime effects."); -cvar_t r_skyboxname = CVARFC ("r_skybox", "", - CVAR_RENDERERCALLBACK | CVAR_SHADERSYSTEM, R_SkyBox_Changed); -cvar_t r_skybox_orientation = CVARFD ("r_glsl_skybox_orientation", "0 0 0 0", CVAR_SHADERSYSTEM, "Defines the axis around which skyboxes will rotate (the first three values). The fourth value defines the speed the skybox rotates at, in degrees per second."); cvar_t r_softwarebanding_cvar = CVARFD ("r_softwarebanding", "0", CVAR_SHADERSYSTEM|CVAR_RENDERERLATCH|CVAR_ARCHIVE, "Utilise the Quake colormap in order to emulate 8bit software rendering. This results in banding as well as other artifacts that some believe adds character. Also forces nearest sampling on affected surfaces (palette indicies do not interpolate well)."); qboolean r_softwarebanding; cvar_t r_speeds = CVAR ("r_speeds", "0"); @@ -257,7 +228,6 @@ cvar_t r_wallcolour = CVARAF ("r_wallcolour", "128 128 128", "r_wallcolor", CVAR_RENDERERCALLBACK|CVAR_SHADERSYSTEM);//FIXME: broken //cvar_t r_walltexture = CVARF ("r_walltexture", "", // CVAR_RENDERERCALLBACK|CVAR_SHADERSYSTEM); //FIXME: broken -cvar_t r_skyfog = CVARD ("r_skyfog", "0.5", "This controls an alpha-blend value for fog on skyboxes, cumulative with regular fog alpha."); cvar_t r_wateralpha = CVARF ("r_wateralpha", "1", CVAR_ARCHIVE | CVAR_SHADERSYSTEM); cvar_t r_lavaalpha = CVARF ("r_lavaalpha", "", @@ -453,7 +423,6 @@ cvar_t gl_picmip_sprites = CVARFD ("gl_picmip_sprites", "0", CVAR_ARCHIVE, cvar_t gl_picmip_other = CVARFD ("gl_picmip_other", "0", CVAR_ARCHIVE, "Effectively added to gl_picmip for the purposes of model textures."); cvar_t gl_nohwblend = CVARD ("gl_nohwblend","1", "If 1, don't use hardware gamma ramps for transient effects that change each frame (does not affect long-term effects like holding quad or underwater tints)."); //cvar_t gl_schematics = CVARD ("gl_schematics", "0", "Gimmick rendering mode that draws the length of various world edges."); -cvar_t gl_skyboxdist = CVARD ("gl_skyboxdist", "0", "The distance of the skybox. If 0, the engine will determine it based upon the far clip plane distance."); //0 = guess. cvar_t gl_smoothcrosshair = CVAR ("gl_smoothcrosshair", "1"); cvar_t gl_maxdist = CVARAD ("gl_maxdist", "0", "gl_farclip", "The distance of the far clip plane. If set to 0, some fancy maths will be used to place it at an infinite distance."); @@ -636,8 +605,6 @@ void GLRenderer_Init(void) Cvar_Register (&gl_screenangle, GLRENDEREROPTIONS); - Cvar_Register (&gl_skyboxdist, GLRENDEREROPTIONS); - Cvar_Register (&r_wallcolour, GLRENDEREROPTIONS); Cvar_Register (&r_floorcolour, GLRENDEREROPTIONS); // Cvar_Register (&r_walltexture, GLRENDEREROPTIONS); @@ -709,22 +676,6 @@ void R_ListSkins_f(void) { COM_EnumerateFiles("skins/*.*", ShowFileList, NULL); } -void R_ListSkyBoxes_f(void) -{ - //FIXME: this demonstrates why we need a nicer result printer. - COM_EnumerateFiles("env/*rt.*", ShowFileList, NULL); - COM_EnumerateFiles("env/*px.*", ShowFileList, NULL); - COM_EnumerateFiles("env/*posx.*", ShowFileList, NULL); - COM_EnumerateFiles("gfx/env/*rt.*", ShowFileList, NULL); - COM_EnumerateFiles("gfx/env/*px.*", ShowFileList, NULL); - COM_EnumerateFiles("gfx/env/*posx.*", ShowFileList, NULL); - COM_EnumerateFiles("textures/env/*rt.*", ShowFileList, NULL); - COM_EnumerateFiles("textures/env/*px.*", ShowFileList, NULL); - COM_EnumerateFiles("textures/env/*posx.*", ShowFileList, NULL); - COM_EnumerateFiles("textures/gfx/env/*rt.*", ShowFileList, NULL); - COM_EnumerateFiles("textures/gfx/env/*px.*", ShowFileList, NULL); - COM_EnumerateFiles("textures/gfx/env/*posx.*", ShowFileList, NULL); -} void R_SetRenderer_f (void); @@ -862,12 +813,6 @@ void Renderer_Init(void) Cvar_Register (&r_mirroralpha, GLRENDEREROPTIONS); Cvar_Register (&r_softwarebanding_cvar, GRAPHICALNICETIES); - Cvar_Register (&r_skyfog, GRAPHICALNICETIES); - Cvar_Register (&r_skyboxname, GRAPHICALNICETIES); - Cvar_Register (&r_skybox_orientation, GRAPHICALNICETIES); - Cmd_AddCommand("sky", R_ForceSky_f); //QS compat - Cmd_AddCommand("loadsky", R_ForceSky_f);//DP compat - Cvar_Register(&r_keepimages, GRAPHICALNICETIES); Cvar_Register(&r_ignoremapprefixes, GRAPHICALNICETIES); Cvar_ForceCallback(&r_keepimages); @@ -1003,9 +948,6 @@ void Renderer_Init(void) Cvar_Register (&r_nolightdir, GRAPHICALNICETIES); Cvar_Register (&r_fastturb, GRAPHICALNICETIES); - Cvar_Register (&r_skycloudalpha, GRAPHICALNICETIES); - Cvar_Register (&r_fastsky, GRAPHICALNICETIES); - Cvar_Register (&r_fastskycolour, GRAPHICALNICETIES); Cvar_Register (&r_wateralpha, GRAPHICALNICETIES); Cvar_Register (&r_lavaalpha, GRAPHICALNICETIES); Cvar_Register (&r_slimealpha, GRAPHICALNICETIES); @@ -1072,9 +1014,9 @@ void Renderer_Init(void) Cmd_AddCommand ("listfonts", R_ListFonts_f); Cmd_AddCommand ("listskins", R_ListSkins_f); - Cmd_AddCommand ("listskyboxes", R_ListSkyBoxes_f); Cmd_AddCommand ("listconfigs", R_ListConfigs_f); + R_Sky_Register(); #if defined(D3DQUAKE) GLD3DRenderer_Init(); diff --git a/engine/gl/gl_warp.c b/engine/gl/gl_warp.c index 94172bbd9..d82cdc0f6 100644 --- a/engine/gl/gl_warp.c +++ b/engine/gl/gl_warp.c @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // gl_warp.c -- sky and water polygons #include "quakedef.h" -#ifndef SERVERONLY +#ifdef HAVE_CLIENT #include "glquake.h" #include "shader.h" #include @@ -32,17 +32,21 @@ static void GL_DrawSkyBox (texid_t *texnums, batch_t *s); static void GL_DrawSkyGrid (texnums_t *tex); -extern cvar_t gl_skyboxdist; -extern cvar_t r_fastsky; -extern cvar_t r_fastskycolour; -extern cvar_t r_skycloudalpha; +static void QDECL R_SkyBox_Changed (struct cvar_s *var, char *oldvalue); + +cvar_t r_fastsky = CVARF ("r_fastsky", "0", CVAR_ARCHIVE); +static cvar_t r_fastskycolour = CVARF ("r_fastskycolour", "0", CVAR_RENDERERCALLBACK|CVAR_SHADERSYSTEM); +static cvar_t gl_skyboxdist = CVARD ("gl_skyboxdist", "0", "The distance of the skybox. If 0, the engine will determine it based upon the far clip plane distance."); //0 = guess. +static cvar_t r_skycloudalpha = CVARFD ("r_skycloudalpha", "1", CVAR_RENDERERLATCH, "Controls how opaque the front layer of legacy scrolling skies should be."); +cvar_t r_skyboxname = CVARFC ("r_skybox", "", CVAR_RENDERERCALLBACK | CVAR_SHADERSYSTEM, R_SkyBox_Changed); +cvar_t r_skybox_orientation = CVARFD ("r_glsl_skybox_orientation", "0 0 0 0", CVAR_SHADERSYSTEM, "Defines the axis around which skyboxes will rotate (the first three values). The fourth value defines the speed the skybox rotates at, in degrees per second."); +cvar_t r_skyfog = CVARD ("r_skyfog", "0.5", "This controls an alpha-blend value for fog on skyboxes, cumulative with regular fog alpha."); static shader_t *forcedsky; static shader_t *skyboxface; static shader_t *skygridface; - //========================================================= //called on video shutdown to reset internal state @@ -155,6 +159,110 @@ void R_SetSky(const char *sky) } } +struct skylist_s +{ + const char *prefix; + const char *partial; + size_t partiallen; + struct xcommandargcompletioncb_s *ctx; +}; +static int QDECL R_ForceSky_Enumerated (const char *name, qofs_t flags, time_t mtime, void *parm, searchpathfuncs_t *spath) +{ + struct skylist_s *ctx = parm; + char base[MAX_QPATH]; + const char *ext; + size_t l = strlen(ctx->prefix), pl; + size_t p; + + static char *skypost[] = + { + "rt","lf","bk","ft","up","dn", + "px","nx","py","ny","pz","nz", + "posx","negx","posy","negy","posz","negz", + }; + + if (!strncmp(name, ctx->prefix, l)) + { + ext = COM_GetFileExtension(name+l, NULL); + COM_StripExtension(name+l, base, sizeof(base)); + l = strlen(base); + for (p = 0; p < countof(skypost); p++) + { + pl = strlen(skypost[p]); + if (pl > l) + continue; + if (!strcmp(base+l-pl, skypost[p])) + { + if (p%6) + return true; + base[l-pl] = 0; //strip the postfix too. + break; + } + } + if (p == countof(skypost) && strcmp(ext, ".tga") && strcmp(ext, ".png")) //give it its extension back if its not a regular skybox. + Q_strncatz(base, ext, sizeof(base)); + if (!Q_strncasecmp(base, ctx->partial, ctx->partiallen)) + { + //non-matches are dds/ktx cubemaps, or equirectangular or something + if (ctx->ctx) + ctx->ctx->cb(base, NULL, NULL, ctx->ctx); + else + Con_Printf("\t^[%s\\type\\%s %s^]\n", base, r_skyboxname.name, base); + } + } + return true; +} +static void R_ForceSky_c(int argn, const char *partial, struct xcommandargcompletioncb_s *ctx) +{ + static char *skypath[] = + { + "env/", + "gfx/env/", + "textures/env/", + "textures/gfx/env/", + }; + struct skylist_s l; + size_t pre; + l.ctx = ctx; + l.partial = partial; + l.partiallen = strlen(partial); + for (pre = 0; pre < countof(skypath); pre++) + { + l.prefix = skypath[pre]; + COM_EnumerateFiles(va("%s*.*", l.prefix), R_ForceSky_Enumerated, &l); + } + + //no skybox is also an option. + if (ctx && !*partial) + ctx->cb("", NULL, NULL, ctx); +} +static void R_ListSkyBoxes_f(void) +{ + Con_Printf("Skybox Options:\n"); + R_ForceSky_c(0, "", NULL); +} +static void R_ForceSky_f(void) +{ + if (Cmd_Argc() < 2) + { + if (*r_skyboxname.string) + Con_Printf("Current user skybox is %s\n", r_skyboxname.string); + else if (*cl.skyname) + Con_Printf("Current per-map skybox is %s\n", cl.skyname); + else + Con_Printf("no skybox forced.\n"); + } + else + { + R_SetSky(Cmd_Argv(1)); + } +} +void QDECL R_SkyBox_Changed (struct cvar_s *var, char *oldvalue) +{ + R_SetSky(var->string); +// Shader_NeedReload(false); +} + void R_DrawFastSky(batch_t *batch) { batch_t b = *batch; @@ -1218,4 +1326,20 @@ void R_InitSky (shader_t *shader, const char *skyname, uploadfmt_t fmt, qbyte *s BZ_Free(temp); } } + +void R_Sky_Register(void) +{ + const char *groupname = "Skies"; + Cvar_Register (&r_skycloudalpha, groupname); + Cvar_Register (&r_fastsky, groupname); + Cvar_Register (&r_fastskycolour, groupname); + Cvar_Register (&r_skyfog, groupname); + Cvar_Register (&r_skyboxname, groupname); + Cvar_Register (&r_skybox_orientation, groupname); + Cvar_Register (&gl_skyboxdist, groupname); + + Cmd_AddCommandAD("sky", R_ForceSky_f, R_ForceSky_c, "For compat with Quakespasm"); //QS compat + Cmd_AddCommandAD("loadsky", R_ForceSky_f, R_ForceSky_c, "For compat with DP"); + Cmd_AddCommand ("listskyboxes", R_ListSkyBoxes_f); +} #endif diff --git a/engine/gl/r_bishaders.h b/engine/gl/r_bishaders.h index 43d7c8726..e58f0fa07 100644 --- a/engine/gl/r_bishaders.h +++ b/engine/gl/r_bishaders.h @@ -4452,7 +4452,7 @@ YOU SHOULD NOT EDIT THIS FILE BY HAND "#ifdef EQUI\n" "#define PI 3.1415926535897932384626433832795\n" "dir = normalize(dir);\n" -"tccoord.x = atan(dir.x,dir.y) / (PI*2.0) + 0.5;\n" +"tccoord.x = atan(dir.y,-dir.x) / (PI*2.0);\n" "tccoord.y = acos(dir.z) / PI;\n" "vec3 sky = vec3(texture2D(s_base, tccoord));\n" diff --git a/engine/shaders/glsl/defaultsky.glsl b/engine/shaders/glsl/defaultsky.glsl index e9c21203b..91dad8455 100644 --- a/engine/shaders/glsl/defaultsky.glsl +++ b/engine/shaders/glsl/defaultsky.glsl @@ -26,7 +26,7 @@ void main () #ifdef EQUI #define PI 3.1415926535897932384626433832795 dir = normalize(dir); - tccoord.x = atan(dir.x,dir.y) / (PI*2.0) + 0.5; + tccoord.x = atan(dir.y,-dir.x) / (PI*2.0); tccoord.y = acos(dir.z) / PI; vec3 sky = vec3(texture2D(s_base, tccoord));