1431c68ea6565154c74a3b3c61cf99ea7598e632
[supertux.git] / src / video / texture_manager.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #ifndef __IMAGE_TEXTURE_MANAGER_HPP__
21 #define __IMAGE_TEXTURE_MANAGER_HPP__
22
23 #include <config.h>
24
25 #include "glutil.hpp"
26 #include <string>
27 #include <vector>
28 #include <map>
29 #include <set>
30
31 class Texture;
32 namespace GL { class Texture; }
33
34 class TextureManager
35 {
36 public:
37   TextureManager();
38   ~TextureManager();
39
40   Texture* get(const std::string& filename);
41
42 #ifdef HAVE_OPENGL
43   void register_texture(GL::Texture* texture);
44   void remove_texture(GL::Texture* texture);
45
46   void save_textures();
47   void reload_textures();
48 #endif
49
50 private:
51   friend class Texture;
52   void release(Texture* texture);
53
54   typedef std::map<std::string, Texture*> ImageTextures;
55   ImageTextures image_textures;
56
57   Texture* create_image_texture(const std::string& filename);
58
59 #ifdef HAVE_OPENGL
60   typedef std::set<GL::Texture*> Textures;
61   Textures textures;
62
63   struct SavedTexture
64   {
65     GL::Texture* texture;
66     GLint width;
67     GLint height;
68     char* pixels;
69     GLint border;
70
71     GLint min_filter;
72     GLint mag_filter;
73     GLint wrap_s;
74     GLint wrap_t;
75   };
76   std::vector<SavedTexture> saved_textures;
77
78   void save_texture(GL::Texture* texture);
79 #endif
80 };
81
82 extern TextureManager* texture_manager;
83
84 #endif