From 5be72125bf4dfddf5dfe720caa12b3163f540faf Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Mon, 22 Feb 2021 09:44:57 -0300 Subject: Cleanup: Move some utilities to 'gpu_py.h' --- source/blender/python/gpu/gpu_py.c | 19 +++++++++++++++++++ source/blender/python/gpu/gpu_py.h | 13 +++++++++++++ source/blender/python/gpu/gpu_py_api.c | 20 -------------------- source/blender/python/gpu/gpu_py_api.h | 12 ------------ source/blender/python/gpu/gpu_py_batch.c | 1 - source/blender/python/gpu/gpu_py_element.c | 1 - source/blender/python/gpu/gpu_py_framebuffer.c | 2 +- source/blender/python/gpu/gpu_py_offscreen.c | 2 +- source/blender/python/gpu/gpu_py_shader.c | 2 +- source/blender/python/gpu/gpu_py_texture.c | 1 - source/blender/python/gpu/gpu_py_uniformbuffer.c | 1 - 11 files changed, 35 insertions(+), 39 deletions(-) (limited to 'source/blender/python') diff --git a/source/blender/python/gpu/gpu_py.c b/source/blender/python/gpu/gpu_py.c index 2c5daaf1962..7aea940da94 100644 --- a/source/blender/python/gpu/gpu_py.c +++ b/source/blender/python/gpu/gpu_py.c @@ -23,6 +23,7 @@ #include +#include "GPU_init_exit.h" #include "GPU_primitive.h" #include "GPU_texture.h" @@ -58,3 +59,21 @@ struct PyC_StringEnumItems bpygpu_dataformat_items[] = { {0, NULL}, }; /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Utilities + * \{ */ + +bool bpygpu_is_init_or_error(void) +{ + if (!GPU_is_init()) { + PyErr_SetString(PyExc_SystemError, + "GPU functions for drawing are not available in background mode"); + + return false; + } + + return true; +} + +/** \} */ diff --git a/source/blender/python/gpu/gpu_py.h b/source/blender/python/gpu/gpu_py.h index 28b3e41a08f..39e5997f866 100644 --- a/source/blender/python/gpu/gpu_py.h +++ b/source/blender/python/gpu/gpu_py.h @@ -22,3 +22,16 @@ extern struct PyC_StringEnumItems bpygpu_primtype_items[]; extern struct PyC_StringEnumItems bpygpu_dataformat_items[]; + +bool bpygpu_is_init_or_error(void); + +#define BPYGPU_IS_INIT_OR_ERROR_OBJ \ + if (UNLIKELY(!bpygpu_is_init_or_error())) { \ + return NULL; \ + } \ + ((void)0) +#define BPYGPU_IS_INIT_OR_ERROR_INT \ + if (UNLIKELY(!bpygpu_is_init_or_error())) { \ + return -1; \ + } \ + ((void)0) diff --git a/source/blender/python/gpu/gpu_py_api.c b/source/blender/python/gpu/gpu_py_api.c index 7213dc59886..68f7eb9816c 100644 --- a/source/blender/python/gpu/gpu_py_api.c +++ b/source/blender/python/gpu/gpu_py_api.c @@ -30,8 +30,6 @@ #include "../generic/python_utildefines.h" -#include "GPU_init_exit.h" - #include "gpu_py_matrix.h" #include "gpu_py_select.h" #include "gpu_py_state.h" @@ -39,24 +37,6 @@ #include "gpu_py_api.h" /* own include */ -/* -------------------------------------------------------------------- */ -/** \name Utils to invalidate functions - * \{ */ - -bool bpygpu_is_init_or_error(void) -{ - if (!GPU_is_init()) { - PyErr_SetString(PyExc_SystemError, - "GPU functions for drawing are not available in background mode"); - - return false; - } - - return true; -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name GPU Module * \{ */ diff --git a/source/blender/python/gpu/gpu_py_api.h b/source/blender/python/gpu/gpu_py_api.h index 5e399a233aa..38452ad67c1 100644 --- a/source/blender/python/gpu/gpu_py_api.h +++ b/source/blender/python/gpu/gpu_py_api.h @@ -25,15 +25,3 @@ // #define BPYGPU_USE_GPUOBJ_FREE_METHOD PyObject *BPyInit_gpu(void); - -bool bpygpu_is_init_or_error(void); -#define BPYGPU_IS_INIT_OR_ERROR_OBJ \ - if (UNLIKELY(!bpygpu_is_init_or_error())) { \ - return NULL; \ - } \ - ((void)0) -#define BPYGPU_IS_INIT_OR_ERROR_INT \ - if (UNLIKELY(!bpygpu_is_init_or_error())) { \ - return -1; \ - } \ - ((void)0) diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c index 9989077670b..ef795268158 100644 --- a/source/blender/python/gpu/gpu_py_batch.c +++ b/source/blender/python/gpu/gpu_py_batch.c @@ -39,7 +39,6 @@ #include "../generic/py_capi_utils.h" #include "gpu_py.h" -#include "gpu_py_api.h" #include "gpu_py_element.h" #include "gpu_py_shader.h" #include "gpu_py_vertex_buffer.h" diff --git a/source/blender/python/gpu/gpu_py_element.c b/source/blender/python/gpu/gpu_py_element.c index 0e5094cbbc0..2beabe6a93d 100644 --- a/source/blender/python/gpu/gpu_py_element.c +++ b/source/blender/python/gpu/gpu_py_element.c @@ -33,7 +33,6 @@ #include "../generic/python_utildefines.h" #include "gpu_py.h" -#include "gpu_py_api.h" #include "gpu_py_element.h" /* own include */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/python/gpu/gpu_py_framebuffer.c b/source/blender/python/gpu/gpu_py_framebuffer.c index 04d49a9f15d..5bf577f3b96 100644 --- a/source/blender/python/gpu/gpu_py_framebuffer.c +++ b/source/blender/python/gpu/gpu_py_framebuffer.c @@ -34,7 +34,7 @@ #include "../generic/python_utildefines.h" #include "../mathutils/mathutils.h" -#include "gpu_py_api.h" +#include "gpu_py.h" #include "gpu_py_texture.h" #include "gpu_py_framebuffer.h" /* own include */ diff --git a/source/blender/python/gpu/gpu_py_offscreen.c b/source/blender/python/gpu/gpu_py_offscreen.c index a98d9649f6f..9d5671ff702 100644 --- a/source/blender/python/gpu/gpu_py_offscreen.c +++ b/source/blender/python/gpu/gpu_py_offscreen.c @@ -52,7 +52,7 @@ #include "../generic/py_capi_utils.h" -#include "gpu_py_api.h" +#include "gpu_py.h" #include "gpu_py_offscreen.h" /* own include */ /* Define the free method to avoid breakage. */ diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index 2f9b67bdb6a..4237e2d4b2d 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -33,7 +33,7 @@ #include "../generic/python_utildefines.h" #include "../mathutils/mathutils.h" -#include "gpu_py_api.h" +#include "gpu_py.h" #include "gpu_py_texture.h" #include "gpu_py_uniformbuffer.h" #include "gpu_py_vertex_format.h" diff --git a/source/blender/python/gpu/gpu_py_texture.c b/source/blender/python/gpu/gpu_py_texture.c index 85246bffac7..12855b8dbcc 100644 --- a/source/blender/python/gpu/gpu_py_texture.c +++ b/source/blender/python/gpu/gpu_py_texture.c @@ -33,7 +33,6 @@ #include "../generic/py_capi_utils.h" #include "gpu_py.h" -#include "gpu_py_api.h" #include "gpu_py_buffer.h" #include "gpu_py_texture.h" /* own include */ diff --git a/source/blender/python/gpu/gpu_py_uniformbuffer.c b/source/blender/python/gpu/gpu_py_uniformbuffer.c index d1b86455918..c60d6216834 100644 --- a/source/blender/python/gpu/gpu_py_uniformbuffer.c +++ b/source/blender/python/gpu/gpu_py_uniformbuffer.c @@ -34,7 +34,6 @@ #include "../generic/py_capi_utils.h" #include "gpu_py.h" -#include "gpu_py_api.h" #include "gpu_py_buffer.h" #include "gpu_py_uniformbuffer.h" /* own include */ -- cgit v1.2.3