1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
// 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, "-glsl") == 0 )
{
gOptions.mode = Mode::GLSL;
}
else if( strcmp(arg, "-hlsl-rewrite") == 0 )
{
gOptions.mode = Mode::HLSLRewrite;
}
else if( strcmp(arg, "-glsl-rewrite") == 0 )
{
gOptions.mode = Mode::GLSLRewrite;
}
else if( strcmp(arg, "-slang") == 0 )
{
gOptions.mode = Mode::Slang;
}
else if( strcmp(arg, "-glsl-cross") == 0 )
{
gOptions.mode = Mode::GLSLCrossCompile;
}
else if( strcmp(arg, "-xslang") == 0 )
{
// This is an option that we want to pass along to Slang
if( argCursor == argEnd )
{
fprintf(stderr, "expected argument for '%s' option\n", arg);
exit(1);
}
if( gOptions.slangArgCount == kMaxSlangArgs )
{
fprintf(stderr, "maximum number of '%s' options exceeded (%d)\n", arg, kMaxSlangArgs);
exit(1);
}
gOptions.slangArgs[gOptions.slangArgCount++] = *argCursor++;
}
else if (strcmp(arg, "-compute") == 0)
{
gOptions.shaderType = ShaderProgramType::Compute;
}
else if (strcmp(arg, "-graphics") == 0)
{
gOptions.shaderType = ShaderProgramType::Graphics;
}
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
|