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:
authorCampbell Barton <campbell@blender.org>2022-07-16 10:28:09 +0300
committerCampbell Barton <campbell@blender.org>2022-07-16 10:30:17 +0300
commit0a8d21e0c96e2f9c7f6f990d756f5abe011ed805 (patch)
treec034a7814b53d4c425c8d2435c2be38fa57b45e4 /source/blender/python
parent49babc7caa82883fa891640406da89b68ae8d8e5 (diff)
PyAPI: re-enable the "bgl" module for headless builds
Instead of removing the `bgl` module, set all it's functions to stubs so importing `bgl` or any of it's members doesn't raise an error. This avoids problems for scripts that import bgl but don't call it's functions when running in background mode.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/generic/CMakeLists.txt10
-rw-r--r--source/blender/python/generic/bgl.c66
-rw-r--r--source/blender/python/intern/bpy_interface.c2
3 files changed, 50 insertions, 28 deletions
diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt
index dfca528e758..69bcfdfae4e 100644
--- a/source/blender/python/generic/CMakeLists.txt
+++ b/source/blender/python/generic/CMakeLists.txt
@@ -17,6 +17,7 @@ set(INC_SYS
)
set(SRC
+ bgl.c
bl_math_py_api.c
blf_py_api.c
bpy_threads.c
@@ -26,6 +27,7 @@ set(SRC
py_capi_rna.c
py_capi_utils.c
+ bgl.h
bl_math_py_api.h
blf_py_api.h
idprop_py_api.h
@@ -38,14 +40,6 @@ set(SRC
python_utildefines.h
)
-if(WITH_OPENGL)
- list(APPEND SRC
- bgl.c
-
- bgl.h
- )
-endif()
-
set(LIB
${GLEW_LIBRARY}
${PYTHON_LINKFLAGS}
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 92ed0c51b1f..f5c1f060e80 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -1082,18 +1082,34 @@ static PyObject *Buffer_repr(Buffer *self)
/** \name OpenGL API Wrapping
* \{ */
-#define BGL_Wrap(funcname, ret, arg_list) \
- static PyObject *Method_##funcname(PyObject *UNUSED(self), PyObject *args) \
- { \
- arg_def arg_list; \
- ret_def_##ret; \
- if (!PyArg_ParseTuple(args, arg_str arg_list, arg_ref arg_list)) { \
+#ifdef WITH_OPENGL
+# define BGL_Wrap(funcname, ret, arg_list) \
+ static PyObject *Method_##funcname(PyObject *UNUSED(self), PyObject *args) \
+ { \
+ arg_def arg_list; \
+ ret_def_##ret; \
+ if (!PyArg_ParseTuple(args, arg_str arg_list, arg_ref arg_list)) { \
+ return NULL; \
+ } \
+ GPU_bgl_start(); \
+ ret_set_##ret gl##funcname(arg_var arg_list); \
+ ret_ret_##ret; \
+ }
+#else
+
+static void bgl_no_opengl_error(void)
+{
+ PyErr_SetString(PyExc_RuntimeError, "Built without OpenGL support");
+}
+
+# define BGL_Wrap(funcname, ret, arg_list) \
+ static PyObject *Method_##funcname(PyObject *UNUSED(self), PyObject *args) \
+ { \
+ (void)args; \
+ bgl_no_opengl_error(); \
return NULL; \
- } \
- GPU_bgl_start(); \
- ret_set_##ret gl##funcname(arg_var arg_list); \
- ret_ret_##ret; \
- }
+ }
+#endif
/* GL_VERSION_1_0 */
BGL_Wrap(BlendFunc, void, (GLenum, GLenum));
@@ -1421,12 +1437,22 @@ static void py_module_dict_add_method(PyObject *submodule,
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Waddress"
#endif
-#define PY_MOD_ADD_METHOD(func) \
- { \
- static PyMethodDef method_def = {"gl" #func, Method_##func, METH_VARARGS}; \
- py_module_dict_add_method(submodule, dict, &method_def, (gl##func != NULL)); \
- } \
- ((void)0)
+
+#ifdef WITH_OPENGL
+# define PY_MOD_ADD_METHOD(func) \
+ { \
+ static PyMethodDef method_def = {"gl" #func, Method_##func, METH_VARARGS}; \
+ py_module_dict_add_method(submodule, dict, &method_def, (gl##func != NULL)); \
+ } \
+ ((void)0)
+#else
+# define PY_MOD_ADD_METHOD(func) \
+ { \
+ static PyMethodDef method_def = {"gl" #func, Method_##func, METH_VARARGS}; \
+ py_module_dict_add_method(submodule, dict, &method_def, false); \
+ } \
+ ((void)0)
+#endif
static void init_bgl_version_1_0_methods(PyObject *submodule, PyObject *dict)
{
@@ -2620,9 +2646,13 @@ static PyObject *Method_ShaderSource(PyObject *UNUSED(self), PyObject *args)
return NULL;
}
+#ifdef WITH_OPENGL
glShaderSource(shader, 1, (const char **)&source, NULL);
-
Py_RETURN_NONE;
+#else
+ bgl_no_opengl_error();
+ return NULL;
+#endif
}
/** \} */
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 08dd5fe9cfc..939fa475344 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -259,9 +259,7 @@ static struct _inittab bpy_internal_modules[] = {
{"mathutils.kdtree", PyInit_mathutils_kdtree},
#endif
{"_bpy_path", BPyInit__bpy_path},
-#ifdef WITH_OPENGL
{"bgl", BPyInit_bgl},
-#endif
{"blf", BPyInit_blf},
{"bl_math", BPyInit_bl_math},
{"imbuf", BPyInit_imbuf},