finderrors.c
branchtrunk
changeset 224 4acaf8199665
parent 188 2b43d053d9cd
child 227 c6192a343fef
equal deleted inserted replaced
223:8df4e9545c87 224:4acaf8199665
    18 #include "gl.h"
    18 #include "gl.h"
    19 #include "glext.h"
    19 #include "glext.h"
    20 #endif
    20 #endif
    21 
    21 
    22 #define report printf
    22 #define report printf
    23 
       
    24 static int compile_shader(const char *fname, const MOJOSHADER_parseData *pd)
       
    25 {
       
    26     int retval = 1;
       
    27 
       
    28     #if FINDERRORS_COMPILE_SHADERS
       
    29     const GLenum shader_type = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? GL_FRAGMENT_SHADER_ARB : GL_VERTEX_SHADER_ARB;
       
    30     GLint shaderlen = (GLint) pd->output_len;
       
    31     GLhandleARB program = glCreateProgramObjectARB();
       
    32     GLhandleARB shader = glCreateShaderObjectARB(shader_type);
       
    33     GLint ok = 0;
       
    34     GLcharARB err[1024];
       
    35     GLsizei len = 0;
       
    36 
       
    37     retval = 0;
       
    38 
       
    39     glShaderSourceARB(shader, 1, (const GLcharARB **) &pd->output, &shaderlen);
       
    40     glCompileShaderARB(shader);
       
    41     glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &ok);
       
    42     if (!ok)
       
    43     {
       
    44         glGetInfoLogARB(shader, sizeof (err), &len, err);
       
    45         printf("FAIL: %s glsl compile: %s\n", fname, err);
       
    46     } // if
       
    47     else
       
    48     {
       
    49         glAttachObjectARB(program, shader);
       
    50         glLinkProgramARB(program);
       
    51         glGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &ok);
       
    52         if (!ok)
       
    53         {
       
    54             glGetInfoLogARB(program, sizeof (err), &len, err);
       
    55             printf("FAIL: %s glsl link: %s\n", fname, err);
       
    56         } // if
       
    57         else
       
    58         {
       
    59             retval = 1;
       
    60         } // else
       
    61     } // else
       
    62     glDeleteObjectARB(shader);
       
    63     glDeleteObjectARB(program);
       
    64     #endif
       
    65 
       
    66     return retval;
       
    67 } // compile_shader
       
    68 
       
    69 
    23 
    70 static int do_dir(const char *dname, const char *profile)
    24 static int do_dir(const char *dname, const char *profile)
    71 {
    25 {
    72     const int dirlen = strlen(dname) + 1;
    26     const int dirlen = strlen(dname) + 1;
    73     int total = 0;
    27     int total = 0;
   116             {
    70             {
   117                 report("FAIL: %s %s\n", fname, strerror(errno));
    71                 report("FAIL: %s %s\n", fname, strerror(errno));
   118                 continue;
    72                 continue;
   119             } // if
    73             } // if
   120 
    74 
       
    75             #if FINDERRORS_COMPILE_SHADERS
       
    76             MOJOSHADER_glShader *shader = MOJOSHADER_glCompileShader(buf, rc);
       
    77             if (shader == NULL)
       
    78                 report("FAIL: %s %s\n", fname, MOJOSHADER_glGetError());
       
    79             else
       
    80                 report("PASS: %s\n", fname);
       
    81             MOJOSHADER_glDeleteShader(shader);
       
    82             #else
   121             const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, buf, rc, 0, 0, 0);
    83             const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, buf, rc, 0, 0, 0);
   122             if (pd->error != NULL)
    84             if (pd->error != NULL)
   123                 report("FAIL: %s %s\n", fname, pd->error);
    85                 report("FAIL: %s %s\n", fname, pd->error);
   124             else
    86             else
   125             {
    87                 report("PASS: %s\n", fname);
   126                 if (compile_shader(fname, pd))
       
   127                     report("PASS: %s\n", fname);
       
   128             } // else
       
   129             MOJOSHADER_freeParseData(pd);
    88             MOJOSHADER_freeParseData(pd);
       
    89             #endif
   130         } // while
    90         } // while
   131         closedir(dirp);
    91         closedir(dirp);
   132     } // if
    92     } // if
   133 
    93 
   134     return total;
    94     return total;
   146         printf("\n\nUSAGE: %s <profile> [dir1] ... [dirN]\n\n", argv[0]);
   106         printf("\n\nUSAGE: %s <profile> [dir1] ... [dirN]\n\n", argv[0]);
   147     else
   107     else
   148     {
   108     {
   149         int total = 0;
   109         int total = 0;
   150         int i;
   110         int i;
       
   111         const char *profile = argv[1];
   151 
   112 
   152         #if FINDERRORS_COMPILE_SHADERS
   113         #if FINDERRORS_COMPILE_SHADERS
   153         SDL_Init(SDL_INIT_VIDEO);
   114         SDL_Init(SDL_INIT_VIDEO);
       
   115         SDL_GL_LoadLibrary(NULL);
   154         SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
   116         SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
   155         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
   117         glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
       
   118         MOJOSHADER_glInit(profile, SDL_GL_GetProcAddress, 0, 0, 0);
   156         #endif
   119         #endif
   157 
       
   158         const char *profile = argv[1];
       
   159 
   120 
   160         for (i = 2; i < argc; i++)
   121         for (i = 2; i < argc; i++)
   161             total += do_dir(argv[i], profile);
   122             total += do_dir(argv[i], profile);
   162 
   123 
   163         printf("Saw %d bytecode files.\n", total);
   124         printf("Saw %d bytecode files.\n", total);
   164 
   125 
   165         #if FINDERRORS_COMPILE_SHADERS
   126         #if FINDERRORS_COMPILE_SHADERS
       
   127         MOJOSHADER_glDeinit();
   166         SDL_Quit();
   128         SDL_Quit();
   167         #endif
   129         #endif
   168     } // else
   130     } // else
   169 
   131 
   170     return 0;
   132     return 0;