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 | #include "OgreStableHeaders.h" |
---|
30 | #include "OgreCompositorScriptCompiler.h" |
---|
31 | #include "OgreCommon.h" |
---|
32 | #include "OgreStringConverter.h" |
---|
33 | #include "OgreLogManager.h" |
---|
34 | #include "OgreException.h" |
---|
35 | #include "OgreCompositorManager.h" |
---|
36 | #include "OgreCompositionTechnique.h" |
---|
37 | #include "OgreCompositionTargetPass.h" |
---|
38 | #include "OgreCompositionPass.h" |
---|
39 | |
---|
40 | namespace Ogre { |
---|
41 | |
---|
42 | //----------------------------------------------------------------------- |
---|
43 | // Static definitions |
---|
44 | //----------------------------------------------------------------------- |
---|
45 | CompositorScriptCompiler::TokenActionMap CompositorScriptCompiler::mTokenActionMap; |
---|
46 | |
---|
47 | const String& CompositorScriptCompiler::getClientBNFGrammer(void) const |
---|
48 | { |
---|
49 | // simplified Backus - Naur Form (BNF) grammer for compositor scripts |
---|
50 | static const String compositorScript_BNF = |
---|
51 | // Top level rule |
---|
52 | "<Script> ::= {<Compositor>} \n" |
---|
53 | "<Compositor> ::= 'compositor' <Flex_Label> '{' {<Technique>} '}' \n" |
---|
54 | // Technique |
---|
55 | "<Technique> ::= 'technique' '{' {<Texture>} {<Target>} <TargetOutput> '}' \n" |
---|
56 | "<Texture> ::= 'texture' <Label> <WidthOption> <HeightOption> <PixelFormat> \n" |
---|
57 | "<WidthOption> ::= 'target_width' | <#width> \n" |
---|
58 | "<HeightOption> ::= 'target_height' | <#height> \n" |
---|
59 | "<PixelFormat> ::= 'PF_A8R8G8B8' | 'PF_R8G8B8A8' | 'PF_R8G8B8' | 'PF_FLOAT16_RGBA' | \n" |
---|
60 | " 'PF_FLOAT16_RGB' | 'PF_FLOAT16_R' | 'PF_FLOAT32_RGBA' | 'PF_FLOAT32_RGB' | 'PF_FLOAT32_R' | \n" |
---|
61 | " 'PF_FLOAT16_GR' | 'PF_FLOAT32_GR' \n" |
---|
62 | // Target |
---|
63 | "<Target> ::= 'target ' <Label> '{' {<TargetOptions>} {<Pass>} '}' \n" |
---|
64 | "<TargetOptions> ::= <TargetInput> | <OnlyInitial> | <VisibilityMask> | \n" |
---|
65 | " <LodBias> | <MaterialScheme> \n" |
---|
66 | "<TargetInput> ::= 'input' <TargetInputOptions> \n" |
---|
67 | "<TargetInputOptions> ::= 'none' | 'previous' \n" |
---|
68 | "<OnlyInitial> ::= 'only_initial' <On_Off> \n" |
---|
69 | "<VisibilityMask> ::= 'visibility_mask' <#mask> \n" |
---|
70 | "<LodBias> ::= 'lod_bias' <#lodbias> \n" |
---|
71 | "<MaterialScheme> ::= 'material_scheme' <Label> \n" |
---|
72 | "<TargetOutput> ::= 'target_output' '{' [<TargetInput>] {<Pass>} '}' \n" |
---|
73 | // Pass |
---|
74 | "<Pass> ::= 'pass' <PassTypes> '{' {<PassOptions>} '}' \n" |
---|
75 | "<PassTypes> ::= 'render_quad' | 'clear' | 'stencil' | 'render_scene' \n" |
---|
76 | "<PassOptions> ::= <PassFirstRenderQueue> | <PassLastRenderQueue> | \n" |
---|
77 | " <PassIdentifier> | <PassMaterial> | <PassInput> | <ClearSection> | <StencilSection> \n" |
---|
78 | "<PassMaterial> ::= 'material' <Label> \n" |
---|
79 | "<PassInput> ::= 'input' <#id> <Label> \n" |
---|
80 | "<PassFirstRenderQueue> ::= 'first_render_queue' <#queue> \n" |
---|
81 | "<PassLastRenderQueue> ::= 'last_render_queue' <#queue> \n" |
---|
82 | "<PassIdentifier> ::= 'identifier' <#id> \n" |
---|
83 | // clear |
---|
84 | "<ClearSection> ::= -'clear' -'{' {<ClearOptions>} -'}' \n" |
---|
85 | "<ClearOptions> ::= <Buffers> | <ColourValue> | <DepthValue> | <StencilValue> \n" |
---|
86 | "<Buffers> ::= 'buffers' {<BufferTypes>} \n" |
---|
87 | "<BufferTypes> ::= <Colour> | <Depth> | <Stencil> \n" |
---|
88 | "<Colour> ::= 'colour' (?!<ValueChk>) \n" |
---|
89 | "<Depth> ::= 'depth' (?!<ValueChk>) \n" |
---|
90 | "<Stencil> ::= 'stencil' (?!<ValueChk>) \n" |
---|
91 | "<ValueChk> ::= '_value' \n" |
---|
92 | "<ColourValue> ::= 'colour_value' <#red> <#green> <#blue> <#alpha> \n" |
---|
93 | "<DepthValue> ::= 'depth_value' <#depth> \n" |
---|
94 | "<StencilValue> ::= 'stencil_value' <#val> \n" |
---|
95 | // stencil |
---|
96 | "<StencilSection> ::= -'stencil' -'{' {<StencilOptions>} -'}' \n" |
---|
97 | "<StencilOptions> ::= <Check> | <CompareFunction> | <RefVal> | <Mask> | <FailOp> | <DepthFailOp> | \n" |
---|
98 | " <PassOp> | <TwoSided> \n" |
---|
99 | "<Check> ::= 'check' <On_Off> \n" |
---|
100 | "<CompareFunction> ::= 'comp_func' <CompFunc> \n" |
---|
101 | "<CompFunc> ::= 'always_fail' | 'always_pass' | 'less_equal' | 'less' | 'equal' | \n" |
---|
102 | " 'not_equal' | 'equal' | 'greater_equal' | 'greater' \n" |
---|
103 | "<RefVal> ::= 'ref_value' <#val> \n" |
---|
104 | "<Mask> ::= 'mask' <#mask> \n" |
---|
105 | "<FailOp> ::= 'fail_op' <StencilOperation> \n" |
---|
106 | "<DepthFailOp> ::= 'depth_fail_op' <StencilOperation> \n" |
---|
107 | "<PassOp> ::= 'pass_op' <StencilOperation> \n" |
---|
108 | "<TwoSided> ::= 'two_sided' <On_Off> \n" |
---|
109 | "<StencilOperation> ::= 'keep' | 'zero' | 'replace' | 'increment_wrap' | 'increment' | \n" |
---|
110 | " 'decrement_wrap' | 'decrement' | 'invert' \n" |
---|
111 | |
---|
112 | // common rules |
---|
113 | "<On_Off> ::= 'on' | 'off' \n" |
---|
114 | "<Label> ::= <Quoted_Label> | <Unquoted_Label> \n" |
---|
115 | "<Flex_Label> ::= <Quoted_Label> | <Spaced_Label> \n" |
---|
116 | "<Quoted_Label> ::= -'\"' <Spaced_Label> -'\"' \n" |
---|
117 | "<Spaced_Label> ::= <Spaced_Label_Illegals> {<Spaced_Label_Illegals>} \n" |
---|
118 | "<Unquoted_Label> ::= <Unquoted_Label_Illegals> {<Unquoted_Label_Illegals>} \n" |
---|
119 | "<Spaced_Label_Illegals> ::= (!,\n\r\t{}\") \n" |
---|
120 | "<Unquoted_Label_Illegals> ::= (! \n\r\t{}\") \n" |
---|
121 | |
---|
122 | ; |
---|
123 | |
---|
124 | return compositorScript_BNF; |
---|
125 | } |
---|
126 | //----------------------------------------------------------------------- |
---|
127 | const String& CompositorScriptCompiler::getClientGrammerName(void) const |
---|
128 | { |
---|
129 | static const String grammerName = "Compositor Script"; |
---|
130 | return grammerName; |
---|
131 | } |
---|
132 | //----------------------------------------------------------------------- |
---|
133 | CompositorScriptCompiler::CompositorScriptCompiler(void) |
---|
134 | { |
---|
135 | // set default group resource name |
---|
136 | mScriptContext.groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME; |
---|
137 | } |
---|
138 | //----------------------------------------------------------------------- |
---|
139 | CompositorScriptCompiler::~CompositorScriptCompiler(void) |
---|
140 | { |
---|
141 | |
---|
142 | } |
---|
143 | //----------------------------------------------------------------------- |
---|
144 | void CompositorScriptCompiler::setupTokenDefinitions(void) |
---|
145 | { |
---|
146 | addLexemeAction("{", &CompositorScriptCompiler::parseOpenBrace); |
---|
147 | addLexemeAction("}", &CompositorScriptCompiler::parseCloseBrace); |
---|
148 | addLexemeAction("compositor", &CompositorScriptCompiler::parseCompositor); |
---|
149 | |
---|
150 | // Technique section |
---|
151 | addLexemeAction("technique", &CompositorScriptCompiler::parseTechnique); |
---|
152 | addLexemeAction("texture", &CompositorScriptCompiler::parseTexture); |
---|
153 | addLexemeToken("target_width", ID_TARGET_WIDTH); |
---|
154 | addLexemeToken("target_height", ID_TARGET_HEIGHT); |
---|
155 | addLexemeToken("PF_A8R8G8B8", ID_PF_A8R8G8B8); |
---|
156 | addLexemeToken("PF_R8G8B8A8", ID_PF_R8G8B8A8); |
---|
157 | addLexemeToken("PF_R8G8B8", ID_PF_R8G8B8); |
---|
158 | addLexemeToken("PF_FLOAT16_R", ID_PF_FLOAT16_R); |
---|
159 | addLexemeToken("PF_FLOAT16_GR", ID_PF_FLOAT16_GR); |
---|
160 | addLexemeToken("PF_FLOAT16_RGB", ID_PF_FLOAT16_RGB); |
---|
161 | addLexemeToken("PF_FLOAT16_RGBA", ID_PF_FLOAT16_RGBA); |
---|
162 | addLexemeToken("PF_FLOAT32_R", ID_PF_FLOAT32_R); |
---|
163 | addLexemeToken("PF_FLOAT32_GR", ID_PF_FLOAT32_GR); |
---|
164 | addLexemeToken("PF_FLOAT32_RGB", ID_PF_FLOAT32_RGB); |
---|
165 | addLexemeToken("PF_FLOAT32_RGBA", ID_PF_FLOAT32_RGBA); |
---|
166 | |
---|
167 | // Target section |
---|
168 | addLexemeAction("target ", &CompositorScriptCompiler::parseTarget); |
---|
169 | addLexemeAction("input", &CompositorScriptCompiler::parseInput); |
---|
170 | addLexemeToken("none", ID_NONE); |
---|
171 | addLexemeToken("previous", ID_PREVIOUS); |
---|
172 | addLexemeAction("target_output", &CompositorScriptCompiler::parseTargetOutput); |
---|
173 | addLexemeAction("only_initial", &CompositorScriptCompiler::parseOnlyInitial); |
---|
174 | addLexemeAction("visibility_mask", &CompositorScriptCompiler::parseVisibilityMask); |
---|
175 | addLexemeAction("lod_bias", &CompositorScriptCompiler::parseLodBias); |
---|
176 | addLexemeAction("material_scheme", &CompositorScriptCompiler::parseMaterialScheme); |
---|
177 | |
---|
178 | // pass section |
---|
179 | addLexemeAction("pass", &CompositorScriptCompiler::parsePass); |
---|
180 | // input defined above |
---|
181 | addLexemeToken("render_quad", ID_RENDER_QUAD); |
---|
182 | addLexemeToken("clear", ID_CLEAR); |
---|
183 | addLexemeToken("stencil", ID_STENCIL); |
---|
184 | addLexemeToken("render_scene", ID_RENDER_SCENE); |
---|
185 | // pass attributes |
---|
186 | addLexemeAction("material", &CompositorScriptCompiler::parseMaterial); |
---|
187 | addLexemeAction("first_render_queue", &CompositorScriptCompiler::parseFirstRenderQueue); |
---|
188 | addLexemeAction("last_render_queue", &CompositorScriptCompiler::parseLastRenderQueue); |
---|
189 | addLexemeAction("identifier", &CompositorScriptCompiler::parseIdentifier); |
---|
190 | // clear |
---|
191 | addLexemeAction("buffers", &CompositorScriptCompiler::parseClearBuffers); |
---|
192 | addLexemeToken("colour", ID_CLR_COLOUR); |
---|
193 | addLexemeToken("depth", ID_CLR_DEPTH); |
---|
194 | addLexemeAction("colour_value", &CompositorScriptCompiler::parseClearColourValue); |
---|
195 | addLexemeAction("depth_value", &CompositorScriptCompiler::parseClearDepthValue); |
---|
196 | addLexemeAction("stencil_value", &CompositorScriptCompiler::parseClearStencilValue); |
---|
197 | // stencil |
---|
198 | addLexemeAction("check", &CompositorScriptCompiler::parseStencilCheck); |
---|
199 | addLexemeAction("comp_func", &CompositorScriptCompiler::parseStencilFunc); |
---|
200 | addLexemeAction("ref_value", &CompositorScriptCompiler::parseStencilRefVal); |
---|
201 | addLexemeAction("mask", &CompositorScriptCompiler::parseStencilMask); |
---|
202 | addLexemeAction("fail_op", &CompositorScriptCompiler::parseStencilFailOp); |
---|
203 | addLexemeAction("depth_fail_op", &CompositorScriptCompiler::parseStencilDepthFailOp); |
---|
204 | addLexemeAction("pass_op", &CompositorScriptCompiler::parseStencilPassOp); |
---|
205 | addLexemeAction("two_sided", &CompositorScriptCompiler::parseStencilTwoSided); |
---|
206 | // compare functions |
---|
207 | addLexemeToken("always_fail", ID_ST_ALWAYS_FAIL); |
---|
208 | addLexemeToken("always_pass", ID_ST_ALWAYS_PASS); |
---|
209 | addLexemeToken("less", ID_ST_LESS); |
---|
210 | addLexemeToken("less_equal", ID_ST_LESS_EQUAL); |
---|
211 | addLexemeToken("equal", ID_ST_EQUAL); |
---|
212 | addLexemeToken("not_equal", ID_ST_NOT_EQUAL); |
---|
213 | addLexemeToken("greater_equal", ID_ST_GREATER_EQUAL); |
---|
214 | addLexemeToken("greater", ID_ST_GREATER); |
---|
215 | // stencil operations |
---|
216 | addLexemeToken("keep", ID_ST_KEEP); |
---|
217 | addLexemeToken("zero", ID_ST_ZERO); |
---|
218 | addLexemeToken("replace", ID_ST_REPLACE); |
---|
219 | addLexemeToken("increment", ID_ST_INCREMENT); |
---|
220 | addLexemeToken("decrement", ID_ST_DECREMENT); |
---|
221 | addLexemeToken("increment_wrap", ID_ST_INCREMENT_WRAP); |
---|
222 | addLexemeToken("decrement_wrap", ID_ST_DECREMENT_WRAP); |
---|
223 | addLexemeToken("invert", ID_ST_INVERT); |
---|
224 | |
---|
225 | // common section |
---|
226 | addLexemeToken("on", ID_ON); |
---|
227 | addLexemeToken("off", ID_OFF); |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | //----------------------------------------------------------------------- |
---|
232 | void CompositorScriptCompiler::addLexemeTokenAction(const String& lexeme, |
---|
233 | const size_t token, const CSC_Action action) |
---|
234 | { |
---|
235 | size_t newtokenID = addLexemeToken(lexeme, token, action != 0); |
---|
236 | // only add actions to the map if they exist |
---|
237 | if (action) |
---|
238 | mTokenActionMap[newtokenID] = action; |
---|
239 | } |
---|
240 | |
---|
241 | //----------------------------------------------------------------------- |
---|
242 | void CompositorScriptCompiler::executeTokenAction(const size_t tokenID) |
---|
243 | { |
---|
244 | TokenActionIterator action = mTokenActionMap.find(tokenID); |
---|
245 | |
---|
246 | if (action == mTokenActionMap.end()) |
---|
247 | { |
---|
248 | // BAD command. BAD! |
---|
249 | logParseError("Unrecognised compositor script command action"); |
---|
250 | return; |
---|
251 | } |
---|
252 | else |
---|
253 | { |
---|
254 | try |
---|
255 | { |
---|
256 | (this->*action->second)(); |
---|
257 | } |
---|
258 | catch (Exception& ogreException) |
---|
259 | { |
---|
260 | // an unknown token found or BNF Grammer rule was not successful |
---|
261 | // in finding a valid terminal token to complete the rule expression. |
---|
262 | logParseError(ogreException.getDescription()); |
---|
263 | } |
---|
264 | } |
---|
265 | } |
---|
266 | |
---|
267 | //----------------------------------------------------------------------- |
---|
268 | void CompositorScriptCompiler::logParseError(const String& error) |
---|
269 | { |
---|
270 | // log material name only if filename not specified |
---|
271 | if (mSourceName.empty() && !mScriptContext.compositor.isNull()) |
---|
272 | { |
---|
273 | LogManager::getSingleton().logMessage( |
---|
274 | "Error in compositor " + mScriptContext.compositor->getName() + |
---|
275 | " : " + error); |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | if (!mScriptContext.compositor.isNull()) |
---|
280 | { |
---|
281 | LogManager::getSingleton().logMessage( |
---|
282 | "Error in compositor " + mScriptContext.compositor->getName() + |
---|
283 | " at line " + StringConverter::toString(mCurrentLine) + |
---|
284 | " of " + mSourceName + ": " + error); |
---|
285 | } |
---|
286 | else |
---|
287 | { |
---|
288 | LogManager::getSingleton().logMessage( |
---|
289 | "Error at line " + StringConverter::toString(mCurrentLine) + |
---|
290 | " of " + mSourceName + ": " + error); |
---|
291 | } |
---|
292 | } |
---|
293 | } |
---|
294 | //----------------------------------------------------------------------- |
---|
295 | void CompositorScriptCompiler::parseOpenBrace(void) |
---|
296 | { |
---|
297 | |
---|
298 | } |
---|
299 | //----------------------------------------------------------------------- |
---|
300 | void CompositorScriptCompiler::parseCloseBrace(void) |
---|
301 | { |
---|
302 | switch(mScriptContext.section) |
---|
303 | { |
---|
304 | case CSS_NONE: |
---|
305 | logParseError("Unexpected terminating brace."); |
---|
306 | break; |
---|
307 | case CSS_COMPOSITOR: |
---|
308 | // End of compositor |
---|
309 | mScriptContext.section = CSS_NONE; |
---|
310 | mScriptContext.compositor.setNull(); |
---|
311 | break; |
---|
312 | case CSS_TECHNIQUE: |
---|
313 | // End of technique |
---|
314 | mScriptContext.section = CSS_COMPOSITOR; |
---|
315 | mScriptContext.technique = NULL; |
---|
316 | break; |
---|
317 | case CSS_TARGET: |
---|
318 | // End of target |
---|
319 | mScriptContext.section = CSS_TECHNIQUE; |
---|
320 | mScriptContext.target = NULL; |
---|
321 | break; |
---|
322 | case CSS_PASS: |
---|
323 | // End of pass |
---|
324 | mScriptContext.section = CSS_TARGET; |
---|
325 | mScriptContext.pass = NULL; |
---|
326 | break; |
---|
327 | }; |
---|
328 | } |
---|
329 | //----------------------------------------------------------------------- |
---|
330 | void CompositorScriptCompiler::parseCompositor(void) |
---|
331 | { |
---|
332 | const String compositorName = getNextTokenLabel(); |
---|
333 | mScriptContext.compositor = CompositorManager::getSingleton().create( |
---|
334 | compositorName, mScriptContext.groupName |
---|
335 | ); |
---|
336 | mScriptContext.section = CSS_COMPOSITOR; |
---|
337 | |
---|
338 | } |
---|
339 | //----------------------------------------------------------------------- |
---|
340 | void CompositorScriptCompiler::parseTechnique(void) |
---|
341 | { |
---|
342 | mScriptContext.technique = mScriptContext.compositor->createTechnique(); |
---|
343 | mScriptContext.section = CSS_TECHNIQUE; |
---|
344 | } |
---|
345 | //----------------------------------------------------------------------- |
---|
346 | void CompositorScriptCompiler::parseTexture(void) |
---|
347 | { |
---|
348 | assert(mScriptContext.technique); |
---|
349 | const String textureName = getNextTokenLabel(); |
---|
350 | CompositionTechnique::TextureDefinition* textureDef = mScriptContext.technique->createTextureDefinition(textureName); |
---|
351 | // if peek next token is target_width then get token and use 0 for width |
---|
352 | // determine width parameter |
---|
353 | if (testNextTokenID(ID_TARGET_WIDTH)) |
---|
354 | { |
---|
355 | getNextToken(); |
---|
356 | // a value of zero causes texture to be size of render target |
---|
357 | textureDef->width = 0; |
---|
358 | } |
---|
359 | else |
---|
360 | { |
---|
361 | textureDef->width = static_cast<size_t>(getNextTokenValue()); |
---|
362 | } |
---|
363 | // determine height parameter |
---|
364 | if (testNextTokenID(ID_TARGET_HEIGHT)) |
---|
365 | { |
---|
366 | getNextToken(); |
---|
367 | // a value of zero causes texture to be size of render target |
---|
368 | textureDef->height = 0; |
---|
369 | } |
---|
370 | else |
---|
371 | { |
---|
372 | textureDef->height = static_cast<size_t>(getNextTokenValue()); |
---|
373 | } |
---|
374 | // get pixel factor |
---|
375 | switch (getNextTokenID()) |
---|
376 | { |
---|
377 | case ID_PF_A8R8G8B8: |
---|
378 | textureDef->format = PF_A8R8G8B8; |
---|
379 | break; |
---|
380 | |
---|
381 | case ID_PF_R8G8B8A8: |
---|
382 | textureDef->format = PF_R8G8B8A8; |
---|
383 | break; |
---|
384 | case ID_PF_R8G8B8: |
---|
385 | textureDef->format = PF_R8G8B8; |
---|
386 | break; |
---|
387 | case ID_PF_FLOAT16_R: |
---|
388 | textureDef->format = PF_FLOAT16_R; |
---|
389 | break; |
---|
390 | case ID_PF_FLOAT16_GR: |
---|
391 | textureDef->format = PF_FLOAT16_GR; |
---|
392 | break; |
---|
393 | case ID_PF_FLOAT16_RGB: |
---|
394 | textureDef->format = PF_FLOAT16_RGB; |
---|
395 | break; |
---|
396 | case ID_PF_FLOAT16_RGBA: |
---|
397 | textureDef->format = PF_FLOAT16_RGBA; |
---|
398 | break; |
---|
399 | case ID_PF_FLOAT32_R: |
---|
400 | textureDef->format = PF_FLOAT32_R; |
---|
401 | break; |
---|
402 | case ID_PF_FLOAT32_GR: |
---|
403 | textureDef->format = PF_FLOAT32_GR; |
---|
404 | break; |
---|
405 | case ID_PF_FLOAT32_RGB: |
---|
406 | textureDef->format = PF_FLOAT32_RGB; |
---|
407 | break; |
---|
408 | case ID_PF_FLOAT32_RGBA: |
---|
409 | textureDef->format = PF_FLOAT32_RGBA; |
---|
410 | break; |
---|
411 | |
---|
412 | default: |
---|
413 | // should never get here? |
---|
414 | break; |
---|
415 | } |
---|
416 | } |
---|
417 | //----------------------------------------------------------------------- |
---|
418 | void CompositorScriptCompiler::parseTarget(void) |
---|
419 | { |
---|
420 | assert(mScriptContext.technique); |
---|
421 | |
---|
422 | mScriptContext.section = CSS_TARGET; |
---|
423 | mScriptContext.target = mScriptContext.technique->createTargetPass(); |
---|
424 | mScriptContext.target->setOutputName(getNextTokenLabel()); |
---|
425 | |
---|
426 | } |
---|
427 | //----------------------------------------------------------------------- |
---|
428 | void CompositorScriptCompiler::parseInput(void) |
---|
429 | { |
---|
430 | // input parameters depends on context either target or pass |
---|
431 | if (mScriptContext.section == CSS_TARGET) |
---|
432 | { |
---|
433 | // for input in target, there is only one parameter |
---|
434 | assert(mScriptContext.target); |
---|
435 | if (testNextTokenID(ID_PREVIOUS)) |
---|
436 | mScriptContext.target->setInputMode(CompositionTargetPass::IM_PREVIOUS); |
---|
437 | else |
---|
438 | mScriptContext.target->setInputMode(CompositionTargetPass::IM_NONE); |
---|
439 | } |
---|
440 | else // assume for pass section context |
---|
441 | { |
---|
442 | // for input in pass, there are two parameters |
---|
443 | assert(mScriptContext.pass); |
---|
444 | uint32 id = static_cast<uint32>(getNextTokenValue()); |
---|
445 | const String& textureName = getNextTokenLabel(); |
---|
446 | mScriptContext.pass->setInput(id, textureName); |
---|
447 | } |
---|
448 | |
---|
449 | } |
---|
450 | //----------------------------------------------------------------------- |
---|
451 | void CompositorScriptCompiler::parseTargetOutput(void) |
---|
452 | { |
---|
453 | assert(mScriptContext.technique); |
---|
454 | mScriptContext.target = mScriptContext.technique->getOutputTargetPass(); |
---|
455 | mScriptContext.section = CSS_TARGET; |
---|
456 | } |
---|
457 | //----------------------------------------------------------------------- |
---|
458 | void CompositorScriptCompiler::parseOnlyInitial(void) |
---|
459 | { |
---|
460 | assert(mScriptContext.target); |
---|
461 | mScriptContext.target->setOnlyInitial(testNextTokenID(ID_ON)); |
---|
462 | } |
---|
463 | //----------------------------------------------------------------------- |
---|
464 | void CompositorScriptCompiler::parseVisibilityMask(void) |
---|
465 | { |
---|
466 | assert(mScriptContext.target); |
---|
467 | mScriptContext.target->setVisibilityMask(static_cast<uint32>(getNextTokenValue())); |
---|
468 | } |
---|
469 | //----------------------------------------------------------------------- |
---|
470 | void CompositorScriptCompiler::parseLodBias(void) |
---|
471 | { |
---|
472 | assert(mScriptContext.target); |
---|
473 | mScriptContext.target->setLodBias(getNextTokenValue()); |
---|
474 | } |
---|
475 | //----------------------------------------------------------------------- |
---|
476 | void CompositorScriptCompiler::parseMaterialScheme(void) |
---|
477 | { |
---|
478 | assert(mScriptContext.target); |
---|
479 | mScriptContext.target->setMaterialScheme(getNextTokenLabel()); |
---|
480 | } |
---|
481 | //----------------------------------------------------------------------- |
---|
482 | void CompositorScriptCompiler::parsePass(void) |
---|
483 | { |
---|
484 | assert(mScriptContext.target); |
---|
485 | mScriptContext.pass = mScriptContext.target->createPass(); |
---|
486 | CompositionPass::PassType passType = CompositionPass::PT_RENDERQUAD; |
---|
487 | switch (getNextTokenID()) |
---|
488 | { |
---|
489 | case ID_RENDER_QUAD: |
---|
490 | passType = CompositionPass::PT_RENDERQUAD; |
---|
491 | break; |
---|
492 | |
---|
493 | case ID_CLEAR: |
---|
494 | passType = CompositionPass::PT_CLEAR; |
---|
495 | break; |
---|
496 | |
---|
497 | case ID_STENCIL: |
---|
498 | passType = CompositionPass::PT_STENCIL; |
---|
499 | break; |
---|
500 | |
---|
501 | case ID_RENDER_SCENE: |
---|
502 | passType = CompositionPass::PT_RENDERSCENE; |
---|
503 | break; |
---|
504 | |
---|
505 | default: |
---|
506 | break; |
---|
507 | } |
---|
508 | |
---|
509 | mScriptContext.pass->setType(passType); |
---|
510 | |
---|
511 | mScriptContext.section = CSS_PASS; |
---|
512 | |
---|
513 | } |
---|
514 | //----------------------------------------------------------------------- |
---|
515 | void CompositorScriptCompiler::parseMaterial(void) |
---|
516 | { |
---|
517 | assert(mScriptContext.pass); |
---|
518 | mScriptContext.pass->setMaterialName(getNextTokenLabel()); |
---|
519 | } |
---|
520 | //----------------------------------------------------------------------- |
---|
521 | void CompositorScriptCompiler::parseFirstRenderQueue(void) |
---|
522 | { |
---|
523 | assert(mScriptContext.pass); |
---|
524 | mScriptContext.pass->setFirstRenderQueue(static_cast<uint8>(getNextTokenValue())); |
---|
525 | } |
---|
526 | //----------------------------------------------------------------------- |
---|
527 | void CompositorScriptCompiler::parseLastRenderQueue(void) |
---|
528 | { |
---|
529 | assert(mScriptContext.pass); |
---|
530 | mScriptContext.pass->setLastRenderQueue(static_cast<uint8>(getNextTokenValue())); |
---|
531 | } |
---|
532 | //----------------------------------------------------------------------- |
---|
533 | void CompositorScriptCompiler::parseIdentifier(void) |
---|
534 | { |
---|
535 | assert(mScriptContext.pass); |
---|
536 | mScriptContext.pass->setIdentifier(static_cast<uint32>(getNextTokenValue())); |
---|
537 | } |
---|
538 | //----------------------------------------------------------------------- |
---|
539 | void CompositorScriptCompiler::parseClearBuffers(void) |
---|
540 | { |
---|
541 | assert(mScriptContext.pass); |
---|
542 | // while there are tokens for the action, get next token and set buffer flag |
---|
543 | uint32 bufferFlags = 0; |
---|
544 | |
---|
545 | while (getRemainingTokensForAction() > 0) |
---|
546 | { |
---|
547 | switch (getNextTokenID()) |
---|
548 | { |
---|
549 | case ID_CLR_COLOUR: |
---|
550 | bufferFlags |= FBT_COLOUR; |
---|
551 | break; |
---|
552 | |
---|
553 | case ID_CLR_DEPTH: |
---|
554 | bufferFlags |= FBT_DEPTH; |
---|
555 | break; |
---|
556 | |
---|
557 | case ID_STENCIL: |
---|
558 | bufferFlags |= FBT_STENCIL; |
---|
559 | break; |
---|
560 | |
---|
561 | default: |
---|
562 | break; |
---|
563 | } |
---|
564 | } |
---|
565 | mScriptContext.pass->setClearBuffers(bufferFlags); |
---|
566 | } |
---|
567 | //----------------------------------------------------------------------- |
---|
568 | void CompositorScriptCompiler::parseClearColourValue(void) |
---|
569 | { |
---|
570 | assert(mScriptContext.pass); |
---|
571 | Real red = getNextTokenValue(); |
---|
572 | Real green = getNextTokenValue(); |
---|
573 | Real blue = getNextTokenValue(); |
---|
574 | Real alpha = getNextTokenValue(); |
---|
575 | mScriptContext.pass->setClearColour(ColourValue(red, green, blue, alpha)); |
---|
576 | } |
---|
577 | //----------------------------------------------------------------------- |
---|
578 | void CompositorScriptCompiler::parseClearDepthValue(void) |
---|
579 | { |
---|
580 | assert(mScriptContext.pass); |
---|
581 | mScriptContext.pass->setClearDepth(getNextTokenValue()); |
---|
582 | } |
---|
583 | //----------------------------------------------------------------------- |
---|
584 | void CompositorScriptCompiler::parseClearStencilValue(void) |
---|
585 | { |
---|
586 | assert(mScriptContext.pass); |
---|
587 | mScriptContext.pass->setClearStencil(static_cast<uint32>(getNextTokenValue())); |
---|
588 | } |
---|
589 | //----------------------------------------------------------------------- |
---|
590 | void CompositorScriptCompiler::parseStencilCheck(void) |
---|
591 | { |
---|
592 | assert(mScriptContext.pass); |
---|
593 | mScriptContext.pass->setStencilCheck(testNextTokenID(ID_ON)); |
---|
594 | } |
---|
595 | //----------------------------------------------------------------------- |
---|
596 | void CompositorScriptCompiler::parseStencilFunc(void) |
---|
597 | { |
---|
598 | assert(mScriptContext.pass); |
---|
599 | mScriptContext.pass->setStencilFunc(extractCompareFunc()); |
---|
600 | } |
---|
601 | //----------------------------------------------------------------------- |
---|
602 | void CompositorScriptCompiler::parseStencilRefVal(void) |
---|
603 | { |
---|
604 | assert(mScriptContext.pass); |
---|
605 | mScriptContext.pass->setStencilRefValue(static_cast<uint32>(getNextTokenValue())); |
---|
606 | } |
---|
607 | //----------------------------------------------------------------------- |
---|
608 | void CompositorScriptCompiler::parseStencilMask(void) |
---|
609 | { |
---|
610 | assert(mScriptContext.pass); |
---|
611 | mScriptContext.pass->setStencilMask(static_cast<uint32>(getNextTokenValue())); |
---|
612 | } |
---|
613 | //----------------------------------------------------------------------- |
---|
614 | void CompositorScriptCompiler::parseStencilFailOp(void) |
---|
615 | { |
---|
616 | assert(mScriptContext.pass); |
---|
617 | mScriptContext.pass->setStencilFailOp(extractStencilOp()); |
---|
618 | } |
---|
619 | //----------------------------------------------------------------------- |
---|
620 | void CompositorScriptCompiler::parseStencilDepthFailOp(void) |
---|
621 | { |
---|
622 | assert(mScriptContext.pass); |
---|
623 | mScriptContext.pass->setStencilDepthFailOp(extractStencilOp()); |
---|
624 | } |
---|
625 | //----------------------------------------------------------------------- |
---|
626 | void CompositorScriptCompiler::parseStencilPassOp(void) |
---|
627 | { |
---|
628 | assert(mScriptContext.pass); |
---|
629 | mScriptContext.pass->setStencilPassOp(extractStencilOp()); |
---|
630 | } |
---|
631 | //----------------------------------------------------------------------- |
---|
632 | void CompositorScriptCompiler::parseStencilTwoSided(void) |
---|
633 | { |
---|
634 | assert(mScriptContext.pass); |
---|
635 | mScriptContext.pass->setStencilTwoSidedOperation(testNextTokenID(ID_ON)); |
---|
636 | } |
---|
637 | //----------------------------------------------------------------------- |
---|
638 | StencilOperation CompositorScriptCompiler::extractStencilOp(void) |
---|
639 | { |
---|
640 | StencilOperation sop = SOP_KEEP; |
---|
641 | |
---|
642 | switch (getNextTokenID()) |
---|
643 | { |
---|
644 | case ID_ST_KEEP: |
---|
645 | sop = SOP_KEEP; |
---|
646 | break; |
---|
647 | |
---|
648 | case ID_ST_ZERO: |
---|
649 | sop = SOP_ZERO; |
---|
650 | break; |
---|
651 | |
---|
652 | case ID_ST_REPLACE: |
---|
653 | sop = SOP_REPLACE; |
---|
654 | break; |
---|
655 | |
---|
656 | case ID_ST_INCREMENT: |
---|
657 | sop = SOP_INCREMENT; |
---|
658 | break; |
---|
659 | |
---|
660 | case ID_ST_DECREMENT: |
---|
661 | sop = SOP_DECREMENT; |
---|
662 | break; |
---|
663 | |
---|
664 | case ID_ST_INCREMENT_WRAP: |
---|
665 | sop = SOP_INCREMENT_WRAP; |
---|
666 | break; |
---|
667 | |
---|
668 | case ID_ST_DECREMENT_WRAP: |
---|
669 | sop = SOP_DECREMENT_WRAP; |
---|
670 | break; |
---|
671 | |
---|
672 | case ID_ST_INVERT: |
---|
673 | sop = SOP_INVERT; |
---|
674 | break; |
---|
675 | |
---|
676 | default: |
---|
677 | break; |
---|
678 | } |
---|
679 | |
---|
680 | return sop; |
---|
681 | } |
---|
682 | CompareFunction CompositorScriptCompiler::extractCompareFunc(void) |
---|
683 | { |
---|
684 | CompareFunction compFunc = CMPF_ALWAYS_PASS; |
---|
685 | |
---|
686 | switch (getNextTokenID()) |
---|
687 | { |
---|
688 | case ID_ST_ALWAYS_FAIL: |
---|
689 | compFunc = CMPF_ALWAYS_FAIL; |
---|
690 | break; |
---|
691 | |
---|
692 | case ID_ST_ALWAYS_PASS: |
---|
693 | compFunc = CMPF_ALWAYS_PASS; |
---|
694 | break; |
---|
695 | |
---|
696 | case ID_ST_LESS: |
---|
697 | compFunc = CMPF_LESS; |
---|
698 | break; |
---|
699 | |
---|
700 | case ID_ST_LESS_EQUAL: |
---|
701 | compFunc = CMPF_LESS_EQUAL; |
---|
702 | break; |
---|
703 | |
---|
704 | case ID_ST_EQUAL: |
---|
705 | compFunc = CMPF_EQUAL; |
---|
706 | break; |
---|
707 | |
---|
708 | case ID_ST_NOT_EQUAL: |
---|
709 | compFunc = CMPF_NOT_EQUAL; |
---|
710 | break; |
---|
711 | |
---|
712 | case ID_ST_GREATER_EQUAL: |
---|
713 | compFunc = CMPF_GREATER_EQUAL; |
---|
714 | break; |
---|
715 | |
---|
716 | case ID_ST_GREATER: |
---|
717 | compFunc = CMPF_GREATER; |
---|
718 | break; |
---|
719 | |
---|
720 | default: |
---|
721 | break; |
---|
722 | } |
---|
723 | |
---|
724 | return compFunc; |
---|
725 | } |
---|
726 | |
---|
727 | } |
---|