finderrors.c
author Ryan C. Gordon <icculus@icculus.org>
Tue, 26 Aug 2008 05:54:49 -0400
changeset 450 6a9faf398c1d
parent 437 a97a9b21087b
child 456 39a9be44129d
permissions -rw-r--r--
Allow overriding of swizzle on vertex attributes during bytecode parsing. This lets you compile a shader that you know wants ARGB color data, for example, when you're definitely going to pass it RGBA. The parser will handle this by changing the swizzle on that input register (including handling swizzling explicit swizzles), at no extra cost over not overriding swizzling; it does not generate any extra shader opcodes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
244
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     1
/**
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     3
 *  Direct3D shaders.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     4
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     6
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     7
 *  This file written by Ryan C. Gordon.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     8
 */
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
     9
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#include <stdio.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
#include <stdlib.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
#include <string.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
#include <stdarg.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#include <sys/types.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#include <errno.h>
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#include "mojoshader.h"
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    19
#if FINDERRORS_COMPILE_SHADERS
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    20
#include "SDL.h"
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    21
#endif
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    22
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    23
#ifdef _MSC_VER
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    24
#define WIN32_LEAN_AND_MEAN 1
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    25
#include <windows.h>
260
5b5fc8c5661b More Windows fixes: include malloc.h for alloca() support.
Ryan C. Gordon <icculus@icculus.org>
parents: 259
diff changeset
    26
#include <malloc.h>  // for alloca().
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    27
#define snprintf _snprintf
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    28
#else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    29
#include <dirent.h>
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    30
#endif
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 247
diff changeset
    31
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
    32
