Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

OgreMaterialScriptCompiler.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.stevestreeting.com/ogre/
00006 
00007 Copyright (c) 2000-2005 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/gpl.html.
00023 -----------------------------------------------------------------------------
00024 */
00025 
00026 #ifndef __MaterialScriptScompiler_H__
00027 #define __MaterialScriptScompiler_H__
00028 
00029 #include "OgreCompiler2Pass.h"
00030 #include "OgrePrerequisites.h"
00031 //#include "OgreMaterial.h"
00032 //#include "OgreBlendMode.h"
00033 //#include "OgreTextureUnitState.h"
00034 //#include "OgreGpuProgram.h"
00035 
00036 namespace Ogre {
00037 
00038     class _OgreExport MaterialScriptCompiler : public Compiler2Pass
00039     {
00040 
00041     public:
00042         MaterialScriptCompiler(void);
00043         ~MaterialScriptCompiler(void);
00046         virtual const String& getClientBNFGrammer(void) { return materialScript_BNF; }
00047 
00050         virtual const String& getClientGrammerName(void) { static const String grammerName("Material Script"); return grammerName; }
00051 
00052     protected:
00053         // Token ID enumeration
00054         enum TokenID {
00055             // Terminal Tokens section
00056             ID_UNKOWN = 0, ID_OPENBRACE, ID_CLOSEBRACE,
00057             ID_VERTEX_PROGRAM, ID_FRAGMENT_PROGRAM,
00058             // material
00059             ID_MATERIAL, ID_CLONE, ID_TECHNIQUE, ID_SET_TEXTURE_ALIAS, ID_LOD_DISTANCES,
00060             ID_RECEIVE_SHADOWS, ID_TRANSPARENCY_CASTS_SHADOWS, ID_LOD_INDEX,
00061 
00062             // pass
00063             ID_PASS, ID_AMBIENT, ID_DIFFUSE, ID_SPECULAR, ID_EMISSIVE,
00064             ID_VERTEXCOLOUR, ID_SCENE_BLEND, ID_BLEND_ADD, ID_BLEND_MODULATE, ID_COLOUR_BLEND, ID_ALPHA_BLEND,
00065             ID_BLEND_ONE, ID_BLEND_ZERO, ID_BLEND_DEST_COLOUR,
00066             ID_BLEND_SRC_COLOUR, ID_BLEND_ONCE_MINUS_DEST_COLOUR, ID_BLEND_ONE_MINUS_SRC_COLOUR,
00067             ID_BLEND_DEST_ALPHA, ID_BLEND_SRC_ALPHA, ID_BLEND_ONE_MINUS_DEST_ALPHA, ID_BLEND_ONE_MINUS_SRC_ALPHA,
00068             ID_DEPTH_CHECK, ID_DEPTH_WRITE, ID_ALPHA_REJECTION, ID_DEPTH_FUNC, ID_ALWAYS_FAIL, ID_ALWAYS_PASS,
00069             ID_LESS_EQUAL, ID_LESS, ID_EQUAL, ID_NOT_EQUAL, ID_GREATER_EQUAL, ID_GREATER,
00070 
00071             ID_COLOUR_WRITE, ID_CULL_HARDWARE, ID_CLOCKWISE, ID_ANTICLOCKWISE, ID_CULL_NONE,
00072             ID_CULL_SOFTWARE, ID_CULL_BACK, ID_CULL_FRONT,
00073             ID_SHADING, ID_FLAT, ID_GOURAUD, ID_PHONG,
00074             ID_LIGHTING, ID_MAX_LIGHTS, ID_FOG_OVERRIDE,
00075             ID_POINT_SIZE, ID_POINT_SPRITES, ID_POINT_SIZE_ATTENUATION,
00076             ID_POINT_SIZE_MIN, ID_POINT_SIZE_MAX,
00077 
00078             ID_TEXTURE_UNIT,
00079 
00080             // general
00081             ID_ON, ID_OFF, ID_TRUE, ID_FALSE
00082         };
00083 
00085         enum MaterialScriptSection
00086         {
00087             MSS_NONE,
00088             MSS_MATERIAL,
00089             MSS_TECHNIQUE,
00090             MSS_PASS,
00091             MSS_TEXTUREUNIT,
00092             MSS_PROGRAM_REF,
00093             MSS_PROGRAM,
00094             MSS_DEFAULT_PARAMETERS,
00095             MSS_TEXTURESOURCE
00096         };
00098         struct MaterialScriptProgramDefinition
00099         {
00100             String name;
00101             GpuProgramType progType;
00102             String language;
00103             String source;
00104             String syntax;
00105             bool supportsSkeletalAnimation;
00106             bool supportsMorphAnimation;
00107             ushort supportsPoseAnimation; // number of simultaneous poses supported
00108             std::map<String, String> customParameters;
00109         };
00111         struct MaterialScriptContext
00112         {
00113             MaterialScriptSection section;
00114             String groupName;
00115             MaterialPtr material;
00116             Technique* technique;
00117             Pass* pass;
00118             TextureUnitState* textureUnit;
00119             GpuProgramPtr program; // used when referencing a program, not when defining it
00120             bool isProgramShadowCaster; // when referencing, are we in context of shadow caster
00121             bool isProgramShadowReceiver; // when referencing, are we in context of shadow caster
00122             GpuProgramParametersSharedPtr programParams;
00123             ushort numAnimationParametrics;
00124             MaterialScriptProgramDefinition* programDef; // this is used while defining a program
00125 
00126             int techLev,    //Keep track of what tech, pass, and state level we are in
00127                 passLev,
00128                 stateLev;
00129             StringVector defaultParamLines;
00130 
00131             // Error reporting state
00132             size_t lineNo;
00133             String filename;
00134             AliasTextureNamePairList textureAliases;
00135         };
00136 
00137         MaterialScriptContext mScriptContext;
00138 
00139         // static library database for tokens and BNF rules
00140         static TokenRule materialScript_RulePath[];
00141         // simplified Backus - Naur Form (BNF) grammer for material scripts
00142         static String materialScript_BNF;
00143 
00144         typedef void (MaterialScriptCompiler::* MSC_Action)(void);
00145         typedef std::map<size_t, MSC_Action> TokenActionMap;
00146         typedef TokenActionMap::iterator TokenActionIterator;
00151         static TokenActionMap mTokenActionMap;
00152 
00156         virtual void executeTokenAction(const size_t tokenID);
00159         virtual void setupTokenDefinitions(void);
00160         void addLexemeTokenAction(const String& lexeme, const size_t token, const MSC_Action action = 0);
00161 
00162         void logParseError(const String& error);
00163 
00164         // support methods that convert tokens
00165         ColourValue _parseColourValue(void);
00166         CompareFunction convertCompareFunction(void);
00167 
00168         // Token Actions which get called when tokens are created during parsing.
00169         void parseOpenBrace(void);
00170         void parseCloseBrace(void);
00171         void parseVertexProgram(void);
00172         void parseFragmentProgram(void);
00173         void parseMaterial(void);
00174         // Technique related actions
00175         void parseTechnique(void);
00176         void parseTransparencyCastsShadows(void);
00177         void parseReceiveShadows(void);
00178         // Pass related Actions
00179         void parsePass(void);
00180         void parseAmbient(void);
00181         void parseDiffuse(void);
00182         void parseSpecular(void);
00183         void parseEmissive(void);
00184         void parseDepthCheck(void);
00185         void parseDepthWrite(void);
00186         void parseDepthFunc(void);
00187         void parseAlphaRejection(void);
00188         void parseColourWrite(void);
00189         void parseCullHardware(void);
00190         void parseCullSoftware(void);
00191         void parseLighting(void);
00192         void parseMaxLights(void);
00193         void parseShading(void);
00194         void parsePointSize(void);
00195         void parsePointSprites(void);
00196         void parsePointSizeMin(void);
00197         void parsePointSizeMax(void);
00198         void parsePointSizeAttenuation(void);
00199 
00200         void parseTextureUnit(void);
00201         void parseTextureCustomParameter(void);
00202         void finishProgramDefinition(void);
00203 
00204     };
00205 }
00206 
00207 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:43 2006