From 01f9c2e4676821e13aa1f78ddc9453e680c0e2f0 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 9 May 2011 17:22:41 -0400 Subject: [PATCH] add guGetShaderLog() and guGetProgramLog() --- glslUtil/glslUtil.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ glslUtil/glslUtil.h | 2 ++ 2 files changed, 49 insertions(+) diff --git a/glslUtil/glslUtil.c b/glslUtil/glslUtil.c index 1a586f1..1b8dc2e 100644 --- a/glslUtil/glslUtil.c +++ b/glslUtil/glslUtil.c @@ -1,8 +1,29 @@ +#include +#include +#include #include #include #include "glslUtil.h" +/************************************************************************** + * Helper Functions * + *************************************************************************/ +static char *loadFile(const char *fname) +{ + struct stat st; + if (stat(fname, &st) != 0) + return NULL; + if (st.st_size <= 0) + return NULL; + char * buff = malloc(st.st_size + 1); + int fd = open(fname, O_RDONLY); + read(fd, buff, st.st_size); + close(fd); + buff[st.st_size] = '\0'; + return buff; +} + void guMatrixLoadIdentity(guMatrix4x4 *m) { int i, j; @@ -168,3 +189,29 @@ void guOrtho(guMatrix4x4 *m, mult[2][3] = - (far + near) / fn; mult[3][3] = 1.0; } + +char *guGetShaderLog(GLuint id) +{ + GLint log_length; + glGetShaderiv(id, GL_INFO_LOG_LENGTH, &log_length); + if (log_length > 0) + { + char *log = malloc(sizeof(char) * log_length); + glGetShaderInfoLog(id, log_length, &log_length, log); + return log; + } + return NULL; +} + +char *guGetProgramLog(GLuint id) +{ + GLint log_length; + glGetProgramiv(id, GL_INFO_LOG_LENGTH, &log_length); + if (log_length > 0) + { + char *log = malloc(sizeof(char) * log_length); + glGetProgramInfoLog(id, log_length, &log_length, log); + return log; + } + return NULL; +} diff --git a/glslUtil/glslUtil.h b/glslUtil/glslUtil.h index 040c977..d05498e 100644 --- a/glslUtil/glslUtil.h +++ b/glslUtil/glslUtil.h @@ -30,6 +30,8 @@ void guOrtho(guMatrix4x4 *m, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far); +char *guGetShaderLog(GLuint id); +char *guGetProgramLog(GLuint id); #ifdef __cplusplus }