mojoshader.h
author Ryan C. Gordon <icculus@icculus.org>
Fri, 02 May 2008 07:04:43 -0400
branchtrunk
changeset 268 6d5a1323db28
parent 262 0f1531ac2578
child 276 1d7437469c94
permissions -rw-r--r--
GLSL profile now emits correct array deference on instructions. Need to coerce the uniforms into real arrays, still, though. :/
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
{
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
    57
    MOJOSHADER_ATTRIBUTE_UNKNOWN = -1,  /* housekeeping; not returned. */
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    58
    MOJOSHADER_ATTRIBUTE_BYTE,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    59
    MOJOSHADER_ATTRIBUTE_UBYTE,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    60
    MOJOSHADER_ATTRIBUTE_SHORT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    61
    MOJOSHADER_ATTRIBUTE_USHORT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    62
    MOJOSHADER_ATTRIBUTE_INT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    63
    MOJOSHADER_ATTRIBUTE_UINT,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    64
    MOJOSHADER_ATTRIBUTE_FLOAT,
236
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
    65
    MOJOSHADER_ATTRIBUTE_DOUBLE,
8e2fc535b210 Support for half-float attribute arrays.
Ryan C. Gordon <icculus@icculus.org>
parents: 219
diff changeset
    66
    MOJOSHADER_ATTRIBUTE_HALF_FLOAT,  /* MAYBE available in your OpenGL! */
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    67
} MOJOSHADER_attributeType;
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    68
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
    69
/*
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    70
 * 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
    71
 */
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    72
typedef enum
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    73
{
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
    74
    MOJOSHADER_UNIFORM_UNKNOWN = -1, /* housekeeping value; never returned. */
147
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
    75
    MOJOSHADER_UNIFORM_FLOAT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
    76
    MOJOSHADER_UNIFORM_INT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
    77
    MOJOSHADER_UNIFORM_BOOL,
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    78
} MOJOSHADER_uniformType;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    79
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    80
/*
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    81
 * 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
    82
 *  calls "Constants" ... IDirect3DDevice::SetVertexShaderConstantF() would
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    83
 *  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
    84
 *  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
    85
 *  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
    86
 *  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
    87
 * (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
    88
 *  applicable to the requested profile.
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
    89
 */
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    90
typedef struct
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    91
{
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    92
    MOJOSHADER_uniformType type;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    93
    int index;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
    94
    const char *name;
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    95
} MOJOSHADER_uniform;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
    96
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
    97
/*
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
    98
 * 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
    99
 */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   100
typedef enum
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   101
{
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
   102
    MOJOSHADER_SAMPLER_UNKNOWN = -1, /* housekeeping value; never returned. */
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   103
    MOJOSHADER_SAMPLER_2D,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   104
    MOJOSHADER_SAMPLER_CUBE,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   105
    MOJOSHADER_SAMPLER_VOLUME,
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   106
} MOJOSHADER_samplerType;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   107
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   108
/*
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   109
 * 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
   110
 *  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
   111
 * 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
   112
 *  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
   113
 *  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
   114
 *  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
   115
 * (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
   116
 *  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
   117
 */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   118
typedef struct
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   119
{
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   120
    MOJOSHADER_samplerType type;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   121
    int index;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   122
    const char *name;
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   123
} MOJOSHADER_sampler;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   124
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   125
/*
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   126
 * 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
   127
 */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   128
typedef enum
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   129
{
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
   130
    MOJOSHADER_USAGE_UNKNOWN = -1,  /* housekeeping value; never returned. */
147
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   131
    MOJOSHADER_USAGE_POSITION,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   132
    MOJOSHADER_USAGE_BLENDWEIGHT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   133
    MOJOSHADER_USAGE_BLENDINDICES,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   134
    MOJOSHADER_USAGE_NORMAL,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   135
    MOJOSHADER_USAGE_POINTSIZE,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   136
    MOJOSHADER_USAGE_TEXCOORD,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   137
    MOJOSHADER_USAGE_TANGENT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   138
    MOJOSHADER_USAGE_BINORMAL,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   139
    MOJOSHADER_USAGE_TESSFACTOR,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   140
    MOJOSHADER_USAGE_POSITIONT,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   141
    MOJOSHADER_USAGE_COLOR,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   142
    MOJOSHADER_USAGE_FOG,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   143
    MOJOSHADER_USAGE_DEPTH,
98043daf5027 Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents: 146
diff changeset
   144
    MOJOSHADER_USAGE_SAMPLE,
240
a945af028366 Added UNKNOWN value to the enums in the public API.
Ryan C. Gordon <icculus@icculus.org>
parents: 239
diff changeset
   145
    MOJOSHADER_USAGE_TOTAL,  /* housekeeping value; never returned. */
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   146
} MOJOSHADER_usage;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   147
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   148
/*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   149
 * 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
   150
 *  Direct3D calls "Vertex Declarations Usages" ...
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   151
 *  IDirect3DDevice::CreateVertexDeclaration() would need this data, for
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   152
 *  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
   153
 *  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
   154
 *  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
   155
 *  before drawing.
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   156
 * (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
   157
 *  applicable to the requested profile.
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   158
 */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   159
