readd shader to config, let's use a runtime check instead of overwritting the shader preset all the time

This commit is contained in:
radius 2018-01-29 22:11:08 -05:00
parent d5dbfe78d5
commit c64d5556c1
9 changed files with 65 additions and 62 deletions

View File

@ -1295,31 +1295,13 @@ static void command_event_disable_overrides(void)
return;
/* reload the original config */
config_unload_override();
rarch_ctl(RARCH_CTL_UNSET_OVERRIDES_ACTIVE, NULL);
}
static void command_event_restore_default_shader_preset(void)
{
if (!path_is_empty(RARCH_PATH_DEFAULT_SHADER_PRESET))
{
/* auto shader preset: reload the original shader */
settings_t *settings = config_get_ptr();
const char *shader_preset = path_get(RARCH_PATH_DEFAULT_SHADER_PRESET);
if (!string_is_empty(shader_preset))
{
RARCH_LOG("%s %s\n",
msg_hash_to_str(MSG_RESTORING_DEFAULT_SHADER_PRESET_TO),
shader_preset);
strlcpy(settings->paths.path_shader,
shader_preset,
sizeof(settings->paths.path_shader));
}
}
path_clear(RARCH_PATH_DEFAULT_SHADER_PRESET);
retroarch_unset_shader_preset();
}
static void command_event_restore_remaps(void)

View File

@ -1070,6 +1070,8 @@ 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",
@ -2873,41 +2875,28 @@ static bool config_load_file(const char *path, bool set_defaults,
config_read_keybinds_conf(conf);
ret = true;
/* Find a compatible startup shader*/
if (!string_is_empty(settings->paths.directory_video_shader))
const char *shader_ext = path_get_extension(settings->paths.path_shader);
if (!string_is_empty(shader_ext))
{
/* Get the config filename */
const char *s = path_basename(path_get(RARCH_PATH_CONFIG));
strlcpy (tmp_str, s, PATH_MAX_LENGTH);
path_remove_extension(tmp_str);
for(i = FILE_PATH_CGP_EXTENSION; i <= FILE_PATH_SLANGP_EXTENSION; i++)
{
if (!check_shader_compatibility((enum file_path_enum)(i)))
enum file_path_enum ext = (enum file_path_enum)(i);
if(!strstr(file_path_str(ext), shader_ext))
continue;
/* Build up the startup shader path from the config name and the
supported extensions */
fill_pathname_join_special_ext(settings->paths.path_shader,
settings->paths.directory_video_shader, "", tmp_str,
file_path_str((enum file_path_enum)(i)),
sizeof(settings->paths.path_shader));
/* Check if the shader exists */
if (!path_is_valid(settings->paths.path_shader))
{
RARCH_LOG("Shaders: no startup shader found at %s.\n", settings->paths.path_shader);
if (check_shader_compatibility(ext))
continue;
}
/* Game shader preset exists, load it */
RARCH_LOG("Shaders: startup shader found at %s.\n", settings->paths.path_shader);
path_set(RARCH_PATH_DEFAULT_SHADER_PRESET, settings->paths.path_shader);
}
RARCH_LOG("Incompatible shader for backend %s, clearing...\n",
settings->arrays.video_driver);
settings->paths.path_shader[0] = '\0';
break;
}
}
ret = true;
end:
@ -3302,9 +3291,7 @@ bool config_load_shader_preset(void)
/* Game shader preset exists, load it. */
RARCH_LOG("Shaders: game-specific shader preset found at %s.\n", game_path);
path_set(RARCH_PATH_DEFAULT_SHADER_PRESET, settings->paths.path_shader);
strlcpy(settings->paths.path_shader, game_path, sizeof(settings->paths.path_shader));
retroarch_set_shader_preset(game_path);
goto success;
}
@ -3328,10 +3315,9 @@ bool config_load_shader_preset(void)
continue;
}
/* Core shader preset exists, load it. */
/* Parent-dir shader preset exists, load it. */
RARCH_LOG("Shaders: parent-dir-specific shader preset found at %s.\n", parent_path);
path_set(RARCH_PATH_DEFAULT_SHADER_PRESET, settings->paths.path_shader);
strlcpy(settings->paths.path_shader, parent_path, sizeof(settings->paths.path_shader));
retroarch_set_shader_preset(parent_path);
goto success;
}
@ -3357,8 +3343,7 @@ bool config_load_shader_preset(void)
/* Core shader preset exists, load it. */
RARCH_LOG("Shaders: core-specific shader preset found at %s.\n", core_path);
path_set(RARCH_PATH_DEFAULT_SHADER_PRESET, settings->paths.path_shader);
strlcpy(settings->paths.path_shader, core_path, sizeof(settings->paths.path_shader));
retroarch_set_shader_preset(core_path);
goto success;
}

View File

