Spinning Topp Logo BlackTopp Studios
inc
texturemanager.h
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_h
41 #define _graphicstexturemanager_h
42 
43 #include "entresolmanager.h"
44 #include "entresolmanagerfactory.h"
45 #include "singleton.h"
46 #include "Graphics/graphicsenumerations.h"
47 
48 namespace Ogre
49 {
50  class Texture;
51  template<typename T> class SharedPtr;
52  typedef SharedPtr<Texture> TexturePtr;
53  class TextureManager;
54 }
55 
56 namespace Mezzanine
57 {
58  namespace Graphics
59  {
60  class Texture;
61  // Used by the scripting language binder to help create bindgings for this class. SWIG does know to creation template instances
62  #ifdef SWIG
63  %template(SingletonTextureManager) Singleton<TextureManager>;
64  #endif
65 
66  ///////////////////////////////////////////////////////////////////////////////
67  /// @class TextureManager
68  /// @brief This manager handles the storage and query of of Graphics Textures.
69  /// @details
70  ///////////////////////////////////////
72  {
73  public:
74  /// @brief Basic container type for Texture storage in this class.
75  typedef std::map< String, Texture* > TextureContainer;
76  /// @brief Iterator type for Texture instances stored in this class.
77  typedef TextureContainer::iterator TextureIterator;
78  /// @brief Const Iterator type for Texture instances stored in this class.
79  typedef TextureContainer::const_iterator ConstTextureIterator;
80 
81  /// @brief A String containing the name of this manager implementation.
82  static const String ImplementationName;
83  /// @brief A ManagerType enum value used to describe the type of interface/functionality this manager provides.
85  protected:
86  /// @internal
87  /// @brief Container storing all of the currently loaded Textures.
88  TextureContainer Textures;
89 
90  /// @internal
91  /// @brief Adds a Texture to this manager.
92  /// @exception If the name of the Texture being added is not unique a II_DUPLICATE_IDENTITY_EXCEPTION will be thrown.
93  /// @param ToAdd The Texture to be added.
94  virtual void AddTexture(Texture* ToAdd);
95  public:
96  /// @brief Class constructor.
98  /// @brief XML constructor.
99  /// @param XMLNode The node of the xml document to construct from.
100  TextureManager(const XML::Node& XMLNode);
101  /// @brief Class destructor.
102  virtual ~TextureManager();
103 
104  ///////////////////////////////////////////////////////////////////////////////
105  // Manual Creation
106 
107  /// @brief Creates a blank texture with a width and height.
108  /// @param ResourceName The name of the resource to be created.
109  /// @param ResourceGroup The name of the group the resource will be created in.
110  /// @param Type The type of blank texture to be created. See @ref TextureType enum for more details.
111  /// @param Width The width of the texture to be loaded.
112  /// @param Height The height of the texture to be loaded.
113  /// @param NumMipMaps The number of mipmaps that exist for the texture.
114  /// @param Format The pixel format to create the buffer for.
115  /// @param Usage Indicates how the texture will be used so the buffer structure can be optimized.
116  /// @param HWGammaCorrect Whether or not to enable hardware gamma correction (sRGB) on this texture. The hardware will convert from gamma space to linear space when reading from this texture. Only applicable for 8-bits per channel textures, will be ignored for other types.
117  /// @param FSAA The level of multisampling to use if this is a render target. Ignored if usage does not include TU_RenderTarget or if the device does not support it.
118  /// @return Returns a pointer to the created texture.
119  Texture* CreateManualTexture(const String& ResourceName, const String& ResourceGroup, const Graphics::TextureType Type, const Whole Width, const Whole Height,
120  const Integer NumMipMaps, const Graphics::PixelFormat Format, const Whole Usage = Graphics::TU_Default, const Boole HWGammaCorrect = false, const Whole FSAA = 0);
121  /// @brief Creates a blank texture with a width, height, and depth.
122  /// @param ResourceName The name of the resource to be created.
123  /// @param ResourceGroup The name of the group the resource will be created in.
124  /// @param Type The type of blank texture to be created. See @ref TextureType enum for more details.
125  /// @param Width The width of the texture to be loaded.
126  /// @param Height The height of the texture to be loaded.
127  /// @param NumMipMaps The number of mipmaps that exist for the texture.
128  /// @param Format The pixel format to create the buffer for.
129  /// @param Usage Indicates how the texture will be used so the buffer structure can be optimized.
130  /// @param HWGammaCorrect Whether or not to enable hardware gamma correction (sRGB) on this texture. The hardware will convert from gamma space to linear space when reading from this texture. Only applicable for 8-bits per channel textures, will be ignored for other types.
131  /// @param FSAA The level of multisampling to use if this is a render target. Ignored if usage does not include TU_RenderTarget or if the device does not support it.
132  /// @return Returns a pointer to the created texture.
133  Texture* CreateManualTexture(const String& ResourceName, const String& ResourceGroup, const Graphics::TextureType Type, const Whole Width, const Whole Height, const Whole Depth,
134  const Integer NumMipMaps, const Graphics::PixelFormat Format, const Whole Usage = Graphics::TU_Default, const Boole HWGammaCorrect = false, const Whole FSAA = 0);
135 
136  ///////////////////////////////////////////////////////////////////////////////
137  // Texture Management
138 
139  /// @brief Loads a Texture file from disk and prepares it for use.
140  /// @param TextureName The name of the Texture file to be loaded.
141  /// @param Group The resource group from which the Texture file should be loaded.
142  /// @return Returns a pointer to the loaded Texture.
143  virtual Texture* LoadTexture(const String& TextureName, const String& Group);
144  /// @brief Unloads a Texture file.
145  /// @param MeshName The name of the Texture to be unloaded.
146  virtual void UnloadTexture(const String& TextureName);
147  /// @brief Gets a Texture stored in this manager.
148  /// @param MeshName The name of the Texture to retrieve.
149  /// @return Returns a pointer to the requested Texture.
150  Texture* GetTexture(const String& TextureName);
151  /// @brief Gets the number of currently loaded Textures.
152  /// @return Returns a Whole representing the number of Textures currently loaded.
153  virtual Whole GetNumTextures();
154  /// @brief Unloads every Texture that is currently loaded.
155  virtual void UnloadAllTextures();
156 
157  ///////////////////////////////////////////////////////////////////////////////
158  // Utility
159 
160  /// @copydoc ManagerBase::Initialize()
161  virtual void Initialize();
162  /// @copydoc ManagerBase::Deinitialize()
163  virtual void Deinitialize();
164 
165  ///////////////////////////////////////////////////////////////////////////////
166  // Type Identifier Methods
167 
168  /// @copydoc ManagerBase::GetInterfaceType()
169  virtual ManagerType GetInterfaceType() const;
170  /// @copydoc ManagerBase::GetImplementationTypeName()
171  virtual String GetImplementationTypeName() const;
172 
173  ///////////////////////////////////////////////////////////////////////////////
174  // Internal Methods
175 
176  /// @internal
177  /// @brief Wraps and stores an Ogre Texture instance.
178  /// @param ToWrap The Ogre Texture to get wrapped.
179  /// @return Returns a pointer to the wrapped Texture.
180  virtual Texture* _WrapInternalTexture(Ogre::TexturePtr ToWrap);
181  /// @internal
182  /// @brief Gets the internal TextureManager.
183  /// @return Returns a pointer to the internal TextureManager.
184  Ogre::TextureManager* _GetInternalManager() const;
185  };//TextureManager
186 
187  ///////////////////////////////////////////////////////////////////////////////
188  /// @class DefaultTextureManagerFactory
189  /// @brief A factory responsible for the creation and destruction of the default TextureManager.
190  ///////////////////////////////////////
192  {
193  public:
194  /// @brief Class constructor.
196  /// @brief Class destructor.
197  virtual ~DefaultTextureManagerFactory();
198 
199  /// @copydoc ManagerFactory::GetManagerImplName()
200  String GetManagerImplName() const;
201  /// @copydoc ManagerFactory::GetManagerType() const
202  ManagerBase::ManagerType GetManagerType() const;
203 
204  /// @copydoc EntresolManagerFactory::CreateManager(const NameValuePairList&)
205  EntresolManager* CreateManager(const NameValuePairList& Params);
206  /// @copydoc EntresolManagerFactory::CreateManager(const XML::Node&)
207  EntresolManager* CreateManager(const XML::Node& XMLNode);
208  /// @copydoc EntresolManagerFactory::DestroyManager(EntresolManager*)
209  void DestroyManager(EntresolManager* ToBeDestroyed);
210  };//DefaultTextureManagerFactory
211  }//Graphics
212 }//Mezzanine
213 
214 
215 #endif
TextureType
An enum used to describe the various types of supported textures.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
std::map< String, Texture * > TextureContainer
Basic container type for Texture storage in this class.
This is a base class for factories that construct managers used by the Entresol class.
By default textures are TU_Static_Write_Only and TU_AutoMipMap.
TextureContainer Textures
Container storing all of the currently loaded Textures.
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
TextureContainer::iterator TextureIterator
Iterator type for Texture instances stored in this class.
static const String ImplementationName
A String containing the name of this manager implementation.
A factory responsible for the creation and destruction of the default TextureManager.
int Usage(Mezzanine::String ThisName, CoreTestGroup &TestGroups)
Print a message for the user onf the standard output that briefly describes hwo to use this...
This is the base class for all managers that do no describe properties of a single world...
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.
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
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
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
TextureContainer::const_iterator ConstTextureIterator
Const Iterator type for Texture instances stored in this class.
This manager handles the storage and query of of Graphics Textures.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159