mojoshader.h
author Ryan C. Gordon <icculus@icculus.org>
Sat, 19 Apr 2008 02:26:26 -0400
branchtrunk
changeset 146 9a0d4707feb8
parent 145 5325c8d6077c
child 147 98043daf5027
permissions -rw-r--r--
Export sampler information in public API.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     1
/**
35
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
     3
 *  Direct3D shaders.
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     4
 *
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     6
 *
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     8
 */
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
     9
35
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
    10
#ifndef __INCL_MOJOSHADER_H_
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
    11
#define __INCL_MOJOSHADER_H_
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    12
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    13
#ifdef __cplusplus
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    14
extern "C" {
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    15
#endif
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    16
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    17
/*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    18
 * For determining the version of MojoShader you are using:
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    19
 *    const int compiled_against = MOJOSHADER_VERSION;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    20
 *    const int linked_against = MOJOSHADER_version();
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    21
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    22
 * The version is a single integer that increments, not a major/minor value.
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    23
 */
35
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
    24
#define MOJOSHADER_VERSION 1
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
    25
int MOJOSHADER_version(void);
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    26
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    27
/*
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    28
 * These allocators work just like the C runtime's malloc() and free()
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    29
 *  (in fact, they probably use malloc() and free() internally if you don't
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    30
 *  specify your own allocator, but don't rely on that behaviour).
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    31
 * (data) is the pointer you supplied when specifying these allocator
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    32
 *  callbacks, in case you need instance-specific data...it is passed through
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    33
 *  to your allocator unmolested, and can be NULL if you like.
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 18
diff changeset
    34
 */
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    35
typedef void *(*MOJOSHADER_malloc)(int bytes, void *data);
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
    36
typedef void (*MOJOSHADER_free)(void *ptr, void *data);
18
0dbdb2be8bf8 [svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents: 14
diff changeset
    37
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    38
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    39
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    40
 * These are enum values, but they also can be used in bitmasks, so we can
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    41
 *  test if an opcode is acceptable: if (op->shader_types & ourtype) {} ...
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    42
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    43
typedef enum
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    44
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    45
    MOJOSHADER_TYPE_UNKNOWN  = 0,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    46
    MOJOSHADER_TYPE_PIXEL    = (1 << 0),
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    47
    MOJOSHADER_TYPE_VERTEX   = (1 << 1),
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    48
    MOJOSHADER_TYPE_GEOMETRY = (1 << 2),  /* (not supported yet.) */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    49
    MOJOSHADER_TYPE_ANY = 0xFFFFFFFF   /* used for bitmasks */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    50
} MOJOSHADER_shaderType;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
    51
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    52
/*
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    53
 * Data types for uniforms. See MOJOSHADER_uniform for more information.
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    54
 */
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    55
typedef enum
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    56
{
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    57
    MOJOSHADER_UNIFORM_FLOAT = 0,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    58
    MOJOSHADER_UNIFORM_INT = 1,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    59
    MOJOSHADER_UNIFORM_BOOL = 2,
146
9a0d4707feb8 Export sampler information in public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    60
    MOJOSHADER_UNIFORM_SAMPLER_2D = 3,
9a0d4707feb8 Export sampler information in public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    61
    MOJOSHADER_UNIFORM_SAMPLER_CUBE = 4,
9a0d4707feb8 Export sampler information in public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    62
    MOJOSHADER_UNIFORM_SAMPLER_3D = 5,
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    63
} MOJOSHADER_uniformType;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    64
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    65
/*
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    66
 * These are the uniforms to be set for a shader. "Uniforms" are what Direct3D
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    67
 *  calls "Constants" ... IDirect3DDevice::SetVertexShaderConstantF() would
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    68
 *  need this data, for example. These integers are register indexes. So if
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    69
 *  index==6 and type==MOJOSHADER_UNIFORM_FLOAT, that means we'd expect a
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    70
 *  4-float vector to be specified for what would be register "c6" in D3D
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    71
 *  assembly language, before drawing with the shader.
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    72
 */
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    73
typedef struct
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    74
{
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    75
    MOJOSHADER_uniformType type;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    76
    int index;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    77
} MOJOSHADER_uniform;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    78
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    79
/*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    80
 * Data types for attributes. See MOJOSHADER_attribute for more information.
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    81
 */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    82
typedef enum
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    83
{
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    84
    MOJOSHADER_USAGE_POSITION = 0,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    85
    MOJOSHADER_USAGE_BLENDWEIGHT = 1,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    86
    MOJOSHADER_USAGE_BLENDINDICES = 2,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    87
    MOJOSHADER_USAGE_NORMAL = 3,
101
0834e95e5e76 First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
    88
    MOJOSHADER_USAGE_POINTSIZE = 4,
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    89
    MOJOSHADER_USAGE_TEXCOORD = 5,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    90
    MOJOSHADER_USAGE_TANGENT = 6,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    91
    MOJOSHADER_USAGE_BINORMAL = 7,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    92
    MOJOSHADER_USAGE_TESSFACTOR = 8,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    93
    MOJOSHADER_USAGE_POSITIONT = 9,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    94
    MOJOSHADER_USAGE_COLOR = 10,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    95
    MOJOSHADER_USAGE_FOG = 11,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    96
    MOJOSHADER_USAGE_DEPTH = 12,
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    97
    MOJOSHADER_USAGE_SAMPLE = 13,
101
0834e95e5e76 First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
    98
    MOJOSHADER_USAGE_TOTAL,  /* housekeeping value; not ever returned. */
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    99
} MOJOSHADER_usage;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   101
/*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   102
 * These are the attributes to be set for a shader. "Attributes" are what
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   103
 *  Direct3D calls "Vertex Declarations Usages" ...
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   104
 *  IDirect3DDevice::CreateVertexDeclaration() would need this data, for
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   105
 *  example. Each attribute is associated with an array of data that uses one
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   106
 *  element per-vertex. So if usage==MOJOSHADER_USAGE_COLOR and index==1, that
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   107
 *  means we'd expect a secondary color array to be bound to this shader
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   108
 *  before drawing.
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   109
 */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   110
typedef struct
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   111
{
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   112
    MOJOSHADER_usage usage;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   113
    int index;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   114
} MOJOSHADER_attribute;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   115
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   116
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   117
 * Structure used to return data from parsing of a shader...
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   118
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   119
typedef struct
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   120
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   121
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   122
     * Human-readable error, if there is one. Will be NULL if there was no
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   123
     *  error. The string will be UTF-8 encoded, and English only. Most of
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   124
     *  these shouldn't be shown to the end-user anyhow.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   125
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   126
    const char *error;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   127
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   128
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   129
     * Bytes of output from parsing. Most profiles produce a string of source
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   130
     *  code, but profiles that do binary output may not be text at all.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   131
     *  Will be NULL on error.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   132
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   133
    const char *output;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   134
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   135
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   136
     * Byte count for output, not counting any null terminator. Most profiles
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 109
diff changeset
   137
     *  produce an ASCII string of source code (which will be null-terminated
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 109
diff changeset
   138
     *  even though that null char isn't included in output_len), but profiles
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 109
diff changeset
   139
     *  that do binary output may not be text at all. Will be 0 on error.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   140
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   141
    int output_len;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   142
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   143
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   144
     * Count of Direct3D instructions we parsed. This is meaningless in terms
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   145
     *  of the actual output, as the profile will probably grow or reduce
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   146
     *  the count (or for high-level languages, not have that information at
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   147
     *  all), but it can give you a rough idea of the size of your shader.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   148
     *  Will be zero on error.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   149
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   150
    int instruction_count;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   151
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   152
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   153
     * The type of shader we parsed. Will be MOJOSHADER_TYPE_UNKNOWN on error.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   154
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   155
    MOJOSHADER_shaderType shader_type;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   156
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   157
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   158
     * The shader's major version. If this was a "vs_3_0", this would be 3.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   159
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   160
    int major_ver;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   161
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   162
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   163
     * The shader's minor version. If this was a "ps_1_4", this would be 4.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   164
     *  Two notes: for "vs_2_x", this is 1, and for "vs_3_sw", this is 255.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   165
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   166
    int minor_ver;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   167
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   168
    /*
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   169
     * The number of elements pointed to by (uniforms).
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   170
     */
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   171
    int uniform_count;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   172
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   173
    /*
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   174
     * (uniform_count) elements of data that specify Uniforms to be set for
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   175
     *  this shader. See discussion on MOJOSHADER_uniform for details.
145
5325c8d6077c Don't create unnecessary attributes.
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   176
     * This can be NULL on error or if (uniform_count) is zero.
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   177
     */
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   178
    MOJOSHADER_uniform *uniforms;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   179
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   180
    /*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   181
     * The number of elements pointed to by (attributes).
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   182
     */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   183
    int attribute_count;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   184
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   185
    /*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   186
     * (attribute_count) elements of data that specify Attributes to be set
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   187
     *  for this shader. See discussion on MOJOSHADER_attribute for details.
145
5325c8d6077c Don't create unnecessary attributes.
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   188
     * This can be NULL on error or if (attribute_count) is zero.
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   189
     */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   190
    MOJOSHADER_attribute *attributes;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   191
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   192
    /*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   193
     * This is the malloc implementation you passed to MOJOSHADER_parse().
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   194
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   195
    MOJOSHADER_malloc malloc;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   196
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   197
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   198
     * This is the free implementation you passed to MOJOSHADER_parse().
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   199
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   200
    MOJOSHADER_free free;
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   201
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   202
    /*
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   203
     * This is the pointer you passed as opaque data for your allocator.
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   204
     */
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   205
    void *malloc_data;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   206
} MOJOSHADER_parseData;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   207
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   208
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   209
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   210
 * Profile string for Direct3D assembly language output.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   211
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   212
#define MOJOSHADER_PROFILE_D3D "d3d"
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   213
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   214
/*
109
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   215
 * Profile string for passthrough of the original bytecode, unchanged.
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   216
 */
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   217
#define MOJOSHADER_PROFILE_PASSTHROUGH "passthrough"
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   218
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   219
/*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   220
 * Profile string for GLSL: OpenGL high-level shader language output.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   221
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   222
#define MOJOSHADER_PROFILE_GLSL "glsl"
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   223
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   224
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   225
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   226
 * Parse a compiled Direct3D shader's bytecode.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   227
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   228
 * This is your primary entry point into MojoShader. You need to pass it
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   229
 *  a compiled D3D shader and tell it which "profile" you want to use to
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   230
 *  convert it into useful data.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   231
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   232
 * The available profiles are the set of MOJOSHADER_PROFILE_* defines.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   233
 *  Note that MojoShader may be built without support for all listed
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   234
 *  profiles (in which case using one here will return with an error).
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   235
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   236
 * As parsing requires some memory to be allocated, you may provide a custom
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   237
 *  allocator to this function, which will be used to allocate/free memory.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   238
 *  They function just like malloc() and free(). We do not use realloc().
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   239
 *  If you don't care, pass NULL in for the allocator functions. If your
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   240
 *  allocator needs instance-specific data, you may supply it with the
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   241
 *  (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   242
 *
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   243
 * This function returns a MOJOSHADER_parseData.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   244
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   245
 * This function will never return NULL, even if the system is completely
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   246
 *  out of memory upon entry (in which case, this function returns a static
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   247
 *  MOJOSHADER_parseData object, which is still safe to pass to
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   248
 *  MOJOSHADER_freeParseData()).
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   249
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   250
 * This function is thread safe, so long (m) and (f) are too, and that
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   251
 *  (tokenbuf) remains intact for the duration of the call. This allows you
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   252
 *  to parse several shaders on separate CPU cores at the same time.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   253
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   254
const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   255
                                             const unsigned char *tokenbuf,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   256
                                             const unsigned int bufsize,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   257
                                             MOJOSHADER_malloc m,
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   258
                                             MOJOSHADER_free f,
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   259
                                             void *d);
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   260
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   261
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   262
 * Call this to dispose of parsing results when you are done with them.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   263
 *  This will call the MOJOSHADER_free function you provided to
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   264
 *  MOJOSHADER_parse multiple times, if you provided one.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   265
 *  Passing a NULL here is a safe no-op.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   266
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   267
 * This function is thread safe, so long as any allocator you passed into
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   268
 *  MOJOSHADER_parse() is, too.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   269
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   270
void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *data);
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   271
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   272
#ifdef __cplusplus
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   273
}
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   274
#endif
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   275
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   276
#endif  /* include-once blocker. */
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   277
35
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
   278
/* end of mojoshader.h ... */
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   279