VideoCommon: add a method to calculate a default value for ShaderAsset and another to list its types

This commit is contained in:
iwubcode 2024-01-23 01:07:42 -06:00
parent b5a6225e1a
commit a40a952177
2 changed files with 74 additions and 0 deletions

View File

@ -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>();

View File

@ -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;