2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2017-06-07 12:16:48 +02:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup pythonintern
|
2017-06-07 12:16:48 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <Python.h>
|
2017-06-07 12:16:48 +02:00
|
|
|
|
2024-09-24 12:05:13 +02:00
|
|
|
#include "bpy_app_opensubdiv.hh"
|
2017-06-07 12:16:48 +02:00
|
|
|
|
2024-09-24 15:25:36 +02:00
|
|
|
#include "../generic/py_capi_utils.hh"
|
2017-08-22 18:02:58 +10:00
|
|
|
|
2017-06-07 12:16:48 +02:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
2023-12-10 20:18:40 -05:00
|
|
|
# include "opensubdiv_capi.hh"
|
2017-06-07 12:16:48 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static PyTypeObject BlenderAppOpenSubdivType;
|
|
|
|
|
|
|
|
|
|
static PyStructSequence_Field app_opensubdiv_info_fields[] = {
|
2019-12-20 10:42:57 +11:00
|
|
|
{"supported", "Boolean, True when Blender is built with OpenSubdiv support"},
|
|
|
|
|
{"version", "The OpenSubdiv version as a tuple of 3 numbers"},
|
|
|
|
|
{"version_string", "The OpenSubdiv version formatted as a string"},
|
2023-07-21 02:18:59 +02:00
|
|
|
{nullptr},
|
2017-06-07 12:16:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static PyStructSequence_Desc app_opensubdiv_info_desc = {
|
2024-08-19 11:37:20 +10:00
|
|
|
/*name*/ "bpy.app.opensubdiv",
|
|
|
|
|
/*doc*/ "This module contains information about OpenSubdiv blender is linked against",
|
|
|
|
|
/*fields*/ app_opensubdiv_info_fields,
|
|
|
|
|
/*n_in_sequence*/ ARRAY_SIZE(app_opensubdiv_info_fields) - 1,
|
2017-06-07 12:16:48 +02:00
|
|
|
};
|
|
|
|
|
|
2023-07-21 10:59:54 +10:00
|
|
|
static PyObject *make_opensubdiv_info()
|
2017-06-07 12:16:48 +02:00
|
|
|
{
|
|
|
|
|
PyObject *opensubdiv_info;
|
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
|
|
opensubdiv_info = PyStructSequence_New(&BlenderAppOpenSubdivType);
|
2023-07-21 02:18:59 +02:00
|
|
|
if (opensubdiv_info == nullptr) {
|
|
|
|
|
return nullptr;
|
2017-06-07 12:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef WITH_OPENSUBDIV
|
|
|
|
|
# define SetStrItem(str) \
|
|
|
|
|
PyStructSequence_SET_ITEM(opensubdiv_info, pos++, PyUnicode_FromString(str))
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define SetObjItem(obj) PyStructSequence_SET_ITEM(opensubdiv_info, pos++, obj)
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_OPENSUBDIV
|
2020-08-20 16:10:13 +10:00
|
|
|
const int curversion = openSubdiv_getVersionHex();
|
2017-06-07 12:16:48 +02:00
|
|
|
SetObjItem(PyBool_FromLong(1));
|
2023-07-21 02:18:59 +02:00
|
|
|
SetObjItem(PyC_Tuple_Pack_I32({curversion / 10000, (curversion / 100) % 100, curversion % 100}));
|
2017-06-07 12:16:48 +02:00
|
|
|
SetObjItem(PyUnicode_FromFormat(
|
|
|
|
|
"%2d, %2d, %2d", curversion / 10000, (curversion / 100) % 100, curversion % 100));
|
|
|
|
|
#else
|
|
|
|
|
SetObjItem(PyBool_FromLong(0));
|
2023-07-21 10:53:30 +10:00
|
|
|
SetObjItem(PyC_Tuple_Pack_I32({0, 0, 0}));
|
2017-06-07 12:16:48 +02:00
|
|
|
SetStrItem("Unknown");
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-03-04 15:46:07 +11:00
|
|
|
if (UNLIKELY(PyErr_Occurred())) {
|
|
|
|
|
Py_DECREF(opensubdiv_info);
|
2023-07-21 02:18:59 +02:00
|
|
|
return nullptr;
|
2017-06-07 12:16:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef SetStrItem
|
|
|
|
|
#undef SetObjItem
|
|
|
|
|
|
|
|
|
|
return opensubdiv_info;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 10:59:54 +10:00
|
|
|
PyObject *BPY_app_opensubdiv_struct()
|
2017-06-07 12:16:48 +02:00
|
|
|
{
|
|
|
|
|
PyObject *ret;
|
|
|
|
|
|
|
|
|
|
PyStructSequence_InitType(&BlenderAppOpenSubdivType, &app_opensubdiv_info_desc);
|
|
|
|
|
|
|
|
|
|
ret = make_opensubdiv_info();
|
|
|
|
|
|
|
|
|
|
/* prevent user from creating new instances */
|
2023-07-21 02:18:59 +02:00
|
|
|
BlenderAppOpenSubdivType.tp_init = nullptr;
|
|
|
|
|
BlenderAppOpenSubdivType.tp_new = nullptr;
|
2023-05-24 11:21:18 +10:00
|
|
|
/* Without this we can't do `set(sys.modules)` #29635. */
|
2017-06-07 12:16:48 +02:00
|
|
|
BlenderAppOpenSubdivType.tp_hash = (hashfunc)_Py_HashPointer;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|