2
0

BsASTFX.h 7.1 KB

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