diff --git a/zeno/include/zeno/extra/ShaderNode.h b/zeno/include/zeno/extra/ShaderNode.h index 5710b1aa2..b83a032fa 100644 --- a/zeno/include/zeno/extra/ShaderNode.h +++ b/zeno/include/zeno/extra/ShaderNode.h @@ -21,6 +21,9 @@ struct ShaderNode : INode { ZENO_API ShaderNode(); ZENO_API ~ShaderNode() override; }; +using ShaderDataTypeList = std::tuple; + +inline const auto ShaderDataTypeNames = std::array { "bool", "int", "uint", "float", "vec2", "vec3", "vec4" }; static const inline std::map TypeHint { @@ -34,18 +37,14 @@ static const inline std::map TypeHint { {"vec4", 4} }; -static const inline std::map TypeHintReverse { - - {0, "bool"}, - {10, "int"}, - {11, "uint"}, - - {1, "float"}, - {2, "vec2"}, - {3, "vec3"}, - {4, "vec4"} -}; +static const inline std::map TypeHintReverse = []() { + std::map result {}; + for (auto& [k, v] : TypeHint) { + result[v] = k; + } + return result; +} (); template struct ShaderNodeClone : ShaderNode { diff --git a/zeno/src/extra/ShaderNode.cpp b/zeno/src/extra/ShaderNode.cpp index a24e724bb..d3016a2a4 100644 --- a/zeno/src/extra/ShaderNode.cpp +++ b/zeno/src/extra/ShaderNode.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -38,27 +39,21 @@ ZENO_API int EmissionPass::determineType(IObject *object) { int type = std::visit([&] (auto const &value) -> int { using T = std::decay_t; + size_t typeIdx = 0; - if constexpr (std::is_same_v) { - return 0; - } else if constexpr (std::is_same_v) { - return 10; - } else if constexpr (std::is_same_v) { - return 11; - } + zeno::static_for<0, std::tuple_size_v>([&] (auto i) { + using ThisType = std::tuple_element_t; - if constexpr (std::is_same_v) { - return 1; - } else if constexpr (std::is_same_v) { - return 2; - } else if constexpr (std::is_same_v) { - return 3; - } else if constexpr (std::is_same_v) { - return 4; - } else { - throw zeno::Exception("bad numeric object type: " + (std::string)typeid(T).name()); - } + if (std::is_same_v) { + typeIdx = i; + return true; + } + return false; + }); + + return TypeHint.at(ShaderDataTypeNames.at(typeIdx)); }, num->value); + constmap[num] = constants.size(); constants.push_back(ConstInfo{type, num->value}); return type;