Commit: 3cbe9218994aec59e417a595b9a1f7256108e693 Author: Hans Goudey Date: Mon Oct 18 10:08:57 2021 -0500 Branches: master https://developer.blender.org/rB3cbe9218994aec59e417a595b9a1f7256108e693
Cleanup: Use simpler method to create attribute lookups Instead of switch statements, make use of generic virtual arrays so the code is shorter and easier to read. Differential Revision: https://developer.blender.org/D12908 =================================================================== M source/blender/blenkernel/intern/attribute_access.cc M source/blender/blenkernel/intern/attribute_access_intern.hh =================================================================== diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index d686cd8fa55..289c458c1e4 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -51,6 +51,7 @@ using blender::bke::OutputAttribute; using blender::fn::GMutableSpan; using blender::fn::GSpan; using blender::fn::GVArray_For_GSpan; +using blender::fn::GVMutableArray_For_GMutableSpan; using blender::fn::GVArray_For_SingleValue; namespace blender::bke { @@ -388,23 +389,12 @@ ReadAttributeLookup CustomDataAttributeProvider::try_get_for_read( if (!custom_data_layer_matches_attribute_id(layer, attribute_id)) { continue; } - const CustomDataType data_type = (CustomDataType)layer.type; - switch (data_type) { - case CD_PROP_FLOAT: - return this->layer_to_read_attribute<float>(layer, domain_size); - case CD_PROP_FLOAT2: - return this->layer_to_read_attribute<float2>(layer, domain_size); - case CD_PROP_FLOAT3: - return this->layer_to_read_attribute<float3>(layer, domain_size); - case CD_PROP_INT32: - return this->layer_to_read_attribute<int>(layer, domain_size); - case CD_PROP_COLOR: - return this->layer_to_read_attribute<ColorGeometry4f>(layer, domain_size); - case CD_PROP_BOOL: - return this->layer_to_read_attribute<bool>(layer, domain_size); - default: - break; + const CPPType *type = custom_data_type_to_cpp_type((CustomDataType)layer.type); + if (type == nullptr) { + continue; } + GSpan data{*type, layer.data, domain_size}; + return {std::make_unique<GVArray_For_GSpan>(data), domain_}; } return {}; } @@ -429,23 +419,12 @@ WriteAttributeLookup CustomDataAttributeProvider::try_get_for_write( CustomData_duplicate_referenced_layer_anonymous( custom_data, layer.type, &attribute_id.anonymous_id(), domain_size); } - const CustomDataType data_type = (CustomDataType)layer.type; - switch (data_type) { - case CD_PROP_FLOAT: - return this->layer_to_write_attribute<float>(layer, domain_size); - case CD_PROP_FLOAT2: - return this->layer_to_write_attribute<float2>(layer, domain_size); - case CD_PROP_FLOAT3: - return this->layer_to_write_attribute<float3>(layer, domain_size); - case CD_PROP_INT32: - return this->layer_to_write_attribute<int>(layer, domain_size); - case CD_PROP_COLOR: - return this->layer_to_write_attribute<ColorGeometry4f>(layer, domain_size); - case CD_PROP_BOOL: - return this->layer_to_write_attribute<bool>(layer, domain_size); - default: - break; + const CPPType *type = custom_data_type_to_cpp_type((CustomDataType)layer.type); + if (type == nullptr) { + continue; } + GMutableSpan data{*type, layer.data, domain_size}; + return {std::make_unique<GVMutableArray_For_GMutableSpan>(data), domain_}; } return {}; } diff --git a/source/blender/blenkernel/intern/attribute_access_intern.hh b/source/blender/blenkernel/intern/attribute_access_intern.hh index 261cb26d4e5..6e5cdd6faba 100644 --- a/source/blender/blenkernel/intern/attribute_access_intern.hh +++ b/source/blender/blenkernel/intern/attribute_access_intern.hh @@ -177,24 +177,6 @@ class CustomDataAttributeProvider final : public DynamicAttributesProvider { } private: - template<typename T> - ReadAttributeLookup layer_to_read_attribute(const CustomDataLayer &layer, - const int domain_size) const - { - return {std::make_unique<fn::GVArray_For_Span<T>>( - Span(static_cast<const T *>(layer.data), domain_size)), - domain_}; - } - - template<typename T> - WriteAttributeLookup layer_to_write_attribute(CustomDataLayer &layer, - const int domain_size) const - { - return {std::make_unique<fn::GVMutableArray_For_MutableSpan<T>>( - MutableSpan(static_cast<T *>(layer.data), domain_size)), - domain_}; - } - bool type_is_supported(CustomDataType data_type) const { return ((1ULL << data_type) & supported_types_mask) != 0; _______________________________________________ Bf-blender-cvs mailing list [email protected] List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs
