diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2018-08-12 14:59:39 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2018-08-12 14:59:39 +0300 |
commit | b8ab411185c11ce98e7e791b0d30a9d9b1ce6d69 (patch) | |
tree | 9c219e06fc6a1f9b09d6fbf7d86c8526cfa6d775 /source/blender/python | |
parent | 209686f1c8189bc01f91d14a922651844df8b201 (diff) | |
parent | dc2d841b7c50565302af2986d62ddbd29c332acd (diff) |
Merge branch 'hair_guides' into hair_guides_groominghair_guides_grooming
Diffstat (limited to 'source/blender/python')
20 files changed, 774 insertions, 421 deletions
diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/CMakeLists.txt index 8d26fee0abd..030576fefd1 100644 --- a/source/blender/python/CMakeLists.txt +++ b/source/blender/python/CMakeLists.txt @@ -17,7 +17,7 @@ # ***** END GPL LICENSE BLOCK ***** add_subdirectory(intern) -add_subdirectory(gawain) add_subdirectory(generic) +add_subdirectory(gpu) add_subdirectory(mathutils) add_subdirectory(bmesh) diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c index 4e55495a0cd..62981798b1a 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c @@ -192,7 +192,7 @@ static int bpy_bmvertskin_radius_set(BPy_BMVertSkin *self, PyObject *value, void } PyDoc_STRVAR(bpy_bmvertskin_flag__use_root_doc, -"Use as root vertex.\n\n:type: boolean" +"Use as root vertex. Setting this flag does not clear other roots in the same mesh island.\n\n:type: boolean" ); PyDoc_STRVAR(bpy_bmvertskin_flag__use_loose_doc, "Use loose vertex.\n\n:type: boolean" @@ -221,17 +221,16 @@ static int bpy_bmvertskin_flag_set(BPy_BMVertSkin *self, PyObject *value, void * } } -/* XXX Todo: Make root settable, currently the code to disable all other verts as roots sits within the modifier */ static PyGetSetDef bpy_bmvertskin_getseters[] = { /* attributes match rna_mesh_gen */ {(char *)"radius", (getter)bpy_bmvertskin_radius_get, (setter)bpy_bmvertskin_radius_set, (char *)bpy_bmvertskin_radius_doc, NULL}, - {(char *)"use_root", (getter)bpy_bmvertskin_flag_get, (setter)NULL, (char *)bpy_bmvertskin_flag__use_root_doc, (void *)MVERT_SKIN_ROOT}, + {(char *)"use_root", (getter)bpy_bmvertskin_flag_get, (setter)bpy_bmvertskin_flag_set, (char *)bpy_bmvertskin_flag__use_root_doc, (void *)MVERT_SKIN_ROOT}, {(char *)"use_loose", (getter)bpy_bmvertskin_flag_get, (setter)bpy_bmvertskin_flag_set, (char *)bpy_bmvertskin_flag__use_loose_doc, (void *)MVERT_SKIN_LOOSE}, {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; -static PyTypeObject BPy_BMVertSkin_Type; /* bm.loops.layers.uv.active */ +static PyTypeObject BPy_BMVertSkin_Type; /* bm.loops.layers.skin.active */ static void bm_init_types_bmvertskin(void) { diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c index d0f708b7e3c..71812466477 100644 --- a/source/blender/python/generic/blf_py_api.c +++ b/source/blender/python/generic/blf_py_api.c @@ -500,6 +500,7 @@ PyObject *BPyInit_blf(void) PyModule_AddIntConstant(submodule, "SHADOW", BLF_SHADOW); PyModule_AddIntConstant(submodule, "KERNING_DEFAULT", BLF_KERNING_DEFAULT); PyModule_AddIntConstant(submodule, "WORD_WRAP", BLF_WORD_WRAP); + PyModule_AddIntConstant(submodule, "MONOCHROME", BLF_MONOCHROME); return submodule; } diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c index 4b56d4412e6..4d4d5232800 100644 --- a/source/blender/python/generic/idprop_py_api.c +++ b/source/blender/python/generic/idprop_py_api.c @@ -596,15 +596,15 @@ static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob) return prop; } -static IDProperty *idp_from_DatablockPointer(const char *name, PyObject *ob, IDPropertyTemplate *val) +static IDProperty *idp_from_DatablockPointer(const char *name, PyObject *ob) { - pyrna_id_FromPyObject(ob, &val->id); - return IDP_New(IDP_ID, val, name); + IDPropertyTemplate val = {0}; + pyrna_id_FromPyObject(ob, &val.id); + return IDP_New(IDP_ID, &val, name); } static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob) { - IDPropertyTemplate val = {0}; const char *name = idp_try_read_name(name_obj); if (name == NULL) { return NULL; @@ -626,7 +626,7 @@ static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob) return idp_from_PySequence(name, ob); } else if (ob == Py_None || pyrna_id_CheckPyObject(ob)) { - return idp_from_DatablockPointer(name, ob, &val); + return idp_from_DatablockPointer(name, ob); } else if (PyMapping_Check(ob)) { return idp_from_PyMapping(name, ob); diff --git a/source/blender/python/generic/imbuf_py_api.h b/source/blender/python/generic/imbuf_py_api.h index 92c1732a9c9..35adc541bfc 100644 --- a/source/blender/python/generic/imbuf_py_api.h +++ b/source/blender/python/generic/imbuf_py_api.h @@ -27,4 +27,6 @@ PyObject *BPyInit_imbuf(void); +extern PyTypeObject Py_ImBuf_Type; + #endif /* __IMBUF_PY_API_H__ */ diff --git a/source/blender/python/gawain/CMakeLists.txt b/source/blender/python/gpu/CMakeLists.txt index 9eab323a0fe..141a36bbcc2 100644 --- a/source/blender/python/gawain/CMakeLists.txt +++ b/source/blender/python/gpu/CMakeLists.txt @@ -24,7 +24,6 @@ set(INC ../../blenlib ../../gpu ../../makesdna - ../../../../intern/gawain ../../../../intern/guardedalloc ../../../../intern/glew-mx ) @@ -35,13 +34,13 @@ set(INC_SYS ) set(SRC - gwn_py_api.c - gwn_py_types.c + gpu_py_api.c + gpu_py_types.c - gwn_py_api.h - gwn_py_types.h + gpu_py_api.h + gpu_py_types.h ) add_definitions(${GL_DEFINITIONS}) -blender_add_lib(bf_python_gawain "${SRC}" "${INC}" "${INC_SYS}") +blender_add_lib(bf_python_gpu "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/python/gawain/gwn_py_api.c b/source/blender/python/gpu/gpu_py_api.c index d79ef070649..53285b372d8 100644 --- a/source/blender/python/gawain/gwn_py_api.c +++ b/source/blender/python/gpu/gpu_py_api.c @@ -18,44 +18,44 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/python/gawain/gwn_py_api.c - * \ingroup pygawain +/** \file blender/python/gpu/gpu_py_api.c + * \ingroup pygpu * - * Experimental Python API, not considered public yet (called '_gawain'), + * Experimental Python API, not considered public yet (called '_gpu'), * we may re-expose as public later. */ #include <Python.h> -#include "gawain/gwn_batch.h" -#include "gawain/gwn_vertex_format.h" +#include "GPU_batch.h" +#include "GPU_vertex_format.h" -#include "gwn_py_api.h" -#include "gwn_py_types.h" +#include "gpu_py_api.h" +#include "gpu_py_types.h" #include "BLI_utildefines.h" #include "../generic/python_utildefines.h" -PyDoc_STRVAR(GWN_doc, -"This module provides access to gawain drawing functions." +PyDoc_STRVAR(GPU_doc, +"This module provides access to gpu drawing functions." ); -static struct PyModuleDef GWN_module_def = { +static struct PyModuleDef GPU_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "_gawain", /* m_name */ - .m_doc = GWN_doc, /* m_doc */ + .m_name = "_gpu", /* m_name */ + .m_doc = GPU_doc, /* m_doc */ }; -PyObject *BPyInit_gawain(void) +PyObject *BPyInit_gpu(void) { PyObject *sys_modules = PyThreadState_GET()->interp->modules; PyObject *submodule; PyObject *mod; - mod = PyModule_Create(&GWN_module_def); + mod = PyModule_Create(&GPU_module_def); - /* _gawain.types */ - PyModule_AddObject(mod, "types", (submodule = BPyInit_gawain_types())); + /* _gpu.types */ + PyModule_AddObject(mod, "types", (submodule = BPyInit_gpu_types())); PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); Py_INCREF(submodule); diff --git a/source/blender/python/gawain/gwn_py_api.h b/source/blender/python/gpu/gpu_py_api.h index 3ef85e8ae0f..387bfcab950 100644 --- a/source/blender/python/gawain/gwn_py_api.h +++ b/source/blender/python/gpu/gpu_py_api.h @@ -18,13 +18,13 @@ * ***** END GPL LICENSE BLOCK ***** */ -#ifndef __GWN_PY_API_H__ -#define __GWN_PY_API_H__ +#ifndef __GPU_PY_API_H__ +#define __GPU_PY_API_H__ -/** \file blender/python/gawain/gwn_py_api.h - * \ingroup pygawain +/** \file blender/python/gpu/gpu_py_api.h + * \ingroup pygpu */ -PyObject *BPyInit_gawain(void); +PyObject *BPyInit_gpu(void); -#endif /* __GWN_PY_API_H__ */ +#endif /* __GPU_PY_API_H__ */ diff --git a/source/blender/python/gawain/gwn_py_types.c b/source/blender/python/gpu/gpu_py_types.c index bdf0be9f7e1..4e564fdf849 100644 --- a/source/blender/python/gawain/gwn_py_types.c +++ b/source/blender/python/gpu/gpu_py_types.c @@ -18,28 +18,26 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/python/gawain/gwn_py_types.c - * \ingroup pygawain +/** \file blender/python/gpu/gpu_py_types.c + * \ingroup pygpu * - * - Use ``bpygwn_`` for local API. - * - Use ``BPyGwn_`` for public API. + * - Use ``bpygpu_`` for local API. + * - Use ``BPyGPU`` for public API. */ #include <Python.h> -#include "gawain/gwn_batch.h" -#include "gawain/gwn_vertex_format.h" +#include "GPU_batch.h" +#include "GPU_vertex_format.h" #include "BLI_math.h" -#include "GPU_batch.h" - #include "MEM_guardedalloc.h" #include "../generic/py_capi_utils.h" #include "../generic/python_utildefines.h" -#include "gwn_py_types.h" /* own include */ +#include "gpu_py_types.h" /* own include */ #ifdef __BIG_ENDIAN__ /* big endian */ @@ -60,7 +58,7 @@ * Use with PyArg_ParseTuple's "O&" formatting. * \{ */ -static int bpygwn_ParseVertCompType(PyObject *o, void *p) +static int bpygpu_ParseVertCompType(PyObject *o, void *p) { Py_ssize_t comp_type_id_len; const char *comp_type_id = _PyUnicode_AsStringAndSize(o, &comp_type_id_len); @@ -71,21 +69,21 @@ static int bpygwn_ParseVertCompType(PyObject *o, void *p) return 0; } - Gwn_VertCompType comp_type; + GPUVertCompType comp_type; if (comp_type_id_len == 2) { switch (*((ushort *)comp_type_id)) { - case MAKE_ID2('I', '8'): { comp_type = GWN_COMP_I8; goto success; } - case MAKE_ID2('U', '8'): { comp_type = GWN_COMP_U8; goto success; } + case MAKE_ID2('I', '8'): { comp_type = GPU_COMP_I8; goto success; } + case MAKE_ID2('U', '8'): { comp_type = GPU_COMP_U8; goto success; } } } else if (comp_type_id_len == 3) { switch (*((uint *)comp_type_id)) { - case MAKE_ID3('I', '1', '6'): { comp_type = GWN_COMP_I16; goto success; } - case MAKE_ID3('U', '1', '6'): { comp_type = GWN_COMP_U16; goto success; } - case MAKE_ID3('I', '3', '2'): { comp_type = GWN_COMP_I32; goto success; } - case MAKE_ID3('U', '3', '2'): { comp_type = GWN_COMP_U32; goto success; } - case MAKE_ID3('F', '3', '2'): { comp_type = GWN_COMP_F32; goto success; } - case MAKE_ID3('I', '1', '0'): { comp_type = GWN_COMP_I10; goto success; } + case MAKE_ID3('I', '1', '6'): { comp_type = GPU_COMP_I16; goto success; } + case MAKE_ID3('U', '1', '6'): { comp_type = GPU_COMP_U16; goto success; } + case MAKE_ID3('I', '3', '2'): { comp_type = GPU_COMP_I32; goto success; } + case MAKE_ID3('U', '3', '2'): { comp_type = GPU_COMP_U32; goto success; } + case MAKE_ID3('F', '3', '2'): { comp_type = GPU_COMP_F32; goto success; } + case MAKE_ID3('I', '1', '0'): { comp_type = GPU_COMP_I10; goto success; } } } @@ -95,11 +93,11 @@ static int bpygwn_ParseVertCompType(PyObject *o, void *p) return 0; success: - *((Gwn_VertCompType *)p) = comp_type; + *((GPUVertCompType *)p) = comp_type; return 1; } -static int bpygwn_ParseVertFetchMode(PyObject *o, void *p) +static int bpygpu_ParseVertFetchMode(PyObject *o, void *p) { Py_ssize_t mode_id_len; const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len); @@ -112,12 +110,12 @@ static int bpygwn_ParseVertFetchMode(PyObject *o, void *p) #define MATCH_ID(id) \ if (mode_id_len == strlen(STRINGIFY(id))) { \ if (STREQ(mode_id, STRINGIFY(id))) { \ - mode = GWN_FETCH_##id; \ + mode = GPU_FETCH_##id; \ goto success; \ } \ } ((void)0) - Gwn_VertFetchMode mode; + GPUVertFetchMode mode; MATCH_ID(FLOAT); MATCH_ID(INT); MATCH_ID(INT_TO_FLOAT_UNIT); @@ -129,11 +127,11 @@ static int bpygwn_ParseVertFetchMode(PyObject *o, void *p) return 0; success: - (*(Gwn_VertFetchMode *)p) = mode; + (*(GPUVertFetchMode *)p) = mode; return 1; } -static int bpygwn_ParsePrimType(PyObject *o, void *p) +static int bpygpu_ParsePrimType(PyObject *o, void *p) { Py_ssize_t mode_id_len; const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len); @@ -146,12 +144,12 @@ static int bpygwn_ParsePrimType(PyObject *o, void *p) #define MATCH_ID(id) \ if (mode_id_len == strlen(STRINGIFY(id))) { \ if (STREQ(mode_id, STRINGIFY(id))) { \ - mode = GWN_PRIM_##id; \ + mode = GPU_PRIM_##id; \ goto success; \ } \ } ((void)0) - Gwn_PrimType mode; + GPUPrimType mode; MATCH_ID(POINTS); MATCH_ID(LINES); MATCH_ID(TRIS); @@ -168,7 +166,7 @@ static int bpygwn_ParsePrimType(PyObject *o, void *p) return 0; success: - (*(Gwn_PrimType *)p) = mode; + (*(GPUPrimType *)p) = mode; return 1; } @@ -182,19 +180,19 @@ success: #define PY_AS_NATIVE_SWITCH(attr) \ switch (attr->comp_type) { \ - case GWN_COMP_I8: { PY_AS_NATIVE(int8_t, PyC_Long_AsI8); break; } \ - case GWN_COMP_U8: { PY_AS_NATIVE(uint8_t, PyC_Long_AsU8); break; } \ - case GWN_COMP_I16: { PY_AS_NATIVE(int16_t, PyC_Long_AsI16); break; } \ - case GWN_COMP_U16: { PY_AS_NATIVE(uint16_t, PyC_Long_AsU16); break; } \ - case GWN_COMP_I32: { PY_AS_NATIVE(int32_t, PyC_Long_AsI32); break; } \ - case GWN_COMP_U32: { PY_AS_NATIVE(uint32_t, PyC_Long_AsU32); break; } \ - case GWN_COMP_F32: { PY_AS_NATIVE(float, PyFloat_AsDouble); break; } \ + case GPU_COMP_I8: { PY_AS_NATIVE(int8_t, PyC_Long_AsI8); break; } \ + case GPU_COMP_U8: { PY_AS_NATIVE(uint8_t, PyC_Long_AsU8); break; } \ + case GPU_COMP_I16: { PY_AS_NATIVE(int16_t, PyC_Long_AsI16); break; } \ + case GPU_COMP_U16: { PY_AS_NATIVE(uint16_t, PyC_Long_AsU16); break; } \ + case GPU_COMP_I32: { PY_AS_NATIVE(int32_t, PyC_Long_AsI32); break; } \ + case GPU_COMP_U32: { PY_AS_NATIVE(uint32_t, PyC_Long_AsU32); break; } \ + case GPU_COMP_F32: { PY_AS_NATIVE(float, PyFloat_AsDouble); break; } \ default: \ BLI_assert(0); \ } ((void)0) /* No error checking, callers must run PyErr_Occurred */ -static void fill_format_elem(void *data_dst_void, PyObject *py_src, const Gwn_VertAttr *attr) +static void fill_format_elem(void *data_dst_void, PyObject *py_src, const GPUVertAttr *attr) { #define PY_AS_NATIVE(ty_dst, py_as_native) \ { \ @@ -208,7 +206,7 @@ static void fill_format_elem(void *data_dst_void, PyObject *py_src, const Gwn_Ve } /* No error checking, callers must run PyErr_Occurred */ -static void fill_format_tuple(void *data_dst_void, PyObject *py_src, const Gwn_VertAttr *attr) +static void fill_format_tuple(void *data_dst_void, PyObject *py_src, const GPUVertAttr *attr) { const uint len = attr->comp_len; @@ -230,15 +228,15 @@ static void fill_format_tuple(void *data_dst_void, PyObject *py_src, const Gwn_V #undef WARN_TYPE_LIMIT_PUSH #undef WARN_TYPE_LIMIT_POP -static bool bpygwn_vertbuf_fill_impl( - Gwn_VertBuf *vbo, +static bool bpygpu_vertbuf_fill_impl( + GPUVertBuf *vbo, uint data_id, PyObject *seq) { bool ok = true; - const Gwn_VertAttr *attr = &vbo->format.attribs[data_id]; + const GPUVertAttr *attr = &vbo->format.attribs[data_id]; - Gwn_VertBufRaw data_step; - GWN_vertbuf_attr_get_raw_data(vbo, data_id, &data_step); + GPUVertBufRaw data_step; + GPU_vertbuf_attr_get_raw_data(vbo, data_id, &data_step); PyObject *seq_fast = PySequence_Fast(seq, "Vertex buffer fill"); if (seq_fast == NULL) { @@ -257,14 +255,14 @@ static bool bpygwn_vertbuf_fill_impl( if (attr->comp_len == 1) { for (uint i = 0; i < seq_len; i++) { - uchar *data = (uchar *)GWN_vertbuf_raw_step(&data_step); + uchar *data = (uchar *)GPU_vertbuf_raw_step(&data_step); PyObject *item = seq_items[i]; fill_format_elem(data, item, attr); } } else { for (uint i = 0; i < seq_len; i++) { - uchar *data = (uchar *)GWN_vertbuf_raw_step(&data_step); + uchar *data = (uchar *)GPU_vertbuf_raw_step(&data_step); PyObject *item = seq_items[i]; if (!PyTuple_CheckExact(item)) { PyErr_Format(PyExc_ValueError, @@ -298,7 +296,7 @@ finally: /* handy, but not used just now */ #if 0 -static int bpygwn_find_id(const Gwn_VertFormat *fmt, const char *id) +static int bpygpu_find_id(const GPUVertFormat *fmt, const char *id) { for (int i = 0; i < fmt->attr_len; i++) { for (uint j = 0; j < fmt->name_len; j++) { @@ -319,7 +317,7 @@ static int bpygwn_find_id(const Gwn_VertFormat *fmt, const char *id) /** \name VertFormat Type * \{ */ -static PyObject *bpygwn_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) +static PyObject *bpygpu_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) { if (PyTuple_GET_SIZE(args) || (kwds && PyDict_Size(kwds))) { PyErr_SetString(PyExc_TypeError, @@ -327,64 +325,64 @@ static PyObject *bpygwn_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *arg return NULL; } - BPyGwn_VertFormat *ret = (BPyGwn_VertFormat *)BPyGwn_VertFormat_CreatePyObject(NULL); + BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(NULL); return (PyObject *)ret; } -PyDoc_STRVAR(bpygwn_VertFormat_attr_add_doc, +PyDoc_STRVAR(bpygpu_VertFormat_attr_add_doc, "TODO" ); -static PyObject *bpygwn_VertFormat_attr_add(BPyGwn_VertFormat *self, PyObject *args, PyObject *kwds) +static PyObject *bpygpu_VertFormat_attr_add(BPyGPUVertFormat *self, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"id", "comp_type", "len", "fetch_mode", NULL}; struct { const char *id; - Gwn_VertCompType comp_type; + GPUVertCompType comp_type; uint len; - Gwn_VertFetchMode fetch_mode; + GPUVertFetchMode fetch_mode; } params; - if (self->fmt.attr_len == GWN_VERT_ATTR_MAX_LEN) { - PyErr_SetString(PyExc_ValueError, "Maxumum attr reached " STRINGIFY(GWN_VERT_ATTR_MAX_LEN)); + if (self->fmt.attr_len == GPU_VERT_ATTR_MAX_LEN) { + PyErr_SetString(PyExc_ValueError, "Maxumum attr reached " STRINGIFY(GPU_VERT_ATTR_MAX_LEN)); return NULL; } if (!PyArg_ParseTupleAndKeywords( args, kwds, "$sO&IO&:attr_add", (char **)kwlist, ¶ms.id, - bpygwn_ParseVertCompType, ¶ms.comp_type, + bpygpu_ParseVertCompType, ¶ms.comp_type, ¶ms.len, - bpygwn_ParseVertFetchMode, ¶ms.fetch_mode)) + bpygpu_ParseVertFetchMode, ¶ms.fetch_mode)) { return NULL; } - uint attr_id = GWN_vertformat_attr_add(&self->fmt, params.id, params.comp_type, params.len, params.fetch_mode); + uint attr_id = GPU_vertformat_attr_add(&self->fmt, params.id, params.comp_type, params.len, params.fetch_mode); return PyLong_FromLong(attr_id); } -static struct PyMethodDef bpygwn_VertFormat_methods[] = { - {"attr_add", (PyCFunction)bpygwn_VertFormat_attr_add, - METH_VARARGS | METH_KEYWORDS, bpygwn_VertFormat_attr_add_doc}, +static struct PyMethodDef bpygpu_VertFormat_methods[] = { + {"attr_add", (PyCFunction)bpygpu_VertFormat_attr_add, + METH_VARARGS | METH_KEYWORDS, bpygpu_VertFormat_attr_add_doc}, {NULL, NULL, 0, NULL} }; -static void bpygwn_VertFormat_dealloc(BPyGwn_VertFormat *self) +static void bpygpu_VertFormat_dealloc(BPyGPUVertFormat *self) { Py_TYPE(self)->tp_free(self); } -PyTypeObject BPyGwn_VertFormat_Type = { +PyTypeObject BPyGPUVertFormat_Type = { PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "Gwn_VertFormat", - .tp_basicsize = sizeof(BPyGwn_VertFormat), - .tp_dealloc = (destructor)bpygwn_VertFormat_dealloc, + .tp_name = "GPUVertFormat", + .tp_basicsize = sizeof(BPyGPUVertFormat), + .tp_dealloc = (destructor)bpygpu_VertFormat_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_methods = bpygwn_VertFormat_methods, - .tp_new = bpygwn_VertFormat_new, + .tp_methods = bpygpu_VertFormat_methods, + .tp_new = bpygpu_VertFormat_new, }; /** \} */ @@ -395,35 +393,35 @@ PyTypeObject BPyGwn_VertFormat_Type = { /** \name VertBuf Type * \{ */ -static PyObject *bpygwn_VertBuf_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) +static PyObject *bpygpu_VertBuf_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) { const char * const keywords[] = {"len", "format", NULL}; struct { - BPyGwn_VertFormat *py_fmt; + BPyGPUVertFormat *py_fmt; uint len; } params; if (!PyArg_ParseTupleAndKeywords( args, kwds, - "$IO!:Gwn_VertBuf.__new__", (char **)keywords, + "$IO!:GPUVertBuf.__new__", (char **)keywords, ¶ms.len, - &BPyGwn_VertFormat_Type, ¶ms.py_fmt)) + &BPyGPUVertFormat_Type, ¶ms.py_fmt)) { return NULL; } - struct Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(¶ms.py_fmt->fmt); + struct GPUVertBuf *vbo = GPU_vertbuf_create_with_format(¶ms.py_fmt->fmt); - GWN_vertbuf_data_alloc(vbo, params.len); + GPU_vertbuf_data_alloc(vbo, params.len); - return BPyGwn_VertBuf_CreatePyObject(vbo); + return BPyGPUVertBuf_CreatePyObject(vbo); } -PyDoc_STRVAR(bpygwn_VertBuf_fill_doc, +PyDoc_STRVAR(bpygpu_VertBuf_fill_doc, "TODO" ); -static PyObject *bpygwn_VertBuf_fill(BPyGwn_VertBuf *self, PyObject *args, PyObject *kwds) +static PyObject *bpygpu_VertBuf_fill(BPyGPUVertBuf *self, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"id", "data", NULL}; @@ -453,32 +451,32 @@ static PyObject *bpygwn_VertBuf_fill(BPyGwn_VertBuf *self, PyObject *args, PyObj return NULL; } - if (!bpygwn_vertbuf_fill_impl(self->buf, params.id, params.py_seq_data)) { + if (!bpygpu_vertbuf_fill_impl(self->buf, params.id, params.py_seq_data)) { return NULL; } Py_RETURN_NONE; } -static struct PyMethodDef bpygwn_VertBuf_methods[] = { - {"fill", (PyCFunction) bpygwn_VertBuf_fill, - METH_VARARGS | METH_KEYWORDS, bpygwn_VertBuf_fill_doc}, +static struct PyMethodDef bpygpu_VertBuf_methods[] = { + {"fill", (PyCFunction) bpygpu_VertBuf_fill, + METH_VARARGS | METH_KEYWORDS, bpygpu_VertBuf_fill_doc}, {NULL, NULL, 0, NULL} }; -static void bpygwn_VertBuf_dealloc(BPyGwn_VertBuf *self) +static void bpygpu_VertBuf_dealloc(BPyGPUVertBuf *self) { - GWN_vertbuf_discard(self->buf); + GPU_vertbuf_discard(self->buf); Py_TYPE(self)->tp_free(self); } -PyTypeObject BPyGwn_VertBuf_Type = { +PyTypeObject BPyGPUVertBuf_Type = { PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "Gwn_VertBuf", - .tp_basicsize = sizeof(BPyGwn_VertBuf), - .tp_dealloc = (destructor)bpygwn_VertBuf_dealloc, + .tp_name = "GPUVertBuf", + .tp_basicsize = sizeof(BPyGPUVertBuf), + .tp_dealloc = (destructor)bpygpu_VertBuf_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, - .tp_methods = bpygwn_VertBuf_methods, - .tp_new = bpygwn_VertBuf_new, + .tp_methods = bpygpu_VertBuf_methods, + .tp_new = bpygpu_VertBuf_new, }; /** \} */ @@ -489,28 +487,28 @@ PyTypeObject BPyGwn_VertBuf_Type = { /** \name VertBatch Type * \{ */ -static PyObject *bpygwn_Batch_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) +static PyObject *bpygpu_Batch_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) { const char * const keywords[] = {"type", "buf", NULL}; struct { - Gwn_PrimType type_id; - BPyGwn_VertBuf *py_buf; + GPUPrimType type_id; + BPyGPUVertBuf *py_buf; } params; if (!PyArg_ParseTupleAndKeywords( args, kwds, - "$O&O!:Gwn_Batch.__new__", (char **)keywords, - bpygwn_ParsePrimType, ¶ms.type_id, - &BPyGwn_VertBuf_Type, ¶ms.py_buf)) + "$O&O!:GPUBatch.__new__", (char **)keywords, + bpygpu_ParsePrimType, ¶ms.type_id, + &BPyGPUVertBuf_Type, ¶ms.py_buf)) { return NULL; } - Gwn_Batch *batch = GWN_batch_create(params.type_id, params.py_buf->buf, NULL); - BPyGwn_Batch *ret = (BPyGwn_Batch *)BPyGwn_Batch_CreatePyObject(batch); + GPUBatch *batch = GPU_batch_create(params.type_id, params.py_buf->buf, NULL); + BPyGPUBatch *ret = (BPyGPUBatch *)BPyGPUBatch_CreatePyObject(batch); -#ifdef USE_GWN_PY_REFERENCES +#ifdef USE_GPU_PY_REFERENCES ret->references = PyList_New(1); PyList_SET_ITEM(ret->references, 0, (PyObject *)params.py_buf); Py_INCREF(params.py_buf); @@ -520,14 +518,14 @@ static PyObject *bpygwn_Batch_new(PyTypeObject *UNUSED(type), PyObject *args, Py return (PyObject *)ret; } -PyDoc_STRVAR(bpygwn_VertBatch_vertbuf_add_doc, +PyDoc_STRVAR(bpygpu_VertBatch_vertbuf_add_doc, "TODO" ); -static PyObject *bpygwn_VertBatch_vertbuf_add(BPyGwn_Batch *self, BPyGwn_VertBuf *py_buf) +static PyObject *bpygpu_VertBatch_vertbuf_add(BPyGPUBatch *self, BPyGPUVertBuf *py_buf) { - if (!BPyGwn_VertBuf_Check(py_buf)) { + if (!BPyGPUVertBuf_Check(py_buf)) { PyErr_Format(PyExc_TypeError, - "Expected a Gwn_VertBuf, got %s", + "Expected a GPUVertBuf, got %s", Py_TYPE(py_buf)->tp_name); return NULL; } @@ -539,20 +537,20 @@ static PyObject *bpygwn_VertBatch_vertbuf_add(BPyGwn_Batch *self, BPyGwn_VertBuf return NULL; } -#ifdef USE_GWN_PY_REFERENCES +#ifdef USE_GPU_PY_REFERENCES /* Hold user */ PyList_Append(self->references, (PyObject *)py_buf); #endif - GWN_batch_vertbuf_add(self->batch, py_buf->buf); + GPU_batch_vertbuf_add(self->batch, py_buf->buf); Py_RETURN_NONE; } /* Currently magic number from Py perspective. */ -PyDoc_STRVAR(bpygwn_VertBatch_program_set_builtin_doc, +PyDoc_STRVAR(bpygpu_VertBatch_program_set_builtin_doc, "TODO" ); -static PyObject *bpygwn_VertBatch_program_set_builtin(BPyGwn_Batch *self, PyObject *args, PyObject *kwds) +static PyObject *bpygpu_VertBatch_program_set_builtin(BPyGPUBatch *self, PyObject *args, PyObject *kwds) { static const char *kwlist[] = {"id", NULL}; @@ -590,11 +588,11 @@ static PyObject *bpygwn_VertBatch_program_set_builtin(BPyGwn_Batch *self, PyObje return NULL; success: - GWN_batch_program_set_builtin(self->batch, shader); + GPU_batch_program_set_builtin(self->batch, shader); Py_RETURN_NONE; } -static PyObject *bpygwn_VertBatch_uniform_bool(BPyGwn_Batch *self, PyObject *args) +static PyObject *bpygpu_VertBatch_uniform_bool(BPyGPUBatch *self, PyObject *args) { struct { const char *id; @@ -609,11 +607,11 @@ static PyObject *bpygwn_VertBatch_uniform_bool(BPyGwn_Batch *self, PyObject *arg return NULL; } - GWN_batch_uniform_1b(self->batch, params.id, params.values[0]); + GPU_batch_uniform_1b(self->batch, params.id, params.values[0]); Py_RETURN_NONE; } -static PyObject *bpygwn_VertBatch_uniform_i32(BPyGwn_Batch *self, PyObject *args) +static PyObject *bpygpu_VertBatch_uniform_i32(BPyGPUBatch *self, PyObject *args) { struct { const char *id; @@ -628,11 +626,11 @@ static PyObject *bpygwn_VertBatch_uniform_i32(BPyGwn_Batch *self, PyObject *args return NULL; } - GWN_batch_uniform_1i(self->batch, params.id, params.values[0]); + GPU_batch_uniform_1i(self->batch, params.id, params.values[0]); Py_RETURN_NONE; } -static PyObject *bpygwn_VertBatch_uniform_f32(BPyGwn_Batch *self, PyObject *args) +static PyObject *bpygpu_VertBatch_uniform_f32(BPyGPUBatch *self, PyObject *args) { struct { const char *id; @@ -648,78 +646,78 @@ static PyObject *bpygwn_VertBatch_uniform_f32(BPyGwn_Batch *self, PyObject *args } switch (PyTuple_GET_SIZE(args)) { - case 2: GWN_batch_uniform_1f(self->batch, params.id, params.values[0]); break; - case 3: GWN_batch_uniform_2f(self->batch, params.id, UNPACK2(params.values)); break; - case 4: GWN_batch_uniform_3f(self->batch, params.id, UNPACK3(params.values)); break; - case 5: GWN_batch_uniform_4f(self->batch, params.id, UNPACK4(params.values)); break; + case 2: GPU_batch_uniform_1f(self->batch, params.id, params.values[0]); break; + case 3: GPU_batch_uniform_2f(self->batch, params.id, UNPACK2(params.values)); break; + case 4: GPU_batch_uniform_3f(self->batch, params.id, UNPACK3(params.values)); break; + case 5: GPU_batch_uniform_4f(self->batch, params.id, UNPACK4(params.values)); break; default: BLI_assert(0); } Py_RETURN_NONE; } -PyDoc_STRVAR(bpygwn_VertBatch_draw_doc, +PyDoc_STRVAR(bpygpu_VertBatch_draw_doc, "TODO" ); -static PyObject *bpygwn_VertBatch_draw(BPyGwn_Batch *self) +static PyObject *bpygpu_VertBatch_draw(BPyGPUBatch *self) { if (!glIsProgram(self->batch->program)) { PyErr_SetString(PyExc_ValueError, "batch program has not not set"); } - GWN_batch_draw(self->batch); + GPU_batch_draw(self->batch); Py_RETURN_NONE; } -static PyObject *bpygwn_VertBatch_program_use_begin(BPyGwn_Batch *self) +static PyObject *bpygpu_VertBatch_program_use_begin(BPyGPUBatch *self) { if (!glIsProgram(self->batch->program)) { PyErr_SetString(PyExc_ValueError, "batch program has not not set"); } - GWN_batch_program_use_begin(self->batch); + GPU_batch_program_use_begin(self->batch); Py_RETURN_NONE; } -static PyObject *bpygwn_VertBatch_program_use_end(BPyGwn_Batch *self) +static PyObject *bpygpu_VertBatch_program_use_end(BPyGPUBatch *self) { if (!glIsProgram(self->batch->program)) { PyErr_SetString(PyExc_ValueError, "batch program has not not set"); } - GWN_batch_program_use_end(self->batch); + GPU_batch_program_use_end(self->batch); Py_RETURN_NONE; } -static struct PyMethodDef bpygwn_VertBatch_methods[] = { - {"vertbuf_add", (PyCFunction)bpygwn_VertBatch_vertbuf_add, - METH_O, bpygwn_VertBatch_vertbuf_add_doc}, - {"program_set_builtin", (PyCFunction)bpygwn_VertBatch_program_set_builtin, - METH_VARARGS | METH_KEYWORDS, bpygwn_VertBatch_program_set_builtin_doc}, - {"uniform_bool", (PyCFunction)bpygwn_VertBatch_uniform_bool, +static struct PyMethodDef bpygpu_VertBatch_methods[] = { + {"vertbuf_add", (PyCFunction)bpygpu_VertBatch_vertbuf_add, + METH_O, bpygpu_VertBatch_vertbuf_add_doc}, + {"program_set_builtin", (PyCFunction)bpygpu_VertBatch_program_set_builtin, + METH_VARARGS | METH_KEYWORDS, bpygpu_VertBatch_program_set_builtin_doc}, + {"uniform_bool", (PyCFunction)bpygpu_VertBatch_uniform_bool, METH_VARARGS, NULL}, - {"uniform_i32", (PyCFunction)bpygwn_VertBatch_uniform_i32, + {"uniform_i32", (PyCFunction)bpygpu_VertBatch_uniform_i32, METH_VARARGS, NULL}, - {"uniform_f32", (PyCFunction)bpygwn_VertBatch_uniform_f32, + {"uniform_f32", (PyCFunction)bpygpu_VertBatch_uniform_f32, METH_VARARGS, NULL}, - {"draw", (PyCFunction) bpygwn_VertBatch_draw, - METH_NOARGS, bpygwn_VertBatch_draw_doc}, - {"program_use_begin", (PyCFunction)bpygwn_VertBatch_program_use_begin, + {"draw", (PyCFunction) bpygpu_VertBatch_draw, + METH_NOARGS, bpygpu_VertBatch_draw_doc}, + {"program_use_begin", (PyCFunction)bpygpu_VertBatch_program_use_begin, METH_NOARGS, ""}, - {"program_use_end", (PyCFunction)bpygwn_VertBatch_program_use_end, + {"program_use_end", (PyCFunction)bpygpu_VertBatch_program_use_end, METH_NOARGS, ""}, {NULL, NULL, 0, NULL} }; -#ifdef USE_GWN_PY_REFERENCES +#ifdef USE_GPU_PY_REFERENCES -static int bpygwn_Batch_traverse(BPyGwn_Batch *self, visitproc visit, void *arg) +static int bpygpu_Batch_traverse(BPyGPUBatch *self, visitproc visit, void *arg) { Py_VISIT(self->references); return 0; } -static int bpygwn_Batch_clear(BPyGwn_Batch *self) +static int bpygpu_Batch_clear(BPyGPUBatch *self) { Py_CLEAR(self->references); return 0; @@ -727,14 +725,14 @@ static int bpygwn_Batch_clear(BPyGwn_Batch *self) #endif -static void bpygwn_Batch_dealloc(BPyGwn_Batch *self) +static void bpygpu_Batch_dealloc(BPyGPUBatch *self) { - GWN_batch_discard(self->batch); + GPU_batch_discard(self->batch); -#ifdef USE_GWN_PY_REFERENCES +#ifdef USE_GPU_PY_REFERENCES if (self->references) { PyObject_GC_UnTrack(self); - bpygwn_Batch_clear(self); + bpygpu_Batch_clear(self); Py_XDECREF(self->references); } #endif @@ -742,52 +740,52 @@ static void bpygwn_Batch_dealloc(BPyGwn_Batch *self) Py_TYPE(self)->tp_free(self); } -PyTypeObject BPyGwn_Batch_Type = { +PyTypeObject BPyGPUBatch_Type = { PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "Gwn_Batch", - .tp_basicsize = sizeof(BPyGwn_Batch), - .tp_dealloc = (destructor)bpygwn_Batch_dealloc, -#ifdef USE_GWN_PY_REFERENCES + .tp_name = "GPUBatch", + .tp_basicsize = sizeof(BPyGPUBatch), + .tp_dealloc = (destructor)bpygpu_Batch_dealloc, +#ifdef USE_GPU_PY_REFERENCES .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, - .tp_traverse = (traverseproc)bpygwn_Batch_traverse, - .tp_clear = (inquiry)bpygwn_Batch_clear, + .tp_traverse = (traverseproc)bpygpu_Batch_traverse, + .tp_clear = (inquiry)bpygpu_Batch_clear, #else .tp_flags = Py_TPFLAGS_DEFAULT, #endif - .tp_methods = bpygwn_VertBatch_methods, - .tp_new = bpygwn_Batch_new, + .tp_methods = bpygpu_VertBatch_methods, + .tp_new = bpygpu_Batch_new, }; /* -------------------------------------------------------------------- */ -/** \name Gawain Types Module +/** \name GPU Types Module * \{ */ static struct PyModuleDef BPy_BM_types_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "_gawain.types", + .m_name = "_gpu.types", }; -PyObject *BPyInit_gawain_types(void) +PyObject *BPyInit_gpu_types(void) { PyObject *submodule; submodule = PyModule_Create(&BPy_BM_types_module_def); - if (PyType_Ready(&BPyGwn_VertFormat_Type) < 0) + if (PyType_Ready(&BPyGPUVertFormat_Type) < 0) return NULL; - if (PyType_Ready(&BPyGwn_VertBuf_Type) < 0) + if (PyType_Ready(&BPyGPUVertBuf_Type) < 0) return NULL; - if (PyType_Ready(&BPyGwn_Batch_Type) < 0) + if (PyType_Ready(&BPyGPUBatch_Type) < 0) return NULL; #define MODULE_TYPE_ADD(s, t) \ PyModule_AddObject(s, t.tp_name, (PyObject *)&t); Py_INCREF((PyObject *)&t) - MODULE_TYPE_ADD(submodule, BPyGwn_VertFormat_Type); - MODULE_TYPE_ADD(submodule, BPyGwn_VertBuf_Type); - MODULE_TYPE_ADD(submodule, BPyGwn_Batch_Type); + MODULE_TYPE_ADD(submodule, BPyGPUVertFormat_Type); + MODULE_TYPE_ADD(submodule, BPyGPUVertBuf_Type); + MODULE_TYPE_ADD(submodule, BPyGPUBatch_Type); #undef MODULE_TYPE_ADD @@ -802,11 +800,11 @@ PyObject *BPyInit_gawain_types(void) /** \name Public API * \{ */ -PyObject *BPyGwn_VertFormat_CreatePyObject(Gwn_VertFormat *fmt) +PyObject *BPyGPUVertFormat_CreatePyObject(GPUVertFormat *fmt) { - BPyGwn_VertFormat *self; + BPyGPUVertFormat *self; - self = PyObject_New(BPyGwn_VertFormat, &BPyGwn_VertFormat_Type); + self = PyObject_New(BPyGPUVertFormat, &BPyGPUVertFormat_Type); if (fmt) { self->fmt = *fmt; } @@ -817,26 +815,26 @@ PyObject *BPyGwn_VertFormat_CreatePyObject(Gwn_VertFormat *fmt) return (PyObject *)self; } -PyObject *BPyGwn_VertBuf_CreatePyObject(Gwn_VertBuf *buf) +PyObject *BPyGPUVertBuf_CreatePyObject(GPUVertBuf *buf) { - BPyGwn_VertBuf *self; + BPyGPUVertBuf *self; - self = PyObject_New(BPyGwn_VertBuf, &BPyGwn_VertBuf_Type); + self = PyObject_New(BPyGPUVertBuf, &BPyGPUVertBuf_Type); self->buf = buf; return (PyObject *)self; } -PyObject *BPyGwn_Batch_CreatePyObject(Gwn_Batch *batch) +PyObject *BPyGPUBatch_CreatePyObject(GPUBatch *batch) { - BPyGwn_Batch *self; + BPyGPUBatch *self; -#ifdef USE_GWN_PY_REFERENCES - self = (BPyGwn_Batch *)_PyObject_GC_New(&BPyGwn_Batch_Type); +#ifdef USE_GPU_PY_REFERENCES + self = (BPyGPUBatch *)_PyObject_GC_New(&BPyGPUBatch_Type); self->references = NULL; #else - self = PyObject_New(BPyGwn_Batch, &BPyGwn_Batch_Type); + self = PyObject_New(BPyGPUBatch, &BPyGPUBatch_Type); #endif self->batch = batch; diff --git a/source/blender/python/gawain/gwn_py_types.h b/source/blender/python/gpu/gpu_py_types.h index dde6cf98827..f736a8f749a 100644 --- a/source/blender/python/gawain/gwn_py_types.h +++ b/source/blender/python/gpu/gpu_py_types.h @@ -18,50 +18,50 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/python/gawain/gwn_py_types.h - * \ingroup pygawain +/** \file blender/python/gpu/gpu_py_types.h + * \ingroup pygpu */ -#ifndef __GWN_PY_TYPES_H__ -#define __GWN_PY_TYPES_H__ +#ifndef __GPU_PY_TYPES_H__ +#define __GPU_PY_TYPES_H__ #include "BLI_compiler_attrs.h" -#define USE_GWN_PY_REFERENCES +#define USE_GPU_PY_REFERENCES -extern PyTypeObject BPyGwn_VertFormat_Type; -extern PyTypeObject BPyGwn_VertBuf_Type; -extern PyTypeObject BPyGwn_Batch_Type; +extern PyTypeObject BPyGPUVertFormat_Type; +extern PyTypeObject BPyGPUVertBuf_Type; +extern PyTypeObject BPyGPUBatch_Type; -#define BPyGwn_VertFormat_Check(v) (Py_TYPE(v) == &BPyGwn_VertFormat_Type) -#define BPyGwn_VertBuf_Check(v) (Py_TYPE(v) == &BPyGwn_VertBuf_Type) -#define BPyGwn_Batch_Check(v) (Py_TYPE(v) == &BPyGwn_Batch_Type) +#define BPyGPUVertFormat_Check(v) (Py_TYPE(v) == &BPyGPUVertFormat_Type) +#define BPyGPUVertBuf_Check(v) (Py_TYPE(v) == &BPyGPUVertBuf_Type) +#define BPyGPUBatch_Check(v) (Py_TYPE(v) == &BPyGPUBatch_Type) -typedef struct BPyGwn_VertFormat { +typedef struct BPyGPUVertFormat { PyObject_VAR_HEAD - struct Gwn_VertFormat fmt; -} BPyGwn_VertFormat; + struct GPUVertFormat fmt; +} BPyGPUVertFormat; -typedef struct BPyGwn_VertBuf { +typedef struct BPyGPUVertBuf { PyObject_VAR_HEAD /* The buf is owned, we may support thin wrapped batches later. */ - struct Gwn_VertBuf *buf; -} BPyGwn_VertBuf; + struct GPUVertBuf *buf; +} BPyGPUVertBuf; -typedef struct BPyGwn_Batch { +typedef struct BPyGPUBatch { PyObject_VAR_HEAD /* The batch is owned, we may support thin wrapped batches later. */ - struct Gwn_Batch *batch; -#ifdef USE_GWN_PY_REFERENCES + struct GPUBatch *batch; +#ifdef USE_GPU_PY_REFERENCES /* Just to keep a user to prevent freeing buf's we're using */ PyObject *references; #endif -} BPyGwn_Batch; +} BPyGPUBatch; -PyObject *BPyInit_gawain_types(void); +PyObject *BPyInit_gpu_types(void); -PyObject *BPyGwn_VertFormat_CreatePyObject(struct Gwn_VertFormat *fmt); -PyObject *BPyGwn_VertBuf_CreatePyObject(struct Gwn_VertBuf *vbo) ATTR_NONNULL(1); -PyObject *BPyGwn_Batch_CreatePyObject(struct Gwn_Batch *batch) ATTR_NONNULL(1); +PyObject *BPyGPUVertFormat_CreatePyObject(struct GPUVertFormat *fmt); +PyObject *BPyGPUVertBuf_CreatePyObject(struct GPUVertBuf *vbo) ATTR_NONNULL(1); +PyObject *BPyGPUBatch_CreatePyObject(struct GPUBatch *batch) ATTR_NONNULL(1); -#endif /* __GWN_PY_TYPES_H__ */ +#endif /* __GPU_PY_TYPES_H__ */ diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index d3464ea5841..a94708c0602 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -254,7 +254,7 @@ static void pydriver_error(ChannelDriver *driver) #define OK_OP(op) [op] = 1 -const char secure_opcodes[255] = { +static const char secure_opcodes[255] = { OK_OP(POP_TOP), OK_OP(ROT_TWO), OK_OP(ROT_THREE), diff --git a/source/blender/python/intern/bpy_gizmo_wrap.c b/source/blender/python/intern/bpy_gizmo_wrap.c index 4b71ea92010..2a932cb6a99 100644 --- a/source/blender/python/intern/bpy_gizmo_wrap.c +++ b/source/blender/python/intern/bpy_gizmo_wrap.c @@ -54,7 +54,7 @@ static bool bpy_gizmotype_target_property_def( - wmGizmoType *wt, PyObject *item) + wmGizmoType *gzt, PyObject *item) { /* Note: names based on 'rna_rna.c' */ PyObject *empty_tuple = PyTuple_New(0); @@ -102,7 +102,7 @@ static bool bpy_gizmotype_target_property_def( goto fail; } - WM_gizmotype_target_property_def(wt, params.id, params.type, params.array_length); + WM_gizmotype_target_property_def(gzt, params.id, params.type, params.array_length); Py_DECREF(empty_tuple); return true; @@ -111,17 +111,17 @@ fail: return false; } -static void gizmo_properties_init(wmGizmoType *wt) +static void gizmo_properties_init(wmGizmoType *gzt) { - PyTypeObject *py_class = wt->ext.data; - RNA_struct_blender_type_set(wt->ext.srna, wt); + PyTypeObject *py_class = gzt->ext.data; + RNA_struct_blender_type_set(gzt->ext.srna, gzt); /* only call this so pyrna_deferred_register_class gives a useful error * WM_operatortype_append_ptr will call RNA_def_struct_identifier * later */ - RNA_def_struct_identifier_no_struct_map(wt->srna, wt->idname); + RNA_def_struct_identifier_no_struct_map(gzt->srna, gzt->idname); - if (pyrna_deferred_register_class(wt->srna, py_class) != 0) { + if (pyrna_deferred_register_class(gzt->srna, py_class) != 0) { PyErr_Print(); /* failed to register operator props */ PyErr_Clear(); } @@ -149,7 +149,7 @@ static void gizmo_properties_init(wmGizmoType *wt) PyObject **items = PySequence_Fast_ITEMS(bl_target_properties_fast); for (uint i = 0; i < items_len; i++) { - if (!bpy_gizmotype_target_property_def(wt, items[i])) { + if (!bpy_gizmotype_target_property_def(gzt, items[i])) { PyErr_Print(); PyErr_Clear(); break; @@ -161,25 +161,25 @@ static void gizmo_properties_init(wmGizmoType *wt) } } -void BPY_RNA_gizmo_wrapper(wmGizmoType *wt, void *userdata) +void BPY_RNA_gizmo_wrapper(wmGizmoType *gzt, void *userdata) { /* take care not to overwrite anything set in * WM_gizmomaptype_group_link_ptr before opfunc() is called */ - StructRNA *srna = wt->srna; - *wt = *((wmGizmoType *)userdata); - wt->srna = srna; /* restore */ + StructRNA *srna = gzt->srna; + *gzt = *((wmGizmoType *)userdata); + gzt->srna = srna; /* restore */ /* don't do translations here yet */ #if 0 /* Use i18n context from ext.srna if possible (py gizmogroups). */ - if (wt->ext.srna) { - RNA_def_struct_translation_context(wt->srna, RNA_struct_translation_context(wt->ext.srna)); + if (gt->ext.srna) { + RNA_def_struct_translation_context(gt->srna, RNA_struct_translation_context(gt->ext.srna)); } #endif - wt->struct_size = sizeof(wmGizmo); + gzt->struct_size = sizeof(wmGizmo); - gizmo_properties_init(wt); + gizmo_properties_init(gzt); } /** \} */ @@ -190,46 +190,46 @@ void BPY_RNA_gizmo_wrapper(wmGizmoType *wt, void *userdata) /** \name Gizmo Group * \{ */ -static void gizmogroup_properties_init(wmGizmoGroupType *wgt) +static void gizmogroup_properties_init(wmGizmoGroupType *gzgt) { #ifdef USE_SRNA - PyTypeObject *py_class = wgt->ext.data; + PyTypeObject *py_class = gzgt->ext.data; #endif - RNA_struct_blender_type_set(wgt->ext.srna, wgt); + RNA_struct_blender_type_set(gzgt->ext.srna, gzgt); #ifdef USE_SRNA /* only call this so pyrna_deferred_register_class gives a useful error * WM_operatortype_append_ptr will call RNA_def_struct_identifier * later */ - RNA_def_struct_identifier(wgt->srna, wgt->idname); + RNA_def_struct_identifier(gzgt->srna, gzgt->idname); - if (pyrna_deferred_register_class(wgt->srna, py_class) != 0) { + if (pyrna_deferred_register_class(gzgt->srna, py_class) != 0) { PyErr_Print(); /* failed to register operator props */ PyErr_Clear(); } #endif } -void BPY_RNA_gizmogroup_wrapper(wmGizmoGroupType *wgt, void *userdata) +void BPY_RNA_gizmogroup_wrapper(wmGizmoGroupType *gzgt, void *userdata) { /* take care not to overwrite anything set in * WM_gizmomaptype_group_link_ptr before opfunc() is called */ #ifdef USE_SRNA - StructRNA *srna = wgt->srna; + StructRNA *srna = gzgt->srna; #endif - *wgt = *((wmGizmoGroupType *)userdata); + *gzgt = *((wmGizmoGroupType *)userdata); #ifdef USE_SRNA - wgt->srna = srna; /* restore */ + gzgt->srna = srna; /* restore */ #endif #ifdef USE_SRNA /* Use i18n context from ext.srna if possible (py gizmogroups). */ - if (wgt->ext.srna) { - RNA_def_struct_translation_context(wgt->srna, RNA_struct_translation_context(wgt->ext.srna)); + if (gzgt->ext.srna) { + RNA_def_struct_translation_context(gzgt->srna, RNA_struct_translation_context(gzgt->ext.srna)); } #endif - gizmogroup_properties_init(wgt); + gizmogroup_properties_init(gzgt); } /** \} */ diff --git a/source/blender/python/intern/bpy_gizmo_wrap.h b/source/blender/python/intern/bpy_gizmo_wrap.h index 4d6639d977f..96f15312a4e 100644 --- a/source/blender/python/intern/bpy_gizmo_wrap.h +++ b/source/blender/python/intern/bpy_gizmo_wrap.h @@ -29,7 +29,7 @@ struct wmGizmoType; struct wmGizmoGroupType; /* exposed to rna/wm api */ -void BPY_RNA_gizmo_wrapper(struct wmGizmoType *wt, void *userdata); -void BPY_RNA_gizmogroup_wrapper(struct wmGizmoGroupType *wgt, void *userdata); +void BPY_RNA_gizmo_wrapper(struct wmGizmoType *gzt, void *userdata); +void BPY_RNA_gizmogroup_wrapper(struct wmGizmoGroupType *gzgt, void *userdata); #endif /* __BPY_GIZMO_WRAP_H__ */ diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 0d7b0c92a90..64bc54c6221 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -75,7 +75,7 @@ #include "../generic/blf_py_api.h" #include "../generic/idprop_py_api.h" #include "../generic/imbuf_py_api.h" -#include "../gawain/gwn_py_api.h" +#include "../gpu/gpu_py_api.h" #include "../bmesh/bmesh_py_api.h" #include "../mathutils/mathutils.h" @@ -219,7 +219,7 @@ static struct _inittab bpy_internal_modules[] = { {"mathutils.kdtree", PyInit_mathutils_kdtree}, #endif {"_bpy_path", BPyInit__bpy_path}, - {"_gawain", BPyInit_gawain}, + {"_gpu", BPyInit_gpu}, {"bgl", BPyInit_bgl}, {"blf", BPyInit_blf}, {"imbuf", BPyInit_imbuf}, diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index e0fbd144590..30bd3bc5ca3 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -5118,6 +5118,9 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) case PROP_RAW_DOUBLE: item = PyFloat_FromDouble((double) ((double *)array)[i]); break; + case PROP_RAW_BOOLEAN: + item = PyBool_FromLong((long) ((bool *)array)[i]); + break; default: /* PROP_RAW_UNSET */ /* should never happen */ BLI_assert(!"Invalid array type - get"); diff --git a/source/blender/python/intern/bpy_rna_gizmo.c b/source/blender/python/intern/bpy_rna_gizmo.c index e834595114a..ded26f777a5 100644 --- a/source/blender/python/intern/bpy_rna_gizmo.c +++ b/source/blender/python/intern/bpy_rna_gizmo.c @@ -67,26 +67,26 @@ struct BPyGizmoHandlerUserData { }; static void py_rna_gizmo_handler_get_cb( - const wmGizmo *UNUSED(mpr), wmGizmoProperty *mpr_prop, + const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, void *value_p) { PyGILState_STATE gilstate = PyGILState_Ensure(); - struct BPyGizmoHandlerUserData *data = mpr_prop->custom_func.user_data; + struct BPyGizmoHandlerUserData *data = gz_prop->custom_func.user_data; PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_GIZMO_FN_SLOT_GET], NULL); if (ret == NULL) { goto fail; } - if (mpr_prop->type->data_type == PROP_FLOAT) { + if (gz_prop->type->data_type == PROP_FLOAT) { float *value = value_p; - if (mpr_prop->type->array_length == 1) { + if (gz_prop->type->array_length == 1) { if ((*value = PyFloat_AsDouble(ret)) == -1.0f && PyErr_Occurred()) { goto fail; } } else { - if (PyC_AsArray(value, ret, mpr_prop->type->array_length, &PyFloat_Type, false, + if (PyC_AsArray(value, ret, gz_prop->type->array_length, &PyFloat_Type, false, "Gizmo get callback: ") == -1) { goto fail; @@ -111,23 +111,23 @@ fail: } static void py_rna_gizmo_handler_set_cb( - const wmGizmo *UNUSED(mpr), wmGizmoProperty *mpr_prop, + const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, const void *value_p) { PyGILState_STATE gilstate = PyGILState_Ensure(); - struct BPyGizmoHandlerUserData *data = mpr_prop->custom_func.user_data; + struct BPyGizmoHandlerUserData *data = gz_prop->custom_func.user_data; PyObject *args = PyTuple_New(1); - if (mpr_prop->type->data_type == PROP_FLOAT) { + if (gz_prop->type->data_type == PROP_FLOAT) { const float *value = value_p; PyObject *py_value; - if (mpr_prop->type->array_length == 1) { + if (gz_prop->type->array_length == 1) { py_value = PyFloat_FromDouble(*value); } else { - py_value = PyC_Tuple_PackArray_F32(value, mpr_prop->type->array_length); + py_value = PyC_Tuple_PackArray_F32(value, gz_prop->type->array_length); } if (py_value == NULL) { goto fail; @@ -158,10 +158,10 @@ fail: } static void py_rna_gizmo_handler_range_get_cb( - const wmGizmo *UNUSED(mpr), wmGizmoProperty *mpr_prop, + const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop, void *value_p) { - struct BPyGizmoHandlerUserData *data = mpr_prop->custom_func.user_data; + struct BPyGizmoHandlerUserData *data = gz_prop->custom_func.user_data; PyGILState_STATE gilstate = PyGILState_Ensure(); @@ -184,7 +184,7 @@ static void py_rna_gizmo_handler_range_get_cb( goto fail; } - if (mpr_prop->type->data_type == PROP_FLOAT) { + if (gz_prop->type->data_type == PROP_FLOAT) { float range[2]; for (int i = 0; i < 2; i++) { if (((range[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(ret, i))) == -1.0f && PyErr_Occurred()) == 0) { @@ -215,9 +215,9 @@ fail: } static void py_rna_gizmo_handler_free_cb( - const wmGizmo *UNUSED(mpr), wmGizmoProperty *mpr_prop) + const wmGizmo *UNUSED(gz), wmGizmoProperty *gz_prop) { - struct BPyGizmoHandlerUserData *data = mpr_prop->custom_func.user_data; + struct BPyGizmoHandlerUserData *data = gz_prop->custom_func.user_data; PyGILState_STATE gilstate = PyGILState_Ensure(); for (int i = 0; i < BPY_GIZMO_FN_SLOT_LEN; i++) { @@ -271,14 +271,14 @@ static PyObject *bpy_gizmo_target_set_handler(PyObject *UNUSED(self), PyObject * goto fail; } - wmGizmo *mpr = ((BPy_StructRNA *)params.self)->ptr.data; + wmGizmo *gz = ((BPy_StructRNA *)params.self)->ptr.data; - const wmGizmoPropertyType *mpr_prop_type = - WM_gizmotype_target_property_find(mpr->type, params.target); - if (mpr_prop_type == NULL) { + const wmGizmoPropertyType *gz_prop_type = + WM_gizmotype_target_property_find(gz->type, params.target); + if (gz_prop_type == NULL) { PyErr_Format(PyExc_ValueError, "Gizmo target property '%s.%s' not found", - mpr->type->idname, params.target); + gz->type->idname, params.target); goto fail; } @@ -307,7 +307,7 @@ static PyObject *bpy_gizmo_target_set_handler(PyObject *UNUSED(self), PyObject * } WM_gizmo_target_property_def_func_ptr( - mpr, mpr_prop_type, + gz, gz_prop_type, &(const struct wmGizmoPropertyFnParams) { .value_get_fn = py_rna_gizmo_handler_get_cb, .value_set_fn = py_rna_gizmo_handler_set_cb, @@ -361,28 +361,28 @@ static PyObject *bpy_gizmo_target_get_value(PyObject *UNUSED(self), PyObject *ar goto fail; } - wmGizmo *mpr = ((BPy_StructRNA *)params.self)->ptr.data; + wmGizmo *gz = ((BPy_StructRNA *)params.self)->ptr.data; - wmGizmoProperty *mpr_prop = - WM_gizmo_target_property_find(mpr, params.target); - if (mpr_prop == NULL) { + wmGizmoProperty *gz_prop = + WM_gizmo_target_property_find(gz, params.target); + if (gz_prop == NULL) { PyErr_Format(PyExc_ValueError, "Gizmo target property '%s.%s' not found", - mpr->type->idname, params.target); + gz->type->idname, params.target); goto fail; } - const int array_len = WM_gizmo_target_property_array_length(mpr, mpr_prop); - switch (mpr_prop->type->data_type) { + const int array_len = WM_gizmo_target_property_array_length(gz, gz_prop); + switch (gz_prop->type->data_type) { case PROP_FLOAT: { if (array_len != 0) { float *value = BLI_array_alloca(value, array_len); - WM_gizmo_target_property_value_get_array(mpr, mpr_prop, value); + WM_gizmo_target_property_value_get_array(gz, gz_prop, value); return PyC_Tuple_PackArray_F32(value, array_len); } else { - float value = WM_gizmo_target_property_value_get(mpr, mpr_prop); + float value = WM_gizmo_target_property_value_get(gz, gz_prop); return PyFloat_FromDouble(value); } break; @@ -429,36 +429,36 @@ static PyObject *bpy_gizmo_target_set_value(PyObject *UNUSED(self), PyObject *ar goto fail; } - wmGizmo *mpr = ((BPy_StructRNA *)params.self)->ptr.data; + wmGizmo *gz = ((BPy_StructRNA *)params.self)->ptr.data; - wmGizmoProperty *mpr_prop = - WM_gizmo_target_property_find(mpr, params.target); - if (mpr_prop == NULL) { + wmGizmoProperty *gz_prop = + WM_gizmo_target_property_find(gz, params.target); + if (gz_prop == NULL) { PyErr_Format(PyExc_ValueError, "Gizmo target property '%s.%s' not found", - mpr->type->idname, params.target); + gz->type->idname, params.target); goto fail; } - const int array_len = WM_gizmo_target_property_array_length(mpr, mpr_prop); - switch (mpr_prop->type->data_type) { + const int array_len = WM_gizmo_target_property_array_length(gz, gz_prop); + switch (gz_prop->type->data_type) { case PROP_FLOAT: { if (array_len != 0) { float *value = BLI_array_alloca(value, array_len); - if (PyC_AsArray(value, params.value, mpr_prop->type->array_length, &PyFloat_Type, false, + if (PyC_AsArray(value, params.value, gz_prop->type->array_length, &PyFloat_Type, false, "Gizmo target property array") == -1) { goto fail; } - WM_gizmo_target_property_value_set_array(BPy_GetContext(), mpr, mpr_prop, value); + WM_gizmo_target_property_value_set_array(BPy_GetContext(), gz, gz_prop, value); } else { float value; if ((value = PyFloat_AsDouble(params.value)) == -1.0f && PyErr_Occurred()) { goto fail; } - WM_gizmo_target_property_value_set(BPy_GetContext(), mpr, mpr_prop, value); + WM_gizmo_target_property_value_set(BPy_GetContext(), gz, gz_prop, value); } Py_RETURN_NONE; } @@ -504,22 +504,22 @@ static PyObject *bpy_gizmo_target_get_range(PyObject *UNUSED(self), PyObject *ar goto fail; } - wmGizmo *mpr = ((BPy_StructRNA *)params.self)->ptr.data; + wmGizmo *gz = ((BPy_StructRNA *)params.self)->ptr.data; - wmGizmoProperty *mpr_prop = - WM_gizmo_target_property_find(mpr, params.target); - if (mpr_prop == NULL) { + wmGizmoProperty *gz_prop = + WM_gizmo_target_property_find(gz, params.target); + if (gz_prop == NULL) { PyErr_Format(PyExc_ValueError, "Gizmo target property '%s.%s' not found", - mpr->type->idname, params.target); + gz->type->idname, params.target); goto fail; } - switch (mpr_prop->type->data_type) { + switch (gz_prop->type->data_type) { case PROP_FLOAT: { float range[2]; - WM_gizmo_target_property_range_get(mpr, mpr_prop, range); + WM_gizmo_target_property_range_get(gz, gz_prop, range); return PyC_Tuple_PackArray_F32(range, 2); } default: diff --git a/source/blender/python/intern/gpu_py_matrix.c b/source/blender/python/intern/gpu_py_matrix.c index 68b08dfb324..2ab6fd864eb 100644 --- a/source/blender/python/intern/gpu_py_matrix.c +++ b/source/blender/python/intern/gpu_py_matrix.c @@ -102,7 +102,7 @@ static PyObject *pygpu_matrix_push(PyObject *UNUSED(self)) if (!pygpu_stack_is_push_model_view_ok_or_error()) { return NULL; } - gpuPushMatrix(); + GPU_matrix_push(); Py_RETURN_NONE; } @@ -116,7 +116,7 @@ static PyObject *pygpu_matrix_pop(PyObject *UNUSED(self)) if (!pygpu_stack_is_pop_model_view_ok_or_error()) { return NULL; } - gpuPopMatrix(); + GPU_matrix_pop(); Py_RETURN_NONE; } @@ -130,7 +130,7 @@ static PyObject *pygpu_matrix_push_projection(PyObject *UNUSED(self)) if (!pygpu_stack_is_push_projection_ok_or_error()) { return NULL; } - gpuPushProjectionMatrix(); + GPU_matrix_push_projection(); Py_RETURN_NONE; } @@ -144,7 +144,7 @@ static PyObject *pygpu_matrix_pop_projection(PyObject *UNUSED(self)) if (!pygpu_stack_is_pop_projection_ok_or_error()) { return NULL; } - gpuPopProjectionMatrix(); + GPU_matrix_pop_projection(); Py_RETURN_NONE; } @@ -197,14 +197,14 @@ static PyObject *pygpu_matrix_stack_context_enter(BPy_GPU_MatrixStackContext *se if (!pygpu_stack_is_push_model_view_ok_or_error()) { return NULL; } - gpuPushMatrix(); + GPU_matrix_push(); self->level = GPU_matrix_stack_level_get_model_view(); } else if (self->type == PYGPU_MATRIX_TYPE_PROJECTION) { if (!pygpu_stack_is_push_projection_ok_or_error()) { return NULL; } - gpuPushProjectionMatrix(); + GPU_matrix_push_projection(); self->level = GPU_matrix_stack_level_get_projection(); } else { @@ -227,7 +227,7 @@ static PyObject *pygpu_matrix_stack_context_exit(BPy_GPU_MatrixStackContext *sel fprintf(stderr, "Level push/pop mismatch, expected %d, got %d\n", self->level, level); } if (level != 0) { - gpuPopMatrix(); + GPU_matrix_pop(); } } else if (self->type == PYGPU_MATRIX_TYPE_PROJECTION) { @@ -236,7 +236,7 @@ static PyObject *pygpu_matrix_stack_context_exit(BPy_GPU_MatrixStackContext *sel fprintf(stderr, "Level push/pop mismatch, expected %d, got %d", self->level, level); } if (level != 0) { - gpuPopProjectionMatrix(); + GPU_matrix_pop_projection(); } } else { @@ -294,7 +294,7 @@ static PyObject *pygpu_matrix_multiply_matrix(PyObject *UNUSED(self), PyObject * if (!Matrix_Parse4x4(value, &pymat)) { return NULL; } - gpuMultMatrix(pymat->matrix); + GPU_matrix_mul(pymat->matrix); Py_RETURN_NONE; } @@ -314,10 +314,10 @@ static PyObject *pygpu_matrix_scale(PyObject *UNUSED(self), PyObject *value) return NULL; } if (len == 2) { - gpuScale2fv(scale); + GPU_matrix_scale_2fv(scale); } else { - gpuScale3fv(scale); + GPU_matrix_scale_3fv(scale); } Py_RETURN_NONE; } @@ -337,7 +337,7 @@ static PyObject *pygpu_matrix_scale_uniform(PyObject *UNUSED(self), PyObject *va Py_TYPE(value)->tp_name); return NULL; } - gpuScaleUniform(scalar); + GPU_matrix_scale_1f(scalar); Py_RETURN_NONE; } @@ -357,10 +357,10 @@ static PyObject *pygpu_matrix_translate(PyObject *UNUSED(self), PyObject *value) return NULL; } if (len == 2) { - gpuTranslate2fv(offset); + GPU_matrix_translate_2fv(offset); } else { - gpuTranslate3fv(offset); + GPU_matrix_translate_3fv(offset); } Py_RETURN_NONE; } @@ -378,7 +378,7 @@ PyDoc_STRVAR(pygpu_matrix_reset_doc, ); static PyObject *pygpu_matrix_reset(PyObject *UNUSED(self)) { - gpuMatrixReset(); + GPU_matrix_reset(); Py_RETURN_NONE; } @@ -389,7 +389,7 @@ PyDoc_STRVAR(pygpu_matrix_load_identity_doc, ); static PyObject *pygpu_matrix_load_identity(PyObject *UNUSED(self)) { - gpuLoadIdentity(); + GPU_matrix_identity_set(); Py_RETURN_NONE; } @@ -407,7 +407,7 @@ static PyObject *pygpu_matrix_load_matrix(PyObject *UNUSED(self), PyObject *valu if (!Matrix_Parse4x4(value, &pymat)) { return NULL; } - gpuLoadMatrix(pymat->matrix); + GPU_matrix_set(pymat->matrix); Py_RETURN_NONE; } @@ -428,7 +428,7 @@ PyDoc_STRVAR(pygpu_matrix_get_projection_matrix_doc, static PyObject *pygpu_matrix_get_projection_matrix(PyObject *UNUSED(self)) { float matrix[4][4]; - gpuGetModelViewMatrix(matrix); + GPU_matrix_model_view_get(matrix); return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL); } @@ -444,7 +444,7 @@ PyDoc_STRVAR(pygpu_matrix_get_modal_view_matrix_doc, static PyObject *pygpu_matrix_get_modal_view_matrix(PyObject *UNUSED(self)) { float matrix[4][4]; - gpuGetProjectionMatrix(matrix); + GPU_matrix_projection_get(matrix); return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL); } @@ -459,7 +459,7 @@ PyDoc_STRVAR(pygpu_matrix_get_normal_matrix_doc, static PyObject *pygpu_matrix_get_normal_matrix(PyObject *UNUSED(self)) { float matrix[3][3]; - gpuGetNormalMatrix(matrix); + GPU_matrix_normal_get(matrix); return Matrix_CreatePyObject(&matrix[0][0], 3, 3, NULL); } diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 70c400f99b8..3bd40cca5c6 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -2321,7 +2321,7 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2) return Matrix_CreatePyObject(mat, mat1->num_col, mat1->num_row, Py_TYPE(mat1)); } /*------------------------obj * obj------------------------------ - * multiplication */ + * element-wise multiplication */ static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar) { float tmat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; @@ -2332,7 +2332,6 @@ static PyObject *matrix_mul_float(MatrixObject *mat, const float scalar) static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) { float scalar; - int vec_size; MatrixObject *mat1 = NULL, *mat2 = NULL; @@ -2348,15 +2347,124 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) } if (mat1 && mat2) { +#ifdef USE_MATHUTILS_ELEM_MUL /* MATRIX * MATRIX */ float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; + if ((mat1->num_row != mat2->num_row) || (mat1->num_col != mat2->num_col)) { + PyErr_SetString(PyExc_ValueError, + "matrix1 * matrix2: matrix1 number of rows/columns " + "and the matrix2 number of rows/columns must be the same"); + return NULL; + } + + mul_vn_vnvn(mat, mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row); + + return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1)); +#endif + } + else if (mat2) { + /*FLOAT/INT * MATRIX */ + if (((scalar = PyFloat_AsDouble(m1)) == -1.0f && PyErr_Occurred()) == 0) { + return matrix_mul_float(mat2, scalar); + } + } + else if (mat1) { + /* MATRIX * FLOAT/INT */ + if (((scalar = PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred()) == 0) { + return matrix_mul_float(mat1, scalar); + } + } + + PyErr_Format(PyExc_TypeError, + "Element-wise multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name); + return NULL; +} +/*------------------------obj *= obj------------------------------ + * Inplace element-wise multiplication */ +static PyObject *Matrix_imul(PyObject *m1, PyObject *m2) +{ + float scalar; + + MatrixObject *mat1 = NULL, *mat2 = NULL; + + if (MatrixObject_Check(m1)) { + mat1 = (MatrixObject *)m1; + if (BaseMath_ReadCallback(mat1) == -1) + return NULL; + } + if (MatrixObject_Check(m2)) { + mat2 = (MatrixObject *)m2; + if (BaseMath_ReadCallback(mat2) == -1) + return NULL; + } + + if (mat1 && mat2) { +#ifdef USE_MATHUTILS_ELEM_MUL + /* MATRIX *= MATRIX */ + if ((mat1->num_row != mat2->num_row) || (mat1->num_col != mat2->num_col)) { + PyErr_SetString(PyExc_ValueError, + "matrix1 *= matrix2: matrix1 number of rows/columns " + "and the matrix2 number of rows/columns must be the same"); + return NULL; + } + + mul_vn_vn(mat1->matrix, mat2->matrix, mat1->num_col * mat1->num_row); +#else + PyErr_Format(PyExc_TypeError, + "Inplace element-wise multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name); + return NULL; +#endif + } + else if (mat1 && (((scalar = PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred()) == 0)) { + /* MATRIX *= FLOAT/INT */ + mul_vn_fl(mat1->matrix, mat1->num_row * mat1->num_col, scalar); + } + else { + PyErr_Format(PyExc_TypeError, + "Inplace element-wise multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name); + return NULL; + } + + (void)BaseMath_WriteCallback(mat1); + Py_INCREF(m1); + return m1; +} +/*------------------------obj @ obj------------------------------ + * matrix multiplication */ +static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2) +{ + int vec_size; + + MatrixObject *mat1 = NULL, *mat2 = NULL; + + if (MatrixObject_Check(m1)) { + mat1 = (MatrixObject *)m1; + if (BaseMath_ReadCallback(mat1) == -1) + return NULL; + } + if (MatrixObject_Check(m2)) { + mat2 = (MatrixObject *)m2; + if (BaseMath_ReadCallback(mat2) == -1) + return NULL; + } + + if (mat1 && mat2) { + /* MATRIX @ MATRIX */ + float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; + int col, row, item; if (mat1->num_col != mat2->num_row) { PyErr_SetString(PyExc_ValueError, - "matrix1 * matrix2: matrix1 number of columns " - "and the matrix2 number of rows must be the same"); + "matrix1 * matrix2: matrix1 number of columns " + "and the matrix2 number of rows must be the same"); return NULL; } @@ -2372,14 +2480,8 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1)); } - else if (mat2) { - /*FLOAT/INT * MATRIX */ - if (((scalar = PyFloat_AsDouble(m1)) == -1.0f && PyErr_Occurred()) == 0) { - return matrix_mul_float(mat2, scalar); - } - } else if (mat1) { - /* MATRIX * VECTOR */ + /* MATRIX @ VECTOR */ if (VectorObject_Check(m2)) { VectorObject *vec2 = (VectorObject *)m2; float tvec[MATRIX_MAX_DIM]; @@ -2398,20 +2500,69 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) return Vector_CreatePyObject(tvec, vec_size, Py_TYPE(m2)); } - /*FLOAT/INT * MATRIX */ - else if (((scalar = PyFloat_AsDouble(m2)) == -1.0f && PyErr_Occurred()) == 0) { - return matrix_mul_float(mat1, scalar); + } + + PyErr_Format(PyExc_TypeError, + "Matrix multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name); + return NULL; +} +/*------------------------obj @= obj------------------------------ + * inplace matrix multiplication */ +static PyObject *Matrix_imatmul(PyObject *m1, PyObject *m2) +{ + MatrixObject *mat1 = NULL, *mat2 = NULL; + + if (MatrixObject_Check(m1)) { + mat1 = (MatrixObject *)m1; + if (BaseMath_ReadCallback(mat1) == -1) + return NULL; + } + if (MatrixObject_Check(m2)) { + mat2 = (MatrixObject *)m2; + if (BaseMath_ReadCallback(mat2) == -1) + return NULL; + } + + if (mat1 && mat2) { + /* MATRIX @= MATRIX */ + float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; + int col, row, item; + + if (mat1->num_col != mat2->num_row) { + PyErr_SetString(PyExc_ValueError, + "matrix1 * matrix2: matrix1 number of columns " + "and the matrix2 number of rows must be the same"); + return NULL; } + + for (col = 0; col < mat2->num_col; col++) { + for (row = 0; row < mat1->num_row; row++) { + double dot = 0.0f; + for (item = 0; item < mat1->num_col; item++) { + dot += (double)(MATRIX_ITEM(mat1, row, item) * MATRIX_ITEM(mat2, item, col)); + } + /* store in new matrix as overwriting original at this point will cause + * subsequent iterations to use incorrect values */ + mat[(col * mat1->num_row) + row] = (float)dot; + } + } + + /* copy matrix back */ + memcpy(mat1->matrix, mat, mat1->num_row * mat1->num_col); } else { - BLI_assert(!"internal error"); + PyErr_Format(PyExc_TypeError, + "Inplace matrix multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name); + return NULL; } - PyErr_Format(PyExc_TypeError, - "Matrix multiplication: " - "not supported between '%.200s' and '%.200s' types", - Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name); - return NULL; + (void)BaseMath_WriteCallback(mat1); + Py_INCREF(m1); + return m1; } /*-----------------PROTOCOL DECLARATIONS--------------------------*/ @@ -2527,7 +2678,7 @@ static PyNumberMethods Matrix_NumMethods = { NULL, /*nb_float*/ NULL, /* nb_inplace_add */ NULL, /* nb_inplace_subtract */ - NULL, /* nb_inplace_multiply */ + (binaryfunc) Matrix_imul, /* nb_inplace_multiply */ NULL, /* nb_inplace_remainder */ NULL, /* nb_inplace_power */ NULL, /* nb_inplace_lshift */ @@ -2540,6 +2691,8 @@ static PyNumberMethods Matrix_NumMethods = { NULL, /* nb_inplace_floor_divide */ NULL, /* nb_inplace_true_divide */ NULL, /* nb_index */ + (binaryfunc) Matrix_matmul, /* nb_matrix_multiply */ + (binaryfunc) Matrix_imatmul, /* nb_inplace_matrix_multiply */ }; PyDoc_STRVAR(Matrix_translation_doc, diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 1a6fd0ee86f..bb5983af535 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -834,7 +834,7 @@ static PyObject *quat_mul_float(QuaternionObject *quat, const float scalar) * multiplication */ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2) { - float quat[QUAT_SIZE], scalar; + float scalar; QuaternionObject *quat1 = NULL, *quat2 = NULL; if (QuaternionObject_Check(q1)) { @@ -848,9 +848,12 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2) return NULL; } - if (quat1 && quat2) { /* QUAT * QUAT (cross product) */ - mul_qt_qtqt(quat, quat1->quat, quat2->quat); + if (quat1 && quat2) { /* QUAT * QUAT (element-wise product) */ +#ifdef USE_MATHUTILS_ELEM_MUL + float quat[QUAT_SIZE]; + mul_vn_vnvn(quat, quat1->quat, quat2->quat, QUAT_SIZE); return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); +#endif } /* the only case this can happen (for a supported type is "FLOAT * QUAT") */ else if (quat2) { /* FLOAT * QUAT */ @@ -858,17 +861,96 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2) return quat_mul_float(quat2, scalar); } } + else if (quat1) { /* QUAT * FLOAT */ + if ((((scalar = PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred()) == 0)) { + return quat_mul_float(quat1, scalar); + } + } + + PyErr_Format(PyExc_TypeError, + "Element-wise multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); + return NULL; +} +/*------------------------obj *= obj------------------------------ + * inplace multiplication */ +static PyObject *Quaternion_imul(PyObject *q1, PyObject *q2) +{ + float scalar; + QuaternionObject *quat1 = NULL, *quat2 = NULL; + + if (QuaternionObject_Check(q1)) { + quat1 = (QuaternionObject *)q1; + if (BaseMath_ReadCallback(quat1) == -1) + return NULL; + } + if (QuaternionObject_Check(q2)) { + quat2 = (QuaternionObject *)q2; + if (BaseMath_ReadCallback(quat2) == -1) + return NULL; + } + + if (quat1 && quat2) { /* QUAT *= QUAT (inplace element-wise product) */ +#ifdef USE_MATHUTILS_ELEM_MUL + mul_vn_vn(quat1->quat, quat2->quat, QUAT_SIZE); +#else + PyErr_Format(PyExc_TypeError, + "Inplace element-wise multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); + return NULL; +#endif + } + else if (quat1 && (((scalar = PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred()) == 0)) { + /* QUAT *= FLOAT */ + mul_qt_fl(quat1->quat, scalar); + } + else { + PyErr_Format(PyExc_TypeError, + "Element-wise multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); + return NULL; + } + + (void)BaseMath_WriteCallback(quat1); + Py_INCREF(q1); + return q1; +} +/*------------------------obj @ obj------------------------------ + * quaternion multiplication */ +static PyObject *Quaternion_matmul(PyObject *q1, PyObject *q2) +{ + float quat[QUAT_SIZE]; + QuaternionObject *quat1 = NULL, *quat2 = NULL; + + if (QuaternionObject_Check(q1)) { + quat1 = (QuaternionObject *)q1; + if (BaseMath_ReadCallback(quat1) == -1) + return NULL; + } + if (QuaternionObject_Check(q2)) { + quat2 = (QuaternionObject *)q2; + if (BaseMath_ReadCallback(quat2) == -1) + return NULL; + } + + if (quat1 && quat2) { /* QUAT @ QUAT (cross product) */ + mul_qt_qtqt(quat, quat1->quat, quat2->quat); + return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); + } else if (quat1) { - /* QUAT * VEC */ + /* QUAT @ VEC */ if (VectorObject_Check(q2)) { VectorObject *vec2 = (VectorObject *)q2; float tvec[3]; if (vec2->size != 3) { PyErr_SetString(PyExc_ValueError, - "Vector multiplication: " - "only 3D vector rotations (with quats) " - "currently supported"); + "Vector multiplication: " + "only 3D vector rotations (with quats) " + "currently supported"); return NULL; } if (BaseMath_ReadCallback(vec2) == -1) { @@ -880,21 +962,48 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2) return Vector_CreatePyObject(tvec, 3, Py_TYPE(vec2)); } - /* QUAT * FLOAT */ - else if ((((scalar = PyFloat_AsDouble(q2)) == -1.0f && PyErr_Occurred()) == 0)) { - return quat_mul_float(quat1, scalar); - } - } - else { - BLI_assert(!"internal error"); } PyErr_Format(PyExc_TypeError, - "Quaternion multiplication: " - "not supported between '%.200s' and '%.200s' types", - Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); + "Quaternion multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); return NULL; } +/*------------------------obj @= obj------------------------------ + * inplace quaternion multiplication */ +static PyObject *Quaternion_imatmul(PyObject *q1, PyObject *q2) +{ + float quat[QUAT_SIZE]; + QuaternionObject *quat1 = NULL, *quat2 = NULL; + + if (QuaternionObject_Check(q1)) { + quat1 = (QuaternionObject *)q1; + if (BaseMath_ReadCallback(quat1) == -1) + return NULL; + } + if (QuaternionObject_Check(q2)) { + quat2 = (QuaternionObject *)q2; + if (BaseMath_ReadCallback(quat2) == -1) + return NULL; + } + + if (quat1 && quat2) { /* QUAT @ QUAT (cross product) */ + mul_qt_qtqt(quat, quat1->quat, quat2->quat); + copy_qt_qt(quat1->quat, quat); + } + else { + PyErr_Format(PyExc_TypeError, + "Inplace quaternion multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(q1)->tp_name, Py_TYPE(q2)->tp_name); + return NULL; + } + + (void)BaseMath_WriteCallback(quat1); + Py_INCREF(q1); + return q1; +} /* -obj * returns the negative of this object*/ @@ -952,7 +1061,7 @@ static PyNumberMethods Quaternion_NumMethods = { NULL, /*nb_float*/ NULL, /* nb_inplace_add */ NULL, /* nb_inplace_subtract */ - NULL, /* nb_inplace_multiply */ + (binaryfunc) Quaternion_imul, /* nb_inplace_multiply */ NULL, /* nb_inplace_remainder */ NULL, /* nb_inplace_power */ NULL, /* nb_inplace_lshift */ @@ -965,6 +1074,8 @@ static PyNumberMethods Quaternion_NumMethods = { NULL, /* nb_inplace_floor_divide */ NULL, /* nb_inplace_true_divide */ NULL, /* nb_index */ + (binaryfunc) Quaternion_matmul, /* nb_matrix_multiply */ + (binaryfunc) Quaternion_imatmul, /* nb_inplace_matrix_multiply */ }; PyDoc_STRVAR(Quaternion_axis_doc, @@ -1100,7 +1211,8 @@ static PyObject *Quaternion_new(PyTypeObject *type, PyObject *args, PyObject *kw { PyObject *seq = NULL; double angle = 0.0f; - float quat[QUAT_SIZE] = {0.0f, 0.0f, 0.0f, 0.0f}; + float quat[QUAT_SIZE]; + unit_qt(quat); if (kwds && PyDict_Size(kwds)) { PyErr_SetString(PyExc_TypeError, diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index a06a63c8067..dc05f463d22 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -1127,23 +1127,17 @@ PyDoc_STRVAR(Vector_project_doc, static PyObject *Vector_project(VectorObject *self, PyObject *value) { const int size = self->size; - float tvec[MAX_DIMENSIONS]; - float vec[MAX_DIMENSIONS]; + float *tvec; double dot = 0.0f, dot2 = 0.0f; int x; - if (mathutils_array_parse(tvec, size, size, value, "Vector.project(other), invalid 'other' arg") == -1) + if (BaseMath_ReadCallback(self) == -1) return NULL; - if (self->size > 4) { - PyErr_SetString(PyExc_ValueError, - "Vector must be 2D, 3D or 4D"); + if (mathutils_array_parse_alloc(&tvec, size, value, "Vector.project(other), invalid 'other' arg") == -1) { return NULL; } - if (BaseMath_ReadCallback(self) == -1) - return NULL; - /* get dot products */ for (x = 0; x < size; x++) { dot += (double)(self->vec[x] * tvec[x]); @@ -1152,9 +1146,9 @@ static PyObject *Vector_project(VectorObject *self, PyObject *value) /* projection */ dot /= dot2; for (x = 0; x < size; x++) { - vec[x] = (float)dot * tvec[x]; + tvec[x] *= (float)dot; } - return Vector_CreatePyObject(vec, size, Py_TYPE(self)); + return Vector_CreatePyObject_alloc(tvec, size, Py_TYPE(self)); } PyDoc_STRVAR(Vector_lerp_doc, @@ -1712,12 +1706,25 @@ static PyObject *vector_mul_float(VectorObject *vec, const float scalar) mul_vn_vn_fl(tvec, vec->vec, vec->size, scalar); return Vector_CreatePyObject_alloc(tvec, vec->size, Py_TYPE(vec)); } +#ifdef USE_MATHUTILS_ELEM_MUL +static PyObject *vector_mul_vec(VectorObject *vec1, VectorObject *vec2) +{ + float *tvec = PyMem_Malloc(vec1->size * sizeof(float)); + if (tvec == NULL) { + PyErr_SetString(PyExc_MemoryError, + "vec * vec: " + "problem allocating pointer space"); + return NULL; + } + mul_vn_vnvn(tvec, vec1->vec, vec2->vec, vec1->size); + return Vector_CreatePyObject_alloc(tvec, vec1->size, Py_TYPE(vec1)); +} +#endif static PyObject *Vector_mul(PyObject *v1, PyObject *v2) { VectorObject *vec1 = NULL, *vec2 = NULL; float scalar; - int vec_size; if (VectorObject_Check(v1)) { vec1 = (VectorObject *)v1; @@ -1735,6 +1742,7 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) /* make sure v1 is always the vector */ if (vec1 && vec2) { +#ifdef USE_MATHUTILS_ELEM_MUL if (vec1->size != vec2->size) { PyErr_SetString(PyExc_ValueError, "Vector multiplication: " @@ -1742,30 +1750,12 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) return NULL; } - /*dot product*/ - return PyFloat_FromDouble(dot_vn_vn(vec1->vec, vec2->vec, vec1->size)); + /* element-wise product */ + return vector_mul_vec(vec1, vec2); +#endif } else if (vec1) { - if (MatrixObject_Check(v2)) { - /* VEC * MATRIX */ - float tvec[MAX_DIMENSIONS]; - - if (BaseMath_ReadCallback((MatrixObject *)v2) == -1) - return NULL; - if (row_vector_multiplication(tvec, vec1, (MatrixObject *)v2) == -1) { - return NULL; - } - - if (((MatrixObject *)v2)->num_row == 4 && vec1->size == 3) { - vec_size = 3; - } - else { - vec_size = ((MatrixObject *)v2)->num_col; - } - - return Vector_CreatePyObject(tvec, vec_size, Py_TYPE(vec1)); - } - else if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* VEC * FLOAT */ + if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* VEC * FLOAT */ return vector_mul_float(vec1, scalar); } } @@ -1774,12 +1764,9 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) return vector_mul_float(vec2, scalar); } } - else { - BLI_assert(!"internal error"); - } PyErr_Format(PyExc_TypeError, - "Vector multiplication: " + "Element-wise multiplication: " "not supported between '%.200s' and '%.200s' types", Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name); return NULL; @@ -1788,32 +1775,129 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) /* multiplication in-place: obj *= obj */ static PyObject *Vector_imul(PyObject *v1, PyObject *v2) { - VectorObject *vec = (VectorObject *)v1; + VectorObject *vec1 = NULL, *vec2 = NULL; float scalar; - if (BaseMath_ReadCallback_ForWrite(vec) == -1) + if (VectorObject_Check(v1)) { + vec1 = (VectorObject *)v1; + if (BaseMath_ReadCallback(vec1) == -1) + return NULL; + } + if (VectorObject_Check(v2)) { + vec2 = (VectorObject *)v2; + if (BaseMath_ReadCallback(vec2) == -1) + return NULL; + } + + if (BaseMath_ReadCallback_ForWrite(vec1) == -1) return NULL; /* Intentionally don't support (Quaternion, Matrix) here, uses reverse order instead. */ - /* only support 'vec *= float' - * vec*=vec result is a float so that wont work */ - if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* VEC *= FLOAT */ - mul_vn_fl(vec->vec, vec->size, scalar); + if (vec1 && vec2) { +#ifdef USE_MATHUTILS_ELEM_MUL + if (vec1->size != vec2->size) { + PyErr_SetString(PyExc_ValueError, + "Vector multiplication: " + "vectors must have the same dimensions for this operation"); + return NULL; + } + + /* element-wise product inplace */ + mul_vn_vn(vec1->vec, vec2->vec, vec1->size); +#else + PyErr_Format(PyExc_TypeError, + "Inplace element-wise multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name); + return NULL; +#endif + } + else if (vec1 && (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0)) { /* VEC *= FLOAT */ + mul_vn_fl(vec1->vec, vec1->size, scalar); } else { PyErr_Format(PyExc_TypeError, - "Vector multiplication: (%s *= %s) " - "invalid type for this operation", - Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name); + "Inplace element-wise multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name); return NULL; } - (void)BaseMath_WriteCallback(vec); + (void)BaseMath_WriteCallback(vec1); Py_INCREF(v1); return v1; } +static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) +{ + VectorObject *vec1 = NULL, *vec2 = NULL; + int vec_size; + + if (VectorObject_Check(v1)) { + vec1 = (VectorObject *)v1; + if (BaseMath_ReadCallback(vec1) == -1) + return NULL; + } + if (VectorObject_Check(v2)) { + vec2 = (VectorObject *)v2; + if (BaseMath_ReadCallback(vec2) == -1) + return NULL; + } + + + /* Intentionally don't support (Quaternion) here, uses reverse order instead. */ + + /* make sure v1 is always the vector */ + if (vec1 && vec2) { + if (vec1->size != vec2->size) { + PyErr_SetString(PyExc_ValueError, + "Vector multiplication: " + "vectors must have the same dimensions for this operation"); + return NULL; + } + + /*dot product*/ + return PyFloat_FromDouble(dot_vn_vn(vec1->vec, vec2->vec, vec1->size)); + } + else if (vec1) { + if (MatrixObject_Check(v2)) { + /* VEC @ MATRIX */ + float tvec[MAX_DIMENSIONS]; + + if (BaseMath_ReadCallback((MatrixObject *)v2) == -1) + return NULL; + if (row_vector_multiplication(tvec, vec1, (MatrixObject *)v2) == -1) { + return NULL; + } + + if (((MatrixObject *)v2)->num_row == 4 && vec1->size == 3) { + vec_size = 3; + } + else { + vec_size = ((MatrixObject *)v2)->num_col; + } + + return Vector_CreatePyObject(tvec, vec_size, Py_TYPE(vec1)); + } + } + + PyErr_Format(PyExc_TypeError, + "Vector multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name); + return NULL; +} + +static PyObject *Vector_imatmul(PyObject *v1, PyObject *v2) +{ + PyErr_Format(PyExc_TypeError, + "Inplace vector multiplication: " + "not supported between '%.200s' and '%.200s' types", + Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name); + return NULL; +} + /* divid: obj / obj */ static PyObject *Vector_div(PyObject *v1, PyObject *v2) { @@ -2125,6 +2209,8 @@ static PyNumberMethods Vector_NumMethods = { NULL, /* nb_inplace_floor_divide */ Vector_idiv, /* nb_inplace_true_divide */ NULL, /* nb_index */ + (binaryfunc) Vector_matmul, /* nb_matrix_multiply */ + (binaryfunc) Vector_imatmul, /* nb_inplace_matrix_multiply */ }; /*------------------PY_OBECT DEFINITION--------------------------*/ |