[gtk+/wip/ebassi/gles: 108/113] gdk: Add GLES shaders
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/ebassi/gles: 108/113] gdk: Add GLES shaders
- Date: Fri, 22 Apr 2016 17:52:43 +0000 (UTC)
commit e9da51579c554257b8e1ae5fe77fe4963c4976df
Author: Emmanuele Bassi <ebassi gnome org>
Date: Fri Apr 22 13:52:49 2016 +0100
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 | 7 +++++++
gdk/resources/glsl/gles2-texture.vs.glsl | 10 ++++++++++
4 files changed, 43 insertions(+), 4 deletions(-)
---
diff --git a/gdk/Makefile.am b/gdk/Makefile.am
index f33c8ae..0cb43ba 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 155e8cd..748e80f 100644
--- a/gdk/gdkgl.c
+++ b/gdk/gdkgl.c
@@ -152,6 +152,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)
{
const char *vertex_shader_path = paint_data->is_legacy
@@ -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 0000000..a2a0415
--- /dev/null
+++ b/gdk/resources/glsl/gles2-texture.fs.glsl
@@ -0,0 +1,7 @@
+uniform sampler2D map;
+
+varying 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 0000000..0625cb3
--- /dev/null
+++ b/gdk/resources/glsl/gles2-texture.vs.glsl
@@ -0,0 +1,10 @@
+attribute vec2 position;
+attribute vec2 uv;
+
+varying vec2 vUv;
+
+void main() {
+ vUv = uv;
+
+ gl_Position = vec4(position, 0.0, 1.0);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]