BsASTFX.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #ifndef __ASTFX_H__
  4. #define __ASTFX_H__
  5. #include <stdlib.h>
  6. #include <string.h>
  7. enum tagNodeType
  8. {
  9. NT_Shader,
  10. NT_Options,
  11. NT_Technique,
  12. NT_Mixin,
  13. NT_Pass,
  14. NT_Blend,
  15. NT_Raster,
  16. NT_Depth,
  17. NT_Stencil,
  18. NT_Target,
  19. NT_StencilOp,
  20. NT_BlendDef,
  21. NT_Tags,
  22. NT_CodeVertex,
  23. NT_CodeFragment,
  24. NT_CodeGeometry,
  25. NT_CodeHull,
  26. NT_CodeDomain,
  27. NT_CodeCompute,
  28. NT_CodeCommon,
  29. };
  30. enum tagOptionType
  31. {
  32. OT_None = 0,
  33. OT_Options,
  34. OT_Separable,
  35. OT_Priority,
  36. OT_Sort,
  37. OT_Transparent,
  38. OT_Technique,
  39. OT_Mixin,
  40. OT_Raster,
  41. OT_Depth,
  42. OT_Stencil,
  43. OT_Blend,
  44. OT_Renderer,
  45. OT_Pass,
  46. OT_FillMode,
  47. OT_CullMode,
  48. OT_DepthBias,
  49. OT_SDepthBias,
  50. OT_DepthClip,
  51. OT_Scissor,
  52. OT_Multisample,
  53. OT_AALine,
  54. OT_DepthRead,
  55. OT_DepthWrite,
  56. OT_CompareFunc,
  57. OT_StencilReadMask,
  58. OT_StencilWriteMask,
  59. OT_StencilOpFront,
  60. OT_StencilOpBack,
  61. OT_PassOp,
  62. OT_Fail,
  63. OT_ZFail,
  64. OT_AlphaToCoverage,
  65. OT_IndependantBlend,
  66. OT_Target,
  67. OT_Index,
  68. OT_Enabled,
  69. OT_Color,
  70. OT_Alpha,
  71. OT_WriteMask,
  72. OT_Source,
  73. OT_Dest,
  74. OT_Op,
  75. OT_Identifier,
  76. OT_Code,
  77. OT_StencilRef,
  78. OT_Tags,
  79. OT_TagValue,
  80. OT_Count
  81. };
  82. enum tagOptionDataType
  83. {
  84. ODT_Int,
  85. ODT_Float,
  86. ODT_Bool,
  87. ODT_String,
  88. ODT_Complex,
  89. ODT_Matrix
  90. };
  91. enum tagFillModeValue
  92. {
  93. FMV_Wire, FMV_Solid
  94. };
  95. enum tagCullAndSortModeValue
  96. {
  97. CASV_None, CASV_CW, CASV_CCW, CASV_FrontToBack, CASV_BackToFront
  98. };
  99. enum tagCompFuncValue
  100. {
  101. CFV_Fail, CFV_Pass, CFV_LT, CFV_LTE,
  102. CFV_EQ, CFV_NEQ, CFV_GTE, CFV_GT
  103. };
  104. enum tagOpValue
  105. {
  106. OV_Keep, OV_Zero, OV_Replace, OV_Incr, OV_Decr,
  107. OV_IncrWrap, OV_DecrWrap, OV_Invert, OV_One, OV_DestColor,
  108. OV_SrcColor, OV_InvDestColor, OV_InvSrcColor, OV_DestAlpha,
  109. OV_SrcAlpha, OV_InvDestAlpha, OV_InvSrcAlpha
  110. };
  111. enum tagBlendOpValue
  112. {
  113. BOV_Add, BOV_Subtract, BOV_RevSubtract,
  114. BOV_Min, BOV_Max
  115. };
  116. typedef enum tagNodeType NodeType;
  117. typedef enum tagOptionType OptionType;
  118. typedef enum tagOptionDataType OptionDataType;
  119. typedef struct tagParseState ParseState;
  120. typedef struct tagOptionInfo OptionInfo;
  121. typedef union tagOptionData OptionData;
  122. typedef struct tagNodeOptions NodeOptions;
  123. typedef struct tagNodeOption NodeOption;
  124. typedef struct tagASTFXNode ASTFXNode;
  125. typedef struct tagNodeLink NodeLink;
  126. typedef struct tagIncludeData IncludeData;
  127. typedef struct tagIncludeLink IncludeLink;
  128. typedef struct tagConditionalData ConditionalData;
  129. typedef struct tagCodeString CodeString;
  130. typedef struct tagDefineEntry DefineEntry;
  131. typedef enum tagFillModeValue FillModeValue;
  132. typedef enum tagCullAndSortModeValue CullAndSortModeValue;
  133. typedef enum tagCompFuncValue CompFuncValue;
  134. typedef enum tagOpValue OpValue;
  135. typedef enum tagBlendOpValue BlendOpValue;
  136. struct tagNodeLink
  137. {
  138. ASTFXNode* node;
  139. NodeLink* next;
  140. };
  141. struct tagIncludeData
  142. {
  143. char* filename;
  144. char* buffer;
  145. };
  146. struct tagIncludeLink
  147. {
  148. IncludeData* data;
  149. IncludeLink* next;
  150. };
  151. struct tagConditionalData
  152. {
  153. int selfEnabled;
  154. int enabled;
  155. ConditionalData* next;
  156. };
  157. struct tagCodeString
  158. {
  159. char* code;
  160. int index;
  161. int size;
  162. int capacity;
  163. CodeString* next;
  164. };
  165. struct tagDefineEntry
  166. {
  167. char* name;
  168. char* expr;
  169. };
  170. struct tagParseState
  171. {
  172. ASTFXNode* rootNode;
  173. ASTFXNode* topNode;
  174. void* memContext;
  175. int hasError;
  176. int errorLine;
  177. int errorColumn;
  178. const char* errorMessage;
  179. char* errorFile;
  180. NodeLink* nodeStack;
  181. IncludeLink* includeStack;
  182. IncludeLink* includes;
  183. CodeString* codeStrings;
  184. int numCodeStrings;
  185. int numOpenBrackets;
  186. DefineEntry* defines;
  187. int numDefines;
  188. int defineCapacity;
  189. ConditionalData* conditionalStack;
  190. };
  191. struct tagOptionInfo
  192. {
  193. OptionType type;
  194. OptionDataType dataType;
  195. };
  196. union tagOptionData
  197. {
  198. int intValue;
  199. float floatValue;
  200. const char* strValue;
  201. float matrixValue[16];
  202. int intVectorValue[4];
  203. ASTFXNode* nodePtr;
  204. };
  205. struct tagNodeOption
  206. {
  207. OptionType type;
  208. OptionData value;
  209. };
  210. struct tagNodeOptions
  211. {
  212. NodeOption* entries;
  213. int count;
  214. int bufferSize;
  215. };
  216. struct tagASTFXNode
  217. {
  218. NodeType type;
  219. NodeOptions* options;
  220. };
  221. extern OptionInfo OPTION_LOOKUP[OT_Count];
  222. NodeOptions* nodeOptionsCreate(void* context);
  223. void nodeOptionDelete(NodeOption* option);
  224. void nodeOptionsDelete(NodeOptions* options);
  225. void nodeOptionsResize(void* context, NodeOptions* options, int size);
  226. void nodeOptionsGrowIfNeeded(void* context, NodeOptions* options);
  227. void nodeOptionsAdd(void* context, NodeOptions* options, const NodeOption* option);
  228. ASTFXNode* nodeCreate(void* context, NodeType type);
  229. void nodeDelete(ASTFXNode* node);
  230. void nodePush(ParseState* parseState, ASTFXNode* node);
  231. void nodePop(ParseState* parseState);
  232. void beginCodeBlock(ParseState* parseState);
  233. void appendCodeBlock(ParseState* parseState, const char* value, int size);
  234. int getCodeBlockIndex(ParseState* parseState);
  235. void addDefine(ParseState* parseState, const char* value);
  236. void addDefineExpr(ParseState* parseState, const char* value);
  237. int hasDefine(ParseState* parseState, const char* value);
  238. void removeDefine(ParseState* parseState, const char* value);
  239. int pushConditional(ParseState* parseState, int state);
  240. int switchConditional(ParseState* parseState);
  241. int setConditional(ParseState* parseState, int state);
  242. int popConditional(ParseState* parseState);
  243. char* getCurrentFilename(ParseState* parseState);
  244. ParseState* parseStateCreate();
  245. void parseStateDelete(ParseState* parseState);
  246. #endif