X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fvideo%2Ftexture_manager.cpp;h=dc38be94943ea7393eed7933912b9514fdb81ff8;hb=77b5a67fccb8ce3a5ba43280105031a46560a5c8;hp=7d7830efae0c6ebdd777854b4a67694002cb7256;hpb=bd47623805cd3eb2bcb5953946282a7a92453eb9;p=supertux.git diff --git a/src/video/texture_manager.cpp b/src/video/texture_manager.cpp index 7d7830efa..dc38be949 100644 --- a/src/video/texture_manager.cpp +++ b/src/video/texture_manager.cpp @@ -28,54 +28,54 @@ #include "util/log.hpp" #include "video/sdl_surface_ptr.hpp" #include "video/texture.hpp" -#include "video/video_systems.hpp" +#include "video/video_system.hpp" #ifdef HAVE_OPENGL #include "video/gl/gl_texture.hpp" #endif TextureManager::TextureManager() : - image_textures() - ,surfaces() + m_image_textures() + ,m_surfaces() #ifdef HAVE_OPENGL - ,textures(), - saved_textures() + ,m_textures(), + m_saved_textures() #endif { } TextureManager::~TextureManager() { - for(ImageTextures::iterator i = image_textures.begin(); i != image_textures.end(); ++i) + for(ImageTextures::iterator i = m_image_textures.begin(); i != m_image_textures.end(); ++i) { if(!i->second.expired()) { log_warning << "Texture '" << i->first << "' not freed" << std::endl; } } - image_textures.clear(); + m_image_textures.clear(); - for(auto& surface : surfaces) + for(auto& surface : m_surfaces) { SDL_FreeSurface(surface.second); } - surfaces.clear(); + m_surfaces.clear(); } TexturePtr TextureManager::get(const std::string& _filename) { std::string filename = FileSystem::normalize(_filename); - ImageTextures::iterator i = image_textures.find(filename); + ImageTextures::iterator i = m_image_textures.find(filename); TexturePtr texture; - if(i != image_textures.end()) + if(i != m_image_textures.end()) texture = i->second.lock(); if(!texture) { texture = create_image_texture(filename); texture->cache_filename = filename; - image_textures[filename] = texture; + m_image_textures[filename] = texture; } return texture; @@ -92,23 +92,23 @@ TextureManager::get(const std::string& _filename, const Rect& rect) void TextureManager::reap_cache_entry(const std::string& filename) { - ImageTextures::iterator i = image_textures.find(filename); - assert(i != image_textures.end()); + ImageTextures::iterator i = m_image_textures.find(filename); + assert(i != m_image_textures.end()); assert(i->second.expired()); - image_textures.erase(i); + m_image_textures.erase(i); } #ifdef HAVE_OPENGL void TextureManager::register_texture(GLTexture* texture) { - textures.insert(texture); + m_textures.insert(texture); } void TextureManager::remove_texture(GLTexture* texture) { - textures.erase(texture); + m_textures.erase(texture); } #endif @@ -131,8 +131,8 @@ TextureManager::create_image_texture_raw(const std::string& filename, const Rect { SDL_Surface *image = nullptr; - Surfaces::iterator i = surfaces.find(filename); - if (i != surfaces.end()) + Surfaces::iterator i = m_surfaces.find(filename); + if (i != m_surfaces.end()) { image = i->second; } @@ -146,7 +146,13 @@ TextureManager::create_image_texture_raw(const std::string& filename, const Rect throw std::runtime_error(msg.str()); } - surfaces[filename] = image; + m_surfaces[filename] = image; + } + + SDL_PixelFormat* format = image->format; + if(format->Rmask == 0 && format->Gmask == 0 && format->Bmask == 0 && format->Amask == 0) { + log_debug << "Wrong surface format for image " << filename << ". Compensating." << std::endl; + image = SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_RGBA8888, 0); } SDLSurfacePtr subimage(SDL_CreateRGBSurfaceFrom(static_cast(image->pixels) + @@ -171,7 +177,7 @@ TextureManager::create_image_texture_raw(const std::string& filename, const Rect } #endif - return VideoSystem::new_texture(subimage.get()); + return VideoSystem::current()->new_texture(subimage.get()); } TexturePtr @@ -200,7 +206,7 @@ TextureManager::create_image_texture_raw(const std::string& filename) } else { - TexturePtr texture = VideoSystem::new_texture(image.get()); + TexturePtr texture = VideoSystem::current()->new_texture(image.get()); image.reset(NULL); return texture; } @@ -224,12 +230,12 @@ TextureManager::create_dummy_texture() SDLSurfacePtr image(SDL_CreateRGBSurface(0, 1024, 1024, 8, 0, 0, 0, 0)); if (!image) { - throw err; + throw; } else { log_warning << "Couldn't load texture '" << dummy_texture_fname << "' (now using empty one): " << err.what() << std::endl; - TexturePtr texture = VideoSystem::new_texture(image.get()); + TexturePtr texture = VideoSystem::current()->new_texture(image.get()); image.reset(NULL); return texture; } @@ -240,7 +246,7 @@ TextureManager::create_dummy_texture() void TextureManager::save_textures() { -#ifdef GL_PACK_ROW_LENGTH +#if defined(GL_PACK_ROW_LENGTH) || defined(USE_GLBINDING) /* all this stuff is not support by OpenGL ES */ glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0); @@ -250,12 +256,20 @@ TextureManager::save_textures() #endif glPixelStorei(GL_PACK_ALIGNMENT, 1); - for(Textures::iterator i = textures.begin(); i != textures.end(); ++i) { + + for(Textures::iterator i = m_textures.begin(); i != m_textures.end(); ++i) + { save_texture(*i); } - for(ImageTextures::iterator i = image_textures.begin(); - i != image_textures.end(); ++i) { - save_texture(dynamic_cast(i->second.lock().get())); + + for(ImageTextures::iterator i = m_image_textures.begin(); + i != m_image_textures.end(); ++i) + { + GLTexture* texture = dynamic_cast(i->second.lock().get()); + if(texture == NULL) + continue; + + save_texture(texture); } } @@ -290,7 +304,7 @@ TextureManager::save_texture(GLTexture* texture) saved_texture.pixels); #endif - saved_textures.push_back(saved_texture); + m_saved_textures.push_back(saved_texture); glDeleteTextures(1, &(texture->get_handle())); texture->set_handle(0); @@ -301,7 +315,7 @@ TextureManager::save_texture(GLTexture* texture) void TextureManager::reload_textures() { -#ifdef GL_UNPACK_ROW_LENGTH +#if defined(GL_UNPACK_ROW_LENGTH) || defined(USE_GLBINDING) /* OpenGL ES doesn't support these */ glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0); @@ -311,8 +325,8 @@ TextureManager::reload_textures() #endif glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - for(std::vector::iterator i = saved_textures.begin(); - i != saved_textures.end(); ++i) { + for(std::vector::iterator i = m_saved_textures.begin(); + i != m_saved_textures.end(); ++i) { SavedTexture& saved_texture = *i; GLuint handle; @@ -320,7 +334,7 @@ TextureManager::reload_textures() assert_gl("creating texture handle"); glBindTexture(GL_TEXTURE_2D, handle); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, + glTexImage2D(GL_TEXTURE_2D, 0, static_cast(GL_RGBA), saved_texture.width, saved_texture.height, saved_texture.border, GL_RGBA, GL_UNSIGNED_BYTE, saved_texture.pixels); @@ -340,7 +354,7 @@ TextureManager::reload_textures() saved_texture.texture->set_handle(handle); } - saved_textures.clear(); + m_saved_textures.clear(); } #endif