1 /* SPDX-FileCopyrightText: 2023 Blender Authors
3 * SPDX-License-Identifier: GPL-2.0-or-later */
6 * \ingroup pythonintern
9 #include "BLI_utildefines.h"
12 #include "bpy_app_opensubdiv.hh"
14 #include "../generic/py_capi_utils.hh"
16 #ifdef WITH_OPENSUBDIV
17 # include "opensubdiv_capi.hh"
20 static PyTypeObject BlenderAppOpenSubdivType
;
22 static PyStructSequence_Field app_opensubdiv_info_fields
[] = {
23 {"supported", "Boolean, True when Blender is built with OpenSubdiv support"},
24 {"version", "The OpenSubdiv version as a tuple of 3 numbers"},
25 {"version_string", "The OpenSubdiv version formatted as a string"},
29 static PyStructSequence_Desc app_opensubdiv_info_desc
= {
30 /*name*/ "bpy.app.opensubdiv",
31 /*doc*/ "This module contains information about OpenSubdiv blender is linked against",
32 /*fields*/ app_opensubdiv_info_fields
,
33 /*n_in_sequence*/ ARRAY_SIZE(app_opensubdiv_info_fields
) - 1,
36 static PyObject
*make_opensubdiv_info()
38 PyObject
*opensubdiv_info
;
41 opensubdiv_info
= PyStructSequence_New(&BlenderAppOpenSubdivType
);
42 if (opensubdiv_info
== nullptr) {
46 #ifndef WITH_OPENSUBDIV
47 # define SetStrItem(str) \
48 PyStructSequence_SET_ITEM(opensubdiv_info, pos++, PyUnicode_FromString(str))
51 #define SetObjItem(obj) PyStructSequence_SET_ITEM(opensubdiv_info, pos++, obj)
53 #ifdef WITH_OPENSUBDIV
54 const int curversion
= openSubdiv_getVersionHex();
55 SetObjItem(PyBool_FromLong(1));
56 SetObjItem(PyC_Tuple_Pack_I32({curversion
/ 10000, (curversion
/ 100) % 100, curversion
% 100}));
57 SetObjItem(PyUnicode_FromFormat(
58 "%2d, %2d, %2d", curversion
/ 10000, (curversion
/ 100) % 100, curversion
% 100));
60 SetObjItem(PyBool_FromLong(0));
61 SetObjItem(PyC_Tuple_Pack_I32({0, 0, 0}));
62 SetStrItem("Unknown");
65 if (UNLIKELY(PyErr_Occurred())) {
66 Py_DECREF(opensubdiv_info
);
73 return opensubdiv_info
;
76 PyObject
*BPY_app_opensubdiv_struct()
80 PyStructSequence_InitType(&BlenderAppOpenSubdivType
, &app_opensubdiv_info_desc
);
82 ret
= make_opensubdiv_info();
84 /* prevent user from creating new instances */
85 BlenderAppOpenSubdivType
.tp_init
= nullptr;
86 BlenderAppOpenSubdivType
.tp_new
= nullptr;
87 /* Without this we can't do `set(sys.modules)` #29635. */
88 BlenderAppOpenSubdivType
.tp_hash
= (hashfunc
)_Py_HashPointer
;