diff options
author | Ian Romanick <[email protected]> | 2010-06-17 12:22:16 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2010-06-17 12:22:16 -0700 |
commit | 6fd9fb23de908ec52089fdc6e24af9e2ebbe126e (patch) | |
tree | 2e3c6b8e1b8b375ff2cdf207ad7faec535219979 /main.cpp | |
parent | 8ce55dbd9207ff4338588dcba155f1a754dc8f19 (diff) |
Compile multiple shaders listed on the command line
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 54 |
1 files changed, 36 insertions, 18 deletions
@@ -164,7 +164,7 @@ compile_shader(struct glsl_program *prog) int main(int argc, char **argv) { - struct _mesa_glsl_parse_state state; + int status = EXIT_SUCCESS; int c; int idx = 0; @@ -175,26 +175,44 @@ main(int argc, char **argv) if (argc <= optind) usage_fail(argv[0]); - struct glsl_program *prog = new glsl_program; - memset(prog, 0, sizeof(*prog)); + struct glsl_program **prog_list = NULL; + unsigned prog_list_len = 0; - const unsigned len = strlen(argv[optind]); - if (len < 6) - usage_fail(argv[0]); + for (/* empty */; argc > optind; optind++) { + prog_list = (struct glsl_program **) + realloc(prog_list, + sizeof(struct glsl_program *) * (prog_list_len + 1)); + assert(prog_list != NULL); - const char *const ext = & argv[optind][len - 5]; - if (strncmp(".vert", ext, 5) == 0) - prog->Type = GL_VERTEX_SHADER; - else if (strncmp(".geom", ext, 5) == 0) - prog->Type = GL_GEOMETRY_SHADER; - else if (strncmp(".frag", ext, 5) == 0) - prog->Type = GL_FRAGMENT_SHADER; - else - usage_fail(argv[0]); + struct glsl_program *prog = new glsl_program; + memset(prog, 0, sizeof(*prog)); + + prog_list[prog_list_len] = prog; + prog_list_len++; + + const unsigned len = strlen(argv[optind]); + if (len < 6) + usage_fail(argv[0]); - prog->Source = load_text_file(argv[optind], &prog->SourceLen); + const char *const ext = & argv[optind][len - 5]; + if (strncmp(".vert", ext, 5) == 0) + prog->Type = GL_VERTEX_SHADER; + else if (strncmp(".geom", ext, 5) == 0) + prog->Type = GL_GEOMETRY_SHADER; + else if (strncmp(".frag", ext, 5) == 0) + prog->Type = GL_FRAGMENT_SHADER; + else + usage_fail(argv[0]); - compile_shader(prog); + prog->Source = load_text_file(argv[optind], &prog->SourceLen); + + compile_shader(prog); + + if (!prog->CompileStatus) { + status = EXIT_FAILURE; + break; + } + } - return prog->CompileStatus ? EXIT_SUCCESS : EXIT_FAILURE; + return status; } |