SuperTuxKart
stk_tex_manager.hpp
1 // SuperTuxKart - a fun racing game with go-kart
2 // Copyright (C) 2017 SuperTuxKart-Team
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 3
7 // of the License, or (at your option) any later version.
8 //
9 // This program 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 this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 
18 #ifndef HEADER_STK_TEX_MANAGER_HPP
19 #define HEADER_STK_TEX_MANAGER_HPP
20 
21 #include "graphics/gl_headers.hpp"
22 #include "utils/no_copy.hpp"
23 #include "utils/singleton.hpp"
24 
25 #include "irrString.h"
26 #include "ITexture.h"
27 
28 #include <cassert>
29 #include <functional>
30 #include <string>
31 #include <unordered_map>
32 
33 class STKTexture;
34 namespace irr
35 {
36  namespace video { class SColor; }
37 }
38 
39 class STKTexManager : public Singleton<STKTexManager>, NoCopy
40 {
41 private:
42  std::unordered_map<std::string, irr::video::ITexture*> m_all_textures;
43 
47 
48  // ------------------------------------------------------------------------
49  irr::video::ITexture* findTextureInFileSystem(const std::string& filename,
50  std::string* full_path);
51 public:
52  // ------------------------------------------------------------------------
53  STKTexManager() {}
54  // ------------------------------------------------------------------------
55  ~STKTexManager();
56  // ------------------------------------------------------------------------
57  irr::video::ITexture* getTexture(const std::string& path,
58  std::function<void(irr::video::IImage*)> image_mani = nullptr);
59  // ------------------------------------------------------------------------
60  irr::video::ITexture* addTexture(irr::video::ITexture* texture);
61  // ------------------------------------------------------------------------
62  bool hasTexture(const std::string& path);
63  // ------------------------------------------------------------------------
64  bool removeTexture(irr::video::ITexture* texture, bool remove_all = false);
65  // ------------------------------------------------------------------------
66  int dumpTextureUsage();
67  // ------------------------------------------------------------------------
68  void reloadAllTextures(bool mesh_texture_only = false);
69  // ------------------------------------------------------------------------
75  const std::string &getTextureErrorMessage()
76  {
78  } // getTextureErrorMessage
79  // ------------------------------------------------------------------------
80  void setTextureErrorMessage(const std::string &error,
81  const std::string &detail="");
82  // ------------------------------------------------------------------------
86  // ------------------------------------------------------------------------
94  irr::video::ITexture* getTexture(const std::string &filename,
95  const std::string &error_message,
96  const std::string &detail="")
97  {
98  setTextureErrorMessage(error_message, detail);
99  irr::video::ITexture *tex = getTexture(filename);
101  return tex;
102  } // getTexture
103  // ------------------------------------------------------------------------
111  irr::video::ITexture* getTexture(const std::string &filename,
112  char *error_message,
113  char *detail = NULL)
114  {
115  if (!detail)
116  return getTexture(filename, std::string(error_message),
117  std::string(""));
118 
119  return getTexture(filename, std::string(error_message),
120  std::string(detail));
121  } // getTexture
122  // ------------------------------------------------------------------------
123  std::unordered_map<std::string, irr::video::ITexture*>& getAllTextures()
124  { return m_all_textures; }
125 
126 }; // STKTexManager
127 
128 #endif
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Definition: stk_tex_manager.hpp:40
const std::string & getTextureErrorMessage()
Returns the currently defined texture error message, which is used by event_handler....
Definition: stk_tex_manager.hpp:75
std::string m_texture_error_message
Additional details to be shown in case that a texture is not found.
Definition: stk_tex_manager.hpp:46
irr::video::ITexture * getTexture(const std::string &filename, char *error_message, char *detail=NULL)
Convenience function that loads a texture with default parameters but includes an error message.
Definition: stk_tex_manager.hpp:111
irr::video::ITexture * getTexture(const std::string &filename, const std::string &error_message, const std::string &detail="")
Convenience function that loads a texture with default parameters but includes an error message.
Definition: stk_tex_manager.hpp:94
void setTextureErrorMessage(const std::string &error, const std::string &detail="")
Sets an error message to be displayed when a texture is not found.
Definition: stk_tex_manager.cpp:204
void unsetTextureErrorMessage()
Disables the texture error message again.
Definition: stk_tex_manager.hpp:85
Definition: singleton.hpp:87