[gtk+/wip/ebassi/legacy-gl: 3/5] gl: Use older GLSL shaders with legacy contexts



commit 99650ff2ae1eb6c65769cc3809347695bf5e6be2
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Oct 6 19:55:43 2015 +0100

    gl: Use older GLSL shaders with legacy contexts
    
    If we're using modern GLSL, then we should stop using deprecated
    modifiers, like 'varying' and 'attribute', as well as deprecated global
    variables, like 'gl_FragColor'.
    
    On the other hand, with legacy contexts we should be using older GLSL
    shaders, to maximize compatibility.

 gdk/gdkgl.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 54 insertions(+), 5 deletions(-)
---
diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c
index 85ce63d..061b329 100644
--- a/gdk/gdkgl.c
+++ b/gdk/gdkgl.c
@@ -147,9 +147,27 @@ bind_vao (GdkGLContextPaintData *paint_data)
 static void
 use_texture_2d_program (GdkGLContextPaintData *paint_data)
 {
-  static const char *vertex_shader_code =
+  static const char *vertex_shader_code_150 =
     "#version 150\n"
     "uniform sampler2D map;"
+    "in vec2 position;\n"
+    "in vec2 uv;\n"
+    "out vec2 vUv;\n"
+    "void main() {\n"
+    "  gl_Position = vec4(position, 0, 1);\n"
+    "  vUv = uv;\n"
+    "}\n";
+  static const char *fragment_shader_code_150 =
+    "#version 150\n"
+    "in vec2 vUv;\n"
+    "out vec4 vertexColor;\n"
+    "uniform sampler2D map;\n"
+    "void main() {\n"
+    "  vertexColor = texture2D (map, vUv);\n"
+    "}\n";
+  static const char *vertex_shader_code_130 =
+    "#version 130\n"
+    "uniform sampler2D map;"
     "attribute vec2 position;\n"
     "attribute vec2 uv;\n"
     "varying vec2 vUv;\n"
@@ -157,14 +175,21 @@ use_texture_2d_program (GdkGLContextPaintData *paint_data)
     "  gl_Position = vec4(position, 0, 1);\n"
     "  vUv = uv;\n"
     "}\n";
-  static const char *fragment_shader_code =
-    "#version 150\n"
+  static const char *fragment_shader_code_130 =
+    "#version 130\n"
     "varying vec2 vUv;\n"
     "uniform sampler2D map;\n"
     "void main() {\n"
     "  gl_FragColor = texture2D (map, vUv);\n"
     "}\n";
 
+  const char *vertex_shader_code = paint_data->is_legacy
+                                 ? vertex_shader_code_130
+                                 : vertex_shader_code_150;
+  const char *fragment_shader_code = paint_data->is_legacy
+                                   ? fragment_shader_code_130
+                                   : fragment_shader_code_150;
+
   if (paint_data->texture_2d_quad_program.program == 0)
     make_program (&paint_data->texture_2d_quad_program, vertex_shader_code, fragment_shader_code);
 
@@ -178,7 +203,7 @@ use_texture_2d_program (GdkGLContextPaintData *paint_data)
 static void
 use_texture_rect_program (GdkGLContextPaintData *paint_data)
 {
-  static const char *vertex_shader_code =
+  static const char *vertex_shader_code_150 =
     "#version 150\n"
     "uniform sampler2DRect map;"
     "attribute vec2 position;\n"
@@ -188,13 +213,37 @@ use_texture_rect_program (GdkGLContextPaintData *paint_data)
     "  gl_Position = vec4(position, 0, 1);\n"
     "  vUv = uv;\n"
     "}\n";
-  static const char *fragment_shader_code =
+  static const char *fragment_shader_code_150 =
     "#version 150\n"
     "varying vec2 vUv;\n"
     "uniform sampler2DRect map;\n"
     "void main() {\n"
     "  gl_FragColor = texture2DRect (map, vUv);\n"
     "}\n";
+  static const char *vertex_shader_code_130 =
+    "#version 130\n"
+    "uniform sampler2DRect map;"
+    "attribute vec2 position;\n"
+    "attribute vec2 uv;\n"
+    "varying vec2 vUv;\n"
+    "void main() {\n"
+    "  gl_Position = vec4(position, 0, 1);\n"
+    "  vUv = uv;\n"
+    "}\n";
+  static const char *fragment_shader_code_130 =
+    "#version 130\n"
+    "varying vec2 vUv;\n"
+    "uniform sampler2DRect map;\n"
+    "void main() {\n"
+    "  gl_FragColor = texture2DRect (map, vUv);\n"
+    "}\n";
+
+  const char *vertex_shader_code = paint_data->is_legacy
+                                 ? vertex_shader_code_130
+                                 : vertex_shader_code_150;
+  const char *fragment_shader_code = paint_data->is_legacy
+                                   ? fragment_shader_code_130
+                                   : fragment_shader_code_150;
 
   if (paint_data->texture_rect_quad_program.program == 0)
     make_program (&paint_data->texture_rect_quad_program, vertex_shader_code, fragment_shader_code);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]