[Bf-blender-cvs] [146f6a827ba] functions-experimental-refactor: add utility to destruct and reorder attribute arrays
Jacques Lucke
noreply at git.blender.org
Sun Nov 3 14:30:58 CET 2019
Commit: 146f6a827ba7dfbe21eb5722c56f7ca01a511210
Author: Jacques Lucke
Date: Sun Nov 3 13:08:35 2019 +0100
Branches: functions-experimental-refactor
https://developer.blender.org/rB146f6a827ba7dfbe21eb5722c56f7ca01a511210
add utility to destruct and reorder attribute arrays
===================================================================
M source/blender/functions2/FN_attributes_ref.h
M source/blender/functions2/intern/attributes_ref.cc
===================================================================
diff --git a/source/blender/functions2/FN_attributes_ref.h b/source/blender/functions2/FN_attributes_ref.h
index 1fb6c03ffe9..9889da37f08 100644
--- a/source/blender/functions2/FN_attributes_ref.h
+++ b/source/blender/functions2/FN_attributes_ref.h
@@ -164,11 +164,11 @@ class AttributesRef {
return *m_info;
}
- void *get(uint index) const
+ GenericMutableArrayRef get(uint index) const
{
- void *ptr = m_buffers[index];
- uint size = m_info->type_of(index).size();
- return POINTER_OFFSET(ptr, m_range.start() * size);
+ const CPPType &type = m_info->type_of(index);
+ void *ptr = POINTER_OFFSET(m_buffers[index], type.size() * m_range.start());
+ return GenericMutableArrayRef(m_info->type_of(index), ptr, m_range.size());
}
template<typename T> MutableArrayRef<T> get(uint index) const
@@ -207,6 +207,8 @@ class AttributesRef {
{
return this->slice(0, n);
}
+
+ void destruct_and_reorder(ArrayRef<uint> sorted_indices_to_destruct);
};
class AttributesRefGroup {
diff --git a/source/blender/functions2/intern/attributes_ref.cc b/source/blender/functions2/intern/attributes_ref.cc
index 87182abf857..deedc7b969a 100644
--- a/source/blender/functions2/intern/attributes_ref.cc
+++ b/source/blender/functions2/intern/attributes_ref.cc
@@ -25,6 +25,36 @@ AttributesInfo::AttributesInfo(const AttributesInfoBuilder &builder)
}
}
+void AttributesRef::destruct_and_reorder(ArrayRef<uint> indices)
+{
+#ifdef DEBUG
+ BLI_assert(indices.size() <= m_range.size());
+ BLI_assert(indices.size() == 0 || indices.last() < m_range.size());
+ for (uint i = 1; i < indices.size(); i++) {
+ BLI_assert(indices[i - 1] < indices[i]);
+ }
+#endif
+
+ for (uint attribute_index : m_info->indices()) {
+ GenericMutableArrayRef array = this->get(attribute_index);
+ const CPPType &type = m_info->type_of(attribute_index);
+
+ array.destruct_indices(indices);
+
+ for (uint i = 0; i < indices.size(); i++) {
+ uint last_index = m_range.size() - 1 - i;
+ uint index_to_remove = indices[indices.size() - 1 - i];
+ if (index_to_remove == last_index) {
+ /* Do nothing. It has been destructed before. */
+ }
+ else {
+ /* Relocate last undestructed value. */
+ type.relocate_to_uninitialized(array[last_index], array[index_to_remove]);
+ }
+ }
+ }
+}
+
AttributesRefGroup::AttributesRefGroup(const AttributesInfo &info,
Vector<ArrayRef<void *>> buffers,
Vector<IndexRange> ranges)
More information about the Bf-blender-cvs
mailing list