author | Ryan C. Gordon <icculus@icculus.org> |
Sat, 19 Apr 2008 13:50:26 -0400 | |
branch | trunk |
changeset 151 | 1667680fe402 |
parent 148 | 645003ec6623 |
child 187 | 1c709f65cf1b |
permissions | -rw-r--r-- |
7 | 1 |
/** |
35 | 2 |
* MojoShader; generate shader programs from bytecode of compiled |
3 |
* Direct3D shaders. |
|
7 | 4 |
* |
5 |
* Please see the file LICENSE.txt in the source's root directory. |
|
6 |
* |
|
7 |
* This file written by Ryan C. Gordon. |
|
8 |
*/ |
|
9 |
||
35 | 10 |
#ifndef __INCL_MOJOSHADER_H_ |
11 |
#define __INCL_MOJOSHADER_H_ |
|
7 | 12 |
|
13 |
#ifdef __cplusplus |
|
14 |
extern "C" { |
|
15 |
#endif |
|
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 | 18 |
* For determining the version of MojoShader you are using: |
19 |
* const int compiled_against = MOJOSHADER_VERSION; |
|
20 |
* const int linked_against = MOJOSHADER_version(); |
|
21 |
* |
|
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 | 24 |
#define MOJOSHADER_VERSION 1 |
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 | 29 |
* (in fact, they probably use malloc() and free() internally if you don't |
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 | 38 |
|
39 |
/* |
|
40 |
* These are enum values, but they also can be used in bitmasks, so we can |
|
41 |
* test if an opcode is acceptable: if (op->shader_types & ourtype) {} ... |
|
42 |
*/ |
|
43 |
typedef enum |
|
44 |
{ |
|
45 |
MOJOSHADER_TYPE_UNKNOWN = 0, |
|
46 |
MOJOSHADER_TYPE_PIXEL = (1 << 0), |
|
47 |
MOJOSHADER_TYPE_VERTEX = (1 << 1), |
|
48 |
MOJOSHADER_TYPE_GEOMETRY = (1 << 2), /* (not supported yet.) */ |
|
49 |
MOJOSHADER_TYPE_ANY = 0xFFFFFFFF /* used for bitmasks */ |
|
50 |
} MOJOSHADER_shaderType; |
|
51 |
||
94
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
52 |
/* |
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
53 |
* Data types for uniforms. See MOJOSHADER_uniform for more information. |
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
54 |
*/ |
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
55 |
typedef enum |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
56 |
{ |
147
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
57 |
MOJOSHADER_UNIFORM_FLOAT, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
58 |
MOJOSHADER_UNIFORM_INT, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
59 |
MOJOSHADER_UNIFORM_BOOL, |
94
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
60 |
} MOJOSHADER_uniformType; |
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
61 |
|
94
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
62 |
/* |
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
63 |
* 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
|
64 |
* calls "Constants" ... IDirect3DDevice::SetVertexShaderConstantF() would |
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
65 |
* 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
|
66 |
* 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
|
67 |
* 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
|
68 |
* assembly language, before drawing with the shader. |
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
69 |
*/ |
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
70 |
typedef struct |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
71 |
{ |
100
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
72 |
MOJOSHADER_uniformType type; |
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
73 |
int index; |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
74 |
} MOJOSHADER_uniform; |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
75 |
|
100
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
76 |
/* |
148
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
77 |
* 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
|
78 |
*/ |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
79 |
typedef enum |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
80 |
{ |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
81 |
MOJOSHADER_SAMPLER_2D, |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
82 |
MOJOSHADER_SAMPLER_CUBE, |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
83 |
MOJOSHADER_SAMPLER_VOLUME, |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
84 |
} MOJOSHADER_samplerType; |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
85 |
|
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
86 |
/* |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
87 |
* 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
|
88 |
* 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
|
89 |
* 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
|
90 |
* 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
|
91 |
* 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
|
92 |
* before drawing with the shader. |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
93 |
*/ |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
94 |
typedef struct |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
95 |
{ |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
96 |
MOJOSHADER_samplerType type; |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
97 |
int index; |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
98 |
} MOJOSHADER_sampler; |
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 |
/* |
100
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
101 |
* 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
|
102 |
*/ |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
103 |
typedef enum |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
104 |
{ |
147
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
105 |
MOJOSHADER_USAGE_POSITION, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
106 |
MOJOSHADER_USAGE_BLENDWEIGHT, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
107 |
MOJOSHADER_USAGE_BLENDINDICES, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
108 |
MOJOSHADER_USAGE_NORMAL, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
109 |
MOJOSHADER_USAGE_POINTSIZE, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
110 |
MOJOSHADER_USAGE_TEXCOORD, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
111 |
MOJOSHADER_USAGE_TANGENT, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
112 |
MOJOSHADER_USAGE_BINORMAL, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
113 |
MOJOSHADER_USAGE_TESSFACTOR, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
114 |
MOJOSHADER_USAGE_POSITIONT, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
115 |
MOJOSHADER_USAGE_COLOR, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
116 |
MOJOSHADER_USAGE_FOG, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
117 |
MOJOSHADER_USAGE_DEPTH, |
98043daf5027
Removed explicit numbers on enums in mojoshader.h.
Ryan C. Gordon <icculus@icculus.org>
parents:
146
diff
changeset
|
118 |
MOJOSHADER_USAGE_SAMPLE, |
101
0834e95e5e76
First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents:
100
diff
changeset
|
119 |
MOJOSHADER_USAGE_TOTAL, /* housekeeping value; not ever returned. */ |
100
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
120 |
} MOJOSHADER_usage; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
121 |
|
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
122 |
/* |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
123 |
* 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
|
124 |
* Direct3D calls "Vertex Declarations Usages" ... |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
125 |
* IDirect3DDevice::CreateVertexDeclaration() would need this data, for |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
126 |
* 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
|
127 |
* 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
|
128 |
* 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
|
129 |
* before drawing. |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
130 |
*/ |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
131 |
typedef struct |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
132 |
{ |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
133 |
MOJOSHADER_usage usage; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
134 |
int index; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
135 |
} MOJOSHADER_attribute; |
46 | 136 |
|
137 |
/* |
|
138 |
* Structure used to return data from parsing of a shader... |
|
139 |
*/ |
|
140 |
typedef struct |
|
141 |
{ |
|
142 |
/* |
|
143 |
* Human-readable error, if there is one. Will be NULL if there was no |
|
144 |
* error. The string will be UTF-8 encoded, and English only. Most of |
|
145 |
* these shouldn't be shown to the end-user anyhow. |
|
146 |
*/ |
|
147 |
const char *error; |
|
148 |
||
149 |
/* |
|
150 |
* Bytes of output from parsing. Most profiles produce a string of source |
|
151 |
* code, but profiles that do binary output may not be text at all. |
|
152 |
* Will be NULL on error. |
|
153 |
*/ |
|
154 |
const char *output; |
|
155 |
||
156 |
/* |
|
157 |
* 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
|
158 |
* 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
|
159 |
* 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
|
160 |
* that do binary output may not be text at all. Will be 0 on error. |
46 | 161 |
*/ |
162 |
int output_len; |
|
163 |
||
164 |
/* |
|
165 |
* Count of Direct3D instructions we parsed. This is meaningless in terms |
|
166 |
* of the actual output, as the profile will probably grow or reduce |
|
167 |
* the count (or for high-level languages, not have that information at |
|
168 |
* all), but it can give you a rough idea of the size of your shader. |
|
169 |
* Will be zero on error. |
|
170 |
*/ |
|
171 |
int instruction_count; |
|
172 |
||
173 |
/* |
|
174 |
* The type of shader we parsed. Will be MOJOSHADER_TYPE_UNKNOWN on error. |
|
175 |
*/ |
|
176 |
MOJOSHADER_shaderType shader_type; |
|
177 |
||
178 |
/* |
|
179 |
* The shader's major version. If this was a "vs_3_0", this would be 3. |
|
180 |
*/ |
|
181 |
int major_ver; |
|
182 |
||
183 |
/* |
|
184 |
* The shader's minor version. If this was a "ps_1_4", this would be 4. |
|
185 |
* Two notes: for "vs_2_x", this is 1, and for "vs_3_sw", this is 255. |
|
186 |
*/ |
|
187 |
int minor_ver; |
|
188 |
||
189 |
/* |
|
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
190 |
* 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
|
191 |
*/ |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
192 |
int uniform_count; |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
193 |
|
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
194 |
/* |
94
57adfb4769a0
Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents:
92
diff
changeset
|
195 |
* (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
|
196 |
* 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
|
197 |
* 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
|
198 |
*/ |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
199 |
MOJOSHADER_uniform *uniforms; |
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
200 |
|
100
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
201 |
/* |
148
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
202 |
* 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
|
203 |
*/ |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
204 |
int sampler_count; |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
205 |
|
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
206 |
/* |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
207 |
* (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
|
208 |
* 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
|
209 |
* 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
|
210 |
*/ |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
211 |
MOJOSHADER_sampler *samplers; |
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
212 |
|
645003ec6623
Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents:
147
diff
changeset
|
213 |
/* |
100
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
214 |
* 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
|
215 |
*/ |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
216 |
int attribute_count; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
217 |
|
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
218 |
/* |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
219 |
* (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
|
220 |
* 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
|
221 |
* 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
|
222 |
*/ |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
223 |
MOJOSHADER_attribute *attributes; |
2b88649b6f98
First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents:
97
diff
changeset
|
224 |
|
92
bc1bb138e855
Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents:
46
diff
changeset
|
225 |
/* |
46 | 226 |
* This is the malloc implementation you passed to MOJOSHADER_parse(). |
227 |
*/ |
|
228 |
MOJOSHADER_malloc malloc; |
|
229 |
||
230 |
/* |
|
231 |
* This is the free implementation you passed to MOJOSHADER_parse(). |
|
232 |
*/ |
|
233 |
MOJOSHADER_free free; |
|
97
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
234 |
|
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
235 |
/* |
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
236 |
* 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
|
237 |
*/ |
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
238 |
void *malloc_data; |
46 | 239 |
} MOJOSHADER_parseData; |
240 |
||
241 |
||
242 |
/* |
|
243 |
* Profile string for Direct3D assembly language output. |
|
244 |
*/ |
|
245 |
#define MOJOSHADER_PROFILE_D3D "d3d" |
|
246 |
||
247 |
/* |
|
109
48e95cf41505
Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
248 |
* 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
|
249 |
*/ |
48e95cf41505
Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
250 |
#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
|
251 |
|
48e95cf41505
Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents:
101
diff
changeset
|
252 |
/* |
46 | 253 |
* Profile string for GLSL: OpenGL high-level shader language output. |
254 |
*/ |
|
255 |
#define MOJOSHADER_PROFILE_GLSL "glsl" |
|
256 |
||
97
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
257 |
|
46 | 258 |
/* |
259 |
* Parse a compiled Direct3D shader's bytecode. |
|
260 |
* |
|
261 |
* This is your primary entry point into MojoShader. You need to pass it |
|
262 |
* a compiled D3D shader and tell it which "profile" you want to use to |
|
263 |
* convert it into useful data. |
|
264 |
* |
|
265 |
* The available profiles are the set of MOJOSHADER_PROFILE_* defines. |
|
266 |
* Note that MojoShader may be built without support for all listed |
|
267 |
* profiles (in which case using one here will return with an error). |
|
268 |
* |
|
269 |
* As parsing requires some memory to be allocated, you may provide a custom |
|
270 |
* allocator to this function, which will be used to allocate/free memory. |
|
271 |
* 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
|
272 |
* 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
|
273 |
* 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
|
274 |
* (d) parameter. This pointer is passed as-is to your (m) and (f) functions. |
46 | 275 |
* |
97
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
276 |
* This function returns a MOJOSHADER_parseData. |
46 | 277 |
* |
278 |
* This function will never return NULL, even if the system is completely |
|
279 |
* out of memory upon entry (in which case, this function returns a static |
|
280 |
* MOJOSHADER_parseData object, which is still safe to pass to |
|
281 |
* MOJOSHADER_freeParseData()). |
|
282 |
* |
|
283 |
* This function is thread safe, so long (m) and (f) are too, and that |
|
284 |
* (tokenbuf) remains intact for the duration of the call. This allows you |
|
285 |
* to parse several shaders on separate CPU cores at the same time. |
|
286 |
*/ |
|
287 |
const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile, |
|
288 |
const unsigned char *tokenbuf, |
|
289 |
const unsigned int bufsize, |
|
290 |
MOJOSHADER_malloc m, |
|
97
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
291 |
MOJOSHADER_free f, |
4a41e3d17297
Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents:
94
diff
changeset
|
292 |
void *d); |
46 | 293 |
|
294 |
/* |
|
295 |
* Call this to dispose of parsing results when you are done with them. |
|
296 |
* This will call the MOJOSHADER_free function you provided to |
|
297 |
* MOJOSHADER_parse multiple times, if you provided one. |
|
298 |
* Passing a NULL here is a safe no-op. |
|
299 |
* |
|
300 |
* This function is thread safe, so long as any allocator you passed into |
|
301 |
* MOJOSHADER_parse() is, too. |
|
302 |
*/ |
|
303 |
void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *data); |
|
7 | 304 |
|
305 |
#ifdef __cplusplus |
|
306 |
} |
|
307 |
#endif |
|
308 |
||
309 |
#endif /* include-once blocker. */ |
|
310 |
||
35 | 311 |
/* end of mojoshader.h ... */ |
7 | 312 |