2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer #"__init__", "to_list"
gpu.types.GPUTexture #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__", "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf #"__init__", "update"
gpu.state #"blend_set", "blend_get", "depth_test_set", "depth_test_get", "depth_mask_set", "depth_mask_get", "viewport_set", "viewport_get", "line_width_set", "line_width_get", "point_size_set", "color_mask_set", "face_culling_set", "front_facing_set", "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
2021-02-17 10:48:08 -03:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup bpygpu
|
|
|
|
|
*
|
2021-07-20 22:52:31 +10:00
|
|
|
* - Use `bpygpu_` for local API.
|
|
|
|
|
* - Use `BPyGPU` for public API.
|
Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer #"__init__", "to_list"
gpu.types.GPUTexture #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__", "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf #"__init__", "update"
gpu.state #"blend_set", "blend_get", "depth_test_set", "depth_test_get", "depth_mask_set", "depth_mask_get", "viewport_set", "viewport_get", "line_width_set", "line_width_get", "point_size_set", "color_mask_set", "face_culling_set", "front_facing_set", "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
2021-02-17 10:48:08 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
2021-02-22 09:44:57 -03:00
|
|
|
#include "GPU_init_exit.h"
|
2021-02-22 08:26:45 -03:00
|
|
|
#include "GPU_primitive.h"
|
Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer #"__init__", "to_list"
gpu.types.GPUTexture #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__", "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf #"__init__", "update"
gpu.state #"blend_set", "blend_get", "depth_test_set", "depth_test_get", "depth_mask_set", "depth_mask_get", "viewport_set", "viewport_get", "line_width_set", "line_width_get", "point_size_set", "color_mask_set", "face_culling_set", "front_facing_set", "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
2021-02-17 10:48:08 -03:00
|
|
|
#include "GPU_texture.h"
|
|
|
|
|
|
|
|
|
|
#include "../generic/py_capi_utils.h"
|
|
|
|
|
|
|
|
|
|
#include "gpu_py.h" /* own include */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
2021-02-22 08:26:45 -03:00
|
|
|
/** \name GPU Enums
|
Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer #"__init__", "to_list"
gpu.types.GPUTexture #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__", "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf #"__init__", "update"
gpu.state #"blend_set", "blend_get", "depth_test_set", "depth_test_get", "depth_mask_set", "depth_mask_get", "viewport_set", "viewport_get", "line_width_set", "line_width_get", "point_size_set", "color_mask_set", "face_culling_set", "front_facing_set", "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
2021-02-17 10:48:08 -03:00
|
|
|
* \{ */
|
|
|
|
|
|
2021-02-22 08:26:45 -03:00
|
|
|
struct PyC_StringEnumItems bpygpu_primtype_items[] = {
|
|
|
|
|
{GPU_PRIM_POINTS, "POINTS"},
|
|
|
|
|
{GPU_PRIM_LINES, "LINES"},
|
|
|
|
|
{GPU_PRIM_TRIS, "TRIS"},
|
|
|
|
|
{GPU_PRIM_LINE_STRIP, "LINE_STRIP"},
|
|
|
|
|
{GPU_PRIM_LINE_LOOP, "LINE_LOOP"},
|
|
|
|
|
{GPU_PRIM_TRI_STRIP, "TRI_STRIP"},
|
|
|
|
|
{GPU_PRIM_TRI_FAN, "TRI_FAN"},
|
|
|
|
|
{GPU_PRIM_LINES_ADJ, "LINES_ADJ"},
|
|
|
|
|
{GPU_PRIM_TRIS_ADJ, "TRIS_ADJ"},
|
|
|
|
|
{GPU_PRIM_LINE_STRIP_ADJ, "LINE_STRIP_ADJ"},
|
|
|
|
|
{0, NULL},
|
|
|
|
|
};
|
|
|
|
|
|
Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer #"__init__", "to_list"
gpu.types.GPUTexture #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__", "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf #"__init__", "update"
gpu.state #"blend_set", "blend_get", "depth_test_set", "depth_test_get", "depth_mask_set", "depth_mask_get", "viewport_set", "viewport_get", "line_width_set", "line_width_get", "point_size_set", "color_mask_set", "face_culling_set", "front_facing_set", "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
2021-02-17 10:48:08 -03:00
|
|
|
struct PyC_StringEnumItems bpygpu_dataformat_items[] = {
|
|
|
|
|
{GPU_DATA_FLOAT, "FLOAT"},
|
|
|
|
|
{GPU_DATA_INT, "INT"},
|
2021-02-17 12:38:21 -03:00
|
|
|
{GPU_DATA_UINT, "UINT"},
|
|
|
|
|
{GPU_DATA_UBYTE, "UBYTE"},
|
|
|
|
|
{GPU_DATA_UINT_24_8, "UINT_24_8"},
|
Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer #"__init__", "to_list"
gpu.types.GPUTexture #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__", "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf #"__init__", "update"
gpu.state #"blend_set", "blend_get", "depth_test_set", "depth_test_get", "depth_mask_set", "depth_mask_get", "viewport_set", "viewport_get", "line_width_set", "line_width_get", "point_size_set", "color_mask_set", "face_culling_set", "front_facing_set", "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
2021-02-17 10:48:08 -03:00
|
|
|
{GPU_DATA_10_11_11_REV, "10_11_11_REV"},
|
|
|
|
|
{0, NULL},
|
|
|
|
|
};
|
2021-12-14 15:49:31 +11:00
|
|
|
|
Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer #"__init__", "to_list"
gpu.types.GPUTexture #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__", "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf #"__init__", "update"
gpu.state #"blend_set", "blend_get", "depth_test_set", "depth_test_get", "depth_mask_set", "depth_mask_get", "viewport_set", "viewport_get", "line_width_set", "line_width_get", "point_size_set", "color_mask_set", "face_culling_set", "front_facing_set", "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
2021-02-17 10:48:08 -03:00
|
|
|
/** \} */
|
2021-02-22 09:44:57 -03:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Utilities
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2022-11-29 13:55:37 -03:00
|
|
|
static const char g_error[] = "GPU API is not available in background mode";
|
|
|
|
|
|
|
|
|
|
static PyObject *py_error__ml_meth(PyObject *UNUSED(self), PyObject *UNUSED(args))
|
2021-02-22 09:44:57 -03:00
|
|
|
{
|
2022-11-29 13:55:37 -03:00
|
|
|
PyErr_SetString(PyExc_SystemError, g_error);
|
2022-11-29 13:59:52 -03:00
|
|
|
return NULL;
|
2022-11-29 13:55:37 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *py_error__getter(PyObject *UNUSED(self), void *UNUSED(type))
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString(PyExc_SystemError, g_error);
|
2022-11-29 13:59:52 -03:00
|
|
|
return NULL;
|
2022-11-29 13:55:37 -03:00
|
|
|
}
|
|
|
|
|
|
2022-11-29 18:46:59 +01:00
|
|
|
static int py_error__setter(PyObject *UNUSED(self), PyObject *UNUSED(value), void *UNUSED(type))
|
2022-11-29 13:55:37 -03:00
|
|
|
{
|
|
|
|
|
PyErr_SetString(PyExc_SystemError, g_error);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static PyObject *py_error__tp_new(PyTypeObject *UNUSED(type),
|
|
|
|
|
PyObject *UNUSED(args),
|
|
|
|
|
PyObject *UNUSED(kwds))
|
|
|
|
|
{
|
|
|
|
|
PyErr_SetString(PyExc_SystemError, g_error);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyObject *bpygpu_create_module(PyModuleDef *module_type)
|
|
|
|
|
{
|
|
|
|
|
if (!GPU_is_init() && module_type->m_methods) {
|
|
|
|
|
/* Replace all methods with an error method.
|
|
|
|
|
* That way when the method is called, an error will appear instead. */
|
|
|
|
|
for (PyMethodDef *meth = module_type->m_methods; meth->ml_name; meth++) {
|
|
|
|
|
meth->ml_meth = py_error__ml_meth;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-22 09:44:57 -03:00
|
|
|
|
2022-11-29 13:55:37 -03:00
|
|
|
PyObject *module = PyModule_Create(module_type);
|
|
|
|
|
|
|
|
|
|
return module;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int bpygpu_finalize_type(PyTypeObject *py_type)
|
|
|
|
|
{
|
|
|
|
|
if (!GPU_is_init()) {
|
|
|
|
|
if (py_type->tp_methods) {
|
|
|
|
|
/* Replace all methods with an error method. */
|
|
|
|
|
for (PyMethodDef *meth = py_type->tp_methods; meth->ml_name; meth++) {
|
|
|
|
|
meth->ml_meth = py_error__ml_meth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (py_type->tp_getset) {
|
|
|
|
|
/* Replace all getters and setter with a functions that always returns error. */
|
|
|
|
|
for (PyGetSetDef *getset = py_type->tp_getset; getset->name; getset++) {
|
|
|
|
|
getset->get = py_error__getter;
|
|
|
|
|
getset->set = py_error__setter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (py_type->tp_new) {
|
|
|
|
|
/* If initialized, return error. */
|
|
|
|
|
py_type->tp_new = py_error__tp_new;
|
|
|
|
|
}
|
2021-02-22 09:44:57 -03:00
|
|
|
}
|
|
|
|
|
|
2022-11-29 13:55:37 -03:00
|
|
|
return PyType_Ready(py_type);
|
2021-02-22 09:44:57 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|