Game Develop Core: ImageManager.h Source File

| Game Develop Core Core library for developing platforms and tools compatible with Game Develop.

- Main Page
- Modules
- Classes

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Macros Groups Pages
ImageManager.h
Go to the documentation of this file.
1
6 #ifndef ImageManager_H
7 #define ImageManager_H
8
9 #include <iostream>
10 #include <vector>
11 #include <string>
12 #include <boost/shared_ptr.hpp>
13 #include <boost/weak_ptr.hpp>
14 #include <SFML/System.hpp>
15 #include <SFML/Graphics.hpp>
16 #include <SFML/OpenGL.hpp>
17 namespace gd { class Project; }
18 class OpenGLTextureWrapper;
19 class SFMLTextureWrapper;
20 #undef LoadImage //thx windows.h
21
22 namespace gd
23 {
24
39 class GD_CORE_API ImageManager
40 {
41 public:
42 ImageManager();
43 virtual ~ImageManager() {};
44
48 boost::shared_ptr<OpenGLTextureWrapper> GetOpenGLTexture(const std::string & name) const;
49
56 boost::shared_ptr<SFMLTextureWrapper> GetSFMLTexture(const std::string & name) const;
57
61 void SetGame(gd::Project * game_) { game = game_; }
62
67 void LoadPermanentImages();
68
73 bool HasLoadedSFMLTexture(const std::string & name) const;
74
79 void SetSFMLTextureAsPermanentlyLoaded(const std::string & name, boost::shared_ptr<SFMLTextureWrapper> & texture) const;
80
84 void ReloadImage(const std::string & name) const;
85
86 #if defined(GD_IDE_ONLY)
87
91 void PreventImagesUnloading();
92
96 void EnableImagesUnloading();
97 #endif
98
99 private:
100 mutable std::map < std::string, boost::weak_ptr<SFMLTextureWrapper> > alreadyLoadedImages;
101 mutable std::map < std::string, boost::shared_ptr<SFMLTextureWrapper> > permanentlyLoadedImages;
102
103 #if defined(GD_IDE_ONLY)
104
112 mutable std::vector< boost::shared_ptr<SFMLTextureWrapper> > unloadingPreventer;
113 bool preventUnloading;
114 #endif
115
116 mutable std::map < std::string, boost::weak_ptr<OpenGLTextureWrapper> > alreadyLoadedOpenGLTextures;
117
118 mutable boost::shared_ptr<SFMLTextureWrapper> badTexture;
119 mutable boost::shared_ptr<OpenGLTextureWrapper> badOpenGLTexture;
120
121 gd::Project * game;
122 };
123
124 }
125
132 class GD_CORE_API SFMLTextureWrapper
133 {
134 public :
135 SFMLTextureWrapper(sf::Texture & texture);
136 SFMLTextureWrapper();
137 ~SFMLTextureWrapper();
138
139 sf::Texture texture;
140 sf::Image image;
141 };
142
149 class GD_CORE_API OpenGLTextureWrapper
150 {
151 public :
152 OpenGLTextureWrapper(boost::shared_ptr<SFMLTextureWrapper> sfmlTexture_);
153 OpenGLTextureWrapper() : texture(0) {};
154 ~OpenGLTextureWrapper();
155 inline GLuint GetOpenGLTexture() const { return texture; }
156
157 private :
158 boost::shared_ptr<SFMLTextureWrapper> sfmlTexture;
159 GLuint texture;
160 };
161
162
163 #endif // ImageManager_H