[gtk+/wip/ebassi/gles: 3/3] tests: Add GLES shaders to testglarea



commit 68f7081a212b5e67672c43696d4467dae2dbaf8e
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Fri Apr 22 13:53:16 2016 +0100

    tests: Add GLES shaders to testglarea
    
    Check if the GdkGLContext is using ES, and load the appropriate shaders
    in that case.

 tests/testglarea.c |   31 ++++++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/tests/testglarea.c b/tests/testglarea.c
index 764e231..b8e9be0 100644
--- a/tests/testglarea.c
+++ b/tests/testglarea.c
@@ -80,6 +80,19 @@ create_shader (int type, const char *src)
   return shader;
 }
 
+static const char *vertex_shader_code_gles =
+"attribute vec4 position;\n" \
+"uniform mat4 mvp;\n" \
+"void main() {\n" \
+"  gl_Position = mvp * position;\n" \
+"}";
+
+static const char *fragment_shader_code_gles =
+"void main() {\n" \
+"  float lerpVal = gl_FragCoord.y / 400.0;\n" \
+"  gl_FragColor = mix(vec4(1.0, 0.85, 0.35, 1.0), vec4(0.2, 0.2, 0.2, 1.0), lerpVal);\n" \
+"}";
+
 static const char *vertex_shader_code_330 =
 "#version 330\n" \
 "\n" \
@@ -243,15 +256,23 @@ realize (GtkWidget *widget)
     return;
 
   context = gtk_gl_area_get_context (GTK_GL_AREA (widget));
-  if (!gdk_gl_context_is_legacy (context))
+  if (gdk_gl_context_get_use_es (context))
     {
-      vertex = vertex_shader_code_330;
-      fragment = fragment_shader_code_330;
+      vertex = vertex_shader_code_gles;
+      fragment = fragment_shader_code_gles;
     }
   else
     {
-      vertex = vertex_shader_code_legacy;
-      fragment = fragment_shader_code_legacy;
+      if (!gdk_gl_context_is_legacy (context))
+        {
+          vertex = vertex_shader_code_330;
+          fragment = fragment_shader_code_330;
+        }
+      else
+        {
+          vertex = vertex_shader_code_legacy;
+          fragment = fragment_shader_code_legacy;
+        }
     }
 
   init_buffers (&position_buffer, NULL);


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