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 #include "OgreStableHeaders.h" 00026 #include "OgreMaterialManager.h" 00027 00028 #include "OgreMaterial.h" 00029 #include "OgreStringVector.h" 00030 #include "OgreLogManager.h" 00031 #include "OgreSDDataChunk.h" 00032 #include "OgreArchiveEx.h" 00033 #include "OgreStringConverter.h" 00034 #include "OgreBlendMode.h" 00035 #include "OgreTechnique.h" 00036 #include "OgrePass.h" 00037 #include "OgreTextureUnitState.h" 00038 #include "OgreException.h" 00039 00040 namespace Ogre { 00041 00042 //----------------------------------------------------------------------- 00043 template<> MaterialManager* Singleton<MaterialManager>::ms_Singleton = 0; 00044 //----------------------------------------------------------------------- 00045 MaterialManager::MaterialManager() 00046 { 00047 mDefaultMinFilter = FO_LINEAR; 00048 mDefaultMagFilter = FO_LINEAR; 00049 mDefaultMipFilter = FO_POINT; 00050 mDefaultMaxAniso = 1; 00051 00052 00053 } 00054 //----------------------------------------------------------------------- 00055 MaterialManager::~MaterialManager() 00056 { 00057 delete Material::mDefaultSettings; 00058 // Resources cleared by superclass 00059 } 00060 //----------------------------------------------------------------------- 00061 void MaterialManager::initialise(void) 00062 { 00063 // Set up default material - don't use name contructor as we want to avoid applying defaults 00064 Material::mDefaultSettings = new Material(); 00065 Material::mDefaultSettings->mName = "DefaultSettings"; 00066 // Add a single technique and pass, non-programmable 00067 Material::mDefaultSettings->createTechnique()->createPass(); 00068 00069 // Set up a lit base white material 00070 this->create("BaseWhite"); 00071 // Set up an unlit base white material 00072 Material* baseWhiteNoLighting = (Material*)this->create("BaseWhiteNoLighting"); 00073 baseWhiteNoLighting->setLightingEnabled(false); 00074 00075 // Parse all .program scripts first 00076 parseAllSources(".program"); 00077 // Parse all .material scripts 00078 parseAllSources(".material"); 00079 00080 } 00081 //----------------------------------------------------------------------- 00082 void MaterialManager::parseScript(DataChunk& chunk) 00083 { 00084 // Delegate to serializer 00085 mSerializer.parseScript(chunk); 00086 } 00087 //----------------------------------------------------------------------- 00088 void MaterialManager::parseAllSources(const String& extension) 00089 { 00090 StringVector materialFiles; 00091 DataChunk* pChunk; 00092 00093 std::vector<ArchiveEx*>::iterator i = mVFS.begin(); 00094 00095 // Specific archives 00096 for (; i != mVFS.end(); ++i) 00097 { 00098 materialFiles = (*i)->getAllNamesLike( "./", extension); 00099 for (StringVector::iterator si = materialFiles.begin(); si != materialFiles.end(); ++si) 00100 { 00101 SDDataChunk dat; pChunk = &dat; 00102 (*i)->fileRead(si[0], &pChunk ); 00103 LogManager::getSingleton().logMessage("Parsing material script: " + si[0]); 00104 mSerializer.parseScript(dat, si[0]); 00105 } 00106 00107 } 00108 // search common archives 00109 for (i = mCommonVFS.begin(); i != mCommonVFS.end(); ++i) 00110 { 00111 materialFiles = (*i)->getAllNamesLike( "./", extension); 00112 for (StringVector::iterator si = materialFiles.begin(); si != materialFiles.end(); ++si) 00113 { 00114 SDDataChunk dat; pChunk = &dat; 00115 (*i)->fileRead(si[0], &pChunk ); 00116 LogManager::getSingleton().logMessage("Parsing material script: " + si[0]); 00117 mSerializer.parseScript(dat, si[0]); 00118 } 00119 } 00120 00121 00122 } 00123 //----------------------------------------------------------------------- 00124 MaterialManager& MaterialManager::getSingleton(void) 00125 { 00126 return Singleton<MaterialManager>::getSingleton(); 00127 } 00128 //----------------------------------------------------------------------- 00129 Resource* MaterialManager::create( const String& name) 00130 { 00131 // Check name not already used 00132 if (getByName(name) != 0) 00133 Except(Exception::ERR_DUPLICATE_ITEM, "Material " + name + " already exists.", 00134 "MaterialManager::create"); 00135 00136 Material* m = new Material(name); 00137 this->add(m); 00138 00139 return m; 00140 } 00141 //----------------------------------------------------------------------- 00142 void MaterialManager::setDefaultTextureFiltering(TextureFilterOptions fo) 00143 { 00144 switch (fo) 00145 { 00146 case TFO_NONE: 00147 setDefaultTextureFiltering(FO_POINT, FO_POINT, FO_NONE); 00148 break; 00149 case TFO_BILINEAR: 00150 setDefaultTextureFiltering(FO_LINEAR, FO_LINEAR, FO_POINT); 00151 break; 00152 case TFO_TRILINEAR: 00153 setDefaultTextureFiltering(FO_LINEAR, FO_LINEAR, FO_LINEAR); 00154 break; 00155 case TFO_ANISOTROPIC: 00156 setDefaultTextureFiltering(FO_ANISOTROPIC, FO_ANISOTROPIC, FO_LINEAR); 00157 break; 00158 } 00159 } 00160 //----------------------------------------------------------------------- 00161 void MaterialManager::setDefaultAnisotropy(unsigned int maxAniso) 00162 { 00163 mDefaultMaxAniso = maxAniso; 00164 } 00165 //----------------------------------------------------------------------- 00166 unsigned int MaterialManager::getDefaultAnisotropy() const 00167 { 00168 return mDefaultMaxAniso; 00169 } 00170 //----------------------------------------------------------------------- 00171 void MaterialManager::setDefaultTextureFiltering(FilterType ftype, FilterOptions opts) 00172 { 00173 switch (ftype) 00174 { 00175 case FT_MIN: 00176 mDefaultMinFilter = opts; 00177 break; 00178 case FT_MAG: 00179 mDefaultMagFilter = opts; 00180 break; 00181 case FT_MIP: 00182 mDefaultMipFilter = opts; 00183 break; 00184 } 00185 } 00186 //----------------------------------------------------------------------- 00187 void MaterialManager::setDefaultTextureFiltering(FilterOptions minFilter, 00188 FilterOptions magFilter, FilterOptions mipFilter) 00189 { 00190 mDefaultMinFilter = minFilter; 00191 mDefaultMagFilter = magFilter; 00192 mDefaultMipFilter = mipFilter; 00193 } 00194 //----------------------------------------------------------------------- 00195 FilterOptions MaterialManager::getDefaultTextureFiltering(FilterType ftype) const 00196 { 00197 switch (ftype) 00198 { 00199 case FT_MIN: 00200 return mDefaultMinFilter; 00201 break; 00202 case FT_MAG: 00203 return mDefaultMagFilter; 00204 break; 00205 case FT_MIP: 00206 return mDefaultMipFilter; 00207 break; 00208 } 00209 // to keep compiler happy 00210 return mDefaultMinFilter; 00211 } 00212 }
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:15 2004