Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/gpu/gpu_py_offscreen.c
| Show All 34 Lines | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BLI_listbase.h" | |||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "DNA_view3d_types.h" | #include "DNA_view3d_types.h" | ||||
| #include "GPU_framebuffer.h" | #include "GPU_framebuffer.h" | ||||
| #include "GPU_texture.h" | #include "GPU_texture.h" | ||||
| #include "../editors/include/ED_view3d.h" | #include "../editors/include/ED_view3d.h" | ||||
| ▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
| PyDoc_STRVAR(bpygpu_offscreen_color_texture_doc, "Color texture.\n\n:type: int"); | PyDoc_STRVAR(bpygpu_offscreen_color_texture_doc, "Color texture.\n\n:type: int"); | ||||
| static PyObject *bpygpu_offscreen_color_texture_get(BPyGPUOffScreen *self, void *UNUSED(type)) | static PyObject *bpygpu_offscreen_color_texture_get(BPyGPUOffScreen *self, void *UNUSED(type)) | ||||
| { | { | ||||
| BPY_GPU_OFFSCREEN_CHECK_OBJ(self); | BPY_GPU_OFFSCREEN_CHECK_OBJ(self); | ||||
| GPUTexture *texture = GPU_offscreen_color_texture(self->ofs); | GPUTexture *texture = GPU_offscreen_color_texture(self->ofs); | ||||
| return PyLong_FromLong(GPU_texture_opengl_bindcode(texture)); | return PyLong_FromLong(GPU_texture_opengl_bindcode(texture)); | ||||
| } | } | ||||
| PyDoc_STRVAR(bpygpu_offscreen_is_free_doc, | |||||
| "Framebuffer has been freed. " | |||||
| "This can happen automatically when the opengl context, this object has been created in, is discared." | |||||
| "In practice that mostly means that a window has been closed.\n\n" | |||||
| ":type: bool"); | |||||
| static PyObject *bpygpu_offscreen_is_free_get(BPyGPUOffScreen *self, void *UNUSED(type)) | |||||
| { | |||||
| return PyBool_FromLong(self->ofs == NULL); | |||||
| } | |||||
| PyDoc_STRVAR(bpygpu_offscreen_bind_doc, | PyDoc_STRVAR(bpygpu_offscreen_bind_doc, | ||||
| "bind(save=True)\n" | "bind(save=True)\n" | ||||
| "\n" | "\n" | ||||
| " Bind the offscreen object.\n" | " Bind the offscreen object.\n" | ||||
| "\n" | "\n" | ||||
| " :param save: save OpenGL current states.\n" | " :param save: save OpenGL current states.\n" | ||||
| " :type save: bool\n" | " :type save: bool\n" | ||||
| ); | ); | ||||
| ▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BPY_GPU_OFFSCREEN_CHECK_OBJ(self); | BPY_GPU_OFFSCREEN_CHECK_OBJ(self); | ||||
| GPU_offscreen_free(self->ofs); | GPU_offscreen_free(self->ofs); | ||||
| self->ofs = NULL; | self->ofs = NULL; | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| /* Keep track of all framebuffers so that they can be free when | |||||
| * the opengl context is discarded (i.e. a window is closed) | |||||
| */ | |||||
| ListBase all_py_offscreens; | |||||
fclem: Use `static` and initialize to {NULL, NULL}. | |||||
| static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self) | static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self) | ||||
| { | { | ||||
| LISTBASE_FOREACH(LinkData *, link, &all_py_offscreens) { | |||||
| if (link->data == self) { | |||||
| BLI_remlink(&all_py_offscreens, link); | |||||
| MEM_freeN(link); | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (self->ofs) | if (self->ofs) | ||||
| GPU_offscreen_free(self->ofs); | GPU_offscreen_free(self->ofs); | ||||
| Py_TYPE(self)->tp_free((PyObject *)self); | Py_TYPE(self)->tp_free((PyObject *)self); | ||||
| } | } | ||||
| void BPyGPUOffScreen_free_for_context(struct GPUContext *ctx) | |||||
| { | |||||
| LISTBASE_FOREACH(LinkData *, link, &all_py_offscreens) { | |||||
| BPyGPUOffScreen *py_ofs = link->data; | |||||
| if (py_ofs->ofs && GPU_offscreen_context(py_ofs->ofs) == ctx) { | |||||
| bpygpu_offscreen_free(py_ofs); | |||||
| printf("GPUOffScreen object was freed because the opengl context was discarded.\n"); | |||||
| } | |||||
| } | |||||
| } | |||||
| static PyGetSetDef bpygpu_offscreen_getseters[] = { | static PyGetSetDef bpygpu_offscreen_getseters[] = { | ||||
| {(char *)"color_texture", (getter)bpygpu_offscreen_color_texture_get, (setter)NULL, bpygpu_offscreen_color_texture_doc, NULL}, | {(char *)"color_texture", (getter)bpygpu_offscreen_color_texture_get, (setter)NULL, bpygpu_offscreen_color_texture_doc, NULL}, | ||||
| {(char *)"width", (getter)bpygpu_offscreen_width_get, (setter)NULL, bpygpu_offscreen_width_doc, NULL}, | {(char *)"width", (getter)bpygpu_offscreen_width_get, (setter)NULL, bpygpu_offscreen_width_doc, NULL}, | ||||
| {(char *)"height", (getter)bpygpu_offscreen_height_get, (setter)NULL, bpygpu_offscreen_height_doc, NULL}, | {(char *)"height", (getter)bpygpu_offscreen_height_get, (setter)NULL, bpygpu_offscreen_height_doc, NULL}, | ||||
| {(char *)"is_free", (getter)bpygpu_offscreen_is_free_get, (setter)NULL, bpygpu_offscreen_is_free_doc, NULL}, | |||||
| {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ | {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ | ||||
| }; | }; | ||||
| static struct PyMethodDef bpygpu_offscreen_methods[] = { | static struct PyMethodDef bpygpu_offscreen_methods[] = { | ||||
| {"bind", (PyCFunction)bpygpu_offscreen_bind, METH_VARARGS | METH_KEYWORDS, bpygpu_offscreen_bind_doc}, | {"bind", (PyCFunction)bpygpu_offscreen_bind, METH_VARARGS | METH_KEYWORDS, bpygpu_offscreen_bind_doc}, | ||||
| {"unbind", (PyCFunction)bpygpu_offscreen_unbind, METH_VARARGS | METH_KEYWORDS, bpygpu_offscreen_unbind_doc}, | {"unbind", (PyCFunction)bpygpu_offscreen_unbind, METH_VARARGS | METH_KEYWORDS, bpygpu_offscreen_unbind_doc}, | ||||
| {"draw_view3d", (PyCFunction)bpygpu_offscreen_draw_view3d, METH_VARARGS | METH_KEYWORDS, bpygpu_offscreen_draw_view3d_doc}, | {"draw_view3d", (PyCFunction)bpygpu_offscreen_draw_view3d, METH_VARARGS | METH_KEYWORDS, bpygpu_offscreen_draw_view3d_doc}, | ||||
| {"free", (PyCFunction)bpygpu_offscreen_free, METH_NOARGS, bpygpu_offscreen_free_doc}, | {"free", (PyCFunction)bpygpu_offscreen_free, METH_NOARGS, bpygpu_offscreen_free_doc}, | ||||
| Show All 34 Lines | |||||
| PyObject *BPyGPUOffScreen_CreatePyObject(GPUOffScreen *ofs) | PyObject *BPyGPUOffScreen_CreatePyObject(GPUOffScreen *ofs) | ||||
| { | { | ||||
| BPyGPUOffScreen *self; | BPyGPUOffScreen *self; | ||||
| self = PyObject_New(BPyGPUOffScreen, &BPyGPUOffScreen_Type); | self = PyObject_New(BPyGPUOffScreen, &BPyGPUOffScreen_Type); | ||||
| self->ofs = ofs; | self->ofs = ofs; | ||||
| BLI_addtail(&all_py_offscreens, BLI_genericNodeN(self)); | |||||
| return (PyObject *)self; | return (PyObject *)self; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| #undef BPY_GPU_OFFSCREEN_CHECK_OBJ | #undef BPY_GPU_OFFSCREEN_CHECK_OBJ | ||||
Use static and initialize to {NULL, NULL}.