[Bf-blender-cvs] [1275a7991cc] pygpu_extensions: Comment the methods of free a GPU object (except offscreen)
Germano Cavalcante
noreply at git.blender.org
Fri Feb 12 22:56:30 CET 2021
Commit: 1275a7991ccab1a830d9a520d07dbc72b681c35f
Author: Germano Cavalcante
Date: Fri Feb 12 18:44:01 2021 -0300
Branches: pygpu_extensions
https://developer.blender.org/rB1275a7991ccab1a830d9a520d07dbc72b681c35f
Comment the methods of free a GPU object (except offscreen)
===================================================================
M source/blender/python/gpu/gpu_py_api.h
M source/blender/python/gpu/gpu_py_framebuffer.c
M source/blender/python/gpu/gpu_py_offscreen.c
M source/blender/python/gpu/gpu_py_texture.c
M source/blender/python/gpu/gpu_py_uniformbuffer.c
===================================================================
diff --git a/source/blender/python/gpu/gpu_py_api.h b/source/blender/python/gpu/gpu_py_api.h
index b8f0cde129f..fe645d8cd3a 100644
--- a/source/blender/python/gpu/gpu_py_api.h
+++ b/source/blender/python/gpu/gpu_py_api.h
@@ -20,6 +20,10 @@
#pragma once
+/* Each type object could have a method for free GPU resources.
+ * However, it is currently of little use. */
+// #define BPYGPU_USE_GPUOBJ_FREE_METHOD
+
int bpygpu_ParsePrimType(PyObject *o, void *p);
PyObject *BPyInit_gpu(void);
diff --git a/source/blender/python/gpu/gpu_py_framebuffer.c b/source/blender/python/gpu/gpu_py_framebuffer.c
index 6def4eec472..069ea90c580 100644
--- a/source/blender/python/gpu/gpu_py_framebuffer.c
+++ b/source/blender/python/gpu/gpu_py_framebuffer.c
@@ -46,7 +46,13 @@
static int py_framebuffer_valid_check(BPyGPUFrameBuffer *bpygpu_fb)
{
if (UNLIKELY(bpygpu_fb->fb == NULL)) {
- PyErr_SetString(PyExc_ReferenceError, "GPU framebuffer was freed, no further access is valid");
+ PyErr_SetString(PyExc_ReferenceError,
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
+ "GPU framebuffer was freed, no further access is valid"
+#else
+ "GPU framebuffer: internal error"
+#endif
+ );
return -1;
}
return 0;
@@ -319,19 +325,6 @@ static PyObject *py_framebuffer_is_bound(BPyGPUFrameBuffer *self, void *UNUSED(t
return PyBool_FromLong(GPU_framebuffer_bound(self->fb));
}
-PyDoc_STRVAR(py_framebuffer_free_doc,
- ".. method:: free()\n"
- "\n"
- " Free the framebuffer object.\n"
- " The framebuffer will no longer be accessible.\n");
-static PyObject *py_framebuffer_free(BPyGPUFrameBuffer *self)
-{
- PY_FRAMEBUFFER_CHECK_OBJ(self);
- py_framebuffer_free_if_possible(self->fb);
- self->fb = NULL;
- Py_RETURN_NONE;
-}
-
PyDoc_STRVAR(py_framebuffer_clear_doc,
".. method:: clear(color=(0.0, 0.0, 0.0, 1.0), depth=None, stencil=None,)\n"
"\n"
@@ -434,6 +427,21 @@ static PyObject *py_framebuffer_viewport_get(BPyGPUFrameBuffer *self, void *UNUS
return ret;
}
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
+PyDoc_STRVAR(py_framebuffer_free_doc,
+ ".. method:: free()\n"
+ "\n"
+ " Free the framebuffer object.\n"
+ " The framebuffer will no longer be accessible.\n");
+static PyObject *py_framebuffer_free(BPyGPUFrameBuffer *self)
+{
+ PY_FRAMEBUFFER_CHECK_OBJ(self);
+ py_framebuffer_free_if_possible(self->fb);
+ self->fb = NULL;
+ Py_RETURN_NONE;
+}
+#endif
+
static void BPyGPUFrameBuffer__tp_dealloc(BPyGPUFrameBuffer *self)
{
py_framebuffer_free_if_possible(self->fb);
@@ -447,7 +455,6 @@ static PyGetSetDef py_framebuffer_getseters[] = {
static struct PyMethodDef py_framebuffer_methods[] = {
{"bind", (PyCFunction)py_framebuffer_bind, METH_NOARGS, py_framebuffer_bind_doc},
- {"free", (PyCFunction)py_framebuffer_free, METH_NOARGS, py_framebuffer_free_doc},
{"clear",
(PyCFunction)py_framebuffer_clear,
METH_VARARGS | METH_KEYWORDS,
@@ -460,6 +467,9 @@ static struct PyMethodDef py_framebuffer_methods[] = {
(PyCFunction)py_framebuffer_viewport_get,
METH_VARARGS,
py_framebuffer_viewport_get_doc},
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
+ {"free", (PyCFunction)py_framebuffer_free, METH_NOARGS, py_framebuffer_free_doc},
+#endif
{NULL, NULL, 0, NULL},
};
diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c
index 3f59eb23df7..8fe05c061af 100644
--- a/source/blender/python/gpu/gpu_py_offscreen.c
+++ b/source/blender/python/gpu/gpu_py_offscreen.c
@@ -54,6 +54,9 @@
#include "gpu_py_api.h"
#include "gpu_py_offscreen.h" /* own include */
+/* Define the free method to avoid breakage. */
+#define BPYGPU_USE_GPUOBJ_FREE_METHOD
+
/* -------------------------------------------------------------------- */
/** \name GPUOffScreen Common Utilities
* \{ */
@@ -61,7 +64,13 @@
static int py_offscreen_valid_check(BPyGPUOffScreen *py_ofs)
{
if (UNLIKELY(py_ofs->ofs == NULL)) {
- PyErr_SetString(PyExc_ReferenceError, "GPU offscreen was freed, no further access is valid");
+ PyErr_SetString(PyExc_ReferenceError,
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
+ "GPU offscreen was freed, no further access is valid"
+#else
+ "GPU offscreen: internal error"
+#endif
+ );
return -1;
}
return 0;
@@ -311,6 +320,7 @@ static PyObject *py_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *args,
Py_RETURN_NONE;
}
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
PyDoc_STRVAR(py_offscreen_free_doc,
".. method:: free()\n"
"\n"
@@ -324,6 +334,7 @@ static PyObject *py_offscreen_free(BPyGPUOffScreen *self)
self->ofs = NULL;
Py_RETURN_NONE;
}
+#endif
static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self)
{
@@ -350,7 +361,9 @@ static struct PyMethodDef py_offscreen_methods[] = {
(PyCFunction)py_offscreen_draw_view3d,
METH_VARARGS | METH_KEYWORDS,
py_offscreen_draw_view3d_doc},
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
{"free", (PyCFunction)py_offscreen_free, METH_NOARGS, py_offscreen_free_doc},
+#endif
{NULL, NULL, 0, NULL},
};
diff --git a/source/blender/python/gpu/gpu_py_texture.c b/source/blender/python/gpu/gpu_py_texture.c
index 90970f622e0..557a7fbf129 100644
--- a/source/blender/python/gpu/gpu_py_texture.c
+++ b/source/blender/python/gpu/gpu_py_texture.c
@@ -91,7 +91,14 @@ static const struct PyC_StringEnumItems pygpu_textureformat_items[] = {
static int py_texture_valid_check(BPyGPUTexture *bpygpu_tex)
{
if (UNLIKELY(bpygpu_tex->tex == NULL)) {
- PyErr_SetString(PyExc_ReferenceError, "GPU texture was freed, no further access is valid");
+ PyErr_SetString(PyExc_ReferenceError,
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
+ "GPU texture was freed, no further access is valid"
+#else
+ "GPU texture: internal error"
+#endif
+ );
+
return -1;
}
return 0;
@@ -275,20 +282,6 @@ static PyObject *py_texture_height_get(BPyGPUTexture *self, void *UNUSED(type))
return PyLong_FromLong(GPU_texture_height(self->tex));
}
-PyDoc_STRVAR(py_texture_free_doc,
- ".. method:: free()\n"
- "\n"
- " Free the texture object.\n"
- " The texture object will no longer be accessible.\n");
-static PyObject *py_texture_free(BPyGPUTexture *self)
-{
- PY_TEXTURE_CHECK_OBJ(self);
-
- GPU_texture_free(self->tex);
- self->tex = NULL;
- Py_RETURN_NONE;
-}
-
PyDoc_STRVAR(py_texture_clear_doc,
".. method:: clear(format='FLOAT', value=(0.0, 0.0, 0.0, 1.0))\n"
"\n"
@@ -374,6 +367,22 @@ static PyObject *py_texture_read(BPyGPUTexture *self, PyObject *args)
buf);
}
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
+PyDoc_STRVAR(py_texture_free_doc,
+ ".. method:: free()\n"
+ "\n"
+ " Free the texture object.\n"
+ " The texture object will no longer be accessible.\n");
+static PyObject *py_texture_free(BPyGPUTexture *self)
+{
+ PY_TEXTURE_CHECK_OBJ(self);
+
+ GPU_texture_free(self->tex);
+ self->tex = NULL;
+ Py_RETURN_NONE;
+}
+#endif
+
static void BPyGPUTexture__tp_dealloc(BPyGPUTexture *self)
{
if (self->tex) {
@@ -389,9 +398,11 @@ static PyGetSetDef py_texture_getseters[] = {
};
static struct PyMethodDef py_texture_methods[] = {
- {"free", (PyCFunction)py_texture_free, METH_NOARGS, py_texture_free_doc},
{"clear", (PyCFunction)py_texture_clear, METH_VARARGS, py_texture_clear_doc},
{"read", (PyCFunction)py_texture_read, METH_VARARGS, py_texture_read_doc},
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
+ {"free", (PyCFunction)py_texture_free, METH_NOARGS, py_texture_free_doc},
+#endif
{NULL, NULL, 0, NULL},
};
diff --git a/source/blender/python/gpu/gpu_py_uniformbuffer.c b/source/blender/python/gpu/gpu_py_uniformbuffer.c
index 40951ef4ef4..f6b9016bc8b 100644
--- a/source/blender/python/gpu/gpu_py_uniformbuffer.c
+++ b/source/blender/python/gpu/gpu_py_uniformbuffer.c
@@ -45,7 +45,12 @@ static int py_uniformbuffer_valid_check(BPyGPUUniformBuf *bpygpu_ub)
{
if (UNLIKELY(bpygpu_ub->ubo == NULL)) {
PyErr_SetString(PyExc_ReferenceError,
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
"GPU uniform buffer was freed, no further access is valid");
+#else
+
+ "GPU uniform buffer: internal error");
+#endif
return -1;
}
return 0;
@@ -111,6 +116,7 @@ static PyObject *py_uniformbuffer_update(BPyGPUUniformBuf *self, PyObject *obj)
Py_RETURN_NONE;
}
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
PyDoc_STRVAR(py_uniformbuffer_free_doc,
".. method::free()\n"
"\n"
@@ -124,6 +130,7 @@ static PyObject *py_uniformbuffer_free(BPyGPUUniformBuf *self)
self->ubo = NULL;
Py_RETURN_NONE;
}
+#endif
static void BPyGPUUniformBuf__tp_dealloc(BPyGPUUniformBuf *self)
{
@@ -139,7 +146,9 @@ static PyGetSetDef py_uniformbuffer_getseters[] = {
static struct PyMethodDef py_uniformbuffer_methods[] = {
{"update", (PyCFunction)py_uniformbuffer_update, METH_O, py_uniformbuffer_update_doc},
+#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
{"free", (PyCFunction)py_uniformbuffer_free, METH_NOARGS, py_uniformbuffer_free_doc},
+#endif
{NULL, NULL, 0, NULL},
};
More information about the Bf-blender-cvs
mailing list