diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2015-10-06 21:59:59 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2015-10-07 16:21:57 +0100 |
commit | 9601479f0c6c18558603989cccb9cb9cea1dc158 (patch) | |
tree | 7d8e69f5d3a44f8e30faf6ba9b295bdbb2843ece /tests | |
parent | 105f1c9fd3650eefafcfe4c97cffe7ca93d4b457 (diff) | |
download | gtk+-9601479f0c6c18558603989cccb9cb9cea1dc158.tar.gz |
Allow testglarea to work with legacy GL contexts
Use the 1.30 GLSL shading language for the fragment and vertex shaders.
https://bugzilla.gnome.org/show_bug.cgi?id=756142
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testglarea.c | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/tests/testglarea.c b/tests/testglarea.c index 41ac705098..310a244b4e 100644 --- a/tests/testglarea.c +++ b/tests/testglarea.c @@ -80,7 +80,7 @@ create_shader (int type, const char *src) return shader; } -static const char *vertex_shader_code = +static const char *vertex_shader_code_330 = "#version 330\n" \ "\n" \ "layout(location = 0) in vec4 position;\n" \ @@ -89,7 +89,16 @@ static const char *vertex_shader_code = " gl_Position = mvp * position;\n" \ "}"; -static const char *fragment_shader_code = +static const char *vertex_shader_code_legacy = +"#version 130\n" \ +"\n" \ +"attribute vec4 position;\n" \ +"uniform mat4 mvp;\n" \ +"void main() {\n" \ +" gl_Position = mvp * position;\n" \ +"}"; + +static const char *fragment_shader_code_330 = "#version 330\n" \ "\n" \ "out vec4 outputColor;\n" \ @@ -98,8 +107,18 @@ static const char *fragment_shader_code = " outputColor = mix(vec4(1.0f, 0.85f, 0.35f, 1.0f), vec4(0.2f, 0.2f, 0.2f, 1.0f), lerpVal);\n" \ "}"; +static const char *fragment_shader_code_legacy = +"#version 130\n" \ +"\n" \ +"void main() {\n" \ +" float lerpVal = gl_FragCoord.y / 400.0f;\n" \ +" gl_FragColor = mix(vec4(1.0f, 0.85f, 0.35f, 1.0f), vec4(0.2f, 0.2, 0.2f, 1.0f), lerpVal);\n" \ +"}"; + static void -init_shaders (GLuint *program_out, +init_shaders (const char *vertex_shader_code, + const char *fragment_shader_code, + GLuint *program_out, GLuint *mvp_out) { GLuint vertex, fragment; @@ -215,10 +234,28 @@ static GLuint mvp_location; static void realize (GtkWidget *widget) { + const char *fragment, *vertex; + GdkGLContext *context; + gtk_gl_area_make_current (GTK_GL_AREA (widget)); + if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL) + return; + + context = gtk_gl_area_get_context (GTK_GL_AREA (widget)); + if (!gdk_gl_context_is_legacy (context)) + { + vertex = vertex_shader_code_330; + fragment = fragment_shader_code_330; + } + else + { + vertex = vertex_shader_code_legacy; + fragment = fragment_shader_code_legacy; + } + init_buffers (&position_buffer, NULL); - init_shaders (&program, &mvp_location); + init_shaders (vertex, fragment, &program, &mvp_location); } static void @@ -226,6 +263,9 @@ unrealize (GtkWidget *widget) { gtk_gl_area_make_current (GTK_GL_AREA (widget)); + if (gtk_gl_area_get_error (GTK_GL_AREA (widget)) != NULL) + return; + glDeleteBuffers (1, &position_buffer); glDeleteProgram (program); } |