diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 5c70c0639..89bd99503 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -31,6 +31,8 @@ #include "graphics/shaders.hpp" #include "graphics/shared_gpu_objects.hpp" #include "graphics/stk_mesh_scene_node.hpp" +#include "graphics/stk_texture.hpp" +#include "graphics/stk_tex_manager.hpp" #include "graphics/weather.hpp" #include "io/file_manager.hpp" #include "karts/abstract_kart.hpp" @@ -769,18 +771,20 @@ PostProcessing::PostProcessing(IVideoDriver* video_driver) { m_material.TextureLayer[i].TextureWrapU = m_material.TextureLayer[i].TextureWrapV = ETC_CLAMP_TO_EDGE; - } + } // Load the MLAA area map io::IReadFile *areamap = irr_driver->getDevice()->getFileSystem()-> createMemoryReadFile((void *) AreaMap33, sizeof(AreaMap33), "AreaMap33", false); - if (!areamap) + video::IImage* img = irr_driver->getVideoDriver()->createImageFromFile(areamap); + m_areamap = new STKTexture(img, "AreaMap33"); + if (m_areamap->getOpenGLTextureName() == 0) { Log::fatal("postprocessing", "Failed to load the areamap"); return; } - m_areamap = irr_driver->getVideoDriver()->getTexture(areamap); + STKTexManager::getInstance()->addTexture(m_areamap); areamap->drop(); } // PostProcessing diff --git a/src/graphics/post_processing.hpp b/src/graphics/post_processing.hpp index fde35f1f2..d78a0ae96 100644 --- a/src/graphics/post_processing.hpp +++ b/src/graphics/post_processing.hpp @@ -27,6 +27,7 @@ class FrameBuffer; class RTT; +class STKTexture; namespace irr { @@ -63,7 +64,7 @@ private: * the vertex position, normal, and texture coordinate. */ std::vector m_vertices; - video::ITexture *m_areamap; + STKTexture* m_areamap; void setMotionBlurCenterY(const u32 num, const float y); diff --git a/src/graphics/stk_tex_manager.cpp b/src/graphics/stk_tex_manager.cpp index 14b5cee1c..2ebf95abc 100644 --- a/src/graphics/stk_tex_manager.cpp +++ b/src/graphics/stk_tex_manager.cpp @@ -122,6 +122,7 @@ void STKTexManager::removeTexture(STKTexture* texture, bool remove_all) } } #ifdef DEBUG + if (!remove_all) return; for (const std::string& s : undeleted_texture) { Log::error("STKTexManager", "%s undeleted!", s.c_str()); diff --git a/src/graphics/stk_texture.cpp b/src/graphics/stk_texture.cpp index 11d9e39c8..d09426de7 100644 --- a/src/graphics/stk_texture.cpp +++ b/src/graphics/stk_texture.cpp @@ -70,6 +70,16 @@ STKTexture::STKTexture(uint8_t* data, const std::string& name, size_t size, reload(false/*no_upload*/, data, single_channel); } // STKTexture +// ---------------------------------------------------------------------------- +STKTexture::STKTexture(video::IImage* img, const std::string& name) + : video::ITexture(name.c_str()), m_texture_handle(0), m_srgb(false), + m_premul_alpha(false), m_mesh_texture(false), m_material(NULL), + m_texture_name(0), m_texture_size(0), m_texture_image(NULL) +{ + reload(false/*no_upload*/, NULL/*preload_data*/, false/*single_channel*/, + img); +} // STKTexture + // ---------------------------------------------------------------------------- STKTexture::~STKTexture() { @@ -86,7 +96,7 @@ STKTexture::~STKTexture() // ---------------------------------------------------------------------------- void STKTexture::reload(bool no_upload, uint8_t* preload_data, - bool single_channel) + bool single_channel, video::IImage* preload_img) { if (ProfileWorld::isNoGraphics()) { @@ -143,7 +153,7 @@ void STKTexture::reload(bool no_upload, uint8_t* preload_data, uint8_t* data = preload_data; if (data == NULL) { - orig_img = + orig_img = preload_img ? preload_img : irr_driver->getVideoDriver()->createImageFromFile(NamedPath); if (orig_img == NULL) { diff --git a/src/graphics/stk_texture.hpp b/src/graphics/stk_texture.hpp index 9c78eb11a..9e4776514 100644 --- a/src/graphics/stk_texture.hpp +++ b/src/graphics/stk_texture.hpp @@ -66,6 +66,8 @@ public: STKTexture(uint8_t* data, const std::string& name, size_t size, bool single_channel = false); // ------------------------------------------------------------------------ + STKTexture(video::IImage* img, const std::string& name); + // ------------------------------------------------------------------------ virtual ~STKTexture(); // ------------------------------------------------------------------------ virtual void* lock(video::E_TEXTURE_LOCK_MODE mode = @@ -117,7 +119,8 @@ public: unsigned int getTextureSize() const { return m_texture_size; } // ------------------------------------------------------------------------ void reload(bool no_upload = false, uint8_t* preload_data = NULL, - bool single_channel = false); + bool single_channel = false, + video::IImage* preload_img = NULL); // ------------------------------------------------------------------------ video::IImage* getTextureImage() { return m_texture_image; }