diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-26 21:48:44 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-26 21:56:43 +0300 |
commit | 85915ae1aad761fc79eccf005e68a2334ad6b81c (patch) | |
tree | 2e29e8464de59e838c329e7c7579f51e71125a85 /source/blender/python/generic/bgl.c | |
parent | c515ea2e93b02674a6d847f1a3851194f5bb9aa2 (diff) |
Python API: allow passing None to some BGL functions instead of bgl.Buffer
Many OpenGL functions take NULL pointers, passing those was quite complicated
with some addons even using ctypes to manipulate internal bgl.Buffer pointers.
Diffstat (limited to 'source/blender/python/generic/bgl.c')
-rw-r--r-- | source/blender/python/generic/bgl.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 08280248649..13342b7dac8 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -132,9 +132,9 @@ #define GLclampfP_def(number) Buffer *bgl_buffer##number #endif -#define GLvoidP_str "O!" -#define GLvoidP_var(number) (bgl_buffer##number)->buf.asvoid -#define GLvoidP_ref(number) &BGL_bufferType, &bgl_buffer##number +#define GLvoidP_str "O&" +#define GLvoidP_var(number) ((bgl_buffer##number) ? (bgl_buffer##number)->buf.asvoid : NULL) +#define GLvoidP_ref(number) BGL_BufferOrNoneConverter, &bgl_buffer##number #define GLvoidP_def(number) Buffer *bgl_buffer##number #define GLsizeiP_str "O!" @@ -703,6 +703,22 @@ Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuf return buffer; } +/* Custom converter function so we can support a buffer or NULL. */ +static int BGL_BufferOrNoneConverter(PyObject *object, Buffer **buffer) +{ + if (object == Py_None) { + *buffer = NULL; + return 1; + } + else if (PyObject_TypeCheck(object, &BGL_bufferType)) { + *buffer = (Buffer *)object; + return 1; + } + else { + PyErr_SetString(PyExc_TypeError, "expected a bgl.Buffer or None"); + return 0; + } +} #define MAX_DIMENSIONS 256 static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) |