1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | |
---|
30 | #ifndef __CompositorScriptScompiler_H__ |
---|
31 | #define __CompositorScriptScompiler_H__ |
---|
32 | |
---|
33 | #include "OgrePrerequisites.h" |
---|
34 | #include "OgreCompiler2Pass.h" |
---|
35 | #include "OgreCompositor.h" |
---|
36 | #include "OgreRenderSystem.h" |
---|
37 | |
---|
38 | |
---|
39 | namespace Ogre { |
---|
40 | |
---|
41 | /** Compiler for parsing & lexing .compositor scripts */ |
---|
42 | class _OgreExport CompositorScriptCompiler : public Compiler2Pass |
---|
43 | { |
---|
44 | |
---|
45 | public: |
---|
46 | CompositorScriptCompiler(void); |
---|
47 | ~CompositorScriptCompiler(void); |
---|
48 | |
---|
49 | /** gets BNF Grammer for Compositor script. |
---|
50 | */ |
---|
51 | virtual const String& getClientBNFGrammer(void) const; |
---|
52 | |
---|
53 | /** get the name of the Compositor script BNF grammer. |
---|
54 | */ |
---|
55 | virtual const String& getClientGrammerName(void) const; |
---|
56 | |
---|
57 | /** Compile a compositor script from a data stream using a specific resource group name. |
---|
58 | @param stream Weak reference to a data stream which is the source of the material script |
---|
59 | @param groupName The name of the resource group that resources which are |
---|
60 | parsed are to become a member of. If this group is loaded or unloaded, |
---|
61 | then the resources discovered in this script will be loaded / unloaded |
---|
62 | with it. |
---|
63 | */ |
---|
64 | void parseScript(DataStreamPtr& stream, const String& groupName) |
---|
65 | { |
---|
66 | mScriptContext.groupName = groupName; |
---|
67 | Compiler2Pass::compile(stream->getAsString(), stream->getName()); |
---|
68 | } |
---|
69 | |
---|
70 | protected: |
---|
71 | // Token ID enumeration |
---|
72 | enum TokenID { |
---|
73 | // Terminal Tokens section |
---|
74 | ID_UNKOWN = 0, |
---|
75 | // Techniques |
---|
76 | ID_TARGET_WIDTH, ID_TARGET_HEIGHT, |
---|
77 | ID_PF_A8R8G8B8, ID_PF_R8G8B8A8, ID_PF_R8G8B8, |
---|
78 | ID_PF_FLOAT16_R, ID_PF_FLOAT16_RGB, ID_PF_FLOAT16_RGBA, |
---|
79 | ID_PF_FLOAT32_R, ID_PF_FLOAT32_RGB, ID_PF_FLOAT32_RGBA, |
---|
80 | ID_PF_FLOAT16_GR, ID_PF_FLOAT32_GR, |
---|
81 | // Targets |
---|
82 | ID_PREVIOUS, ID_NONE, |
---|
83 | // Passes |
---|
84 | ID_RENDER_QUAD, ID_CLEAR, ID_STENCIL, ID_RENDER_SCENE, |
---|
85 | // Clear section |
---|
86 | ID_CLR_COLOUR, ID_CLR_DEPTH, |
---|
87 | // Stencil section |
---|
88 | |
---|
89 | // compare functions |
---|
90 | ID_ST_ALWAYS_FAIL, ID_ST_ALWAYS_PASS, ID_ST_LESS, |
---|
91 | ID_ST_LESS_EQUAL, ID_ST_EQUAL, ID_ST_NOT_EQUAL, |
---|
92 | ID_ST_GREATER_EQUAL, ID_ST_GREATER, |
---|
93 | |
---|
94 | // stencil operations |
---|
95 | ID_ST_KEEP, ID_ST_ZERO, ID_ST_REPLACE, ID_ST_INCREMENT, |
---|
96 | ID_ST_DECREMENT, ID_ST_INCREMENT_WRAP, ID_ST_DECREMENT_WRAP, |
---|
97 | ID_ST_INVERT, |
---|
98 | |
---|
99 | // general |
---|
100 | ID_ON, ID_OFF, ID_TRUE, ID_FALSE, |
---|
101 | // where auto generated tokens start so donot remove |
---|
102 | ID_AUTOTOKENSTART |
---|
103 | }; |
---|
104 | |
---|
105 | /** Enum to identify compositor sections. */ |
---|
106 | enum CompositorScriptSection |
---|
107 | { |
---|
108 | CSS_NONE, |
---|
109 | CSS_COMPOSITOR, |
---|
110 | CSS_TECHNIQUE, |
---|
111 | CSS_TARGET, |
---|
112 | CSS_PASS |
---|
113 | }; |
---|
114 | /** Struct for holding the script context while parsing. */ |
---|
115 | struct CompositorScriptContext |
---|
116 | { |
---|
117 | CompositorScriptSection section; |
---|
118 | String groupName; |
---|
119 | CompositorPtr compositor; |
---|
120 | CompositionTechnique* technique; |
---|
121 | CompositionTargetPass* target; |
---|
122 | CompositionPass* pass; |
---|
123 | }; |
---|
124 | |
---|
125 | CompositorScriptContext mScriptContext; |
---|
126 | |
---|
127 | typedef void (CompositorScriptCompiler::* CSC_Action)(void); |
---|
128 | typedef std::map<size_t, CSC_Action> TokenActionMap; |
---|
129 | typedef TokenActionMap::iterator TokenActionIterator; |
---|
130 | /** Map of Token value as key to an Action. An Action converts tokens into |
---|
131 | the final format. |
---|
132 | All instances use the same Token Action Map. |
---|
133 | */ |
---|
134 | static TokenActionMap mTokenActionMap; |
---|
135 | |
---|
136 | /** Execute an Action associated with a token. Gets called when the compiler finishes tokenizing a |
---|
137 | section of the source that has been parsed. |
---|
138 | **/ |
---|
139 | virtual void executeTokenAction(const size_t tokenID); |
---|
140 | /** Get the start position of auto generated token IDs. |
---|
141 | */ |
---|
142 | virtual size_t getAutoTokenIDStart() const {return ID_AUTOTOKENSTART;} |
---|
143 | /** Associate all the lexemes used in a material script with their corresponding tokens and actions. |
---|
144 | **/ |
---|
145 | virtual void setupTokenDefinitions(void); |
---|
146 | void addLexemeTokenAction(const String& lexeme, const size_t token, const CSC_Action action = 0); |
---|
147 | void addLexemeAction(const String& lexeme, const CSC_Action action) { addLexemeTokenAction(lexeme, 0, action); } |
---|
148 | |
---|
149 | void logParseError(const String& error); |
---|
150 | |
---|
151 | // Token Actions which get called when tokens are created during parsing. |
---|
152 | void parseOpenBrace(void); |
---|
153 | void parseCloseBrace(void); |
---|
154 | void parseCompositor(void); |
---|
155 | void parseTechnique(void); |
---|
156 | void parseTexture(void); |
---|
157 | void parseTarget(void); |
---|
158 | void parseInput(void); |
---|
159 | void parseTargetOutput(void); |
---|
160 | void parseOnlyInitial(void); |
---|
161 | void parseVisibilityMask(void); |
---|
162 | void parseLodBias(void); |
---|
163 | void parseMaterialScheme(void); |
---|
164 | void parsePass(void); |
---|
165 | void parseMaterial(void); |
---|
166 | void parseFirstRenderQueue(void); |
---|
167 | void parseLastRenderQueue(void); |
---|
168 | void parseIdentifier(void); |
---|
169 | void parseClearBuffers(void); |
---|
170 | void parseClearColourValue(void); |
---|
171 | void parseClearDepthValue(void); |
---|
172 | void parseClearStencilValue(void); |
---|
173 | void parseStencilCheck(void); |
---|
174 | void parseStencilFunc(void); |
---|
175 | void parseStencilRefVal(void); |
---|
176 | void parseStencilMask(void); |
---|
177 | void parseStencilFailOp(void); |
---|
178 | void parseStencilDepthFailOp(void); |
---|
179 | void parseStencilPassOp(void); |
---|
180 | void parseStencilTwoSided(void); |
---|
181 | StencilOperation extractStencilOp(void); |
---|
182 | CompareFunction extractCompareFunc(void); |
---|
183 | }; |
---|
184 | } |
---|
185 | |
---|
186 | #endif |
---|