Reimplement video_shader_get_type_from_ext

This commit is contained in:
twinaphex 2019-03-13 20:31:57 +01:00
parent 4c29f3102f
commit 57e11a10e7
3 changed files with 39 additions and 136 deletions

View File

@ -254,9 +254,6 @@ bool command_set_shader(const char *arg)
bool is_preset = false;
enum rarch_shader_type type = video_shader_get_type_from_ext(
path_get_extension(arg), &is_preset);
#ifdef HAVE_MENU
struct video_shader *shader = menu_shader_get();
#endif
if (type == RARCH_SHADER_NONE)
return false;
@ -269,7 +266,7 @@ bool command_set_shader(const char *arg)
retroarch_set_shader_preset(arg);
#ifdef HAVE_MENU
return menu_shader_manager_set_preset(shader, type, arg);
return menu_shader_manager_set_preset(menu_shader_get(), type, arg);
#else
return true;
#endif

View File

@ -1152,147 +1152,54 @@ bool video_shader_any_supported(void)
return false;
}
enum rarch_shader_type video_shader_get_type_from_ext(
const char *ext, bool *is_preset)
enum rarch_shader_type video_shader_get_type_from_ext(const char *ext,
bool *is_preset)
{
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_case_insensitive(ext, "cg")
)
{
switch (api)
{
case GFX_CTX_DIRECT3D9_API:
return RARCH_SHADER_CG;
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
{
struct retro_hw_render_callback *hwr =
video_driver_get_hw_context();
if (hwr)
{
switch (hwr->context_type)
{
case RETRO_HW_CONTEXT_OPENGLES2:
case RETRO_HW_CONTEXT_OPENGL_CORE:
case RETRO_HW_CONTEXT_OPENGLES3:
return RARCH_SHADER_NONE;
default:
break;
}
}
}
return RARCH_SHADER_CG;
default:
break;
}
}
if (
string_is_equal_case_insensitive(ext, "cgp")
)
{
*is_preset = true;
switch (api)
{
case GFX_CTX_DIRECT3D9_API:
return RARCH_SHADER_CG;
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
{
struct retro_hw_render_callback *hwr =
video_driver_get_hw_context();
if (hwr)
{
switch (hwr->context_type)
{
case RETRO_HW_CONTEXT_OPENGLES2:
case RETRO_HW_CONTEXT_OPENGL_CORE:
case RETRO_HW_CONTEXT_OPENGLES3:
return RARCH_SHADER_NONE;
default:
break;
}
}
}
return RARCH_SHADER_CG;
default:
break;
}
}
if (
string_is_equal_case_insensitive(ext, "glsl")
)
{
switch (api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
return RARCH_SHADER_GLSL;
default:
break;
}
}
if (
string_is_equal_case_insensitive(ext, "glslp")
)
{
*is_preset = true;
switch (api)
{
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
return RARCH_SHADER_GLSL;
default:
break;
}
}
if (
string_is_equal_case_insensitive(ext, "slang")
)
{
switch (api)
{
case GFX_CTX_DIRECT3D10_API:
case GFX_CTX_DIRECT3D11_API:
case GFX_CTX_DIRECT3D12_API:
case GFX_CTX_GX2_API:
case GFX_CTX_VULKAN_API:
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_METAL_API:
return RARCH_SHADER_SLANG;
default:
break;
}
}
if (
string_is_equal_case_insensitive(ext, "cgp") ||
string_is_equal_case_insensitive(ext, "glslp") ||
string_is_equal_case_insensitive(ext, "slangp")
)
{
)
*is_preset = true;
else
*is_preset = false;
switch (api)
{
gfx_ctx_flags_t flags;
if (string_is_equal_case_insensitive(ext, "cgp") ||
string_is_equal_case_insensitive(ext, "cg")
)
{
case GFX_CTX_DIRECT3D10_API:
case GFX_CTX_DIRECT3D11_API:
case GFX_CTX_DIRECT3D12_API:
case GFX_CTX_GX2_API:
case GFX_CTX_VULKAN_API:
case GFX_CTX_OPENGL_API:
case GFX_CTX_OPENGL_ES_API:
case GFX_CTX_METAL_API:
if (video_driver_get_all_flags(&flags, GFX_CTX_FLAGS_SHADERS_CG))
return RARCH_SHADER_CG;
}
}
{
gfx_ctx_flags_t flags;
if (string_is_equal_case_insensitive(ext, "glslp") ||
string_is_equal_case_insensitive(ext, "glsl")
)
{
if (video_driver_get_all_flags(&flags, GFX_CTX_FLAGS_SHADERS_GLSL))
return RARCH_SHADER_GLSL;
}
}
{
gfx_ctx_flags_t flags;
if (string_is_equal_case_insensitive(ext, "slangp") ||
string_is_equal_case_insensitive(ext, "slang")
)
{
if (video_driver_get_all_flags(&flags, GFX_CTX_FLAGS_SHADERS_SLANG))
return RARCH_SHADER_SLANG;
default:
break;
}
}
@ -1313,8 +1220,7 @@ enum rarch_shader_type video_shader_get_type_from_ext(
enum rarch_shader_type video_shader_parse_type(const char *path,
enum rarch_shader_type fallback)
{
bool is_preset = false;
bool is_preset = false;
if (!path)
return fallback;
return video_shader_get_type_from_ext(path_get_extension(path),

View File

@ -241,8 +241,8 @@ bool video_shader_resolve_parameters(config_file_t *conf,
enum rarch_shader_type video_shader_parse_type(const char *path,
enum rarch_shader_type fallback);
enum rarch_shader_type video_shader_get_type_from_ext(
const char *ext, bool *is_preset);
enum rarch_shader_type video_shader_get_type_from_ext(const char *ext,
bool *is_preset);
bool video_shader_is_supported(enum rarch_shader_type type);