00001 // SuperTux 00002 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #ifndef HEADER_SUPERTUX_VIDEO_TEXTURE_MANAGER_HPP 00018 #define HEADER_SUPERTUX_VIDEO_TEXTURE_MANAGER_HPP 00019 00020 #include <config.h> 00021 00022 #include <map> 00023 #include <set> 00024 #include <string> 00025 #include <vector> 00026 #include <boost/weak_ptr.hpp> 00027 00028 #include "video/glutil.hpp" 00029 #include "video/texture_ptr.hpp" 00030 00031 class Texture; 00032 class GLTexture; 00033 class Rect; 00034 00035 class TextureManager 00036 { 00037 public: 00038 TextureManager(); 00039 ~TextureManager(); 00040 00041 TexturePtr get(const std::string& filename); 00042 TexturePtr get(const std::string& filename, const Rect& rect); 00043 00044 #ifdef HAVE_OPENGL 00045 void register_texture(GLTexture* texture); 00046 void remove_texture(GLTexture* texture); 00047 00048 void save_textures(); 00049 void reload_textures(); 00050 #endif 00051 00052 private: 00053 friend class Texture; 00054 void reap_cache_entry(const std::string& filename); 00055 00056 typedef std::map<std::string, boost::weak_ptr<Texture> > ImageTextures; 00057 ImageTextures image_textures; 00058 00059 TexturePtr create_image_texture(const std::string& filename, const Rect& rect); 00060 00062 TexturePtr create_image_texture(const std::string& filename); 00063 00065 TexturePtr create_image_texture_raw(const std::string& filename); 00066 TexturePtr create_image_texture_raw(const std::string& filename, const Rect& rect); 00067 00068 TexturePtr create_dummy_texture(); 00069 00070 #ifdef HAVE_OPENGL 00071 typedef std::set<GLTexture*> Textures; 00072 Textures textures; 00073 00074 struct SavedTexture 00075 { 00076 GLTexture* texture; 00077 GLint width; 00078 GLint height; 00079 char* pixels; 00080 GLint border; 00081 00082 GLint min_filter; 00083 GLint mag_filter; 00084 GLint wrap_s; 00085 GLint wrap_t; 00086 }; 00087 std::vector<SavedTexture> saved_textures; 00088 00089 void save_texture(GLTexture* texture); 00090 #endif 00091 }; 00092 00093 #endif 00094 00095 /* EOF */