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>2022-01-27 20:46:01 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-01-27 20:46:01 +0300
commita21f1e81e07f4664d78a177bd41c2a769c42a473 (patch)
tree26cdf5eb7bfd446baadeea03ae959db2f0b251d4
parent87c13ac68c477486adecd8d548a016309fc2b54d (diff)
DRW: Fix some issues with DRW_gpu_wrapper.hh
- Fix assert on size. - Fix void * casting. - Pass extent by values. - Add swap function to avoid letting the types copyable. - Add back the GPUTexture * operator on TextureFromPool.
-rw-r--r--source/blender/draw/intern/DRW_gpu_wrapper.hh43
1 files changed, 27 insertions, 16 deletions
diff --git a/source/blender/draw/intern/DRW_gpu_wrapper.hh b/source/blender/draw/intern/DRW_gpu_wrapper.hh
index a0656ce5ab2..af262272577 100644
--- a/source/blender/draw/intern/DRW_gpu_wrapper.hh
+++ b/source/blender/draw/intern/DRW_gpu_wrapper.hh
@@ -102,7 +102,8 @@ class DataBuffer {
T *data_ = nullptr;
int64_t len_ = len;
- BLI_STATIC_ASSERT((sizeof(T) % 16) == 0, "Type need to be aligned to size of float4.");
+ BLI_STATIC_ASSERT(((sizeof(T) * len) % 16) == 0,
+ "Buffer size need to be aligned to size of float4.");
public:
/**
@@ -292,7 +293,7 @@ class UniformArrayBuffer : public detail::UniformCommon<T, len, false> {
UniformArrayBuffer()
{
/* TODO(fclem) We should map memory instead. */
- this->data_ = MEM_mallocN_aligned(this->name_);
+ this->data_ = (T *)MEM_mallocN_aligned(len * sizeof(T), 16, this->name_);
}
};
@@ -481,7 +482,7 @@ class Texture : NonCopyable {
* Ensure the texture has the correct properties. Recreating it if needed.
* Return true if a texture has been created.
*/
- bool ensure_2d(eGPUTextureFormat format, const int2 &extent, float *data = nullptr, int mips = 1)
+ bool ensure_2d(eGPUTextureFormat format, int2 extent, float *data = nullptr, int mips = 1)
{
return ensure_impl(UNPACK2(extent), 0, mips, format, data, false, false);
}
@@ -490,11 +491,8 @@ class Texture : NonCopyable {
* Ensure the texture has the correct properties. Recreating it if needed.
* Return true if a texture has been created.
*/
- bool ensure_2d_array(eGPUTextureFormat format,
- const int2 &extent,
- int layers,
- float *data = nullptr,
- int mips = 1)
+ bool ensure_2d_array(
+ eGPUTextureFormat format, int2 extent, int layers, float *data = nullptr, int mips = 1)
{
return ensure_impl(UNPACK2(extent), layers, mips, format, data, true, false);
}
@@ -503,7 +501,7 @@ class Texture : NonCopyable {
* Ensure the texture has the correct properties. Recreating it if needed.
* Return true if a texture has been created.
*/
- bool ensure_3d(eGPUTextureFormat format, const int3 &extent, float *data = nullptr, int mips = 1)
+ bool ensure_3d(eGPUTextureFormat format, int3 extent, float *data = nullptr, int mips = 1)
{
return ensure_impl(UNPACK3(extent), mips, format, data, false, false);
}
@@ -623,6 +621,15 @@ class Texture : NonCopyable {
GPU_TEXTURE_FREE_SAFE(tx_);
}
+ /**
+ * Swap the content of the two textures.
+ */
+ static void swap(Texture &a, Texture &b)
+ {
+ SWAP(GPUTexture *, a.tx_, b.tx_);
+ SWAP(const char *, a.name_, b.name_);
+ }
+
private:
bool ensure_impl(int w,
int h = 0,
@@ -702,7 +709,7 @@ class TextureFromPool : public Texture, NonMovable {
TextureFromPool(const char *name = "gpu::Texture") : Texture(name){};
/* Always use `release()` after rendering. */
- void acquire(int w, int h, eGPUTextureFormat format, void *owner_)
+ void acquire(int2 extent, eGPUTextureFormat format, void *owner_)
{
if (this->tx_ == nullptr) {
if (tx_tmp_saved_ != nullptr) {
@@ -710,7 +717,7 @@ class TextureFromPool : public Texture, NonMovable {
return;
}
DrawEngineType *owner = (DrawEngineType *)owner_;
- this->tx_ = DRW_texture_pool_query_2d(w, h, format, owner);
+ this->tx_ = DRW_texture_pool_query_2d(UNPACK2(extent), format, owner);
}
}
@@ -739,11 +746,6 @@ class TextureFromPool : public Texture, NonMovable {
bool ensure_cube_array(int, int, int, eGPUTextureFormat, float *) = delete;
void filter_mode(bool) = delete;
void free() = delete;
- /**
- * Forbid the use of DRW_shgroup_uniform_texture.
- * Use DRW_shgroup_uniform_texture_ref instead.
- */
- operator GPUTexture *() const = delete;
};
/** \} */
@@ -794,6 +796,15 @@ class Framebuffer : NonCopyable {
{
return fb_;
}
+
+ /**
+ * Swap the content of the two framebuffer.
+ */
+ static void swap(Framebuffer &a, Framebuffer &b)
+ {
+ SWAP(GPUFrameBuffer *, a.fb_, b.fb_);
+ SWAP(const char *, a.name_, b.name_);
+ }
};
/** \} */