BsASTFX.h 6.3 KB

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