Skip to content

Latest commit

 

History

History
147 lines (124 loc) · 3.88 KB

finderrors.c

File metadata and controls

147 lines (124 loc) · 3.88 KB
 
Apr 29, 2008
Apr 29, 2008
1
2
3
4
5
6
7
8
9
/**
* MojoShader; generate shader programs from bytecode of compiled
* Direct3D shaders.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
10
11
12
13
14
15
16
#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
17
#include <unistd.h>
18
19
20
#include "mojoshader.h"
Apr 22, 2008
Apr 22, 2008
21
22
23
24
25
26
#define FINDERRORS_COMPILE_SHADERS 1
#if FINDERRORS_COMPILE_SHADERS
#include "SDL.h"
#endif
Apr 22, 2008
Apr 22, 2008
27
#define report printf
Apr 22, 2008
Apr 22, 2008
28
Apr 22, 2008
Apr 22, 2008
29
static int do_dir(const char *dname, const char *profile)
30
31
32
33
34
35
{
const int dirlen = strlen(dname) + 1;
int total = 0;
DIR *dirp = opendir(dname);
if (dirp != NULL)
{
Apr 22, 2008
Apr 22, 2008
36
int do_quit = 0;
37
38
39
struct dirent *dent;
while ((dent = readdir(dirp)) != NULL)
{
Apr 22, 2008
Apr 22, 2008
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#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
SDL_GL_SwapBuffers();
#endif
if (do_quit)
{
report("FAIL: user requested quit!\n");
break;
} // if
56
57
58
59
if (strstr(dent->d_name, ".bytecode") == NULL)
continue;
total++;
Apr 22, 2008
Apr 22, 2008
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
Apr 27, 2008
Apr 27, 2008
79
80
81
82
83
84
85
86
#if FINDERRORS_COMPILE_SHADERS
MOJOSHADER_glShader *shader = MOJOSHADER_glCompileShader(buf, rc);
if (shader == NULL)
report("FAIL: %s %s\n", fname, MOJOSHADER_glGetError());
else
report("PASS: %s\n", fname);
MOJOSHADER_glDeleteShader(shader);
#else
Apr 22, 2008
Apr 22, 2008
87
88
89
90
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
Apr 27, 2008
Apr 27, 2008
91
report("PASS: %s\n", fname);
Apr 22, 2008
Apr 22, 2008
92
MOJOSHADER_freeParseData(pd);
Apr 27, 2008
Apr 27, 2008
93
#endif
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
} // 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
114
int i;
Apr 27, 2008
Apr 27, 2008
115
const char *profile = argv[1];
116
Apr 22, 2008
Apr 22, 2008
117
118
#if FINDERRORS_COMPILE_SHADERS
SDL_Init(SDL_INIT_VIDEO);
Apr 27, 2008
Apr 27, 2008
119
SDL_GL_LoadLibrary(NULL);
Apr 22, 2008
Apr 22, 2008
120
SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
Apr 28, 2008
Apr 28, 2008
121
MOJOSHADER_glContext *ctx;
Apr 28, 2008
Apr 28, 2008
122
ctx = MOJOSHADER_glCreateContext(profile, SDL_GL_GetProcAddress, 0, 0, 0);
Apr 28, 2008
Apr 28, 2008
123
if (ctx == NULL)
Apr 27, 2008
Apr 27, 2008
124
{
Apr 28, 2008
Apr 28, 2008
125
printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
Apr 27, 2008
Apr 27, 2008
126
127
128
SDL_Quit();
return 1;
} // if
Apr 28, 2008
Apr 28, 2008
129
MOJOSHADER_glMakeContextCurrent(ctx);
Apr 22, 2008
Apr 22, 2008
130
131
#endif
132
for (i = 2; i < argc; i++)
Apr 22, 2008
Apr 22, 2008
133
total += do_dir(argv[i], profile);
134
135
136
printf("Saw %d bytecode files.\n", total);
Apr 22, 2008
Apr 22, 2008
137
#if FINDERRORS_COMPILE_SHADERS
Apr 28, 2008
Apr 28, 2008
138
MOJOSHADER_glDestroyContext(ctx);
Apr 22, 2008
Apr 22, 2008
139
140
SDL_Quit();
#endif
141
142
143
144
145
146
} // else
return 0;
} // main
// end of finderrors.c ...