typedef struct
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   160
{
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   161
    MOJOSHADER_usage usage;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   162
    int index;
190
2a2fb0f656cf Added profile-specific variable names to returned parse data.
Ryan C. Gordon <icculus@icculus.org>
parents: 187
diff changeset
   163
    const char *name;
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   164
} MOJOSHADER_attribute;
46
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
 * 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
   168
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   169
typedef struct
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
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   172
     * 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
   173
     *  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
   174
     *  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
   175
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   176
    const char *error;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   177
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   178
    /*
187
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   179
     * 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
   180
     */
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   181
    const char *profile;
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   182
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   183
    /*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   184
     * 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
   185
     *  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
   186
     *  Will be NULL on error.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   187
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   188
    const char *output;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   189
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
     * 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
   192
     *  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
   193
     *  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
   194
     *  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
   195
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   196
    int output_len;
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
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   199
     * 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
   200
     *  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
   201
     *  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
   202
     *  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
   203
     *  Will be zero 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
    int instruction_count;
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 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
   209
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   210
    MOJOSHADER_shaderType shader_type;
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 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
   214
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   215
    int major_ver;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   216
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
     * 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
   219
     *  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
   220
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   221
    int minor_ver;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   222
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   223
    /*
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   224
     * 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
   225
     */
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   226
    int uniform_count;
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
    /*
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   229
     * (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
   230
     *  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
   231
     * 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
   232
     */
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   233
    MOJOSHADER_uniform *uniforms;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   234
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   235
    /*
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   236
     * 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
   237
     */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   238
    int sampler_count;
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
    /*
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   241
     * (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
   242
     *  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
   243
     * 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
   244
     */
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   245
    MOJOSHADER_sampler *samplers;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   246
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 147
diff changeset
   247
    /*
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   248
     * 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
   249
     */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   250
    int attribute_count;
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
    /*
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   253
     * (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
   254
     *  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
   255
     * 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
   256
     */
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   257
    MOJOSHADER_attribute *attributes;
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   258
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 46
diff changeset
   259
    /*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   260
     * 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
   261
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   262
    MOJOSHADER_malloc malloc;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   263
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   264
    /*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   265
     * 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
   266
     */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   267
    MOJOSHADER_free free;
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   268
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   269
    /*
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   270
     * 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
   271
     */
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   272
    void *malloc_data;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   273
} MOJOSHADER_parseData;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   274
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
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   277
 * Profile string for Direct3D assembly language output.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   278
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   279
#define MOJOSHADER_PROFILE_D3D "d3d"
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   280
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   281
/*
109
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   282
 * 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
   283
 */
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   284
#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
   285
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 101
diff changeset
   286
/*
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   287
 * 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
   288
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   289
#define MOJOSHADER_PROFILE_GLSL "glsl"
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   290
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   291
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   292
/*
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   293
 * Parse a compiled Direct3D shader's bytecode.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   294
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   295
 * 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
   296
 *  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
   297
 *  convert it into useful data.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   298
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   299
 * 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
   300
 *  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
   301
 *  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
   302
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   303
 * 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
   304
 *  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
   305
 *  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
   306
 *  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
   307
 *  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
   308
 *  (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
   309
 *
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   310
 * This function returns a MOJOSHADER_parseData.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   311
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   312
 * 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
   313
 *  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
   314
 *  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
   315
 *  MOJOSHADER_freeParseData()).
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   316
 *
187
1c709f65cf1b Store profile string in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   317
 * 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
   318
 *  (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
   319
 *  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
   320
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   321
const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   322
                                             const unsigned char *tokenbuf,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   323
                                             const unsigned int bufsize,
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   324
                                             MOJOSHADER_malloc m,
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   325
                                             MOJOSHADER_free f,
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 94
diff changeset
   326
                                             void *d);
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   327
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
 * 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
   330
 *  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
   331
 *  MOJOSHADER_parse multiple times, if you provided one.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   332
 *  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
   333
 *
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   334
 * 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
   335
 *  MOJOSHADER_parse() is, too.
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   336
 */
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 36
diff changeset
   337
