aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2018-05-02 19:35:20 +0100
committerTomasz Kramkowski <tk@the-tk.com>2018-05-02 19:35:20 +0100
commit3c1b90a736e3958a9f0545f04b1af7fc00b74b4e (patch)
tree7e65e1edcbf231710534c7a391e08a24b3cdfb76
parent024a3b2dc8c600013b9b76c7f919594d533ba774 (diff)
downloadfaqe-3c1b90a736e3958a9f0545f04b1af7fc00b74b4e.tar.gz
faqe-3c1b90a736e3958a9f0545f04b1af7fc00b74b4e.tar.xz
faqe-3c1b90a736e3958a9f0545f04b1af7fc00b74b4e.zip
Improve glprog_load to take sentinel terminated lists
Numerous times a new uniform has been added and the corresponding increment of the nunis parameter was forgotten causing confusion. This should not happen anymore.
-rw-r--r--faqe.c6
-rw-r--r--glprog.c14
-rw-r--r--glprog.h2
3 files changed, 12 insertions, 10 deletions
diff --git a/faqe.c b/faqe.c
index 5098429..9567d1f 100644
--- a/faqe.c
+++ b/faqe.c
@@ -75,14 +75,16 @@ int main(int argc, char **argv)
fmd_free(&cube_fmd);
fclose(cube_file);
- prog = glprog_load(2, (struct shdrdat []){
+ prog = glprog_load((struct shdrdat []){
{ GL_VERTEX_SHADER, vert_glsl.data, vert_glsl.size },
{ GL_FRAGMENT_SHADER, frag_glsl.data, frag_glsl.size },
+ { 0 },
},
- 3, (struct unidat []){
+ (struct unidat []){
{ "model", &uni.model },
{ "view", &uni.view },
{ "proj", &uni.proj },
+ { 0 },
});
gl_prog_use(prog);
diff --git a/glprog.c b/glprog.c
index 19e0d44..5019af2 100644
--- a/glprog.c
+++ b/glprog.c
@@ -40,19 +40,17 @@ void detach_shaders(GLuint prog)
gl_prog_detachshdr(prog, shdr);
}
-GLuint glprog_load(int nshdrs, const struct shdrdat *shdrs, int nunis, const struct unidat *unis)
+GLuint glprog_load(const struct shdrdat *shdrs, const struct unidat *unis)
{
GLuint prog;
GLint success;
char log[LOGSIZE];
- assert(nshdrs > 0);
assert(shdrs != NULL);
- assert(nunis <= 0 || unis != NULL);
prog = gl_prog_create();
- for (int i = 0; i < nshdrs; i++) {
- GLuint shdr = load_shader(&shdrs[i]);
+ for (const struct shdrdat *s = shdrs; s->type != 0; s++) {
+ GLuint shdr = load_shader(s);
gl_prog_attachshdr(prog, shdr);
gl_shdr_del(shdr);
}
@@ -65,8 +63,10 @@ GLuint glprog_load(int nshdrs, const struct shdrdat *shdrs, int nunis, const str
detach_shaders(prog);
- for (int i = 0; i < nunis; i++)
- *unis[i].loc = gl_uni_loc(prog, unis[i].name);
+ if (unis == NULL) return prog;
+
+ for (const struct unidat *u = unis; u->name != NULL; u++)
+ *u->loc = gl_uni_loc(prog, u->name);
return prog;
}
diff --git a/glprog.h b/glprog.h
index a81f6d6..cd0ef83 100644
--- a/glprog.h
+++ b/glprog.h
@@ -18,6 +18,6 @@ struct shdrdat {
GLint len;
};
-GLuint glprog_load(int nshdrs, const struct shdrdat *shdrs, int nunis, const struct unidat *unis);
+GLuint glprog_load(const struct shdrdat *shdrs, const struct unidat *unis);
#endif // SHADER_H