BsASTFX.h 6.0 KB

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