static int action_ok_shader_preset_load(const char *path, const char *label, unsigned type, size_t idx) { const char *menu_path = NULL; char shader_path[PATH_MAX_LENGTH]; menu_handle_t *menu = menu_driver_get_ptr(); if (!menu) return -1; (void)shader_path; (void)menu_path; #ifdef HAVE_SHADER_MANAGER menu_list_get_last_stack(menu->menu_list, &menu_path, NULL, NULL); fill_pathname_join(shader_path, menu_path, path, sizeof(shader_path)); menu_shader_manager_set_preset(menu->shader, video_shader_parse_type(shader_path, RARCH_SHADER_NONE), shader_path); menu_list_flush_stack_by_needle(menu->menu_list, "shader_options"); return 0; #else return -1; #endif }
/** * menu_shader_manager_apply_changes: * * Apply shader state changes. **/ void menu_shader_manager_apply_changes(void) { #ifdef HAVE_SHADER_MANAGER menu_handle_t *menu = menu_driver_get_ptr(); unsigned shader_type = menu_shader_manager_get_type(menu->shader); if (menu->shader->passes && shader_type != RARCH_SHADER_NONE) { menu_shader_manager_save_preset(NULL, true); return; } /* Fall-back */ #if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL) shader_type = video_shader_parse_type("", DEFAULT_SHADER_TYPE); #endif if (shader_type == RARCH_SHADER_NONE) { #if defined(HAVE_GLSL) shader_type = RARCH_SHADER_GLSL; #elif defined(HAVE_CG) || defined(HAVE_HLSL) shader_type = RARCH_SHADER_CG; #endif } menu_shader_manager_set_preset(NULL, shader_type, NULL); #endif }
/** * menu_shader_manager_apply_changes: * * Apply shader state changes. **/ void menu_shader_manager_apply_changes(void) { #ifdef HAVE_SHADER_MANAGER unsigned shader_type; struct video_shader *shader = menu_shader_get(); if (!shader) return; shader_type = menu_shader_manager_get_type(shader); if (shader->passes && shader_type != RARCH_SHADER_NONE) { menu_shader_manager_save_preset(NULL, true, false); return; } /* Fall-back */ #if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL) shader_type = video_shader_parse_type("", DEFAULT_SHADER_TYPE); #endif if (shader_type == RARCH_SHADER_NONE) { #if defined(HAVE_GLSL) shader_type = RARCH_SHADER_GLSL; #elif defined(HAVE_CG) || defined(HAVE_HLSL) shader_type = RARCH_SHADER_CG; #elif defined(HAVE_VULKAN) shader_type = RARCH_SHADER_SLANG; #endif } menu_shader_manager_set_preset(NULL, shader_type, NULL); #endif }
void ShaderParamsDialog::onShaderLoadPresetClicked() { QString path; QString filter; QByteArray pathArray; struct video_shader *menu_shader = NULL; struct video_shader *video_shader = NULL; const char *pathData = NULL; settings_t *settings = config_get_ptr(); enum rarch_shader_type type = RARCH_SHADER_NONE; bool is_preset = false; if (!settings) return; getShaders(&menu_shader, &video_shader); if (!menu_shader) return; filter = "Shader Preset ("; /* NOTE: Maybe we should have a way to get a list of all shader types instead of hard-coding this? */ if (video_shader_is_supported(RARCH_SHADER_CG) && video_shader_get_type_from_ext(file_path_str(FILE_PATH_CGP_EXTENSION), &is_preset) != RARCH_SHADER_NONE) filter += QLatin1Literal("*") + file_path_str(FILE_PATH_CGP_EXTENSION); if (video_shader_is_supported(RARCH_SHADER_GLSL) && video_shader_get_type_from_ext(file_path_str(FILE_PATH_GLSLP_EXTENSION), &is_preset) != RARCH_SHADER_NONE) filter += QLatin1Literal(" *") + file_path_str(FILE_PATH_GLSLP_EXTENSION); if (video_shader_is_supported(RARCH_SHADER_SLANG) && video_shader_get_type_from_ext(file_path_str(FILE_PATH_SLANGP_EXTENSION), &is_preset) != RARCH_SHADER_NONE) filter += QLatin1Literal(" *") + file_path_str(FILE_PATH_SLANGP_EXTENSION); filter += ")"; path = QFileDialog::getOpenFileName(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET), settings->paths.directory_video_shader, filter); if (path.isEmpty()) return; pathArray = path.toUtf8(); pathData = pathArray.constData(); type = video_shader_parse_type(pathData, RARCH_SHADER_NONE); menu_shader_manager_set_preset(menu_shader, type, pathData); }
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"); }
/** * menu_shader_manager_save_preset: * @basename : basename of preset * @apply : immediately set preset after saving * * Save a shader preset to disk. **/ void menu_shader_manager_save_preset( const char *basename, bool apply) { #ifdef HAVE_SHADER_MANAGER char buffer[PATH_MAX_LENGTH], config_directory[PATH_MAX_LENGTH], preset_path[PATH_MAX_LENGTH]; unsigned d, type = RARCH_SHADER_NONE; const char *dirs[3] = {0}; config_file_t *conf = NULL; bool ret = false; global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr(); if (!menu) { RARCH_ERR("Cannot save shader preset, menu handle is not initialized.\n"); return; } type = menu_shader_manager_get_type(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")) { switch (type) { case RARCH_SHADER_GLSL: strlcat(buffer, ".glslp", sizeof(buffer)); break; case RARCH_SHADER_CG: strlcat(buffer, ".cgp", sizeof(buffer)); break; } } } else { const char *conf_path = (type == RARCH_SHADER_GLSL) ? menu->default_glslp : menu->default_cgp; strlcpy(buffer, conf_path, sizeof(buffer)); } if (*global->path.config) fill_pathname_basedir(config_directory, global->path.config, sizeof(config_directory)); dirs[0] = settings->video.shader_dir; dirs[1] = settings->menu_config_directory; dirs[2] = config_directory; if (!(conf = (config_file_t*)config_file_new(NULL))) return; video_shader_write_conf_cgp(conf, menu->shader); for (d = 0; d < ARRAY_SIZE(dirs); d++) { if (!*dirs[d]) continue; fill_pathname_join(preset_path, dirs[d], buffer, sizeof(preset_path)); if (config_file_write(conf, preset_path)) { RARCH_LOG("Saved shader preset to %s.\n", preset_path); if (apply) menu_shader_manager_set_preset(NULL, type, preset_path); ret = true; break; } else RARCH_LOG("Failed writing shader preset to %s.\n", preset_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 }
/** * menu_shader_manager_save_preset: * @basename : basename of preset * @apply : immediately set preset after saving * * Save a shader preset to disk. **/ bool menu_shader_manager_save_preset( const char *basename, bool apply, bool fullpath) { #ifdef HAVE_SHADER_MANAGER char buffer[PATH_MAX_LENGTH]; char config_directory[PATH_MAX_LENGTH]; char preset_path[PATH_MAX_LENGTH]; unsigned d, type = RARCH_SHADER_NONE; const char *dirs[3] = {0}; config_file_t *conf = NULL; bool ret = false; struct video_shader *shader = NULL; settings_t *settings = config_get_ptr(); menu_handle_t *menu = NULL; buffer[0] = config_directory[0] = '\0'; preset_path[0] = '\0'; if (!menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu)) { RARCH_ERR("Cannot save shader preset.\n"); return false; } menu_driver_ctl(RARCH_MENU_CTL_SHADER_GET, &shader); if (!shader) return false; type = menu_shader_manager_get_type(shader); if (type == RARCH_SHADER_NONE) return false; *config_directory = '\0'; if (basename) { strlcpy(buffer, basename, sizeof(buffer)); /* Append extension automatically as appropriate. */ if ( !strstr(basename, file_path_str(FILE_PATH_CGP_EXTENSION)) && !strstr(basename, file_path_str(FILE_PATH_GLSLP_EXTENSION)) && !strstr(basename, file_path_str(FILE_PATH_SLANGP_EXTENSION))) { switch (type) { case RARCH_SHADER_GLSL: strlcat(buffer, file_path_str(FILE_PATH_GLSLP_EXTENSION), sizeof(buffer)); break; case RARCH_SHADER_SLANG: strlcat(buffer, file_path_str(FILE_PATH_SLANGP_EXTENSION), sizeof(buffer)); break; case RARCH_SHADER_CG: strlcat(buffer, file_path_str(FILE_PATH_CGP_EXTENSION), sizeof(buffer)); break; } } } else { const char *conf_path = NULL; switch (type) { case RARCH_SHADER_GLSL: conf_path = default_glslp; break; case RARCH_SHADER_SLANG: conf_path = default_slangp; break; default: case RARCH_SHADER_CG: conf_path = default_cgp; break; } if (!string_is_empty(conf_path)) strlcpy(buffer, conf_path, sizeof(buffer)); } if (!path_is_empty(RARCH_PATH_CONFIG)) fill_pathname_basedir( config_directory, path_get(RARCH_PATH_CONFIG), sizeof(config_directory)); if (!fullpath) { dirs[0] = settings->directory.video_shader; dirs[1] = settings->directory.menu_config; dirs[2] = config_directory; } if (!(conf = (config_file_t*)config_file_new(NULL))) return false; video_shader_write_conf_cgp(conf, shader); if (!fullpath) { for (d = 0; d < ARRAY_SIZE(dirs); d++) { if (!*dirs[d]) continue; fill_pathname_join(preset_path, dirs[d], buffer, sizeof(preset_path)); if (config_file_write(conf, preset_path)) { RARCH_LOG("Saved shader preset to %s.\n", preset_path); if (apply) menu_shader_manager_set_preset(NULL, type, preset_path); ret = true; break; } else RARCH_LOG("Failed writing shader preset to %s.\n", preset_path); } } else { if (!string_is_empty(basename)) strlcpy(preset_path, buffer, sizeof(preset_path)); if (config_file_write(conf, preset_path)) { RARCH_LOG("Saved shader preset to %s.\n", preset_path); if (apply) menu_shader_manager_set_preset(NULL, type, preset_path); ret = true; } else RARCH_LOG("Failed writing shader preset to %s.\n", preset_path); } config_file_free(conf); if (ret) return true; RARCH_ERR("Failed to save shader preset. Make sure config directory" " and/or shader dir are writable.\n"); #endif return false; }
static int menu_action_ok(const char *menu_path, const char *menu_label, unsigned menu_type) { const char *label = NULL; const char *path = NULL; unsigned type = 0; rarch_setting_t *setting_data = (rarch_setting_t *)driver.menu->list_settings; rarch_setting_t *setting = (rarch_setting_t*) setting_data_find_setting(setting_data, menu_label); (void)hack_shader_pass; if (file_list_get_size(driver.menu->selection_buf) == 0) return 0; file_list_get_at_offset(driver.menu->selection_buf, driver.menu->selection_ptr, &path, &label, &type); #if 0 RARCH_LOG("menu label: %s\n", menu_label); RARCH_LOG("type : %d\n", type == MENU_FILE_USE_DIRECTORY); RARCH_LOG("type id : %d\n", type); #endif while (true) { switch (type) { case MENU_FILE_PLAYLIST_ENTRY: rarch_playlist_load_content(g_defaults.history, driver.menu->selection_ptr); menu_flush_stack_type(driver.menu->menu_stack, MENU_SETTINGS); return -1; #ifdef HAVE_COMPRESSION case MENU_FILE_IN_CARCHIVE: #endif case MENU_FILE_PLAIN: if (!strcmp(menu_label, "detect_core_list")) { int ret = rarch_defer_core(g_extern.core_info, menu_path, path, driver.menu->deferred_path, sizeof(driver.menu->deferred_path)); if (ret == -1) { rarch_main_command(RARCH_CMD_LOAD_CORE); menu_common_load_content(); return -1; } else if (ret == 0) menu_entries_push(driver.menu->menu_stack, g_settings.libretro_directory, "deferred_core_list", 0, driver.menu->selection_ptr); } else if ((setting && setting->type == ST_PATH)) { menu_action_setting_set_current_string_path(setting, menu_path, path); menu_entries_pop_stack(driver.menu->menu_stack, setting->name); } else if (!strcmp(menu_label, "disk_image_append")) { char image[PATH_MAX]; fill_pathname_join(image, menu_path, path, sizeof(image)); rarch_disk_control_append_image(image); rarch_main_command(RARCH_CMD_RESUME); menu_flush_stack_type(driver.menu->menu_stack,MENU_SETTINGS); return -1; } else { if (type == MENU_FILE_IN_CARCHIVE) { fill_pathname_join_delim(g_extern.fullpath, menu_path, path, '#',sizeof(g_extern.fullpath)); } else { fill_pathname_join(g_extern.fullpath, menu_path, path, sizeof(g_extern.fullpath)); } menu_common_load_content(); rarch_main_command(RARCH_CMD_LOAD_CONTENT_PERSIST); menu_flush_stack_type(driver.menu->menu_stack,MENU_SETTINGS); driver.menu->msg_force = true; return -1; } return 0; case MENU_FILE_CONFIG: { char config[PATH_MAX]; fill_pathname_join(config, menu_path, path, sizeof(config)); menu_flush_stack_type(driver.menu->menu_stack,MENU_SETTINGS); driver.menu->msg_force = true; if (rarch_replace_config(config)) { menu_clear_navigation(driver.menu); return -1; } } return 0; case MENU_FILE_FONT: case MENU_FILE_OVERLAY: case MENU_FILE_AUDIOFILTER: case MENU_FILE_VIDEOFILTER: menu_action_setting_set_current_string_path(setting, menu_path, path); menu_entries_pop_stack(driver.menu->menu_stack, setting->name); return 0; case MENU_FILE_SHADER_PRESET: #ifdef HAVE_SHADER_MANAGER { char shader_path[PATH_MAX]; fill_pathname_join(shader_path, menu_path, path, sizeof(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 return 0; case MENU_FILE_SHADER: #ifdef HAVE_SHADER_MANAGER fill_pathname_join(driver.menu->shader->pass[hack_shader_pass].source.path, menu_path, path, sizeof(driver.menu->shader->pass[hack_shader_pass].source.path)); /* This will reset any changed parameters. */ gfx_shader_resolve_parameters(NULL, driver.menu->shader); menu_flush_stack_label(driver.menu->menu_stack, "Shader Options"); #endif return 0; case MENU_FILE_CORE: if (!strcmp(menu_label, "deferred_core_list")) { strlcpy(g_settings.libretro, path, sizeof(g_settings.libretro)); strlcpy(g_extern.fullpath, driver.menu->deferred_path, sizeof(g_extern.fullpath)); menu_common_load_content(); return -1; } else if (!strcmp(menu_label, "core_list")) { fill_pathname_join(g_settings.libretro, menu_path, path, sizeof(g_settings.libretro)); rarch_main_command(RARCH_CMD_LOAD_CORE); menu_flush_stack_type(driver.menu->menu_stack,MENU_SETTINGS); #if defined(HAVE_DYNAMIC) /* No content needed for this core, load core immediately. */ if (driver.menu->load_no_content) { *g_extern.fullpath = '\0'; menu_common_load_content(); return -1; } /* Core selection on non-console just updates directory listing. * Will take effect on new content load. */ #elif defined(RARCH_CONSOLE) rarch_main_command(RARCH_CMD_RESTART_RETROARCH); return -1; #endif } return 0; case MENU_FILE_USE_DIRECTORY: if (setting && setting->type == ST_DIR) { menu_action_setting_set_current_string(setting, menu_path); menu_entries_pop_stack(driver.menu->menu_stack, setting->name); } return 0; case MENU_FILE_DIRECTORY: case MENU_FILE_CARCHIVE: { char cat_path[PATH_MAX]; if (type == MENU_FILE_CARCHIVE && !strcmp(menu_label, "detect_core_list")) { file_list_push(driver.menu->menu_stack, path, "load_open_zip", 0, driver.menu->selection_ptr); return 0; } fill_pathname_join(cat_path, menu_path, path, sizeof(cat_path)); menu_entries_push(driver.menu->menu_stack, cat_path, menu_label, type, driver.menu->selection_ptr); } return 0; } break; } if (menu_parse_check(label, type) == 0) { char cat_path[PATH_MAX]; fill_pathname_join(cat_path, menu_path, path, sizeof(cat_path)); menu_entries_push(driver.menu->menu_stack, cat_path, menu_label, type, driver.menu->selection_ptr); } return 0; }