BsASTFX.h 6.8 KB

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