mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-27 02:00:41 +00:00
(Menu/Shaders) Move all shader manager code to frontend/menu/menu_shader
This commit is contained in:
parent
93fbb44402
commit
9d94513dc4
@ -270,6 +270,7 @@ ifeq ($(HAVE_MENU_COMMON), 1)
|
||||
frontend/menu/menu_common.o \
|
||||
frontend/menu/menu_navigation.o \
|
||||
frontend/menu/menu_action.o \
|
||||
frontend/menu/menu_shader.o \
|
||||
frontend/menu/menu_entries.o
|
||||
endif
|
||||
|
||||
|
@ -8,14 +8,6 @@ extern "C" {
|
||||
typedef struct menu_ctx_driver_backend
|
||||
{
|
||||
int (*iterate)(unsigned);
|
||||
void (*shader_manager_init)(menu_handle_t *);
|
||||
void (*shader_manager_get_str)(struct gfx_shader *, char *,
|
||||
size_t, const char *, const char *, unsigned);
|
||||
void (*shader_manager_set_preset)(struct gfx_shader *,
|
||||
unsigned, const char*);
|
||||
void (*shader_manager_save_preset)(const char *, bool);
|
||||
unsigned (*shader_manager_get_type)(const struct gfx_shader *);
|
||||
int (*shader_manager_setting_toggle)(unsigned, const char *, unsigned);
|
||||
unsigned (*type_is)(const char *, unsigned);
|
||||
void (*setting_set_label)(char *, size_t, unsigned *,
|
||||
unsigned, const char *, const char *, unsigned);
|
||||
|
@ -28,7 +28,6 @@
|
||||
#include "../menu_input_line_cb.h"
|
||||
|
||||
#include "../../../gfx/gfx_common.h"
|
||||
#include "../../../gfx/shader_common.h"
|
||||
#include "../../../driver.h"
|
||||
#include "../../../file_ext.h"
|
||||
#include "../../../input/input_common.h"
|
||||
@ -39,22 +38,15 @@
|
||||
#define HAVE_SHADER_MANAGER
|
||||
#endif
|
||||
|
||||
#include "../menu_shader.h"
|
||||
|
||||
#ifdef GEKKO
|
||||
extern unsigned menu_gx_resolutions[GX_RESOLUTIONS_LAST][2];
|
||||
extern unsigned menu_current_gx_resolution;
|
||||
#endif
|
||||
|
||||
// FIXME: Ugly hack, nees to be refactored badly
|
||||
static size_t hack_shader_pass = 0;
|
||||
|
||||
static void *get_last_setting(const file_list_t *list, int index,
|
||||
rarch_setting_t *settings)
|
||||
{
|
||||
if (settings)
|
||||
return (rarch_setting_t*)setting_data_find_setting(settings,
|
||||
list->list[index].label);
|
||||
return NULL;
|
||||
}
|
||||
size_t hack_shader_pass = 0;
|
||||
|
||||
static int menu_message_toggle(unsigned action)
|
||||
{
|
||||
@ -76,6 +68,7 @@ static int menu_info_screen_iterate(unsigned action)
|
||||
unsigned info_type = 0;
|
||||
rarch_setting_t *current_setting = NULL;
|
||||
rarch_setting_t *setting_data = (rarch_setting_t *)setting_data_get_list();
|
||||
file_list_t *list = (file_list_t*)driver.menu->selection_buf;
|
||||
|
||||
if (!driver.menu || !setting_data)
|
||||
return 0;
|
||||
@ -83,15 +76,15 @@ static int menu_info_screen_iterate(unsigned action)
|
||||
if (driver.video_data && driver.menu_ctx && driver.menu_ctx->render)
|
||||
driver.menu_ctx->render();
|
||||
|
||||
current_setting = (rarch_setting_t*)get_last_setting(
|
||||
driver.menu->selection_buf,
|
||||
current_setting = (rarch_setting_t*)menu_entries_get_last_setting(
|
||||
list->list[driver.menu->selection_ptr].label,
|
||||
driver.menu->selection_ptr,
|
||||
setting_data_get_list());
|
||||
|
||||
if (current_setting)
|
||||
strlcpy(needle, current_setting->name, sizeof(needle));
|
||||
else if ((current_setting = (rarch_setting_t*)get_last_setting(
|
||||
driver.menu->selection_buf,
|
||||
else if ((current_setting = (rarch_setting_t*)menu_entries_get_last_setting(
|
||||
list->list[driver.menu->selection_ptr].label,
|
||||
driver.menu->selection_ptr,
|
||||
setting_data_get_mainmenu(true))))
|
||||
{
|
||||
@ -191,857 +184,6 @@ static int menu_start_screen_iterate(unsigned action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int menu_common_setting_set_current_path_selection(
|
||||
rarch_setting_t *setting, const char *start_path,
|
||||
const char *label, unsigned type,
|
||||
unsigned action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_OK:
|
||||
menu_entries_push(driver.menu->menu_stack,
|
||||
start_path, label, type,
|
||||
driver.menu->selection_ptr);
|
||||
|
||||
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
|
||||
setting->cmd_trigger.triggered = true;
|
||||
break;
|
||||
case MENU_ACTION_START:
|
||||
*setting->value.string = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
return menu_action_setting_apply(setting);
|
||||
}
|
||||
|
||||
static int handle_setting(rarch_setting_t *setting,
|
||||
unsigned id, const char *label, unsigned action)
|
||||
{
|
||||
if (setting->type == ST_BOOL)
|
||||
return menu_action_setting_boolean(setting, action);
|
||||
if (setting->type == ST_UINT)
|
||||
return menu_action_setting_unsigned_integer(setting, id, action);
|
||||
if (setting->type == ST_FLOAT)
|
||||
return menu_action_setting_fraction(setting, action);
|
||||
if (setting->type == ST_PATH)
|
||||
return menu_common_setting_set_current_path_selection(setting,
|
||||
setting->default_value.string, setting->name, id, action);
|
||||
|
||||
if (setting->type == ST_DIR)
|
||||
{
|
||||
if (action == MENU_ACTION_START)
|
||||
{
|
||||
*setting->value.string = '\0';
|
||||
return menu_action_setting_apply(setting);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (setting->type == ST_STRING)
|
||||
{
|
||||
if (
|
||||
(setting->flags & SD_FLAG_ALLOW_INPUT) ||
|
||||
id == MENU_FILE_LINEFEED_SWITCH)
|
||||
{
|
||||
if (action == MENU_ACTION_OK)
|
||||
menu_key_start_line(driver.menu, setting->short_description,
|
||||
setting->name, st_string_callback);
|
||||
else if (action == MENU_ACTION_START)
|
||||
*setting->value.string = '\0';
|
||||
}
|
||||
else
|
||||
menu_action_setting_driver(setting, action);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int menu_setting_set(unsigned id, const char *label,
|
||||
unsigned action)
|
||||
{
|
||||
unsigned port = driver.menu->current_pad;
|
||||
rarch_setting_t *setting = (rarch_setting_t*)get_last_setting(
|
||||
driver.menu->selection_buf, driver.menu->selection_ptr,
|
||||
setting_data_get_list()
|
||||
);
|
||||
|
||||
if (setting)
|
||||
return handle_setting(setting, id, label, action);
|
||||
else
|
||||
{
|
||||
setting = (rarch_setting_t*)get_last_setting(
|
||||
driver.menu->selection_buf, driver.menu->selection_ptr,
|
||||
setting_data_get_mainmenu(true)
|
||||
);
|
||||
|
||||
if (setting)
|
||||
{
|
||||
if (!strcmp(setting->name, "disk_index"))
|
||||
{
|
||||
int step = 0;
|
||||
|
||||
if (action == MENU_ACTION_RIGHT || action == MENU_ACTION_OK)
|
||||
step = 1;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
step = -1;
|
||||
|
||||
if (step)
|
||||
{
|
||||
const struct retro_disk_control_callback *control =
|
||||
(const struct retro_disk_control_callback*)
|
||||
&g_extern.system.disk_control;
|
||||
unsigned num_disks = control->get_num_images();
|
||||
unsigned current = control->get_image_index();
|
||||
unsigned next_index = (current + num_disks + 1 + step)
|
||||
% (num_disks + 1);
|
||||
rarch_disk_control_set_eject(true, false);
|
||||
rarch_disk_control_set_index(next_index);
|
||||
rarch_disk_control_set_eject(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
return handle_setting(setting, id, label, action);
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_num_passes"))
|
||||
{
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
struct gfx_shader *shader = (struct gfx_shader*)
|
||||
driver.menu->shader;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
if (shader && shader->passes)
|
||||
shader->passes = 0;
|
||||
driver.menu->need_refresh = true;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
if (shader && shader->passes)
|
||||
shader->passes--;
|
||||
driver.menu->need_refresh = true;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
if (shader && (shader->passes < GFX_MAX_SHADERS))
|
||||
shader->passes++;
|
||||
driver.menu->need_refresh = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (driver.menu->need_refresh)
|
||||
gfx_shader_resolve_parameters(NULL, driver.menu->shader);
|
||||
#endif
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_device_id"))
|
||||
{
|
||||
int *p = &g_settings.input.joypad_map[port];
|
||||
if (action == MENU_ACTION_START)
|
||||
*p = port;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
(*p)--;
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
(*p)++;
|
||||
|
||||
if (*p < -1)
|
||||
*p = -1;
|
||||
else if (*p >= MAX_PLAYERS)
|
||||
*p = MAX_PLAYERS - 1;
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_device_type"))
|
||||
{
|
||||
unsigned current_device, current_index, i, devices[128];
|
||||
const struct retro_controller_info *desc;
|
||||
unsigned types = 0;
|
||||
|
||||
devices[types++] = RETRO_DEVICE_NONE;
|
||||
devices[types++] = RETRO_DEVICE_JOYPAD;
|
||||
|
||||
/* Only push RETRO_DEVICE_ANALOG as default if we use an
|
||||
* older core which doesn't use SET_CONTROLLER_INFO. */
|
||||
if (!g_extern.system.num_ports)
|
||||
devices[types++] = RETRO_DEVICE_ANALOG;
|
||||
|
||||
desc = port < g_extern.system.num_ports ?
|
||||
&g_extern.system.ports[port] : NULL;
|
||||
if (desc)
|
||||
{
|
||||
for (i = 0; i < desc->num_types; i++)
|
||||
{
|
||||
unsigned id = desc->types[i].id;
|
||||
if (types < ARRAY_SIZE(devices) &&
|
||||
id != RETRO_DEVICE_NONE &&
|
||||
id != RETRO_DEVICE_JOYPAD)
|
||||
devices[types++] = id;
|
||||
}
|
||||
}
|
||||
|
||||
current_device = g_settings.input.libretro_device[port];
|
||||
current_index = 0;
|
||||
for (i = 0; i < types; i++)
|
||||
{
|
||||
if (current_device == devices[i])
|
||||
{
|
||||
current_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool updated = true;
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
current_device = RETRO_DEVICE_JOYPAD;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
current_device = devices
|
||||
[(current_index + types - 1) % types];
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
current_device = devices
|
||||
[(current_index + 1) % types];
|
||||
break;
|
||||
|
||||
default:
|
||||
updated = false;
|
||||
}
|
||||
|
||||
if (updated)
|
||||
{
|
||||
g_settings.input.libretro_device[port] = current_device;
|
||||
pretro_set_controller_port_device(port, current_device);
|
||||
}
|
||||
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_player_no"))
|
||||
{
|
||||
if (action == MENU_ACTION_START)
|
||||
driver.menu->current_pad = 0;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
if (driver.menu->current_pad != 0)
|
||||
driver.menu->current_pad--;
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
{
|
||||
if (driver.menu->current_pad < MAX_PLAYERS - 1)
|
||||
driver.menu->current_pad++;
|
||||
}
|
||||
if (port != driver.menu->current_pad)
|
||||
driver.menu->need_refresh = true;
|
||||
port = driver.menu->current_pad;
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_analog_dpad_mode"))
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
g_settings.input.analog_dpad_mode[port] = 0;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_OK:
|
||||
case MENU_ACTION_RIGHT:
|
||||
g_settings.input.analog_dpad_mode[port] =
|
||||
(g_settings.input.analog_dpad_mode[port] + 1)
|
||||
% ANALOG_DPAD_LAST;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
g_settings.input.analog_dpad_mode[port] =
|
||||
(g_settings.input.analog_dpad_mode
|
||||
[port] + ANALOG_DPAD_LAST - 1) % ANALOG_DPAD_LAST;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case MENU_SETTINGS_CUSTOM_BIND_MODE:
|
||||
if (action == MENU_ACTION_LEFT || action == MENU_ACTION_RIGHT)
|
||||
driver.menu->bind_mode_keyboard =
|
||||
!driver.menu->bind_mode_keyboard;
|
||||
break;
|
||||
#if defined(GEKKO)
|
||||
case MENU_SETTINGS_VIDEO_RESOLUTION:
|
||||
if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
if (menu_current_gx_resolution > 0)
|
||||
menu_current_gx_resolution--;
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
{
|
||||
if (menu_current_gx_resolution < GX_RESOLUTIONS_LAST - 1)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
if ((menu_current_gx_resolution + 1) > GX_RESOLUTIONS_640_480)
|
||||
if (CONF_GetVideo() != CONF_VIDEO_PAL)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
menu_current_gx_resolution++;
|
||||
}
|
||||
}
|
||||
else if (action == MENU_ACTION_OK)
|
||||
{
|
||||
if (driver.video_data)
|
||||
gx_set_video_mode(driver.video_data, menu_gx_resolutions
|
||||
[menu_current_gx_resolution][0],
|
||||
menu_gx_resolutions[menu_current_gx_resolution][1]);
|
||||
}
|
||||
break;
|
||||
#elif defined(__CELLOS_LV2__)
|
||||
case MENU_SETTINGS_VIDEO_RESOLUTION:
|
||||
if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
if (g_extern.console.screen.resolutions.current.idx)
|
||||
{
|
||||
g_extern.console.screen.resolutions.current.idx--;
|
||||
g_extern.console.screen.resolutions.current.id =
|
||||
g_extern.console.screen.resolutions.list
|
||||
[g_extern.console.screen.resolutions.current.idx];
|
||||
}
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
{
|
||||
if (g_extern.console.screen.resolutions.current.idx + 1 <
|
||||
g_extern.console.screen.resolutions.count)
|
||||
{
|
||||
g_extern.console.screen.resolutions.current.idx++;
|
||||
g_extern.console.screen.resolutions.current.id =
|
||||
g_extern.console.screen.resolutions.list
|
||||
[g_extern.console.screen.resolutions.current.idx];
|
||||
}
|
||||
}
|
||||
else if (action == MENU_ACTION_OK)
|
||||
{
|
||||
if (g_extern.console.screen.resolutions.list[
|
||||
g_extern.console.screen.resolutions.current.idx] ==
|
||||
CELL_VIDEO_OUT_RESOLUTION_576)
|
||||
{
|
||||
if (g_extern.console.screen.pal_enable)
|
||||
g_extern.console.screen.pal60_enable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_extern.console.screen.pal_enable = false;
|
||||
g_extern.console.screen.pal60_enable = false;
|
||||
}
|
||||
|
||||
rarch_main_command(RARCH_CMD_REINIT);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void menu_common_shader_manager_init(menu_handle_t *menu)
|
||||
{
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
char cgp_path[PATH_MAX];
|
||||
config_file_t *conf = NULL;
|
||||
const char *config_path = NULL;
|
||||
struct gfx_shader *shader = (struct gfx_shader*)menu->shader;
|
||||
|
||||
if (*g_extern.core_specific_config_path
|
||||
&& g_settings.core_specific_config)
|
||||
config_path = g_extern.core_specific_config_path;
|
||||
else if (*g_extern.config_path)
|
||||
config_path = g_extern.config_path;
|
||||
|
||||
/* In a multi-config setting, we can't have
|
||||
* conflicts on menu.cgp/menu.glslp. */
|
||||
if (config_path)
|
||||
{
|
||||
fill_pathname_base(menu->default_glslp, config_path,
|
||||
sizeof(menu->default_glslp));
|
||||
path_remove_extension(menu->default_glslp);
|
||||
strlcat(menu->default_glslp, ".glslp", sizeof(menu->default_glslp));
|
||||
fill_pathname_base(menu->default_cgp, config_path,
|
||||
sizeof(menu->default_cgp));
|
||||
path_remove_extension(menu->default_cgp);
|
||||
strlcat(menu->default_cgp, ".cgp", sizeof(menu->default_cgp));
|
||||
}
|
||||
else
|
||||
{
|
||||
strlcpy(menu->default_glslp, "menu.glslp", sizeof(menu->default_glslp));
|
||||
strlcpy(menu->default_cgp, "menu.cgp", sizeof(menu->default_cgp));
|
||||
}
|
||||
|
||||
|
||||
const char *ext = path_get_extension(g_settings.video.shader_path);
|
||||
if (strcmp(ext, "glslp") == 0 || strcmp(ext, "cgp") == 0)
|
||||
{
|
||||
conf = config_file_new(g_settings.video.shader_path);
|
||||
if (conf)
|
||||
{
|
||||
if (gfx_shader_read_conf_cgp(conf, shader))
|
||||
{
|
||||
gfx_shader_resolve_relative(shader, g_settings.video.shader_path);
|
||||
gfx_shader_resolve_parameters(conf, shader);
|
||||
}
|
||||
config_file_free(conf);
|
||||
}
|
||||
}
|
||||
else if (strcmp(ext, "glsl") == 0 || strcmp(ext, "cg") == 0)
|
||||
{
|
||||
strlcpy(shader->pass[0].source.path, g_settings.video.shader_path,
|
||||
sizeof(shader->pass[0].source.path));
|
||||
shader->passes = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *shader_dir = *g_settings.video.shader_dir ?
|
||||
g_settings.video.shader_dir : g_settings.system_directory;
|
||||
|
||||
fill_pathname_join(cgp_path, shader_dir, "menu.glslp", sizeof(cgp_path));
|
||||
conf = config_file_new(cgp_path);
|
||||
|
||||
if (!conf)
|
||||
{
|
||||
fill_pathname_join(cgp_path, shader_dir, "menu.cgp", sizeof(cgp_path));
|
||||
conf = config_file_new(cgp_path);
|
||||
}
|
||||
|
||||
if (conf)
|
||||
{
|
||||
if (gfx_shader_read_conf_cgp(conf, shader))
|
||||
{
|
||||
gfx_shader_resolve_relative(shader, cgp_path);
|
||||
gfx_shader_resolve_parameters(conf, shader);
|
||||
}
|
||||
config_file_free(conf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void menu_common_shader_manager_set_preset(struct gfx_shader *shader,
|
||||
unsigned type, const char *cgp_path)
|
||||
{
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
RARCH_LOG("Setting Menu shader: %s.\n", cgp_path ? cgp_path : "N/A (stock)");
|
||||
g_settings.video.shader_enable = false;
|
||||
|
||||
if (driver.video->set_shader && driver.video->set_shader(driver.video_data,
|
||||
(enum rarch_shader_type)type, cgp_path))
|
||||
{
|
||||
/* Makes sure that we use Menu CGP shader on driver reinit.
|
||||
* Only do this when the cgp actually works to avoid potential errors. */
|
||||
strlcpy(g_settings.video.shader_path, cgp_path ? cgp_path : "",
|
||||
sizeof(g_settings.video.shader_path));
|
||||
g_settings.video.shader_enable = true;
|
||||
|
||||
if (cgp_path && shader)
|
||||
{
|
||||
/* Load stored CGP into menu on success.
|
||||
* Used when a preset is directly loaded.
|
||||
* No point in updating when the CGP was
|
||||
* created from the menu itself. */
|
||||
config_file_t *conf = config_file_new(cgp_path);
|
||||
|
||||
if (conf)
|
||||
{
|
||||
if (gfx_shader_read_conf_cgp(conf, shader))
|
||||
{
|
||||
gfx_shader_resolve_relative(shader, cgp_path);
|
||||
gfx_shader_resolve_parameters(conf, shader);
|
||||
}
|
||||
config_file_free(conf);
|
||||
}
|
||||
|
||||
driver.menu->need_refresh = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void menu_common_shader_manager_get_str(struct gfx_shader *shader,
|
||||
char *type_str, size_t type_str_size, const char *menu_label,
|
||||
const char *label, unsigned type)
|
||||
{
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
*type_str = '\0';
|
||||
|
||||
if (!strcmp(label, "video_shader_num_passes"))
|
||||
snprintf(type_str, type_str_size, "%u", shader->passes);
|
||||
else if (type >= MENU_SETTINGS_SHADER_PARAMETER_0
|
||||
&& type <= MENU_SETTINGS_SHADER_PARAMETER_LAST)
|
||||
{
|
||||
/* menu->parameter_shader here. */
|
||||
if (shader)
|
||||
{
|
||||
const struct gfx_shader_parameter *param =
|
||||
(const struct gfx_shader_parameter*)&shader->parameters
|
||||
[type - MENU_SETTINGS_SHADER_PARAMETER_0];
|
||||
snprintf(type_str, type_str_size, "%.2f [%.2f %.2f]",
|
||||
param->current, param->minimum, param->maximum);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_default_filter"))
|
||||
snprintf(type_str, type_str_size, "%s",
|
||||
g_settings.video.smooth ? "Linear" : "Nearest");
|
||||
else if (!strcmp(label, "video_shader_pass"))
|
||||
{
|
||||
unsigned pass = (type - MENU_SETTINGS_SHADER_PASS_0);
|
||||
if (*shader->pass[pass].source.path)
|
||||
fill_pathname_base(type_str,
|
||||
shader->pass[pass].source.path, type_str_size);
|
||||
else
|
||||
strlcpy(type_str, "N/A", type_str_size);
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_filter_pass"))
|
||||
{
|
||||
unsigned pass = (type - MENU_SETTINGS_SHADER_PASS_FILTER_0);
|
||||
static const char *modes[] = {
|
||||
"Don't care",
|
||||
"Linear",
|
||||
"Nearest"
|
||||
};
|
||||
|
||||
strlcpy(type_str, modes[shader->pass[pass].filter],
|
||||
type_str_size);
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_scale_pass"))
|
||||
{
|
||||
unsigned pass = (type - MENU_SETTINGS_SHADER_PASS_SCALE_0);
|
||||
unsigned scale = shader->pass[pass].fbo.scale_x;
|
||||
if (!scale)
|
||||
strlcpy(type_str, "Don't care", type_str_size);
|
||||
else
|
||||
snprintf(type_str, type_str_size, "%ux", scale);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void menu_common_shader_manager_save_preset(
|
||||
const char *basename, bool apply)
|
||||
{
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
char buffer[PATH_MAX], config_directory[PATH_MAX], cgp_path[PATH_MAX];
|
||||
unsigned d, type = RARCH_SHADER_NONE;
|
||||
config_file_t *conf = NULL;
|
||||
bool ret = false;
|
||||
|
||||
if (!driver.menu)
|
||||
{
|
||||
RARCH_ERR("Cannot save shader preset, menu handle is not initialized.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (driver.menu_ctx && driver.menu_ctx->backend
|
||||
&& driver.menu_ctx->backend->shader_manager_get_type)
|
||||
type = driver.menu_ctx->backend->shader_manager_get_type
|
||||
(driver.menu->shader);
|
||||
|
||||
if (type == RARCH_SHADER_NONE)
|
||||
return;
|
||||
|
||||
*config_directory = '\0';
|
||||
|
||||
if (basename)
|
||||
{
|
||||
strlcpy(buffer, basename, sizeof(buffer));
|
||||
|
||||
/* Append extension automatically as appropriate. */
|
||||
if (!strstr(basename, ".cgp") && !strstr(basename, ".glslp"))
|
||||
{
|
||||
if (type == RARCH_SHADER_GLSL)
|
||||
strlcat(buffer, ".glslp", sizeof(buffer));
|
||||
else if (type == RARCH_SHADER_CG)
|
||||
strlcat(buffer, ".cgp", sizeof(buffer));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *conf_path = (type == RARCH_SHADER_GLSL) ?
|
||||
driver.menu->default_glslp : driver.menu->default_cgp;
|
||||
strlcpy(buffer, conf_path, sizeof(buffer));
|
||||
}
|
||||
|
||||
if (*g_extern.config_path)
|
||||
fill_pathname_basedir(config_directory,
|
||||
g_extern.config_path, sizeof(config_directory));
|
||||
|
||||
const char *dirs[] = {
|
||||
g_settings.video.shader_dir,
|
||||
g_settings.menu_config_directory,
|
||||
config_directory,
|
||||
};
|
||||
|
||||
if (!(conf = (config_file_t*)config_file_new(NULL)))
|
||||
return;
|
||||
gfx_shader_write_conf_cgp(conf, driver.menu->shader);
|
||||
|
||||
for (d = 0; d < ARRAY_SIZE(dirs); d++)
|
||||
{
|
||||
if (!*dirs[d])
|
||||
continue;
|
||||
|
||||
fill_pathname_join(cgp_path, dirs[d], buffer, sizeof(cgp_path));
|
||||
if (config_file_write(conf, cgp_path))
|
||||
{
|
||||
RARCH_LOG("Saved shader preset to %s.\n", cgp_path);
|
||||
if (apply)
|
||||
{
|
||||
if (driver.menu_ctx && driver.menu_ctx->backend
|
||||
&& driver.menu_ctx->backend->shader_manager_set_preset)
|
||||
driver.menu_ctx->backend->shader_manager_set_preset(
|
||||
NULL, type, cgp_path);
|
||||
}
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
RARCH_LOG("Failed writing shader preset to %s.\n", cgp_path);
|
||||
}
|
||||
|
||||
config_file_free(conf);
|
||||
if (!ret)
|
||||
RARCH_ERR("Failed to save shader preset. Make sure config directory and/or shader dir are writable.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static unsigned menu_common_shader_manager_get_type(
|
||||
const struct gfx_shader *shader)
|
||||
{
|
||||
/* All shader types must be the same, or we cannot use it. */
|
||||
unsigned i = 0, type = 0;
|
||||
|
||||
(void)i;
|
||||
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
if (!shader)
|
||||
{
|
||||
RARCH_ERR("Cannot get shader type, shader handle is not initialized.\n");
|
||||
return RARCH_SHADER_NONE;
|
||||
}
|
||||
|
||||
for (i = 0; i < shader->passes; i++)
|
||||
{
|
||||
enum rarch_shader_type pass_type = gfx_shader_parse_type(shader->pass[i].source.path,
|
||||
RARCH_SHADER_NONE);
|
||||
|
||||
switch (pass_type)
|
||||
{
|
||||
case RARCH_SHADER_CG:
|
||||
case RARCH_SHADER_GLSL:
|
||||
if (type == RARCH_SHADER_NONE)
|
||||
type = pass_type;
|
||||
else if (type != pass_type)
|
||||
return RARCH_SHADER_NONE;
|
||||
break;
|
||||
default:
|
||||
return RARCH_SHADER_NONE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static int menu_common_shader_manager_setting_toggle(
|
||||
unsigned id, const char *label, unsigned action)
|
||||
{
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
if (!driver.menu)
|
||||
{
|
||||
RARCH_ERR("Cannot toggle shader setting, menu handle is not initialized.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
RARCH_LOG("shader label: %s\n", label);
|
||||
#endif
|
||||
|
||||
rarch_setting_t *current_setting = NULL;
|
||||
rarch_setting_t *setting_data = (rarch_setting_t *)setting_data_get_list();
|
||||
|
||||
|
||||
if (!strcmp(label, "video_shader_default_filter"))
|
||||
{
|
||||
if ((current_setting = setting_data_find_setting(
|
||||
setting_data, "video_smooth")))
|
||||
menu_action_setting_boolean(current_setting, action);
|
||||
}
|
||||
else if (id >= MENU_SETTINGS_SHADER_PARAMETER_0
|
||||
&& id <= MENU_SETTINGS_SHADER_PARAMETER_LAST)
|
||||
{
|
||||
bool apply_changes = false;
|
||||
struct gfx_shader *shader = NULL;
|
||||
struct gfx_shader_parameter *param = NULL;
|
||||
|
||||
if (!(shader = (struct gfx_shader*)driver.menu->parameter_shader))
|
||||
return 0;
|
||||
|
||||
if (!(param = &shader->parameters[id - MENU_SETTINGS_SHADER_PARAMETER_0]))
|
||||
return 0;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
param->current = param->initial;
|
||||
apply_changes = true;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
param->current -= param->step;
|
||||
apply_changes = true;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
param->current += param->step;
|
||||
apply_changes = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
param->current = min(max(param->minimum, param->current), param->maximum);
|
||||
|
||||
if (apply_changes
|
||||
&& !strcmp(label, "video_shader_parameters"))
|
||||
rarch_main_command(RARCH_CMD_SHADERS_APPLY_CHANGES);
|
||||
}
|
||||
else if ((!strcmp(label, "video_shader_parameters") ||
|
||||
!strcmp(label, "video_shader_preset_parameters"))
|
||||
&& action == MENU_ACTION_OK)
|
||||
menu_entries_push(driver.menu->menu_stack, "",
|
||||
"video_shader_parameters", MENU_FILE_SWITCH, driver.menu->selection_ptr);
|
||||
else if (!strcmp(label, "shader_apply_changes") ||
|
||||
!strcmp(label, "video_shader_num_passes"))
|
||||
menu_setting_set(id, label, action);
|
||||
else if (!strcmp(label, "video_shader_preset"))
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_OK:
|
||||
menu_entries_push(driver.menu->menu_stack,
|
||||
g_settings.video.shader_dir,
|
||||
"video_shader_preset",
|
||||
id, driver.menu->selection_ptr);
|
||||
break;
|
||||
|
||||
case MENU_ACTION_START:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_pass"))
|
||||
{
|
||||
hack_shader_pass = id - MENU_SETTINGS_SHADER_PASS_0;
|
||||
struct gfx_shader *shader = (struct gfx_shader*)driver.menu->shader;
|
||||
struct gfx_shader_pass *shader_pass = NULL;
|
||||
|
||||
if (shader)
|
||||
shader_pass = (struct gfx_shader_pass*)&shader->pass[hack_shader_pass];
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_OK:
|
||||
menu_entries_push(driver.menu->menu_stack,
|
||||
g_settings.video.shader_dir,
|
||||
"video_shader_pass",
|
||||
id, driver.menu->selection_ptr);
|
||||
break;
|
||||
case MENU_ACTION_START:
|
||||
if (shader_pass)
|
||||
*shader_pass->source.path = '\0';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_filter_pass"))
|
||||
{
|
||||
unsigned pass = id - MENU_SETTINGS_SHADER_PASS_FILTER_0;
|
||||
struct gfx_shader *shader = (struct gfx_shader*)driver.menu->shader;
|
||||
struct gfx_shader_pass *shader_pass = (struct gfx_shader_pass*)
|
||||
&shader->pass[pass];
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
if (shader)
|
||||
shader->pass[pass].filter = RARCH_FILTER_UNSPEC;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
{
|
||||
unsigned delta = (action == MENU_ACTION_LEFT) ? 2 : 1;
|
||||
if (shader_pass)
|
||||
shader_pass->filter = ((shader_pass->filter + delta) % 3);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_scale_pass"))
|
||||
{
|
||||
unsigned pass = id - MENU_SETTINGS_SHADER_PASS_SCALE_0;
|
||||
struct gfx_shader *shader = (struct gfx_shader*)driver.menu->shader;
|
||||
struct gfx_shader_pass *shader_pass = (struct gfx_shader_pass*)
|
||||
&shader->pass[pass];
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
if (shader)
|
||||
{
|
||||
shader_pass->fbo.scale_x = shader_pass->fbo.scale_y = 0;
|
||||
shader_pass->fbo.valid = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
{
|
||||
unsigned current_scale = shader_pass->fbo.scale_x;
|
||||
unsigned delta = action == MENU_ACTION_LEFT ? 5 : 1;
|
||||
current_scale = (current_scale + delta) % 6;
|
||||
|
||||
if (shader_pass)
|
||||
{
|
||||
shader_pass->fbo.valid = current_scale;
|
||||
shader_pass->fbo.scale_x = shader_pass->fbo.scale_y = current_scale;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int menu_setting_ok_toggle(unsigned type,
|
||||
const char *dir, const char *label,
|
||||
unsigned action)
|
||||
@ -1233,12 +375,7 @@ static int menu_setting_toggle(unsigned type,
|
||||
!strcmp(label, "video_shader_parameters") ||
|
||||
!strcmp(label, "video_shader_preset_parameters")
|
||||
)
|
||||
{
|
||||
if (driver.menu_ctx && driver.menu_ctx->backend
|
||||
&& driver.menu_ctx->backend->shader_manager_setting_toggle)
|
||||
return driver.menu_ctx->backend->shader_manager_setting_toggle(
|
||||
type, label, action);
|
||||
}
|
||||
return menu_shader_manager_setting_toggle(type, label, action);
|
||||
else if ((type >= MENU_SETTINGS_CORE_OPTION_START))
|
||||
return menu_common_core_setting_toggle(type, action);
|
||||
else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN &&
|
||||
@ -1256,7 +393,7 @@ static int menu_setting_toggle(unsigned type,
|
||||
type - MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN);
|
||||
}
|
||||
else if (driver.menu_ctx && driver.menu_ctx->backend)
|
||||
return menu_setting_set(type, label, action);
|
||||
return menu_action_setting_set(type, label, action);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1756,12 +893,9 @@ static int menu_action_ok(const char *menu_path,
|
||||
{
|
||||
char shader_path[PATH_MAX];
|
||||
fill_pathname_join(shader_path, menu_path, path, sizeof(shader_path));
|
||||
if (driver.menu_ctx && driver.menu_ctx->backend &&
|
||||
driver.menu_ctx->backend->shader_manager_set_preset)
|
||||
driver.menu_ctx->backend->shader_manager_set_preset(
|
||||
driver.menu->shader,
|
||||
gfx_shader_parse_type(shader_path, RARCH_SHADER_NONE),
|
||||
shader_path);
|
||||
menu_shader_manager_set_preset(driver.menu->shader,
|
||||
gfx_shader_parse_type(shader_path, RARCH_SHADER_NONE),
|
||||
shader_path);
|
||||
menu_flush_stack_label(driver.menu->menu_stack, "Shader Options");
|
||||
}
|
||||
#endif
|
||||
@ -2000,12 +1134,6 @@ static void menu_common_setting_set_label(char *type_str,
|
||||
|
||||
menu_ctx_driver_backend_t menu_ctx_backend_common = {
|
||||
menu_common_iterate,
|
||||
menu_common_shader_manager_init,
|
||||
menu_common_shader_manager_get_str,
|
||||
menu_common_shader_manager_set_preset,
|
||||
menu_common_shader_manager_save_preset,
|
||||
menu_common_shader_manager_get_type,
|
||||
menu_common_shader_manager_setting_toggle,
|
||||
menu_common_type_is,
|
||||
menu_common_setting_set_label,
|
||||
"menu_common",
|
||||
|
@ -20,10 +20,6 @@
|
||||
#include "../menu_common.h"
|
||||
#include "../../../settings_data.h"
|
||||
|
||||
#ifndef GFX_MAX_PARAMETERS
|
||||
#define GFX_MAX_PARAMETERS 64
|
||||
#endif
|
||||
|
||||
#ifndef MAX_COUNTERS
|
||||
#define MAX_COUNTERS 64
|
||||
#endif
|
||||
|
@ -542,14 +542,6 @@ static int menu_lakka_iterate(unsigned action)
|
||||
|
||||
menu_ctx_driver_backend_t menu_ctx_backend_lakka = {
|
||||
menu_lakka_iterate,
|
||||
//#ifndef HAVE_SHADER_MANAGER
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
//#endif
|
||||
NULL,
|
||||
NULL,
|
||||
"menu_lakka",
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "menu_common.h"
|
||||
#include "menu_input_line_cb.h"
|
||||
#include "menu_action.h"
|
||||
#include "menu_entries.h"
|
||||
#include "menu_shader.h"
|
||||
|
||||
int menu_action_setting_apply(rarch_setting_t *setting)
|
||||
{
|
||||
@ -259,13 +261,7 @@ int menu_action_set_current_string_based_on_label(
|
||||
const char *label, const char *str)
|
||||
{
|
||||
if (!strcmp(label, "video_shader_preset_save_as"))
|
||||
{
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
if (driver.menu_ctx && driver.menu_ctx->backend
|
||||
&& driver.menu_ctx->backend->shader_manager_save_preset)
|
||||
driver.menu_ctx->backend->shader_manager_save_preset(str, false);
|
||||
#endif
|
||||
}
|
||||
menu_shader_manager_save_preset(str, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -277,3 +273,310 @@ int menu_action_setting_set_current_string_path(
|
||||
|
||||
return menu_action_setting_apply(setting);
|
||||
}
|
||||
|
||||
|
||||
int menu_action_handle_setting(rarch_setting_t *setting,
|
||||
unsigned id, const char *label, unsigned action)
|
||||
{
|
||||
if (setting->type == ST_BOOL)
|
||||
return menu_action_setting_boolean(setting, action);
|
||||
if (setting->type == ST_UINT)
|
||||
return menu_action_setting_unsigned_integer(setting, id, action);
|
||||
if (setting->type == ST_FLOAT)
|
||||
return menu_action_setting_fraction(setting, action);
|
||||
if (setting->type == ST_PATH)
|
||||
return menu_entries_set_current_path_selection(setting,
|
||||
setting->default_value.string, setting->name, id, action);
|
||||
|
||||
if (setting->type == ST_DIR)
|
||||
{
|
||||
if (action == MENU_ACTION_START)
|
||||
{
|
||||
*setting->value.string = '\0';
|
||||
return menu_action_setting_apply(setting);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (setting->type == ST_STRING)
|
||||
{
|
||||
if (
|
||||
(setting->flags & SD_FLAG_ALLOW_INPUT) ||
|
||||
id == MENU_FILE_LINEFEED_SWITCH)
|
||||
{
|
||||
if (action == MENU_ACTION_OK)
|
||||
menu_key_start_line(driver.menu, setting->short_description,
|
||||
setting->name, st_string_callback);
|
||||
else if (action == MENU_ACTION_START)
|
||||
*setting->value.string = '\0';
|
||||
}
|
||||
else
|
||||
menu_action_setting_driver(setting, action);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int menu_action_setting_set(unsigned id, const char *label,
|
||||
unsigned action)
|
||||
{
|
||||
unsigned port = driver.menu->current_pad;
|
||||
const file_list_t *list = (const file_list_t*)driver.menu->selection_buf;
|
||||
|
||||
rarch_setting_t *setting = (rarch_setting_t*)menu_entries_get_last_setting(
|
||||
list->list[driver.menu->selection_ptr].label,
|
||||
driver.menu->selection_ptr,
|
||||
setting_data_get_list()
|
||||
);
|
||||
|
||||
if (setting)
|
||||
return menu_action_handle_setting(setting, id, label, action);
|
||||
else
|
||||
{
|
||||
setting = (rarch_setting_t*)menu_entries_get_last_setting(
|
||||
list->list[driver.menu->selection_ptr].label,
|
||||
driver.menu->selection_ptr,
|
||||
setting_data_get_mainmenu(true)
|
||||
);
|
||||
|
||||
if (setting)
|
||||
{
|
||||
if (!strcmp(setting->name, "disk_index"))
|
||||
{
|
||||
int step = 0;
|
||||
|
||||
if (action == MENU_ACTION_RIGHT || action == MENU_ACTION_OK)
|
||||
step = 1;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
step = -1;
|
||||
|
||||
if (step)
|
||||
{
|
||||
const struct retro_disk_control_callback *control =
|
||||
(const struct retro_disk_control_callback*)
|
||||
&g_extern.system.disk_control;
|
||||
unsigned num_disks = control->get_num_images();
|
||||
unsigned current = control->get_image_index();
|
||||
unsigned next_index = (current + num_disks + 1 + step)
|
||||
% (num_disks + 1);
|
||||
rarch_disk_control_set_eject(true, false);
|
||||
rarch_disk_control_set_index(next_index);
|
||||
rarch_disk_control_set_eject(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
return menu_action_handle_setting(setting, id, label, action);
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_device_id"))
|
||||
{
|
||||
int *p = &g_settings.input.joypad_map[port];
|
||||
if (action == MENU_ACTION_START)
|
||||
*p = port;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
(*p)--;
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
(*p)++;
|
||||
|
||||
if (*p < -1)
|
||||
*p = -1;
|
||||
else if (*p >= MAX_PLAYERS)
|
||||
*p = MAX_PLAYERS - 1;
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_device_type"))
|
||||
{
|
||||
unsigned current_device, current_index, i, devices[128];
|
||||
const struct retro_controller_info *desc;
|
||||
unsigned types = 0;
|
||||
|
||||
devices[types++] = RETRO_DEVICE_NONE;
|
||||
devices[types++] = RETRO_DEVICE_JOYPAD;
|
||||
|
||||
/* Only push RETRO_DEVICE_ANALOG as default if we use an
|
||||
* older core which doesn't use SET_CONTROLLER_INFO. */
|
||||
if (!g_extern.system.num_ports)
|
||||
devices[types++] = RETRO_DEVICE_ANALOG;
|
||||
|
||||
desc = port < g_extern.system.num_ports ?
|
||||
&g_extern.system.ports[port] : NULL;
|
||||
if (desc)
|
||||
{
|
||||
for (i = 0; i < desc->num_types; i++)
|
||||
{
|
||||
unsigned id = desc->types[i].id;
|
||||
if (types < ARRAY_SIZE(devices) &&
|
||||
id != RETRO_DEVICE_NONE &&
|
||||
id != RETRO_DEVICE_JOYPAD)
|
||||
devices[types++] = id;
|
||||
}
|
||||
}
|
||||
|
||||
current_device = g_settings.input.libretro_device[port];
|
||||
current_index = 0;
|
||||
for (i = 0; i < types; i++)
|
||||
{
|
||||
if (current_device == devices[i])
|
||||
{
|
||||
current_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool updated = true;
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
current_device = RETRO_DEVICE_JOYPAD;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
current_device = devices
|
||||
[(current_index + types - 1) % types];
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
current_device = devices
|
||||
[(current_index + 1) % types];
|
||||
break;
|
||||
|
||||
default:
|
||||
updated = false;
|
||||
}
|
||||
|
||||
if (updated)
|
||||
{
|
||||
g_settings.input.libretro_device[port] = current_device;
|
||||
pretro_set_controller_port_device(port, current_device);
|
||||
}
|
||||
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_player_no"))
|
||||
{
|
||||
if (action == MENU_ACTION_START)
|
||||
driver.menu->current_pad = 0;
|
||||
else if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
if (driver.menu->current_pad != 0)
|
||||
driver.menu->current_pad--;
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
{
|
||||
if (driver.menu->current_pad < MAX_PLAYERS - 1)
|
||||
driver.menu->current_pad++;
|
||||
}
|
||||
if (port != driver.menu->current_pad)
|
||||
driver.menu->need_refresh = true;
|
||||
port = driver.menu->current_pad;
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_analog_dpad_mode"))
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
g_settings.input.analog_dpad_mode[port] = 0;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_OK:
|
||||
case MENU_ACTION_RIGHT:
|
||||
g_settings.input.analog_dpad_mode[port] =
|
||||
(g_settings.input.analog_dpad_mode[port] + 1)
|
||||
% ANALOG_DPAD_LAST;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
g_settings.input.analog_dpad_mode[port] =
|
||||
(g_settings.input.analog_dpad_mode
|
||||
[port] + ANALOG_DPAD_LAST - 1) % ANALOG_DPAD_LAST;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case MENU_SETTINGS_CUSTOM_BIND_MODE:
|
||||
if (action == MENU_ACTION_LEFT || action == MENU_ACTION_RIGHT)
|
||||
driver.menu->bind_mode_keyboard =
|
||||
!driver.menu->bind_mode_keyboard;
|
||||
break;
|
||||
#if defined(GEKKO)
|
||||
case MENU_SETTINGS_VIDEO_RESOLUTION:
|
||||
if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
if (menu_current_gx_resolution > 0)
|
||||
menu_current_gx_resolution--;
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
{
|
||||
if (menu_current_gx_resolution < GX_RESOLUTIONS_LAST - 1)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
if ((menu_current_gx_resolution + 1) > GX_RESOLUTIONS_640_480)
|
||||
if (CONF_GetVideo() != CONF_VIDEO_PAL)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
menu_current_gx_resolution++;
|
||||
}
|
||||
}
|
||||
else if (action == MENU_ACTION_OK)
|
||||
{
|
||||
if (driver.video_data)
|
||||
gx_set_video_mode(driver.video_data, menu_gx_resolutions
|
||||
[menu_current_gx_resolution][0],
|
||||
menu_gx_resolutions[menu_current_gx_resolution][1]);
|
||||
}
|
||||
break;
|
||||
#elif defined(__CELLOS_LV2__)
|
||||
case MENU_SETTINGS_VIDEO_RESOLUTION:
|
||||
if (action == MENU_ACTION_LEFT)
|
||||
{
|
||||
if (g_extern.console.screen.resolutions.current.idx)
|
||||
{
|
||||
g_extern.console.screen.resolutions.current.idx--;
|
||||
g_extern.console.screen.resolutions.current.id =
|
||||
g_extern.console.screen.resolutions.list
|
||||
[g_extern.console.screen.resolutions.current.idx];
|
||||
}
|
||||
}
|
||||
else if (action == MENU_ACTION_RIGHT)
|
||||
{
|
||||
if (g_extern.console.screen.resolutions.current.idx + 1 <
|
||||
g_extern.console.screen.resolutions.count)
|
||||
{
|
||||
g_extern.console.screen.resolutions.current.idx++;
|
||||
g_extern.console.screen.resolutions.current.id =
|
||||
g_extern.console.screen.resolutions.list
|
||||
[g_extern.console.screen.resolutions.current.idx];
|
||||
}
|
||||
}
|
||||
else if (action == MENU_ACTION_OK)
|
||||
{
|
||||
if (g_extern.console.screen.resolutions.list[
|
||||
g_extern.console.screen.resolutions.current.idx] ==
|
||||
CELL_VIDEO_OUT_RESOLUTION_576)
|
||||
{
|
||||
if (g_extern.console.screen.pal_enable)
|
||||
g_extern.console.screen.pal60_enable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_extern.console.screen.pal_enable = false;
|
||||
g_extern.console.screen.pal60_enable = false;
|
||||
}
|
||||
|
||||
rarch_main_command(RARCH_CMD_REINIT);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -42,4 +42,10 @@ int menu_action_setting_set_current_string(
|
||||
int menu_action_setting_set_current_string_path(
|
||||
rarch_setting_t *setting, const char *dir, const char *path);
|
||||
|
||||
int menu_action_setting_set(unsigned id, const char *label,
|
||||
unsigned action);
|
||||
|
||||
int menu_action_handle_setting(rarch_setting_t *setting,
|
||||
unsigned id, const char *label, unsigned action);
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "menu_common.h"
|
||||
#include "menu_input_line_cb.h"
|
||||
#include "menu_entries.h"
|
||||
#include "menu_shader.h"
|
||||
#include "../frontend.h"
|
||||
|
||||
static void draw_frame(bool enable)
|
||||
@ -137,9 +138,7 @@ bool load_menu_content(void)
|
||||
rarch_main_command(RARCH_CMD_HISTORY_DEINIT);
|
||||
rarch_main_command(RARCH_CMD_HISTORY_INIT);
|
||||
|
||||
if (driver.menu_ctx && driver.menu_ctx->backend
|
||||
&& driver.menu_ctx->backend->shader_manager_init)
|
||||
driver.menu_ctx->backend->shader_manager_init(driver.menu);
|
||||
menu_shader_manager_init(driver.menu);
|
||||
|
||||
rarch_main_command(RARCH_CMD_VIDEO_SET_ASPECT_RATIO);
|
||||
rarch_main_command(RARCH_CMD_RESUME);
|
||||
@ -182,9 +181,7 @@ void *menu_init(const void *data)
|
||||
|
||||
update_libretro_info(&g_extern.menu.info);
|
||||
|
||||
if (menu_ctx->backend
|
||||
&& menu_ctx->backend->shader_manager_init)
|
||||
menu_ctx->backend->shader_manager_init(menu);
|
||||
menu_shader_manager_init(menu);
|
||||
|
||||
rarch_main_command(RARCH_CMD_HISTORY_INIT);
|
||||
menu->last_time = rarch_get_time_usec();
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include "menu_entries.h"
|
||||
#include "menu_action.h"
|
||||
#include "backend/menu_common_backend.h"
|
||||
#include "../../settings_data.h"
|
||||
#include "../../file_ext.h"
|
||||
@ -912,3 +913,35 @@ void menu_entries_push(file_list_t *list,
|
||||
menu_clear_navigation(driver.menu);
|
||||
driver.menu->need_refresh = true;
|
||||
}
|
||||
|
||||
int menu_entries_set_current_path_selection(
|
||||
rarch_setting_t *setting, const char *start_path,
|
||||
const char *label, unsigned type,
|
||||
unsigned action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_OK:
|
||||
menu_entries_push(driver.menu->menu_stack,
|
||||
start_path, label, type,
|
||||
driver.menu->selection_ptr);
|
||||
|
||||
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
|
||||
setting->cmd_trigger.triggered = true;
|
||||
break;
|
||||
case MENU_ACTION_START:
|
||||
*setting->value.string = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
return menu_action_setting_apply(setting);
|
||||
}
|
||||
|
||||
void *menu_entries_get_last_setting(const char *label, int index,
|
||||
rarch_setting_t *settings)
|
||||
{
|
||||
if (settings)
|
||||
return (rarch_setting_t*)setting_data_find_setting(settings,
|
||||
label);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "menu_common.h"
|
||||
#include "../../file_list.h"
|
||||
#include "../../settings_data.h"
|
||||
|
||||
void menu_entries_push(file_list_t *list,
|
||||
const char *path, const char *label, unsigned type,
|
||||
@ -39,4 +40,12 @@ void menu_entries_pop_stack(file_list_t *list, const char *needle);
|
||||
void menu_flush_stack_type(file_list_t *list, unsigned final_type);
|
||||
void menu_flush_stack_label(file_list_t *list, const char *needle);
|
||||
|
||||
int menu_entries_set_current_path_selection(
|
||||
rarch_setting_t *setting, const char *start_path,
|
||||
const char *label, unsigned type,
|
||||
unsigned action);
|
||||
|
||||
void *menu_entries_get_last_setting(const char *label, int index,
|
||||
rarch_setting_t *settings);
|
||||
|
||||
#endif
|
||||
|
568
frontend/menu/menu_shader.c
Normal file
568
frontend/menu/menu_shader.c
Normal file
@ -0,0 +1,568 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2014 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../../gfx/shader_common.h"
|
||||
#include "menu_action.h"
|
||||
#include "menu_common.h"
|
||||
#include "menu_entries.h"
|
||||
#include "menu_shader.h"
|
||||
#include "../../settings_data.h"
|
||||
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
|
||||
extern size_t hack_shader_pass;
|
||||
|
||||
void menu_shader_manager_init(void *data)
|
||||
{
|
||||
char cgp_path[PATH_MAX];
|
||||
struct gfx_shader *shader;
|
||||
config_file_t *conf = NULL;
|
||||
const char *config_path = NULL;
|
||||
menu_handle_t *menu = (menu_handle_t*)data;
|
||||
|
||||
if (!menu)
|
||||
return;
|
||||
|
||||
shader = (struct gfx_shader*)menu->shader;
|
||||
|
||||
if (*g_extern.core_specific_config_path
|
||||
&& g_settings.core_specific_config)
|
||||
config_path = g_extern.core_specific_config_path;
|
||||
else if (*g_extern.config_path)
|
||||
config_path = g_extern.config_path;
|
||||
|
||||
/* In a multi-config setting, we can't have
|
||||
* conflicts on menu.cgp/menu.glslp. */
|
||||
if (config_path)
|
||||
{
|
||||
fill_pathname_base(menu->default_glslp, config_path,
|
||||
sizeof(menu->default_glslp));
|
||||
path_remove_extension(menu->default_glslp);
|
||||
strlcat(menu->default_glslp, ".glslp", sizeof(menu->default_glslp));
|
||||
fill_pathname_base(menu->default_cgp, config_path,
|
||||
sizeof(menu->default_cgp));
|
||||
path_remove_extension(menu->default_cgp);
|
||||
strlcat(menu->default_cgp, ".cgp", sizeof(menu->default_cgp));
|
||||
}
|
||||
else
|
||||
{
|
||||
strlcpy(menu->default_glslp, "menu.glslp", sizeof(menu->default_glslp));
|
||||
strlcpy(menu->default_cgp, "menu.cgp", sizeof(menu->default_cgp));
|
||||
}
|
||||
|
||||
|
||||
const char *ext = path_get_extension(g_settings.video.shader_path);
|
||||
if (strcmp(ext, "glslp") == 0 || strcmp(ext, "cgp") == 0)
|
||||
{
|
||||
conf = config_file_new(g_settings.video.shader_path);
|
||||
if (conf)
|
||||
{
|
||||
if (gfx_shader_read_conf_cgp(conf, shader))
|
||||
{
|
||||
gfx_shader_resolve_relative(shader, g_settings.video.shader_path);
|
||||
gfx_shader_resolve_parameters(conf, shader);
|
||||
}
|
||||
config_file_free(conf);
|
||||
}
|
||||
}
|
||||
else if (strcmp(ext, "glsl") == 0 || strcmp(ext, "cg") == 0)
|
||||
{
|
||||
strlcpy(shader->pass[0].source.path, g_settings.video.shader_path,
|
||||
sizeof(shader->pass[0].source.path));
|
||||
shader->passes = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *shader_dir = *g_settings.video.shader_dir ?
|
||||
g_settings.video.shader_dir : g_settings.system_directory;
|
||||
|
||||
fill_pathname_join(cgp_path, shader_dir, "menu.glslp", sizeof(cgp_path));
|
||||
conf = config_file_new(cgp_path);
|
||||
|
||||
if (!conf)
|
||||
{
|
||||
fill_pathname_join(cgp_path, shader_dir, "menu.cgp", sizeof(cgp_path));
|
||||
conf = config_file_new(cgp_path);
|
||||
}
|
||||
|
||||
if (conf)
|
||||
{
|
||||
if (gfx_shader_read_conf_cgp(conf, shader))
|
||||
{
|
||||
gfx_shader_resolve_relative(shader, cgp_path);
|
||||
gfx_shader_resolve_parameters(conf, shader);
|
||||
}
|
||||
config_file_free(conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void menu_shader_manager_set_preset(struct gfx_shader *shader,
|
||||
unsigned type, const char *cgp_path)
|
||||
{
|
||||
RARCH_LOG("Setting Menu shader: %s.\n", cgp_path ? cgp_path : "N/A (stock)");
|
||||
g_settings.video.shader_enable = false;
|
||||
|
||||
if (driver.video->set_shader && driver.video->set_shader(driver.video_data,
|
||||
(enum rarch_shader_type)type, cgp_path))
|
||||
{
|
||||
/* Makes sure that we use Menu CGP shader on driver reinit.
|
||||
* Only do this when the cgp actually works to avoid potential errors. */
|
||||
strlcpy(g_settings.video.shader_path, cgp_path ? cgp_path : "",
|
||||
sizeof(g_settings.video.shader_path));
|
||||
g_settings.video.shader_enable = true;
|
||||
|
||||
if (cgp_path && shader)
|
||||
{
|
||||
/* Load stored CGP into menu on success.
|
||||
* Used when a preset is directly loaded.
|
||||
* No point in updating when the CGP was
|
||||
* created from the menu itself. */
|
||||
config_file_t *conf = config_file_new(cgp_path);
|
||||
|
||||
if (conf)
|
||||
{
|
||||
if (gfx_shader_read_conf_cgp(conf, shader))
|
||||
{
|
||||
gfx_shader_resolve_relative(shader, cgp_path);
|
||||
gfx_shader_resolve_parameters(conf, shader);
|
||||
}
|
||||
config_file_free(conf);
|
||||
}
|
||||
|
||||
driver.menu->need_refresh = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void menu_shader_manager_get_str(struct gfx_shader *shader,
|
||||
char *type_str, size_t type_str_size, const char *menu_label,
|
||||
const char *label, unsigned type)
|
||||
{
|
||||
*type_str = '\0';
|
||||
|
||||
if (!strcmp(label, "video_shader_num_passes"))
|
||||
snprintf(type_str, type_str_size, "%u", shader->passes);
|
||||
else if (type >= MENU_SETTINGS_SHADER_PARAMETER_0
|
||||
&& type <= MENU_SETTINGS_SHADER_PARAMETER_LAST)
|
||||
{
|
||||
/* menu->parameter_shader here. */
|
||||
if (shader)
|
||||
{
|
||||
const struct gfx_shader_parameter *param =
|
||||
(const struct gfx_shader_parameter*)&shader->parameters
|
||||
[type - MENU_SETTINGS_SHADER_PARAMETER_0];
|
||||
snprintf(type_str, type_str_size, "%.2f [%.2f %.2f]",
|
||||
param->current, param->minimum, param->maximum);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_default_filter"))
|
||||
snprintf(type_str, type_str_size, "%s",
|
||||
g_settings.video.smooth ? "Linear" : "Nearest");
|
||||
else if (!strcmp(label, "video_shader_pass"))
|
||||
{
|
||||
unsigned pass = (type - MENU_SETTINGS_SHADER_PASS_0);
|
||||
if (*shader->pass[pass].source.path)
|
||||
fill_pathname_base(type_str,
|
||||
shader->pass[pass].source.path, type_str_size);
|
||||
else
|
||||
strlcpy(type_str, "N/A", type_str_size);
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_filter_pass"))
|
||||
{
|
||||
unsigned pass = (type - MENU_SETTINGS_SHADER_PASS_FILTER_0);
|
||||
static const char *modes[] = {
|
||||
"Don't care",
|
||||
"Linear",
|
||||
"Nearest"
|
||||
};
|
||||
|
||||
strlcpy(type_str, modes[shader->pass[pass].filter],
|
||||
type_str_size);
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_scale_pass"))
|
||||
{
|
||||
unsigned pass = (type - MENU_SETTINGS_SHADER_PASS_SCALE_0);
|
||||
unsigned scale = shader->pass[pass].fbo.scale_x;
|
||||
if (!scale)
|
||||
strlcpy(type_str, "Don't care", type_str_size);
|
||||
else
|
||||
snprintf(type_str, type_str_size, "%ux", scale);
|
||||
}
|
||||
}
|
||||
|
||||
void menu_shader_manager_save_preset(
|
||||
const char *basename, bool apply)
|
||||
{
|
||||
char buffer[PATH_MAX], config_directory[PATH_MAX], cgp_path[PATH_MAX];
|
||||
unsigned d, type = RARCH_SHADER_NONE;
|
||||
config_file_t *conf = NULL;
|
||||
bool ret = false;
|
||||
|
||||
if (!driver.menu)
|
||||
{
|
||||
RARCH_ERR("Cannot save shader preset, menu handle is not initialized.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
type = menu_shader_manager_get_type(driver.menu->shader);
|
||||
|
||||
if (type == RARCH_SHADER_NONE)
|
||||
return;
|
||||
|
||||
*config_directory = '\0';
|
||||
|
||||
if (basename)
|
||||
{
|
||||
strlcpy(buffer, basename, sizeof(buffer));
|
||||
|
||||
/* Append extension automatically as appropriate. */
|
||||
if (!strstr(basename, ".cgp") && !strstr(basename, ".glslp"))
|
||||
{
|
||||
if (type == RARCH_SHADER_GLSL)
|
||||
strlcat(buffer, ".glslp", sizeof(buffer));
|
||||
else if (type == RARCH_SHADER_CG)
|
||||
strlcat(buffer, ".cgp", sizeof(buffer));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const char *conf_path = (type == RARCH_SHADER_GLSL) ?
|
||||
driver.menu->default_glslp : driver.menu->default_cgp;
|
||||
strlcpy(buffer, conf_path, sizeof(buffer));
|
||||
}
|
||||
|
||||
if (*g_extern.config_path)
|
||||
fill_pathname_basedir(config_directory,
|
||||
g_extern.config_path, sizeof(config_directory));
|
||||
|
||||
const char *dirs[] = {
|
||||
g_settings.video.shader_dir,
|
||||
g_settings.menu_config_directory,
|
||||
config_directory,
|
||||
};
|
||||
|
||||
if (!(conf = (config_file_t*)config_file_new(NULL)))
|
||||
return;
|
||||
gfx_shader_write_conf_cgp(conf, driver.menu->shader);
|
||||
|
||||
for (d = 0; d < ARRAY_SIZE(dirs); d++)
|
||||
{
|
||||
if (!*dirs[d])
|
||||
continue;
|
||||
|
||||
fill_pathname_join(cgp_path, dirs[d], buffer, sizeof(cgp_path));
|
||||
if (config_file_write(conf, cgp_path))
|
||||
{
|
||||
RARCH_LOG("Saved shader preset to %s.\n", cgp_path);
|
||||
if (apply)
|
||||
menu_shader_manager_set_preset(NULL, type, cgp_path);
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
RARCH_LOG("Failed writing shader preset to %s.\n", cgp_path);
|
||||
}
|
||||
|
||||
config_file_free(conf);
|
||||
if (!ret)
|
||||
RARCH_ERR("Failed to save shader preset. Make sure config directory and/or shader dir are writable.\n");
|
||||
}
|
||||
|
||||
unsigned menu_shader_manager_get_type(const struct gfx_shader *shader)
|
||||
{
|
||||
/* All shader types must be the same, or we cannot use it. */
|
||||
unsigned i = 0, type = 0;
|
||||
|
||||
if (!shader)
|
||||
{
|
||||
RARCH_ERR("Cannot get shader type, shader handle is not initialized.\n");
|
||||
return RARCH_SHADER_NONE;
|
||||
}
|
||||
|
||||
for (i = 0; i < shader->passes; i++)
|
||||
{
|
||||
enum rarch_shader_type pass_type = gfx_shader_parse_type(shader->pass[i].source.path,
|
||||
RARCH_SHADER_NONE);
|
||||
|
||||
switch (pass_type)
|
||||
{
|
||||
case RARCH_SHADER_CG:
|
||||
case RARCH_SHADER_GLSL:
|
||||
if (type == RARCH_SHADER_NONE)
|
||||
type = pass_type;
|
||||
else if (type != pass_type)
|
||||
return RARCH_SHADER_NONE;
|
||||
break;
|
||||
default:
|
||||
return RARCH_SHADER_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
int menu_shader_manager_setting_toggle(
|
||||
unsigned id, const char *label, unsigned action)
|
||||
{
|
||||
if (!driver.menu)
|
||||
{
|
||||
RARCH_ERR("Cannot toggle shader setting, menu handle is not initialized.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
RARCH_LOG("shader label: %s\n", label);
|
||||
#endif
|
||||
|
||||
rarch_setting_t *current_setting = NULL;
|
||||
rarch_setting_t *setting_data = (rarch_setting_t *)setting_data_get_list();
|
||||
|
||||
|
||||
if (!strcmp(label, "video_shader_default_filter"))
|
||||
{
|
||||
if ((current_setting = setting_data_find_setting(
|
||||
setting_data, "video_smooth")))
|
||||
menu_action_setting_boolean(current_setting, action);
|
||||
}
|
||||
else if (id >= MENU_SETTINGS_SHADER_PARAMETER_0
|
||||
&& id <= MENU_SETTINGS_SHADER_PARAMETER_LAST)
|
||||
{
|
||||
bool apply_changes = false;
|
||||
struct gfx_shader *shader = NULL;
|
||||
struct gfx_shader_parameter *param = NULL;
|
||||
|
||||
if (!(shader = (struct gfx_shader*)driver.menu->parameter_shader))
|
||||
return 0;
|
||||
|
||||
if (!(param = &shader->parameters[id - MENU_SETTINGS_SHADER_PARAMETER_0]))
|
||||
return 0;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
param->current = param->initial;
|
||||
apply_changes = true;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
param->current -= param->step;
|
||||
apply_changes = true;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
param->current += param->step;
|
||||
apply_changes = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
param->current = min(max(param->minimum, param->current), param->maximum);
|
||||
|
||||
if (apply_changes
|
||||
&& !strcmp(label, "video_shader_parameters"))
|
||||
rarch_main_command(RARCH_CMD_SHADERS_APPLY_CHANGES);
|
||||
}
|
||||
else if ((!strcmp(label, "video_shader_parameters") ||
|
||||
!strcmp(label, "video_shader_preset_parameters"))
|
||||
&& action == MENU_ACTION_OK)
|
||||
menu_entries_push(driver.menu->menu_stack, "",
|
||||
"video_shader_parameters", MENU_FILE_SWITCH, driver.menu->selection_ptr);
|
||||
else if (!strcmp(label, "shader_apply_changes") ||
|
||||
!strcmp(label, "video_shader_num_passes"))
|
||||
{
|
||||
if (!strcmp(label, "video_shader_num_passes"))
|
||||
return handle_shader_pass_setting(driver.menu->shader, action);
|
||||
menu_action_setting_set(id, label, action);
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_preset"))
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_OK:
|
||||
menu_entries_push(driver.menu->menu_stack,
|
||||
g_settings.video.shader_dir,
|
||||
"video_shader_preset",
|
||||
id, driver.menu->selection_ptr);
|
||||
break;
|
||||
|
||||
case MENU_ACTION_START:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_pass"))
|
||||
{
|
||||
hack_shader_pass = id - MENU_SETTINGS_SHADER_PASS_0;
|
||||
struct gfx_shader *shader = (struct gfx_shader*)driver.menu->shader;
|
||||
struct gfx_shader_pass *shader_pass = NULL;
|
||||
|
||||
if (shader)
|
||||
shader_pass = (struct gfx_shader_pass*)&shader->pass[hack_shader_pass];
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_OK:
|
||||
menu_entries_push(driver.menu->menu_stack,
|
||||
g_settings.video.shader_dir,
|
||||
"video_shader_pass",
|
||||
id, driver.menu->selection_ptr);
|
||||
break;
|
||||
case MENU_ACTION_START:
|
||||
if (shader_pass)
|
||||
*shader_pass->source.path = '\0';
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_filter_pass"))
|
||||
{
|
||||
unsigned pass = id - MENU_SETTINGS_SHADER_PASS_FILTER_0;
|
||||
struct gfx_shader *shader = (struct gfx_shader*)driver.menu->shader;
|
||||
struct gfx_shader_pass *shader_pass = (struct gfx_shader_pass*)
|
||||
&shader->pass[pass];
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
if (shader)
|
||||
shader->pass[pass].filter = RARCH_FILTER_UNSPEC;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
{
|
||||
unsigned delta = (action == MENU_ACTION_LEFT) ? 2 : 1;
|
||||
if (shader_pass)
|
||||
shader_pass->filter = ((shader_pass->filter + delta) % 3);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(label, "video_shader_scale_pass"))
|
||||
{
|
||||
unsigned pass = id - MENU_SETTINGS_SHADER_PASS_SCALE_0;
|
||||
struct gfx_shader *shader = (struct gfx_shader*)driver.menu->shader;
|
||||
struct gfx_shader_pass *shader_pass = (struct gfx_shader_pass*)
|
||||
&shader->pass[pass];
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
if (shader)
|
||||
{
|
||||
shader_pass->fbo.scale_x = shader_pass->fbo.scale_y = 0;
|
||||
shader_pass->fbo.valid = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
{
|
||||
unsigned current_scale = shader_pass->fbo.scale_x;
|
||||
unsigned delta = action == MENU_ACTION_LEFT ? 5 : 1;
|
||||
current_scale = (current_scale + delta) % 6;
|
||||
|
||||
if (shader_pass)
|
||||
{
|
||||
shader_pass->fbo.valid = current_scale;
|
||||
shader_pass->fbo.scale_x = shader_pass->fbo.scale_y = current_scale;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int handle_shader_pass_setting(struct gfx_shader *shader, unsigned action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case MENU_ACTION_START:
|
||||
if (shader && shader->passes)
|
||||
shader->passes = 0;
|
||||
driver.menu->need_refresh = true;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_LEFT:
|
||||
if (shader && shader->passes)
|
||||
shader->passes--;
|
||||
driver.menu->need_refresh = true;
|
||||
break;
|
||||
|
||||
case MENU_ACTION_RIGHT:
|
||||
case MENU_ACTION_OK:
|
||||
if (shader && (shader->passes < GFX_MAX_SHADERS))
|
||||
shader->passes++;
|
||||
driver.menu->need_refresh = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (driver.menu->need_refresh)
|
||||
gfx_shader_resolve_parameters(NULL, driver.menu->shader);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void menu_shader_manager_init(void *data) {}
|
||||
void menu_shader_manager_set_preset(struct gfx_shader *shader,
|
||||
unsigned type, const char *cgp_path) { }
|
||||
|
||||
int menu_shader_manager_setting_toggle(
|
||||
unsigned id, const char *label, unsigned action)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void menu_shader_manager_save_preset(
|
||||
const char *basename, bool apply) { }
|
||||
|
||||
unsigned menu_shader_manager_get_type(const struct gfx_shader *shader)
|
||||
{
|
||||
return RARCH_SHADER_NONE;
|
||||
}
|
||||
|
||||
void menu_shader_manager_get_str(struct gfx_shader *shader,
|
||||
char *type_str, size_t type_str_size, const char *menu_label,
|
||||
const char *label, unsigned type) { }
|
||||
|
||||
int handle_shader_pass_setting(struct gfx_shader *shader)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
40
frontend/menu/menu_shader.h
Normal file
40
frontend/menu/menu_shader.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2014 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _MENU_SHADER_MANAGER_H
|
||||
#define _MENU_SHADER_MANAGER_H
|
||||
|
||||
#if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL)
|
||||
#define HAVE_SHADER_MANAGER
|
||||
#endif
|
||||
|
||||
#include "../../gfx/shader_parse.h"
|
||||
|
||||
void menu_shader_manager_init(void *data);
|
||||
void menu_shader_manager_set_preset(struct gfx_shader *shader,
|
||||
unsigned type, const char *cgp_path);
|
||||
int menu_shader_manager_setting_toggle(
|
||||
unsigned id, const char *label, unsigned action);
|
||||
void menu_shader_manager_save_preset(
|
||||
const char *basename, bool apply);
|
||||
unsigned menu_shader_manager_get_type(
|
||||
const struct gfx_shader *shader);
|
||||
void menu_shader_manager_get_str(struct gfx_shader *shader,
|
||||
char *type_str, size_t type_str_size, const char *menu_label,
|
||||
const char *label, unsigned type);
|
||||
int handle_shader_pass_setting(struct gfx_shader *shader, unsigned action);
|
||||
|
||||
#endif
|
@ -642,6 +642,7 @@ MENU
|
||||
#include "../frontend/menu/menu_common.c"
|
||||
#include "../frontend/menu/menu_action.c"
|
||||
#include "../frontend/menu/menu_entries.c"
|
||||
#include "../frontend/menu/menu_shader.c"
|
||||
#include "../frontend/menu/menu_navigation.c"
|
||||
|
||||
#include "../frontend/menu/backend/menu_common_backend.c"
|
||||
|
18
retroarch.c
18
retroarch.c
@ -44,6 +44,7 @@
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
#include "frontend/menu/menu_common.h"
|
||||
#include "frontend/menu/menu_shader.h"
|
||||
#include "frontend/menu/menu_input_line_cb.h"
|
||||
#endif
|
||||
|
||||
@ -3334,16 +3335,10 @@ void rarch_main_command(unsigned cmd)
|
||||
#ifdef HAVE_MENU
|
||||
{
|
||||
unsigned shader_type = RARCH_SHADER_NONE;
|
||||
shader_type = menu_shader_manager_get_type(driver.menu->shader);
|
||||
|
||||
if (driver.menu_ctx && driver.menu_ctx->backend &&
|
||||
driver.menu_ctx->backend->shader_manager_get_type)
|
||||
shader_type = driver.menu_ctx->backend->shader_manager_get_type(
|
||||
driver.menu->shader);
|
||||
|
||||
if (driver.menu->shader->passes && shader_type != RARCH_SHADER_NONE
|
||||
&& driver.menu_ctx && driver.menu_ctx->backend &&
|
||||
driver.menu_ctx->backend->shader_manager_save_preset)
|
||||
driver.menu_ctx->backend->shader_manager_save_preset(NULL, true);
|
||||
if (driver.menu->shader->passes && shader_type != RARCH_SHADER_NONE)
|
||||
menu_shader_manager_save_preset(NULL, true);
|
||||
else
|
||||
{
|
||||
#if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL)
|
||||
@ -3358,10 +3353,7 @@ void rarch_main_command(unsigned cmd)
|
||||
shader_type = RARCH_SHADER_CG;
|
||||
#endif
|
||||
}
|
||||
if (driver.menu_ctx && driver.menu_ctx->backend &&
|
||||
driver.menu_ctx->backend->shader_manager_set_preset)
|
||||
driver.menu_ctx->backend->shader_manager_set_preset(
|
||||
NULL, shader_type, NULL);
|
||||
menu_shader_manager_set_preset(NULL, shader_type, NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
#include "frontend/menu/menu_entries.h"
|
||||
#include "frontend/menu/menu_shader.h"
|
||||
#endif
|
||||
|
||||
static void get_input_config_prefix(char *buf, size_t sizeof_buf,
|
||||
@ -1832,8 +1833,6 @@ static void menu_common_setting_set_label_perf(char *type_str,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void setting_data_get_label(char *type_str,
|
||||
size_t type_str_size, unsigned *w, unsigned type,
|
||||
const char *menu_label, const char *label, unsigned index)
|
||||
@ -1845,14 +1844,12 @@ void setting_data_get_label(char *type_str,
|
||||
if ((!strcmp(menu_label, "Shader Options") ||
|
||||
!strcmp(menu_label, "video_shader_parameters") ||
|
||||
!strcmp(menu_label, "video_shader_preset_parameters"))
|
||||
&&
|
||||
driver.menu_ctx && driver.menu_ctx->backend &&
|
||||
driver.menu_ctx->backend->shader_manager_get_str
|
||||
)
|
||||
{
|
||||
driver.menu_ctx->backend->shader_manager_get_str(
|
||||
driver.menu->shader, type_str, type_str_size,
|
||||
#ifdef HAVE_MENU
|
||||
menu_shader_manager_get_str(driver.menu->shader, type_str, type_str_size,
|
||||
menu_label, label, type);
|
||||
#endif
|
||||
}
|
||||
else if (!strcmp(label, "input_bind_device_id"))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user