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

OgreTextureManager.cpp

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 © 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 "OgreTextureManager.h"
00027 #include "OgreException.h"
00028 
00029 namespace Ogre {
00030     //-----------------------------------------------------------------------
00031     template<> TextureManager* Singleton<TextureManager>::ms_Singleton = 0;
00032     //-----------------------------------------------------------------------
00033     TextureManager::~TextureManager(){}
00034     //-----------------------------------------------------------------------
00035     Texture * TextureManager::load(
00036         const String &name, TextureType texType, int numMipMaps, 
00037         Real gamma, int priority )
00038     {
00039         Texture* tex = (Texture*)getByName( name );
00040 
00041         if( tex == NULL )
00042         {
00043             tex = (Texture*)create( name, texType );
00044 
00045             if (numMipMaps == -1)
00046                 tex->setNumMipMaps(mDefaultNumMipMaps);
00047             else
00048                 tex->setNumMipMaps(numMipMaps);
00049 
00050             tex->setGamma( gamma );
00051             tex->enable32Bit( mIs32Bit );
00052 
00053             ResourceManager::load( tex, priority );
00054         }
00055 
00056         return tex;
00057     }
00058 
00059     //-----------------------------------------------------------------------
00060     Texture * TextureManager::loadImage( 
00061         const String &name, const Image &img, TextureType texType,
00062         int iNumMipMaps /* = -1 */, Real gamma /* = 1.0f  */, int priority /* = 1 */ )
00063     {
00064         Texture *tex = (Texture*)create( name, texType );
00065 
00066         if( iNumMipMaps == -1 )
00067             tex->setNumMipMaps( mDefaultNumMipMaps );
00068         else
00069             tex->setNumMipMaps( iNumMipMaps );
00070 
00071         tex->setGamma( gamma );        
00072         tex->loadImage( img );
00073 
00074         std::pair<ResourceMap::iterator, bool> res = mResources.insert(
00075             ResourceMap::value_type( tex->getName(), tex));
00076         if (!res.second)
00077         {
00078             // Key was already used
00079             Except(Exception::ERR_DUPLICATE_ITEM, "A texture with the name " + tex->getName() + 
00080                 " was already loaded.", "TextureManager::loadImage");
00081         }
00082 
00083         return tex;
00084     }
00085     //-----------------------------------------------------------------------
00086     Texture * TextureManager::loadRawData( 
00087         const String &name, const DataChunk &pData, 
00088         ushort uWidth, ushort uHeight, PixelFormat eFormat,
00089         TextureType texType,
00090         int iNumMipMaps, Real gamma, int priority )
00091     {
00092         Texture *tex = (Texture*)create( name, texType );
00093         if( iNumMipMaps == -1 )
00094             tex->setNumMipMaps( mDefaultNumMipMaps );
00095         else
00096             tex->setNumMipMaps( iNumMipMaps );
00097 
00098         tex->setGamma( gamma );        
00099         tex->loadRawData( pData, uWidth, uHeight, eFormat);
00100         
00101         std::pair<ResourceMap::iterator, bool> res = mResources.insert(
00102             ResourceMap::value_type( tex->getName(), tex));
00103         if (!res.second)
00104         {
00105             // Key was already used
00106             Except(Exception::ERR_DUPLICATE_ITEM, "A texture with the name " + tex->getName() + 
00107                 " was already loaded.", "TextureManager::loadRawData");
00108         }
00109 
00110         return tex;
00111     }
00112     //-----------------------------------------------------------------------
00113     void TextureManager::unload( const String& filename )
00114     {
00115         Resource* res = getByName( filename );
00116         ResourceManager::unload( res );
00117     }
00118     //-----------------------------------------------------------------------
00119     void TextureManager::enable32BitTextures( bool setting )
00120     {
00121         // Reload all textures
00122         for( ResourceMap::iterator it = mResources.begin(); it != mResources.end(); ++it )
00123         {
00124             ((Texture*)it->second)->unload();
00125             ((Texture*)it->second)->enable32Bit(setting);
00126             ((Texture*)it->second)->load();
00127             mIs32Bit = setting;
00128         }
00129     }
00130     //-----------------------------------------------------------------------
00131     void TextureManager::setDefaultNumMipMaps( int num )
00132     {
00133         mDefaultNumMipMaps = num;
00134     }
00135     //-----------------------------------------------------------------------
00136     TextureManager& TextureManager::getSingleton(void)
00137     {
00138         return Singleton<TextureManager>::getSingleton();
00139     }
00140 }

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:30 2004