[Bf-blender-cvs] [06ddde0daa1] functions: new way to construct custom functions at compile time
Jacques Lucke
noreply at git.blender.org
Wed Jan 29 21:05:29 CET 2020
Commit: 06ddde0daa164d57556bac219cf74d3e1a02d361
Author: Jacques Lucke
Date: Wed Jan 29 18:43:52 2020 +0100
Branches: functions
https://developer.blender.org/rB06ddde0daa164d57556bac219cf74d3e1a02d361
new way to construct custom functions at compile time
===================================================================
M source/blender/functions/intern/multi_functions/customizable.h
===================================================================
diff --git a/source/blender/functions/intern/multi_functions/customizable.h b/source/blender/functions/intern/multi_functions/customizable.h
index 594197a9593..d0d9d0d09dd 100644
--- a/source/blender/functions/intern/multi_functions/customizable.h
+++ b/source/blender/functions/intern/multi_functions/customizable.h
@@ -47,6 +47,31 @@ template<typename InT, typename OutT> class MF_Custom_In1_Out1 final : public Mu
signature.operation_hash(operation_hash);
}
+ template<typename ElementFuncT>
+ MF_Custom_In1_Out1(StringRef name,
+ ElementFuncT element_fn,
+ Optional<uint32_t> operation_hash = {})
+ : MF_Custom_In1_Out1(name, MF_Custom_In1_Out1::create_function(element_fn), operation_hash)
+ {
+ }
+
+ template<typename ElementFuncT> static FunctionT create_function(ElementFuncT element_fn)
+ {
+ return [=](IndexMask mask, VirtualListRef<InT> inputs, MutableArrayRef<OutT> outputs) {
+ if (inputs.is_non_single_full_array()) {
+ ArrayRef<InT> in_array = inputs.as_full_array();
+ mask.foreach_index([=](uint i) { outputs[i] = element_fn(in_array[i]); });
+ }
+ else if (inputs.is_single_element()) {
+ InT in_single = inputs.as_single_element();
+ outputs.fill_indices(mask.indices(), element_fn(in_single));
+ }
+ else {
+ mask.foreach_index([=](uint i) { outputs[i] = element_fn(inputs[i]); });
+ }
+ };
+ }
+
void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
{
VirtualListRef<InT> inputs = params.readonly_single_input<InT>(0);
More information about the Bf-blender-cvs
mailing list