Changeset View
Standalone View
source/blender/python/generic/bgl.c
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| /** \file | /** \file | ||||
| * \ingroup pygen | * \ingroup pygen | ||||
| * | * | ||||
| * This file is the 'bgl' module which wraps OpenGL functions and constants, | * This file is the 'bgl' module which wraps OpenGL functions and constants, | ||||
| * allowing script writers to make OpenGL calls in their Python scripts. | * allowing script writers to make OpenGL calls in their Python scripts. | ||||
| * | * | ||||
| * \note | * \note | ||||
| * This module is very similar to 'PyOpenGL' which could replace 'bgl' one day. | * This module is very similar to 'PyOpenGL' which could replace 'bgl' one day. | ||||
| */ | */ | ||||
| #include <Python.h> | #include <Python.h> | ||||
| #include "BLI_string.h" | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "GPU_context.h" | |||||
| #include "GPU_state.h" | #include "GPU_state.h" | ||||
| #include "BKE_global.h" | |||||
| #include "../generic/py_capi_utils.h" | #include "../generic/py_capi_utils.h" | ||||
| #include <epoxy/gl.h> | #include <epoxy/gl.h> | ||||
| #include "bgl.h" | #include "bgl.h" | ||||
| #include "CLG_log.h" | |||||
| static CLG_LogRef LOG = {"bgl"}; | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name Local utility defines for wrapping OpenGL | |||||
| * \{ */ | |||||
| static void report_deprecated_call(const char *function_name) | |||||
| { | |||||
| char message[256]; | |||||
| SNPRINTF(message, | |||||
| "'bgl.gl%s' is deprecated and will be removed in Blender 3.7. Report or update your " | |||||
| "script to use 'gpu' module.", | |||||
| function_name); | |||||
| CLOG_WARN(&LOG, "%s", message); | |||||
| PyErr_WarnEx(PyExc_DeprecationWarning, message, 1); | |||||
| } | |||||
| static void report_deprecated_call_to_user() | |||||
campbellbarton: Use `(void)`, to prevent `-Wstrict-prototypes` warning. | |||||
| { | |||||
| G.opengl_deprecation_usage_detected = true; | |||||
| } | |||||
| /** \} */ | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Local utility defines for wrapping OpenGL | /** \name Local utility defines for wrapping OpenGL | ||||
| * \{ */ | * \{ */ | ||||
| /* By golly George! It looks like fancy pants macro time! */ | /* By golly George! It looks like fancy pants macro time! */ | ||||
| /* TYPE_str is the string to pass to Py_ArgParse (for the format) */ | /* TYPE_str is the string to pass to Py_ArgParse (for the format) */ | ||||
| /* TYPE_var is the name to pass to the GL function */ | /* TYPE_var is the name to pass to the GL function */ | ||||
| ▲ Show 20 Lines • Show All 1,032 Lines • ▼ Show 20 Lines | |||||
| * \{ */ | * \{ */ | ||||
| #ifdef WITH_OPENGL | #ifdef WITH_OPENGL | ||||
| # define BGL_Wrap(funcname, ret, arg_list) \ | # define BGL_Wrap(funcname, ret, arg_list) \ | ||||
| static PyObject *Method_##funcname(PyObject *UNUSED(self), PyObject *args) \ | static PyObject *Method_##funcname(PyObject *UNUSED(self), PyObject *args) \ | ||||
| { \ | { \ | ||||
| arg_def arg_list; \ | arg_def arg_list; \ | ||||
| ret_def_##ret; \ | ret_def_##ret; \ | ||||
| report_deprecated_call(#funcname); \ | |||||
| const bool has_opengl_backend = GPU_backend_get_type() == GPU_BACKEND_OPENGL; \ | |||||
| if (!has_opengl_backend) { \ | |||||
Done Inline ActionsThe deprecated warning is often overlooked. mano-wii: The deprecated warning is often overlooked.
The error message cannot be ignored.
If we wanted… | |||||
Done Inline ActionsThis would still not show to the user on a mac. I believe the best option is to load sys.excepthook with a custom callback that reports back to the user. Still investigating how to do this via CPython jbakker: This would still not show to the user on a mac. I believe the best option is to load sys. | |||||
| report_deprecated_call_to_user(); \ | |||||
| Py_RETURN_NONE; \ | |||||
campbellbartonUnsubmitted Done Inline ActionsIs it possible to continue with the functions logic (even if the BGL call does nothing), as any function that is expected to return a non None value will error (although admittedly there aren't too many of these). campbellbarton: Is it possible to continue with the functions logic (even if the BGL call does nothing), as any… | |||||
jbakkerAuthorUnsubmitted Done Inline ActionsThe biggest issue is that on metal the opengl library isn't loaded, that will crash when continuing the logic. Adding logic to use the correct return type might be doable, For example -1 for integer types. Will have a look how to do this jbakker: The biggest issue is that on metal the opengl library isn't loaded, that will crash when… | |||||
| } \ | |||||
| if (!PyArg_ParseTuple(args, arg_str arg_list, arg_ref arg_list)) { \ | if (!PyArg_ParseTuple(args, arg_str arg_list, arg_ref arg_list)) { \ | ||||
| return NULL; \ | return NULL; \ | ||||
| } \ | } \ | ||||
| GPU_bgl_start(); \ | GPU_bgl_start(); \ | ||||
| ret_set_##ret gl##funcname(arg_var arg_list); \ | ret_set_##ret gl##funcname(arg_var arg_list); \ | ||||
| ret_ret_##ret; \ | ret_ret_##ret; \ | ||||
| } | } | ||||
| #else | #else | ||||
| ▲ Show 20 Lines • Show All 1,502 Lines • ▼ Show 20 Lines | PyObject *BPyInit_bgl(void) | ||||
| PyObject *submodule, *dict; | PyObject *submodule, *dict; | ||||
| submodule = PyModule_Create(&BGL_module_def); | submodule = PyModule_Create(&BGL_module_def); | ||||
| dict = PyModule_GetDict(submodule); | dict = PyModule_GetDict(submodule); | ||||
| if (PyType_Ready(&BGL_bufferType) < 0) { | if (PyType_Ready(&BGL_bufferType) < 0) { | ||||
| return NULL; /* should never happen */ | return NULL; /* should never happen */ | ||||
| } | } | ||||
| if (GPU_backend_get_type() != GPU_BACKEND_OPENGL) { | |||||
| CLOG_ERROR(&LOG, | |||||
| "'bgl' imported without an OpenGL backend. Please update your add-ons to use the " | |||||
| "'gpu' module. In Blender 3.7 'bgl' will be removed."); | |||||
| } | |||||
| PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType); | PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType); | ||||
| Py_INCREF((PyObject *)&BGL_bufferType); | Py_INCREF((PyObject *)&BGL_bufferType); | ||||
| init_bgl_version_1_0_methods(submodule, dict); | init_bgl_version_1_0_methods(submodule, dict); | ||||
| init_bgl_version_1_1_methods(submodule, dict); | init_bgl_version_1_1_methods(submodule, dict); | ||||
| init_bgl_version_1_2_methods(submodule, dict); | init_bgl_version_1_2_methods(submodule, dict); | ||||
| init_bgl_version_1_3_methods(submodule, dict); | init_bgl_version_1_3_methods(submodule, dict); | ||||
| init_bgl_version_1_4_methods(submodule, dict); | init_bgl_version_1_4_methods(submodule, dict); | ||||
| ▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines | |||||
Use (void), to prevent -Wstrict-prototypes warning.