Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreMaterialScriptCompiler.h @ 5

Last change on this file since 5 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 12.9 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
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 Lesser 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 Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser 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/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29
30#ifndef __MaterialScriptScompiler_H__
31#define __MaterialScriptScompiler_H__
32
33#include "OgreCompiler2Pass.h"
34#include "OgreTextureUnitState.h"
35#include "OgreMaterial.h"
36#include "OgreGpuProgram.h"
37#include "OgreStringVector.h"
38
39namespace Ogre {
40
41    class _OgreExport MaterialScriptCompiler : public Compiler2Pass
42    {
43
44    public:
45        MaterialScriptCompiler(void);
46        ~MaterialScriptCompiler(void);
47
48        /** gets BNF Grammer for Compositor script.
49        */
50        virtual const String& getClientBNFGrammer(void) const;
51
52        /** get the name of the BNF grammer.
53        */
54        virtual const String& getClientGrammerName(void) const;
55
56        /** Compile a material script from a data stream using a specific resource group name.
57        @param stream Weak reference to a data stream which is the source of the material script
58        @param groupName The name of the resource group that resources which are
59                        parsed are to become a member of. If this group is loaded or unloaded,
60                        then the resources discovered in this script will be loaded / unloaded
61                        with it.
62        @param allowOverride if material or gpu program name already exists then use definition
63            in the material script being parsed to override the existing instance.  The default
64            value is false which causes an exception to be thrown if a duplicate is found.
65        */
66        void parseScript(DataStreamPtr& stream, const String& groupName, const bool allowOverride = false);
67
68    protected:
69            // Token ID enumeration
70            enum TokenID {
71                    // Terminal Tokens section
72            ID_UNKOWN = 0,
73            // GPU Program
74            ID_VERTEX_PROGRAM, ID_FRAGMENT_PROGRAM,
75
76            // material
77            ID_CLONE,
78
79            // technique
80
81            // pass
82
83            ID_VERTEXCOLOUR,
84            // scene blend
85            ID_COLOUR_BLEND, ID_DEST_COLOUR,
86            ID_SRC_COLOUR, ID_ONE_MINUS_DEST_COLOUR, ID_ONE_MINUS_SRC_COLOUR,
87            ID_DEST_ALPHA, ID_SRC_ALPHA, ID_ONE_MINUS_DEST_ALPHA, ID_ONE_MINUS_SRC_ALPHA,
88            // Depth
89            ID_ALWAYS_FAIL, ID_ALWAYS_PASS,
90            ID_LESS_EQUAL, ID_LESS, ID_EQUAL, ID_NOT_EQUAL, ID_GREATER_EQUAL, ID_GREATER,
91            // culling
92            ID_CLOCKWISE, ID_ANTICLOCKWISE,
93            ID_CULL_BACK, ID_CULL_FRONT,
94            // shading
95            ID_FLAT, ID_GOURAUD, ID_PHONG,
96            // polygon mode
97            ID_SOLID, ID_WIREFRAME, ID_POINTS,
98            // fog overide
99            ID_EXP, ID_EXP2,
100            // iteration
101            ID_ONCE, ID_ONCE_PER_LIGHT, ID_PER_LIGHT, ID_PER_N_LIGHTS, ID_DIRECTIONAL, ID_SPOT,
102
103            // texture unit state
104            // texture
105            ID_1D, ID_2D, ID_3D, ID_CUBIC, ID_UNLIMITED, ID_ALPHA,
106            // cubic texture
107            ID_SEPARATE_UV, ID_COMBINED_UVW,
108            // address mode
109            ID_WRAP, ID_CLAMP, ID_MIRROR, ID_BORDER,
110            // filtering
111            ID_BILINEAR, ID_TRILINEAR, ID_ANISOTROPIC,
112            // color op
113            ID_REPLACE,
114            ID_SOURCE1, ID_SOURCE2, ID_MODULATE_X2, ID_MODULATE_X4, ID_ADD_SIGNED,
115            ID_ADD_SMOOTH, ID_SUBTRACT, ID_BLEND_DIFFUSE_COLOUR, ID_BLEND_DIFFUSE_ALPHA,
116            ID_BLEND_TEXTURE_ALPHA, ID_BLEND_CURRENT_ALPHA, ID_BLEND_MANUAL, ID_DOTPRODUCT,
117            ID_SRC_CURRENT, ID_SRC_TEXTURE, ID_SRC_DIFFUSE, ID_SRC_SPECULAR, ID_SRC_MANUAL,
118
119            // env map
120            ID_SPHERICAL, ID_PLANAR, ID_CUBIC_REFLECTION, ID_CUBIC_NORMAL,
121            // wave transform
122            ID_SCROLL_X, ID_SCROLL_Y, ID_SCALE_X, ID_SCALE_Y, ID_SINE, ID_TRIANGLE,
123            ID_SQUARE, ID_SAWTOOTH, ID_INVERSE_SAWTOOTH, ID_ROTATE,
124                        // content type
125                        ID_NAMED, ID_SHADOW,
126
127            // GPU program references
128            // GPU Parameters
129
130            // general
131            ID_ON, ID_OFF, ID_TRUE, ID_FALSE, ID_NONE, ID_POINT, ID_LINEAR, ID_ADD, ID_MODULATE, ID_ALPHA_BLEND,
132            ID_ONE, ID_ZERO, ID_VERTEX, ID_FRAGMENT,
133
134            // where auto generated tokens start so donot remove
135            ID_AUTOTOKENSTART
136        };
137
138        /** Enum to identify material sections. */
139        enum MaterialScriptSection
140        {
141            MSS_NONE,
142            MSS_MATERIAL,
143            MSS_TECHNIQUE,
144            MSS_PASS,
145            MSS_TEXTUREUNIT,
146            MSS_PROGRAM_REF,
147                    MSS_PROGRAM,
148            MSS_DEFAULT_PARAMETERS,
149                    MSS_TEXTURESOURCE
150        };
151            /** Struct for holding a program definition which is in progress. */
152            struct MaterialScriptProgramDefinition
153            {
154                    String name;
155                    GpuProgramType progType;
156            String language;
157                    String source;
158                    String syntax;
159            bool supportsSkeletalAnimation;
160                    bool supportsMorphAnimation;
161                    ushort supportsPoseAnimation; // number of simultaneous poses supported
162            bool usesVertexTextureFetch;
163                        std::vector<std::pair<String, String> > customParameters;
164            };
165        /** Struct for holding the script context while parsing. */
166        struct MaterialScriptContext
167        {
168            MaterialScriptSection section;
169                    String groupName;
170            MaterialPtr material;
171            Technique* technique;
172            Pass* pass;
173            TextureUnitState* textureUnit;
174            GpuProgramPtr program; // used when referencing a program, not when defining it
175            bool isProgramShadowCaster; // when referencing, are we in context of shadow caster
176            bool isVertexProgramShadowReceiver; // when referencing, are we in context of shadow caster
177            bool isFragmentProgramShadowReceiver; // when referencing, are we in context of shadow caster
178            bool allowOverride; // if true then allow existing materials and gpu programs to be overriden
179            GpuProgramParametersSharedPtr programParams;
180                        ushort numAnimationParametrics;
181                    MaterialScriptProgramDefinition* programDef; // this is used while defining a program
182
183                    int techLev,        //Keep track of what tech, pass, and state level we are in
184                            passLev,
185                            stateLev;
186            // container of token que positions for default params that require pass 2 processing
187            std::vector<size_t> pendingDefaultParams;
188
189            AliasTextureNamePairList textureAliases;
190        };
191
192        MaterialScriptContext mScriptContext;
193
194        typedef void (MaterialScriptCompiler::* MSC_Action)(void);
195        typedef std::map<size_t, MSC_Action> TokenActionMap;
196        typedef TokenActionMap::iterator TokenActionIterator;
197        /** Map of Token value as key to an Action.  An Action converts tokens into
198            the final format.
199            All instances use the same Token Action Map.
200        */
201        static TokenActionMap mTokenActionMap;
202
203        /** Execute an Action associated with a token.  Gets called when the compiler finishes tokenizing a
204            section of the source that has been parsed.
205        **/
206        virtual void executeTokenAction(const size_t tokenID);
207        /** Get the start position of auto generated token IDs.
208        */
209        virtual size_t getAutoTokenIDStart() const {return ID_AUTOTOKENSTART;}
210
211        /** Associate all the lexemes used in a material script with their corresponding tokens and actions.
212        **/
213        virtual void setupTokenDefinitions(void);
214        void addLexemeTokenAction(const String& lexeme, const size_t token, const MSC_Action action = 0);
215        /** Associate all the lexemes used in a material script with their corresponding actions and have
216            token IDs auto-generated.
217        **/
218        void addLexemeAction(const String& lexeme, const MSC_Action action) {addLexemeTokenAction(lexeme, 0, action);}
219
220        void logParseError(const String& error);
221
222        // support methods that convert tokens
223        ColourValue _parseColourValue(void);
224        CompareFunction convertCompareFunction(void);
225
226        // Token Actions which get called when tokens are created during parsing.
227        void parseOpenBrace(void);
228        void parseCloseBrace(void);
229        // material section Actions
230        void parseMaterial(void);
231        void parseLodDistances(void);
232        void parseReceiveShadows(void);
233        void parseTransparencyCastsShadows(void);
234        void parseSetTextureAlias(void);
235        // Technique related actions
236        void parseTechnique(void);
237        void parseScheme(void);
238        void parseLodIndex(void);
239        // Pass related Actions
240        void parsePass(void);
241        void parseAmbient(void);
242        void parseDiffuse(void);
243        void parseSpecular(void);
244        void parseEmissive(void);
245        void parseSceneBlend(void);
246        SceneBlendFactor convertBlendFactor(void);
247        void parseDepthCheck(void);
248        void parseDepthWrite(void);
249        void parseDepthFunc(void);
250        void parseDepthBias(void);
251        void parseAlphaRejection(void);
252        void parseCullHardware(void);
253        void parseCullSoftware(void);
254        void parseLighting(void);
255        void parseShading(void);
256        void parsePolygonMode(void);
257        void parseFogOverride(void);
258        void parseMaxLights(void);
259                void parseStartLight(void);
260        void parseIteration(void);
261        void parseIterationLightTypes(void);
262        void parseColourWrite(void);
263        void parsePointSize(void);
264        void parsePointSprites(void);
265        void parsePointSizeMin(void);
266        void parsePointSizeMax(void);
267        void parsePointSizeAttenuation(void);
268        // Texture Unit related Actions
269        void parseTextureUnit(void);
270        void parseTextureAlias(void);
271        void parseTexture(void);
272        void parseAnimTexture(void);
273        void parseCubicTexture(void);
274        void parseTexCoord(void);
275        TextureUnitState::TextureAddressingMode convTexAddressMode(void);
276        void parseTexAddressMode(void);
277        void parseTexBorderColour(void);
278        void parseFiltering(void);
279        FilterOptions convertFiltering();
280        void parseMaxAnisotropy(void);
281        void parseMipMapBias(void);
282        void parseColourOp(void);
283        void parseColourOpEx(void);
284        LayerBlendOperationEx convertBlendOpEx(void);
285        LayerBlendSource convertBlendSource(void);
286        void parseColourOpMultipassFallback(void);
287        void parseAlphaOpEx(void);
288        void parseEnvMap(void);
289        void parseScroll(void);
290        void parseScrollAnim(void);
291        void parseRotate(void);
292        void parseRotateAnim(void);
293        void parseScale(void);
294        void parseWaveXform(void);
295        void parseTransform(void);
296        void parseTextureCustomParameter(void);
297        void parseBindingType(void);
298                void parseContentType(void);
299
300        // GPU Program
301        void parseGPUProgram(void);
302        void parseProgramSource(void);
303        void parseProgramSyntax(void);
304        void parseProgramCustomParameter(void);
305        void parseDefaultParams(void);
306        void parseProgramSkeletalAnimation(void);
307        void parseProgramMorphAnimation(void);
308        void parseProgramPoseAnimation(void);
309        void parseProgramVertexTextureFetch(void);
310        void parseVertexProgramRef(void);
311        void parseFragmentProgramRef(void);
312        void parseShadowCasterVertexProgramRef(void);
313        void parseShadowReceiverVertexProgramRef(void);
314        void parseShadowReceiverFragmentProgramRef(void);
315        void parseParamIndexed(void);
316        void parseParamIndexedAuto(void);
317        void parseParamNamed(void);
318        void parseParamNamedAuto(void);
319        void processManualProgramParam(bool isNamed, const String commandName, 
320                        size_t index = 0, const String& paramName = StringUtil::BLANK);
321                void processAutoProgramParam(bool isNamed, const String commandName, 
322                        size_t index, const String& paramName = StringUtil::BLANK);
323
324
325        void finishProgramDefinition(void);
326
327    };
328}
329
330#endif
Note: See TracBrowser for help on using the repository browser.