[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:
Emmanuele Bassi 2009-06-01 16:31:32 +01:00
parent 9d41a27f61
commit c0c7565ffc
3 changed files with 22 additions and 21 deletions

View File

@ -106,7 +106,7 @@ gboolean cogl_is_shader (CoglHandle handle);
* one. * one.
*/ */
void cogl_shader_source (CoglHandle shader, void cogl_shader_source (CoglHandle shader,
const char *source); const gchar *source);
/** /**
* cogl_shader_compile: * cogl_shader_compile:
* @handle: #CoglHandle for a shader. * @handle: #CoglHandle for a shader.
@ -119,17 +119,16 @@ void cogl_shader_compile (CoglHandle handle);
/** /**
* cogl_shader_get_info_log: * cogl_shader_get_info_log:
* @handle: #CoglHandle for a shader. * @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 * 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 * messages that caused a shader to not compile correctly, mainly useful for
* debugging purposes. * 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, gchar * cogl_shader_get_info_log (CoglHandle handle);
size_t size,
char *buffer);
/** /**
* cogl_shader_get_type: * cogl_shader_get_type:

View File

@ -108,22 +108,23 @@ cogl_shader_compile (CoglHandle handle)
glCompileShaderARB (shader->gl_handle); glCompileShaderARB (shader->gl_handle);
} }
void gchar *
cogl_shader_get_info_log (CoglHandle handle, cogl_shader_get_info_log (CoglHandle handle)
size_t size,
char *buffer)
{ {
CoglShader *shader; CoglShader *shader;
char buffer[512];
int len; int len;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NULL);
if (!cogl_is_shader (handle)) if (!cogl_is_shader (handle))
return; return NULL;
shader = _cogl_shader_pointer_from_handle (handle); 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'; buffer[len]='\0';
return g_strdup (buffer);
} }
CoglShaderType CoglShaderType

View File

@ -99,22 +99,23 @@ cogl_shader_compile (CoglHandle handle)
glCompileShader (shader->gl_handle); glCompileShader (shader->gl_handle);
} }
void gchar *
cogl_shader_get_info_log (CoglHandle handle, cogl_shader_get_info_log (CoglHandle handle)
size_t size,
char *buffer)
{ {
CoglShader *shader; CoglShader *shader;
char buffer[512]
int len = 0; int len = 0;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NULL);
if (!cogl_is_shader (handle)) if (!cogl_is_shader (handle))
return; return NULL;
shader = _cogl_shader_pointer_from_handle (handle); 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'; buffer[len] = '\0';
return g_strdup (buffer);
} }
CoglShaderType CoglShaderType