summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/TextureAsset.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/VideoCommon/Assets/TextureAsset.cpp')
-rw-r--r--Source/Core/VideoCommon/Assets/TextureAsset.cpp95
1 files changed, 12 insertions, 83 deletions
diff --git a/Source/Core/VideoCommon/Assets/TextureAsset.cpp b/Source/Core/VideoCommon/Assets/TextureAsset.cpp
index 335ed73b33..fc6c865f76 100644
--- a/Source/Core/VideoCommon/Assets/TextureAsset.cpp
+++ b/Source/Core/VideoCommon/Assets/TextureAsset.cpp
@@ -153,8 +153,8 @@ bool ParseSampler(const VideoCommon::CustomAssetLibrary::AssetID& asset_id,
return true;
}
} // namespace
-bool TextureData::FromJson(const CustomAssetLibrary::AssetID& asset_id,
- const picojson::object& json, TextureData* data)
+bool TextureAndSamplerData::FromJson(const CustomAssetLibrary::AssetID& asset_id,
+ const picojson::object& json, TextureAndSamplerData* data)
{
const auto type_iter = json.find("type");
if (type_iter == json.end())
@@ -176,7 +176,7 @@ bool TextureData::FromJson(const CustomAssetLibrary::AssetID& asset_id,
if (type == "texture2d")
{
- data->m_type = TextureData::Type::Type_Texture2D;
+ data->m_type = TextureAndSamplerData::Type::Type_Texture2D;
if (!ParseSampler(asset_id, json, &data->m_sampler))
{
@@ -185,7 +185,7 @@ bool TextureData::FromJson(const CustomAssetLibrary::AssetID& asset_id,
}
else if (type == "texturecube")
{
- data->m_type = TextureData::Type::Type_TextureCube;
+ data->m_type = TextureAndSamplerData::Type::Type_TextureCube;
}
else
{
@@ -199,7 +199,7 @@ bool TextureData::FromJson(const CustomAssetLibrary::AssetID& asset_id,
return true;
}
-void TextureData::ToJson(picojson::object* obj, const TextureData& data)
+void TextureAndSamplerData::ToJson(picojson::object* obj, const TextureAndSamplerData& data)
{
if (!obj) [[unlikely]]
return;
@@ -207,13 +207,13 @@ void TextureData::ToJson(picojson::object* obj, const TextureData& data)
auto& json_obj = *obj;
switch (data.m_type)
{
- case TextureData::Type::Type_Texture2D:
+ case TextureAndSamplerData::Type::Type_Texture2D:
json_obj.emplace("type", "texture2d");
break;
- case TextureData::Type::Type_TextureCube:
+ case TextureAndSamplerData::Type::Type_TextureCube:
json_obj.emplace("type", "texturecube");
break;
- case TextureData::Type::Type_Undefined:
+ case TextureAndSamplerData::Type::Type_Undefined:
break;
};
@@ -254,11 +254,11 @@ void TextureData::ToJson(picojson::object* obj, const TextureData& data)
json_obj.emplace("filter_mode", filter_mode);
}
-CustomAssetLibrary::LoadInfo GameTextureAsset::LoadImpl(const CustomAssetLibrary::AssetID& asset_id)
+CustomAssetLibrary::LoadInfo TextureAsset::LoadImpl(const CustomAssetLibrary::AssetID& asset_id)
{
- auto potential_data = std::make_shared<TextureData>();
- const auto loaded_info = m_owning_library->LoadGameTexture(asset_id, potential_data.get());
- if (loaded_info.m_bytes_loaded == 0)
+ auto potential_data = std::make_shared<CustomTextureData>();
+ const auto loaded_info = m_owning_library->LoadTexture(asset_id, potential_data.get());
+ if (loaded_info.bytes_loaded == 0)
return {};
{
std::lock_guard lk(m_data_lock);
@@ -267,75 +267,4 @@ CustomAssetLibrary::LoadInfo GameTextureAsset::LoadImpl(const CustomAssetLibrary
}
return loaded_info;
}
-
-bool GameTextureAsset::Validate(u32 native_width, u32 native_height) const
-{
- std::lock_guard lk(m_data_lock);
-
- if (!m_loaded)
- {
- ERROR_LOG_FMT(VIDEO,
- "Game texture can't be validated for asset '{}' because it is not loaded yet.",
- GetAssetId());
- return false;
- }
-
- if (m_data->m_texture.m_slices.empty())
- {
- ERROR_LOG_FMT(VIDEO,
- "Game texture can't be validated for asset '{}' because no data was available.",
- GetAssetId());
- return false;
- }
-
- if (m_data->m_texture.m_slices.size() > 1)
- {
- ERROR_LOG_FMT(
- VIDEO,
- "Game texture can't be validated for asset '{}' because it has more slices than expected.",
- GetAssetId());
- return false;
- }
-
- const auto& slice = m_data->m_texture.m_slices[0];
- if (slice.m_levels.empty())
- {
- ERROR_LOG_FMT(
- VIDEO,
- "Game texture can't be validated for asset '{}' because first slice has no data available.",
- GetAssetId());
- return false;
- }
-
- // Verify that the aspect ratio of the texture hasn't changed, as this could have
- // side-effects.
- const VideoCommon::CustomTextureData::ArraySlice::Level& first_mip = slice.m_levels[0];
- if (first_mip.width * native_height != first_mip.height * native_width)
- {
- // Note: this feels like this should return an error but
- // for legacy reasons this is only a notice that something *could*
- // go wrong
- WARN_LOG_FMT(
- VIDEO,
- "Invalid custom texture size {}x{} for game texture asset '{}'. The aspect differs "
- "from the native size {}x{}.",
- first_mip.width, first_mip.height, GetAssetId(), native_width, native_height);
- }
-
- // Same deal if the custom texture isn't a multiple of the native size.
- if (native_width != 0 && native_height != 0 &&
- (first_mip.width % native_width || first_mip.height % native_height))
- {
- // Note: this feels like this should return an error but
- // for legacy reasons this is only a notice that something *could*
- // go wrong
- WARN_LOG_FMT(
- VIDEO,
- "Invalid custom texture size {}x{} for game texture asset '{}'. Please use an integer "
- "upscaling factor based on the native size {}x{}.",
- first_mip.width, first_mip.height, GetAssetId(), native_width, native_height);
- }
-
- return true;
-}
} // namespace VideoCommon