From 9601479f0c6c18558603989cccb9cb9cea1dc158 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 6 Oct 2015 21:59:59 +0100 Subject: [PATCH] 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 --- tests/testglarea.c | 48 ++++++++++++++++++++++++++++++++++++++++++---- 1 file 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); }