Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2020-07-15 15:18:30 +0300
committerClément Foucault <foucault.clem@gmail.com>2020-07-15 15:23:35 +0300
commite8f8c13d4b76ba587ef7cf33370b286d4fbd36bc (patch)
tree371472ae220ad8740b310aaa8f4c5746448302c5 /source/blender/blenlib/BLI_array.hh
parent0c062a9e082130212447c2b67e8e16b8a2e622d1 (diff)
parent44bb73e765a6f79bc14a46449368f83e572d8bad (diff)
PointCloud: Initial rendering support for Workbenchtmp-pointcloud-render
Also includes outline overlays. Removes the temp overlay drawing We make the geometry follow camera like billboards this uses less geometry. Currently we use half octahedron for now. Goal would be to use icospheres. This patch also optimize the case when pointcloud has uniform radius. However we should premultiply the radius prop by the default radius beforehand to avoid a multiplication on CPU. Differential Revision: https://developer.blender.org/D8301
Diffstat (limited to 'source/blender/blenlib/BLI_array.hh')
-rw-r--r--source/blender/blenlib/BLI_array.hh43
1 files changed, 26 insertions, 17 deletions
diff --git a/source/blender/blenlib/BLI_array.hh b/source/blender/blenlib/BLI_array.hh
index ee4e9702779..c411fc50f15 100644
--- a/source/blender/blenlib/BLI_array.hh
+++ b/source/blender/blenlib/BLI_array.hh
@@ -74,7 +74,7 @@ class Array {
Allocator allocator_;
/** A placeholder buffer that will remain uninitialized until it is used. */
- AlignedBuffer<sizeof(T) * InlineBufferCapacity, alignof(T)> inline_buffer_;
+ TypedBuffer<T, InlineBufferCapacity> inline_buffer_;
public:
/**
@@ -82,23 +82,29 @@ class Array {
*/
Array()
{
- data_ = this->inline_buffer();
+ data_ = inline_buffer_;
size_ = 0;
}
/**
* Create a new array that contains copies of all values.
*/
- Array(Span<T> values)
+ template<typename U, typename std::enable_if_t<std::is_convertible_v<U, T>> * = nullptr>
+ Array(Span<U> values, Allocator allocator = {}) : allocator_(allocator)
{
size_ = values.size();
data_ = this->get_buffer_for_size(values.size());
- uninitialized_copy_n(values.data(), size_, data_);
+ uninitialized_convert_n<U, T>(values.data(), size_, data_);
}
/**
* Create a new array that contains copies of all values.
*/
+ template<typename U, typename std::enable_if_t<std::is_convertible_v<U, T>> * = nullptr>
+ Array(const std::initializer_list<U> &values) : Array(Span<U>(values))
+ {
+ }
+
Array(const std::initializer_list<T> &values) : Array(Span<T>(values))
{
}
@@ -147,12 +153,8 @@ class Array {
data_ = this->get_buffer_for_size(size);
}
- Array(const Array &other) : allocator_(other.allocator_)
+ Array(const Array &other) : Array(other.as_span(), other.allocator_)
{
- size_ = other.size();
-
- data_ = this->get_buffer_for_size(other.size());
- uninitialized_copy_n(other.data(), size_, data_);
}
Array(Array &&other) noexcept : allocator_(other.allocator_)
@@ -167,7 +169,7 @@ class Array {
uninitialized_relocate_n(other.data_, size_, data_);
}
- other.data_ = other.inline_buffer();
+ other.data_ = other.inline_buffer_;
other.size_ = 0;
}
@@ -223,6 +225,18 @@ class Array {
return MutableSpan<T>(data_, size_);
}
+ template<typename U, typename std::enable_if_t<is_convertible_pointer_v<T, U>> * = nullptr>
+ operator Span<U>() const
+ {
+ return Span<U>(data_, size_);
+ }
+
+ template<typename U, typename std::enable_if_t<is_convertible_pointer_v<T, U>> * = nullptr>
+ operator MutableSpan<U>()
+ {
+ return MutableSpan<U>(data_, size_);
+ }
+
Span<T> as_span() const
{
return *this;
@@ -335,18 +349,13 @@ class Array {
T *get_buffer_for_size(uint size)
{
if (size <= InlineBufferCapacity) {
- return this->inline_buffer();
+ return inline_buffer_;
}
else {
return this->allocate(size);
}
}
- T *inline_buffer() const
- {
- return (T *)inline_buffer_.ptr();
- }
-
T *allocate(uint size)
{
return (T *)allocator_.allocate(size * sizeof(T), alignof(T), AT);
@@ -354,7 +363,7 @@ class Array {
bool uses_inline_buffer() const
{
- return data_ == this->inline_buffer();
+ return data_ == inline_buffer_;
}
};