Spinning Topp Logo BlackTopp Studios
inc
texturemanager.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _graphicstexturemanager_cpp
41 #define _graphicstexturemanager_cpp
42 
43 #include "Graphics/texturemanager.h"
44 #include "Graphics/texture.h"
45 
46 #include <Ogre.h>
47 
48 namespace Mezzanine
49 {
50  template<> Graphics::TextureManager* Singleton<Graphics::TextureManager>::SingletonPtr = NULL;
51 
52  namespace Graphics
53  {
54  const String TextureManager::ImplementationName = "DefaultTextureManager";
55  const ManagerBase::ManagerType TextureManager::InterfaceType = ManagerBase::MT_TextureManager;
56 
58  { }
59 
61  {
62  /// @todo This class currently doesn't initialize anything from XML, if that changes this constructor needs to be expanded.
63  }
64 
66  {
67  this->Deinitialize();
68  }
69 
71  {
72  String TextureName = ToAdd->GetName();
73  TextureIterator TextureIt = this->Textures.find( TextureName );
74  if( TextureIt == this->Textures.end() ) {
75  this->Textures.insert( std::pair<String,Texture*>(TextureName,ToAdd) );
76  }else{
77  MEZZ_EXCEPTION(ExceptionBase::II_DUPLICATE_IDENTITY_EXCEPTION,"Textures must have unique names when loaded!");
78  }
79  }
80 
81  ///////////////////////////////////////////////////////////////////////////////
82  // Manual Creation
83 
84  Texture* TextureManager::CreateManualTexture(const String& ResourceName, const String& ResourceGroup, const Graphics::TextureType Type, const Whole Width, const Whole Height,
85  const Integer NumMipMaps, const Graphics::PixelFormat Format, const Whole Usage, const Boole HWGammaCorrect, const Whole FSAA)
86  {
87  return this->_WrapInternalTexture( this->_GetInternalManager()->createManual(ResourceName,ResourceGroup,static_cast<Ogre::TextureType>(Type),Width,Height,NumMipMaps,static_cast<Ogre::PixelFormat>(Format),Usage,NULL,HWGammaCorrect,FSAA) );
88  }
89 
90  Texture* TextureManager::CreateManualTexture(const String& ResourceName, const String& ResourceGroup, const Graphics::TextureType Type, const Whole Width, const Whole Height, const Whole Depth,
91  const Integer NumMipMaps, const Graphics::PixelFormat Format, const Whole Usage, const Boole HWGammaCorrect, const Whole FSAA)
92  {
93  return this->_WrapInternalTexture( this->_GetInternalManager()->createManual(ResourceName,ResourceGroup,static_cast<Ogre::TextureType>(Type),Width,Height,Depth,NumMipMaps,static_cast<Ogre::PixelFormat>(Format),Usage,NULL,HWGammaCorrect,FSAA) );
94  }
95 
96  ///////////////////////////////////////////////////////////////////////////////
97  // Texture Management
98 
99  Texture* TextureManager::LoadTexture(const String& TextureName, const String& Group)
100  {
101  TextureIterator TexIt = this->Textures.find(TextureName);
102  if( TexIt != this->Textures.end() ) {
103  return (*TexIt).second;
104  }
105  return this->_WrapInternalTexture( this->_GetInternalManager()->load(TextureName,Group) );
106  }
107 
108  void TextureManager::UnloadTexture(const String& TextureName)
109  {
110  TextureIterator TexIt = this->Textures.find(TextureName);
111  if( TexIt == this->Textures.end() ) {
112  return;
113  }
114  this->_GetInternalManager()->unload(TextureName);
115  delete (*TexIt).second;
116  this->Textures.erase(TexIt);
117  }
118 
120  {
121  TextureIterator TexIt = this->Textures.find(TextureName);
122  if( TexIt != this->Textures.end() ) {
123  return (*TexIt).second;
124  }
125  return NULL;
126  }
127 
129  {
130  return this->Textures.size();
131  }
132 
134  {
135  for( TextureIterator TexIt = this->Textures.begin() ; TexIt != this->Textures.end() ; ++TexIt )
136  { delete (*TexIt).second; }
137  this->Textures.clear();
138  this->_GetInternalManager()->unloadAll();
139  }
140 
141  ///////////////////////////////////////////////////////////////////////////////
142  // Utility
143 
145  { this->Initialized = true; }
146 
148  {
149  if( this->Initialized ) {
150  this->UnloadAllTextures();
151  this->Initialized = false;
152  }
153  }
154 
155  ///////////////////////////////////////////////////////////////////////////////
156  // Type Identifier Methods
157 
160 
163 
164  ///////////////////////////////////////////////////////////////////////////////
165  // Internal Methods
166 
168  {
169  Texture* Wrapped = new Texture(ToWrap);
170  this->AddTexture( Wrapped );
171  return Wrapped;
172  }
173 
174  Ogre::TextureManager* TextureManager::_GetInternalManager() const
175  { return Ogre::TextureManager::getSingletonPtr(); }
176 
177  ///////////////////////////////////////////////////////////////////////////////
178  // DefaultTextureManagerFactory Methods
179 
181  { }
182 
184  { }
185 
188 
191 
193  {
195  /// @todo Add something to log a warning that the manager exists and was requested to be constructed when we have a logging manager set up.
197  }else return new TextureManager();
198  }
199 
201  {
203  /// @todo Add something to log a warning that the manager exists and was requested to be constructed when we have a logging manager set up.
205  }else return new TextureManager(XMLNode);
206  }
207 
209  { delete ToBeDestroyed; }
210  }//Graphics
211 }//Mezzanine
212 
213 
214 #endif
Texture * CreateManualTexture(const String &ResourceName, const String &ResourceGroup, const Graphics::TextureType Type, const Whole Width, const Whole Height, const Integer NumMipMaps, const Graphics::PixelFormat Format, const Whole Usage=Graphics::TU_Default, const Boole HWGammaCorrect=false, const Whole FSAA=0)
Creates a blank texture with a width and height.
Thrown when duplicates of teh same identity string exist.
Definition: exception.h:95
TextureType
An enum used to describe the various types of supported textures.
EntresolManager * CreateManager(const NameValuePairList &Params)
Creates a manager of the type represented by this factory.
virtual ManagerType GetInterfaceType() const
This returns the type of this manager.
virtual String GetImplementationTypeName() const
This Allows any manager name to be sent to a stream. Primarily used for logging.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual Whole GetNumTextures()
Gets the number of currently loaded Textures.
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
const String & GetName() const
Gets the Name of this Texture.
Definition: texture.cpp:106
TextureContainer Textures
Container storing all of the currently loaded Textures.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
virtual void UnloadTexture(const String &TextureName)
Unloads a Texture file.
ManagerBase::ManagerType GetManagerType() const
Gets the type of manager that is created by this factory.
TextureContainer::iterator TextureIterator
Iterator type for Texture instances stored in this class.
virtual Texture * LoadTexture(const String &TextureName, const String &Group)
Loads a Texture file from disk and prepares it for use.
static const String ImplementationName
A String containing the name of this manager implementation.
int Usage(Mezzanine::String ThisName, CoreTestGroup &TestGroups)
Print a message for the user onf the standard output that briefly describes hwo to use this...
static Boole SingletonValid()
Checks to see if the singleton pointer is valid.
Definition: singleton.h:110
static TextureManager * GetSingletonPtr()
Fetches a pointer to the singleton.
Definition: singleton.h:97
This is the base class for all managers that do no describe properties of a single world...
virtual ~TextureManager()
Class destructor.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
ProcessDepth Depth
The current process depth as interpretted by Main.
Definition: mezztest.cpp:82
This class represents a texture loaded into video memory.
Definition: texture.h:63
PixelFormat
This is used to describe how bits are arraged for each pixel in an image.
virtual void AddTexture(Texture *ToAdd)
Adds a Texture to this manager. the name of the Texture being added is not unique a II_DUPLICATE_IDEN...
Texture * GetTexture(const String &TextureName)
Gets a Texture stored in this manager.
String GetManagerImplName() const
Gets the name of the manager that is created by this factory.
std::list< NameValuePair > NameValuePairList
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:206
virtual Texture * _WrapInternalTexture(Ogre::TexturePtr ToWrap)
Wraps and stores an Ogre Texture instance.
Ogre::TextureManager * _GetInternalManager() const
Gets the internal TextureManager.
virtual void UnloadAllTextures()
Unloads every Texture that is currently loaded.
virtual void Deinitialize()
Removes this manager from any necessary configuration so it can be safely disposed of...
static const ManagerBase::ManagerType InterfaceType
A ManagerType enum value used to describe the type of interface/functionality this manager provides...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
virtual ~DefaultTextureManagerFactory()
Class destructor.
void DestroyManager(EntresolManager *ToBeDestroyed)
Destroys a Manager created by this factory.
This manager handles the storage and query of of Graphics Textures.
virtual void Initialize()
Configures this manager for use prior to entering the main loop.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Boole Initialized
Simple Boole indicating whether or not this manager has been initialized.
Definition: managerbase.h:111