mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-13 00:58:29 +02:00
HiresTextures: Move the maximum mip level check from DDS to main loader
This way that the mip count check occurs on .png and uncombined DDS textures as well.
This commit is contained in:
@ -366,6 +366,21 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co
|
||||
return name;
|
||||
}
|
||||
|
||||
u32 HiresTexture::CalculateMipCount(u32 width, u32 height)
|
||||
{
|
||||
u32 mip_width = width;
|
||||
u32 mip_height = height;
|
||||
u32 mip_count = 1;
|
||||
while (mip_width > 1 || mip_height > 1)
|
||||
{
|
||||
mip_width = std::max(mip_width / 2, 1u);
|
||||
mip_height = std::max(mip_height / 2, 1u);
|
||||
mip_count++;
|
||||
}
|
||||
|
||||
return mip_count;
|
||||
}
|
||||
|
||||
std::shared_ptr<HiresTexture> HiresTexture::Search(const u8* texture, size_t texture_size,
|
||||
const u8* tlut, size_t tlut_size, u32 width,
|
||||
u32 height, int format, bool has_mipmaps)
|
||||
@ -453,39 +468,45 @@ std::unique_ptr<HiresTexture> HiresTexture::Load(const std::string& base_filenam
|
||||
// Same deal if the custom texture isn't a multiple of the native size.
|
||||
if (width != 0 && height != 0 && (first_mip.width % width || first_mip.height % height))
|
||||
{
|
||||
WARN_LOG(VIDEO, "Invalid custom texture size %ux%u for texture %s. Please use an integer "
|
||||
"upscaling factor based on the native size %ux%u.",
|
||||
first_mip.width, first_mip.height, first_mip_filename.c_str(), width, height);
|
||||
ERROR_LOG(VIDEO, "Invalid custom texture size %ux%u for texture %s. Please use an integer "
|
||||
"upscaling factor based on the native size %ux%u.",
|
||||
first_mip.width, first_mip.height, first_mip_filename.c_str(), width, height);
|
||||
}
|
||||
|
||||
// Verify that each mip level is the correct size (divide by 2 each time).
|
||||
u32 current_mip_width = std::max(first_mip.width / 2, 1u);
|
||||
u32 current_mip_height = std::max(first_mip.height / 2, 1u);
|
||||
u32 current_mip_width = first_mip.width;
|
||||
u32 current_mip_height = first_mip.height;
|
||||
for (u32 mip_level = 1; mip_level < static_cast<u32>(ret->m_levels.size()); mip_level++)
|
||||
{
|
||||
const Level& level = ret->m_levels[mip_level];
|
||||
if (current_mip_width == level.width && current_mip_height == level.height)
|
||||
if (current_mip_width != 1 || current_mip_height != 1)
|
||||
{
|
||||
current_mip_width = std::max(current_mip_width / 2, 1u);
|
||||
current_mip_height = std::max(current_mip_height / 2, 1u);
|
||||
continue;
|
||||
}
|
||||
|
||||
ERROR_LOG(VIDEO,
|
||||
"Invalid custom texture size %dx%d for texture %s. Mipmap level %u _must_ be %dx%d.",
|
||||
level.width, level.height, first_mip_filename.c_str(), mip_level, current_mip_width,
|
||||
current_mip_height);
|
||||
const Level& level = ret->m_levels[mip_level];
|
||||
if (current_mip_width == level.width && current_mip_height == level.height)
|
||||
continue;
|
||||
|
||||
ERROR_LOG(VIDEO,
|
||||
"Invalid custom texture size %dx%d for texture %s. Mipmap level %u must be %dx%d.",
|
||||
level.width, level.height, first_mip_filename.c_str(), mip_level, current_mip_width,
|
||||
current_mip_height);
|
||||
}
|
||||
else
|
||||
{
|
||||
// It is invalid to have more than a single 1x1 mipmap.
|
||||
ERROR_LOG(VIDEO, "Custom texture %s has too many 1x1 mipmaps. Skipping extra levels.",
|
||||
first_mip_filename.c_str());
|
||||
}
|
||||
|
||||
// Drop this mip level and any others after it.
|
||||
while (ret->m_levels.size() > mip_level)
|
||||
ret->m_levels.pop_back();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// All levels have to have the same format.
|
||||
if (ret && std::any_of(ret->m_levels.begin(), ret->m_levels.end(),
|
||||
[&ret](const Level& l) { return l.format != ret->m_levels[0].format; }))
|
||||
if (std::any_of(ret->m_levels.begin(), ret->m_levels.end(),
|
||||
[&ret](const Level& l) { return l.format != ret->m_levels[0].format; }))
|
||||
{
|
||||
ERROR_LOG(VIDEO, "Custom texture %s has inconsistent formats across mip levels.",
|
||||
first_mip_filename.c_str());
|
||||
|
Reference in New Issue
Block a user