[gtk+/wip/ebassi/gsk-renderer: 10/58] gsk: Port GskGLRenderer to GLES



commit a407a733ffa84e5d61548c285872bcda7b03ebb9
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Apr 25 12:26:46 2016 +0100

    gsk: Port GskGLRenderer to GLES
    
    Use the appropriate API and shaders if the GdkGLContext was created for
    OpenGL ES instead of OpenGL.

 gsk/gskglrenderer.c                  |   18 +++++++++++++++---
 gsk/resources/glsl/gles-base.fs.glsl |   11 +++++++++++
 gsk/resources/glsl/gles-base.vs.glsl |   12 ++++++++++++
 3 files changed, 38 insertions(+), 3 deletions(-)
---
diff --git a/gsk/gskglrenderer.c b/gsk/gskglrenderer.c
index 4a5a03f..53945ee 100644
--- a/gsk/gskglrenderer.c
+++ b/gsk/gskglrenderer.c
@@ -160,7 +160,11 @@ gsk_gl_renderer_allocate_buffers (GskGLRenderer *self,
       glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
       glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
       glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-      glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
+
+      if (gdk_gl_context_get_use_es (self->context))
+        glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+      else
+        glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
     }
 
   if (self->render_buffer != 0)
@@ -302,8 +306,16 @@ gsk_gl_renderer_create_program (GskGLRenderer *self)
   GBytes *source;
   int status;
 
-  vs_path = "/org/gtk/libgsk/glsl/gl3-base.vs.glsl";
-  fs_path = "/org/gtk/libgsk/glsl/gl3-base.fs.glsl";
+  if (gdk_gl_context_get_use_es (self->context))
+    {
+      vs_path = "/org/gtk/libgsk/glsl/gles-base.vs.glsl";
+      fs_path = "/org/gtk/libgsk/glsl/gles-base.fs.glsl";
+    }
+  else
+    {
+      vs_path = "/org/gtk/libgsk/glsl/gl3-base.vs.glsl";
+      fs_path = "/org/gtk/libgsk/glsl/gl3-base.fs.glsl";
+    }
 
   GSK_NOTE (OPENGL, g_print ("Compiling vertex shader\n"));
   source = g_resources_lookup_data (vs_path, 0, NULL);
diff --git a/gsk/resources/glsl/gles-base.fs.glsl b/gsk/resources/glsl/gles-base.fs.glsl
new file mode 100644
index 0000000..ff43db9
--- /dev/null
+++ b/gsk/resources/glsl/gles-base.fs.glsl
@@ -0,0 +1,11 @@
+precision mediump float;
+
+uniform mat4 mvp;
+uniform sampler2D map;
+uniform float alpha;
+
+varying vec2 vUv;
+
+void main() {
+  gl_FragColor = texture2D(map, vUv) * vec4(alpha);
+}
diff --git a/gsk/resources/glsl/gles-base.vs.glsl b/gsk/resources/glsl/gles-base.vs.glsl
new file mode 100644
index 0000000..747e05e
--- /dev/null
+++ b/gsk/resources/glsl/gles-base.vs.glsl
@@ -0,0 +1,12 @@
+uniform mat4 mvp;
+
+attribute vec2 position;
+attribute vec2 uv;
+
+varying vec2 vUv;
+
+void main() {
+  gl_Position = mvp * vec4(position, 0.0, 1.0);
+
+  vUv = vec2(uv.x, 1.0 - uv.y);
+}


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