mojoshader.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 25 Apr 2008 21:12:42 -0400
branchtrunk
changeset 196 5715754e5549
parent 190 2a2fb0f656cf
child 197 2ad08d31ea93
permissions -rw-r--r--
Initial API proposal for OpenGL glue.
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
/*
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    53
 * Data types for vertex attribute streams.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    54
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    55
typedef enum
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    56
{
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    57
    MOJOSHADER_ATTRIBUTE_BYTE,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    58
    MOJOSHADER_ATTRIBUTE_UBYTE,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    59
    MOJOSHADER_ATTRIBUTE_SHORT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    60
    MOJOSHADER_ATTRIBUTE_USHORT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    61
    MOJOSHADER_ATTRIBUTE_INT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    62
    MOJOSHADER_ATTRIBUTE_UINT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    63
    MOJOSHADER_ATTRIBUTE_FLOAT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    64
    MOJOSHADER_ATTRIBUTE_DOUBLE
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    65
} MOJOSHADER_attributeType;
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    66
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    67
/*
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    68
 * 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
    69
 */
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    70
typedef enum
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    71
{
147
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
    72
    MOJOSHADER_UNIFORM_FLOAT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
    73
    MOJOSHADER_UNIFORM_INT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
    74
    MOJOSHADER_UNIFORM_BOOL,
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    75
} MOJOSHADER_uniformType;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    76
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    77
/*
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    78
 * 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
    79
 *  calls "Constants" ... IDirect3DDevice::SetVertexShaderConstantF() would
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    80
 *  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
    81
 *  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
    82
 *  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
    83
 *  assembly language, before drawing with the shader.
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
    84
 * (name) is a profile-specific variable name; it may be NULL if it isn't
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
    85
 *  applicable to the requested profile.
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    86
 */
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    87
typedef struct
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    88
{
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    89
    MOJOSHADER_uniformType type;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    90
    int index;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
    91
    const char *name;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    92
} MOJOSHADER_uniform;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    93
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    94
/*
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
    95
 * Data types for samplers. See MOJOSHADER_sampler for more information.
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
    96
 */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
    97
typedef enum
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
    98
{
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
    99
    MOJOSHADER_SAMPLER_2D,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   100
    MOJOSHADER_SAMPLER_CUBE,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   101
    MOJOSHADER_SAMPLER_VOLUME,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   102
} MOJOSHADER_samplerType;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   103
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   104
/*
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   105
 * These are the samplers to be set for a shader. ...
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   106
 *  IDirect3DDevice::SetTexture() would need this data, for example.
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   107
 * These integers are the sampler "stage". So if index==6 and
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   108
 *  type==MOJOSHADER_SAMPLER_2D, that means we'd expect a regular 2D texture
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   109
 *  to be specified for what would be register "s6" in D3D assembly language,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   110
 *  before drawing with the shader.
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   111
 * (name) is a profile-specific variable name; it may be NULL if it isn't
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   112
 *  applicable to the requested profile.
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   113
 */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   114
typedef struct
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   115
{
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   116
    MOJOSHADER_samplerType type;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   117
    int index;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   118
    const char *name;
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   119
} MOJOSHADER_sampler;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   120
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   121
/*
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   122
 * 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
   123
 */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   124
