diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-05-18 22:39:56 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-05-19 00:01:08 +0300 |
commit | 80811c5638ac5ccb425eaea2886273c4a3121aea (patch) | |
tree | b3b70b1b427fccb6216e4f860a86b5bbeffff7e5 /source/blender | |
parent | 790598fa609accde463bbda9c990dd55f881940c (diff) |
DRW: Replace StorageFlexibleBuffer with explicit `get_or_resize()`
This is to avoid hiding resize inside the `[]` operator.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/intern/DRW_gpu_wrapper.hh | 46 |
1 files changed, 11 insertions, 35 deletions
diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh index 366dd40c220..361ea743bb6 100644 --- a/source/blender/draw/intern/DRW_gpu_wrapper.hh +++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh @@ -31,9 +31,6 @@ * discarding all data inside it. * Data can be accessed using the [] operator. * - * `draw::StorageFlexibleBuffer<T>` - * Same as StorageArrayBuffer but will auto resize on access when using the [] operator. - * * `draw::StorageBuffer<T>` * A storage buffer object class inheriting from T. * Data can be accessed just like a normal T object. @@ -237,6 +234,17 @@ class StorageCommon : public DataBuffer<T, len, false>, NonMovable, NonCopyable } } + /* Resize on access. */ + T &get_or_resize(int64_t index) + { + BLI_assert(index >= 0); + if (index >= this->len_) { + size_t size = 1u << log2_ceil_u(index); + this->resize(size); + } + return this->data_[index]; + } + void push_update(void) { BLI_assert(device_only == false); @@ -343,38 +351,6 @@ template< typename T, /** True if created on device and no memory host memory is allocated. */ bool device_only = false> -class StorageFlexibleBuffer : public detail::StorageCommon<T, 1, device_only> { - public: - StorageFlexibleBuffer(const char *name = nullptr) - : detail::StorageCommon<T, 1, device_only>(name) - { - /* TODO(@fclem): We should map memory instead. */ - this->data_ = (T *)MEM_mallocN_aligned(sizeof(T), 16, this->name_); - } - ~StorageFlexibleBuffer() - { - MEM_freeN(this->data_); - } - - /* Resize on access. */ - T &operator[](int64_t index) - { - BLI_STATIC_ASSERT(!device_only, ""); - BLI_assert(index >= 0); - if (index >= this->len_) { - this->resize(this->len_ * 2); - } - return this->data_[index]; - } - - /* TODO(fclem): Implement shrinking. */ -}; - -template< - /** Type of the values stored in this uniform buffer. */ - typename T, - /** True if created on device and no memory host memory is allocated. */ - bool device_only = false> class StorageBuffer : public T, public detail::StorageCommon<T, 1, device_only> { public: StorageBuffer(const char *name = nullptr) : detail::StorageCommon<T, 1, device_only>(name) |