[692] | 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 |
|
---|
| 26 | #ifndef __CompositorScriptScompiler_H__
|
---|
| 27 | #define __CompositorScriptScompiler_H__
|
---|
| 28 |
|
---|
| 29 | #include "OgrePrerequisites.h"
|
---|
| 30 | #include "OgreCompiler2Pass.h"
|
---|
| 31 | #include "OgreCompositor.h"
|
---|
| 32 | #include "OgreRenderSystem.h"
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | namespace Ogre {
|
---|
| 36 |
|
---|
| 37 | /** Compiler for parsing & lexing .compositor scripts */
|
---|
| 38 | class _OgreExport CompositorScriptCompiler : public Compiler2Pass
|
---|
| 39 | {
|
---|
| 40 |
|
---|
| 41 | public:
|
---|
| 42 | CompositorScriptCompiler(void);
|
---|
| 43 | ~CompositorScriptCompiler(void);
|
---|
| 44 |
|
---|
| 45 | /** gets BNF Grammer for Compositor script.
|
---|
| 46 | */
|
---|
| 47 | virtual const String& getClientBNFGrammer(void) { return compositorScript_BNF; }
|
---|
| 48 |
|
---|
| 49 | /** get the name of the Compositor script BNF grammer.
|
---|
| 50 | */
|
---|
| 51 | virtual const String& getClientGrammerName(void) { static const String grammerName("Compositor Script"); return grammerName; }
|
---|
| 52 |
|
---|
| 53 | protected:
|
---|
| 54 | // Token ID enumeration
|
---|
| 55 | enum TokenID {
|
---|
| 56 | // Terminal Tokens section
|
---|
| 57 | ID_UNKOWN = 0, ID_OPENBRACE, ID_CLOSEBRACE,
|
---|
| 58 | // Top level
|
---|
| 59 | ID_COMPOSITOR,
|
---|
| 60 | // Techniques
|
---|
| 61 | ID_TECHNIQUE, ID_TEXTURE, ID_TARGET_WIDTH, ID_TARGET_HEIGHT,
|
---|
| 62 | ID_PF_A8R8G8B8, ID_PF_R8G8B8A8, ID_PF_R8G8B8,
|
---|
| 63 | ID_PF_FLOAT16_R, ID_PF_FLOAT16_RGB, ID_PF_FLOAT16_RGBA,
|
---|
| 64 | ID_PF_FLOAT32_R, ID_PF_FLOAT32_RGB, ID_PF_FLOAT32_RGBA,
|
---|
| 65 | // Targets
|
---|
| 66 | ID_TARGET, ID_INPUT, ID_TARGET_OUTPUT, ID_ONLY_INITIAL,
|
---|
| 67 | ID_VISIBILITY_MASK, ID_LOD_BIAS, ID_MATERIAL_SCHEME,
|
---|
| 68 | ID_PREVIOUS, ID_NONE,
|
---|
| 69 | // Passes
|
---|
| 70 | ID_PASS,
|
---|
| 71 | ID_MATERIAL,
|
---|
| 72 | ID_RENDER_QUAD, ID_CLEAR, ID_STENCIL, ID_RENDER_SCENE,
|
---|
| 73 | ID_FIRST_RQ, ID_LAST_RQ,
|
---|
| 74 | // clear
|
---|
| 75 | ID_CLR_BUFF, ID_CLR_COLOUR, ID_CLR_DEPTH,
|
---|
| 76 | ID_CLR_COLOUR_VAL, ID_CLR_DEPTH_VAL, ID_CLR_STENCIL_VAL,
|
---|
| 77 | // stencil
|
---|
| 78 | ID_ST_CHECK, ID_ST_FUNC, ID_ST_REF_VAL, ID_ST_MASK, ID_ST_FAILOP,
|
---|
| 79 | ID_ST_DEPTH_FAILOP, ID_ST_PASSOP, ID_ST_TWOSIDED,
|
---|
| 80 |
|
---|
| 81 | // compare functions
|
---|
| 82 | ID_ST_ALWAYS_FAIL, ID_ST_ALWAYS_PASS, ID_ST_LESS,
|
---|
| 83 | ID_ST_LESS_EQUAL, ID_ST_EQUAL, ID_ST_NOT_EQUAL,
|
---|
| 84 | ID_ST_GREATER_EQUAL, ID_ST_GREATER,
|
---|
| 85 |
|
---|
| 86 | // stencil operations
|
---|
| 87 | ID_ST_KEEP, ID_ST_ZERO, ID_ST_REPLACE, ID_ST_INCREMENT,
|
---|
| 88 | ID_ST_DECREMENT, ID_ST_INCREMENT_WRAP, ID_ST_DECREMENT_WRAP,
|
---|
| 89 | ID_ST_INVERT,
|
---|
| 90 |
|
---|
| 91 | // general
|
---|
| 92 | ID_ON, ID_OFF, ID_TRUE, ID_FALSE
|
---|
| 93 | };
|
---|
| 94 |
|
---|
| 95 | /** Enum to identify compositor sections. */
|
---|
| 96 | enum CompositorScriptSection
|
---|
| 97 | {
|
---|
| 98 | CSS_NONE,
|
---|
| 99 | CSS_COMPOSITOR,
|
---|
| 100 | CSS_TECHNIQUE,
|
---|
| 101 | CSS_TARGET,
|
---|
| 102 | CSS_PASS
|
---|
| 103 | };
|
---|
| 104 | /** Struct for holding the script context while parsing. */
|
---|
| 105 | struct CompositorScriptContext
|
---|
| 106 | {
|
---|
| 107 | CompositorScriptSection section;
|
---|
| 108 | CompositorPtr compositor;
|
---|
| 109 | CompositionTechnique* technique;
|
---|
| 110 | CompositionTargetPass* target;
|
---|
| 111 | CompositionPass* pass;
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | CompositorScriptContext mScriptContext;
|
---|
| 115 |
|
---|
| 116 | // static library database for tokens and BNF rules
|
---|
| 117 | static TokenRule compositorScript_RulePath[];
|
---|
| 118 | // simplified Backus - Naur Form (BNF) grammer for compositor scripts
|
---|
| 119 | static String compositorScript_BNF;
|
---|
| 120 |
|
---|
| 121 | typedef void (CompositorScriptCompiler::* CSC_Action)(void);
|
---|
| 122 | typedef std::map<size_t, CSC_Action> TokenActionMap;
|
---|
| 123 | typedef TokenActionMap::iterator TokenActionIterator;
|
---|
| 124 | /** Map of Token value as key to an Action. An Action converts tokens into
|
---|
| 125 | the final format.
|
---|
| 126 | All instances use the same Token Action Map.
|
---|
| 127 | */
|
---|
| 128 | static TokenActionMap mTokenActionMap;
|
---|
| 129 |
|
---|
| 130 | /** Execute an Action associated with a token. Gets called when the compiler finishes tokenizing a
|
---|
| 131 | section of the source that has been parsed.
|
---|
| 132 | **/
|
---|
| 133 | virtual void executeTokenAction(const size_t tokenID);
|
---|
| 134 | /** Associate all the lexemes used in a material script with their corresponding tokens and actions.
|
---|
| 135 | **/
|
---|
| 136 | virtual void setupTokenDefinitions(void);
|
---|
| 137 | void addLexemeTokenAction(const String& lexeme, const size_t token, const CSC_Action action = 0);
|
---|
| 138 |
|
---|
| 139 | void logParseError(const String& error);
|
---|
| 140 |
|
---|
| 141 | // Token Actions which get called when tokens are created during parsing.
|
---|
| 142 | void parseOpenBrace(void);
|
---|
| 143 | void parseCloseBrace(void);
|
---|
| 144 | void parseCompositor(void);
|
---|
| 145 | void parseTechnique(void);
|
---|
| 146 | void parseTexture(void);
|
---|
| 147 | void parseTarget(void);
|
---|
| 148 | void parseInput(void);
|
---|
| 149 | void parseTargetOutput(void);
|
---|
| 150 | void parseOnlyInitial(void);
|
---|
| 151 | void parseVisibilityMask(void);
|
---|
| 152 | void parseLodBias(void);
|
---|
| 153 | void parseMaterialScheme(void);
|
---|
| 154 | void parsePass(void);
|
---|
| 155 | void parseMaterial(void);
|
---|
| 156 | void parseFirstRenderQueue(void);
|
---|
| 157 | void parseLastRenderQueue(void);
|
---|
| 158 | void parseClearBuffers(void);
|
---|
| 159 | void parseClearColourValue(void);
|
---|
| 160 | void parseClearDepthValue(void);
|
---|
| 161 | void parseClearStencilValue(void);
|
---|
| 162 | void parseStencilCheck(void);
|
---|
| 163 | void parseStencilFunc(void);
|
---|
| 164 | void parseStencilRefVal(void);
|
---|
| 165 | void parseStencilMask(void);
|
---|
| 166 | void parseStencilFailOp(void);
|
---|
| 167 | void parseStencilDepthFailOp(void);
|
---|
| 168 | void parseStencilPassOp(void);
|
---|
| 169 | void parseStencilTwoSided(void);
|
---|
| 170 | StencilOperation extractStencilOp(void);
|
---|
| 171 | CompareFunction extractCompareFunc(void);
|
---|
| 172 | };
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | #endif
|
---|