Fix shader toggle and add hotkey + sublabel (#14628)

This commit is contained in:
sonninnos 2022-11-15 23:14:09 +02:00 committed by GitHub
parent 7ca0d36169
commit 3b921ffbfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 96 additions and 26 deletions

View File

@ -255,6 +255,7 @@ enum event_command
CMD_EVENT_BSV_RECORDING_TOGGLE,
CMD_EVENT_SHADER_NEXT,
CMD_EVENT_SHADER_PREV,
CMD_EVENT_SHADER_TOGGLE,
CMD_EVENT_CHEAT_INDEX_PLUS,
CMD_EVENT_CHEAT_INDEX_MINUS,
CMD_EVENT_CHEAT_TOGGLE,
@ -463,6 +464,7 @@ static const struct cmd_map map[] = {
{ "RESET", RARCH_RESET },
{ "SHADER_NEXT", RARCH_SHADER_NEXT },
{ "SHADER_PREV", RARCH_SHADER_PREV },
{ "SHADER_TOGGLE", RARCH_SHADER_TOGGLE },
{ "CHEAT_INDEX_PLUS", RARCH_CHEAT_INDEX_PLUS },
{ "CHEAT_INDEX_MINUS", RARCH_CHEAT_INDEX_MINUS },
{ "CHEAT_TOGGLE", RARCH_CHEAT_TOGGLE },

View File

@ -409,6 +409,13 @@ static const struct retro_keybind retro_keybinds_1[] = {
RARCH_SHADER_PREV, NO_BTN, NO_BTN, 0,
true
},
{
NULL, NULL,
AXIS_NONE, AXIS_NONE, AXIS_NONE,
MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE, RETROK_UNKNOWN,
RARCH_SHADER_TOGGLE, NO_BTN, NO_BTN, 0,
true
},
{
NULL, NULL,
AXIS_NONE, AXIS_NONE, AXIS_NONE,
@ -998,6 +1005,13 @@ static const struct retro_keybind retro_keybinds_1[] = {
RARCH_SHADER_PREV, NO_BTN, NO_BTN, 0,
true
},
{
NULL, NULL,
AXIS_NONE, AXIS_NONE, AXIS_NONE,
MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE, RETROK_UNKNOWN,
RARCH_SHADER_TOGGLE, NO_BTN, NO_BTN, 0,
true
},
{
NULL, NULL,
AXIS_NONE, AXIS_NONE, AXIS_NONE,
@ -1597,6 +1611,13 @@ static const struct retro_keybind retro_keybinds_1[] = {
RARCH_SHADER_PREV, NO_BTN, NO_BTN, 0,
true
},
{
NULL, NULL,
AXIS_NONE, AXIS_NONE, AXIS_NONE,
MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE, RETROK_COMMA,
RARCH_SHADER_TOGGLE, NO_BTN, NO_BTN, 0,
true
},
{
NULL, NULL,
AXIS_NONE, AXIS_NONE, AXIS_NONE,

View File

@ -329,6 +329,7 @@ const struct input_bind_map input_config_bind_map[RARCH_BIND_LIST_END_NULL] = {
DECLARE_META_BIND(2, reset, RARCH_RESET, MENU_ENUM_LABEL_VALUE_INPUT_META_RESET),
DECLARE_META_BIND(2, shader_next, RARCH_SHADER_NEXT, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_NEXT),
DECLARE_META_BIND(2, shader_prev, RARCH_SHADER_PREV, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_PREV),
DECLARE_META_BIND(2, shader_toggle, RARCH_SHADER_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE),
DECLARE_META_BIND(2, cheat_index_plus, RARCH_CHEAT_INDEX_PLUS, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_PLUS),
DECLARE_META_BIND(2, cheat_index_minus, RARCH_CHEAT_INDEX_MINUS, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_MINUS),
DECLARE_META_BIND(2, cheat_toggle, RARCH_CHEAT_TOGGLE, MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_TOGGLE),

View File

@ -2653,3 +2653,26 @@ const char *retroarch_get_shader_preset(void)
return NULL;
}
void video_shader_toggle(settings_t *settings)
{
bool toggle = !settings->bools.video_shader_enable;
bool refresh = false;
struct video_shader *shader = menu_shader_get();
shader->flags |= SHDR_FLAG_MODIFIED;
if (toggle)
shader->flags &= ~SHDR_FLAG_DISABLED;
else
shader->flags |= SHDR_FLAG_DISABLED;
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL);
/* TODO/FIXME: Due to general_write_handler being called twice,
* this has be done in this order in order to truly disable */
if (!toggle)
configuration_set_bool(settings, settings->bools.video_shader_enable, toggle);
}

View File

@ -153,7 +153,8 @@ enum video_shader_flags
SHDR_FLAG_MODERN = (1 << 0), /* Only used for XML shaders. */
/* Indicative of whether shader was modified -
* for instance from the menus */
SHDR_FLAG_MODIFIED = (1 << 1)
SHDR_FLAG_MODIFIED = (1 << 1),
SHDR_FLAG_DISABLED = (1 << 2)
};
/* This is pretty big, shouldn't be put on the stack.
@ -316,6 +317,8 @@ bool apply_shader(
const char *video_shader_get_preset_extension(enum rarch_shader_type type);
void video_shader_toggle(settings_t *settings);
RETRO_END_DECLS
#endif

View File

@ -93,6 +93,7 @@ enum
RARCH_RESET,
RARCH_SHADER_NEXT,
RARCH_SHADER_PREV,
RARCH_SHADER_TOGGLE,
RARCH_CHEAT_INDEX_PLUS,
RARCH_CHEAT_INDEX_MINUS,
RARCH_CHEAT_TOGGLE,

View File

@ -2898,6 +2898,14 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_META_SHADER_PREV,
"Loads and applies the previous shader preset file in the root of the 'Video Shaders' directory."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE,
"Shader (Toggle)"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_META_SHADER_TOGGLE,
"Switches the currently selected shader on/off."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_PLUS,
"Next Cheat Index"
@ -7974,6 +7982,10 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_VIDEO_SHADERS_ENABLE,
"Video Shaders"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_VIDEO_SHADERS_ENABLE,
"Enable video shader pipeline."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_SHADER_WATCH_FOR_CHANGES,
"Watch Shader Files for Changes"

View File

@ -392,6 +392,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_frameadvance, ME
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_reset, MENU_ENUM_SUBLABEL_INPUT_META_RESET)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_shader_next, MENU_ENUM_SUBLABEL_INPUT_META_SHADER_NEXT)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_shader_prev, MENU_ENUM_SUBLABEL_INPUT_META_SHADER_PREV)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_shader_toggle, MENU_ENUM_SUBLABEL_INPUT_META_SHADER_TOGGLE)
#ifdef HAVE_CHEATS
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_cheat_index_plus, MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_INDEX_PLUS)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_cheat_index_minus, MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_INDEX_MINUS)
@ -1037,6 +1038,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_shader_directory,
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_recording_output_directory, MENU_ENUM_SUBLABEL_RECORDING_OUTPUT_DIRECTORY)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_recording_config_directory, MENU_ENUM_SUBLABEL_RECORDING_CONFIG_DIRECTORY)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_font_path, MENU_ENUM_SUBLABEL_VIDEO_FONT_PATH)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_shaders_enable, MENU_ENUM_SUBLABEL_VIDEO_SHADERS_ENABLE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_apply_changes, MENU_ENUM_SUBLABEL_SHADER_APPLY_CHANGES)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_shader_watch_for_changes, MENU_ENUM_SUBLABEL_SHADER_WATCH_FOR_CHANGES)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_shader_remember_last_dir, MENU_ENUM_SUBLABEL_VIDEO_SHADER_REMEMBER_LAST_DIR)
@ -2130,6 +2132,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case RARCH_SHADER_PREV:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_shader_prev);
return 0;
case RARCH_SHADER_TOGGLE:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_shader_toggle);
return 0;
case RARCH_CHEAT_INDEX_PLUS:
#ifdef HAVE_CHEATS
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_meta_cheat_index_plus);
@ -2452,6 +2457,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_VIDEO_SHADER_NUM_PASSES:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_shader_num_passes);
break;
case MENU_ENUM_LABEL_VIDEO_SHADERS_ENABLE:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_video_shaders_enable);
break;
case MENU_ENUM_LABEL_SHADER_APPLY_CHANGES:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_shader_apply_changes);
break;

View File

@ -2908,7 +2908,9 @@ void menu_shader_manager_apply_changes(
type = menu_shader_manager_get_type(shader);
if (shader->passes && type != RARCH_SHADER_NONE)
if (shader->passes
&& type != RARCH_SHADER_NONE
&& !(shader->flags & SHDR_FLAG_DISABLED))
{
menu_shader_manager_save_preset(shader, NULL,
dir_video_shader, dir_menu_config, true);
@ -3554,8 +3556,12 @@ bool rarch_menu_init(
}
#endif
#if 0
/* TODO: No reason to do this here since shaders need
* content, and this is called in content_load() */
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
menu_shader_manager_init();
#endif
#endif
return true;

View File

@ -7863,26 +7863,8 @@ static void general_write_handler(rarch_setting_t *setting)
case MENU_ENUM_LABEL_VIDEO_SHADERS_ENABLE:
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
{
if (*setting->value.target.boolean)
{
bool refresh = false;
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
}
else
{
bool refresh = false;
settings_t *settings = config_get_ptr();
struct video_shader *shader = menu_shader_get();
shader->passes = 0;
shader->flags |= SHDR_FLAG_MODIFIED;
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
command_event(CMD_EVENT_SHADERS_APPLY_CHANGES, NULL);
configuration_set_bool(settings, settings->bools.video_shader_enable, false);
}
settings_t *settings = config_get_ptr();
video_shader_toggle(settings);
}
#endif
break;

View File

@ -914,6 +914,7 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_INPUT_META_RESET,
MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_NEXT,
MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_PREV,
MENU_ENUM_LABEL_VALUE_INPUT_META_SHADER_TOGGLE,
MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_PLUS,
MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_INDEX_MINUS,
MENU_ENUM_LABEL_VALUE_INPUT_META_CHEAT_TOGGLE,
@ -976,6 +977,7 @@ enum msg_hash_enums
MENU_ENUM_SUBLABEL_INPUT_META_RESET,
MENU_ENUM_SUBLABEL_INPUT_META_SHADER_NEXT,
MENU_ENUM_SUBLABEL_INPUT_META_SHADER_PREV,
MENU_ENUM_SUBLABEL_INPUT_META_SHADER_TOGGLE,
MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_INDEX_PLUS,
MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_INDEX_MINUS,
MENU_ENUM_SUBLABEL_INPUT_META_CHEAT_TOGGLE,
@ -1886,6 +1888,7 @@ enum msg_hash_enums
MENU_LABEL(CHEAT_INDEX_PLUS),
MENU_LABEL(SHADER_NEXT),
MENU_LABEL(SHADER_PREV),
MENU_LABEL(SHADER_TOGGLE),
MENU_LABEL(FRAME_ADVANCE),
MENU_LABEL(FPS_SHOW),
MENU_LABEL(FPS_UPDATE_INTERVAL),

View File

@ -1533,6 +1533,11 @@ bool command_event(enum event_command cmd, void *data)
dir_check_shader(NULL, settings,
&video_st->dir_shader_list, false, true);
#endif
#endif
break;
case CMD_EVENT_SHADER_TOGGLE:
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
video_shader_toggle(settings);
#endif
break;
case CMD_EVENT_BSV_RECORDING_TOGGLE:

View File

@ -580,6 +580,7 @@
# Applies next and previous shader in directory.
# input_shader_next = m
# input_shader_prev = n
# input_shader_toggle = comma
# Hold button down to rewind. Rewinding must be enabled.
# input_rewind = r

View File

@ -7565,10 +7565,6 @@ static enum runloop_state_enum runloop_check_state(
/* Check movie record toggle */
HOTKEY_CHECK(RARCH_BSV_RECORD_TOGGLE, CMD_EVENT_BSV_RECORDING_TOGGLE, true, NULL);
/* Check shader prev/next */
HOTKEY_CHECK(RARCH_SHADER_NEXT, CMD_EVENT_SHADER_NEXT, true, NULL);
HOTKEY_CHECK(RARCH_SHADER_PREV, CMD_EVENT_SHADER_PREV, true, NULL);
/* Check if we have pressed any of the disk buttons */
HOTKEY_CHECK3(
RARCH_DISK_EJECT_TOGGLE, CMD_EVENT_DISK_EJECT_TOGGLE,
@ -7585,6 +7581,12 @@ static enum runloop_state_enum runloop_check_state(
RARCH_CHEAT_TOGGLE, CMD_EVENT_CHEAT_TOGGLE);
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
/* Check shader prev/next/toggle */
HOTKEY_CHECK3(
RARCH_SHADER_NEXT, CMD_EVENT_SHADER_NEXT,
RARCH_SHADER_PREV, CMD_EVENT_SHADER_PREV,
RARCH_SHADER_TOGGLE, CMD_EVENT_SHADER_TOGGLE);
if (settings->bools.video_shader_watch_files)
{
static rarch_timer_t timer = {0};