diff options
author | Jacques Lucke <jacques@blender.org> | 2020-07-11 19:02:06 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-07-11 19:02:06 +0300 |
commit | c7eada103c67021052f4c6a2340ca8f744cf17db (patch) | |
tree | a999a3b43574dbad33b58f1a61c283cac1db5824 /source/blender/functions | |
parent | 06401157a69f769388c533979b0558ac599d792e (diff) |
Nodes: support implicit conversions and incorrectly linked sockets
Diffstat (limited to 'source/blender/functions')
-rw-r--r-- | source/blender/functions/FN_multi_function_builder.hh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/source/blender/functions/FN_multi_function_builder.hh b/source/blender/functions/FN_multi_function_builder.hh index 5905d1cc315..6e7efb21850 100644 --- a/source/blender/functions/FN_multi_function_builder.hh +++ b/source/blender/functions/FN_multi_function_builder.hh @@ -203,6 +203,30 @@ template<typename Mut1> class CustomMF_SM : public MultiFunction { }; /** + * Generates a multi-function that converts between two types. + */ +template<typename From, typename To> class CustomMF_Convert : public MultiFunction { + public: + CustomMF_Convert() + { + std::string name = CPPType::get<From>().name() + " to " + CPPType::get<To>().name(); + MFSignatureBuilder signature = this->get_builder(std::move(name)); + signature.single_input<From>("Input"); + signature.single_output<To>("Output"); + } + + void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override + { + VSpan<From> inputs = params.readonly_single_input<From>(0); + MutableSpan<To> outputs = params.uninitialized_single_output<To>(1); + + for (uint i : mask) { + new ((void *)&outputs[i]) To(inputs[i]); + } + } +}; + +/** * A multi-function that outputs the same value every time. The value is not owned by an instance * of this function. The caller is responsible for destructing and freeing the value. */ |