From 7ee6de6b6aa438ac15cc7f679ed4686cc43077dc Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 1 Mar 2024 23:12:23 +0100 Subject: [PATCH 01/11] software sdl windows scaling quality setting --- src/m_menu.c | 8 ++++++++ src/sdl/i_video.c | 12 ++++++++++++ src/v_video.h | 6 +++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 0bed7567f..7416bd4fd 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1425,6 +1425,11 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 95}, {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 105}, + +#if defined(HAVE_SDL) + {IT_STRING | IT_CVAR, NULL, "Scale Quality", &cv_scalequality, 115}, +#endif + #ifdef HWRENDER {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 95}, @@ -1449,6 +1454,7 @@ static const char* OP_ExpTooltips[] = "Which version of R_PointToAngle should\nbe used for Sector Clipping?\n64 may fix rendering issues on larger maps\nat the cost of performance.", "Hides 3DFloors which are not visible\npotentially resulting in a performance boost.", "Hides Sprites which are not visible\npotentially resulting in a performance boost.", + "Scale Quality", #ifdef HWRENDER "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", "Change the depth of the Palette in Palette rendering mod\n 16 bits is like software looks ingame\nwhile 24 bits is how software looks in screenshots.", @@ -1470,6 +1476,7 @@ enum op_exp_angleshit, op_exp_ffclip, op_exp_sprclip, + op_exp_sclqal, #ifdef HWRENDER op_exp_grscrtx, op_exp_spltwal, @@ -4444,6 +4451,7 @@ void M_Init(void) if (rendermode == render_opengl){ OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_sprclip].status = IT_DISABLED; + OP_ExpOptionsMenu[op_exp_sclqal].status = IT_DISABLED; } #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 7a85fb6cd..eed9c8302 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -87,6 +87,8 @@ #include "../discord.h" #endif +static void ScaleQuality_OnChange(void); + // maximum number of windowed modes (see windowedModes[][]) #define MAXWINMODES (22) @@ -117,6 +119,9 @@ static void Impl_SetVsync(void); consvar_t cv_vidwait = {"vid_wait", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Impl_SetVsync, 0, NULL, NULL, 0, 0, NULL}; static consvar_t cv_stretch = {"stretch", "Off", CV_SAVE|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t scalequality_cons_t[] = {{0, "Nearest"}, {1, "Linear"}, {2, "Best"}, {0, NULL}}; +consvar_t cv_scalequality = {"vid_scalequality", "Nearest", CV_SAVE|CV_CALL|CV_NOINIT, scalequality_cons_t, ScaleQuality_OnChange, 0, NULL, NULL, 0, 0, NULL}; + // these cant be used since config is read after window creation, so need to use command line parameter instead //static CV_PossibleValue_t msaa_cons_t[] = {{0, "Off"}, {2, "2X"}, {4, "4X"}, {8, "8X"}, {16, "16X"}, {0, NULL}}; //consvar_t cv_msaa = {"msaa", "Off", CV_SAVE, msaa_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -164,6 +169,12 @@ static SDL_Texture *texture; static SDL_bool havefocus = SDL_TRUE; static const char *fallback_resolution_name = "Fallback"; +static void ScaleQuality_OnChange(void) +{ + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, cv_scalequality.string); + COM_ImmedExecute(va("vid_mode %d", vid.modenum)); // Hack to make it apply without restarting +} + // windowed video modes from which to choose from. static INT32 windowedModes[MAXWINMODES][2] = { @@ -2109,6 +2120,7 @@ void I_StartupGraphics(void) COM_AddCommand ("vid_mode", VID_Command_Mode_f); CV_RegisterVar (&cv_vidwait); CV_RegisterVar (&cv_stretch); + CV_RegisterVar(&cv_scalequality); disable_mouse = M_CheckParm("-nomouse"); disable_fullscreen = M_CheckParm("-win") ? 1 : 0; diff --git a/src/v_video.h b/src/v_video.h index 3b011a10f..4625b3057 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -27,10 +27,10 @@ extern UINT8 *screens[5]; -extern consvar_t cv_ticrate, cv_allcaps, cv_constextsize, cv_menucaps,\ -cv_globalgamma, cv_globalsaturation, \ +extern consvar_t cv_ticrate, cv_allcaps, cv_constextsize, cv_menucaps, cv_scalequality,\ +cv_globalgamma, cv_globalsaturation,\ cv_rhue, cv_yhue, cv_ghue, cv_chue, cv_bhue, cv_mhue,\ -cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma, \ +cv_rgamma, cv_ygamma, cv_ggamma, cv_cgamma, cv_bgamma, cv_mgamma,\ cv_rsaturation, cv_ysaturation, cv_gsaturation, cv_csaturation, cv_bsaturation, cv_msaturation; From e86490103504306006d5583db868f76abd7419e2 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 01:09:10 +0100 Subject: [PATCH 02/11] Options Menu for custom console variables https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2380#9cc73f4b99ff925448389969b0ade6ba3947fc31 --- src/lua_consolelib.c | 61 +++++++++++++++++++++++++++++------ src/m_menu.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ src/m_menu.h | 7 +++- 3 files changed, 135 insertions(+), 10 deletions(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index b6ad0e17e..6c9252ff9 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -17,6 +17,11 @@ #include "byteptr.h" #include "z_zone.h" +#include "d_netfil.h" + +#include "m_menu.h" +#include "w_wad.h" + #include "lua_script.h" #include "lua_libs.h" #include "lua_hud.h" // hud_running errors @@ -186,8 +191,8 @@ static int lib_comAddCommand(lua_State *L) const char *luaname = luaL_checkstring(L, 1); // must store in all lowercase - char *name = Z_StrDup(luaname); - strlwr(name); + char *comname = Z_StrDup(luaname); + strlwr(comname); luaL_checktype(L, 2, LUA_TFUNCTION); NOHUD @@ -220,25 +225,26 @@ static int lib_comAddCommand(lua_State *L) lua_pushvalue(L, 3); lua_rawseti(L, -2, 2); - lua_setfield(L, -2, name); + lua_setfield(L, -2, comname); // Try to add the Lua command - com_return = COM_AddLuaCommand(name); + com_return = COM_AddLuaCommand(comname); if (com_return < 0) { // failed to add -- free the lowercased name and return error - Z_Free(name); + Z_Free(comname); return luaL_error(L, "Couldn't add a new console command \"%s\"", luaname); } else if (com_return == 1) { // command existed already -- free our name as the old string will continue to be used - CONS_Printf("Replaced command \"%s\"\n", name); - Z_Free(name); + CONS_Printf("Replaced command \"%s\"\n", comname); + Z_Free(comname); } else { // new command was added -- do NOT free the string as it will forever be used by the console - CONS_Printf("Added command \"%s\"\n", name); + CONS_Printf("Added command \"%s\"\n", comname); } + return 0; } @@ -314,12 +320,17 @@ static int lib_cvRegisterVar(lua_State *L) const char *k; lua_Integer i; consvar_t *cvar; + + const char* category = NULL; + const char* menu_name = NULL; + luaL_checktype(L, 1, LUA_TTABLE); lua_settop(L, 1); // Clear out all other possible arguments, leaving only the first one. NOHUD cvar = lua_newuserdata(L, sizeof(consvar_t)); luaL_getmetatable(L, META_CVAR); lua_setmetatable(L, -2); + boolean hasminmax = false; #define FIELDERROR(f, e) luaL_error(L, "bad value for " LUA_QL(f) " in table passed to " LUA_QL("CV_RegisterVar") " (%s)", e); #define TYPEERROR(f, t) FIELDERROR(f, va("%s expected, got %s", lua_typename(L, t), luaL_typename(L, -1))) @@ -385,13 +396,17 @@ static int lib_cvRegisterVar(lua_State *L) if (lua_type(L, 5) != LUA_TSTRING || lua_type(L, 6) != LUA_TNUMBER) FIELDERROR("PossibleValue", "custom PossibleValue table requires a format of string=integer, i.e. {MIN=0, MAX=9999}"); - cvpv[i].strvalue = Z_StrDup(lua_tostring(L, 5)); + char *strvalue = Z_StrDup(lua_tostring(L, 5)); + if (fasticmp(strvalue, "MIN")) + hasminmax = true; + cvpv[i].strvalue = strvalue; cvpv[i].value = (INT32)lua_tonumber(L, 6); i++; lua_pop(L, 1); } cvpv[i].value = 0; cvpv[i].strvalue = NULL; + hasminmax = false; cvar->PossibleValue = cvpv; } else FIELDERROR("PossibleValue", va("%s or CV_PossibleValue_t expected, got %s", lua_typename(L, LUA_TTABLE), luaL_typename(L, -1))) @@ -405,6 +420,18 @@ static int lib_cvRegisterVar(lua_State *L) lua_pop(L, 1); cvar->func = Lua_OnChange; } + else if (((i == 5 && !(cvar->flags & CV_CALL)) + || (cvar->flags & CV_CALL && i == 7)) + || (k && fasticmp(k, "category"))) + { + category = lua_isnoneornil(L, 4) ? NULL : lua_tostring(L, 4); + } + else if (((i == 6 && !(cvar->flags & CV_CALL)) + || (cvar->flags & CV_CALL && i == 8)) + || (k && fasticmp(k, "menuname"))) + { + menu_name = lua_isnoneornil(L, 4) ? NULL : lua_tostring(L, 4); + } lua_pop(L, 1); } #undef FIELDERROR @@ -429,6 +456,22 @@ static int lib_cvRegisterVar(lua_State *L) if (cvar->flags & CV_MODIFIED) return luaL_error(L, "failed to register cvar (probable conflict with internal variable/command names)"); + if (!(((cvar->flags & CV_HIDEN)) || (cvar->flags & CV_NOSHOWHELP)) + { + if (!category) + { + char *temp = strdup(wadfiles[numwadfiles - 1]->filename); + nameonly(temp); + + category = temp; + } + + if (menu_name && menu_name[0] != '\0') + M_SlotCvarIntoModMenu(cvar, category, menu_name, hasminmax); + else + M_SlotCvarIntoModMenu(cvar, category, cvar->name, hasminmax); + } + // return cvar userdata return 1; } diff --git a/src/m_menu.c b/src/m_menu.c index 7416bd4fd..eee6c5a11 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -50,6 +50,10 @@ #include "p_setup.h" #include "f_finale.h" +#include "lua_libs.h" + +#include "fastcmp.h" + #ifdef HWRENDER #include "hardware/hw_main.h" #endif @@ -302,6 +306,7 @@ static void M_SetupMultiHandler(INT32 choice); menu_t OP_ControlsDef, OP_AllControlsDef; menu_t OP_MouseOptionsDef, OP_Mouse2OptionsDef; menu_t OP_Joystick1Def, OP_Joystick2Def, OP_Joystick3Def, OP_Joystick4Def; +menu_t OP_CustomCvarMenuDef; static void M_VideoModeMenu(INT32 choice); static void M_Setup1PControlsMenu(INT32 choice); static void M_Setup2PControlsMenu(INT32 choice); @@ -346,6 +351,8 @@ static void M_AddonsInternal(); static void M_Addons(INT32 choice); static void M_LocalSkins(INT32 choice); static void M_AddonsOptions(INT32 choice); + +static void M_CustomCvarMenu(INT32 choice); static patch_t *addonsp[NUM_EXT+5]; static void M_DeleteProtocol(void); @@ -1095,6 +1102,7 @@ static menuitem_t OP_MainMenu[] = {IT_SUBMENU|IT_STRING, NULL, "Server Options...", &OP_ServerOptionsDef, 70}, {IT_SUBMENU|IT_STRING, NULL, "Data Options...", &OP_DataOptionsDef, 90}, + {IT_CALL|IT_STRING, NULL, "Custom Options...", M_CustomCvarMenu, 100}, {IT_CALL|IT_STRING, NULL, "Tricks & Secrets (F1)", M_Manual, 110}, {IT_CALL|IT_STRING, NULL, "Play Credits", M_Credits, 120}, @@ -2381,6 +2389,8 @@ enum syncspecialonly, }; +menuitem_t OP_CustomCvarMenu[MAXMENUCCVARS]; + // ========================================================================== // ALL MENU DEFINITIONS GO HERE // ========================================================================== @@ -2878,6 +2888,23 @@ menu_t OP_DriftGaugeDef = DEFAULTMENUSTYLE(NULL, OP_DriftGaugeMenu, &OP_SaturnDe menu_t OP_TiltDef = DEFAULTMENUSTYLE(NULL, OP_TiltMenu, &OP_BirdDef, 30, 60); menu_t OP_AdvancedBirdDef = DEFAULTMENUSTYLE(NULL, OP_AdvancedBirdMenu, &OP_BirdDef, 30, 60); +INT16 ccvarposition = 0; + +static void M_CustomCvarMenu(INT32 choice) +{ + (void)choice; + + if (ccvarposition) + M_SetupNextMenu(&OP_CustomCvarMenuDef); + else + M_StartMessage(M_GetText("No custom options were found\n"), NULL, MM_NOTHING); +} + +/*menu_t OP_CustomCvarMenuDef = DEFAULTSCROLLMENUSTYLE( + MTREE3(MN_OP_MAIN, MN_OP_DATA, MN_OP_ADDONS), + "M_ADDONS", OP_CustomCvarMenu, &OP_MainDef, 30, 30);*/ +menu_t OP_CustomCvarMenuDef = DEFAULTSCROLLSTYLE("M_ADDONS", OP_CustomCvarMenu, &OP_MainDef, 30, 30); + menu_t OP_ForkedBirdDef = { NULL, sizeof(OP_ForkedBirdMenu)/sizeof(menuitem_t), @@ -7768,6 +7795,56 @@ void M_PopupMasterServerRules(void) #endif } +#define CCVHEIGHT 5 +#define CCVHEIGHTHEADER 1 +#define CCVHEIGHTHEADERAFTER 6 + +UINT16 ccvaralphakey = 4; +INT16 ccvarlaststheader = 0; + +INT32 CVARSETUP; + +void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* name, boolean minmax) +{ + if (ccvarposition == INT16_MAX) + return; + + if (ccvarposition >= MAXMENUCCVARS - 2) + { + CONS_Printf("failed to register cvar into custom settings menu as menu reached limit\n"); + ccvarposition = INT16_MAX; + return; + } + + if (!CVARSETUP) + { + CONS_Printf("custom settings menu initiation\n"); + for (CVARSETUP = 0; CVARSETUP < MAXMENUCCVARS; ++CVARSETUP) + OP_CustomCvarMenu[CVARSETUP] = (menuitem_t){IT_DISABLED, NULL, "", 0, INT16_MAX}; + } + + if (category && ((ccvarposition == 0 && category[0] != '\0') || !fasticmp(category, OP_CustomCvarMenu[ccvarlaststheader].text))) + { + ccvarlaststheader = ccvarposition; + ccvaralphakey += CCVHEIGHTHEADER; + + OP_CustomCvarMenu[ccvarposition] = (menuitem_t){IT_HEADER, NULL, Z_StrDup(category), NULL, ccvaralphakey}; + ccvaralphakey += CCVHEIGHTHEADERAFTER; + + ++ccvarposition; + } + + if (minmax) + OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, Z_StrDup(name), cvar, ccvaralphakey }; + else if (cvar->flags & CV_FLOAT) + OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR , NULL, Z_StrDup(name), cvar, ccvaralphakey }; + else + OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR, NULL, Z_StrDup(name), cvar, ccvaralphakey }; + + ccvaralphakey += CCVHEIGHT; + ++ccvarposition; +} + // ====== // CHEATS // ====== diff --git a/src/m_menu.h b/src/m_menu.h index 805f562f8..a3760ff27 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -147,6 +147,8 @@ boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt); #define MAXSTRINGLENGTH 32 +#define MAXMENUCCVARS 999 + #define MAXTOOLTIPS 255 typedef union @@ -171,7 +173,7 @@ typedef struct menuitem_s void *itemaction; // hotkey in menu or y of the item - UINT8 alphaKey; + UINT16 alphaKey; } menuitem_t; extern menuitem_t PlayerMenu[MAXSKINS]; @@ -289,6 +291,8 @@ void M_PopupMasterServerRules(void); void M_PopupMasterServerConnectError(void); #endif +void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* name, boolean minmax); + // These defines make it a little easier to make menus #define DEFAULTMENUSTYLE(header, source, prev, x, y)\ {\ @@ -316,6 +320,7 @@ void M_PopupMasterServerConnectError(void); {NULL}\ } + #define PAUSEMENUSTYLE(source, x, y)\ {\ NULL,\ From 3492b77aa0ce3a8137280b05672b020f654ee0fe Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 01:14:36 +0100 Subject: [PATCH 03/11] we dont have IT_CV_FLOATSLIDER so dont even need to check for float --- src/m_menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index eee6c5a11..a7d0187c4 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7836,8 +7836,8 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na if (minmax) OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, Z_StrDup(name), cvar, ccvaralphakey }; - else if (cvar->flags & CV_FLOAT) - OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR , NULL, Z_StrDup(name), cvar, ccvaralphakey }; + //else if (cvar->flags & CV_FLOAT) + //OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR | IT_CV_FLOATSLIDER , NULL, Z_StrDup(name), cvar, ccvaralphakey }; else OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR, NULL, Z_StrDup(name), cvar, ccvaralphakey }; From 6e995207a68d1f2d0b4b58bee639998399d418e0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 01:15:03 +0100 Subject: [PATCH 04/11] smh --- src/lua_consolelib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 6c9252ff9..8f66d8be1 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -456,7 +456,7 @@ static int lib_cvRegisterVar(lua_State *L) if (cvar->flags & CV_MODIFIED) return luaL_error(L, "failed to register cvar (probable conflict with internal variable/command names)"); - if (!(((cvar->flags & CV_HIDEN)) || (cvar->flags & CV_NOSHOWHELP)) + if (!(((cvar->flags & CV_HIDEN)) || (cvar->flags & CV_NOSHOWHELP))) { if (!category) { From 081a7779a6b65f5b92117683193190c52d239d5d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 01:32:12 +0100 Subject: [PATCH 05/11] make netvars red --- src/m_menu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/m_menu.c b/src/m_menu.c index a7d0187c4..dfaaed282 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7838,6 +7838,8 @@ void M_SlotCvarIntoModMenu(consvar_t* cvar, const char* category, const char* na OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, Z_StrDup(name), cvar, ccvaralphakey }; //else if (cvar->flags & CV_FLOAT) //OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR | IT_CV_FLOATSLIDER , NULL, Z_StrDup(name), cvar, ccvaralphakey }; + else if (cvar->flags & CV_NETVAR) + OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR , NULL, Z_StrDup(va("\x85 %s", name)), cvar, ccvaralphakey }; else OP_CustomCvarMenu[ccvarposition] = (menuitem_t){ IT_STRING | IT_CVAR, NULL, Z_StrDup(name), cvar, ccvaralphakey }; From 75f3edcd926fe940cabea412a78e2d4273f1e652 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 01:50:35 +0100 Subject: [PATCH 06/11] shader stuffs --- src/hardware/r_opengl/r_opengl.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 5a733f056..24b4fa5c4 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -887,6 +887,11 @@ EXPORT void HWRAPI(SetShaderInfo) (hwdshaderinfo_t info, INT32 value) EXPORT void HWRAPI(SetShader) (int slot) { + if (slot == SHADER_NONE) + { + UnSetShader(); + return; + } if (gl_allowshaders) { gl_shader_t *next_shader = &gl_shaders[slot]; // the gl_shader_t we are going to switch to @@ -907,21 +912,26 @@ EXPORT void HWRAPI(SetShader) (int slot) return; } + gl_shadersenabled = false; } EXPORT void HWRAPI(UnSetShader) (void) { - gl_shaderstate.current = NULL; - gl_shaderstate.type = 0; - gl_shaderstate.program = 0; + if (gl_shadersenabled) // don't repeatedly call glUseProgram if not needed + { + gl_shaderstate.current = NULL; + gl_shaderstate.type = 0; + gl_shaderstate.program = 0; - if (pglUseProgram) - pglUseProgram(0); + if (pglUseProgram) + pglUseProgram(0); + } gl_shadersenabled = false; } + // -----------------+ // SetNoTexture : Disable texture // -----------------+ From 3c713248b326075bfc5df5bc96f290eed68d241b Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 01:53:11 +0100 Subject: [PATCH 07/11] more shader stuff --- src/hardware/hw_shaders.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index f9c755b0d..427bd1540 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -439,7 +439,7 @@ void HWR_LoadAllCustomShaders(void) // read every custom shader for (i = 0; i < numwadfiles; i++) - HWR_LoadCustomShadersFromFile(i, (wadfiles[i]->type == RET_PK3)); + HWR_LoadCustomShadersFromFile(i, W_FileHasFolders(wadfiles[i])); } void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) @@ -454,7 +454,7 @@ void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) int i; boolean modified_shaders[NUMSHADERTARGETS] = {0}; - if (!HWR_UseShader()) + if (!gr_shadersavailable) return; lump = HWR_FindShaderDefs(wadnum); From 88ce9fc0a63e5e7d66f22b2e1efe9b73d71029f9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 02:02:03 +0100 Subject: [PATCH 08/11] more stuffs --- src/hardware/r_opengl/r_opengl.c | 72 +++++++++++--------------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 24b4fa5c4..3b8fa1778 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -8,7 +8,7 @@ // terms of the GNU General Public License, version 2. // See the 'LICENSE' file for more details. //----------------------------------------------------------------------------- -/// \file +/// \file r_opengl.c /// \brief OpenGL API for Sonic Robo Blast 2 #if defined (_WIN32) @@ -26,7 +26,7 @@ #include "../../r_local.h" // For rendertimefrac, used for the leveltime shader uniform #include "r_opengl.h" #include "r_vbo.h" - +#include "../hw_shaders.h" #include "../hw_main.h" // Eeeeh not sure is this right way, but it works < sry :c < sry again it had to go :c @@ -723,29 +723,6 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f}; // -// Generic vertex shader -// - -#define GLSL_FALLBACK_VERTEX_SHADER \ - "void main()\n" \ - "{\n" \ - "gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \ - "gl_FrontColor = gl_Color;\n" \ - "gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \ - "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ - "}\0" - -// -// Generic fragment shader -// - -#define GLSL_FALLBACK_FRAGMENT_SHADER \ - "uniform sampler2D tex;\n" \ - "uniform vec4 poly_color;\n" \ - "void main(void) {\n" \ - "gl_FragColor = texture2D(tex, gl_TexCoord[0].st) * poly_color;\n" \ - "}\0" - void SetupGLFunc4(void) { @@ -959,7 +936,7 @@ static void GLPerspective(GLfloat fovy, GLfloat aspect) const GLfloat zNear = NEAR_CLIPPING_PLANE; const GLfloat zFar = FAR_CLIPPING_PLANE; const GLfloat radians = (GLfloat)(fovy / 2.0f * M_PIl / 180.0f); - const GLfloat sine = sin(radians); + const GLfloat sine = (GLfloat)sin(radians); const GLfloat deltaZ = zFar - zNear; GLfloat cotangent; @@ -1860,9 +1837,9 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF if (Surface != NULL) { - UNIFORM_1(shader->uniforms[gluniform_lighting], Surface->LightInfo.light_level, pglUniform1f); - UNIFORM_1(shader->uniforms[gluniform_fade_start], Surface->LightInfo.fade_start, pglUniform1f); - UNIFORM_1(shader->uniforms[gluniform_fade_end], Surface->LightInfo.fade_end, pglUniform1f); + UNIFORM_1(shader->uniforms[gluniform_lighting], (GLfloat)Surface->LightInfo.light_level, pglUniform1f); + UNIFORM_1(shader->uniforms[gluniform_fade_start], (GLfloat)Surface->LightInfo.fade_start, pglUniform1f); + UNIFORM_1(shader->uniforms[gluniform_fade_end], (GLfloat)Surface->LightInfo.fade_end, pglUniform1f); } UNIFORM_1(shader->uniforms[gluniform_leveltime], ((float)shader_leveltime) / TICRATE, pglUniform1f); @@ -2018,31 +1995,32 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD SetBlend(PolyFlags); //TODO: inline (#pragma..) - // PolyColor if (pSurf) { - // If Modulated, mix the surface colour to the texture + // If modulated, mix the surface colour to the texture if (CurrentPolyFlags & PF_Modulated) - { - // Poly color - poly.red = byte2float[pSurf->PolyColor.s.red]; - poly.green = byte2float[pSurf->PolyColor.s.green]; - poly.blue = byte2float[pSurf->PolyColor.s.blue]; - poly.alpha = byte2float[pSurf->PolyColor.s.alpha]; - pglColor4ubv((GLubyte*)&pSurf->PolyColor.s); + + // If the surface is either modulated or colormapped, or both + if (CurrentPolyFlags & (PF_Modulated | PF_ColorMapped)) + { + poly.red = byte2float[pSurf->PolyColor.s.red]; + poly.green = byte2float[pSurf->PolyColor.s.green]; + poly.blue = byte2float[pSurf->PolyColor.s.blue]; + poly.alpha = byte2float[pSurf->PolyColor.s.alpha]; } - // Tint color - tint.red = byte2float[pSurf->TintColor.s.red]; - tint.green = byte2float[pSurf->TintColor.s.green]; - tint.blue = byte2float[pSurf->TintColor.s.blue]; - tint.alpha = byte2float[pSurf->TintColor.s.alpha]; + // Only if the surface is colormapped + if (CurrentPolyFlags & PF_ColorMapped) + { + tint.red = byte2float[pSurf->TintColor.s.red]; + tint.green = byte2float[pSurf->TintColor.s.green]; + tint.blue = byte2float[pSurf->TintColor.s.blue]; + tint.alpha = byte2float[pSurf->TintColor.s.alpha]; - // Fade color - fade.red = byte2float[pSurf->FadeColor.s.red]; - fade.green = byte2float[pSurf->FadeColor.s.green]; - fade.blue = byte2float[pSurf->FadeColor.s.blue]; + fade.red = byte2float[pSurf->FadeColor.s.red]; + fade.green = byte2float[pSurf->FadeColor.s.green]; + fade.blue = byte2float[pSurf->FadeColor.s.blue]; fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded) From ded2c8a7c8e3a43b09e1f1d32ac3e73dfe0dcb89 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 02:03:22 +0100 Subject: [PATCH 09/11] a --- src/hardware/r_opengl/r_opengl.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 3b8fa1778..7f9cea586 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -722,7 +722,6 @@ static void Shader_SetUniforms(FSurfaceInfo *Surface, GLRGBAFloat *poly, GLRGBAF static GLRGBAFloat shader_defaultcolor = {1.0f, 1.0f, 1.0f, 1.0f}; -// void SetupGLFunc4(void) { @@ -2021,14 +2020,15 @@ static void PreparePolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FBITFIELD fade.red = byte2float[pSurf->FadeColor.s.red]; fade.green = byte2float[pSurf->FadeColor.s.green]; fade.blue = byte2float[pSurf->FadeColor.s.blue]; - fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; - - if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded) - { - pglActiveTexture(GL_TEXTURE2); - pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); - pglActiveTexture(GL_TEXTURE0); - lt_downloaded = pSurf->LightTableId; + fade.alpha = byte2float[pSurf->FadeColor.s.alpha]; + + if (pSurf->LightTableId && pSurf->LightTableId != lt_downloaded) + { + pglActiveTexture(GL_TEXTURE2); + pglBindTexture(GL_TEXTURE_2D, pSurf->LightTableId); + pglActiveTexture(GL_TEXTURE0); + lt_downloaded = pSurf->LightTableId; + } } } From e50bd4125d6f191e9a367247f480b39b71b95aa2 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 02:07:54 +0100 Subject: [PATCH 10/11] e --- src/hardware/r_opengl/r_opengl.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 7f9cea586..5f9fbcdff 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -894,15 +894,12 @@ EXPORT void HWRAPI(SetShader) (int slot) EXPORT void HWRAPI(UnSetShader) (void) { - if (gl_shadersenabled) // don't repeatedly call glUseProgram if not needed - { - gl_shaderstate.current = NULL; - gl_shaderstate.type = 0; - gl_shaderstate.program = 0; + gl_shaderstate.current = NULL; + gl_shaderstate.type = 0; + gl_shaderstate.program = 0; - if (pglUseProgram) - pglUseProgram(0); - } + if (pglUseProgram) + pglUseProgram(0); gl_shadersenabled = false; } From 91f0cdbaca1a296119b76821141a2aa5b0e6473d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 2 Mar 2024 02:15:28 +0100 Subject: [PATCH 11/11] unhack palrendering screentex stuff --- src/hardware/r_opengl/r_opengl.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 5f9fbcdff..cf7b55e1b 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -894,12 +894,15 @@ EXPORT void HWRAPI(SetShader) (int slot) EXPORT void HWRAPI(UnSetShader) (void) { - gl_shaderstate.current = NULL; - gl_shaderstate.type = 0; - gl_shaderstate.program = 0; + if (gl_shadersenabled) // don't repeatedly call glUseProgram if not needed + { + gl_shaderstate.current = NULL; + gl_shaderstate.type = 0; + gl_shaderstate.program = 0; - if (pglUseProgram) - pglUseProgram(0); + if (pglUseProgram) + pglUseProgram(0); + } gl_shadersenabled = false; } @@ -3442,7 +3445,7 @@ EXPORT void HWRAPI(DrawScreenFinalTexture)(int tex, INT32 width, INT32 height) pglDrawArrays(GL_TRIANGLE_FAN, 0, 4); if (HWR_ShouldUsePaletteRendering()) - UnSetShader(); + pglUseProgram(0); tex_downloaded = screenTextures[tex]; }