summaryrefslogtreecommitdiffstats
path: root/tools/render-test/options.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/render-test/options.cpp')
-rw-r--r--tools/render-test/options.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp
new file mode 100644
index 000000000..9cfbb81fb
--- /dev/null
+++ b/tools/render-test/options.cpp
@@ -0,0 +1,95 @@
+// options.cpp
+
+#include "options.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+namespace renderer_test {
+
+Options gOptions;
+
+void parseOptions(int* argc, char** argv)
+{
+ int argCount = *argc;
+ char const* const* argCursor = argv;
+ char const* const* argEnd = argCursor + argCount;
+
+ char const** writeCursor = (char const**) argv;
+
+ // first argument is the application name
+ if( argCursor != argEnd )
+ {
+ gOptions.appName = *argCursor++;
+ }
+
+ // now iterate over arguments to collect options
+ while(argCursor != argEnd)
+ {
+ char const* arg = *argCursor++;
+ if( arg[0] != '-' )
+ {
+ *writeCursor++ = arg;
+ continue;
+ }
+
+ if( strcmp(arg, "--") == 0 )
+ {
+ while(argCursor != argEnd)
+ {
+ char const* arg = *argCursor++;
+ *writeCursor++ = arg;
+ }
+ break;
+ }
+ else if( strcmp(arg, "-o") == 0 )
+ {
+ if( argCursor == argEnd )
+ {
+ fprintf(stderr, "expected argument for '%s' option\n", arg);
+ exit(1);
+ }
+ gOptions.outputPath = *argCursor++;
+ }
+ else if( strcmp(arg, "-hlsl") == 0 )
+ {
+ gOptions.mode = Mode::HLSL;
+ }
+ else if( strcmp(arg, "-slang") == 0 )
+ {
+ gOptions.mode = Mode::Slang;
+ }
+ else if( strcmp(arg, "-glsl-cross") == 0 )
+ {
+ gOptions.mode = Mode::GLSLCrossCompile;
+ }
+ else
+ {
+ fprintf(stderr, "unknown option '%s'\n", arg);
+ exit(1);
+ }
+ }
+
+ // any arguments left over were positional arguments
+ argCount = (int)(writeCursor - argv);
+ argCursor = argv;
+ argEnd = argCursor + argCount;
+
+ // first positional argument is source shader path
+ if( argCursor != argEnd )
+ {
+ gOptions.sourcePath = *argCursor++;
+ }
+
+ // any remaining arguments represent an error
+ if(argCursor != argEnd)
+ {
+ fprintf(stderr, "unexpected arguments\n");
+ exit(1);
+ }
+
+ *argc = 0;
+}
+
+} // renderer_test