gdk: Add GLES shaders

We cannot use GL shaders with GLES.
This commit is contained in:
Emmanuele Bassi 2016-04-22 13:52:49 +01:00
parent 3da73371b9
commit 8bb4eb5544
4 changed files with 45 additions and 4 deletions

View File

@ -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

View File

@ -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 (paint_data->use_es)
use_texture_gles_program (paint_data);
else
{
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;

View File

@ -0,0 +1,9 @@
precision mediump float;
uniform sampler2D map;
varying highp vec2 vUv;
void main() {
gl_FragColor = texture2D(map, vUv);
}

View File

@ -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);
}