summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/TextureAsset.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2025-09-16 14:48:24 -0400
committerGitHub <noreply@github.com>2025-09-16 14:48:24 -0400
commit8b0498f5f22639967e3b7ac7a5fcab649ea5d3ca (patch)
tree45fbf75d0517e415d7629bcd47cca18f329c312a /Source/Core/VideoCommon/Assets/TextureAsset.cpp
parentc7b4cd9961e9bb1bedb0c3aeccdf0c60dbc8efd0 (diff)
parent4489ea0ec29b91564de2e1b3a3ad0b2092dd2202 (diff)
Merge pull request #13889 from iwubcode/texture_and_sampler_asset
VideoCommon: add TextureAndSamplerAsset for use in custom materials
Diffstat (limited to 'Source/Core/VideoCommon/Assets/TextureAsset.cpp')
-rw-r--r--Source/Core/VideoCommon/Assets/TextureAsset.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/Source/Core/VideoCommon/Assets/TextureAsset.cpp b/Source/Core/VideoCommon/Assets/TextureAsset.cpp
index fc6c865f76..7c76426619 100644
--- a/Source/Core/VideoCommon/Assets/TextureAsset.cpp
+++ b/Source/Core/VideoCommon/Assets/TextureAsset.cpp
@@ -176,16 +176,20 @@ bool TextureAndSamplerData::FromJson(const CustomAssetLibrary::AssetID& asset_id
if (type == "texture2d")
{
- data->m_type = TextureAndSamplerData::Type::Type_Texture2D;
+ data->type = AbstractTextureType::Texture_2D;
- if (!ParseSampler(asset_id, json, &data->m_sampler))
+ if (!ParseSampler(asset_id, json, &data->sampler))
{
return false;
}
}
else if (type == "texturecube")
{
- data->m_type = TextureAndSamplerData::Type::Type_TextureCube;
+ data->type = AbstractTextureType::Texture_CubeMap;
+ }
+ else if (type == "texture2darray")
+ {
+ data->type = AbstractTextureType::Texture_2DArray;
}
else
{
@@ -205,15 +209,16 @@ void TextureAndSamplerData::ToJson(picojson::object* obj, const TextureAndSample
return;
auto& json_obj = *obj;
- switch (data.m_type)
+ switch (data.type)
{
- case TextureAndSamplerData::Type::Type_Texture2D:
+ case AbstractTextureType::Texture_2D:
json_obj.emplace("type", "texture2d");
break;
- case TextureAndSamplerData::Type::Type_TextureCube:
+ case AbstractTextureType::Texture_CubeMap:
json_obj.emplace("type", "texturecube");
break;
- case TextureAndSamplerData::Type::Type_Undefined:
+ case AbstractTextureType::Texture_2DArray:
+ json_obj.emplace("type", "texture2darray");
break;
};
@@ -243,14 +248,14 @@ void TextureAndSamplerData::ToJson(picojson::object* obj, const TextureAndSample
};
picojson::object wrap_mode;
- wrap_mode.emplace("u", wrap_mode_to_string(data.m_sampler.tm0.wrap_u));
- wrap_mode.emplace("v", wrap_mode_to_string(data.m_sampler.tm0.wrap_v));
+ wrap_mode.emplace("u", wrap_mode_to_string(data.sampler.tm0.wrap_u));
+ wrap_mode.emplace("v", wrap_mode_to_string(data.sampler.tm0.wrap_v));
json_obj.emplace("wrap_mode", wrap_mode);
picojson::object filter_mode;
- filter_mode.emplace("min", filter_mode_to_string(data.m_sampler.tm0.min_filter));
- filter_mode.emplace("mag", filter_mode_to_string(data.m_sampler.tm0.mag_filter));
- filter_mode.emplace("mipmap", filter_mode_to_string(data.m_sampler.tm0.mipmap_filter));
+ filter_mode.emplace("min", filter_mode_to_string(data.sampler.tm0.min_filter));
+ filter_mode.emplace("mag", filter_mode_to_string(data.sampler.tm0.mag_filter));
+ filter_mode.emplace("mipmap", filter_mode_to_string(data.sampler.tm0.mipmap_filter));
json_obj.emplace("filter_mode", filter_mode);
}
@@ -267,4 +272,19 @@ CustomAssetLibrary::LoadInfo TextureAsset::LoadImpl(const CustomAssetLibrary::As
}
return loaded_info;
}
+
+CustomAssetLibrary::LoadInfo
+TextureAndSamplerAsset::LoadImpl(const CustomAssetLibrary::AssetID& asset_id)
+{
+ auto potential_data = std::make_shared<TextureAndSamplerData>();
+ 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);
+ m_loaded = true;
+ m_data = std::move(potential_data);
+ }
+ return loaded_info;
+}
} // namespace VideoCommon