Skip to content

Latest commit

 

History

History
174 lines (145 loc) · 4.51 KB

finderrors.c

File metadata and controls

174 lines (145 loc) · 4.51 KB
 
1
2
3
4
5
6
7
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
Apr 22, 2008
Apr 22, 2008
8
#include <unistd.h>
9
10
11
#include "mojoshader.h"
Apr 22, 2008
Apr 22, 2008
12
13
14
#define FINDERRORS_COMPILE_SHADERS 1
#if FINDERRORS_COMPILE_SHADERS
Apr 22, 2008
Apr 22, 2008
15
#define GL_GLEXT_PROTOTYPES 1
Apr 24, 2008
Apr 24, 2008
16
#define GL_GLEXT_LEGACY 1
Apr 22, 2008
Apr 22, 2008
17
#include "SDL.h"
Apr 22, 2008
Apr 22, 2008
18
19
#include "gl.h"
#include "glext.h"
Apr 22, 2008
Apr 22, 2008
20
21
#endif
Apr 22, 2008
Apr 22, 2008
22
#define report printf
Apr 22, 2008
Apr 22, 2008
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
static int compile_shader(const char *fname, const MOJOSHADER_parseData *pd)
{
int retval = 1;
#if FINDERRORS_COMPILE_SHADERS
const GLenum shader_type = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? GL_FRAGMENT_SHADER_ARB : GL_VERTEX_SHADER_ARB;
GLint shaderlen = (GLint) pd->output_len;
GLhandleARB program = glCreateProgramObjectARB();
GLhandleARB shader = glCreateShaderObjectARB(shader_type);
GLint ok = 0;
GLcharARB err[1024];
GLsizei len = 0;
retval = 0;
glShaderSourceARB(shader, 1, (const GLcharARB **) &pd->output, &shaderlen);
glCompileShaderARB(shader);
glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &ok);
if (!ok)
{
glGetInfoLogARB(shader, sizeof (err), &len, err);
printf("FAIL: %s glsl compile: %s\n", fname, err);
} // if
else
{
glAttachObjectARB(program, shader);
glLinkProgramARB(program);
glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &ok);
if (!ok)
{
glGetInfoLogARB(program, sizeof (err), &len, err);
printf("FAIL: %s glsl link: %s\n", fname, err);
} // if
else
{
retval = 1;
} // else
} // else
glDeleteObjectARB(shader);
glDeleteObjectARB(program);
#endif
return retval;
} // compile_shader
Apr 22, 2008
Apr 22, 2008
70
static int do_dir(const char *dname, const char *profile)
71
72
73
74
75
76
{
const int dirlen = strlen(dname) + 1;
int total = 0;
DIR *dirp = opendir(dname);
if (dirp != NULL)
{
Apr 22, 2008
Apr 22, 2008
77
int do_quit = 0;
78
79
80
struct dirent *dent;
while ((dent = readdir(dirp)) != NULL)
{
Apr 22, 2008
Apr 22, 2008
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#if FINDERRORS_COMPILE_SHADERS
SDL_Event e; // pump event queue to keep OS happy.
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
do_quit = 1;
} // while
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapBuffers();
#endif
if (do_quit)
{
report("FAIL: user requested quit!\n");
break;
} // if
98
99
100
101
if (strstr(dent->d_name, ".bytecode") == NULL)
continue;
total++;
Apr 22, 2008
Apr 22, 2008
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
char *fname = (char *) alloca(strlen(dent->d_name) + dirlen);
sprintf(fname, "%s/%s", dname, dent->d_name);
FILE *io = fopen(fname, "rb");
if (io == NULL)
{
report("FAIL: %s fopen() failed.\n", fname);
continue;
} // if
static unsigned char buf[1024 * 256];
int rc = fread(buf, 1, sizeof (buf), io);
fclose(io);
if (rc == -1)
{
report("FAIL: %s %s\n", fname, strerror(errno));
continue;
} // if
const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, buf, rc, 0, 0, 0);
if (pd->error != NULL)
report("FAIL: %s %s\n", fname, pd->error);
else
{
if (compile_shader(fname, pd))
report("PASS: %s\n", fname);
} // else
MOJOSHADER_freeParseData(pd);
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
} // while
closedir(dirp);
} // if
return total;
} // do_dir
int main(int argc, char **argv)
{
//printf("MojoShader finderrors\n");
//printf("Compiled against version %d\n", MOJOSHADER_VERSION);
//printf("Linked against version %d\n", MOJOSHADER_version());
//printf("\n");
if (argc <= 2)
printf("\n\nUSAGE: %s <profile> [dir1] ... [dirN]\n\n", argv[0]);
else
{
int total = 0;
Apr 22, 2008
Apr 22, 2008
150
int i;
151
Apr 22, 2008
Apr 22, 2008
152
153
154
#if FINDERRORS_COMPILE_SHADERS
SDL_Init(SDL_INIT_VIDEO);
SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
Apr 22, 2008
Apr 22, 2008
155
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Apr 22, 2008
Apr 22, 2008
156
157
#endif
Apr 22, 2008
Apr 22, 2008
158
const char *profile = argv[1];
159
160
for (i = 2; i < argc; i++)
Apr 22, 2008
Apr 22, 2008
161
total += do_dir(argv[i], profile);
162
163
164
printf("Saw %d bytecode files.\n", total);
Apr 22, 2008
Apr 22, 2008
165
166
167
#if FINDERRORS_COMPILE_SHADERS
SDL_Quit();
#endif
168
169
170
171
172
173
} // else
return 0;
} // main
// end of finderrors.c ...