From d3f47e042aebd5fbf86477abf7058704657e8430 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 27 Oct 2018 12:41:58 +0100 Subject: Cleanup pass --- glprog.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'glprog.c') diff --git a/glprog.c b/glprog.c index 93dc22c..edb819e 100644 --- a/glprog.c +++ b/glprog.c @@ -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; -- cgit v1.2.3-54-g00ecf