typedef enum
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   125
{
147
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   126
    MOJOSHADER_USAGE_POSITION,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   127
    MOJOSHADER_USAGE_BLENDWEIGHT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   128
    MOJOSHADER_USAGE_BLENDINDICES,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   129
    MOJOSHADER_USAGE_NORMAL,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   130
    MOJOSHADER_USAGE_POINTSIZE,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   131
    MOJOSHADER_USAGE_TEXCOORD,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   132
    MOJOSHADER_USAGE_TANGENT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   133
    MOJOSHADER_USAGE_BINORMAL,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   134
    MOJOSHADER_USAGE_TESSFACTOR,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   135
    MOJOSHADER_USAGE_POSITIONT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   136
    MOJOSHADER_USAGE_COLOR,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   137
    MOJOSHADER_USAGE_FOG,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   138
    MOJOSHADER_USAGE_DEPTH,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   139
    MOJOSHADER_USAGE_SAMPLE,
101
0834e95e5e76 First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   140
    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
   141
} MOJOSHADER_usage;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   142
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   143
/*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   144
 * 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
   145
 *  Direct3D calls "Vertex Declarations Usages" ...
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   146
 *  IDirect3DDevice::CreateVertexDeclaration() would need this data, for
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   147
 *  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
   148
 *  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
   149
 *  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
   150
 *  before drawing.
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   151
 * (name) is a profile-specific variable name; it may be NULL if it isn't
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   152
 *  applicable to the requested profile.
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   153
 */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   154
