BsASTFX.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. typedef enum tagNodeType NodeType;
  8. typedef enum tagOptionType OptionType;
  9. typedef enum tagOptionDataType OptionDataType;
  10. typedef enum tagParamType ParamType;
  11. typedef struct tagParseState ParseState;
  12. typedef struct tagOptionInfo OptionInfo;
  13. typedef union tagOptionData OptionData;
  14. typedef struct tagNodeOptions NodeOptions;
  15. typedef struct tagNodeOption NodeOption;
  16. typedef struct tagASTFXNode ASTFXNode;
  17. typedef struct tagNodeLink NodeLink;
  18. typedef struct tagIncludeData IncludeData;
  19. typedef struct tagIncludeLink IncludeLink;
  20. typedef struct tagConditionalData ConditionalData;
  21. typedef struct tagCodeString CodeString;
  22. typedef struct tagDefineEntry DefineEntry;
  23. typedef enum tagFillModeValue FillModeValue;
  24. typedef enum tagCullModeValue CullModeValue;
  25. typedef enum tagCompFuncValue CompFuncValue;
  26. typedef enum tagOpValue OpValue;
  27. typedef enum tagBlendOpValue BlendOpValue;
  28. typedef enum tagAddrModeValue AddrModeValue;
  29. typedef enum tagFilterValue FilterValue;
  30. typedef enum tagBufferUsageValue BufferUsageValue;
  31. typedef enum tagQueueSortTypeValue QueueSortTypeValue;
  32. enum tagNodeType
  33. {
  34. NT_Shader,
  35. NT_Technique,
  36. NT_Parameters,
  37. NT_Blocks,
  38. NT_Pass,
  39. NT_StencilOp,
  40. NT_Target,
  41. NT_BlendDef,
  42. NT_SamplerState,
  43. NT_AddrMode,
  44. NT_Parameter,
  45. NT_Block,
  46. NT_CodeVertex,
  47. NT_CodeFragment,
  48. NT_CodeGeometry,
  49. NT_CodeHull,
  50. NT_CodeDomain,
  51. NT_CodeCompute,
  52. NT_CodeCommon,
  53. };
  54. enum tagOptionType
  55. {
  56. OT_None = 0,
  57. OT_Separable,
  58. OT_Priority,
  59. OT_Sort,
  60. OT_Transparent,
  61. OT_Technique,
  62. OT_Renderer,
  63. OT_Language,
  64. OT_Pass,
  65. OT_FillMode,
  66. OT_CullMode,
  67. OT_DepthBias,
  68. OT_SDepthBias,
  69. OT_DepthClip,
  70. OT_Scissor,
  71. OT_Multisample,
  72. OT_AALine,
  73. OT_DepthRead,
  74. OT_DepthWrite,
  75. OT_CompareFunc,
  76. OT_Stencil,
  77. OT_StencilReadMask,
  78. OT_StencilWriteMask,
  79. OT_StencilOpFront,
  80. OT_StencilOpBack,
  81. OT_PassOp,
  82. OT_Fail,
  83. OT_ZFail,
  84. OT_AlphaToCoverage,
  85. OT_IndependantBlend,
  86. OT_Target,
  87. OT_Index,
  88. OT_Blend,
  89. OT_Color,
  90. OT_Alpha,
  91. OT_WriteMask,
  92. OT_Source,
  93. OT_Dest,
  94. OT_Op,
  95. OT_AddrMode,
  96. OT_MinFilter,
  97. OT_MagFilter,
  98. OT_MipFilter,
  99. OT_MaxAniso,
  100. OT_MipBias,
  101. OT_MipMin,
  102. OT_MipMax,
  103. OT_BorderColor,
  104. OT_U,
  105. OT_V,
  106. OT_W,
  107. OT_Alias,
  108. OT_Auto,
  109. OT_Shared,
  110. OT_Usage,
  111. OT_ParamType,
  112. OT_Identifier,
  113. OT_ParamValue,
  114. OT_ParamStrValue,
  115. OT_Parameters,
  116. OT_Blocks,
  117. OT_Parameter,
  118. OT_Block,
  119. OT_SamplerState,
  120. OT_Code,
  121. OT_StencilRef
  122. };
  123. enum tagOptionDataType
  124. {
  125. ODT_Int,
  126. ODT_Float,
  127. ODT_Bool,
  128. ODT_String,
  129. ODT_Complex,
  130. ODT_Matrix
  131. };
  132. enum tagParamType
  133. {
  134. PT_Float, PT_Float2, PT_Float3, PT_Float4,
  135. PT_Int, PT_Int2, PT_Int3, PT_Int4, PT_Color,
  136. PT_Mat2x2, PT_Mat2x3, PT_Mat2x4,
  137. PT_Mat3x2, PT_Mat3x3, PT_Mat3x4,
  138. PT_Mat4x2, PT_Mat4x3, PT_Mat4x4,
  139. PT_Sampler1D, PT_Sampler2D, PT_Sampler3D, PT_SamplerCUBE, PT_Sampler2DMS,
  140. PT_Texture1D, PT_Texture2D, PT_Texture3D, PT_TextureCUBE, PT_Texture2DMS,
  141. PT_ByteBuffer, PT_StructBuffer, PT_ByteBufferRW, PT_StructBufferRW,
  142. PT_TypedBufferRW, PT_AppendBuffer, PT_ConsumeBuffer,
  143. PT_Count // Keep at end
  144. };
  145. enum tagFillModeValue
  146. {
  147. FMV_Wire, FMV_Solid
  148. };
  149. enum tagCullModeValue
  150. {
  151. CMV_None, CMV_CW, CMV_CCW
  152. };
  153. enum tagCompFuncValue
  154. {
  155. CFV_Fail, CFV_Pass, CFV_LT, CFV_LTE,
  156. CFV_EQ, CFV_NEQ, CFV_GTE, CFV_GT
  157. };
  158. enum tagOpValue
  159. {
  160. OV_Keep, OV_Zero, OV_Replace, OV_Incr, OV_Decr,
  161. OV_IncrWrap, OV_DecrWrap, OV_Invert, OV_One, OV_DestColor,
  162. OV_SrcColor, OV_InvDestColor, OV_InvSrcColor, OV_DestAlpha,
  163. OV_SrcAlpha, OV_InvDestAlpha, OV_InvSrcAlpha
  164. };
  165. enum tagBlendOpValue
  166. {
  167. BOV_Add, BOV_Subtract, BOV_RevSubtract,
  168. BOV_Min, BOV_Max
  169. };
  170. enum tagAddrModeValue
  171. {
  172. AMV_Wrap, AMV_Mirror, AMV_Clamp, AMV_Border
  173. };
  174. enum tagFilterValue
  175. {
  176. FV_None, FV_Point, FV_Linear, FV_Anisotropic,
  177. FV_PointCmp, FV_LinearCmp, FV_AnisotropicCmp
  178. };
  179. enum tagBufferUsageValue
  180. {
  181. BUV_Static, BUV_Dynamic
  182. };
  183. enum tagQueueSortTypeValue
  184. {
  185. QST_FrontToBack, QST_BackToFront, QST_None
  186. };
  187. struct tagNodeLink
  188. {
  189. ASTFXNode* node;
  190. NodeLink* next;
  191. };
  192. struct tagIncludeData
  193. {
  194. char* filename;
  195. char* buffer;
  196. };
  197. struct tagIncludeLink
  198. {
  199. IncludeData* data;
  200. IncludeLink* next;
  201. };
  202. struct tagConditionalData
  203. {
  204. int selfEnabled;
  205. int enabled;
  206. ConditionalData* next;
  207. };
  208. struct tagCodeString
  209. {
  210. char* code;
  211. int index;
  212. int size;
  213. int capacity;
  214. CodeString* next;
  215. };
  216. struct tagDefineEntry
  217. {
  218. char* name;
  219. char* expr;
  220. };
  221. struct tagParseState
  222. {
  223. ASTFXNode* rootNode;
  224. ASTFXNode* topNode;
  225. void* memContext;
  226. int hasError;
  227. int errorLine;
  228. int errorColumn;
  229. const char* errorMessage;
  230. char* errorFile;
  231. NodeLink* nodeStack;
  232. IncludeLink* includeStack;
  233. IncludeLink* includes;
  234. CodeString* codeStrings;
  235. int numCodeStrings;
  236. int numOpenBrackets;
  237. DefineEntry* defines;
  238. int numDefines;
  239. int defineCapacity;
  240. ConditionalData* conditionalStack;
  241. };
  242. struct tagOptionInfo
  243. {
  244. OptionType type;
  245. OptionDataType dataType;
  246. };
  247. union tagOptionData
  248. {
  249. int intValue;
  250. float floatValue;
  251. const char* strValue;
  252. float matrixValue[16];
  253. int intVectorValue[4];
  254. ASTFXNode* nodePtr;
  255. };
  256. struct tagNodeOption
  257. {
  258. OptionType type;
  259. OptionData value;
  260. };
  261. struct tagNodeOptions
  262. {
  263. NodeOption* entries;
  264. int count;
  265. int bufferSize;
  266. };
  267. struct tagASTFXNode
  268. {
  269. NodeType type;
  270. NodeOptions* options;
  271. };
  272. OptionInfo OPTION_LOOKUP[];
  273. NodeOptions* nodeOptionsCreate(void* context);
  274. void nodeOptionDelete(NodeOption* option);
  275. void nodeOptionsDelete(NodeOptions* options);
  276. void nodeOptionsResize(void* context, NodeOptions* options, int size);
  277. void nodeOptionsGrowIfNeeded(void* context, NodeOptions* options);
  278. void nodeOptionsAdd(void* context, NodeOptions* options, const NodeOption* option);
  279. ASTFXNode* nodeCreate(void* context, NodeType type);
  280. void nodeDelete(ASTFXNode* node);
  281. void nodePush(ParseState* parseState, ASTFXNode* node);
  282. void nodePop(ParseState* parseState);
  283. void beginCodeBlock(ParseState* parseState);
  284. void appendCodeBlock(ParseState* parseState, const char* value, int size);
  285. int getCodeBlockIndex(ParseState* parseState);
  286. void addDefine(ParseState* parseState, const char* value);
  287. void addDefineExpr(ParseState* parseState, const char* value);
  288. int hasDefine(ParseState* parseState, const char* value);
  289. void removeDefine(ParseState* parseState, const char* value);
  290. int pushConditional(ParseState* parseState, int state);
  291. int switchConditional(ParseState* parseState);
  292. int setConditional(ParseState* parseState, int state);
  293. int popConditional(ParseState* parseState);
  294. char* getCurrentFilename(ParseState* parseState);
  295. ParseState* parseStateCreate();
  296. void parseStateDelete(ParseState* parseState);
  297. #endif