diff --git a/config.def.h b/config.def.h index ce19fdc890..c6e054da2a 100644 --- a/config.def.h +++ b/config.def.h @@ -176,18 +176,6 @@ enum #define DEFAULT_ASPECT_RATIO -1.0f #endif -#if defined(_XBOX360) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_HLSL -#elif defined(__PSL1GHT__) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL -#elif defined(__CELLOS_LV2__) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_CG -#elif defined(ANDROID) -#define DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL -#else -#define DEFAULT_SHADER_TYPE RARCH_SHADER_AUTO -#endif - #ifdef HAVE_DYNAMIC #ifdef _WIN32 #define EXT_EXECUTABLES "dll|DLL" @@ -260,6 +248,9 @@ static const bool video_smooth = true; // On resize and fullscreen, rendering area will stay 4:3 static const bool force_aspect = true; +// Enable use of shaders. +static const bool shader_enable = false; + // Only scale in integer steps. // The base size depends on system-reported geometry and aspect ratio. // If video_force_aspect is not set, X/Y will be integer scaled independently. diff --git a/driver.h b/driver.h index bebb720152..46578e1906 100644 --- a/driver.h +++ b/driver.h @@ -143,10 +143,21 @@ enum rarch_shader_type RARCH_SHADER_CG, RARCH_SHADER_HLSL, RARCH_SHADER_GLSL, - RARCH_SHADER_AUTO, RARCH_SHADER_NONE }; +#if defined(_XBOX360) +#define DEFAULT_SHADER_TYPE RARCH_SHADER_HLSL +#elif defined(__PSL1GHT__) +#define DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL +#elif defined(__CELLOS_LV2__) +#define DEFAULT_SHADER_TYPE RARCH_SHADER_CG +#elif defined(HAVE_OPENGLES2) +#define DEFAULT_SHADER_TYPE RARCH_SHADER_GLSL +#else +#define DEFAULT_SHADER_TYPE RARCH_SHADER_NONE +#endif + enum rarch_shader_index { RARCH_SHADER_INDEX_MULTIPASS = 0, diff --git a/general.h b/general.h index 3b92ae01a8..7299e53069 100644 --- a/general.h +++ b/general.h @@ -176,10 +176,11 @@ struct settings bool aspect_ratio_auto; bool scale_integer; unsigned aspect_ratio_idx; - char cg_shader_path[PATH_MAX]; - char xml_shader_path[PATH_MAX]; + + char shader_path[PATH_MAX]; + bool shader_enable; + char filter_path[PATH_MAX]; - enum rarch_shader_type shader_type; float refresh_rate; bool threaded; diff --git a/gfx/gl.c b/gfx/gl.c index 327ceebe2a..bfda3da8b1 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -245,63 +245,33 @@ static inline bool load_gl_proc_win32(gl_t *gl) ////////////////// Shaders -#ifdef HAVE_OPENGLES2 -static bool gl_shader_init(void *data) // We always need a shader alive in GLES2. -{ - gl_t *gl = (gl_t*)data; - const char *shader_path = NULL; - if ((g_settings.video.shader_type == RARCH_SHADER_AUTO || g_settings.video.shader_type == RARCH_SHADER_GLSL) - && *g_settings.video.xml_shader_path) - shader_path = g_settings.video.xml_shader_path; - - gl->shader = &gl_glsl_backend; - return gl->shader->init(shader_path); -} -#else static bool gl_shader_init(void *data) { gl_t *gl = (gl_t*)data; const gl_shader_backend_t *backend = NULL; - const char *shader_path = NULL; - switch (g_settings.video.shader_type) +#if DEFAULT_SHADER == RARCH_SHADER_NONE + if (!g_settings.video.shader_enable) + return true; +#endif + + const char *shader_path = *g_settings.video.shader_path ? g_settings.video.shader_path : NULL; + enum rarch_shader_type type = gfx_shader_parse_type(g_settings.video.shader_path, DEFAULT_SHADER_TYPE); + + if (type == RARCH_SHADER_NONE) + return true; + + switch (type) { - case RARCH_SHADER_AUTO: - { - if (*g_settings.video.cg_shader_path && *g_settings.video.xml_shader_path) - RARCH_WARN("Both Cg and GLSL XML shader are defined in config file. Cg shader will be selected by default.\n"); - -#ifdef HAVE_CG - if (*g_settings.video.cg_shader_path) - { - backend = &gl_cg_backend; - shader_path = g_settings.video.cg_shader_path; - } -#endif - -#ifdef HAVE_GLSL - if (*g_settings.video.xml_shader_path) - { - backend = &gl_glsl_backend; - shader_path = g_settings.video.xml_shader_path; - } -#endif - break; - } - #ifdef HAVE_CG case RARCH_SHADER_CG: backend = &gl_cg_backend; - if (*g_settings.video.cg_shader_path) - shader_path = g_settings.video.cg_shader_path; break; #endif #ifdef HAVE_GLSL case RARCH_SHADER_GLSL: backend = &gl_glsl_backend; - if (*g_settings.video.xml_shader_path) - shader_path = g_settings.video.xml_shader_path; break; #endif @@ -315,7 +285,6 @@ static bool gl_shader_init(void *data) gl->shader = backend; return gl->shader->init(shader_path); } -#endif void gl_shader_use(void *data, unsigned index) { diff --git a/gfx/shader_parse.c b/gfx/shader_parse.c index 8c7e70270d..06621d8b55 100644 --- a/gfx/shader_parse.c +++ b/gfx/shader_parse.c @@ -16,6 +16,7 @@ #include "shader_parse.h" #include "../compat/posix_string.h" #include "../msvc/msvc_compat.h" +#include "../file.h" #include #include @@ -509,3 +510,15 @@ void gfx_shader_write_conf_cgp(config_file_t *conf, const struct gfx_shader *sha } } +enum rarch_shader_type gfx_shader_parse_type(const char *path, enum rarch_shader_type fallback) +{ + const char *ext = path_get_extension(path); + + if (strcmp(ext, "cg") == 0 || strcmp(ext, "cgp") == 0) + return RARCH_SHADER_CG; + else if (strcmp(ext, "shader") == 0) + return RARCH_SHADER_GLSL; + + return fallback; +} + diff --git a/gfx/shader_parse.h b/gfx/shader_parse.h index 09168d7460..64d19fd158 100644 --- a/gfx/shader_parse.h +++ b/gfx/shader_parse.h @@ -90,5 +90,7 @@ struct gfx_shader bool gfx_shader_read_conf_cgp(config_file_t *conf, struct gfx_shader *shader); void gfx_shader_write_conf_cgp(config_file_t *conf, const struct gfx_shader *shader); +enum rarch_shader_type gfx_shader_parse_type(const char *path, enum rarch_shader_type fallback); + #endif diff --git a/retroarch.cfg b/retroarch.cfg index 2314307df8..5229b55091 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -97,17 +97,14 @@ # Exact behavior of this option is implementation specific. # video_crop_overscan = false -# Path to Cg shader. -# video_cg_shader = "/path/to/cg/shader.cg" +# Path to shader. Shader can be either Cg, CGP (Cg preset) or XML/GLSL format if support is enabled. +# video_shader = "/path/to/shader.{cg,cgp,shader}" -# Path to GLSL XML shader. If both Cg shader path and XML shader path are defined, -# Cg shader will take priority unless overridden in video_shader_type. -# video_xml_shader = "/path/to/xml/shader.shader" +# Load video_shader on startup. +# Other shaders can still be loaded later in runtime. +# video_shader_enable = false -# Which shader type to use. Valid values are "cg", "bsnes", "none" and "auto" -# video_shader_type = auto - -# Defines a directory where XML shaders are kept. +# Defines a directory where shaders (Cg, CGP, XML) are kept for easy access. # video_shader_dir = # CPU-based filter. Path to a bSNES CPU filter (*.filter) diff --git a/settings.c b/settings.c index dca5f6c198..6bc16c24f3 100644 --- a/settings.c +++ b/settings.c @@ -170,7 +170,7 @@ void config_set_defaults(void) g_settings.video.crop_overscan = crop_overscan; g_settings.video.aspect_ratio = aspect_ratio; g_settings.video.aspect_ratio_auto = aspect_ratio_auto; // Let implementation decide if automatic, or 1:1 PAR. - g_settings.video.shader_type = DEFAULT_SHADER_TYPE; + g_settings.video.shader_enable = shader_enable; g_settings.video.allow_rotate = allow_rotate; g_settings.video.font_enable = font_enable; @@ -440,8 +440,9 @@ bool config_load_file(const char *path) CONFIG_GET_BOOL(video.aspect_ratio_auto, "video_aspect_ratio_auto"); CONFIG_GET_FLOAT(video.refresh_rate, "video_refresh_rate"); - CONFIG_GET_PATH(video.cg_shader_path, "video_cg_shader"); - CONFIG_GET_PATH(video.xml_shader_path, "video_xml_shader"); + CONFIG_GET_PATH(video.shader_path, "video_shader"); + CONFIG_GET_BOOL(video.shader_enable, "video_shader_enable"); + CONFIG_GET_BOOL(video.allow_rotate, "video_allow_rotate"); CONFIG_GET_PATH(video.font_path, "video_font_path"); @@ -597,18 +598,6 @@ bool config_load_file(const char *path) CONFIG_GET_PATH(video.filter_path, "video_filter"); #endif - if (config_get_array(conf, "video_shader_type", tmp_str, sizeof(tmp_str))) - { - if (strcmp("cg", tmp_str) == 0) - g_settings.video.shader_type = RARCH_SHADER_CG; - else if (strcmp("bsnes", tmp_str) == 0) - g_settings.video.shader_type = RARCH_SHADER_GLSL; - else if (strcmp("auto", tmp_str) == 0) - g_settings.video.shader_type = RARCH_SHADER_AUTO; - else if (strcmp("none", tmp_str) == 0) - g_settings.video.shader_type = RARCH_SHADER_NONE; - } - CONFIG_GET_PATH(video.shader_dir, "video_shader_dir"); CONFIG_GET_FLOAT(input.axis_threshold, "input_axis_threshold");