Blender
V5.0
source
blender
python
intern
bpy_app_openvdb.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2015 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_openvdb.hh
"
15
16
#include "
../generic/py_capi_utils.hh
"
17
18
#ifdef WITH_OPENVDB
19
# include "
openvdb_capi.h
"
20
#endif
21
22
static
PyTypeObject
BlenderAppOVDBType
;
23
24
static
PyStructSequence_Field
app_openvdb_info_fields
[] = {
25
{
"supported"
,
"Boolean, True when Blender is built with OpenVDB support"
},
26
{
"version"
,
"The OpenVDB version as a tuple of 3 numbers"
},
27
{
"version_string"
,
"The OpenVDB version formatted as a string"
},
28
{
nullptr
},
29
};
30
31
static
PyStructSequence_Desc
app_openvdb_info_desc
= {
32
/*name*/
"bpy.app.openvdb"
,
33
/*doc*/
"This module contains information about OpenVDB blender is linked against"
,
34
/*fields*/
app_openvdb_info_fields
,
35
/*n_in_sequence*/
ARRAY_SIZE
(
app_openvdb_info_fields
) - 1,
36
};
37
38
static
PyObject *
make_openvdb_info
()
39
{
40
PyObject *openvdb_info;
41
int
pos
= 0;
42
43
#ifdef WITH_OPENVDB
44
int
curversion;
45
#endif
46
47
openvdb_info = PyStructSequence_New(&
BlenderAppOVDBType
);
48
if
(openvdb_info ==
nullptr
) {
49
return
nullptr
;
50
}
51
52
#ifndef WITH_OPENVDB
53
# define SetStrItem(str) PyStructSequence_SET_ITEM(openvdb_info, pos++, PyUnicode_FromString(str))
54
#endif
55
56
#define SetObjItem(obj) PyStructSequence_SET_ITEM(openvdb_info, pos++, obj)
57
58
#ifdef WITH_OPENVDB
59
curversion =
OpenVDB_getVersionHex
();
60
SetObjItem
(PyBool_FromLong(1));
61
SetObjItem
(
62
PyC_Tuple_Pack_I32
({curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256}));
63
SetObjItem
(PyUnicode_FromFormat(
64
"%2d, %2d, %2d"
, curversion >> 24, (curversion >> 16) % 256, (curversion >> 8) % 256));
65
#else
66
SetObjItem
(PyBool_FromLong(0));
67
SetObjItem
(
PyC_Tuple_Pack_I32
({0, 0, 0}));
68
SetStrItem
(
"Unknown"
);
69
#endif
70
71
if
(
UNLIKELY
(PyErr_Occurred())) {
72
Py_DECREF
(openvdb_info);
73
return
nullptr
;
74
}
75
76
#undef SetStrItem
77
#undef SetObjItem
78
79
return
openvdb_info;
80
}
81
82
PyObject *
BPY_app_openvdb_struct
()
83
{
84
PyObject *
ret
;
85
86
PyStructSequence_InitType(&
BlenderAppOVDBType
, &
app_openvdb_info_desc
);
87
88
ret
=
make_openvdb_info
();
89
90
/* prevent user from creating new instances */
91
BlenderAppOVDBType
.tp_init =
nullptr
;
92
BlenderAppOVDBType
.tp_new =
nullptr
;
93
/* Without this we can't do `set(sys.modules)` #29635. */
94
BlenderAppOVDBType
.tp_hash = (hashfunc)
Py_HashPointer
;
95
96
return
ret
;
97
}
BLI_utildefines.h
ARRAY_SIZE
#define ARRAY_SIZE(arr)
Definition
BLI_utildefines.h:271
UNLIKELY
#define UNLIKELY(x)
Definition
BLI_utildefines.h:526
app_openvdb_info_desc
static PyStructSequence_Desc app_openvdb_info_desc
Definition
bpy_app_openvdb.cc:31
BPY_app_openvdb_struct
PyObject * BPY_app_openvdb_struct()
Definition
bpy_app_openvdb.cc:82
make_openvdb_info
static PyObject * make_openvdb_info()
Definition
bpy_app_openvdb.cc:38
BlenderAppOVDBType
static PyTypeObject BlenderAppOVDBType
Definition
bpy_app_openvdb.cc:22
SetStrItem
#define SetStrItem(str)
app_openvdb_info_fields
static PyStructSequence_Field app_openvdb_info_fields[]
Definition
bpy_app_openvdb.cc:24
SetObjItem
#define SetObjItem(obj)
bpy_app_openvdb.hh
pos
uint pos
Definition
gpu_batch_presets.cc:36
OpenVDB_getVersionHex
int OpenVDB_getVersionHex()
Definition
openvdb_capi.cc:8
openvdb_capi.h
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