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