BsASTFX.h 5.3 KB

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