summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2024-01-23 01:07:42 -0600
committeriwubcode <iwubcode@users.noreply.github.com>2024-01-23 11:58:32 -0600
commita40a952177faae7add798980ff83aebc0a94db8a (patch)
tree7eaf9416926f3df1464bb82105cfe51323d03af2
parentb5a6225e1ae4cbd50a9234a0ed85d9e78bdcfd20 (diff)
VideoCommon: add a method to calculate a default value for ShaderAsset and another to list its types
-rw-r--r--Source/Core/VideoCommon/Assets/ShaderAsset.cpp70
-rw-r--r--Source/Core/VideoCommon/Assets/ShaderAsset.h4
2 files changed, 74 insertions, 0 deletions
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<const std::string_view> ShaderProperty::GetValueTypeNames()
+{
+ static constexpr std::array<std::string_view, 14> 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<s32, 2>{};
+ }
+ else if (name == "int3")
+ {
+ return std::array<s32, 3>{};
+ }
+ else if (name == "int4")
+ {
+ return std::array<s32, 4>{};
+ }
+ else if (name == "float")
+ {
+ return 0.0f;
+ }
+ else if (name == "float2")
+ {
+ return std::array<float, 2>{};
+ }
+ else if (name == "float3")
+ {
+ return std::array<float, 3>{};
+ }
+ else if (name == "float4")
+ {
+ return std::array<float, 4>{};
+ }
+ 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<PixelShaderData>();
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 <array>
#include <map>
+#include <span>
#include <string>
+#include <string_view>
#include <variant>
#include <picojson.h>
@@ -44,6 +46,8 @@ struct ShaderProperty
using Value = std::variant<s32, std::array<s32, 2>, std::array<s32, 3>, std::array<s32, 4>, float,
std::array<float, 2>, std::array<float, 3>, std::array<float, 4>, bool,
RGB, RGBA, Sampler2D, Sampler2DArray, SamplerCube>;
+ static std::span<const std::string_view> GetValueTypeNames();
+ static Value GetDefaultValueFromTypeName(std::string_view name);
Value m_default;
std::string m_description;