From 7238f82f18ce754ad0286cb2ca43f1b1e2bdf3fe Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 20 Jun 2008 19:57:02 -0400 Subject: [PATCH] Added testoutput program for outputting just the generated shaders. --HG-- branch : trunk --- .hgignore | 1 + CMakeLists.txt | 1 + testoutput.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 testoutput.c diff --git a/.hgignore b/.hgignore index 1b745e8d..c11cacd3 100644 --- a/.hgignore +++ b/.hgignore @@ -4,6 +4,7 @@ CMakeFiles Makefile cmake_install.cmake testparse +testoutput finderrors glcaps *.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 10aac769..e3919877 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ IF(SDL_FOUND) ENDIF(SDL_FOUND) ADD_EXECUTABLE(testparse testparse.c mojoshader.c) +ADD_EXECUTABLE(testoutput testoutput.c mojoshader.c) ADD_EXECUTABLE(finderrors finderrors.c mojoshader.c mojoshader_opengl.c) TARGET_LINK_LIBRARIES(finderrors ${SDL_LIBRARY} ${EXTRA_LIBS}) diff --git a/testoutput.c b/testoutput.c new file mode 100644 index 00000000..8c44eaac --- /dev/null +++ b/testoutput.c @@ -0,0 +1,72 @@ +/** + * MojoShader; generate shader programs from bytecode of compiled + * Direct3D shaders. + * + * Please see the file LICENSE.txt in the source's root directory. + * + * This file written by Ryan C. Gordon. + */ + +#include +#include +#include "mojoshader.h" + +static int do_parse(const unsigned char *buf, const int len, const char *prof) +{ + const MOJOSHADER_parseData *pd; + int retval = 0; + + pd = MOJOSHADER_parse(prof, buf, len, NULL, NULL, NULL); + if (pd->error != NULL) + printf("ERROR: %s\n", pd->error); + else + { + retval = 1; + if (pd->output != NULL) + { + int i; + for (i = 0; i < pd->output_len; i++) + putchar((int) pd->output[i]); + printf("\n"); + } // if + } // else + printf("\n\n"); + MOJOSHADER_freeParseData(pd); + + return retval; +} // do_parse + + +int main(int argc, char **argv) +{ + int retval = 0; + + if (argc <= 2) + printf("\n\nUSAGE: %s [file1] ... [fileN]\n\n", argv[0]); + else + { + const char *profile = argv[1]; + int i; + + for (i = 2; i < argc; i++) + { + FILE *io = fopen(argv[i], "rb"); + if (io == NULL) + printf(" ... fopen('%s') failed.\n", argv[i]); + else + { + unsigned char *buf = (unsigned char *) malloc(1000000); + int rc = fread(buf, 1, 1000000, io); + fclose(io); + if (!do_parse(buf, rc, profile)) + retval = 1; + free(buf); + } // else + } // for + } // else + + return retval; +} // main + +// end of testoutput.c ... +