From 93dc6ed7702793c0a72196d5d67a791633ddae2c Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 6 Aug 2022 11:01:54 +0800 Subject: [PATCH] Fix GEVulkanTexture::getTextureData for compressed internal format --- lib/graphics_engine/include/ge_texture.hpp | 3 ++ lib/graphics_engine/src/ge_texture.cpp | 13 ++++++++ lib/graphics_engine/src/ge_vulkan_texture.cpp | 32 +++++++++++++------ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/graphics_engine/include/ge_texture.hpp b/lib/graphics_engine/include/ge_texture.hpp index 518ebf5f7..3295ff4e8 100644 --- a/lib/graphics_engine/include/ge_texture.hpp +++ b/lib/graphics_engine/include/ge_texture.hpp @@ -16,6 +16,9 @@ irr::video::ITexture* createTexture(irr::video::IImage* img, irr::video::IImage* getResizedImage(const std::string& path, const irr::core::dimension2d& max_size, irr::core::dimension2d* orig_size = NULL); +irr::video::IImage* getResizedImageFullPath(const irr::io::path& fullpath, + const irr::core::dimension2d& max_size, + irr::core::dimension2d* orig_size = NULL); irr::video::IImage* getResizedImage(irr::io::IReadFile* file, const irr::core::dimension2d& max_size, irr::core::dimension2d* orig_size = NULL); diff --git a/lib/graphics_engine/src/ge_texture.cpp b/lib/graphics_engine/src/ge_texture.cpp index 5f7fd2990..d948488d4 100644 --- a/lib/graphics_engine/src/ge_texture.cpp +++ b/lib/graphics_engine/src/ge_texture.cpp @@ -23,6 +23,19 @@ video::IImage* getResizedImage(const std::string& path, return image; } // getResizedImage +// ---------------------------------------------------------------------------- +video::IImage* getResizedImageFullPath(const io::path& fullpath, + const core::dimension2d& max_size, + core::dimension2d* orig_size) +{ + io::IReadFile* file = io::createReadFile(fullpath); + if (file == NULL) + return NULL; + video::IImage* texture_image = getResizedImage(file, max_size, orig_size); + file->drop(); + return texture_image; +} // getResizedImageFullPath + // ---------------------------------------------------------------------------- video::IImage* getResizedImage(irr::io::IReadFile* file, const core::dimension2du& max_size, diff --git a/lib/graphics_engine/src/ge_vulkan_texture.cpp b/lib/graphics_engine/src/ge_vulkan_texture.cpp index 58de43243..241b0de3c 100644 --- a/lib/graphics_engine/src/ge_vulkan_texture.cpp +++ b/lib/graphics_engine/src/ge_vulkan_texture.cpp @@ -413,17 +413,13 @@ void GEVulkanTexture::reloadInternal() clearVulkanData(); - io::IReadFile* file = io::createReadFile(m_full_path); - if (file == NULL) - { - // We checked for file existence so we should always get a file - throw std::runtime_error("File missing in getResizedImage"); - } - video::IImage* texture_image = getResizedImage(file, m_max_size, - &m_orig_size); + video::IImage* texture_image = getResizedImageFullPath(m_full_path, + m_max_size, &m_orig_size); if (texture_image == NULL) - throw std::runtime_error("Missing texture_image in getResizedImage"); - file->drop(); + { + throw std::runtime_error( + "Missing texture_image in getResizedImageFullPath"); + } m_size = texture_image->getDimension(); if (m_size.Width < 4 || m_size.Height < 4) @@ -480,6 +476,22 @@ void* GEVulkanTexture::lock(video::E_TEXTURE_LOCK_MODE mode, u32 mipmap_level) // ---------------------------------------------------------------------------- uint8_t* GEVulkanTexture::getTextureData() { + if (m_internal_format != VK_FORMAT_R8G8B8A8_UNORM || + m_internal_format != VK_FORMAT_R8_UNORM) + { + if (m_full_path.empty()) + return NULL; + + video::IImage* texture_image = getResizedImageFullPath(m_full_path, + m_max_size, &m_orig_size); + if (texture_image == NULL) + return NULL; + texture_image->setDeleteMemory(false); + uint8_t* data = (uint8_t*)texture_image->lock(); + texture_image->drop(); + return data; + } + m_image_view_lock.lock(); m_image_view_lock.unlock();