From 8bb4eb55448ec72338fa14d71c24a1cacc35756c Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Fri, 22 Apr 2016 13:52:49 +0100 Subject: [PATCH] gdk: Add GLES shaders We cannot use GL shaders with GLES. --- gdk/Makefile.am | 4 +++- gdk/gdkgl.c | 26 +++++++++++++++++++++--- gdk/resources/glsl/gles2-texture.fs.glsl | 9 ++++++++ gdk/resources/glsl/gles2-texture.vs.glsl | 10 +++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 gdk/resources/glsl/gles2-texture.fs.glsl create mode 100644 gdk/resources/glsl/gles2-texture.vs.glsl diff --git a/gdk/Makefile.am b/gdk/Makefile.am index f33c8aec73..0cb43ba152 100644 --- a/gdk/Makefile.am +++ b/gdk/Makefile.am @@ -468,7 +468,9 @@ glsl_sources = \ resources/glsl/gl2-texture-2d.fs.glsl \ resources/glsl/gl2-texture-2d.fs.glsl \ resources/glsl/gl2-texture-rect.vs.glsl \ - resources/glsl/gl2-texture-rect.vs.glsl + resources/glsl/gl2-texture-rect.vs.glsl \ + resources/glsl/gles2-texture.fs.glsl \ + resources/glsl/gles2-texture.vs.glsl EXTRA_DIST += $(glsl_sources) CLEANFILES += gdk.gresource.xml diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c index 155e8cd344..748e80f6c0 100644 --- a/gdk/gdkgl.c +++ b/gdk/gdkgl.c @@ -151,6 +151,21 @@ bind_vao (GdkGLContextPaintData *paint_data) } } +static void +use_texture_gles_program (GdkGLContextPaintData *paint_data) +{ + if (paint_data->texture_2d_quad_program.program == 0) + make_program (&paint_data->texture_2d_quad_program, + "/org/gtk/libgdk/glsl/gles2-texture.vs.glsl", + "/org/gtk/libgdk/glsl/gles2-texture.fs.glsl"); + + if (paint_data->current_program != &paint_data->texture_2d_quad_program) + { + paint_data->current_program = &paint_data->texture_2d_quad_program; + glUseProgram (paint_data->current_program->program); + } +} + static void use_texture_2d_program (GdkGLContextPaintData *paint_data) { @@ -213,10 +228,15 @@ gdk_gl_texture_quads (GdkGLContext *paint_context, if (paint_data->tmp_vertex_buffer == 0) glGenBuffers(1, &paint_data->tmp_vertex_buffer); - if (texture_target == GL_TEXTURE_RECTANGLE_ARB) - use_texture_rect_program (paint_data); + if (paint_data->use_es) + use_texture_gles_program (paint_data); else - use_texture_2d_program (paint_data); + { + if (texture_target == GL_TEXTURE_RECTANGLE_ARB) + use_texture_rect_program (paint_data); + else + use_texture_2d_program (paint_data); + } program = paint_data->current_program; diff --git a/gdk/resources/glsl/gles2-texture.fs.glsl b/gdk/resources/glsl/gles2-texture.fs.glsl new file mode 100644 index 0000000000..68e455fcf3 --- /dev/null +++ b/gdk/resources/glsl/gles2-texture.fs.glsl @@ -0,0 +1,9 @@ +precision mediump float; + +uniform sampler2D map; + +varying highp vec2 vUv; + +void main() { + gl_FragColor = texture2D(map, vUv); +} diff --git a/gdk/resources/glsl/gles2-texture.vs.glsl b/gdk/resources/glsl/gles2-texture.vs.glsl new file mode 100644 index 0000000000..62fb1c7e9a --- /dev/null +++ b/gdk/resources/glsl/gles2-texture.vs.glsl @@ -0,0 +1,10 @@ +attribute vec2 position; +attribute vec2 uv; + +varying highp vec2 vUv; + +void main() { + vUv = uv; + + gl_Position = vec4(position, 0.0, 1.0); +}