gsk: Port GskGLRenderer to GLES

Use the appropriate API and shaders if the GdkGLContext was created for
OpenGL ES instead of OpenGL.
This commit is contained in:
Emmanuele Bassi 2016-04-25 12:26:46 +01:00
parent 5909ce6897
commit 9d3ca22b4c
3 changed files with 38 additions and 3 deletions

View File

@ -160,6 +160,10 @@ 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);
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);
}
@ -302,8 +306,16 @@ gsk_gl_renderer_create_program (GskGLRenderer *self)
GBytes *source;
int status;
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);

View File

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

View File

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