diff options
Diffstat (limited to 'source/blender/python')
36 files changed, 3191 insertions, 1392 deletions
diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/CMakeLists.txt index e855f3a3756..8d26fee0abd 100644 --- a/source/blender/python/CMakeLists.txt +++ b/source/blender/python/CMakeLists.txt @@ -17,6 +17,7 @@ # ***** END GPL LICENSE BLOCK ***** add_subdirectory(intern) +add_subdirectory(gawain) add_subdirectory(generic) add_subdirectory(mathutils) add_subdirectory(bmesh) diff --git a/source/blender/python/bmesh/CMakeLists.txt b/source/blender/python/bmesh/CMakeLists.txt index c7b86acc8f9..4d3230fa3e9 100644 --- a/source/blender/python/bmesh/CMakeLists.txt +++ b/source/blender/python/bmesh/CMakeLists.txt @@ -23,6 +23,7 @@ set(INC ../../bmesh ../../blenkernel ../../blenlib + ../../depsgraph ../../makesdna ../../../../intern/guardedalloc ) diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index d5973baeadb..d6189f7c1eb 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -156,11 +156,6 @@ static PyObject *bpy_bm_update_edit_mesh(PyObject *UNUSED(self), PyObject *args, { extern void EDBM_update_generic(BMEditMesh *em, const bool do_tessface, const bool is_destructive); - BMEditMesh *em = me->edit_btmesh; - BMesh *bm = em->bm; - - /* python won't ensure matching uv/mtex */ - BM_mesh_cd_validate(bm); EDBM_update_generic(me->edit_btmesh, do_tessface, is_destructive); } diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 2866683b89b..ec787768a57 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -34,10 +34,11 @@ #include "DNA_object_types.h" #include "DNA_material_types.h" -#include "BKE_depsgraph.h" #include "BKE_customdata.h" #include "BKE_DerivedMesh.h" +#include "DEG_depsgraph.h" + #include "bmesh.h" #include <Python.h> @@ -901,9 +902,6 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args) bm = self->bm; - /* python won't ensure matching uv/mtex */ - BM_mesh_cd_validate(bm); - BM_mesh_bm_to_me( bm, me, (&(struct BMeshToMeshParams){ @@ -912,7 +910,7 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args) /* we could have the user do this but if they forget blender can easy crash * since the references arrays for the objects derived meshes are now invalid */ - DAG_id_tag_update(&me->id, OB_RECALC_DATA); + DEG_id_tag_update(&me->id, OB_RECALC_DATA); Py_RETURN_NONE; } @@ -935,6 +933,8 @@ PyDoc_STRVAR(bpy_bmesh_from_object_doc, ); static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject *kw) { + /* TODO: This doesn't work currently because of eval_ctx. */ +#if 0 static const char *kwlist[] = {"object", "scene", "deform", "render", "cage", "face_normals", NULL}; PyObject *py_object; PyObject *py_scene; @@ -1027,6 +1027,10 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject dm->release(dm); Py_RETURN_NONE; +#else + UNUSED_VARS(self, args, kw); +#endif + return NULL; } diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index cb95ded4f0d..e2241ade7f0 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c @@ -105,9 +105,6 @@ PyDoc_STRVAR(bpy_bmlayeraccess_collection__bevel_weight_doc, PyDoc_STRVAR(bpy_bmlayeraccess_collection__crease_doc, "Edge crease for subsurf - float in [0 - 1].\n\n:type: :class:`BMLayerCollection`" ); -PyDoc_STRVAR(bpy_bmlayeraccess_collection__tex_doc, -"Accessor for :class:`BMTexPoly` layer (TODO).\n\ntype: :class:`BMLayerCollection`" // TYPE DOESN'T EXIST YET -); PyDoc_STRVAR(bpy_bmlayeraccess_collection__uv_doc, "Accessor for :class:`BMLoopUV` UV (as a 2D Vector).\n\ntype: :class:`BMLayerCollection`" ); @@ -120,6 +117,9 @@ PyDoc_STRVAR(bpy_bmlayeraccess_collection__skin_doc, PyDoc_STRVAR(bpy_bmlayeraccess_collection__paint_mask_doc, "Accessor for paint mask layer.\n\ntype: :class:`BMLayerCollection`" ); +PyDoc_STRVAR(bpy_bmlayeraccess_collection__face_map_doc, +"FaceMap custom-data layer.\n\ntype: :class:`BMLayerCollection`" +); #ifdef WITH_FREESTYLE PyDoc_STRVAR(bpy_bmlayeraccess_collection__freestyle_edge_doc, "Accessor for Freestyle edge layer.\n\ntype: :class:`BMLayerCollection`" @@ -222,8 +222,7 @@ static PyGetSetDef bpy_bmlayeraccess_face_getseters[] = { {(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT}, {(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT}, {(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR}, - - {(char *)"tex", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__tex_doc, (void *)CD_MTEXPOLY}, + {(char *)"face_map", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__face_map_doc, (void *)CD_FACEMAP}, #ifdef WITH_FREESTYLE {(char *)"freestyle", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__freestyle_face_doc, (void *)CD_FREESTYLE_FACE}, @@ -989,6 +988,7 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer) break; } case CD_PROP_INT: + case CD_FACEMAP: { ret = PyLong_FromLong(*(int *)value); break; @@ -999,11 +999,6 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer) ret = PyBytes_FromStringAndSize(mstring->s, mstring->s_len); break; } - case CD_MTEXPOLY: - { - ret = BPy_BMTexPoly_CreatePyObject(value); - break; - } case CD_MLOOPUV: { ret = BPy_BMLoopUV_CreatePyObject(value); @@ -1074,6 +1069,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj break; } case CD_PROP_INT: + case CD_FACEMAP: { int tmp_val = PyC_Long_AsI32(py_value); if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) { @@ -1102,11 +1098,6 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj } break; } - case CD_MTEXPOLY: - { - ret = BPy_BMTexPoly_AssignPyObject(value, py_value); - break; - } case CD_MLOOPUV: { ret = BPy_BMLoopUV_AssignPyObject(value, py_value); diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c index 7984f625d96..54b33e7b6b6 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c @@ -48,96 +48,6 @@ #include "../generic/py_capi_utils.h" #include "../generic/python_utildefines.h" - -/* Mesh BMTexPoly - * ************** */ - -#define BPy_BMTexPoly_Check(v) (Py_TYPE(v) == &BPy_BMTexPoly_Type) - -typedef struct BPy_BMTexPoly { - PyObject_VAR_HEAD - MTexPoly *data; -} BPy_BMTexPoly; - -extern PyObject *pyrna_id_CreatePyObject(ID *id); -extern bool pyrna_id_FromPyObject(PyObject *obj, ID **id); - -PyDoc_STRVAR(bpy_bmtexpoly_image_doc, -"Image or None.\n\n:type: :class:`bpy.types.Image`" -); -static PyObject *bpy_bmtexpoly_image_get(BPy_BMTexPoly *self, void *UNUSED(closure)) -{ - return pyrna_id_CreatePyObject((ID *)self->data->tpage); -} - -static int bpy_bmtexpoly_image_set(BPy_BMTexPoly *self, PyObject *value, void *UNUSED(closure)) -{ - ID *id; - - if (value == Py_None) { - id = NULL; - } - else if (pyrna_id_FromPyObject(value, &id) && id && GS(id->name) == ID_IM) { - /* pass */ - } - else { - PyErr_Format(PyExc_KeyError, "BMTexPoly.image = x" - "expected an image or None, not '%.200s'", - Py_TYPE(value)->tp_name); - return -1; - } - - id_lib_extern(id); - self->data->tpage = (struct Image *)id; - - return 0; -} - -static PyGetSetDef bpy_bmtexpoly_getseters[] = { - /* attributes match rna_def_mtpoly */ - {(char *)"image", (getter)bpy_bmtexpoly_image_get, (setter)bpy_bmtexpoly_image_set, (char *)bpy_bmtexpoly_image_doc, NULL}, - - {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ -}; - -static PyTypeObject BPy_BMTexPoly_Type; /* bm.loops.layers.uv.active */ - -static void bm_init_types_bmtexpoly(void) -{ - BPy_BMTexPoly_Type.tp_basicsize = sizeof(BPy_BMTexPoly); - - BPy_BMTexPoly_Type.tp_name = "BMTexPoly"; - - BPy_BMTexPoly_Type.tp_doc = NULL; // todo - - BPy_BMTexPoly_Type.tp_getset = bpy_bmtexpoly_getseters; - - BPy_BMTexPoly_Type.tp_flags = Py_TPFLAGS_DEFAULT; - - PyType_Ready(&BPy_BMTexPoly_Type); -} - -int BPy_BMTexPoly_AssignPyObject(struct MTexPoly *mtpoly, PyObject *value) -{ - if (UNLIKELY(!BPy_BMTexPoly_Check(value))) { - PyErr_Format(PyExc_TypeError, "expected BMTexPoly, not a %.200s", Py_TYPE(value)->tp_name); - return -1; - } - else { - *((MTexPoly *)mtpoly) = *(((BPy_BMTexPoly *)value)->data); - return 0; - } -} - -PyObject *BPy_BMTexPoly_CreatePyObject(struct MTexPoly *mtpoly) -{ - BPy_BMTexPoly *self = PyObject_New(BPy_BMTexPoly, &BPy_BMTexPoly_Type); - self->data = mtpoly; - return (PyObject *)self; -} - -/* --- End Mesh BMTexPoly --- */ - /* Mesh Loop UV * ************ */ @@ -797,7 +707,6 @@ PyObject *BPy_BMDeformVert_CreatePyObject(struct MDeformVert *dvert) /* call to init all types */ void BPy_BM_init_types_meshdata(void) { - bm_init_types_bmtexpoly(); bm_init_types_bmloopuv(); bm_init_types_bmloopcol(); bm_init_types_bmdvert(); diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.h b/source/blender/python/bmesh/bmesh_py_types_meshdata.h index 07d8a46cc65..c8ae2596f99 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.h +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.h @@ -40,15 +40,11 @@ typedef struct BPy_BMGenericMeshData { void *data; } BPy_BMGenericMeshData; -struct MTexPoly; struct MLoopUV; struct MLoopCol; struct MDeformVert; struct MVertSkin; -int BPy_BMTexPoly_AssignPyObject(struct MTexPoly *mloopuv, PyObject *value); -PyObject *BPy_BMTexPoly_CreatePyObject(struct MTexPoly *mloopuv); - int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *data, PyObject *value); PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *data); diff --git a/source/blender/python/gawain/CMakeLists.txt b/source/blender/python/gawain/CMakeLists.txt new file mode 100644 index 00000000000..6b6c902f48a --- /dev/null +++ b/source/blender/python/gawain/CMakeLists.txt @@ -0,0 +1,47 @@ +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# Contributor(s): Campbell Barton +# +# ***** END GPL LICENSE BLOCK ***** + +set(INC + . + ../../blenkernel + ../../blenlib + ../../gpu + ../../makesdna + ../../../../intern/gawain + ../../../../intern/guardedalloc + ../../../../intern/glew-mx +) + +set(INC_SYS + ${GLEW_INCLUDE_PATH} + ${PYTHON_INCLUDE_DIRS} +) + +set(SRC + gwn_py_api.c + gwn_py_types.c + + gwn_py_api.h + gwn_py_types.h +) + +add_definitions(${GL_DEFINITIONS}) + +blender_add_lib(bf_python_gawain "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/python/gawain/gwn_py_api.c b/source/blender/python/gawain/gwn_py_api.c new file mode 100644 index 00000000000..d79ef070649 --- /dev/null +++ b/source/blender/python/gawain/gwn_py_api.c @@ -0,0 +1,63 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/gawain/gwn_py_api.c + * \ingroup pygawain + * + * Experimental Python API, not considered public yet (called '_gawain'), + * we may re-expose as public later. + */ + +#include <Python.h> + +#include "gawain/gwn_batch.h" +#include "gawain/gwn_vertex_format.h" + +#include "gwn_py_api.h" +#include "gwn_py_types.h" + +#include "BLI_utildefines.h" + +#include "../generic/python_utildefines.h" + +PyDoc_STRVAR(GWN_doc, +"This module provides access to gawain drawing functions." +); +static struct PyModuleDef GWN_module_def = { + PyModuleDef_HEAD_INIT, + .m_name = "_gawain", /* m_name */ + .m_doc = GWN_doc, /* m_doc */ +}; + +PyObject *BPyInit_gawain(void) +{ + PyObject *sys_modules = PyThreadState_GET()->interp->modules; + PyObject *submodule; + PyObject *mod; + + mod = PyModule_Create(&GWN_module_def); + + /* _gawain.types */ + PyModule_AddObject(mod, "types", (submodule = BPyInit_gawain_types())); + PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); + Py_INCREF(submodule); + + return mod; +} diff --git a/source/blender/python/gawain/gwn_py_api.h b/source/blender/python/gawain/gwn_py_api.h new file mode 100644 index 00000000000..3ef85e8ae0f --- /dev/null +++ b/source/blender/python/gawain/gwn_py_api.h @@ -0,0 +1,30 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __GWN_PY_API_H__ +#define __GWN_PY_API_H__ + +/** \file blender/python/gawain/gwn_py_api.h + * \ingroup pygawain + */ + +PyObject *BPyInit_gawain(void); + +#endif /* __GWN_PY_API_H__ */ diff --git a/source/blender/python/gawain/gwn_py_types.c b/source/blender/python/gawain/gwn_py_types.c new file mode 100644 index 00000000000..3146993d665 --- /dev/null +++ b/source/blender/python/gawain/gwn_py_types.c @@ -0,0 +1,847 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/gawain/gwn_py_types.c + * \ingroup pygawain + * + * - Use ``bpygwn_`` for local API. + * - Use ``BPyGwn_`` for public API. + */ + +#include <Python.h> + +#include "gawain/gwn_batch.h" +#include "gawain/gwn_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 */ + +#ifdef __BIG_ENDIAN__ + /* big endian */ +# define MAKE_ID2(c, d) ((c) << 8 | (d)) +# define MAKE_ID3(a, b, c) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 ) +# define MAKE_ID4(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) ) +#else + /* little endian */ +# define MAKE_ID2(c, d) ((d) << 8 | (c)) +# define MAKE_ID3(a, b, c) ( (int)(c) << 16 | (b) << 8 | (a) ) +# define MAKE_ID4(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) ) +#endif + +/* -------------------------------------------------------------------- */ + +/** \name Enum Conversion + * + * Use with PyArg_ParseTuple's "O&" formatting. + * \{ */ + +static int bpygwn_ParseVertCompType(PyObject *o, void *p) +{ + Py_ssize_t comp_type_id_len; + const char *comp_type_id = _PyUnicode_AsStringAndSize(o, &comp_type_id_len); + if (comp_type_id == NULL) { + PyErr_Format(PyExc_ValueError, + "expected a string, got %s", + Py_TYPE(o)->tp_name); + return 0; + } + + Gwn_VertCompType 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; } + } + } + 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; } + } + } + + PyErr_Format(PyExc_ValueError, + "unknown type literal: '%s'", + comp_type_id); + return 0; + +success: + *((Gwn_VertCompType *)p) = comp_type; + return 1; +} + +static int bpygwn_ParseVertFetchMode(PyObject *o, void *p) +{ + Py_ssize_t mode_id_len; + const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len); + if (mode_id == NULL) { + PyErr_Format(PyExc_ValueError, + "expected a string, got %s", + Py_TYPE(o)->tp_name); + return 0; + } +#define MATCH_ID(id) \ + if (mode_id_len == strlen(STRINGIFY(id))) { \ + if (STREQ(mode_id, STRINGIFY(id))) { \ + mode = GWN_FETCH_##id; \ + goto success; \ + } \ + } ((void)0) + + Gwn_VertFetchMode mode; + MATCH_ID(FLOAT); + MATCH_ID(INT); + MATCH_ID(INT_TO_FLOAT_UNIT); + MATCH_ID(INT_TO_FLOAT); +#undef MATCH_ID + PyErr_Format(PyExc_ValueError, + "unknown type literal: '%s'", + mode_id); + return 0; + +success: + (*(Gwn_VertFetchMode *)p) = mode; + return 1; +} + +static int bpygwn_ParsePrimType(PyObject *o, void *p) +{ + Py_ssize_t mode_id_len; + const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len); + if (mode_id == NULL) { + PyErr_Format(PyExc_ValueError, + "expected a string, got %s", + Py_TYPE(o)->tp_name); + return 0; + } +#define MATCH_ID(id) \ + if (mode_id_len == strlen(STRINGIFY(id))) { \ + if (STREQ(mode_id, STRINGIFY(id))) { \ + mode = GWN_PRIM_##id; \ + goto success; \ + } \ + } ((void)0) + + Gwn_PrimType mode; + MATCH_ID(POINTS); + MATCH_ID(LINES); + MATCH_ID(TRIS); + MATCH_ID(LINE_STRIP); + MATCH_ID(LINE_LOOP); + MATCH_ID(TRI_STRIP); + MATCH_ID(TRI_FAN); + MATCH_ID(LINE_STRIP_ADJ); + +#undef MATCH_ID + PyErr_Format(PyExc_ValueError, + "unknown type literal: '%s'", + mode_id); + return 0; + +success: + (*(Gwn_PrimType *)p) = mode; + return 1; +} + +/** \} */ + + +/* -------------------------------------------------------------------- */ + +/** \name Utility Functions + * \{ */ + +#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; } \ + 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) +{ +#define PY_AS_NATIVE(ty_dst, py_as_native) \ +{ \ + ty_dst *data_dst = data_dst_void; \ + *data_dst = py_as_native(py_src); \ +} ((void)0) + + PY_AS_NATIVE_SWITCH(attr); + +#undef PY_AS_NATIVE +} + +/* No error checking, callers must run PyErr_Occurred */ +static void fill_format_tuple(void *data_dst_void, PyObject *py_src, const Gwn_VertAttr *attr) +{ + const uint len = attr->comp_ct; + +/** + * Args are constants, so range checks will be optimized out if they're nop's. + */ +#define PY_AS_NATIVE(ty_dst, py_as_native) \ + ty_dst *data_dst = data_dst_void; \ + for (uint i = 0; i < len; i++) { \ + data_dst[i] = py_as_native(PyTuple_GET_ITEM(py_src, i)); \ + } ((void)0) + + PY_AS_NATIVE_SWITCH(attr); + +#undef PY_AS_NATIVE +} + +#undef PY_AS_NATIVE_SWITCH +#undef WARN_TYPE_LIMIT_PUSH +#undef WARN_TYPE_LIMIT_POP + +static bool bpygwn_vertbuf_fill_impl( + Gwn_VertBuf *vbo, + uint data_id, PyObject *seq) +{ + bool ok = true; + const Gwn_VertAttr *attr = &vbo->format.attribs[data_id]; + + Gwn_VertBufRaw data_step; + GWN_vertbuf_attr_get_raw_data(vbo, data_id, &data_step); + + PyObject *seq_fast = PySequence_Fast(seq, "Vertex buffer fill"); + if (seq_fast == NULL) { + goto finally; + } + + const uint seq_len = PySequence_Fast_GET_SIZE(seq_fast); + + if (seq_len != vbo->vertex_ct) { + PyErr_Format(PyExc_ValueError, + "Expected a sequence of size %d, got %d", + vbo->vertex_ct, seq_len); + } + + PyObject **seq_items = PySequence_Fast_ITEMS(seq_fast); + + if (attr->comp_ct == 1) { + for (uint i = 0; i < seq_len; i++) { + uchar *data = (uchar *)GWN_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); + PyObject *item = seq_items[i]; + if (!PyTuple_CheckExact(item)) { + PyErr_Format(PyExc_ValueError, + "expected a tuple, got %s", + Py_TYPE(item)->tp_name); + ok = false; + goto finally; + } + if (PyTuple_GET_SIZE(item) != attr->comp_ct) { + PyErr_Format(PyExc_ValueError, + "expected a tuple of size %d, got %d", + attr->comp_ct, PyTuple_GET_SIZE(item)); + ok = false; + goto finally; + } + + /* May trigger error, check below */ + fill_format_tuple(data, item, attr); + } + } + + if (PyErr_Occurred()) { + ok = false; + } + +finally: + + Py_DECREF(seq_fast); + return ok; +} + +/* handy, but not used just now */ +#if 0 +static int bpygwn_find_id(const Gwn_VertFormat *fmt, const char *id) +{ + for (int i = 0; i < fmt->attrib_ct; i++) { + for (uint j = 0; j < fmt->name_ct; j++) { + if (STREQ(fmt->attribs[i].name[j], id)) { + return i; + } + } + } + return -1; +} +#endif + +/** \} */ + + +/* -------------------------------------------------------------------- */ + +/** \name VertFormat Type + * \{ */ + +static PyObject *bpygwn_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) +{ + if (PyTuple_GET_SIZE(args) || (kwds && PyDict_Size(kwds))) { + PyErr_SetString(PyExc_TypeError, + "VertFormat(): takes no arguments"); + return NULL; + } + + BPyGwn_VertFormat *ret = (BPyGwn_VertFormat *)BPyGwn_VertFormat_CreatePyObject(NULL); + + return (PyObject *)ret; +} + +PyDoc_STRVAR(bpygwn_VertFormat_attr_add_doc, +"TODO" +); +static PyObject *bpygwn_VertFormat_attr_add(BPyGwn_VertFormat *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist[] = {"id", "comp_type", "len", "fetch_mode", NULL}; + + struct { + const char *id; + Gwn_VertCompType comp_type; + uint len; + Gwn_VertFetchMode fetch_mode; + } params; + + if (self->fmt.attrib_ct == GWN_VERT_ATTR_MAX_LEN) { + PyErr_SetString(PyExc_ValueError, "Maxumum attr reached " STRINGIFY(GWN_VERT_ATTR_MAX_LEN)); + return NULL; + } + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "$sO&IO&:attr_add", (char **)kwlist, + ¶ms.id, + bpygwn_ParseVertCompType, ¶ms.comp_type, + ¶ms.len, + bpygwn_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); + 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}, + {NULL, NULL, 0, NULL} +}; + + +static void bpygwn_VertFormat_dealloc(BPyGwn_VertFormat *self) +{ + Py_TYPE(self)->tp_free(self); +} + +PyTypeObject BPyGwn_VertFormat_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "Gwn_VertFormat", + .tp_basicsize = sizeof(BPyGwn_VertFormat), + .tp_dealloc = (destructor)bpygwn_VertFormat_dealloc, + .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_methods = bpygwn_VertFormat_methods, + .tp_new = bpygwn_VertFormat_new, +}; + +/** \} */ + + +/* -------------------------------------------------------------------- */ + +/** \name VertBuf Type + * \{ */ + +static PyObject *bpygwn_VertBuf_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) +{ + const char * const keywords[] = {"len", "format", NULL}; + + struct { + BPyGwn_VertFormat *py_fmt; + uint len; + } params; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, + "$IO!:Gwn_VertBuf.__new__", (char **)keywords, + ¶ms.len, + &BPyGwn_VertFormat_Type, ¶ms.py_fmt)) + { + return NULL; + } + + struct Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(¶ms.py_fmt->fmt); + + GWN_vertbuf_data_alloc(vbo, params.len); + + return BPyGwn_VertBuf_CreatePyObject(vbo); +} + +PyDoc_STRVAR(bpygwn_VertBuf_fill_doc, +"TODO" +); +static PyObject *bpygwn_VertBuf_fill(BPyGwn_VertBuf *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist[] = {"id", "data", NULL}; + + struct { + uint id; + PyObject *py_seq_data; + } params; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "$IO:fill", (char **)kwlist, + ¶ms.id, + ¶ms.py_seq_data)) + { + return NULL; + } + + if (params.id >= self->buf->format.attrib_ct) { + PyErr_Format(PyExc_ValueError, + "Format id %d out of range", + params.id); + return NULL; + } + + if (self->buf->vbo_id != 0) { + PyErr_SetString(PyExc_ValueError, + "Can't fill, buffer already in use"); + return NULL; + } + + if (!bpygwn_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}, + {NULL, NULL, 0, NULL} +}; + +static void bpygwn_VertBuf_dealloc(BPyGwn_VertBuf *self) +{ + GWN_vertbuf_discard(self->buf); + Py_TYPE(self)->tp_free(self); +} + +PyTypeObject BPyGwn_VertBuf_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "Gwn_VertBuf", + .tp_basicsize = sizeof(BPyGwn_VertBuf), + .tp_dealloc = (destructor)bpygwn_VertBuf_dealloc, + .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_methods = bpygwn_VertBuf_methods, + .tp_new = bpygwn_VertBuf_new, +}; + +/** \} */ + + +/* -------------------------------------------------------------------- */ + +/** \name VertBatch Type + * \{ */ + +static PyObject *bpygwn_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; + } params; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, + "$O&O!:Gwn_Batch.__new__", (char **)keywords, + bpygwn_ParsePrimType, ¶ms.type_id, + &BPyGwn_VertBuf_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); + +#ifdef USE_GWN_PY_REFERENCES + ret->references = PyList_New(1); + PyList_SET_ITEM(ret->references, 0, (PyObject *)params.py_buf); + Py_INCREF(params.py_buf); + PyObject_GC_Track(ret); +#endif + + return (PyObject *)ret; +} + +PyDoc_STRVAR(bpygwn_VertBatch_vertbuf_add_doc, +"TODO" +); +static PyObject *bpygwn_VertBatch_vertbuf_add(BPyGwn_Batch *self, BPyGwn_VertBuf *py_buf) +{ + if (!BPyGwn_VertBuf_Check(py_buf)) { + PyErr_Format(PyExc_TypeError, + "Expected a Gwn_VertBuf, got %s", + Py_TYPE(py_buf)->tp_name); + return NULL; + } + + if (self->batch->verts[0]->vertex_ct != py_buf->buf->vertex_ct) { + PyErr_Format(PyExc_TypeError, + "Expected %d length, got %d", + self->batch->verts[0]->vertex_ct, py_buf->buf->vertex_ct); + return NULL; + } + +#ifdef USE_GWN_PY_REFERENCES + /* Hold user */ + PyList_Append(self->references, (PyObject *)py_buf); +#endif + + GWN_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, +"TODO" +); +static PyObject *bpygwn_VertBatch_program_set_builtin(BPyGwn_Batch *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist[] = {"id", NULL}; + + struct { + const char *shader; + } params; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "s:program_set_builtin", (char **)kwlist, + ¶ms.shader)) + { + return NULL; + } + + GPUBuiltinShader shader; + +#define MATCH_ID(id) \ + if (STREQ(params.shader, STRINGIFY(id))) { \ + shader = GPU_SHADER_##id; \ + goto success; \ + } ((void)0) + + MATCH_ID(2D_FLAT_COLOR); + MATCH_ID(2D_SMOOTH_COLOR); + MATCH_ID(2D_UNIFORM_COLOR); + + MATCH_ID(3D_FLAT_COLOR); + MATCH_ID(3D_SMOOTH_COLOR); + MATCH_ID(3D_UNIFORM_COLOR); + +#undef MATCH_ID + + PyErr_SetString(PyExc_ValueError, + "shader name not known"); + return NULL; + +success: + GWN_batch_program_set_builtin(self->batch, shader); + Py_RETURN_NONE; +} + +static PyObject *bpygwn_VertBatch_uniform_bool(BPyGwn_Batch *self, PyObject *args) +{ + struct { + const char *id; + bool values[1]; + } params; + + if (!PyArg_ParseTuple( + args, "sO&:uniform_bool", + ¶ms.id, + PyC_ParseBool, ¶ms.values[0])) + { + return NULL; + } + + GWN_batch_uniform_1b(self->batch, params.id, params.values[0]); + Py_RETURN_NONE; +} + +static PyObject *bpygwn_VertBatch_uniform_i32(BPyGwn_Batch *self, PyObject *args) +{ + struct { + const char *id; + int values[1]; + } params; + + if (!PyArg_ParseTuple( + args, "si:uniform_i32", + ¶ms.id, + ¶ms.values[0])) + { + return NULL; + } + + GWN_batch_uniform_1i(self->batch, params.id, params.values[0]); + Py_RETURN_NONE; +} + +static PyObject *bpygwn_VertBatch_uniform_f32(BPyGwn_Batch *self, PyObject *args) +{ + struct { + const char *id; + float values[4]; + } params; + + if (!PyArg_ParseTuple( + args, "sf|fff:uniform_f32", + ¶ms.id, + ¶ms.values[0], ¶ms.values[1], ¶ms.values[2], ¶ms.values[3])) + { + return NULL; + } + + 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; + default: + BLI_assert(0); + } + Py_RETURN_NONE; +} + +PyDoc_STRVAR(bpygwn_VertBatch_draw_doc, +"TODO" +); +static PyObject *bpygwn_VertBatch_draw(BPyGwn_Batch *self) +{ + if (!glIsProgram(self->batch->program)) { + PyErr_SetString(PyExc_ValueError, + "batch program has not not set"); + } + GWN_batch_draw(self->batch); + Py_RETURN_NONE; +} + +static PyObject *bpygwn_VertBatch_program_use_begin(BPyGwn_Batch *self) +{ + if (!glIsProgram(self->batch->program)) { + PyErr_SetString(PyExc_ValueError, + "batch program has not not set"); + } + GWN_batch_program_use_begin(self->batch); + Py_RETURN_NONE; +} + +static PyObject *bpygwn_VertBatch_program_use_end(BPyGwn_Batch *self) +{ + if (!glIsProgram(self->batch->program)) { + PyErr_SetString(PyExc_ValueError, + "batch program has not not set"); + } + GWN_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, + METH_VARARGS, NULL}, + {"uniform_i32", (PyCFunction)bpygwn_VertBatch_uniform_i32, + METH_VARARGS, NULL}, + {"uniform_f32", (PyCFunction)bpygwn_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, + METH_NOARGS, ""}, + {"program_use_end", (PyCFunction)bpygwn_VertBatch_program_use_end, + METH_NOARGS, ""}, + {NULL, NULL, 0, NULL} +}; + +#ifdef USE_GWN_PY_REFERENCES + +static int bpygwn_Batch_traverse(BPyGwn_Batch *self, visitproc visit, void *arg) +{ + Py_VISIT(self->references); + return 0; +} + +static int bpygwn_Batch_clear(BPyGwn_Batch *self) +{ + Py_CLEAR(self->references); + return 0; +} + +#endif + +static void bpygwn_Batch_dealloc(BPyGwn_Batch *self) +{ + GWN_batch_discard(self->batch); + +#ifdef USE_GWN_PY_REFERENCES + if (self->references) { + PyObject_GC_UnTrack(self); + bpygwn_Batch_clear(self); + Py_XDECREF(self->references); + } +#endif + + Py_TYPE(self)->tp_free(self); +} + +PyTypeObject BPyGwn_Batch_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_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + .tp_traverse = (traverseproc)bpygwn_Batch_traverse, + .tp_clear = (inquiry)bpygwn_Batch_clear, +#else + .tp_flags = Py_TPFLAGS_DEFAULT, +#endif + .tp_methods = bpygwn_VertBatch_methods, + .tp_new = bpygwn_Batch_new, +}; + +/* -------------------------------------------------------------------- */ + + +/** \name Gawain Types Module + * \{ */ + +static struct PyModuleDef BPy_BM_types_module_def = { + PyModuleDef_HEAD_INIT, + .m_name = "_gawain.types", +}; + +PyObject *BPyInit_gawain_types(void) +{ + PyObject *submodule; + + submodule = PyModule_Create(&BPy_BM_types_module_def); + + if (PyType_Ready(&BPyGwn_VertFormat_Type) < 0) + return NULL; + if (PyType_Ready(&BPyGwn_VertBuf_Type) < 0) + return NULL; + if (PyType_Ready(&BPyGwn_Batch_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); + +#undef MODULE_TYPE_ADD + + return submodule; +} + +/** \} */ + + +/* -------------------------------------------------------------------- */ + +/** \name Public API + * \{ */ + +PyObject *BPyGwn_VertFormat_CreatePyObject(Gwn_VertFormat *fmt) +{ + BPyGwn_VertFormat *self; + + self = PyObject_New(BPyGwn_VertFormat, &BPyGwn_VertFormat_Type); + if (fmt) { + self->fmt = *fmt; + } + else { + memset(&self->fmt, 0, sizeof(self->fmt)); + } + + return (PyObject *)self; +} + +PyObject *BPyGwn_VertBuf_CreatePyObject(Gwn_VertBuf *buf) +{ + BPyGwn_VertBuf *self; + + self = PyObject_New(BPyGwn_VertBuf, &BPyGwn_VertBuf_Type); + self->buf = buf; + + return (PyObject *)self; +} + + +PyObject *BPyGwn_Batch_CreatePyObject(Gwn_Batch *batch) +{ + BPyGwn_Batch *self; + +#ifdef USE_GWN_PY_REFERENCES + self = (BPyGwn_Batch *)_PyObject_GC_New(&BPyGwn_Batch_Type); + self->references = NULL; +#else + self = PyObject_New(BPyGwn_Batch, &BPyGwn_Batch_Type); +#endif + + self->batch = batch; + + return (PyObject *)self; +} + +/** \} */ diff --git a/source/blender/python/gawain/gwn_py_types.h b/source/blender/python/gawain/gwn_py_types.h new file mode 100644 index 00000000000..dde6cf98827 --- /dev/null +++ b/source/blender/python/gawain/gwn_py_types.h @@ -0,0 +1,67 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/gawain/gwn_py_types.h + * \ingroup pygawain + */ + +#ifndef __GWN_PY_TYPES_H__ +#define __GWN_PY_TYPES_H__ + +#include "BLI_compiler_attrs.h" + +#define USE_GWN_PY_REFERENCES + +extern PyTypeObject BPyGwn_VertFormat_Type; +extern PyTypeObject BPyGwn_VertBuf_Type; +extern PyTypeObject BPyGwn_Batch_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) + +typedef struct BPyGwn_VertFormat { + PyObject_VAR_HEAD + struct Gwn_VertFormat fmt; +} BPyGwn_VertFormat; + +typedef struct BPyGwn_VertBuf { + PyObject_VAR_HEAD + /* The buf is owned, we may support thin wrapped batches later. */ + struct Gwn_VertBuf *buf; +} BPyGwn_VertBuf; + +typedef struct BPyGwn_Batch { + PyObject_VAR_HEAD + /* The batch is owned, we may support thin wrapped batches later. */ + struct Gwn_Batch *batch; +#ifdef USE_GWN_PY_REFERENCES + /* Just to keep a user to prevent freeing buf's we're using */ + PyObject *references; +#endif +} BPyGwn_Batch; + +PyObject *BPyInit_gawain_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); + +#endif /* __GWN_PY_TYPES_H__ */ diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 072021c6ac9..827b69f5403 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -185,11 +185,13 @@ #define GLbitfield_ref(num) &bgl_var##num #define GLbitfield_def(num) /* unsigned */ int GLbitfield_var(num) +#if 0 /* typedef signed char GLbyte; */ #define GLbyte_str "b" #define GLbyte_var(num) bgl_var##num #define GLbyte_ref(num) &bgl_var##num #define GLbyte_def(num) signed char GLbyte_var(num) +#endif /* typedef short GLshort; */ #define GLshort_str "h" @@ -227,11 +229,13 @@ #define GLubyte_ref(num) &bgl_var##num #define GLubyte_def(num) /* unsigned */ char GLubyte_var(num) +#if 0 /* typedef unsigned short GLushort; */ #define GLushort_str "H" #define GLushort_var(num) bgl_var##num #define GLushort_ref(num) &bgl_var##num #define GLushort_def(num) /* unsigned */ short GLushort_var(num) +#endif /* typedef unsigned int GLuint; */ #define GLuint_str "I" @@ -1073,358 +1077,71 @@ static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) \ ret_ret_##ret; \ } -#define BGLU_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; \ - } \ - ret_set_##ret glu##funcname (arg_var arg_list); \ - ret_ret_##ret; \ -} - /* GL_VERSION_1_0 */ -BGL_Wrap(Accum, void, (GLenum, GLfloat)) -BGL_Wrap(AlphaFunc, void, (GLenum, GLfloat)) -BGL_Wrap(Begin, void, (GLenum)) -BGL_Wrap(Bitmap, void, (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat, GLfloat, GLubyteP)) BGL_Wrap(BlendFunc, void, (GLenum, GLenum)) -BGL_Wrap(CallList, void, (GLuint)) -BGL_Wrap(CallLists, void, (GLsizei, GLenum, GLvoidP)) BGL_Wrap(Clear, void, (GLbitfield)) -BGL_Wrap(ClearAccum, void, (GLfloat, GLfloat, GLfloat, GLfloat)) BGL_Wrap(ClearColor, void, (GLfloat, GLfloat, GLfloat, GLfloat)) BGL_Wrap(ClearDepth, void, (GLdouble)) -BGL_Wrap(ClearIndex, void, (GLfloat)) BGL_Wrap(ClearStencil, void, (GLint)) -BGL_Wrap(ClipPlane, void, (GLenum, GLdoubleP)) -BGL_Wrap(Color3b, void, (GLbyte, GLbyte, GLbyte)) -BGL_Wrap(Color3bv, void, (GLbyteP)) -BGL_Wrap(Color3d, void, (GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Color3dv, void, (GLdoubleP)) -BGL_Wrap(Color3f, void, (GLfloat, GLfloat, GLfloat)) -BGL_Wrap(Color3fv, void, (GLfloatP)) -BGL_Wrap(Color3i, void, (GLint, GLint, GLint)) -BGL_Wrap(Color3iv, void, (GLintP)) -BGL_Wrap(Color3s, void, (GLshort, GLshort, GLshort)) -BGL_Wrap(Color3sv, void, (GLshortP)) -BGL_Wrap(Color3ub, void, (GLubyte, GLubyte, GLubyte)) -BGL_Wrap(Color3ubv, void, (GLubyteP)) -BGL_Wrap(Color3ui, void, (GLuint, GLuint, GLuint)) -BGL_Wrap(Color3uiv, void, (GLuintP)) -BGL_Wrap(Color3us, void, (GLushort, GLushort, GLushort)) -BGL_Wrap(Color3usv, void, (GLushortP)) -BGL_Wrap(Color4b, void, (GLbyte, GLbyte, GLbyte, GLbyte)) -BGL_Wrap(Color4bv, void, (GLbyteP)) -BGL_Wrap(Color4d, void, (GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Color4dv, void, (GLdoubleP)) -BGL_Wrap(Color4f, void, (GLfloat, GLfloat, GLfloat, GLfloat)) -BGL_Wrap(Color4fv, void, (GLfloatP)) -BGL_Wrap(Color4i, void, (GLint, GLint, GLint, GLint)) -BGL_Wrap(Color4iv, void, (GLintP)) -BGL_Wrap(Color4s, void, (GLshort, GLshort, GLshort, GLshort)) -BGL_Wrap(Color4sv, void, (GLshortP)) -BGL_Wrap(Color4ub, void, (GLubyte, GLubyte, GLubyte, GLubyte)) -BGL_Wrap(Color4ubv, void, (GLubyteP)) -BGL_Wrap(Color4ui, void, (GLuint, GLuint, GLuint, GLuint)) -BGL_Wrap(Color4uiv, void, (GLuintP)) -BGL_Wrap(Color4us, void, (GLushort, GLushort, GLushort, GLushort)) -BGL_Wrap(Color4usv, void, (GLushortP)) BGL_Wrap(ColorMask, void, (GLboolean, GLboolean, GLboolean, GLboolean)) -BGL_Wrap(ColorMaterial, void, (GLenum, GLenum)) -BGL_Wrap(CopyPixels, void, (GLint, GLint, GLsizei, GLsizei, GLenum)) BGL_Wrap(CullFace, void, (GLenum)) -BGL_Wrap(DeleteLists, void, (GLuint, GLsizei)) BGL_Wrap(DepthFunc, void, (GLenum)) BGL_Wrap(DepthMask, void, (GLboolean)) BGL_Wrap(DepthRange, void, (GLdouble, GLdouble)) BGL_Wrap(Disable, void, (GLenum)) BGL_Wrap(DrawBuffer, void, (GLenum)) -BGL_Wrap(DrawPixels, void, (GLsizei, GLsizei, GLenum, GLenum, GLvoidP)) -BGL_Wrap(EdgeFlag, void, (GLboolean)) -BGL_Wrap(EdgeFlagv, void, (GLbooleanP)) BGL_Wrap(Enable, void, (GLenum)) -BGL_Wrap(End, void, (void)) -BGL_Wrap(EndList, void, (void)) -BGL_Wrap(EvalCoord1d, void, (GLdouble)) -BGL_Wrap(EvalCoord1dv, void, (GLdoubleP)) -BGL_Wrap(EvalCoord1f, void, (GLfloat)) -BGL_Wrap(EvalCoord1fv, void, (GLfloatP)) -BGL_Wrap(EvalCoord2d, void, (GLdouble, GLdouble)) -BGL_Wrap(EvalCoord2dv, void, (GLdoubleP)) -BGL_Wrap(EvalCoord2f, void, (GLfloat, GLfloat)) -BGL_Wrap(EvalCoord2fv, void, (GLfloatP)) -BGL_Wrap(EvalMesh1, void, (GLenum, GLint, GLint)) -BGL_Wrap(EvalMesh2, void, (GLenum, GLint, GLint, GLint, GLint)) -BGL_Wrap(EvalPoint1, void, (GLint)) -BGL_Wrap(EvalPoint2, void, (GLint, GLint)) -BGL_Wrap(FeedbackBuffer, void, (GLsizei, GLenum, GLfloatP)) BGL_Wrap(Finish, void, (void)) BGL_Wrap(Flush, void, (void)) -BGL_Wrap(Fogf, void, (GLenum, GLfloat)) -BGL_Wrap(Fogfv, void, (GLenum, GLfloatP)) -BGL_Wrap(Fogi, void, (GLenum, GLint)) -BGL_Wrap(Fogiv, void, (GLenum, GLintP)) BGL_Wrap(FrontFace, void, (GLenum)) -BGL_Wrap(Frustum, void, (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(GenLists, GLuint, (GLsizei)) BGL_Wrap(GetBooleanv, void, (GLenum, GLbooleanP)) -BGL_Wrap(GetClipPlane, void, (GLenum, GLdoubleP)) BGL_Wrap(GetDoublev, void, (GLenum, GLdoubleP)) BGL_Wrap(GetError, GLenum, (void)) BGL_Wrap(GetFloatv, void, (GLenum, GLfloatP)) BGL_Wrap(GetIntegerv, void, (GLenum, GLintP)) -BGL_Wrap(GetLightfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(GetLightiv, void, (GLenum, GLenum, GLintP)) -BGL_Wrap(GetMapdv, void, (GLenum, GLenum, GLdoubleP)) -BGL_Wrap(GetMapfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(GetMapiv, void, (GLenum, GLenum, GLintP)) -BGL_Wrap(GetMaterialfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(GetMaterialiv, void, (GLenum, GLenum, GLintP)) -BGL_Wrap(GetPixelMapfv, void, (GLenum, GLfloatP)) -BGL_Wrap(GetPixelMapuiv, void, (GLenum, GLuintP)) -BGL_Wrap(GetPixelMapusv, void, (GLenum, GLushortP)) -BGL_Wrap(GetPolygonStipple, void, (GLubyteP)) BGL_Wrap(GetString, GLstring, (GLenum)) -BGL_Wrap(GetTexEnvfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(GetTexEnviv, void, (GLenum, GLenum, GLintP)) -BGL_Wrap(GetTexGendv, void, (GLenum, GLenum, GLdoubleP)) -BGL_Wrap(GetTexGenfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(GetTexGeniv, void, (GLenum, GLenum, GLintP)) BGL_Wrap(GetTexImage, void, (GLenum, GLint, GLenum, GLenum, GLvoidP)) BGL_Wrap(GetTexLevelParameterfv, void, (GLenum, GLint, GLenum, GLfloatP)) BGL_Wrap(GetTexLevelParameteriv, void, (GLenum, GLint, GLenum, GLintP)) BGL_Wrap(GetTexParameterfv, void, (GLenum, GLenum, GLfloatP)) BGL_Wrap(GetTexParameteriv, void, (GLenum, GLenum, GLintP)) BGL_Wrap(Hint, void, (GLenum, GLenum)) -BGL_Wrap(IndexMask, void, (GLuint)) -BGL_Wrap(Indexd, void, (GLdouble)) -BGL_Wrap(Indexdv, void, (GLdoubleP)) -BGL_Wrap(Indexf, void, (GLfloat)) -BGL_Wrap(Indexfv, void, (GLfloatP)) -BGL_Wrap(Indexi, void, (GLint)) -BGL_Wrap(Indexiv, void, (GLintP)) -BGL_Wrap(Indexs, void, (GLshort)) -BGL_Wrap(Indexsv, void, (GLshortP)) -BGL_Wrap(InitNames, void, (void)) BGL_Wrap(IsEnabled, GLboolean, (GLenum)) -BGL_Wrap(IsList, GLboolean, (GLuint)) -BGL_Wrap(LightModelf, void, (GLenum, GLfloat)) -BGL_Wrap(LightModelfv, void, (GLenum, GLfloatP)) -BGL_Wrap(LightModeli, void, (GLenum, GLint)) -BGL_Wrap(LightModeliv, void, (GLenum, GLintP)) -BGL_Wrap(Lightf, void, (GLenum, GLenum, GLfloat)) -BGL_Wrap(Lightfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(Lighti, void, (GLenum, GLenum, GLint)) -BGL_Wrap(Lightiv, void, (GLenum, GLenum, GLintP)) -BGL_Wrap(LineStipple, void, (GLint, GLushort)) BGL_Wrap(LineWidth, void, (GLfloat)) -BGL_Wrap(ListBase, void, (GLuint)) -BGL_Wrap(LoadIdentity, void, (void)) -BGL_Wrap(LoadMatrixd, void, (GLdoubleP)) -BGL_Wrap(LoadMatrixf, void, (GLfloatP)) -BGL_Wrap(LoadName, void, (GLuint)) BGL_Wrap(LogicOp, void, (GLenum)) -BGL_Wrap(Map1d, void, (GLenum, GLdouble, GLdouble, GLint, GLint, GLdoubleP)) -BGL_Wrap(Map1f, void, (GLenum, GLfloat, GLfloat, GLint, GLint, GLfloatP)) -BGL_Wrap(Map2d, void, (GLenum, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, GLdoubleP)) -BGL_Wrap(Map2f, void, (GLenum, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, GLfloatP)) -BGL_Wrap(MapGrid1d, void, (GLint, GLdouble, GLdouble)) -BGL_Wrap(MapGrid1f, void, (GLint, GLfloat, GLfloat)) -BGL_Wrap(MapGrid2d, void, (GLint, GLdouble, GLdouble, GLint, GLdouble, GLdouble)) -BGL_Wrap(MapGrid2f, void, (GLint, GLfloat, GLfloat, GLint, GLfloat, GLfloat)) -BGL_Wrap(Materialf, void, (GLenum, GLenum, GLfloat)) -BGL_Wrap(Materialfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(Materiali, void, (GLenum, GLenum, GLint)) -BGL_Wrap(Materialiv, void, (GLenum, GLenum, GLintP)) -BGL_Wrap(MatrixMode, void, (GLenum)) -BGL_Wrap(MultMatrixd, void, (GLdoubleP)) -BGL_Wrap(MultMatrixf, void, (GLfloatP)) -BGL_Wrap(NewList, void, (GLuint, GLenum)) -BGL_Wrap(Normal3b, void, (GLbyte, GLbyte, GLbyte)) -BGL_Wrap(Normal3bv, void, (GLbyteP)) -BGL_Wrap(Normal3d, void, (GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Normal3dv, void, (GLdoubleP)) -BGL_Wrap(Normal3f, void, (GLfloat, GLfloat, GLfloat)) -BGL_Wrap(Normal3fv, void, (GLfloatP)) -BGL_Wrap(Normal3i, void, (GLint, GLint, GLint)) -BGL_Wrap(Normal3iv, void, (GLintP)) -BGL_Wrap(Normal3s, void, (GLshort, GLshort, GLshort)) -BGL_Wrap(Normal3sv, void, (GLshortP)) -BGL_Wrap(Ortho, void, (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(PassThrough, void, (GLfloat)) -BGL_Wrap(PixelMapfv, void, (GLenum, GLsizei, GLfloatP)) -BGL_Wrap(PixelMapuiv, void, (GLenum, GLsizei, GLuintP)) -BGL_Wrap(PixelMapusv, void, (GLenum, GLsizei, GLushortP)) BGL_Wrap(PixelStoref, void, (GLenum, GLfloat)) BGL_Wrap(PixelStorei, void, (GLenum, GLint)) -BGL_Wrap(PixelTransferf, void, (GLenum, GLfloat)) -BGL_Wrap(PixelTransferi, void, (GLenum, GLint)) -BGL_Wrap(PixelZoom, void, (GLfloat, GLfloat)) BGL_Wrap(PointSize, void, (GLfloat)) BGL_Wrap(PolygonMode, void, (GLenum, GLenum)) -BGL_Wrap(PolygonStipple, void, (GLubyteP)) -BGL_Wrap(PopAttrib, void, (void)) -BGL_Wrap(PopMatrix, void, (void)) -BGL_Wrap(PopName, void, (void)) -BGL_Wrap(PushAttrib, void, (GLbitfield)) -BGL_Wrap(PushMatrix, void, (void)) -BGL_Wrap(PushName, void, (GLuint)) -BGL_Wrap(RasterPos2d, void, (GLdouble, GLdouble)) -BGL_Wrap(RasterPos2dv, void, (GLdoubleP)) -BGL_Wrap(RasterPos2f, void, (GLfloat, GLfloat)) -BGL_Wrap(RasterPos2fv, void, (GLfloatP)) -BGL_Wrap(RasterPos2i, void, (GLint, GLint)) -BGL_Wrap(RasterPos2iv, void, (GLintP)) -BGL_Wrap(RasterPos2s, void, (GLshort, GLshort)) -BGL_Wrap(RasterPos2sv, void, (GLshortP)) -BGL_Wrap(RasterPos3d, void, (GLdouble, GLdouble, GLdouble)) -BGL_Wrap(RasterPos3dv, void, (GLdoubleP)) -BGL_Wrap(RasterPos3f, void, (GLfloat, GLfloat, GLfloat)) -BGL_Wrap(RasterPos3fv, void, (GLfloatP)) -BGL_Wrap(RasterPos3i, void, (GLint, GLint, GLint)) -BGL_Wrap(RasterPos3iv, void, (GLintP)) -BGL_Wrap(RasterPos3s, void, (GLshort, GLshort, GLshort)) -BGL_Wrap(RasterPos3sv, void, (GLshortP)) -BGL_Wrap(RasterPos4d, void, (GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(RasterPos4dv, void, (GLdoubleP)) -BGL_Wrap(RasterPos4f, void, (GLfloat, GLfloat, GLfloat, GLfloat)) -BGL_Wrap(RasterPos4fv, void, (GLfloatP)) -BGL_Wrap(RasterPos4i, void, (GLint, GLint, GLint, GLint)) -BGL_Wrap(RasterPos4iv, void, (GLintP)) -BGL_Wrap(RasterPos4s, void, (GLshort, GLshort, GLshort, GLshort)) -BGL_Wrap(RasterPos4sv, void, (GLshortP)) BGL_Wrap(ReadBuffer, void, (GLenum)) BGL_Wrap(ReadPixels, void, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP)) -BGL_Wrap(Rectd, void, (GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Rectdv, void, (GLdoubleP, GLdoubleP)) -BGL_Wrap(Rectf, void, (GLfloat, GLfloat, GLfloat, GLfloat)) -BGL_Wrap(Rectfv, void, (GLfloatP, GLfloatP)) -BGL_Wrap(Recti, void, (GLint, GLint, GLint, GLint)) -BGL_Wrap(Rectiv, void, (GLintP, GLintP)) -BGL_Wrap(Rects, void, (GLshort, GLshort, GLshort, GLshort)) -BGL_Wrap(Rectsv, void, (GLshortP, GLshortP)) -BGL_Wrap(RenderMode, GLint, (GLenum)) -BGL_Wrap(Rotated, void, (GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Rotatef, void, (GLfloat, GLfloat, GLfloat, GLfloat)) -BGL_Wrap(Scaled, void, (GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Scalef, void, (GLfloat, GLfloat, GLfloat)) BGL_Wrap(Scissor, void, (GLint, GLint, GLsizei, GLsizei)) -BGL_Wrap(SelectBuffer, void, (GLsizei, GLuintP)) -BGL_Wrap(ShadeModel, void, (GLenum)) BGL_Wrap(StencilFunc, void, (GLenum, GLint, GLuint)) BGL_Wrap(StencilMask, void, (GLuint)) BGL_Wrap(StencilOp, void, (GLenum, GLenum, GLenum)) -BGL_Wrap(TexCoord1d, void, (GLdouble)) -BGL_Wrap(TexCoord1dv, void, (GLdoubleP)) -BGL_Wrap(TexCoord1f, void, (GLfloat)) -BGL_Wrap(TexCoord1fv, void, (GLfloatP)) -BGL_Wrap(TexCoord1i, void, (GLint)) -BGL_Wrap(TexCoord1iv, void, (GLintP)) -BGL_Wrap(TexCoord1s, void, (GLshort)) -BGL_Wrap(TexCoord1sv, void, (GLshortP)) -BGL_Wrap(TexCoord2d, void, (GLdouble, GLdouble)) -BGL_Wrap(TexCoord2dv, void, (GLdoubleP)) -BGL_Wrap(TexCoord2f, void, (GLfloat, GLfloat)) -BGL_Wrap(TexCoord2fv, void, (GLfloatP)) -BGL_Wrap(TexCoord2i, void, (GLint, GLint)) -BGL_Wrap(TexCoord2iv, void, (GLintP)) -BGL_Wrap(TexCoord2s, void, (GLshort, GLshort)) -BGL_Wrap(TexCoord2sv, void, (GLshortP)) -BGL_Wrap(TexCoord3d, void, (GLdouble, GLdouble, GLdouble)) -BGL_Wrap(TexCoord3dv, void, (GLdoubleP)) -BGL_Wrap(TexCoord3f, void, (GLfloat, GLfloat, GLfloat)) -BGL_Wrap(TexCoord3fv, void, (GLfloatP)) -BGL_Wrap(TexCoord3i, void, (GLint, GLint, GLint)) -BGL_Wrap(TexCoord3iv, void, (GLintP)) -BGL_Wrap(TexCoord3s, void, (GLshort, GLshort, GLshort)) -BGL_Wrap(TexCoord3sv, void, (GLshortP)) -BGL_Wrap(TexCoord4d, void, (GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(TexCoord4dv, void, (GLdoubleP)) -BGL_Wrap(TexCoord4f, void, (GLfloat, GLfloat, GLfloat, GLfloat)) -BGL_Wrap(TexCoord4fv, void, (GLfloatP)) -BGL_Wrap(TexCoord4i, void, (GLint, GLint, GLint, GLint)) -BGL_Wrap(TexCoord4iv, void, (GLintP)) -BGL_Wrap(TexCoord4s, void, (GLshort, GLshort, GLshort, GLshort)) -BGL_Wrap(TexCoord4sv, void, (GLshortP)) -BGL_Wrap(TexEnvf, void, (GLenum, GLenum, GLfloat)) -BGL_Wrap(TexEnvfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(TexEnvi, void, (GLenum, GLenum, GLint)) -BGL_Wrap(TexEnviv, void, (GLenum, GLenum, GLintP)) -BGL_Wrap(TexGend, void, (GLenum, GLenum, GLdouble)) -BGL_Wrap(TexGendv, void, (GLenum, GLenum, GLdoubleP)) -BGL_Wrap(TexGenf, void, (GLenum, GLenum, GLfloat)) -BGL_Wrap(TexGenfv, void, (GLenum, GLenum, GLfloatP)) -BGL_Wrap(TexGeni, void, (GLenum, GLenum, GLint)) -BGL_Wrap(TexGeniv, void, (GLenum, GLenum, GLintP)) BGL_Wrap(TexImage1D, void, (GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, GLvoidP)) BGL_Wrap(TexImage2D, void, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP)) BGL_Wrap(TexParameterf, void, (GLenum, GLenum, GLfloat)) BGL_Wrap(TexParameterfv, void, (GLenum, GLenum, GLfloatP)) BGL_Wrap(TexParameteri, void, (GLenum, GLenum, GLint)) BGL_Wrap(TexParameteriv, void, (GLenum, GLenum, GLintP)) -BGL_Wrap(Translated, void, (GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Translatef, void, (GLfloat, GLfloat, GLfloat)) -BGL_Wrap(Vertex2d, void, (GLdouble, GLdouble)) -BGL_Wrap(Vertex2dv, void, (GLdoubleP)) -BGL_Wrap(Vertex2f, void, (GLfloat, GLfloat)) -BGL_Wrap(Vertex2fv, void, (GLfloatP)) -BGL_Wrap(Vertex2i, void, (GLint, GLint)) -BGL_Wrap(Vertex2iv, void, (GLintP)) -BGL_Wrap(Vertex2s, void, (GLshort, GLshort)) -BGL_Wrap(Vertex2sv, void, (GLshortP)) -BGL_Wrap(Vertex3d, void, (GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Vertex3dv, void, (GLdoubleP)) -BGL_Wrap(Vertex3f, void, (GLfloat, GLfloat, GLfloat)) -BGL_Wrap(Vertex3fv, void, (GLfloatP)) -BGL_Wrap(Vertex3i, void, (GLint, GLint, GLint)) -BGL_Wrap(Vertex3iv, void, (GLintP)) -BGL_Wrap(Vertex3s, void, (GLshort, GLshort, GLshort)) -BGL_Wrap(Vertex3sv, void, (GLshortP)) -BGL_Wrap(Vertex4d, void, (GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(Vertex4dv, void, (GLdoubleP)) -BGL_Wrap(Vertex4f, void, (GLfloat, GLfloat, GLfloat, GLfloat)) -BGL_Wrap(Vertex4fv, void, (GLfloatP)) -BGL_Wrap(Vertex4i, void, (GLint, GLint, GLint, GLint)) -BGL_Wrap(Vertex4iv, void, (GLintP)) -BGL_Wrap(Vertex4s, void, (GLshort, GLshort, GLshort, GLshort)) -BGL_Wrap(Vertex4sv, void, (GLshortP)) BGL_Wrap(Viewport, void, (GLint, GLint, GLsizei, GLsizei)) /* GL_VERSION_1_1 */ -BGL_Wrap(AreTexturesResident, GLboolean, (GLsizei, GLuintP, GLbooleanP)) -BGL_Wrap(ArrayElement, void, (GLint)) BGL_Wrap(BindTexture, void, (GLenum, GLuint)) -BGL_Wrap(ColorPointer, void, (GLint, GLenum, GLsizei, GLvoidP)) BGL_Wrap(CopyTexImage1D, void, (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint)) BGL_Wrap(CopyTexImage2D, void, (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint)) BGL_Wrap(CopyTexSubImage1D, void, (GLenum, GLint, GLint, GLint, GLint, GLsizei)) BGL_Wrap(CopyTexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei)) BGL_Wrap(DeleteTextures, void, (GLsizei, GLuintP)) -BGL_Wrap(DisableClientState, void, (GLenum)) BGL_Wrap(DrawArrays, void, (GLenum, GLint, GLsizei)) BGL_Wrap(DrawElements, void, (GLenum, GLsizei, GLenum, GLvoidP)) -BGL_Wrap(EdgeFlagPointer, void, (GLsizei, GLvoidP)) -BGL_Wrap(EnableClientState, void, (GLenum)) BGL_Wrap(GenTextures, void, (GLsizei, GLuintP)) -BGL_Wrap(GetPointerv, void, (GLenum, GLvoidP)) -BGL_Wrap(IndexPointer, void, (GLenum, GLsizei, GLvoidP)) -BGL_Wrap(Indexub, void, (GLubyte)) -BGL_Wrap(Indexubv, void, (GLubyteP)) -BGL_Wrap(InterleavedArrays, void, (GLenum, GLsizei, GLvoidP)) BGL_Wrap(IsTexture, GLboolean, (GLuint)) -BGL_Wrap(NormalPointer, void, (GLenum, GLsizei, GLvoidP)) BGL_Wrap(PolygonOffset, void, (GLfloat, GLfloat)) -BGL_Wrap(PopClientAttrib, void, (void)) -BGL_Wrap(PrioritizeTextures, void, (GLsizei, GLuintP, GLfloatP)) -BGL_Wrap(PushClientAttrib, void, (GLbitfield)) -BGL_Wrap(TexCoordPointer, void, (GLint, GLenum, GLsizei, GLvoidP)) BGL_Wrap(TexSubImage1D, void, (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, GLvoidP)) BGL_Wrap(TexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP)) -BGL_Wrap(VertexPointer, void, (GLint, GLenum, GLsizei, GLvoidP)) /* GL_VERSION_1_2 */ @@ -1436,7 +1153,6 @@ BGL_Wrap(TexSubImage3D, void, (GLenum, GLint, GLint, GLint, GLi /* GL_VERSION_1_3 */ BGL_Wrap(ActiveTexture, void, (GLenum)) -BGL_Wrap(ClientActiveTexture, void, (GLenum)) BGL_Wrap(CompressedTexImage1D, void, (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, GLvoidP)) BGL_Wrap(CompressedTexImage2D, void, (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, GLvoidP)) BGL_Wrap(CompressedTexImage3D, void, (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, GLvoidP)) @@ -1444,42 +1160,6 @@ BGL_Wrap(CompressedTexSubImage1D, void, (GLenum, GLint, GLint, GLsizei, G BGL_Wrap(CompressedTexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP)) BGL_Wrap(CompressedTexSubImage3D, void, (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP)) BGL_Wrap(GetCompressedTexImage, void, (GLenum, GLint, GLvoidP)) -BGL_Wrap(LoadTransposeMatrixd, void, (GLdoubleP)) -BGL_Wrap(LoadTransposeMatrixf, void, (GLfloatP)) -BGL_Wrap(MultTransposeMatrixd, void, (GLdoubleP)) -BGL_Wrap(MultTransposeMatrixf, void, (GLfloatP)) -BGL_Wrap(MultiTexCoord1d, void, (GLenum, GLdouble)) -BGL_Wrap(MultiTexCoord1dv, void, (GLenum, GLdoubleP)) -BGL_Wrap(MultiTexCoord1f, void, (GLenum, GLfloat)) -BGL_Wrap(MultiTexCoord1fv, void, (GLenum, GLfloatP)) -BGL_Wrap(MultiTexCoord1i, void, (GLenum, GLint)) -BGL_Wrap(MultiTexCoord1iv, void, (GLenum, GLintP)) -BGL_Wrap(MultiTexCoord1s, void, (GLenum, GLshort)) -BGL_Wrap(MultiTexCoord1sv, void, (GLenum, GLshortP)) -BGL_Wrap(MultiTexCoord2d, void, (GLenum, GLdouble, GLdouble)) -BGL_Wrap(MultiTexCoord2dv, void, (GLenum, GLdoubleP)) -BGL_Wrap(MultiTexCoord2f, void, (GLenum, GLfloat, GLfloat)) -BGL_Wrap(MultiTexCoord2fv, void, (GLenum, GLfloatP)) -BGL_Wrap(MultiTexCoord2i, void, (GLenum, GLint, GLint)) -BGL_Wrap(MultiTexCoord2iv, void, (GLenum, GLintP)) -BGL_Wrap(MultiTexCoord2s, void, (GLenum, GLshort, GLshort)) -BGL_Wrap(MultiTexCoord2sv, void, (GLenum, GLshortP)) -BGL_Wrap(MultiTexCoord3d, void, (GLenum, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(MultiTexCoord3dv, void, (GLenum, GLdoubleP)) -BGL_Wrap(MultiTexCoord3f, void, (GLenum, GLfloat, GLfloat, GLfloat)) -BGL_Wrap(MultiTexCoord3fv, void, (GLenum, GLfloatP)) -BGL_Wrap(MultiTexCoord3i, void, (GLenum, GLint, GLint, GLint)) -BGL_Wrap(MultiTexCoord3iv, void, (GLenum, GLintP)) -BGL_Wrap(MultiTexCoord3s, void, (GLenum, GLshort, GLshort, GLshort)) -BGL_Wrap(MultiTexCoord3sv, void, (GLenum, GLshortP)) -BGL_Wrap(MultiTexCoord4d, void, (GLenum, GLdouble, GLdouble, GLdouble, GLdouble)) -BGL_Wrap(MultiTexCoord4dv, void, (GLenum, GLdoubleP)) -BGL_Wrap(MultiTexCoord4f, void, (GLenum, GLfloat, GLfloat, GLfloat, GLfloat)) -BGL_Wrap(MultiTexCoord4fv, void, (GLenum, GLfloatP)) -BGL_Wrap(MultiTexCoord4i, void, (GLenum, GLint, GLint, GLint, GLint)) -BGL_Wrap(MultiTexCoord4iv, void, (GLenum, GLintP)) -BGL_Wrap(MultiTexCoord4s, void, (GLenum, GLshort, GLshort, GLshort, GLshort)) -BGL_Wrap(MultiTexCoord4sv, void, (GLenum, GLshortP)) BGL_Wrap(SampleCoverage, void, (GLfloat, GLboolean)) @@ -1618,6 +1298,7 @@ BGL_Wrap(UniformMatrix4x3fv, void, (GLint, GLsizei, GLboolean, GLflo BGL_Wrap(BindVertexArray, void, (GLuint)) BGL_Wrap(DeleteVertexArrays, void, (GLsizei, GLuintP)) BGL_Wrap(GenVertexArrays, void, (GLsizei, GLuintP)) +BGL_Wrap(GetStringi, GLstring, (GLenum, GLuint)) BGL_Wrap(IsVertexArray, GLboolean, (GLuint)) @@ -1645,44 +1326,7 @@ BGL_Wrap(TexImage3DMultisample, void, (GLenum, GLsizei, GLenum, GLsizei /* GL_VERSION_3_3 */ -BGL_Wrap(ColorP3ui, void, (GLenum, GLuint)) -BGL_Wrap(ColorP3uiv, void, (GLenum, GLuintP)) -BGL_Wrap(ColorP4ui, void, (GLenum, GLuint)) -BGL_Wrap(ColorP4uiv, void, (GLenum, GLuintP)) -BGL_Wrap(MultiTexCoordP1ui, void, (GLenum, GLenum, GLuint)) -BGL_Wrap(MultiTexCoordP1uiv, void, (GLenum, GLenum, GLuintP)) -BGL_Wrap(MultiTexCoordP2ui, void, (GLenum, GLenum, GLuint)) -BGL_Wrap(MultiTexCoordP2uiv, void, (GLenum, GLenum, GLuintP)) -BGL_Wrap(MultiTexCoordP3ui, void, (GLenum, GLenum, GLuint)) -BGL_Wrap(MultiTexCoordP3uiv, void, (GLenum, GLenum, GLuintP)) -BGL_Wrap(MultiTexCoordP4ui, void, (GLenum, GLenum, GLuint)) -BGL_Wrap(MultiTexCoordP4uiv, void, (GLenum, GLenum, GLuintP)) -BGL_Wrap(NormalP3ui, void, (GLenum, GLuint)) -BGL_Wrap(NormalP3uiv, void, (GLenum, GLuintP)) -BGL_Wrap(SecondaryColorP3ui, void, (GLenum, GLuint)) -BGL_Wrap(SecondaryColorP3uiv, void, (GLenum, GLuintP)) -BGL_Wrap(TexCoordP1ui, void, (GLenum, GLuint)) -BGL_Wrap(TexCoordP1uiv, void, (GLenum, GLuintP)) -BGL_Wrap(TexCoordP2ui, void, (GLenum, GLuint)) -BGL_Wrap(TexCoordP2uiv, void, (GLenum, GLuintP)) -BGL_Wrap(TexCoordP3ui, void, (GLenum, GLuint)) -BGL_Wrap(TexCoordP3uiv, void, (GLenum, GLuintP)) -BGL_Wrap(TexCoordP4ui, void, (GLenum, GLuint)) -BGL_Wrap(TexCoordP4uiv, void, (GLenum, GLuintP)) -BGL_Wrap(VertexP2ui, void, (GLenum, GLuint)) -BGL_Wrap(VertexP2uiv, void, (GLenum, GLuintP)) -BGL_Wrap(VertexP3ui, void, (GLenum, GLuint)) -BGL_Wrap(VertexP3uiv, void, (GLenum, GLuintP)) -BGL_Wrap(VertexP4ui, void, (GLenum, GLuint)) -BGL_Wrap(VertexP4uiv, void, (GLenum, GLuintP)) - - -BGLU_Wrap(Perspective, void, (GLdouble, GLdouble, GLdouble, GLdouble)) -BGLU_Wrap(LookAt, void, (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble)) -BGLU_Wrap(Ortho2D, void, (GLdouble, GLdouble, GLdouble, GLdouble)) -BGLU_Wrap(PickMatrix, void, (GLdouble, GLdouble, GLdouble, GLdouble, GLintP)) -BGLU_Wrap(Project, GLint, (GLdouble, GLdouble, GLdouble, GLdoubleP, GLdoubleP, GLintP, GLdoubleP, GLdoubleP, GLdoubleP)) -BGLU_Wrap(UnProject, GLint, (GLdouble, GLdouble, GLdouble, GLdoubleP, GLdoubleP, GLintP, GLdoubleP, GLdoubleP, GLdoubleP)) +/* no new functions besides packed immediate mode (not part of core profile) */ /** \} */ @@ -1692,26 +1336,12 @@ BGLU_Wrap(UnProject, GLint, (GLdouble, GLdouble, GLdouble, GLdouble /** \name Module Definition * \{ */ -#define MethodDefu(func) {"glu"#func, Method_##func, METH_VARARGS, NULL} - -static struct PyMethodDef BGL_methods[] = { - MethodDefu(Perspective), - MethodDefu(LookAt), - MethodDefu(Ortho2D), - MethodDefu(PickMatrix), - MethodDefu(Project), - MethodDefu(UnProject), - {NULL, NULL, 0, NULL} -}; - -#undef MethodDefu - static struct PyModuleDef BGL_module_def = { PyModuleDef_HEAD_INIT, "bgl", /* m_name */ NULL, /* m_doc */ 0, /* m_size */ - BGL_methods, /* m_methods */ + NULL, /* m_methods */ NULL, /* m_reload */ NULL, /* m_traverse */ NULL, /* m_clear */ @@ -1745,9 +1375,6 @@ static void py_module_dict_add_method(PyObject *submodule, PyObject *dict, PyMet } } -/* TODO, expose to users */ -static bool use_deprecated = true; - PyObject *BPyInit_bgl(void) { PyObject *submodule, *dict; @@ -1822,268 +1449,6 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(TexParameteriv); PY_MOD_ADD_METHOD(Viewport); } - /* adding in GL_VERSION_1_0 removed from core profile */ - if (use_deprecated == true) { - PY_MOD_ADD_METHOD(Accum); - PY_MOD_ADD_METHOD(AlphaFunc); - PY_MOD_ADD_METHOD(Begin); - PY_MOD_ADD_METHOD(Bitmap); - PY_MOD_ADD_METHOD(CallList); - PY_MOD_ADD_METHOD(CallLists); - PY_MOD_ADD_METHOD(ClearAccum); - PY_MOD_ADD_METHOD(ClearIndex); - PY_MOD_ADD_METHOD(ClipPlane); - PY_MOD_ADD_METHOD(Color3b); - PY_MOD_ADD_METHOD(Color3bv); - PY_MOD_ADD_METHOD(Color3d); - PY_MOD_ADD_METHOD(Color3dv); - PY_MOD_ADD_METHOD(Color3f); - PY_MOD_ADD_METHOD(Color3fv); - PY_MOD_ADD_METHOD(Color3i); - PY_MOD_ADD_METHOD(Color3iv); - PY_MOD_ADD_METHOD(Color3s); - PY_MOD_ADD_METHOD(Color3sv); - PY_MOD_ADD_METHOD(Color3ub); - PY_MOD_ADD_METHOD(Color3ubv); - PY_MOD_ADD_METHOD(Color3ui); - PY_MOD_ADD_METHOD(Color3uiv); - PY_MOD_ADD_METHOD(Color3us); - PY_MOD_ADD_METHOD(Color3usv); - PY_MOD_ADD_METHOD(Color4b); - PY_MOD_ADD_METHOD(Color4bv); - PY_MOD_ADD_METHOD(Color4d); - PY_MOD_ADD_METHOD(Color4dv); - PY_MOD_ADD_METHOD(Color4f); - PY_MOD_ADD_METHOD(Color4fv); - PY_MOD_ADD_METHOD(Color4i); - PY_MOD_ADD_METHOD(Color4iv); - PY_MOD_ADD_METHOD(Color4s); - PY_MOD_ADD_METHOD(Color4sv); - PY_MOD_ADD_METHOD(Color4ub); - PY_MOD_ADD_METHOD(Color4ubv); - PY_MOD_ADD_METHOD(Color4ui); - PY_MOD_ADD_METHOD(Color4uiv); - PY_MOD_ADD_METHOD(Color4us); - PY_MOD_ADD_METHOD(Color4usv); - PY_MOD_ADD_METHOD(ColorMaterial); - PY_MOD_ADD_METHOD(CopyPixels); - PY_MOD_ADD_METHOD(DeleteLists); - PY_MOD_ADD_METHOD(DrawPixels); - PY_MOD_ADD_METHOD(EdgeFlag); - PY_MOD_ADD_METHOD(EdgeFlagv); - PY_MOD_ADD_METHOD(End); - PY_MOD_ADD_METHOD(EndList); - PY_MOD_ADD_METHOD(EvalCoord1d); - PY_MOD_ADD_METHOD(EvalCoord1dv); - PY_MOD_ADD_METHOD(EvalCoord1f); - PY_MOD_ADD_METHOD(EvalCoord1fv); - PY_MOD_ADD_METHOD(EvalCoord2d); - PY_MOD_ADD_METHOD(EvalCoord2dv); - PY_MOD_ADD_METHOD(EvalCoord2f); - PY_MOD_ADD_METHOD(EvalCoord2fv); - PY_MOD_ADD_METHOD(EvalMesh1); - PY_MOD_ADD_METHOD(EvalMesh2); - PY_MOD_ADD_METHOD(EvalPoint1); - PY_MOD_ADD_METHOD(EvalPoint2); - PY_MOD_ADD_METHOD(FeedbackBuffer); - PY_MOD_ADD_METHOD(Fogf); - PY_MOD_ADD_METHOD(Fogfv); - PY_MOD_ADD_METHOD(Fogi); - PY_MOD_ADD_METHOD(Fogiv); - PY_MOD_ADD_METHOD(Frustum); - PY_MOD_ADD_METHOD(GenLists); - PY_MOD_ADD_METHOD(GetClipPlane); - PY_MOD_ADD_METHOD(GetLightfv); - PY_MOD_ADD_METHOD(GetLightiv); - PY_MOD_ADD_METHOD(GetMapdv); - PY_MOD_ADD_METHOD(GetMapfv); - PY_MOD_ADD_METHOD(GetMapiv); - PY_MOD_ADD_METHOD(GetMaterialfv); - PY_MOD_ADD_METHOD(GetMaterialiv); - PY_MOD_ADD_METHOD(GetPixelMapfv); - PY_MOD_ADD_METHOD(GetPixelMapuiv); - PY_MOD_ADD_METHOD(GetPixelMapusv); - PY_MOD_ADD_METHOD(GetPolygonStipple); - PY_MOD_ADD_METHOD(GetTexEnvfv); - PY_MOD_ADD_METHOD(GetTexEnviv); - PY_MOD_ADD_METHOD(GetTexGendv); - PY_MOD_ADD_METHOD(GetTexGenfv); - PY_MOD_ADD_METHOD(GetTexGeniv); - PY_MOD_ADD_METHOD(IndexMask); - PY_MOD_ADD_METHOD(Indexd); - PY_MOD_ADD_METHOD(Indexdv); - PY_MOD_ADD_METHOD(Indexf); - PY_MOD_ADD_METHOD(Indexfv); - PY_MOD_ADD_METHOD(Indexi); - PY_MOD_ADD_METHOD(Indexiv); - PY_MOD_ADD_METHOD(Indexs); - PY_MOD_ADD_METHOD(Indexsv); - PY_MOD_ADD_METHOD(InitNames); - PY_MOD_ADD_METHOD(IsList); - PY_MOD_ADD_METHOD(LightModelf); - PY_MOD_ADD_METHOD(LightModelfv); - PY_MOD_ADD_METHOD(LightModeli); - PY_MOD_ADD_METHOD(LightModeliv); - PY_MOD_ADD_METHOD(Lightf); - PY_MOD_ADD_METHOD(Lightfv); - PY_MOD_ADD_METHOD(Lighti); - PY_MOD_ADD_METHOD(Lightiv); - PY_MOD_ADD_METHOD(LineStipple); - PY_MOD_ADD_METHOD(ListBase); - PY_MOD_ADD_METHOD(LoadIdentity); - PY_MOD_ADD_METHOD(LoadMatrixd); - PY_MOD_ADD_METHOD(LoadMatrixf); - PY_MOD_ADD_METHOD(LoadName); - PY_MOD_ADD_METHOD(Map1d); - PY_MOD_ADD_METHOD(Map1f); - PY_MOD_ADD_METHOD(Map2d); - PY_MOD_ADD_METHOD(Map2f); - PY_MOD_ADD_METHOD(MapGrid1d); - PY_MOD_ADD_METHOD(MapGrid1f); - PY_MOD_ADD_METHOD(MapGrid2d); - PY_MOD_ADD_METHOD(MapGrid2f); - PY_MOD_ADD_METHOD(Materialf); - PY_MOD_ADD_METHOD(Materialfv); - PY_MOD_ADD_METHOD(Materiali); - PY_MOD_ADD_METHOD(Materialiv); - PY_MOD_ADD_METHOD(MatrixMode); - PY_MOD_ADD_METHOD(MultMatrixd); - PY_MOD_ADD_METHOD(MultMatrixf); - PY_MOD_ADD_METHOD(NewList); - PY_MOD_ADD_METHOD(Normal3b); - PY_MOD_ADD_METHOD(Normal3bv); - PY_MOD_ADD_METHOD(Normal3d); - PY_MOD_ADD_METHOD(Normal3dv); - PY_MOD_ADD_METHOD(Normal3f); - PY_MOD_ADD_METHOD(Normal3fv); - PY_MOD_ADD_METHOD(Normal3i); - PY_MOD_ADD_METHOD(Normal3iv); - PY_MOD_ADD_METHOD(Normal3s); - PY_MOD_ADD_METHOD(Normal3sv); - PY_MOD_ADD_METHOD(Ortho); - PY_MOD_ADD_METHOD(PassThrough); - PY_MOD_ADD_METHOD(PixelMapfv); - PY_MOD_ADD_METHOD(PixelMapuiv); - PY_MOD_ADD_METHOD(PixelMapusv); - PY_MOD_ADD_METHOD(PixelTransferf); - PY_MOD_ADD_METHOD(PixelTransferi); - PY_MOD_ADD_METHOD(PixelZoom); - PY_MOD_ADD_METHOD(PolygonStipple); - PY_MOD_ADD_METHOD(PopAttrib); - PY_MOD_ADD_METHOD(PopMatrix); - PY_MOD_ADD_METHOD(PopName); - PY_MOD_ADD_METHOD(PushAttrib); - PY_MOD_ADD_METHOD(PushMatrix); - PY_MOD_ADD_METHOD(PushName); - PY_MOD_ADD_METHOD(RasterPos2d); - PY_MOD_ADD_METHOD(RasterPos2dv); - PY_MOD_ADD_METHOD(RasterPos2f); - PY_MOD_ADD_METHOD(RasterPos2fv); - PY_MOD_ADD_METHOD(RasterPos2i); - PY_MOD_ADD_METHOD(RasterPos2iv); - PY_MOD_ADD_METHOD(RasterPos2s); - PY_MOD_ADD_METHOD(RasterPos2sv); - PY_MOD_ADD_METHOD(RasterPos3d); - PY_MOD_ADD_METHOD(RasterPos3dv); - PY_MOD_ADD_METHOD(RasterPos3f); - PY_MOD_ADD_METHOD(RasterPos3fv); - PY_MOD_ADD_METHOD(RasterPos3i); - PY_MOD_ADD_METHOD(RasterPos3iv); - PY_MOD_ADD_METHOD(RasterPos3s); - PY_MOD_ADD_METHOD(RasterPos3sv); - PY_MOD_ADD_METHOD(RasterPos4d); - PY_MOD_ADD_METHOD(RasterPos4dv); - PY_MOD_ADD_METHOD(RasterPos4f); - PY_MOD_ADD_METHOD(RasterPos4fv); - PY_MOD_ADD_METHOD(RasterPos4i); - PY_MOD_ADD_METHOD(RasterPos4iv); - PY_MOD_ADD_METHOD(RasterPos4s); - PY_MOD_ADD_METHOD(RasterPos4sv); - PY_MOD_ADD_METHOD(Rectd); - PY_MOD_ADD_METHOD(Rectdv); - PY_MOD_ADD_METHOD(Rectf); - PY_MOD_ADD_METHOD(Rectfv); - PY_MOD_ADD_METHOD(Recti); - PY_MOD_ADD_METHOD(Rectiv); - PY_MOD_ADD_METHOD(Rects); - PY_MOD_ADD_METHOD(Rectsv); - PY_MOD_ADD_METHOD(RenderMode); - PY_MOD_ADD_METHOD(Rotated); - PY_MOD_ADD_METHOD(Rotatef); - PY_MOD_ADD_METHOD(Scaled); - PY_MOD_ADD_METHOD(Scalef); - PY_MOD_ADD_METHOD(SelectBuffer); - PY_MOD_ADD_METHOD(ShadeModel); - PY_MOD_ADD_METHOD(TexCoord1d); - PY_MOD_ADD_METHOD(TexCoord1dv); - PY_MOD_ADD_METHOD(TexCoord1f); - PY_MOD_ADD_METHOD(TexCoord1fv); - PY_MOD_ADD_METHOD(TexCoord1i); - PY_MOD_ADD_METHOD(TexCoord1iv); - PY_MOD_ADD_METHOD(TexCoord1s); - PY_MOD_ADD_METHOD(TexCoord1sv); - PY_MOD_ADD_METHOD(TexCoord2d); - PY_MOD_ADD_METHOD(TexCoord2dv); - PY_MOD_ADD_METHOD(TexCoord2f); - PY_MOD_ADD_METHOD(TexCoord2fv); - PY_MOD_ADD_METHOD(TexCoord2i); - PY_MOD_ADD_METHOD(TexCoord2iv); - PY_MOD_ADD_METHOD(TexCoord2s); - PY_MOD_ADD_METHOD(TexCoord2sv); - PY_MOD_ADD_METHOD(TexCoord3d); - PY_MOD_ADD_METHOD(TexCoord3dv); - PY_MOD_ADD_METHOD(TexCoord3f); - PY_MOD_ADD_METHOD(TexCoord3fv); - PY_MOD_ADD_METHOD(TexCoord3i); - PY_MOD_ADD_METHOD(TexCoord3iv); - PY_MOD_ADD_METHOD(TexCoord3s); - PY_MOD_ADD_METHOD(TexCoord3sv); - PY_MOD_ADD_METHOD(TexCoord4d); - PY_MOD_ADD_METHOD(TexCoord4dv); - PY_MOD_ADD_METHOD(TexCoord4f); - PY_MOD_ADD_METHOD(TexCoord4fv); - PY_MOD_ADD_METHOD(TexCoord4i); - PY_MOD_ADD_METHOD(TexCoord4iv); - PY_MOD_ADD_METHOD(TexCoord4s); - PY_MOD_ADD_METHOD(TexCoord4sv); - PY_MOD_ADD_METHOD(TexEnvf); - PY_MOD_ADD_METHOD(TexEnvfv); - PY_MOD_ADD_METHOD(TexEnvi); - PY_MOD_ADD_METHOD(TexEnviv); - PY_MOD_ADD_METHOD(TexGend); - PY_MOD_ADD_METHOD(TexGendv); - PY_MOD_ADD_METHOD(TexGenf); - PY_MOD_ADD_METHOD(TexGenfv); - PY_MOD_ADD_METHOD(TexGeni); - PY_MOD_ADD_METHOD(TexGeniv); - PY_MOD_ADD_METHOD(Translated); - PY_MOD_ADD_METHOD(Translatef); - PY_MOD_ADD_METHOD(Vertex2d); - PY_MOD_ADD_METHOD(Vertex2dv); - PY_MOD_ADD_METHOD(Vertex2f); - PY_MOD_ADD_METHOD(Vertex2fv); - PY_MOD_ADD_METHOD(Vertex2i); - PY_MOD_ADD_METHOD(Vertex2iv); - PY_MOD_ADD_METHOD(Vertex2s); - PY_MOD_ADD_METHOD(Vertex2sv); - PY_MOD_ADD_METHOD(Vertex3d); - PY_MOD_ADD_METHOD(Vertex3dv); - PY_MOD_ADD_METHOD(Vertex3f); - PY_MOD_ADD_METHOD(Vertex3fv); - PY_MOD_ADD_METHOD(Vertex3i); - PY_MOD_ADD_METHOD(Vertex3iv); - PY_MOD_ADD_METHOD(Vertex3s); - PY_MOD_ADD_METHOD(Vertex3sv); - PY_MOD_ADD_METHOD(Vertex4d); - PY_MOD_ADD_METHOD(Vertex4dv); - PY_MOD_ADD_METHOD(Vertex4f); - PY_MOD_ADD_METHOD(Vertex4fv); - PY_MOD_ADD_METHOD(Vertex4i); - PY_MOD_ADD_METHOD(Vertex4iv); - PY_MOD_ADD_METHOD(Vertex4s); - PY_MOD_ADD_METHOD(Vertex4sv); - } - /* GL_VERSION_1_1 */ { @@ -2101,27 +1466,6 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(TexSubImage1D); PY_MOD_ADD_METHOD(TexSubImage2D); } - /* adding in GL_VERSION_1_1 removed from core profile */ - if (use_deprecated == true) { - PY_MOD_ADD_METHOD(AreTexturesResident); - PY_MOD_ADD_METHOD(ArrayElement); - PY_MOD_ADD_METHOD(ColorPointer); - PY_MOD_ADD_METHOD(DisableClientState); - PY_MOD_ADD_METHOD(EdgeFlagPointer); - PY_MOD_ADD_METHOD(EnableClientState); - PY_MOD_ADD_METHOD(GetPointerv); - PY_MOD_ADD_METHOD(IndexPointer); - PY_MOD_ADD_METHOD(Indexub); - PY_MOD_ADD_METHOD(Indexubv); - PY_MOD_ADD_METHOD(InterleavedArrays); - PY_MOD_ADD_METHOD(NormalPointer); - PY_MOD_ADD_METHOD(PopClientAttrib); - PY_MOD_ADD_METHOD(PrioritizeTextures); - PY_MOD_ADD_METHOD(PushClientAttrib); - PY_MOD_ADD_METHOD(TexCoordPointer); - PY_MOD_ADD_METHOD(VertexPointer); - } - /* GL_VERSION_1_2 */ { @@ -2131,7 +1475,6 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(TexSubImage3D); } - /* GL_VERSION_1_3 */ { PY_MOD_ADD_METHOD(ActiveTexture); @@ -2144,47 +1487,6 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(GetCompressedTexImage); PY_MOD_ADD_METHOD(SampleCoverage); } - /* adding in GL_VERSION_1_3 removed from core profile */ - if (use_deprecated == true) { - PY_MOD_ADD_METHOD(ClientActiveTexture); - PY_MOD_ADD_METHOD(LoadTransposeMatrixd); - PY_MOD_ADD_METHOD(LoadTransposeMatrixf); - PY_MOD_ADD_METHOD(MultTransposeMatrixd); - PY_MOD_ADD_METHOD(MultTransposeMatrixf); - PY_MOD_ADD_METHOD(MultiTexCoord1d); - PY_MOD_ADD_METHOD(MultiTexCoord1dv); - PY_MOD_ADD_METHOD(MultiTexCoord1f); - PY_MOD_ADD_METHOD(MultiTexCoord1fv); - PY_MOD_ADD_METHOD(MultiTexCoord1i); - PY_MOD_ADD_METHOD(MultiTexCoord1iv); - PY_MOD_ADD_METHOD(MultiTexCoord1s); - PY_MOD_ADD_METHOD(MultiTexCoord1sv); - PY_MOD_ADD_METHOD(MultiTexCoord2d); - PY_MOD_ADD_METHOD(MultiTexCoord2dv); - PY_MOD_ADD_METHOD(MultiTexCoord2f); - PY_MOD_ADD_METHOD(MultiTexCoord2fv); - PY_MOD_ADD_METHOD(MultiTexCoord2i); - PY_MOD_ADD_METHOD(MultiTexCoord2iv); - PY_MOD_ADD_METHOD(MultiTexCoord2s); - PY_MOD_ADD_METHOD(MultiTexCoord2sv); - PY_MOD_ADD_METHOD(MultiTexCoord3d); - PY_MOD_ADD_METHOD(MultiTexCoord3dv); - PY_MOD_ADD_METHOD(MultiTexCoord3f); - PY_MOD_ADD_METHOD(MultiTexCoord3fv); - PY_MOD_ADD_METHOD(MultiTexCoord3i); - PY_MOD_ADD_METHOD(MultiTexCoord3iv); - PY_MOD_ADD_METHOD(MultiTexCoord3s); - PY_MOD_ADD_METHOD(MultiTexCoord3sv); - PY_MOD_ADD_METHOD(MultiTexCoord4d); - PY_MOD_ADD_METHOD(MultiTexCoord4dv); - PY_MOD_ADD_METHOD(MultiTexCoord4f); - PY_MOD_ADD_METHOD(MultiTexCoord4fv); - PY_MOD_ADD_METHOD(MultiTexCoord4i); - PY_MOD_ADD_METHOD(MultiTexCoord4iv); - PY_MOD_ADD_METHOD(MultiTexCoord4s); - PY_MOD_ADD_METHOD(MultiTexCoord4sv); - } - /* GL_VERSION_1_4 */ { @@ -2192,7 +1494,6 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(BlendEquation); } - /* GL_VERSION_1_5 */ { PY_MOD_ADD_METHOD(BeginQuery); @@ -2216,7 +1517,6 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(UnmapBuffer); } - /* GL_VERSION_2_0 */ { PY_MOD_ADD_METHOD(AttachShader); @@ -2314,7 +1614,6 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(VertexAttribPointer); } - /* GL_VERSION_2_1 */ { PY_MOD_ADD_METHOD(UniformMatrix2x3fv); @@ -2325,16 +1624,15 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(UniformMatrix4x3fv); } - /* GL_VERSION_3_0 */ { PY_MOD_ADD_METHOD(BindVertexArray); PY_MOD_ADD_METHOD(DeleteVertexArrays); PY_MOD_ADD_METHOD(GenVertexArrays); + PY_MOD_ADD_METHOD(GetStringi); PY_MOD_ADD_METHOD(IsVertexArray); } - /* GL_VERSION_3_1 */ { PY_MOD_ADD_METHOD(BindBufferBase); @@ -2349,7 +1647,6 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(UniformBlockBinding); } - /* GL_VERSION_3_2 */ { PY_MOD_ADD_METHOD(FramebufferTexture); @@ -2361,39 +1658,8 @@ PyObject *BPyInit_bgl(void) PY_MOD_ADD_METHOD(TexImage3DMultisample); } - /* GL_VERSION_3_3 */ { - PY_MOD_ADD_METHOD(ColorP3ui); - PY_MOD_ADD_METHOD(ColorP3uiv); - PY_MOD_ADD_METHOD(ColorP4ui); - PY_MOD_ADD_METHOD(ColorP4uiv); - PY_MOD_ADD_METHOD(MultiTexCoordP1ui); - PY_MOD_ADD_METHOD(MultiTexCoordP1uiv); - PY_MOD_ADD_METHOD(MultiTexCoordP2ui); - PY_MOD_ADD_METHOD(MultiTexCoordP2uiv); - PY_MOD_ADD_METHOD(MultiTexCoordP3ui); - PY_MOD_ADD_METHOD(MultiTexCoordP3uiv); - PY_MOD_ADD_METHOD(MultiTexCoordP4ui); - PY_MOD_ADD_METHOD(MultiTexCoordP4uiv); - PY_MOD_ADD_METHOD(NormalP3ui); - PY_MOD_ADD_METHOD(NormalP3uiv); - PY_MOD_ADD_METHOD(SecondaryColorP3ui); - PY_MOD_ADD_METHOD(SecondaryColorP3uiv); - PY_MOD_ADD_METHOD(TexCoordP1ui); - PY_MOD_ADD_METHOD(TexCoordP1uiv); - PY_MOD_ADD_METHOD(TexCoordP2ui); - PY_MOD_ADD_METHOD(TexCoordP2uiv); - PY_MOD_ADD_METHOD(TexCoordP3ui); - PY_MOD_ADD_METHOD(TexCoordP3uiv); - PY_MOD_ADD_METHOD(TexCoordP4ui); - PY_MOD_ADD_METHOD(TexCoordP4uiv); - PY_MOD_ADD_METHOD(VertexP2ui); - PY_MOD_ADD_METHOD(VertexP2uiv); - PY_MOD_ADD_METHOD(VertexP3ui); - PY_MOD_ADD_METHOD(VertexP3uiv); - PY_MOD_ADD_METHOD(VertexP4ui); - PY_MOD_ADD_METHOD(VertexP4uiv); } #define PY_DICT_ADD_INT(x) py_module_dict_add_int(dict, #x, x) @@ -2511,8 +1777,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_POINT); PY_DICT_ADD_INT(GL_POINTS); PY_DICT_ADD_INT(GL_POINT_SIZE); - PY_DICT_ADD_INT(GL_POINT_SIZE_GRANULARITY); - PY_DICT_ADD_INT(GL_POINT_SIZE_RANGE); PY_DICT_ADD_INT(GL_POLYGON_MODE); PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FACTOR); PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FILL); @@ -2602,338 +1866,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_XOR); PY_DICT_ADD_INT(GL_ZERO); } - /* adding in GL_VERSION_1_1 removed from core profile */ - if (use_deprecated == true) { - PY_DICT_ADD_INT(GL_2D); - PY_DICT_ADD_INT(GL_2_BYTES); - PY_DICT_ADD_INT(GL_3D); - PY_DICT_ADD_INT(GL_3D_COLOR); - PY_DICT_ADD_INT(GL_3D_COLOR_TEXTURE); - PY_DICT_ADD_INT(GL_3_BYTES); - PY_DICT_ADD_INT(GL_4D_COLOR_TEXTURE); - PY_DICT_ADD_INT(GL_4_BYTES); - PY_DICT_ADD_INT(GL_ACCUM); - PY_DICT_ADD_INT(GL_ACCUM_ALPHA_BITS); - PY_DICT_ADD_INT(GL_ACCUM_BLUE_BITS); - PY_DICT_ADD_INT(GL_ACCUM_BUFFER_BIT); - PY_DICT_ADD_INT(GL_ACCUM_CLEAR_VALUE); - PY_DICT_ADD_INT(GL_ACCUM_GREEN_BITS); - PY_DICT_ADD_INT(GL_ACCUM_RED_BITS); - PY_DICT_ADD_INT(GL_ADD); - PY_DICT_ADD_INT(GL_ALL_ATTRIB_BITS); - PY_DICT_ADD_INT(GL_ALPHA12); - PY_DICT_ADD_INT(GL_ALPHA16); - PY_DICT_ADD_INT(GL_ALPHA4); - PY_DICT_ADD_INT(GL_ALPHA8); - PY_DICT_ADD_INT(GL_ALPHA_BIAS); - PY_DICT_ADD_INT(GL_ALPHA_BITS); - PY_DICT_ADD_INT(GL_ALPHA_SCALE); - PY_DICT_ADD_INT(GL_ALPHA_TEST); - PY_DICT_ADD_INT(GL_ALPHA_TEST_FUNC); - PY_DICT_ADD_INT(GL_ALPHA_TEST_REF); - PY_DICT_ADD_INT(GL_AMBIENT); - PY_DICT_ADD_INT(GL_AMBIENT_AND_DIFFUSE); - PY_DICT_ADD_INT(GL_ATTRIB_STACK_DEPTH); - PY_DICT_ADD_INT(GL_AUTO_NORMAL); - PY_DICT_ADD_INT(GL_AUX0); - PY_DICT_ADD_INT(GL_AUX1); - PY_DICT_ADD_INT(GL_AUX2); - PY_DICT_ADD_INT(GL_AUX3); - PY_DICT_ADD_INT(GL_AUX_BUFFERS); - PY_DICT_ADD_INT(GL_BITMAP); - PY_DICT_ADD_INT(GL_BITMAP_TOKEN); - PY_DICT_ADD_INT(GL_BLUE_BIAS); - PY_DICT_ADD_INT(GL_BLUE_BITS); - PY_DICT_ADD_INT(GL_BLUE_SCALE); - PY_DICT_ADD_INT(GL_C3F_V3F); - PY_DICT_ADD_INT(GL_C4F_N3F_V3F); - PY_DICT_ADD_INT(GL_C4UB_V2F); - PY_DICT_ADD_INT(GL_C4UB_V3F); - PY_DICT_ADD_INT(GL_CLAMP); - PY_DICT_ADD_INT(GL_CLIENT_ALL_ATTRIB_BITS); - PY_DICT_ADD_INT(GL_CLIENT_ATTRIB_STACK_DEPTH); - PY_DICT_ADD_INT(GL_CLIENT_PIXEL_STORE_BIT); - PY_DICT_ADD_INT(GL_CLIENT_VERTEX_ARRAY_BIT); - PY_DICT_ADD_INT(GL_CLIP_PLANE0); - PY_DICT_ADD_INT(GL_CLIP_PLANE1); - PY_DICT_ADD_INT(GL_CLIP_PLANE2); - PY_DICT_ADD_INT(GL_CLIP_PLANE3); - PY_DICT_ADD_INT(GL_CLIP_PLANE4); - PY_DICT_ADD_INT(GL_CLIP_PLANE5); - PY_DICT_ADD_INT(GL_COEFF); - PY_DICT_ADD_INT(GL_COLOR_ARRAY); - PY_DICT_ADD_INT(GL_COLOR_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_COLOR_ARRAY_SIZE); - PY_DICT_ADD_INT(GL_COLOR_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_COLOR_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_COLOR_INDEX); - PY_DICT_ADD_INT(GL_COLOR_INDEXES); - PY_DICT_ADD_INT(GL_COLOR_MATERIAL); - PY_DICT_ADD_INT(GL_COLOR_MATERIAL_FACE); - PY_DICT_ADD_INT(GL_COLOR_MATERIAL_PARAMETER); - PY_DICT_ADD_INT(GL_COMPILE); - PY_DICT_ADD_INT(GL_COMPILE_AND_EXECUTE); - PY_DICT_ADD_INT(GL_CONSTANT_ATTENUATION); - PY_DICT_ADD_INT(GL_COPY_PIXEL_TOKEN); - PY_DICT_ADD_INT(GL_CURRENT_BIT); - PY_DICT_ADD_INT(GL_CURRENT_COLOR); - PY_DICT_ADD_INT(GL_CURRENT_INDEX); - PY_DICT_ADD_INT(GL_CURRENT_NORMAL); - PY_DICT_ADD_INT(GL_CURRENT_RASTER_COLOR); - PY_DICT_ADD_INT(GL_CURRENT_RASTER_DISTANCE); - PY_DICT_ADD_INT(GL_CURRENT_RASTER_INDEX); - PY_DICT_ADD_INT(GL_CURRENT_RASTER_POSITION); - PY_DICT_ADD_INT(GL_CURRENT_RASTER_POSITION_VALID); - PY_DICT_ADD_INT(GL_CURRENT_RASTER_TEXTURE_COORDS); - PY_DICT_ADD_INT(GL_CURRENT_TEXTURE_COORDS); - PY_DICT_ADD_INT(GL_DECAL); - PY_DICT_ADD_INT(GL_DEPTH_BIAS); - PY_DICT_ADD_INT(GL_DEPTH_BITS); - PY_DICT_ADD_INT(GL_DEPTH_SCALE); - PY_DICT_ADD_INT(GL_DIFFUSE); - PY_DICT_ADD_INT(GL_DOMAIN); - PY_DICT_ADD_INT(GL_DRAW_PIXEL_TOKEN); - PY_DICT_ADD_INT(GL_EDGE_FLAG); - PY_DICT_ADD_INT(GL_EDGE_FLAG_ARRAY); - PY_DICT_ADD_INT(GL_EDGE_FLAG_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_EDGE_FLAG_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_EMISSION); - PY_DICT_ADD_INT(GL_ENABLE_BIT); - PY_DICT_ADD_INT(GL_EVAL_BIT); - PY_DICT_ADD_INT(GL_EXP); - PY_DICT_ADD_INT(GL_EXP2); - PY_DICT_ADD_INT(GL_EYE_LINEAR); - PY_DICT_ADD_INT(GL_EYE_PLANE); - PY_DICT_ADD_INT(GL_FEEDBACK); - PY_DICT_ADD_INT(GL_FEEDBACK_BUFFER_POINTER); - PY_DICT_ADD_INT(GL_FEEDBACK_BUFFER_SIZE); - PY_DICT_ADD_INT(GL_FEEDBACK_BUFFER_TYPE); - PY_DICT_ADD_INT(GL_FLAT); - PY_DICT_ADD_INT(GL_FOG); - PY_DICT_ADD_INT(GL_FOG_BIT); - PY_DICT_ADD_INT(GL_FOG_COLOR); - PY_DICT_ADD_INT(GL_FOG_DENSITY); - PY_DICT_ADD_INT(GL_FOG_END); - PY_DICT_ADD_INT(GL_FOG_HINT); - PY_DICT_ADD_INT(GL_FOG_INDEX); - PY_DICT_ADD_INT(GL_FOG_MODE); - PY_DICT_ADD_INT(GL_FOG_START); - PY_DICT_ADD_INT(GL_GREEN_BIAS); - PY_DICT_ADD_INT(GL_GREEN_BITS); - PY_DICT_ADD_INT(GL_GREEN_SCALE); - PY_DICT_ADD_INT(GL_HINT_BIT); - PY_DICT_ADD_INT(GL_INDEX_ARRAY); - PY_DICT_ADD_INT(GL_INDEX_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_INDEX_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_INDEX_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_INDEX_BITS); - PY_DICT_ADD_INT(GL_INDEX_CLEAR_VALUE); - PY_DICT_ADD_INT(GL_INDEX_LOGIC_OP); - PY_DICT_ADD_INT(GL_INDEX_MODE); - PY_DICT_ADD_INT(GL_INDEX_OFFSET); - PY_DICT_ADD_INT(GL_INDEX_SHIFT); - PY_DICT_ADD_INT(GL_INDEX_WRITEMASK); - PY_DICT_ADD_INT(GL_INTENSITY); - PY_DICT_ADD_INT(GL_INTENSITY12); - PY_DICT_ADD_INT(GL_INTENSITY16); - PY_DICT_ADD_INT(GL_INTENSITY4); - PY_DICT_ADD_INT(GL_INTENSITY8); - PY_DICT_ADD_INT(GL_LIGHT0); - PY_DICT_ADD_INT(GL_LIGHT1); - PY_DICT_ADD_INT(GL_LIGHT2); - PY_DICT_ADD_INT(GL_LIGHT3); - PY_DICT_ADD_INT(GL_LIGHT4); - PY_DICT_ADD_INT(GL_LIGHT5); - PY_DICT_ADD_INT(GL_LIGHT6); - PY_DICT_ADD_INT(GL_LIGHT7); - PY_DICT_ADD_INT(GL_LIGHTING); - PY_DICT_ADD_INT(GL_LIGHTING_BIT); - PY_DICT_ADD_INT(GL_LIGHT_MODEL_AMBIENT); - PY_DICT_ADD_INT(GL_LIGHT_MODEL_LOCAL_VIEWER); - PY_DICT_ADD_INT(GL_LIGHT_MODEL_TWO_SIDE); - PY_DICT_ADD_INT(GL_LINEAR_ATTENUATION); - PY_DICT_ADD_INT(GL_LINE_BIT); - PY_DICT_ADD_INT(GL_LINE_RESET_TOKEN); - PY_DICT_ADD_INT(GL_LINE_STIPPLE); - PY_DICT_ADD_INT(GL_LINE_STIPPLE_PATTERN); - PY_DICT_ADD_INT(GL_LINE_STIPPLE_REPEAT); - PY_DICT_ADD_INT(GL_LINE_TOKEN); - PY_DICT_ADD_INT(GL_LIST_BASE); - PY_DICT_ADD_INT(GL_LIST_BIT); - PY_DICT_ADD_INT(GL_LIST_INDEX); - PY_DICT_ADD_INT(GL_LIST_MODE); - PY_DICT_ADD_INT(GL_LOAD); - PY_DICT_ADD_INT(GL_LOGIC_OP); - PY_DICT_ADD_INT(GL_LUMINANCE); - PY_DICT_ADD_INT(GL_LUMINANCE12); - PY_DICT_ADD_INT(GL_LUMINANCE12_ALPHA12); - PY_DICT_ADD_INT(GL_LUMINANCE12_ALPHA4); - PY_DICT_ADD_INT(GL_LUMINANCE16); - PY_DICT_ADD_INT(GL_LUMINANCE16_ALPHA16); - PY_DICT_ADD_INT(GL_LUMINANCE4); - PY_DICT_ADD_INT(GL_LUMINANCE4_ALPHA4); - PY_DICT_ADD_INT(GL_LUMINANCE6_ALPHA2); - PY_DICT_ADD_INT(GL_LUMINANCE8); - PY_DICT_ADD_INT(GL_LUMINANCE8_ALPHA8); - PY_DICT_ADD_INT(GL_LUMINANCE_ALPHA); - PY_DICT_ADD_INT(GL_MAP1_COLOR_4); - PY_DICT_ADD_INT(GL_MAP1_GRID_DOMAIN); - PY_DICT_ADD_INT(GL_MAP1_GRID_SEGMENTS); - PY_DICT_ADD_INT(GL_MAP1_INDEX); - PY_DICT_ADD_INT(GL_MAP1_NORMAL); - PY_DICT_ADD_INT(GL_MAP1_TEXTURE_COORD_1); - PY_DICT_ADD_INT(GL_MAP1_TEXTURE_COORD_2); - PY_DICT_ADD_INT(GL_MAP1_TEXTURE_COORD_3); - PY_DICT_ADD_INT(GL_MAP1_TEXTURE_COORD_4); - PY_DICT_ADD_INT(GL_MAP1_VERTEX_3); - PY_DICT_ADD_INT(GL_MAP1_VERTEX_4); - PY_DICT_ADD_INT(GL_MAP2_COLOR_4); - PY_DICT_ADD_INT(GL_MAP2_GRID_DOMAIN); - PY_DICT_ADD_INT(GL_MAP2_GRID_SEGMENTS); - PY_DICT_ADD_INT(GL_MAP2_INDEX); - PY_DICT_ADD_INT(GL_MAP2_NORMAL); - PY_DICT_ADD_INT(GL_MAP2_TEXTURE_COORD_1); - PY_DICT_ADD_INT(GL_MAP2_TEXTURE_COORD_2); - PY_DICT_ADD_INT(GL_MAP2_TEXTURE_COORD_3); - PY_DICT_ADD_INT(GL_MAP2_TEXTURE_COORD_4); - PY_DICT_ADD_INT(GL_MAP2_VERTEX_3); - PY_DICT_ADD_INT(GL_MAP2_VERTEX_4); - PY_DICT_ADD_INT(GL_MAP_COLOR); - PY_DICT_ADD_INT(GL_MAP_STENCIL); - PY_DICT_ADD_INT(GL_MATRIX_MODE); - PY_DICT_ADD_INT(GL_MAX_ATTRIB_STACK_DEPTH); - PY_DICT_ADD_INT(GL_MAX_CLIENT_ATTRIB_STACK_DEPTH); - PY_DICT_ADD_INT(GL_MAX_CLIP_PLANES); - PY_DICT_ADD_INT(GL_MAX_EVAL_ORDER); - PY_DICT_ADD_INT(GL_MAX_LIGHTS); - PY_DICT_ADD_INT(GL_MAX_LIST_NESTING); - PY_DICT_ADD_INT(GL_MAX_MODELVIEW_STACK_DEPTH); - PY_DICT_ADD_INT(GL_MAX_NAME_STACK_DEPTH); - PY_DICT_ADD_INT(GL_MAX_PIXEL_MAP_TABLE); - PY_DICT_ADD_INT(GL_MAX_PROJECTION_STACK_DEPTH); - PY_DICT_ADD_INT(GL_MAX_TEXTURE_STACK_DEPTH); - PY_DICT_ADD_INT(GL_MODELVIEW); - PY_DICT_ADD_INT(GL_MODELVIEW_MATRIX); - PY_DICT_ADD_INT(GL_MODELVIEW_STACK_DEPTH); - PY_DICT_ADD_INT(GL_MODULATE); - PY_DICT_ADD_INT(GL_MULT); - PY_DICT_ADD_INT(GL_N3F_V3F); - PY_DICT_ADD_INT(GL_NAME_STACK_DEPTH); - PY_DICT_ADD_INT(GL_NORMALIZE); - PY_DICT_ADD_INT(GL_NORMAL_ARRAY); - PY_DICT_ADD_INT(GL_NORMAL_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_NORMAL_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_NORMAL_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_OBJECT_LINEAR); - PY_DICT_ADD_INT(GL_OBJECT_PLANE); - PY_DICT_ADD_INT(GL_ORDER); - PY_DICT_ADD_INT(GL_PASS_THROUGH_TOKEN); - PY_DICT_ADD_INT(GL_PERSPECTIVE_CORRECTION_HINT); - PY_DICT_ADD_INT(GL_PIXEL_MAP_A_TO_A); - PY_DICT_ADD_INT(GL_PIXEL_MAP_A_TO_A_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_B_TO_B); - PY_DICT_ADD_INT(GL_PIXEL_MAP_B_TO_B_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_G_TO_G); - PY_DICT_ADD_INT(GL_PIXEL_MAP_G_TO_G_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_A); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_A_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_B); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_B_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_G); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_G_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_I); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_I_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_R); - PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_R_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_R_TO_R); - PY_DICT_ADD_INT(GL_PIXEL_MAP_R_TO_R_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MAP_S_TO_S); - PY_DICT_ADD_INT(GL_PIXEL_MAP_S_TO_S_SIZE); - PY_DICT_ADD_INT(GL_PIXEL_MODE_BIT); - PY_DICT_ADD_INT(GL_POINT_BIT); - PY_DICT_ADD_INT(GL_POINT_SMOOTH); - PY_DICT_ADD_INT(GL_POINT_SMOOTH_HINT); - PY_DICT_ADD_INT(GL_POINT_TOKEN); - PY_DICT_ADD_INT(GL_POLYGON); - PY_DICT_ADD_INT(GL_POLYGON_BIT); - PY_DICT_ADD_INT(GL_POLYGON_STIPPLE); - PY_DICT_ADD_INT(GL_POLYGON_STIPPLE_BIT); - PY_DICT_ADD_INT(GL_POLYGON_TOKEN); - PY_DICT_ADD_INT(GL_POSITION); - PY_DICT_ADD_INT(GL_PROJECTION); - PY_DICT_ADD_INT(GL_PROJECTION_MATRIX); - PY_DICT_ADD_INT(GL_PROJECTION_STACK_DEPTH); - PY_DICT_ADD_INT(GL_Q); - PY_DICT_ADD_INT(GL_QUADRATIC_ATTENUATION); - PY_DICT_ADD_INT(GL_QUADS); - PY_DICT_ADD_INT(GL_QUAD_STRIP); - PY_DICT_ADD_INT(GL_R); - PY_DICT_ADD_INT(GL_RED_BIAS); - PY_DICT_ADD_INT(GL_RED_BITS); - PY_DICT_ADD_INT(GL_RED_SCALE); - PY_DICT_ADD_INT(GL_RENDER); - PY_DICT_ADD_INT(GL_RENDER_MODE); - PY_DICT_ADD_INT(GL_RETURN); - PY_DICT_ADD_INT(GL_RGBA_MODE); - PY_DICT_ADD_INT(GL_S); - PY_DICT_ADD_INT(GL_SCISSOR_BIT); - PY_DICT_ADD_INT(GL_SELECT); - PY_DICT_ADD_INT(GL_SELECTION_BUFFER_POINTER); - PY_DICT_ADD_INT(GL_SELECTION_BUFFER_SIZE); - PY_DICT_ADD_INT(GL_SHADE_MODEL); - PY_DICT_ADD_INT(GL_SHININESS); - PY_DICT_ADD_INT(GL_SMOOTH); - PY_DICT_ADD_INT(GL_SPECULAR); - PY_DICT_ADD_INT(GL_SPHERE_MAP); - PY_DICT_ADD_INT(GL_SPOT_CUTOFF); - PY_DICT_ADD_INT(GL_SPOT_DIRECTION); - PY_DICT_ADD_INT(GL_SPOT_EXPONENT); - PY_DICT_ADD_INT(GL_STACK_OVERFLOW); - PY_DICT_ADD_INT(GL_STACK_UNDERFLOW); - PY_DICT_ADD_INT(GL_STENCIL_BITS); - PY_DICT_ADD_INT(GL_T); - PY_DICT_ADD_INT(GL_T2F_C3F_V3F); - PY_DICT_ADD_INT(GL_T2F_C4F_N3F_V3F); - PY_DICT_ADD_INT(GL_T2F_C4UB_V3F); - PY_DICT_ADD_INT(GL_T2F_N3F_V3F); - PY_DICT_ADD_INT(GL_T2F_V3F); - PY_DICT_ADD_INT(GL_T4F_C4F_N3F_V4F); - PY_DICT_ADD_INT(GL_T4F_V4F); - PY_DICT_ADD_INT(GL_TEXTURE_BIT); - PY_DICT_ADD_INT(GL_TEXTURE_BORDER); - PY_DICT_ADD_INT(GL_TEXTURE_COMPONENTS); - PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY); - PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_TEXTURE_ENV); - PY_DICT_ADD_INT(GL_TEXTURE_ENV_COLOR); - PY_DICT_ADD_INT(GL_TEXTURE_ENV_MODE); - PY_DICT_ADD_INT(GL_TEXTURE_GEN_MODE); - PY_DICT_ADD_INT(GL_TEXTURE_GEN_Q); - PY_DICT_ADD_INT(GL_TEXTURE_GEN_R); - PY_DICT_ADD_INT(GL_TEXTURE_GEN_S); - PY_DICT_ADD_INT(GL_TEXTURE_GEN_T); - PY_DICT_ADD_INT(GL_TEXTURE_INTENSITY_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_LUMINANCE_SIZE); - PY_DICT_ADD_INT(GL_TEXTURE_MATRIX); - PY_DICT_ADD_INT(GL_TEXTURE_PRIORITY); - PY_DICT_ADD_INT(GL_TEXTURE_RESIDENT); - PY_DICT_ADD_INT(GL_TEXTURE_STACK_DEPTH); - PY_DICT_ADD_INT(GL_TRANSFORM_BIT); - PY_DICT_ADD_INT(GL_V2F); - PY_DICT_ADD_INT(GL_V3F); - PY_DICT_ADD_INT(GL_VERTEX_ARRAY); - PY_DICT_ADD_INT(GL_VERTEX_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_VERTEX_ARRAY_SIZE); - PY_DICT_ADD_INT(GL_VERTEX_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_VERTEX_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_VIEWPORT_BIT); - PY_DICT_ADD_INT(GL_ZOOM_X); - PY_DICT_ADD_INT(GL_ZOOM_Y); - } - /* GL_VERSION_1_2 */ { @@ -2974,15 +1906,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5); PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5_REV); } - /* adding in GL_VERSION_1_2 removed from core profile */ - if (use_deprecated == true) { - PY_DICT_ADD_INT(GL_ALIASED_POINT_SIZE_RANGE); - PY_DICT_ADD_INT(GL_LIGHT_MODEL_COLOR_CONTROL); - PY_DICT_ADD_INT(GL_RESCALE_NORMAL); - PY_DICT_ADD_INT(GL_SEPARATE_SPECULAR_COLOR); - PY_DICT_ADD_INT(GL_SINGLE_COLOR); - } - /* GL_VERSION_1_3 */ { @@ -3046,47 +1969,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y); PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z); } - /* adding in GL_VERSION_1_3 removed from core profile */ - if (use_deprecated == true) { - PY_DICT_ADD_INT(GL_ADD_SIGNED); - PY_DICT_ADD_INT(GL_CLIENT_ACTIVE_TEXTURE); - PY_DICT_ADD_INT(GL_COMBINE); - PY_DICT_ADD_INT(GL_COMBINE_ALPHA); - PY_DICT_ADD_INT(GL_COMBINE_RGB); - PY_DICT_ADD_INT(GL_COMPRESSED_ALPHA); - PY_DICT_ADD_INT(GL_COMPRESSED_INTENSITY); - PY_DICT_ADD_INT(GL_COMPRESSED_LUMINANCE); - PY_DICT_ADD_INT(GL_COMPRESSED_LUMINANCE_ALPHA); - PY_DICT_ADD_INT(GL_CONSTANT); - PY_DICT_ADD_INT(GL_DOT3_RGB); - PY_DICT_ADD_INT(GL_DOT3_RGBA); - PY_DICT_ADD_INT(GL_INTERPOLATE); - PY_DICT_ADD_INT(GL_MAX_TEXTURE_UNITS); - PY_DICT_ADD_INT(GL_MULTISAMPLE_BIT); - PY_DICT_ADD_INT(GL_NORMAL_MAP); - PY_DICT_ADD_INT(GL_OPERAND0_ALPHA); - PY_DICT_ADD_INT(GL_OPERAND0_RGB); - PY_DICT_ADD_INT(GL_OPERAND1_ALPHA); - PY_DICT_ADD_INT(GL_OPERAND1_RGB); - PY_DICT_ADD_INT(GL_OPERAND2_ALPHA); - PY_DICT_ADD_INT(GL_OPERAND2_RGB); - PY_DICT_ADD_INT(GL_PREVIOUS); - PY_DICT_ADD_INT(GL_PRIMARY_COLOR); - PY_DICT_ADD_INT(GL_REFLECTION_MAP); - PY_DICT_ADD_INT(GL_RGB_SCALE); - PY_DICT_ADD_INT(GL_SOURCE0_ALPHA); - PY_DICT_ADD_INT(GL_SOURCE0_RGB); - PY_DICT_ADD_INT(GL_SOURCE1_ALPHA); - PY_DICT_ADD_INT(GL_SOURCE1_RGB); - PY_DICT_ADD_INT(GL_SOURCE2_ALPHA); - PY_DICT_ADD_INT(GL_SOURCE2_RGB); - PY_DICT_ADD_INT(GL_SUBTRACT); - PY_DICT_ADD_INT(GL_TRANSPOSE_COLOR_MATRIX); - PY_DICT_ADD_INT(GL_TRANSPOSE_MODELVIEW_MATRIX); - PY_DICT_ADD_INT(GL_TRANSPOSE_PROJECTION_MATRIX); - PY_DICT_ADD_INT(GL_TRANSPOSE_TEXTURE_MATRIX); - } - /* GL_VERSION_1_4 */ { @@ -3116,33 +1998,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_TEXTURE_DEPTH_SIZE); PY_DICT_ADD_INT(GL_TEXTURE_LOD_BIAS); } - /* adding in GL_VERSION_1_4 removed from core profile */ - if (use_deprecated == true) { - PY_DICT_ADD_INT(GL_COLOR_SUM); - PY_DICT_ADD_INT(GL_COMPARE_R_TO_TEXTURE); - PY_DICT_ADD_INT(GL_CURRENT_FOG_COORDINATE); - PY_DICT_ADD_INT(GL_CURRENT_SECONDARY_COLOR); - PY_DICT_ADD_INT(GL_DEPTH_TEXTURE_MODE); - PY_DICT_ADD_INT(GL_FOG_COORDINATE); - PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY); - PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_FOG_COORDINATE_SOURCE); - PY_DICT_ADD_INT(GL_FRAGMENT_DEPTH); - PY_DICT_ADD_INT(GL_GENERATE_MIPMAP); - PY_DICT_ADD_INT(GL_GENERATE_MIPMAP_HINT); - PY_DICT_ADD_INT(GL_POINT_DISTANCE_ATTENUATION); - PY_DICT_ADD_INT(GL_POINT_SIZE_MAX); - PY_DICT_ADD_INT(GL_POINT_SIZE_MIN); - PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY); - PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_SIZE); - PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_TEXTURE_FILTER_CONTROL); - } - /* GL_VERSION_1_5 */ { @@ -3165,7 +2020,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_READ_ONLY); PY_DICT_ADD_INT(GL_READ_WRITE); PY_DICT_ADD_INT(GL_SAMPLES_PASSED); - PY_DICT_ADD_INT(GL_SRC1_ALPHA); PY_DICT_ADD_INT(GL_STATIC_COPY); PY_DICT_ADD_INT(GL_STATIC_DRAW); PY_DICT_ADD_INT(GL_STATIC_READ); @@ -3175,32 +2029,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING); PY_DICT_ADD_INT(GL_WRITE_ONLY); } - /* adding in GL_VERSION_1_5 removed from core profile */ - if (use_deprecated == true) { - PY_DICT_ADD_INT(GL_COLOR_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_CURRENT_FOG_COORD); - PY_DICT_ADD_INT(GL_EDGE_FLAG_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_FOG_COORD); - PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY); - PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY_POINTER); - PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY_STRIDE); - PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY_TYPE); - PY_DICT_ADD_INT(GL_FOG_COORD_SRC); - PY_DICT_ADD_INT(GL_INDEX_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_NORMAL_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_SRC0_ALPHA); - PY_DICT_ADD_INT(GL_SRC0_RGB); - PY_DICT_ADD_INT(GL_SRC1_RGB); - PY_DICT_ADD_INT(GL_SRC2_ALPHA); - PY_DICT_ADD_INT(GL_SRC2_RGB); - PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_VERTEX_ARRAY_BUFFER_BINDING); - PY_DICT_ADD_INT(GL_WEIGHT_ARRAY_BUFFER_BINDING); - } - /* GL_VERSION_2_0 */ { @@ -3285,14 +2113,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_VERTEX_PROGRAM_POINT_SIZE); PY_DICT_ADD_INT(GL_VERTEX_SHADER); } - /* adding in GL_VERSION_2_0 removed from core profile */ - if (use_deprecated == true) { - PY_DICT_ADD_INT(GL_COORD_REPLACE); - PY_DICT_ADD_INT(GL_MAX_TEXTURE_COORDS); - PY_DICT_ADD_INT(GL_POINT_SPRITE); - PY_DICT_ADD_INT(GL_VERTEX_PROGRAM_TWO_SIDE); - } - /* GL_VERSION_2_1 */ { @@ -3313,16 +2133,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_SRGB8_ALPHA8); PY_DICT_ADD_INT(GL_SRGB_ALPHA); } - /* adding in GL_VERSION_2_1 removed from core profile */ - if (use_deprecated == true) { - PY_DICT_ADD_INT(GL_COMPRESSED_SLUMINANCE); - PY_DICT_ADD_INT(GL_COMPRESSED_SLUMINANCE_ALPHA); - PY_DICT_ADD_INT(GL_CURRENT_RASTER_SECONDARY_COLOR); - PY_DICT_ADD_INT(GL_SLUMINANCE); - PY_DICT_ADD_INT(GL_SLUMINANCE8); - PY_DICT_ADD_INT(GL_SLUMINANCE8_ALPHA8); - PY_DICT_ADD_INT(GL_SLUMINANCE_ALPHA); - } /* GL_VERSION_3_0 */ { @@ -3563,14 +2373,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_VERTEX_ARRAY_BINDING); PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_INTEGER); } - /* adding in GL_VERSION_3_0 removed from core profile */ - if (use_deprecated == true) { - PY_DICT_ADD_INT(GL_ALPHA_INTEGER); - PY_DICT_ADD_INT(GL_CLAMP_FRAGMENT_COLOR); - PY_DICT_ADD_INT(GL_CLAMP_VERTEX_COLOR); - PY_DICT_ADD_INT(GL_TEXTURE_INTENSITY_TYPE); - PY_DICT_ADD_INT(GL_TEXTURE_LUMINANCE_TYPE); - } /* GL_VERSION_3_1 */ { @@ -3637,7 +2439,6 @@ PyObject *BPyInit_bgl(void) PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_BUFFER); } - /* GL_VERSION_3_2 */ { PY_DICT_ADD_INT(GL_ALREADY_SIGNALED); @@ -3743,4 +2544,4 @@ static PyObject *Method_ShaderSource(PyObject *UNUSED(self), PyObject *args) } -/** \} */
\ No newline at end of file +/** \} */ diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c index 69f1e297b43..02bd1fdbe39 100644 --- a/source/blender/python/generic/blf_py_api.c +++ b/source/blender/python/generic/blf_py_api.c @@ -114,6 +114,7 @@ static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args) } +#if BLF_BLUR_ENABLE PyDoc_STRVAR(py_blf_blur_doc, ".. function:: blur(fontid, radius)\n" "\n" @@ -135,6 +136,7 @@ static PyObject *py_blf_blur(PyObject *UNUSED(self), PyObject *args) Py_RETURN_NONE; } +#endif PyDoc_STRVAR(py_blf_draw_doc, @@ -418,7 +420,9 @@ static PyObject *py_blf_unload(PyObject *UNUSED(self), PyObject *args) /*----------------------------MODULE INIT-------------------------*/ static PyMethodDef BLF_methods[] = { {"aspect", (PyCFunction) py_blf_aspect, METH_VARARGS, py_blf_aspect_doc}, +#if BLF_BLUR_ENABLE {"blur", (PyCFunction) py_blf_blur, METH_VARARGS, py_blf_blur_doc}, +#endif {"clipping", (PyCFunction) py_blf_clipping, METH_VARARGS, py_blf_clipping_doc}, {"word_wrap", (PyCFunction) py_blf_word_wrap, METH_VARARGS, py_blf_word_wrap_doc}, {"disable", (PyCFunction) py_blf_disable, METH_VARARGS, py_blf_disable_doc}, diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 2b6dc54dad4..a71478cdb15 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -64,6 +64,8 @@ set(SRC bpy_intern_string.c bpy_library_load.c bpy_library_write.c + bpy_manipulator_wrap.c + bpy_msgbus.c bpy_operator.c bpy_operator_wrap.c bpy_path.c @@ -74,11 +76,14 @@ set(SRC bpy_rna_callback.c bpy_rna_driver.c bpy_rna_id_collection.c + bpy_rna_manipulator.c bpy_traceback.c bpy_utils_previews.c bpy_utils_units.c gpu.c gpu_offscreen.c + gpu_py_matrix.c + gpu_py_select.c stubs.c bpy.h @@ -97,6 +102,8 @@ set(SRC bpy_driver.h bpy_intern_string.h bpy_library.h + bpy_manipulator_wrap.h + bpy_msgbus.h bpy_operator.h bpy_operator_wrap.h bpy_path.h @@ -106,6 +113,7 @@ set(SRC bpy_rna_callback.h bpy_rna_driver.h bpy_rna_id_collection.h + bpy_rna_manipulator.h bpy_traceback.h bpy_utils_previews.h bpy_utils_units.h diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index 7150cc65942..e07fa46424c 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -46,6 +46,7 @@ #include "bpy_rna.h" #include "bpy_app.h" #include "bpy_rna_id_collection.h" +#include "bpy_rna_manipulator.h" #include "bpy_props.h" #include "bpy_library.h" #include "bpy_operator.h" @@ -57,6 +58,7 @@ /* external util modules */ #include "../generic/idprop_py_api.h" +#include "bpy_msgbus.h" #ifdef WITH_FREESTYLE # include "BPy_Freestyle.h" @@ -338,6 +340,8 @@ void BPy_init_modules(void) BPY_rna_id_collection_module(mod); + BPY_rna_manipulator_module(mod); + bpy_import_test("bpy_types"); PyModule_AddObject(mod, "data", BPY_rna_module()); /* imports bpy_types by running this */ bpy_import_test("bpy_types"); @@ -347,6 +351,7 @@ void BPy_init_modules(void) PyModule_AddObject(mod, "app", BPY_app_struct()); PyModule_AddObject(mod, "_utils_units", BPY_utils_units()); PyModule_AddObject(mod, "_utils_previews", BPY_utils_previews_module()); + PyModule_AddObject(mod, "msgbus", BPY_msgbus_module()); /* bpy context */ RNA_pointer_create(NULL, &RNA_Context, (void *)BPy_GetContext(), &ctx_ptr); @@ -371,6 +376,9 @@ void BPy_init_modules(void) PyModule_AddObject(mod, meth_bpy_register_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_register_class, NULL)); PyModule_AddObject(mod, meth_bpy_unregister_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_unregister_class, NULL)); + PyModule_AddObject(mod, meth_bpy_owner_id_get.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_owner_id_get, NULL)); + PyModule_AddObject(mod, meth_bpy_owner_id_set.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_owner_id_set, NULL)); + /* add our own modules dir, this is a python package */ bpy_package_py = bpy_import_test("bpy"); } diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c index 90aa22de5bf..5a309339e17 100644 --- a/source/blender/python/intern/bpy_app_handlers.c +++ b/source/blender/python/intern/bpy_app_handlers.c @@ -59,12 +59,6 @@ static PyStructSequence_Field app_cb_info_fields[] = { {(char *)"load_post", (char *)"on loading a new blend file (after)"}, {(char *)"save_pre", (char *)"on saving a blend file (before)"}, {(char *)"save_post", (char *)"on saving a blend file (after)"}, - {(char *)"scene_update_pre", (char *)"on every scene data update. Does not imply that anything changed in the " - "scene, just that the dependency graph is about to be reevaluated, and the " - "scene is about to be updated by Blender's animation system."}, - {(char *)"scene_update_post", (char *)"on every scene data update. Does not imply that anything changed in the " - "scene, just that the dependency graph was reevaluated, and the scene was " - "possibly updated by Blender's animation system."}, {(char *)"game_pre", (char *)"on starting the game engine"}, {(char *)"game_post", (char *)"on ending the game engine"}, {(char *)"version_update", (char *)"on ending the versioning code"}, diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index ae8e35ae3fc..11a233461d8 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -72,6 +72,7 @@ #include "../generic/bgl.h" #include "../generic/blf_py_api.h" #include "../generic/idprop_py_api.h" +#include "../gawain/gwn_py_api.h" #include "../bmesh/bmesh_py_api.h" #include "../mathutils/mathutils.h" @@ -212,6 +213,7 @@ static struct _inittab bpy_internal_modules[] = { {"mathutils.kdtree", PyInit_mathutils_kdtree}, #endif {"_bpy_path", BPyInit__bpy_path}, + {"_gawain", BPyInit_gawain}, {"bgl", BPyInit_bgl}, {"blf", BPyInit_blf}, {"bmesh", BPyInit_bmesh}, @@ -530,7 +532,8 @@ static bool python_script_exec( if (py_dict) { #ifdef PYMODULE_CLEAR_WORKAROUND - PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__"); + PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItem( + PyThreadState_GET()->interp->modules, bpy_intern_str___main__); PyObject *dict_back = mmod->md_dict; /* freeing the module will clear the namespace, * gives problems running classes defined in this namespace being used later. */ diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c index ac0100fa75d..6911e985e93 100644 --- a/source/blender/python/intern/bpy_intern_string.c +++ b/source/blender/python/intern/bpy_intern_string.c @@ -34,21 +34,24 @@ #include "BLI_utildefines.h" -static PyObject *bpy_intern_str_arr[13]; +static PyObject *bpy_intern_str_arr[16]; -PyObject *bpy_intern_str_register; -PyObject *bpy_intern_str_unregister; -PyObject *bpy_intern_str_bl_rna; +PyObject *bpy_intern_str___doc__; +PyObject *bpy_intern_str___main__; +PyObject *bpy_intern_str___module__; +PyObject *bpy_intern_str___name__; +PyObject *bpy_intern_str___slots__; +PyObject *bpy_intern_str_attr; PyObject *bpy_intern_str_bl_property; +PyObject *bpy_intern_str_bl_rna; +PyObject *bpy_intern_str_bl_target_properties; PyObject *bpy_intern_str_bpy_types; +PyObject *bpy_intern_str_frame; PyObject *bpy_intern_str_order; -PyObject *bpy_intern_str_attr; +PyObject *bpy_intern_str_properties; +PyObject *bpy_intern_str_register; PyObject *bpy_intern_str_self; -PyObject *bpy_intern_str_frame; -PyObject *bpy_intern_str___slots__; -PyObject *bpy_intern_str___name__; -PyObject *bpy_intern_str___doc__; -PyObject *bpy_intern_str___module__; +PyObject *bpy_intern_str_unregister; void bpy_intern_string_init(void) { @@ -57,19 +60,22 @@ void bpy_intern_string_init(void) #define BPY_INTERN_STR(var, str) \ { var = bpy_intern_str_arr[i++] = PyUnicode_FromString(str); } (void)0 - BPY_INTERN_STR(bpy_intern_str_register, "register"); - BPY_INTERN_STR(bpy_intern_str_unregister, "unregister"); - BPY_INTERN_STR(bpy_intern_str_bl_rna, "bl_rna"); + BPY_INTERN_STR(bpy_intern_str___doc__, "__doc__"); + BPY_INTERN_STR(bpy_intern_str___main__, "__main__"); + BPY_INTERN_STR(bpy_intern_str___module__, "__module__"); + BPY_INTERN_STR(bpy_intern_str___name__, "__name__"); + BPY_INTERN_STR(bpy_intern_str___slots__, "__slots__"); + BPY_INTERN_STR(bpy_intern_str_attr, "attr"); BPY_INTERN_STR(bpy_intern_str_bl_property, "bl_property"); + BPY_INTERN_STR(bpy_intern_str_bl_rna, "bl_rna"); + BPY_INTERN_STR(bpy_intern_str_bl_target_properties, "bl_target_properties"); BPY_INTERN_STR(bpy_intern_str_bpy_types, "bpy.types"); + BPY_INTERN_STR(bpy_intern_str_frame, "frame"); BPY_INTERN_STR(bpy_intern_str_order, "order"); - BPY_INTERN_STR(bpy_intern_str_attr, "attr"); + BPY_INTERN_STR(bpy_intern_str_properties, "properties"); + BPY_INTERN_STR(bpy_intern_str_register, "register"); BPY_INTERN_STR(bpy_intern_str_self, "self"); - BPY_INTERN_STR(bpy_intern_str_frame, "frame"); - BPY_INTERN_STR(bpy_intern_str___slots__, "__slots__"); - BPY_INTERN_STR(bpy_intern_str___name__, "__name__"); - BPY_INTERN_STR(bpy_intern_str___doc__, "__doc__"); - BPY_INTERN_STR(bpy_intern_str___module__, "__module__"); + BPY_INTERN_STR(bpy_intern_str_unregister, "unregister"); #undef BPY_INTERN_STR diff --git a/source/blender/python/intern/bpy_intern_string.h b/source/blender/python/intern/bpy_intern_string.h index 394e84d89bd..998c312c321 100644 --- a/source/blender/python/intern/bpy_intern_string.h +++ b/source/blender/python/intern/bpy_intern_string.h @@ -30,18 +30,21 @@ void bpy_intern_string_init(void); void bpy_intern_string_exit(void); -extern PyObject *bpy_intern_str_register; -extern PyObject *bpy_intern_str_unregister; -extern PyObject *bpy_intern_str_bl_rna; +extern PyObject *bpy_intern_str___doc__; +extern PyObject *bpy_intern_str___main__; +extern PyObject *bpy_intern_str___module__; +extern PyObject *bpy_intern_str___name__; +extern PyObject *bpy_intern_str___slots__; +extern PyObject *bpy_intern_str_attr; extern PyObject *bpy_intern_str_bl_property; +extern PyObject *bpy_intern_str_bl_rna; +extern PyObject *bpy_intern_str_bl_target_properties; extern PyObject *bpy_intern_str_bpy_types; +extern PyObject *bpy_intern_str_frame; extern PyObject *bpy_intern_str_order; -extern PyObject *bpy_intern_str_attr; +extern PyObject *bpy_intern_str_properties; +extern PyObject *bpy_intern_str_register; extern PyObject *bpy_intern_str_self; -extern PyObject *bpy_intern_str_frame; -extern PyObject *bpy_intern_str___slots__; -extern PyObject *bpy_intern_str___name__; -extern PyObject *bpy_intern_str___doc__; -extern PyObject *bpy_intern_str___module__; +extern PyObject *bpy_intern_str_unregister; #endif /* __BPY_INTERN_STRING_H__ */ diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c index 20226ffe6a3..4cd5e21bc22 100644 --- a/source/blender/python/intern/bpy_library_load.c +++ b/source/blender/python/intern/bpy_library_load.c @@ -38,8 +38,6 @@ #include "BLI_linklist.h" #include "BLI_path_util.h" -#include "BLO_readfile.h" - #include "BKE_main.h" #include "BKE_library.h" #include "BKE_idcode.h" @@ -48,6 +46,8 @@ #include "DNA_space_types.h" /* FILE_LINK, FILE_RELPATH */ +#include "BLO_readfile.h" + #include "bpy_capi_utils.h" #include "bpy_library.h" @@ -332,6 +332,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) Main *bmain = CTX_data_main(BPy_GetContext()); Main *mainl = NULL; int err = 0; + const bool do_append = ((self->flag & FILE_LINK) == 0); BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true); @@ -341,7 +342,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) { int idcode_step = 0, idcode; while ((idcode = BKE_idcode_iter_step(&idcode_step))) { - if (BKE_idcode_is_linkable(idcode)) { + if (BKE_idcode_is_linkable(idcode) && (idcode != ID_WS || do_append)) { const char *name_plural = BKE_idcode_to_name_plural(idcode); PyObject *ls = PyDict_GetItemString(self->dict, name_plural); // printf("lib: %s\n", name_plural); @@ -414,7 +415,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) BKE_main_lib_objects_recalc_all(bmain); /* append, rather than linking */ - if ((self->flag & FILE_LINK) == 0) { + if (do_append) { BKE_library_make_local(bmain, lib, old_to_new_ids, true, false); } } @@ -427,7 +428,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) { int idcode_step = 0, idcode; while ((idcode = BKE_idcode_iter_step(&idcode_step))) { - if (BKE_idcode_is_linkable(idcode)) { + if (BKE_idcode_is_linkable(idcode) && (idcode != ID_WS || do_append)) { const char *name_plural = BKE_idcode_to_name_plural(idcode); PyObject *ls = PyDict_GetItemString(self->dict, name_plural); if (ls && PyList_Check(ls)) { diff --git a/source/blender/python/intern/bpy_manipulator_wrap.c b/source/blender/python/intern/bpy_manipulator_wrap.c new file mode 100644 index 00000000000..9df4e81ec55 --- /dev/null +++ b/source/blender/python/intern/bpy_manipulator_wrap.c @@ -0,0 +1,236 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_manipulator_wrap.c + * \ingroup pythonintern + * + * This file is so Python can define widget-group's that C can call into. + * The generic callback functions for Python widget-group are defines in + * 'rna_wm.c', some calling into functions here to do python specific + * functionality. + * + * \note This follows 'bpy_operator_wrap.c' very closely. + * Keep in sync unless there is good reason not to! + */ + +#include <Python.h> + +#include "BLI_utildefines.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "bpy_rna.h" +#include "bpy_intern_string.h" +#include "bpy_manipulator_wrap.h" /* own include */ + +/* we may want to add, but not now */ + +/* -------------------------------------------------------------------- */ + +/** \name Manipulator + * \{ */ + + +static bool bpy_manipulatortype_target_property_def( + wmManipulatorType *wt, PyObject *item) +{ + /* Note: names based on 'rna_rna.c' */ + PyObject *empty_tuple = PyTuple_New(0); + + struct { + char *id; + char *type_id; int type; + int array_length; + } params = { + .id = NULL, /* not optional */ + .type = PROP_FLOAT, + .type_id = NULL, + .array_length = 1, + }; + + static const char * const _keywords[] = {"id", "type", "array_length", NULL}; + static _PyArg_Parser _parser = {"|$ssi:register_class", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + empty_tuple, item, + &_parser, + ¶ms.id, + ¶ms.type_id, + ¶ms.array_length)) + { + goto fail; + } + + if (params.id == NULL) { + PyErr_SetString(PyExc_ValueError, "'id' argument not given"); + goto fail; + } + + if ((params.type_id != NULL) && + pyrna_enum_value_from_id( + rna_enum_property_type_items, params.type_id, ¶ms.type, "'type' enum value") == -1) + { + goto fail; + } + else { + params.type = rna_enum_property_type_items[params.type].value; + } + + if ((params.array_length < 1 || params.array_length > RNA_MAX_ARRAY_LENGTH)) { + PyErr_SetString(PyExc_ValueError, "'array_length' out of range"); + goto fail; + } + + WM_manipulatortype_target_property_def(wt, params.id, params.type, params.array_length); + Py_DECREF(empty_tuple); + return true; + +fail: + Py_DECREF(empty_tuple); + return false; +} + +static void manipulator_properties_init(wmManipulatorType *wt) +{ + PyTypeObject *py_class = wt->ext.data; + RNA_struct_blender_type_set(wt->ext.srna, wt); + + /* 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); + + if (pyrna_deferred_register_class(wt->srna, py_class) != 0) { + PyErr_Print(); /* failed to register operator props */ + PyErr_Clear(); + } + + /* Extract target property definitions from 'bl_target_properties' */ + { + /* picky developers will notice that 'bl_targets' won't work with inheritance + * get direct from the dict to avoid raising a load of attribute errors (yes this isnt ideal) - campbell */ + PyObject *py_class_dict = py_class->tp_dict; + PyObject *bl_target_properties = PyDict_GetItem(py_class_dict, bpy_intern_str_bl_target_properties); + + /* Some widgets may only exist to activate operators. */ + if (bl_target_properties != NULL) { + PyObject *bl_target_properties_fast; + if (!(bl_target_properties_fast = PySequence_Fast( + bl_target_properties, "bl_target_properties sequence"))) + { + /* PySequence_Fast sets the error */ + PyErr_Print(); + PyErr_Clear(); + return; + } + + const uint items_len = PySequence_Fast_GET_SIZE(bl_target_properties_fast); + PyObject **items = PySequence_Fast_ITEMS(bl_target_properties_fast); + + for (uint i = 0; i < items_len; i++) { + if (!bpy_manipulatortype_target_property_def(wt, items[i])) { + PyErr_Print(); + PyErr_Clear(); + break; + } + } + + Py_DECREF(bl_target_properties_fast); + } + } +} + +void BPY_RNA_manipulator_wrapper(wmManipulatorType *wt, void *userdata) +{ + /* take care not to overwrite anything set in + * WM_manipulatormaptype_group_link_ptr before opfunc() is called */ + StructRNA *srna = wt->srna; + *wt = *((wmManipulatorType *)userdata); + wt->srna = srna; /* restore */ + + /* don't do translations here yet */ +#if 0 + /* Use i18n context from ext.srna if possible (py manipulatorgroups). */ + if (wt->ext.srna) { + RNA_def_struct_translation_context(wt->srna, RNA_struct_translation_context(wt->ext.srna)); + } +#endif + + wt->struct_size = sizeof(wmManipulator); + + manipulator_properties_init(wt); +} + +/** \} */ + + +/* -------------------------------------------------------------------- */ + +/** \name Manipulator Group + * \{ */ + +static void manipulatorgroup_properties_init(wmManipulatorGroupType *wgt) +{ +#ifdef USE_SRNA + PyTypeObject *py_class = wgt->ext.data; +#endif + RNA_struct_blender_type_set(wgt->ext.srna, wgt); + +#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); + + if (pyrna_deferred_register_class(wgt->srna, py_class) != 0) { + PyErr_Print(); /* failed to register operator props */ + PyErr_Clear(); + } +#endif +} + +void BPY_RNA_manipulatorgroup_wrapper(wmManipulatorGroupType *wgt, void *userdata) +{ + /* take care not to overwrite anything set in + * WM_manipulatormaptype_group_link_ptr before opfunc() is called */ +#ifdef USE_SRNA + StructRNA *srna = wgt->srna; +#endif + *wgt = *((wmManipulatorGroupType *)userdata); +#ifdef USE_SRNA + wgt->srna = srna; /* restore */ +#endif + +#ifdef USE_SRNA + /* Use i18n context from ext.srna if possible (py manipulatorgroups). */ + if (wgt->ext.srna) { + RNA_def_struct_translation_context(wgt->srna, RNA_struct_translation_context(wgt->ext.srna)); + } +#endif + + manipulatorgroup_properties_init(wgt); +} + +/** \} */ + diff --git a/source/blender/python/intern/bpy_manipulator_wrap.h b/source/blender/python/intern/bpy_manipulator_wrap.h new file mode 100644 index 00000000000..3f739e26059 --- /dev/null +++ b/source/blender/python/intern/bpy_manipulator_wrap.h @@ -0,0 +1,36 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_manipulator_wrap.h + * \ingroup pythonintern + */ + +#ifndef __BPY_MANIPULATOR_WRAP_H__ +#define __BPY_MANIPULATOR_WRAP_H__ + +struct wmManipulatorType; +struct wmManipulatorGroupType; + +/* exposed to rna/wm api */ +void BPY_RNA_manipulator_wrapper(struct wmManipulatorType *wt, void *userdata); +void BPY_RNA_manipulatorgroup_wrapper(struct wmManipulatorGroupType *wgt, void *userdata); + +#endif /* __BPY_MANIPULATOR_WRAP_H__ */ + diff --git a/source/blender/python/intern/bpy_msgbus.c b/source/blender/python/intern/bpy_msgbus.c new file mode 100644 index 00000000000..941d6b760dc --- /dev/null +++ b/source/blender/python/intern/bpy_msgbus.c @@ -0,0 +1,400 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_msgbus.c + * \ingroup pythonintern + * This file defines '_bpy_msgbus' module, exposed as 'bpy.msgbus'. + */ + +#include <Python.h> + +#include "../generic/python_utildefines.h" +#include "../generic/py_capi_utils.h" +#include "../mathutils/mathutils.h" + +#include "BLI_utildefines.h" + +#include "BKE_context.h" + +#include "WM_api.h" +#include "WM_types.h" +#include "WM_message.h" + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_enum_types.h" + +#include "bpy_capi_utils.h" +#include "bpy_rna.h" +#include "bpy_intern_string.h" +#include "bpy_manipulator_wrap.h" /* own include */ + + +#include "bpy_msgbus.h" /* own include */ + + +/* -------------------------------------------------------------------- */ +/** \name Internal Utils + * \{ */ + +#define BPY_MSGBUS_RNA_MSGKEY_DOC \ +" :arg key: Represents the type of data being subscribed to\n" \ +"\n" \ +" Arguments include\n" \ +" - :class:`bpy.types.Property` instance.\n" \ +" - :class:`bpy.types.Struct` type.\n" \ +" - (:class:`bpy.types.Struct`, str) type and property name.\n" \ +" :type key: Muliple\n" + +/** + * There are multiple ways we can get RNA from Python, + * it's also possible to register a type instead of an instance. + * + * This function handles converting Python to RNA subscription information. + * + * \param py_sub: See #BPY_MSGBUS_RNA_MSGKEY_DOC for description. + * \param msg_key_params: Message key with all members zeroed out. + * \return -1 on failure, 0 on success. + */ +static int py_msgbus_rna_key_from_py( + PyObject *py_sub, + wmMsgParams_RNA *msg_key_params, + const char *error_prefix) +{ + + /* Allow common case, object rotation, location - etc. */ + if (BaseMathObject_CheckExact(py_sub)) { + BaseMathObject *py_sub_math = (BaseMathObject *)py_sub; + if (py_sub_math->cb_user == NULL) { + PyErr_Format( + PyExc_TypeError, + "%s: math argument has no owner", + error_prefix); + return -1; + } + py_sub = py_sub_math->cb_user; + /* Common case will use BPy_PropertyRNA_Check below. */ + } + + if (BPy_PropertyRNA_Check(py_sub)) { + BPy_PropertyRNA *data_prop = (BPy_PropertyRNA *)py_sub; + PYRNA_PROP_CHECK_INT(data_prop); + msg_key_params->ptr = data_prop->ptr; + msg_key_params->prop = data_prop->prop; + } + else if (BPy_StructRNA_Check(py_sub)) { + /* note, this isn't typically used since we don't edit structs directly. */ + BPy_StructRNA *data_srna = (BPy_StructRNA *)py_sub; + PYRNA_STRUCT_CHECK_INT(data_srna); + msg_key_params->ptr = data_srna->ptr; + } + /* TODO - property / type, not instance. */ + else if (PyType_Check(py_sub)) { + StructRNA *data_type = pyrna_struct_as_srna(py_sub, false, error_prefix); + if (data_type == NULL) { + return -1; + } + msg_key_params->ptr.type = data_type; + } + else if (PyTuple_CheckExact(py_sub)) { + if (PyTuple_GET_SIZE(py_sub) == 2) { + PyObject *data_type_py = PyTuple_GET_ITEM(py_sub, 0); + PyObject *data_prop_py = PyTuple_GET_ITEM(py_sub, 1); + StructRNA *data_type = pyrna_struct_as_srna(data_type_py, false, error_prefix); + if (data_type == NULL) { + return -1; + } + if (!PyUnicode_CheckExact(data_prop_py)) { + PyErr_Format( + PyExc_TypeError, + "%s: expected property to be a string", + error_prefix); + return -1; + } + PointerRNA data_type_ptr = { .type = data_type, }; + const char *data_prop_str = _PyUnicode_AsString(data_prop_py); + PropertyRNA *data_prop = RNA_struct_find_property(&data_type_ptr, data_prop_str); + + if (data_prop == NULL) { + PyErr_Format( + PyExc_TypeError, + "%s: struct %.200s does not contain property %.200s", + error_prefix, + RNA_struct_identifier(data_type), + data_prop_str); + return -1; + } + + msg_key_params->ptr.type = data_type; + msg_key_params->prop = data_prop; + } + else { + PyErr_Format( + PyExc_ValueError, + "%s: Expected a pair (type, property_id)", + error_prefix); + return -1; + } + } + return 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Internal Callbacks + * \{ */ + +#define BPY_MSGBUS_USER_DATA_LEN 2 + +/* Follow wmMsgNotifyFn spec */ +static void bpy_msgbus_notify( + bContext *C, wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val) +{ + PyGILState_STATE gilstate; + bpy_context_set(C, &gilstate); + + PyObject *user_data = msg_val->user_data; + BLI_assert(PyTuple_GET_SIZE(user_data) == BPY_MSGBUS_USER_DATA_LEN); + + PyObject *callback_args = PyTuple_GET_ITEM(user_data, 0); + PyObject *callback_notify = PyTuple_GET_ITEM(user_data, 1); + + const bool is_write_ok = pyrna_write_check(); + if (!is_write_ok) { + pyrna_write_set(true); + } + + PyObject *ret = PyObject_CallObject(callback_notify, callback_args); + + if (ret == NULL) { + PyC_Err_PrintWithFunc(callback_notify); + } + else { + if (ret != Py_None) { + PyErr_SetString(PyExc_ValueError, "the return value must be None"); + PyC_Err_PrintWithFunc(callback_notify); + } + Py_DECREF(ret); + } + + bpy_context_clear(C, &gilstate); + + if (!is_write_ok) { + pyrna_write_set(false); + } +} + +/* Follow wmMsgSubscribeValueFreeDataFn spec */ +static void bpy_msgbus_subscribe_value_free_data( + struct wmMsgSubscribeKey *UNUSED(msg_key), struct wmMsgSubscribeValue *msg_val) +{ + PyGILState_STATE gilstate = PyGILState_Ensure(); + Py_DECREF(msg_val->owner); + Py_DECREF(msg_val->user_data); + PyGILState_Release(gilstate); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Public Message Bus API + * \{ */ + +PyDoc_STRVAR(bpy_msgbus_subscribe_rna_doc, +".. function:: subscribe_rna(data, owner, args, notify)\n" +"\n" +BPY_MSGBUS_RNA_MSGKEY_DOC +" :arg owner: Handle for this subscription (compared by identity).\n" +" :type owner: Any type.\n" +"\n" +" Returns a new vector int property definition.\n" +); +static PyObject *bpy_msgbus_subscribe_rna(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +{ + const char *error_prefix = "subscribe_rna"; + PyObject *py_sub = NULL; + PyObject *py_owner = NULL; + PyObject *callback_args = NULL; + PyObject *callback_notify = NULL; + + enum { + IS_PERSISTENT = (1 << 0), + }; + PyObject *py_options = NULL; + EnumPropertyItem py_options_enum[] = { + {IS_PERSISTENT, "PERSISTENT", 0, ""}, + {0, NULL, 0, NULL, NULL} + }; + int options = 0; + + static const char *_keywords[] = { + "key", + "owner", + "args", + "notify", + "options", + NULL, + }; + static _PyArg_Parser _parser = {"$OOO!OO!:subscribe_rna", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kw, &_parser, + &py_sub, &py_owner, + &PyTuple_Type, &callback_args, + &callback_notify, + &PySet_Type, &py_options)) + { + return NULL; + } + + if (py_options && + (pyrna_set_to_enum_bitfield(py_options_enum, py_options, &options, error_prefix)) == -1) + { + return NULL; + } + + /* Note: we may want to have a way to pass this in. */ + bContext *C = (bContext *)BPy_GetContext(); + struct wmMsgBus *mbus = CTX_wm_message_bus(C); + wmMsgParams_RNA msg_key_params = {{{0}}}; + + wmMsgSubscribeValue msg_val_params = {0}; + + if (py_msgbus_rna_key_from_py(py_sub, &msg_key_params, error_prefix) == -1) { + return NULL; + } + + if (!PyFunction_Check(callback_notify)) { + PyErr_Format( + PyExc_TypeError, + "notify expects a function, found %.200s", + Py_TYPE(callback_notify)->tp_name); + return NULL; + } + + if (options != 0) { + if (options & IS_PERSISTENT) { + msg_val_params.is_persistent = true; + } + } + + /* owner can be anything. */ + { + msg_val_params.owner = py_owner; + Py_INCREF(py_owner); + } + + { + PyObject *user_data = PyTuple_New(2); + PyTuple_SET_ITEMS( + user_data, + Py_INCREF_RET(callback_args), + Py_INCREF_RET(callback_notify)); + msg_val_params.user_data = user_data; + } + + msg_val_params.notify = bpy_msgbus_notify; + msg_val_params.free_data = bpy_msgbus_subscribe_value_free_data; + + WM_msg_subscribe_rna_params(mbus, &msg_key_params, &msg_val_params, __func__); + + WM_msg_dump(mbus, __func__); + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(bpy_msgbus_publish_rna_doc, +".. function:: publish_rna(data, owner, args, notify)\n" +"\n" +BPY_MSGBUS_RNA_MSGKEY_DOC +"\n" +" Notify subscribers of changes to this property\n" +" (this typically doesn't need to be called explicitly since changes will automatically publish updates).\n" +" In some cases it may be useful to publish changes explicitly using more general keys.\n" +); +static PyObject *bpy_msgbus_publish_rna(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +{ + const char *error_prefix = "publish_rna"; + PyObject *py_sub = NULL; + + static const char *_keywords[] = { + "key", + NULL, + }; + static _PyArg_Parser _parser = {"$O:publish_rna", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kw, &_parser, + &py_sub)) + { + return NULL; + } + + /* Note: we may want to have a way to pass this in. */ + bContext *C = (bContext *)BPy_GetContext(); + struct wmMsgBus *mbus = CTX_wm_message_bus(C); + wmMsgParams_RNA msg_key_params = {{{0}}}; + + if (py_msgbus_rna_key_from_py(py_sub, &msg_key_params, error_prefix) == -1) { + return NULL; + } + + WM_msg_publish_rna_params(mbus, &msg_key_params); + + Py_RETURN_NONE; +} + +PyDoc_STRVAR(bpy_msgbus_clear_by_owner_doc, +".. function:: clear_by_owner(owner)\n" +"\n" +" Clear all subscribers using this owner.\n" +); +static PyObject *bpy_msgbus_clear_by_owner(PyObject *UNUSED(self), PyObject *py_owner) +{ + bContext *C = (bContext *)BPy_GetContext(); + struct wmMsgBus *mbus = CTX_wm_message_bus(C); + WM_msgbus_clear_by_owner(mbus, py_owner); + Py_RETURN_NONE; +} + +static struct PyMethodDef BPy_msgbus_methods[] = { + {"subscribe_rna", (PyCFunction)bpy_msgbus_subscribe_rna, METH_VARARGS | METH_KEYWORDS, bpy_msgbus_subscribe_rna_doc}, + {"publish_rna", (PyCFunction)bpy_msgbus_publish_rna, METH_VARARGS | METH_KEYWORDS, bpy_msgbus_publish_rna_doc}, + {"clear_by_owner", (PyCFunction)bpy_msgbus_clear_by_owner, METH_O, bpy_msgbus_clear_by_owner_doc}, + {NULL, NULL, 0, NULL} +}; + +static struct PyModuleDef _bpy_msgbus_def = { + PyModuleDef_HEAD_INIT, + .m_name = "msgbus", + .m_methods = BPy_msgbus_methods, +}; + + +PyObject *BPY_msgbus_module(void) +{ + PyObject *submodule; + + submodule = PyModule_Create(&_bpy_msgbus_def); + + return submodule; +} + +/** \} */ + diff --git a/source/blender/python/intern/bpy_msgbus.h b/source/blender/python/intern/bpy_msgbus.h new file mode 100644 index 00000000000..97b20e9b926 --- /dev/null +++ b/source/blender/python/intern/bpy_msgbus.h @@ -0,0 +1,30 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_msgbus.h + * \ingroup pythonintern + */ + +#ifndef __BPY_MSGBUS_H__ +#define __BPY_MSGBUS_H__ + +PyObject *BPY_msgbus_module(void); + +#endif /* __BPY_MSGBUS_H__ */ diff --git a/source/blender/python/intern/bpy_props.h b/source/blender/python/intern/bpy_props.h index 614c1b4b708..fa2594f94d2 100644 --- a/source/blender/python/intern/bpy_props.h +++ b/source/blender/python/intern/bpy_props.h @@ -34,6 +34,6 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw); PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw); StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix); -#define PYRNA_STACK_ARRAY 32 +#define PYRNA_STACK_ARRAY RNA_STACK_ARRAY #endif diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 87260d6e786..2aff61dc2b8 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -312,7 +312,7 @@ static bool rna_id_write_error(PointerRNA *ptr, PyObject *key) ID *id = ptr->id.data; if (id) { const short idcode = GS(id->name); - if (!ELEM(idcode, ID_WM, ID_SCR)) { /* may need more added here */ + if (!ELEM(idcode, ID_WM, ID_SCR, ID_WS)) { /* may need more added here */ const char *idtype = BKE_idcode_to_name(idcode); const char *pyname; if (key && PyUnicode_Check(key)) pyname = _PyUnicode_AsString(key); @@ -1845,19 +1845,28 @@ static int pyrna_py_to_prop( * class mixing if this causes problems in the future it should be removed. */ if ((ptr_type == &RNA_AnyType) && - (BPy_StructRNA_Check(value)) && - (RNA_struct_is_a(((BPy_StructRNA *)value)->ptr.type, &RNA_Operator))) + (BPy_StructRNA_Check(value))) { - value = PyObject_GetAttrString(value, "properties"); - value_new = value; + const StructRNA *base_type = + RNA_struct_base_child_of(((const BPy_StructRNA *)value)->ptr.type, NULL); + if (ELEM(base_type, &RNA_Operator, &RNA_Manipulator)) { + value = PyObject_GetAttr(value, bpy_intern_str_properties); + value_new = value; + } } - - /* if property is an OperatorProperties pointer and value is a map, + /* if property is an OperatorProperties/ManipulatorProperties pointer and value is a map, * forward back to pyrna_pydict_to_props */ - if (RNA_struct_is_a(ptr_type, &RNA_OperatorProperties) && PyDict_Check(value)) { - PointerRNA opptr = RNA_property_pointer_get(ptr, prop); - return pyrna_pydict_to_props(&opptr, value, false, error_prefix); + if (PyDict_Check(value)) { + const StructRNA *base_type = RNA_struct_base_child_of(ptr_type, NULL); + if (base_type == &RNA_OperatorProperties) { + PointerRNA opptr = RNA_property_pointer_get(ptr, prop); + return pyrna_pydict_to_props(&opptr, value, false, error_prefix); + } + else if (base_type == &RNA_ManipulatorProperties) { + PointerRNA opptr = RNA_property_pointer_get(ptr, prop); + return pyrna_pydict_to_props(&opptr, value, false, error_prefix); + } } /* another exception, allow to pass a collection as an RNA property */ @@ -7588,7 +7597,8 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param PyGILState_STATE gilstate; #ifdef USE_PEDANTIC_WRITE - const bool is_readonly_init = !RNA_struct_is_a(ptr->type, &RNA_Operator); + const bool is_readonly_init = !(RNA_struct_is_a(ptr->type, &RNA_Operator) || + RNA_struct_is_a(ptr->type, &RNA_Manipulator)); // const char *func_id = RNA_function_identifier(func); /* UNUSED */ /* testing, for correctness, not operator and not draw function */ const bool is_readonly = !(RNA_function_flag(func) & FUNC_ALLOW_WRITE); @@ -8247,6 +8257,43 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla Py_RETURN_NONE; } +/* Access to 'owner_id' internal global. */ + +static PyObject *pyrna_bl_owner_id_get(PyObject *UNUSED(self)) +{ + const char *name = RNA_struct_state_owner_get(); + if (name) { + return PyUnicode_FromString(name); + } + Py_RETURN_NONE; +} + +static PyObject *pyrna_bl_owner_id_set(PyObject *UNUSED(self), PyObject *value) +{ + const char *name; + if (value == Py_None) { + name = NULL; + } + else if (PyUnicode_Check(value)) { + name = _PyUnicode_AsString(value); + } + else { + PyErr_Format(PyExc_ValueError, + "owner_set(...): " + "expected None or a string, not '%.200s'", Py_TYPE(value)->tp_name); + return NULL; + } + RNA_struct_state_owner_set(name); + Py_RETURN_NONE; +} + +PyMethodDef meth_bpy_owner_id_get = { + "_bl_owner_id_get", (PyCFunction)pyrna_bl_owner_id_get, METH_NOARGS, NULL, +}; +PyMethodDef meth_bpy_owner_id_set = { + "_bl_owner_id_set", (PyCFunction)pyrna_bl_owner_id_set, METH_O, NULL, +}; + /* currently this is fairly limited, we would need to make some way to split up * pyrna_callback_classmethod_... if we want more than one callback per type */ typedef struct BPyRNA_CallBack { diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index f666294666e..32a63acde40 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -225,4 +225,8 @@ int pyrna_prop_validity_check(BPy_PropertyRNA *self); extern PyMethodDef meth_bpy_register_class; extern PyMethodDef meth_bpy_unregister_class; +/* bpy.utils._bl_owner_(get/set) */ +extern PyMethodDef meth_bpy_owner_id_set; +extern PyMethodDef meth_bpy_owner_id_get; + #endif diff --git a/source/blender/python/intern/bpy_rna_manipulator.c b/source/blender/python/intern/bpy_rna_manipulator.c new file mode 100644 index 00000000000..950f7f98be0 --- /dev/null +++ b/source/blender/python/intern/bpy_rna_manipulator.c @@ -0,0 +1,565 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_rna_manipulator.c + * \ingroup pythonintern + * + * . + */ + +#include <Python.h> +#include <stddef.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_utildefines.h" +#include "BLI_alloca.h" + +#include "BKE_main.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "bpy_capi_utils.h" +#include "bpy_rna_manipulator.h" + +#include "../generic/py_capi_utils.h" +#include "../generic/python_utildefines.h" + +#include "RNA_access.h" +#include "RNA_types.h" +#include "RNA_enum_types.h" + +#include "bpy_rna.h" + + +/* -------------------------------------------------------------------- */ +/** \name Manipulator Target Property Define API + * \{ */ + +enum { + BPY_MANIPULATOR_FN_SLOT_GET = 0, + BPY_MANIPULATOR_FN_SLOT_SET, + BPY_MANIPULATOR_FN_SLOT_RANGE_GET, +}; +#define BPY_MANIPULATOR_FN_SLOT_LEN (BPY_MANIPULATOR_FN_SLOT_RANGE_GET + 1) + +struct BPyManipulatorHandlerUserData { + + PyObject *fn_slots[BPY_MANIPULATOR_FN_SLOT_LEN]; +}; + +static void py_rna_manipulator_handler_get_cb( + const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop, + void *value_p) +{ + PyGILState_STATE gilstate = PyGILState_Ensure(); + + struct BPyManipulatorHandlerUserData *data = mpr_prop->custom_func.user_data; + PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_MANIPULATOR_FN_SLOT_GET], NULL); + if (ret == NULL) { + goto fail; + } + + if (mpr_prop->type->data_type == PROP_FLOAT) { + float *value = value_p; + if (mpr_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, + "Manipulator get callback: ") == -1) + { + goto fail; + } + } + } + else { + PyErr_SetString(PyExc_AttributeError, "internal error, unsupported type"); + goto fail; + } + + Py_DECREF(ret); + + PyGILState_Release(gilstate); + return; + +fail: + PyErr_Print(); + PyErr_Clear(); + + PyGILState_Release(gilstate); +} + +static void py_rna_manipulator_handler_set_cb( + const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop, + const void *value_p) +{ + PyGILState_STATE gilstate = PyGILState_Ensure(); + + struct BPyManipulatorHandlerUserData *data = mpr_prop->custom_func.user_data; + + PyObject *args = PyTuple_New(1); + + if (mpr_prop->type->data_type == PROP_FLOAT) { + const float *value = value_p; + PyObject *py_value; + if (mpr_prop->type->array_length == 1) { + py_value = PyFloat_FromDouble(*value); + } + else { + py_value = PyC_Tuple_PackArray_F32(value, mpr_prop->type->array_length); + } + if (py_value == NULL) { + goto fail; + } + PyTuple_SET_ITEM(args, 0, py_value); + } + else { + PyErr_SetString(PyExc_AttributeError, "internal error, unsupported type"); + goto fail; + } + + PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_MANIPULATOR_FN_SLOT_SET], args); + if (ret == NULL) { + goto fail; + } + Py_DECREF(ret); + + PyGILState_Release(gilstate); + return; + +fail: + PyErr_Print(); + PyErr_Clear(); + + Py_DECREF(args); + + PyGILState_Release(gilstate); +} + +static void py_rna_manipulator_handler_range_get_cb( + const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop, + void *value_p) +{ + struct BPyManipulatorHandlerUserData *data = mpr_prop->custom_func.user_data; + + PyGILState_STATE gilstate = PyGILState_Ensure(); + + PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_MANIPULATOR_FN_SLOT_RANGE_GET], NULL); + if (ret == NULL) { + goto fail; + } + + if (!PyTuple_Check(ret)) { + PyErr_Format(PyExc_TypeError, + "Expected a tuple, not %.200s", + Py_TYPE(ret)->tp_name); + goto fail; + } + + if (PyTuple_GET_SIZE(ret) != 2) { + PyErr_Format(PyExc_TypeError, + "Expected a tuple of size 2, not %d", + PyTuple_GET_SIZE(ret)); + goto fail; + } + + if (mpr_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) { + /* pass */ + } + else { + goto fail; + } + } + memcpy(value_p, range, sizeof(range)); + } + else { + PyErr_SetString(PyExc_AttributeError, "internal error, unsupported type"); + goto fail; + } + + Py_DECREF(ret); + PyGILState_Release(gilstate); + return; + +fail: + Py_XDECREF(ret); + + PyErr_Print(); + PyErr_Clear(); + + PyGILState_Release(gilstate); +} + +static void py_rna_manipulator_handler_free_cb( + const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop) +{ + struct BPyManipulatorHandlerUserData *data = mpr_prop->custom_func.user_data; + + PyGILState_STATE gilstate = PyGILState_Ensure(); + for (int i = 0; i < BPY_MANIPULATOR_FN_SLOT_LEN; i++) { + Py_XDECREF(data->fn_slots[i]); + } + PyGILState_Release(gilstate); + + MEM_freeN(data); + +} + +PyDoc_STRVAR(bpy_manipulator_target_set_handler_doc, +".. method:: target_set_handler(target, get, set, range=None):\n" +"\n" +" Assigns callbacks to a manipulators property.\n" +"\n" +" :arg get: Function that returns the value for this property (single value or sequence).\n" +" :type get: callable\n" +" :arg set: Function that takes a single value argument and applies it.\n" +" :type set: callable\n" +" :arg range: Function that returns a (min, max) tuple for manipulators that use a range.\n" +" :type range: callable\n" +); +static PyObject *bpy_manipulator_target_set_handler(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +{ + PyGILState_STATE gilstate = PyGILState_Ensure(); + + struct { + PyObject *self; + char *target; + PyObject *py_fn_slots[BPY_MANIPULATOR_FN_SLOT_LEN]; + } params = { + .self = NULL, + .target = NULL, + .py_fn_slots = {NULL}, + }; + + /* Note: this is a counter-part to functions: + * 'Manipulator.target_set_prop & target_set_operator' + * (see: rna_wm_manipulator_api.c). conventions should match. */ + static const char * const _keywords[] = {"self", "target", "get", "set", "range", NULL}; + static _PyArg_Parser _parser = {"Os|$OOO:target_set_handler", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kw, &_parser, + ¶ms.self, + ¶ms.target, + ¶ms.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_GET], + ¶ms.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_SET], + ¶ms.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_RANGE_GET])) + { + goto fail; + } + + wmManipulator *mpr = ((BPy_StructRNA *)params.self)->ptr.data; + + const wmManipulatorPropertyType *mpr_prop_type = + WM_manipulatortype_target_property_find(mpr->type, params.target); + if (mpr_prop_type == NULL) { + PyErr_Format(PyExc_ValueError, + "Manipulator target property '%s.%s' not found", + mpr->type->idname, params.target); + goto fail; + } + + { + const int slots_required = 2; + const int slots_start = 2; + for (int i = 0; i < BPY_MANIPULATOR_FN_SLOT_LEN; i++) { + if (params.py_fn_slots[i] == NULL) { + if (i < slots_required) { + PyErr_Format(PyExc_ValueError, "Argument '%s' not given", _keywords[slots_start + i]); + goto fail; + } + } + else if (!PyCallable_Check(params.py_fn_slots[i])) { + PyErr_Format(PyExc_ValueError, "Argument '%s' not callable", _keywords[slots_start + i]); + goto fail; + } + } + } + + struct BPyManipulatorHandlerUserData *data = MEM_callocN(sizeof(*data), __func__); + + for (int i = 0; i < BPY_MANIPULATOR_FN_SLOT_LEN; i++) { + data->fn_slots[i] = params.py_fn_slots[i]; + Py_XINCREF(params.py_fn_slots[i]); + } + + WM_manipulator_target_property_def_func_ptr( + mpr, mpr_prop_type, + &(const struct wmManipulatorPropertyFnParams) { + .value_get_fn = py_rna_manipulator_handler_get_cb, + .value_set_fn = py_rna_manipulator_handler_set_cb, + .range_get_fn = py_rna_manipulator_handler_range_get_cb, + .free_fn = py_rna_manipulator_handler_free_cb, + .user_data = data, + }); + + PyGILState_Release(gilstate); + + Py_RETURN_NONE; + +fail: + PyGILState_Release(gilstate); + return NULL; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Manipulator Target Property Access API + * \{ */ + +PyDoc_STRVAR(bpy_manipulator_target_get_value_doc, +".. method:: target_get_value(target):\n" +"\n" +" Get the value of this target property.\n" +"\n" +" :arg target: Target property name.\n" +" :type target: string\n" +" :return: The value of the target property.\n" +" :rtype: Single value or array based on the target type\n" +); +static PyObject *bpy_manipulator_target_get_value(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +{ + struct { + PyObject *self; + char *target; + } params = { + .self = NULL, + .target = NULL, + }; + + static const char * const _keywords[] = {"self", "target", NULL}; + static _PyArg_Parser _parser = {"Os:target_get_value", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kw, &_parser, + ¶ms.self, + ¶ms.target)) + { + goto fail; + } + + wmManipulator *mpr = ((BPy_StructRNA *)params.self)->ptr.data; + + wmManipulatorProperty *mpr_prop = + WM_manipulator_target_property_find(mpr, params.target); + if (mpr_prop == NULL) { + PyErr_Format(PyExc_ValueError, + "Manipulator target property '%s.%s' not found", + mpr->type->idname, params.target); + goto fail; + } + + const int array_len = WM_manipulator_target_property_array_length(mpr, mpr_prop); + switch (mpr_prop->type->data_type) { + case PROP_FLOAT: + { + if (array_len != 0) { + float *value = BLI_array_alloca(value, array_len); + WM_manipulator_target_property_value_get_array(mpr, mpr_prop, value); + return PyC_Tuple_PackArray_F32(value, array_len); + } + else { + float value = WM_manipulator_target_property_value_get(mpr, mpr_prop); + return PyFloat_FromDouble(value); + } + break; + } + default: + { + PyErr_SetString(PyExc_RuntimeError, "Not yet supported type"); + goto fail; + } + } + +fail: + return NULL; +} + +PyDoc_STRVAR(bpy_manipulator_target_set_value_doc, +".. method:: target_set_value(target):\n" +"\n" +" Set the value of this target property.\n" +"\n" +" :arg target: Target property name.\n" +" :type target: string\n" +); +static PyObject *bpy_manipulator_target_set_value(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +{ + struct { + PyObject *self; + char *target; + PyObject *value; + } params = { + .self = NULL, + .target = NULL, + .value = NULL, + }; + + static const char * const _keywords[] = {"self", "target", "value", NULL}; + static _PyArg_Parser _parser = {"OsO:target_set_value", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kw, &_parser, + ¶ms.self, + ¶ms.target, + ¶ms.value)) + { + goto fail; + } + + wmManipulator *mpr = ((BPy_StructRNA *)params.self)->ptr.data; + + wmManipulatorProperty *mpr_prop = + WM_manipulator_target_property_find(mpr, params.target); + if (mpr_prop == NULL) { + PyErr_Format(PyExc_ValueError, + "Manipulator target property '%s.%s' not found", + mpr->type->idname, params.target); + goto fail; + } + + const int array_len = WM_manipulator_target_property_array_length(mpr, mpr_prop); + switch (mpr_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, + "Manipulator target property array") == -1) + { + goto fail; + } + WM_manipulator_target_property_value_set_array(BPy_GetContext(), mpr, mpr_prop, value); + } + else { + float value; + if ((value = PyFloat_AsDouble(params.value)) == -1.0f && PyErr_Occurred()) { + goto fail; + } + WM_manipulator_target_property_value_set(BPy_GetContext(), mpr, mpr_prop, value); + } + Py_RETURN_NONE; + } + default: + { + PyErr_SetString(PyExc_RuntimeError, "Not yet supported type"); + goto fail; + } + } + +fail: + return NULL; +} + + +PyDoc_STRVAR(bpy_manipulator_target_get_range_doc, +".. method:: target_get_range(target):\n" +"\n" +" Get the range for this target property.\n" +"\n" +" :arg target: Target property name.\n" +" :Get the range for this target property" +" :return: The range of this property (min, max).\n" +" :rtype: tuple pair.\n" +); +static PyObject *bpy_manipulator_target_get_range(PyObject *UNUSED(self), PyObject *args, PyObject *kw) +{ + struct { + PyObject *self; + char *target; + } params = { + .self = NULL, + .target = NULL, + }; + + static const char * const _keywords[] = {"self", "target", NULL}; + static _PyArg_Parser _parser = {"Os:target_get_range", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast( + args, kw, &_parser, + ¶ms.self, + ¶ms.target)) + { + goto fail; + } + + wmManipulator *mpr = ((BPy_StructRNA *)params.self)->ptr.data; + + wmManipulatorProperty *mpr_prop = + WM_manipulator_target_property_find(mpr, params.target); + if (mpr_prop == NULL) { + PyErr_Format(PyExc_ValueError, + "Manipulator target property '%s.%s' not found", + mpr->type->idname, params.target); + goto fail; + } + + switch (mpr_prop->type->data_type) { + case PROP_FLOAT: + { + float range[2]; + WM_manipulator_target_property_range_get(mpr, mpr_prop, range); + return PyC_Tuple_PackArray_F32(range, 2); + } + default: + { + PyErr_SetString(PyExc_RuntimeError, "Not yet supported type"); + goto fail; + } + } + +fail: + return NULL; +} + +/** \} */ + +int BPY_rna_manipulator_module(PyObject *mod_par) +{ + static PyMethodDef method_def_array[] = { + /* Manipulator Target Property Define API */ + {"target_set_handler", (PyCFunction)bpy_manipulator_target_set_handler, + METH_VARARGS | METH_KEYWORDS, bpy_manipulator_target_set_handler_doc}, + /* Manipulator Target Property Access API */ + {"target_get_value", (PyCFunction)bpy_manipulator_target_get_value, + METH_VARARGS | METH_KEYWORDS, bpy_manipulator_target_get_value_doc}, + {"target_set_value", (PyCFunction)bpy_manipulator_target_set_value, + METH_VARARGS | METH_KEYWORDS, bpy_manipulator_target_set_value_doc}, + {"target_get_range", (PyCFunction)bpy_manipulator_target_get_range, + METH_VARARGS | METH_KEYWORDS, bpy_manipulator_target_get_range_doc}, + /* no sentinel needed. */ + }; + + for (int i = 0; i < ARRAY_SIZE(method_def_array); i++) { + PyMethodDef *m = &method_def_array[i]; + PyObject *func = PyCFunction_New(m, NULL); + PyObject *func_inst = PyInstanceMethod_New(func); + char name_prefix[128]; + PyOS_snprintf(name_prefix, sizeof(name_prefix), "_rna_manipulator_%s", m->ml_name); + /* TODO, return a type that binds nearly to a method. */ + PyModule_AddObject(mod_par, name_prefix, func_inst); + } + + return 0; +} diff --git a/source/blender/python/intern/bpy_rna_manipulator.h b/source/blender/python/intern/bpy_rna_manipulator.h new file mode 100644 index 00000000000..b6f3a2e651d --- /dev/null +++ b/source/blender/python/intern/bpy_rna_manipulator.h @@ -0,0 +1,32 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Bastien Montagne + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_rna_manipulator.h + * \ingroup pythonintern + */ + +#ifndef __BPY_RNA_MANIPULATOR_H__ +#define __BPY_RNA_MANIPULATOR_H__ + +int BPY_rna_manipulator_module(PyObject *); + +#endif /* __BPY_RNA_MANIPULATOR_H__ */ diff --git a/source/blender/python/intern/gpu.c b/source/blender/python/intern/gpu.c index 60ce00c583e..a7a0ae78f26 100644 --- a/source/blender/python/intern/gpu.c +++ b/source/blender/python/intern/gpu.c @@ -337,6 +337,14 @@ PyObject *GPU_initPython(void) PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); Py_INCREF(submodule); + PyModule_AddObject(module, "matrix", (submodule = BPyInit_gpu_matrix())); + PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); + Py_INCREF(submodule); + + PyModule_AddObject(module, "select", (submodule = BPyInit_gpu_select())); + PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); + Py_INCREF(submodule); + PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module); return module; } diff --git a/source/blender/python/intern/gpu.h b/source/blender/python/intern/gpu.h index 0da44a4eb87..92841db9027 100644 --- a/source/blender/python/intern/gpu.h +++ b/source/blender/python/intern/gpu.h @@ -37,5 +37,7 @@ PyObject *GPU_initPython(void); PyObject *BPyInit_gpu_offscreen(void); +PyObject *BPyInit_gpu_matrix(void); +PyObject *BPyInit_gpu_select(void); #endif /* __GPU_H__ */ diff --git a/source/blender/python/intern/gpu_offscreen.c b/source/blender/python/intern/gpu_offscreen.c index 3c340d14e3f..72d338bd5db 100644 --- a/source/blender/python/intern/gpu_offscreen.c +++ b/source/blender/python/intern/gpu_offscreen.c @@ -37,8 +37,8 @@ #include "ED_screen.h" -#include "GPU_compositing.h" #include "GPU_framebuffer.h" +#include "GPU_texture.h" #include "../mathutils/mathutils.h" @@ -89,7 +89,8 @@ PyDoc_STRVAR(pygpu_offscreen_color_texture_doc, "Color texture.\n\n:type: int"); static PyObject *pygpu_offscreen_color_texture_get(BPy_GPUOffScreen *self, void *UNUSED(type)) { BPY_GPU_OFFSCREEN_CHECK_OBJ(self); - return PyLong_FromLong(GPU_offscreen_color_texture(self->ofs)); + GPUTexture *texture = GPU_offscreen_color_texture(self->ofs); + return PyLong_FromLong(GPU_texture_opengl_bindcode(texture)); } PyDoc_STRVAR(pygpu_offscreen_bind_doc, @@ -162,12 +163,15 @@ PyDoc_STRVAR(pygpu_offscreen_draw_view3d_doc, ); static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *args, PyObject *kwds) { - static const char *kwlist[] = {"scene", "view3d", "region", "projection_matrix", "modelview_matrix", NULL}; + /* TODO: This doesn't work currently because of eval_ctx. */ +#if 0 + static const char *kwlist[] = {"scene", "view_layer", "view3d", "region", "projection_matrix", "modelview_matrix", NULL}; MatrixObject *py_mat_modelview, *py_mat_projection; - PyObject *py_scene, *py_region, *py_view3d; + PyObject *py_scene, *py_view_layer, *py_region, *py_view3d; Scene *scene; + ViewLayer *view_layer; View3D *v3d; ARegion *ar; GPUFX *fx; @@ -177,13 +181,14 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a BPY_GPU_OFFSCREEN_CHECK_OBJ(self); if (!PyArg_ParseTupleAndKeywords( - args, kwds, "OOOO&O&:draw_view3d", (char **)(kwlist), - &py_scene, &py_view3d, &py_region, + args, kwds, "OOOOO&O&:draw_view3d", (char **)(kwlist), + &py_scene, &py_view_layer, &py_view3d, &py_region, Matrix_Parse4x4, &py_mat_projection, Matrix_Parse4x4, &py_mat_modelview) || - (!(scene = PyC_RNA_AsPointer(py_scene, "Scene")) || - !(v3d = PyC_RNA_AsPointer(py_view3d, "SpaceView3D")) || - !(ar = PyC_RNA_AsPointer(py_region, "Region")))) + (!(scene = PyC_RNA_AsPointer(py_scene, "Scene")) || + !(view_layer = PyC_RNA_AsPointer(py_view_layer, "ViewLayer")) || + !(v3d = PyC_RNA_AsPointer(py_view3d, "SpaceView3D")) || + !(ar = PyC_RNA_AsPointer(py_region, "Region")))) { return NULL; } @@ -192,14 +197,14 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a fx_settings = v3d->fx_settings; /* full copy */ - ED_view3d_draw_offscreen_init(scene, v3d); + ED_view3d_draw_offscreen_init(scene, view_layer, v3d); rv3d_mats = ED_view3d_mats_rv3d_backup(ar->regiondata); GPU_offscreen_bind(self->ofs, true); /* bind */ ED_view3d_draw_offscreen( - scene, v3d, ar, GPU_offscreen_width(self->ofs), GPU_offscreen_height(self->ofs), + scene, view_layer, v3d, ar, GPU_offscreen_width(self->ofs), GPU_offscreen_height(self->ofs), (float(*)[4])py_mat_modelview->matrix, (float(*)[4])py_mat_projection->matrix, false, true, true, "", fx, &fx_settings, @@ -212,6 +217,10 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a MEM_freeN(rv3d_mats); Py_RETURN_NONE; +#else + UNUSED_VARS(self, args, kwds); +#endif + return NULL; } PyDoc_STRVAR(pygpu_offscreen_free_doc, @@ -346,7 +355,7 @@ static PyObject *pygpu_offscreen_new(PyObject *UNUSED(self), PyObject *args, PyO return NULL; } - ofs = GPU_offscreen_create(width, height, samples, err_out); + ofs = GPU_offscreen_create(width, height, samples, true, false, err_out); if (ofs == NULL) { PyErr_Format(PyExc_RuntimeError, diff --git a/source/blender/python/intern/gpu_py_matrix.c b/source/blender/python/intern/gpu_py_matrix.c new file mode 100644 index 00000000000..68b08dfb324 --- /dev/null +++ b/source/blender/python/intern/gpu_py_matrix.c @@ -0,0 +1,552 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/gpu_py_matrix.c + * \ingroup pythonintern + * + * This file defines the gpu.matrix stack API. + * + * \warning While these functions attempt to ensure correct stack usage. + * Mixing Python and C functions may still crash on invalid use. + */ + +#include <Python.h> + + +#include "BLI_utildefines.h" + +#include "../mathutils/mathutils.h" + +#include "../generic/py_capi_utils.h" + +#include "gpu.h" + +#define USE_GPU_PY_MATRIX_API +#include "GPU_matrix.h" +#undef USE_GPU_PY_MATRIX_API + +/* -------------------------------------------------------------------- */ +/** \name Helper Functions + * \{ */ + +static bool pygpu_stack_is_push_model_view_ok_or_error(void) +{ + if (GPU_matrix_stack_level_get_model_view() >= GPU_PY_MATRIX_STACK_LEN) { + PyErr_SetString(PyExc_RuntimeError, + "Maximum model-view stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH) " reached"); + return false; + } + return true; +} + +static bool pygpu_stack_is_push_projection_ok_or_error(void) +{ + if (GPU_matrix_stack_level_get_projection() >= GPU_PY_MATRIX_STACK_LEN) { + PyErr_SetString(PyExc_RuntimeError, + "Maximum projection stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH) " reached"); + return false; + } + return true; +} + +static bool pygpu_stack_is_pop_model_view_ok_or_error(void) +{ + if (GPU_matrix_stack_level_get_model_view() == 0) { + PyErr_SetString(PyExc_RuntimeError, + "Minimum model-view stack depth reached"); + return false; + } + return true; +} + +static bool pygpu_stack_is_pop_projection_ok_or_error(void) +{ + if (GPU_matrix_stack_level_get_projection() == 0) { + PyErr_SetString(PyExc_RuntimeError, + "Minimum projection stack depth reached"); + return false; + } + return true; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Manage Stack + * \{ */ + +PyDoc_STRVAR(pygpu_matrix_push_doc, +"push()\n" +"\n" +" Add to the model-view matrix stack.\n" +); +static PyObject *pygpu_matrix_push(PyObject *UNUSED(self)) +{ + if (!pygpu_stack_is_push_model_view_ok_or_error()) { + return NULL; + } + gpuPushMatrix(); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(pygpu_matrix_pop_doc, +"pop()\n" +"\n" +" Remove the last model-view matrix from the stack.\n" +); +static PyObject *pygpu_matrix_pop(PyObject *UNUSED(self)) +{ + if (!pygpu_stack_is_pop_model_view_ok_or_error()) { + return NULL; + } + gpuPopMatrix(); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(pygpu_matrix_push_projection_doc, +"push_projection()\n" +"\n" +" Add to the projection matrix stack.\n" +); +static PyObject *pygpu_matrix_push_projection(PyObject *UNUSED(self)) +{ + if (!pygpu_stack_is_push_projection_ok_or_error()) { + return NULL; + } + gpuPushProjectionMatrix(); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(pygpu_matrix_pop_projection_doc, +"pop_projection()\n" +"\n" +" Remove the last projection matrix from the stack.\n" +); +static PyObject *pygpu_matrix_pop_projection(PyObject *UNUSED(self)) +{ + if (!pygpu_stack_is_pop_projection_ok_or_error()) { + return NULL; + } + gpuPopProjectionMatrix(); + Py_RETURN_NONE; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Stack (Context Manager) + * + * Safer alternative to ensure balanced push/pop calls. + * + * \{ */ + +typedef struct { + PyObject_HEAD /* required python macro */ + int type; + int level; +} BPy_GPU_MatrixStackContext; + +enum { + PYGPU_MATRIX_TYPE_MODEL_VIEW = 1, + PYGPU_MATRIX_TYPE_PROJECTION = 2, +}; + +static PyObject *pygpu_matrix_stack_context_enter(BPy_GPU_MatrixStackContext *self); +static PyObject *pygpu_matrix_stack_context_exit(BPy_GPU_MatrixStackContext *self, PyObject *args); + +static PyMethodDef pygpu_matrix_stack_context_methods[] = { + {"__enter__", (PyCFunction)pygpu_matrix_stack_context_enter, METH_NOARGS}, + {"__exit__", (PyCFunction)pygpu_matrix_stack_context_exit, METH_VARARGS}, + {NULL} +}; + +static PyTypeObject pygpu_matrix_stack_context_Type = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "GPUMatrixStackContext", + .tp_basicsize = sizeof(BPy_GPU_MatrixStackContext), + .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_methods = pygpu_matrix_stack_context_methods, +}; + +static PyObject *pygpu_matrix_stack_context_enter(BPy_GPU_MatrixStackContext *self) +{ + /* sanity - should never happen */ + if (self->level != -1) { + PyErr_SetString(PyExc_RuntimeError, "Already in use"); + return NULL; + } + + if (self->type == PYGPU_MATRIX_TYPE_MODEL_VIEW) { + if (!pygpu_stack_is_push_model_view_ok_or_error()) { + return NULL; + } + gpuPushMatrix(); + 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(); + self->level = GPU_matrix_stack_level_get_projection(); + } + else { + BLI_assert(0); + } + Py_RETURN_NONE; +} + +static PyObject *pygpu_matrix_stack_context_exit(BPy_GPU_MatrixStackContext *self, PyObject *UNUSED(args)) +{ + /* sanity - should never happen */ + if (self->level == -1) { + fprintf(stderr, "Not yet in use\n"); + goto finally; + } + + if (self->type == PYGPU_MATRIX_TYPE_MODEL_VIEW) { + const int level = GPU_matrix_stack_level_get_model_view(); + if (level != self->level) { + fprintf(stderr, "Level push/pop mismatch, expected %d, got %d\n", self->level, level); + } + if (level != 0) { + gpuPopMatrix(); + } + } + else if (self->type == PYGPU_MATRIX_TYPE_PROJECTION) { + const int level = GPU_matrix_stack_level_get_projection(); + if (level != self->level) { + fprintf(stderr, "Level push/pop mismatch, expected %d, got %d", self->level, level); + } + if (level != 0) { + gpuPopProjectionMatrix(); + } + } + else { + BLI_assert(0); + } +finally: + Py_RETURN_NONE; +} + +static PyObject *pygpu_matrix_push_pop_impl(int type) +{ + BPy_GPU_MatrixStackContext *ret = PyObject_New(BPy_GPU_MatrixStackContext, &pygpu_matrix_stack_context_Type); + ret->type = type; + ret->level = -1; + return (PyObject *)ret; +} + +PyDoc_STRVAR(pygpu_matrix_push_pop_doc, +"push_pop()\n" +"\n" +" Context manager to ensure balanced push/pop calls, even in the case of an error.\n" +); +static PyObject *pygpu_matrix_push_pop(PyObject *UNUSED(self)) +{ + return pygpu_matrix_push_pop_impl(PYGPU_MATRIX_TYPE_MODEL_VIEW); +} + +PyDoc_STRVAR(pygpu_matrix_push_pop_projection_doc, +"push_pop_projection()\n" +"\n" +" Context manager to ensure balanced push/pop calls, even in the case of an error.\n" +); +static PyObject *pygpu_matrix_push_pop_projection(PyObject *UNUSED(self)) +{ + return pygpu_matrix_push_pop_impl(PYGPU_MATRIX_TYPE_PROJECTION); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Manipulate State + * \{ */ + +PyDoc_STRVAR(pygpu_matrix_multiply_matrix_doc, +"multiply_matrix(matrix)\n" +"\n" +" Multiply the current stack matrix.\n" +"\n" +" :param matrix: A 4x4 matrix.\n" +" :type matrix: :class:`mathutils.Matrix`\n" +); +static PyObject *pygpu_matrix_multiply_matrix(PyObject *UNUSED(self), PyObject *value) +{ + MatrixObject *pymat; + if (!Matrix_Parse4x4(value, &pymat)) { + return NULL; + } + gpuMultMatrix(pymat->matrix); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(pygpu_matrix_scale_doc, +"scale(scale)\n" +"\n" +" Scale the current stack matrix.\n" +"\n" +" :param scale: Scale the current stack matrix.\n" +" :type scale: sequence of 2 or 3 floats\n" +); +static PyObject *pygpu_matrix_scale(PyObject *UNUSED(self), PyObject *value) +{ + float scale[3]; + int len; + if ((len = mathutils_array_parse(scale, 2, 3, value, "gpu.matrix.scale(): invalid vector arg")) == -1) { + return NULL; + } + if (len == 2) { + gpuScale2fv(scale); + } + else { + gpuScale3fv(scale); + } + Py_RETURN_NONE; +} + +PyDoc_STRVAR(pygpu_matrix_scale_uniform_doc, +"scale_uniform(scale)\n" +"\n" +" :param scale: Scale the current stack matrix.\n" +" :type scale: sequence of 2 or 3 floats\n" +); +static PyObject *pygpu_matrix_scale_uniform(PyObject *UNUSED(self), PyObject *value) +{ + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { + PyErr_Format(PyExc_TypeError, + "expected a number, not %.200s", + Py_TYPE(value)->tp_name); + return NULL; + } + gpuScaleUniform(scalar); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(pygpu_matrix_translate_doc, +"translate(offset)\n" +"\n" +" Scale the current stack matrix.\n" +"\n" +" :param offset: Translate the current stack matrix.\n" +" :type offset: sequence of 2 or 3 floats\n" +); +static PyObject *pygpu_matrix_translate(PyObject *UNUSED(self), PyObject *value) +{ + float offset[3]; + int len; + if ((len = mathutils_array_parse(offset, 2, 3, value, "gpu.matrix.translate(): invalid vector arg")) == -1) { + return NULL; + } + if (len == 2) { + gpuTranslate2fv(offset); + } + else { + gpuTranslate3fv(offset); + } + Py_RETURN_NONE; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Write State + * \{ */ + +PyDoc_STRVAR(pygpu_matrix_reset_doc, +"reset()\n" +"\n" +" Empty stack and set to identity.\n" +); +static PyObject *pygpu_matrix_reset(PyObject *UNUSED(self)) +{ + gpuMatrixReset(); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(pygpu_matrix_load_identity_doc, +"load_identity()\n" +"\n" +" Empty stack and set to identity.\n" +); +static PyObject *pygpu_matrix_load_identity(PyObject *UNUSED(self)) +{ + gpuLoadIdentity(); + Py_RETURN_NONE; +} + +PyDoc_STRVAR(pygpu_matrix_load_matrix_doc, +"load_matrix(matrix)\n" +"\n" +" Load a matrix into the stack.\n" +"\n" +" :param matrix: A 4x4 matrix.\n" +" :type matrix: :class:`mathutils.Matrix`\n" +); +static PyObject *pygpu_matrix_load_matrix(PyObject *UNUSED(self), PyObject *value) +{ + MatrixObject *pymat; + if (!Matrix_Parse4x4(value, &pymat)) { + return NULL; + } + gpuLoadMatrix(pymat->matrix); + Py_RETURN_NONE; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Read State + * \{ */ + +PyDoc_STRVAR(pygpu_matrix_get_projection_matrix_doc, +"get_projection_matrix()\n" +"\n" +" Return a copy of the projection matrix.\n" +"\n" +" :return: A 4x4 projection matrix.\n" +" :rtype: :class:`mathutils.Matrix`\n" +); +static PyObject *pygpu_matrix_get_projection_matrix(PyObject *UNUSED(self)) +{ + float matrix[4][4]; + gpuGetModelViewMatrix(matrix); + return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL); +} + + +PyDoc_STRVAR(pygpu_matrix_get_modal_view_matrix_doc, +"get_view_matrix()\n" +"\n" +" Return a copy of the view matrix.\n" +"\n" +" :return: A 4x4 view matrix.\n" +" :rtype: :class:`mathutils.Matrix`\n" +); +static PyObject *pygpu_matrix_get_modal_view_matrix(PyObject *UNUSED(self)) +{ + float matrix[4][4]; + gpuGetProjectionMatrix(matrix); + return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL); +} + +PyDoc_STRVAR(pygpu_matrix_get_normal_matrix_doc, +"get_normal_matrix()\n" +"\n" +" Return a copy of the normal matrix.\n" +"\n" +" :return: A 3x3 normal matrix.\n" +" :rtype: :class:`mathutils.Matrix`\n" +); +static PyObject *pygpu_matrix_get_normal_matrix(PyObject *UNUSED(self)) +{ + float matrix[3][3]; + gpuGetNormalMatrix(matrix); + return Matrix_CreatePyObject(&matrix[0][0], 3, 3, NULL); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Module + * \{ */ + +static struct PyMethodDef BPy_GPU_matrix_methods[] = { + /* Manage Stack */ + {"push", (PyCFunction)pygpu_matrix_push, + METH_NOARGS, pygpu_matrix_push_doc}, + {"pop", (PyCFunction)pygpu_matrix_pop, + METH_NOARGS, pygpu_matrix_pop_doc}, + + {"push_projection", (PyCFunction)pygpu_matrix_push_projection, + METH_NOARGS, pygpu_matrix_push_projection_doc}, + {"pop_projection", (PyCFunction)pygpu_matrix_pop_projection, + METH_NOARGS, pygpu_matrix_pop_projection_doc}, + + /* Stack (Context Manager) */ + {"push_pop", (PyCFunction)pygpu_matrix_push_pop, + METH_NOARGS, pygpu_matrix_push_pop_doc}, + {"push_pop_projection", (PyCFunction)pygpu_matrix_push_pop_projection, + METH_NOARGS, pygpu_matrix_push_pop_projection_doc}, + + /* Manipulate State */ + {"multiply_matrix", (PyCFunction)pygpu_matrix_multiply_matrix, + METH_O, pygpu_matrix_multiply_matrix_doc}, + {"scale", (PyCFunction)pygpu_matrix_scale, + METH_O, pygpu_matrix_scale_doc}, + {"scale_uniform", (PyCFunction)pygpu_matrix_scale_uniform, + METH_O, pygpu_matrix_scale_uniform_doc}, + {"translate", (PyCFunction)pygpu_matrix_translate, + METH_O, pygpu_matrix_translate_doc}, + + /* TODO */ +#if 0 + {"rotate", (PyCFunction)pygpu_matrix_rotate, + METH_O, pygpu_matrix_rotate_doc}, + {"rotate_axis", (PyCFunction)pygpu_matrix_rotate_axis, + METH_O, pygpu_matrix_rotate_axis_doc}, + {"look_at", (PyCFunction)pygpu_matrix_look_at, + METH_O, pygpu_matrix_look_at_doc}, +#endif + + /* Write State */ + {"reset", (PyCFunction)pygpu_matrix_reset, + METH_NOARGS, pygpu_matrix_reset_doc}, + {"load_identity", (PyCFunction)pygpu_matrix_load_identity, + METH_NOARGS, pygpu_matrix_load_identity_doc}, + {"load_matrix", (PyCFunction)pygpu_matrix_load_matrix, + METH_O, pygpu_matrix_load_matrix_doc}, + + /* Read State */ + {"get_projection_matrix", (PyCFunction)pygpu_matrix_get_projection_matrix, + METH_NOARGS, pygpu_matrix_get_projection_matrix_doc}, + {"get_model_view_matrix", (PyCFunction)pygpu_matrix_get_modal_view_matrix, + METH_NOARGS, pygpu_matrix_get_modal_view_matrix_doc}, + {"get_normal_matrix", (PyCFunction)pygpu_matrix_get_normal_matrix, + METH_NOARGS, pygpu_matrix_get_normal_matrix_doc}, + + {NULL, NULL, 0, NULL} +}; + +PyDoc_STRVAR(BPy_GPU_matrix_doc, +"This module provides access to the matrix stack." +); +static PyModuleDef BPy_GPU_matrix_module_def = { + PyModuleDef_HEAD_INIT, + .m_name = "gpu.matrix", + .m_doc = BPy_GPU_matrix_doc, + .m_methods = BPy_GPU_matrix_methods, +}; + +PyObject *BPyInit_gpu_matrix(void) +{ + PyObject *submodule; + + submodule = PyModule_Create(&BPy_GPU_matrix_module_def); + + if (PyType_Ready(&pygpu_matrix_stack_context_Type) < 0) { + return NULL; + } + + return submodule; +} + +/** \} */ diff --git a/source/blender/python/intern/gpu_py_select.c b/source/blender/python/intern/gpu_py_select.c new file mode 100644 index 00000000000..f570c4cdae2 --- /dev/null +++ b/source/blender/python/intern/gpu_py_select.c @@ -0,0 +1,92 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/gpu_py_select.c + * \ingroup pythonintern + * + * This file defines the gpu.select API. + * + * \note Currently only used for manipulator selection, + * will need to add begin/end and a way to access the hits. + */ + +#include <Python.h> + +#include "BLI_utildefines.h" + +#include "../generic/py_capi_utils.h" + +#include "gpu.h" + +#include "GPU_select.h" + +/* -------------------------------------------------------------------- */ +/** \name Methods + * \{ */ + +PyDoc_STRVAR(pygpu_select_load_id_doc, +"load_id(id)\n" +"\n" +" Set the selection ID.\n" +"\n" +" :param id: Number (32-bit unsigned int).\n" +" :type select: int\n" +); +static PyObject *pygpu_select_load_id(PyObject *UNUSED(self), PyObject *value) +{ + uint id; + if ((id = PyC_Long_AsU32(value)) == (uint)-1) { + return NULL; + } + GPU_select_load_id(id); + Py_RETURN_NONE; +} +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Module + * \{ */ + +static struct PyMethodDef BPy_GPU_select_methods[] = { + /* Manage Stack */ + {"load_id", (PyCFunction)pygpu_select_load_id, METH_O, pygpu_select_load_id_doc}, + {NULL, NULL, 0, NULL} +}; + +PyDoc_STRVAR(BPy_GPU_select_doc, +"This module provides access to selection." +); +static PyModuleDef BPy_GPU_select_module_def = { + PyModuleDef_HEAD_INIT, + .m_name = "gpu.select", + .m_doc = BPy_GPU_select_doc, + .m_methods = BPy_GPU_select_methods, +}; + +PyObject *BPyInit_gpu_select(void) +{ + PyObject *submodule; + + submodule = PyModule_Create(&BPy_GPU_select_module_def); + + return submodule; +} + +/** \} */ diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c index c044cc54965..88195700a50 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.c +++ b/source/blender/python/mathutils/mathutils_bvhtree.c @@ -1049,6 +1049,8 @@ static DerivedMesh *bvh_get_derived_mesh( const char *funcname, struct Scene *scene, Object *ob, bool use_deform, bool use_render, bool use_cage) { + /* TODO: This doesn't work currently because of eval_ctx. */ +#if 0 /* we only need minimum mesh data for topology and vertex locations */ CustomDataMask mask = CD_MASK_BAREMESH; @@ -1096,6 +1098,11 @@ static DerivedMesh *bvh_get_derived_mesh( } } } +#else + UNUSED_VARS(funcname, scene, ob, use_deform, use_render, use_cage); +#endif + + return NULL; } PyDoc_STRVAR(C_BVHTree_FromObject_doc, |