author | Ryan C. Gordon <icculus@icculus.org> |
Mon, 05 May 2008 02:50:19 -0400 | |
branch | trunk |
changeset 280 | 61b2abd9c927 |
parent 278 | 5c432d216078 |
child 438 | 73492129c1af |
permissions | -rw-r--r-- |
244 | 1 |
/** |
2 |
* MojoShader; generate shader programs from bytecode of compiled |
|
3 |
* Direct3D shaders. |
|
4 |
* |
|
5 |
* Please see the file LICENSE.txt in the source's root directory. |
|
6 |
* |
|
7 |
* This file written by Ryan C. Gordon. |
|
8 |
*/ |
|
9 |
||
7 | 10 |
#include <stdio.h> |
9 | 11 |
#include <stdlib.h> |
37 | 12 |
#include "mojoshader.h" |
7 | 13 |
|
254 | 14 |
#ifdef _MSC_VER |
15 |
#define snprintf _snprintf |
|
16 |
#endif |
|
46 | 17 |
|
50 | 18 |
#if MOJOSHADER_DEBUG_MALLOC |
46 | 19 |
static void *Malloc(int len) |
20 |
{ |
|
21 |
void *ptr = malloc(len + sizeof (int)); |
|
22 |
int *store = (int *) ptr; |
|
23 |
printf("malloc() %d bytes (%p)\n", len, ptr); |
|
24 |
if (ptr == NULL) return NULL; |
|
25 |
*store = len; |
|
26 |
return (void *) (store + 1); |
|
27 |
} // Malloc |
|
28 |
||
29 |
||
30 |
static void Free(void *_ptr) |
|
31 |
{ |
|
50 | 32 |
int *ptr = (((int *) _ptr) - 1); |
33 |
int len = *ptr; |
|
46 | 34 |
printf("free() %d bytes (%p)\n", len, ptr); |
35 |
free(ptr); |
|
36 |
} // Free |
|
37 |
#else |
|
38 |
#define Malloc NULL |
|
39 |
#define Free NULL |
|
40 |
#endif |
|
41 |
||
48 | 42 |
static const char *shader_type(const MOJOSHADER_shaderType s) |
46 | 43 |
{ |
44 |
switch (s) |
|
45 |
{ |
|
46 |
case MOJOSHADER_TYPE_UNKNOWN: return "unknown"; |
|
47 |
case MOJOSHADER_TYPE_PIXEL: return "pixel"; |
|
48 |
case MOJOSHADER_TYPE_VERTEX: return "vertex"; |
|
49 |
case MOJOSHADER_TYPE_GEOMETRY: return "geometry"; |
|
48 | 50 |
default: return "(bogus value?)"; |
46 | 51 |
} // switch |
52 |
||
48 | 53 |
return NULL; // shouldn't hit this. |
46 | 54 |
} // shader_type |
55 |
||
56 |
||
142
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
57 |
static int do_parse(const unsigned char *buf, const int len, const char *prof) |
46 | 58 |
{ |
59 |
const MOJOSHADER_parseData *pd; |
|
142
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
60 |
int retval = 0; |
46 | 61 |
|
97
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
62 |
pd = MOJOSHADER_parse(prof, buf, len, Malloc, Free, NULL); |
46 | 63 |
printf("PROFILE: %s\n", prof); |
64 |
if (pd->error != NULL) |
|
65 |
printf("ERROR: %s\n", pd->error); |
|
53 | 66 |
else |
67 |
{ |
|
142
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
68 |
retval = 1; |
53 | 69 |
printf("SHADER TYPE: %s\n", shader_type(pd->shader_type)); |
70 |
printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver); |
|
71 |
printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count); |
|
100
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
72 |
|
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
73 |
printf("ATTRIBUTES:"); |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
74 |
if (pd->attribute_count == 0) |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
75 |
printf(" (none.)\n"); |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
76 |
else |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
77 |
{ |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
78 |
int i; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
79 |
printf("\n"); |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
80 |
for (i = 0; i < pd->attribute_count; i++) |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
81 |
{ |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
82 |
static const char *usagenames[] = { |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
83 |
"position", "blendweight", "blendindices", "normal", |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
84 |
"psize", "texcoord", "tangent", "binormal", "tessfactor", |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
85 |
"positiont", "color", "fog", "depth", "sample" |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
86 |
}; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
87 |
const MOJOSHADER_attribute *a = &pd->attributes[i]; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
88 |
char numstr[16] = { 0 }; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
89 |
if (a->index != 0) |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
90 |
snprintf(numstr, sizeof (numstr), "%d", a->index); |
192
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
91 |
printf(" * %s%s", usagenames[(int) a->usage], numstr); |
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
92 |
if (a->name != NULL) |
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
93 |
printf(" (\"%s\")", a->name); |
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
94 |
printf("\n"); |
100
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
95 |
} // for |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
96 |
} // else |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
97 |
|
278
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
98 |
printf("CONSTANTS:"); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
99 |
if (pd->constant_count == 0) |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
100 |
printf(" (none.)\n"); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
101 |
else |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
102 |
{ |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
103 |
int i; |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
104 |
printf("\n"); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
105 |
for (i = 0; i < pd->constant_count; i++) |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
106 |
{ |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
107 |
static const char *typenames[] = { "float", "int", "bool" }; |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
108 |
const MOJOSHADER_constant *c = &pd->constants[i]; |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
109 |
printf(" * %d: %s (", c->index, typenames[(int) c->type]); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
110 |
if (c->type == MOJOSHADER_UNIFORM_FLOAT) |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
111 |
{ |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
112 |
printf("%f %f %f %f", c->value.f[0], c->value.f[1], |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
113 |
c->value.f[2], c->value.f[3]); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
114 |
} // if |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
115 |
else if (c->type == MOJOSHADER_UNIFORM_INT) |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
116 |
{ |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
117 |
printf("%d %d %d %d", c->value.i[0], c->value.i[1], |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
118 |
c->value.i[2], c->value.i[3]); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
119 |
} // else if |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
120 |
else if (c->type == MOJOSHADER_UNIFORM_BOOL) |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
121 |
{ |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
122 |
printf("%s", c->value.b ? "true" : "false"); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
123 |
} // else if |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
124 |
else |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
125 |
{ |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
126 |
printf("???"); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
127 |
} // else |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
128 |
printf(")\n"); |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
129 |
} // for |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
130 |
} // else |
5c432d216078
Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents:
254
diff
changeset
|
131 |
|
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
132 |
printf("UNIFORMS:"); |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
133 |
if (pd->uniform_count == 0) |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
134 |
printf(" (none.)\n"); |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
135 |
else |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
136 |
{ |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
137 |
int i; |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
138 |
printf("\n"); |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
139 |
for (i = 0; i < pd->uniform_count; i++) |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
140 |
{ |
94
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
141 |
static const char *typenames[] = { "float", "int", "bool" }; |
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
142 |
const MOJOSHADER_uniform *u = &pd->uniforms[i]; |
280
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
143 |
const char *arrayof = ""; |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
144 |
char arrayrange[64] = { '\0' }; |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
145 |
if (u->array_count > 0) |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
146 |
{ |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
147 |
arrayof = "array["; |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
148 |
snprintf(arrayrange, sizeof (arrayrange), "%d] ", |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
149 |
u->array_count); |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
150 |
} // if |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
151 |
|
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
152 |
printf(" * %d: %s%s%s", u->index, arrayof, arrayrange, |
61b2abd9c927
Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents:
278
diff
changeset
|
153 |
typenames[(int) u->type]); |
192
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
154 |
if (u->name != NULL) |
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
155 |
printf(" (\"%s\")", u->name); |
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
156 |
printf("\n"); |
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
157 |
} // for |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
158 |
} // else |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
53
diff
changeset
|
159 |
|
148
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
160 |
printf("SAMPLERS:"); |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
161 |
if (pd->sampler_count == 0) |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
162 |
printf(" (none.)\n"); |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
163 |
else |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
164 |
{ |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
165 |
int i; |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
166 |
printf("\n"); |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
167 |
for (i = 0; i < pd->sampler_count; i++) |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
168 |
{ |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
169 |
static const char *typenames[] = { "2d", "cube", "volume" }; |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
170 |
const MOJOSHADER_sampler *s = &pd->samplers[i]; |
192
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
171 |
printf(" * %d: %s", s->index, typenames[(int) s->type]); |
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
172 |
if (s->name != NULL) |
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
173 |
printf(" (\"%s\")", s->name); |
e7c864575d1c
Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents:
148
diff
changeset
|
174 |
printf("\n"); |
148
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
175 |
} // for |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
176 |
} // else |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
142
diff
changeset
|
177 |
|
53 | 178 |
if (pd->output != NULL) |
113
8ebf445c5305
Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
179 |
{ |
8ebf445c5305
Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
180 |
int i; |
8ebf445c5305
Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
181 |
printf("OUTPUT:\n"); |
8ebf445c5305
Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
182 |
for (i = 0; i < pd->output_len; i++) |
8ebf445c5305
Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
183 |
putchar((int) pd->output[i]); |
8ebf445c5305
Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
184 |
printf("\n"); |
8ebf445c5305
Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
185 |
} // if |
53 | 186 |
} // else |
46 | 187 |
printf("\n\n"); |
188 |
MOJOSHADER_freeParseData(pd); |
|
142
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
189 |
|
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
190 |
return retval; |
46 | 191 |
} // do_parse |
192 |
||
193 |
||
7 | 194 |
int main(int argc, char **argv) |
195 |
{ |
|
142
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
196 |
int retval = 0; |
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
197 |
|
47 | 198 |
printf("MojoShader testparse\n"); |
37 | 199 |
printf("Compiled against version %d\n", MOJOSHADER_VERSION); |
200 |
printf("Linked against version %d\n", MOJOSHADER_version()); |
|
47 | 201 |
printf("\n"); |
37 | 202 |
|
53 | 203 |
if (argc <= 2) |
204 |
printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]); |
|
47 | 205 |
else |
7 | 206 |
{ |
53 | 207 |
const char *profile = argv[1]; |
208 |
int i; |
|
209 |
||
210 |
for (i = 2; i < argc; i++) |
|
7 | 211 |
{ |
47 | 212 |
FILE *io = fopen(argv[i], "rb"); |
213 |
printf("FILE: %s\n", argv[i]); |
|
214 |
if (io == NULL) |
|
53 | 215 |
printf(" ... fopen('%s') failed.\n", argv[i]); |
47 | 216 |
else |
217 |
{ |
|
218 |
unsigned char *buf = (unsigned char *) malloc(1000000); |
|
219 |
int rc = fread(buf, 1, 1000000, io); |
|
220 |
fclose(io); |
|
142
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
221 |
if (!do_parse(buf, rc, profile)) |
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
222 |
retval = 1; |
47 | 223 |
free(buf); |
224 |
} // else |
|
225 |
} // for |
|
226 |
} // else |
|
7 | 227 |
|
142
e064b4cefb4e
Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents:
113
diff
changeset
|
228 |
return retval; |
7 | 229 |
} // main |
230 |
||
231 |
// end of testparse.c ... |
|
232 |