@ -56,6 +56,7 @@
#include "../../core.h"
#include "../../verbosity.h"
#include "../../retroarch.h"
static LPDIRECT3D9 g_pD3D9;
@ -1081,7 +1082,7 @@ static bool d3d9_init_internal(d3d_video_t *d3d,
if (settings->bools.video_shader_enable)
{
enum rarch_shader_type type =
video_shader_parse_type(settings->paths.path_shader,
video_shader_parse_type(retroarch_get_shader_preset(),
RARCH_SHADER_NONE);
switch (type)
@ -1089,8 +1090,8 @@ static bool d3d9_init_internal(d3d_video_t *d3d,
case RARCH_SHADER_CG:
if (!string_is_empty(d3d->shader_path))
free(d3d->shader_path);
if (!string_is_empty(settings->paths.path_shader))
d3d->shader_path = strdup(settings->paths.path_shader);
if (!string_is_empty(retroarch_get_shader_preset()))
d3d->shader_path = strdup(retroarch_get_shader_preset());
break;
default:
break;

View File

@ -379,8 +379,7 @@ static bool gl_shader_init(gl_t *gl, const gfx_ctx_driver_t *ctx_driver,
{
video_shader_ctx_init_t init_data;
settings_t *settings = config_get_ptr();
const char *shader_path = (settings->bools.video_shader_enable
&& *settings->paths.path_shader) ? settings->paths.path_shader : NULL;
const char *shader_path = retroarch_get_shader_preset();
enum rarch_shader_type type = video_shader_parse_type(shader_path,
gl->core_context_in_use
? RARCH_SHADER_GLSL : DEFAULT_SHADER_TYPE);

View File

@ -810,8 +810,7 @@ static bool vulkan_init_filter_chain_preset(vk_t *vk, const char *shader_path)
static bool vulkan_init_filter_chain(vk_t *vk)
{
settings_t *settings = config_get_ptr();
const char *shader_path = (settings->bools.video_shader_enable && *settings->paths.path_shader) ?
settings->paths.path_shader : NULL;
const char *shader_path = retroarch_get_shader_preset();
enum rarch_shader_type type = video_shader_parse_type(shader_path, RARCH_SHADER_NONE);

View File

@ -296,7 +296,7 @@ static bool hlsl_d3d9_renderchain_init_shader(void *data,
init.shader_type = RARCH_SHADER_HLSL;
init.data = data;
init.path = settings->paths.path_shader;
init.path = retroarch_get_shader_preset();
init.shader = &hlsl_backend;
RARCH_LOG("D3D]: Using HLSL shader backend.\n");

View File

@ -130,7 +130,7 @@ bool menu_shader_manager_init(void)
#ifdef HAVE_SHADER_MANAGER
settings_t *settings = config_get_ptr();
const char *config_path = path_get(RARCH_PATH_CONFIG);
const char *path_shader = settings->paths.path_shader;
const char *path_shader = retroarch_get_shader_preset();
menu_shader_manager_free();

View File

@ -182,6 +182,7 @@ static jmp_buf error_sjlj_context;
static enum rarch_core_type current_core_type = CORE_TYPE_PLAIN;
static enum rarch_core_type explicit_current_core_type = CORE_TYPE_PLAIN;
static char error_string[255] = {0};
static char runtime_shader_preset[255] = {0};
#ifdef HAVE_THREAD_STORAGE
static sthread_tls_t rarch_tls;
@ -1924,6 +1925,36 @@ void retroarch_unset_forced_fullscreen(void)
rarch_force_fullscreen = false;
}
/* set a runtime shader preset without overwriting the settings value */
void retroarch_set_shader_preset(char* preset)
{
if (!string_is_empty(preset))
strlcpy(runtime_shader_preset, preset, sizeof(runtime_shader_preset));
else
runtime_shader_preset[0] = '\0';
}
/* unset a runtime shader preset */
void retroarch_unset_shader_preset(void)
{
runtime_shader_preset[0] = '\0';
}
/* get the name of the current shader preset */
char* retroarch_get_shader_preset(void)
{
settings_t *settings = config_get_ptr();
if (!settings->bools.video_shader_enable)
return "";
if (!string_is_empty(runtime_shader_preset))
return runtime_shader_preset;
else if (!string_is_empty(settings->paths.path_shader))
return settings->paths.path_shader;
else
return "";
}
bool retroarch_override_setting_is_set(enum rarch_override_setting enum_idx, void *data)
{
switch (enum_idx)

View File

@ -288,6 +288,12 @@ void retroarch_unset_forced_fullscreen(void);
void retroarch_set_current_core_type(enum rarch_core_type type, bool explicitly_set);
void retroarch_set_shader_preset(char* preset);
void retroarch_unset_shader_preset(void);
char* retroarch_get_shader_preset(void);
/**
* retroarch_fail:
* @error_code : Error code.