]> git.sesse.net Git - movit/commitdiff
Add separate shaders for GLSL 1.50.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 7 Oct 2015 17:24:19 +0000 (19:24 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 7 Oct 2015 17:24:19 +0000 (19:24 +0200)
Seemingly, Apple's drivers (in OS X) do not support GLSL 1.30 in
core contexts, only 1.50. Reported by Dan Dennedy.

header.150.frag [new file with mode: 0644]
init.cpp
init.h
texture1d.150.frag [new file with mode: 0644]
util.cpp
vs.150.vert [new file with mode: 0644]

diff --git a/header.150.frag b/header.150.frag
new file mode 100644 (file)
index 0000000..d8a2d84
--- /dev/null
@@ -0,0 +1,8 @@
+#version 150
+
+in vec2 tc;
+
+vec4 tex2D(sampler2D s, vec2 coord)
+{
+       return texture(s, coord);
+}
index 5b8da897271e8cf6b282cf153759bb8666e47a53..ed8172dcaefa25059c64566cc4ebbe59a6657d72 100644 (file)
--- 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;
                }
                                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;
        }
        } else {
                movit_shader_model = MOVIT_ESSL_300;
        }
diff --git a/init.h b/init.h
index 5cede57ffb909541c0493ed8479ff36798d7c58a..7e1e13028b35bd6a0069c45828df88f7133b535f 100644 (file)
--- 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,
 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;
 
 };
 extern MovitShaderModel movit_shader_model;
 
diff --git a/texture1d.150.frag b/texture1d.150.frag
new file mode 100644 (file)
index 0000000..8fd18a9
--- /dev/null
@@ -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.
+}
index 3f59edfbce359e752eaa7786fdd6e10636052c36..9c077e92909d639f203299b3162f805c8bd975e3 100644 (file)
--- 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);
 {
        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 {
        } 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 (file)
index 0000000..4a524bc
--- /dev/null
@@ -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
+}