Compile multiple shaders listed on the command line
This commit is contained in:
54
main.cpp
54
main.cpp
@@ -164,7 +164,7 @@ compile_shader(struct glsl_program *prog)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct _mesa_glsl_parse_state state;
|
int status = EXIT_SUCCESS;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
@@ -175,26 +175,44 @@ main(int argc, char **argv)
|
|||||||
if (argc <= optind)
|
if (argc <= optind)
|
||||||
usage_fail(argv[0]);
|
usage_fail(argv[0]);
|
||||||
|
|
||||||
struct glsl_program *prog = new glsl_program;
|
struct glsl_program **prog_list = NULL;
|
||||||
memset(prog, 0, sizeof(*prog));
|
unsigned prog_list_len = 0;
|
||||||
|
|
||||||
const unsigned len = strlen(argv[optind]);
|
for (/* empty */; argc > optind; optind++) {
|
||||||
if (len < 6)
|
prog_list = (struct glsl_program **)
|
||||||
usage_fail(argv[0]);
|
realloc(prog_list,
|
||||||
|
sizeof(struct glsl_program *) * (prog_list_len + 1));
|
||||||
|
assert(prog_list != NULL);
|
||||||
|
|
||||||
const char *const ext = & argv[optind][len - 5];
|
struct glsl_program *prog = new glsl_program;
|
||||||
if (strncmp(".vert", ext, 5) == 0)
|
memset(prog, 0, sizeof(*prog));
|
||||||
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]);
|
|
||||||
|
|
||||||
prog->Source = load_text_file(argv[optind], &prog->SourceLen);
|
prog_list[prog_list_len] = prog;
|
||||||
|
prog_list_len++;
|
||||||
|
|
||||||
compile_shader(prog);
|
const unsigned len = strlen(argv[optind]);
|
||||||
|
if (len < 6)
|
||||||
|
usage_fail(argv[0]);
|
||||||
|
|
||||||
return prog->CompileStatus ? EXIT_SUCCESS : EXIT_FAILURE;
|
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]);
|
||||||
|
|
||||||
|
prog->Source = load_text_file(argv[optind], &prog->SourceLen);
|
||||||
|
|
||||||
|
compile_shader(prog);
|
||||||
|
|
||||||
|
if (!prog->CompileStatus) {
|
||||||
|
status = EXIT_FAILURE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user