rhino/demo/c/dr_libs/old/dr_mtl.h
Go to the documentation of this file.
1 // Public Domain. See "unlicense" statement at the end of this file.
2 
3 // ABOUT
4 //
5 // dr_mtl is a library for loading materials for use in 2D or 3D graphics. But it's a bit different to
6 // what you may expect. It does not reprsent materials as a static data, but rather as a series of
7 // instructions that interface with a set of inputs. Indeed, this library is more like a compiler - you
8 // specify an input file (such as a Wavefront MTL file), compile it into an intermediate bytecode
9 // represenation, and then run it through a code generator to generate shader code such as GLSL, HLSL,
10 // Spir-V, etc.
11 //
12 //
13 //
14 // USAGE
15 //
16 // This is a single-file library. To use it, do something like the following in one .c file.
17 // #define DR_MTL_IMPLEMENTATION
18 // #include "dr_mtl.h"
19 //
20 // You can then #include dr_mtl.h in other parts of the program as you would with any other header file.
21 //
22 //
23 //
24 // OPTIONS
25 //
26 // #define DRMTL_NO_MTL_COMPILER
27 // Disables the Wavefront MTL compiler.
28 //
29 // #define DRMTL_NO_GLSL_CODEGEN
30 // Disables the GLSL code generator.
31 //
32 //
33 //
34 // TODO
35 // - Add more documentation.
36 // - Add a demo to demonstrate the awesomeness of this library.
37 // - Add trigonometric instructions.
38 
39 #ifndef dr_mtl_h
40 #define dr_mtl_h
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #include <stddef.h>
47 #include <stdbool.h>
48 
49 #if defined(_MSC_VER)
50  #pragma warning(push)
51  #pragma warning(disable:4201) // Non-standard extension used: nameless struct/union.
52 #endif
53 
54 
55 #define DRMTL_MAGIC_NUMBER 0x81DF7405
56 #define DRMTL_CURRENT_VERSION 1
57 
58 #define DRMTL_INPUT_DESC_CONSTI ((unsigned char)-2)
59 #define DRMTL_INPUT_DESC_CONSTF ((unsigned char)-1)
60 #define DRMTL_INPUT_DESC_VARX ((unsigned char)0)
61 #define DRMTL_INPUT_DESC_VARY ((unsigned char)1)
62 #define DRMTL_INPUT_DESC_VARZ ((unsigned char)2)
63 #define DRMTL_INPUT_DESC_VARW ((unsigned char)3)
64 
65 #define DRMTL_MAX_IDENTIFIER_NAME 28
66 #define DRMTL_MAX_CHANNEL_NAME 28
67 #define DRMTL_MAX_PROPERTY_NAME 28
68 
69 #define DRMTL_MAX_INPUT_PATH 252
70 #define DRMTL_MAX_PROPERTY_PATH 224
71 
72 
73 typedef unsigned char drmtl_uint8;
74 typedef unsigned int drmtl_uint32;
75 
77 
78 
80 typedef enum
81 {
95 
96 } drmtl_type;
97 
99 typedef enum
100 {
102  // Assignment
103 
104  // mov
105  drmtl_opcode_movf1 = 0x00000001,
106  drmtl_opcode_movf2 = 0x00000002,
107  drmtl_opcode_movf3 = 0x00000003,
108  drmtl_opcode_movf4 = 0x00000004,
109  drmtl_opcode_movi1 = 0x00000005,
110  drmtl_opcode_movi2 = 0x00000006,
111  drmtl_opcode_movi3 = 0x00000007,
112  drmtl_opcode_movi4 = 0x00000008,
113 
114 
116  // Arithmetic
117 
118  // add
119  drmtl_opcode_addf1 = 0x00001001,
120  drmtl_opcode_addf2 = 0x00001002,
121  drmtl_opcode_addf3 = 0x00001003,
122  drmtl_opcode_addf4 = 0x00001004,
123  drmtl_opcode_addi1 = 0x00001005,
124  drmtl_opcode_addi2 = 0x00001006,
125  drmtl_opcode_addi3 = 0x00001007,
126  drmtl_opcode_addi4 = 0x00001008,
127 
128  // sub
129  drmtl_opcode_subf1 = 0x00001101,
130  drmtl_opcode_subf2 = 0x00001102,
131  drmtl_opcode_subf3 = 0x00001103,
132  drmtl_opcode_subf4 = 0x00001104,
133  drmtl_opcode_subi1 = 0x00001105,
134  drmtl_opcode_subi2 = 0x00001106,
135  drmtl_opcode_subi3 = 0x00001107,
136  drmtl_opcode_subi4 = 0x00001108,
137 
138  // mul
139  drmtl_opcode_mulf1 = 0x00001201,
140  drmtl_opcode_mulf2 = 0x00001202,
141  drmtl_opcode_mulf3 = 0x00001203,
142  drmtl_opcode_mulf4 = 0x00001204,
143  drmtl_opcode_muli1 = 0x00001205,
144  drmtl_opcode_muli2 = 0x00001206,
145  drmtl_opcode_muli3 = 0x00001207,
146  drmtl_opcode_muli4 = 0x00001208,
147 
148  // div
149  drmtl_opcode_divf1 = 0x00001301,
150  drmtl_opcode_divf2 = 0x00001302,
151  drmtl_opcode_divf3 = 0x00001303,
152  drmtl_opcode_divf4 = 0x00001304,
153  drmtl_opcode_divi1 = 0x00001305,
154  drmtl_opcode_divi2 = 0x00001306,
155  drmtl_opcode_divi3 = 0x00001307,
156  drmtl_opcode_divi4 = 0x00001308,
157 
158  // pow
159  drmtl_opcode_powf1 = 0x00001401,
160  drmtl_opcode_powf2 = 0x00001402,
161  drmtl_opcode_powf3 = 0x00001403,
162  drmtl_opcode_powf4 = 0x00001404,
163  drmtl_opcode_powi1 = 0x00001405,
164  drmtl_opcode_powi2 = 0x00001406,
165  drmtl_opcode_powi3 = 0x00001407,
166  drmtl_opcode_powi4 = 0x00001408,
167 
168 
170  // Textures
171 
172  // tex
173  drmtl_opcode_tex1 = 0x00002001,
174  drmtl_opcode_tex2 = 0x00002002,
175  drmtl_opcode_tex3 = 0x00002003,
176  drmtl_opcode_texcube = 0x00002004,
177 
178 
180  // Miscellaneous
181 
182  // var
183  drmtl_opcode_var = 0x00003000,
184 
185  // ret
186  drmtl_opcode_retf1 = 0x00003001,
187  drmtl_opcode_retf2 = 0x00003002,
188  drmtl_opcode_retf3 = 0x00003003,
189  drmtl_opcode_retf4 = 0x00003004,
190  drmtl_opcode_reti1 = 0x00003005,
191  drmtl_opcode_reti2 = 0x00003006,
192  drmtl_opcode_reti3 = 0x00003007,
193  drmtl_opcode_reti4 = 0x00003008
194 
195 } drmtl_opcode;
196 
197 
200 typedef struct
201 {
203  drmtl_type type;
204 
207 
209 
210 
212 typedef struct
213 {
215  unsigned int identifierIndex;
216 
218  union
219  {
220  struct
221  {
222  float x;
223  } f1;
224  struct
225  {
226  float x;
227  float y;
228  } f2;
229  struct
230  {
231  float x;
232  float y;
233  float z;
234  } f3;
235  struct
236  {
237  float x;
238  float y;
239  float z;
240  float w;
241  } f4;
242 
243  struct
244  {
245  int x;
246  } i1;
247  struct
248  {
249  int x;
250  int y;
251  } i2;
252  struct
253  {
254  int x;
255  int y;
256  int z;
257  } i3;
258  struct
259  {
260  int x;
261  int y;
262  int z;
263  int w;
264  } i4;
265 
266  struct
267  {
268  char value[DRMTL_MAX_INPUT_PATH]; // Enough room for a path, but less to keep the total size of the structure at 256 bytes. Null terminated.
269  } path;
270 
271 
272  struct
273  {
274  drmtl_uint32 x;
275  drmtl_uint32 y;
276  drmtl_uint32 z;
277  drmtl_uint32 w;
278  } raw4;
279  };
280 
281 } drmtl_input;
282 
283 
284 typedef struct
285 {
287  drmtl_type type;
288 
291 
292 } drmtl_channel;
293 
294 
297 typedef union
298 {
300  unsigned int id;
301 
303  float valuef;
304 
306  int valuei;
307 
309 
310 
312 typedef struct
313 {
314  unsigned char x;
315  unsigned char y;
316  unsigned char z;
317  unsigned char w;
318 
320 
322 typedef struct
323 {
325  drmtl_opcode opcode;
326 
328  union
329  {
330  // mov data.
331  struct
332  {
338  unsigned int output;
339  } mov;
340 
341 
342  // add data.
343  struct
344  {
350  unsigned int output;
351  } add;
352 
353  // sub data.
354  struct
355  {
361  unsigned int output;
362  } sub;
363 
364  // mul data.
365  struct
366  {
372  unsigned int output;
373  } mul;
374 
375  // div data.
376  struct
377  {
383  unsigned int output;
384  } div;
385 
386  // pow data.
387  struct
388  {
394  unsigned int output;
395  } pow;
396 
397 
398  // tex data.
399  struct
400  {
406  unsigned int texture;
407  unsigned int output;
408  } tex;
409 
410 
411  // ret data.
412  struct
413  {
419  } ret;
420 
421 
422  // var data
423  struct
424  {
425  //drmtl_type type;
426  unsigned int identifierIndex;
427  } var;
428 
429 
430  // Ensures the size of the instruction is always 32 bytes.
431  struct
432  {
433  drmtl_uint8 _unused[32];
434  } unused;
435  };
436 
438 
439 
440 typedef struct
441 {
443  drmtl_type type;
444 
447 
449  union
450  {
451  struct
452  {
453  float x;
454  } f1;
455  struct
456  {
457  float x;
458  float y;
459  } f2;
460  struct
461  {
462  float x;
463  float y;
464  float z;
465  } f3;
466  struct
467  {
468  float x;
469  float y;
470  float z;
471  float w;
472  } f4;
473 
474  struct
475  {
476  int x;
477  } i1;
478  struct
479  {
480  int x;
481  int y;
482  } i2;
483  struct
484  {
485  int x;
486  int y;
487  int z;
488  } i3;
489  struct
490  {
491  int x;
492  int y;
493  int z;
494  int w;
495  } i4;
496 
497  struct
498  {
499  char value[DRMTL_MAX_PROPERTY_PATH]; // Enough room for a path, but less to keep the total size of the structure at 256 bytes. Null terminated.
500  } path;
501 
502  struct
503  {
504  int x;
505  } b1;
506  };
507 
509 
510 
512 typedef struct
513 {
515  unsigned int magic;
516 
519  unsigned int version;
520 
521 
523  unsigned int identifierSizeInBytes;
524 
526  unsigned int inputSizeInBytes;
527 
529  unsigned int channelHeaderSizeInBytes;
530 
532  unsigned int instructionSizeInBytes;
533 
535  unsigned int propertySizeInBytes;
536 
537 
539  unsigned int identifierCount;
540 
542  unsigned int privateInputCount;
543 
545  unsigned int publicInputCount;
546 
548  unsigned int channelCount;
549 
551  unsigned int propertyCount;
552 
553 
555  unsigned int identifiersOffset;
556 
558  unsigned int inputsOffset;
559 
561  unsigned int channelsOffset;
562 
564  unsigned int propertiesOffset;
565 
566 
567 } drmtl_header;
568 
569 typedef struct
570 {
572  drmtl_channel channel;
573 
575  unsigned int instructionCount;
576 
578 
579 
581 struct drmtl_material
582 {
585 
587  unsigned int sizeInBytes;
588 
590  unsigned int bufferSizeInBytes;
591 
592 
595  unsigned int currentStage;
596 
599  unsigned int currentChannelOffset;
600 
601 
604  bool ownsRawData;
605 };
606 
607 
608 
610 // Low-Level APIs
611 //
612 // Use these APIs to work on materials directly. Note that these are intentionally restrictive in that things can
613 // be added to the material, however they can never be removed. In addition, everything must be added in order which
614 // means identifiers need to be added first, followed by private inputs, followed by public inputs, followed by
615 // channels, followed by properties.
616 //
617 // Use these to construct a material after everything has been processed at a higher level.
618 
624 bool drmtl_init(drmtl_material* pMaterial);
625 bool drmtl_initfromexisting(drmtl_material* pMaterial, const void* pRawData, unsigned int dataSizeInBytes);
626 bool drmtl_initfromexisting_nocopy(drmtl_material* pMaterial, const void* pRawData, unsigned int dataSizeInBytes);
627 
631 void drmtl_uninit(drmtl_material* pMaterial);
632 
633 
636 
637 
641 bool drmtl_appendidentifier(drmtl_material* pMaterial, drmtl_identifier identifier, unsigned int* indexOut);
642 
644 bool drmtl_appendprivateinput(drmtl_material* pMaterial, drmtl_input input);
645 
647 bool drmtl_appendpublicinput(drmtl_material* pMaterial, drmtl_input input);
648 
655 bool drmtl_appendchannel(drmtl_material* pMaterial, drmtl_channel channelHeader);
656 
658 bool drmtl_appendinstruction(drmtl_material* pMaterial, drmtl_instruction instruction);
659 
661 bool drmtl_appendproperty(drmtl_material* pMaterial, drmtl_property prop);
662 
663 
668 drmtl_channel_header* drmtl_getchannelheaderbyindex(drmtl_material* pMaterial, unsigned int channelIndex);
669 
674 drmtl_channel_header* drmtl_getchannelheaderbyname(drmtl_material* pMaterial, const char* channelName);
675 
676 
679 drmtl_identifier* drmtl_getidentifier(drmtl_material* pMaterial, unsigned int index);
680 
682 unsigned int drmtl_getidentifiercount(drmtl_material* pMaterial);
683 
684 
686 unsigned int drmtl_getinputcount(drmtl_material* pMaterial);
687 
689 drmtl_input* drmtl_getinputbyindex(drmtl_material* pMaterial, unsigned int index);
690 
692 unsigned int drmtl_getprivateinputcount(drmtl_material* pMaterial);
693 
695 drmtl_input* drmtl_getprivateinputbyindex(drmtl_material* pMaterial, unsigned int index);
696 
698 unsigned int drmtl_getpublicinputcount(drmtl_material* pMaterial);
699 
701 drmtl_input* drmtl_getpublicinputbyindex(drmtl_material* pMaterial, unsigned int index);
702 
703 
705 unsigned int drmtl_getpropertycount(drmtl_material* pMaterial);
706 
708 drmtl_property* drmtl_getpropertybyindex(drmtl_material* pMaterial, unsigned int index);
709 
715 
716 
717 
719 // Mid-Level APIs
720 
731 
733 drmtl_input drmtl_input_float(unsigned int identifierIndex, float x);
734 drmtl_input drmtl_input_float2(unsigned int identifierIndex, float x, float y);
735 drmtl_input drmtl_input_float3(unsigned int identifierIndex, float x, float y, float z);
736 drmtl_input drmtl_input_float4(unsigned int identifierIndex, float x, float y, float z, float w);
737 drmtl_input drmtl_input_int(unsigned int identifierIndex, int x);
738 drmtl_input drmtl_input_int2(unsigned int identifierIndex, int x, int y);
739 drmtl_input drmtl_input_int3(unsigned int identifierIndex, int x, int y, int z);
740 drmtl_input drmtl_input_int4(unsigned int identifierIndex, int x, int y, int z, int w);
741 drmtl_input drmtl_input_tex(unsigned int identifierIndex, const char* path);
742 
752 
754 drmtl_instruction drmtl_movf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
755 drmtl_instruction drmtl_movf1_c1(unsigned int outputIdentifierIndex, float x);
756 drmtl_instruction drmtl_movf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
757 drmtl_instruction drmtl_movf2_c2(unsigned int outputIdentifierIndex, float x, float y);
758 drmtl_instruction drmtl_movf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
759 drmtl_instruction drmtl_movf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z);
760 drmtl_instruction drmtl_movf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
761 drmtl_instruction drmtl_movf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w);
762 
763 drmtl_instruction drmtl_addf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
764 drmtl_instruction drmtl_addf1_c1(unsigned int outputIdentifierIndex, float x);
765 drmtl_instruction drmtl_addf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
766 drmtl_instruction drmtl_addf2_c2(unsigned int outputIdentifierIndex, float x, float y);
767 drmtl_instruction drmtl_addf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
768 drmtl_instruction drmtl_addf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z);
769 drmtl_instruction drmtl_addf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
770 drmtl_instruction drmtl_addf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w);
771 
772 drmtl_instruction drmtl_subf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
773 drmtl_instruction drmtl_subf1_c1(unsigned int outputIdentifierIndex, float x);
774 drmtl_instruction drmtl_subf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
775 drmtl_instruction drmtl_subf2_c2(unsigned int outputIdentifierIndex, float x, float y);
776 drmtl_instruction drmtl_subf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
777 drmtl_instruction drmtl_subf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z);
778 drmtl_instruction drmtl_subf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
779 drmtl_instruction drmtl_subf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w);
780 
781 drmtl_instruction drmtl_mulf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
782 drmtl_instruction drmtl_mulf1_c1(unsigned int outputIdentifierIndex, float x);
783 drmtl_instruction drmtl_mulf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
784 drmtl_instruction drmtl_mulf2_c2(unsigned int outputIdentifierIndex, float x, float y);
785 drmtl_instruction drmtl_mulf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
786 drmtl_instruction drmtl_mulf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z);
787 drmtl_instruction drmtl_mulf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
788 drmtl_instruction drmtl_mulf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w);
789 drmtl_instruction drmtl_mulf4_v3v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndexXYZ, unsigned int inputIdentifierIndexW);
790 drmtl_instruction drmtl_mulf4_v3c1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float w);
791 drmtl_instruction drmtl_mulf4_v2c2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float z, float w);
792 drmtl_instruction drmtl_mulf4_v1c3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float y, float z, float w);
793 drmtl_instruction drmtl_mulf4_v1v1v1v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndexX, unsigned int inputIdentifierIndexY, unsigned int inputIdentifierIndexZ, unsigned int inputIdentifierIndexW);
794 
795 drmtl_instruction drmtl_divf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
796 drmtl_instruction drmtl_divf1_c1(unsigned int outputIdentifierIndex, float x);
797 drmtl_instruction drmtl_divf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
798 drmtl_instruction drmtl_divf2_c2(unsigned int outputIdentifierIndex, float x, float y);
799 drmtl_instruction drmtl_divf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
800 drmtl_instruction drmtl_divf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z);
801 drmtl_instruction drmtl_divf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex);
802 drmtl_instruction drmtl_divf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w);
803 
804 drmtl_instruction drmtl_tex2(unsigned int outputIdentifierIndex, unsigned int textureIdentifierIndex, unsigned int texcoordIdentifierIndex);
805 drmtl_instruction drmtl_var(unsigned int identifierIndex);
806 drmtl_instruction drmtl_retf1(unsigned int identifierIndex);
807 drmtl_instruction drmtl_retf2(unsigned int identifierIndex);
808 drmtl_instruction drmtl_retf3(unsigned int identifierIndex);
809 drmtl_instruction drmtl_retf4(unsigned int identifierIndex);
811 drmtl_instruction drmtl_retf2_c2(float x, float y);
812 drmtl_instruction drmtl_retf3_c3(float x, float y, float z);
813 drmtl_instruction drmtl_retf4_c4(float x, float y, float z, float w);
814 drmtl_instruction drmtl_reti1(unsigned int identifierIndex);
815 drmtl_instruction drmtl_reti2(unsigned int identifierIndex);
816 drmtl_instruction drmtl_reti3(unsigned int identifierIndex);
817 drmtl_instruction drmtl_reti4(unsigned int identifierIndex);
819 drmtl_instruction drmtl_reti2_c2(int x, int y);
820 drmtl_instruction drmtl_reti3_c3(int x, int y, int z);
821 drmtl_instruction drmtl_reti4_c4(int x, int y, int z, int w);
822 
824 drmtl_property drmtl_property_float(const char* name, float x);
825 drmtl_property drmtl_property_float2(const char* name, float x, float y);
826 drmtl_property drmtl_property_float3(const char* name, float x, float y, float z);
827 drmtl_property drmtl_property_float4(const char* name, float x, float y, float z, float w);
828 drmtl_property drmtl_property_int(const char* name, int x);
829 drmtl_property drmtl_property_int2(const char* name, int x, int y);
830 drmtl_property drmtl_property_int3(const char* name, int x, int y, int z);
831 drmtl_property drmtl_property_int4(const char* name, int x, int y, int z, int w);
832 drmtl_property drmtl_property_bool(const char* name, bool value);
833 
834 
835 
836 
839 //
840 // Compilers
841 //
844 
845 #ifndef DRMTL_NO_MTL_COMPILER
846 bool drmtl_compile_wavefront_mtl(drmtl_material* pMaterial, const char* mtlData, size_t mtlDataSizeInBytes, const char* texcoordInputName);
860 #endif
861 
862 
863 
864 
867 //
868 // Code Generators
869 //
872 
873 #ifndef DRMTL_NO_GLSL_CODEGEN
874 bool drmtl_codegen_glsl_channel(drmtl_material* pMaterial, const char* channelName, char* codeOut, size_t codeOutSizeInBytes, size_t* pBytesWrittenOut);
876 
878 bool drmtl_codegen_glsl_uniforms(drmtl_material* pMaterial, char* codeOut, size_t codeOutSizeInBytes, size_t* pBytesWritteOut);
879 #endif
880 
881 
882 
883 
884 
885 #if defined(_MSC_VER)
886  #pragma warning(pop)
887 #endif
888 
889 #ifdef __cplusplus
890 }
891 #endif
892 
893 #endif //dr_mtl_h
894 
895 
897 //
898 // IMPLEMENTATION
899 //
901 #ifdef DR_MTL_IMPLEMENTATION
902 #include <stdlib.h>
903 #include <string.h>
904 #include <assert.h>
905 #include <errno.h>
906 #include <limits.h>
907 
908 #if defined(__clang__)
909  #pragma GCC diagnostic push
910  #pragma GCC diagnostic ignored "-Wcast-align"
911 #endif
912 
913 
914 // When constructing the material's raw data, memory is allocated in blocks of this amount. This must be at least 256.
915 #define DRMTL_CHUNK_SIZE 4096
916 
917 #define DRMTL_STAGE_IDS 0
918 #define DRMTL_STAGE_PRIVATE_INPUTS 1
919 #define DRMTL_STAGE_PUBLIC_INPUTS 2
920 #define DRMTL_STAGE_CHANNELS 3
921 #define DRMTL_STAGE_PROPERTIES 4
922 #define DRMTL_STAGE_COMPLETE UINT_MAX
923 
924 
926 // Utilities
927 
928 // strcpy()
929 static int drmtl_strcpy(char* dst, size_t dstSizeInBytes, const char* src)
930 {
931 #if defined(_MSC_VER)
932  return strcpy_s(dst, dstSizeInBytes, src);
933 #else
934  if (dst == 0) {
935  return EINVAL;
936  }
937  if (dstSizeInBytes == 0) {
938  return ERANGE;
939  }
940  if (src == 0) {
941  dst[0] = '\0';
942  return EINVAL;
943  }
944 
945  char* iDst = dst;
946  const char* iSrc = src;
947  size_t remainingSizeInBytes = dstSizeInBytes;
948  while (remainingSizeInBytes > 0 && iSrc[0] != '\0')
949  {
950  iDst[0] = iSrc[0];
951 
952  iDst += 1;
953  iSrc += 1;
954  remainingSizeInBytes -= 1;
955  }
956 
957  if (remainingSizeInBytes > 0) {
958  iDst[0] = '\0';
959  } else {
960  dst[0] = '\0';
961  return ERANGE;
962  }
963 
964  return 0;
965 #endif
966 }
967 
968 
969 
971 bool _drmtl_inflate(drmtl_material* pMaterial);
972 
973 
974 bool drmtl_init(drmtl_material* pMaterial)
975 {
976  if (pMaterial != NULL)
977  {
978  assert(DRMTL_CHUNK_SIZE >= 256);
979 
980  pMaterial->pRawData = (drmtl_uint8*)malloc(DRMTL_CHUNK_SIZE);
981  if (pMaterial->pRawData != NULL)
982  {
983  pMaterial->sizeInBytes = sizeof(drmtl_header);
984  pMaterial->bufferSizeInBytes = DRMTL_CHUNK_SIZE;
985  pMaterial->currentStage = DRMTL_STAGE_IDS;
986  pMaterial->currentChannelOffset = 0;
987  pMaterial->ownsRawData = 1;
988 
989  drmtl_header* pHeader = drmtl_getheader(pMaterial);
990  assert(pHeader != NULL);
991 
992  pHeader->magic = DRMTL_MAGIC_NUMBER;
993  pHeader->version = DRMTL_CURRENT_VERSION;
994  pHeader->identifierSizeInBytes = sizeof(drmtl_identifier);
995  pHeader->inputSizeInBytes = sizeof(drmtl_input);
997  pHeader->instructionSizeInBytes = sizeof(drmtl_instruction);
998  pHeader->propertySizeInBytes = sizeof(drmtl_property);
999  pHeader->identifierCount = 0;
1000  pHeader->privateInputCount = 0;
1001  pHeader->publicInputCount = 0;
1002  pHeader->channelCount = 0;
1003  pHeader->propertyCount = 0;
1004  pHeader->identifiersOffset = pMaterial->sizeInBytes;
1005  pHeader->inputsOffset = pMaterial->sizeInBytes;
1006  pHeader->channelsOffset = pMaterial->sizeInBytes;
1007  pHeader->propertiesOffset = pMaterial->sizeInBytes;
1008 
1009  return 1;
1010  }
1011  }
1012 
1013  return 0;
1014 }
1015 
1016 bool drmtl_initfromexisting(drmtl_material* pMaterial, const void* pRawData, unsigned int dataSizeInBytes)
1017 {
1018  if (pMaterial != NULL)
1019  {
1020  if (pRawData != NULL && dataSizeInBytes >= sizeof(drmtl_header))
1021  {
1022  if (((drmtl_header*)pMaterial->pRawData)->magic == DRMTL_MAGIC_NUMBER)
1023  {
1024  pMaterial->pRawData = (drmtl_uint8*)malloc(DRMTL_CHUNK_SIZE);
1025  if (pMaterial->pRawData != NULL)
1026  {
1027  memcpy(pMaterial->pRawData, pRawData, dataSizeInBytes);
1028  pMaterial->sizeInBytes = dataSizeInBytes;
1029  pMaterial->bufferSizeInBytes = dataSizeInBytes;
1030  pMaterial->currentStage = DRMTL_STAGE_COMPLETE;
1031  pMaterial->currentChannelOffset = 0;
1032  pMaterial->ownsRawData = 1;
1033 
1034  return 1;
1035  }
1036  }
1037  }
1038  }
1039 
1040  return 0;
1041 }
1042 
1043 bool drmtl_initfromexisting_nocopy(drmtl_material* pMaterial, const void* pRawData, unsigned int dataSizeInBytes)
1044 {
1045  if (pMaterial != NULL)
1046  {
1047  if (pRawData != NULL && dataSizeInBytes >= sizeof(drmtl_header))
1048  {
1049  if (((const drmtl_header*)pRawData)->magic == DRMTL_MAGIC_NUMBER)
1050  {
1051  pMaterial->pRawData = (drmtl_uint8*)pRawData;
1052  pMaterial->sizeInBytes = dataSizeInBytes;
1053  pMaterial->bufferSizeInBytes = dataSizeInBytes;
1054  pMaterial->currentStage = DRMTL_STAGE_COMPLETE;
1055  pMaterial->currentChannelOffset = 0;
1056  pMaterial->ownsRawData = 0;
1057 
1058  return 1;
1059  }
1060  }
1061  }
1062 
1063  return 0;
1064 }
1065 
1066 void drmtl_uninit(drmtl_material* pMaterial)
1067 {
1068  if (pMaterial != NULL)
1069  {
1070  if (pMaterial->ownsRawData)
1071  {
1072  free(pMaterial->pRawData);
1073  }
1074 
1075  pMaterial->pRawData = NULL;
1076  }
1077 }
1078 
1079 
1081 {
1082  if (pMaterial != NULL)
1083  {
1084  return (drmtl_header*)pMaterial->pRawData;
1085  }
1086 
1087  return NULL;
1088 }
1089 
1090 
1091 bool drmtl_appendidentifier(drmtl_material* pMaterial, drmtl_identifier identifier, unsigned int* indexOut)
1092 {
1093  if (pMaterial != NULL)
1094  {
1095  if (pMaterial->currentStage <= DRMTL_STAGE_IDS)
1096  {
1097  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1098  if (pHeader != NULL)
1099  {
1100  if (pMaterial->sizeInBytes + pHeader->identifierSizeInBytes > pMaterial->bufferSizeInBytes)
1101  {
1102  if (!_drmtl_inflate(pMaterial))
1103  {
1104  // An error occured when trying to inflate the buffer. Might be out of memory.
1105  return 0;
1106  }
1107 
1108  pHeader = drmtl_getheader(pMaterial);
1109  assert(pMaterial->sizeInBytes + pHeader->identifierSizeInBytes <= pMaterial->bufferSizeInBytes);
1110  }
1111 
1112 
1113  memcpy(pMaterial->pRawData + pHeader->inputsOffset, &identifier, pHeader->identifierSizeInBytes);
1114  pMaterial->sizeInBytes += pHeader->identifierSizeInBytes;
1115 
1116  pHeader->identifierCount += 1;
1117  pHeader->inputsOffset += pHeader->identifierSizeInBytes;
1118  pHeader->channelsOffset += pHeader->identifierSizeInBytes;
1119  pHeader->propertiesOffset += pHeader->identifierSizeInBytes;
1120 
1121 
1122  if (indexOut != NULL)
1123  {
1124  *indexOut = pHeader->identifierCount - 1;
1125  }
1126 
1127  return 1;
1128  }
1129  }
1130  }
1131 
1132  return 0;
1133 }
1134 
1135 bool drmtl_appendprivateinput(drmtl_material* pMaterial, drmtl_input input)
1136 {
1137  if (pMaterial != NULL)
1138  {
1139  if (pMaterial->currentStage <= DRMTL_STAGE_PRIVATE_INPUTS)
1140  {
1141  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1142  if (pHeader != NULL)
1143  {
1144  if (pMaterial->sizeInBytes + pHeader->inputSizeInBytes > pMaterial->bufferSizeInBytes)
1145  {
1146  if (!_drmtl_inflate(pMaterial))
1147  {
1148  // An error occured when trying to inflate the buffer. Might be out of memory.
1149  return 0;
1150  }
1151 
1152  pHeader = drmtl_getheader(pMaterial);
1153  assert(pMaterial->sizeInBytes + pHeader->inputSizeInBytes <= pMaterial->bufferSizeInBytes);
1154  }
1155 
1156 
1157  memcpy(pMaterial->pRawData + pHeader->channelsOffset, &input, pHeader->inputSizeInBytes);
1158  pMaterial->sizeInBytes += pHeader->inputSizeInBytes;
1159 
1160  pHeader->privateInputCount += 1;
1161  pHeader->channelsOffset += pHeader->inputSizeInBytes;
1162  pHeader->propertiesOffset += pHeader->inputSizeInBytes;
1163 
1164 
1165  pMaterial->currentStage = DRMTL_STAGE_PRIVATE_INPUTS;
1166  return 1;
1167  }
1168  }
1169  }
1170 
1171  return 0;
1172 }
1173 
1174 bool drmtl_appendpublicinput(drmtl_material* pMaterial, drmtl_input input)
1175 {
1176  if (pMaterial != NULL)
1177  {
1178  if (pMaterial->currentStage <= DRMTL_STAGE_PUBLIC_INPUTS)
1179  {
1180  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1181  if (pHeader != NULL)
1182  {
1183  if (pMaterial->sizeInBytes + pHeader->inputSizeInBytes > pMaterial->bufferSizeInBytes)
1184  {
1185  if (!_drmtl_inflate(pMaterial))
1186  {
1187  // An error occured when trying to inflate the buffer. Might be out of memory.
1188  return 0;
1189  }
1190 
1191  pHeader = drmtl_getheader(pMaterial);
1192  assert(pMaterial->sizeInBytes + pHeader->inputSizeInBytes <= pMaterial->bufferSizeInBytes);
1193  }
1194 
1195 
1196  memcpy(pMaterial->pRawData + pHeader->channelsOffset, &input, pHeader->inputSizeInBytes);
1197  pMaterial->sizeInBytes += pHeader->inputSizeInBytes;
1198 
1199  pHeader->publicInputCount += 1;
1200  pHeader->channelsOffset += pHeader->inputSizeInBytes;
1201  pHeader->propertiesOffset += pHeader->inputSizeInBytes;
1202 
1203 
1204  pMaterial->currentStage = DRMTL_STAGE_PUBLIC_INPUTS;
1205  return 1;
1206  }
1207  }
1208  }
1209 
1210  return 0;
1211 }
1212 
1213 bool drmtl_appendchannel(drmtl_material* pMaterial, drmtl_channel channel)
1214 {
1215  if (pMaterial != NULL)
1216  {
1217  if (pMaterial->currentStage <= DRMTL_STAGE_CHANNELS)
1218  {
1219  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1220  if (pHeader != NULL)
1221  {
1222  drmtl_channel_header channelHeader;
1223  channelHeader.channel = channel;
1224  channelHeader.instructionCount = 0;
1225 
1226  if (pMaterial->sizeInBytes + pHeader->channelHeaderSizeInBytes > pMaterial->bufferSizeInBytes)
1227  {
1228  if (!_drmtl_inflate(pMaterial))
1229  {
1230  // An error occured when trying to inflate the buffer. Might be out of memory.
1231  return 0;
1232  }
1233 
1234  pHeader = drmtl_getheader(pMaterial);
1235  assert(pMaterial->sizeInBytes + pHeader->channelHeaderSizeInBytes <= pMaterial->bufferSizeInBytes);
1236  }
1237 
1238 
1239  memcpy(pMaterial->pRawData + pHeader->propertiesOffset, &channelHeader, pHeader->channelHeaderSizeInBytes);
1240  pMaterial->currentChannelOffset = pMaterial->sizeInBytes;
1241  pMaterial->sizeInBytes += pHeader->channelHeaderSizeInBytes;
1242 
1243  pHeader->channelCount += 1;
1244  pHeader->propertiesOffset += pHeader->channelHeaderSizeInBytes;
1245 
1246 
1247  pMaterial->currentStage = DRMTL_STAGE_CHANNELS;
1248  return 1;
1249  }
1250  }
1251  }
1252 
1253  return 0;
1254 }
1255 
1256 bool drmtl_appendinstruction(drmtl_material* pMaterial, drmtl_instruction instruction)
1257 {
1258  if (pMaterial != NULL)
1259  {
1260  if (pMaterial->currentStage == DRMTL_STAGE_CHANNELS)
1261  {
1262  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1263  if (pHeader != NULL)
1264  {
1265  if (pMaterial->sizeInBytes + pHeader->instructionSizeInBytes > pMaterial->bufferSizeInBytes)
1266  {
1267  if (!_drmtl_inflate(pMaterial))
1268  {
1269  // An error occured when trying to inflate the buffer. Might be out of memory.
1270  return 0;
1271  }
1272 
1273  pHeader = drmtl_getheader(pMaterial);
1274  assert(pMaterial->sizeInBytes + pHeader->instructionSizeInBytes <= pMaterial->bufferSizeInBytes);
1275  }
1276 
1277 
1278  memcpy(pMaterial->pRawData + pHeader->propertiesOffset, &instruction, pHeader->instructionSizeInBytes);
1279  pMaterial->sizeInBytes += pHeader->instructionSizeInBytes;
1280 
1281  drmtl_channel_header* pChannelHeader = (drmtl_channel_header*)(pMaterial->pRawData + pMaterial->currentChannelOffset);
1282  if (pChannelHeader != NULL)
1283  {
1284  pChannelHeader->instructionCount += 1;
1285  }
1286 
1287  pHeader->propertiesOffset += pHeader->instructionSizeInBytes;
1288 
1289 
1290  return 1;
1291  }
1292  }
1293  }
1294 
1295  return 0;
1296 }
1297 
1298 bool drmtl_appendproperty(drmtl_material* pMaterial, drmtl_property prop)
1299 {
1300  if (pMaterial != NULL)
1301  {
1302  if (pMaterial->currentStage <= DRMTL_STAGE_CHANNELS)
1303  {
1304  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1305  if (pHeader != NULL)
1306  {
1307  if (pMaterial->sizeInBytes + pHeader->propertySizeInBytes > pMaterial->bufferSizeInBytes)
1308  {
1309  if (!_drmtl_inflate(pMaterial))
1310  {
1311  // An error occured when trying to inflate the buffer. Might be out of memory.
1312  return 0;
1313  }
1314 
1315  pHeader = drmtl_getheader(pMaterial);
1316  assert(pMaterial->sizeInBytes + pHeader->propertySizeInBytes <= pMaterial->bufferSizeInBytes);
1317  }
1318 
1319 
1320  memcpy(pMaterial->pRawData + pMaterial->sizeInBytes, &prop, pHeader->propertySizeInBytes);
1321  pMaterial->sizeInBytes += pHeader->propertySizeInBytes;
1322 
1323  pHeader->propertyCount += 1;
1324 
1325 
1326  pMaterial->currentStage = DRMTL_STAGE_PROPERTIES;
1327  return 1;
1328  }
1329  }
1330  }
1331 
1332  return 0;
1333 }
1334 
1335 
1336 drmtl_channel_header* drmtl_getchannelheaderbyindex(drmtl_material* pMaterial, unsigned int channelIndex)
1337 {
1338  if (pMaterial != NULL)
1339  {
1340  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1341  assert(pHeader != NULL);
1342 
1343  if (channelIndex < pHeader->channelCount)
1344  {
1345  drmtl_uint8* pChannelHeader = pMaterial->pRawData + pHeader->channelsOffset;
1346  for (unsigned int iChannel = 0; iChannel < channelIndex; ++iChannel)
1347  {
1348  pChannelHeader += sizeof(drmtl_channel_header) + (sizeof(drmtl_instruction) * ((drmtl_channel_header*)pChannelHeader)->instructionCount);
1349  }
1350 
1351  return (drmtl_channel_header*)pChannelHeader;
1352  }
1353  }
1354 
1355  return NULL;
1356 }
1357 
1358 drmtl_channel_header* drmtl_getchannelheaderbyname(drmtl_material* pMaterial, const char* channelName)
1359 {
1360  if (pMaterial != NULL)
1361  {
1362  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1363  assert(pHeader != NULL);
1364 
1365  drmtl_uint8* pChannelHeader = pMaterial->pRawData + pHeader->channelsOffset;
1366  for (unsigned int iChannel = 0; iChannel < pHeader->channelCount; ++iChannel)
1367  {
1368  if (strcmp(((drmtl_channel_header*)pChannelHeader)->channel.name, channelName) == 0)
1369  {
1370  return (drmtl_channel_header*)pChannelHeader;
1371  }
1372 
1373  pChannelHeader += sizeof(drmtl_channel_header) + (sizeof(drmtl_instruction) * ((drmtl_channel_header*)pChannelHeader)->instructionCount);
1374  }
1375  }
1376 
1377  return NULL;
1378 }
1379 
1381 {
1382  if (pMaterial != NULL)
1383  {
1384  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1385  assert(pHeader != NULL);
1386 
1387  return (drmtl_identifier*)(pMaterial->pRawData + pHeader->identifiersOffset);
1388  }
1389 
1390  return NULL;
1391 }
1392 
1393 drmtl_identifier* drmtl_getidentifier(drmtl_material* pMaterial, unsigned int index)
1394 {
1395  if (pMaterial != NULL)
1396  {
1397  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1398  assert(pHeader != NULL);
1399 
1400  if (index < pHeader->identifierCount)
1401  {
1402  drmtl_identifier* firstIdentifier = (drmtl_identifier*)(pMaterial->pRawData + pHeader->identifiersOffset);
1403  return firstIdentifier + index;
1404  }
1405  }
1406 
1407  return NULL;
1408 }
1409 
1410 unsigned int drmtl_getidentifiercount(drmtl_material* pMaterial)
1411 {
1412  if (pMaterial != NULL)
1413  {
1414  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1415  assert(pHeader != NULL);
1416 
1417  return pHeader->identifierCount;
1418  }
1419 
1420  return 0;
1421 }
1422 
1423 
1424 unsigned int drmtl_getinputcount(drmtl_material* pMaterial)
1425 {
1426  if (pMaterial != NULL)
1427  {
1428  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1429  assert(pHeader != NULL);
1430 
1431  return pHeader->privateInputCount + pHeader->publicInputCount;
1432  }
1433 
1434  return 0;
1435 }
1436 
1437 drmtl_input* drmtl_getinputbyindex(drmtl_material* pMaterial, unsigned int index)
1438 {
1439  if (pMaterial != NULL)
1440  {
1441  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1442  assert(pHeader != NULL);
1443 
1444  if (index < (pHeader->privateInputCount + pHeader->publicInputCount))
1445  {
1446  drmtl_input* firstInput = (drmtl_input*)(pMaterial->pRawData + pHeader->inputsOffset);
1447  return firstInput + index;
1448  }
1449  }
1450 
1451  return NULL;
1452 }
1453 
1454 unsigned int drmtl_getprivateinputcount(drmtl_material* pMaterial)
1455 {
1456  if (pMaterial != NULL)
1457  {
1458  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1459  assert(pHeader != NULL);
1460 
1461  return pHeader->privateInputCount;
1462  }
1463 
1464  return 0;
1465 }
1466 
1467 drmtl_input* drmtl_getprivateinputbyindex(drmtl_material* pMaterial, unsigned int index)
1468 {
1469  if (pMaterial != NULL)
1470  {
1471  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1472  assert(pHeader != NULL);
1473 
1474  if (index < pHeader->privateInputCount)
1475  {
1476  drmtl_input* firstInput = (drmtl_input*)(pMaterial->pRawData + pHeader->inputsOffset);
1477  return firstInput + index;
1478  }
1479  }
1480 
1481  return NULL;
1482 }
1483 
1484 unsigned int drmtl_getpublicinputcount(drmtl_material* pMaterial)
1485 {
1486  if (pMaterial != NULL)
1487  {
1488  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1489  assert(pHeader != NULL);
1490 
1491  return pHeader->publicInputCount;
1492  }
1493 
1494  return 0;
1495 }
1496 
1497 drmtl_input* drmtl_getpublicinputbyindex(drmtl_material* pMaterial, unsigned int index)
1498 {
1499  if (pMaterial != NULL)
1500  {
1501  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1502  assert(pHeader != NULL);
1503 
1504  if (index < pHeader->publicInputCount)
1505  {
1506  drmtl_input* firstInput = (drmtl_input*)(pMaterial->pRawData + pHeader->inputsOffset);
1507  return firstInput + pHeader->privateInputCount + index;
1508  }
1509  }
1510 
1511  return NULL;
1512 }
1513 
1514 
1515 unsigned int drmtl_getpropertycount(drmtl_material* pMaterial)
1516 {
1517  if (pMaterial != NULL)
1518  {
1519  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1520  assert(pHeader != NULL);
1521 
1522  return pHeader->propertyCount;
1523  }
1524 
1525  return 0;
1526 }
1527 
1528 drmtl_property* drmtl_getpropertybyindex(drmtl_material* pMaterial, unsigned int index)
1529 {
1530  if (pMaterial != NULL)
1531  {
1532  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1533  assert(pHeader != NULL);
1534 
1535  if (index < pHeader->propertyCount)
1536  {
1537  drmtl_property* firstProperty = (drmtl_property*)(pMaterial->pRawData + pHeader->propertiesOffset);
1538  return firstProperty + index;
1539  }
1540  }
1541 
1542  return NULL;
1543 }
1544 
1546 {
1547  if (pMaterial != NULL)
1548  {
1549  drmtl_header* pHeader = drmtl_getheader(pMaterial);
1550  assert(pHeader != NULL);
1551 
1552  for (unsigned int i = 0; i < pHeader->propertyCount; ++i)
1553  {
1554  drmtl_property* pProperty = ((drmtl_property*)(pMaterial->pRawData + pHeader->propertiesOffset)) + i;
1555  assert(pProperty != NULL);
1556 
1557  if (strcmp(pProperty->name, name) == 0)
1558  {
1559  return pProperty;
1560  }
1561  }
1562  }
1563 
1564  return NULL;
1565 }
1566 
1567 
1569 // Private low-level API.
1570 
1571 bool _drmtl_inflate(drmtl_material* pMaterial)
1572 {
1573  assert(pMaterial != NULL);
1574 
1575  drmtl_uint8* pOldBuffer = pMaterial->pRawData;
1576  drmtl_uint8* pNewBuffer = (drmtl_uint8*)malloc(pMaterial->bufferSizeInBytes + DRMTL_CHUNK_SIZE);
1577  if (pNewBuffer != NULL)
1578  {
1579  memcpy(pNewBuffer, pOldBuffer, pMaterial->sizeInBytes);
1580  pMaterial->pRawData = pNewBuffer;
1581  pMaterial->bufferSizeInBytes += DRMTL_CHUNK_SIZE;
1582 
1583  free(pOldBuffer);
1584  return 1;
1585  }
1586 
1587  return 0;
1588 }
1589 
1590 
1591 
1593 // Mid-Level APIs
1594 
1596 {
1597  drmtl_identifier identifier;
1598  identifier.type = drmtl_type_float;
1599  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1600 
1601  return identifier;
1602 }
1603 
1605 {
1606  drmtl_identifier identifier;
1607  identifier.type = drmtl_type_float2;
1608  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1609 
1610  return identifier;
1611 }
1612 
1614 {
1615  drmtl_identifier identifier;
1616  identifier.type = drmtl_type_float3;
1617  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1618 
1619  return identifier;
1620 }
1621 
1623 {
1624  drmtl_identifier identifier;
1625  identifier.type = drmtl_type_float4;
1626  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1627 
1628  return identifier;
1629 }
1630 
1632 {
1633  drmtl_identifier identifier;
1634  identifier.type = drmtl_type_int;
1635  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1636 
1637  return identifier;
1638 }
1639 
1641 {
1642  drmtl_identifier identifier;
1643  identifier.type = drmtl_type_int2;
1644  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1645 
1646  return identifier;
1647 }
1648 
1650 {
1651  drmtl_identifier identifier;
1652  identifier.type = drmtl_type_int3;
1653  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1654 
1655  return identifier;
1656 }
1657 
1659 {
1660  drmtl_identifier identifier;
1661  identifier.type = drmtl_type_int4;
1662  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1663 
1664  return identifier;
1665 }
1666 
1668 {
1669  drmtl_identifier identifier;
1670  identifier.type = drmtl_type_tex2d;
1671  drmtl_strcpy(identifier.name, DRMTL_MAX_IDENTIFIER_NAME, name);
1672 
1673  return identifier;
1674 }
1675 
1676 
1677 drmtl_input drmtl_input_float(unsigned int identifierIndex, float x)
1678 {
1679  drmtl_input input;
1680  input.identifierIndex = identifierIndex;
1681  input.f1.x = x;
1682 
1683  return input;
1684 }
1685 
1686 drmtl_input drmtl_input_float2(unsigned int identifierIndex, float x, float y)
1687 {
1688  drmtl_input input;
1689  input.identifierIndex = identifierIndex;
1690  input.f2.x = x;
1691  input.f2.y = y;
1692 
1693  return input;
1694 }
1695 
1696 drmtl_input drmtl_input_float3(unsigned int identifierIndex, float x, float y, float z)
1697 {
1698  drmtl_input input;
1699  input.identifierIndex = identifierIndex;
1700  input.f3.x = x;
1701  input.f3.y = y;
1702  input.f3.z = z;
1703 
1704  return input;
1705 }
1706 
1707 drmtl_input drmtl_input_float4(unsigned int identifierIndex, float x, float y, float z, float w)
1708 {
1709  drmtl_input input;
1710  input.identifierIndex = identifierIndex;
1711  input.f4.x = x;
1712  input.f4.y = y;
1713  input.f4.z = z;
1714  input.f4.w = w;
1715 
1716  return input;
1717 }
1718 
1719 drmtl_input drmtl_input_int(unsigned int identifierIndex, int x)
1720 {
1721  drmtl_input input;
1722  input.identifierIndex = identifierIndex;
1723  input.i1.x = x;
1724 
1725  return input;
1726 }
1727 
1728 drmtl_input drmtl_input_int2(unsigned int identifierIndex, int x, int y)
1729 {
1730  drmtl_input input;
1731  input.identifierIndex = identifierIndex;
1732  input.i2.x = x;
1733  input.i2.y = y;
1734 
1735  return input;
1736 }
1737 
1738 drmtl_input drmtl_input_int3(unsigned int identifierIndex, int x, int y, int z)
1739 {
1740  drmtl_input input;
1741  input.identifierIndex = identifierIndex;
1742  input.i3.x = x;
1743  input.i3.y = y;
1744  input.i3.z = z;
1745 
1746  return input;
1747 }
1748 
1749 drmtl_input drmtl_input_int4(unsigned int identifierIndex, int x, int y, int z, int w)
1750 {
1751  drmtl_input input;
1752  input.identifierIndex = identifierIndex;
1753  input.i4.x = x;
1754  input.i4.y = y;
1755  input.i4.z = z;
1756  input.i4.w = w;
1757 
1758  return input;
1759 }
1760 
1761 drmtl_input drmtl_input_tex(unsigned int identifierIndex, const char* path)
1762 {
1763  drmtl_input input;
1764  input.identifierIndex = identifierIndex;
1765  drmtl_strcpy(input.path.value, DRMTL_MAX_INPUT_PATH, path);
1766 
1767  return input;
1768 }
1769 
1770 
1772 {
1773  drmtl_channel channel;
1774  channel.type = drmtl_type_float;
1775  drmtl_strcpy(channel.name, DRMTL_MAX_CHANNEL_NAME, name);
1776 
1777  return channel;
1778 }
1779 
1781 {
1782  drmtl_channel channel;
1783  channel.type = drmtl_type_float2;
1784  drmtl_strcpy(channel.name, DRMTL_MAX_CHANNEL_NAME, name);
1785 
1786  return channel;
1787 }
1788 
1790 {
1791  drmtl_channel channel;
1792  channel.type = drmtl_type_float3;
1793  drmtl_strcpy(channel.name, DRMTL_MAX_CHANNEL_NAME, name);
1794 
1795  return channel;
1796 }
1797 
1799 {
1800  drmtl_channel channel;
1801  channel.type = drmtl_type_float4;
1802  drmtl_strcpy(channel.name, DRMTL_MAX_CHANNEL_NAME, name);
1803 
1804  return channel;
1805 }
1806 
1808 {
1809  drmtl_channel channel;
1810  channel.type = drmtl_type_int;
1811  drmtl_strcpy(channel.name, DRMTL_MAX_CHANNEL_NAME, name);
1812 
1813  return channel;
1814 }
1815 
1817 {
1818  drmtl_channel channel;
1819  channel.type = drmtl_type_int2;
1820  drmtl_strcpy(channel.name, DRMTL_MAX_CHANNEL_NAME, name);
1821 
1822  return channel;
1823 }
1824 
1826 {
1827  drmtl_channel channel;
1828  channel.type = drmtl_type_int3;
1829  drmtl_strcpy(channel.name, DRMTL_MAX_CHANNEL_NAME, name);
1830 
1831  return channel;
1832 }
1833 
1835 {
1836  drmtl_channel channel;
1837  channel.type = drmtl_type_int4;
1838  drmtl_strcpy(channel.name, DRMTL_MAX_CHANNEL_NAME, name);
1839 
1840  return channel;
1841 }
1842 
1843 
1844 drmtl_instruction drmtl_movf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
1845 {
1846  drmtl_instruction inst;
1847  inst.opcode = drmtl_opcode_movf1;
1848  inst.mov.inputDesc.x = DRMTL_INPUT_DESC_VARX;
1849  inst.mov.inputX.id = inputIdentifierIndex;
1850  inst.mov.output = outputIdentifierIndex;
1851 
1852  return inst;
1853 }
1854 
1855 drmtl_instruction drmtl_movf1_c1(unsigned int outputIdentifierIndex, float x)
1856 {
1857  drmtl_instruction inst;
1858  inst.opcode = drmtl_opcode_movf1;
1859  inst.mov.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
1860  inst.mov.inputX.valuef = x;
1861  inst.mov.output = outputIdentifierIndex;
1862 
1863  return inst;
1864 }
1865 
1866 drmtl_instruction drmtl_movf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
1867 {
1868  drmtl_instruction inst;
1869  inst.opcode = drmtl_opcode_movf2;
1870  inst.mov.inputDesc.x = DRMTL_INPUT_DESC_VARX;
1871  inst.mov.inputDesc.y = DRMTL_INPUT_DESC_VARY;
1872  inst.mov.inputX.id = inputIdentifierIndex;
1873  inst.mov.inputY.id = inputIdentifierIndex;
1874  inst.mov.output = outputIdentifierIndex;
1875 
1876  return inst;
1877 }
1878 
1879 drmtl_instruction drmtl_movf2_c2(unsigned int outputIdentifierIndex, float x, float y)
1880 {
1881  drmtl_instruction inst;
1882  inst.opcode = drmtl_opcode_movf2;
1883  inst.mov.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
1884  inst.mov.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
1885  inst.mov.inputX.valuef = x;
1886  inst.mov.inputY.valuef = y;
1887  inst.mov.output = outputIdentifierIndex;
1888 
1889  return inst;
1890 }
1891 
1892 drmtl_instruction drmtl_movf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
1893 {
1894  drmtl_instruction inst;
1895  inst.opcode = drmtl_opcode_movf3;
1896  inst.mov.inputDesc.x = DRMTL_INPUT_DESC_VARX;
1897  inst.mov.inputDesc.y = DRMTL_INPUT_DESC_VARY;
1898  inst.mov.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
1899  inst.mov.inputX.id = inputIdentifierIndex;
1900  inst.mov.inputY.id = inputIdentifierIndex;
1901  inst.mov.inputZ.id = inputIdentifierIndex;
1902  inst.mov.output = outputIdentifierIndex;
1903 
1904  return inst;
1905 }
1906 
1907 drmtl_instruction drmtl_movf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
1908 {
1909  drmtl_instruction inst;
1910  inst.opcode = drmtl_opcode_movf3;
1911  inst.mov.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
1912  inst.mov.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
1913  inst.mov.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
1914  inst.mov.inputX.valuef = x;
1915  inst.mov.inputY.valuef = y;
1916  inst.mov.inputZ.valuef = z;
1917  inst.mov.output = outputIdentifierIndex;
1918 
1919  return inst;
1920 }
1921 
1922 drmtl_instruction drmtl_movf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
1923 {
1924  drmtl_instruction inst;
1925  inst.opcode = drmtl_opcode_movf4;
1926  inst.mov.inputDesc.x = DRMTL_INPUT_DESC_VARX;
1927  inst.mov.inputDesc.y = DRMTL_INPUT_DESC_VARY;
1928  inst.mov.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
1929  inst.mov.inputDesc.w = DRMTL_INPUT_DESC_VARW;
1930  inst.mov.inputX.id = inputIdentifierIndex;
1931  inst.mov.inputY.id = inputIdentifierIndex;
1932  inst.mov.inputZ.id = inputIdentifierIndex;
1933  inst.mov.inputW.id = inputIdentifierIndex;
1934  inst.mov.output = outputIdentifierIndex;
1935 
1936  return inst;
1937 }
1938 
1939 drmtl_instruction drmtl_movf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
1940 {
1941  drmtl_instruction inst;
1942  inst.opcode = drmtl_opcode_movf4;
1943  inst.mov.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
1944  inst.mov.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
1945  inst.mov.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
1946  inst.mov.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
1947  inst.mov.inputX.valuef = x;
1948  inst.mov.inputY.valuef = y;
1949  inst.mov.inputZ.valuef = z;
1950  inst.mov.inputW.valuef = w;
1951  inst.mov.output = outputIdentifierIndex;
1952 
1953  return inst;
1954 }
1955 
1956 
1957 drmtl_instruction drmtl_addf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
1958 {
1959  drmtl_instruction inst;
1960  inst.opcode = drmtl_opcode_addf1;
1961  inst.add.inputDesc.x = DRMTL_INPUT_DESC_VARX;
1962  inst.add.inputX.id = inputIdentifierIndex;
1963  inst.add.output = outputIdentifierIndex;
1964 
1965  return inst;
1966 }
1967 
1968 drmtl_instruction drmtl_addf1_c1(unsigned int outputIdentifierIndex, float x)
1969 {
1970  drmtl_instruction inst;
1971  inst.opcode = drmtl_opcode_addf1;
1972  inst.add.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
1973  inst.add.inputX.valuef = x;
1974  inst.add.output = outputIdentifierIndex;
1975 
1976  return inst;
1977 }
1978 
1979 drmtl_instruction drmtl_addf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
1980 {
1981  drmtl_instruction inst;
1982  inst.opcode = drmtl_opcode_addf2;
1983  inst.add.inputDesc.x = DRMTL_INPUT_DESC_VARX;
1984  inst.add.inputDesc.y = DRMTL_INPUT_DESC_VARY;
1985  inst.add.inputX.id = inputIdentifierIndex;
1986  inst.add.inputY.id = inputIdentifierIndex;
1987  inst.add.output = outputIdentifierIndex;
1988 
1989  return inst;
1990 }
1991 
1992 drmtl_instruction drmtl_addf2_c2(unsigned int outputIdentifierIndex, float x, float y)
1993 {
1994  drmtl_instruction inst;
1995  inst.opcode = drmtl_opcode_addf2;
1996  inst.add.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
1997  inst.add.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
1998  inst.add.inputX.valuef = x;
1999  inst.add.inputY.valuef = y;
2000  inst.add.output = outputIdentifierIndex;
2001 
2002  return inst;
2003 }
2004 
2005 drmtl_instruction drmtl_addf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2006 {
2007  drmtl_instruction inst;
2008  inst.opcode = drmtl_opcode_addf3;
2009  inst.add.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2010  inst.add.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2011  inst.add.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2012  inst.add.inputX.id = inputIdentifierIndex;
2013  inst.add.inputY.id = inputIdentifierIndex;
2014  inst.add.inputZ.id = inputIdentifierIndex;
2015  inst.add.output = outputIdentifierIndex;
2016 
2017  return inst;
2018 }
2019 
2020 drmtl_instruction drmtl_addf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
2021 {
2022  drmtl_instruction inst;
2023  inst.opcode = drmtl_opcode_addf3;
2024  inst.add.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2025  inst.add.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2026  inst.add.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2027  inst.add.inputX.valuef = x;
2028  inst.add.inputY.valuef = y;
2029  inst.add.inputZ.valuef = z;
2030  inst.add.output = outputIdentifierIndex;
2031 
2032  return inst;
2033 }
2034 
2035 drmtl_instruction drmtl_addf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2036 {
2037  drmtl_instruction inst;
2038  inst.opcode = drmtl_opcode_addf4;
2039  inst.add.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2040  inst.add.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2041  inst.add.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2042  inst.add.inputDesc.w = DRMTL_INPUT_DESC_VARW;
2043  inst.add.inputX.id = inputIdentifierIndex;
2044  inst.add.inputY.id = inputIdentifierIndex;
2045  inst.add.inputZ.id = inputIdentifierIndex;
2046  inst.add.inputW.id = inputIdentifierIndex;
2047  inst.add.output = outputIdentifierIndex;
2048 
2049  return inst;
2050 }
2051 
2052 drmtl_instruction drmtl_addf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
2053 {
2054  drmtl_instruction inst;
2055  inst.opcode = drmtl_opcode_addf4;
2056  inst.add.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2057  inst.add.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2058  inst.add.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2059  inst.add.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
2060  inst.add.inputX.valuef = x;
2061  inst.add.inputY.valuef = y;
2062  inst.add.inputZ.valuef = z;
2063  inst.add.inputW.valuef = w;
2064  inst.add.output = outputIdentifierIndex;
2065 
2066  return inst;
2067 }
2068 
2069 
2070 drmtl_instruction drmtl_subf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2071 {
2072  drmtl_instruction inst;
2073  inst.opcode = drmtl_opcode_subf1;
2074  inst.sub.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2075  inst.sub.inputX.id = inputIdentifierIndex;
2076  inst.sub.output = outputIdentifierIndex;
2077 
2078  return inst;
2079 }
2080 
2081 drmtl_instruction drmtl_subf1_c1(unsigned int outputIdentifierIndex, float x)
2082 {
2083  drmtl_instruction inst;
2084  inst.opcode = drmtl_opcode_subf1;
2085  inst.sub.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2086  inst.sub.inputX.valuef = x;
2087  inst.sub.output = outputIdentifierIndex;
2088 
2089  return inst;
2090 }
2091 
2092 drmtl_instruction drmtl_subf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2093 {
2094  drmtl_instruction inst;
2095  inst.opcode = drmtl_opcode_subf2;
2096  inst.sub.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2097  inst.sub.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2098  inst.sub.inputX.id = inputIdentifierIndex;
2099  inst.sub.inputY.id = inputIdentifierIndex;
2100  inst.sub.output = outputIdentifierIndex;
2101 
2102  return inst;
2103 }
2104 
2105 drmtl_instruction drmtl_subf2_c2(unsigned int outputIdentifierIndex, float x, float y)
2106 {
2107  drmtl_instruction inst;
2108  inst.opcode = drmtl_opcode_subf2;
2109  inst.sub.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2110  inst.sub.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2111  inst.sub.inputX.valuef = x;
2112  inst.sub.inputY.valuef = y;
2113  inst.sub.output = outputIdentifierIndex;
2114 
2115  return inst;
2116 }
2117 
2118 drmtl_instruction drmtl_subf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2119 {
2120  drmtl_instruction inst;
2121  inst.opcode = drmtl_opcode_subf3;
2122  inst.sub.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2123  inst.sub.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2124  inst.sub.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2125  inst.sub.inputX.id = inputIdentifierIndex;
2126  inst.sub.inputY.id = inputIdentifierIndex;
2127  inst.sub.inputZ.id = inputIdentifierIndex;
2128  inst.sub.output = outputIdentifierIndex;
2129 
2130  return inst;
2131 }
2132 
2133 drmtl_instruction drmtl_subf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
2134 {
2135  drmtl_instruction inst;
2136  inst.opcode = drmtl_opcode_subf3;
2137  inst.sub.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2138  inst.sub.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2139  inst.sub.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2140  inst.sub.inputX.valuef = x;
2141  inst.sub.inputY.valuef = y;
2142  inst.sub.inputZ.valuef = z;
2143  inst.sub.output = outputIdentifierIndex;
2144 
2145  return inst;
2146 }
2147 
2148 drmtl_instruction drmtl_subf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2149 {
2150  drmtl_instruction inst;
2151  inst.opcode = drmtl_opcode_subf4;
2152  inst.sub.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2153  inst.sub.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2154  inst.sub.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2155  inst.sub.inputDesc.w = DRMTL_INPUT_DESC_VARW;
2156  inst.sub.inputX.id = inputIdentifierIndex;
2157  inst.sub.inputY.id = inputIdentifierIndex;
2158  inst.sub.inputZ.id = inputIdentifierIndex;
2159  inst.sub.inputW.id = inputIdentifierIndex;
2160  inst.sub.output = outputIdentifierIndex;
2161 
2162  return inst;
2163 }
2164 
2165 drmtl_instruction drmtl_subf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
2166 {
2167  drmtl_instruction inst;
2168  inst.opcode = drmtl_opcode_subf4;
2169  inst.sub.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2170  inst.sub.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2171  inst.sub.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2172  inst.sub.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
2173  inst.sub.inputX.valuef = x;
2174  inst.sub.inputY.valuef = y;
2175  inst.sub.inputZ.valuef = z;
2176  inst.sub.inputW.valuef = w;
2177  inst.sub.output = outputIdentifierIndex;
2178 
2179  return inst;
2180 }
2181 
2182 
2183 drmtl_instruction drmtl_mulf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2184 {
2185  drmtl_instruction inst;
2186  inst.opcode = drmtl_opcode_mulf1;
2187  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2188  inst.mul.inputX.id = inputIdentifierIndex;
2189  inst.mul.output = outputIdentifierIndex;
2190 
2191  return inst;
2192 }
2193 
2194 drmtl_instruction drmtl_mulf1_c1(unsigned int outputIdentifierIndex, float x)
2195 {
2196  drmtl_instruction inst;
2197  inst.opcode = drmtl_opcode_mulf1;
2198  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2199  inst.mul.inputX.valuef = x;
2200  inst.mul.output = outputIdentifierIndex;
2201 
2202  return inst;
2203 }
2204 
2205 drmtl_instruction drmtl_mulf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2206 {
2207  drmtl_instruction inst;
2208  inst.opcode = drmtl_opcode_mulf2;
2209  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2210  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2211  inst.mul.inputX.id = inputIdentifierIndex;
2212  inst.mul.inputY.id = inputIdentifierIndex;
2213  inst.mul.output = outputIdentifierIndex;
2214 
2215  return inst;
2216 }
2217 
2218 drmtl_instruction drmtl_mulf2_c2(unsigned int outputIdentifierIndex, float x, float y)
2219 {
2220  drmtl_instruction inst;
2221  inst.opcode = drmtl_opcode_mulf2;
2222  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2223  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2224  inst.mul.inputX.valuef = x;
2225  inst.mul.inputY.valuef = y;
2226  inst.mul.output = outputIdentifierIndex;
2227 
2228  return inst;
2229 }
2230 
2231 drmtl_instruction drmtl_mulf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2232 {
2233  drmtl_instruction inst;
2234  inst.opcode = drmtl_opcode_mulf3;
2235  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2236  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2237  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2238  inst.mul.inputX.id = inputIdentifierIndex;
2239  inst.mul.inputY.id = inputIdentifierIndex;
2240  inst.mul.inputZ.id = inputIdentifierIndex;
2241  inst.mul.output = outputIdentifierIndex;
2242 
2243  return inst;
2244 }
2245 
2246 drmtl_instruction drmtl_mulf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
2247 {
2248  drmtl_instruction inst;
2249  inst.opcode = drmtl_opcode_mulf3;
2250  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2251  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2252  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2253  inst.mul.inputX.valuef = x;
2254  inst.mul.inputY.valuef = y;
2255  inst.mul.inputZ.valuef = z;
2256  inst.mul.output = outputIdentifierIndex;
2257 
2258  return inst;
2259 }
2260 
2261 drmtl_instruction drmtl_mulf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2262 {
2263  drmtl_instruction inst;
2264  inst.opcode = drmtl_opcode_mulf4;
2265  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2266  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2267  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2268  inst.mul.inputDesc.w = DRMTL_INPUT_DESC_VARW;
2269  inst.mul.inputX.id = inputIdentifierIndex;
2270  inst.mul.inputY.id = inputIdentifierIndex;
2271  inst.mul.inputZ.id = inputIdentifierIndex;
2272  inst.mul.inputW.id = inputIdentifierIndex;
2273  inst.mul.output = outputIdentifierIndex;
2274 
2275  return inst;
2276 }
2277 
2278 drmtl_instruction drmtl_mulf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
2279 {
2280  drmtl_instruction inst;
2281  inst.opcode = drmtl_opcode_mulf4;
2282  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2283  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2284  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2285  inst.mul.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
2286  inst.mul.inputX.valuef = x;
2287  inst.mul.inputY.valuef = y;
2288  inst.mul.inputZ.valuef = z;
2289  inst.mul.inputW.valuef = w;
2290  inst.mul.output = outputIdentifierIndex;
2291 
2292  return inst;
2293 }
2294 
2295 drmtl_instruction drmtl_mulf4_v3v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndexXYZ, unsigned int inputIdentifierIndexW)
2296 {
2297  drmtl_instruction inst;
2298  inst.opcode = drmtl_opcode_mulf4;
2299  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2300  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2301  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2302  inst.mul.inputDesc.w = DRMTL_INPUT_DESC_VARX;
2303  inst.mul.inputX.id = inputIdentifierIndexXYZ;
2304  inst.mul.inputY.id = inputIdentifierIndexXYZ;
2305  inst.mul.inputZ.id = inputIdentifierIndexXYZ;
2306  inst.mul.inputW.id = inputIdentifierIndexW;
2307  inst.mul.output = outputIdentifierIndex;
2308 
2309  return inst;
2310 }
2311 
2312 drmtl_instruction drmtl_mulf4_v3c1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float w)
2313 {
2314  drmtl_instruction inst;
2315  inst.opcode = drmtl_opcode_mulf4;
2316  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2317  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2318  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2319  inst.mul.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
2320  inst.mul.inputX.id = inputIdentifierIndex;
2321  inst.mul.inputY.id = inputIdentifierIndex;
2322  inst.mul.inputZ.id = inputIdentifierIndex;
2323  inst.mul.inputW.valuef = w;
2324  inst.mul.output = outputIdentifierIndex;
2325 
2326  return inst;
2327 }
2328 
2329 drmtl_instruction drmtl_mulf4_v2c2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float z, float w)
2330 {
2331  drmtl_instruction inst;
2332  inst.opcode = drmtl_opcode_mulf4;
2333  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2334  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2335  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2336  inst.mul.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
2337  inst.mul.inputX.id = inputIdentifierIndex;
2338  inst.mul.inputY.id = inputIdentifierIndex;
2339  inst.mul.inputZ.valuef = z;
2340  inst.mul.inputW.valuef = w;
2341  inst.mul.output = outputIdentifierIndex;
2342 
2343  return inst;
2344 }
2345 
2346 drmtl_instruction drmtl_mulf4_v1c3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float y, float z, float w)
2347 {
2348  drmtl_instruction inst;
2349  inst.opcode = drmtl_opcode_mulf4;
2350  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2351  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2352  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2353  inst.mul.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
2354  inst.mul.inputX.id = inputIdentifierIndex;
2355  inst.mul.inputY.valuef = y;
2356  inst.mul.inputZ.valuef = z;
2357  inst.mul.inputW.valuef = w;
2358  inst.mul.output = outputIdentifierIndex;
2359 
2360  return inst;
2361 }
2362 
2363 drmtl_instruction drmtl_mulf4_v1v1v1v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndexX, unsigned int inputIdentifierIndexY, unsigned int inputIdentifierIndexZ, unsigned int inputIdentifierIndexW)
2364 {
2365  drmtl_instruction inst;
2366  inst.opcode = drmtl_opcode_mulf4;
2367  inst.mul.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2368  inst.mul.inputDesc.y = DRMTL_INPUT_DESC_VARX;
2369  inst.mul.inputDesc.z = DRMTL_INPUT_DESC_VARX;
2370  inst.mul.inputDesc.w = DRMTL_INPUT_DESC_VARX;
2371  inst.mul.inputX.id = inputIdentifierIndexX;
2372  inst.mul.inputY.id = inputIdentifierIndexY;
2373  inst.mul.inputZ.id = inputIdentifierIndexZ;
2374  inst.mul.inputW.id = inputIdentifierIndexW;
2375  inst.mul.output = outputIdentifierIndex;
2376 
2377  return inst;
2378 }
2379 
2380 
2381 drmtl_instruction drmtl_divf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2382 {
2383  drmtl_instruction inst;
2384  inst.opcode = drmtl_opcode_divf1;
2385  inst.div.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2386  inst.div.inputX.id = inputIdentifierIndex;
2387  inst.div.output = outputIdentifierIndex;
2388 
2389  return inst;
2390 }
2391 
2392 drmtl_instruction drmtl_divf1_c1(unsigned int outputIdentifierIndex, float x)
2393 {
2394  drmtl_instruction inst;
2395  inst.opcode = drmtl_opcode_divf1;
2396  inst.div.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2397  inst.div.inputX.valuef = x;
2398  inst.div.output = outputIdentifierIndex;
2399 
2400  return inst;
2401 }
2402 
2403 drmtl_instruction drmtl_divf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2404 {
2405  drmtl_instruction inst;
2406  inst.opcode = drmtl_opcode_divf2;
2407  inst.div.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2408  inst.div.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2409  inst.div.inputX.id = inputIdentifierIndex;
2410  inst.div.inputY.id = inputIdentifierIndex;
2411  inst.div.output = outputIdentifierIndex;
2412 
2413  return inst;
2414 }
2415 
2416 drmtl_instruction drmtl_divf2_c2(unsigned int outputIdentifierIndex, float x, float y)
2417 {
2418  drmtl_instruction inst;
2419  inst.opcode = drmtl_opcode_divf2;
2420  inst.div.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2421  inst.div.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2422  inst.div.inputX.valuef = x;
2423  inst.div.inputY.valuef = y;
2424  inst.div.output = outputIdentifierIndex;
2425 
2426  return inst;
2427 }
2428 
2429 drmtl_instruction drmtl_divf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2430 {
2431  drmtl_instruction inst;
2432  inst.opcode = drmtl_opcode_divf3;
2433  inst.div.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2434  inst.div.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2435  inst.div.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2436  inst.div.inputX.id = inputIdentifierIndex;
2437  inst.div.inputY.id = inputIdentifierIndex;
2438  inst.div.inputZ.id = inputIdentifierIndex;
2439  inst.div.output = outputIdentifierIndex;
2440 
2441  return inst;
2442 }
2443 
2444 drmtl_instruction drmtl_divf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
2445 {
2446  drmtl_instruction inst;
2447  inst.opcode = drmtl_opcode_divf3;
2448  inst.div.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2449  inst.div.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2450  inst.div.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2451  inst.div.inputX.valuef = x;
2452  inst.div.inputY.valuef = y;
2453  inst.div.inputZ.valuef = z;
2454  inst.div.output = outputIdentifierIndex;
2455 
2456  return inst;
2457 }
2458 
2459 drmtl_instruction drmtl_divf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
2460 {
2461  drmtl_instruction inst;
2462  inst.opcode = drmtl_opcode_divf4;
2463  inst.div.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2464  inst.div.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2465  inst.div.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2466  inst.div.inputDesc.w = DRMTL_INPUT_DESC_VARW;
2467  inst.div.inputX.id = inputIdentifierIndex;
2468  inst.div.inputY.id = inputIdentifierIndex;
2469  inst.div.inputZ.id = inputIdentifierIndex;
2470  inst.div.inputW.id = inputIdentifierIndex;
2471  inst.div.output = outputIdentifierIndex;
2472 
2473  return inst;
2474 }
2475 
2476 drmtl_instruction drmtl_divf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
2477 {
2478  drmtl_instruction inst;
2479  inst.opcode = drmtl_opcode_divf4;
2480  inst.div.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2481  inst.div.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2482  inst.div.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2483  inst.div.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
2484  inst.div.inputX.valuef = x;
2485  inst.div.inputY.valuef = y;
2486  inst.div.inputZ.valuef = z;
2487  inst.div.inputW.valuef = w;
2488  inst.div.output = outputIdentifierIndex;
2489 
2490  return inst;
2491 }
2492 
2493 
2494 drmtl_instruction drmtl_tex2(unsigned int outputIdentifierIndex, unsigned int textureIdentifierIndex, unsigned int texcoordIdentifierIndex)
2495 {
2496  drmtl_instruction inst;
2497  inst.opcode = drmtl_opcode_tex2;
2498  inst.tex.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2499  inst.tex.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2500  inst.tex.inputX.id = texcoordIdentifierIndex;
2501  inst.tex.inputY.id = texcoordIdentifierIndex;
2502  inst.tex.texture = textureIdentifierIndex;
2503  inst.tex.output = outputIdentifierIndex;
2504 
2505  return inst;
2506 }
2507 
2508 drmtl_instruction drmtl_var(unsigned int identifierIndex)
2509 {
2510  drmtl_instruction inst;
2511  inst.opcode = drmtl_opcode_var;
2512  inst.var.identifierIndex = identifierIndex;
2513 
2514  return inst;
2515 }
2516 
2517 drmtl_instruction drmtl_retf1(unsigned int identifierIndex)
2518 {
2519  drmtl_instruction inst;
2520  inst.opcode = drmtl_opcode_retf1;
2521  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2522  inst.ret.inputX.id = identifierIndex;
2523 
2524  return inst;
2525 }
2526 
2527 drmtl_instruction drmtl_retf2(unsigned int identifierIndex)
2528 {
2529  drmtl_instruction inst;
2530  inst.opcode = drmtl_opcode_retf2;
2531  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2532  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2533  inst.ret.inputX.id = identifierIndex;
2534  inst.ret.inputY.id = identifierIndex;
2535 
2536  return inst;
2537 }
2538 
2539 drmtl_instruction drmtl_retf3(unsigned int identifierIndex)
2540 {
2541  drmtl_instruction inst;
2542  inst.opcode = drmtl_opcode_retf3;
2543  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2544  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2545  inst.ret.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2546  inst.ret.inputX.id = identifierIndex;
2547  inst.ret.inputY.id = identifierIndex;
2548  inst.ret.inputZ.id = identifierIndex;
2549 
2550  return inst;
2551 }
2552 
2553 drmtl_instruction drmtl_retf4(unsigned int identifierIndex)
2554 {
2555  drmtl_instruction inst;
2556  inst.opcode = drmtl_opcode_retf4;
2557  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2558  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2559  inst.ret.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2560  inst.ret.inputDesc.w = DRMTL_INPUT_DESC_VARW;
2561  inst.ret.inputX.id = identifierIndex;
2562  inst.ret.inputY.id = identifierIndex;
2563  inst.ret.inputZ.id = identifierIndex;
2564  inst.ret.inputW.id = identifierIndex;
2565 
2566  return inst;
2567 }
2568 
2570 {
2571  drmtl_instruction inst;
2572  inst.opcode = drmtl_opcode_retf1;
2573  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2574  inst.ret.inputX.valuef = x;
2575 
2576  return inst;
2577 }
2578 
2579 drmtl_instruction drmtl_retf2_c2(float x, float y)
2580 {
2581  drmtl_instruction inst;
2582  inst.opcode = drmtl_opcode_retf2;
2583  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2584  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2585  inst.ret.inputX.valuef = x;
2586  inst.ret.inputY.valuef = y;
2587 
2588  return inst;
2589 }
2590 
2591 drmtl_instruction drmtl_retf3_c3(float x, float y, float z)
2592 {
2593  drmtl_instruction inst;
2594  inst.opcode = drmtl_opcode_retf3;
2595  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2596  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2597  inst.ret.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2598  inst.ret.inputX.valuef = x;
2599  inst.ret.inputY.valuef = y;
2600  inst.ret.inputZ.valuef = z;
2601 
2602  return inst;
2603 }
2604 
2605 drmtl_instruction drmtl_retf4_c4(float x, float y, float z, float w)
2606 {
2607  drmtl_instruction inst;
2608  inst.opcode = drmtl_opcode_retf4;
2609  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_CONSTF;
2610  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_CONSTF;
2611  inst.ret.inputDesc.z = DRMTL_INPUT_DESC_CONSTF;
2612  inst.ret.inputDesc.w = DRMTL_INPUT_DESC_CONSTF;
2613  inst.ret.inputX.valuef = x;
2614  inst.ret.inputY.valuef = y;
2615  inst.ret.inputZ.valuef = z;
2616  inst.ret.inputW.valuef = w;
2617 
2618  return inst;
2619 }
2620 
2621 drmtl_instruction drmtl_reti1(unsigned int identifierIndex)
2622 {
2623  drmtl_instruction inst;
2624  inst.opcode = drmtl_opcode_reti1;
2625  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2626  inst.ret.inputX.id = identifierIndex;
2627 
2628  return inst;
2629 }
2630 
2631 drmtl_instruction drmtl_reti2(unsigned int identifierIndex)
2632 {
2633  drmtl_instruction inst;
2634  inst.opcode = drmtl_opcode_reti2;
2635  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2636  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2637  inst.ret.inputX.id = identifierIndex;
2638  inst.ret.inputY.id = identifierIndex;
2639 
2640  return inst;
2641 }
2642 
2643 drmtl_instruction drmtl_reti3(unsigned int identifierIndex)
2644 {
2645  drmtl_instruction inst;
2646  inst.opcode = drmtl_opcode_reti3;
2647  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2648  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2649  inst.ret.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2650  inst.ret.inputX.id = identifierIndex;
2651  inst.ret.inputY.id = identifierIndex;
2652  inst.ret.inputZ.id = identifierIndex;
2653 
2654  return inst;
2655 }
2656 
2657 drmtl_instruction drmtl_reti4(unsigned int identifierIndex)
2658 {
2659  drmtl_instruction inst;
2660  inst.opcode = drmtl_opcode_reti4;
2661  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_VARX;
2662  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_VARY;
2663  inst.ret.inputDesc.z = DRMTL_INPUT_DESC_VARZ;
2664  inst.ret.inputDesc.w = DRMTL_INPUT_DESC_VARW;
2665  inst.ret.inputX.id = identifierIndex;
2666  inst.ret.inputY.id = identifierIndex;
2667  inst.ret.inputZ.id = identifierIndex;
2668  inst.ret.inputW.id = identifierIndex;
2669 
2670  return inst;
2671 }
2672 
2674 {
2675  drmtl_instruction inst;
2676  inst.opcode = drmtl_opcode_reti1;
2677  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_CONSTI;
2678  inst.ret.inputX.valuei = x;
2679 
2680  return inst;
2681 }
2682 
2683 drmtl_instruction drmtl_reti2_c2(int x, int y)
2684 {
2685  drmtl_instruction inst;
2686  inst.opcode = drmtl_opcode_reti2;
2687  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_CONSTI;
2688  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_CONSTI;
2689  inst.ret.inputX.valuei = x;
2690  inst.ret.inputY.valuei = y;
2691 
2692  return inst;
2693 }
2694 
2695 drmtl_instruction drmtl_reti3_c3(int x, int y, int z)
2696 {
2697  drmtl_instruction inst;
2698  inst.opcode = drmtl_opcode_reti3;
2699  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_CONSTI;
2700  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_CONSTI;
2701  inst.ret.inputDesc.z = DRMTL_INPUT_DESC_CONSTI;
2702  inst.ret.inputX.valuei = x;
2703  inst.ret.inputY.valuei = y;
2704  inst.ret.inputZ.valuei = z;
2705 
2706  return inst;
2707 }
2708 
2709 drmtl_instruction drmtl_reti4_c4(int x, int y, int z, int w)
2710 {
2711  drmtl_instruction inst;
2712  inst.opcode = drmtl_opcode_reti4;
2713  inst.ret.inputDesc.x = DRMTL_INPUT_DESC_CONSTI;
2714  inst.ret.inputDesc.y = DRMTL_INPUT_DESC_CONSTI;
2715  inst.ret.inputDesc.z = DRMTL_INPUT_DESC_CONSTI;
2716  inst.ret.inputDesc.w = DRMTL_INPUT_DESC_CONSTI;
2717  inst.ret.inputX.valuei = x;
2718  inst.ret.inputY.valuei = y;
2719  inst.ret.inputZ.valuei = z;
2720  inst.ret.inputW.valuei = w;
2721 
2722  return inst;
2723 }
2724 
2725 
2726 
2727 drmtl_property drmtl_property_float(const char* name, float x)
2728 {
2729  drmtl_property prop;
2730  prop.type = drmtl_type_float;
2731  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2732  prop.f1.x = x;
2733 
2734  return prop;
2735 }
2736 
2737 drmtl_property drmtl_property_float2(const char* name, float x, float y)
2738 {
2739  drmtl_property prop;
2740  prop.type = drmtl_type_float2;
2741  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2742  prop.f2.x = x;
2743  prop.f2.y = y;
2744 
2745  return prop;
2746 }
2747 
2748 drmtl_property drmtl_property_float3(const char* name, float x, float y, float z)
2749 {
2750  drmtl_property prop;
2751  prop.type = drmtl_type_float3;
2752  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2753  prop.f3.x = x;
2754  prop.f3.y = y;
2755  prop.f3.z = z;
2756 
2757  return prop;
2758 }
2759 
2760 drmtl_property drmtl_property_float4(const char* name, float x, float y, float z, float w)
2761 {
2762  drmtl_property prop;
2763  prop.type = drmtl_type_float4;
2764  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2765  prop.f4.x = x;
2766  prop.f4.y = y;
2767  prop.f4.z = z;
2768  prop.f4.w = w;
2769 
2770  return prop;
2771 }
2772 
2773 drmtl_property drmtl_property_int(const char* name, int x)
2774 {
2775  drmtl_property prop;
2776  prop.type = drmtl_type_int;
2777  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2778  prop.i1.x = x;
2779 
2780  return prop;
2781 }
2782 
2783 drmtl_property drmtl_property_int2(const char* name, int x, int y)
2784 {
2785  drmtl_property prop;
2786  prop.type = drmtl_type_int2;
2787  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2788  prop.i2.x = x;
2789  prop.i2.y = y;
2790 
2791  return prop;
2792 }
2793 
2794 drmtl_property drmtl_property_int3(const char* name, int x, int y, int z)
2795 {
2796  drmtl_property prop;
2797  prop.type = drmtl_type_int3;
2798  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2799  prop.i3.x = x;
2800  prop.i3.y = y;
2801  prop.i3.z = z;
2802 
2803  return prop;
2804 }
2805 
2806 drmtl_property drmtl_property_int4(const char* name, int x, int y, int z, int w)
2807 {
2808  drmtl_property prop;
2809  prop.type = drmtl_type_int4;
2810  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2811  prop.i4.x = x;
2812  prop.i4.y = y;
2813  prop.i4.z = z;
2814  prop.i4.w = w;
2815 
2816  return prop;
2817 }
2818 
2819 drmtl_property drmtl_property_bool(const char* name, bool value)
2820 {
2821  drmtl_property prop;
2822  prop.type = drmtl_type_bool;
2823  drmtl_strcpy(prop.name, DRMTL_MAX_PROPERTY_NAME, name);
2824  prop.b1.x = value;
2825 
2826  return prop;
2827 }
2828 
2829 
2830 
2831 
2832 
2835 //
2836 // Compilers
2837 //
2840 
2841 #ifndef DRMTL_NO_MTL_COMPILER
2842 typedef struct
2843 {
2845  const char* pData;
2846 
2848  unsigned int dataSizeInBytes;
2849 
2851  const char* pDataCur;
2852 
2854  const char* pDataEnd;
2855 
2856 
2858  float diffuse[3];
2859 
2861  char diffuseMap[DRMTL_MAX_INPUT_PATH];
2862 
2863 
2865  float specular[3];
2866 
2868  char specularMap[DRMTL_MAX_INPUT_PATH];
2869 
2870 
2872  float specularExponent;
2873 
2875  char specularExponentMap[DRMTL_MAX_INPUT_PATH];
2876 
2877 
2879  float alpha;
2880 
2882  char alphaMap[DRMTL_MAX_INPUT_PATH];
2883 
2884 
2885 } drmtl_wavefront;
2886 
2887 bool drmtl_wavefront_is_whitespace(char c)
2888 {
2889  return c == ' ' || c == '\t';
2890 }
2891 
2892 bool drmtl_wavefront_is_valid_digit(char c)
2893 {
2894  return c >= '0' && c <= '9';
2895 }
2896 
2897 bool drmtl_wavefront_atof(const char* str, const char* strEnd, const char** strEndOut, float* valueOut)
2898 {
2899  // Skip leading whitespace.
2900  while (str < strEnd && drmtl_wavefront_is_whitespace(*str))
2901  {
2902  str += 1;
2903  }
2904 
2905 
2906  // Check that we have a string after moving the whitespace.
2907  if (str < strEnd)
2908  {
2909  float sign = 1.0f;
2910  float value = 0.0f;
2911 
2912  // Sign.
2913  if (*str == '-')
2914  {
2915  sign = -1.0f;
2916  str += 1;
2917  }
2918  else if (*str == '+')
2919  {
2920  sign = 1.0f;
2921  str += 1;
2922  }
2923 
2924 
2925  // Digits before the decimal point.
2926  while (str < strEnd && drmtl_wavefront_is_valid_digit(*str))
2927  {
2928  value = value * 10.0f + (*str - '0');
2929 
2930  str += 1;
2931  }
2932 
2933  // Digits after the decimal point.
2934  if (*str == '.')
2935  {
2936  float pow10 = 10.0f;
2937 
2938  str += 1;
2939  while (str < strEnd && drmtl_wavefront_is_valid_digit(*str))
2940  {
2941  value += (*str - '0') / pow10;
2942  pow10 *= 10.0f;
2943 
2944  str += 1;
2945  }
2946  }
2947 
2948 
2949  if (strEndOut != NULL)
2950  {
2951  *strEndOut = str;
2952  }
2953 
2954  if (valueOut != NULL)
2955  {
2956  *valueOut = sign * value;
2957  }
2958 
2959  return 1;
2960  }
2961  else
2962  {
2963  // Empty string. Leave output untouched and return 0.
2964  return 0;
2965  }
2966 }
2967 
2968 bool drmtl_wavefront_atof_3(const char* str, const char* strEnd, const char** strEndOut, float valueOut[3])
2969 {
2970  float value[3];
2971  if (drmtl_wavefront_atof(str, strEnd, &str, &value[0]))
2972  {
2973  value[1] = value[0];
2974  value[2] = value[0];
2975 
2976  if (drmtl_wavefront_atof(str, strEnd, &str, &value[1]))
2977  {
2978  // We got two numbers which means we must have the third for this to be successful.
2979  if (!drmtl_wavefront_atof(str, strEnd, strEndOut, &value[2]))
2980  {
2981  // Failed to get the third number. We only found 2 which is not valid. Error.
2982  return 0;
2983  }
2984  }
2985 
2986 
2987  valueOut[0] = value[0];
2988  valueOut[1] = value[1];
2989  valueOut[2] = value[2];
2990 
2991  return 1;
2992  }
2993 
2994  return 0;
2995 }
2996 
2997 const char* drmtl_wavefront_find_end_of_line(const char* pDataCur, const char* pDataEnd)
2998 {
2999  assert(pDataCur != NULL);
3000  assert(pDataEnd != NULL);
3001 
3002  while (pDataCur < pDataEnd)
3003  {
3004  if (pDataCur[0] == '\n')
3005  {
3006  return pDataCur;
3007  }
3008  else
3009  {
3010  if (pDataCur + 1 < pDataEnd)
3011  {
3012  if (pDataCur[0] == '\r' && pDataCur[1] == '\n')
3013  {
3014  return pDataCur;
3015  }
3016  }
3017  }
3018 
3019  pDataCur += 1;
3020  }
3021 
3022  // If we get here it means we hit the end of the file before find a new-line character.
3023  return pDataEnd;
3024 }
3025 
3026 const char* drmtl_wavefront_find_next_line(const char* pDataCur, const char* pDataEnd)
3027 {
3028  assert(pDataCur != NULL);
3029  assert(pDataEnd != NULL);
3030 
3031  pDataCur = drmtl_wavefront_find_end_of_line(pDataCur, pDataEnd);
3032  if (pDataCur != NULL)
3033  {
3034  if (pDataCur < pDataEnd)
3035  {
3036  if (pDataCur[0] == '\n')
3037  {
3038  return pDataCur + 1;
3039  }
3040  else
3041  {
3042  if (pDataCur + 1 < pDataEnd)
3043  {
3044  if (pDataCur[0] == '\r' && pDataCur[1] == '\n')
3045  {
3046  return pDataCur + 2;
3047  }
3048  }
3049  }
3050  }
3051  }
3052 
3053  return NULL;
3054 }
3055 
3056 const char* drmtl_wavefront_find_next_newmtl(const char* pDataCur, const char* pDataEnd)
3057 {
3058  assert(pDataCur != NULL);
3059  assert(pDataEnd != NULL);
3060 
3061  while (pDataCur + 7 < pDataEnd) // +7 for "newmtl" + a whitespace character.
3062  {
3063  if (pDataCur[0] == 'n' && pDataCur[1] == 'e' && pDataCur[2] == 'w' && pDataCur[3] == 'm' && pDataCur[4] == 't' && pDataCur[5] == 'l')
3064  {
3065  // We found "newmtl", however the next line must be whitespace.
3066  if (drmtl_wavefront_is_whitespace(pDataCur[6]))
3067  {
3068  // We found it.
3069  return pDataCur;
3070  }
3071  }
3072 
3073 
3074  const char* nextLineStart = drmtl_wavefront_find_next_line(pDataCur, pDataEnd);
3075  if (nextLineStart != NULL)
3076  {
3077  pDataCur = nextLineStart;
3078  }
3079  else
3080  {
3081  // Reached the end before finding "newmtl". Return null.
3082  return NULL;
3083  }
3084  }
3085 
3086  return NULL;
3087 }
3088 
3089 const char* drmtl_wavefront_find_next_nonwhitespace(const char* pDataCur, const char* pDataEnd)
3090 {
3091  assert(pDataCur != NULL);
3092  assert(pDataEnd != NULL);
3093 
3094  while (pDataCur < pDataEnd)
3095  {
3096  if (!drmtl_wavefront_is_whitespace(pDataCur[0]))
3097  {
3098  return pDataCur;
3099  }
3100 
3101  pDataCur += 1;
3102  }
3103 
3104  return NULL;
3105 }
3106 
3107 
3108 bool drmtl_wavefront_parse_K(const char* pDataCur, const char* pDataEnd, float valueOut[3])
3109 {
3110  assert(pDataCur != NULL);
3111  assert(pDataEnd != NULL);
3112 
3113  return drmtl_wavefront_atof_3(pDataCur, pDataEnd, &pDataEnd, valueOut);
3114 }
3115 
3116 bool drmtl_wavefront_parse_N(const char* pDataCur, const char* pDataEnd, float* valueOut)
3117 {
3118  assert(pDataCur != NULL);
3119  assert(pDataEnd != NULL);
3120 
3121  return drmtl_wavefront_atof(pDataCur, pDataEnd, &pDataEnd, valueOut);
3122 }
3123 
3124 bool drmtl_wavefront_parse_map(const char* pDataCur, const char* pDataEnd, char* pathOut, unsigned int pathSizeInBytes)
3125 {
3126  assert(pDataCur != NULL);
3127  assert(pDataEnd != NULL);
3128 
3129  // For now we're not supporting options, however support for that will be added later.
3130 
3131  const char* pPathStart = drmtl_wavefront_find_next_nonwhitespace(pDataCur, pDataEnd);
3132  if (pPathStart != NULL)
3133  {
3134  if (pPathStart < pDataEnd)
3135  {
3136  if (pPathStart[0] != '#')
3137  {
3138  // Find the last non-whitespace, making sure we don't include comments.
3139  pDataCur = pPathStart;
3140  const char* pPathEnd = pDataCur;
3141  while (pDataCur < pDataEnd && pDataCur[0] != '#')
3142  {
3143  if (!drmtl_wavefront_is_whitespace(pDataCur[0]))
3144  {
3145  pPathEnd = pDataCur + 1;
3146  }
3147 
3148  pDataCur += 1;
3149  }
3150 
3151  assert(pPathStart < pPathEnd);
3152 
3153  ptrdiff_t pathLength = pPathEnd - pPathStart;
3154  if ((size_t)pathLength + 1 < pathSizeInBytes)
3155  {
3156  memcpy(pathOut, pPathStart, (size_t)pathLength);
3157  pathOut[pathLength] = '\0';
3158 
3159  return 1;
3160  }
3161  }
3162  }
3163  }
3164 
3165  return 0;
3166 }
3167 
3168 
3169 bool drmtl_wavefront_seek_to_next_line(drmtl_wavefront* pWavefront)
3170 {
3171  assert(pWavefront != NULL);
3172 
3173  const char* lineStart = drmtl_wavefront_find_next_line(pWavefront->pDataCur, pWavefront->pDataEnd);
3174  if (lineStart != NULL)
3175  {
3176  pWavefront->pDataCur = lineStart;
3177  return 1;
3178  }
3179 
3180  return 0;
3181 }
3182 
3183 bool drmtl_wavefront_seek_to_newmtl(drmtl_wavefront* pWavefront)
3184 {
3185  assert(pWavefront != NULL);
3186 
3187  const char* usemtl = drmtl_wavefront_find_next_newmtl(pWavefront->pDataCur, pWavefront->pDataEnd);
3188  if (usemtl != NULL)
3189  {
3190  pWavefront->pDataCur = usemtl;
3191  return 1;
3192  }
3193 
3194  return 0;
3195 }
3196 
3197 bool drmtl_wavefront_parse(drmtl_wavefront* pWavefront)
3198 {
3199  assert(pWavefront != NULL);
3200 
3201  if (drmtl_wavefront_seek_to_newmtl(pWavefront) && drmtl_wavefront_seek_to_next_line(pWavefront))
3202  {
3203  // Set the end of the material to the start of the second usemtl statement, if it exists.
3204  const char* usemtl2 = drmtl_wavefront_find_next_newmtl(pWavefront->pDataCur, pWavefront->pDataEnd);
3205  if (usemtl2 != NULL)
3206  {
3207  pWavefront->pDataEnd = usemtl2;
3208  }
3209 
3210 
3211  while (pWavefront->pDataCur < pWavefront->pDataEnd)
3212  {
3213  const char* lineCur = pWavefront->pDataCur;
3214  const char* lineEnd = drmtl_wavefront_find_end_of_line(lineCur, pWavefront->pDataEnd);
3215 
3216  lineCur = drmtl_wavefront_find_next_nonwhitespace(lineCur, lineEnd);
3217  if (lineCur != NULL && (lineCur + 2 < lineEnd))
3218  {
3219  if (lineCur[0] == 'K' && lineCur[1] == 'd' && drmtl_wavefront_is_whitespace(lineCur[2])) // Diffuse colour
3220  {
3221  lineCur += 3;
3222  drmtl_wavefront_parse_K(lineCur, lineEnd, pWavefront->diffuse);
3223  }
3224  else if (lineCur[0] == 'K' && lineCur[1] == 's' && drmtl_wavefront_is_whitespace(lineCur[2])) // Specular colour
3225  {
3226  lineCur += 3;
3227  drmtl_wavefront_parse_K(lineCur, lineEnd, pWavefront->specular);
3228  }
3229  else if (lineCur[0] == 'N' && lineCur[1] == 's' && drmtl_wavefront_is_whitespace(lineCur[2])) // Specular exponent
3230  {
3231  lineCur += 3;
3232  drmtl_wavefront_parse_N(lineCur, lineEnd, &pWavefront->specularExponent);
3233  }
3234  else if (lineCur[0] == 'd' && drmtl_wavefront_is_whitespace(lineCur[1])) // Opacity/Alpha
3235  {
3236  lineCur += 2;
3237  drmtl_wavefront_parse_N(lineCur, lineEnd, &pWavefront->alpha);
3238  }
3239  else
3240  {
3241  // Check for maps.
3242  if (lineCur + 6 < lineEnd)
3243  {
3244  if (lineCur[0] == 'm' && lineCur[1] == 'a' && lineCur[2] == 'p' && lineCur[3] == '_')
3245  {
3246  if (lineCur[4] == 'K' && lineCur[5] == 'd' && drmtl_wavefront_is_whitespace(lineCur[6])) // Diffuse map
3247  {
3248  lineCur += 7;
3249  drmtl_wavefront_parse_map(lineCur, lineEnd, pWavefront->diffuseMap, DRMTL_MAX_INPUT_PATH);
3250  }
3251  else if (lineCur[4] == 'K' && lineCur[5] == 's' && drmtl_wavefront_is_whitespace(lineCur[6])) // Specular map
3252  {
3253  lineCur += 7;
3254  drmtl_wavefront_parse_map(lineCur, lineEnd, pWavefront->specularMap, DRMTL_MAX_INPUT_PATH);
3255  }
3256  else if (lineCur[4] == 'N' && lineCur[5] == 's' && drmtl_wavefront_is_whitespace(lineCur[6])) // Specular exponent map
3257  {
3258  lineCur += 7;
3259  drmtl_wavefront_parse_map(lineCur, lineEnd, pWavefront->specularExponentMap, DRMTL_MAX_INPUT_PATH);
3260  }
3261  else if (lineCur[4] == 'd' && drmtl_wavefront_is_whitespace(lineCur[5])) // Opacity/Alpha map
3262  {
3263  lineCur += 6;
3264  drmtl_wavefront_parse_map(lineCur, lineEnd, pWavefront->alphaMap, DRMTL_MAX_INPUT_PATH);
3265  }
3266  }
3267  }
3268  }
3269  }
3270 
3271 
3272  // Move to the end of the line.
3273  pWavefront->pDataCur = lineEnd;
3274 
3275  // Move to the start of the next line. If this fails it probably means we've reached the end of the data so we just break from the loop
3276  if (!drmtl_wavefront_seek_to_next_line(pWavefront))
3277  {
3278  break;
3279  }
3280  }
3281 
3282 
3283  return 1;
3284  }
3285 
3286  return 0;
3287 }
3288 
3289 bool drmtl_wavefront_compile(drmtl_material* pMaterial, drmtl_wavefront* pWavefront, const char* texcoordInputName)
3290 {
3291  assert(pMaterial != NULL);
3292  assert(pWavefront != NULL);
3293 
3294  unsigned int texCoordID; // Private input for texture coordinates.
3295  unsigned int diffuseID;
3296  unsigned int specularID;
3297  unsigned int specularExponentID;
3298  unsigned int alphaID;
3299  unsigned int diffuseMapID = (unsigned int)-1;
3300  unsigned int specularMapID = (unsigned int)-1;
3301  unsigned int specularExponentMapID = (unsigned int)-1;
3302  unsigned int alphaMapID = (unsigned int)-1;
3303  unsigned int diffuseResultID = (unsigned int)-1;
3304  unsigned int specularResultID = (unsigned int)-1;
3305  unsigned int specularExponentResultID = (unsigned int)-1;
3306  unsigned int alphaResultID = (unsigned int)-1;
3307 
3308 
3309  // Identifiers.
3310  drmtl_appendidentifier(pMaterial, drmtl_identifier_float2(texcoordInputName), &texCoordID);
3311  drmtl_appendidentifier(pMaterial, drmtl_identifier_float4("DiffuseColor"), &diffuseID);
3312  drmtl_appendidentifier(pMaterial, drmtl_identifier_float3("SpecularColor"), &specularID);
3313  drmtl_appendidentifier(pMaterial, drmtl_identifier_float("SpecularExponent"), &specularExponentID);
3314  drmtl_appendidentifier(pMaterial, drmtl_identifier_float("Alpha"), &alphaID);
3315 
3316  if (pWavefront->diffuseMap[0] != '\0') {
3317  drmtl_appendidentifier(pMaterial, drmtl_identifier_tex2d("DiffuseMap"), &diffuseMapID);
3318  drmtl_appendidentifier(pMaterial, drmtl_identifier_float4("DiffuseResult"), &diffuseResultID);
3319  }
3320  if (pWavefront->specularMap[0] != '\0') {
3321  drmtl_appendidentifier(pMaterial, drmtl_identifier_tex2d("SpecularMap"), &specularMapID);
3322  drmtl_appendidentifier(pMaterial, drmtl_identifier_float4("SpecularResult"), &specularResultID);
3323  }
3324  if (pWavefront->specularExponentMap[0] != '\0') {
3325  drmtl_appendidentifier(pMaterial, drmtl_identifier_tex2d("SpecularExponentMap"), &specularExponentMapID);
3326  drmtl_appendidentifier(pMaterial, drmtl_identifier_float4("SpecularExponentResult"), &specularExponentResultID);
3327  }
3328  if (pWavefront->alphaMap[0] != '\0') {
3329  drmtl_appendidentifier(pMaterial, drmtl_identifier_tex2d("AlphaMap"), &alphaMapID);
3330  drmtl_appendidentifier(pMaterial, drmtl_identifier_float4("AlphaResult"), &alphaResultID);
3331  }
3332 
3333 
3334  // Inputs.
3335  drmtl_appendprivateinput(pMaterial, drmtl_input_float2(texCoordID, 0, 0));
3336  drmtl_appendpublicinput(pMaterial, drmtl_input_float4(diffuseID, pWavefront->diffuse[0], pWavefront->diffuse[1], pWavefront->diffuse[2], 1.0f));
3337  drmtl_appendpublicinput(pMaterial, drmtl_input_float3(specularID, pWavefront->specular[0], pWavefront->specular[1], pWavefront->specular[2]));
3338  drmtl_appendpublicinput(pMaterial, drmtl_input_float(specularExponentID, pWavefront->specularExponent));
3339  drmtl_appendpublicinput(pMaterial, drmtl_input_float(alphaID, pWavefront->alpha));
3340 
3341  if (pWavefront->diffuseMap[0] != '\0') {
3342  drmtl_appendpublicinput(pMaterial, drmtl_input_tex(diffuseMapID, pWavefront->diffuseMap));
3343  }
3344  if (pWavefront->specularMap[0] != '\0') {
3345  drmtl_appendpublicinput(pMaterial, drmtl_input_tex(specularMapID, pWavefront->specularMap));
3346  }
3347  if (pWavefront->specularExponentMap[0] != '\0') {
3348  drmtl_appendpublicinput(pMaterial, drmtl_input_tex(specularExponentMapID, pWavefront->specularExponentMap));
3349  }
3350  if (pWavefront->alphaMap[0] != '\0') {
3351  drmtl_appendpublicinput(pMaterial, drmtl_input_tex(alphaMapID, pWavefront->alphaMap));
3352  }
3353 
3354 
3355  // Channels.
3356  drmtl_appendchannel(pMaterial, drmtl_channel_float4("DiffuseChannel"));
3357  if (pWavefront->diffuseMap[0] != '\0') {
3358  drmtl_appendinstruction(pMaterial, drmtl_var(diffuseResultID));
3359  drmtl_appendinstruction(pMaterial, drmtl_tex2(diffuseResultID, diffuseMapID, texCoordID));
3360  drmtl_appendinstruction(pMaterial, drmtl_mulf4_v3c1(diffuseResultID, diffuseID, 1.0f));
3361  drmtl_appendinstruction(pMaterial, drmtl_retf4(diffuseResultID));
3362  } else {
3363  drmtl_appendinstruction(pMaterial, drmtl_retf4(diffuseID));
3364  }
3365 
3366  drmtl_appendchannel(pMaterial, drmtl_channel_float3("SpecularChannel"));
3367  if (pWavefront->specularMap[0] != '\0') {
3368  drmtl_appendinstruction(pMaterial, drmtl_var(specularResultID));
3369  drmtl_appendinstruction(pMaterial, drmtl_tex2(specularResultID, specularMapID, texCoordID));
3370  drmtl_appendinstruction(pMaterial, drmtl_mulf4_v3c1(specularResultID, specularID, 1.0f));
3371  drmtl_appendinstruction(pMaterial, drmtl_retf3(specularResultID));
3372  } else {
3373  drmtl_appendinstruction(pMaterial, drmtl_retf3(specularID));
3374  }
3375 
3376  drmtl_appendchannel(pMaterial, drmtl_channel_float("SpecularExponentChannel"));
3377  if (pWavefront->specularExponentMap[0] != '\0') {
3378  drmtl_appendinstruction(pMaterial, drmtl_var(specularExponentResultID));
3379  drmtl_appendinstruction(pMaterial, drmtl_tex2(specularResultID, specularMapID, texCoordID));
3380  drmtl_appendinstruction(pMaterial, drmtl_mulf4_v1c3(specularResultID, specularID, 1.0f, 1.0f, 1.0f));
3381  drmtl_appendinstruction(pMaterial, drmtl_retf1(specularResultID));
3382  } else {
3383  drmtl_appendinstruction(pMaterial, drmtl_retf1(specularExponentID));
3384  }
3385 
3386  drmtl_appendchannel(pMaterial, drmtl_channel_float("AlphaChannel"));
3387  if (pWavefront->alphaMap[0] != '\0') {
3388  drmtl_appendinstruction(pMaterial, drmtl_var(alphaResultID));
3389  drmtl_appendinstruction(pMaterial, drmtl_tex2(alphaResultID, alphaMapID, texCoordID));
3390  drmtl_appendinstruction(pMaterial, drmtl_mulf4_v1c3(alphaResultID, alphaID, 1.0f, 1.0f, 1.0f));
3391  drmtl_appendinstruction(pMaterial, drmtl_retf1(alphaResultID));
3392  } else {
3393  drmtl_appendinstruction(pMaterial, drmtl_retf1(alphaID));
3394  }
3395 
3396 
3397 
3398  // Properties.
3399  if (pWavefront->alphaMap[0] != '\0' || pWavefront->alpha < 1)
3400  {
3401  drmtl_appendproperty(pMaterial, drmtl_property_bool("IsTransparent", 1));
3402  }
3403 
3404  return 1;
3405 }
3406 
3407 
3408 bool drmtl_compile_wavefront_mtl(drmtl_material* pMaterial, const char* mtlData, size_t mtlDataSizeInBytes, const char* texcoordInputName)
3409 {
3410  if (pMaterial != NULL && mtlData != NULL && mtlDataSizeInBytes > 0)
3411  {
3412  if (drmtl_init(pMaterial))
3413  {
3414  drmtl_wavefront wavefront;
3415  wavefront.pData = mtlData;
3416  wavefront.dataSizeInBytes = mtlDataSizeInBytes;
3417  wavefront.pDataCur = wavefront.pData;
3418  wavefront.pDataEnd = wavefront.pData + wavefront.dataSizeInBytes;
3419  wavefront.diffuse[0] = 1; wavefront.diffuse[1] = 1; wavefront.diffuse[2] = 1;
3420  wavefront.diffuseMap[0] = '\0';
3421  wavefront.specular[0] = 1; wavefront.specular[1] = 1; wavefront.specular[2] = 1;
3422  wavefront.specularMap[0] = '\0';
3423  wavefront.specularExponent = 10;
3424  wavefront.specularExponentMap[0] = '\0';
3425  wavefront.alpha = 1;
3426  wavefront.alphaMap[0] = '\0';
3427 
3428  if (drmtl_wavefront_parse(&wavefront))
3429  {
3430  if (drmtl_wavefront_compile(pMaterial, &wavefront, texcoordInputName))
3431  {
3432  return 1;
3433  }
3434  else
3435  {
3436  // Failed to compile.
3437  drmtl_uninit(pMaterial);
3438  }
3439  }
3440  else
3441  {
3442  // Failed to parse the file.
3443  drmtl_uninit(pMaterial);
3444  }
3445  }
3446  }
3447 
3448  return 0;
3449 }
3450 #endif
3451 
3452 
3453 
3454 
3457 //
3458 // Code Generators
3459 //
3462 
3463 #ifndef DRMTL_NO_GLSL_CODEGEN
3464 #include <stdio.h>
3465 
3466 #if defined(__clang__)
3467  #pragma GCC diagnostic push
3468  #pragma GCC diagnostic ignored "-Wswitch-enum"
3469  #pragma GCC diagnostic ignored "-Wcovered-switch-default"
3470  #pragma GCC diagnostic ignored "-Wused-but-marked-unused" // This ie emitted for snprintf() for some reason. Need to investigate...
3471 #endif
3472 
3473 typedef struct
3474 {
3476  char* pBufferOut;
3477 
3479  unsigned int bufferOutSizeInBytes;
3480 
3482  unsigned int runningLength;
3483 
3484 
3486  drmtl_material* pMaterial;
3487 
3489  drmtl_identifier* pIdentifiers;
3490 
3492  unsigned int identifierCount;
3493 
3494 
3496  unsigned int indentationLevel;
3497 
3498 } drmtl_codegen_glsl;
3499 
3500 bool drmtl_codegen_glsl_write(drmtl_codegen_glsl* pCodegen, const char* src)
3501 {
3502  assert(pCodegen != NULL);
3503  assert(src != NULL);
3504 
3505  if (pCodegen->pBufferOut != NULL)
3506  {
3507  unsigned int dstSizeInBytes = (pCodegen->bufferOutSizeInBytes - pCodegen->runningLength);
3508  while (dstSizeInBytes > 0 && src[0] != '\0')
3509  {
3510  pCodegen->pBufferOut[pCodegen->runningLength + 0] = src[0];
3511 
3512  pCodegen->runningLength += 1;
3513  src += 1;
3514  dstSizeInBytes -= 1;
3515  }
3516 
3517  if (dstSizeInBytes > 0)
3518  {
3519  // There's enough room for the null terminator which means there was enough room in the buffer. All good.
3520  pCodegen->pBufferOut[pCodegen->runningLength] = '\0';
3521  return 1;
3522  }
3523  else
3524  {
3525  // There's not enough room for the null terminator which means there was NOT enough room in the buffer. Error.
3526  return 0;
3527  }
3528  }
3529  else
3530  {
3531  // We're just measuring.
3532  pCodegen->runningLength += (unsigned int)strlen(src);
3533  return 1;
3534  }
3535 }
3536 
3537 bool drmtl_codegen_glsl_write_float(drmtl_codegen_glsl* pCodegen, float src)
3538 {
3539  assert(pCodegen != NULL);
3540 
3541  char str[32];
3542  if (snprintf(str, 32, "%f", src) > 0)
3543  {
3544  return drmtl_codegen_glsl_write(pCodegen, str);
3545  }
3546  else
3547  {
3548  return 0;
3549  }
3550 }
3551 
3552 bool drmtl_codegen_glsl_write_int(drmtl_codegen_glsl* pCodegen, int src)
3553 {
3554  assert(pCodegen != NULL);
3555 
3556  char str[32];
3557  if (snprintf(str, 32, "%d", src) > 0)
3558  {
3559  return drmtl_codegen_glsl_write(pCodegen, str);
3560  }
3561  else
3562  {
3563  return 0;
3564  }
3565 }
3566 
3567 bool drmtl_codegen_glsl_write_indentation(drmtl_codegen_glsl* pCodegen)
3568 {
3569  assert(pCodegen != NULL);
3570 
3571  for (unsigned int i = 0; i < pCodegen->indentationLevel; ++i)
3572  {
3573  drmtl_codegen_glsl_write(pCodegen, " ");
3574  }
3575 
3576  return 1;
3577 }
3578 
3579 bool drmtl_codegen_glsl_write_type(drmtl_codegen_glsl* pCodegen, drmtl_type type)
3580 {
3581  assert(pCodegen != NULL);
3582 
3583  switch (type)
3584  {
3585  case drmtl_type_float:
3586  {
3587  if (!drmtl_codegen_glsl_write(pCodegen, "float"))
3588  {
3589  return 0;
3590  }
3591 
3592  break;
3593  }
3594  case drmtl_type_float2:
3595  {
3596  if (!drmtl_codegen_glsl_write(pCodegen, "vec2"))
3597  {
3598  return 0;
3599  }
3600 
3601  break;
3602  }
3603  case drmtl_type_float3:
3604  {
3605  if (!drmtl_codegen_glsl_write(pCodegen, "vec3"))
3606  {
3607  return 0;
3608  }
3609 
3610  break;
3611  }
3612  case drmtl_type_float4:
3613  {
3614  if (!drmtl_codegen_glsl_write(pCodegen, "vec4"))
3615  {
3616  return 0;
3617  }
3618 
3619  break;
3620  }
3621 
3622  case drmtl_type_int:
3623  {
3624  if (!drmtl_codegen_glsl_write(pCodegen, "int"))
3625  {
3626  return 0;
3627  }
3628 
3629  break;
3630  }
3631  case drmtl_type_int2:
3632  {
3633  if (!drmtl_codegen_glsl_write(pCodegen, "ivec2"))
3634  {
3635  return 0;
3636  }
3637 
3638  break;
3639  }
3640  case drmtl_type_int3:
3641  {
3642  if (!drmtl_codegen_glsl_write(pCodegen, "ivec3"))
3643  {
3644  return 0;
3645  }
3646 
3647  break;
3648  }
3649  case drmtl_type_int4:
3650  {
3651  if (!drmtl_codegen_glsl_write(pCodegen, "ivec4"))
3652  {
3653  return 0;
3654  }
3655 
3656  break;
3657  }
3658 
3659  case drmtl_type_tex1d:
3660  {
3661  if (!drmtl_codegen_glsl_write(pCodegen, "sampler1D"))
3662  {
3663  return 0;
3664  }
3665 
3666  break;
3667  }
3668  case drmtl_type_tex2d:
3669  {
3670  if (!drmtl_codegen_glsl_write(pCodegen, "sampler2D"))
3671  {
3672  return 0;
3673  }
3674 
3675  break;
3676  }
3677  case drmtl_type_tex3d:
3678  {
3679  if (!drmtl_codegen_glsl_write(pCodegen, "sampler3D"))
3680  {
3681  return 0;
3682  }
3683 
3684  break;
3685  }
3686  case drmtl_type_texcube:
3687  {
3688  if (!drmtl_codegen_glsl_write(pCodegen, "samplerCube"))
3689  {
3690  return 0;
3691  }
3692 
3693  break;
3694  }
3695 
3696  default:
3697  {
3698  // Unsupported return type.
3699  return 0;
3700  }
3701  }
3702 
3703  return 1;
3704 }
3705 
3706 bool drmtl_codegen_glsl_write_instruction_input_scalar(drmtl_codegen_glsl* pCodegen, unsigned char descriptor, drmtl_instruction_input* pInput)
3707 {
3708  assert(pCodegen != NULL);
3709  assert(pInput != NULL);
3710 
3711  if (descriptor == DRMTL_INPUT_DESC_CONSTF)
3712  {
3713  // It's a constant float.
3714  return drmtl_codegen_glsl_write_float(pCodegen, pInput->valuef);
3715  }
3716  else if (descriptor == DRMTL_INPUT_DESC_CONSTI)
3717  {
3718  // It's a constant int.
3719  return drmtl_codegen_glsl_write_int(pCodegen, pInput->valuei);
3720  }
3721  else
3722  {
3723  // It's a variable.
3724  if (pInput->id < pCodegen->identifierCount)
3725  {
3726  drmtl_identifier* pIdentifier = pCodegen->pIdentifiers + pInput->id;
3727  assert(pIdentifier != NULL);
3728 
3729  if (pIdentifier->type == drmtl_type_float)
3730  {
3731  // The input variable is a float, so we don't want to use any selectors.
3732  return drmtl_codegen_glsl_write(pCodegen, pIdentifier->name);
3733  }
3734  else
3735  {
3736  if (drmtl_codegen_glsl_write(pCodegen, pIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, "."))
3737  {
3738  switch (descriptor)
3739  {
3740  case 0: return drmtl_codegen_glsl_write(pCodegen, "x");
3741  case 1: return drmtl_codegen_glsl_write(pCodegen, "y");
3742  case 2: return drmtl_codegen_glsl_write(pCodegen, "z");
3743  case 3: return drmtl_codegen_glsl_write(pCodegen, "w");
3744  default: return 0;
3745  }
3746  }
3747  }
3748  }
3749  }
3750 
3751  return 0;
3752 }
3753 
3754 bool drmtl_codegen_glsl_write_instruction_input_initializer(drmtl_codegen_glsl* pCodegen, drmtl_type type, drmtl_instruction_input_descriptor inputDesc, drmtl_instruction_input* pInputs)
3755 {
3756  assert(pCodegen != NULL);
3757  assert(pInputs != NULL);
3758 
3759  switch (type)
3760  {
3761  case drmtl_type_float:
3762  {
3763  return drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.x, pInputs + 0);
3764  }
3765 
3766  case drmtl_type_float2:
3767  {
3768  if (drmtl_codegen_glsl_write(pCodegen, "vec2("))
3769  {
3770  if (drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.x, pInputs + 0) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3771  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.y, pInputs + 1))
3772  {
3773  return drmtl_codegen_glsl_write(pCodegen, ")");
3774  }
3775  }
3776 
3777  break;
3778  }
3779 
3780  case drmtl_type_float3:
3781  {
3782  if (drmtl_codegen_glsl_write(pCodegen, "vec3("))
3783  {
3784  if (drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.x, pInputs + 0) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3785  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.y, pInputs + 1) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3786  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.z, pInputs + 2))
3787  {
3788  return drmtl_codegen_glsl_write(pCodegen, ")");
3789  }
3790  }
3791 
3792  break;
3793  }
3794 
3795  case drmtl_type_float4:
3796  {
3797  if (drmtl_codegen_glsl_write(pCodegen, "vec4("))
3798  {
3799  if (drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.x, pInputs + 0) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3800  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.y, pInputs + 1) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3801  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.z, pInputs + 2) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3802  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.w, pInputs + 3))
3803  {
3804  return drmtl_codegen_glsl_write(pCodegen, ")");
3805  }
3806  }
3807 
3808  break;
3809  }
3810 
3811 
3812  case drmtl_type_int:
3813  {
3814  return drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.x, pInputs + 0);
3815  }
3816 
3817  case drmtl_type_int2:
3818  {
3819  if (drmtl_codegen_glsl_write(pCodegen, "ivec2("))
3820  {
3821  if (drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.x, pInputs + 0) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3822  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.y, pInputs + 1))
3823  {
3824  return drmtl_codegen_glsl_write(pCodegen, ")");
3825  }
3826  }
3827 
3828  break;
3829  }
3830 
3831  case drmtl_type_int3:
3832  {
3833  if (drmtl_codegen_glsl_write(pCodegen, "ivec3("))
3834  {
3835  if (drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.x, pInputs + 0) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3836  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.y, pInputs + 1) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3837  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.z, pInputs + 2))
3838  {
3839  return drmtl_codegen_glsl_write(pCodegen, ")");
3840  }
3841  }
3842 
3843  break;
3844  }
3845 
3846  case drmtl_type_int4:
3847  {
3848  if (drmtl_codegen_glsl_write(pCodegen, "ivec4("))
3849  {
3850  if (drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.x, pInputs + 0) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3851  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.y, pInputs + 1) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3852  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.z, pInputs + 2) && drmtl_codegen_glsl_write(pCodegen, ", ") &&
3853  drmtl_codegen_glsl_write_instruction_input_scalar(pCodegen, inputDesc.w, pInputs + 3))
3854  {
3855  return drmtl_codegen_glsl_write(pCodegen, ")");
3856  }
3857  }
3858 
3859  break;
3860  }
3861 
3862 
3863  default:
3864  {
3865  // Unsupported return type.
3866  return 0;
3867  }
3868  }
3869 
3870  return 0;
3871 }
3872 
3873 
3874 bool drmtl_codegen_glsl_write_instruction_mov(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
3875 {
3876  assert(pCodegen != NULL);
3877  assert(pInstruction != NULL);
3878 
3879  if (pInstruction->mov.output < pCodegen->identifierCount)
3880  {
3881  drmtl_identifier* pOutputIdentifier = pCodegen->pIdentifiers + pInstruction->mov.output;
3882  assert(pOutputIdentifier != NULL);
3883 
3884  if (drmtl_codegen_glsl_write(pCodegen, pOutputIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, " = "))
3885  {
3886  drmtl_type type;
3887  switch (pInstruction->opcode)
3888  {
3889  case drmtl_opcode_movf1: type = drmtl_type_float; break;
3890  case drmtl_opcode_movf2: type = drmtl_type_float2; break;
3891  case drmtl_opcode_movf3: type = drmtl_type_float3; break;
3892  case drmtl_opcode_movf4: type = drmtl_type_float4; break;
3893  case drmtl_opcode_movi1: type = drmtl_type_int; break;
3894  case drmtl_opcode_movi2: type = drmtl_type_int2; break;
3895  case drmtl_opcode_movi3: type = drmtl_type_int3; break;
3896  case drmtl_opcode_movi4: type = drmtl_type_int4; break;
3897  default: return 0;
3898  }
3899 
3900  return drmtl_codegen_glsl_write_instruction_input_initializer(pCodegen, type, pInstruction->mov.inputDesc, &pInstruction->mov.inputX) && drmtl_codegen_glsl_write(pCodegen, ";\n");
3901  }
3902  }
3903 
3904  return 0;
3905 }
3906 
3907 bool drmtl_codegen_glsl_write_instruction_add(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
3908 {
3909  assert(pCodegen != NULL);
3910  assert(pInstruction != NULL);
3911 
3912  if (pInstruction->add.output < pCodegen->identifierCount)
3913  {
3914  drmtl_identifier* pOutputIdentifier = pCodegen->pIdentifiers + pInstruction->add.output;
3915  assert(pOutputIdentifier != NULL);
3916 
3917  if (drmtl_codegen_glsl_write(pCodegen, pOutputIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, " += "))
3918  {
3919  drmtl_type type;
3920  switch (pInstruction->opcode)
3921  {
3922  case drmtl_opcode_addf1: type = drmtl_type_float; break;
3923  case drmtl_opcode_addf2: type = drmtl_type_float2; break;
3924  case drmtl_opcode_addf3: type = drmtl_type_float3; break;
3925  case drmtl_opcode_addf4: type = drmtl_type_float4; break;
3926  case drmtl_opcode_addi1: type = drmtl_type_int; break;
3927  case drmtl_opcode_addi2: type = drmtl_type_int2; break;
3928  case drmtl_opcode_addi3: type = drmtl_type_int3; break;
3929  case drmtl_opcode_addi4: type = drmtl_type_int4; break;
3930  default: return 0;
3931  }
3932 
3933  return drmtl_codegen_glsl_write_instruction_input_initializer(pCodegen, type, pInstruction->add.inputDesc, &pInstruction->add.inputX) && drmtl_codegen_glsl_write(pCodegen, ";\n");
3934  }
3935  }
3936 
3937  return 0;
3938 }
3939 
3940 bool drmtl_codegen_glsl_write_instruction_sub(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
3941 {
3942  assert(pCodegen != NULL);
3943  assert(pInstruction != NULL);
3944 
3945  if (pInstruction->add.output < pCodegen->identifierCount)
3946  {
3947  drmtl_identifier* pOutputIdentifier = pCodegen->pIdentifiers + pInstruction->sub.output;
3948  assert(pOutputIdentifier != NULL);
3949 
3950  if (drmtl_codegen_glsl_write(pCodegen, pOutputIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, " -= "))
3951  {
3952  drmtl_type type;
3953  switch (pInstruction->opcode)
3954  {
3955  case drmtl_opcode_subf1: type = drmtl_type_float; break;
3956  case drmtl_opcode_subf2: type = drmtl_type_float2; break;
3957  case drmtl_opcode_subf3: type = drmtl_type_float3; break;
3958  case drmtl_opcode_subf4: type = drmtl_type_float4; break;
3959  case drmtl_opcode_subi1: type = drmtl_type_int; break;
3960  case drmtl_opcode_subi2: type = drmtl_type_int2; break;
3961  case drmtl_opcode_subi3: type = drmtl_type_int3; break;
3962  case drmtl_opcode_subi4: type = drmtl_type_int4; break;
3963  default: return 0;
3964  }
3965 
3966  return drmtl_codegen_glsl_write_instruction_input_initializer(pCodegen, type, pInstruction->sub.inputDesc, &pInstruction->sub.inputX) && drmtl_codegen_glsl_write(pCodegen, ";\n");
3967  }
3968  }
3969 
3970  return 0;
3971 }
3972 
3973 bool drmtl_codegen_glsl_write_instruction_mul(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
3974 {
3975  assert(pCodegen != NULL);
3976  assert(pInstruction != NULL);
3977 
3978  if (pInstruction->mul.output < pCodegen->identifierCount)
3979  {
3980  drmtl_identifier* pOutputIdentifier = pCodegen->pIdentifiers + pInstruction->mul.output;
3981  assert(pOutputIdentifier != NULL);
3982 
3983  if (drmtl_codegen_glsl_write(pCodegen, pOutputIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, " *= "))
3984  {
3985  drmtl_type type;
3986  switch (pInstruction->opcode)
3987  {
3988  case drmtl_opcode_mulf1: type = drmtl_type_float; break;
3989  case drmtl_opcode_mulf2: type = drmtl_type_float2; break;
3990  case drmtl_opcode_mulf3: type = drmtl_type_float3; break;
3991  case drmtl_opcode_mulf4: type = drmtl_type_float4; break;
3992  case drmtl_opcode_muli1: type = drmtl_type_int; break;
3993  case drmtl_opcode_muli2: type = drmtl_type_int2; break;
3994  case drmtl_opcode_muli3: type = drmtl_type_int3; break;
3995  case drmtl_opcode_muli4: type = drmtl_type_int4; break;
3996  default: return 0;
3997  }
3998 
3999  return drmtl_codegen_glsl_write_instruction_input_initializer(pCodegen, type, pInstruction->mul.inputDesc, &pInstruction->mul.inputX) && drmtl_codegen_glsl_write(pCodegen, ";\n");
4000  }
4001  }
4002 
4003  return 0;
4004 }
4005 
4006 bool drmtl_codegen_glsl_write_instruction_div(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
4007 {
4008  assert(pCodegen != NULL);
4009  assert(pInstruction != NULL);
4010 
4011  if (pInstruction->div.output < pCodegen->identifierCount)
4012  {
4013  drmtl_identifier* pOutputIdentifier = pCodegen->pIdentifiers + pInstruction->div.output;
4014  assert(pOutputIdentifier != NULL);
4015 
4016  if (drmtl_codegen_glsl_write(pCodegen, pOutputIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, " = "))
4017  {
4018  drmtl_type type;
4019  switch (pInstruction->opcode)
4020  {
4021  case drmtl_opcode_divf1: type = drmtl_type_float; break;
4022  case drmtl_opcode_divf2: type = drmtl_type_float2; break;
4023  case drmtl_opcode_divf3: type = drmtl_type_float3; break;
4024  case drmtl_opcode_divf4: type = drmtl_type_float4; break;
4025  case drmtl_opcode_divi1: type = drmtl_type_int; break;
4026  case drmtl_opcode_divi2: type = drmtl_type_int2; break;
4027  case drmtl_opcode_divi3: type = drmtl_type_int3; break;
4028  case drmtl_opcode_divi4: type = drmtl_type_int4; break;
4029  default: return 0;
4030  }
4031 
4032  return drmtl_codegen_glsl_write_instruction_input_initializer(pCodegen, type, pInstruction->div.inputDesc, &pInstruction->div.inputX) && drmtl_codegen_glsl_write(pCodegen, ";\n");
4033  }
4034  }
4035 
4036  return 0;
4037 }
4038 
4039 bool drmtl_codegen_glsl_write_instruction_pow(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
4040 {
4041  assert(pCodegen != NULL);
4042  assert(pInstruction != NULL);
4043 
4044  if (pInstruction->pow.output < pCodegen->identifierCount)
4045  {
4046  drmtl_identifier* pOutputIdentifier = pCodegen->pIdentifiers + pInstruction->pow.output;
4047  assert(pOutputIdentifier != NULL);
4048 
4049  if (drmtl_codegen_glsl_write(pCodegen, pOutputIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, " = pow(") && drmtl_codegen_glsl_write(pCodegen, pOutputIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, ", "))
4050  {
4051  drmtl_type type;
4052  switch (pInstruction->opcode)
4053  {
4054  case drmtl_opcode_powf1: type = drmtl_type_float; break;
4055  case drmtl_opcode_powf2: type = drmtl_type_float2; break;
4056  case drmtl_opcode_powf3: type = drmtl_type_float3; break;
4057  case drmtl_opcode_powf4: type = drmtl_type_float4; break;
4058  case drmtl_opcode_powi1: type = drmtl_type_int; break;
4059  case drmtl_opcode_powi2: type = drmtl_type_int2; break;
4060  case drmtl_opcode_powi3: type = drmtl_type_int3; break;
4061  case drmtl_opcode_powi4: type = drmtl_type_int4; break;
4062  default: return 0;
4063  }
4064 
4065  return drmtl_codegen_glsl_write_instruction_input_initializer(pCodegen, type, pInstruction->pow.inputDesc, &pInstruction->pow.inputX) && drmtl_codegen_glsl_write(pCodegen, ");\n");
4066  }
4067  }
4068 
4069  return 0;
4070 }
4071 
4072 bool drmtl_codegen_glsl_write_instruction_tex(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
4073 {
4074  assert(pCodegen != NULL);
4075  assert(pInstruction != NULL);
4076 
4077  if (pInstruction->tex.output < pCodegen->identifierCount && pInstruction->tex.texture < pCodegen->identifierCount)
4078  {
4079  drmtl_identifier* pOutputIdentifier = pCodegen->pIdentifiers + pInstruction->tex.output;
4080  assert(pOutputIdentifier != NULL);
4081 
4082  drmtl_identifier* pTextureIdentifier = pCodegen->pIdentifiers + pInstruction->tex.texture;
4083  assert(pTextureIdentifier != NULL);
4084 
4085  if (drmtl_codegen_glsl_write(pCodegen, pOutputIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, " = "))
4086  {
4087  drmtl_type type;
4088  switch (pInstruction->opcode)
4089  {
4090  case drmtl_opcode_tex1:
4091  {
4092  type = drmtl_type_float;
4093  if (!drmtl_codegen_glsl_write(pCodegen, "texture1D("))
4094  {
4095  return 0;
4096  }
4097 
4098  break;
4099  }
4100 
4101  case drmtl_opcode_tex2:
4102  {
4103  type = drmtl_type_float2;
4104  if (!drmtl_codegen_glsl_write(pCodegen, "texture2D("))
4105  {
4106  return 0;
4107  }
4108 
4109  break;
4110  }
4111 
4112  case drmtl_opcode_tex3:
4113  {
4114  type = drmtl_type_float3;
4115  if (!drmtl_codegen_glsl_write(pCodegen, "texture3D("))
4116  {
4117  return 0;
4118  }
4119 
4120  break;
4121  }
4122 
4123  case drmtl_opcode_texcube:
4124  {
4125  type = drmtl_type_float3;
4126  if (!drmtl_codegen_glsl_write(pCodegen, "textureCube("))
4127  {
4128  return 0;
4129  }
4130 
4131  break;
4132  }
4133 
4134  default: return 0;
4135  }
4136 
4137  return
4138  drmtl_codegen_glsl_write(pCodegen, pTextureIdentifier->name) &&
4139  drmtl_codegen_glsl_write(pCodegen, ", ") &&
4140  drmtl_codegen_glsl_write_instruction_input_initializer(pCodegen, type, pInstruction->tex.inputDesc, &pInstruction->tex.inputX) &&
4141  drmtl_codegen_glsl_write(pCodegen, ");\n");
4142  }
4143  }
4144 
4145  return 0;
4146 }
4147 
4148 bool drmtl_codegen_glsl_write_instruction_var(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
4149 {
4150  assert(pCodegen != NULL);
4151  assert(pInstruction != NULL);
4152 
4153  if (pInstruction->var.identifierIndex < pCodegen->identifierCount)
4154  {
4155  drmtl_identifier* pIdentifier = pCodegen->pIdentifiers + pInstruction->var.identifierIndex;
4156  assert(pIdentifier != NULL);
4157 
4158  return drmtl_codegen_glsl_write_type(pCodegen, pIdentifier->type) && drmtl_codegen_glsl_write(pCodegen, " ") && drmtl_codegen_glsl_write(pCodegen, pIdentifier->name) && drmtl_codegen_glsl_write(pCodegen, ";\n");
4159  }
4160 
4161  return 0;
4162 }
4163 
4164 bool drmtl_codegen_glsl_write_instruction_ret(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
4165 {
4166  assert(pCodegen != NULL);
4167  assert(pInstruction != NULL);
4168 
4169  if (drmtl_codegen_glsl_write(pCodegen, "return "))
4170  {
4171  drmtl_type type;
4172  switch (pInstruction->opcode)
4173  {
4174  case drmtl_opcode_retf1: type = drmtl_type_float; break;
4175  case drmtl_opcode_retf2: type = drmtl_type_float2; break;
4176  case drmtl_opcode_retf3: type = drmtl_type_float3; break;
4177  case drmtl_opcode_retf4: type = drmtl_type_float4; break;
4178  case drmtl_opcode_reti1: type = drmtl_type_int; break;
4179  case drmtl_opcode_reti2: type = drmtl_type_int2; break;
4180  case drmtl_opcode_reti3: type = drmtl_type_int3; break;
4181  case drmtl_opcode_reti4: type = drmtl_type_int4; break;
4182  default: return 0;
4183  }
4184 
4185  return drmtl_codegen_glsl_write_instruction_input_initializer(pCodegen, type, pInstruction->ret.inputDesc, &pInstruction->ret.inputX) && drmtl_codegen_glsl_write(pCodegen, ";\n");
4186  }
4187 
4188  return 0;
4189 }
4190 
4191 bool drmtl_codegen_glsl_write_instruction(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstruction)
4192 {
4193  assert(pCodegen != NULL);
4194  assert(pInstruction != NULL);
4195 
4196  if (drmtl_codegen_glsl_write_indentation(pCodegen))
4197  {
4198  switch (pInstruction->opcode)
4199  {
4200  case drmtl_opcode_movf1:
4201  case drmtl_opcode_movf2:
4202  case drmtl_opcode_movf3:
4203  case drmtl_opcode_movf4:
4204  case drmtl_opcode_movi1:
4205  case drmtl_opcode_movi2:
4206  case drmtl_opcode_movi3:
4207  case drmtl_opcode_movi4:
4208  {
4209  return drmtl_codegen_glsl_write_instruction_mov(pCodegen, pInstruction);
4210  }
4211 
4212 
4213  case drmtl_opcode_addf1:
4214  case drmtl_opcode_addf2:
4215  case drmtl_opcode_addf3:
4216  case drmtl_opcode_addf4:
4217  case drmtl_opcode_addi1:
4218  case drmtl_opcode_addi2:
4219  case drmtl_opcode_addi3:
4220  case drmtl_opcode_addi4:
4221  {
4222  return drmtl_codegen_glsl_write_instruction_add(pCodegen, pInstruction);
4223  }
4224 
4225  case drmtl_opcode_subf1:
4226  case drmtl_opcode_subf2:
4227  case drmtl_opcode_subf3:
4228  case drmtl_opcode_subf4:
4229  case drmtl_opcode_subi1:
4230  case drmtl_opcode_subi2:
4231  case drmtl_opcode_subi3:
4232  case drmtl_opcode_subi4:
4233  {
4234  return drmtl_codegen_glsl_write_instruction_sub(pCodegen, pInstruction);
4235  }
4236 
4237  case drmtl_opcode_mulf1:
4238  case drmtl_opcode_mulf2:
4239  case drmtl_opcode_mulf3:
4240  case drmtl_opcode_mulf4:
4241  case drmtl_opcode_muli1:
4242  case drmtl_opcode_muli2:
4243  case drmtl_opcode_muli3:
4244  case drmtl_opcode_muli4:
4245  {
4246  return drmtl_codegen_glsl_write_instruction_mul(pCodegen, pInstruction);
4247  }
4248 
4249  case drmtl_opcode_divf1:
4250  case drmtl_opcode_divf2:
4251  case drmtl_opcode_divf3:
4252  case drmtl_opcode_divf4:
4253  case drmtl_opcode_divi1:
4254  case drmtl_opcode_divi2:
4255  case drmtl_opcode_divi3:
4256  case drmtl_opcode_divi4:
4257  {
4258  return drmtl_codegen_glsl_write_instruction_div(pCodegen, pInstruction);
4259  }
4260 
4261  case drmtl_opcode_powf1:
4262  case drmtl_opcode_powf2:
4263  case drmtl_opcode_powf3:
4264  case drmtl_opcode_powf4:
4265  case drmtl_opcode_powi1:
4266  case drmtl_opcode_powi2:
4267  case drmtl_opcode_powi3:
4268  case drmtl_opcode_powi4:
4269  {
4270  return drmtl_codegen_glsl_write_instruction_pow(pCodegen, pInstruction);
4271  }
4272 
4273  case drmtl_opcode_tex1:
4274  case drmtl_opcode_tex2:
4275  case drmtl_opcode_tex3:
4276  case drmtl_opcode_texcube:
4277  {
4278  return drmtl_codegen_glsl_write_instruction_tex(pCodegen, pInstruction);
4279  }
4280 
4281 
4282  case drmtl_opcode_var:
4283  {
4284  return drmtl_codegen_glsl_write_instruction_var(pCodegen, pInstruction);
4285  }
4286 
4287  case drmtl_opcode_retf1:
4288  case drmtl_opcode_retf2:
4289  case drmtl_opcode_retf3:
4290  case drmtl_opcode_retf4:
4291  case drmtl_opcode_reti1:
4292  case drmtl_opcode_reti2:
4293  case drmtl_opcode_reti3:
4294  case drmtl_opcode_reti4:
4295  {
4296  return drmtl_codegen_glsl_write_instruction_ret(pCodegen, pInstruction);
4297  }
4298 
4299 
4300  default:
4301  {
4302  // Unknown or unsupported opcode.
4303  break;
4304  }
4305  }
4306  }
4307 
4308  return 0;
4309 }
4310 
4311 bool drmtl_codegen_glsl_write_instructions(drmtl_codegen_glsl* pCodegen, drmtl_instruction* pInstructions, unsigned int instructionCount)
4312 {
4313  assert(pCodegen != NULL);
4314  assert(pInstructions != NULL);
4315 
4316  for (unsigned int iInstruction = 0; iInstruction < instructionCount; ++iInstruction)
4317  {
4318  drmtl_instruction* pInstruction = pInstructions + iInstruction;
4319  assert(pInstruction != NULL);
4320 
4321  if (!drmtl_codegen_glsl_write_instruction(pCodegen, pInstruction))
4322  {
4323  return 0;
4324  }
4325  }
4326 
4327  return 1;
4328 }
4329 
4330 bool drmtl_codegen_glsl_channel_function_begin(drmtl_codegen_glsl* pCodegen, drmtl_channel_header* pChannelHeader)
4331 {
4332  assert(pCodegen != NULL);
4333  assert(pChannelHeader != NULL);
4334 
4335  // <type> <name> {\n
4336  bool result =
4337  drmtl_codegen_glsl_write_type(pCodegen, pChannelHeader->channel.type) &&
4338  drmtl_codegen_glsl_write(pCodegen, " ") &&
4339  drmtl_codegen_glsl_write(pCodegen, pChannelHeader->channel.name) &&
4340  drmtl_codegen_glsl_write(pCodegen, "() {\n");
4341  if (result)
4342  {
4343  pCodegen->indentationLevel += 4;
4344  }
4345 
4346  return result;
4347 }
4348 
4349 bool drmtl_codegen_glsl_channel_function_close(drmtl_codegen_glsl* pCodegen)
4350 {
4351  assert(pCodegen != NULL);
4352 
4353  if (pCodegen->indentationLevel > 4) {
4354  pCodegen->indentationLevel -= 4;
4355  } else {
4356  pCodegen->indentationLevel = 0;
4357  }
4358 
4359  return drmtl_codegen_glsl_write(pCodegen, "}\n");
4360 }
4361 
4362 bool drmtl_codegen_glsl_channel(drmtl_material* pMaterial, const char* channelName, char* codeOut, size_t codeOutSizeInBytes, size_t* pBytesWrittenOut)
4363 {
4364  if (pMaterial != NULL)
4365  {
4366  drmtl_header* pHeader = drmtl_getheader(pMaterial);
4367  if (pHeader != NULL)
4368  {
4369  drmtl_channel_header* pChannelHeader = drmtl_getchannelheaderbyname(pMaterial, channelName);
4370  if (pChannelHeader != NULL)
4371  {
4372  drmtl_codegen_glsl codegen;
4373  codegen.pBufferOut = codeOut;
4374  codegen.bufferOutSizeInBytes = codeOutSizeInBytes;
4375  codegen.runningLength = 0;
4376  codegen.pMaterial = pMaterial;
4377  codegen.pIdentifiers = drmtl_getidentifiers(pMaterial);
4378  codegen.identifierCount = drmtl_getidentifiercount(pMaterial);
4379  codegen.indentationLevel = 0;
4380 
4381  if (drmtl_codegen_glsl_channel_function_begin(&codegen, pChannelHeader))
4382  {
4383  drmtl_instruction* pInstructions = (drmtl_instruction*)(pChannelHeader + 1);
4384  assert(pInstructions != NULL);
4385 
4386  if (drmtl_codegen_glsl_write_instructions(&codegen, pInstructions, pChannelHeader->instructionCount))
4387  {
4388  bool result = drmtl_codegen_glsl_channel_function_close(&codegen);
4389  if (result)
4390  {
4391  if (pBytesWrittenOut != NULL)
4392  {
4393  *pBytesWrittenOut = codegen.runningLength + 1;
4394  }
4395  }
4396 
4397  return result;
4398  }
4399  }
4400  }
4401  }
4402  }
4403 
4404  return 0;
4405 }
4406 
4407 
4408 
4409 bool drmtl_codegen_glsl_uniform(drmtl_codegen_glsl* pCodegen, drmtl_input* pInput)
4410 {
4411  assert(pCodegen != NULL);
4412  assert(pInput != NULL);
4413 
4414  if (pInput->identifierIndex < pCodegen->identifierCount)
4415  {
4416  drmtl_identifier* pIdentifier = pCodegen->pIdentifiers + pInput->identifierIndex;
4417  assert(pIdentifier != NULL);
4418 
4419  // uniform <type> <name>;
4420  return
4421  drmtl_codegen_glsl_write(pCodegen, "uniform ") &&
4422  drmtl_codegen_glsl_write_type(pCodegen, pIdentifier->type) &&
4423  drmtl_codegen_glsl_write(pCodegen, " ") &&
4424  drmtl_codegen_glsl_write(pCodegen, pIdentifier->name) &&
4425  drmtl_codegen_glsl_write(pCodegen, ";\n");
4426  }
4427 
4428  return 0;
4429 }
4430 
4431 bool drmtl_codegen_glsl_uniforms(drmtl_material* pMaterial, char* codeOut, size_t codeOutSizeInBytes, size_t* pBytesWritteOut)
4432 {
4433  if (pMaterial != NULL)
4434  {
4435  drmtl_codegen_glsl codegen;
4436  codegen.pBufferOut = codeOut;
4437  codegen.bufferOutSizeInBytes = codeOutSizeInBytes;
4438  codegen.runningLength = 0;
4439  codegen.pMaterial = pMaterial;
4440  codegen.pIdentifiers = drmtl_getidentifiers(pMaterial);
4441  codegen.identifierCount = drmtl_getidentifiercount(pMaterial);
4442  codegen.indentationLevel = 0;
4443 
4444 
4445  unsigned int inputCount = drmtl_getpublicinputcount(pMaterial);
4446  if (inputCount > 0)
4447  {
4448  for (unsigned int iInput = 0; iInput < inputCount; ++iInput)
4449  {
4450  drmtl_input* pInput = drmtl_getpublicinputbyindex(pMaterial, iInput);
4451  assert(pInput != NULL);
4452 
4453  if (!drmtl_codegen_glsl_uniform(&codegen, pInput))
4454  {
4455  // There was an error writing one of the uniforms. Return false.
4456  return 0;
4457  }
4458  }
4459  }
4460  else
4461  {
4462  // No inputs. Just write an empty string.
4463  drmtl_codegen_glsl_write(&codegen, "");
4464  }
4465 
4466  if (pBytesWritteOut != NULL)
4467  {
4468  *pBytesWritteOut = codegen.runningLength + 1;
4469  }
4470 
4471  return 1;
4472  }
4473 
4474  return 0;
4475 }
4476 
4477 #if defined(__clang__)
4478  #pragma GCC diagnostic pop
4479 #endif
4480 #endif
4481 
4482 #if defined(__clang__)
4483  #pragma GCC diagnostic pop
4484 #endif
4485 #endif
4486 
4487 /*
4488 This is free and unencumbered software released into the public domain.
4489 
4490 Anyone is free to copy, modify, publish, use, compile, sell, or
4491 distribute this software, either in source code form or as a compiled
4492 binary, for any purpose, commercial or non-commercial, and by any
4493 means.
4494 
4495 In jurisdictions that recognize copyright laws, the author or authors
4496 of this software dedicate any and all copyright interest in the
4497 software to the public domain. We make this dedication for the benefit
4498 of the public at large and to the detriment of our heirs and
4499 successors. We intend this dedication to be an overt act of
4500 relinquishment in perpetuity of all present and future rights to this
4501 software under copyright law.
4502 
4503 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
4504 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4505 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
4506 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
4507 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
4508 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
4509 OTHER DEALINGS IN THE SOFTWARE.
4510 
4511 For more information, please refer to <http://unlicense.org/>
4512 */
drmtl_opcode_subi1
@ drmtl_opcode_subi1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:133
drmtl_property::name
char name[DRMTL_MAX_PROPERTY_NAME]
The name of the property.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:446
drmtl_reti2_c2
drmtl_instruction drmtl_reti2_c2(int x, int y)
drmtl_mulf3_v3
drmtl_instruction drmtl_mulf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_header::propertySizeInBytes
unsigned int propertySizeInBytes
The size in bytes of a property.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:535
drmtl_mulf3_c3
drmtl_instruction drmtl_mulf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
drmtl_instruction_input::valuei
int valuei
The constant value, as an integer.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:306
drmtl_type_int
@ drmtl_type_int
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:86
drmtl_opcode_muli3
@ drmtl_opcode_muli3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:145
drmtl_material::ownsRawData
bool ownsRawData
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:604
drmtl_opcode_powf2
@ drmtl_opcode_powf2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:160
drmtl_opcode_movf4
@ drmtl_opcode_movf4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:108
drmtl_channel_float2
drmtl_channel drmtl_channel_float2(const char *name)
drmtl_instruction_input::id
unsigned int id
The identifier index of the applicable variable.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:300
drmtl_opcode_movi4
@ drmtl_opcode_movi4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:112
drmtl_mulf4_v1v1v1v1
drmtl_instruction drmtl_mulf4_v1v1v1v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndexX, unsigned int inputIdentifierIndexY, unsigned int inputIdentifierIndexZ, unsigned int inputIdentifierIndexW)
drmtl_type
drmtl_type
The various data type available to the material.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:80
drmtl_subf3_v3
drmtl_instruction drmtl_subf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_opcode_powi4
@ drmtl_opcode_powi4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:166
DRMTL_MAX_PROPERTY_PATH
#define DRMTL_MAX_PROPERTY_PATH
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:70
drmtl_material::bufferSizeInBytes
unsigned int bufferSizeInBytes
The size of the buffer, in bytes. This is used to determine when the buffer needs to be inflated.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:590
drmtl_opcode_muli1
@ drmtl_opcode_muli1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:143
drmtl_type_tex3d
@ drmtl_type_tex3d
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:92
drmtl_mulf2_v2
drmtl_instruction drmtl_mulf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_type_float3
@ drmtl_type_float3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:84
drmtl_retf4_c4
drmtl_instruction drmtl_retf4_c4(float x, float y, float z, float w)
drmtl_input::i2
struct drmtl_input::@21::@28 i2
drmtl_opcode_divf1
@ drmtl_opcode_divf1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:149
drmtl_movf4_c4
drmtl_instruction drmtl_movf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
drmtl_header::propertyCount
unsigned int propertyCount
The total number of properties.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:551
drmtl_property::f2
struct drmtl_property::@45::@48 f2
drmtl_opcode_addi2
@ drmtl_opcode_addi2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:124
drmtl_opcode_addi1
@ drmtl_opcode_addi1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:123
drmtl_opcode_muli4
@ drmtl_opcode_muli4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:146
drmtl_material::currentChannelOffset
unsigned int currentChannelOffset
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:599
drmtl_material
Structure containing the definition of the material.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:581
drmtl_codegen_glsl_channel
bool drmtl_codegen_glsl_channel(drmtl_material *pMaterial, const char *channelName, char *codeOut, size_t codeOutSizeInBytes, size_t *pBytesWrittenOut)
Generates GLSL code for the channel with the given name.
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
drmtl_header::publicInputCount
unsigned int publicInputCount
The total number of public input variables.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:545
drmtl_divf3_c3
drmtl_instruction drmtl_divf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
drmtl_channel_int3
drmtl_channel drmtl_channel_int3(const char *name)
drmtl_opcode_movf2
@ drmtl_opcode_movf2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:106
drmtl_appendidentifier
bool drmtl_appendidentifier(drmtl_material *pMaterial, drmtl_identifier identifier, unsigned int *indexOut)
DRMTL_INPUT_DESC_VARX
#define DRMTL_INPUT_DESC_VARX
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:60
drmtl_opcode_divf4
@ drmtl_opcode_divf4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:152
drmtl_uninit
void drmtl_uninit(drmtl_material *pMaterial)
drmtl_instruction_input
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:297
drmtl_movf1_c1
drmtl_instruction drmtl_movf1_c1(unsigned int outputIdentifierIndex, float x)
drmtl_opcode_retf1
@ drmtl_opcode_retf1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:186
drmtl_movf4_v4
drmtl_instruction drmtl_movf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_addf4_v4
drmtl_instruction drmtl_addf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_opcode_subf1
@ drmtl_opcode_subf1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:129
drmtl_property::f1
struct drmtl_property::@45::@47 f1
drmtl_type_tex2d
@ drmtl_type_tex2d
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:91
drmtl_getpublicinputbyindex
drmtl_input * drmtl_getpublicinputbyindex(drmtl_material *pMaterial, unsigned int index)
Retrieves the public input variable by it's index.
drmtl_channel_int4
drmtl_channel drmtl_channel_int4(const char *name)
drmtl_reti1_c1
drmtl_instruction drmtl_reti1_c1(int x)
drmtl_input_float3
drmtl_input drmtl_input_float3(unsigned int identifierIndex, float x, float y, float z)
drmtl_input::i1
struct drmtl_input::@21::@27 i1
drmtl_opcode_mulf4
@ drmtl_opcode_mulf4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:142
drmtl_type_texcube
@ drmtl_type_texcube
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:93
drmtl_property::f3
struct drmtl_property::@45::@49 f3
drmtl_opcode_divf3
@ drmtl_opcode_divf3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:151
drmtl_retf3
drmtl_instruction drmtl_retf3(unsigned int identifierIndex)
drmtl_mulf2_c2
drmtl_instruction drmtl_mulf2_c2(unsigned int outputIdentifierIndex, float x, float y)
drmtl_getpropertybyindex
drmtl_property * drmtl_getpropertybyindex(drmtl_material *pMaterial, unsigned int index)
Retrieves a property by it's index.
drmtl_instruction::tex
struct drmtl_instruction::@33::@41 tex
drmtl_opcode_subi4
@ drmtl_opcode_subi4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:136
drmtl_reti3
drmtl_instruction drmtl_reti3(unsigned int identifierIndex)
drmtl_header::magic
unsigned int magic
The magic number: 0x81DF7405.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:515
drmtl_opcode_divf2
@ drmtl_opcode_divf2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:150
drmtl_opcode_tex1
@ drmtl_opcode_tex1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:173
drmtl_instruction::pow
struct drmtl_instruction::@33::@40 pow
drmtl_divf1_c1
drmtl_instruction drmtl_divf1_c1(unsigned int outputIdentifierIndex, float x)
drmtl_reti4_c4
drmtl_instruction drmtl_reti4_c4(int x, int y, int z, int w)
drmtl_var
drmtl_instruction drmtl_var(unsigned int identifierIndex)
drmtl_channel
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:284
drmtl_identifier_tex2d
drmtl_identifier drmtl_identifier_tex2d(const char *name)
drmtl_opcode_powi2
@ drmtl_opcode_powi2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:164
drmtl_input_int
drmtl_input drmtl_input_int(unsigned int identifierIndex, int x)
drmtl_opcode_powf1
@ drmtl_opcode_powf1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:159
drmtl_opcode_divi2
@ drmtl_opcode_divi2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:154
drmtl_instruction::mul
struct drmtl_instruction::@33::@38 mul
drmtl_opcode
drmtl_opcode
The various run-time opcodes.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:99
drmtl_opcode_powf3
@ drmtl_opcode_powf3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:161
DRMTL_MAGIC_NUMBER
#define DRMTL_MAGIC_NUMBER
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:55
drmtl_divf4_c4
drmtl_instruction drmtl_divf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
drmtl_movf1_v1
drmtl_instruction drmtl_movf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
Helper for creating an instruction. These are heavily simplified and more complex setups are possible...
drmtl_reti2
drmtl_instruction drmtl_reti2(unsigned int identifierIndex)
drmtl_property::i3
struct drmtl_property::@45::@53 i3
drmtl_subf4_c4
drmtl_instruction drmtl_subf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
drmtl_instruction::var
struct drmtl_instruction::@33::@43 var
drmtl_property::b1
struct drmtl_property::@45::@56 b1
drmtl_retf2_c2
drmtl_instruction drmtl_retf2_c2(float x, float y)
drmtl_input_float4
drmtl_input drmtl_input_float4(unsigned int identifierIndex, float x, float y, float z, float w)
drmtl_subf2_v2
drmtl_instruction drmtl_subf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_instruction::add
struct drmtl_instruction::@33::@36 add
drmtl_mulf4_v3c1
drmtl_instruction drmtl_mulf4_v3c1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float w)
drmtl_getpropertycount
unsigned int drmtl_getpropertycount(drmtl_material *pMaterial)
Retrieves the number of properties.
drmtl_type_float2
@ drmtl_type_float2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:83
drmtl_opcode_powf4
@ drmtl_opcode_powf4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:162
drmtl_tex2
drmtl_instruction drmtl_tex2(unsigned int outputIdentifierIndex, unsigned int textureIdentifierIndex, unsigned int texcoordIdentifierIndex)
drmtl_type_int2
@ drmtl_type_int2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:87
drmtl_channel_float4
drmtl_channel drmtl_channel_float4(const char *name)
drmtl_channel_int
drmtl_channel drmtl_channel_int(const char *name)
drmtl_input_int4
drmtl_input drmtl_input_int4(unsigned int identifierIndex, int x, int y, int z, int w)
drmtl_mulf4_v2c2
drmtl_instruction drmtl_mulf4_v2c2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float z, float w)
drmtl_header::inputsOffset
unsigned int inputsOffset
The offset of the input variables.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:558
DRMTL_INPUT_DESC_CONSTF
#define DRMTL_INPUT_DESC_CONSTF
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:59
drmtl_compile_wavefront_mtl
bool drmtl_compile_wavefront_mtl(drmtl_material *pMaterial, const char *mtlData, size_t mtlDataSizeInBytes, const char *texcoordInputName)
drmtl_movf2_c2
drmtl_instruction drmtl_movf2_c2(unsigned int outputIdentifierIndex, float x, float y)
drmtl_opcode_mulf2
@ drmtl_opcode_mulf2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:140
python.setup.name
name
Definition: porcupine/binding/python/setup.py:69
drmtl_instruction_input_descriptor::w
unsigned char w
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:317
drmtl_opcode_addf2
@ drmtl_opcode_addf2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:120
drmtl_opcode_reti2
@ drmtl_opcode_reti2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:191
drmtl_opcode_retf4
@ drmtl_opcode_retf4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:189
drmtl_opcode_muli2
@ drmtl_opcode_muli2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:144
drmtl_input::identifierIndex
unsigned int identifierIndex
The index into the identifier table that this input variable is identified by.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:215
drmtl_getidentifiers
drmtl_identifier * drmtl_getidentifiers(drmtl_material *pMaterial)
Retrieves a pointer to the buffer containing the list of identifiers.
drmtl_subf1_c1
drmtl_instruction drmtl_subf1_c1(unsigned int outputIdentifierIndex, float x)
drmtl_type_int4
@ drmtl_type_int4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:89
drmtl_retf4
drmtl_instruction drmtl_retf4(unsigned int identifierIndex)
drmtl_addf1_c1
drmtl_instruction drmtl_addf1_c1(unsigned int outputIdentifierIndex, float x)
drmtl_opcode_movi1
@ drmtl_opcode_movi1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:109
drmtl_movf2_v2
drmtl_instruction drmtl_movf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_divf2_v2
drmtl_instruction drmtl_divf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_reti3_c3
drmtl_instruction drmtl_reti3_c3(int x, int y, int z)
drmtl_opcode_movf3
@ drmtl_opcode_movf3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:107
drmtl_input::f4
struct drmtl_input::@21::@26 f4
drmtl_addf3_v3
drmtl_instruction drmtl_addf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_divf3_v3
drmtl_instruction drmtl_divf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_initfromexisting_nocopy
bool drmtl_initfromexisting_nocopy(drmtl_material *pMaterial, const void *pRawData, unsigned int dataSizeInBytes)
drmtl_subf2_c2
drmtl_instruction drmtl_subf2_c2(unsigned int outputIdentifierIndex, float x, float y)
drmtl_type_float
@ drmtl_type_float
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:82
drmtl_identifier_float
drmtl_identifier drmtl_identifier_float(const char *name)
Helper for creating an identifier.
drmtl_property_bool
drmtl_property drmtl_property_bool(const char *name, bool value)
strcpy_s
DR_INLINE int strcpy_s(char *dst, size_t dstSizeInBytes, const char *src)
Definition: porcupine/demo/c/dr_libs/old/dr.h:157
drmtl_opcode_subi3
@ drmtl_opcode_subi3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:135
drmtl_getprivateinputbyindex
drmtl_input * drmtl_getprivateinputbyindex(drmtl_material *pMaterial, unsigned int index)
Retrieves the private input variable by it's index.
drmtl_subf4_v4
drmtl_instruction drmtl_subf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_getidentifiercount
unsigned int drmtl_getidentifiercount(drmtl_material *pMaterial)
Retrieves the number of identifiers defined by the given material.
drmtl_channel_header
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:569
drmtl_opcode_powi1
@ drmtl_opcode_powi1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:163
drmtl_header::inputSizeInBytes
unsigned int inputSizeInBytes
The size in bytes of an input variable.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:526
drmtl_property::f4
struct drmtl_property::@45::@50 f4
drmtl_header::instructionSizeInBytes
unsigned int instructionSizeInBytes
The size in bytes of an instruction.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:532
drmtl_property_int
drmtl_property drmtl_property_int(const char *name, int x)
drmtl_input::path
struct drmtl_input::@21::@31 path
drmtl_opcode_movi2
@ drmtl_opcode_movi2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:110
drmtl_header
Structure containing the header information of the material.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:512
drmtl_input_int3
drmtl_input drmtl_input_int3(unsigned int identifierIndex, int x, int y, int z)
drmtl_identifier_int3
drmtl_identifier drmtl_identifier_int3(const char *name)
drmtl_mulf4_c4
drmtl_instruction drmtl_mulf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
drmtl_property_float3
drmtl_property drmtl_property_float3(const char *name, float x, float y, float z)
drmtl_opcode_addf1
@ drmtl_opcode_addf1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:119
drmtl_addf1_v1
drmtl_instruction drmtl_addf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_opcode_addi3
@ drmtl_opcode_addi3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:125
drmtl_property_int4
drmtl_property drmtl_property_int4(const char *name, int x, int y, int z, int w)
drmtl_getprivateinputcount
unsigned int drmtl_getprivateinputcount(drmtl_material *pMaterial)
Retrieves the number of private input variables.
drmtl_appendprivateinput
bool drmtl_appendprivateinput(drmtl_material *pMaterial, drmtl_input input)
Appends a private input variable.
drmtl_addf2_c2
drmtl_instruction drmtl_addf2_c2(unsigned int outputIdentifierIndex, float x, float y)
drmtl_subf1_v1
drmtl_instruction drmtl_subf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_appendchannel
bool drmtl_appendchannel(drmtl_material *pMaterial, drmtl_channel channelHeader)
drmtl_property_int3
drmtl_property drmtl_property_int3(const char *name, int x, int y, int z)
drmtl_header::propertiesOffset
unsigned int propertiesOffset
The offset of the properties.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:564
drmtl_subf3_c3
drmtl_instruction drmtl_subf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
drmtl_initfromexisting
bool drmtl_initfromexisting(drmtl_material *pMaterial, const void *pRawData, unsigned int dataSizeInBytes)
drmtl_channel_float3
drmtl_channel drmtl_channel_float3(const char *name)
drmtl_identifier::name
char name[DRMTL_MAX_IDENTIFIER_NAME]
The name of the identifier.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:206
drmtl_type_bool
@ drmtl_type_bool
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:94
drmtl_instruction::ret
struct drmtl_instruction::@33::@42 ret
drmtl_material::sizeInBytes
unsigned int sizeInBytes
The size of the data, in bytes.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:587
drmtl_movf3_v3
drmtl_instruction drmtl_movf3_v3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_channel_header::instructionCount
unsigned int instructionCount
The instruction count of the channel.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:575
drmtl_type_float4
@ drmtl_type_float4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:85
drmtl_type_tex1d
@ drmtl_type_tex1d
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:90
drmtl_header::privateInputCount
unsigned int privateInputCount
The total number of private input variables.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:542
drmtl_mulf1_v1
drmtl_instruction drmtl_mulf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_input_float2
drmtl_input drmtl_input_float2(unsigned int identifierIndex, float x, float y)
drmtl_instruction_input_descriptor::x
unsigned char x
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:314
drmtl_appendinstruction
bool drmtl_appendinstruction(drmtl_material *pMaterial, drmtl_instruction instruction)
Appends an instruction to the most recently appended channel.
drmtl_input::f1
struct drmtl_input::@21::@23 f1
drmtl_getinputcount
unsigned int drmtl_getinputcount(drmtl_material *pMaterial)
Retrieves the number of private + public input variables.
drmtl_mulf4_v4
drmtl_instruction drmtl_mulf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_opcode_tex3
@ drmtl_opcode_tex3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:175
drmtl_uint32
unsigned int drmtl_uint32
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:74
drmtl_input_int2
drmtl_input drmtl_input_int2(unsigned int identifierIndex, int x, int y)
drmtl_property::type
drmtl_type type
The type of the property.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:443
drmtl_getpropertybyname
drmtl_property * drmtl_getpropertybyname(drmtl_material *pMaterial, const char *name)
DRMTL_MAX_CHANNEL_NAME
#define DRMTL_MAX_CHANNEL_NAME
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:66
drmtl_property_int2
drmtl_property drmtl_property_int2(const char *name, int x, int y)
drmtl_appendpublicinput
bool drmtl_appendpublicinput(drmtl_material *pMaterial, drmtl_input input)
Appends a public input variable.
drmtl_divf1_v1
drmtl_instruction drmtl_divf1_v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_identifier_float4
drmtl_identifier drmtl_identifier_float4(const char *name)
drmtl_instruction_input_descriptor
Structure used for describing an instructions input data.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:312
drmtl_opcode_divi3
@ drmtl_opcode_divi3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:155
drmtl_opcode_texcube
@ drmtl_opcode_texcube
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:176
drmtl_codegen_glsl_uniforms
bool drmtl_codegen_glsl_uniforms(drmtl_material *pMaterial, char *codeOut, size_t codeOutSizeInBytes, size_t *pBytesWritteOut)
Generates GLSL code for the uniform variables as defined by the material's public input variables.
drmtl_getidentifier
drmtl_identifier * drmtl_getidentifier(drmtl_material *pMaterial, unsigned int index)
drmtl_identifier_int4
drmtl_identifier drmtl_identifier_int4(const char *name)
add
bool add(const actionlib::TwoIntsGoal &req, actionlib::TwoIntsResult &res)
drmtl_identifier_int2
drmtl_identifier drmtl_identifier_int2(const char *name)
drmtl_retf2
drmtl_instruction drmtl_retf2(unsigned int identifierIndex)
drmtl_opcode
drmtl_opcode
The various run-time opcodes.
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:99
drmtl_init
bool drmtl_init(drmtl_material *pMaterial)
drmtl_channel_float
drmtl_channel drmtl_channel_float(const char *name)
Helper for creating a channel.
drmtl_type
drmtl_type
The various data type available to the material.
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:80
drmtl_property::i4
struct drmtl_property::@45::@54 i4
drmtl_property_float
drmtl_property drmtl_property_float(const char *name, float x)
Helper for creating a property.
drmtl_opcode_movi3
@ drmtl_opcode_movi3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:111
drmtl_opcode_reti3
@ drmtl_opcode_reti3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:192
drmtl_getchannelheaderbyindex
drmtl_channel_header * drmtl_getchannelheaderbyindex(drmtl_material *pMaterial, unsigned int channelIndex)
DRMTL_INPUT_DESC_CONSTI
#define DRMTL_INPUT_DESC_CONSTI
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:58
drmtl_input
Structure containing information about an input variable.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:212
drmtl_material::pRawData
drmtl_uint8 * pRawData
A pointer to the raw data. This will at least be the size of drmtl_header (128 bytes,...
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:584
drmtl_instruction::div
struct drmtl_instruction::@33::@39 div
DRMTL_MAX_PROPERTY_NAME
#define DRMTL_MAX_PROPERTY_NAME
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:67
drmtl_uint8
unsigned char drmtl_uint8
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:73
drmtl_header::identifiersOffset
unsigned int identifiersOffset
The offset of the identifiers.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:555
drmtl_addf2_v2
drmtl_instruction drmtl_addf2_v2(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
DRMTL_MAX_INPUT_PATH
#define DRMTL_MAX_INPUT_PATH
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:69
DRMTL_INPUT_DESC_VARW
#define DRMTL_INPUT_DESC_VARW
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:63
drmtl_reti4
drmtl_instruction drmtl_reti4(unsigned int identifierIndex)
drmtl_opcode_tex2
@ drmtl_opcode_tex2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:174
drmtl_channel::name
char name[DRMTL_MAX_CHANNEL_NAME]
The name of the channel. Null terminated.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:290
drmtl_instruction::sub
struct drmtl_instruction::@33::@37 sub
drmtl_opcode_subf4
@ drmtl_opcode_subf4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:132
drmtl_mulf4_v3v1
drmtl_instruction drmtl_mulf4_v3v1(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndexXYZ, unsigned int inputIdentifierIndexW)
drmtl_opcode_movf1
@ drmtl_opcode_movf1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:105
drmtl_opcode_reti1
@ drmtl_opcode_reti1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:190
drmtl_opcode_var
@ drmtl_opcode_var
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:183
drmtl_material::currentStage
unsigned int currentStage
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:595
drmtl_opcode_reti4
@ drmtl_opcode_reti4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:193
drmtl_input::f2
struct drmtl_input::@21::@24 f2
drmtl_opcode_subi2
@ drmtl_opcode_subi2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:134
drmtl_uint8
unsigned char drmtl_uint8
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:73
python.setup.version
version
Definition: porcupine/binding/python/setup.py:70
drmtl_input::i4
struct drmtl_input::@21::@30 i4
drmtl_getheader
drmtl_header * drmtl_getheader(drmtl_material *pMaterial)
Retrieve a pointer to the header information.
drmtl_header::channelHeaderSizeInBytes
unsigned int channelHeaderSizeInBytes
The size of a channel header, in bytes.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:529
drmtl_instruction_input::valuef
float valuef
The constant value, as a float.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:303
drmtl_opcode_subf3
@ drmtl_opcode_subf3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:131
drmtl_channel::type
drmtl_type type
The return type of the channel.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:287
drmtl_property_float2
drmtl_property drmtl_property_float2(const char *name, float x, float y)
drmtl_type_int3
@ drmtl_type_int3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:88
drmtl_retf1_c1
drmtl_instruction drmtl_retf1_c1(float x)
drmtl_channel_int2
drmtl_channel drmtl_channel_int2(const char *name)
drmtl_instruction_input_descriptor::y
unsigned char y
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:315
drmtl_addf3_c3
drmtl_instruction drmtl_addf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
drmtl_input_float
drmtl_input drmtl_input_float(unsigned int identifierIndex, float x)
Helper for creating an input variable.
drmtl_opcode_addi4
@ drmtl_opcode_addi4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:126
drmtl_identifier_float2
drmtl_identifier drmtl_identifier_float2(const char *name)
drmtl_addf4_c4
drmtl_instruction drmtl_addf4_c4(unsigned int outputIdentifierIndex, float x, float y, float z, float w)
drmtl_getchannelheaderbyname
drmtl_channel_header * drmtl_getchannelheaderbyname(drmtl_material *pMaterial, const char *channelName)
drmtl_channel_header::channel
drmtl_channel channel
The channel information.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:572
drmtl_movf3_c3
drmtl_instruction drmtl_movf3_c3(unsigned int outputIdentifierIndex, float x, float y, float z)
drmtl_opcode_subf2
@ drmtl_opcode_subf2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:130
drmtl_opcode_powi3
@ drmtl_opcode_powi3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:165
drmtl_retf3_c3
drmtl_instruction drmtl_retf3_c3(float x, float y, float z)
drmtl_opcode_addf4
@ drmtl_opcode_addf4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:122
DRMTL_INPUT_DESC_VARY
#define DRMTL_INPUT_DESC_VARY
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:61
drmtl_instruction_input_descriptor::z
unsigned char z
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:316
drmtl_mulf1_c1
drmtl_instruction drmtl_mulf1_c1(unsigned int outputIdentifierIndex, float x)
drmtl_opcode_addf3
@ drmtl_opcode_addf3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:121
DRMTL_INPUT_DESC_VARZ
#define DRMTL_INPUT_DESC_VARZ
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:62
drmtl_appendproperty
bool drmtl_appendproperty(drmtl_material *pMaterial, drmtl_property prop)
Append a property.
drmtl_header::identifierSizeInBytes
unsigned int identifierSizeInBytes
The size in bytes of an identifier.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:523
drmtl_identifier
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:200
assert.h
drmtl_mulf4_v1c3
drmtl_instruction drmtl_mulf4_v1c3(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex, float y, float z, float w)
drmtl_header::version
unsigned int version
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:519
drmtl_uint32
unsigned int drmtl_uint32
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:74
drmtl_opcode_mulf1
@ drmtl_opcode_mulf1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:139
DRMTL_CURRENT_VERSION
#define DRMTL_CURRENT_VERSION
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:56
drmtl_opcode_retf3
@ drmtl_opcode_retf3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:188
drmtl_getinputbyindex
drmtl_input * drmtl_getinputbyindex(drmtl_material *pMaterial, unsigned int index)
Retrieves the input variable by it's index.
drmtl_input::f3
struct drmtl_input::@21::@25 f3
drmtl_header::channelCount
unsigned int channelCount
The total number of channels.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:548
drmtl_opcode_divi4
@ drmtl_opcode_divi4
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:156
drmtl_identifier_int
drmtl_identifier drmtl_identifier_int(const char *name)
drmtl_divf2_c2
drmtl_instruction drmtl_divf2_c2(unsigned int outputIdentifierIndex, float x, float y)
drmtl_identifier::type
drmtl_type type
The type of the identifier.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:203
drmtl_instruction::mov
struct drmtl_instruction::@33::@35 mov
drmtl_opcode_divi1
@ drmtl_opcode_divi1
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:153
drmtl_property
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:440
drmtl_input::i3
struct drmtl_input::@21::@29 i3
drmtl_retf1
drmtl_instruction drmtl_retf1(unsigned int identifierIndex)
drmtl_header::channelsOffset
unsigned int channelsOffset
The offset of the channels.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:561
drmtl_instruction
Structure containing information about an instruction.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:322
drmtl_property::i2
struct drmtl_property::@45::@52 i2
drmtl_property_float4
drmtl_property drmtl_property_float4(const char *name, float x, float y, float z, float w)
drmtl_divf4_v4
drmtl_instruction drmtl_divf4_v4(unsigned int outputIdentifierIndex, unsigned int inputIdentifierIndex)
drmtl_instruction::opcode
drmtl_opcode opcode
The instruction's opcode.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:325
DRMTL_MAX_IDENTIFIER_NAME
#define DRMTL_MAX_IDENTIFIER_NAME
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:65
drmtl_getpublicinputcount
unsigned int drmtl_getpublicinputcount(drmtl_material *pMaterial)
Retrieves the number of public input variables.
drmtl_opcode_retf2
@ drmtl_opcode_retf2
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:187
drmtl_input_tex
drmtl_input drmtl_input_tex(unsigned int identifierIndex, const char *path)
drmtl_reti1
drmtl_instruction drmtl_reti1(unsigned int identifierIndex)
drmtl_opcode_mulf3
@ drmtl_opcode_mulf3
Definition: rhino/demo/c/dr_libs/old/dr_mtl.h:141
drmtl_header::identifierCount
unsigned int identifierCount
The total number of identifiers.
Definition: porcupine/demo/c/dr_libs/old/dr_mtl.h:539
drmtl_property::i1
struct drmtl_property::@45::@51 i1
drmtl_identifier_float3
drmtl_identifier drmtl_identifier_float3(const char *name)


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:13:55