Fix GEVulkanTexture::getTextureData for compressed internal format

This commit is contained in:
Benau 2022-08-06 11:01:54 +08:00
parent b4b0ddc620
commit 93dc6ed770
3 changed files with 38 additions and 10 deletions

View File

@ -16,6 +16,9 @@ irr::video::ITexture* createTexture(irr::video::IImage* img,
irr::video::IImage* getResizedImage(const std::string& path,
const irr::core::dimension2d<irr::u32>& max_size,
irr::core::dimension2d<irr::u32>* orig_size = NULL);
irr::video::IImage* getResizedImageFullPath(const irr::io::path& fullpath,
const irr::core::dimension2d<irr::u32>& max_size,
irr::core::dimension2d<irr::u32>* orig_size = NULL);
irr::video::IImage* getResizedImage(irr::io::IReadFile* file,
const irr::core::dimension2d<irr::u32>& max_size,
irr::core::dimension2d<irr::u32>* orig_size = NULL);

View File

@ -23,6 +23,19 @@ video::IImage* getResizedImage(const std::string& path,
return image;
} // getResizedImage
// ----------------------------------------------------------------------------
video::IImage* getResizedImageFullPath(const io::path& fullpath,
const core::dimension2d<u32>& max_size,
core::dimension2d<u32>* 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,

View File

@ -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();