Cleanup: Move some utilities to 'gpu_py.h'

This commit is contained in:
Germano Cavalcante 2021-02-22 09:44:57 -03:00
parent 8f6fd07b54
commit 5be72125bf
11 changed files with 35 additions and 39 deletions

@ -23,6 +23,7 @@
#include <Python.h>
#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;
}
/** \} */

@ -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)

@ -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
* \{ */

@ -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)

@ -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"

@ -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 */
/* -------------------------------------------------------------------- */

@ -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 */

@ -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. */

@ -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"

@ -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 */

@ -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 */