1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#ifndef __ASTFX_H__
4#define __ASTFX_H__
5
6#include <stdlib.h>
7#include <string.h>
8
9enum tagNodeType
10{
11 NT_Root,
12 NT_Options,
13 NT_Shader,
14 NT_SubShader,
15 NT_Mixin,
16 NT_Pass,
17 NT_Blend,
18 NT_Raster,
19 NT_Depth,
20 NT_Stencil,
21 NT_Target,
22 NT_StencilOp,
23 NT_BlendDef,
24 NT_Tags,
25 NT_Code,
26 NT_Variations,
27 NT_Variation,
28 NT_VariationOption,
29 NT_Attributes
30};
31
32enum tagOptionType
33{
34 OT_None = 0,
35 OT_Options,
36 OT_Separable,
37 OT_Priority,
38 OT_Sort,
39 OT_Transparent,
40 OT_Shader,
41 OT_SubShader,
42 OT_Mixin,
43 OT_Raster,
44 OT_Depth,
45 OT_Stencil,
46 OT_Blend,
47 OT_FeatureSet,
48 OT_Pass,
49 OT_FillMode,
50 OT_CullMode,
51 OT_DepthBias,
52 OT_SDepthBias,
53 OT_DepthClip,
54 OT_Scissor,
55 OT_Multisample,
56 OT_AALine,
57 OT_DepthRead,
58 OT_DepthWrite,
59 OT_CompareFunc,
60 OT_StencilReadMask,
61 OT_StencilWriteMask,
62 OT_StencilOpFront,
63 OT_StencilOpBack,
64 OT_PassOp,
65 OT_Fail,
66 OT_ZFail,
67 OT_AlphaToCoverage,
68 OT_IndependantBlend,
69 OT_Target,
70 OT_Index,
71 OT_Enabled,
72 OT_Color,
73 OT_Alpha,
74 OT_WriteMask,
75 OT_Source,
76 OT_Dest,
77 OT_Op,
78 OT_Identifier,
79 OT_Code,
80 OT_StencilRef,
81 OT_Tags,
82 OT_TagValue,
83 OT_Variations,
84 OT_Variation,
85 OT_VariationValue,
86 OT_Forward,
87 OT_Attributes,
88 OT_AttrName,
89 OT_VariationOption,
90 OT_AttrShow,
91 OT_Count
92};
93
94enum tagOptionDataType
95{
96 ODT_Int,
97 ODT_Float,
98 ODT_Bool,
99 ODT_String,
100 ODT_Complex,
101 ODT_Matrix
102};
103
104enum tagFillModeValue
105{
106 FMV_Wire, FMV_Solid
107};
108
109enum tagCullAndSortModeValue
110{
111 CASV_None, CASV_CW, CASV_CCW, CASV_FrontToBack, CASV_BackToFront
112};
113
114enum tagCompFuncValue
115{
116 CFV_Fail, CFV_Pass, CFV_LT, CFV_LTE,
117 CFV_EQ, CFV_NEQ, CFV_GTE, CFV_GT
118};
119
120enum tagOpValue
121{
122 OV_Keep, OV_Zero, OV_Replace, OV_Incr, OV_Decr,
123 OV_IncrWrap, OV_DecrWrap, OV_Invert, OV_One, OV_DestColor,
124 OV_SrcColor, OV_InvDestColor, OV_InvSrcColor, OV_DestAlpha,
125 OV_SrcAlpha, OV_InvDestAlpha, OV_InvSrcAlpha
126};
127
128enum tagBlendOpValue
129{
130 BOV_Add, BOV_Subtract, BOV_RevSubtract,
131 BOV_Min, BOV_Max
132};
133
134enum tagRawCodeType
135{
136 RCT_CodeBlock,
137 RCT_SubShaderBlock,
138 RCT_Count
139};
140
141enum tagConditionalOp
142{
143 CO_None, CO_Equals, CO_NotEquals, CO_Lesser, CO_Greater, CO_LesserEqual, CO_GreaterEqual
144};
145
146typedef enum tagNodeType NodeType;
147typedef enum tagOptionType OptionType;
148typedef enum tagOptionDataType OptionDataType;
149typedef struct tagParseState ParseState;
150typedef struct tagOptionInfo OptionInfo;
151typedef union tagOptionData OptionData;
152typedef struct tagNodeOptions NodeOptions;
153typedef struct tagNodeOption NodeOption;
154typedef struct tagASTFXNode ASTFXNode;
155typedef struct tagNodeLink NodeLink;
156typedef struct tagIncludeData IncludeData;
157typedef struct tagIncludeLink IncludeLink;
158typedef struct tagConditionalData ConditionalData;
159typedef struct tagRawCode RawCode;
160typedef struct tagDefineEntry DefineEntry;
161typedef enum tagFillModeValue FillModeValue;
162typedef enum tagCullAndSortModeValue CullAndSortModeValue;
163typedef enum tagCompFuncValue CompFuncValue;
164typedef enum tagOpValue OpValue;
165typedef enum tagBlendOpValue BlendOpValue;
166typedef enum tagRawCodeType RawCodeType;
167typedef enum tagConditionalOp ConditionalOp;
168
169struct tagNodeLink
170{
171 ASTFXNode* node;
172 NodeLink* next;
173};
174
175struct tagIncludeData
176{
177 char* filename;
178 char* buffer;
179};
180
181struct tagIncludeLink
182{
183 IncludeData* data;
184 IncludeLink* next;
185};
186
187struct tagConditionalData
188{
189 char* name;
190 int selfEnabled;
191 int enabled;
192 ConditionalOp op;
193 char* value;
194
195 ConditionalData* next;
196};
197
198struct tagRawCode
199{
200 char* code;
201 int index;
202 int size;
203 int capacity;
204
205 RawCode* next;
206};
207
208struct tagDefineEntry
209{
210 char* name;
211 char* expr;
212};
213
214struct tagParseState
215{
216 ASTFXNode* rootNode;
217 ASTFXNode* topNode;
218 void* memContext;
219
220 int hasError;
221 int errorLine;
222 int errorColumn;
223 const char* errorMessage;
224 char* errorFile;
225
226 NodeLink* nodeStack;
227 IncludeLink* includeStack;
228 IncludeLink* includes;
229 RawCode* rawCodeBlock[RCT_Count];
230 int numRawCodeBlocks[RCT_Count];
231 int numOpenBrackets;
232
233 DefineEntry* defines;
234 int numDefines;
235 int defineCapacity;
236 ConditionalData* conditionalStack;
237};
238
239struct tagOptionInfo
240{
241 OptionType type;
242 OptionDataType dataType;
243};
244
245union tagOptionData
246{
247 int intValue;
248 float floatValue;
249 const char* strValue;
250 float matrixValue[16];
251 int intVectorValue[4];
252 ASTFXNode* nodePtr;
253};
254
255struct tagNodeOption
256{
257 OptionType type;
258 OptionData value;
259};
260
261struct tagNodeOptions
262{
263 NodeOption* entries;
264
265 int count;
266 int bufferSize;
267};
268
269struct tagASTFXNode
270{
271 NodeType type;
272 NodeOptions* options;
273};
274
275extern OptionInfo OPTION_LOOKUP[OT_Count];
276
277NodeOptions* nodeOptionsCreate(void* context);
278void nodeOptionDelete(NodeOption* option);
279void nodeOptionsDelete(NodeOptions* options);
280void nodeOptionsResize(void* context, NodeOptions* options, int size);
281void nodeOptionsGrowIfNeeded(void* context, NodeOptions* options);
282void nodeOptionsAdd(void* context, NodeOptions* options, const NodeOption* option);
283
284ASTFXNode* nodeCreate(void* context, NodeType type);
285void nodeDelete(ASTFXNode* node);
286
287void nodePush(ParseState* parseState, ASTFXNode* node);
288void nodePop(ParseState* parseState);
289
290void beginCodeBlock(ParseState* parseState, RawCodeType type);
291void appendCodeBlock(ParseState* parseState, RawCodeType type, const char* value, int size);
292int getCodeBlockIndex(ParseState* parseState, RawCodeType type);
293
294void addDefine(ParseState* parseState, const char* value);
295void addDefineExpr(ParseState* parseState, const char* value);
296int hasDefine(ParseState* parseState, const char* value);
297void removeDefine(ParseState* parseState, const char* value);
298
299int pushConditionalDef(ParseState* parseState, int state);
300void pushConditional(ParseState* parseState, const char* name);
301void setConditionalOp(ParseState* parseState, ConditionalOp op);
302void setConditionalVal(ParseState* parseState, const char* value);
303int evalConditional(ParseState* parseState);
304int switchConditional(ParseState* parseState);
305void setConditional(ParseState* parseState, const char* name);
306int popConditional(ParseState* parseState);
307
308char* getCurrentFilename(ParseState* parseState);
309
310ParseState* parseStateCreate();
311void parseStateDelete(ParseState* parseState);
312
313#endif