From 9abf213004850c50d866b074b74d71ed06b3771d Mon Sep 17 00:00:00 2001 From: iwubcode Date: Wed, 26 Feb 2025 00:38:22 -0600 Subject: [PATCH] material asset changes for render targets --- .../Core/VideoCommon/Assets/MaterialAsset.cpp | 39 ++++++++++++++++++- .../Core/VideoCommon/Assets/MaterialAsset.h | 5 ++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/Assets/MaterialAsset.cpp b/Source/Core/VideoCommon/Assets/MaterialAsset.cpp index 67c126d474..58ac49942c 100644 --- a/Source/Core/VideoCommon/Assets/MaterialAsset.cpp +++ b/Source/Core/VideoCommon/Assets/MaterialAsset.cpp @@ -708,10 +708,40 @@ bool RasterMaterialData::FromJson(const CustomAssetLibrary::AssetID& asset_id, auto& pixel_texture_json_obj = pixel_texture_json.get(); TextureSamplerValue sampler_value; - TextureSamplerValue::FromJson(pixel_texture_json_obj, &sampler_value); + if (!TextureSamplerValue::FromJson(pixel_texture_json_obj, &sampler_value)) + return false; data->pixel_textures.push_back(std::move(sampler_value)); } + const auto render_targets_iter = json.find("render_targets"); + if (render_targets_iter == json.end()) + { + ERROR_LOG_FMT(VIDEO, "Asset '{}' failed to parse json, 'render_targets' not found", asset_id); + return false; + } + if (!render_targets_iter->second.is()) + { + ERROR_LOG_FMT(VIDEO, + "Asset '{}' failed to parse json, 'render_targets' is not the right json type", + asset_id); + return false; + } + const auto& render_targets_array = render_targets_iter->second.get(); + if (!std::ranges::all_of(render_targets_array, [](const picojson::value& json_data) { + return json_data.is(); + })) + { + ERROR_LOG_FMT(VIDEO, "Asset '{}' failed to parse json, 'render_targets' must contain strings", + asset_id); + return false; + } + + for (const auto& render_target_json : render_targets_array) + { + std::string render_target_str = render_target_json.to_str(); + data->render_targets.push_back(std::move(render_target_str)); + } + return true; } @@ -838,6 +868,13 @@ void RasterMaterialData::ToJson(picojson::object* obj, const RasterMaterialData& json_textures.emplace_back(std::move(json_texture)); } json_obj.emplace("pixel_textures", json_textures); + + picojson::array json_render_targets; + for (const auto& render_target : data.render_targets) + { + json_render_targets.emplace_back(render_target); + } + json_obj.emplace("render_targets", json_render_targets); } CustomAssetLibrary::LoadInfo MaterialAsset::LoadImpl(const CustomAssetLibrary::AssetID& asset_id) diff --git a/Source/Core/VideoCommon/Assets/MaterialAsset.h b/Source/Core/VideoCommon/Assets/MaterialAsset.h index de8d7c622f..0c292d0fba 100644 --- a/Source/Core/VideoCommon/Assets/MaterialAsset.h +++ b/Source/Core/VideoCommon/Assets/MaterialAsset.h @@ -71,8 +71,8 @@ struct RasterMaterialData static bool FromJson(const CustomAssetLibrary::AssetID& asset_id, const picojson::object& json, RasterMaterialData* data); static void ToJson(picojson::object* obj, const RasterMaterialData& data); - std::string shader_asset; - std::string next_material_asset; + CustomAssetLibrary::AssetID shader_asset; + CustomAssetLibrary::AssetID next_material_asset; std::vector vertex_properties; std::vector pixel_properties; @@ -81,6 +81,7 @@ struct RasterMaterialData std::optional blending_state; std::vector pixel_textures; + std::vector render_targets; }; class RasterMaterialAsset final : public CustomLoadableAsset