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