Blender
V5.0
source
blender
python
intern
bpy_app_opensubdiv.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9
#include "
BLI_utildefines.h
"
10
#include <Python.h>
11
12
#include "
../generic/python_compat.hh
"
/* IWYU pragma: keep. */
13
14
#include "
bpy_app_opensubdiv.hh
"
15
16
#include "
../generic/py_capi_utils.hh
"
17
18
#ifdef WITH_OPENSUBDIV
19
# include "
opensubdiv_capi.hh
"
20
#endif
21
22
static
PyTypeObject
BlenderAppOpenSubdivType
;
23
24
static
PyStructSequence_Field
app_opensubdiv_info_fields
[] = {
25
{
"supported"
,
"Boolean, True when Blender is built with OpenSubdiv support"
},
26
{
"version"
,
"The OpenSubdiv version as a tuple of 3 numbers"
},
27
{
"version_string"
,
"The OpenSubdiv version formatted as a string"
},
28
{
nullptr
},
29
};
30
31
static
PyStructSequence_Desc
app_opensubdiv_info_desc
= {
32
/*name*/
"bpy.app.opensubdiv"
,
33
/*doc*/
"This module contains information about OpenSubdiv blender is linked against"
,
34
/*fields*/
app_opensubdiv_info_fields
,
35
/*n_in_sequence*/
ARRAY_SIZE
(
app_opensubdiv_info_fields
) - 1,
36
};
37
38
static
PyObject *
make_opensubdiv_info
()
39
{
40
PyObject *opensubdiv_info;
41
int
pos
= 0;
42
43
opensubdiv_info = PyStructSequence_New(&
BlenderAppOpenSubdivType
);
44
if
(opensubdiv_info ==
nullptr
) {
45
return
nullptr
;
46
}
47
48
#ifndef WITH_OPENSUBDIV
49
# define SetStrItem(str) \
50
PyStructSequence_SET_ITEM(opensubdiv_info, pos++, PyUnicode_FromString(str))
51
#endif
52
53
#define SetObjItem(obj) PyStructSequence_SET_ITEM(opensubdiv_info, pos++, obj)
54
55
#ifdef WITH_OPENSUBDIV
56
const
int
curversion =
openSubdiv_getVersionHex
();
57
SetObjItem
(PyBool_FromLong(1));
58
SetObjItem
(
PyC_Tuple_Pack_I32
({curversion / 10000, (curversion / 100) % 100, curversion % 100}));
59
SetObjItem
(PyUnicode_FromFormat(
60
"%2d, %2d, %2d"
, curversion / 10000, (curversion / 100) % 100, curversion % 100));
61
#else
62
SetObjItem
(PyBool_FromLong(0));
63
SetObjItem
(
PyC_Tuple_Pack_I32
({0, 0, 0}));
64
SetStrItem
(
"Unknown"
);
65
#endif
66
67
if
(
UNLIKELY
(PyErr_Occurred())) {
68
Py_DECREF
(opensubdiv_info);
69
return
nullptr
;
70
}
71
72
#undef SetStrItem
73
#undef SetObjItem
74
75
return
opensubdiv_info;
76
}
77
78
PyObject *
BPY_app_opensubdiv_struct
()
79
{
80
PyObject *
ret
;
81
82
PyStructSequence_InitType(&
BlenderAppOpenSubdivType
, &
app_opensubdiv_info_desc
);
83
84
ret
=
make_opensubdiv_info
();
85
86
/* prevent user from creating new instances */
87
BlenderAppOpenSubdivType
.tp_init =
nullptr
;
88
BlenderAppOpenSubdivType
.tp_new =
nullptr
;
89
/* Without this we can't do `set(sys.modules)` #29635. */
90
BlenderAppOpenSubdivType
.tp_hash = (hashfunc)
Py_HashPointer
;
91
92
return
ret
;
93
}
BLI_utildefines.h
ARRAY_SIZE
#define ARRAY_SIZE(arr)
Definition
BLI_utildefines.h:271
UNLIKELY
#define UNLIKELY(x)
Definition
BLI_utildefines.h:526
make_opensubdiv_info
static PyObject * make_opensubdiv_info()
Definition
bpy_app_opensubdiv.cc:38
app_opensubdiv_info_fields
static PyStructSequence_Field app_opensubdiv_info_fields[]
Definition
bpy_app_opensubdiv.cc:24
BPY_app_opensubdiv_struct
PyObject * BPY_app_opensubdiv_struct()
Definition
bpy_app_opensubdiv.cc:78
app_opensubdiv_info_desc
static PyStructSequence_Desc app_opensubdiv_info_desc
Definition
bpy_app_opensubdiv.cc:31
BlenderAppOpenSubdivType
static PyTypeObject BlenderAppOpenSubdivType
Definition
bpy_app_opensubdiv.cc:22
SetStrItem
#define SetStrItem(str)
SetObjItem
#define SetObjItem(obj)
bpy_app_opensubdiv.hh
pos
uint pos
Definition
gpu_batch_presets.cc:36
openSubdiv_getVersionHex
int openSubdiv_getVersionHex()
Definition
opensubdiv_capi.cc:15
opensubdiv_capi.hh
py_capi_utils.hh
PyC_Tuple_Pack_I32
PyObject * PyC_Tuple_Pack_I32(const blender::Span< int > values)
Definition
py_capi_utils.hh:391
python_compat.hh
header-only compatibility defines.
Py_HashPointer
#define Py_HashPointer
Definition
python_compat.hh:49
Py_DECREF
Py_DECREF(oname)
ret
return ret
Definition
python_utildefines.hh:33
Generated on
for Blender by
doxygen
1.16.1