#define report printf
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
    33
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    34
static int do_file(const char *profile, const char *dname, const char *fn, int *total)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    35
{
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    36
    int do_quit = 0;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    37
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    38
    #if FINDERRORS_COMPILE_SHADERS
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    39
    SDL_Event e;  // pump event queue to keep OS happy.
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    40
    while (SDL_PollEvent(&e))
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    41
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    42
        if (e.type == SDL_QUIT)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    43
            do_quit = 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    44
    } // while
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    45
    SDL_GL_SwapBuffers();
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    46
    #endif
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    47
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    48
    if (do_quit)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    49
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    50
        report("FAIL: user requested quit!\n");
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    51
        return 0;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    52
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    53
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    54
    if (strstr(fn, ".bytecode") == NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    55
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    56
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    57
    (*total)++;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    58
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    59
    char *fname = (char *) alloca(strlen(fn) + strlen(dname) + 1);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    60
    sprintf(fname, "%s/%s", dname, fn);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    61
    FILE *io = fopen(fname, "rb");
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    62
    if (io == NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    63
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    64
        report("FAIL: %s fopen() failed.\n", fname);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    65
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    66
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    67
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    68
    static unsigned char buf[1024 * 256];
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    69
    int rc = fread(buf, 1, sizeof (buf), io);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    70
    fclose(io);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    71
    if (rc == -1)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    72
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    73
        report("FAIL: %s %s\n", fname, strerror(errno));
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    74
        return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    75
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    76
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    77
    #if FINDERRORS_COMPILE_SHADERS
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 437
diff changeset
    78
    MOJOSHADER_glShader *shader = MOJOSHADER_glCompileShader(buf, rc, NULL, 0);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    79
    if (shader == NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    80
        report("FAIL: %s %s\n", fname, MOJOSHADER_glGetError());
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    81
    else
437
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    82
    {
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    83
        const MOJOSHADER_parseData *pd = MOJOSHADER_glGetShaderParseData(shader);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    84
        MOJOSHADER_glShader *v = (pd->shader_type == MOJOSHADER_TYPE_VERTEX) ? shader : NULL;
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    85
        MOJOSHADER_glShader *p = (pd->shader_type == MOJOSHADER_TYPE_PIXEL) ? shader : NULL;
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    86
        MOJOSHADER_glProgram *program = MOJOSHADER_glLinkProgram(v, p);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    87
        if (program == NULL)
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    88
            report("FAIL: %s %s\n", fname, MOJOSHADER_glGetError());
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    89
        else
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    90
        {
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    91
            report("PASS: %s\n", fname);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    92
            MOJOSHADER_glDeleteProgram(program);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    93
        } // else
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    94
        MOJOSHADER_glDeleteShader(shader);
a97a9b21087b Also link programs when testing for shader compile errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 262
diff changeset
    95
    }
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    96
    #else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    97
    const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, buf, rc, 0, 0, 0);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    98
    if (pd->error != NULL)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
    99
        report("FAIL: %s %s\n", fname, pd->error);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   100
    else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   101
        report("PASS: %s\n", fname);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   102
    MOJOSHADER_freeParseData(pd);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   103
    #endif
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   104
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   105
    return 1;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   106
} // do_file
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   107
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   108
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   109
static int do_dir(const char *dname, const char *profile)
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
{
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
    int total = 0;
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   112
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   113
#ifdef _MSC_VER
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   114
    WIN32_FIND_DATA dent;
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   115
    HANDLE dirp = INVALID_HANDLE_VALUE;
259
68ba103e17e4 More Windows fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 258
diff changeset
   116
    FindFirstFileA(dname, &dent);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   117
    if (dirp != INVALID_HANDLE_VALUE)
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   118
    {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   119
        do
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   120
        {
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   121
            if (!do_file(profile, dname, dent.cFileName, &total))
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   122
                break;
259
68ba103e17e4 More Windows fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 258
diff changeset
   123
        } while (FindNextFileA(dirp, &dent) != 0);
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   124
        CloseHandle(dirp);
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   125
    } // if
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   126
#else
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   127
    struct dirent *dent = NULL;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    DIR *dirp = opendir(dname);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    if (dirp != NULL)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
    {
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
        while ((dent = readdir(dirp)) != NULL)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
        {
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   133
            if (!do_file(profile, dname, dent->d_name, &total))
172
f81c6cb14140 finderrors.c now pumps event queue and paints the SDL window.
Ryan C. Gordon <icculus@icculus.org>
parents: 170
diff changeset
   134
                break;
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
        } // while
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
        closedir(dirp);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    } // if
256
8339b461ef26 More Windows support.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   138
#endif
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    return total;
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
} // do_dir
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
int main(int argc, char **argv)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
{
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
    //printf("MojoShader finderrors\n");
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    //printf("Compiled against version %d\n", MOJOSHADER_VERSION);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    //printf("Linked against version %d\n", MOJOSHADER_version());
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
    //printf("\n");
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
    if (argc <= 2)
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
        printf("\n\nUSAGE: %s <profile> [dir1] ... [dirN]\n\n", argv[0]);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    else
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
    {
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
        int total = 0;
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   156
        int i;
224
4acaf8199665 Moved finderrors.c from GL calls to MOJOSHADER_gl* functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 188
diff changeset
   157
        const char *profile = argv[1];
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   159
        #if FINDERRORS_COMPILE_SHADERS
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   160
        SDL_Init(SDL_INIT_VIDEO);
224
4acaf8199665 Moved finderrors.c from GL calls to MOJOSHADER_gl* functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 188
diff changeset
   161
        SDL_GL_LoadLibrary(NULL);
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   162
        SDL_SetVideoMode(640, 480, 0, SDL_OPENGL);
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 260
diff changeset
   163
        printf("Best profile is '%s'\n", MOJOSHADER_glBestProfile(SDL_GL_GetProcAddress));
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   164
        MOJOSHADER_glContext *ctx;
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   165
        ctx = MOJOSHADER_glCreateContext(profile, SDL_GL_GetProcAddress, 0, 0, 0);
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   166
        if (ctx == NULL)
227
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   167
        {
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   168
            printf("MOJOSHADER_glCreateContext() fail: %s\n", MOJOSHADER_glGetError());
227
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   169
            SDL_Quit();
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   170
            return 1;
c6192a343fef Check return value from MOJOSHADER_glInit().
Ryan C. Gordon <icculus@icculus.org>
parents: 224
diff changeset
   171
        } // if
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 228
diff changeset
   172
        MOJOSHADER_glMakeContextCurrent(ctx);
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   173
        #endif
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   174
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
        for (i = 2; i < argc; i++)
170
9d71c08c756e Ripped out the multithreading from finderrors.c ...
Ryan C. Gordon <icculus@icculus.org>
parents: 169
diff changeset
   176
            total += do_dir(argv[i], profile);
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
        printf("Saw %d bytecode files.\n", total);
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   180
        #if FINDERRORS_COMPILE_SHADERS
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   181
        MOJOSHADER_glDestroyContext(ctx);
169
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   182
        SDL_Quit();
7e9d90724cf8 Push parsed shaders through GLSL compiler to see what breaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 153
diff changeset
   183
        #endif
153
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
    } // else
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    return 0;
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
} // main
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
// end of finderrors.c ...
4410cc03dade Added finderrors.c to revision control.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190