Commit e636c316 authored by Emmanuele Bassi's avatar Emmanuele Bassi

gl: Use older GLSL shaders with legacy contexts

If we're using modern GLSL, then we should stop using deprecated
modifiers, like 'varying' and 'attribute', as well as deprecated global
variables, like 'gl_FragColor'.

On the other hand, with legacy contexts we should be using older GLSL
shaders, to maximize compatibility.

https://bugzilla.gnome.org/show_bug.cgi?id=756142
parent 24230ca7
......@@ -147,9 +147,27 @@ bind_vao (GdkGLContextPaintData *paint_data)
static void
use_texture_2d_program (GdkGLContextPaintData *paint_data)
{
static const char *vertex_shader_code =
static const char *vertex_shader_code_150 =
"#version 150\n"
"uniform sampler2D map;"
"in vec2 position;\n"
"in vec2 uv;\n"
"out vec2 vUv;\n"
"void main() {\n"
" gl_Position = vec4(position, 0, 1);\n"
" vUv = uv;\n"
"}\n";
static const char *fragment_shader_code_150 =
"#version 150\n"
"in vec2 vUv;\n"
"out vec4 vertexColor;\n"
"uniform sampler2D map;\n"
"void main() {\n"
" vertexColor = texture2D (map, vUv);\n"
"}\n";
static const char *vertex_shader_code_130 =
"#version 130\n"
"uniform sampler2D map;"
"attribute vec2 position;\n"
"attribute vec2 uv;\n"
"varying vec2 vUv;\n"
......@@ -157,14 +175,21 @@ use_texture_2d_program (GdkGLContextPaintData *paint_data)
" gl_Position = vec4(position, 0, 1);\n"
" vUv = uv;\n"
"}\n";
static const char *fragment_shader_code =
"#version 150\n"
static const char *fragment_shader_code_130 =
"#version 130\n"
"varying vec2 vUv;\n"
"uniform sampler2D map;\n"
"void main() {\n"
" gl_FragColor = texture2D (map, vUv);\n"
"}\n";
const char *vertex_shader_code = paint_data->is_legacy
? vertex_shader_code_130
: vertex_shader_code_150;
const char *fragment_shader_code = paint_data->is_legacy
? fragment_shader_code_130
: fragment_shader_code_150;
if (paint_data->texture_2d_quad_program.program == 0)
make_program (&paint_data->texture_2d_quad_program, vertex_shader_code, fragment_shader_code);
......@@ -178,9 +203,9 @@ use_texture_2d_program (GdkGLContextPaintData *paint_data)
static void
use_texture_rect_program (GdkGLContextPaintData *paint_data)
{
static const char *vertex_shader_code =
static const char *vertex_shader_code_150 =
"#version 150\n"
"uniform sampler2DRect map;"
"uniform sampler2DRect map;\n"
"attribute vec2 position;\n"
"attribute vec2 uv;\n"
"varying vec2 vUv;\n"
......@@ -188,13 +213,37 @@ use_texture_rect_program (GdkGLContextPaintData *paint_data)
" gl_Position = vec4(position, 0, 1);\n"
" vUv = uv;\n"
"}\n";
static const char *fragment_shader_code =
static const char *fragment_shader_code_150 =
"#version 150\n"
"varying vec2 vUv;\n"
"uniform sampler2DRect map;\n"
"void main() {\n"
" gl_FragColor = texture2DRect (map, vUv);\n"
"}\n";
static const char *vertex_shader_code_130 =
"#version 130\n"
"uniform sampler2DRect map;\n"
"attribute vec2 position;\n"
"attribute vec2 uv;\n"
"varying vec2 vUv;\n"
"void main() {\n"
" gl_Position = vec4(position, 0, 1);\n"
" vUv = uv;\n"
"}\n";
static const char *fragment_shader_code_130 =
"#version 130\n"
"varying vec2 vUv;\n"
"uniform sampler2DRect map;\n"
"void main() {\n"
" gl_FragColor = texture2DRect (map, vUv);\n"
"}\n";
const char *vertex_shader_code = paint_data->is_legacy
? vertex_shader_code_130
: vertex_shader_code_150;
const char *fragment_shader_code = paint_data->is_legacy
? fragment_shader_code_130
: fragment_shader_code_150;
if (paint_data->texture_rect_quad_program.program == 0)
make_program (&paint_data->texture_rect_quad_program, vertex_shader_code, fragment_shader_code);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment