mirror of
https://github.com/libretro/RetroArch
synced 2025-03-02 19:13:34 +00:00
Overhaul shader loading logic, add --set-shader CLI option
This commit is contained in:
parent
d96d80cf5c
commit
719555bae1
@ -1204,8 +1204,6 @@ static struct config_path_setting *populate_settings_path(settings_t *settings,
|
||||
settings->paths.path_core_options, false, NULL, true);
|
||||
SETTING_PATH("libretro_info_path",
|
||||
settings->paths.path_libretro_info, false, NULL, true);
|
||||
SETTING_PATH("video_shader",
|
||||
settings->paths.path_shader, false, NULL, true);
|
||||
SETTING_PATH("content_database_path",
|
||||
settings->paths.path_content_database, false, NULL, true);
|
||||
SETTING_PATH("cheat_database_path",
|
||||
@ -2179,7 +2177,6 @@ void config_set_defaults(void)
|
||||
*settings->paths.path_content_image_history = '\0';
|
||||
*settings->paths.path_content_video_history = '\0';
|
||||
*settings->paths.path_cheat_settings = '\0';
|
||||
*settings->paths.path_shader = '\0';
|
||||
#ifndef IOS
|
||||
*settings->arrays.bundle_assets_src = '\0';
|
||||
*settings->arrays.bundle_assets_dst = '\0';
|
||||
@ -4102,11 +4099,6 @@ bool config_save_overrides(int override_type)
|
||||
|
||||
for (i = 0; i < (unsigned)path_settings_size; i++)
|
||||
{
|
||||
|
||||
/* blacklist video_shader, better handled by shader presets*/
|
||||
/* to-do: add setting to control blacklisting */
|
||||
if (string_is_equal(path_settings[i].ident, "video_shader"))
|
||||
continue;
|
||||
if (!string_is_equal(path_settings[i].ptr, path_overrides[i].ptr))
|
||||
{
|
||||
RARCH_LOG(" original: %s=%s\n",
|
||||
|
@ -625,7 +625,6 @@ typedef struct settings
|
||||
char path_content_video_history[PATH_MAX_LENGTH];
|
||||
char path_libretro_info[PATH_MAX_LENGTH];
|
||||
char path_cheat_settings[PATH_MAX_LENGTH];
|
||||
char path_shader[PATH_MAX_LENGTH];
|
||||
char path_font[PATH_MAX_LENGTH];
|
||||
char path_rgui_theme_preset[PATH_MAX_LENGTH];
|
||||
|
||||
|
@ -156,7 +156,7 @@ static void salamander_init(char *s, size_t len)
|
||||
|
||||
if (!config_exists)
|
||||
{
|
||||
config_file_t *conf = (config_file_t*)config_file_new_alloc();
|
||||
config_file_t *conf = config_file_new_alloc();
|
||||
|
||||
if (conf)
|
||||
{
|
||||
|
@ -655,8 +655,6 @@ bool video_shader_read_conf_preset(config_file_t *conf,
|
||||
string_list_free(file_list);
|
||||
}
|
||||
|
||||
command_event(CMD_EVENT_SHADER_PRESET_LOADED, NULL);
|
||||
|
||||
if (!video_shader_parse_textures(conf, shader))
|
||||
return false;
|
||||
|
||||
@ -982,11 +980,14 @@ const char *video_shader_get_preset_extension(enum rarch_shader_type type)
|
||||
|
||||
bool video_shader_any_supported(void)
|
||||
{
|
||||
gfx_ctx_flags_t flags;
|
||||
video_context_driver_get_flags(&flags);
|
||||
|
||||
return
|
||||
video_shader_is_supported(RARCH_SHADER_SLANG) ||
|
||||
video_shader_is_supported(RARCH_SHADER_HLSL) ||
|
||||
video_shader_is_supported(RARCH_SHADER_GLSL) ||
|
||||
video_shader_is_supported(RARCH_SHADER_CG);
|
||||
BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_SLANG) ||
|
||||
BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_GLSL) ||
|
||||
BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_CG) ||
|
||||
BIT32_GET(flags.flags, GFX_CTX_FLAGS_SHADERS_HLSL);
|
||||
}
|
||||
|
||||
enum rarch_shader_type video_shader_get_type_from_ext(const char *ext,
|
||||
@ -998,10 +999,11 @@ enum rarch_shader_type video_shader_get_type_from_ext(const char *ext,
|
||||
if (strlen(ext) > 1 && ext[0] == '.')
|
||||
ext++;
|
||||
|
||||
*is_preset =
|
||||
string_is_equal_case_insensitive(ext, "cgp") ||
|
||||
string_is_equal_case_insensitive(ext, "glslp") ||
|
||||
string_is_equal_case_insensitive(ext, "slangp");
|
||||
if (is_preset)
|
||||
*is_preset =
|
||||
string_is_equal_case_insensitive(ext, "cgp") ||
|
||||
string_is_equal_case_insensitive(ext, "glslp") ||
|
||||
string_is_equal_case_insensitive(ext, "slangp");
|
||||
|
||||
if (string_is_equal_case_insensitive(ext, "cgp") ||
|
||||
string_is_equal_case_insensitive(ext, "cg")
|
||||
@ -1032,10 +1034,7 @@ enum rarch_shader_type video_shader_get_type_from_ext(const char *ext,
|
||||
**/
|
||||
enum rarch_shader_type video_shader_parse_type(const char *path)
|
||||
{
|
||||
bool is_preset = false;
|
||||
if (!path)
|
||||
return RARCH_SHADER_NONE;
|
||||
return video_shader_get_type_from_ext(path_get_extension(path), &is_preset);
|
||||
return video_shader_get_type_from_ext(path_get_extension(path), NULL);
|
||||
}
|
||||
|
||||
bool video_shader_check_for_changes(void)
|
||||
|
@ -1586,7 +1586,8 @@ static int generic_action_ok(const char *path,
|
||||
flush_char = msg_hash_to_str(flush_id);
|
||||
menu_shader_manager_set_preset(shader,
|
||||
video_shader_parse_type(action_path),
|
||||
action_path);
|
||||
action_path,
|
||||
true);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
@ -59,22 +59,47 @@ void menu_shader_manager_free(void)
|
||||
**/
|
||||
bool menu_shader_manager_init(void)
|
||||
{
|
||||
bool ret = true;
|
||||
bool is_preset = false;
|
||||
config_file_t *conf = NULL;
|
||||
const char *path_shader = retroarch_get_shader_preset();
|
||||
enum rarch_shader_type type = RARCH_SHADER_NONE;
|
||||
enum rarch_shader_type type;
|
||||
const char *path_shader;
|
||||
|
||||
/* We get the shader preset directly from the video driver, so that
|
||||
* we are in sync with it (it could fail loading an auto-shader)
|
||||
* If we can't (e.g. get_current_shader is not implemented),
|
||||
* we'll load retroarch_get_shader_preset() like always */
|
||||
video_shader_ctx_t shader_info = {0};
|
||||
video_shader_driver_get_current_shader(&shader_info);
|
||||
|
||||
if (shader_info.data)
|
||||
path_shader = shader_info.data->path;
|
||||
else
|
||||
path_shader = retroarch_get_shader_preset();
|
||||
|
||||
menu_shader_manager_free();
|
||||
|
||||
menu_driver_shader = (struct video_shader*)
|
||||
calloc(1, sizeof(struct video_shader));
|
||||
|
||||
if (!menu_driver_shader || !path_shader)
|
||||
return false;
|
||||
if (!menu_driver_shader)
|
||||
{
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (string_is_empty(path_shader))
|
||||
goto end;
|
||||
|
||||
type = video_shader_get_type_from_ext(path_get_extension(path_shader),
|
||||
&is_preset);
|
||||
|
||||
if (!video_shader_is_supported(type))
|
||||
{
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (is_preset)
|
||||
{
|
||||
if (path_is_valid(path_shader))
|
||||
@ -82,53 +107,9 @@ bool menu_shader_manager_init(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (video_shader_is_supported(type))
|
||||
{
|
||||
strlcpy(menu_driver_shader->pass[0].source.path, path_shader,
|
||||
sizeof(menu_driver_shader->pass[0].source.path));
|
||||
menu_driver_shader->passes = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
char preset_path[PATH_MAX_LENGTH];
|
||||
settings_t *settings = config_get_ptr();
|
||||
const char *shader_dir =
|
||||
*settings->paths.directory_video_shader ?
|
||||
settings->paths.directory_video_shader :
|
||||
settings->paths.directory_system;
|
||||
|
||||
preset_path[0] = '\0';
|
||||
|
||||
#ifdef HAVE_GLSL
|
||||
fill_pathname_join(preset_path, shader_dir,
|
||||
"menu.glslp", sizeof(preset_path));
|
||||
|
||||
if (path_is_valid(preset_path))
|
||||
conf = config_file_new_from_path_to_string(preset_path);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CG
|
||||
if (!conf)
|
||||
{
|
||||
fill_pathname_join(preset_path, shader_dir,
|
||||
"menu.cgp", sizeof(preset_path));
|
||||
|
||||
if (path_is_valid(preset_path))
|
||||
conf = config_file_new_from_path_to_string(preset_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
if (!conf)
|
||||
{
|
||||
fill_pathname_join(preset_path, shader_dir,
|
||||
"menu.slangp", sizeof(preset_path));
|
||||
|
||||
if (path_is_valid(preset_path))
|
||||
conf = config_file_new_from_path_to_string(preset_path);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
strlcpy(menu_driver_shader->pass[0].source.path, path_shader,
|
||||
sizeof(menu_driver_shader->pass[0].source.path));
|
||||
menu_driver_shader->passes = 1;
|
||||
}
|
||||
|
||||
if (conf && video_shader_read_conf_preset(conf, menu_driver_shader))
|
||||
@ -137,7 +118,9 @@ bool menu_shader_manager_init(void)
|
||||
if (conf)
|
||||
config_file_free(conf);
|
||||
|
||||
return true;
|
||||
end:
|
||||
command_event(CMD_EVENT_SHADER_PRESET_LOADED, NULL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,36 +128,20 @@ bool menu_shader_manager_init(void)
|
||||
* @shader : Shader handle.
|
||||
* @type : Type of shader.
|
||||
* @preset_path : Preset path to load from.
|
||||
* @apply : Whether to apply the shader or just update shader information
|
||||
*
|
||||
* Sets shader preset.
|
||||
**/
|
||||
bool menu_shader_manager_set_preset(void *data,
|
||||
enum rarch_shader_type type, const char *preset_path)
|
||||
enum rarch_shader_type type, const char *preset_path, bool apply)
|
||||
{
|
||||
struct video_shader *shader = (struct video_shader*)data;
|
||||
config_file_t *conf = NULL;
|
||||
bool refresh = false;
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool ret;
|
||||
|
||||
if (!video_driver_set_shader(type, preset_path))
|
||||
if (apply && !retroarch_apply_shader(type, preset_path))
|
||||
{
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
const char *preset_file = NULL;
|
||||
|
||||
msg[0] = '\0';
|
||||
|
||||
/* Display error message */
|
||||
if (!string_is_empty(preset_path))
|
||||
preset_file = path_basename(preset_path);
|
||||
|
||||
snprintf(msg, sizeof(msg), "%s %s",
|
||||
msg_hash_to_str(MSG_FAILED_TO_APPLY_SHADER_PRESET),
|
||||
string_is_empty(preset_file) ? "(null)" : preset_file);
|
||||
|
||||
runloop_msg_queue_push(
|
||||
msg, 1, 180, true, NULL,
|
||||
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR);
|
||||
|
||||
/* We don't want to disable shaders entirely here,
|
||||
* just reset number of passes
|
||||
* > Note: Disabling shaders at this point would in
|
||||
@ -183,39 +150,49 @@ bool menu_shader_manager_set_preset(void *data,
|
||||
* turn lead to the menu selection pointer going out
|
||||
* of bounds. This causes undefined behaviour/segfaults */
|
||||
menu_shader_manager_clear_num_passes();
|
||||
|
||||
command_event(CMD_EVENT_SHADER_PRESET_LOADED, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Makes sure that we use Menu Preset shader on driver reinit.
|
||||
* Only do this when the preset actually works to avoid potential errors. */
|
||||
strlcpy(settings->paths.path_shader,
|
||||
preset_path ? preset_path : "",
|
||||
sizeof(settings->paths.path_shader));
|
||||
configuration_set_bool(settings, settings->bools.video_shader_enable, true);
|
||||
if (string_is_empty(preset_path))
|
||||
{
|
||||
menu_shader_manager_clear_num_passes();
|
||||
command_event(CMD_EVENT_SHADER_PRESET_LOADED, NULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!preset_path || !shader)
|
||||
return false;
|
||||
if (!shader)
|
||||
{
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* Load stored Preset into menu on success.
|
||||
* Used when a preset is directly loaded.
|
||||
* No point in updating when the Preset was
|
||||
* created from the menu itself. */
|
||||
if (!(conf = config_file_new_from_path_to_string(preset_path)))
|
||||
return false;
|
||||
{
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
RARCH_LOG("Setting Menu shader: %s.\n", preset_path);
|
||||
|
||||
if (video_shader_read_conf_preset(conf, shader))
|
||||
video_shader_resolve_parameters(conf, shader);
|
||||
|
||||
config_file_free(conf);
|
||||
if (conf)
|
||||
config_file_free(conf);
|
||||
|
||||
ret = true;
|
||||
|
||||
end:
|
||||
command_event(CMD_EVENT_SHADER_PRESET_LOADED, NULL);
|
||||
#ifdef HAVE_MENU
|
||||
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -269,39 +246,9 @@ bool menu_shader_manager_save_preset(
|
||||
}
|
||||
else
|
||||
{
|
||||
char default_preset[PATH_MAX_LENGTH];
|
||||
|
||||
default_preset[0] = '\0';
|
||||
|
||||
if (video_shader_is_supported(type))
|
||||
{
|
||||
const char *config_path = path_get(RARCH_PATH_CONFIG);
|
||||
/* In a multi-config setting, we can't have
|
||||
* conflicts on menu.cgp/menu.glslp. */
|
||||
const char *preset_ext = video_shader_get_preset_extension(type);
|
||||
|
||||
if (!string_is_empty(preset_ext))
|
||||
{
|
||||
if (config_path)
|
||||
{
|
||||
fill_pathname_base_ext(default_preset,
|
||||
config_path,
|
||||
preset_ext,
|
||||
sizeof(default_preset));
|
||||
}
|
||||
else
|
||||
{
|
||||
strlcpy(default_preset, "menu",
|
||||
sizeof(default_preset));
|
||||
strlcat(default_preset,
|
||||
preset_ext,
|
||||
sizeof(default_preset));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string_is_empty(default_preset))
|
||||
strlcpy(buffer, default_preset, sizeof(buffer));
|
||||
const char *preset_ext = video_shader_get_preset_extension(type);
|
||||
strlcpy(buffer, "retroarch", sizeof(buffer));
|
||||
strlcat(buffer, preset_ext, sizeof(buffer));
|
||||
}
|
||||
|
||||
if (!fullpath)
|
||||
@ -319,7 +266,7 @@ bool menu_shader_manager_save_preset(
|
||||
dirs[2] = config_directory;
|
||||
}
|
||||
|
||||
if (!(conf = (config_file_t*)config_file_new_alloc()))
|
||||
if (!(conf = config_file_new_alloc()))
|
||||
return false;
|
||||
|
||||
if (fullpath)
|
||||
@ -333,7 +280,7 @@ bool menu_shader_manager_save_preset(
|
||||
{
|
||||
RARCH_LOG("Saved shader preset to %s.\n", preset_path);
|
||||
if (apply)
|
||||
menu_shader_manager_set_preset(NULL, type, preset_path);
|
||||
menu_shader_manager_set_preset(NULL, type, preset_path, true);
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
@ -355,7 +302,7 @@ bool menu_shader_manager_save_preset(
|
||||
{
|
||||
RARCH_LOG("Saved shader preset to %s.\n", preset_path);
|
||||
if (apply)
|
||||
menu_shader_manager_set_preset(NULL, type, preset_path);
|
||||
menu_shader_manager_set_preset(NULL, type, preset_path, true);
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
@ -381,8 +328,7 @@ int menu_shader_manager_clear_num_passes(void)
|
||||
if (!shader)
|
||||
return 0;
|
||||
|
||||
if (shader->passes)
|
||||
shader->passes = 0;
|
||||
shader->passes = 0;
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
|
||||
@ -509,20 +455,5 @@ void menu_shader_manager_apply_changes(void)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Fall-back */
|
||||
shader_type = DEFAULT_SHADER_TYPE;
|
||||
|
||||
if (shader_type == RARCH_SHADER_NONE)
|
||||
{
|
||||
if (video_shader_is_supported(RARCH_SHADER_GLSL))
|
||||
shader_type = RARCH_SHADER_GLSL;
|
||||
else if (
|
||||
video_shader_is_supported(RARCH_SHADER_CG) ||
|
||||
video_shader_is_supported(RARCH_SHADER_HLSL)
|
||||
)
|
||||
shader_type = RARCH_SHADER_CG;
|
||||
else if (video_shader_is_supported(RARCH_SHADER_SLANG))
|
||||
shader_type = RARCH_SHADER_SLANG;
|
||||
}
|
||||
menu_shader_manager_set_preset(NULL, shader_type, NULL);
|
||||
menu_shader_manager_set_preset(NULL, shader_type, NULL, true);
|
||||
}
|
||||
|
@ -40,11 +40,12 @@ bool menu_shader_manager_init(void);
|
||||
* @shader : Shader handle.
|
||||
* @type : Type of shader.
|
||||
* @preset_path : Preset path to load from.
|
||||
* @apply : Whether to apply the shader or just update shader information
|
||||
*
|
||||
* Sets shader preset.
|
||||
**/
|
||||
bool menu_shader_manager_set_preset(
|
||||
void *data, enum rarch_shader_type type, const char *preset_path);
|
||||
void *data, enum rarch_shader_type type, const char *preset_path, bool apply);
|
||||
|
||||
/**
|
||||
* menu_shader_manager_save_preset:
|
||||
|
191
retroarch.c
191
retroarch.c
@ -786,7 +786,8 @@ enum
|
||||
RA_OPT_LOG_FILE,
|
||||
RA_OPT_MAX_FRAMES,
|
||||
RA_OPT_MAX_FRAMES_SCREENSHOT,
|
||||
RA_OPT_MAX_FRAMES_SCREENSHOT_PATH
|
||||
RA_OPT_MAX_FRAMES_SCREENSHOT_PATH,
|
||||
RA_OPT_SET_SHADER
|
||||
};
|
||||
|
||||
enum runloop_state
|
||||
@ -897,7 +898,9 @@ static bool shader_presets_need_reload = true;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
|
||||
static char runtime_shader_preset[255] = {0};
|
||||
static char cli_shader[PATH_MAX_LENGTH] = {0};
|
||||
static bool cli_shader_disable = false;
|
||||
static char runtime_shader_preset[PATH_MAX_LENGTH] = {0};
|
||||
#endif
|
||||
static char runloop_max_frames_screenshot_path[PATH_MAX_LENGTH] = {0};
|
||||
static char runtime_content_path[PATH_MAX_LENGTH] = {0};
|
||||
@ -1300,8 +1303,17 @@ static bool wifi_driver_active = false;
|
||||
|
||||
/* VIDEO GLOBAL VARIABLES */
|
||||
|
||||
/* unset a runtime shader preset */
|
||||
static void retroarch_unset_shader_preset(void)
|
||||
static void retroarch_set_runtime_shader_preset(const char *arg)
|
||||
{
|
||||
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
|
||||
if (!string_is_empty(arg))
|
||||
strlcpy(runtime_shader_preset, arg, sizeof(runtime_shader_preset));
|
||||
else
|
||||
runtime_shader_preset[0] = '\0';
|
||||
#endif
|
||||
}
|
||||
|
||||
static void retroarch_unset_runtime_shader_preset(void)
|
||||
{
|
||||
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
|
||||
runtime_shader_preset[0] = '\0';
|
||||
@ -2186,44 +2198,87 @@ static const struct cmd_map map[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
bool retroarch_apply_shader(enum rarch_shader_type type, const char *preset_path)
|
||||
{
|
||||
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
|
||||
settings_t *settings = configuration_settings;
|
||||
bool ret;
|
||||
bool refresh;
|
||||
char msg[256];
|
||||
const char *preset_file = NULL;
|
||||
|
||||
if (!string_is_empty(preset_path))
|
||||
preset_file = path_basename(preset_path);
|
||||
|
||||
ret = video_driver_set_shader(type, preset_path);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
configuration_set_bool(settings, settings->bools.video_shader_enable, true);
|
||||
retroarch_set_runtime_shader_preset(preset_path);
|
||||
|
||||
/* reflect in shader manager */
|
||||
menu_shader_manager_set_preset(menu_shader_get(), type, preset_path, false);
|
||||
|
||||
/* Display message */
|
||||
snprintf(msg, sizeof(msg),
|
||||
"Shader: \"%s\"", preset_file ? preset_file : "(null)");
|
||||
#ifdef HAVE_MENU_WIDGETS
|
||||
if (menu_widgets_inited)
|
||||
menu_widgets_set_message(msg);
|
||||
else
|
||||
#endif
|
||||
runloop_msg_queue_push(msg, 1, 120, true, NULL,
|
||||
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
||||
RARCH_LOG("%s \"%s\".\n",
|
||||
msg_hash_to_str(MSG_APPLYING_SHADER),
|
||||
preset_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
retroarch_set_runtime_shader_preset(NULL);
|
||||
|
||||
/* reflect in shader manager */
|
||||
menu_shader_manager_set_preset(menu_shader_get(), type, NULL, false);
|
||||
|
||||
/* Display error message */
|
||||
snprintf(msg, sizeof(msg), "%s %s",
|
||||
msg_hash_to_str(MSG_FAILED_TO_APPLY_SHADER_PRESET),
|
||||
preset_file ? preset_file : "(null)");
|
||||
|
||||
runloop_msg_queue_push(
|
||||
msg, 1, 180, true, NULL,
|
||||
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR);
|
||||
}
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool command_set_shader(const char *arg)
|
||||
{
|
||||
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
|
||||
char msg[256];
|
||||
bool is_preset = false;
|
||||
settings_t *settings = configuration_settings;
|
||||
enum rarch_shader_type type = video_shader_get_type_from_ext(
|
||||
path_get_extension(arg), &is_preset);
|
||||
enum rarch_shader_type type = video_shader_parse_type(arg);
|
||||
|
||||
if (type == RARCH_SHADER_NONE || !video_shader_is_supported(type))
|
||||
return false;
|
||||
if (!string_is_empty(arg))
|
||||
{
|
||||
if (!video_shader_is_supported(type))
|
||||
return false;
|
||||
|
||||
snprintf(msg, sizeof(msg),
|
||||
"Shader: \"%s\"", arg ? path_basename(arg) : "null");
|
||||
#ifdef HAVE_MENU_WIDGETS
|
||||
if (menu_widgets_inited)
|
||||
menu_widgets_set_message(msg);
|
||||
else
|
||||
#endif
|
||||
runloop_msg_queue_push(msg, 1, 120, true, NULL,
|
||||
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
||||
RARCH_LOG("%s \"%s\".\n",
|
||||
msg_hash_to_str(MSG_APPLYING_SHADER),
|
||||
arg);
|
||||
/* rebase on shader directory */
|
||||
if (!path_is_absolute(arg))
|
||||
{
|
||||
char abs_arg[PATH_MAX_LENGTH];
|
||||
const char *ref_path = configuration_settings->paths.directory_video_shader;
|
||||
fill_pathname_join(abs_arg,
|
||||
ref_path, arg, sizeof(abs_arg));
|
||||
arg = abs_arg;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
|
||||
if (!string_is_empty(arg))
|
||||
strlcpy(runtime_shader_preset, arg, sizeof(runtime_shader_preset));
|
||||
else
|
||||
runtime_shader_preset[0] = '\0';
|
||||
#ifdef HAVE_MENU
|
||||
if (!menu_shader_manager_set_preset(menu_shader_get(), type, arg))
|
||||
return false;
|
||||
#endif
|
||||
#endif
|
||||
if (settings && !settings->bools.video_shader_enable)
|
||||
settings->bools.video_shader_enable = true;
|
||||
return true;
|
||||
return retroarch_apply_shader(type, arg);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
@ -3021,7 +3076,7 @@ static void command_event_deinit_core(bool reinit)
|
||||
driver_uninit(DRIVERS_CMD_ALL);
|
||||
|
||||
command_event_disable_overrides();
|
||||
retroarch_unset_shader_preset();
|
||||
retroarch_unset_runtime_shader_preset();
|
||||
|
||||
if ( runloop_remaps_core_active
|
||||
|| runloop_remaps_content_dir_active
|
||||
@ -4110,7 +4165,7 @@ bool command_event(enum event_command cmd, void *data)
|
||||
command_event_runtime_log_deinit();
|
||||
command_event_save_auto_state();
|
||||
command_event_disable_overrides();
|
||||
retroarch_unset_shader_preset();
|
||||
retroarch_unset_runtime_shader_preset();
|
||||
|
||||
if ( runloop_remaps_core_active
|
||||
|| runloop_remaps_content_dir_active
|
||||
@ -20836,6 +20891,9 @@ static void retroarch_print_help(const char *arg0)
|
||||
#endif
|
||||
puts(" -s, --save=PATH Path for save files (*.srm).");
|
||||
puts(" -S, --savestate=PATH Path for the save state files (*.state).");
|
||||
puts(" --set-shader PATH Path to a shader (preset) that will be loaded each time content is loaded.\n"
|
||||
" Effectively overrides core shader presets.\n"
|
||||
" An empty argument \"\" will disable shader core presets.");
|
||||
puts(" -f, --fullscreen Start the program in fullscreen regardless "
|
||||
"of config settings.");
|
||||
puts(" -c, --config=FILE Path for config file."
|
||||
@ -20990,6 +21048,7 @@ static void retroarch_parse_input_and_config(int argc, char *argv[])
|
||||
{ "dualanalog", 1, NULL, 'A' },
|
||||
{ "device", 1, NULL, 'd' },
|
||||
{ "savestate", 1, NULL, 'S' },
|
||||
{ "set-shader", 1, NULL, RA_OPT_SET_SHADER },
|
||||
{ "bsvplay", 1, NULL, 'P' },
|
||||
{ "bsvrecord", 1, NULL, 'R' },
|
||||
{ "sram-mode", 1, NULL, 'M' },
|
||||
@ -21255,6 +21314,26 @@ static void retroarch_parse_input_and_config(int argc, char *argv[])
|
||||
recording_enable = true;
|
||||
break;
|
||||
|
||||
case RA_OPT_SET_SHADER:
|
||||
/* disable auto-shaders */
|
||||
if (string_is_empty(optarg))
|
||||
{
|
||||
cli_shader_disable = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/* rebase on shader directory */
|
||||
if (!path_is_absolute(optarg))
|
||||
{
|
||||
char *ref_path = configuration_settings->paths.directory_video_shader;
|
||||
fill_pathname_join(cli_shader,
|
||||
ref_path, optarg, sizeof(cli_shader));
|
||||
break;
|
||||
}
|
||||
|
||||
strlcpy(cli_shader, optarg, sizeof(cli_shader));
|
||||
break;
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
case 'L':
|
||||
{
|
||||
@ -22649,12 +22728,8 @@ static bool retroarch_load_shader_preset_internal(
|
||||
/* Shader preset exists, load it. */
|
||||
RARCH_LOG("[Shaders]: Specific shader preset found at %s.\n",
|
||||
shader_path);
|
||||
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
|
||||
if (!string_is_empty(shader_path))
|
||||
strlcpy(runtime_shader_preset, shader_path, sizeof(runtime_shader_preset));
|
||||
else
|
||||
runtime_shader_preset[0] = '\0';
|
||||
#endif
|
||||
retroarch_set_runtime_shader_preset(shader_path);
|
||||
|
||||
free(shader_path);
|
||||
return true;
|
||||
}
|
||||
@ -22743,24 +22818,26 @@ success:
|
||||
#endif
|
||||
|
||||
/* get the name of the current shader preset */
|
||||
char* retroarch_get_shader_preset(void)
|
||||
const char* retroarch_get_shader_preset(void)
|
||||
{
|
||||
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
|
||||
settings_t *settings = configuration_settings;
|
||||
if (!settings->bools.video_shader_enable)
|
||||
return NULL;
|
||||
|
||||
if (shader_presets_need_reload)
|
||||
{
|
||||
retroarch_load_shader_preset();
|
||||
shader_presets_need_reload = false;
|
||||
}
|
||||
|
||||
if (!string_is_empty(runtime_shader_preset))
|
||||
return runtime_shader_preset;
|
||||
|
||||
if (!string_is_empty(settings->paths.path_shader))
|
||||
return settings->paths.path_shader;
|
||||
/* load auto-shader once, --set-shader works like a global auto-shader */
|
||||
if (shader_presets_need_reload && !cli_shader_disable)
|
||||
{
|
||||
shader_presets_need_reload = false;
|
||||
if (video_shader_is_supported(video_shader_parse_type(cli_shader)))
|
||||
strlcpy(runtime_shader_preset, cli_shader, sizeof(runtime_shader_preset));
|
||||
else
|
||||
retroarch_load_shader_preset(); /* sets runtime_shader_preset */
|
||||
return runtime_shader_preset;
|
||||
}
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
@ -22951,7 +23028,7 @@ bool retroarch_main_quit(void)
|
||||
{
|
||||
command_event_save_auto_state();
|
||||
command_event_disable_overrides();
|
||||
retroarch_unset_shader_preset();
|
||||
retroarch_unset_runtime_shader_preset();
|
||||
|
||||
if ( runloop_remaps_core_active
|
||||
|| runloop_remaps_content_dir_active
|
||||
@ -24752,10 +24829,10 @@ static bool rarch_write_debug_info(void)
|
||||
|
||||
if (shader_info.data)
|
||||
{
|
||||
if (string_is_equal(shader_info.data->path, settings->paths.path_shader))
|
||||
filestream_printf(file, " - Video Shader: %s\n", !string_is_empty(settings->paths.path_shader) ? settings->paths.path_shader : "n/a");
|
||||
if (string_is_equal(shader_info.data->path, runtime_shader_preset))
|
||||
filestream_printf(file, " - Video Shader: %s\n", !string_is_empty(runtime_shader_preset) ? runtime_shader_preset : "n/a");
|
||||
else
|
||||
filestream_printf(file, " - Video Shader: %s (configured for %s)\n", !string_is_empty(shader_info.data->path) ? shader_info.data->path : "n/a", !string_is_empty(settings->paths.path_shader) ? settings->paths.path_shader : "n/a");
|
||||
filestream_printf(file, " - Video Shader: %s (configured for %s)\n", !string_is_empty(shader_info.data->path) ? shader_info.data->path : "n/a", !string_is_empty(runtime_shader_preset) ? runtime_shader_preset : "n/a");
|
||||
}
|
||||
else
|
||||
filestream_printf(file, " - Video Shader: n/a\n");
|
||||
|
@ -38,6 +38,7 @@
|
||||
#endif
|
||||
|
||||
#include "audio/audio_defines.h"
|
||||
#include "gfx/video_shader_parse.h"
|
||||
|
||||
#include "core_type.h"
|
||||
#include "core.h"
|
||||
@ -306,7 +307,9 @@ bool retroarch_is_forced_fullscreen(void);
|
||||
void retroarch_set_current_core_type(
|
||||
enum rarch_core_type type, bool explicitly_set);
|
||||
|
||||
char* retroarch_get_shader_preset(void);
|
||||
bool retroarch_apply_shader(enum rarch_shader_type type, const char *preset_path);
|
||||
|
||||
const char* retroarch_get_shader_preset(void);
|
||||
|
||||
bool retroarch_is_switching_display_mode(void);
|
||||
|
||||
@ -762,7 +765,6 @@ void recording_driver_update_streaming_url(void);
|
||||
#include "gfx/video_defines.h"
|
||||
#include "gfx/video_coord_array.h"
|
||||
#include "gfx/video_filter.h"
|
||||
#include "gfx/video_shader_parse.h"
|
||||
|
||||
#include "input/input_driver.h"
|
||||
#include "input/input_types.h"
|
||||
|
@ -510,7 +510,7 @@ void ShaderParamsDialog::onShaderLoadPresetClicked()
|
||||
|
||||
type = video_shader_parse_type(pathData);
|
||||
|
||||
menu_shader_manager_set_preset(menu_shader, type, pathData);
|
||||
menu_shader_manager_set_preset(menu_shader, type, pathData, true);
|
||||
}
|
||||
|
||||
void ShaderParamsDialog::onShaderResetPass(int pass)
|
||||
|
Loading…
x
Reference in New Issue
Block a user