Blender V5.0
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
17
18#ifdef WITH_OPENVDB
19# include "openvdb_capi.h"
20#endif
21
22static PyTypeObject BlenderAppOVDBType;
23
24static 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
31static 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
38static 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));
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));
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
83{
84 PyObject *ret;
85
86 PyStructSequence_InitType(&BlenderAppOVDBType, &app_openvdb_info_desc);
87
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}
#define ARRAY_SIZE(arr)
#define UNLIKELY(x)
static PyStructSequence_Desc app_openvdb_info_desc
PyObject * BPY_app_openvdb_struct()
static PyObject * make_openvdb_info()
static PyTypeObject BlenderAppOVDBType
#define SetStrItem(str)
static PyStructSequence_Field app_openvdb_info_fields[]
#define SetObjItem(obj)
uint pos
int OpenVDB_getVersionHex()
PyObject * PyC_Tuple_Pack_I32(const blender::Span< int > values)
header-only compatibility defines.
#define Py_HashPointer
Py_DECREF(oname)
return ret