author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 12 Feb 2009 01:47:35 -0500 | |
changeset 573 | 1cd1d99a79cb |
parent 536 | 5af65fe6e917 |
child 577 | bec531dd448e |
permissions | -rw-r--r-- |
390
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/** |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
* MojoShader; generate shader programs from bytecode of compiled |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* Direct3D shaders. |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
* |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* Please see the file LICENSE.txt in the source's root directory. |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 |
* |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
* This file written by Ryan C. Gordon. |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
*/ |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 |
#include <stdio.h> |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
#include <stdlib.h> |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 |
#include "mojoshader.h" |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 |
static int do_parse(const unsigned char *buf, const int len, const char *prof) |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 |
{ |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 |
const MOJOSHADER_parseData *pd; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 |
int retval = 0; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
|
450
6a9faf398c1d
Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
390
diff
changeset
|
19 |
pd = MOJOSHADER_parse(prof, buf, len, NULL, 0, NULL, NULL, NULL); |
536
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
20 |
if (pd->error_count > 0) |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
21 |
{ |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
22 |
int i; |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
23 |
for (i = 0; i < pd->error_count; i++) |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
24 |
{ |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
25 |
printf("ERROR: (line %d) %s\n", |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
26 |
pd->errors[i].error_position, |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
27 |
pd->errors[i].error); |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
28 |
} // for |
5af65fe6e917
Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents:
475
diff
changeset
|
29 |
} // if |
390
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 |
else |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 |
{ |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
retval = 1; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 |
if (pd->output != NULL) |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
{ |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
int i; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 |
for (i = 0; i < pd->output_len; i++) |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 |
putchar((int) pd->output[i]); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 |
printf("\n"); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
} // if |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 |
} // else |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
printf("\n\n"); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
MOJOSHADER_freeParseData(pd); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 |
return retval; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 |
} // do_parse |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 |
int main(int argc, char **argv) |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 |
{ |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 |
int retval = 0; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
if (argc <= 2) |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 |
printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 |
else |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 |
{ |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
const char *profile = argv[1]; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 |
int i; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 |
for (i = 2; i < argc; i++) |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
{ |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 |
FILE *io = fopen(argv[i], "rb"); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 |
if (io == NULL) |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 |
printf(" ... fopen('%s') failed.\n", argv[i]); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
else |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 |
{ |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
unsigned char *buf = (unsigned char *) malloc(1000000); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 |
int rc = fread(buf, 1, 1000000, io); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
fclose(io); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
if (!do_parse(buf, rc, profile)) |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |
retval = 1; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 |
free(buf); |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 |
} // else |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 |
} // for |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 |
} // else |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 |
return retval; |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 |
} // main |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
|
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
79 |
// end of testoutput.c ... |
4effa7e6b49c
Added testoutput program for outputting just the generated shaders.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
80 |