X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fvideo%2Ftexture_manager.cpp;h=d45eb84f8bffe255d9143f7c3054d4e387751ff6;hb=6cd71a8644049d1951b5a9702a57ad02a7971c1e;hp=ab5788eaa5e2c1c145c79e31c46564d63afd61a3;hpb=86181b0a14d89cf45daf97199c3556c4dd1ee7b7;p=supertux.git diff --git a/src/video/texture_manager.cpp b/src/video/texture_manager.cpp index ab5788eaa..d45eb84f8 100644 --- a/src/video/texture_manager.cpp +++ b/src/video/texture_manager.cpp @@ -1,3 +1,22 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include "texture_manager.hpp" @@ -6,12 +25,15 @@ #include #include #include +#include #include #include #include #include "physfs/physfs_sdl.hpp" #include "image_texture.hpp" #include "glutil.hpp" +#include "file_system.hpp" +#include "log.hpp" TextureManager* texture_manager = NULL; @@ -25,16 +47,15 @@ TextureManager::~TextureManager() i != image_textures.end(); ++i) { if(i->second == NULL) continue; -#ifdef DEBUG - std::cerr << "Warning: Texture '" << i->first << "' not freed\n"; -#endif + log_warning << "Texture '" << i->first << "' not freed" << std::endl; delete i->second; } } ImageTexture* -TextureManager::get(const std::string& filename) +TextureManager::get(const std::string& _filename) { + std::string filename = FileSystem::normalize(_filename); ImageTextures::iterator i = image_textures.find(filename); ImageTexture* texture = NULL; @@ -52,7 +73,7 @@ TextureManager::get(const std::string& filename) void TextureManager::release(ImageTexture* texture) { - image_textures[texture->filename] = NULL; + image_textures.erase(texture->filename); delete texture; } @@ -116,7 +137,7 @@ TextureManager::create_image_texture(const std::string& filename) SDL_FreeSurface(convert); throw; } - + SDL_FreeSurface(convert); return result; } @@ -162,7 +183,7 @@ TextureManager::save_texture(Texture* texture) size_t pixelssize = saved_texture.width * saved_texture.height * 4; saved_texture.pixels = new char[pixelssize]; - + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, saved_texture.pixels); @@ -171,7 +192,7 @@ TextureManager::save_texture(Texture* texture) glDeleteTextures(1, &(texture->handle)); texture->handle = 0; - assert_gl("retrieving texture"); + assert_gl("retrieving texture for save"); } void @@ -183,11 +204,11 @@ TextureManager::reload_textures() glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_IMAGES, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - + for(std::vector::iterator i = saved_textures.begin(); i != saved_textures.end(); ++i) { SavedTexture& saved_texture = *i; - + GLuint handle; glGenTextures(1, &handle); assert_gl("creating texture handle"); @@ -215,4 +236,3 @@ TextureManager::reload_textures() saved_textures.clear(); } -