source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreCompositorScriptCompiler.h @ 1812

Revision 1812, 6.7 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[1812]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.stevestreeting.com/ogre/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://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
35namespace 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) const { static const String grammerName("Compositor Script"); return grammerName; }
52        /** Compile a compositor script from a data stream using a specific resource group name.
53        @param stream Weak reference to a data stream which is the source of the material script
54        @param groupName The name of the resource group that resources which are
55                        parsed are to become a member of. If this group is loaded or unloaded,
56                        then the resources discovered in this script will be loaded / unloaded
57                        with it.
58        */
59        void parseScript(DataStreamPtr& stream, const String& groupName)
60        {
61            mScriptContext.groupName = groupName;
62            Compiler2Pass::compile(stream->getAsString(),  stream->getName());
63        }
64
65        protected:
66                // Token ID enumeration
67                enum TokenID {
68                        // Terminal Tokens section
69                        ID_UNKOWN = 0, ID_OPENBRACE, ID_CLOSEBRACE,
70                        // Top level
71                        ID_COMPOSITOR,
72                        // Techniques
73                        ID_TECHNIQUE, ID_TEXTURE, ID_TARGET_WIDTH, ID_TARGET_HEIGHT,
74                        ID_PF_A8R8G8B8, ID_PF_R8G8B8A8, ID_PF_R8G8B8,
75                        ID_PF_FLOAT16_R, ID_PF_FLOAT16_RGB, ID_PF_FLOAT16_RGBA,
76                        ID_PF_FLOAT32_R, ID_PF_FLOAT32_RGB, ID_PF_FLOAT32_RGBA,
77                        // Targets
78                        ID_TARGET, ID_INPUT, ID_TARGET_OUTPUT, ID_ONLY_INITIAL,
79                        ID_VISIBILITY_MASK, ID_LOD_BIAS, ID_MATERIAL_SCHEME,
80                        ID_PREVIOUS, ID_NONE,
81                        // Passes
82                        ID_PASS,
83                        ID_MATERIAL,
84                        ID_RENDER_QUAD, ID_CLEAR, ID_STENCIL, ID_RENDER_SCENE,
85                        ID_FIRST_RQ, ID_LAST_RQ,
86                        ID_IDENTIFIER,
87                        // clear
88                        ID_CLR_BUFF, ID_CLR_COLOUR, ID_CLR_DEPTH,
89                        ID_CLR_COLOUR_VAL, ID_CLR_DEPTH_VAL, ID_CLR_STENCIL_VAL,
90                        // stencil
91                        ID_ST_CHECK, ID_ST_FUNC, ID_ST_REF_VAL, ID_ST_MASK, ID_ST_FAILOP,
92                        ID_ST_DEPTH_FAILOP, ID_ST_PASSOP, ID_ST_TWOSIDED,
93
94                        // compare functions
95            ID_ST_ALWAYS_FAIL, ID_ST_ALWAYS_PASS, ID_ST_LESS,
96            ID_ST_LESS_EQUAL, ID_ST_EQUAL, ID_ST_NOT_EQUAL,
97            ID_ST_GREATER_EQUAL, ID_ST_GREATER,
98
99            // stencil operations
100            ID_ST_KEEP, ID_ST_ZERO, ID_ST_REPLACE, ID_ST_INCREMENT,
101            ID_ST_DECREMENT, ID_ST_INCREMENT_WRAP, ID_ST_DECREMENT_WRAP,
102            ID_ST_INVERT,
103
104                        // general
105                        ID_ON, ID_OFF, ID_TRUE, ID_FALSE
106                };
107
108                /** Enum to identify compositor sections. */
109                enum CompositorScriptSection
110                {
111                        CSS_NONE,
112                        CSS_COMPOSITOR,
113                        CSS_TECHNIQUE,
114                        CSS_TARGET,
115                        CSS_PASS
116                };
117                /** Struct for holding the script context while parsing. */
118                struct CompositorScriptContext
119                {
120                        CompositorScriptSection section;
121                    String groupName;
122                        CompositorPtr compositor;
123                        CompositionTechnique* technique;
124                        CompositionTargetPass* target;
125                        CompositionPass* pass;
126                };
127
128                CompositorScriptContext mScriptContext;
129
130                // static library database for tokens and BNF rules
131                static TokenRule compositorScript_RulePath[];
132                // simplified Backus - Naur Form (BNF) grammer for compositor scripts
133                static String compositorScript_BNF;
134
135                typedef void (CompositorScriptCompiler::* CSC_Action)(void);
136                typedef std::map<size_t, CSC_Action> TokenActionMap;
137                typedef TokenActionMap::iterator TokenActionIterator;
138                /** Map of Token value as key to an Action.  An Action converts tokens into
139                the final format.
140            All instances use the same Token Action Map.
141                */
142                static TokenActionMap mTokenActionMap;
143
144                /** Execute an Action associated with a token.  Gets called when the compiler finishes tokenizing a
145                section of the source that has been parsed.
146                **/
147                virtual void executeTokenAction(const size_t tokenID);
148                /** Associate all the lexemes used in a material script with their corresponding tokens and actions.
149                **/
150        virtual void setupTokenDefinitions(void);
151                void addLexemeTokenAction(const String& lexeme, const size_t token, const CSC_Action action = 0);
152
153                void logParseError(const String& error);
154
155                // Token Actions which get called when tokens are created during parsing.
156                void parseOpenBrace(void);
157                void parseCloseBrace(void);
158                void parseCompositor(void);
159                void parseTechnique(void);
160                void parseTexture(void);
161                void parseTarget(void);
162                void parseInput(void);
163                void parseTargetOutput(void);
164                void parseOnlyInitial(void);
165                void parseVisibilityMask(void);
166                void parseLodBias(void);
167                void parseMaterialScheme(void);
168                void parsePass(void);
169                void parseMaterial(void);
170                void parseFirstRenderQueue(void);
171                void parseLastRenderQueue(void);
172                void parseIdentifier(void);
173                void parseClearBuffers(void);
174                void parseClearColourValue(void);
175                void parseClearDepthValue(void);
176                void parseClearStencilValue(void);
177                void parseStencilCheck(void);
178                void parseStencilFunc(void);
179                void parseStencilRefVal(void);
180                void parseStencilMask(void);
181                void parseStencilFailOp(void);
182                void parseStencilDepthFailOp(void);
183                void parseStencilPassOp(void);
184                void parseStencilTwoSided(void);
185                StencilOperation extractStencilOp(void);
186        CompareFunction extractCompareFunc(void);
187        };
188}
189
190#endif
Note: See TracBrowser for help on using the repository browser.