diff --git a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp index 7933212d3a4..79e09bffa81 100644 --- a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp +++ b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp @@ -298,8 +298,8 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass return {}; } - if (!LoadTextureDataFromFile(asset_id, texture_path->second, - TextureAndSamplerData::Type::Type_Texture2D, data)) + if (!LoadTextureDataFromFile(asset_id, texture_path->second, AbstractTextureType::Texture_2D, + data)) { return {}; } @@ -370,16 +370,16 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass } else { - data->m_sampler = RenderState::GetLinearSamplerState(); - data->m_type = TextureAndSamplerData::Type::Type_Texture2D; + data->sampler = RenderState::GetLinearSamplerState(); + data->type = AbstractTextureType::Texture_2D; } - if (!LoadTextureDataFromFile(asset_id, texture_path->second, data->m_type, &data->m_texture)) + if (!LoadTextureDataFromFile(asset_id, texture_path->second, data->type, &data->texture_data)) return {}; - if (!PurgeInvalidMipsFromTextureData(asset_id, &data->m_texture)) + if (!PurgeInvalidMipsFromTextureData(asset_id, &data->texture_data)) return {}; - return LoadInfo{GetAssetSize(data->m_texture) + metadata_size}; + return LoadInfo{GetAssetSize(data->texture_data) + metadata_size}; } void DirectFilesystemAssetLibrary::SetAssetIDMapData(const AssetID& asset_id, diff --git a/Source/Core/VideoCommon/Assets/TextureAsset.cpp b/Source/Core/VideoCommon/Assets/TextureAsset.cpp index fc6c865f762..7c76426619f 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(); + 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 diff --git a/Source/Core/VideoCommon/Assets/TextureAsset.h b/Source/Core/VideoCommon/Assets/TextureAsset.h index f83d8ad109a..a3c1fa104aa 100644 --- a/Source/Core/VideoCommon/Assets/TextureAsset.h +++ b/Source/Core/VideoCommon/Assets/TextureAsset.h @@ -18,16 +18,9 @@ struct TextureAndSamplerData static bool FromJson(const CustomAssetLibrary::AssetID& asset_id, const picojson::object& json, TextureAndSamplerData* data); static void ToJson(picojson::object* obj, const TextureAndSamplerData& data); - enum class Type - { - Type_Undefined, - Type_Texture2D, - Type_TextureCube, - Type_Max = Type_TextureCube - }; - Type m_type; - CustomTextureData m_texture; - SamplerState m_sampler; + AbstractTextureType type; + CustomTextureData texture_data; + SamplerState sampler; }; class TextureAsset final : public CustomLoadableAsset @@ -38,11 +31,13 @@ public: private: CustomAssetLibrary::LoadInfo LoadImpl(const CustomAssetLibrary::AssetID& asset_id) override; }; -} // namespace VideoCommon -template <> -struct fmt::formatter - : EnumFormatter +class TextureAndSamplerAsset final : public CustomLoadableAsset { - constexpr formatter() : EnumFormatter({"Undefined", "Texture2D", "TextureCube"}) {} +public: + using CustomLoadableAsset::CustomLoadableAsset; + +private: + CustomAssetLibrary::LoadInfo LoadImpl(const CustomAssetLibrary::AssetID& asset_id) override; }; +} // namespace VideoCommon diff --git a/Source/Core/VideoCommon/Assets/TextureAssetUtils.cpp b/Source/Core/VideoCommon/Assets/TextureAssetUtils.cpp index 5285c61bba3..4d2316081e5 100644 --- a/Source/Core/VideoCommon/Assets/TextureAssetUtils.cpp +++ b/Source/Core/VideoCommon/Assets/TextureAssetUtils.cpp @@ -66,8 +66,8 @@ bool LoadMips(const std::filesystem::path& asset_path, CustomTextureData::ArrayS } } // namespace bool LoadTextureDataFromFile(const CustomAssetLibrary::AssetID& asset_id, - const std::filesystem::path& asset_path, - TextureAndSamplerData::Type type, CustomTextureData* data) + const std::filesystem::path& asset_path, AbstractTextureType type, + CustomTextureData* data) { auto ext = PathToString(asset_path.extension()); Common::ToLower(&ext); @@ -92,7 +92,7 @@ bool LoadTextureDataFromFile(const CustomAssetLibrary::AssetID& asset_id, { // PNG could support more complicated texture types in the future // but for now just error - if (type != TextureAndSamplerData::Type::Type_Texture2D) + if (type != AbstractTextureType::Texture_2D) { ERROR_LOG_FMT(VIDEO, "Asset '{}' error - PNG is not supported for texture type '{}'!", asset_id, type); diff --git a/Source/Core/VideoCommon/Assets/TextureAssetUtils.h b/Source/Core/VideoCommon/Assets/TextureAssetUtils.h index ef7bc007518..8cf30547c2f 100644 --- a/Source/Core/VideoCommon/Assets/TextureAssetUtils.h +++ b/Source/Core/VideoCommon/Assets/TextureAssetUtils.h @@ -7,12 +7,13 @@ #include "VideoCommon/Assets/CustomAssetLibrary.h" #include "VideoCommon/Assets/TextureAsset.h" +#include "VideoCommon/TextureConfig.h" namespace VideoCommon { bool LoadTextureDataFromFile(const CustomAssetLibrary::AssetID& asset_id, - const std::filesystem::path& asset_path, - TextureAndSamplerData::Type type, CustomTextureData* data); + const std::filesystem::path& asset_path, AbstractTextureType type, + CustomTextureData* data); bool ValidateTextureData(const CustomAssetLibrary::AssetID& asset_id, const CustomTextureData& data, u32 native_width, u32 native_height);