source: OGRE/trunk/ogrenew/OgreMain/include/OgreMaterialScriptCompiler.h @ 692

Revision 692, 8.1 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

RevLine 
[692]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 __MaterialScriptScompiler_H__
27#define __MaterialScriptScompiler_H__
28
29#include "OgreCompiler2Pass.h"
30#include "OgrePrerequisites.h"
31//#include "OgreMaterial.h"
32//#include "OgreBlendMode.h"
33//#include "OgreTextureUnitState.h"
34//#include "OgreGpuProgram.h"
35
36namespace Ogre {
37
38    class _OgreExport MaterialScriptCompiler : public Compiler2Pass
39    {
40
41    public:
42        MaterialScriptCompiler(void);
43        ~MaterialScriptCompiler(void);
44        /** gets BNF Grammer for Compositor script.
45        */
46        virtual const String& getClientBNFGrammer(void) { return materialScript_BNF; }
47
48        /** get the name of the BNF grammer.
49        */
50        virtual const String& getClientGrammerName(void) { static const String grammerName("Material Script"); return grammerName; }
51
52    protected:
53            // Token ID enumeration
54            enum TokenID {
55                    // Terminal Tokens section
56            ID_UNKOWN = 0, ID_OPENBRACE, ID_CLOSEBRACE,
57            ID_VERTEX_PROGRAM, ID_FRAGMENT_PROGRAM,
58            // material
59            ID_MATERIAL, ID_CLONE, ID_TECHNIQUE, ID_SET_TEXTURE_ALIAS, ID_LOD_DISTANCES,
60            ID_RECEIVE_SHADOWS, ID_TRANSPARENCY_CASTS_SHADOWS, ID_LOD_INDEX,
61
62            // pass
63            ID_PASS, ID_AMBIENT, ID_DIFFUSE, ID_SPECULAR, ID_EMISSIVE,
64            ID_VERTEXCOLOUR, ID_SCENE_BLEND, ID_BLEND_ADD, ID_BLEND_MODULATE, ID_COLOUR_BLEND, ID_ALPHA_BLEND,
65            ID_BLEND_ONE, ID_BLEND_ZERO, ID_BLEND_DEST_COLOUR,
66            ID_BLEND_SRC_COLOUR, ID_BLEND_ONCE_MINUS_DEST_COLOUR, ID_BLEND_ONE_MINUS_SRC_COLOUR,
67            ID_BLEND_DEST_ALPHA, ID_BLEND_SRC_ALPHA, ID_BLEND_ONE_MINUS_DEST_ALPHA, ID_BLEND_ONE_MINUS_SRC_ALPHA,
68            ID_DEPTH_CHECK, ID_DEPTH_WRITE, ID_ALPHA_REJECTION, ID_DEPTH_FUNC, ID_ALWAYS_FAIL, ID_ALWAYS_PASS,
69            ID_LESS_EQUAL, ID_LESS, ID_EQUAL, ID_NOT_EQUAL, ID_GREATER_EQUAL, ID_GREATER,
70
71            ID_COLOUR_WRITE, ID_CULL_HARDWARE, ID_CLOCKWISE, ID_ANTICLOCKWISE, ID_CULL_NONE,
72            ID_CULL_SOFTWARE, ID_CULL_BACK, ID_CULL_FRONT,
73            ID_SHADING, ID_FLAT, ID_GOURAUD, ID_PHONG,
74            ID_LIGHTING, ID_MAX_LIGHTS, ID_FOG_OVERRIDE,
75                        ID_POINT_SIZE, ID_POINT_SPRITES, ID_POINT_SIZE_ATTENUATION,
76                        ID_POINT_SIZE_MIN, ID_POINT_SIZE_MAX,
77
78            ID_TEXTURE_UNIT,
79
80            // general
81            ID_ON, ID_OFF, ID_TRUE, ID_FALSE
82        };
83
84        /** Enum to identify material sections. */
85        enum MaterialScriptSection
86        {
87            MSS_NONE,
88            MSS_MATERIAL,
89            MSS_TECHNIQUE,
90            MSS_PASS,
91            MSS_TEXTUREUNIT,
92            MSS_PROGRAM_REF,
93                    MSS_PROGRAM,
94            MSS_DEFAULT_PARAMETERS,
95                    MSS_TEXTURESOURCE
96        };
97            /** Struct for holding a program definition which is in progress. */
98            struct MaterialScriptProgramDefinition
99            {
100                    String name;
101                    GpuProgramType progType;
102            String language;
103                    String source;
104                    String syntax;
105            bool supportsSkeletalAnimation;
106                    bool supportsMorphAnimation;
107                    ushort supportsPoseAnimation; // number of simultaneous poses supported
108                    std::map<String, String> customParameters;
109            };
110        /** Struct for holding the script context while parsing. */
111        struct MaterialScriptContext
112        {
113            MaterialScriptSection section;
114                    String groupName;
115            MaterialPtr material;
116            Technique* technique;
117            Pass* pass;
118            TextureUnitState* textureUnit;
119            GpuProgramPtr program; // used when referencing a program, not when defining it
120            bool isProgramShadowCaster; // when referencing, are we in context of shadow caster
121            bool isProgramShadowReceiver; // when referencing, are we in context of shadow caster
122            GpuProgramParametersSharedPtr programParams;
123                        ushort numAnimationParametrics;
124                    MaterialScriptProgramDefinition* programDef; // this is used while defining a program
125
126                    int techLev,        //Keep track of what tech, pass, and state level we are in
127                            passLev,
128                            stateLev;
129            StringVector defaultParamLines;
130
131                    // Error reporting state
132            size_t lineNo;
133            String filename;
134            AliasTextureNamePairList textureAliases;
135        };
136
137        MaterialScriptContext mScriptContext;
138
139            // static library database for tokens and BNF rules
140            static TokenRule materialScript_RulePath[];
141        // simplified Backus - Naur Form (BNF) grammer for material scripts
142        static String materialScript_BNF;
143
144        typedef void (MaterialScriptCompiler::* MSC_Action)(void);
145        typedef std::map<size_t, MSC_Action> TokenActionMap;
146        typedef TokenActionMap::iterator TokenActionIterator;
147        /** Map of Token value as key to an Action.  An Action converts tokens into
148            the final format.
149            All instances use the same Token Action Map.
150        */
151        static TokenActionMap mTokenActionMap;
152
153        /** Execute an Action associated with a token.  Gets called when the compiler finishes tokenizing a
154            section of the source that has been parsed.
155        **/
156        virtual void executeTokenAction(const size_t tokenID);
157        /** Associate all the lexemes used in a material script with their corresponding tokens and actions.
158        **/
159        virtual void setupTokenDefinitions(void);
160        void addLexemeTokenAction(const String& lexeme, const size_t token, const MSC_Action action = 0);
161
162        void logParseError(const String& error);
163
164        // support methods that convert tokens
165        ColourValue _parseColourValue(void);
166        CompareFunction convertCompareFunction(void);
167
168        // Token Actions which get called when tokens are created during parsing.
169        void parseOpenBrace(void);
170        void parseCloseBrace(void);
171        void parseVertexProgram(void);
172        void parseFragmentProgram(void);
173        void parseMaterial(void);
174        // Technique related actions
175        void parseTechnique(void);
176        void parseTransparencyCastsShadows(void);
177        void parseReceiveShadows(void);
178        // Pass related Actions
179        void parsePass(void);
180        void parseAmbient(void);
181        void parseDiffuse(void);
182        void parseSpecular(void);
183        void parseEmissive(void);
184        void parseDepthCheck(void);
185        void parseDepthWrite(void);
186        void parseDepthFunc(void);
187        void parseAlphaRejection(void);
188        void parseColourWrite(void);
189        void parseCullHardware(void);
190        void parseCullSoftware(void);
191        void parseLighting(void);
192        void parseMaxLights(void);
193        void parseShading(void);
194        void parsePointSize(void);
195        void parsePointSprites(void);
196        void parsePointSizeMin(void);
197        void parsePointSizeMax(void);
198        void parsePointSizeAttenuation(void);
199
200        void parseTextureUnit(void);
201        void parseTextureCustomParameter(void);
202        void finishProgramDefinition(void);
203
204    };
205}
206
207#endif
Note: See TracBrowser for help on using the repository browser.