Qt: limit shader preset/pass selection to the appropriate extensions

This commit is contained in:
Brad Parker 2018-08-20 20:26:50 -04:00
parent e9c68597ff
commit 4d09ddde1c
2 changed files with 54 additions and 4 deletions

View File

@ -1136,11 +1136,16 @@ enum rarch_shader_type video_shader_get_type_from_ext(
{
enum gfx_ctx_api api = video_context_driver_get_api();
if (string_is_empty(ext))
return RARCH_SHADER_NONE;
if (strlen(ext) > 1 && ext[0] == '.')
ext++;
*is_preset = false;
if (
string_is_equal(ext, "cg") ||
string_is_equal(ext, "CG")
string_is_equal_case_insensitive(ext, "cg")
)
{
switch (api)

View File

@ -27,6 +27,7 @@ extern "C" {
#include "../../../configuration.h"
#include "../../../retroarch.h"
#include "../../../paths.h"
#include "../../../file_path_special.h"
#ifdef HAVE_MENU
#include "../../../menu/menu_shader.h"
#endif
@ -384,12 +385,14 @@ void ShaderParamsDialog::onShaderLoadPresetClicked()
{
#ifdef HAVE_MENU
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;
@ -399,7 +402,27 @@ void ShaderParamsDialog::onShaderLoadPresetClicked()
if (!menu_shader)
return;
path = QFileDialog::getOpenFileName(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET), settings->paths.directory_video_shader);
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;
@ -417,12 +440,14 @@ void ShaderParamsDialog::onShaderAddPassClicked()
{
#ifdef HAVE_MENU
QString path;
QString filter;
QByteArray pathArray;
struct video_shader *menu_shader = NULL;
struct video_shader *video_shader = NULL;
struct video_shader_pass *shader_pass = NULL;
const char *pathData = NULL;
settings_t *settings = config_get_ptr();
bool is_preset = false;
if (!settings)
return;
@ -432,7 +457,27 @@ void ShaderParamsDialog::onShaderAddPassClicked()
if (!menu_shader)
return;
path = QFileDialog::getOpenFileName(this, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_VIDEO_SHADER_PRESET), settings->paths.directory_video_shader);
filter = "Shader (";
/* 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(".cg", &is_preset)
!= RARCH_SHADER_NONE)
filter += QLatin1Literal("*.cg");
if (video_shader_is_supported(RARCH_SHADER_GLSL) &&
video_shader_get_type_from_ext(".glsl", &is_preset)
!= RARCH_SHADER_NONE)
filter += QLatin1Literal(" *.glsl");
if (video_shader_is_supported(RARCH_SHADER_SLANG) &&
video_shader_get_type_from_ext(".slang", &is_preset)
!= RARCH_SHADER_NONE)
filter += QLatin1Literal(" *.slang");
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;