From a946821b4fa9e6ebf380aa3f2ca76ca5e48bd27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Mon, 14 Jun 2010 21:03:11 -0400 Subject: [PATCH] Propagate shader compile/link errors And silence the no-error case. --- compositor-drm.c | 3 ++- compositor-x11.c | 3 ++- compositor.c | 32 ++++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/compositor-drm.c b/compositor-drm.c index 608ada91..c45b1d8a 100644 --- a/compositor-drm.c +++ b/compositor-drm.c @@ -662,7 +662,8 @@ drm_compositor_create(struct wl_display *display) } /* Can't init base class until we have a current egl context */ - wlsc_compositor_init(&ec->base, display); + if (wlsc_compositor_init(&ec->base, display) < 0) + return NULL; if (create_outputs(ec) < 0) { fprintf(stderr, "failed to create output for %s\n", path); diff --git a/compositor-x11.c b/compositor-x11.c index 3cbe0c8e..61369fdc 100644 --- a/compositor-x11.c +++ b/compositor-x11.c @@ -644,7 +644,8 @@ x11_compositor_create(struct wl_display *display) x11_compositor_init_egl(c); /* Can't init base class until we have a current egl context */ - wlsc_compositor_init(&c->base, display); + if (wlsc_compositor_init(&c->base, display) < 0) + return NULL; x11_compositor_create_output(c, 1024, 640); diff --git a/compositor.c b/compositor.c index 310ee023..6b31b483 100644 --- a/compositor.c +++ b/compositor.c @@ -801,27 +801,36 @@ static const char fragment_shader[] = " gl_FragColor = texture2D(tex, v_texcoord)\n;" "}\n"; -static void +static int init_shaders(struct wlsc_compositor *ec) { GLuint v, f, program; const char *p; char msg[512]; GLfloat vertices[4 * 5]; + GLint status; p = vertex_shader; v = glCreateShader(GL_VERTEX_SHADER); glShaderSource(v, 1, &p, NULL); glCompileShader(v); - glGetShaderInfoLog(v, sizeof msg, NULL, msg); - printf("vertex shader info: %s\n", msg); + glGetShaderiv(v, GL_COMPILE_STATUS, &status); + if (!status) { + glGetShaderInfoLog(v, sizeof msg, NULL, msg); + fprintf(stderr, "vertex shader info: %s\n", msg); + return -1; + } p = fragment_shader; f = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(f, 1, &p, NULL); glCompileShader(f); - glGetShaderInfoLog(f, sizeof msg, NULL, msg); - printf("fragment shader info: %s\n", msg); + glGetShaderiv(f, GL_COMPILE_STATUS, &status); + if (!status) { + glGetShaderInfoLog(f, sizeof msg, NULL, msg); + fprintf(stderr, "fragment shader info: %s\n", msg); + return -1; + } program = glCreateProgram(); glAttachShader(program, v); @@ -830,8 +839,12 @@ init_shaders(struct wlsc_compositor *ec) glBindAttribLocation(program, 1, "texcoord"); glLinkProgram(program); - glGetProgramInfoLog(program, sizeof msg, NULL, msg); - printf("info: %s\n", msg); + glGetProgramiv(program, GL_LINK_STATUS, &status); + if (!status) { + glGetProgramInfoLog(program, sizeof msg, NULL, msg); + fprintf(stderr, "link info: %s\n", msg); + return -1; + } glUseProgram(program); ec->proj_uniform = glGetUniformLocation(program, "proj"); @@ -864,6 +877,8 @@ init_shaders(struct wlsc_compositor *ec) glGenBuffers(1, &ec->vbo); glBindBuffer(GL_ARRAY_BUFFER, ec->vbo); glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW); + + return 0; } static const struct wl_interface visual_interface = { @@ -938,7 +953,8 @@ wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display) glGenFramebuffers(1, &ec->fbo); glBindFramebuffer(GL_FRAMEBUFFER, ec->fbo); glActiveTexture(GL_TEXTURE0); - init_shaders(ec); + if (init_shaders(ec) < 0) + return -1; loop = wl_display_get_event_loop(ec->wl_display); ec->timer_source = wl_event_loop_add_timer(loop, repaint, ec);