Start passing shader pointer to menu_shader.c functions

This commit is contained in:
twinaphex 2019-08-18 16:59:09 +02:00
parent c963b3be6a
commit b13ee8485f
6 changed files with 43 additions and 37 deletions

View File

@ -2600,7 +2600,8 @@ static void menu_input_st_string_cb_save_preset(void *userdata,
menu_setting_generic(setting, false);
}
else if (!string_is_empty(label))
ret = menu_shader_manager_save_preset(str, false, false);
ret = menu_shader_manager_save_preset(menu_shader_get(),
str, false, false);
if (ret)
runloop_msg_queue_push(
@ -2762,7 +2763,7 @@ static int generic_action_ok_shader_preset_save(const char *path,
break;
}
if (menu_shader_manager_save_preset(file, false, true))
if (menu_shader_manager_save_preset(menu_shader_get(), file, false, true))
runloop_msg_queue_push(
msg_hash_to_str(MSG_SHADER_PRESET_SAVED_SUCCESSFULLY),
1, 100, true,

View File

@ -164,7 +164,7 @@ static int action_start_shader_action_parameter(
param->current = param->initial;
param->current = MIN(MAX(param->minimum, param->current), param->maximum);
return menu_shader_manager_clear_parameter(parameter);
return menu_shader_manager_clear_parameter(menu_shader_get(), parameter);
}
static int action_start_shader_pass(unsigned type, const char *label)
@ -176,7 +176,8 @@ static int action_start_shader_pass(unsigned type, const char *label)
menu->scratchpad.unsigned_var = type - MENU_SETTINGS_SHADER_PASS_0;
menu_shader_manager_clear_pass_path(menu->scratchpad.unsigned_var);
menu_shader_manager_clear_pass_path(menu_shader_get(),
menu->scratchpad.unsigned_var);
return 0;
}
@ -185,7 +186,7 @@ static int action_start_shader_scale_pass(unsigned type, const char *label)
{
unsigned pass = type - MENU_SETTINGS_SHADER_PASS_SCALE_0;
menu_shader_manager_clear_pass_scale(pass);
menu_shader_manager_clear_pass_scale(menu_shader_get(), pass);
return 0;
}
@ -193,7 +194,7 @@ static int action_start_shader_scale_pass(unsigned type, const char *label)
static int action_start_shader_filter_pass(unsigned type, const char *label)
{
unsigned pass = type - MENU_SETTINGS_SHADER_PASS_FILTER_0;
return menu_shader_manager_clear_pass_filter(pass);
return menu_shader_manager_clear_pass_filter(menu_shader_get(), pass);
}
#endif
@ -214,7 +215,7 @@ static int action_start_shader_watch_for_changes(unsigned type, const char *labe
static int action_start_shader_num_passes(unsigned type, const char *label)
{
return menu_shader_manager_clear_num_passes();
return menu_shader_manager_clear_num_passes(menu_shader_get());
}
#endif

View File

@ -133,10 +133,9 @@ end:
*
* Sets shader preset.
**/
bool menu_shader_manager_set_preset(void *data,
bool menu_shader_manager_set_preset(struct video_shader *shader,
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;
bool ret = false;
@ -150,14 +149,14 @@ bool menu_shader_manager_set_preset(void *data,
* entries in the shader options menu which can in
* turn lead to the menu selection pointer going out
* of bounds. This causes undefined behaviour/segfaults */
menu_shader_manager_clear_num_passes();
menu_shader_manager_clear_num_passes(shader);
command_event(CMD_EVENT_SHADER_PRESET_LOADED, NULL);
return false;
}
if (string_is_empty(preset_path))
{
menu_shader_manager_clear_num_passes();
menu_shader_manager_clear_num_passes(shader);
command_event(CMD_EVENT_SHADER_PRESET_LOADED, NULL);
return true;
}
@ -204,6 +203,7 @@ end:
* Save a shader preset to disk.
**/
bool menu_shader_manager_save_preset(
struct video_shader *shader,
const char *basename, bool apply, bool fullpath)
{
char buffer[PATH_MAX_LENGTH];
@ -214,7 +214,6 @@ bool menu_shader_manager_save_preset(
enum rarch_shader_type type = RARCH_SHADER_NONE;
const char *dirs[3] = {0};
config_file_t *conf = NULL;
struct video_shader *shader = menu_shader_get();
config_directory[0] = '\0';
buffer[0] = '\0';
@ -321,10 +320,9 @@ bool menu_shader_manager_save_preset(
return false;
}
int menu_shader_manager_clear_num_passes(void)
int menu_shader_manager_clear_num_passes(struct video_shader *shader)
{
bool refresh = false;
struct video_shader *shader = menu_shader_get();
if (!shader)
return 0;
@ -340,9 +338,9 @@ int menu_shader_manager_clear_num_passes(void)
return 0;
}
int menu_shader_manager_clear_parameter(unsigned i)
int menu_shader_manager_clear_parameter(struct video_shader *shader,
unsigned i)
{
struct video_shader *shader = menu_shader_get();
struct video_shader_parameter *param = shader ?
&shader->parameters[i] : NULL;
@ -356,9 +354,9 @@ int menu_shader_manager_clear_parameter(unsigned i)
return 0;
}
int menu_shader_manager_clear_pass_filter(unsigned i)
int menu_shader_manager_clear_pass_filter(struct video_shader *shader,
unsigned i)
{
struct video_shader *shader = menu_shader_get();
struct video_shader_pass *shader_pass = shader ?
&shader->pass[i] : NULL;
@ -370,9 +368,9 @@ int menu_shader_manager_clear_pass_filter(unsigned i)
return 0;
}
void menu_shader_manager_clear_pass_scale(unsigned i)
void menu_shader_manager_clear_pass_scale(struct video_shader *shader,
unsigned i)
{
struct video_shader *shader = menu_shader_get();
struct video_shader_pass *shader_pass = shader ?
&shader->pass[i] : NULL;
@ -384,9 +382,9 @@ void menu_shader_manager_clear_pass_scale(unsigned i)
shader_pass->fbo.valid = false;
}
void menu_shader_manager_clear_pass_path(unsigned i)
void menu_shader_manager_clear_pass_path(struct video_shader *shader,
unsigned i)
{
struct video_shader *shader = menu_shader_get();
struct video_shader_pass *shader_pass = shader ?
&shader->pass[i] : NULL;
@ -402,10 +400,10 @@ void menu_shader_manager_clear_pass_path(unsigned i)
*
* Returns: type of shader.
**/
enum rarch_shader_type menu_shader_manager_get_type(const void *data)
enum rarch_shader_type menu_shader_manager_get_type(
const struct video_shader *shader)
{
enum rarch_shader_type type = RARCH_SHADER_NONE;
const struct video_shader *shader = (const struct video_shader*)data;
/* All shader types must be the same, or we cannot use it. */
size_t i = 0;
@ -449,10 +447,9 @@ enum rarch_shader_type menu_shader_manager_get_type(const void *data)
*
* Apply shader state changes.
**/
void menu_shader_manager_apply_changes(void)
void menu_shader_manager_apply_changes(struct video_shader *shader)
{
enum rarch_shader_type type = RARCH_SHADER_NONE;
struct video_shader *shader = menu_shader_get();
if (!shader)
return;
@ -461,7 +458,7 @@ void menu_shader_manager_apply_changes(void)
if (shader->passes && type != RARCH_SHADER_NONE)
{
menu_shader_manager_save_preset(NULL, true, false);
menu_shader_manager_save_preset(shader, NULL, true, false);
return;
}

View File

@ -45,7 +45,8 @@ bool menu_shader_manager_init(void);
* Sets shader preset.
**/
bool menu_shader_manager_set_preset(
void *data, enum rarch_shader_type type, const char *preset_path, bool apply);
struct video_shader *shader,
enum rarch_shader_type type, const char *preset_path, bool apply);
/**
* menu_shader_manager_save_preset:
@ -55,6 +56,7 @@ bool menu_shader_manager_set_preset(
* Save a shader preset to disk.
**/
bool menu_shader_manager_save_preset(
struct video_shader *shader,
const char *basename, bool apply, bool fullpath);
/**
@ -65,24 +67,29 @@ bool menu_shader_manager_save_preset(
*
* Returns: type of shader.
**/
enum rarch_shader_type menu_shader_manager_get_type(const void *data);
enum rarch_shader_type menu_shader_manager_get_type(
const struct video_shader *shader);
/**
* menu_shader_manager_apply_changes:
*
* Apply shader state changes.
**/
void menu_shader_manager_apply_changes(void);
void menu_shader_manager_apply_changes(struct video_shader *shader);
int menu_shader_manager_clear_num_passes(void);
int menu_shader_manager_clear_num_passes(struct video_shader *shader);
int menu_shader_manager_clear_parameter(unsigned i);
int menu_shader_manager_clear_parameter(struct video_shader *shader,
unsigned i);
int menu_shader_manager_clear_pass_filter(unsigned i);
int menu_shader_manager_clear_pass_filter(struct video_shader *shader,
unsigned i);
void menu_shader_manager_clear_pass_scale(unsigned i);
void menu_shader_manager_clear_pass_scale(struct video_shader *shader,
unsigned i);
void menu_shader_manager_clear_pass_path(unsigned i);
void menu_shader_manager_clear_pass_path(struct video_shader *shader,
unsigned i);
RETRO_END_DECLS

View File

@ -4633,7 +4633,7 @@ TODO: Add a setting for these tweaks */
case CMD_EVENT_SHADERS_APPLY_CHANGES:
#ifdef HAVE_MENU
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_SLANG) || defined(HAVE_HLSL)
menu_shader_manager_apply_changes();
menu_shader_manager_apply_changes(menu_shader_get());
#endif
#endif
ui_companion_event_command(cmd);

View File

@ -748,7 +748,7 @@ void ShaderParamsDialog::saveShaderPreset(const char *path, unsigned action_type
break;
}
if (menu_shader_manager_save_preset(file, false, true))
if (menu_shader_manager_save_preset(menu_shader_get(), file, false, true))
runloop_msg_queue_push(
msg_hash_to_str(MSG_SHADER_PRESET_SAVED_SUCCESSFULLY),
1, 100, true, NULL,