X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=examples%2Fshared%2Flibc3%2Fsrc%2Fc3program.c;h=f045de85a8102d0157ee7c806a5f332b45f8cf92;hb=ecb88cd8b73307501ce7a89f79f33d4e1e054d5b;hp=5e2edf41717628857f3ee6a636781004d75e6d52;hpb=1b4c2367d6ee9a886949eaa64feec929cf8e387d;p=simavr diff --git a/examples/shared/libc3/src/c3program.c b/examples/shared/libc3/src/c3program.c index 5e2edf4..f045de8 100644 --- a/examples/shared/libc3/src/c3program.c +++ b/examples/shared/libc3/src/c3program.c @@ -31,11 +31,27 @@ c3program_p c3program_new( - const char * name) + const char * name, + const char ** uniforms ) { c3program_p p = malloc(sizeof(*p)); memset(p, 0, sizeof(*p)); p->name = str_new(name); + + /* Allow specifying uniform names to make sure they are in + * the specified order in the array, this allow direct indexing + * instead of doign string lookup + */ + if (uniforms) { + for (int ui = 0; uniforms[ui]; ui++) { + c3program_param_t pa = { + .name = str_new(uniforms[ui]), + .program = p, + .index = p->params.count, + }; + c3program_param_array_add(&p->params, pa); + } + } return p; } @@ -128,29 +144,33 @@ c3program_load_shader( char * sep = line->str; char * uniform = strsep(&sep, " \t"); char * unitype = strsep(&sep, " \t"); - char * uniname = strsep(&sep, " \t"); + char * uniname = strsep(&sep, " \t=;"); /* * found a parameter, extract it's type & name */ if (uniform && unitype && uniname) { // trim semicolons etc char *cl = uniname; - while (isalpha(*cl) || *cl == '_') + while (isalpha(*cl) || *cl == '_' || isdigit(*cl)) cl++; *cl = 0; str_p name = str_new(uniname); for (int pi = 0; pi < p->params.count && uniform; pi++) - if (!str_cmp(name, p->params.e[pi].name)) + if (!str_cmp(name, p->params.e[pi].name)) { + if (!p->params.e[pi].type) + p->params.e[pi].type = str_new(unitype); uniform = NULL; // already there + } if (uniform) { c3program_param_t pa = { .type = str_new(unitype), .name = name, .program = p, + .index = p->params.count, }; c3program_param_array_add(&p->params, pa); if (p->verbose) - printf("%s %s: new parameter '%s' '%s'\n", __func__, + printf("%s %s: new parameter '%s' '%s'\n", __func__, p->name->str, unitype, uniname); } else str_free(name);