diff options
author | Germano Cavalcante <mano-wii> | 2021-04-29 20:48:59 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2021-04-30 16:42:13 +0300 |
commit | 04b6296e8165736d17fb5167e45a93178f9f71c2 (patch) | |
tree | 62229a42466cdf374f1a9b08da19de7a29e6286e /source/blender/gpu | |
parent | c96506d54ad0aeb683896db50cf787d90840f702 (diff) |
Python GPU: Add reference of PyObject GPU object to the GPU object itself
Instead of creating different python wrappers for the same GPU object,
return the same `PyObject` created earlier.
This also allows for more secure access to existing GPU objects.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11044
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_common.h | 1 | ||||
-rw-r--r-- | source/blender/gpu/GPU_framebuffer.h | 5 | ||||
-rw-r--r-- | source/blender/gpu/GPU_texture.h | 6 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer.cc | 19 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_framebuffer_private.hh | 9 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.cc | 19 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture_private.hh | 7 |
7 files changed, 66 insertions, 0 deletions
diff --git a/source/blender/gpu/GPU_common.h b/source/blender/gpu/GPU_common.h index 1be74701176..bc57a381f00 100644 --- a/source/blender/gpu/GPU_common.h +++ b/source/blender/gpu/GPU_common.h @@ -24,6 +24,7 @@ #pragma once #define PROGRAM_NO_OPTI 0 +#define USE_PY_REFERENCES 1 #if defined(NDEBUG) # define TRUST_NO_ONE 0 diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h index af94c1fb0e6..ccab80c5702 100644 --- a/source/blender/gpu/GPU_framebuffer.h +++ b/source/blender/gpu/GPU_framebuffer.h @@ -209,6 +209,11 @@ void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *fb, void (*callback)(void *userData, int level), void *userData); +#if USE_PY_REFERENCES +void **GPU_framebuffer_py_reference_get(GPUFrameBuffer *gpu_fb); +void GPU_framebuffer_py_reference_set(GPUFrameBuffer *gpu_fb, void **py_ref); +#endif + void GPU_framebuffer_push(GPUFrameBuffer *fb); GPUFrameBuffer *GPU_framebuffer_pop(void); uint GPU_framebuffer_stack_level_get(void); diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h index d9a01663de0..21d3070e252 100644 --- a/source/blender/gpu/GPU_texture.h +++ b/source/blender/gpu/GPU_texture.h @@ -269,6 +269,12 @@ bool GPU_texture_cube(const GPUTexture *tex); bool GPU_texture_depth(const GPUTexture *tex); bool GPU_texture_stencil(const GPUTexture *tex); bool GPU_texture_integer(const GPUTexture *tex); + +#if USE_PY_REFERENCES +void **GPU_texture_py_reference_get(GPUTexture *tex); +void GPU_texture_py_reference_set(GPUTexture *tex, void **py_ref); +#endif + int GPU_texture_opengl_bindcode(const GPUTexture *tex); void GPU_texture_get_mipmap_size(GPUTexture *tex, int lvl, int *size); diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc index 1e3cf479462..f593a5e4182 100644 --- a/source/blender/gpu/intern/gpu_framebuffer.cc +++ b/source/blender/gpu/intern/gpu_framebuffer.cc @@ -71,6 +71,12 @@ FrameBuffer::~FrameBuffer() reinterpret_cast<Texture *>(attachment.tex)->detach_from(this); } } + +#if USE_PY_REFERENCES + if (this->py_ref) { + *this->py_ref = nullptr; + } +#endif } /** \} */ @@ -473,6 +479,19 @@ void GPU_framebuffer_recursive_downsample(GPUFrameBuffer *gpu_fb, unwrap(gpu_fb)->recursive_downsample(max_lvl, callback, userData); } +#if USE_PY_REFERENCES +void **GPU_framebuffer_py_reference_get(GPUFrameBuffer *gpu_fb) +{ + return unwrap(gpu_fb)->py_ref; +} + +void GPU_framebuffer_py_reference_set(GPUFrameBuffer *gpu_fb, void **py_ref) +{ + BLI_assert(ref == nullptr || unwrap(gpu_fb)->py_ref == nullptr); + unwrap(gpu_fb)->py_ref = py_ref; +} +#endif + /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/gpu/intern/gpu_framebuffer_private.hh b/source/blender/gpu/intern/gpu_framebuffer_private.hh index d63d72cf4f7..6e4be6de42a 100644 --- a/source/blender/gpu/intern/gpu_framebuffer_private.hh +++ b/source/blender/gpu/intern/gpu_framebuffer_private.hh @@ -100,6 +100,15 @@ class FrameBuffer { bool scissor_test_ = false; bool dirty_state_ = true; +#if USE_PY_REFERENCES + public: + /** + * Reference of a pointer that needs to be cleaned when deallocating the frame-buffer. + * Points to #BPyGPUFrameBuffer.fb + */ + void **py_ref = nullptr; +#endif + public: FrameBuffer(const char *name); virtual ~FrameBuffer(); diff --git a/source/blender/gpu/intern/gpu_texture.cc b/source/blender/gpu/intern/gpu_texture.cc index c3e9058c6c7..b0b0fb970d7 100644 --- a/source/blender/gpu/intern/gpu_texture.cc +++ b/source/blender/gpu/intern/gpu_texture.cc @@ -60,6 +60,12 @@ Texture::~Texture() fb_[i]->attachment_remove(fb_attachment_[i]); } } + +#if USE_PY_REFERENCES + if (this->py_ref) { + *this->py_ref = nullptr; + } +#endif } bool Texture::init_1D(int w, int layers, eGPUTextureFormat format) @@ -581,6 +587,19 @@ bool GPU_texture_array(const GPUTexture *tex) return (reinterpret_cast<const Texture *>(tex)->type_get() & GPU_TEXTURE_ARRAY) != 0; } +#if USE_PY_REFERENCES +void **GPU_texture_py_reference_get(GPUTexture *tex) +{ + return unwrap(tex)->py_ref; +} + +void GPU_texture_py_reference_set(GPUTexture *tex, void **py_ref) +{ + BLI_assert(py_ref == nullptr || unwrap(tex)->py_ref == nullptr); + unwrap(tex)->py_ref = py_ref; +} +#endif + /* TODO remove */ int GPU_texture_opengl_bindcode(const GPUTexture *tex) { diff --git a/source/blender/gpu/intern/gpu_texture_private.hh b/source/blender/gpu/intern/gpu_texture_private.hh index 3d808bce152..9f185e03493 100644 --- a/source/blender/gpu/intern/gpu_texture_private.hh +++ b/source/blender/gpu/intern/gpu_texture_private.hh @@ -80,6 +80,13 @@ class Texture { int refcount = 1; /** Width & Height (of source data), optional. */ int src_w = 0, src_h = 0; +#if USE_PY_REFERENCES + /** + * Reference of a pointer that needs to be cleaned when deallocating the texture. + * Points to #BPyGPUTexture.tex + */ + void **py_ref = nullptr; +#endif protected: /* ---- Texture format (immutable after init). ---- */ |