Implemented fullscreen mode selection, OpenGL only for the moment
[supertux.git] / src / video / texture_manager.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program 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 //  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, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_VIDEO_TEXTURE_MANAGER_HPP
18 #define HEADER_SUPERTUX_VIDEO_TEXTURE_MANAGER_HPP
19
20 #include <SDL_video.h>
21
22 #include <config.h>
23
24 #include <map>
25 #include <set>
26 #include <string>
27 #include <vector>
28 #include <boost/weak_ptr.hpp>
29
30 #include "video/glutil.hpp"
31 #include "video/texture_ptr.hpp"
32
33 class Texture;
34 class GLTexture;
35 class Rect;
36
37 class TextureManager
38 {
39 public:
40   TextureManager();
41   ~TextureManager();
42
43   TexturePtr get(const std::string& filename);
44   TexturePtr get(const std::string& filename, const Rect& rect);
45
46 #ifdef HAVE_OPENGL
47   void register_texture(GLTexture* texture);
48   void remove_texture(GLTexture* texture);
49
50   void save_textures();
51   void reload_textures();
52 #endif
53
54 private:
55   friend class Texture;
56   void reap_cache_entry(const std::string& filename);
57
58   typedef std::map<std::string, boost::weak_ptr<Texture> > ImageTextures;
59   ImageTextures image_textures;
60   typedef std::map<std::string, SDL_Surface*> Surfaces;
61   Surfaces surfaces;
62
63   TexturePtr create_image_texture(const std::string& filename, const Rect& rect);
64
65   /** on failure a dummy texture is returned and no exception is thrown */
66   TexturePtr create_image_texture(const std::string& filename);
67
68   /** throw an exception on error */
69   TexturePtr create_image_texture_raw(const std::string& filename);
70   TexturePtr create_image_texture_raw(const std::string& filename, const Rect& rect);
71
72   TexturePtr create_dummy_texture();
73   
74 #ifdef HAVE_OPENGL
75   typedef std::set<GLTexture*> Textures;
76   Textures textures;
77
78   struct SavedTexture
79   {
80     GLTexture* texture;
81     GLint width;
82     GLint height;
83     char* pixels;
84     GLint border;
85
86     GLint min_filter;
87     GLint mag_filter;
88     GLint wrap_s;
89     GLint wrap_t;
90   };
91   std::vector<SavedTexture> saved_textures;
92
93   void save_texture(GLTexture* texture);
94 #endif
95 };
96
97 #endif
98
99 /* EOF */