Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/attribute_access.cc
| Show First 20 Lines • Show All 808 Lines • ▼ Show 20 Lines | blender::bke::ReadAttributePtr attribute = std::make_unique<blender::bke::ConstantReadAttribute>( | ||||
| domain, domain_size, *out_cpp_type, out_value); | domain, domain_size, *out_cpp_type, out_value); | ||||
| out_cpp_type->destruct(out_value); | out_cpp_type->destruct(out_value); | ||||
| return attribute; | return attribute; | ||||
| } | } | ||||
| OutputAttributePtr GeometryComponent::attribute_try_get_for_output(const StringRef attribute_name, | OutputAttributePtr GeometryComponent::attribute_try_get_for_output(const StringRef attribute_name, | ||||
| const AttributeDomain domain, | const AttributeDomain domain, | ||||
| const CustomDataType data_type) | const CustomDataType data_type, | ||||
| const void *default_value) | |||||
| { | { | ||||
| BLI_assert(this->attribute_domain_with_type_supported(domain, data_type)); | BLI_assert(this->attribute_domain_with_type_supported(domain, data_type)); | ||||
| const blender::fn::CPPType *cpp_type = blender::bke::custom_data_type_to_cpp_type(data_type); | const blender::fn::CPPType *cpp_type = blender::bke::custom_data_type_to_cpp_type(data_type); | ||||
JacquesLucke: Can use `cpp_type.fill_initialized`. | |||||
| BLI_assert(cpp_type != nullptr); | BLI_assert(cpp_type != nullptr); | ||||
| WriteAttributePtr attribute = this->attribute_try_get_for_write(attribute_name); | WriteAttributePtr attribute = this->attribute_try_get_for_write(attribute_name); | ||||
| /* If the attribute doesn't exist, make a new one with the correct type. */ | /* If the attribute doesn't exist, make a new one with the correct type. */ | ||||
| if (!attribute) { | if (!attribute) { | ||||
| this->attribute_try_create(attribute_name, domain, data_type); | this->attribute_try_create(attribute_name, domain, data_type); | ||||
| attribute = this->attribute_try_get_for_write(attribute_name); | attribute = this->attribute_try_get_for_write(attribute_name); | ||||
| if (default_value != nullptr) { | |||||
| void *data = attribute->get_span_for_write_only().data(); | |||||
| cpp_type->fill_initialized(default_value, data, attribute->size()); | |||||
| attribute->apply_span(); | |||||
| } | |||||
| return OutputAttributePtr(std::move(attribute)); | return OutputAttributePtr(std::move(attribute)); | ||||
| } | } | ||||
| /* If an existing attribute has a matching domain and type, just use that. */ | /* If an existing attribute has a matching domain and type, just use that. */ | ||||
| if (attribute->domain() == domain && attribute->cpp_type() == *cpp_type) { | if (attribute->domain() == domain && attribute->cpp_type() == *cpp_type) { | ||||
| return OutputAttributePtr(std::move(attribute)); | return OutputAttributePtr(std::move(attribute)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 480 Lines • Show Last 20 Lines | |||||
Can use cpp_type.fill_initialized.