From 6fd9fb23de908ec52089fdc6e24af9e2ebbe126e Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 17 Jun 2010 12:22:16 -0700 Subject: [PATCH] Compile multiple shaders listed on the command line --- main.cpp | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/main.cpp b/main.cpp index ae564e860dd..68a8fd2b691 100644 --- a/main.cpp +++ b/main.cpp @@ -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; } -- 2.30.2