Patch 2793067: fix trunk with OGRE_THREAD_SUPPORT=1 on non-Windows platforms (don...
[ogre3d.git] / OgreMain / src / OgreCompositorScriptCompiler.cpp
blobacde79b8f5e24a5d0c44c1a31dece94bcd33ac9d
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
7 Copyright (c) 2000-2006 Torus Knot Software Ltd
8 Also see acknowledgements in Readme.html
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.
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.
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.
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 -----------------------------------------------------------------------------
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"
40 namespace Ogre {
42 //-----------------------------------------------------------------------
43 // Static definitions
44 //-----------------------------------------------------------------------
45 CompositorScriptCompiler::TokenActionMap CompositorScriptCompiler::mTokenActionMap;
47 const String& CompositorScriptCompiler::getClientBNFGrammer(void) const
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> {<PixelFormat>} [<Shared>] \n"
57 "<WidthOption> ::= <TargetWidthScaled> | 'target_width' | <#width> \n"
58 "<HeightOption> ::= <TargetHeightScaled> | 'target_height' | <#height> \n"
59 "<TargetWidthScaled> ::= 'target_width_scaled' <#scaling> \n"
60 "<TargetHeightScaled> ::= 'target_height_scaled' <#scaling> \n"
61 "<PixelFormat> ::= 'PF_A8R8G8B8' | 'PF_R8G8B8A8' | 'PF_R8G8B8' | 'PF_FLOAT16_RGBA' | \n"
62 " 'PF_FLOAT16_RGB' | 'PF_FLOAT16_R' | 'PF_FLOAT32_RGBA' | 'PF_FLOAT32_RGB' | 'PF_FLOAT32_R' | \n"
63 " 'PF_FLOAT16_GR' | 'PF_FLOAT32_GR' \n"
64 "<Shared> ::= 'shared' \n"
65 // Target
66 "<Target> ::= 'target ' <Label> '{' {<TargetOptions>} {<Pass>} '}' \n"
67 "<TargetOptions> ::= <TargetInput> | <OnlyInitial> | <VisibilityMask> | \n"
68 " <LodBias> | <MaterialScheme> | <Shadows> \n"
69 "<TargetInput> ::= 'input' <TargetInputOptions> \n"
70 "<TargetInputOptions> ::= 'none' | 'previous' \n"
71 "<OnlyInitial> ::= 'only_initial' <On_Off> \n"
72 "<VisibilityMask> ::= 'visibility_mask' <#mask> \n"
73 "<LodBias> ::= 'lod_bias' <#lodbias> \n"
74 "<MaterialScheme> ::= 'material_scheme' <Label> \n"
75 "<Shadows> ::= 'shadows' <On_Off> \n"
76 "<TargetOutput> ::= 'target_output' '{' [<TargetOptions>] {<Pass>} '}' \n"
77 // Pass
78 "<Pass> ::= 'pass' <PassTypes> '{' {<PassOptions>} '}' \n"
79 "<PassTypes> ::= 'render_quad' | 'clear' | 'stencil' | 'render_scene' \n"
80 "<PassOptions> ::= <PassFirstRenderQueue> | <PassLastRenderQueue> | \n"
81 " <PassIdentifier> | <PassMaterial> | <PassInput> | <ClearSection> | <StencilSection> \n"
82 "<PassMaterial> ::= 'material' <Label> \n"
83 "<PassInput> ::= 'input' <#id> <Label> [<#mrtIndex>] \n"
84 "<PassFirstRenderQueue> ::= 'first_render_queue' <#queue> \n"
85 "<PassLastRenderQueue> ::= 'last_render_queue' <#queue> \n"
86 "<PassIdentifier> ::= 'identifier' <#id> \n"
87 // clear
88 "<ClearSection> ::= -'clear' -'{' {<ClearOptions>} -'}' \n"
89 "<ClearOptions> ::= <Buffers> | <ColourValue> | <DepthValue> | <StencilValue> \n"
90 "<Buffers> ::= 'buffers' {<BufferTypes>} \n"
91 "<BufferTypes> ::= <Colour> | <Depth> | <Stencil> \n"
92 "<Colour> ::= 'colour' (?!<ValueChk>) \n"
93 "<Depth> ::= 'depth' (?!<ValueChk>) \n"
94 "<Stencil> ::= 'stencil' (?!<ValueChk>) \n"
95 "<ValueChk> ::= '_value' \n"
96 "<ColourValue> ::= 'colour_value' <#red> <#green> <#blue> <#alpha> \n"
97 "<DepthValue> ::= 'depth_value' <#depth> \n"
98 "<StencilValue> ::= 'stencil_value' <#val> \n"
99 // stencil
100 "<StencilSection> ::= -'stencil' -'{' {<StencilOptions>} -'}' \n"
101 "<StencilOptions> ::= <Check> | <CompareFunction> | <RefVal> | <Mask> | <FailOp> | <DepthFailOp> | \n"
102 " <PassOp> | <TwoSided> \n"
103 "<Check> ::= 'check' <On_Off> \n"
104 "<CompareFunction> ::= 'comp_func' <CompFunc> \n"
105 "<CompFunc> ::= 'always_fail' | 'always_pass' | 'less_equal' | 'less' | 'equal' | \n"
106 " 'not_equal' | 'equal' | 'greater_equal' | 'greater' \n"
107 "<RefVal> ::= 'ref_value' <#val> \n"
108 "<Mask> ::= 'mask' <#mask> \n"
109 "<FailOp> ::= 'fail_op' <StencilOperation> \n"
110 "<DepthFailOp> ::= 'depth_fail_op' <StencilOperation> \n"
111 "<PassOp> ::= 'pass_op' <StencilOperation> \n"
112 "<TwoSided> ::= 'two_sided' <On_Off> \n"
113 "<StencilOperation> ::= 'keep' | 'zero' | 'replace' | 'increment_wrap' | 'increment' | \n"
114 " 'decrement_wrap' | 'decrement' | 'invert' \n"
116 // common rules
117 "<On_Off> ::= 'on' | 'off' \n"
118 "<Label> ::= <Quoted_Label> | <Unquoted_Label> \n"
119 "<Flex_Label> ::= <Quoted_Label> | <Spaced_Label> \n"
120 "<Quoted_Label> ::= -'\"' <Spaced_Label> -'\"' \n"
121 "<Spaced_Label> ::= <Spaced_Label_Illegals> {<Spaced_Label_Illegals>} \n"
122 "<Unquoted_Label> ::= <Unquoted_Label_Illegals> {<Unquoted_Label_Illegals>} \n"
123 "<Spaced_Label_Illegals> ::= (!,\n\r\t{}\") \n"
124 "<Unquoted_Label_Illegals> ::= (! \n\r\t{}\") \n"
128 return compositorScript_BNF;
130 //-----------------------------------------------------------------------
131 const String& CompositorScriptCompiler::getClientGrammerName(void) const
133 static const String grammerName = "Compositor Script";
134 return grammerName;
136 //-----------------------------------------------------------------------
137 CompositorScriptCompiler::CompositorScriptCompiler(void)
139 // set default group resource name
140 mScriptContext.groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME;
142 //-----------------------------------------------------------------------
143 CompositorScriptCompiler::~CompositorScriptCompiler(void)
147 //-----------------------------------------------------------------------
148 void CompositorScriptCompiler::setupTokenDefinitions(void)
150 addLexemeAction("{", &CompositorScriptCompiler::parseOpenBrace);
151 addLexemeAction("}", &CompositorScriptCompiler::parseCloseBrace);
152 addLexemeAction("compositor", &CompositorScriptCompiler::parseCompositor);
154 // Technique section
155 addLexemeAction("technique", &CompositorScriptCompiler::parseTechnique);
156 addLexemeAction("texture", &CompositorScriptCompiler::parseTexture);
157 addLexemeAction("scheme", &CompositorScriptCompiler::parseScheme);
158 addLexemeToken("target_width_scaled", ID_TARGET_WIDTH_SCALED);
159 addLexemeToken("target_height_scaled", ID_TARGET_HEIGHT_SCALED);
160 addLexemeToken("target_width", ID_TARGET_WIDTH);
161 addLexemeToken("target_height", ID_TARGET_HEIGHT);
162 addLexemeToken("PF_A8R8G8B8", ID_PF_A8R8G8B8);
163 addLexemeToken("PF_R8G8B8A8", ID_PF_R8G8B8A8);
164 addLexemeToken("PF_R8G8B8", ID_PF_R8G8B8);
165 addLexemeToken("PF_FLOAT16_R", ID_PF_FLOAT16_R);
166 addLexemeToken("PF_FLOAT16_GR", ID_PF_FLOAT16_GR);
167 addLexemeToken("PF_FLOAT16_RGB", ID_PF_FLOAT16_RGB);
168 addLexemeToken("PF_FLOAT16_RGBA", ID_PF_FLOAT16_RGBA);
169 addLexemeToken("PF_FLOAT32_R", ID_PF_FLOAT32_R);
170 addLexemeToken("PF_FLOAT32_GR", ID_PF_FLOAT32_GR);
171 addLexemeToken("PF_FLOAT32_RGB", ID_PF_FLOAT32_RGB);
172 addLexemeToken("PF_FLOAT32_RGBA", ID_PF_FLOAT32_RGBA);
173 addLexemeToken("shared", ID_SHARED);
174 addLexemeToken("gamma", ID_GAMMA);
175 addLexemeToken("no_fsaa", ID_NO_FSAA);
177 // Target section
178 addLexemeAction("target ", &CompositorScriptCompiler::parseTarget);
179 addLexemeAction("input", &CompositorScriptCompiler::parseInput);
180 addLexemeToken("none", ID_NONE);
181 addLexemeToken("previous", ID_PREVIOUS);
182 addLexemeAction("target_output", &CompositorScriptCompiler::parseTargetOutput);
183 addLexemeAction("only_initial", &CompositorScriptCompiler::parseOnlyInitial);
184 addLexemeAction("visibility_mask", &CompositorScriptCompiler::parseVisibilityMask);
185 addLexemeAction("lod_bias", &CompositorScriptCompiler::parseLodBias);
186 addLexemeAction("material_scheme", &CompositorScriptCompiler::parseMaterialScheme);
187 addLexemeAction("shadows", &CompositorScriptCompiler::parseShadowsEnabled);
189 // pass section
190 addLexemeAction("pass", &CompositorScriptCompiler::parsePass);
191 // input defined above
192 addLexemeToken("render_quad", ID_RENDER_QUAD);
193 addLexemeToken("clear", ID_CLEAR);
194 addLexemeToken("stencil", ID_STENCIL);
195 addLexemeToken("render_scene", ID_RENDER_SCENE);
196 // pass attributes
197 addLexemeAction("material", &CompositorScriptCompiler::parseMaterial);
198 addLexemeAction("first_render_queue", &CompositorScriptCompiler::parseFirstRenderQueue);
199 addLexemeAction("last_render_queue", &CompositorScriptCompiler::parseLastRenderQueue);
200 addLexemeAction("identifier", &CompositorScriptCompiler::parseIdentifier);
201 // clear
202 addLexemeAction("buffers", &CompositorScriptCompiler::parseClearBuffers);
203 addLexemeToken("colour", ID_CLR_COLOUR);
204 addLexemeToken("depth", ID_CLR_DEPTH);
205 addLexemeAction("colour_value", &CompositorScriptCompiler::parseClearColourValue);
206 addLexemeAction("depth_value", &CompositorScriptCompiler::parseClearDepthValue);
207 addLexemeAction("stencil_value", &CompositorScriptCompiler::parseClearStencilValue);
208 // stencil
209 addLexemeAction("check", &CompositorScriptCompiler::parseStencilCheck);
210 addLexemeAction("comp_func", &CompositorScriptCompiler::parseStencilFunc);
211 addLexemeAction("ref_value", &CompositorScriptCompiler::parseStencilRefVal);
212 addLexemeAction("mask", &CompositorScriptCompiler::parseStencilMask);
213 addLexemeAction("fail_op", &CompositorScriptCompiler::parseStencilFailOp);
214 addLexemeAction("depth_fail_op", &CompositorScriptCompiler::parseStencilDepthFailOp);
215 addLexemeAction("pass_op", &CompositorScriptCompiler::parseStencilPassOp);
216 addLexemeAction("two_sided", &CompositorScriptCompiler::parseStencilTwoSided);
217 // compare functions
218 addLexemeToken("always_fail", ID_ST_ALWAYS_FAIL);
219 addLexemeToken("always_pass", ID_ST_ALWAYS_PASS);
220 addLexemeToken("less", ID_ST_LESS);
221 addLexemeToken("less_equal", ID_ST_LESS_EQUAL);
222 addLexemeToken("equal", ID_ST_EQUAL);
223 addLexemeToken("not_equal", ID_ST_NOT_EQUAL);
224 addLexemeToken("greater_equal", ID_ST_GREATER_EQUAL);
225 addLexemeToken("greater", ID_ST_GREATER);
226 // stencil operations
227 addLexemeToken("keep", ID_ST_KEEP);
228 addLexemeToken("zero", ID_ST_ZERO);
229 addLexemeToken("replace", ID_ST_REPLACE);
230 addLexemeToken("increment", ID_ST_INCREMENT);
231 addLexemeToken("decrement", ID_ST_DECREMENT);
232 addLexemeToken("increment_wrap", ID_ST_INCREMENT_WRAP);
233 addLexemeToken("decrement_wrap", ID_ST_DECREMENT_WRAP);
234 addLexemeToken("invert", ID_ST_INVERT);
236 // common section
237 addLexemeToken("on", ID_ON);
238 addLexemeToken("off", ID_OFF);
242 //-----------------------------------------------------------------------
243 void CompositorScriptCompiler::addLexemeTokenAction(const String& lexeme,
244 const size_t token, const CSC_Action action)
246 size_t newtokenID = addLexemeToken(lexeme, token, action != 0);
247 // only add actions to the map if they exist
248 if (action)
249 mTokenActionMap[newtokenID] = action;
252 //-----------------------------------------------------------------------
253 void CompositorScriptCompiler::executeTokenAction(const size_t tokenID)
255 TokenActionIterator action = mTokenActionMap.find(tokenID);
257 if (action == mTokenActionMap.end())
259 // BAD command. BAD!
260 logParseError("Unrecognised compositor script command action");
261 return;
263 else
267 (this->*action->second)();
269 catch (Exception& ogreException)
271 // an unknown token found or BNF Grammer rule was not successful
272 // in finding a valid terminal token to complete the rule expression.
273 logParseError(ogreException.getDescription());
278 //-----------------------------------------------------------------------
279 void CompositorScriptCompiler::logParseError(const String& error)
281 // log material name only if filename not specified
282 if (mSourceName.empty() && !mScriptContext.compositor.isNull())
284 LogManager::getSingleton().logMessage(
285 "Error in compositor " + mScriptContext.compositor->getName() +
286 " : " + error);
288 else
290 if (!mScriptContext.compositor.isNull())
292 LogManager::getSingleton().logMessage(
293 "Error in compositor " + mScriptContext.compositor->getName() +
294 " at line " + StringConverter::toString(mCurrentLine) +
295 " of " + mSourceName + ": " + error);
297 else
299 LogManager::getSingleton().logMessage(
300 "Error at line " + StringConverter::toString(mCurrentLine) +
301 " of " + mSourceName + ": " + error);
305 //-----------------------------------------------------------------------
306 void CompositorScriptCompiler::parseOpenBrace(void)
310 //-----------------------------------------------------------------------
311 void CompositorScriptCompiler::parseCloseBrace(void)
313 switch(mScriptContext.section)
315 case CSS_NONE:
316 logParseError("Unexpected terminating brace.");
317 break;
318 case CSS_COMPOSITOR:
319 // End of compositor
320 mScriptContext.section = CSS_NONE;
321 mScriptContext.compositor.setNull();
322 break;
323 case CSS_TECHNIQUE:
324 // End of technique
325 mScriptContext.section = CSS_COMPOSITOR;
326 mScriptContext.technique = NULL;
327 break;
328 case CSS_TARGET:
329 // End of target
330 mScriptContext.section = CSS_TECHNIQUE;
331 mScriptContext.target = NULL;
332 break;
333 case CSS_PASS:
334 // End of pass
335 mScriptContext.section = CSS_TARGET;
336 mScriptContext.pass = NULL;
337 break;
340 //-----------------------------------------------------------------------
341 void CompositorScriptCompiler::parseCompositor(void)
343 const String compositorName = getNextTokenLabel();
344 mScriptContext.compositor = CompositorManager::getSingleton().create(
345 compositorName, mScriptContext.groupName
347 mScriptContext.section = CSS_COMPOSITOR;
350 //-----------------------------------------------------------------------
351 void CompositorScriptCompiler::parseTechnique(void)
353 mScriptContext.technique = mScriptContext.compositor->createTechnique();
354 mScriptContext.section = CSS_TECHNIQUE;
356 //-----------------------------------------------------------------------
357 void CompositorScriptCompiler::parseTexture(void)
359 assert(mScriptContext.technique);
360 const String textureName = getNextTokenLabel();
361 CompositionTechnique::TextureDefinition* textureDef = mScriptContext.technique->createTextureDefinition(textureName);
362 // if peek next token is target_width then get token and use 0 for width
363 // determine width parameter
364 if (testNextTokenID(ID_TARGET_WIDTH_SCALED))
366 getNextToken();
367 // a value of zero causes texture to be size of render target
368 textureDef->width = 0;
369 // get factor from next token
370 textureDef->widthFactor = static_cast<float>(getNextTokenValue());
373 else if (testNextTokenID(ID_TARGET_WIDTH))
375 getNextToken();
376 // a value of zero causes texture to be size of render target
377 textureDef->width = 0;
378 textureDef->widthFactor = 1.0f;
380 else
382 textureDef->width = static_cast<size_t>(getNextTokenValue());
384 // determine height parameter
385 if (testNextTokenID(ID_TARGET_HEIGHT_SCALED))
387 getNextToken();
388 // a value of zero causes texture to be dependent on render target
389 textureDef->height = 0;
390 // get factor from next token
391 textureDef->heightFactor = static_cast<float>(getNextTokenValue());
394 else if (testNextTokenID(ID_TARGET_HEIGHT))
396 getNextToken();
397 // a value of zero causes texture to be size of render target
398 textureDef->height = 0;
399 textureDef->heightFactor = 1.0f;
401 else
403 textureDef->height = static_cast<size_t>(getNextTokenValue());
405 // get pixel factor & shared option
406 while (getRemainingTokensForAction() > 0)
408 switch (getNextTokenID())
410 case ID_PF_A8R8G8B8:
411 textureDef->formatList.push_back(PF_A8R8G8B8);
412 break;
414 case ID_PF_R8G8B8A8:
415 textureDef->formatList.push_back(PF_R8G8B8A8);
416 break;
417 case ID_PF_R8G8B8:
418 textureDef->formatList.push_back(PF_R8G8B8);
419 break;
420 case ID_PF_FLOAT16_R:
421 textureDef->formatList.push_back(PF_FLOAT16_R);
422 break;
423 case ID_PF_FLOAT16_GR:
424 textureDef->formatList.push_back(PF_FLOAT16_GR);
425 break;
426 case ID_PF_FLOAT16_RGB:
427 textureDef->formatList.push_back(PF_FLOAT16_RGB);
428 break;
429 case ID_PF_FLOAT16_RGBA:
430 textureDef->formatList.push_back(PF_FLOAT16_RGBA);
431 break;
432 case ID_PF_FLOAT32_R:
433 textureDef->formatList.push_back(PF_FLOAT32_R);
434 break;
435 case ID_PF_FLOAT32_GR:
436 textureDef->formatList.push_back(PF_FLOAT32_GR);
437 break;
438 case ID_PF_FLOAT32_RGB:
439 textureDef->formatList.push_back(PF_FLOAT32_RGB);
440 break;
441 case ID_PF_FLOAT32_RGBA:
442 textureDef->formatList.push_back(PF_FLOAT32_RGBA);
443 break;
444 case ID_SHARED:
445 textureDef->shared = true;
446 break;
447 case ID_GAMMA:
448 textureDef->hwGammaWrite = true;
449 break;
450 case ID_NO_FSAA:
451 textureDef->fsaa = false;
452 break;
453 default:
454 // should never get here?
455 break;
459 //-----------------------------------------------------------------------
460 void CompositorScriptCompiler::parseScheme(void)
462 assert(mScriptContext.technique);
463 const String schemeName = getNextTokenLabel();
465 mScriptContext.technique->setSchemeName(schemeName);
467 //-----------------------------------------------------------------------
468 void CompositorScriptCompiler::parseTarget(void)
470 assert(mScriptContext.technique);
472 mScriptContext.section = CSS_TARGET;
473 mScriptContext.target = mScriptContext.technique->createTargetPass();
474 mScriptContext.target->setOutputName(getNextTokenLabel());
477 //-----------------------------------------------------------------------
478 void CompositorScriptCompiler::parseInput(void)
480 // input parameters depends on context either target or pass
481 if (mScriptContext.section == CSS_TARGET)
483 // for input in target, there is only one parameter
484 assert(mScriptContext.target);
485 if (testNextTokenID(ID_PREVIOUS))
486 mScriptContext.target->setInputMode(CompositionTargetPass::IM_PREVIOUS);
487 else
488 mScriptContext.target->setInputMode(CompositionTargetPass::IM_NONE);
490 else // assume for pass section context
492 // for input in pass, there are two parameters
493 assert(mScriptContext.pass);
494 uint32 id = static_cast<uint32>(getNextTokenValue());
495 const String& textureName = getNextTokenLabel();
496 // MRT index?
497 size_t mrtIndex = 0;
498 if (getRemainingTokensForAction() > 0)
500 mrtIndex = static_cast<size_t>(getNextTokenValue());
502 mScriptContext.pass->setInput(id, textureName, mrtIndex);
506 //-----------------------------------------------------------------------
507 void CompositorScriptCompiler::parseTargetOutput(void)
509 assert(mScriptContext.technique);
510 mScriptContext.target = mScriptContext.technique->getOutputTargetPass();
511 mScriptContext.section = CSS_TARGET;
513 //-----------------------------------------------------------------------
514 void CompositorScriptCompiler::parseOnlyInitial(void)
516 assert(mScriptContext.target);
517 mScriptContext.target->setOnlyInitial(testNextTokenID(ID_ON));
519 //-----------------------------------------------------------------------
520 void CompositorScriptCompiler::parseVisibilityMask(void)
522 assert(mScriptContext.target);
523 mScriptContext.target->setVisibilityMask(static_cast<uint32>(getNextTokenValue()));
525 //-----------------------------------------------------------------------
526 void CompositorScriptCompiler::parseLodBias(void)
528 assert(mScriptContext.target);
529 mScriptContext.target->setLodBias(getNextTokenValue());
531 //-----------------------------------------------------------------------
532 void CompositorScriptCompiler::parseMaterialScheme(void)
534 assert(mScriptContext.target);
535 mScriptContext.target->setMaterialScheme(getNextTokenLabel());
537 //-----------------------------------------------------------------------
538 void CompositorScriptCompiler::parseShadowsEnabled(void)
540 assert(mScriptContext.target);
541 mScriptContext.target->setShadowsEnabled(testNextTokenID(ID_ON));
543 //-----------------------------------------------------------------------
544 void CompositorScriptCompiler::parsePass(void)
546 assert(mScriptContext.target);
547 mScriptContext.pass = mScriptContext.target->createPass();
548 CompositionPass::PassType passType = CompositionPass::PT_RENDERQUAD;
549 switch (getNextTokenID())
551 case ID_RENDER_QUAD:
552 passType = CompositionPass::PT_RENDERQUAD;
553 break;
555 case ID_CLEAR:
556 passType = CompositionPass::PT_CLEAR;
557 break;
559 case ID_STENCIL:
560 passType = CompositionPass::PT_STENCIL;
561 break;
563 case ID_RENDER_SCENE:
564 passType = CompositionPass::PT_RENDERSCENE;
565 break;
567 default:
568 break;
571 mScriptContext.pass->setType(passType);
573 mScriptContext.section = CSS_PASS;
576 //-----------------------------------------------------------------------
577 void CompositorScriptCompiler::parseMaterial(void)
579 assert(mScriptContext.pass);
580 mScriptContext.pass->setMaterialName(getNextTokenLabel());
582 //-----------------------------------------------------------------------
583 void CompositorScriptCompiler::parseFirstRenderQueue(void)
585 assert(mScriptContext.pass);
586 mScriptContext.pass->setFirstRenderQueue(static_cast<uint8>(getNextTokenValue()));
588 //-----------------------------------------------------------------------
589 void CompositorScriptCompiler::parseLastRenderQueue(void)
591 assert(mScriptContext.pass);
592 mScriptContext.pass->setLastRenderQueue(static_cast<uint8>(getNextTokenValue()));
594 //-----------------------------------------------------------------------
595 void CompositorScriptCompiler::parseIdentifier(void)
597 assert(mScriptContext.pass);
598 mScriptContext.pass->setIdentifier(static_cast<uint32>(getNextTokenValue()));
600 //-----------------------------------------------------------------------
601 void CompositorScriptCompiler::parseClearBuffers(void)
603 assert(mScriptContext.pass);
604 // while there are tokens for the action, get next token and set buffer flag
605 uint32 bufferFlags = 0;
607 while (getRemainingTokensForAction() > 0)
609 switch (getNextTokenID())
611 case ID_CLR_COLOUR:
612 bufferFlags |= FBT_COLOUR;
613 break;
615 case ID_CLR_DEPTH:
616 bufferFlags |= FBT_DEPTH;
617 break;
619 case ID_STENCIL:
620 bufferFlags |= FBT_STENCIL;
621 break;
623 default:
624 break;
627 mScriptContext.pass->setClearBuffers(bufferFlags);
629 //-----------------------------------------------------------------------
630 void CompositorScriptCompiler::parseClearColourValue(void)
632 assert(mScriptContext.pass);
633 Real red = getNextTokenValue();
634 Real green = getNextTokenValue();
635 Real blue = getNextTokenValue();
636 Real alpha = getNextTokenValue();
637 mScriptContext.pass->setClearColour(ColourValue(red, green, blue, alpha));
639 //-----------------------------------------------------------------------
640 void CompositorScriptCompiler::parseClearDepthValue(void)
642 assert(mScriptContext.pass);
643 mScriptContext.pass->setClearDepth(getNextTokenValue());
645 //-----------------------------------------------------------------------
646 void CompositorScriptCompiler::parseClearStencilValue(void)
648 assert(mScriptContext.pass);
649 mScriptContext.pass->setClearStencil(static_cast<uint32>(getNextTokenValue()));
651 //-----------------------------------------------------------------------
652 void CompositorScriptCompiler::parseStencilCheck(void)
654 assert(mScriptContext.pass);
655 mScriptContext.pass->setStencilCheck(testNextTokenID(ID_ON));
657 //-----------------------------------------------------------------------
658 void CompositorScriptCompiler::parseStencilFunc(void)
660 assert(mScriptContext.pass);
661 mScriptContext.pass->setStencilFunc(extractCompareFunc());
663 //-----------------------------------------------------------------------
664 void CompositorScriptCompiler::parseStencilRefVal(void)
666 assert(mScriptContext.pass);
667 mScriptContext.pass->setStencilRefValue(static_cast<uint32>(getNextTokenValue()));
669 //-----------------------------------------------------------------------
670 void CompositorScriptCompiler::parseStencilMask(void)
672 assert(mScriptContext.pass);
673 mScriptContext.pass->setStencilMask(static_cast<uint32>(getNextTokenValue()));
675 //-----------------------------------------------------------------------
676 void CompositorScriptCompiler::parseStencilFailOp(void)
678 assert(mScriptContext.pass);
679 mScriptContext.pass->setStencilFailOp(extractStencilOp());
681 //-----------------------------------------------------------------------
682 void CompositorScriptCompiler::parseStencilDepthFailOp(void)
684 assert(mScriptContext.pass);
685 mScriptContext.pass->setStencilDepthFailOp(extractStencilOp());
687 //-----------------------------------------------------------------------
688 void CompositorScriptCompiler::parseStencilPassOp(void)
690 assert(mScriptContext.pass);
691 mScriptContext.pass->setStencilPassOp(extractStencilOp());
693 //-----------------------------------------------------------------------
694 void CompositorScriptCompiler::parseStencilTwoSided(void)
696 assert(mScriptContext.pass);
697 mScriptContext.pass->setStencilTwoSidedOperation(testNextTokenID(ID_ON));
699 //-----------------------------------------------------------------------
700 StencilOperation CompositorScriptCompiler::extractStencilOp(void)
702 StencilOperation sop = SOP_KEEP;
704 switch (getNextTokenID())
706 case ID_ST_KEEP:
707 sop = SOP_KEEP;
708 break;
710 case ID_ST_ZERO:
711 sop = SOP_ZERO;
712 break;
714 case ID_ST_REPLACE:
715 sop = SOP_REPLACE;
716 break;
718 case ID_ST_INCREMENT:
719 sop = SOP_INCREMENT;
720 break;
722 case ID_ST_DECREMENT:
723 sop = SOP_DECREMENT;
724 break;
726 case ID_ST_INCREMENT_WRAP:
727 sop = SOP_INCREMENT_WRAP;
728 break;
730 case ID_ST_DECREMENT_WRAP:
731 sop = SOP_DECREMENT_WRAP;
732 break;
734 case ID_ST_INVERT:
735 sop = SOP_INVERT;
736 break;
738 default:
739 break;
742 return sop;
744 CompareFunction CompositorScriptCompiler::extractCompareFunc(void)
746 CompareFunction compFunc = CMPF_ALWAYS_PASS;
748 switch (getNextTokenID())
750 case ID_ST_ALWAYS_FAIL:
751 compFunc = CMPF_ALWAYS_FAIL;
752 break;
754 case ID_ST_ALWAYS_PASS:
755 compFunc = CMPF_ALWAYS_PASS;
756 break;
758 case ID_ST_LESS:
759 compFunc = CMPF_LESS;
760 break;
762 case ID_ST_LESS_EQUAL:
763 compFunc = CMPF_LESS_EQUAL;
764 break;
766 case ID_ST_EQUAL:
767 compFunc = CMPF_EQUAL;
768 break;
770 case ID_ST_NOT_EQUAL:
771 compFunc = CMPF_NOT_EQUAL;
772 break;
774 case ID_ST_GREATER_EQUAL:
775 compFunc = CMPF_GREATER_EQUAL;
776 break;
778 case ID_ST_GREATER:
779 compFunc = CMPF_GREATER;
780 break;
782 default:
783 break;
786 return compFunc;