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

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:52 2004