Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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.ogre3d.org
    00006
    00007 Copyright (c) 2000-2006 Torus Knot Software Ltd
    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 Lesser 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 Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser 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/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029
    00030 #ifndef __MaterialScriptScompiler_H__
    00031 #define __MaterialScriptScompiler_H__
    00032
    00033 #include "OgreCompiler2Pass.h"
    00034 #include "OgreTextureUnitState.h"
    00035 #include "OgreMaterial.h"
    00036 #include "OgreGpuProgram.h"
    00037 #include "OgreStringVector.h"
    00038
    00039 namespace Ogre {
    00040
    00041     class _OgreExport MaterialScriptCompiler : public Compiler2Pass
    00042     {
    00043
    00044     public:
    00045         MaterialScriptCompiler(void);
    00046         ~MaterialScriptCompiler(void);
    00047
    00050         virtual const String& getClientBNFGrammer(void) const;
    00051
    00054         virtual const String& getClientGrammerName(void) const;
    00055
    00066         void parseScript(DataStreamPtr& stream, const String& groupName, const bool allowOverride = false);
    00067
    00068     protected:
    00069         // Token ID enumeration
    00070         enum TokenID {
    00071             // Terminal Tokens section
    00072             ID_UNKOWN = 0,
    00073             // GPU Program
    00074             ID_VERTEX_PROGRAM, ID_FRAGMENT_PROGRAM,
    00075
    00076             // material
    00077             ID_CLONE,
    00078
    00079             // technique
    00080
    00081             // pass
    00082
    00083             ID_VERTEXCOLOUR,
    00084             // scene blend
    00085             ID_COLOUR_BLEND, ID_DEST_COLOUR,
    00086             ID_SRC_COLOUR, ID_ONE_MINUS_DEST_COLOUR, ID_ONE_MINUS_SRC_COLOUR,
    00087             ID_DEST_ALPHA, ID_SRC_ALPHA, ID_ONE_MINUS_DEST_ALPHA, ID_ONE_MINUS_SRC_ALPHA,
    00088             // Depth
    00089             ID_ALWAYS_FAIL, ID_ALWAYS_PASS,
    00090             ID_LESS_EQUAL, ID_LESS, ID_EQUAL, ID_NOT_EQUAL, ID_GREATER_EQUAL, ID_GREATER,
    00091             // culling
    00092             ID_CLOCKWISE, ID_ANTICLOCKWISE,
    00093             ID_CULL_BACK, ID_CULL_FRONT,
    00094             // shading
    00095             ID_FLAT, ID_GOURAUD, ID_PHONG,
    00096             // polygon mode
    00097             ID_SOLID, ID_WIREFRAME, ID_POINTS,
    00098             // fog overide
    00099             ID_EXP, ID_EXP2,
    00100             // iteration
    00101             ID_ONCE, ID_ONCE_PER_LIGHT, ID_PER_LIGHT, ID_PER_N_LIGHTS, ID_DIRECTIONAL, ID_SPOT,
    00102
    00103             // texture unit state
    00104             // texture
    00105             ID_1D, ID_2D, ID_3D, ID_CUBIC, ID_UNLIMITED, ID_ALPHA,
    00106             // cubic texture
    00107             ID_SEPARATE_UV, ID_COMBINED_UVW,
    00108             // address mode
    00109             ID_WRAP, ID_CLAMP, ID_MIRROR, ID_BORDER,
    00110             // filtering
    00111             ID_BILINEAR, ID_TRILINEAR, ID_ANISOTROPIC,
    00112             // color op
    00113             ID_REPLACE,
    00114             ID_SOURCE1, ID_SOURCE2, ID_MODULATE_X2, ID_MODULATE_X4, ID_ADD_SIGNED,
    00115             ID_ADD_SMOOTH, ID_SUBTRACT, ID_BLEND_DIFFUSE_COLOUR, ID_BLEND_DIFFUSE_ALPHA,
    00116             ID_BLEND_TEXTURE_ALPHA, ID_BLEND_CURRENT_ALPHA, ID_BLEND_MANUAL, ID_DOTPRODUCT,
    00117             ID_SRC_CURRENT, ID_SRC_TEXTURE, ID_SRC_DIFFUSE, ID_SRC_SPECULAR, ID_SRC_MANUAL,
    00118
    00119             // env map
    00120             ID_SPHERICAL, ID_PLANAR, ID_CUBIC_REFLECTION, ID_CUBIC_NORMAL,
    00121             // wave transform
    00122             ID_SCROLL_X, ID_SCROLL_Y, ID_SCALE_X, ID_SCALE_Y, ID_SINE, ID_TRIANGLE,
    00123             ID_SQUARE, ID_SAWTOOTH, ID_INVERSE_SAWTOOTH, ID_ROTATE,
    00124             // content type
    00125             ID_NAMED, ID_SHADOW,
    00126
    00127             // GPU program references
    00128             // GPU Parameters
    00129
    00130             // general
    00131             ID_ON, ID_OFF, ID_TRUE, ID_FALSE, ID_NONE, ID_POINT, ID_LINEAR, ID_ADD, ID_MODULATE, ID_ALPHA_BLEND,
    00132             ID_ONE, ID_ZERO, ID_VERTEX, ID_FRAGMENT,
    00133
    00134             // where auto generated tokens start so donot remove
    00135             ID_AUTOTOKENSTART
    00136         };
    00137
    00139         enum MaterialScriptSection
    00140         {
    00141             MSS_NONE,
    00142             MSS_MATERIAL,
    00143             MSS_TECHNIQUE,
    00144             MSS_PASS,
    00145             MSS_TEXTUREUNIT,
    00146             MSS_PROGRAM_REF,
    00147             MSS_PROGRAM,
    00148             MSS_DEFAULT_PARAMETERS,
    00149             MSS_TEXTURESOURCE
    00150         };
    00152         struct MaterialScriptProgramDefinition
    00153         {
    00154             String name;
    00155             GpuProgramType progType;
    00156             String language;
    00157             String source;
    00158             String syntax;
    00159             bool supportsSkeletalAnimation;
    00160             bool supportsMorphAnimation;
    00161             ushort supportsPoseAnimation; // number of simultaneous poses supported
    00162             bool usesVertexTextureFetch;
    00163             std::vector<std::pair<String, String> > customParameters;
    00164         };
    00166         struct MaterialScriptContext
    00167         {
    00168             MaterialScriptSection section;
    00169             String groupName;
    00170             MaterialPtr material;
    00171             Technique* technique;
    00172             Pass* pass;
    00173             TextureUnitState* textureUnit;
    00174             GpuProgramPtr program; // used when referencing a program, not when defining it
    00175             bool isProgramShadowCaster; // when referencing, are we in context of shadow caster
    00176             bool isVertexProgramShadowReceiver; // when referencing, are we in context of shadow caster
    00177             bool isFragmentProgramShadowReceiver; // when referencing, are we in context of shadow caster
    00178             bool allowOverride; // if true then allow existing materials and gpu programs to be overriden
    00179             GpuProgramParametersSharedPtr programParams;
    00180             ushort numAnimationParametrics;
    00181             MaterialScriptProgramDefinition* programDef; // this is used while defining a program
    00182
    00183             int techLev,    //Keep track of what tech, pass, and state level we are in
    00184                 passLev,
    00185                 stateLev;
    00186             // container of token que positions for default params that require pass 2 processing
    00187             std::vector<size_t> pendingDefaultParams;
    00188
    00189             AliasTextureNamePairList textureAliases;
    00190         };
    00191
    00192         MaterialScriptContext mScriptContext;
    00193
    00194         typedef void (MaterialScriptCompiler::* MSC_Action)(void);
    00195         typedef std::map<size_t, MSC_Action> TokenActionMap;
    00196         typedef TokenActionMap::iterator TokenActionIterator;
    00201         static TokenActionMap mTokenActionMap;
    00202
    00206         virtual void executeTokenAction(const size_t tokenID);
    00209         virtual size_t getAutoTokenIDStart() const {return ID_AUTOTOKENSTART;}
    00210
    00213         virtual void setupTokenDefinitions(void);
    00214         void addLexemeTokenAction(const String& lexeme, const size_t token, const MSC_Action action = 0);
    00218         void addLexemeAction(const String& lexeme, const MSC_Action action) {addLexemeTokenAction(lexeme, 0, action);}
    00219
    00220         void logParseError(const String& error);
    00221
    00222         // support methods that convert tokens
    00223         ColourValue _parseColourValue(void);
    00224         CompareFunction convertCompareFunction(void);
    00225
    00226         // Token Actions which get called when tokens are created during parsing.
    00227         void parseOpenBrace(void);
    00228         void parseCloseBrace(void);
    00229         // material section Actions
    00230         void parseMaterial(void);
    00231         void parseLodDistances(void);
    00232         void parseReceiveShadows(void);
    00233         void parseTransparencyCastsShadows(void);
    00234         void parseSetTextureAlias(void);
    00235         // Technique related actions
    00236         void parseTechnique(void);
    00237         void parseScheme(void);
    00238         void parseLodIndex(void);
    00239         // Pass related Actions
    00240         void parsePass(void);
    00241         void parseAmbient(void);
    00242         void parseDiffuse(void);
    00243         void parseSpecular(void);
    00244         void parseEmissive(void);
    00245         void parseSceneBlend(void);
    00246         SceneBlendFactor convertBlendFactor(void);
    00247         void parseDepthCheck(void);
    00248         void parseDepthWrite(void);
    00249         void parseDepthFunc(void);
    00250         void parseDepthBias(void);
    00251         void parseAlphaRejection(void);
    00252         void parseCullHardware(void);
    00253         void parseCullSoftware(void);
    00254         void parseLighting(void);
    00255         void parseShading(void);
    00256         void parsePolygonMode(void);
    00257         void parseFogOverride(void);
    00258         void parseMaxLights(void);
    00259         void parseStartLight(void);
    00260         void parseIteration(void);
    00261         void parseIterationLightTypes(void);
    00262         void parseColourWrite(void);
    00263         void parsePointSize(void);
    00264         void parsePointSprites(void);
    00265         void parsePointSizeMin(void);
    00266         void parsePointSizeMax(void);
    00267         void parsePointSizeAttenuation(void);
    00268         // Texture Unit related Actions
    00269         void parseTextureUnit(void);
    00270         void parseTextureAlias(void);
    00271         void parseTexture(void);
    00272         void parseAnimTexture(void);
    00273         void parseCubicTexture(void);
    00274         void parseTexCoord(void);
    00275         TextureUnitState::TextureAddressingMode convTexAddressMode(void);
    00276         void parseTexAddressMode(void);
    00277         void parseTexBorderColour(void);
    00278         void parseFiltering(void);
    00279         FilterOptions convertFiltering();
    00280         void parseMaxAnisotropy(void);
    00281         void parseMipMapBias(void);
    00282         void parseColourOp(void);
    00283         void parseColourOpEx(void);
    00284         LayerBlendOperationEx convertBlendOpEx(void);
    00285         LayerBlendSource convertBlendSource(void);
    00286         void parseColourOpMultipassFallback(void);
    00287         void parseAlphaOpEx(void);
    00288         void parseEnvMap(void);
    00289         void parseScroll(void);
    00290         void parseScrollAnim(void);
    00291         void parseRotate(void);
    00292         void parseRotateAnim(void);
    00293         void parseScale(void);
    00294         void parseWaveXform(void);
    00295         void parseTransform(void);
    00296         void parseTextureCustomParameter(void);
    00297         void parseBindingType(void);
    00298         void parseContentType(void);
    00299
    00300         // GPU Program
    00301         void parseGPUProgram(void);
    00302         void parseProgramSource(void);
    00303         void parseProgramSyntax(void);
    00304         void parseProgramCustomParameter(void);
    00305         void parseDefaultParams(void);
    00306         void parseProgramSkeletalAnimation(void);
    00307         void parseProgramMorphAnimation(void);
    00308         void parseProgramPoseAnimation(void);
    00309         void parseProgramVertexTextureFetch(void);
    00310         void parseVertexProgramRef(void);
    00311         void parseFragmentProgramRef(void);
    00312         void parseShadowCasterVertexProgramRef(void);
    00313         void parseShadowReceiverVertexProgramRef(void);
    00314         void parseShadowReceiverFragmentProgramRef(void);
    00315         void parseParamIndexed(void);
    00316         void parseParamIndexedAuto(void);
    00317         void parseParamNamed(void);
    00318         void parseParamNamedAuto(void);
    00319         void processManualProgramParam(bool isNamed, const String commandName,
    00320             size_t index = 0, const String& paramName = StringUtil::BLANK);
    00321         void processAutoProgramParam(bool isNamed, const String commandName,
    00322             size_t index, const String& paramName = StringUtil::BLANK);
    00323
    00324
    00325         void finishProgramDefinition(void);
    00326
    00327     };
    00328 }
    00329
    00330 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 30 10:50:57 2007