[cogl-shader] Make get_info_log() slightly nicer
The cogl_shader_get_info_log() function is very inconvenient for language bindings and for regular use, as it requires a static buffer to be filled -- basically just providing a wrapper around glGetInfoLogARB(). Since COGL aims to be a more convenient API than raw GL we should just make cogl_shader_get_info_log() return an allocated string with the GLSL compiler log.
This commit is contained in:
parent
5c26cc6ba7
commit
61deeafa71
@ -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;
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user