From a40a952177faae7add798980ff83aebc0a94db8a Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 23 Jan 2024 01:07:42 -0600 Subject: [PATCH] VideoCommon: add a method to calculate a default value for ShaderAsset and another to list its types --- .../Core/VideoCommon/Assets/ShaderAsset.cpp | 70 +++++++++++++++++++ Source/Core/VideoCommon/Assets/ShaderAsset.h | 4 ++ 2 files changed, 74 insertions(+) diff --git a/Source/Core/VideoCommon/Assets/ShaderAsset.cpp b/Source/Core/VideoCommon/Assets/ShaderAsset.cpp index b45310dab9..67622f20a7 100644 --- a/Source/Core/VideoCommon/Assets/ShaderAsset.cpp +++ b/Source/Core/VideoCommon/Assets/ShaderAsset.cpp @@ -366,6 +366,76 @@ void PixelShaderData::ToJson(picojson::object& obj, const PixelShaderData& data) obj["properties"] = picojson::value{json_properties}; } +std::span ShaderProperty::GetValueTypeNames() +{ + static constexpr std::array values = { + "sampler2d", "sampler2darray", "samplercube", "int", "int2", "int3", "int4", + "float", "float2", "float3", "float4", "rgb", "rgba", "bool"}; + return values; +} + +ShaderProperty::Value ShaderProperty::GetDefaultValueFromTypeName(std::string_view name) +{ + if (name == "sampler2d") + { + return Sampler2D{}; + } + else if (name == "sampler2darray") + { + return Sampler2DArray{}; + } + else if (name == "samplercube") + { + return SamplerCube{}; + } + else if (name == "int") + { + return 0; + } + else if (name == "int2") + { + return std::array{}; + } + else if (name == "int3") + { + return std::array{}; + } + else if (name == "int4") + { + return std::array{}; + } + else if (name == "float") + { + return 0.0f; + } + else if (name == "float2") + { + return std::array{}; + } + else if (name == "float3") + { + return std::array{}; + } + else if (name == "float4") + { + return std::array{}; + } + else if (name == "rgb") + { + return RGB{}; + } + else if (name == "rgba") + { + return RGBA{}; + } + else if (name == "bool") + { + return false; + } + + return Value{}; +} + CustomAssetLibrary::LoadInfo PixelShaderAsset::LoadImpl(const CustomAssetLibrary::AssetID& asset_id) { auto potential_data = std::make_shared(); diff --git a/Source/Core/VideoCommon/Assets/ShaderAsset.h b/Source/Core/VideoCommon/Assets/ShaderAsset.h index 8947cf8f5a..6a9c100d44 100644 --- a/Source/Core/VideoCommon/Assets/ShaderAsset.h +++ b/Source/Core/VideoCommon/Assets/ShaderAsset.h @@ -5,7 +5,9 @@ #include #include +#include #include +#include #include #include @@ -44,6 +46,8 @@ struct ShaderProperty using Value = std::variant, std::array, std::array, float, std::array, std::array, std::array, bool, RGB, RGBA, Sampler2D, Sampler2DArray, SamplerCube>; + static std::span GetValueTypeNames(); + static Value GetDefaultValueFromTypeName(std::string_view name); Value m_default; std::string m_description;