diff --git a/clutter/clutter-shader.c b/clutter/clutter-shader.c index e2ba66ce7..0ff17b431 100644 --- a/clutter/clutter-shader.c +++ b/clutter/clutter-shader.c @@ -451,16 +451,22 @@ clutter_shader_glsl_bind (ClutterShader *self, cogl_shader_compile (shader); if (!cogl_shader_is_compiled (shader)) { - gchar error_buf[512]; + gchar *log_buf; - cogl_shader_get_info_log (shader, 512, error_buf); + log_buf = cogl_shader_get_info_log (shader); + /* translators: the first %s is the type of the shader, either + * Vertex shader or Fragment shader; the second %s is the actual + * error as reported by COGL + */ g_set_error (error, CLUTTER_SHADER_ERROR, CLUTTER_SHADER_ERROR_COMPILE, _("%s compilation failed: %s"), shader_type == CLUTTER_VERTEX_SHADER ? _("Vertex shader") : _("Fragment shader"), - error_buf); + log_buf); + + g_free (log_buf); return FALSE; } diff --git a/clutter/cogl/cogl-shader.h b/clutter/cogl/cogl-shader.h index d0b0ce13e..9eec9bb40 100644 --- a/clutter/cogl/cogl-shader.h +++ b/clutter/cogl/cogl-shader.h @@ -106,7 +106,7 @@ gboolean cogl_is_shader (CoglHandle handle); * one. */ void cogl_shader_source (CoglHandle shader, - const char *source); + const gchar *source); /** * cogl_shader_compile: * @handle: #CoglHandle for a shader. @@ -119,17 +119,16 @@ void cogl_shader_compile (CoglHandle handle); /** * cogl_shader_get_info_log: * @handle: #CoglHandle for a shader. - * @size: maximum number of bytes to retrieve. - * @buffer: location for info log. * * Retrieves the information log for a coglobject, can be used in conjunction - * with #cogl_shader_get_parameteriv to retrieve the compiler warnings/error + * with cogl_shader_get_parameteriv() to retrieve the compiler warnings/error * messages that caused a shader to not compile correctly, mainly useful for * debugging purposes. + * + * Return value: a newly allocated string containing the info log. Use + * g_free() to free it */ -void cogl_shader_get_info_log (CoglHandle handle, - size_t size, - char *buffer); +gchar * cogl_shader_get_info_log (CoglHandle handle); /** * cogl_shader_get_type: diff --git a/clutter/cogl/gl/cogl-shader.c b/clutter/cogl/gl/cogl-shader.c index 944e6736f..de3302e6a 100644 --- a/clutter/cogl/gl/cogl-shader.c +++ b/clutter/cogl/gl/cogl-shader.c @@ -108,22 +108,23 @@ cogl_shader_compile (CoglHandle handle) glCompileShaderARB (shader->gl_handle); } -void -cogl_shader_get_info_log (CoglHandle handle, - size_t size, - char *buffer) +gchar * +cogl_shader_get_info_log (CoglHandle handle) { CoglShader *shader; + char buffer[512]; int len; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _COGL_GET_CONTEXT (ctx, NULL); if (!cogl_is_shader (handle)) - return; + return NULL; shader = _cogl_shader_pointer_from_handle (handle); - glGetInfoLogARB (shader->gl_handle, size-1, &len, buffer); + glGetInfoLogARB (shader->gl_handle, 511, &len, buffer); buffer[len]='\0'; + + return g_strdup (buffer); } CoglShaderType diff --git a/clutter/cogl/gles/cogl-shader.c b/clutter/cogl/gles/cogl-shader.c index ff5f0c58a..11cbe0c33 100644 --- a/clutter/cogl/gles/cogl-shader.c +++ b/clutter/cogl/gles/cogl-shader.c @@ -99,22 +99,23 @@ cogl_shader_compile (CoglHandle handle) glCompileShader (shader->gl_handle); } -void -cogl_shader_get_info_log (CoglHandle handle, - size_t size, - char *buffer) +gchar * +cogl_shader_get_info_log (CoglHandle handle) { CoglShader *shader; + char buffer[512] int len = 0; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _COGL_GET_CONTEXT (ctx, NULL); if (!cogl_is_shader (handle)) - return; + return NULL; shader = _cogl_shader_pointer_from_handle (handle); - glGetShaderInfoLog (shader->gl_handle, size - 1, &len, buffer); + glGetShaderInfoLog (shader->gl_handle, 511, &len, buffer); buffer[len] = '\0'; + + return g_strdup (buffer); } CoglShaderType