summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/ShaderAsset.cpp
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2023-10-15 16:49:31 -0500
committeriwubcode <iwubcode@users.noreply.github.com>2023-10-16 19:02:27 -0500
commitfec2a8af8c470f1a196df68c4a55903831edab9d (patch)
tree33c939a7b5d6de280bcd42c3f39f15a5698a44bd /Source/Core/VideoCommon/Assets/ShaderAsset.cpp
parentbbf3fed93c90d3edddfaab1e970a2326fe06ac51 (diff)
VideoCommon: add additional properties to ShaderAsset to support custom shader uniforms
Diffstat (limited to 'Source/Core/VideoCommon/Assets/ShaderAsset.cpp')
-rw-r--r--Source/Core/VideoCommon/Assets/ShaderAsset.cpp47
1 files changed, 31 insertions, 16 deletions
diff --git a/Source/Core/VideoCommon/Assets/ShaderAsset.cpp b/Source/Core/VideoCommon/Assets/ShaderAsset.cpp
index cbb043095c..f71ed65ff7 100644
--- a/Source/Core/VideoCommon/Assets/ShaderAsset.cpp
+++ b/Source/Core/VideoCommon/Assets/ShaderAsset.cpp
@@ -3,6 +3,11 @@
#include "VideoCommon/Assets/ShaderAsset.h"
+#include <algorithm>
+#include <array>
+#include <string_view>
+#include <utility>
+
#include "Common/Logging/Log.h"
#include "VideoCommon/Assets/CustomAssetLibrary.h"
@@ -45,28 +50,38 @@ bool ParseShaderProperties(const VideoCommon::CustomAssetLibrary::AssetID& asset
std::transform(type.begin(), type.end(), type.begin(),
[](unsigned char c) { return std::tolower(c); });
- if (type == "sampler2d")
- {
- property.m_type = ShaderProperty::Type::Type_Sampler2D;
- }
- else if (type == "samplercube")
- {
- property.m_type = ShaderProperty::Type::Type_SamplerCube;
- }
- else if (type == "samplerarrayshared_main")
- {
- property.m_type = ShaderProperty::Type::Type_SamplerArrayShared_Main;
- }
- else if (type == "samplerarrayshared_additional")
+ static constexpr std::array<std::pair<std::string_view, ShaderProperty::Type>,
+ static_cast<int>(ShaderProperty::Type::Type_Max)>
+ pairs = {{
+ {"sampler2d", ShaderProperty::Type::Type_Sampler2D},
+ {"samplercube", ShaderProperty::Type::Type_SamplerCube},
+ {"samplerarrayshared_main", ShaderProperty::Type::Type_SamplerArrayShared_Main},
+ {"samplerarrayshared_additional",
+ ShaderProperty::Type::Type_SamplerArrayShared_Additional},
+ {"int", ShaderProperty::Type::Type_Int},
+ {"int2", ShaderProperty::Type::Type_Int2},
+ {"int3", ShaderProperty::Type::Type_Int3},
+ {"int4", ShaderProperty::Type::Type_Int4},
+ {"float", ShaderProperty::Type::Type_Float},
+ {"float2", ShaderProperty::Type::Type_Float2},
+ {"float3", ShaderProperty::Type::Type_Float3},
+ {"float4", ShaderProperty::Type::Type_Float4},
+ {"rgb", ShaderProperty::Type::Type_RGB},
+ {"rgba", ShaderProperty::Type::Type_RGBA},
+ {"bool", ShaderProperty::Type::Type_Bool},
+ }};
+ if (const auto it = std::find_if(pairs.begin(), pairs.end(),
+ [&](const auto& pair) { return pair.first == type; });
+ it != pairs.end())
{
- property.m_type = ShaderProperty::Type::Type_SamplerArrayShared_Additional;
+ property.m_type = it->second;
}
else
{
ERROR_LOG_FMT(VIDEO,
- "Asset '{}' failed to parse json, property entry 'description' is "
+ "Asset '{}' failed to parse json, property entry type '{}' is "
"an invalid option",
- asset_id);
+ asset_id, type_iter->second.to_str());
return false;
}