BsASTFX.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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_ByteBuffer, PT_StructBuffer, PT_ByteBufferRW, PT_StructBufferRW,
  118. PT_TypedBufferRW, PT_AppendBuffer, PT_ConsumeBuffer,
  119. PT_Count // Keep at end
  120. };
  121. enum tagFillModeValue
  122. {
  123. FMV_Wire, FMV_Solid
  124. };
  125. enum tagCullModeValue
  126. {
  127. CMV_None, CMV_CW, CMV_CCW
  128. };
  129. enum tagCompFuncValue
  130. {
  131. CFV_Fail, CFV_Pass, CFV_LT, CFV_LTE,
  132. CFV_EQ, CFV_NEQ, CFV_GTE, CFV_GT
  133. };
  134. enum tagOpValue
  135. {
  136. OV_Keep, OV_Zero, OV_Replace, OV_Incr, OV_Decr,
  137. OV_IncrWrap, OV_DecrWrap, OV_Invert, OV_One, OV_DestColor,
  138. OV_SrcColor, OV_InvDestColor, OV_InvSrcColor, OV_DestAlpha,
  139. OV_SrcAlpha, OV_InvDestAlpha, OV_InvSrcAlpha
  140. };
  141. enum tagBlendOpValue
  142. {
  143. BOV_Add, BOV_Subtract, BOV_RevSubtract,
  144. BOV_Min, BOV_Max
  145. };
  146. enum tagAddrModeValue
  147. {
  148. AMV_Wrap, AMV_Mirror, AMV_Clamp, AMV_Border
  149. };
  150. enum tagFilterValue
  151. {
  152. FV_None, FV_Point, FV_Linear, FV_Anisotropic,
  153. FV_PointCmp, FV_LinearCmp, FV_AnisotropicCmp
  154. };
  155. enum tagBufferUsageValue
  156. {
  157. BUV_Static, BUV_Dynamic
  158. };
  159. enum tagQueueSortTypeValue
  160. {
  161. QST_FrontToBack, QST_BackToFront, QST_None
  162. };
  163. typedef enum tagNodeType NodeType;
  164. typedef enum tagOptionType OptionType;
  165. typedef enum tagOptionDataType OptionDataType;
  166. typedef enum tagParamType ParamType;
  167. typedef struct tagParseState ParseState;
  168. typedef struct tagOptionInfo OptionInfo;
  169. typedef union tagOptionData OptionData;
  170. typedef struct tagNodeOptions NodeOptions;
  171. typedef struct tagNodeOption NodeOption;
  172. typedef struct tagASTFXNode ASTFXNode;
  173. typedef struct tagNodeLink NodeLink;
  174. typedef struct tagIncludeData IncludeData;
  175. typedef struct tagIncludeLink IncludeLink;
  176. typedef struct tagConditionalData ConditionalData;
  177. typedef struct tagCodeString CodeString;
  178. typedef struct tagDefineEntry DefineEntry;
  179. typedef enum tagFillModeValue FillModeValue;
  180. typedef enum tagCullModeValue CullModeValue;
  181. typedef enum tagCompFuncValue CompFuncValue;
  182. typedef enum tagOpValue OpValue;
  183. typedef enum tagBlendOpValue BlendOpValue;
  184. typedef enum tagAddrModeValue AddrModeValue;
  185. typedef enum tagFilterValue FilterValue;
  186. typedef enum tagBufferUsageValue BufferUsageValue;
  187. typedef enum tagQueueSortTypeValue QueueSortTypeValue;
  188. struct tagNodeLink
  189. {
  190. ASTFXNode* node;
  191. NodeLink* next;
  192. };
  193. struct tagIncludeData
  194. {
  195. char* filename;
  196. char* buffer;
  197. };
  198. struct tagIncludeLink
  199. {
  200. IncludeData* data;
  201. IncludeLink* next;
  202. };
  203. struct tagConditionalData
  204. {
  205. int selfEnabled;
  206. int enabled;
  207. ConditionalData* next;
  208. };
  209. struct tagCodeString
  210. {
  211. char* code;
  212. int index;
  213. int size;
  214. int capacity;
  215. CodeString* next;
  216. };
  217. struct tagDefineEntry
  218. {
  219. char* name;
  220. char* expr;
  221. };
  222. struct tagParseState
  223. {
  224. ASTFXNode* rootNode;
  225. ASTFXNode* topNode;
  226. void* memContext;
  227. int hasError;
  228. int errorLine;
  229. int errorColumn;
  230. const char* errorMessage;
  231. char* errorFile;
  232. NodeLink* nodeStack;
  233. IncludeLink* includeStack;
  234. IncludeLink* includes;
  235. CodeString* codeStrings;
  236. int numCodeStrings;
  237. int numOpenBrackets;
  238. DefineEntry* defines;
  239. int numDefines;
  240. int defineCapacity;
  241. ConditionalData* conditionalStack;
  242. };
  243. struct tagOptionInfo
  244. {
  245. OptionType type;
  246. OptionDataType dataType;
  247. };
  248. union tagOptionData
  249. {
  250. int intValue;
  251. float floatValue;
  252. const char* strValue;
  253. float matrixValue[16];
  254. int intVectorValue[4];
  255. ASTFXNode* nodePtr;
  256. };
  257. struct tagNodeOption
  258. {
  259. OptionType type;
  260. OptionData value;
  261. };
  262. struct tagNodeOptions
  263. {
  264. NodeOption* entries;
  265. int count;
  266. int bufferSize;
  267. };
  268. struct tagASTFXNode
  269. {
  270. NodeType type;
  271. NodeOptions* options;
  272. };
  273. extern OptionInfo OPTION_LOOKUP[OT_Count];
  274. NodeOptions* nodeOptionsCreate(void* context);
  275. void nodeOptionDelete(NodeOption* option);
  276. void nodeOptionsDelete(NodeOptions* options);
  277. void nodeOptionsResize(void* context, NodeOptions* options, int size);
  278. void nodeOptionsGrowIfNeeded(void* context, NodeOptions* options);
  279. void nodeOptionsAdd(void* context, NodeOptions* options, const NodeOption* option);
  280. ASTFXNode* nodeCreate(void* context, NodeType type);
  281. void nodeDelete(ASTFXNode* node);
  282. void nodePush(ParseState* parseState, ASTFXNode* node);
  283. void nodePop(ParseState* parseState);
  284. void beginCodeBlock(ParseState* parseState);
  285. void appendCodeBlock(ParseState* parseState, const char* value, int size);
  286. int getCodeBlockIndex(ParseState* parseState);
  287. void addDefine(ParseState* parseState, const char* value);
  288. void addDefineExpr(ParseState* parseState, const char* value);
  289. int hasDefine(ParseState* parseState, const char* value);
  290. void removeDefine(ParseState* parseState, const char* value);
  291. int pushConditional(ParseState* parseState, int state);
  292. int switchConditional(ParseState* parseState);
  293. int setConditional(ParseState* parseState, int state);
  294. int popConditional(ParseState* parseState);
  295. char* getCurrentFilename(ParseState* parseState);
  296. ParseState* parseStateCreate();
  297. void parseStateDelete(ParseState* parseState);
  298. #endif