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 © 2000-2002 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 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 */ 00025 #ifndef __MaterialSerializer_H__ 00026 #define __MaterialSerializer_H__ 00027 00028 #include "OgrePrerequisites.h" 00029 #include "OgreMaterial.h" 00030 #include "OgreBlendMode.h" 00031 #include "OgreTextureUnitState.h" 00032 #include "OgreGpuProgram.h" 00033 00034 namespace Ogre { 00035 00037 enum MaterialScriptSection 00038 { 00039 MSS_NONE, 00040 MSS_MATERIAL, 00041 MSS_TECHNIQUE, 00042 MSS_PASS, 00043 MSS_TEXTUREUNIT, 00044 MSS_PROGRAM_REF, 00045 MSS_PROGRAM 00046 }; 00048 struct MaterialScriptProgramDefinition 00049 { 00050 String name; 00051 GpuProgramType progType; 00052 String language; 00053 String source; 00054 String syntax; 00055 std::map<String, String> customParameters; 00056 }; 00058 struct MaterialScriptContext 00059 { 00060 MaterialScriptSection section; 00061 Material* material; 00062 Technique* technique; 00063 Pass* pass; 00064 TextureUnitState* textureUnit; 00065 GpuProgram* program; // used when referencing a program, not when defining it 00066 GpuProgramParametersSharedPtr programParams; 00067 MaterialScriptProgramDefinition* programDef; // this is used while defining a program 00068 00069 // Error reporting state 00070 size_t lineNo; 00071 String filename; 00072 }; 00074 typedef bool (*ATTRIBUTE_PARSER)(String& params, MaterialScriptContext& context); 00075 00077 class _OgreExport MaterialSerializer 00078 { 00079 protected: 00081 typedef std::map<String, ATTRIBUTE_PARSER> AttribParserList; 00082 00083 MaterialScriptContext mScriptContext; 00084 00088 bool parseScriptLine(String& line); 00090 bool invokeParser(String& line, AttribParserList& parsers); 00094 void finishProgramDefinition(void); 00096 AttribParserList mRootAttribParsers; 00098 AttribParserList mMaterialAttribParsers; 00100 AttribParserList mTechniqueAttribParsers; 00102 AttribParserList mPassAttribParsers; 00104 AttribParserList mTextureUnitAttribParsers; 00106 AttribParserList mProgramRefAttribParsers; 00108 AttribParserList mProgramAttribParsers; 00109 00110 void writeMaterial(const Material *pMat); 00111 void writeTechnique(const Technique* pTech); 00112 void writePass(const Pass* pPass); 00113 void writeTextureUnit(const TextureUnitState *pTex); 00114 00115 void writeSceneBlendFactor(const SceneBlendFactor sbf_src, const SceneBlendFactor sbf_dest); 00116 void writeSceneBlendFactor(const SceneBlendFactor sbf); 00117 void writeCompareFunction(const CompareFunction cf); 00118 void writeColourValue(const ColourValue &colour, bool writeAlpha = false); 00119 void writeLayerBlendOperationEx(const LayerBlendOperationEx op); 00120 void writeLayerBlendSource(const LayerBlendSource lbs); 00121 00122 typedef std::multimap<TextureUnitState::TextureEffectType, TextureUnitState::TextureEffect> EffectMap; 00123 00124 void writeRotationEffect(const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex); 00125 void writeTransformEffect(const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex); 00126 void writeScrollEffect(const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex); 00127 void writeEnvironmentMapEffect(const TextureUnitState::TextureEffect& effect, const TextureUnitState *pTex); 00128 00129 String convertFiltering(FilterOptions fo); 00130 public: 00132 MaterialSerializer(); 00134 virtual ~MaterialSerializer() {}; 00135 00137 void queueForExport(const Material *pMat, bool clearQueued = false, bool exportDefaults = false); 00139 void exportQueued(const String& filename); 00141 void exportMaterial(const Material *pMat, const String& filename, bool exportDefaults = false); 00143 const String &getQueuedAsString() const; 00145 void clearQueue(); 00146 00152 void parseScript(DataChunk& chunk, const String& filename = ""); 00153 00154 00155 00156 private: 00157 String mBuffer; 00158 bool mDefaults; 00159 00160 void beginSection(unsigned short level) 00161 { 00162 mBuffer += "\n"; 00163 for (unsigned short i = 0; i < level; ++i) 00164 { 00165 mBuffer += "\t"; 00166 } 00167 mBuffer += "{"; 00168 } 00169 void endSection(unsigned short level) 00170 { 00171 mBuffer += "\n"; 00172 for (unsigned short i = 0; i < level; ++i) 00173 { 00174 mBuffer += "\t"; 00175 } 00176 mBuffer += "}"; 00177 } 00178 00179 void writeAttribute(unsigned short level, const String& att) 00180 { 00181 mBuffer += "\n"; 00182 for (unsigned short i = 0; i < level; ++i) 00183 { 00184 mBuffer += "\t"; 00185 } 00186 mBuffer += att; 00187 } 00188 00189 void writeValue(const String& val) 00190 { 00191 mBuffer += (" " + val); 00192 } 00193 00194 void writeComment(unsigned short level, const String& comment) 00195 { 00196 mBuffer += "\n"; 00197 for (unsigned short i = 0; i < level; ++i) 00198 { 00199 mBuffer += "\t"; 00200 } 00201 mBuffer += "// " + comment; 00202 } 00203 00204 }; 00205 } 00206 #endif
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:16 2004