utils/testparse.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 30 May 2011 16:41:22 -0400
changeset 1030 a407c516e325
parent 1028 74e7ee46ac93
child 1032 464f38a2fb70
permissions -rw-r--r--
Initial work on preshader support. Parses and outputs in testparse. Some gaps in the reverse engineering still, and probably some bugs still, too. Doesn't actually USE the preshaders yet, but now the data is available to us.
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
1028
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    67
static void print_typeinfo(const MOJOSHADER_symbolTypeInfo *info,
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    68
                           unsigned int indent)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    69
{
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    70
    static const char *symclasses[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    71
        "scalar", "vector", "row-major matrix",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    72
        "column-major matrix", "object", "struct"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    73
    };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    74
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    75
    static const char *symtypes[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    76
        "void", "bool", "int", "float", "string", "texture",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    77
        "texture1d", "texture2d", "texture3d", "texturecube",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    78
        "sampler", "sampler1d", "sampler2d", "sampler3d",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    79
        "samplercube", "pixelshader", "vertexshader", "unsupported"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    80
    };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    81
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    82
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    83
    printf("      symbol class %s\n", symclasses[info->parameter_class]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    84
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    85
    printf("      symbol type %s\n", symtypes[info->parameter_type]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    86
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    87
    printf("      rows %u\n", info->rows);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    88
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    89
    printf("      columns %u\n", info->columns);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    90
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    91
    printf("      elements %u\n", info->elements);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    92
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    93
    if (info->member_count > 0)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    94
    {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    95
        int i;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    96
        INDENT(); printf("      MEMBERS:\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    97
        for (i = 0; i < info->member_count; i++)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    98
        {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    99
            const MOJOSHADER_symbolStructMember *member = &info->members[i];
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   100
            INDENT(); printf("      MEMBERS:\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   101
            indent++;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   102
            INDENT(); printf("      * %d: \"%s\"\n", i, member->name);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   103
            print_typeinfo(&member->info, indent);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   104
            indent--;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   105
        } // for
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   106
    } // if
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   107
} // print_typeinfo
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   108
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   109
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   110
static void print_preshader(const MOJOSHADER_preshader *preshader,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   111
                            const int indent)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   112
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   113
    MOJOSHADER_preshaderInstruction *inst = preshader->instructions;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   114
    int i, j, k;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   115
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   116
    static const char *opcodestr[] = {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   117
        "nop", "mov", "cmp", "dot", "dot", "neg", "max", "max",
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   118
        "cmplt", "cmplt", "cmpge", "cmpge", "rcp", "frc", "exp",
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   119
        "add", "add", "mul", "mul", "log", "rsq", "sin", "cos"
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   120
    };
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   121
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   122
    static char mask[] = { 'x', 'y', 'z', 'w' };
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   123
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   124
    INDENT(); printf("PRESHADER:\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   125
    for (i = 0; i < preshader->instruction_count; i++, inst++)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   126
    {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   127
        const MOJOSHADER_preshaderOperand *operand = inst->operands;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   128
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   129
        INDENT();
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   130
        printf("    %s", opcodestr[inst->opcode]);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   131
        for (j = 0; j < inst->operand_count; j++, operand++)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   132
        {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   133
            const int elems = inst->element_count;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   134
            int isscalar = 0;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   135
            if (j == 1)  // This is probably wrong.
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   136
            {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   137
                switch (inst->opcode)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   138
                {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   139
                    case MOJOSHADER_PRESHADEROP_DOT_SCALAR:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   140
                    case MOJOSHADER_PRESHADEROP_MAX_SCALAR:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   141
                    case MOJOSHADER_PRESHADEROP_CMPLT_SCALAR:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   142
                    case MOJOSHADER_PRESHADEROP_CMPGE_SCALAR:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   143
                    case MOJOSHADER_PRESHADEROP_ADD_SCALAR:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   144
                    case MOJOSHADER_PRESHADEROP_MUL_SCALAR:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   145
                        isscalar = 1; break;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   146
                    default:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   147
                        isscalar = 0; break;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   148
                } // switch
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   149
            } // if
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   150
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   151
            if (j != 0)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   152
                printf(",");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   153
            printf(" ");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   154
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   155
            switch (operand->type)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   156
            {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   157
                case MOJOSHADER_PRESHADEROPERAND_LITERAL:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   158
                {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   159
                    const double *lit = &preshader->literals[operand->index];
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   160
                    printf("(");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   161
                    if (isscalar)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   162
                    {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   163
                        const double val = *lit;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   164
                        for (k = 0; k < elems-1; k++)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   165
                            printf("%g, ", val);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   166
                        printf("%g)", val);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   167
                    } // if
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   168
                    else
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   169
                    {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   170
                        for (k = 0; k < elems-1; k++, lit++)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   171
                            printf("%g, ", *lit);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   172
                        printf("%g)", *lit);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   173
                    } // else
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   174
                    break;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   175
                } // case
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   176
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   177
                case MOJOSHADER_PRESHADEROPERAND_INPUT:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   178
                case MOJOSHADER_PRESHADEROPERAND_OUTPUT:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   179
                case MOJOSHADER_PRESHADEROPERAND_TEMP:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   180
                {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   181
                    int idx = operand->index % 4;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   182
                    char regch = 'c';
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   183
                    if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   184
                        regch = 'r';
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   185
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   186
                    printf("%c%d", regch, operand->index / 4);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   187
                    if (isscalar)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   188
                        printf(".%c", mask[idx]);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   189
                    else if (elems != 4)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   190
                    {
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   191
                        printf(".");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   192
                        for (k = 0; k < elems; k++)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   193
                            printf("%c", mask[idx++]);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   194
                    } // else if
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   195
                    break;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   196
                } // case
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   197
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   198
                default:
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   199
                    printf("[???{%d, %u}???]",
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   200
                            (int) operand->type, operand->index);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   201
                    break;
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   202
            } // switch
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   203
        } // for
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   204
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   205
        printf("\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   206
    } // for
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   207
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   208
    printf("\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   209
} // print_preshader
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   210
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   211
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   212
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
   213
                         unsigned int indent)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   214
{
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   215
    INDENT(); printf("PROFILE: %s\n", pd->profile);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   216
    if (pd->error_count > 0)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   217
    {
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   218
        int i;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   219
        for (i = 0; i < pd->error_count; i++)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   220
        {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   221
            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
   222
            INDENT();
577
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
   223
            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
   224
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   225
                    err->error_position, err->error);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   226
        } // for
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   227
    } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   228
    else
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   229
    {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   230
        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
   231
        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
   232
        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
   233
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   234
        INDENT(); printf("ATTRIBUTES:");
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   235
        if (pd->attribute_count == 0)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   236
            printf(" (none.)\n");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   237
        else
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   238
        {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   239
            int i;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   240
            printf("\n");
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   241
            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
   242
            {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   243
                static const char *usagenames[] = {
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   244
                    "position", "blendweight", "blendindices", "normal",
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   245
                    "psize", "texcoord", "tangent", "binormal", "tessfactor",
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   246
                    "positiont", "color", "fog", "depth", "sample"
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   247
                };
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   248
                const MOJOSHADER_attribute *a = &pd->attributes[i];
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   249
                char numstr[16] = { 0 };
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   250
                if (a->index != 0)
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   251
                    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
   252
                INDENT();
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   253
                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
   254
                if (a->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   255
                    printf(" (\"%s\")", a->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   256
                printf("\n");
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   257
            } // for
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   258
        } // else
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   259
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   260
        INDENT(); printf("CONSTANTS:");
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   261
        if (pd->constant_count == 0)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   262
            printf(" (none.)\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   263
        else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   264
        {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   265
            int i;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   266
            printf("\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   267
            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
   268
            {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   269
                static const char *typenames[] = { "float", "int", "bool" };
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   270
                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
   271
                INDENT(); 
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   272
                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
   273
                if (c->type == MOJOSHADER_UNIFORM_FLOAT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   274
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   275
                    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
   276
                                          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
   277
                } // if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   278
                else if (c->type == MOJOSHADER_UNIFORM_INT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   279
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   280
                    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
   281
                                          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
   282
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   283
                else if (c->type == MOJOSHADER_UNIFORM_BOOL)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   284
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   285
                    printf("%s", c->value.b ? "true" : "false");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   286
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   287
                else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   288
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   289
                    printf("???");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   290
                } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   291
                printf(")\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   292
            } // for
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   293
        } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   294
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   295
        INDENT(); printf("UNIFORMS:");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   296
        if (pd->uniform_count == 0)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   297
            printf(" (none.)\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   298
        else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   299
        {
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   300
            int i;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   301
            printf("\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   302
            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
   303
            {
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   304
                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
   305
                const MOJOSHADER_uniform *u = &pd->uniforms[i];
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   306
                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
   307
                const char *constant = u->constant ? "const " : "";
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   308
                char arrayrange[64] = { '\0' };
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   309
                if (u->array_count > 0)
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   310
                {
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   311
                    arrayof = "array[";
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   312
                    snprintf(arrayrange, sizeof (arrayrange), "%d] ",
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   313
                             u->array_count);
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   314
                } // if
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   315
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   316
                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
   317
                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
   318
                        arrayrange, typenames[(int) u->type]);
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   319
                if (u->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   320
                    printf(" (\"%s\")", u->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   321
                printf("\n");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   322
            } // for
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   323
        } // else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   324
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   325
        INDENT(); printf("SAMPLERS:");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   326
        if (pd->sampler_count == 0)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   327
            printf(" (none.)\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   328
        else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   329
        {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   330
            int i;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   331
            printf("\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   332
            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
   333
            {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   334
                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
   335
                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
   336
                INDENT();
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   337
                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
   338
                if (s->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   339
                    printf(" (\"%s\")", s->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   340
                printf("\n");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   341
            } // for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   342
        } // else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   343
1028
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   344
        INDENT(); printf("SYMBOLS:");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   345
        if (pd->symbol_count == 0)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   346
            printf(" (none.)\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   347
        else
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   348
        {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   349
            int i;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   350
            printf("\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   351
            for (i = 0; i < pd->symbol_count; i++)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   352
            {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   353
                static const char *regsets[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   354
                    "bool", "int4", "float4", "sampler"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   355
                };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   356
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   357
                const MOJOSHADER_symbol *sym = &pd->symbols[i];
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   358
                INDENT(); printf("    * %d: \"%s\"\n", i, sym->name);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   359
                INDENT(); printf("      register set %s\n", regsets[sym->register_set]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   360
                INDENT(); printf("      register index %u\n", sym->register_index);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   361
                INDENT(); printf("      register count %u\n", sym->register_count);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   362
                print_typeinfo(&sym->info, indent);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   363
            } // for
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   364
            printf("\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   365
        } // else
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   366
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   367
        if (pd->preshader != NULL)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   368
            print_preshader(pd->preshader, indent);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   369
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   370
        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
   371
        {
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
   372
            int i;
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   373
            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
   374
            printf("OUTPUT:\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   375
            indent++;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   376
            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
   377
            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
   378
            {
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
   379
                putchar((int) pd->output[i]);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   380
                if (pd->output[i] == '\n')
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   381
                    INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   382
            } // 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
   383
            printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   384
            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
   385
        } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   386
    } // else
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   387
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   388
    printf("\n\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   389
} // print_shader
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   390
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   391
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   392
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
   393
                         const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   394
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   395
    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
   396
    printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   397
    if (effect->error_count > 0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   398
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   399
        int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   400
        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
   401
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   402
            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
   403
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   404
            printf("%s:%d: ERROR: %s\n",
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   405
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   406
                    err->error_position, err->error);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   407
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   408
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   409
    else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   410
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   411
        int i, j, k;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   412
        const MOJOSHADER_effectTechnique *technique = effect->techniques;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   413
        const MOJOSHADER_effectTexture *texture = effect->textures;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   414
        const MOJOSHADER_effectShader *shader = effect->shaders;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   415
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   416
        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
   417
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   418
            const MOJOSHADER_effectPass *pass = technique->passes;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   419
            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
   420
            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
   421
            {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   422
                const MOJOSHADER_effectState *state = pass->states;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   423
                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
   424
                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
   425
                {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   426
                    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
   427
                } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   428
            } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   429
            printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   430
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   431
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   432
        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
   433
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   434
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   435
            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
   436
                    texture->name, texture->param);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   437
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   438
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   439
        printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   440
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   441
        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
   442
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   443
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   444
            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
   445
                    shader->technique, shader->pass);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   446
            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
   447
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   448
    } // else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   449
} // print_effect
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   450
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   451
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   452
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
   453
                    const int len, const char *prof)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   454
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   455
    int retval = 0;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   456
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   457
    // 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
   458
    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
   459
         (buf[2] == 0xFF) && (buf[3] == 0xFE) )
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   460
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   461
        const MOJOSHADER_effect *effect;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   462
        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
   463
        retval = (effect->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   464
        printf("EFFECT: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   465
        print_effect(fname, effect, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   466
        MOJOSHADER_freeEffect(effect);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   467
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   468
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   469
    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
   470
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   471
        const MOJOSHADER_parseData *pd;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   472
        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
   473
        retval = (pd->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   474
        printf("SHADER: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   475
        print_shader(fname, pd, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   476
        MOJOSHADER_freeParseData(pd);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   477
    } // else
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   478
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   479
    return retval;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   480
} // do_parse
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   481
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   482
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   483
int main(int argc, char **argv)
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   484
{
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   485
    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
   486
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   487
    printf("MojoShader testparse\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   488
    printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   489
    printf("Linked against changeset %s\n", MOJOSHADER_changeset());
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   490
    printf("\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   491
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   492
    if (argc <= 2)
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   493
        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   494
    else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   495
    {
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   496
        const char *profile = argv[1];
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   497
        int i;
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   498
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   499
        for (i = 2; i < argc; i++)
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   500
        {
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   501
            FILE *io = fopen(argv[i], "rb");
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   502
            if (io == NULL)
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   503
                printf(" ... fopen('%s') failed.\n", argv[i]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   504
            else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   505
            {
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   506
                unsigned char *buf = (unsigned char *) malloc(1000000);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   507
                int rc = fread(buf, 1, 1000000, io);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   508
                fclose(io);
902
cff5841d29e7 Report actual filename in errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
   509
                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
   510
                    retval = 1;
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   511
                free(buf);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   512
            } // else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   513
        } // for
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   514
    } // else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   515
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   516
    return retval;
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   517
} // main
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   518
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   519
// end of testparse.c ...
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   520