typedef struct
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   155
{
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   156
    MOJOSHADER_usage usage;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   157
    int index;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   158
    const char *name;
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   159
} MOJOSHADER_attribute;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   160
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
 * 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
   163
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   164
typedef struct
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
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   167
     * 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
   168
     *  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
   169
     *  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
   170
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   171
    const char *error;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   172
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   173
    /*
187
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   174
     * The name of the profile used to parse the shader. Will be NULL on error.
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   175
     */
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   176
    const char *profile;
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   177
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   178
    /*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   179
     * 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
   180
     *  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
   181
     *  Will be NULL on error.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   182
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   183
    const char *output;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   184
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   185
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   186
     * 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
   187
     *  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
   188
     *  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
   189
     *  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
   190
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   191
    int output_len;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   192
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   193
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   194
     * 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
   195
     *  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
   196
     *  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
   197
     *  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
   198
     *  Will be zero on error.
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
    int instruction_count;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   201
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   202
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   203
     * 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
   204
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   205
    MOJOSHADER_shaderType shader_type;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   206
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
     * 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
   209
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   210
    int major_ver;
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
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   213
     * 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
   214
     *  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
   215
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   216
    int minor_ver;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   217
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   218
    /*
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   219
     * 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
   220
     */
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   221
    int uniform_count;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   222
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   223
    /*
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   224
     * (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
   225
     *  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
   226
     * 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
   227
     */
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   228
    MOJOSHADER_uniform *uniforms;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   229
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   230
    /*
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   231
     * The number of elements pointed to by (samplers).
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   232
     */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   233
    int sampler_count;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   234
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   235
    /*
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   236
     * (sampler_count) elements of data that specify Samplers to be set for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   237
     *  this shader. See discussion on MOJOSHADER_sampler for details.
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   238
     * This can be NULL on error or if (sampler_count) is zero.
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   239
     */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   240
    MOJOSHADER_sampler *samplers;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   241
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   242
    /*
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   243
     * 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
   244
     */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   245
    int attribute_count;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   246
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
     * (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
   249
     *  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
   250
     * 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
   251
     */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   252
    MOJOSHADER_attribute *attributes;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   253
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   254
    /*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   255
     * 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
   256
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   257
    MOJOSHADER_malloc malloc;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   258
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   259
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   260
     * 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
   261
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   262
    MOJOSHADER_free free;
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   263
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   264
    /*
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   265
     * 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
   266
     */
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   267
    void *malloc_data;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   268
} MOJOSHADER_parseData;
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
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   271
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   272
 * Profile string for Direct3D assembly language output.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   273
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   274
#define MOJOSHADER_PROFILE_D3D "d3d"
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   275
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   276
/*
109
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   277
 * 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
   278
 */
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   279
#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
   280
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   281
/*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   282
 * 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
   283
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   284
#define MOJOSHADER_PROFILE_GLSL "glsl"
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   285
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   286
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   287
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   288
 * Parse a compiled Direct3D shader's bytecode.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   289
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   290
 * 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
   291
 *  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
   292
 *  convert it into useful data.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   293
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   294
 * 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
   295
 *  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
   296
 *  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
   297
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   298
 * 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
   299
 *  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
   300
 *  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
   301
 *  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
   302
 *  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
   303
 *  (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
   304
 *
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   305
 * This function returns a MOJOSHADER_parseData.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   306
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   307
 * 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
   308
 *  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
   309
 *  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
   310
 *  MOJOSHADER_freeParseData()).
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   311
 *
187
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   312
 * This function is thread safe, so long as (m) and (f) are too, and that
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   313
 *  (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
   314
 *  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
   315
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   316
const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   317
                                             const unsigned char *tokenbuf,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   318
                                             const unsigned int bufsize,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   319
                                             MOJOSHADER_malloc m,
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   320
                                             MOJOSHADER_free f,
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   321
                                             void *d);
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   322
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   323
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   324
 * 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
   325
 *  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
   326
 *  MOJOSHADER_parse multiple times, if you provided one.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   327
 *  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
   328
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   329
 * 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
   330
 *  MOJOSHADER_parse() is, too.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   331
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   332
void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *data);
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   333
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   334
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   335
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   336
 * Prepare MojoShader to manage OpenGL shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   337
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   338
 * You do not need to call this if all you want is MOJOSHADER_parse().
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   339
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   340
 * You must call this once AFTER you have successfully built your GL context
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   341
 *  and made it current. This function will lookup the GL functions it needs
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   342
 *  through the callback you supply, after which it may call them at any time
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   343
 *  up until you call MOJOSHADER_glDeinit().
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   344
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   345
 * (profile) is an OpenGL-specific MojoShader profile, which decides how
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   346
 *  Direct3D bytecode shaders get turned into OpenGL programs, and how they
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   347
 *  are fed to the GL.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   348
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   349
 * (lookup) is a callback that is used to load GL entry points. This callback
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   350
 *  has to look up base GL functions and extension entry points.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   351
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   352
 * As MojoShader requires some memory to be allocated, you may provide a
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   353
 *  custom allocator to this function, which will be used to allocate/free
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   354
 *  memory. They function just like malloc() and free(). We do not use
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   355
 *  realloc(). If you don't care, pass NULL in for the allocator functions.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   356
 *  If your allocator needs instance-specific data, you may supply it with the
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   357
 *  (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   358
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   359
 * Returns zero on error, non-zero on success.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   360
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   361
 * This call is NOT thread safe! It must return success before you may call
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   362
 *  any other MOJOSHADER_gl* function. Also, as most OpenGL implementations
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   363
 *  are not thread safe, you should probably only call this from the same
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   364
 *  thread that created the GL context.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   365
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   366
int MOJOSHADER_glInit(const char *profile,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   367
                      void *(*lookup)(const char *fnname),
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   368
                      MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   369
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   370
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   371
 * "Shaders" refer to individual vertex or fragment programs, and are created
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   372
 *  by "compiling" Direct3D shader bytecode. A vertex and fragment shader are
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   373
 *  "linked" into a "Program" before you can use them to render.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   374
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   375
 * To the calling application, these are opaque handles.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   376
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   377
typedef struct MOJOSHADER_glShader MOJOSHADER_glShader;
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   378
typedef struct MOJOSHADER_glProgram MOJOSHADER_glProgram;
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   379
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   380
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   381
 * Compile a buffer of Direct3D shader bytecode into an OpenGL shader.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   382
 *  You still need to link the shader before you may render with it.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   383
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   384
 *   (tokenbuf) is a buffer of Direct3D shader bytecode.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   385
 *   (bufsize) is the size, in bytes, of the bytecode buffer.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   386
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   387
 * Returns NULL on error, or a shader handle on success.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   388
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   389
const MOJOSHADER_glShader *MOJOSHADER_glCompileShader(
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   390
                                const unsigned char *tokenbuf,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   391
                                const unsigned int bufsize);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   392
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   393
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   394
 * Link a vertex and fragment shader into an OpenGL program.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   395
 *  (vertex_shader) or (fragment_shader) can be NULL, to specify that the
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   396
 *  GL should use the fixed-function pipeline instead of the programmable
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   397
 *  pipeline for that portion of the work. You can reuse shaders in various
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   398
 *  combinations across multiple programs, by relinking different pairs.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   399
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   400
 * It is illegal to give a vertex shader for (fragment_shader) or a fragment
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   401
 *  shader for (vertex_shader).
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   402
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   403
 * It is illegal to delete a shader while there is still a linked program
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   404
 *  using it. Delete the programs before the shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   405
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   406
 * Once you have successfully linked a program, you may render with it.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   407
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   408
 * Returns NULL on error, or a program handle on success.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   409
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   410
const MOJOSHADER_glProgram *MOJOSHADER_glLinkProgram(
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   411
                                const MOJOSHADER_glShader *vertex_shader,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   412
                                const MOJOSHADER_glShader *fragment_shader);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   413
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   414
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   415
 * This binds the program (using, for example, glUseProgramObjectARB()), and
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   416
 *  disables all the client-side arrays so we can reset them with new values
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   417
 *  if appropriate.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   418
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   419
 * Call with NULL to disable the programmable pipeline and all enabled
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   420
 *  client-side arrays.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   421
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   422
 * After binding a program, you should update any uniforms you care about
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   423
 *  with MOJOSHADER_glSetVertexShaderUniformF() (etc), set any vertex arrays
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   424
 *  you want to use with MOJOSHADER_glSetVertexAttribute(), and finally call
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   425
 *  MOJOSHADER_glProgramReady() to commit everything to the GL. Then you may
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   426
 *  begin drawing through standard GL entry points.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   427
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   428
void MOJOSHADER_glBindProgram(MOJOSHADER_glProgram *program);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   429
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   430
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   431
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   432
 * Set a floating-point uniform value (what Direct3D calls a "constant").
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   433
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   434
 * There is a single array of 4-float "registers" shared by all vertex shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   435
 *  This is the "c" register file in Direct3D (c0, c1, c2, etc...)
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   436
 *  MojoShader will take care of synchronizing this internal array with the
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   437
 *  appropriate variables in the GL shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   438
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   439
 * (idx) is the index into the internal array: 0 is the first four floats,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   440
 *  1 is the next four, etc.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   441
 * (data) is a pointer to (vec4count*4) floats.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   442
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   443
void MOJOSHADER_glSetVertexShaderUniformF(unsigned int idx, const float *data,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   444
                                          unsigned int vec4count);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   445
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   446
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   447
 * Set an integer uniform value (what Direct3D calls a "constant").
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   448
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   449
 * There is a single array of 4-int "registers" shared by all vertex shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   450
 *  This is the "i" register file in Direct3D (i0, i1, i2, etc...)
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   451
 *  MojoShader will take care of synchronizing this internal array with the
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   452
 *  appropriate variables in the GL shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   453
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   454
 * (idx) is the index into the internal array: 0 is the first four ints,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   455
 *  1 is the next four, etc.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   456
 * (data) is a pointer to (ivec4count*4) ints.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   457
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   458
void MOJOSHADER_glSetVertexShaderUniformI(unsigned int idx, const int *data,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   459
                                          unsigned int ivec4count);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   460
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   461
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   462
 * Set a boolean uniform value (what Direct3D calls a "constant").
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   463
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   464
 * There is a single array of "registers" shared by all vertex shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   465
 *  This is the "b" register file in Direct3D (b0, b1, b2, etc...)
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   466
 *  MojoShader will take care of synchronizing this internal array with the
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   467
 *  appropriate variables in the GL shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   468
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   469
 * Unlike the float and int counterparts, booleans are single values, not
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   470
 *  four-element vectors...so idx==1 is the second boolean in the internal
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   471
 *  array, not the fifth.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   472
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   473
 * Non-zero values are considered "true" and zero is considered "false".
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   474
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   475
 * (idx) is the index into the internal array.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   476
 * (data) is a pointer to (bcount) ints.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   477
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   478
void MOJOSHADER_glSetVertexShaderUniformB(unsigned int idx, const int *data,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   479
                                          unsigned int bcount);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   480
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   481
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   482
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   483
 * Connect a client-side array to the currently-bound program.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   484
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   485
 * (usage) and (index) map to Direct3D vertex declaration values: COLOR1 would
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   486
 *  be MOJOSHADER_USAGE_COLOR and 1.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   487
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   488
 * The caller should bind VBOs before this call and treat (ptr) as an offset,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   489
 *  if appropriate.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   490
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   491
 * MojoShader will figure out where to plug this stream into the
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   492
 *  currently-bound program, and enable the appropriate client-side array.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   493
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   494
 * (size), (type), (normalized), (stride), and (ptr) correspond to
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   495
 *  glVertexAttribPointer()'s parameters (in most cases, these get passed
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   496
 *  unmolested to that very entry point during this function).
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   497
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   498
void MOJOSHADER_glSetVertexAttribute(MOJOSHADER_usage usage,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   499
                                     int index, unsigned int size,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   500
                                     MOJOSHADER_attributeType type,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   501
                                     int normalized, unsigned int stride,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   502
                                     const void *ptr);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   503
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   504
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   505
 * Inform MojoShader that it should commit any pending state to the GL. This
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   506
 *  must be called after you bind a program and update any inputs, right
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   507
 *  before you start drawing, so any outstanding changes made to the shared
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   508
 *  constants array (etc) can propagate to the shader during this call.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   509
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   510
void MOJOSHADER_glProgramReady(void);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   511
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   512
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   513
 * Free the resources of a linked program. This will delete the GL object
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   514
 *  and free memory.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   515
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   516
 * You must not call this on a bound program! Either bind a different one
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   517
 *  or call MOJOSHADER_glBindProgram(NULL) first to unbind it.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   518
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   519
void MOJOSHADER_glDeleteProgram(const MOJOSHADER_glProgram *program);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   520
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   521
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   522
 * Free the resources of a compiled shader. This will delete the GL object
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   523
 *  and free memory.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   524
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   525
 * You must not call this on a shader that's currently linked in a program.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   526
 *  Call MOJOSHADER_glDeleteProgram() on any programs, first.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   527
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   528
void MOJOSHADER_glDeleteShader(const MOJOSHADER_glShader *shader);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   529
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   530
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   531
 * Deinitialize MojoShader's OpenGL shader management.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   532
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   533
 * You must call this once, while your GL context is still current, if you
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   534
 *  previously had a successful call to MOJOSHADER_glInit(). This should
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   535
 *  be the last MOJOSHADER_gl* function you call until you've initialized
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   536
 *  again.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   537
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   538
 * This will clean up resources previously allocated, and may call into the GL.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   539
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   540
 * This will not clean up shaders and programs you created! Please call
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   541
 *  MOJOSHADER_glDeleteShader() and MOJOSHADER_glDeleteProgram() to clean
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   542
 *  those up before calling this function!
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   543
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   544
 * This call is NOT thread safe! There must not be any other MOJOSHADER_gl*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   545
 *  functions running when this is called. Also, as most OpenGL implementations
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   546
 *  are not thread safe, you should probably only call this from the same
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   547
 *  thread that created the GL context.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   548
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   549
void MOJOSHADER_glDeinit(void);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   550
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   551
#ifdef __cplusplus
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   552
}
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   553
#endif
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   554
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   555
#endif  /* include-once blocker. */
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   556
35
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
   557
/* end of mojoshader.h ... */
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   558