GLSL and ARB1: Implemented TEXM3X3 opcode.
2 * MojoShader; generate shader programs from bytecode of compiled
5 * Please see the file LICENSE.txt in the source's root directory.
7 * This file written by Ryan C. Gordon.
10 #ifndef _INCL_MOJOSHADER_H_
11 #define _INCL_MOJOSHADER_H_
17 /* You can define this if you aren't generating mojoshader_version.h */
18 #ifndef MOJOSHADER_NO_VERSION_INCLUDE
19 #include "mojoshader_version.h"
22 #ifndef MOJOSHADER_VERSION
23 #define MOJOSHADER_VERSION -1
26 #ifndef MOJOSHADER_CHANGESET
27 #define MOJOSHADER_CHANGESET "???"
31 * For determining the version of MojoShader you are using:
32 * const int compiled_against = MOJOSHADER_VERSION;
33 * const int linked_against = MOJOSHADER_version();
35 * The version is a single integer that increments, not a major/minor value.
37 int MOJOSHADER_version(void);
40 * For determining the revision control changeset of MojoShader you are using:
41 * const char *compiled_against = MOJOSHADER_CHANGESET;
42 * const char *linked_against = MOJOSHADER_changeset();
44 * The version is an arbitrary, null-terminated ASCII string. It is probably
45 * a hash that represents a revision control changeset, and can't be
46 * compared to any other string to determine chronology.
48 * Do not attempt to free this string; it's statically allocated.
50 const char *MOJOSHADER_changeset(void);
53 * These allocators work just like the C runtime's malloc() and free()
54 * (in fact, they probably use malloc() and free() internally if you don't
55 * specify your own allocator, but don't rely on that behaviour).
56 * (data) is the pointer you supplied when specifying these allocator
57 * callbacks, in case you need instance-specific data...it is passed through
58 * to your allocator unmolested, and can be NULL if you like.
60 typedef void *(*MOJOSHADER_malloc)(int bytes, void *data);
61 typedef void (*MOJOSHADER_free)(void *ptr, void *data);
65 * These are enum values, but they also can be used in bitmasks, so we can
66 * test if an opcode is acceptable: if (op->shader_types & ourtype) {} ...
70 MOJOSHADER_TYPE_UNKNOWN = 0,
71 MOJOSHADER_TYPE_PIXEL = (1 << 0),
72 MOJOSHADER_TYPE_VERTEX = (1 << 1),
73 MOJOSHADER_TYPE_GEOMETRY = (1 << 2), /* (not supported yet.) */
74 MOJOSHADER_TYPE_ANY = 0xFFFFFFFF /* used for bitmasks */
75 } MOJOSHADER_shaderType;
78 * Data types for vertex attribute streams.
82 MOJOSHADER_ATTRIBUTE_UNKNOWN = -1, /* housekeeping; not returned. */
83 MOJOSHADER_ATTRIBUTE_BYTE,
84 MOJOSHADER_ATTRIBUTE_UBYTE,
85 MOJOSHADER_ATTRIBUTE_SHORT,
86 MOJOSHADER_ATTRIBUTE_USHORT,
87 MOJOSHADER_ATTRIBUTE_INT,
88 MOJOSHADER_ATTRIBUTE_UINT,
89 MOJOSHADER_ATTRIBUTE_FLOAT,
90 MOJOSHADER_ATTRIBUTE_DOUBLE,
91 MOJOSHADER_ATTRIBUTE_HALF_FLOAT, /* MAYBE available in your OpenGL! */
92 } MOJOSHADER_attributeType;
95 * Data types for uniforms. See MOJOSHADER_uniform for more information.
99 MOJOSHADER_UNIFORM_UNKNOWN = -1, /* housekeeping value; never returned. */
100 MOJOSHADER_UNIFORM_FLOAT,
101 MOJOSHADER_UNIFORM_INT,
102 MOJOSHADER_UNIFORM_BOOL,
103 } MOJOSHADER_uniformType;
106 * These are the uniforms to be set for a shader. "Uniforms" are what Direct3D
107 * calls "Constants" ... IDirect3DDevice::SetVertexShaderConstantF() would
108 * need this data, for example. These integers are register indexes. So if
109 * index==6 and type==MOJOSHADER_UNIFORM_FLOAT, that means we'd expect a
110 * 4-float vector to be specified for what would be register "c6" in D3D
111 * assembly language, before drawing with the shader.
112 * (array_count) means this is an array of uniforms...this happens in some
113 * profiles when we see a relative address ("c0[a0.x]", not the usual "c0").
114 * In those cases, the shader was built to set some range of constant
115 * registers as an array. You should set this array with (array_count)
116 * elements from the constant register file, starting at (index) instead of
117 * just a single uniform. To be extra difficult, you'll need to fill in the
118 * correct values from the MOJOSHADER_constant data into the appropriate
119 * parts of the array, overriding the constant register file. Fun!
120 * (constant) says whether this is a constant array; these need to be loaded
121 * once at creation time, from the constant list and not ever updated from
122 * the constant register file. This is a workaround for limitations in some
124 * (name) is a profile-specific variable name; it may be NULL if it isn't
125 * applicable to the requested profile.
127 typedef struct MOJOSHADER_uniform
129 MOJOSHADER_uniformType type;
134 } MOJOSHADER_uniform;
137 * These are the constants defined in a shader. These are data values
138 * hardcoded in a shader (with the DEF, DEFI, DEFB instructions), which
139 * override your Uniforms. This data is largely for informational purposes,
140 * since they are compiled in and can't be changed, like Uniforms can be.
141 * These integers are register indexes. So if index==6 and
142 * type==MOJOSHADER_UNIFORM_FLOAT, that means we'd expect a 4-float vector
143 * to be specified for what would be register "c6" in D3D assembly language,
144 * before drawing with the shader.
145 * (value) is the value of the constant, unioned by type.
147 typedef struct MOJOSHADER_constant
149 MOJOSHADER_uniformType type;
153 float f[4]; /* if type==MOJOSHADER_UNIFORM_FLOAT */
154 int i[4]; /* if type==MOJOSHADER_UNIFORM_INT */
155 int b; /* if type==MOJOSHADER_UNIFORM_BOOL */
157 } MOJOSHADER_constant;
160 * Data types for samplers. See MOJOSHADER_sampler for more information.
164 MOJOSHADER_SAMPLER_UNKNOWN = -1, /* housekeeping value; never returned. */
165 MOJOSHADER_SAMPLER_2D,
166 MOJOSHADER_SAMPLER_CUBE,
167 MOJOSHADER_SAMPLER_VOLUME,
168 } MOJOSHADER_samplerType;
171 * These are the samplers to be set for a shader. ...
172 * IDirect3DDevice::SetTexture() would need this data, for example.
173 * These integers are the sampler "stage". So if index==6 and
174 * type==MOJOSHADER_SAMPLER_2D, that means we'd expect a regular 2D texture
175 * to be specified for what would be register "s6" in D3D assembly language,
176 * before drawing with the shader.
177 * (name) is a profile-specific variable name; it may be NULL if it isn't
178 * applicable to the requested profile.
179 * (texbem) will be non-zero if a TEXBEM opcode references this sampler. This
180 * is only used in legacy shaders (ps_1_1 through ps_1_3), but it needs some
181 * special support to work, as we have to load a magic uniform behind the
182 * scenes to support it. Most code can ignore this field in general, and no
183 * one has to touch it unless they really know what they're doing.
185 typedef struct MOJOSHADER_sampler
187 MOJOSHADER_samplerType type;
191 } MOJOSHADER_sampler;
194 * Data types for attributes. See MOJOSHADER_attribute for more information.
198 MOJOSHADER_USAGE_UNKNOWN = -1, /* housekeeping value; never returned. */
199 MOJOSHADER_USAGE_POSITION,
200 MOJOSHADER_USAGE_BLENDWEIGHT,
201 MOJOSHADER_USAGE_BLENDINDICES,
202 MOJOSHADER_USAGE_NORMAL,
203 MOJOSHADER_USAGE_POINTSIZE,
204 MOJOSHADER_USAGE_TEXCOORD,
205 MOJOSHADER_USAGE_TANGENT,
206 MOJOSHADER_USAGE_BINORMAL,
207 MOJOSHADER_USAGE_TESSFACTOR,
208 MOJOSHADER_USAGE_POSITIONT,
209 MOJOSHADER_USAGE_COLOR,
210 MOJOSHADER_USAGE_FOG,
211 MOJOSHADER_USAGE_DEPTH,
212 MOJOSHADER_USAGE_SAMPLE,
213 MOJOSHADER_USAGE_TOTAL, /* housekeeping value; never returned. */
217 * These are the attributes to be set for a shader. "Attributes" are what
218 * Direct3D calls "Vertex Declarations Usages" ...
219 * IDirect3DDevice::CreateVertexDeclaration() would need this data, for
220 * example. Each attribute is associated with an array of data that uses one
221 * element per-vertex. So if usage==MOJOSHADER_USAGE_COLOR and index==1, that
222 * means we'd expect a secondary color array to be bound to this shader
224 * (name) is a profile-specific variable name; it may be NULL if it isn't
225 * applicable to the requested profile.
227 typedef struct MOJOSHADER_attribute
229 MOJOSHADER_usage usage;
232 } MOJOSHADER_attribute;
235 * Use this if you want to specify newly-parsed code to swizzle incoming
236 * data. This can be useful if you know, at parse time, that a shader
237 * will be processing data on COLOR0 that should be RGBA, but you'll
238 * be passing it a vertex array full of ARGB instead.
240 typedef struct MOJOSHADER_swizzle
242 MOJOSHADER_usage usage;
244 unsigned char swizzles[4]; /* {0,1,2,3} == .xyzw, {2,2,2,2} == .zzzz */
245 } MOJOSHADER_swizzle;
249 * MOJOSHADER_symbol data.
251 * These are used to expose high-level information in shader bytecode.
252 * They associate HLSL variables with registers. This data is used for both
253 * debugging and optimization.
258 MOJOSHADER_SYMREGSET_BOOL,
259 MOJOSHADER_SYMREGSET_INT4,
260 MOJOSHADER_SYMREGSET_FLOAT4,
261 MOJOSHADER_SYMREGSET_SAMPLER,
262 } MOJOSHADER_symbolRegisterSet;
266 MOJOSHADER_SYMCLASS_SCALAR,
267 MOJOSHADER_SYMCLASS_VECTOR,
268 MOJOSHADER_SYMCLASS_MATRIX_ROWS,
269 MOJOSHADER_SYMCLASS_MATRIX_COLUMNS,
270 MOJOSHADER_SYMCLASS_OBJECT,
271 MOJOSHADER_SYMCLASS_STRUCT,
272 } MOJOSHADER_symbolClass;
276 MOJOSHADER_SYMTYPE_VOID,
277 MOJOSHADER_SYMTYPE_BOOL,
278 MOJOSHADER_SYMTYPE_INT,
279 MOJOSHADER_SYMTYPE_FLOAT,
280 MOJOSHADER_SYMTYPE_STRING,
281 MOJOSHADER_SYMTYPE_TEXTURE,
282 MOJOSHADER_SYMTYPE_TEXTURE1D,
283 MOJOSHADER_SYMTYPE_TEXTURE2D,
284 MOJOSHADER_SYMTYPE_TEXTURE3D,
285 MOJOSHADER_SYMTYPE_TEXTURECUBE,
286 MOJOSHADER_SYMTYPE_SAMPLER,
287 MOJOSHADER_SYMTYPE_SAMPLER1D,
288 MOJOSHADER_SYMTYPE_SAMPLER2D,
289 MOJOSHADER_SYMTYPE_SAMPLER3D,
290 MOJOSHADER_SYMTYPE_SAMPLERCUBE,
291 MOJOSHADER_SYMTYPE_PIXELSHADER,
292 MOJOSHADER_SYMTYPE_VERTEXSHADER,
293 MOJOSHADER_SYMTYPE_PIXELFRAGMENT,
294 MOJOSHADER_SYMTYPE_VERTEXFRAGMENT,
295 MOJOSHADER_SYMTYPE_UNSUPPORTED,
296 } MOJOSHADER_symbolType;
298 typedef struct MOJOSHADER_symbolStructMember MOJOSHADER_symbolStructMember;
300 typedef struct MOJOSHADER_symbolTypeInfo
302 MOJOSHADER_symbolClass parameter_class;
303 MOJOSHADER_symbolType parameter_type;
305 unsigned int columns;
306 unsigned int elements;
307 unsigned int member_count;
308 MOJOSHADER_symbolStructMember *members;
309 } MOJOSHADER_symbolTypeInfo;
311 struct MOJOSHADER_symbolStructMember
314 MOJOSHADER_symbolTypeInfo info;
317 typedef struct MOJOSHADER_symbol
320 MOJOSHADER_symbolRegisterSet register_set;
321 unsigned int register_index;
322 unsigned int register_count;
323 MOJOSHADER_symbolTypeInfo info;
328 * These are used with MOJOSHADER_error as special case positions.
330 #define MOJOSHADER_POSITION_NONE (-3)
331 #define MOJOSHADER_POSITION_BEFORE (-2)
332 #define MOJOSHADER_POSITION_AFTER (-1)
334 typedef struct MOJOSHADER_error
337 * Human-readable error, if there is one. Will be NULL if there was no
338 * error. The string will be UTF-8 encoded, and English only. Most of
339 * these shouldn't be shown to the end-user anyhow.
344 * Filename where error happened. This can be NULL if the information
347 const char *filename;
350 * Position of error, if there is one. Will be MOJOSHADER_POSITION_NONE if
351 * there was no error, MOJOSHADER_POSITION_BEFORE if there was an error
352 * before processing started, and MOJOSHADER_POSITION_AFTER if there was
353 * an error during final processing. If >= 0, MOJOSHADER_parse() sets
354 * this to the byte offset (starting at zero) into the bytecode you
355 * supplied, and MOJOSHADER_assemble(), MOJOSHADER_parseAst(), and
356 * MOJOSHADER_compile() sets this to a a line number in the source code
357 * you supplied (starting at one).
363 /* !!! FIXME: document me. */
364 typedef enum MOJOSHADER_preshaderOpcode
366 MOJOSHADER_PRESHADEROP_NOP,
367 MOJOSHADER_PRESHADEROP_MOV,
368 MOJOSHADER_PRESHADEROP_NEG,
369 MOJOSHADER_PRESHADEROP_RCP,
370 MOJOSHADER_PRESHADEROP_FRC,
371 MOJOSHADER_PRESHADEROP_EXP,
372 MOJOSHADER_PRESHADEROP_LOG,
373 MOJOSHADER_PRESHADEROP_RSQ,
374 MOJOSHADER_PRESHADEROP_SIN,
375 MOJOSHADER_PRESHADEROP_COS,
376 MOJOSHADER_PRESHADEROP_ASIN,
377 MOJOSHADER_PRESHADEROP_ACOS,
378 MOJOSHADER_PRESHADEROP_ATAN,
379 MOJOSHADER_PRESHADEROP_MIN,
380 MOJOSHADER_PRESHADEROP_MAX,
381 MOJOSHADER_PRESHADEROP_LT,
382 MOJOSHADER_PRESHADEROP_GE,
383 MOJOSHADER_PRESHADEROP_ADD,
384 MOJOSHADER_PRESHADEROP_MUL,
385 MOJOSHADER_PRESHADEROP_ATAN2,
386 MOJOSHADER_PRESHADEROP_DIV,
387 MOJOSHADER_PRESHADEROP_CMP,
388 MOJOSHADER_PRESHADEROP_MOVC,
389 MOJOSHADER_PRESHADEROP_DOT,
390 MOJOSHADER_PRESHADEROP_NOISE,
391 MOJOSHADER_PRESHADEROP_SCALAR_OPS,
392 MOJOSHADER_PRESHADEROP_MIN_SCALAR = MOJOSHADER_PRESHADEROP_SCALAR_OPS,
393 MOJOSHADER_PRESHADEROP_MAX_SCALAR,
394 MOJOSHADER_PRESHADEROP_LT_SCALAR,
395 MOJOSHADER_PRESHADEROP_GE_SCALAR,
396 MOJOSHADER_PRESHADEROP_ADD_SCALAR,
397 MOJOSHADER_PRESHADEROP_MUL_SCALAR,
398 MOJOSHADER_PRESHADEROP_ATAN2_SCALAR,
399 MOJOSHADER_PRESHADEROP_DIV_SCALAR,
400 MOJOSHADER_PRESHADEROP_DOT_SCALAR,
401 MOJOSHADER_PRESHADEROP_NOISE_SCALAR,
402 } MOJOSHADER_preshaderOpcode;
404 typedef enum MOJOSHADER_preshaderOperandType
406 MOJOSHADER_PRESHADEROPERAND_INPUT,
407 MOJOSHADER_PRESHADEROPERAND_OUTPUT,
408 MOJOSHADER_PRESHADEROPERAND_LITERAL,
409 MOJOSHADER_PRESHADEROPERAND_TEMP,
410 } MOJOSHADER_preshaderOperandType;
412 typedef struct MOJOSHADER_preshaderOperand
414 MOJOSHADER_preshaderOperandType type;
416 } MOJOSHADER_preshaderOperand;
418 typedef struct MOJOSHADER_preshaderInstruction
420 MOJOSHADER_preshaderOpcode opcode;
421 unsigned int element_count;
422 unsigned int operand_count;
423 MOJOSHADER_preshaderOperand operands[3];
424 } MOJOSHADER_preshaderInstruction;
426 typedef struct MOJOSHADER_preshader
428 unsigned int literal_count;
430 unsigned int temp_count; /* scalar, not vector! */
431 unsigned int symbol_count;
432 MOJOSHADER_symbol *symbols;
433 unsigned int instruction_count;
434 MOJOSHADER_preshaderInstruction *instructions;
435 } MOJOSHADER_preshader;
438 * Structure used to return data from parsing of a shader...
440 /* !!! FIXME: most of these ints should be unsigned. */
441 typedef struct MOJOSHADER_parseData
444 * The number of elements pointed to by (errors).
449 * (error_count) elements of data that specify errors that were generated
450 * by parsing this shader.
451 * This can be NULL if there were no errors or if (error_count) is zero.
453 MOJOSHADER_error *errors;
456 * The name of the profile used to parse the shader. Will be NULL on error.
461 * Bytes of output from parsing. Most profiles produce a string of source
462 * code, but profiles that do binary output may not be text at all.
463 * Will be NULL on error.
468 * Byte count for output, not counting any null terminator. Most profiles
469 * produce an ASCII string of source code (which will be null-terminated
470 * even though that null char isn't included in output_len), but profiles
471 * that do binary output may not be text at all. Will be 0 on error.
476 * Count of Direct3D instruction slots used. This is meaningless in terms
477 * of the actual output, as the profile will probably grow or reduce
478 * the count (or for high-level languages, not have that information at
479 * all). Also, as with Microsoft's own assembler, this value is just a
480 * rough estimate, as unpredicable real-world factors make the actual
481 * value vary at least a little from this count. Still, it can give you
482 * a rough idea of the size of your shader. Will be zero on error.
484 int instruction_count;
487 * The type of shader we parsed. Will be MOJOSHADER_TYPE_UNKNOWN on error.
489 MOJOSHADER_shaderType shader_type;
492 * The shader's major version. If this was a "vs_3_0", this would be 3.
497 * The shader's minor version. If this was a "ps_1_4", this would be 4.
498 * Two notes: for "vs_2_x", this is 1, and for "vs_3_sw", this is 255.
503 * The number of elements pointed to by (uniforms).
508 * (uniform_count) elements of data that specify Uniforms to be set for
509 * this shader. See discussion on MOJOSHADER_uniform for details.
510 * This can be NULL on error or if (uniform_count) is zero.
512 MOJOSHADER_uniform *uniforms;
515 * The number of elements pointed to by (constants).
520 * (constant_count) elements of data that specify constants used in
521 * this shader. See discussion on MOJOSHADER_constant for details.
522 * This can be NULL on error or if (constant_count) is zero.
523 * This is largely informational: constants are hardcoded into a shader.
524 * The constants that you can set like parameters are in the "uniforms"
527 MOJOSHADER_constant *constants;
530 * The number of elements pointed to by (samplers).
535 * (sampler_count) elements of data that specify Samplers to be set for
536 * this shader. See discussion on MOJOSHADER_sampler for details.
537 * This can be NULL on error or if (sampler_count) is zero.
539 MOJOSHADER_sampler *samplers;
541 /* !!! FIXME: this should probably be "input" and not "attribute" */
543 * The number of elements pointed to by (attributes).
547 /* !!! FIXME: this should probably be "input" and not "attribute" */
549 * (attribute_count) elements of data that specify Attributes to be set
550 * for this shader. See discussion on MOJOSHADER_attribute for details.
551 * This can be NULL on error or if (attribute_count) is zero.
553 MOJOSHADER_attribute *attributes;
556 * The number of elements pointed to by (outputs).
561 * (output_count) elements of data that specify outputs this shader
562 * writes to. See discussion on MOJOSHADER_attribute for details.
563 * This can be NULL on error or if (output_count) is zero.
565 MOJOSHADER_attribute *outputs;
568 * The number of elements pointed to by (swizzles).
572 /* !!! FIXME: this should probably be "input" and not "attribute" */
574 * (swizzle_count) elements of data that specify swizzles the shader will
575 * apply to incoming attributes. This is a copy of what was passed to
576 * MOJOSHADER_parseData().
577 * This can be NULL on error or if (swizzle_count) is zero.
579 MOJOSHADER_swizzle *swizzles;
582 * The number of elements pointed to by (symbols).
587 * (symbol_count) elements of data that specify high-level symbol data
588 * for the shader. This will be parsed from the CTAB section
589 * in bytecode, and will be a copy of what you provide to
590 * MOJOSHADER_assemble(). This data is optional.
591 * This can be NULL on error or if (symbol_count) is zero.
593 MOJOSHADER_symbol *symbols;
596 * !!! FIXME: document me.
597 * This can be NULL on error or if no preshader was available.
599 MOJOSHADER_preshader *preshader;
602 * This is the malloc implementation you passed to MOJOSHADER_parse().
604 MOJOSHADER_malloc malloc;
607 * This is the free implementation you passed to MOJOSHADER_parse().
609 MOJOSHADER_free free;
612 * This is the pointer you passed as opaque data for your allocator.
615 } MOJOSHADER_parseData;
619 * Profile string for Direct3D assembly language output.
621 #define MOJOSHADER_PROFILE_D3D "d3d"
624 * Profile string for passthrough of the original bytecode, unchanged.
626 #define MOJOSHADER_PROFILE_BYTECODE "bytecode"
629 * Profile string for GLSL: OpenGL high-level shader language output.
631 #define MOJOSHADER_PROFILE_GLSL "glsl"
634 * Profile string for GLSL 1.20: minor improvements to base GLSL spec.
636 #define MOJOSHADER_PROFILE_GLSL120 "glsl120"
639 * Profile string for OpenGL ARB 1.0 shaders: GL_ARB_(vertex|fragment)_program.
641 #define MOJOSHADER_PROFILE_ARB1 "arb1"
644 * Profile string for OpenGL ARB 1.0 shaders with Nvidia 2.0 extensions:
645 * GL_NV_vertex_program2_option and GL_NV_fragment_program2
647 #define MOJOSHADER_PROFILE_NV2 "nv2"
650 * Profile string for OpenGL ARB 1.0 shaders with Nvidia 3.0 extensions:
651 * GL_NV_vertex_program3 and GL_NV_fragment_program2
653 #define MOJOSHADER_PROFILE_NV3 "nv3"
656 * Profile string for OpenGL ARB 1.0 shaders with Nvidia 4.0 extensions:
659 #define MOJOSHADER_PROFILE_NV4 "nv4"
662 * Determine the highest supported Shader Model for a profile.
664 int MOJOSHADER_maxShaderModel(const char *profile);
668 * Parse a compiled Direct3D shader's bytecode.
670 * This is your primary entry point into MojoShader. You need to pass it
671 * a compiled D3D shader and tell it which "profile" you want to use to
672 * convert it into useful data.
674 * The available profiles are the set of MOJOSHADER_PROFILE_* defines.
675 * Note that MojoShader may be built without support for all listed
676 * profiles (in which case using one here will return with an error).
678 * As parsing requires some memory to be allocated, you may provide a custom
679 * allocator to this function, which will be used to allocate/free memory.
680 * They function just like malloc() and free(). We do not use realloc().
681 * If you don't care, pass NULL in for the allocator functions. If your
682 * allocator needs instance-specific data, you may supply it with the
683 * (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
685 * This function returns a MOJOSHADER_parseData.
687 * This function will never return NULL, even if the system is completely
688 * out of memory upon entry (in which case, this function returns a static
689 * MOJOSHADER_parseData object, which is still safe to pass to
690 * MOJOSHADER_freeParseData()).
692 * You can tell the generated program to swizzle certain inputs. If you know
693 * that COLOR0 should be RGBA but you're passing in ARGB, you can specify
694 * a swizzle of { MOJOSHADER_USAGE_COLOR, 0, {1,2,3,0} } to (swiz). If the
695 * input register in the code would produce reg.ywzx, that swizzle would
696 * change it to reg.wzxy ... (swiz) can be NULL.
698 * This function is thread safe, so long as (m) and (f) are too, and that
699 * (tokenbuf) remains intact for the duration of the call. This allows you
700 * to parse several shaders on separate CPU cores at the same time.
702 const MOJOSHADER_parseData *MOJOSHADER_parse(const char *profile,
703 const unsigned char *tokenbuf,
704 const unsigned int bufsize,
705 const MOJOSHADER_swizzle *swiz,
706 const unsigned int swizcount,
712 * Call this to dispose of parsing results when you are done with them.
713 * This will call the MOJOSHADER_free function you provided to
714 * MOJOSHADER_parse multiple times, if you provided one.
715 * Passing a NULL here is a safe no-op.
717 * This function is thread safe, so long as any allocator you passed into
718 * MOJOSHADER_parse() is, too.
720 void MOJOSHADER_freeParseData(const MOJOSHADER_parseData *data);
723 /* Effects interface... */ /* !!! FIXME: THIS API IS NOT STABLE YET! */
725 typedef struct MOJOSHADER_effectParam
728 const char *semantic;
729 } MOJOSHADER_effectParam;
731 typedef struct MOJOSHADER_effectState
734 } MOJOSHADER_effectState;
736 typedef struct MOJOSHADER_effectPass
739 unsigned int state_count;
740 MOJOSHADER_effectState *states;
741 } MOJOSHADER_effectPass;
743 typedef struct MOJOSHADER_effectTechnique
746 unsigned int pass_count;
747 MOJOSHADER_effectPass *passes;
748 } MOJOSHADER_effectTechnique;
750 typedef struct MOJOSHADER_effectTexture
754 } MOJOSHADER_effectTexture;
756 typedef struct MOJOSHADER_effectShader
758 unsigned int technique;
760 const MOJOSHADER_parseData *shader;
761 } MOJOSHADER_effectShader;
764 * Structure used to return data from parsing of an effect file...
766 /* !!! FIXME: most of these ints should be unsigned. */
767 typedef struct MOJOSHADER_effect
770 * The number of elements pointed to by (errors).
775 * (error_count) elements of data that specify errors that were generated
776 * by parsing this shader.
777 * This can be NULL if there were no errors or if (error_count) is zero.
779 MOJOSHADER_error *errors;
782 * The name of the profile used to parse the shader. Will be NULL on error.
787 * The number of params pointed to by (params).
792 * (param_count) elements of data that specify parameter bind points for
794 * This can be NULL on error or if (param_count) is zero.
796 MOJOSHADER_effectParam *params;
799 * The number of elements pointed to by (techniques).
804 * (technique_count) elements of data that specify techniques used in
805 * this effect. Each technique contains a series of passes, and each pass
806 * specifies state and shaders that affect rendering.
807 * This can be NULL on error or if (technique_count) is zero.
809 MOJOSHADER_effectTechnique *techniques;
812 * The number of elements pointed to by (textures).
817 * (texture_count) elements of data that specify textures used in
819 * This can be NULL on error or if (texture_count) is zero.
821 MOJOSHADER_effectTexture *textures;
824 * The number of elements pointed to by (shaders).
829 * (shader_count) elements of data that specify shaders used in
831 * This can be NULL on error or if (shader_count) is zero.
833 MOJOSHADER_effectShader *shaders;
836 * This is the malloc implementation you passed to MOJOSHADER_parseEffect().
838 MOJOSHADER_malloc malloc;
841 * This is the free implementation you passed to MOJOSHADER_parseEffect().
843 MOJOSHADER_free free;
846 * This is the pointer you passed as opaque data for your allocator.
851 /* !!! FIXME: document me. */
852 const MOJOSHADER_effect *MOJOSHADER_parseEffect(const char *profile,
853 const unsigned char *buf,
854 const unsigned int _len,
855 const MOJOSHADER_swizzle *swiz,
856 const unsigned int swizcount,
862 /* !!! FIXME: document me. */
863 void MOJOSHADER_freeEffect(const MOJOSHADER_effect *effect);
866 /* Preprocessor interface... */
869 * Structure used to pass predefined macros. Maps to D3DXMACRO.
870 * You can have macro arguments: set identifier to "a(b, c)" or whatever.
872 typedef struct MOJOSHADER_preprocessorDefine
874 const char *identifier;
875 const char *definition;
876 } MOJOSHADER_preprocessorDefine;
879 * Used with the MOJOSHADER_includeOpen callback. Maps to D3DXINCLUDE_TYPE.
883 MOJOSHADER_INCLUDETYPE_LOCAL, /* local header: #include "blah.h" */
884 MOJOSHADER_INCLUDETYPE_SYSTEM /* system header: #include <blah.h> */
885 } MOJOSHADER_includeType;
889 * Structure used to return data from preprocessing of a shader...
891 /* !!! FIXME: most of these ints should be unsigned. */
892 typedef struct MOJOSHADER_preprocessData
895 * The number of elements pointed to by (errors).
900 * (error_count) elements of data that specify errors that were generated
901 * by parsing this shader.
902 * This can be NULL if there were no errors or if (error_count) is zero.
904 MOJOSHADER_error *errors;
907 * Bytes of output from preprocessing. This is a UTF-8 string. We
908 * guarantee it to be NULL-terminated. Will be NULL on error.
913 * Byte count for output, not counting any null terminator.
914 * Will be 0 on error.
919 * This is the malloc implementation you passed to MOJOSHADER_parse().
921 MOJOSHADER_malloc malloc;
924 * This is the free implementation you passed to MOJOSHADER_parse().
926 MOJOSHADER_free free;
929 * This is the pointer you passed as opaque data for your allocator.
932 } MOJOSHADER_preprocessData;
936 * This callback allows an app to handle #include statements for the
937 * preprocessor. When the preprocessor sees an #include, it will call this
938 * function to obtain the contents of the requested file. This is optional;
939 * the preprocessor will open files directly if no callback is supplied, but
940 * this allows an app to retrieve data from something other than the
941 * traditional filesystem (for example, headers packed in a .zip file or
942 * headers generated on-the-fly).
944 * This function maps to ID3DXInclude::Open()
946 * (inctype) specifies the type of header we wish to include.
947 * (fname) specifies the name of the file specified on the #include line.
948 * (parent) is a string of the entire source file containing the include, in
949 * its original, not-yet-preprocessed state. Note that this is just the
950 * contents of the specific file, not all source code that the preprocessor
951 * has seen through other includes, etc.
952 * (outdata) will be set by the callback to a pointer to the included file's
953 * contents. The callback is responsible for allocating this however they
954 * see fit (we provide allocator functions, but you may ignore them). This
955 * pointer must remain valid until the includeClose callback runs. This
956 * string does not need to be NULL-terminated.
957 * (outbytes) will be set by the callback to the number of bytes pointed to
959 * (m),(f), and (d) are the allocator details that the application passed to
960 * MojoShader. If these were NULL, MojoShader may have replaced them with its
961 * own internal allocators.
963 * The callback returns zero on error, non-zero on success.
965 * If you supply an includeOpen callback, you must supply includeClose, too.
967 typedef int (*MOJOSHADER_includeOpen)(MOJOSHADER_includeType inctype,
968 const char *fname, const char *parent,
969 const char **outdata, unsigned int *outbytes,
970 MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
973 * This callback allows an app to clean up the results of a previous
974 * includeOpen callback.
976 * This function maps to ID3DXInclude::Close()
978 * (data) is the data that was returned from a previous call to includeOpen.
979 * It is now safe to deallocate this data.
980 * (m),(f), and (d) are the same allocator details that were passed to your
981 * includeOpen callback.
983 * If you supply an includeClose callback, you must supply includeOpen, too.
985 typedef void (*MOJOSHADER_includeClose)(const char *data,
986 MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
990 * This function is optional. Even if you are dealing with shader source
991 * code, you don't need to explicitly use the preprocessor, as the compiler
992 * and assembler will use it behind the scenes. In fact, you probably never
993 * need this function unless you are debugging a custom tool (or debugging
994 * MojoShader itself).
996 * Preprocessing roughly follows the syntax of an ANSI C preprocessor, as
997 * Microsoft's Direct3D assembler and HLSL compiler use this syntax. Please
998 * note that we try to match the output you'd get from Direct3D's
999 * preprocessor, which has some quirks if you're expecting output that matches
1000 * a generic C preprocessor.
1002 * This function maps to D3DXPreprocessShader().
1004 * (filename) is a NULL-terminated UTF-8 filename. It can be NULL. We do not
1005 * actually access this file, as we obtain our data from (source). This
1006 * string is copied when we need to report errors while processing (source),
1007 * as opposed to errors in a file referenced via the #include directive in
1008 * (source). If this is NULL, then errors will report the filename as NULL,
1011 * (source) is an string of UTF-8 text to preprocess. It does not need to be
1014 * (sourcelen) is the length of the string pointed to by (source), in bytes.
1016 * (defines) points to (define_count) preprocessor definitions, and can be
1017 * NULL. These are treated by the preprocessor as if the source code started
1018 * with one #define for each entry you pass in here.
1020 * (include_open) and (include_close) let the app control the preprocessor's
1021 * behaviour for #include statements. Both are optional and can be NULL, but
1022 * both must be specified if either is specified.
1024 * This will return a MOJOSHADER_preprocessorData. You should pass this
1025 * return value to MOJOSHADER_freePreprocessData() when you are done with
1028 * This function will never return NULL, even if the system is completely
1029 * out of memory upon entry (in which case, this function returns a static
1030 * MOJOSHADER_preprocessData object, which is still safe to pass to
1031 * MOJOSHADER_freePreprocessData()).
1033 * As preprocessing requires some memory to be allocated, you may provide a
1034 * custom allocator to this function, which will be used to allocate/free
1035 * memory. They function just like malloc() and free(). We do not use
1036 * realloc(). If you don't care, pass NULL in for the allocator functions.
1037 * If your allocator needs instance-specific data, you may supply it with the
1038 * (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
1040 * This function is thread safe, so long as the various callback functions
1041 * are, too, and that the parameters remains intact for the duration of the
1042 * call. This allows you to preprocess several shaders on separate CPU cores
1045 const MOJOSHADER_preprocessData *MOJOSHADER_preprocess(const char *filename,
1046 const char *source, unsigned int sourcelen,
1047 const MOJOSHADER_preprocessorDefine *defines,
1048 unsigned int define_count,
1049 MOJOSHADER_includeOpen include_open,
1050 MOJOSHADER_includeClose include_close,
1051 MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
1055 * Call this to dispose of preprocessing results when you are done with them.
1056 * This will call the MOJOSHADER_free function you provided to
1057 * MOJOSHADER_preprocess() multiple times, if you provided one.
1058 * Passing a NULL here is a safe no-op.
1060 * This function is thread safe, so long as any allocator you passed into
1061 * MOJOSHADER_preprocess() is, too.
1063 void MOJOSHADER_freePreprocessData(const MOJOSHADER_preprocessData *data);
1066 /* Assembler interface... */
1069 * This function is optional. Use this to convert Direct3D shader assembly
1070 * language into bytecode, which can be handled by MOJOSHADER_parse().
1072 * (filename) is a NULL-terminated UTF-8 filename. It can be NULL. We do not
1073 * actually access this file, as we obtain our data from (source). This
1074 * string is copied when we need to report errors while processing (source),
1075 * as opposed to errors in a file referenced via the #include directive in
1076 * (source). If this is NULL, then errors will report the filename as NULL,
1079 * (source) is an UTF-8 string of valid Direct3D shader assembly source code.
1080 * It does not need to be NULL-terminated.
1082 * (sourcelen) is the length of the string pointed to by (source), in bytes.
1084 * (comments) points to (comment_count) NULL-terminated UTF-8 strings, and
1085 * can be NULL. These strings are inserted as comments in the bytecode.
1087 * (symbols) points to (symbol_count) symbol structs, and can be NULL. These
1088 * become a CTAB field in the bytecode. This is optional, but
1089 * MOJOSHADER_parse() needs CTAB data for all arrays used in a program, or
1090 * relative addressing will not be permitted, so you'll want to at least
1091 * provide symbol information for those. The symbol data is 100% trusted
1092 * at this time; it will not be checked to see if it matches what was
1093 * assembled in any way whatsoever.
1095 * (defines) points to (define_count) preprocessor definitions, and can be
1096 * NULL. These are treated by the preprocessor as if the source code started
1097 * with one #define for each entry you pass in here.
1099 * (include_open) and (include_close) let the app control the preprocessor's
1100 * behaviour for #include statements. Both are optional and can be NULL, but
1101 * both must be specified if either is specified.
1103 * This will return a MOJOSHADER_parseData, like MOJOSHADER_parse() would,
1104 * except the profile will be MOJOSHADER_PROFILE_BYTECODE and the output
1105 * will be the assembled bytecode instead of some other language. This output
1106 * can be pushed back through MOJOSHADER_parseData() with a different profile.
1108 * This function will never return NULL, even if the system is completely
1109 * out of memory upon entry (in which case, this function returns a static
1110 * MOJOSHADER_parseData object, which is still safe to pass to
1111 * MOJOSHADER_freeParseData()).
1113 * As assembling requires some memory to be allocated, you may provide a
1114 * custom allocator to this function, which will be used to allocate/free
1115 * memory. They function just like malloc() and free(). We do not use
1116 * realloc(). If you don't care, pass NULL in for the allocator functions.
1117 * If your allocator needs instance-specific data, you may supply it with the
1118 * (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
1120 * This function is thread safe, so long as the various callback functions
1121 * are, too, and that the parameters remains intact for the duration of the
1122 * call. This allows you to assemble several shaders on separate CPU cores
1125 const MOJOSHADER_parseData *MOJOSHADER_assemble(const char *filename,
1126 const char *source, unsigned int sourcelen,
1127 const char **comments, unsigned int comment_count,
1128 const MOJOSHADER_symbol *symbols,
1129 unsigned int symbol_count,
1130 const MOJOSHADER_preprocessorDefine *defines,
1131 unsigned int define_count,
1132 MOJOSHADER_includeOpen include_open,
1133 MOJOSHADER_includeClose include_close,
1134 MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
1137 /* High level shading language support... */
1140 * Source profile strings for HLSL: Direct3D High Level Shading Language.
1142 #define MOJOSHADER_SRC_PROFILE_HLSL_VS_1_1 "hlsl_vs_1_1"
1143 #define MOJOSHADER_SRC_PROFILE_HLSL_VS_2_0 "hlsl_vs_2_0"
1144 #define MOJOSHADER_SRC_PROFILE_HLSL_VS_3_0 "hlsl_vs_3_0"
1145 #define MOJOSHADER_SRC_PROFILE_HLSL_PS_1_1 "hlsl_ps_1_1"
1146 #define MOJOSHADER_SRC_PROFILE_HLSL_PS_1_2 "hlsl_ps_1_2"
1147 #define MOJOSHADER_SRC_PROFILE_HLSL_PS_1_3 "hlsl_ps_1_3"
1148 #define MOJOSHADER_SRC_PROFILE_HLSL_PS_1_4 "hlsl_ps_1_4"
1149 #define MOJOSHADER_SRC_PROFILE_HLSL_PS_2_0 "hlsl_ps_2_0"
1150 #define MOJOSHADER_SRC_PROFILE_HLSL_PS_3_0 "hlsl_ps_3_0"
1153 /* Abstract Syntax Tree interface... */
1156 * ATTENTION: This adds a lot of stuff to the API, but almost everyone can
1157 * ignore this section. Seriously, go ahead and skip over anything that has
1158 * "AST" in it, unless you know why you'd want to use it.
1160 * ALSO: This API is still evolving! We make no promises at this time to keep
1161 * source or binary compatibility for the AST pieces.
1164 * - ASTs are the result of parsing the source code: a program that fails to
1165 * compile will often parse successfully. Undeclared variables,
1166 * type incompatibilities, etc, aren't detected at this point.
1167 * - Vector swizzles (the ".xyzw" part of "MyVec4.xyzw") will look like
1168 * structure dereferences. We don't realize these are actually swizzles
1169 * until semantic analysis.
1170 * - MOJOSHADER_astDataType info is not reliable when returned from
1171 * MOJOSHADER_parseAst()! Most of the datatype info will be missing or have
1172 * inaccurate data types. We sort these out during semantic analysis, which
1173 * happens after the AST parsing is complete. A few are filled in, or can
1174 * be deduced fairly trivially by processing several pieces into one.
1175 * It's enough that you can reproduce the original source code, more or
1176 * less, from the AST.
1179 /* High-level datatypes for AST nodes. */
1180 typedef enum MOJOSHADER_astDataTypeType
1182 MOJOSHADER_AST_DATATYPE_NONE,
1183 MOJOSHADER_AST_DATATYPE_BOOL,
1184 MOJOSHADER_AST_DATATYPE_INT,
1185 MOJOSHADER_AST_DATATYPE_UINT,
1186 MOJOSHADER_AST_DATATYPE_FLOAT,
1187 MOJOSHADER_AST_DATATYPE_FLOAT_SNORM,
1188 MOJOSHADER_AST_DATATYPE_FLOAT_UNORM,
1189 MOJOSHADER_AST_DATATYPE_HALF,
1190 MOJOSHADER_AST_DATATYPE_DOUBLE,
1191 MOJOSHADER_AST_DATATYPE_STRING,
1192 MOJOSHADER_AST_DATATYPE_SAMPLER_1D,
1193 MOJOSHADER_AST_DATATYPE_SAMPLER_2D,
1194 MOJOSHADER_AST_DATATYPE_SAMPLER_3D,
1195 MOJOSHADER_AST_DATATYPE_SAMPLER_CUBE,
1196 MOJOSHADER_AST_DATATYPE_SAMPLER_STATE,
1197 MOJOSHADER_AST_DATATYPE_SAMPLER_COMPARISON_STATE,
1198 MOJOSHADER_AST_DATATYPE_STRUCT,
1199 MOJOSHADER_AST_DATATYPE_ARRAY,
1200 MOJOSHADER_AST_DATATYPE_VECTOR,
1201 MOJOSHADER_AST_DATATYPE_MATRIX,
1202 MOJOSHADER_AST_DATATYPE_BUFFER,
1203 MOJOSHADER_AST_DATATYPE_FUNCTION,
1204 MOJOSHADER_AST_DATATYPE_USER,
1205 } MOJOSHADER_astDataTypeType;
1206 #define MOJOSHADER_AST_DATATYPE_CONST (1 << 31)
1208 typedef union MOJOSHADER_astDataType MOJOSHADER_astDataType;
1210 // This is just part of DataTypeStruct, never appears outside of it.
1211 typedef struct MOJOSHADER_astDataTypeStructMember
1213 const MOJOSHADER_astDataType *datatype;
1214 const char *identifier;
1215 } MOJOSHADER_astDataTypeStructMember;
1217 typedef struct MOJOSHADER_astDataTypeStruct
1219 MOJOSHADER_astDataTypeType type;
1220 const MOJOSHADER_astDataTypeStructMember *members;
1222 } MOJOSHADER_astDataTypeStruct;
1224 typedef struct MOJOSHADER_astDataTypeArray
1226 MOJOSHADER_astDataTypeType type;
1227 const MOJOSHADER_astDataType *base;
1229 } MOJOSHADER_astDataTypeArray;
1231 typedef MOJOSHADER_astDataTypeArray MOJOSHADER_astDataTypeVector;
1233 typedef struct MOJOSHADER_astDataTypeMatrix
1235 MOJOSHADER_astDataTypeType type;
1236 const MOJOSHADER_astDataType *base;
1239 } MOJOSHADER_astDataTypeMatrix;
1241 typedef struct MOJOSHADER_astDataTypeBuffer
1243 MOJOSHADER_astDataTypeType type;
1244 const MOJOSHADER_astDataType *base;
1245 } MOJOSHADER_astDataTypeBuffer;
1247 typedef struct MOJOSHADER_astDataTypeFunction
1249 MOJOSHADER_astDataTypeType type;
1250 const MOJOSHADER_astDataType *retval;
1251 const MOJOSHADER_astDataType **params;
1253 int intrinsic; /* non-zero for built-in functions */
1254 } MOJOSHADER_astDataTypeFunction;
1256 typedef struct MOJOSHADER_astDataTypeUser
1258 MOJOSHADER_astDataTypeType type;
1259 const MOJOSHADER_astDataType *details;
1261 } MOJOSHADER_astDataTypeUser;
1263 union MOJOSHADER_astDataType
1265 MOJOSHADER_astDataTypeType type;
1266 MOJOSHADER_astDataTypeArray array;
1267 MOJOSHADER_astDataTypeStruct structure;
1268 MOJOSHADER_astDataTypeVector vector;
1269 MOJOSHADER_astDataTypeMatrix matrix;
1270 MOJOSHADER_astDataTypeBuffer buffer;
1271 MOJOSHADER_astDataTypeUser user;
1272 MOJOSHADER_astDataTypeFunction function;
1275 /* Structures that make up the parse tree... */
1277 typedef enum MOJOSHADER_astNodeType
1279 MOJOSHADER_AST_OP_START_RANGE, /* expression operators. */
1281 MOJOSHADER_AST_OP_START_RANGE_UNARY, /* unary operators. */
1282 MOJOSHADER_AST_OP_PREINCREMENT,
1283 MOJOSHADER_AST_OP_PREDECREMENT,
1284 MOJOSHADER_AST_OP_NEGATE,
1285 MOJOSHADER_AST_OP_COMPLEMENT,
1286 MOJOSHADER_AST_OP_NOT,
1287 MOJOSHADER_AST_OP_POSTINCREMENT,
1288 MOJOSHADER_AST_OP_POSTDECREMENT,
1289 MOJOSHADER_AST_OP_CAST,
1290 MOJOSHADER_AST_OP_END_RANGE_UNARY,
1292 MOJOSHADER_AST_OP_START_RANGE_BINARY, /* binary operators. */
1293 MOJOSHADER_AST_OP_COMMA,
1294 MOJOSHADER_AST_OP_MULTIPLY,
1295 MOJOSHADER_AST_OP_DIVIDE,
1296 MOJOSHADER_AST_OP_MODULO,
1297 MOJOSHADER_AST_OP_ADD,
1298 MOJOSHADER_AST_OP_SUBTRACT,
1299 MOJOSHADER_AST_OP_LSHIFT,
1300 MOJOSHADER_AST_OP_RSHIFT,
1301 MOJOSHADER_AST_OP_LESSTHAN,
1302 MOJOSHADER_AST_OP_GREATERTHAN,
1303 MOJOSHADER_AST_OP_LESSTHANOREQUAL,
1304 MOJOSHADER_AST_OP_GREATERTHANOREQUAL,
1305 MOJOSHADER_AST_OP_EQUAL,
1306 MOJOSHADER_AST_OP_NOTEQUAL,
1307 MOJOSHADER_AST_OP_BINARYAND,
1308 MOJOSHADER_AST_OP_BINARYXOR,
1309 MOJOSHADER_AST_OP_BINARYOR,
1310 MOJOSHADER_AST_OP_LOGICALAND,
1311 MOJOSHADER_AST_OP_LOGICALOR,
1312 MOJOSHADER_AST_OP_ASSIGN,
1313 MOJOSHADER_AST_OP_MULASSIGN,
1314 MOJOSHADER_AST_OP_DIVASSIGN,
1315 MOJOSHADER_AST_OP_MODASSIGN,
1316 MOJOSHADER_AST_OP_ADDASSIGN,
1317 MOJOSHADER_AST_OP_SUBASSIGN,
1318 MOJOSHADER_AST_OP_LSHIFTASSIGN,
1319 MOJOSHADER_AST_OP_RSHIFTASSIGN,
1320 MOJOSHADER_AST_OP_ANDASSIGN,
1321 MOJOSHADER_AST_OP_XORASSIGN,
1322 MOJOSHADER_AST_OP_ORASSIGN,
1323 MOJOSHADER_AST_OP_DEREF_ARRAY,
1324 MOJOSHADER_AST_OP_END_RANGE_BINARY,
1326 MOJOSHADER_AST_OP_START_RANGE_TERNARY, /* ternary operators. */
1327 MOJOSHADER_AST_OP_CONDITIONAL,
1328 MOJOSHADER_AST_OP_END_RANGE_TERNARY,
1330 MOJOSHADER_AST_OP_START_RANGE_DATA, /* expression operands. */
1331 MOJOSHADER_AST_OP_IDENTIFIER,
1332 MOJOSHADER_AST_OP_INT_LITERAL,
1333 MOJOSHADER_AST_OP_FLOAT_LITERAL,
1334 MOJOSHADER_AST_OP_STRING_LITERAL,
1335 MOJOSHADER_AST_OP_BOOLEAN_LITERAL,
1336 MOJOSHADER_AST_OP_END_RANGE_DATA,
1338 MOJOSHADER_AST_OP_START_RANGE_MISC, /* other expression things. */
1339 MOJOSHADER_AST_OP_DEREF_STRUCT,
1340 MOJOSHADER_AST_OP_CALLFUNC,
1341 MOJOSHADER_AST_OP_CONSTRUCTOR,
1342 MOJOSHADER_AST_OP_END_RANGE_MISC,
1343 MOJOSHADER_AST_OP_END_RANGE,
1345 MOJOSHADER_AST_COMPUNIT_START_RANGE, /* things in global scope. */
1346 MOJOSHADER_AST_COMPUNIT_FUNCTION,
1347 MOJOSHADER_AST_COMPUNIT_TYPEDEF,
1348 MOJOSHADER_AST_COMPUNIT_STRUCT,
1349 MOJOSHADER_AST_COMPUNIT_VARIABLE,
1350 MOJOSHADER_AST_COMPUNIT_END_RANGE,
1352 MOJOSHADER_AST_STATEMENT_START_RANGE, /* statements in function scope. */
1353 MOJOSHADER_AST_STATEMENT_EMPTY,
1354 MOJOSHADER_AST_STATEMENT_BREAK,
1355 MOJOSHADER_AST_STATEMENT_CONTINUE,
1356 MOJOSHADER_AST_STATEMENT_DISCARD,
1357 MOJOSHADER_AST_STATEMENT_BLOCK,
1358 MOJOSHADER_AST_STATEMENT_EXPRESSION,
1359 MOJOSHADER_AST_STATEMENT_IF,
1360 MOJOSHADER_AST_STATEMENT_SWITCH,
1361 MOJOSHADER_AST_STATEMENT_FOR,
1362 MOJOSHADER_AST_STATEMENT_DO,
1363 MOJOSHADER_AST_STATEMENT_WHILE,
1364 MOJOSHADER_AST_STATEMENT_RETURN,
1365 MOJOSHADER_AST_STATEMENT_TYPEDEF,
1366 MOJOSHADER_AST_STATEMENT_STRUCT,
1367 MOJOSHADER_AST_STATEMENT_VARDECL,
1368 MOJOSHADER_AST_STATEMENT_END_RANGE,
1370 MOJOSHADER_AST_MISC_START_RANGE, /* misc. syntactic glue. */
1371 MOJOSHADER_AST_FUNCTION_PARAMS,
1372 MOJOSHADER_AST_FUNCTION_SIGNATURE,
1373 MOJOSHADER_AST_SCALAR_OR_ARRAY,
1374 MOJOSHADER_AST_TYPEDEF,
1375 MOJOSHADER_AST_PACK_OFFSET,
1376 MOJOSHADER_AST_VARIABLE_LOWLEVEL,
1377 MOJOSHADER_AST_ANNOTATION,
1378 MOJOSHADER_AST_VARIABLE_DECLARATION,
1379 MOJOSHADER_AST_STRUCT_DECLARATION,
1380 MOJOSHADER_AST_STRUCT_MEMBER,
1381 MOJOSHADER_AST_SWITCH_CASE,
1382 MOJOSHADER_AST_ARGUMENTS,
1383 MOJOSHADER_AST_MISC_END_RANGE,
1385 MOJOSHADER_AST_END_RANGE
1386 } MOJOSHADER_astNodeType;
1388 typedef struct MOJOSHADER_astNodeInfo
1390 MOJOSHADER_astNodeType type;
1391 const char *filename;
1393 } MOJOSHADER_astNodeInfo;
1395 typedef enum MOJOSHADER_astVariableAttributes
1397 MOJOSHADER_AST_VARATTR_EXTERN = (1 << 0),
1398 MOJOSHADER_AST_VARATTR_NOINTERPOLATION = (1 << 1),
1399 MOJOSHADER_AST_VARATTR_SHARED = (1 << 2),
1400 MOJOSHADER_AST_VARATTR_STATIC = (1 << 3),
1401 MOJOSHADER_AST_VARATTR_UNIFORM = (1 << 4),
1402 MOJOSHADER_AST_VARATTR_VOLATILE = (1 << 5),
1403 MOJOSHADER_AST_VARATTR_CONST = (1 << 6),
1404 MOJOSHADER_AST_VARATTR_ROWMAJOR = (1 << 7),
1405 MOJOSHADER_AST_VARATTR_COLUMNMAJOR = (1 << 8)
1406 } MOJOSHADER_astVariableAttributes;
1408 typedef enum MOJOSHADER_astIfAttributes
1410 MOJOSHADER_AST_IFATTR_NONE,
1411 MOJOSHADER_AST_IFATTR_BRANCH,
1412 MOJOSHADER_AST_IFATTR_FLATTEN,
1413 MOJOSHADER_AST_IFATTR_IFALL,
1414 MOJOSHADER_AST_IFATTR_IFANY,
1415 MOJOSHADER_AST_IFATTR_PREDICATE,
1416 MOJOSHADER_AST_IFATTR_PREDICATEBLOCK,
1417 } MOJOSHADER_astIfAttributes;
1419 typedef enum MOJOSHADER_astSwitchAttributes
1421 MOJOSHADER_AST_SWITCHATTR_NONE,
1422 MOJOSHADER_AST_SWITCHATTR_FLATTEN,
1423 MOJOSHADER_AST_SWITCHATTR_BRANCH,
1424 MOJOSHADER_AST_SWITCHATTR_FORCECASE,
1425 MOJOSHADER_AST_SWITCHATTR_CALL
1426 } MOJOSHADER_astSwitchAttributes;
1428 /* You can cast any AST node pointer to this. */
1429 typedef struct MOJOSHADER_astGeneric
1431 MOJOSHADER_astNodeInfo ast;
1432 } MOJOSHADER_astGeneric;
1434 typedef struct MOJOSHADER_astExpression
1436 MOJOSHADER_astNodeInfo ast;
1437 const MOJOSHADER_astDataType *datatype;
1438 } MOJOSHADER_astExpression;
1440 typedef struct MOJOSHADER_astArguments
1442 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_ARGUMENTS */
1443 MOJOSHADER_astExpression *argument;
1444 struct MOJOSHADER_astArguments *next;
1445 } MOJOSHADER_astArguments;
1447 typedef struct MOJOSHADER_astExpressionUnary
1449 MOJOSHADER_astNodeInfo ast;
1450 const MOJOSHADER_astDataType *datatype;
1451 MOJOSHADER_astExpression *operand;
1452 } MOJOSHADER_astExpressionUnary;
1454 typedef struct MOJOSHADER_astExpressionBinary
1456 MOJOSHADER_astNodeInfo ast;
1457 const MOJOSHADER_astDataType *datatype;
1458 MOJOSHADER_astExpression *left;
1459 MOJOSHADER_astExpression *right;
1460 } MOJOSHADER_astExpressionBinary;
1462 typedef struct MOJOSHADER_astExpressionTernary
1464 MOJOSHADER_astNodeInfo ast;
1465 const MOJOSHADER_astDataType *datatype;
1466 MOJOSHADER_astExpression *left;
1467 MOJOSHADER_astExpression *center;
1468 MOJOSHADER_astExpression *right;
1469 } MOJOSHADER_astExpressionTernary;
1471 /* Identifier indexes aren't available until semantic analysis phase completes.
1472 * It provides a unique id for this identifier's variable.
1473 * It will be negative for global scope, positive for function scope
1474 * (global values are globally unique, function values are only
1475 * unique within the scope of the given function). There's a different
1476 * set of indices if this identifier is a function (positive for
1477 * user-defined functions, negative for intrinsics).
1478 * May be zero for various reasons (unknown identifier, etc).
1480 typedef struct MOJOSHADER_astExpressionIdentifier
1482 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_IDENTIFIER */
1483 const MOJOSHADER_astDataType *datatype;
1484 const char *identifier;
1486 } MOJOSHADER_astExpressionIdentifier;
1488 typedef struct MOJOSHADER_astExpressionIntLiteral
1490 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_INT_LITERAL */
1491 const MOJOSHADER_astDataType *datatype; /* always AST_DATATYPE_INT */
1493 } MOJOSHADER_astExpressionIntLiteral;
1495 typedef struct MOJOSHADER_astExpressionFloatLiteral
1497 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_FLOAT_LITERAL */
1498 const MOJOSHADER_astDataType *datatype; /* always AST_DATATYPE_FLOAT */
1500 } MOJOSHADER_astExpressionFloatLiteral;
1502 typedef struct MOJOSHADER_astExpressionStringLiteral
1504 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_STRING_LITERAL */
1505 const MOJOSHADER_astDataType *datatype; /* always AST_DATATYPE_STRING */
1507 } MOJOSHADER_astExpressionStringLiteral;
1509 typedef struct MOJOSHADER_astExpressionBooleanLiteral
1511 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_BOOLEAN_LITERAL */
1512 const MOJOSHADER_astDataType *datatype; /* always AST_DATATYPE_BOOL */
1513 int value; /* Always 1 or 0. */
1514 } MOJOSHADER_astExpressionBooleanLiteral;
1516 typedef struct MOJOSHADER_astExpressionConstructor
1518 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_CONSTRUCTOR */
1519 const MOJOSHADER_astDataType *datatype;
1520 MOJOSHADER_astArguments *args;
1521 } MOJOSHADER_astExpressionConstructor;
1523 typedef struct MOJOSHADER_astExpressionDerefStruct
1525 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_DEREF_STRUCT */
1526 const MOJOSHADER_astDataType *datatype;
1528 * "identifier" is misnamed; this might not be an identifier at all:
1529 * x = FunctionThatReturnsAStruct().SomeMember;
1531 MOJOSHADER_astExpression *identifier;
1533 int isswizzle; /* Always 1 or 0. Never set by parseAst()! */
1534 int member_index; /* Never set by parseAst()! */
1535 } MOJOSHADER_astExpressionDerefStruct;
1537 typedef struct MOJOSHADER_astExpressionCallFunction
1539 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_CALLFUNC */
1540 const MOJOSHADER_astDataType *datatype;
1541 MOJOSHADER_astExpressionIdentifier *identifier;
1542 MOJOSHADER_astArguments *args;
1543 } MOJOSHADER_astExpressionCallFunction;
1545 typedef struct MOJOSHADER_astExpressionCast
1547 MOJOSHADER_astNodeInfo ast; /* Always MOJOSHADER_AST_OP_CAST */
1548 const MOJOSHADER_astDataType *datatype;
1549 MOJOSHADER_astExpression *operand;
1550 } MOJOSHADER_astExpressionCast;
1552 typedef struct MOJOSHADER_astCompilationUnit
1554 MOJOSHADER_astNodeInfo ast;
1555 struct MOJOSHADER_astCompilationUnit *next;
1556 } MOJOSHADER_astCompilationUnit;
1558 typedef enum MOJOSHADER_astFunctionStorageClass
1560 MOJOSHADER_AST_FNSTORECLS_NONE,
1561 MOJOSHADER_AST_FNSTORECLS_INLINE
1562 } MOJOSHADER_astFunctionStorageClass;
1564 typedef enum MOJOSHADER_astInputModifier
1566 MOJOSHADER_AST_INPUTMOD_NONE,
1567 MOJOSHADER_AST_INPUTMOD_IN,
1568 MOJOSHADER_AST_INPUTMOD_OUT,
1569 MOJOSHADER_AST_INPUTMOD_INOUT,
1570 MOJOSHADER_AST_INPUTMOD_UNIFORM
1571 } MOJOSHADER_astInputModifier;
1573 typedef enum MOJOSHADER_astInterpolationModifier
1575 MOJOSHADER_AST_INTERPMOD_NONE,
1576 MOJOSHADER_AST_INTERPMOD_LINEAR,
1577 MOJOSHADER_AST_INTERPMOD_CENTROID,
1578 MOJOSHADER_AST_INTERPMOD_NOINTERPOLATION,
1579 MOJOSHADER_AST_INTERPMOD_NOPERSPECTIVE,
1580 MOJOSHADER_AST_INTERPMOD_SAMPLE
1581 } MOJOSHADER_astInterpolationModifier;
1583 typedef struct MOJOSHADER_astFunctionParameters
1585 MOJOSHADER_astNodeInfo ast;
1586 const MOJOSHADER_astDataType *datatype;
1587 MOJOSHADER_astInputModifier input_modifier;
1588 const char *identifier;
1589 const char *semantic;
1590 MOJOSHADER_astInterpolationModifier interpolation_modifier;
1591 MOJOSHADER_astExpression *initializer;
1592 struct MOJOSHADER_astFunctionParameters *next;
1593 } MOJOSHADER_astFunctionParameters;
1595 typedef struct MOJOSHADER_astFunctionSignature
1597 MOJOSHADER_astNodeInfo ast;
1598 const MOJOSHADER_astDataType *datatype;
1599 const char *identifier;
1600 MOJOSHADER_astFunctionParameters *params;
1601 MOJOSHADER_astFunctionStorageClass storage_class;
1602 const char *semantic;
1603 } MOJOSHADER_astFunctionSignature;
1605 typedef struct MOJOSHADER_astScalarOrArray
1607 MOJOSHADER_astNodeInfo ast;
1608 const char *identifier;
1609 int isarray; /* boolean: 1 or 0 */
1610 MOJOSHADER_astExpression *dimension;
1611 } MOJOSHADER_astScalarOrArray;
1613 typedef struct MOJOSHADER_astAnnotations
1615 MOJOSHADER_astNodeInfo ast;
1616 const MOJOSHADER_astDataType *datatype;
1617 MOJOSHADER_astExpression *initializer;
1618 struct MOJOSHADER_astAnnotations *next;
1619 } MOJOSHADER_astAnnotations;
1621 typedef struct MOJOSHADER_astPackOffset
1623 MOJOSHADER_astNodeInfo ast;
1624 const char *ident1; /* !!! FIXME: rename this. */
1626 } MOJOSHADER_astPackOffset;
1628 typedef struct MOJOSHADER_astVariableLowLevel
1630 MOJOSHADER_astNodeInfo ast;
1631 MOJOSHADER_astPackOffset *packoffset;
1632 const char *register_name;
1633 } MOJOSHADER_astVariableLowLevel;
1635 typedef struct MOJOSHADER_astStructMembers
1637 MOJOSHADER_astNodeInfo ast;
1638 const MOJOSHADER_astDataType *datatype;
1639 const char *semantic;
1640 MOJOSHADER_astScalarOrArray *details;
1641 MOJOSHADER_astInterpolationModifier interpolation_mod;
1642 struct MOJOSHADER_astStructMembers *next;
1643 } MOJOSHADER_astStructMembers;
1645 typedef struct MOJOSHADER_astStructDeclaration
1647 MOJOSHADER_astNodeInfo ast;
1648 const MOJOSHADER_astDataType *datatype;
1650 MOJOSHADER_astStructMembers *members;
1651 } MOJOSHADER_astStructDeclaration;
1653 typedef struct MOJOSHADER_astVariableDeclaration
1655 MOJOSHADER_astNodeInfo ast;
1657 const MOJOSHADER_astDataType *datatype;
1658 MOJOSHADER_astStructDeclaration *anonymous_datatype;
1659 MOJOSHADER_astScalarOrArray *details;
1660 const char *semantic;
1661 MOJOSHADER_astAnnotations *annotations;
1662 MOJOSHADER_astExpression *initializer;
1663 MOJOSHADER_astVariableLowLevel *lowlevel;
1664 struct MOJOSHADER_astVariableDeclaration *next;
1665 } MOJOSHADER_astVariableDeclaration;
1667 typedef struct MOJOSHADER_astStatement
1669 MOJOSHADER_astNodeInfo ast;
1670 struct MOJOSHADER_astStatement *next;
1671 } MOJOSHADER_astStatement;
1673 typedef MOJOSHADER_astStatement MOJOSHADER_astEmptyStatement;
1674 typedef MOJOSHADER_astStatement MOJOSHADER_astBreakStatement;
1675 typedef MOJOSHADER_astStatement MOJOSHADER_astContinueStatement;
1676 typedef MOJOSHADER_astStatement MOJOSHADER_astDiscardStatement;
1678 /* something enclosed in "{}" braces. */
1679 typedef struct MOJOSHADER_astBlockStatement
1681 MOJOSHADER_astNodeInfo ast;
1682 MOJOSHADER_astStatement *next;
1683 MOJOSHADER_astStatement *statements; /* list of child statements. */
1684 } MOJOSHADER_astBlockStatement;
1686 typedef struct MOJOSHADER_astReturnStatement
1688 MOJOSHADER_astNodeInfo ast;
1689 MOJOSHADER_astStatement *next;
1690 MOJOSHADER_astExpression *expr;
1691 } MOJOSHADER_astReturnStatement;
1693 typedef struct MOJOSHADER_astExpressionStatement
1695 MOJOSHADER_astNodeInfo ast;
1696 MOJOSHADER_astStatement *next;
1697 MOJOSHADER_astExpression *expr;
1698 } MOJOSHADER_astExpressionStatement;
1700 typedef struct MOJOSHADER_astIfStatement
1702 MOJOSHADER_astNodeInfo ast;
1703 MOJOSHADER_astStatement *next;
1705 MOJOSHADER_astExpression *expr;
1706 MOJOSHADER_astStatement *statement;
1707 MOJOSHADER_astStatement *else_statement;
1708 } MOJOSHADER_astIfStatement;
1710 typedef struct MOJOSHADER_astSwitchCases
1712 MOJOSHADER_astNodeInfo ast;
1713 MOJOSHADER_astExpression *expr;
1714 MOJOSHADER_astStatement *statement;
1715 struct MOJOSHADER_astSwitchCases *next;
1716 } MOJOSHADER_astSwitchCases;
1718 typedef struct MOJOSHADER_astSwitchStatement
1720 MOJOSHADER_astNodeInfo ast;
1721 MOJOSHADER_astStatement *next;
1723 MOJOSHADER_astExpression *expr;
1724 MOJOSHADER_astSwitchCases *cases;
1725 } MOJOSHADER_astSwitchStatement;
1727 typedef struct MOJOSHADER_astWhileStatement
1729 MOJOSHADER_astNodeInfo ast;
1730 MOJOSHADER_astStatement *next;
1731 int unroll; /* # times to unroll, 0 to loop, < 0 == compiler's choice. */
1732 MOJOSHADER_astExpression *expr;
1733 MOJOSHADER_astStatement *statement;
1734 } MOJOSHADER_astWhileStatement;
1736 typedef MOJOSHADER_astWhileStatement MOJOSHADER_astDoStatement;
1738 typedef struct MOJOSHADER_astForStatement
1740 MOJOSHADER_astNodeInfo ast;
1741 MOJOSHADER_astStatement *next;
1742 int unroll; /* # times to unroll, 0 to loop, < 0 == compiler's choice. */
1743 MOJOSHADER_astVariableDeclaration *var_decl; /* either this ... */
1744 MOJOSHADER_astExpression *initializer; /* ... or this will used. */
1745 MOJOSHADER_astExpression *looptest;
1746 MOJOSHADER_astExpression *counter;
1747 MOJOSHADER_astStatement *statement;
1748 } MOJOSHADER_astForStatement;
1750 typedef struct MOJOSHADER_astTypedef
1752 MOJOSHADER_astNodeInfo ast;
1753 const MOJOSHADER_astDataType *datatype;
1754 int isconst; /* boolean: 1 or 0 */
1755 MOJOSHADER_astScalarOrArray *details;
1756 } MOJOSHADER_astTypedef;
1758 typedef struct MOJOSHADER_astTypedefStatement
1760 MOJOSHADER_astNodeInfo ast;
1761 MOJOSHADER_astStatement *next;
1762 MOJOSHADER_astTypedef *type_info;
1763 } MOJOSHADER_astTypedefStatement;
1765 typedef struct MOJOSHADER_astVarDeclStatement
1767 MOJOSHADER_astNodeInfo ast;
1768 MOJOSHADER_astStatement *next;
1769 MOJOSHADER_astVariableDeclaration *declaration;
1770 } MOJOSHADER_astVarDeclStatement;
1772 typedef struct MOJOSHADER_astStructStatement
1774 MOJOSHADER_astNodeInfo ast;
1775 MOJOSHADER_astStatement *next;
1776 MOJOSHADER_astStructDeclaration *struct_info;
1777 } MOJOSHADER_astStructStatement;
1779 typedef struct MOJOSHADER_astCompilationUnitFunction
1781 MOJOSHADER_astNodeInfo ast;
1782 MOJOSHADER_astCompilationUnit *next;
1783 MOJOSHADER_astFunctionSignature *declaration;
1784 MOJOSHADER_astStatement *definition;
1785 int index; /* unique id. Will be 0 until semantic analysis runs. */
1786 } MOJOSHADER_astCompilationUnitFunction;
1788 typedef struct MOJOSHADER_astCompilationUnitTypedef
1790 MOJOSHADER_astNodeInfo ast;
1791 MOJOSHADER_astCompilationUnit *next;
1792 MOJOSHADER_astTypedef *type_info;
1793 } MOJOSHADER_astCompilationUnitTypedef;
1795 typedef struct MOJOSHADER_astCompilationUnitStruct
1797 MOJOSHADER_astNodeInfo ast;
1798 MOJOSHADER_astCompilationUnit *next;
1799 MOJOSHADER_astStructDeclaration *struct_info;
1800 } MOJOSHADER_astCompilationUnitStruct;
1802 typedef struct MOJOSHADER_astCompilationUnitVariable
1804 MOJOSHADER_astNodeInfo ast;
1805 MOJOSHADER_astCompilationUnit *next;
1806 MOJOSHADER_astVariableDeclaration *declaration;
1807 } MOJOSHADER_astCompilationUnitVariable;
1810 /* this is way cleaner than all the nasty typecasting. */
1811 typedef union MOJOSHADER_astNode
1813 MOJOSHADER_astNodeInfo ast;
1814 MOJOSHADER_astGeneric generic;
1815 MOJOSHADER_astExpression expression;
1816 MOJOSHADER_astArguments arguments;
1817 MOJOSHADER_astExpressionUnary unary;
1818 MOJOSHADER_astExpressionBinary binary;
1819 MOJOSHADER_astExpressionTernary ternary;
1820 MOJOSHADER_astExpressionIdentifier identifier;
1821 MOJOSHADER_astExpressionIntLiteral intliteral;
1822 MOJOSHADER_astExpressionFloatLiteral floatliteral;
1823 MOJOSHADER_astExpressionStringLiteral stringliteral;
1824 MOJOSHADER_astExpressionBooleanLiteral boolliteral;
1825 MOJOSHADER_astExpressionConstructor constructor;
1826 MOJOSHADER_astExpressionDerefStruct derefstruct;
1827 MOJOSHADER_astExpressionCallFunction callfunc;
1828 MOJOSHADER_astExpressionCast cast;
1829 MOJOSHADER_astCompilationUnit compunit;
1830 MOJOSHADER_astFunctionParameters params;
1831 MOJOSHADER_astFunctionSignature funcsig;
1832 MOJOSHADER_astScalarOrArray soa;
1833 MOJOSHADER_astAnnotations annotations;
1834 MOJOSHADER_astPackOffset packoffset;
1835 MOJOSHADER_astVariableLowLevel varlowlevel;
1836 MOJOSHADER_astStructMembers structmembers;
1837 MOJOSHADER_astStructDeclaration structdecl;
1838 MOJOSHADER_astVariableDeclaration vardecl;
1839 MOJOSHADER_astStatement stmt;
1840 MOJOSHADER_astEmptyStatement emptystmt;
1841 MOJOSHADER_astBreakStatement breakstmt;
1842 MOJOSHADER_astContinueStatement contstmt;
1843 MOJOSHADER_astDiscardStatement discardstmt;
1844 MOJOSHADER_astBlockStatement blockstmt;
1845 MOJOSHADER_astReturnStatement returnstmt;
1846 MOJOSHADER_astExpressionStatement exprstmt;
1847 MOJOSHADER_astIfStatement ifstmt;
1848 MOJOSHADER_astSwitchCases cases;
1849 MOJOSHADER_astSwitchStatement switchstmt;
1850 MOJOSHADER_astWhileStatement whilestmt;
1851 MOJOSHADER_astDoStatement dostmt;
1852 MOJOSHADER_astForStatement forstmt;
1853 MOJOSHADER_astTypedef typdef;
1854 MOJOSHADER_astTypedefStatement typedefstmt;
1855 MOJOSHADER_astVarDeclStatement vardeclstmt;
1856 MOJOSHADER_astStructStatement structstmt;
1857 MOJOSHADER_astCompilationUnitFunction funcunit;
1858 MOJOSHADER_astCompilationUnitTypedef typedefunit;
1859 MOJOSHADER_astCompilationUnitStruct structunit;
1860 MOJOSHADER_astCompilationUnitVariable varunit;
1861 } MOJOSHADER_astNode;
1865 * Structure used to return data from parsing of a shader into an AST...
1867 /* !!! FIXME: most of these ints should be unsigned. */
1868 typedef struct MOJOSHADER_astData
1871 * The number of elements pointed to by (errors).
1876 * (error_count) elements of data that specify errors that were generated
1877 * by parsing this shader.
1878 * This can be NULL if there were no errors or if (error_count) is zero.
1879 * Note that this will only produce errors for syntax problems. Most of
1880 * the things we expect a compiler to produce errors for--incompatible
1881 * types, unknown identifiers, etc--are not checked at all during
1882 * initial generation of the syntax tree...bogus programs that would
1883 * fail to compile will pass here without error, if they are syntactically
1886 MOJOSHADER_error *errors;
1889 * The name of the source profile used to parse the shader. Will be NULL
1892 const char *source_profile;
1895 * The actual syntax tree. You are responsible for walking it yourself.
1896 * CompilationUnits are always the top of the tree (functions, typedefs,
1897 * global variables, etc). Will be NULL on error.
1899 const MOJOSHADER_astNode *ast;
1902 * This is the malloc implementation you passed to MOJOSHADER_parse().
1904 MOJOSHADER_malloc malloc;
1907 * This is the free implementation you passed to MOJOSHADER_parse().
1909 MOJOSHADER_free free;
1912 * This is the pointer you passed as opaque data for your allocator.
1917 * This is internal data, and not for the application to touch.
1920 } MOJOSHADER_astData;
1924 * You almost certainly don't need this function, unless you absolutely know
1925 * why you need it without hesitation. This is almost certainly only good for
1926 * building code analysis tools on top of.
1928 * This is intended to parse HLSL source code, turning it into an abstract
1931 * (srcprofile) specifies the source language of the shader. You can specify
1932 * a shader model with this, too. See MOJOSHADER_SRC_PROFILE_* constants.
1934 * (filename) is a NULL-terminated UTF-8 filename. It can be NULL. We do not
1935 * actually access this file, as we obtain our data from (source). This
1936 * string is copied when we need to report errors while processing (source),
1937 * as opposed to errors in a file referenced via the #include directive in
1938 * (source). If this is NULL, then errors will report the filename as NULL,
1941 * (source) is an UTF-8 string of valid high-level shader source code.
1942 * It does not need to be NULL-terminated.
1944 * (sourcelen) is the length of the string pointed to by (source), in bytes.
1946 * (defines) points to (define_count) preprocessor definitions, and can be
1947 * NULL. These are treated by the preprocessor as if the source code started
1948 * with one #define for each entry you pass in here.
1950 * (include_open) and (include_close) let the app control the preprocessor's
1951 * behaviour for #include statements. Both are optional and can be NULL, but
1952 * both must be specified if either is specified.
1954 * This will return a MOJOSHADER_astData. The data supplied here gives the
1955 * application a tree-like structure they can walk to see the layout of
1956 * a given program. When you are done with this data, pass it to
1957 * MOJOSHADER_freeCompileData() to deallocate resources.
1959 * This function will never return NULL, even if the system is completely
1960 * out of memory upon entry (in which case, this function returns a static
1961 * MOJOSHADER_astData object, which is still safe to pass to
1962 * MOJOSHADER_freeAstData()).
1964 * As parsing requires some memory to be allocated, you may provide a
1965 * custom allocator to this function, which will be used to allocate/free
1966 * memory. They function just like malloc() and free(). We do not use
1967 * realloc(). If you don't care, pass NULL in for the allocator functions.
1968 * If your allocator needs instance-specific data, you may supply it with the
1969 * (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
1971 * This function is thread safe, so long as the various callback functions
1972 * are, too, and that the parameters remains intact for the duration of the
1973 * call. This allows you to parse several shaders on separate CPU cores
1976 const MOJOSHADER_astData *MOJOSHADER_parseAst(const char *srcprofile,
1977 const char *filename, const char *source,
1978 unsigned int sourcelen,
1979 const MOJOSHADER_preprocessorDefine *defs,
1980 unsigned int define_count,
1981 MOJOSHADER_includeOpen include_open,
1982 MOJOSHADER_includeClose include_close,
1983 MOJOSHADER_malloc m, MOJOSHADER_free f,
1987 /* !!! FIXME: expose semantic analysis to the public API? */
1991 * Call this to dispose of AST parsing results when you are done with them.
1992 * This will call the MOJOSHADER_free function you provided to
1993 * MOJOSHADER_parseAst() multiple times, if you provided one.
1994 * Passing a NULL here is a safe no-op.
1996 * This function is thread safe, so long as any allocator you passed into
1997 * MOJOSHADER_parseAst() is, too.
1999 void MOJOSHADER_freeAstData(const MOJOSHADER_astData *data);
2002 /* Intermediate Representation interface... */
2003 /* !!! FIXME: there is currently no way to access the IR via the public API. */
2004 typedef enum MOJOSHADER_irNodeType
2006 MOJOSHADER_IR_START_RANGE_EXPR,
2007 MOJOSHADER_IR_CONSTANT,
2009 MOJOSHADER_IR_BINOP,
2010 MOJOSHADER_IR_MEMORY,
2013 MOJOSHADER_IR_ARRAY,
2014 MOJOSHADER_IR_CONVERT,
2015 MOJOSHADER_IR_SWIZZLE,
2016 MOJOSHADER_IR_CONSTRUCT,
2017 MOJOSHADER_IR_END_RANGE_EXPR,
2019 MOJOSHADER_IR_START_RANGE_STMT,
2021 MOJOSHADER_IR_EXPR_STMT,
2023 MOJOSHADER_IR_CJUMP,
2025 MOJOSHADER_IR_LABEL,
2026 MOJOSHADER_IR_DISCARD,
2027 MOJOSHADER_IR_END_RANGE_STMT,
2029 MOJOSHADER_IR_START_RANGE_MISC,
2030 MOJOSHADER_IR_EXPRLIST,
2031 MOJOSHADER_IR_END_RANGE_MISC,
2033 MOJOSHADER_IR_END_RANGE
2034 } MOJOSHADER_irNodeType;
2036 typedef struct MOJOSHADER_irNodeInfo
2038 MOJOSHADER_irNodeType type;
2039 const char *filename;
2041 } MOJOSHADER_irNodeInfo;
2043 typedef struct MOJOSHADER_irExprList MOJOSHADER_irExprList;
2046 * IR nodes are categorized into Expressions, Statements, and Everything Else.
2047 * You can cast any of them to MOJOSHADER_irGeneric, but this split is
2048 * useful for slightly better type-checking (you can't cleanly assign
2049 * something that doesn't return a value to something that wants one, etc).
2050 * These broader categories are just unions of the simpler types, so the
2051 * real definitions are below all the things they contain (but these
2052 * predeclarations are because the simpler types refer to the broader
2055 typedef union MOJOSHADER_irExpression MOJOSHADER_irExpression; /* returns a value. */
2056 typedef union MOJOSHADER_irStatement MOJOSHADER_irStatement; /* no returned value. */
2057 typedef union MOJOSHADER_irMisc MOJOSHADER_irMisc; /* Everything Else. */
2058 typedef union MOJOSHADER_irNode MOJOSHADER_irNode; /* Generic uber-wrapper. */
2060 /* You can cast any IR node pointer to this. */
2061 typedef struct MOJOSHADER_irGeneric
2063 MOJOSHADER_irNodeInfo ir;
2064 } MOJOSHADER_irGeneric;
2067 /* These are used for MOJOSHADER_irBinOp */
2068 typedef enum MOJOSHADER_irBinOpType
2070 MOJOSHADER_IR_BINOP_ADD,
2071 MOJOSHADER_IR_BINOP_SUBTRACT,
2072 MOJOSHADER_IR_BINOP_MULTIPLY,
2073 MOJOSHADER_IR_BINOP_DIVIDE,
2074 MOJOSHADER_IR_BINOP_MODULO,
2075 MOJOSHADER_IR_BINOP_AND,
2076 MOJOSHADER_IR_BINOP_OR,
2077 MOJOSHADER_IR_BINOP_XOR,
2078 MOJOSHADER_IR_BINOP_LSHIFT,
2079 MOJOSHADER_IR_BINOP_RSHIFT,
2080 MOJOSHADER_IR_BINOP_UNKNOWN
2081 } MOJOSHADER_irBinOpType;
2083 typedef enum MOJOSHADER_irConditionType
2085 MOJOSHADER_IR_COND_EQL,
2086 MOJOSHADER_IR_COND_NEQ,
2087 MOJOSHADER_IR_COND_LT,
2088 MOJOSHADER_IR_COND_GT,
2089 MOJOSHADER_IR_COND_LEQ,
2090 MOJOSHADER_IR_COND_GEQ,
2091 MOJOSHADER_IR_COND_UNKNOWN
2092 } MOJOSHADER_irConditionType;
2095 /* MOJOSHADER_irExpression types... */
2097 typedef struct MOJOSHADER_irExprInfo
2099 MOJOSHADER_irNodeInfo ir;
2100 MOJOSHADER_astDataTypeType type;
2102 } MOJOSHADER_irExprInfo;
2104 typedef struct MOJOSHADER_irConstant /* Constant value */
2106 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_CONSTANT */
2112 } MOJOSHADER_irConstant;
2114 typedef struct MOJOSHADER_irTemp /* temp value (not necessarily a register). */
2116 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_TEMP */
2118 } MOJOSHADER_irTemp;
2120 typedef struct MOJOSHADER_irBinOp /* binary operator (+, -, etc) */
2122 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_BINOP */
2123 MOJOSHADER_irBinOpType op;
2124 MOJOSHADER_irExpression *left;
2125 MOJOSHADER_irExpression *right;
2126 } MOJOSHADER_irBinOp;
2128 typedef struct MOJOSHADER_irMemory
2130 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_MEMORY */
2131 int index; /* not final addresses, just a unique identifier. */
2132 } MOJOSHADER_irMemory;
2134 typedef struct MOJOSHADER_irCall
2136 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_CALL */
2138 MOJOSHADER_irExprList *args;
2139 } MOJOSHADER_irCall;
2141 typedef struct MOJOSHADER_irESeq /* statement with result */
2143 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_ESEQ */
2144 MOJOSHADER_irStatement *stmt; /* execute this for side-effects, then... */
2145 MOJOSHADER_irExpression *expr; /* ...use this for the result. */
2146 } MOJOSHADER_irESeq;
2148 typedef struct MOJOSHADER_irArray /* Array dereference. */
2150 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_ARRAY */
2151 MOJOSHADER_irExpression *array;
2152 MOJOSHADER_irExpression *element;
2153 } MOJOSHADER_irArray;
2155 typedef struct MOJOSHADER_irConvert /* casting between datatypes */
2157 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_CONVERT */
2158 MOJOSHADER_irExpression *expr;
2159 } MOJOSHADER_irConvert;
2161 typedef struct MOJOSHADER_irSwizzle /* vector swizzle */
2163 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_SWIZZLE */
2164 MOJOSHADER_irExpression *expr;
2166 } MOJOSHADER_irSwizzle;
2168 typedef struct MOJOSHADER_irConstruct /* vector construct from discrete items */
2170 MOJOSHADER_irExprInfo info; /* Always MOJOSHADER_IR_CONTSTRUCT */
2171 MOJOSHADER_irExprList *args;
2172 } MOJOSHADER_irConstruct;
2174 /* Wrap the whole category in a union for type "safety." */
2175 union MOJOSHADER_irExpression
2177 MOJOSHADER_irNodeInfo ir;
2178 MOJOSHADER_irExprInfo info;
2179 MOJOSHADER_irConstant constant;
2180 MOJOSHADER_irTemp temp;
2181 MOJOSHADER_irBinOp binop;
2182 MOJOSHADER_irMemory memory;
2183 MOJOSHADER_irCall call;
2184 MOJOSHADER_irESeq eseq;
2185 MOJOSHADER_irArray array;
2186 MOJOSHADER_irConvert convert;
2187 MOJOSHADER_irSwizzle swizzle;
2188 MOJOSHADER_irConstruct construct;
2191 /* MOJOSHADER_irStatement types. */
2193 typedef struct MOJOSHADER_irMove /* load/store. */
2195 MOJOSHADER_irNodeInfo ir; /* Always MOJOSHADER_IR_MOVE */
2196 MOJOSHADER_irExpression *dst; /* must result in a temp or mem! */
2197 MOJOSHADER_irExpression *src;
2198 int writemask; // for write-masking vector channels.
2199 } MOJOSHADER_irMove;
2201 typedef struct MOJOSHADER_irExprStmt /* evaluate expression, throw it away. */
2203 MOJOSHADER_irNodeInfo ir; /* Always MOJOSHADER_IR_EXPR_STMT */
2204 MOJOSHADER_irExpression *expr;
2205 } MOJOSHADER_irExprStmt;
2207 typedef struct MOJOSHADER_irJump /* unconditional jump */
2209 MOJOSHADER_irNodeInfo ir; /* Always MOJOSHADER_IR_JUMP */
2211 // !!! FIXME: possible label list, for further optimization passes.
2212 } MOJOSHADER_irJump;
2214 typedef struct MOJOSHADER_irCJump /* conditional jump */
2216 MOJOSHADER_irNodeInfo ir; /* Always MOJOSHADER_IR_CJUMP */
2217 MOJOSHADER_irConditionType cond;
2218 MOJOSHADER_irExpression *left; /* if (left cond right) */
2219 MOJOSHADER_irExpression *right;
2220 int iftrue; /* label id for true case. */
2221 int iffalse; /* label id for false case. */
2222 } MOJOSHADER_irCJump;
2224 typedef struct MOJOSHADER_irSeq /* statement without side effects */
2226 MOJOSHADER_irNodeInfo ir; /* Always MOJOSHADER_IR_SEQ */
2227 MOJOSHADER_irStatement *first;
2228 MOJOSHADER_irStatement *next;
2231 typedef struct MOJOSHADER_irLabel /* like a label in assembly language. */
2233 MOJOSHADER_irNodeInfo ir; /* Always MOJOSHADER_IR_LABEL */
2235 } MOJOSHADER_irLabel;
2237 typedef MOJOSHADER_irGeneric MOJOSHADER_irDiscard; /* discard statement. */
2240 /* Wrap the whole category in a union for type "safety." */
2241 union MOJOSHADER_irStatement
2243 MOJOSHADER_irNodeInfo ir;
2244 MOJOSHADER_irGeneric generic;
2245 MOJOSHADER_irMove move;
2246 MOJOSHADER_irExprStmt expr;
2247 MOJOSHADER_irJump jump;
2248 MOJOSHADER_irCJump cjump;
2249 MOJOSHADER_irSeq seq;
2250 MOJOSHADER_irLabel label;
2251 MOJOSHADER_irDiscard discard;
2254 /* MOJOSHADER_irMisc types. */
2256 struct MOJOSHADER_irExprList
2258 MOJOSHADER_irNodeInfo ir; /* Always MOJOSHADER_IR_EXPRLIST */
2259 MOJOSHADER_irExpression *expr;
2260 MOJOSHADER_irExprList *next;
2263 /* Wrap the whole category in a union for type "safety." */
2264 union MOJOSHADER_irMisc
2266 MOJOSHADER_irNodeInfo ir;
2267 MOJOSHADER_irGeneric generic;
2268 MOJOSHADER_irExprList exprlist;
2271 /* This is a catchall for all your needs. :) */
2272 union MOJOSHADER_irNode
2274 MOJOSHADER_irNodeInfo ir;
2275 MOJOSHADER_irGeneric generic;
2276 MOJOSHADER_irExpression expr;
2277 MOJOSHADER_irStatement stmt;
2278 MOJOSHADER_irMisc misc;
2282 /* Compiler interface... */
2285 * Structure used to return data from parsing of a shader...
2287 /* !!! FIXME: most of these ints should be unsigned. */
2288 typedef struct MOJOSHADER_compileData
2291 * The number of elements pointed to by (errors).
2296 * (error_count) elements of data that specify errors that were generated
2297 * by compiling this shader.
2298 * This can be NULL if there were no errors or if (error_count) is zero.
2300 MOJOSHADER_error *errors;
2303 * The number of elements pointed to by (warnings).
2308 * (warning_count) elements of data that specify errors that were
2309 * generated by compiling this shader.
2310 * This can be NULL if there were no errors or if (warning_count) is zero.
2312 MOJOSHADER_error *warnings;
2315 * The name of the source profile used to compile the shader. Will be NULL
2318 const char *source_profile;
2321 * Bytes of output from compiling. This will be a null-terminated ASCII
2322 * string of D3D assembly source code.
2327 * Byte count for output, not counting any null terminator.
2328 * Will be 0 on error.
2333 * The number of elements pointed to by (symbols).
2338 * (symbol_count) elements of data that specify high-level symbol data
2339 * for the shader. This can be used by MOJOSHADER_assemble() to
2340 * generate a CTAB section in bytecode, which is needed by
2341 * MOJOSHADER_parseData() to handle some shaders. This can be NULL on
2342 * error or if (symbol_count) is zero.
2344 MOJOSHADER_symbol *symbols;
2347 * This is the malloc implementation you passed to MOJOSHADER_parse().
2349 MOJOSHADER_malloc malloc;
2352 * This is the free implementation you passed to MOJOSHADER_parse().
2354 MOJOSHADER_free free;
2357 * This is the pointer you passed as opaque data for your allocator.
2360 } MOJOSHADER_compileData;
2364 * This function is optional. Use this to compile high-level shader programs.
2366 * This is intended to turn HLSL source code into D3D assembly code, which
2367 * can then be passed to MOJOSHADER_assemble() to convert it to D3D bytecode
2368 * (which can then be used with MOJOSHADER_parseData() to support other
2371 * (srcprofile) specifies the source language of the shader. You can specify
2372 * a shader model with this, too. See MOJOSHADER_SRC_PROFILE_* constants.
2374 * (filename) is a NULL-terminated UTF-8 filename. It can be NULL. We do not
2375 * actually access this file, as we obtain our data from (source). This
2376 * string is copied when we need to report errors while processing (source),
2377 * as opposed to errors in a file referenced via the #include directive in
2378 * (source). If this is NULL, then errors will report the filename as NULL,
2381 * (source) is an UTF-8 string of valid high-level shader source code.
2382 * It does not need to be NULL-terminated.
2384 * (sourcelen) is the length of the string pointed to by (source), in bytes.
2386 * (defines) points to (define_count) preprocessor definitions, and can be
2387 * NULL. These are treated by the preprocessor as if the source code started
2388 * with one #define for each entry you pass in here.
2390 * (include_open) and (include_close) let the app control the preprocessor's
2391 * behaviour for #include statements. Both are optional and can be NULL, but
2392 * both must be specified if either is specified.
2394 * This will return a MOJOSHADER_compileData. The data supplied here is
2395 * sufficient to supply to MOJOSHADER_assemble() for further processing.
2396 * When you are done with this data, pass it to MOJOSHADER_freeCompileData()
2397 * to deallocate resources.
2399 * This function will never return NULL, even if the system is completely
2400 * out of memory upon entry (in which case, this function returns a static
2401 * MOJOSHADER_compileData object, which is still safe to pass to
2402 * MOJOSHADER_freeCompileData()).
2404 * As compiling requires some memory to be allocated, you may provide a
2405 * custom allocator to this function, which will be used to allocate/free
2406 * memory. They function just like malloc() and free(). We do not use
2407 * realloc(). If you don't care, pass NULL in for the allocator functions.
2408 * If your allocator needs instance-specific data, you may supply it with the
2409 * (d) parameter. This pointer is passed as-is to your (m) and (f) functions.
2411 * This function is thread safe, so long as the various callback functions
2412 * are, too, and that the parameters remains intact for the duration of the
2413 * call. This allows you to compile several shaders on separate CPU cores
2416 const MOJOSHADER_compileData *MOJOSHADER_compile(const char *srcprofile,
2417 const char *filename, const char *source,
2418 unsigned int sourcelen,
2419 const MOJOSHADER_preprocessorDefine *defs,
2420 unsigned int define_count,
2421 MOJOSHADER_includeOpen include_open,
2422 MOJOSHADER_includeClose include_close,
2423 MOJOSHADER_malloc m, MOJOSHADER_free f,
2428 * Call this to dispose of compile results when you are done with them.
2429 * This will call the MOJOSHADER_free function you provided to
2430 * MOJOSHADER_compile() multiple times, if you provided one.
2431 * Passing a NULL here is a safe no-op.
2433 * This function is thread safe, so long as any allocator you passed into
2434 * MOJOSHADER_compile() is, too.
2436 void MOJOSHADER_freeCompileData(const MOJOSHADER_compileData *data);
2439 /* OpenGL interface... */
2442 * Signature for function lookup callbacks. MojoShader will call a function
2443 * you provide to get OpenGL entry points (both standard functions and
2444 * extensions). Through this, MojoShader never links directly to OpenGL,
2445 * but relies on you to provide the implementation. This means you can
2446 * swap in different drivers, or hook functions (log every GL call MojoShader
2449 * (fnname) is the function name we want the address for ("glBegin" or
2450 * whatever. (data) is a void pointer you provide, if this callback needs
2451 * extra information. If you don't need it, you may specify NULL.
2453 * Return the entry point on success, NULL if it couldn't be found.
2454 * Note that this could ask for standard entry points like glEnable(), or
2455 * extensions like glProgramLocalParameterI4ivNV(), so you might need
2456 * to check two places to find the desired entry point, depending on your
2457 * platform (Windows might need to look in OpenGL32.dll and use WGL, etc).
2459 typedef void *(*MOJOSHADER_glGetProcAddress)(const char *fnname, void *data);
2463 * "Contexts" map to OpenGL contexts...you need one per window, or whatever,
2464 * and need to inform MojoShader when you make a new one current.
2466 * "Shaders" refer to individual vertex or pixel programs, and are created
2467 * by "compiling" Direct3D shader bytecode. A vertex and pixel shader are
2468 * "linked" into a "Program" before you can use them to render.
2470 * To the calling application, these are all opaque handles.
2472 typedef struct MOJOSHADER_glContext MOJOSHADER_glContext;
2473 typedef struct MOJOSHADER_glShader MOJOSHADER_glShader;
2474 typedef struct MOJOSHADER_glProgram MOJOSHADER_glProgram;
2478 * Get a list of available profiles. This will fill in the array (profs)
2479 * with up to (size) pointers of profiles that the current system can handle;
2480 * that is, the profiles are built into MojoShader and the OpenGL extensions
2481 * required for them exist at runtime. This function returns the number of
2482 * available profiles, which may be more, less, or equal to (size).
2484 * If there are more than (size) profiles, the (profs) buffer will not
2485 * overflow. You can check the return value for the total number of
2486 * available profiles, allocate more space, and try again if necessary.
2487 * Calling this function with (size) == 0 is legal.
2489 * You can only call this AFTER you have successfully built your GL context
2490 * and made it current. This function will lookup the GL functions it needs
2491 * through the callback you supply, via (lookup) and (d). The lookup function
2492 * is neither stored nor used by MojoShader after this function returns, nor
2493 * are the functions it might look up.
2495 * You should not free any strings returned from this function; they are
2496 * pointers to internal, probably static, memory.
2498 * This call is NOT thread safe! As most OpenGL implementations are not thread
2499 * safe, you should probably only call this from the same thread that created
2502 int MOJOSHADER_glAvailableProfiles(MOJOSHADER_glGetProcAddress lookup, void *d,
2503 const char **profs, const int size);
2507 * Determine the best profile to use for the current system.
2509 * You can only call this AFTER you have successfully built your GL context
2510 * and made it current. This function will lookup the GL functions it needs
2511 * through the callback you supply via (lookup) and (d). The lookup function
2512 * is neither stored nor used by MojoShader after this function returns, nor
2513 * are the functions it might look up.
2515 * Returns the name of the "best" profile on success, NULL if none of the
2516 * available profiles will work on this system. "Best" is a relative term,
2517 * but it generally means the best trade off between feature set and
2518 * performance. The selection algorithm may be arbitrary and complex.
2520 * The returned value is an internal static string, and should not be free()'d
2521 * by the caller. If you get a NULL, calling MOJOSHADER_glGetError() might
2522 * shed some light on why.
2524 * This call is NOT thread safe! As most OpenGL implementations are not thread
2525 * safe, you should probably only call this from the same thread that created
2528 const char *MOJOSHADER_glBestProfile(MOJOSHADER_glGetProcAddress lookup, void *d);
2532 * Prepare MojoShader to manage OpenGL shaders.
2534 * You do not need to call this if all you want is MOJOSHADER_parse().
2536 * You must call this once AFTER you have successfully built your GL context
2537 * and made it current. This function will lookup the GL functions it needs
2538 * through the callback you supply via (lookup) and (lookup_d), after which
2539 * it may call them at any time up until you call
2540 * MOJOSHADER_glDestroyContext(). The lookup function is neither stored nor
2541 * used by MojoShader after this function returns.
2543 * (profile) is an OpenGL-specific MojoShader profile, which decides how
2544 * Direct3D bytecode shaders get turned into OpenGL programs, and how they
2545 * are fed to the GL.
2547 * (lookup) is a callback that is used to load GL entry points. This callback
2548 * has to look up base GL functions and extension entry points. The pointer
2549 * you supply in (lookup_d) is passed as-is to the callback.
2551 * As MojoShader requires some memory to be allocated, you may provide a
2552 * custom allocator to this function, which will be used to allocate/free
2553 * memory. They function just like malloc() and free(). We do not use
2554 * realloc(). If you don't care, pass NULL in for the allocator functions.
2555 * If your allocator needs instance-specific data, you may supply it with the
2556 * (malloc_d) parameter. This pointer is passed as-is to your (m) and (f)
2559 * Returns a new context on success, NULL on error. If you get a new context,
2560 * you need to make it current before using it with
2561 * MOJOSHADER_glMakeContextCurrent().
2563 * This call is NOT thread safe! It must return success before you may call
2564 * any other MOJOSHADER_gl* function. Also, as most OpenGL implementations
2565 * are not thread safe, you should probably only call this from the same
2566 * thread that created the GL context.
2568 MOJOSHADER_glContext *MOJOSHADER_glCreateContext(const char *profile,
2569 MOJOSHADER_glGetProcAddress lookup,
2571 MOJOSHADER_malloc m, MOJOSHADER_free f,
2575 * You must call this before using the context that you got from
2576 * MOJOSHADER_glCreateContext(), and must use it when you switch to a new GL
2579 * You can only have one MOJOSHADER_glContext per actual GL context, or
2580 * undefined behaviour will result.
2582 * It is legal to call this with a NULL pointer to make no context current,
2583 * but you need a valid context to be current to use most of MojoShader.
2585 void MOJOSHADER_glMakeContextCurrent(MOJOSHADER_glContext *ctx);
2588 * Get any error state we might have picked up. MojoShader will NOT call
2589 * glGetError() internally, but there are other errors we can pick up,
2590 * such as failed shader compilation, etc.
2592 * Returns a human-readable string. This string is for debugging purposes, and
2593 * not guaranteed to be localized, coherent, or user-friendly in any way.
2594 * It's for programmers!
2596 * The latest error may remain between calls. New errors replace any existing
2597 * error. Don't check this string for a sign that an error happened, check
2598 * return codes instead and use this for explanation when debugging.
2600 * Do not free the returned string: it's a pointer to a static internal
2601 * buffer. Do not keep the pointer around, either, as it's likely to become
2602 * invalid as soon as you call into MojoShader again.
2604 * This call is NOT thread safe! As most OpenGL implementations are not thread
2605 * safe, you should probably only call this from the same thread that created
2608 * This call does NOT require a valid MOJOSHADER_glContext to have been made
2609 * current. The error buffer is shared between contexts, so you can get
2610 * error results from a failed MOJOSHADER_glCreateContext().
2612 const char *MOJOSHADER_glGetError(void);
2615 * Get the maximum uniforms a shader can support for the current GL context,
2616 * MojoShader profile, and shader type. You can use this to make decisions
2617 * about what shaders you want to use (for example, a less complicated
2618 * shader may be swapped in for lower-end systems).
2620 * Returns the number, or -1 on error.
2622 * This call is NOT thread safe! As most OpenGL implementations are not thread
2623 * safe, you should probably only call this from the same thread that created
2626 * This call requires a valid MOJOSHADER_glContext to have been made current,
2627 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2629 int MOJOSHADER_glMaxUniforms(MOJOSHADER_shaderType shader_type);
2632 * Compile a buffer of Direct3D shader bytecode into an OpenGL shader.
2633 * You still need to link the shader before you may render with it.
2635 * (tokenbuf) is a buffer of Direct3D shader bytecode.
2636 * (bufsize) is the size, in bytes, of the bytecode buffer.
2637 * (swiz) and (swizcount) are passed to MOJOSHADER_parse() unmolested.
2639 * Returns NULL on error, or a shader handle on success.
2641 * This call is NOT thread safe! As most OpenGL implementations are not thread
2642 * safe, you should probably only call this from the same thread that created
2645 * This call requires a valid MOJOSHADER_glContext to have been made current,
2646 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2648 * Compiled shaders from this function may not be shared between contexts.
2650 MOJOSHADER_glShader *MOJOSHADER_glCompileShader(const unsigned char *tokenbuf,
2651 const unsigned int bufsize,
2652 const MOJOSHADER_swizzle *swiz,
2653 const unsigned int swizcount);
2657 * Get the MOJOSHADER_parseData structure that was produced from the
2658 * call to MOJOSHADER_glCompileShader().
2660 * This data is read-only, and you should NOT attempt to free it. This
2661 * pointer remains valid until the shader is deleted.
2663 const MOJOSHADER_parseData *MOJOSHADER_glGetShaderParseData(
2664 MOJOSHADER_glShader *shader);
2666 * Link a vertex and pixel shader into an OpenGL program.
2667 * (vshader) or (pshader) can be NULL, to specify that the GL should use the
2668 * fixed-function pipeline instead of the programmable pipeline for that
2669 * portion of the work. You can reuse shaders in various combinations across
2670 * multiple programs, by relinking different pairs.
2672 * It is illegal to give a vertex shader for (pshader) or a pixel shader
2675 * Once you have successfully linked a program, you may render with it.
2677 * Returns NULL on error, or a program handle on success.
2679 * This call is NOT thread safe! As most OpenGL implementations are not thread
2680 * safe, you should probably only call this from the same thread that created
2683 * This call requires a valid MOJOSHADER_glContext to have been made current,
2684 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2686 * Linked programs from this function may not be shared between contexts.
2688 MOJOSHADER_glProgram *MOJOSHADER_glLinkProgram(MOJOSHADER_glShader *vshader,
2689 MOJOSHADER_glShader *pshader);
2692 * This binds the program (using, for example, glUseProgramObjectARB()), and
2693 * disables all the client-side arrays so we can reset them with new values
2696 * Call with NULL to disable the programmable pipeline and all enabled
2697 * client-side arrays.
2699 * After binding a program, you should update any uniforms you care about
2700 * with MOJOSHADER_glSetVertexShaderUniformF() (etc), set any vertex arrays
2701 * you want to use with MOJOSHADER_glSetVertexAttribute(), and finally call
2702 * MOJOSHADER_glProgramReady() to commit everything to the GL. Then you may
2703 * begin drawing through standard GL entry points.
2705 * This call is NOT thread safe! As most OpenGL implementations are not thread
2706 * safe, you should probably only call this from the same thread that created
2709 * This call requires a valid MOJOSHADER_glContext to have been made current,
2710 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2712 void MOJOSHADER_glBindProgram(MOJOSHADER_glProgram *program);
2715 * This binds individual shaders as if you had linked them with
2716 * MOJOSHADER_glLinkProgram(), and used MOJOSHADER_glBindProgram() on the
2719 * MojoShader will handle linking behind the scenes, and keep a cache of
2720 * programs linked here. Programs are removed from this cache when one of the
2721 * invidual shaders in it is deleted, otherwise they remain cached so future
2722 * calls to this function don't need to relink a previously-used shader
2725 * This function is for convenience, as the API is closer to how Direct3D
2726 * works, and retrofitting linking into your app can be difficult;
2727 * frequently, you just end up building your own cache, anyhow.
2729 * Calling with all shaders set to NULL is equivalent to calling
2730 * MOJOSHADER_glBindProgram(NULL).
2732 * This call is NOT thread safe! As most OpenGL implementations are not thread
2733 * safe, you should probably only call this from the same thread that created
2736 * This call requires a valid MOJOSHADER_glContext to have been made current,
2737 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2739 void MOJOSHADER_glBindShaders(MOJOSHADER_glShader *vshader,
2740 MOJOSHADER_glShader *pshader);
2743 * Set a floating-point uniform value (what Direct3D calls a "constant").
2745 * There is a single array of 4-float "registers" shared by all vertex shaders.
2746 * This is the "c" register file in Direct3D (c0, c1, c2, etc...)
2747 * MojoShader will take care of synchronizing this internal array with the
2748 * appropriate variables in the GL shaders.
2750 * (idx) is the index into the internal array: 0 is the first four floats,
2751 * 1 is the next four, etc.
2752 * (data) is a pointer to (vec4count*4) floats.
2754 * This call is NOT thread safe! As most OpenGL implementations are not thread
2755 * safe, you should probably only call this from the same thread that created
2758 * This call requires a valid MOJOSHADER_glContext to have been made current,
2759 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2761 * Uniforms are not shared between contexts.
2763 void MOJOSHADER_glSetVertexShaderUniformF(unsigned int idx, const float *data,
2764 unsigned int vec4count);
2767 * Retrieve a floating-point uniform value (what Direct3D calls a "constant").
2769 * There is a single array of 4-float "registers" shared by all vertex shaders.
2770 * This is the "c" register file in Direct3D (c0, c1, c2, etc...)
2771 * MojoShader will take care of synchronizing this internal array with the
2772 * appropriate variables in the GL shaders.
2774 * (idx) is the index into the internal array: 0 is the first four floats,
2775 * 1 is the next four, etc.
2776 * (data) is a pointer to space for (vec4count*4) floats.
2777 * (data) will be filled will current values in the register file. Results
2778 * are undefined if you request data past the end of the register file or
2779 * previously uninitialized registers.
2781 * This is a "fast" call; we're just reading memory from internal memory. We
2782 * do not query the GPU or the GL for this information.
2784 * This call is NOT thread safe! As most OpenGL implementations are not thread
2785 * safe, you should probably only call this from the same thread that created
2788 * This call requires a valid MOJOSHADER_glContext to have been made current,
2789 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2791 * Uniforms are not shared between contexts.
2793 void MOJOSHADER_glGetVertexShaderUniformF(unsigned int idx, float *data,
2794 unsigned int vec4count);
2798 * Set an integer uniform value (what Direct3D calls a "constant").
2800 * There is a single array of 4-int "registers" shared by all vertex shaders.
2801 * This is the "i" register file in Direct3D (i0, i1, i2, etc...)
2802 * MojoShader will take care of synchronizing this internal array with the
2803 * appropriate variables in the GL shaders.
2805 * (idx) is the index into the internal array: 0 is the first four ints,
2806 * 1 is the next four, etc.
2807 * (data) is a pointer to (ivec4count*4) ints.
2809 * This call is NOT thread safe! As most OpenGL implementations are not thread
2810 * safe, you should probably only call this from the same thread that created
2813 * This call requires a valid MOJOSHADER_glContext to have been made current,
2814 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2816 * Uniforms are not shared between contexts.
2818 void MOJOSHADER_glSetVertexShaderUniformI(unsigned int idx, const int *data,
2819 unsigned int ivec4count);
2822 * Retrieve an integer uniform value (what Direct3D calls a "constant").
2824 * There is a single array of 4-int "registers" shared by all vertex shaders.
2825 * This is the "i" register file in Direct3D (i0, i1, i2, etc...)
2826 * MojoShader will take care of synchronizing this internal array with the
2827 * appropriate variables in the GL shaders.
2829 * (idx) is the index into the internal array: 0 is the first four ints,
2830 * 1 is the next four, etc.
2831 * (data) is a pointer to space for (ivec4count*4) ints.
2832 * (data) will be filled will current values in the register file. Results
2833 * are undefined if you request data past the end of the register file or
2834 * previously uninitialized registers.
2836 * This is a "fast" call; we're just reading memory from internal memory. We
2837 * do not query the GPU or the GL for this information.
2839 * This call is NOT thread safe! As most OpenGL implementations are not thread
2840 * safe, you should probably only call this from the same thread that created
2843 * This call requires a valid MOJOSHADER_glContext to have been made current,
2844 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2846 * Uniforms are not shared between contexts.
2848 void MOJOSHADER_glGetVertexShaderUniformI(unsigned int idx, int *data,
2849 unsigned int ivec4count);
2852 * Set a boolean uniform value (what Direct3D calls a "constant").
2854 * There is a single array of "registers" shared by all vertex shaders.
2855 * This is the "b" register file in Direct3D (b0, b1, b2, etc...)
2856 * MojoShader will take care of synchronizing this internal array with the
2857 * appropriate variables in the GL shaders.
2859 * Unlike the float and int counterparts, booleans are single values, not
2860 * four-element vectors...so idx==1 is the second boolean in the internal
2861 * array, not the fifth.
2863 * Non-zero values are considered "true" and zero is considered "false".
2865 * (idx) is the index into the internal array.
2866 * (data) is a pointer to (bcount) ints.
2868 * This call is NOT thread safe! As most OpenGL implementations are not thread
2869 * safe, you should probably only call this from the same thread that created
2872 * This call requires a valid MOJOSHADER_glContext to have been made current,
2873 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2875 * Uniforms are not shared between contexts.
2877 void MOJOSHADER_glSetVertexShaderUniformB(unsigned int idx, const int *data,
2878 unsigned int bcount);
2881 * Retrieve a boolean uniform value (what Direct3D calls a "constant").
2883 * There is a single array of "registers" shared by all vertex shaders.
2884 * This is the "b" register file in Direct3D (b0, b1, b2, etc...)
2885 * MojoShader will take care of synchronizing this internal array with the
2886 * appropriate variables in the GL shaders.
2888 * Unlike the float and int counterparts, booleans are single values, not
2889 * four-element vectors...so idx==1 is the second boolean in the internal
2890 * array, not the fifth.
2892 * Non-zero values are considered "true" and zero is considered "false".
2893 * This function will always return true values as 1, regardless of what
2894 * non-zero integer you originally used to set the registers.
2896 * (idx) is the index into the internal array.
2897 * (data) is a pointer to space for (bcount) ints.
2898 * (data) will be filled will current values in the register file. Results
2899 * are undefined if you request data past the end of the register file or
2900 * previously uninitialized registers.
2902 * This is a "fast" call; we're just reading memory from internal memory. We
2903 * do not query the GPU or the GL for this information.
2905 * This call is NOT thread safe! As most OpenGL implementations are not thread
2906 * safe, you should probably only call this from the same thread that created
2909 * This call requires a valid MOJOSHADER_glContext to have been made current,
2910 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2912 * Uniforms are not shared between contexts.
2914 void MOJOSHADER_glGetVertexShaderUniformB(unsigned int idx, int *data,
2915 unsigned int bcount);
2918 * The equivalent of MOJOSHADER_glSetVertexShaderUniformF() for pixel
2919 * shaders. Other than using a different internal array that is specific
2920 * to pixel shaders, this functions just like its vertex array equivalent.
2922 * This call is NOT thread safe! As most OpenGL implementations are not thread
2923 * safe, you should probably only call this from the same thread that created
2926 * This call requires a valid MOJOSHADER_glContext to have been made current,
2927 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2929 * Uniforms are not shared between contexts.
2931 void MOJOSHADER_glSetPixelShaderUniformF(unsigned int idx, const float *data,
2932 unsigned int vec4count);
2936 * The equivalent of MOJOSHADER_glGetVertexShaderUniformF() for pixel
2937 * shaders. Other than using a different internal array that is specific
2938 * to pixel shaders, this functions just like its vertex array equivalent.
2940 * This call is NOT thread safe! As most OpenGL implementations are not thread
2941 * safe, you should probably only call this from the same thread that created
2944 * This call requires a valid MOJOSHADER_glContext to have been made current,
2945 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2947 * Uniforms are not shared between contexts.
2949 void MOJOSHADER_glGetPixelShaderUniformF(unsigned int idx, float *data,
2950 unsigned int vec4count);
2954 * The equivalent of MOJOSHADER_glSetVertexShaderUniformI() for pixel
2955 * shaders. Other than using a different internal array that is specific
2956 * to pixel shaders, this functions just like its vertex array equivalent.
2958 * This call is NOT thread safe! As most OpenGL implementations are not thread
2959 * safe, you should probably only call this from the same thread that created
2962 * This call requires a valid MOJOSHADER_glContext to have been made current,
2963 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2965 * Uniforms are not shared between contexts.
2967 void MOJOSHADER_glSetPixelShaderUniformI(unsigned int idx, const int *data,
2968 unsigned int ivec4count);
2972 * The equivalent of MOJOSHADER_glGetVertexShaderUniformI() for pixel
2973 * shaders. Other than using a different internal array that is specific
2974 * to pixel shaders, this functions just like its vertex array equivalent.
2976 * This call is NOT thread safe! As most OpenGL implementations are not thread
2977 * safe, you should probably only call this from the same thread that created
2980 * This call requires a valid MOJOSHADER_glContext to have been made current,
2981 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
2983 * Uniforms are not shared between contexts.
2985 void MOJOSHADER_glGetPixelShaderUniformI(unsigned int idx, int *data,
2986 unsigned int ivec4count);
2989 * The equivalent of MOJOSHADER_glSetVertexShaderUniformB() for pixel
2990 * shaders. Other than using a different internal array that is specific
2991 * to pixel shaders, this functions just like its vertex array equivalent.
2993 * This call is NOT thread safe! As most OpenGL implementations are not thread
2994 * safe, you should probably only call this from the same thread that created
2997 * This call requires a valid MOJOSHADER_glContext to have been made current,
2998 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
3000 * Uniforms are not shared between contexts.
3002 void MOJOSHADER_glSetPixelShaderUniformB(unsigned int idx, const int *data,
3003 unsigned int bcount);
3006 * The equivalent of MOJOSHADER_glGetVertexShaderUniformB() for pixel
3007 * shaders. Other than using a different internal array that is specific
3008 * to pixel shaders, this functions just like its vertex array equivalent.
3010 * This call is NOT thread safe! As most OpenGL implementations are not thread
3011 * safe, you should probably only call this from the same thread that created
3014 * This call requires a valid MOJOSHADER_glContext to have been made current,
3015 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
3017 * Uniforms are not shared between contexts.
3019 void MOJOSHADER_glGetPixelShaderUniformB(unsigned int idx, int *data,
3020 unsigned int bcount);
3023 * Set up the vector for the TEXBEM opcode. Most apps can ignore this API.
3025 * Shader Model 1.1 through 1.3 had an instruction for "fake bump mapping"
3026 * called TEXBEM. To use it, you had to set some sampler states,
3027 * D3DTSS_BUMPENVMATxx, which would be referenced by the opcode.
3029 * This functionality was removed from Shader Model 1.4 and later, because
3030 * it was special-purpose and limited. The functionality could be built on
3031 * more general opcodes, and the sampler state could be supplied in a more
3034 * However, to support this opcode, we supply a way to specify that sampler
3035 * state, and the OpenGL glue code does the right thing to pass that
3036 * information to the shader.
3038 * This call maps to IDirect3DDevice::SetTextureStageState() with the
3039 * D3DTSS_BUMPENVMAT00, D3DTSS_BUMPENVMAT01, D3DTSS_BUMPENVMAT10,
3040 * D3DTSS_BUMPENVMAT11, D3DTSS_BUMPENVLSCALE, and D3DTSS_BUMPENVLOFFSET
3041 * targets. This is only useful for Shader Model < 1.4 pixel shaders, if
3042 * they use the TEXBEM or TEXBEML opcode. If you aren't sure, you don't need
3045 * Like the rest of your uniforms, you must call MOJOSHADER_glProgramReady()
3046 * between setting new values and drawing with them.
3048 * This call is NOT thread safe! As most OpenGL implementations are not thread
3049 * safe, you should probably only call this from the same thread that created
3052 * This call requires a valid MOJOSHADER_glContext to have been made current,
3053 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
3055 * These values are not shared between contexts.
3057 void MOJOSHADER_glSetLegacyBumpMapEnv(unsigned int sampler, float mat00,
3058 float mat01, float mat10, float mat11,
3059 float lscale, float loffset);
3062 * Connect a client-side array to the currently-bound program.
3064 * (usage) and (index) map to Direct3D vertex declaration values: COLOR1 would
3065 * be MOJOSHADER_USAGE_COLOR and 1.
3067 * The caller should bind VBOs before this call and treat (ptr) as an offset,
3070 * MojoShader will figure out where to plug this stream into the
3071 * currently-bound program, and enable the appropriate client-side array.
3073 * (size), (type), (normalized), (stride), and (ptr) correspond to
3074 * glVertexAttribPointer()'s parameters (in most cases, these get passed
3075 * unmolested to that very entry point during this function).
3077 * This call is NOT thread safe! As most OpenGL implementations are not thread
3078 * safe, you should probably only call this from the same thread that created
3081 * This call requires a valid MOJOSHADER_glContext to have been made current,
3082 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
3084 * Vertex attributes are not shared between contexts.
3086 /* !!! FIXME: this should probably be "input" and not "attribute" */
3087 /* !!! FIXME: or maybe "vertex array" or something. */
3088 void MOJOSHADER_glSetVertexAttribute(MOJOSHADER_usage usage,
3089 int index, unsigned int size,
3090 MOJOSHADER_attributeType type,
3091 int normalized, unsigned int stride,
3097 /* These below functions are temporary and will be removed from the API once
3098 the real Effects API is written. Do not use! */
3099 void MOJOSHADER_glSetVertexPreshaderUniformF(unsigned int idx, const float *data,
3100 unsigned int vec4n);
3101 void MOJOSHADER_glGetVertexPreshaderUniformF(unsigned int idx, float *data,
3102 unsigned int vec4n);
3103 void MOJOSHADER_glSetPixelPreshaderUniformF(unsigned int idx, const float *data,
3104 unsigned int vec4n);
3105 void MOJOSHADER_glGetPixelPreshaderUniformF(unsigned int idx, float *data,
3106 unsigned int vec4n);
3107 /* These above functions are temporary and will be removed from the API once
3108 the real Effects API is written. Do not use! */
3114 * Inform MojoShader that it should commit any pending state to the GL. This
3115 * must be called after you bind a program and update any inputs, right
3116 * before you start drawing, so any outstanding changes made to the shared
3117 * constants array (etc) can propagate to the shader during this call.
3119 * This call is NOT thread safe! As most OpenGL implementations are not thread
3120 * safe, you should probably only call this from the same thread that created
3123 * This call requires a valid MOJOSHADER_glContext to have been made current,
3124 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
3126 void MOJOSHADER_glProgramReady(void);
3129 * Free the resources of a linked program. This will delete the GL object
3132 * If the program is currently bound by MOJOSHADER_glBindProgram(), it will
3133 * be deleted as soon as it becomes unbound.
3135 * This call is NOT thread safe! As most OpenGL implementations are not thread
3136 * safe, you should probably only call this from the same thread that created
3139 * This call requires a valid MOJOSHADER_glContext to have been made current,
3140 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
3142 void MOJOSHADER_glDeleteProgram(MOJOSHADER_glProgram *program);
3145 * Free the resources of a compiled shader. This will delete the GL object
3148 * If the shader is currently referenced by a linked program (or is currently
3149 * bound with MOJOSHADER_glBindShaders()), it will be deleted as soon as all
3150 * referencing programs are deleted and it is no longer bound, too.
3152 * This call is NOT thread safe! As most OpenGL implementations are not thread
3153 * safe, you should probably only call this from the same thread that created
3156 * This call requires a valid MOJOSHADER_glContext to have been made current,
3157 * or it will crash your program. See MOJOSHADER_glMakeContextCurrent().
3159 void MOJOSHADER_glDeleteShader(MOJOSHADER_glShader *shader);
3162 * Deinitialize MojoShader's OpenGL shader management.
3164 * You must call this once, while your GL context (not MojoShader context) is
3165 * still current, if you previously had a successful call to
3166 * MOJOSHADER_glCreateContext(). This should be the last MOJOSHADER_gl*
3167 * function you call until you've prepared a context again.
3169 * This will clean up resources previously allocated, and may call into the GL.
3171 * This will not clean up shaders and programs you created! Please call
3172 * MOJOSHADER_glDeleteShader() and MOJOSHADER_glDeleteProgram() to clean
3173 * those up before calling this function!
3175 * This function destroys the MOJOSHADER_glContext you pass it. If it's the
3176 * current context, then no context will be current upon return.
3178 * This call is NOT thread safe! There must not be any other MOJOSHADER_gl*
3179 * functions running when this is called. Also, as most OpenGL implementations
3180 * are not thread safe, you should probably only call this from the same
3181 * thread that created the GL context.
3183 void MOJOSHADER_glDestroyContext(MOJOSHADER_glContext *ctx);
3189 #endif /* include-once blocker. */
3191 /* end of mojoshader.h ... */