diff options
author | Jacques Lucke <jacques@blender.org> | 2021-01-12 14:49:34 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-01-12 14:50:29 +0300 |
commit | 3a254b93fd8597c47fc4fe55fa0417d1f9fa85fc (patch) | |
tree | 00fe1e373f828b23a3242b80c37b65146a2dd1c3 /source/blender/blenkernel/BKE_attribute_access.hh | |
parent | 58dae919e51547a8fe7e676e317de3ee17b49e64 (diff) |
Geometry Nodes: support reading from spans of WriteAttribute
Previously, the span returned by `WriteAttribute`s might not contain the
current value of the attribute for performance reasons. To avoid some
bugs, the span now always contains the old values (they might have to
be copied over from the internal storage, dependending on how the
attribute is stored).
The old behavior is still available with the `get_span_for_write_only`
method. The span that it returns might not contain the current
attribute values. Therefore, it should only be used when you want
to overwrite an attribute without looking at the old values.
Diffstat (limited to 'source/blender/blenkernel/BKE_attribute_access.hh')
-rw-r--r-- | source/blender/blenkernel/BKE_attribute_access.hh | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh index 22e14e44bec..131656136f1 100644 --- a/source/blender/blenkernel/BKE_attribute_access.hh +++ b/source/blender/blenkernel/BKE_attribute_access.hh @@ -169,8 +169,10 @@ class WriteAttribute { } /* Get a span that new attribute values can be written into. When all values have been changed, - * #apply_span has to be called. The span might not contain the original attribute values. */ + * #apply_span has to be called. */ fn::GMutableSpan get_span(); + /* The span returned by this method might not contain the current attribute values. */ + fn::GMutableSpan get_span_for_write_only(); /* Write the changes to the span into the actual attribute, if they aren't already. */ void apply_span(); @@ -178,7 +180,7 @@ class WriteAttribute { virtual void get_internal(const int64_t index, void *r_value) const = 0; virtual void set_internal(const int64_t index, const void *value) = 0; - virtual void initialize_span(); + virtual void initialize_span(const bool write_only); virtual void apply_span_if_necessary(); }; @@ -250,12 +252,16 @@ template<typename T> class TypedWriteAttribute { } /* Get a span that new values can be written into. Once all values have been updated #apply_span - * has to be called. The span might *not* contain the initial attribute values, so one should - * generally only write to the span. */ + * has to be called. */ MutableSpan<T> get_span() { return attribute_->get_span().typed<T>(); } + /* The span returned by this method might not contain the current attribute values. */ + MutableSpan<T> get_span_for_write_only() + { + return attribute_->get_span_for_write_only().typed<T>(); + } /* Write back all changes to the actual attribute, if necessary. */ void apply_span() |