utils/testparse.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 22 May 2011 03:32:10 -0400
changeset 1019 e8988ca01c6d
parent 902 cff5841d29e7
child 1028 74e7ee46ac93
permissions -rw-r--r--
Initial work on parsing binary Effects files.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
244
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     1
/**
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     3
 *  Direct3D shaders.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     4
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
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: 192
diff changeset
     6
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     7
 *  This file written by Ryan C. Gordon.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     8
 */
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     9
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    10
#include <stdio.h>
9
aea1b254e6a5 [svn] Patched to compile.
icculus
parents: 7
diff changeset
    11
#include <stdlib.h>
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
    12
#include "mojoshader.h"
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    13
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    14
#ifdef _MSC_VER
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    15
#define snprintf _snprintf
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    16
#endif
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    17
50
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    18
#if MOJOSHADER_DEBUG_MALLOC
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    19
static void *Malloc(int len)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    20
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    21
    void *ptr = malloc(len + sizeof (int));
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    22
    int *store = (int *) ptr;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    23
    printf("malloc() %d bytes (%p)\n", len, ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    24
    if (ptr == NULL) return NULL;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    25
    *store = len;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    26
    return (void *) (store + 1);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    27
} // Malloc
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    28
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    29
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    30
static void Free(void *_ptr)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    31
{
50
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    32
    int *ptr = (((int *) _ptr) - 1);
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    33
    int len = *ptr;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    34
    printf("free() %d bytes (%p)\n", len, ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    35
    free(ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    36
} // Free
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    37
#else
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    38
#define Malloc NULL
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    39
#define Free NULL
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    40
#endif
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    41
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    42
static inline void do_indent(const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    43
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    44
    unsigned int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    45
    for (i = 0; i < indent; i++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    46
        printf("    ");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    47
}
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    48
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    49
#define INDENT() do { if (indent) { do_indent(indent); } } while (0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    50
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    51
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    52
static const char *shader_type(const MOJOSHADER_shaderType s)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    53
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    54
    switch (s)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    55
    {
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    56
        case MOJOSHADER_TYPE_UNKNOWN: return "unknown";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    57
        case MOJOSHADER_TYPE_PIXEL: return "pixel";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    58
        case MOJOSHADER_TYPE_VERTEX: return "vertex";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    59
        case MOJOSHADER_TYPE_GEOMETRY: return "geometry";
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    60
        default: return "(bogus value?)";
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    61
    } // switch
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    62
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    63
    return NULL;  // shouldn't hit this.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    64
} // shader_type
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    65
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    66
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    67
static void print_shader(const char *fname, const MOJOSHADER_parseData *pd,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    68
                         unsigned int indent)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    69
{
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    70
    INDENT(); printf("PROFILE: %s\n", pd->profile);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    71
    if (pd->error_count > 0)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    72
    {
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    73
        int i;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    74
        for (i = 0; i < pd->error_count; i++)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    75
        {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    76
            const MOJOSHADER_error *err = &pd->errors[i];
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    77
            INDENT();
577
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
    78
            printf("%s:%d: ERROR: %s\n",
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    79
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    80
                    err->error_position, err->error);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    81
        } // for
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
    82
    } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    83
    else
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
    84
    {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    85
        INDENT(); printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    86
        INDENT(); printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    87
        INDENT(); 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
    88
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    89
        INDENT(); printf("ATTRIBUTES:");
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    90
        if (pd->attribute_count == 0)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    91
            printf(" (none.)\n");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    92
        else
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    93
        {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    94
            int i;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    95
            printf("\n");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    96
            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
    97
            {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    98
                static const char *usagenames[] = {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    99
                    "position", "blendweight", "blendindices", "normal",
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   100
                    "psize", "texcoord", "tangent", "binormal", "tessfactor",
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   101
                    "positiont", "color", "fog", "depth", "sample"
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   102
                };
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   103
                const MOJOSHADER_attribute *a = &pd->attributes[i];
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   104
                char numstr[16] = { 0 };
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   105
                if (a->index != 0)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   106
                    snprintf(numstr, sizeof (numstr), "%d", a->index);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   107
                INDENT();
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   108
                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
   109
                if (a->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   110
                    printf(" (\"%s\")", a->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   111
                printf("\n");
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   112
            } // for
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   113
        } // else
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   114
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   115
        INDENT(); printf("CONSTANTS:");
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   116
        if (pd->constant_count == 0)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   117
            printf(" (none.)\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   118
        else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   119
        {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   120
            int i;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   121
            printf("\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   122
            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
   123
            {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   124
                static const char *typenames[] = { "float", "int", "bool" };
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   125
                const MOJOSHADER_constant *c = &pd->constants[i];
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   126
                INDENT(); 
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   127
                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
   128
                if (c->type == MOJOSHADER_UNIFORM_FLOAT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   129
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   130
                    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
   131
                                          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
   132
                } // if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   133
                else if (c->type == MOJOSHADER_UNIFORM_INT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   134
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   135
                    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
   136
                                          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
   137
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   138
                else if (c->type == MOJOSHADER_UNIFORM_BOOL)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   139
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   140
                    printf("%s", c->value.b ? "true" : "false");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   141
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   142
                else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   143
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   144
                    printf("???");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   145
                } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   146
                printf(")\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   147
            } // for
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   148
        } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   149
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   150
        INDENT(); printf("UNIFORMS:");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   151
        if (pd->uniform_count == 0)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   152
            printf(" (none.)\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   153
        else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   154
        {
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   155
            int i;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   156
            printf("\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   157
            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
   158
            {
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   159
                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
   160
                const MOJOSHADER_uniform *u = &pd->uniforms[i];
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   161
                const char *arrayof = "";
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   162
                const char *constant = u->constant ? "const " : "";
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   163
                char arrayrange[64] = { '\0' };
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   164
                if (u->array_count > 0)
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   165
                {
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   166
                    arrayof = "array[";
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   167
                    snprintf(arrayrange, sizeof (arrayrange), "%d] ",
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   168
                             u->array_count);
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   169
                } // if
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   170
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   171
                INDENT();
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   172
                printf("    * %d: %s%s%s%s", u->index, constant, arrayof,
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   173
                        arrayrange, typenames[(int) u->type]);
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   174
                if (u->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   175
                    printf(" (\"%s\")", u->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   176
                printf("\n");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   177
            } // for
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   178
        } // else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   179
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   180
        INDENT(); printf("SAMPLERS:");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   181
        if (pd->sampler_count == 0)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   182
            printf(" (none.)\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   183
        else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   184
        {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   185
            int i;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   186
            printf("\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   187
            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
   188
            {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   189
                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
   190
                const MOJOSHADER_sampler *s = &pd->samplers[i];
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   191
                INDENT();
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   192
                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
   193
                if (s->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   194
                    printf(" (\"%s\")", s->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   195
                printf("\n");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   196
            } // for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   197
        } // else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   198
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   199
        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
   200
        {
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
   201
            int i;
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   202
            INDENT();
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
   203
            printf("OUTPUT:\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   204
            indent++;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   205
            INDENT();
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
   206
            for (i = 0; i < pd->output_len; i++)
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   207
            {
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
   208
                putchar((int) pd->output[i]);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   209
                if (pd->output[i] == '\n')
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   210
                    INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   211
            } // for
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
   212
            printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   213
            indent--;
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
   214
        } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   215
    } // else
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   216
    printf("\n\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   217
} // print_shader
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   218
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   219
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   220
static void print_effect(const char *fname, const MOJOSHADER_effect *effect,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   221
                         const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   222
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   223
    INDENT(); printf("PROFILE: %s\n", effect->profile);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   224
    printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   225
    if (effect->error_count > 0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   226
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   227
        int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   228
        for (i = 0; i < effect->error_count; i++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   229
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   230
            const MOJOSHADER_error *err = &effect->errors[i];
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   231
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   232
            printf("%s:%d: ERROR: %s\n",
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   233
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   234
                    err->error_position, err->error);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   235
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   236
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   237
    else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   238
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   239
        int i, j, k;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   240
        const MOJOSHADER_effectTechnique *technique = effect->techniques;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   241
        const MOJOSHADER_effectTexture *texture = effect->textures;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   242
        const MOJOSHADER_effectShader *shader = effect->shaders;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   243
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   244
        for (i = 0; i < effect->technique_count; i++, technique++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   245
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   246
            const MOJOSHADER_effectPass *pass = technique->passes;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   247
            INDENT(); printf("TECHNIQUE #%d ('%s'):\n", i, technique->name);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   248
            for (j = 0; j < technique->pass_count; j++, pass++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   249
            {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   250
                const MOJOSHADER_effectState *state = pass->states;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   251
                INDENT(); printf("    PASS #%d ('%s'):\n", j, pass->name);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   252
                for (k = 0; k < pass->state_count; k++, state++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   253
                {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   254
                    INDENT(); printf("        STATE 0x%X\n", state->type);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   255
                } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   256
            } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   257
            printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   258
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   259
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   260
        for (i = 0; i < effect->texture_count; i++, texture++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   261
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   262
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   263
            printf("TEXTURE #%d ('%s'): %u\n", i,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   264
                    texture->name, texture->param);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   265
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   266
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   267
        printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   268
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   269
        for (i = 0; i < effect->shader_count; i++, shader++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   270
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   271
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   272
            printf("SHADER #%d: technique %u, pass %u\n", i,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   273
                    shader->technique, shader->pass);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   274
            print_shader(fname, shader->shader, indent + 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   275
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   276
    } // else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   277
} // print_effect
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   278
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   279
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   280
static int do_parse(const char *fname, const unsigned char *buf,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   281
                    const int len, const char *prof)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   282
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   283
    int retval = 0;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   284
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   285
    // magic for an effects file (!!! FIXME: I _think_).
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   286
    if ( (buf[0] == 0x01) && (buf[1] == 0x09) &&
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   287
         (buf[2] == 0xFF) && (buf[3] == 0xFE) )
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   288
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   289
        const MOJOSHADER_effect *effect;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   290
        effect = MOJOSHADER_parseEffect(prof, buf, len, 0, 0, Malloc, Free, 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   291
        retval = (effect->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   292
        printf("EFFECT: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   293
        print_effect(fname, effect, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   294
        MOJOSHADER_freeEffect(effect);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   295
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   296
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   297
    else  // do it as a regular compiled shader.
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   298
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   299
        const MOJOSHADER_parseData *pd;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   300
        pd = MOJOSHADER_parse(prof, buf, len, NULL, 0, Malloc, Free, NULL);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   301
        retval = (pd->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   302
        printf("SHADER: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   303
        print_shader(fname, pd, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   304
        MOJOSHADER_freeParseData(pd);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   305
    } // else
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   306
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   307
    return retval;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   308
} // do_parse
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   309
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   310
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   311
int main(int argc, char **argv)
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   312
{
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   313
    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
   314
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   315
    printf("MojoShader testparse\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   316
    printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   317
    printf("Linked against changeset %s\n", MOJOSHADER_changeset());
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   318
    printf("\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   319
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   320
    if (argc <= 2)
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   321
        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   322
    else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   323
    {
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   324
        const char *profile = argv[1];
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   325
        int i;
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   326
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   327
        for (i = 2; i < argc; i++)
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   328
        {
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   329
            FILE *io = fopen(argv[i], "rb");
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   330
            if (io == NULL)
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   331
                printf(" ... fopen('%s') failed.\n", argv[i]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   332
            else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   333
            {
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   334
                unsigned char *buf = (unsigned char *) malloc(1000000);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   335
                int rc = fread(buf, 1, 1000000, io);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   336
                fclose(io);
902
cff5841d29e7 Report actual filename in errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
   337
                if (!do_parse(argv[i], buf, rc, profile))
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   338
                    retval = 1;
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   339
                free(buf);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   340
            } // else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   341
        } // for
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   342
    } // else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   343
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   344
    return retval;
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   345
} // main
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   346
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   347
// end of testparse.c ...
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   348