void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *data);
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   338
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   339
218
d3fac270bca1 Minor comment added.
Ryan C. Gordon <icculus@icculus.org>
parents: 217
diff changeset
   340
d3fac270bca1 Minor comment added.
Ryan C. Gordon <icculus@icculus.org>
parents: 217
diff changeset
   341
d3fac270bca1 Minor comment added.
Ryan C. Gordon <icculus@icculus.org>
parents: 217
diff changeset
   342
/* OpenGL interface... */
d3fac270bca1 Minor comment added.
Ryan C. Gordon <icculus@icculus.org>
parents: 217
diff changeset
   343
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   344
/*
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   345
 * "Contexts" map to OpenGL contexts...you need one per window, or whatever,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   346
 *  and need to inform MojoShader when you make a new one current.
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   347
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   348
 * "Shaders" refer to individual vertex or pixel programs, and are created
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   349
 *  by "compiling" Direct3D shader bytecode. A vertex and pixel shader are
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   350
 *  "linked" into a "Program" before you can use them to render.
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   351
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   352
 * To the calling application, these are all opaque handles.
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   353
 */
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   354
typedef struct MOJOSHADER_glContext MOJOSHADER_glContext;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   355
typedef struct MOJOSHADER_glShader MOJOSHADER_glShader;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   356
typedef struct MOJOSHADER_glProgram MOJOSHADER_glProgram;
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   357
262
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   358
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   359
/*
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   360
 * Determine the best profile to use for the current system.
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   361
 *
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   362
 * You do not need to call this if all you want is MOJOSHADER_parse().
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   363
 *
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   364
 * You can only call this AFTER you have successfully built your GL context
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   365
 *  and made it current. This function will lookup the GL functions it needs
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   366
 *  through the callback you supply. The lookup function is neither stored nor
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   367
 *  used by MojoShader after this function returns, nor are the functions it
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   368
 *  might look up.
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   369
 *
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   370
 * Returns the name of the "best" profile on success, NULL if none of the
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   371
 *  available profiles will work on this system. "Best" is a relative term,
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   372
 *  but it generally means the best trade off between feature set and
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   373
 *  performance. The selection algorithm may be arbitrary and complex.
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   374
 *
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   375
 * The returned value is an internal static string, and should not be free()'d
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   376
 *  by the caller. If you get a NULL, calling MOJOSHADER_glGetError() might
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   377
 *  shed some light on why.
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   378
 *
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   379
 * This call is NOT thread safe! As most OpenGL implementations are not thread
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   380
 *  safe, you should probably only call this from the same thread that created
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   381
 *  the GL context.
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   382
 */
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   383
const char *MOJOSHADER_glBestProfile(void *(*lookup)(const char *fnname));
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   384
0f1531ac2578 Implemented MOJOSHADER_glBestProfile().
Ryan C. Gordon <icculus@icculus.org>
parents: 245
diff changeset
   385
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   386
/*
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   387
 * Prepare MojoShader to manage OpenGL shaders.
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
 * 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
   390
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   391
 * 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
   392
 *  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
   393
 *  through the callback you supply, after which it may call them at any time
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   394
 *  up until you call MOJOSHADER_glDestroyContext(). The lookup function is
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   395
 *  neither stored nor used by MojoShader after this function returns.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   396
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   397
 * (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
   398
 *  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
   399
 *  are fed to the GL.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   400
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   401
 * (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
   402
 *  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
   403
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   404
 * 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
   405
 *  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
   406
 *  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
   407
 *  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
   408
 *  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
   409
 *  (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
   410
 *
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   411
 * Returns a new context on success, NULL on error. If you get a new context,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   412
 *  you need to make it current before using it with
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   413
 *  MOJOSHADER_glMakeContextCurrent().
196
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 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
   416
 *  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
   417
 *  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
   418
 *  thread that created the GL context.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   419
 */
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   420
MOJOSHADER_glContext *MOJOSHADER_glCreateContext(const char *profile,
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   421
                                        void *(*lookup)(const char *fnname),
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   422
                                        MOJOSHADER_malloc m, MOJOSHADER_free f,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   423
                                        void *d);
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   424
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   425
/*
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   426
 * You must call this before using the context that you got from
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   427
 *  MOJOSHADER_glCreateContext(), and must use it when you switch to a new GL
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   428
 *  context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   429
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   430
 * You can only have one MOJOSHADER_glContext per actual GL context, or
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   431
 *  undefined behaviour will result.
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   432
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   433
 * It is legal to call this with a NULL pointer to make no context current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   434
 *  but you need a valid context to be current to use most of MojoShader.
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   435
 */
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   436
void MOJOSHADER_glMakeContextCurrent(MOJOSHADER_glContext *ctx);
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   437
219
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   438
/*
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   439
 * Get any error state we might have picked up. MojoShader will NOT call
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   440
 *  glGetError() internally, but there are other errors we can pick up,
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   441
 *  such as failed shader compilation, etc.
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   442
 *
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   443
 * Returns a human-readable string. This string is for debugging purposes, and
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   444
 *  not guaranteed to be localized, coherent, or user-friendly in any way.
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   445
 *  It's for programmers!
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   446
 *
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   447
 * The latest error may remain between calls. New errors replace any existing
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   448
 *  error. Don't check this string for a sign that an error happened, check
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   449
 *  return codes instead and use this for explanation when debugging.
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   450
 *
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   451
 * Do not free the returned string: it's a pointer to a static internal
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   452
 *  buffer. Do not keep the pointer around, either, as it's likely to become
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   453
 *  invalid as soon as you call into MojoShader again.
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   454
 *
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   455
 * This call is NOT thread safe! As most OpenGL implementations are not thread
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   456
 *  safe, you should probably only call this from the same thread that created
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   457
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   458
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   459
 * This call does NOT require a valid MOJOSHADER_glContext to have been made
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   460
 *  current. The error buffer is shared between contexts, so you can get
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   461
 *  error results from a failed MOJOSHADER_glCreateContext().
219
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   462
 */
