diff options
Diffstat (limited to 'source/blender/python/gpu/gpu_py_uniformbuffer.c')
-rw-r--r-- | source/blender/python/gpu/gpu_py_uniformbuffer.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/source/blender/python/gpu/gpu_py_uniformbuffer.c b/source/blender/python/gpu/gpu_py_uniformbuffer.c index f5a0af860b4..f8f88d61cf6 100644 --- a/source/blender/python/gpu/gpu_py_uniformbuffer.c +++ b/source/blender/python/gpu/gpu_py_uniformbuffer.c @@ -64,26 +64,37 @@ static PyObject *pygpu_uniformbuffer__tp_new(PyTypeObject *UNUSED(self), BPYGPU_IS_INIT_OR_ERROR_OBJ; GPUUniformBuf *ubo = NULL; - BPyGPUBuffer *pybuffer_obj; + PyObject *pybuffer_obj; char err_out[256] = "unknown error. See console"; static const char *_keywords[] = {"data", NULL}; static _PyArg_Parser _parser = { - "O!" /* `data` */ + "O" /* `data` */ ":GPUUniformBuf.__new__", _keywords, 0, }; - if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &BPyGPU_BufferType, &pybuffer_obj)) { + if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &pybuffer_obj)) { return NULL; } - if (GPU_context_active_get()) { - ubo = GPU_uniformbuf_create_ex( - bpygpu_Buffer_size(pybuffer_obj), pybuffer_obj->buf.as_void, "python_uniformbuffer"); + if (!GPU_context_active_get()) { + STRNCPY(err_out, "No active GPU context found"); } else { - STRNCPY(err_out, "No active GPU context found"); + Py_buffer pybuffer; + if (PyObject_GetBuffer(pybuffer_obj, &pybuffer, PyBUF_SIMPLE) == -1) { + /* PyObject_GetBuffer raise a PyExc_BufferError */ + return NULL; + } + + if ((pybuffer.len % 16) != 0) { + STRNCPY(err_out, "UBO is not padded to size of vec4"); + } + else { + ubo = GPU_uniformbuf_create_ex(pybuffer.len, pybuffer.buf, "python_uniformbuffer"); + } + PyBuffer_Release(&pybuffer); } if (ubo == NULL) { @@ -102,11 +113,14 @@ static PyObject *pygpu_uniformbuffer_update(BPyGPUUniformBuf *self, PyObject *ob { BPYGPU_UNIFORMBUF_CHECK_OBJ(self); - if (!BPyGPU_Buffer_Check(obj)) { + Py_buffer pybuffer; + if (PyObject_GetBuffer(obj, &pybuffer, PyBUF_SIMPLE) == -1) { + /* PyObject_GetBuffer raise a PyExc_BufferError */ return NULL; } - GPU_uniformbuf_update(self->ubo, ((BPyGPUBuffer *)obj)->buf.as_void); + GPU_uniformbuf_update(self->ubo, pybuffer.buf); + PyBuffer_Release(&pybuffer); Py_RETURN_NONE; } @@ -151,8 +165,8 @@ PyDoc_STRVAR(pygpu_uniformbuffer__tp_doc, "\n" " This object gives access to off uniform buffers.\n" "\n" - " :arg data: Buffer object.\n" - " :type data: :class:`gpu.types.Buffer`\n"); + " :arg data: Data to fill the buffer.\n" + " :type data: object exposing buffer interface\n"); PyTypeObject BPyGPUUniformBuf_Type = { PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUUniformBuf", .tp_basicsize = sizeof(BPyGPUUniformBuf), |