summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2023-07-02 21:27:24 -0500
committeriwubcode <iwubcode@users.noreply.github.com>2023-07-09 12:21:34 -0500
commit77511e8e7cc80cc82fa1edf206948f714413aac8 (patch)
tree112ec9a7f52b18023c9178035ea2e27a2653c053 /Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp
parent7bb04ff1dc7c528c794694edcc9802667345a6e3 (diff)
VideoCommon: add material asset. A material is similar to other graphics engines where it provides data to be used in conjunction with a shader asset to generate a runtime AbstractShader
Diffstat (limited to 'Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp')
-rw-r--r--Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp56
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)
{