61167fc96790 Added MOJOSHADER_glGetError() function, filled in error state.
Ryan C. Gordon <icculus@icculus.org>
parents: 218
diff changeset
   463
const char *MOJOSHADER_glGetError(void);
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   464
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   465
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   466
 * 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
   467
 *  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
   468
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   469
 *   (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
   470
 *   (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
   471
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   472
 * Returns NULL on error, or a shader handle on success.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   473
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   474
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   475
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   476
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   477
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   478
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   479
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   480
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   481
 * Compiled shaders from this function may not be shared between contexts.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   482
 */
199
03463c4621ad Reduced const insanity in API spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 198
diff changeset
   483
MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf,
03463c4621ad Reduced const insanity in API spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 198
diff changeset
   484
                                                const unsigned int bufsize);
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   485
245
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   486
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   487
/*
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   488
 * Get the MOJOSHADER_parseData structure that was produced from the
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   489
 *  call to MOJOSHADER_glCompileShader().
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   490
 *
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   491
 * This data is read-only, and you should NOT attempt to free it. This
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   492
 *  pointer remains valid until the shader is deleted.
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   493
 */
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   494
const MOJOSHADER_parseData *MOJOSHADER_glGetShaderParseData(
1f04b805a4f2 Added MOJOSHADER_glGetShaderParseData().
Ryan C. Gordon <icculus@icculus.org>
parents: 240
diff changeset
   495
                                                MOJOSHADER_glShader *shader);
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   496
/*
200
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   497
 * Link a vertex and pixel shader into an OpenGL program.
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   498
 *  (vshader) or (pshader) can be NULL, to specify that the GL should use the
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   499
 *  fixed-function pipeline instead of the programmable pipeline for that
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   500
 *  portion of the work. You can reuse shaders in various combinations across
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   501
 *  multiple programs, by relinking different pairs.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   502
 *
200
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   503
 * It is illegal to give a vertex shader for (pshader) or a pixel shader
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   504
 *  for (vshader).
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   505
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   506
 * 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
   507
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   508
 * Returns NULL on error, or a program handle on success.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   509
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   510
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   511
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   512
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   513
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   514
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   515
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   516
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   517
 * Linked programs from this function may not be shared between contexts.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   518
 */
200
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   519
MOJOSHADER_glProgram *MOJOSHADER_glLinkProgram(MOJOSHADER_glShader *vshader,
5085c788f769 Removed references to "fragment" programs in header.
Ryan C. Gordon <icculus@icculus.org>
parents: 199
diff changeset
   520
                                               MOJOSHADER_glShader *pshader);
196
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
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   523
 * 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
   524
 *  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
   525
 *  if appropriate.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   526
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   527
 * 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
   528
 *  client-side arrays.
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
 * 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
   531
 *  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
   532
 *  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
   533
 *  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
   534
 *  begin drawing through standard GL entry points.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   535
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   536
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   537
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   538
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   539
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   540
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   541
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   542
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   543
void MOJOSHADER_glBindProgram(MOJOSHADER_glProgram *program);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   544
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   545
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   546
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   547
 * 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
   548
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   549
 * 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
   550
 *  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
   551
 *  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
   552
 *  appropriate variables in the GL shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   553
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   554
 * (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
   555
 *  1 is the next four, etc.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   556
 * (data) is a pointer to (vec4count*4) floats.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   557
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   558
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   559
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   560
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   561
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   562
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   563
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
239
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   564
 *
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   565
 * Uniforms are not shared between contexts.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   566
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   567
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
   568
                                          unsigned int vec4count);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   569
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   570
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   571
 * 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
   572
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   573
 * 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
   574
 *  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
   575
 *  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
   576
 *  appropriate variables in the GL shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   577
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   578
 * (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
   579
 *  1 is the next four, etc.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   580
 * (data) is a pointer to (ivec4count*4) ints.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   581
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   582
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   583
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   584
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   585
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   586
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   587
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
239
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   588
 *
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   589
 * Uniforms are not shared between contexts.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   590
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   591
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
   592
                                          unsigned int ivec4count);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   593
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   594
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   595
 * 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
   596
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   597
 * 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
   598
 *  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
   599
 *  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
   600
 *  appropriate variables in the GL shaders.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   601
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   602
 * 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
   603
 *  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
   604
 *  array, not the fifth.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   605
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   606
 * 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
   607
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   608
 * (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
   609
 * (data) is a pointer to (bcount) ints.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   610
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   611
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   612
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   613
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   614
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   615
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   616
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
239
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   617
 *
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   618
 * Uniforms are not shared between contexts.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   619
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   620
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
   621
                                          unsigned int bcount);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   622
198
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   623
/*
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   624
 * The equivalent of MOJOSHADER_glSetVertexShaderUniformF() for pixel
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   625
 *  shaders. Other than using a different internal array that is specific
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   626
 *  to pixel shaders, this functions just like its vertex array equivalent.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   627
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   628
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   629
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   630
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   631
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   632
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   633
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
239
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   634
 *
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   635
 * Uniforms are not shared between contexts.
198
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   636
 */
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   637
void MOJOSHADER_glSetPixelShaderUniformF(unsigned int idx, const float *data,
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   638
                                         unsigned int vec4count);
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   639
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   640
/*
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   641
 * The equivalent of MOJOSHADER_glSetVertexShaderUniformI() for pixel
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   642
 *  shaders. Other than using a different internal array that is specific
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   643
 *  to pixel shaders, this functions just like its vertex array equivalent.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   644
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   645
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   646
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   647
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   648
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   649
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   650
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
239
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   651
 *
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   652
 * Uniforms are not shared between contexts.
198
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   653
 */
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   654
void MOJOSHADER_glSetPixelShaderUniformI(unsigned int idx, const int *data,
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   655
                                         unsigned int ivec4count);
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   656
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   657
/*
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   658
 * The equivalent of MOJOSHADER_glSetVertexShaderUniformB() for pixel
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   659
 *  shaders. Other than using a different internal array that is specific
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   660
 *  to pixel shaders, this functions just like its vertex array equivalent.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   661
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   662
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   663
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   664
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   665
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   666
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   667
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
239
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   668
 *
9a9971a6828d Minor documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 238
diff changeset
   669
 * Uniforms are not shared between contexts.
198
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   670
 */
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   671
void MOJOSHADER_glSetPixelShaderUniformB(unsigned int idx, const int *data,
e69f11a7b700 Added API to set pixel shader uniforms.
Ryan C. Gordon <icculus@icculus.org>
parents: 197
diff changeset
   672
                                         unsigned int bcount);
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   673
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   674
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   675
 * 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
   676
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   677
 * (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
   678
 *  be MOJOSHADER_USAGE_COLOR and 1.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   679
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   680
 * 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
   681
 *  if appropriate.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   682
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   683
 * 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
   684
 *  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
   685
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   686
 * (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
   687
 *  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
   688
 *  unmolested to that very entry point during this function).
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   689
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   690
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   691
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   692
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   693
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   694
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   695
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   696
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   697
 * Vertex attributes are not shared between contexts.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   698
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   699
void MOJOSHADER_glSetVertexAttribute(MOJOSHADER_usage usage,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   700
                                     int index, unsigned int size,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   701
                                     MOJOSHADER_attributeType type,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   702
                                     int normalized, unsigned int stride,
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   703
                                     const void *ptr);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   704
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   705
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   706
 * 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
   707
 *  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
   708
 *  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
   709
 *  constants array (etc) can propagate to the shader during this call.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   710
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   711
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   712
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   713
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   714
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   715
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   716
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   717
 */
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   718
void MOJOSHADER_glProgramReady(void);
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   719
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   720
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   721
 * 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
   722
 *  and free memory.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   723
 *
197
2ad08d31ea93 API design change.
Ryan C. Gordon <icculus@icculus.org>
parents: 196
diff changeset
   724
 * If the program is currently bound by MOJOSHADER_glBindProgram(), it will
2ad08d31ea93 API design change.
Ryan C. Gordon <icculus@icculus.org>
parents: 196
diff changeset
   725
 *  be deleted as soon as it becomes unbound.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   726
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   727
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   728
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   729
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   730
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   731
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   732
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   733
 */
199
03463c4621ad Reduced const insanity in API spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 198
diff changeset
   734
void MOJOSHADER_glDeleteProgram(MOJOSHADER_glProgram *program);
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   735
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   736
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   737
 * 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
   738
 *  and free memory.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   739
 *
197
2ad08d31ea93 API design change.
Ryan C. Gordon <icculus@icculus.org>
parents: 196
diff changeset
   740
 * If the shader is currently referenced by a linked program, it will
2ad08d31ea93 API design change.
Ryan C. Gordon <icculus@icculus.org>
parents: 196
diff changeset
   741
 *  be deleted as soon as all referencing programs are deleted, too.
217
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   742
 *
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   743
 * This call is NOT thread safe! As most OpenGL implementations are not thread
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   744
 *  safe, you should probably only call this from the same thread that created
611976ab1d25 Documentation update.
Ryan C. Gordon <icculus@icculus.org>
parents: 211
diff changeset
   745
 *  the GL context.
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   746
 *
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   747
 * This call requires a valid MOJOSHADER_glContext to have been made current,
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   748
 *  or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   749
 */
199
03463c4621ad Reduced const insanity in API spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 198
diff changeset
   750
void MOJOSHADER_glDeleteShader(MOJOSHADER_glShader *shader);
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   751
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   752
/*
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   753
 * Deinitialize MojoShader's OpenGL shader management.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   754
 *
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   755
 * You must call this once, while your GL context (not MojoShader context) is
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   756
 *  still current, if you previously had a successful call to
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   757
 *  MOJOSHADER_glCreateContext(). This should be the last MOJOSHADER_gl*
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   758
 *  function you call until you've prepared a context again.
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   759
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   760
 * 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
   761
 *
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   762
 * 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
   763
 *  MOJOSHADER_glDeleteShader() and MOJOSHADER_glDeleteProgram() to clean
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   764
 *  those up before calling this function!
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   765
 *
237
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   766
 * This function destroys the MOJOSHADER_glContext you pass it. If it's the
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   767
 *  current context, then no context will be current upon return.
09f35dfc1d7e OpenGL glue now allows for multiple contexts.
Ryan C. Gordon <icculus@icculus.org>
parents: 236
diff changeset
   768
 *
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   769
 * 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
   770
 *  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
   771
 *  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
   772
 *  thread that created the GL context.
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   773
 */
238
e98f14da2897 Renamed glInit and glDeinit to glCreateContext and glDestroyContext.
Ryan C. Gordon <icculus@icculus.org>
parents: 237
diff changeset
   774
void MOJOSHADER_glDestroyContext(MOJOSHADER_glContext *ctx);
196
5715754e5549 Initial API proposal for OpenGL glue.
Ryan C. Gordon <icculus@icculus.org>
parents: 190
diff changeset
   775
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   776
#ifdef __cplusplus
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   777
}
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   778
#endif
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   779
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   780
#endif  /* include-once blocker. */
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   781
35
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 20
diff changeset
   782
/* end of mojoshader.h ... */
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   783