diff options
| author | Admiral H. Curtiss <pikachu025@gmail.com> | 2023-07-09 21:49:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-09 21:49:16 +0200 |
| commit | fe8a9ac70796498e8bc5b29770e9334ed187c35d (patch) | |
| tree | d70210185ba889c5f45b055b29b351fa4b7c6d1a /Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp | |
| parent | bd90f6be78ffa40c07542c43b74a17f0951f10eb (diff) | |
| parent | 77511e8e7cc80cc82fa1edf206948f714413aac8 (diff) | |
Merge pull request #12024 from iwubcode/material_asset
VideoCommon: add material asset
Diffstat (limited to 'Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp index c234b4088e..cc21549e54 100644 --- a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp +++ b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp @@ -10,6 +10,7 @@ #include "Common/Logging/Log.h" #include "Common/StringUtil.h" #include "VideoCommon/Assets/CustomTextureData.h" +#include "VideoCommon/Assets/MaterialAsset.h" #include "VideoCommon/Assets/ShaderAsset.h" namespace VideoCommon @@ -144,6 +145,61 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadPixelShader(const return LoadInfo{approx_mem_size, GetLastAssetWriteTime(asset_id)}; } +CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const AssetID& asset_id, + MaterialData* data) +{ + const auto asset_map = GetAssetMapForID(asset_id); + + // Material is expected to have one asset mapped + if (asset_map.empty() || asset_map.size() > 1) + { + ERROR_LOG_FMT(VIDEO, "Asset '{}' error - material expected to have one file mapped!", asset_id); + return {}; + } + const auto& asset_path = asset_map.begin()->second; + + std::string json_data; + if (!File::ReadFileToString(asset_path.string(), json_data)) + { + ERROR_LOG_FMT(VIDEO, "Asset '{}' error - material failed to load the json file '{}',", + asset_id, asset_path.string()); + return {}; + } + + picojson::value root; + const auto error = picojson::parse(root, json_data); + + if (!error.empty()) + { + ERROR_LOG_FMT( + VIDEO, + "Asset '{}' error - material failed to load the json file '{}', due to parse error: {}", + asset_id, asset_path.string(), error); + return {}; + } + if (!root.is<picojson::object>()) + { + ERROR_LOG_FMT(VIDEO, + "Asset '{}' error - material failed to load the json file '{}', due to root not " + "being an object!", + asset_id, asset_path.string()); + return {}; + } + + const auto& root_obj = root.get<picojson::object>(); + + if (!MaterialData::FromJson(asset_id, root_obj, data)) + { + ERROR_LOG_FMT(VIDEO, + "Asset '{}' error - material failed to load the json file '{}', as material " + "json could not be parsed!", + asset_id, asset_path.string()); + return {}; + } + + return LoadInfo{json_data.size(), GetLastAssetWriteTime(asset_id)}; +} + CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const AssetID& asset_id, CustomTextureData* data) { |
