2
0

BsASTFX.h 7.0 KB

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