1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4     (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 /***************************************************************************
30 OgreExternalTextureSourceManager.cpp  -
31 	Implementation of the manager class
32 
33 -------------------
34 date                 : Jan 1 2004
35 email                : pjcast@yahoo.com
36 ***************************************************************************/
37 
38 #include "OgreStableHeaders.h"
39 #include "OgreExternalTextureSourceManager.h"
40 #include "OgreLogManager.h"
41 
42 
43 namespace Ogre
44 {
45 	//****************************************************************************************
46     template<> ExternalTextureSourceManager* Singleton<ExternalTextureSourceManager>::msSingleton = 0;
getSingletonPtr(void)47     ExternalTextureSourceManager* ExternalTextureSourceManager::getSingletonPtr(void)
48     {
49         return msSingleton;
50     }
getSingleton(void)51     ExternalTextureSourceManager& ExternalTextureSourceManager::getSingleton(void)
52     {
53         assert( msSingleton );  return ( *msSingleton );
54     }
55 	//****************************************************************************************
56 
57 	//****************************************************************************************
ExternalTextureSourceManager()58 	ExternalTextureSourceManager::ExternalTextureSourceManager()
59 	{
60 		mCurrExternalTextureSource = 0;
61 	}
62 
63 	//****************************************************************************************
~ExternalTextureSourceManager()64 	ExternalTextureSourceManager::~ExternalTextureSourceManager()
65 	{
66 		mTextureSystems.clear();
67 	}
68 
69 	//****************************************************************************************
70 
setCurrentPlugIn(const String & sTexturePlugInType)71 	void ExternalTextureSourceManager::setCurrentPlugIn( const String& sTexturePlugInType )
72 	{
73 		TextureSystemList::iterator i;
74 
75 		for( i = mTextureSystems.begin(); i != mTextureSystems.end(); ++i )
76 		{
77 			if( i->first == sTexturePlugInType )
78 			{
79 				mCurrExternalTextureSource = i->second;
80 				mCurrExternalTextureSource->initialise();	//Now call overridden Init function
81 				return;
82 			}
83 		}
84 		mCurrExternalTextureSource = 0;
85 		LogManager::getSingleton().logMessage( "ExternalTextureSourceManager::SetCurrentPlugIn(ENUM) failed setting texture plugin ", LML_CRITICAL);
86 	}
87 
88 	//****************************************************************************************
destroyAdvancedTexture(const String & sTextureName,const String & groupName)89 	void ExternalTextureSourceManager::destroyAdvancedTexture( const String& sTextureName,
90 		const String& groupName )
91 	{
92 		TextureSystemList::iterator i;
93 		for( i = mTextureSystems.begin(); i != mTextureSystems.end(); ++i )
94 		{
95 			//Broadcast to every registered System... Only the true one will destroy texture
96 			i->second->destroyAdvancedTexture( sTextureName, groupName );
97 		}
98 	}
99 
100 	//****************************************************************************************
setExternalTextureSource(const String & sTexturePlugInType,ExternalTextureSource * pTextureSystem)101 	void ExternalTextureSourceManager::setExternalTextureSource( const String& sTexturePlugInType, ExternalTextureSource* pTextureSystem )
102 	{
103 		LogManager::getSingleton().logMessage( "Registering Texture Controller: Type = "
104 						+ sTexturePlugInType + " Name = " + pTextureSystem->getPluginStringName());
105 
106 		TextureSystemList::iterator i;
107 
108 		for( i = mTextureSystems.begin(); i != mTextureSystems.end(); ++i )
109 		{
110 			if( i->first == sTexturePlugInType )
111 			{
112 				LogManager::getSingleton().logMessage( "Shutting Down Texture Controller: "
113 						+ i->second->getPluginStringName()
114 						+ " To be replaced by: "
115 						+ pTextureSystem->getPluginStringName());
116 
117 				i->second->shutDown();				//Only one plugIn of Sent Type can be registered at a time
118 													//so shut down old plugin before starting new plugin
119 				i->second = pTextureSystem;
120 				// **Moved this line b/c Rendersystem needs to be selected before things
121 				// such as framelistners can be added
122 				// pTextureSystem->Initialise();
123 				return;
124 			}
125 		}
126 		mTextureSystems[sTexturePlugInType] = pTextureSystem;	//If we got here then add it to map
127 	}
128 
129 	//****************************************************************************************
getExternalTextureSource(const String & sTexturePlugInType)130 	ExternalTextureSource* ExternalTextureSourceManager::getExternalTextureSource( const String& sTexturePlugInType )
131 	{
132 		TextureSystemList::iterator i;
133 		for( i = mTextureSystems.begin(); i != mTextureSystems.end(); ++i )
134 		{
135 			if( i->first == sTexturePlugInType )
136 				return i->second;
137 		}
138 		return 0;
139 	}
140 
141 	//****************************************************************************************
142 
143 }  //End Ogre Namespace
144 
145