GPU: Add gpu.platform.backend_type_get function.

Function returns the active GPU backend type.
This commit is contained in:
2022-10-21 14:38:30 +02:00
parent 3225bc2e7f
commit e8c4411035

View File

@@ -11,6 +11,7 @@
#include "BLI_utildefines.h"
#include "GPU_context.h"
#include "GPU_platform.h"
#include "gpu_py_platform.h" /* Own include. */
@@ -83,6 +84,28 @@ static PyObject *pygpu_platform_device_type_get(PyObject *UNUSED(self))
return PyUnicode_FromString("UNKNOWN");
}
PyDoc_STRVAR(pygpu_platform_backend_type_get_doc,
".. function:: backend_type_get()\n"
"\n"
" Get actuve GPU backend.\n"
"\n"
" :return: Backend type ('OPENGL', 'METAL', 'NONE', 'UNKNOWN').\n"
" :rtype: str\n");
static PyObject *pygpu_platform_backend_type_get(PyObject *UNUSED(self))
{
switch (GPU_backend_get_type()) {
case GPU_BACKEND_METAL:
return PyUnicode_FromString("METAL");
case GPU_BACKEND_NONE:
return PyUnicode_FromString("NONE");
case GPU_BACKEND_OPENGL:
return PyUnicode_FromString("OPENGL");
case GPU_BACKEND_ANY:
break;
}
return PyUnicode_FromString("UNKNOWN");
}
/** \} */
/* -------------------------------------------------------------------- */
@@ -106,6 +129,10 @@ static struct PyMethodDef pygpu_platform__tp_methods[] = {
(PyCFunction)pygpu_platform_device_type_get,
METH_NOARGS,
pygpu_platform_device_type_get_doc},
{"backend_type_get",
(PyCFunction)pygpu_platform_backend_type_get,
METH_NOARGS,
pygpu_platform_backend_type_get_doc},
{NULL, NULL, 0, NULL},
};