diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2018-10-22 16:08:06 +0300 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2018-10-22 16:08:06 +0300 |
commit | adbc72e159d48e6b1ad091e6ac19fd1cd6d5f798 (patch) | |
tree | 8f9fc2ef41fc514c0a5c09a1a09796ed890857b4 | |
parent | accfd0b069897c1a07b7ee7dd1f35a345fb76c30 (diff) | |
download | faqe-adbc72e159d48e6b1ad091e6ac19fd1cd6d5f798.tar.gz faqe-adbc72e159d48e6b1ad091e6ac19fd1cd6d5f798.tar.xz faqe-adbc72e159d48e6b1ad091e6ac19fd1cd6d5f798.zip |
Use shaders/data.h to generate material code
There is enough information to generate some of the material loading
code from shaders/data.h.
-rw-r--r-- | faqe.c | 2 | ||||
-rw-r--r-- | glprog.c | 7 | ||||
-rw-r--r-- | glprog.h | 4 | ||||
-rw-r--r-- | mtl.c | 18 | ||||
-rw-r--r-- | shaders/data.h | 4 |
5 files changed, 17 insertions, 18 deletions
@@ -87,8 +87,6 @@ int main(int argc, char **argv) gl_prog_use(prog.main.prog); viewport(prog.main.uni.proj, WIDTH, HEIGHT); - gl_uni_set1i(prog.main.tex.tdiff, 0); - gl_uni_set1i(prog.main.tex.tspec, 1); gl_enable(GL_DEPTH_TEST); gl_enable(GL_FRAMEBUFFER_SRGB); @@ -33,7 +33,7 @@ static const struct { { GL_TESS_EVALUATION_SHADER, "tese", false, "" }, { GL_GEOMETRY_SHADER, "geom", false, "" }, { GL_FRAGMENT_SHADER, "frag", true, -#define SH_TEX(type, name) "uniform sampler" #type " " #name ";\n" +#define SH_TEX(type, name) "uniform sampler" #type " t" #name ";\n" #define SH_OUT(type, name) "out " #type " " #name ";\n" #include "shaders/data.h" }, @@ -110,6 +110,7 @@ static void load_shader(struct shader *s, const char *path) GLint success, pos = 0; char log[LOGSIZE], *full, *src = NULL; size_t srclen = 0, fullsz; + GLint texture = 0; assert(s != NULL); assert(path != NULL); @@ -144,8 +145,10 @@ static void load_shader(struct shader *s, const char *path) detach_shaders(prog); + gl_prog_use(prog); + #define SH_UNI(_, name) s->uni.name = gl_uni_loc(prog, #name); -#define SH_TEX(_, name) s->tex.name = gl_uni_loc(prog, #name); +#define SH_TEX(_, name) gl_uni_set1i(gl_uni_loc(prog, "t" #name), texture++); #include "shaders/data.h" s->prog = prog; } @@ -13,10 +13,6 @@ struct shader { #define SH_UNI(_, name) GLint name; #include "shaders/data.h" } uni; - struct { -#define SH_TEX(_, name) GLint name; -#include "shaders/data.h" - } tex; }; struct glprog_progs { @@ -8,13 +8,14 @@ #include "ensize.h" #include "eprintf.h" +#include "glprog.h" #include "mtl.h" #include "tex.h" struct mtl { char name[50]; - GLuint diff; - GLuint spec; +#define SH_TEX(_, name) GLuint name; +#include "shaders/data.h" }; static struct mtl *mtls; @@ -50,8 +51,8 @@ int mtl_load(char *name) snprintf(m->name, sizeof m->name, "%s", name); - m->diff = tex_file(name, "diff"); - m->spec = tex_file(name, "spec"); +#define SH_TEX(_, n) m->n = tex_file(name, #n); +#include "shaders/data.h" return lmtls++; } @@ -59,13 +60,14 @@ int mtl_load(char *name) void mtl_use(int mtl) { assert(mtl < lmtls); + GLenum texture = GL_TEXTURE0; // TODO: Blank textures or something if (mtl < 0) return; - gl_tex_active(GL_TEXTURE0); - gl_tex_bind(GL_TEXTURE_2D, mtls[mtl].diff); - gl_tex_active(GL_TEXTURE1); - gl_tex_bind(GL_TEXTURE_2D, mtls[mtl].spec); +#define SH_TEX(type, name) \ + gl_tex_active(texture++); \ + gl_tex_bind(GL_TEXTURE_##type, mtls[mtl].name); +#include "shaders/data.h" } diff --git a/shaders/data.h b/shaders/data.h index d7fbfd3..a2d5625 100644 --- a/shaders/data.h +++ b/shaders/data.h @@ -24,8 +24,8 @@ #undef SH_UNI #endif // SH_UNI #ifdef SH_TEX - SH_TEX(2D, tdiff) - SH_TEX(2D, tspec) + SH_TEX(2D, diff) + SH_TEX(2D, spec) #undef SH_TEX #endif // SH_TEX #ifdef SH_OUT |