From: Steinar H. Gunderson Date: Wed, 7 Oct 2015 17:24:19 +0000 (+0200) Subject: Add separate shaders for GLSL 1.50. X-Git-Tag: 1.3.0~29 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=d4cade9004a527206e1360ae24f833a6bcf6d476;hp=5b08f06cd4547102186932ce789788e07ea8fd8c Add separate shaders for GLSL 1.50. Seemingly, Apple's drivers (in OS X) do not support GLSL 1.30 in core contexts, only 1.50. Reported by Dan Dennedy. --- diff --git a/header.150.frag b/header.150.frag new file mode 100644 index 0000000..d8a2d84 --- /dev/null +++ b/header.150.frag @@ -0,0 +1,8 @@ +#version 150 + +in vec2 tc; + +vec4 tex2D(sampler2D s, vec2 coord) +{ + return texture(s, coord); +} diff --git a/init.cpp b/init.cpp index 5b8da89..ed8172d 100644 --- a/init.cpp +++ b/init.cpp @@ -435,7 +435,16 @@ bool init_movit(const string& data_directory, MovitDebugLevel debug_level) get_glsl_version()); return false; } - movit_shader_model = MOVIT_GLSL_130; + if (get_glsl_version() < 1.50f) { + movit_shader_model = MOVIT_GLSL_130; + } else { + // Note: All of our 1.50 shaders are identical to our 1.30 shaders, + // but OS X does not support 1.30; only 1.10 (which we don't support + // anymore) and 1.50 (and then only with core contexts). So we keep + // a second set of shaders around whose only difference is the different + // #version declaration. + movit_shader_model = MOVIT_GLSL_150; + } } else { movit_shader_model = MOVIT_ESSL_300; } diff --git a/init.h b/init.h index 5cede57..7e1e130 100644 --- a/init.h +++ b/init.h @@ -75,7 +75,8 @@ extern bool movit_timer_queries_supported; enum MovitShaderModel { MOVIT_GLSL_110, // No longer in use, but kept until next ABI break in order not to change the enums. MOVIT_GLSL_130, - MOVIT_ESSL_300 + MOVIT_ESSL_300, + MOVIT_GLSL_150, }; extern MovitShaderModel movit_shader_model; diff --git a/texture1d.150.frag b/texture1d.150.frag new file mode 100644 index 0000000..8fd18a9 --- /dev/null +++ b/texture1d.150.frag @@ -0,0 +1,11 @@ +#version 150 + +uniform sampler2D tex; +in vec2 tc; + +out vec4 FragColor; + +void main() +{ + FragColor = texture(tex, tc); // Second component is irrelevant. +} diff --git a/util.cpp b/util.cpp index 3f59edf..9c077e9 100644 --- a/util.cpp +++ b/util.cpp @@ -129,6 +129,8 @@ string read_version_dependent_file(const string &base, const string &extension) { if (movit_shader_model == MOVIT_GLSL_130) { return read_file(base + ".130." + extension); + } else if (movit_shader_model == MOVIT_GLSL_150) { + return read_file(base + ".150." + extension); } else if (movit_shader_model == MOVIT_ESSL_300) { return read_file(base + ".300es." + extension); } else { diff --git a/vs.150.vert b/vs.150.vert new file mode 100644 index 0000000..4a524bc --- /dev/null +++ b/vs.150.vert @@ -0,0 +1,24 @@ +#version 150 + +in vec2 position; +in vec2 texcoord; +out vec2 tc; + +// Will be overridden by compile_glsl_program() if needed. +// (It cannot just be prepended, as #version must be before everything.) +#define FLIP_ORIGIN 0 + +void main() +{ + // The result of glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0) is: + // + // 2.000 0.000 0.000 -1.000 + // 0.000 2.000 0.000 -1.000 + // 0.000 0.000 -2.000 -1.000 + // 0.000 0.000 0.000 1.000 + gl_Position = vec4(2.0 * position.x - 1.0, 2.0 * position.y - 1.0, -1.0, 1.0); + tc = texcoord; +#if FLIP_ORIGIN + tc.y = 1.0f - tc.y; +#endif +}