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:
authorBrecht Van Lommel <brecht@blender.org>2021-06-16 21:07:24 +0300
committerBrecht Van Lommel <brecht@blender.org>2021-06-16 21:19:34 +0300
commitd03b26edbdc3a9fe87fde44bd8db8c4a67a36757 (patch)
treeb791819b2daf9bedb52c5a282c50a292d8de8ae2
parenta1cc7042a745b4bfd882367cf4c4653467c1e430 (diff)
Fix T89204: slow repeated rendering with GPUOffscreen.draw_view3d
Cache the GPUViewport so the framebuffers and associated textures are not reallocated each time.
-rw-r--r--source/blender/python/gpu/gpu_py_offscreen.c15
-rw-r--r--source/blender/python/gpu/gpu_py_offscreen.h4
2 files changed, 18 insertions, 1 deletions
diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c
index 0d29bc98a31..1ccac003e97 100644
--- a/source/blender/python/gpu/gpu_py_offscreen.c
+++ b/source/blender/python/gpu/gpu_py_offscreen.c
@@ -44,6 +44,7 @@
#include "GPU_context.h"
#include "GPU_framebuffer.h"
#include "GPU_texture.h"
+#include "GPU_viewport.h"
#include "ED_view3d.h"
#include "ED_view3d_offscreen.h"
@@ -342,6 +343,10 @@ static PyObject *pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *ar
GPU_offscreen_bind(self->ofs, true);
+ if (!self->viewport) {
+ self->viewport = GPU_viewport_create();
+ }
+
ED_view3d_draw_offscreen(depsgraph,
scene,
v3d->shading.type,
@@ -357,7 +362,7 @@ static PyObject *pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *ar
false,
true,
self->ofs,
- NULL);
+ self->viewport);
GPU_offscreen_unbind(self->ofs, true);
@@ -378,6 +383,10 @@ static PyObject *pygpu_offscreen_free(BPyGPUOffScreen *self)
{
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
+ if (self->viewport) {
+ GPU_viewport_free(self->viewport);
+ self->viewport = NULL;
+ }
GPU_offscreen_free(self->ofs);
self->ofs = NULL;
Py_RETURN_NONE;
@@ -386,6 +395,9 @@ static PyObject *pygpu_offscreen_free(BPyGPUOffScreen *self)
static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self)
{
+ if (self->viewport) {
+ GPU_viewport_free(self->viewport);
+ }
if (self->ofs) {
GPU_offscreen_free(self->ofs);
}
@@ -456,6 +468,7 @@ PyObject *BPyGPUOffScreen_CreatePyObject(GPUOffScreen *ofs)
self = PyObject_New(BPyGPUOffScreen, &BPyGPUOffScreen_Type);
self->ofs = ofs;
+ self->viewport = NULL;
return (PyObject *)self;
}
diff --git a/source/blender/python/gpu/gpu_py_offscreen.h b/source/blender/python/gpu/gpu_py_offscreen.h
index f551730cf54..203c8c69f73 100644
--- a/source/blender/python/gpu/gpu_py_offscreen.h
+++ b/source/blender/python/gpu/gpu_py_offscreen.h
@@ -26,8 +26,12 @@ extern PyTypeObject BPyGPUOffScreen_Type;
#define BPyGPUOffScreen_Check(v) (Py_TYPE(v) == &BPyGPUOffScreen_Type)
+struct GPUOffscreen;
+struct GPUViewport;
+
typedef struct BPyGPUOffScreen {
PyObject_HEAD struct GPUOffScreen *ofs;
+ struct GPUViewport *viewport;
} BPyGPUOffScreen;
PyObject *BPyGPUOffScreen_CreatePyObject(struct GPUOffScreen *ofs) ATTR_NONNULL(1);