diff options
Diffstat (limited to 'glprog.c')
-rw-r--r-- | glprog.c | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -39,6 +39,7 @@ static const struct { }, }; +// readfile: read a whole file into a buffer static bool readfile(char **data, size_t *size, const char *name) { FILE *f; @@ -63,17 +64,19 @@ static bool readfile(char **data, size_t *size, const char *name) *data = erealloc(*data, *size); } + fclose(f); + *size = len; *data = erealloc(*data, *size); return true; } +// compile: compile shader component static GLuint compile(const char *src, size_t len, const char *pre, GLuint type) { GLuint id; GLint success; - char log[LOGSIZE]; static const char *common_pre = #define SH_VER(v) "#version " v "\n" #define SH_UNI(type, name) "uniform " #type " " #name ";\n" @@ -88,6 +91,7 @@ static GLuint compile(const char *src, size_t len, const char *pre, GLuint type) gl_shdr_param(id, GL_COMPILE_STATUS, &success); if (!success) { + char log[LOGSIZE]; gl_shdr_infolog(id, sizeof log, NULL, log); eprintf("Failed to compile shader:\n%s", log); } @@ -108,7 +112,7 @@ static void load_shader(struct shader *s, const char *path) { GLuint prog; GLint success, pos = 0; - char log[LOGSIZE], *full, *src = NULL; + char *full, *src = NULL; size_t srclen = 0, fullsz; GLint texture = 0; @@ -139,6 +143,7 @@ static void load_shader(struct shader *s, const char *path) gl_prog_link(prog); gl_prog_param(prog, GL_LINK_STATUS, &success); if (!success) { + char log[LOGSIZE]; gl_prog_infolog(prog, sizeof log, NULL, log); eprintf("Failed to link program\n%s", log); } @@ -153,6 +158,7 @@ static void load_shader(struct shader *s, const char *path) s->prog = prog; } +// glprog_init: compile and link all shader programs void glprog_init(void) { GLint pos = 0; |