Python: move remaining python files to C++

Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/110352
This commit is contained in:
Jacques Lucke
2023-07-21 19:41:03 +02:00
parent a670b53abe
commit ec05e5a3fc
64 changed files with 2868 additions and 2574 deletions

View File

@@ -15,25 +15,25 @@ set(INC_SYS
)
set(SRC
gpu_py.c
gpu_py_api.c
gpu_py_batch.c
gpu_py_buffer.c
gpu_py_capabilities.c
gpu_py_element.c
gpu_py_framebuffer.c
gpu_py_matrix.c
gpu_py_offscreen.c
gpu_py_platform.c
gpu_py_select.c
gpu_py_shader.c
gpu_py.cc
gpu_py_api.cc
gpu_py_batch.cc
gpu_py_buffer.cc
gpu_py_capabilities.cc
gpu_py_element.cc
gpu_py_framebuffer.cc
gpu_py_matrix.cc
gpu_py_offscreen.cc
gpu_py_platform.cc
gpu_py_select.cc
gpu_py_shader.cc
gpu_py_shader_create_info.cc
gpu_py_state.c
gpu_py_texture.c
gpu_py_types.c
gpu_py_uniformbuffer.c
gpu_py_vertex_buffer.c
gpu_py_vertex_format.c
gpu_py_state.cc
gpu_py_texture.cc
gpu_py_types.cc
gpu_py_uniformbuffer.cc
gpu_py_vertex_buffer.cc
gpu_py_vertex_format.cc
gpu_py.h
gpu_py_api.h

View File

@@ -34,7 +34,7 @@ struct PyC_StringEnumItems bpygpu_primtype_items[] = {
{GPU_PRIM_LINES_ADJ, "LINES_ADJ"},
{GPU_PRIM_TRIS_ADJ, "TRIS_ADJ"},
{GPU_PRIM_LINE_STRIP_ADJ, "LINE_STRIP_ADJ"},
{0, NULL},
{0, nullptr},
};
struct PyC_StringEnumItems bpygpu_dataformat_items[] = {
@@ -44,7 +44,7 @@ struct PyC_StringEnumItems bpygpu_dataformat_items[] = {
{GPU_DATA_UBYTE, "UBYTE"},
{GPU_DATA_UINT_24_8, "UINT_24_8"},
{GPU_DATA_10_11_11_REV, "10_11_11_REV"},
{0, NULL},
{0, nullptr},
};
/** \} */
@@ -55,30 +55,30 @@ struct PyC_StringEnumItems bpygpu_dataformat_items[] = {
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))
static PyObject *py_error__ml_meth(PyObject * /*self*/, PyObject * /*args*/)
{
PyErr_SetString(PyExc_SystemError, g_error);
return NULL;
return nullptr;
}
static PyObject *py_error__getter(PyObject *UNUSED(self), void *UNUSED(type))
static PyObject *py_error__getter(PyObject * /*self*/, void * /*type*/)
{
PyErr_SetString(PyExc_SystemError, g_error);
return NULL;
return nullptr;
}
static int py_error__setter(PyObject *UNUSED(self), PyObject *UNUSED(value), void *UNUSED(type))
static int py_error__setter(PyObject * /*self*/, PyObject * /*value*/, void * /*type*/)
{
PyErr_SetString(PyExc_SystemError, g_error);
return -1;
}
static PyObject *py_error__tp_new(PyTypeObject *UNUSED(type),
PyObject *UNUSED(args),
PyObject *UNUSED(kwds))
static PyObject *py_error__tp_new(PyTypeObject * /*type*/,
PyObject * /*args*/,
PyObject * /*kwds*/)
{
PyErr_SetString(PyExc_SystemError, g_error);
return NULL;
return nullptr;
}
PyObject *bpygpu_create_module(PyModuleDef *module_type)

View File

@@ -10,8 +10,16 @@
#include "../generic/py_capi_utils.h"
#ifdef __cplusplus
extern "C" {
#endif
extern struct PyC_StringEnumItems bpygpu_primtype_items[];
extern struct PyC_StringEnumItems bpygpu_dataformat_items[];
PyObject *bpygpu_create_module(PyModuleDef *module_type);
int bpygpu_finalize_type(PyTypeObject *py_type);
#ifdef __cplusplus
}
#endif

View File

@@ -38,11 +38,11 @@ static PyModuleDef pygpu_module_def = {
/*m_name*/ "gpu",
/*m_doc*/ pygpu_doc,
/*m_size*/ 0,
/*m_methods*/ NULL,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_methods*/ nullptr,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
PyObject *BPyInit_gpu(void)

View File

@@ -46,15 +46,15 @@ static bool pygpu_batch_is_program_or_error(BPyGPUBatch *self)
/** \name GPUBatch Type
* \{ */
static PyObject *pygpu_batch__tp_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
static PyObject *pygpu_batch__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds)
{
const char *exc_str_missing_arg = "GPUBatch.__new__() missing required argument '%s' (pos %d)";
struct PyC_StringEnum prim_type = {bpygpu_primtype_items, GPU_PRIM_NONE};
BPyGPUVertBuf *py_vertbuf = NULL;
BPyGPUIndexBuf *py_indexbuf = NULL;
BPyGPUVertBuf *py_vertbuf = nullptr;
BPyGPUIndexBuf *py_indexbuf = nullptr;
static const char *_keywords[] = {"type", "buf", "elem", NULL};
static const char *_keywords[] = {"type", "buf", "elem", nullptr};
static _PyArg_Parser _parser = {
"|$" /* Optional keyword only arguments. */
"O&" /* `type` */
@@ -74,7 +74,7 @@ static PyObject *pygpu_batch__tp_new(PyTypeObject *UNUSED(type), PyObject *args,
&BPyGPUIndexBuf_Type,
&py_indexbuf))
{
return NULL;
return nullptr;
}
BLI_assert(prim_type.value_found != GPU_PRIM_NONE);
@@ -91,13 +91,14 @@ static PyObject *pygpu_batch__tp_new(PyTypeObject *UNUSED(type), PyObject *args,
1);
}
if (py_vertbuf == NULL) {
if (py_vertbuf == nullptr) {
PyErr_Format(PyExc_TypeError, exc_str_missing_arg, _keywords[1], 2);
return NULL;
return nullptr;
}
GPUBatch *batch = GPU_batch_create(
prim_type.value_found, py_vertbuf->buf, py_indexbuf ? py_indexbuf->elem : NULL);
GPUBatch *batch = GPU_batch_create(GPUPrimType(prim_type.value_found),
py_vertbuf->buf,
py_indexbuf ? py_indexbuf->elem : nullptr);
BPyGPUBatch *ret = (BPyGPUBatch *)BPyGPUBatch_CreatePyObject(batch);
@@ -106,7 +107,7 @@ static PyObject *pygpu_batch__tp_new(PyTypeObject *UNUSED(type), PyObject *args,
PyList_SET_ITEM(ret->references, 0, (PyObject *)py_vertbuf);
Py_INCREF(py_vertbuf);
if (py_indexbuf != NULL) {
if (py_indexbuf != nullptr) {
PyList_SET_ITEM(ret->references, 1, (PyObject *)py_indexbuf);
Py_INCREF(py_indexbuf);
}
@@ -118,8 +119,7 @@ static PyObject *pygpu_batch__tp_new(PyTypeObject *UNUSED(type), PyObject *args,
return (PyObject *)ret;
}
PyDoc_STRVAR(pygpu_batch_vertbuf_add_doc,
".. method:: vertbuf_add(buf)\n"
PyDoc_STRVAR(pygpu_batch_vertbuf_add_doc, ".. method:: vertbuf_add(buf)\n"
"\n"
" Add another vertex buffer to the Batch.\n"
" It is not possible to add more vertices to the batch using this method.\n"
@@ -135,7 +135,7 @@ static PyObject *pygpu_batch_vertbuf_add(BPyGPUBatch *self, BPyGPUVertBuf *py_bu
{
if (!BPyGPUVertBuf_Check(py_buf)) {
PyErr_Format(PyExc_TypeError, "Expected a GPUVertBuf, got %s", Py_TYPE(py_buf)->tp_name);
return NULL;
return nullptr;
}
if (GPU_vertbuf_get_vertex_len(self->batch->verts[0]) != GPU_vertbuf_get_vertex_len(py_buf->buf))
@@ -144,14 +144,14 @@ static PyObject *pygpu_batch_vertbuf_add(BPyGPUBatch *self, BPyGPUVertBuf *py_bu
"Expected %d length, got %d",
GPU_vertbuf_get_vertex_len(self->batch->verts[0]),
GPU_vertbuf_get_vertex_len(py_buf->buf));
return NULL;
return nullptr;
}
if (self->batch->verts[GPU_BATCH_VBO_MAX_LEN - 1] != NULL) {
if (self->batch->verts[GPU_BATCH_VBO_MAX_LEN - 1] != nullptr) {
PyErr_SetString(
PyExc_RuntimeError,
"Maximum number of vertex buffers exceeded: " STRINGIFY(GPU_BATCH_VBO_MAX_LEN));
return NULL;
return nullptr;
}
#ifdef USE_GPU_PY_REFERENCES
@@ -178,7 +178,7 @@ static PyObject *pygpu_batch_program_set(BPyGPUBatch *self, BPyGPUShader *py_sha
{
if (!BPyGPUShader_Check(py_shader)) {
PyErr_Format(PyExc_TypeError, "Expected a GPUShader, got %s", Py_TYPE(py_shader)->tp_name);
return NULL;
return nullptr;
}
GPUShader *shader = py_shader->shader;
@@ -215,14 +215,14 @@ PyDoc_STRVAR(pygpu_batch_draw_doc,
" :type program: :class:`gpu.types.GPUShader`\n");
static PyObject *pygpu_batch_draw(BPyGPUBatch *self, PyObject *args)
{
BPyGPUShader *py_program = NULL;
BPyGPUShader *py_program = nullptr;
if (!PyArg_ParseTuple(args, "|O!:GPUBatch.draw", &BPyGPUShader_Type, &py_program)) {
return NULL;
return nullptr;
}
if (py_program == NULL) {
if (py_program == nullptr) {
if (!pygpu_batch_is_program_or_error(self)) {
return NULL;
return nullptr;
}
}
else if (self->batch->shader != py_program->shader) {
@@ -251,11 +251,11 @@ PyDoc_STRVAR(
" :type instance_count: int\n");
static PyObject *pygpu_batch_draw_instanced(BPyGPUBatch *self, PyObject *args, PyObject *kw)
{
BPyGPUShader *py_program = NULL;
BPyGPUShader *py_program = nullptr;
int instance_start = 0;
int instance_count = 0;
static const char *_keywords[] = {"program", "instance_start", "instance_count", NULL};
static const char *_keywords[] = {"program", "instance_start", "instance_count", nullptr};
static _PyArg_Parser _parser = {
"O!" /* `program` */
"|$" /* Optional keyword only arguments. */
@@ -268,7 +268,7 @@ static PyObject *pygpu_batch_draw_instanced(BPyGPUBatch *self, PyObject *args, P
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kw, &_parser, &BPyGPUShader_Type, &py_program, &instance_start, &instance_count))
{
return NULL;
return nullptr;
}
GPU_batch_set_shader(self->batch, py_program->shader);
@@ -293,11 +293,11 @@ PyDoc_STRVAR(pygpu_batch_draw_range_doc,
" :type elem_count: int\n");
static PyObject *pygpu_batch_draw_range(BPyGPUBatch *self, PyObject *args, PyObject *kw)
{
BPyGPUShader *py_program = NULL;
BPyGPUShader *py_program = nullptr;
int elem_start = 0;
int elem_count = 0;
static const char *_keywords[] = {"program", "elem_start", "elem_count", NULL};
static const char *_keywords[] = {"program", "elem_start", "elem_count", nullptr};
static _PyArg_Parser _parser = {
"O!" /* `program` */
"|$" /* Optional keyword only arguments. */
@@ -310,7 +310,7 @@ static PyObject *pygpu_batch_draw_range(BPyGPUBatch *self, PyObject *args, PyObj
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kw, &_parser, &BPyGPUShader_Type, &py_program, &elem_start, &elem_count))
{
return NULL;
return nullptr;
}
GPU_batch_set_shader(self->batch, py_program->shader);
@@ -321,7 +321,7 @@ static PyObject *pygpu_batch_draw_range(BPyGPUBatch *self, PyObject *args, PyObj
static PyObject *pygpu_batch_program_use_begin(BPyGPUBatch *self)
{
if (!pygpu_batch_is_program_or_error(self)) {
return NULL;
return nullptr;
}
GPU_shader_bind(self->batch->shader);
Py_RETURN_NONE;
@@ -330,7 +330,7 @@ static PyObject *pygpu_batch_program_use_begin(BPyGPUBatch *self)
static PyObject *pygpu_batch_program_use_end(BPyGPUBatch *self)
{
if (!pygpu_batch_is_program_or_error(self)) {
return NULL;
return nullptr;
}
GPU_shader_unbind();
Py_RETURN_NONE;
@@ -350,7 +350,7 @@ static PyMethodDef pygpu_batch__tp_methods[] = {
pygpu_batch_draw_range_doc},
{"_program_use_begin", (PyCFunction)pygpu_batch_program_use_begin, METH_NOARGS, ""},
{"_program_use_end", (PyCFunction)pygpu_batch_program_use_end, METH_NOARGS, ""},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
#ifdef USE_GPU_PY_REFERENCES
@@ -369,7 +369,7 @@ static int pygpu_batch__tp_clear(BPyGPUBatch *self)
static int pygpu_batch__tp_is_gc(BPyGPUBatch *self)
{
return self->references != NULL;
return self->references != nullptr;
}
#endif
@@ -404,25 +404,25 @@ PyDoc_STRVAR(
" :arg elem: An optional index buffer.\n"
" :type elem: :class:`gpu.types.GPUIndexBuf`\n");
PyTypeObject BPyGPUBatch_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUBatch",
/*tp_basicsize*/ sizeof(BPyGPUBatch),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_batch__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
#ifdef USE_GPU_PY_REFERENCES
/*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
#else
@@ -432,43 +432,43 @@ PyTypeObject BPyGPUBatch_Type = {
#ifdef USE_GPU_PY_REFERENCES
/*tp_traverse*/ (traverseproc)pygpu_batch__tp_traverse,
#else
/*tp_traverse*/ NULL,
/*tp_traverse*/ nullptr,
#endif
#ifdef USE_GPU_PY_REFERENCES
/*tp_clear*/ (inquiry)pygpu_batch__tp_clear,
#else
/*tp_clear*/ NULL,
/*tp_clear*/ nullptr,
#endif
/*tp_richcompare*/ NULL,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_batch__tp_methods,
/*tp_members*/ NULL,
/*tp_getset*/ NULL,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ nullptr,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_batch__tp_new,
/*tp_free*/ NULL,
/*tp_free*/ nullptr,
#ifdef USE_GPU_PY_REFERENCES
/*tp_is_gc*/ (inquiry)pygpu_batch__tp_is_gc,
#else
/*tp_is_gc*/ NULL,
/*tp_is_gc*/ nullptr,
#endif
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */
@@ -483,7 +483,7 @@ PyObject *BPyGPUBatch_CreatePyObject(GPUBatch *batch)
#ifdef USE_GPU_PY_REFERENCES
self = (BPyGPUBatch *)_PyObject_GC_New(&BPyGPUBatch_Type);
self->references = NULL;
self->references = nullptr;
#else
self = PyObject_New(BPyGPUBatch, &BPyGPUBatch_Type);
#endif

View File

@@ -10,6 +10,10 @@
#include "BLI_compiler_attrs.h"
#ifdef __cplusplus
extern "C" {
#endif
#define USE_GPU_PY_REFERENCES
extern PyTypeObject BPyGPUBatch_Type;
@@ -27,3 +31,7 @@ typedef struct BPyGPUBatch {
} BPyGPUBatch;
PyObject *BPyGPUBatch_CreatePyObject(struct GPUBatch *batch) ATTR_NONNULL(1);
#ifdef __cplusplus
}
#endif

View File

@@ -129,7 +129,7 @@ static const char *pygpu_buffer_formatstr(eGPUDataFormat data_format)
default:
break;
}
return NULL;
return nullptr;
}
/** \} */
@@ -146,10 +146,11 @@ static BPyGPUBuffer *pygpu_buffer_make_from_data(PyObject *parent,
{
BPyGPUBuffer *buffer = (BPyGPUBuffer *)_PyObject_GC_New(&BPyGPU_BufferType);
buffer->parent = NULL;
buffer->parent = nullptr;
buffer->format = format;
buffer->shape_len = shape_len;
buffer->shape = MEM_mallocN(shape_len * sizeof(*buffer->shape), "BPyGPUBuffer shape");
buffer->shape = static_cast<Py_ssize_t *>(
MEM_mallocN(shape_len * sizeof(*buffer->shape), "BPyGPUBuffer shape"));
memcpy(buffer->shape, shape, shape_len * sizeof(*buffer->shape));
buffer->buf.as_void = buf;
@@ -166,10 +167,10 @@ static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, Py_ssize_t i)
{
if (i >= self->shape[0] || i < 0) {
PyErr_SetString(PyExc_IndexError, "array index out of range");
return NULL;
return nullptr;
}
const char *formatstr = pygpu_buffer_formatstr(self->format);
const char *formatstr = pygpu_buffer_formatstr(eGPUDataFormat(self->format));
if (self->shape_len == 1) {
switch (self->format) {
@@ -186,19 +187,19 @@ static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, Py_ssize_t i)
}
}
else {
int offset = i * GPU_texture_dataformat_size(self->format);
int offset = i * GPU_texture_dataformat_size(eGPUDataFormat(self->format));
for (int j = 1; j < self->shape_len; j++) {
offset *= self->shape[j];
}
return (PyObject *)pygpu_buffer_make_from_data((PyObject *)self,
self->format,
eGPUDataFormat(self->format),
self->shape_len - 1,
self->shape + 1,
self->buf.as_byte + offset);
}
return NULL;
return nullptr;
}
static PyObject *pygpu_buffer_to_list(BPyGPUBuffer *self)
@@ -237,7 +238,7 @@ static PyObject *pygpu_buffer_to_list_recursive(BPyGPUBuffer *self)
return list;
}
static PyObject *pygpu_buffer_dimensions_get(BPyGPUBuffer *self, void *UNUSED(arg))
static PyObject *pygpu_buffer_dimensions_get(BPyGPUBuffer *self, void * /*arg*/)
{
PyObject *list = PyList_New(self->shape_len);
int i;
@@ -249,7 +250,7 @@ static PyObject *pygpu_buffer_dimensions_get(BPyGPUBuffer *self, void *UNUSED(ar
return list;
}
static int pygpu_buffer_dimensions_set(BPyGPUBuffer *self, PyObject *value, void *UNUSED(type))
static int pygpu_buffer_dimensions_set(BPyGPUBuffer *self, PyObject *value, void * /*type*/)
{
Py_ssize_t shape[MAX_DIMENSIONS];
Py_ssize_t shape_len = 0;
@@ -265,7 +266,7 @@ static int pygpu_buffer_dimensions_set(BPyGPUBuffer *self, PyObject *value, void
size_t size = shape_len * sizeof(*self->shape);
if (shape_len != self->shape_len) {
MEM_freeN(self->shape);
self->shape = MEM_mallocN(size, __func__);
self->shape = static_cast<Py_ssize_t *>(MEM_mallocN(size, __func__));
}
self->shape_len = shape_len;
@@ -283,7 +284,7 @@ static int pygpu_buffer__tp_clear(BPyGPUBuffer *self)
{
if (self->parent) {
Py_CLEAR(self->parent);
self->buf.as_void = NULL;
self->buf.as_void = nullptr;
}
return 0;
}
@@ -370,28 +371,28 @@ static int pygpu_buffer_ass_slice(BPyGPUBuffer *self,
return err;
}
static PyObject *pygpu_buffer__tp_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
static PyObject *pygpu_buffer__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds)
{
PyObject *length_ob, *init = NULL;
BPyGPUBuffer *buffer = NULL;
PyObject *length_ob, *init = nullptr;
BPyGPUBuffer *buffer = nullptr;
Py_ssize_t shape[MAX_DIMENSIONS];
Py_ssize_t shape_len = 0;
if (kwds && PyDict_Size(kwds)) {
PyErr_SetString(PyExc_TypeError, "Buffer(): takes no keyword args");
return NULL;
return nullptr;
}
const struct PyC_StringEnum pygpu_dataformat = {bpygpu_dataformat_items, GPU_DATA_FLOAT};
if (!PyArg_ParseTuple(
args, "O&O|O: Buffer", PyC_ParseStringEnum, &pygpu_dataformat, &length_ob, &init))
{
return NULL;
return nullptr;
}
if (!pygpu_buffer_pyobj_as_shape(length_ob, shape, &shape_len)) {
return NULL;
return nullptr;
}
if (init && PyObject_CheckBuffer(init)) {
@@ -399,7 +400,7 @@ static PyObject *pygpu_buffer__tp_new(PyTypeObject *UNUSED(type), PyObject *args
if (PyObject_GetBuffer(init, &pybuffer, PyBUF_ND | PyBUF_FORMAT) == -1) {
/* PyObject_GetBuffer raise a PyExc_BufferError */
return NULL;
return nullptr;
}
Py_ssize_t *pybuffer_shape = pybuffer.shape;
@@ -411,16 +412,16 @@ static PyObject *pygpu_buffer__tp_new(PyTypeObject *UNUSED(type), PyObject *args
if (pygpu_buffer_dimensions_tot_len_compare(shape, shape_len, pybuffer_shape, pybuffer_ndim)) {
buffer = pygpu_buffer_make_from_data(
init, pygpu_dataformat.value_found, shape_len, shape, pybuffer.buf);
init, eGPUDataFormat(pygpu_dataformat.value_found), shape_len, shape, pybuffer.buf);
}
PyBuffer_Release(&pybuffer);
}
else {
buffer = BPyGPU_Buffer_CreatePyObject(pygpu_dataformat.value_found, shape, shape_len, NULL);
buffer = BPyGPU_Buffer_CreatePyObject(pygpu_dataformat.value_found, shape, shape_len, nullptr);
if (init && pygpu_buffer_ass_slice(buffer, 0, shape[0], init)) {
Py_DECREF(buffer);
return NULL;
return nullptr;
}
}
@@ -429,7 +430,7 @@ static PyObject *pygpu_buffer__tp_new(PyTypeObject *UNUSED(type), PyObject *args
static int pygpu_buffer__tp_is_gc(BPyGPUBuffer *self)
{
return self->parent != NULL;
return self->parent != nullptr;
}
/* BPyGPUBuffer sequence methods */
@@ -503,7 +504,7 @@ static PyObject *pygpu_buffer__mp_subscript(BPyGPUBuffer *self, PyObject *item)
Py_ssize_t i;
i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i == -1 && PyErr_Occurred()) {
return NULL;
return nullptr;
}
if (i < 0) {
i += self->shape[0];
@@ -514,7 +515,7 @@ static PyObject *pygpu_buffer__mp_subscript(BPyGPUBuffer *self, PyObject *item)
Py_ssize_t start, stop, step, slicelength;
if (PySlice_GetIndicesEx(item, self->shape[0], &start, &stop, &step, &slicelength) < 0) {
return NULL;
return nullptr;
}
if (slicelength <= 0) {
@@ -525,12 +526,12 @@ static PyObject *pygpu_buffer__mp_subscript(BPyGPUBuffer *self, PyObject *item)
}
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
return NULL;
return nullptr;
}
PyErr_Format(
PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
return NULL;
return nullptr;
}
static int pygpu_buffer__mp_ass_subscript(BPyGPUBuffer *self, PyObject *item, PyObject *value)
@@ -570,29 +571,29 @@ static PyMethodDef pygpu_buffer__tp_methods[] = {
(PyCFunction)pygpu_buffer_to_list_recursive,
METH_NOARGS,
"return the buffer as a list"},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
static PyGetSetDef pygpu_buffer_getseters[] = {
{"dimensions",
(getter)pygpu_buffer_dimensions_get,
(setter)pygpu_buffer_dimensions_set,
NULL,
NULL},
{NULL, NULL, NULL, NULL, NULL},
nullptr,
nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr},
};
static PySequenceMethods pygpu_buffer__tp_as_sequence = {
/*sq_length*/ (lenfunc)pygpu_buffer__sq_length,
/*sq_concat*/ NULL,
/*sq_repeat*/ NULL,
/*sq_concat*/ nullptr,
/*sq_repeat*/ nullptr,
/*sq_item*/ (ssizeargfunc)pygpu_buffer__sq_item,
/*was_sq_slice*/ NULL, /* DEPRECATED. Handled by #pygpu_buffer__sq_item. */
/*was_sq_slice*/ nullptr, /* DEPRECATED. Handled by #pygpu_buffer__sq_item. */
/*sq_ass_item*/ (ssizeobjargproc)pygpu_buffer__sq_ass_item,
/*was_sq_ass_slice*/ NULL, /* DEPRECATED. Handled by #pygpu_buffer__sq_ass_item. */
/*sq_contains*/ NULL,
/*sq_inplace_concat*/ NULL,
/*sq_inplace_repeat*/ NULL,
/*was_sq_ass_slice*/ nullptr, /* DEPRECATED. Handled by #pygpu_buffer__sq_ass_item. */
/*sq_contains*/ nullptr,
/*sq_inplace_concat*/ nullptr,
/*sq_inplace_repeat*/ nullptr,
};
static PyMappingMethods pygpu_buffer__tp_as_mapping = {
@@ -616,8 +617,8 @@ static void pygpu_buffer_strides_calc(const eGPUDataFormat format,
/* Here is the buffer interface function */
static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int flags)
{
if (view == NULL) {
PyErr_SetString(PyExc_ValueError, "NULL view in getbuffer");
if (view == nullptr) {
PyErr_SetString(PyExc_ValueError, "nullptr view in getbuffer");
return -1;
}
@@ -627,26 +628,28 @@ static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int f
view->buf = (void *)self->buf.as_void;
view->len = bpygpu_Buffer_size(self);
view->readonly = 0;
view->itemsize = GPU_texture_dataformat_size(self->format);
view->itemsize = GPU_texture_dataformat_size(eGPUDataFormat(self->format));
if (flags & PyBUF_FORMAT) {
view->format = (char *)pygpu_buffer_formatstr(self->format);
view->format = (char *)pygpu_buffer_formatstr(eGPUDataFormat(self->format));
}
if (flags & PyBUF_ND) {
view->ndim = self->shape_len;
view->shape = self->shape;
}
if (flags & PyBUF_STRIDES) {
view->strides = MEM_mallocN(view->ndim * sizeof(*view->strides), "BPyGPUBuffer strides");
pygpu_buffer_strides_calc(self->format, view->ndim, view->shape, view->strides);
view->strides = static_cast<Py_ssize_t *>(
MEM_mallocN(view->ndim * sizeof(*view->strides), "BPyGPUBuffer strides"));
pygpu_buffer_strides_calc(
eGPUDataFormat(self->format), view->ndim, view->shape, view->strides);
}
view->suboffsets = NULL;
view->internal = NULL;
view->suboffsets = nullptr;
view->internal = nullptr;
Py_INCREF(self);
return 0;
}
static void pygpu_buffer__bf_releasebuffer(PyObject *UNUSED(exporter), Py_buffer *view)
static void pygpu_buffer__bf_releasebuffer(PyObject * /*exporter*/, Py_buffer *view)
{
MEM_SAFE_FREE(view->strides);
}
@@ -671,66 +674,67 @@ PyDoc_STRVAR(
" :arg data: Optional data array.\n"
" :type data: sequence\n");
PyTypeObject BPyGPU_BufferType = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "Buffer",
/*tp_basicsize*/ sizeof(BPyGPUBuffer),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_buffer__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_compare*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_compare*/ nullptr,
/*tp_repr*/ (reprfunc)pygpu_buffer__tp_repr,
/*tp_as_number*/ NULL,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ &pygpu_buffer__tp_as_sequence,
/*tp_as_mapping*/ &pygpu_buffer__tp_as_mapping,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
#ifdef PYGPU_BUFFER_PROTOCOL
/*tp_as_buffer*/ &pygpu_buffer__tp_as_buffer,
#else
/*tp_as_buffer*/ NULL,
/*tp_as_buffer*/ nullptr,
#endif
/*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
/*tp_doc*/ pygpu_buffer__tp_doc,
/*tp_traverse*/ (traverseproc)pygpu_buffer__tp_traverse,
/*tp_clear*/ (inquiry)pygpu_buffer__tp_clear,
/*tp_richcompare*/ NULL,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_buffer__tp_methods,
/*tp_members*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ pygpu_buffer_getseters,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_buffer__tp_new,
/*tp_free*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ (inquiry)pygpu_buffer__tp_is_gc,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
static size_t pygpu_buffer_calc_size(const int format,
const int shape_len,
const Py_ssize_t *shape)
{
return pygpu_buffer_dimensions_tot_elem(shape, shape_len) * GPU_texture_dataformat_size(format);
return pygpu_buffer_dimensions_tot_elem(shape, shape_len) *
GPU_texture_dataformat_size(eGPUDataFormat(format));
}
size_t bpygpu_Buffer_size(BPyGPUBuffer *buffer)
@@ -743,12 +747,12 @@ BPyGPUBuffer *BPyGPU_Buffer_CreatePyObject(const int format,
const int shape_len,
void *buffer)
{
if (buffer == NULL) {
if (buffer == nullptr) {
size_t size = pygpu_buffer_calc_size(format, shape_len, shape);
buffer = MEM_callocN(size, "BPyGPUBuffer buffer");
}
return pygpu_buffer_make_from_data(NULL, format, shape_len, shape, buffer);
return pygpu_buffer_make_from_data(nullptr, eGPUDataFormat(format), shape_len, shape, buffer);
}
/** \} */

View File

@@ -8,6 +8,10 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern PyTypeObject BPyGPU_BufferType;
#define BPyGPU_Buffer_Check(v) (Py_TYPE(v) == &BPyGPU_BufferType)
@@ -47,3 +51,7 @@ BPyGPUBuffer *BPyGPU_Buffer_CreatePyObject(int format,
const Py_ssize_t *shape,
int shape_len,
void *buffer);
#ifdef __cplusplus
}
#endif

View File

@@ -29,7 +29,7 @@ PyDoc_STRVAR(pygpu_max_texture_size_get_doc,
"\n"
" :return: Texture size.\n"
" :rtype: int\n");
static PyObject *pygpu_max_texture_size_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_texture_size_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_texture_size());
}
@@ -41,7 +41,7 @@ PyDoc_STRVAR(pygpu_max_texture_layers_get_doc,
"\n"
" :return: Number of layers.\n"
" :rtype: int\n");
static PyObject *pygpu_max_texture_layers_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_texture_layers_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_texture_layers());
}
@@ -55,7 +55,7 @@ PyDoc_STRVAR(pygpu_max_textures_get_doc,
"\n"
" :return: Texture image units.\n"
" :rtype: int\n");
static PyObject *pygpu_max_textures_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_textures_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_textures());
}
@@ -68,7 +68,7 @@ PyDoc_STRVAR(pygpu_max_textures_vert_get_doc,
"\n"
" :return: Texture image units.\n"
" :rtype: int\n");
static PyObject *pygpu_max_textures_vert_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_textures_vert_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_textures_vert());
}
@@ -81,7 +81,7 @@ PyDoc_STRVAR(pygpu_max_textures_geom_get_doc,
"\n"
" :return: Texture image units.\n"
" :rtype: int\n");
static PyObject *pygpu_max_textures_geom_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_textures_geom_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_textures_geom());
}
@@ -94,7 +94,7 @@ PyDoc_STRVAR(pygpu_max_textures_frag_get_doc,
"\n"
" :return: Texture image units.\n"
" :rtype: int\n");
static PyObject *pygpu_max_textures_frag_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_textures_frag_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_textures_frag());
}
@@ -107,7 +107,7 @@ PyDoc_STRVAR(pygpu_max_uniforms_vert_get_doc,
"\n"
" :return: Number of values.\n"
" :rtype: int\n");
static PyObject *pygpu_max_uniforms_vert_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_uniforms_vert_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_uniforms_vert());
}
@@ -120,7 +120,7 @@ PyDoc_STRVAR(pygpu_max_uniforms_frag_get_doc,
"\n"
" :return: Number of values.\n"
" :rtype: int\n");
static PyObject *pygpu_max_uniforms_frag_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_uniforms_frag_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_uniforms_frag());
}
@@ -132,7 +132,7 @@ PyDoc_STRVAR(pygpu_max_batch_indices_get_doc,
"\n"
" :return: Number of indices.\n"
" :rtype: int\n");
static PyObject *pygpu_max_batch_indices_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_batch_indices_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_batch_indices());
}
@@ -144,7 +144,7 @@ PyDoc_STRVAR(pygpu_max_batch_vertices_get_doc,
"\n"
" :return: Number of vertices.\n"
" :rtype: int\n");
static PyObject *pygpu_max_batch_vertices_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_batch_vertices_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_batch_vertices());
}
@@ -157,7 +157,7 @@ PyDoc_STRVAR(pygpu_max_vertex_attribs_get_doc,
"\n"
" :return: Number of attributes.\n"
" :rtype: int\n");
static PyObject *pygpu_max_vertex_attribs_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_vertex_attribs_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_vertex_attribs());
}
@@ -170,7 +170,7 @@ PyDoc_STRVAR(pygpu_max_varying_floats_get_doc,
"\n"
" :return: Number of variables.\n"
" :rtype: int\n");
static PyObject *pygpu_max_varying_floats_get(PyObject *UNUSED(self))
static PyObject *pygpu_max_varying_floats_get(PyObject * /*self*/)
{
return PyLong_FromLong(GPU_max_varying_floats());
}
@@ -182,7 +182,7 @@ PyDoc_STRVAR(pygpu_extensions_get_doc,
"\n"
" :return: Extensions.\n"
" :rtype: tuple of string\n");
static PyObject *pygpu_extensions_get(PyObject *UNUSED(self))
static PyObject *pygpu_extensions_get(PyObject * /*self*/)
{
int extensions_len = GPU_extensions_len();
PyObject *ret = PyTuple_New(extensions_len);
@@ -201,7 +201,7 @@ PyDoc_STRVAR(pygpu_compute_shader_support_get_doc,
"\n"
" :return: True when supported, False when not supported.\n"
" :rtype: bool\n");
static PyObject *pygpu_compute_shader_support_get(PyObject *UNUSED(self))
static PyObject *pygpu_compute_shader_support_get(PyObject * /*self*/)
{
return PyBool_FromLong(GPU_compute_shader_support());
}
@@ -213,7 +213,7 @@ PyDoc_STRVAR(pygpu_shader_storage_buffer_objects_support_get_doc,
"\n"
" :return: True when supported, False when not supported.\n"
" :rtype: bool\n");
static PyObject *pygpu_shader_storage_buffer_objects_support_get(PyObject *UNUSED(self))
static PyObject *pygpu_shader_storage_buffer_objects_support_get(PyObject * /*self*/)
{
return PyBool_FromLong(GPU_shader_storage_buffer_objects_support());
}
@@ -224,7 +224,7 @@ PyDoc_STRVAR(pygpu_shader_image_load_store_support_get_doc,
"\n"
" :return: True when supported, False when not supported.\n"
" :rtype: bool\n");
static PyObject *pygpu_shader_image_load_store_support_get(PyObject *UNUSED(self))
static PyObject *pygpu_shader_image_load_store_support_get(PyObject * /*self*/)
{
return PyBool_FromLong(GPU_shader_image_load_store_support());
}
@@ -298,7 +298,7 @@ static PyMethodDef pygpu_capabilities__tp_methods[] = {
METH_NOARGS,
pygpu_shader_image_load_store_support_get_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_capabilities__tp_doc, "This module provides access to the GPU capabilities.");
@@ -308,10 +308,10 @@ static PyModuleDef pygpu_capabilities_module_def = {
/*m_doc*/ pygpu_capabilities__tp_doc,
/*m_size*/ 0,
/*m_methods*/ pygpu_capabilities__tp_methods,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
PyObject *bpygpu_capabilities_init(void)

View File

@@ -8,4 +8,12 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
PyObject *bpygpu_capabilities_init(void);
#ifdef __cplusplus
}
#endif

View File

@@ -26,7 +26,7 @@
/** \name IndexBuf Type
* \{ */
static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds)
{
const char *error_prefix = "IndexBuf.__new__";
bool ok = true;
@@ -38,7 +38,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
uint index_len;
GPUIndexBufBuilder builder;
static const char *_keywords[] = {"type", "seq", NULL};
static const char *_keywords[] = {"type", "seq", nullptr};
static _PyArg_Parser _parser = {
"$O" /* `type` */
"&O" /* `seq` */
@@ -48,15 +48,15 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
};
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kwds, &_parser, PyC_ParseStringEnum, &prim_type, &seq)) {
return NULL;
return nullptr;
}
verts_per_prim = GPU_indexbuf_primitive_len(prim_type.value_found);
verts_per_prim = GPU_indexbuf_primitive_len(GPUPrimType(prim_type.value_found));
if (verts_per_prim == -1) {
PyErr_Format(PyExc_ValueError,
"The argument 'type' must be "
"'POINTS', 'LINES', 'TRIS' or 'LINES_ADJ'");
return NULL;
return nullptr;
}
if (PyObject_CheckBuffer(seq)) {
@@ -64,13 +64,13 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
if (PyObject_GetBuffer(seq, &pybuffer, PyBUF_FORMAT | PyBUF_ND) == -1) {
/* PyObject_GetBuffer already handles error messages. */
return NULL;
return nullptr;
}
if (pybuffer.ndim != 1 && pybuffer.shape[1] != verts_per_prim) {
PyErr_Format(PyExc_ValueError, "Each primitive must exactly %d indices", verts_per_prim);
PyBuffer_Release(&pybuffer);
return NULL;
return nullptr;
}
if (pybuffer.itemsize != 4 ||
@@ -78,7 +78,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
{
PyErr_Format(PyExc_ValueError, "Each index must be an 4-bytes integer value");
PyBuffer_Release(&pybuffer);
return NULL;
return nullptr;
}
index_len = pybuffer.shape[0];
@@ -89,9 +89,9 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
/* The `vertex_len` parameter is only used for asserts in the Debug build. */
/* Not very useful in python since scripts are often tested in Release build. */
/* Use `INT_MAX` instead of the actual number of vertices. */
GPU_indexbuf_init(&builder, prim_type.value_found, index_len, INT_MAX);
GPU_indexbuf_init(&builder, GPUPrimType(prim_type.value_found), index_len, INT_MAX);
uint *buf = pybuffer.buf;
uint *buf = static_cast<uint *>(pybuffer.buf);
for (uint i = index_len; i--; buf++) {
GPU_indexbuf_add_generic_vert(&builder, *buf);
}
@@ -101,8 +101,8 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
else {
PyObject *seq_fast = PySequence_Fast(seq, error_prefix);
if (seq_fast == NULL) {
return false;
if (seq_fast == nullptr) {
return nullptr;
}
const uint seq_len = PySequence_Fast_GET_SIZE(seq_fast);
@@ -114,7 +114,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
/* The `vertex_len` parameter is only used for asserts in the Debug build. */
/* Not very useful in python since scripts are often tested in Release build. */
/* Use `INT_MAX` instead of the actual number of vertices. */
GPU_indexbuf_init(&builder, prim_type.value_found, index_len, INT_MAX);
GPU_indexbuf_init(&builder, GPUPrimType(prim_type.value_found), index_len, INT_MAX);
if (verts_per_prim == 1) {
for (uint i = 0; i < seq_len; i++) {
@@ -125,7 +125,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
int values[4];
for (uint i = 0; i < seq_len; i++) {
PyObject *seq_fast_item = PySequence_Fast(seq_items[i], error_prefix);
if (seq_fast_item == NULL) {
if (seq_fast_item == nullptr) {
PyErr_Format(PyExc_TypeError,
"%s: expected a sequence, got %s",
error_prefix,
@@ -161,7 +161,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *ar
if (ok == false) {
MEM_freeN(builder.data);
return NULL;
return nullptr;
}
return BPyGPUIndexBuf_CreatePyObject(GPU_indexbuf_build(&builder));
@@ -186,55 +186,55 @@ PyDoc_STRVAR(pygpu_IndexBuf__tp_doc,
" Optionally the sequence can support the buffer protocol.\n"
" :type seq: 1D or 2D sequence\n");
PyTypeObject BPyGPUIndexBuf_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUIndexBuf",
/*tp_basicsize*/ sizeof(BPyGPUIndexBuf),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_IndexBuf__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ pygpu_IndexBuf__tp_doc,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_methods*/ NULL,
/*tp_members*/ NULL,
/*tp_getset*/ NULL,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ nullptr,
/*tp_members*/ nullptr,
/*tp_getset*/ nullptr,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_IndexBuf__tp_new,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */

View File

@@ -8,6 +8,10 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern PyTypeObject BPyGPUIndexBuf_Type;
#define BPyGPUIndexBuf_Check(v) (Py_TYPE(v) == &BPyGPUIndexBuf_Type)
@@ -18,3 +22,7 @@ typedef struct BPyGPUIndexBuf {
} BPyGPUIndexBuf;
PyObject *BPyGPUIndexBuf_CreatePyObject(struct GPUIndexBuf *elem);
#ifdef __cplusplus
}
#endif

View File

@@ -33,7 +33,7 @@
static int pygpu_framebuffer_valid_check(BPyGPUFrameBuffer *bpygpu_fb)
{
if (UNLIKELY(bpygpu_fb->fb == NULL)) {
if (UNLIKELY(bpygpu_fb->fb == nullptr)) {
PyErr_SetString(PyExc_ReferenceError, "GPU framebuffer was freed, no further access is valid");
return -1;
}
@@ -43,7 +43,7 @@ static int pygpu_framebuffer_valid_check(BPyGPUFrameBuffer *bpygpu_fb)
#define PYGPU_FRAMEBUFFER_CHECK_OBJ(bpygpu) \
{ \
if (UNLIKELY(pygpu_framebuffer_valid_check(bpygpu) == -1)) { \
return NULL; \
return nullptr; \
} \
} \
((void)0)
@@ -62,14 +62,14 @@ static void pygpu_framebuffer_free_safe(BPyGPUFrameBuffer *self)
{
if (self->fb) {
#ifndef GPU_NO_USE_PY_REFERENCES
GPU_framebuffer_py_reference_set(self->fb, NULL);
GPU_framebuffer_py_reference_set(self->fb, nullptr);
if (!self->shared_reference)
#endif
{
pygpu_framebuffer_free_if_possible(self->fb);
}
self->fb = NULL;
self->fb = nullptr;
}
}
@@ -115,11 +115,11 @@ static bool pygpu_framebuffer_stack_pop_and_restore_or_error(GPUFrameBuffer *fb)
*
* \{ */
typedef struct {
struct PyFrameBufferStackContext {
PyObject_HEAD /* Required Python macro. */
BPyGPUFrameBuffer *py_fb;
int level;
} PyFrameBufferStackContext;
};
static void pygpu_framebuffer_stack_context__tp_dealloc(PyFrameBufferStackContext *self)
{
@@ -134,11 +134,11 @@ static PyObject *pygpu_framebuffer_stack_context_enter(PyFrameBufferStackContext
/* sanity - should never happen */
if (self->level != -1) {
PyErr_SetString(PyExc_RuntimeError, "Already in use");
return NULL;
return nullptr;
}
if (!pygpu_framebuffer_stack_push_and_bind_or_error(self->py_fb->fb)) {
return NULL;
return nullptr;
}
self->level = GPU_framebuffer_stack_level_get();
@@ -146,14 +146,14 @@ static PyObject *pygpu_framebuffer_stack_context_enter(PyFrameBufferStackContext
}
static PyObject *pygpu_framebuffer_stack_context_exit(PyFrameBufferStackContext *self,
PyObject *UNUSED(args))
PyObject * /*args*/)
{
PYGPU_FRAMEBUFFER_CHECK_OBJ(self->py_fb);
/* sanity - should never happen */
if (self->level == -1) {
fprintf(stderr, "Not yet in use\n");
return NULL;
return nullptr;
}
const int level = GPU_framebuffer_stack_level_get();
@@ -162,7 +162,7 @@ static PyObject *pygpu_framebuffer_stack_context_exit(PyFrameBufferStackContext
}
if (!pygpu_framebuffer_stack_pop_and_restore_or_error(self->py_fb->fb)) {
return NULL;
return nullptr;
}
Py_RETURN_NONE;
}
@@ -170,59 +170,59 @@ static PyObject *pygpu_framebuffer_stack_context_exit(PyFrameBufferStackContext
static PyMethodDef pygpu_framebuffer_stack_context__tp_methods[] = {
{"__enter__", (PyCFunction)pygpu_framebuffer_stack_context_enter, METH_NOARGS},
{"__exit__", (PyCFunction)pygpu_framebuffer_stack_context_exit, METH_VARARGS},
{NULL},
{nullptr},
};
static PyTypeObject FramebufferStackContext_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUFrameBufferStackContext",
/*tp_basicsize*/ sizeof(PyFrameBufferStackContext),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_framebuffer_stack_context__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ NULL,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_doc*/ nullptr,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_framebuffer_stack_context__tp_methods,
/*tp_members*/ NULL,
/*tp_getset*/ NULL,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ nullptr,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_new*/ NULL,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ nullptr,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
PyDoc_STRVAR(pygpu_framebuffer_bind_doc,
@@ -246,10 +246,9 @@ static PyObject *pygpu_framebuffer_bind(BPyGPUFrameBuffer *self)
* \{ */
/* Fill in the GPUAttachment according to the PyObject parameter.
* PyObject *o can be NULL, Py_None, BPyGPUTexture or a dictionary containing the keyword "texture"
* and the optional keywords "layer" and "mip".
* Returns false on error. In this case, a python message will be raised and GPUAttachment will not
* be touched. */
* PyObject *o can be nullptr, Py_None, BPyGPUTexture or a dictionary containing the keyword
* "texture" and the optional keywords "layer" and "mip". Returns false on error. In this case, a
* python message will be raised and GPUAttachment will not be touched. */
static bool pygpu_framebuffer_new_parse_arg(PyObject *o, GPUAttachment *r_attach)
{
GPUAttachment tmp_attach = GPU_ATTACHMENT_NONE;
@@ -276,14 +275,14 @@ static bool pygpu_framebuffer_new_parse_arg(PyObject *o, GPUAttachment *r_attach
if (c_texture && _PyUnicode_EqualToASCIIString(key, c_texture)) {
/* Compare only once. */
c_texture = NULL;
c_texture = nullptr;
if (!bpygpu_ParseTexture(value, &tmp_attach.tex)) {
return false;
}
}
else if (c_layer && _PyUnicode_EqualToASCIIString(key, c_layer)) {
/* Compare only once. */
c_layer = NULL;
c_layer = nullptr;
tmp_attach.layer = PyLong_AsLong(value);
if (tmp_attach.layer == -1 && PyErr_Occurred()) {
return false;
@@ -291,7 +290,7 @@ static bool pygpu_framebuffer_new_parse_arg(PyObject *o, GPUAttachment *r_attach
}
else if (c_mip && _PyUnicode_EqualToASCIIString(key, c_mip)) {
/* Compare only once. */
c_mip = NULL;
c_mip = nullptr;
tmp_attach.mip = PyLong_AsLong(value);
if (tmp_attach.mip == -1 && PyErr_Occurred()) {
return false;
@@ -309,18 +308,16 @@ static bool pygpu_framebuffer_new_parse_arg(PyObject *o, GPUAttachment *r_attach
return true;
}
static PyObject *pygpu_framebuffer__tp_new(PyTypeObject *UNUSED(self),
PyObject *args,
PyObject *kwds)
static PyObject *pygpu_framebuffer__tp_new(PyTypeObject * /*self*/, PyObject *args, PyObject *kwds)
{
if (!GPU_context_active_get()) {
PyErr_SetString(PyExc_RuntimeError, "No active GPU context found");
return NULL;
return nullptr;
}
PyObject *depth_attachment = NULL;
PyObject *color_attachements = NULL;
static const char *_keywords[] = {"depth_slot", "color_slots", NULL};
PyObject *depth_attachment = nullptr;
PyObject *color_attachements = nullptr;
static const char *_keywords[] = {"depth_slot", "color_slots", nullptr};
static _PyArg_Parser _parser = {
"|$" /* Optional keyword only arguments. */
"O" /* `depth_slot` */
@@ -332,21 +329,21 @@ static PyObject *pygpu_framebuffer__tp_new(PyTypeObject *UNUSED(self),
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kwds, &_parser, &depth_attachment, &color_attachements))
{
return NULL;
return nullptr;
}
/* Keep in sync with #GPU_FB_MAX_COLOR_ATTACHMENT.
* TODO: share the define. */
/* Keep in sync with #GPU_FB_MAX_COLOR_ATTACHMENT.
* TODO: share the define. */
#define BPYGPU_FB_MAX_COLOR_ATTACHMENT 6
GPUAttachment config[BPYGPU_FB_MAX_COLOR_ATTACHMENT + 1];
if (!pygpu_framebuffer_new_parse_arg(depth_attachment, &config[0])) {
return NULL;
return nullptr;
}
if (config[0].tex && !GPU_texture_has_depth_format(config[0].tex)) {
PyErr_SetString(PyExc_ValueError, "Depth texture with incompatible format");
return NULL;
return nullptr;
}
int color_attachements_len = 0;
@@ -357,7 +354,7 @@ static PyObject *pygpu_framebuffer__tp_new(PyTypeObject *UNUSED(self),
PyErr_SetString(
PyExc_AttributeError,
"too many attachements, max is " STRINGIFY(BPYGPU_FB_MAX_COLOR_ATTACHMENT));
return NULL;
return nullptr;
}
for (int i = 0; i < color_attachements_len; i++) {
@@ -365,13 +362,13 @@ static PyObject *pygpu_framebuffer__tp_new(PyTypeObject *UNUSED(self),
bool ok = pygpu_framebuffer_new_parse_arg(o, &config[i + 1]);
Py_DECREF(o);
if (!ok) {
return NULL;
return nullptr;
}
}
}
else {
if (!pygpu_framebuffer_new_parse_arg(color_attachements, &config[1])) {
return NULL;
return nullptr;
}
color_attachements_len = 1;
}
@@ -385,7 +382,7 @@ static PyObject *pygpu_framebuffer__tp_new(PyTypeObject *UNUSED(self),
PyDoc_STRVAR(pygpu_framebuffer_is_bound_doc,
"Checks if this is the active framebuffer in the context.");
static PyObject *pygpu_framebuffer_is_bound(BPyGPUFrameBuffer *self, void *UNUSED(type))
static PyObject *pygpu_framebuffer_is_bound(BPyGPUFrameBuffer *self, void * /*type*/)
{
PYGPU_FRAMEBUFFER_CHECK_OBJ(self);
return PyBool_FromLong(GPU_framebuffer_bound(self->fb));
@@ -408,14 +405,14 @@ static PyObject *pygpu_framebuffer_clear(BPyGPUFrameBuffer *self, PyObject *args
PYGPU_FRAMEBUFFER_CHECK_OBJ(self);
if (!GPU_framebuffer_bound(self->fb)) {
return NULL;
return nullptr;
}
PyObject *py_col = NULL;
PyObject *py_depth = NULL;
PyObject *py_stencil = NULL;
PyObject *py_col = nullptr;
PyObject *py_depth = nullptr;
PyObject *py_stencil = nullptr;
static const char *_keywords[] = {"color", "depth", "stencil", NULL};
static const char *_keywords[] = {"color", "depth", "stencil", nullptr};
static _PyArg_Parser _parser = {
"|$" /* Optional keyword only arguments. */
"O" /* `color` */
@@ -426,10 +423,10 @@ static PyObject *pygpu_framebuffer_clear(BPyGPUFrameBuffer *self, PyObject *args
0,
};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &py_col, &py_depth, &py_stencil)) {
return NULL;
return nullptr;
}
eGPUFrameBufferBits buffers = 0;
eGPUFrameBufferBits buffers = eGPUFrameBufferBits(0);
float col[4] = {0.0f, 0.0f, 0.0f, 1.0f};
float depth = 1.0f;
uint stencil = 0;
@@ -437,7 +434,7 @@ static PyObject *pygpu_framebuffer_clear(BPyGPUFrameBuffer *self, PyObject *args
if (py_col && py_col != Py_None) {
if (mathutils_array_parse(col, 3, 4, py_col, "GPUFrameBuffer.clear(), invalid 'color' arg") ==
-1) {
return NULL;
return nullptr;
}
buffers |= GPU_COLOR_BIT;
}
@@ -445,14 +442,14 @@ static PyObject *pygpu_framebuffer_clear(BPyGPUFrameBuffer *self, PyObject *args
if (py_depth && py_depth != Py_None) {
depth = PyFloat_AsDouble(py_depth);
if (PyErr_Occurred()) {
return NULL;
return nullptr;
}
buffers |= GPU_DEPTH_BIT;
}
if (py_stencil && py_stencil != Py_None) {
if ((stencil = PyC_Long_AsU32(py_stencil)) == (uint)-1) {
return NULL;
return nullptr;
}
buffers |= GPU_STENCIL_BIT;
}
@@ -473,11 +470,11 @@ PyDoc_STRVAR(pygpu_framebuffer_viewport_set_doc,
" :type xsize, ysize: int\n");
static PyObject *pygpu_framebuffer_viewport_set(BPyGPUFrameBuffer *self,
PyObject *args,
void *UNUSED(type))
void * /*type*/)
{
int x, y, xsize, ysize;
if (!PyArg_ParseTuple(args, "iiii:viewport_set", &x, &y, &xsize, &ysize)) {
return NULL;
return nullptr;
}
GPU_framebuffer_viewport_set(self->fb, x, y, xsize, ysize);
@@ -488,7 +485,7 @@ PyDoc_STRVAR(pygpu_framebuffer_viewport_get_doc,
".. function:: viewport_get()\n"
"\n"
" Returns position and dimension to current viewport.\n");
static PyObject *pygpu_framebuffer_viewport_get(BPyGPUFrameBuffer *self, void *UNUSED(type))
static PyObject *pygpu_framebuffer_viewport_get(BPyGPUFrameBuffer *self, void * /*type*/)
{
PYGPU_FRAMEBUFFER_CHECK_OBJ(self);
int viewport[4];
@@ -531,10 +528,10 @@ static PyObject *pygpu_framebuffer_read_color(BPyGPUFrameBuffer *self,
int x, y, w, h, channels;
uint slot;
struct PyC_StringEnum pygpu_dataformat = {bpygpu_dataformat_items, GPU_RGBA8};
BPyGPUBuffer *py_buffer = NULL;
BPyGPUBuffer *py_buffer = nullptr;
static const char *_keywords[] = {
"x", "y", "xsize", "ysize", "channels", "slot", "format", "data", NULL};
"x", "y", "xsize", "ysize", "channels", "slot", "format", "data", nullptr};
static _PyArg_Parser _parser = {
"i" /* `x` */
"i" /* `y` */
@@ -563,38 +560,39 @@ static PyObject *pygpu_framebuffer_read_color(BPyGPUFrameBuffer *self,
&BPyGPU_BufferType,
&py_buffer))
{
return NULL;
return nullptr;
}
if (!IN_RANGE_INCL(channels, 1, 4)) {
PyErr_SetString(PyExc_AttributeError, "Color channels must be 1, 2, 3 or 4");
return NULL;
return nullptr;
}
if (slot >= BPYGPU_FB_MAX_COLOR_ATTACHMENT) {
PyErr_SetString(PyExc_ValueError, "slot overflow");
return NULL;
return nullptr;
}
if (py_buffer) {
if (pygpu_dataformat.value_found != py_buffer->format) {
PyErr_SetString(PyExc_AttributeError,
"the format of the buffer is different from that specified");
return NULL;
return nullptr;
}
size_t size_curr = bpygpu_Buffer_size(py_buffer);
size_t size_expected = w * h * channels *
GPU_texture_dataformat_size(pygpu_dataformat.value_found);
GPU_texture_dataformat_size(
eGPUDataFormat(pygpu_dataformat.value_found));
if (size_curr < size_expected) {
PyErr_SetString(PyExc_BufferError, "the buffer size is smaller than expected");
return NULL;
return nullptr;
}
Py_INCREF(py_buffer);
}
else {
py_buffer = BPyGPU_Buffer_CreatePyObject(
pygpu_dataformat.value_found, (Py_ssize_t[3]){h, w, channels}, 3, NULL);
const Py_ssize_t shape[3] = {h, w, channels};
py_buffer = BPyGPU_Buffer_CreatePyObject(pygpu_dataformat.value_found, shape, 3, nullptr);
BLI_assert(bpygpu_Buffer_size(py_buffer) ==
w * h * channels * GPU_texture_dataformat_size(pygpu_dataformat.value_found));
}
@@ -606,7 +604,7 @@ static PyObject *pygpu_framebuffer_read_color(BPyGPUFrameBuffer *self,
h,
channels,
(int)slot,
pygpu_dataformat.value_found,
eGPUDataFormat(pygpu_dataformat.value_found),
py_buffer->buf.as_void);
return (PyObject *)py_buffer;
@@ -631,9 +629,9 @@ static PyObject *pygpu_framebuffer_read_depth(BPyGPUFrameBuffer *self,
{
PYGPU_FRAMEBUFFER_CHECK_OBJ(self);
int x, y, w, h;
BPyGPUBuffer *py_buffer = NULL;
BPyGPUBuffer *py_buffer = nullptr;
static const char *_keywords[] = {"x", "y", "xsize", "ysize", "data", NULL};
static const char *_keywords[] = {"x", "y", "xsize", "ysize", "data", nullptr};
static _PyArg_Parser _parser = {
"i" /* `x` */
"i" /* `y` */
@@ -648,25 +646,26 @@ static PyObject *pygpu_framebuffer_read_depth(BPyGPUFrameBuffer *self,
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kwds, &_parser, &x, &y, &w, &h, &BPyGPU_BufferType, &py_buffer))
{
return NULL;
return nullptr;
}
if (py_buffer) {
if (py_buffer->format != GPU_DATA_FLOAT) {
PyErr_SetString(PyExc_AttributeError, "the format of the buffer must be 'GPU_DATA_FLOAT'");
return NULL;
return nullptr;
}
size_t size_curr = bpygpu_Buffer_size(py_buffer);
size_t size_expected = w * h * GPU_texture_dataformat_size(GPU_DATA_FLOAT);
if (size_curr < size_expected) {
PyErr_SetString(PyExc_BufferError, "the buffer size is smaller than expected");
return NULL;
return nullptr;
}
Py_INCREF(py_buffer);
}
else {
py_buffer = BPyGPU_Buffer_CreatePyObject(GPU_DATA_FLOAT, (Py_ssize_t[]){h, w}, 2, NULL);
const Py_ssize_t shape[2] = {h, w};
py_buffer = BPyGPU_Buffer_CreatePyObject(GPU_DATA_FLOAT, shape, 2, nullptr);
BLI_assert(bpygpu_Buffer_size(py_buffer) ==
w * h * GPU_texture_dataformat_size(GPU_DATA_FLOAT));
}
@@ -699,10 +698,10 @@ static void BPyGPUFrameBuffer__tp_dealloc(BPyGPUFrameBuffer *self)
static PyGetSetDef pygpu_framebuffer__tp_getseters[] = {
{"is_bound",
(getter)pygpu_framebuffer_is_bound,
(setter)NULL,
(setter) nullptr,
pygpu_framebuffer_is_bound_doc,
NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
};
static PyMethodDef pygpu_framebuffer__tp_methods[] = {
@@ -730,7 +729,7 @@ static PyMethodDef pygpu_framebuffer__tp_methods[] = {
#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
{"free", (PyCFunction)pygpu_framebuffer_free, METH_NOARGS, pygpu_framebuffer_free_doc},
#endif
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_framebuffer__tp_doc,
@@ -748,55 +747,55 @@ PyDoc_STRVAR(pygpu_framebuffer__tp_doc,
"containing keywords: 'texture', 'layer' and 'mip'.\n"
" :type color_slots: tuple or Nonetype\n");
PyTypeObject BPyGPUFrameBuffer_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUFrameBuffer",
/*tp_basicsize*/ sizeof(BPyGPUFrameBuffer),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)BPyGPUFrameBuffer__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ pygpu_framebuffer__tp_doc,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_framebuffer__tp_methods,
/*tp_members*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ pygpu_framebuffer__tp_getseters,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_framebuffer__tp_new,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */
@@ -830,7 +829,7 @@ PyObject *BPyGPUFrameBuffer_CreatePyObject(GPUFrameBuffer *fb, bool shared_refer
#ifndef GPU_NO_USE_PY_REFERENCES
self->shared_reference = shared_reference;
BLI_assert(GPU_framebuffer_py_reference_get(fb) == NULL);
BLI_assert(GPU_framebuffer_py_reference_get(fb) == nullptr);
GPU_framebuffer_py_reference_set(fb, (void **)&self->fb);
#endif

View File

@@ -10,6 +10,10 @@
#include "BLI_compiler_attrs.h"
#ifdef __cplusplus
extern "C" {
#endif
extern PyTypeObject BPyGPUFrameBuffer_Type;
#define BPyGPUFrameBuffer_Check(v) (Py_TYPE(v) == &BPyGPUFrameBuffer_Type)
@@ -25,3 +29,7 @@ typedef struct BPyGPUFrameBuffer {
PyObject *BPyGPUFrameBuffer_CreatePyObject(struct GPUFrameBuffer *fb, bool shared_reference)
ATTR_NONNULL(1);
#ifdef __cplusplus
}
#endif

View File

@@ -83,10 +83,10 @@ PyDoc_STRVAR(pygpu_matrix_push_doc,
".. function:: push()\n"
"\n"
" Add to the model-view matrix stack.\n");
static PyObject *pygpu_matrix_push(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_push(PyObject * /*self*/)
{
if (!pygpu_stack_is_push_model_view_ok_or_error()) {
return NULL;
return nullptr;
}
GPU_matrix_push();
Py_RETURN_NONE;
@@ -96,10 +96,10 @@ PyDoc_STRVAR(pygpu_matrix_pop_doc,
".. function:: pop()\n"
"\n"
" Remove the last model-view matrix from the stack.\n");
static PyObject *pygpu_matrix_pop(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_pop(PyObject * /*self*/)
{
if (!pygpu_stack_is_pop_model_view_ok_or_error()) {
return NULL;
return nullptr;
}
GPU_matrix_pop();
Py_RETURN_NONE;
@@ -109,10 +109,10 @@ PyDoc_STRVAR(pygpu_matrix_push_projection_doc,
".. function:: push_projection()\n"
"\n"
" Add to the projection matrix stack.\n");
static PyObject *pygpu_matrix_push_projection(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_push_projection(PyObject * /*self*/)
{
if (!pygpu_stack_is_push_projection_ok_or_error()) {
return NULL;
return nullptr;
}
GPU_matrix_push_projection();
Py_RETURN_NONE;
@@ -122,10 +122,10 @@ PyDoc_STRVAR(pygpu_matrix_pop_projection_doc,
".. function:: pop_projection()\n"
"\n"
" Remove the last projection matrix from the stack.\n");
static PyObject *pygpu_matrix_pop_projection(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_pop_projection(PyObject * /*self*/)
{
if (!pygpu_stack_is_pop_projection_ok_or_error()) {
return NULL;
return nullptr;
}
GPU_matrix_pop_projection();
Py_RETURN_NONE;
@@ -140,11 +140,11 @@ static PyObject *pygpu_matrix_pop_projection(PyObject *UNUSED(self))
*
* \{ */
typedef struct {
struct BPyGPU_MatrixStackContext {
PyObject_HEAD /* Required Python macro. */
int type;
int level;
} BPyGPU_MatrixStackContext;
};
enum {
PYGPU_MATRIX_TYPE_MODEL_VIEW = 1,
@@ -157,59 +157,59 @@ static PyObject *pygpu_matrix_stack_context_exit(BPyGPU_MatrixStackContext *self
static PyMethodDef pygpu_matrix_stack_context__tp_methods[] = {
{"__enter__", (PyCFunction)pygpu_matrix_stack_context_enter, METH_NOARGS},
{"__exit__", (PyCFunction)pygpu_matrix_stack_context_exit, METH_VARARGS},
{NULL},
{nullptr},
};
static PyTypeObject PyGPUMatrixStackContext_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUMatrixStackContext",
/*tp_basicsize*/ sizeof(BPyGPU_MatrixStackContext),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ NULL,
/*tp_dealloc*/ nullptr,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ NULL,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_doc*/ nullptr,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_matrix_stack_context__tp_methods,
/*tp_members*/ NULL,
/*tp_getset*/ NULL,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ nullptr,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_new*/ NULL,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ nullptr,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
static PyObject *pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *self)
@@ -217,19 +217,19 @@ static PyObject *pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *sel
/* sanity - should never happen */
if (self->level != -1) {
PyErr_SetString(PyExc_RuntimeError, "Already in use");
return NULL;
return nullptr;
}
if (self->type == PYGPU_MATRIX_TYPE_MODEL_VIEW) {
if (!pygpu_stack_is_push_model_view_ok_or_error()) {
return NULL;
return nullptr;
}
GPU_matrix_push();
self->level = GPU_matrix_stack_level_get_model_view();
}
else if (self->type == PYGPU_MATRIX_TYPE_PROJECTION) {
if (!pygpu_stack_is_push_projection_ok_or_error()) {
return NULL;
return nullptr;
}
GPU_matrix_push_projection();
self->level = GPU_matrix_stack_level_get_projection();
@@ -241,7 +241,7 @@ static PyObject *pygpu_matrix_stack_context_enter(BPyGPU_MatrixStackContext *sel
}
static PyObject *pygpu_matrix_stack_context_exit(BPyGPU_MatrixStackContext *self,
PyObject *UNUSED(args))
PyObject * /*args*/)
{
/* sanity - should never happen */
if (self->level == -1) {
@@ -288,7 +288,7 @@ PyDoc_STRVAR(
".. function:: push_pop()\n"
"\n"
" Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
static PyObject *pygpu_matrix_push_pop(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_push_pop(PyObject * /*self*/)
{
return pygpu_matrix_push_pop_impl(PYGPU_MATRIX_TYPE_MODEL_VIEW);
}
@@ -298,7 +298,7 @@ PyDoc_STRVAR(
".. function:: push_pop_projection()\n"
"\n"
" Context manager to ensure balanced push/pop calls, even in the case of an error.\n");
static PyObject *pygpu_matrix_push_pop_projection(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_push_pop_projection(PyObject * /*self*/)
{
return pygpu_matrix_push_pop_impl(PYGPU_MATRIX_TYPE_PROJECTION);
}
@@ -316,11 +316,11 @@ PyDoc_STRVAR(pygpu_matrix_multiply_matrix_doc,
"\n"
" :arg matrix: A 4x4 matrix.\n"
" :type matrix: :class:`mathutils.Matrix`\n");
static PyObject *pygpu_matrix_multiply_matrix(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_matrix_multiply_matrix(PyObject * /*self*/, PyObject *value)
{
MatrixObject *pymat;
if (!Matrix_Parse4x4(value, &pymat)) {
return NULL;
return nullptr;
}
GPU_matrix_mul(pymat->matrix);
Py_RETURN_NONE;
@@ -333,14 +333,14 @@ PyDoc_STRVAR(pygpu_matrix_scale_doc,
"\n"
" :arg scale: Scale the current stack matrix.\n"
" :type scale: sequence of 2 or 3 floats\n");
static PyObject *pygpu_matrix_scale(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_matrix_scale(PyObject * /*self*/, PyObject *value)
{
float scale[3];
int len;
if ((len = mathutils_array_parse(
scale, 2, 3, value, "gpu.matrix.scale(): invalid vector arg")) == -1)
{
return NULL;
return nullptr;
}
if (len == 2) {
GPU_matrix_scale_2fv(scale);
@@ -356,12 +356,12 @@ PyDoc_STRVAR(pygpu_matrix_scale_uniform_doc,
"\n"
" :arg scale: Scale the current stack matrix.\n"
" :type scale: float\n");
static PyObject *pygpu_matrix_scale_uniform(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_matrix_scale_uniform(PyObject * /*self*/, PyObject *value)
{
float scalar;
if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError, "expected a number, not %.200s", Py_TYPE(value)->tp_name);
return NULL;
return nullptr;
}
GPU_matrix_scale_1f(scalar);
Py_RETURN_NONE;
@@ -374,14 +374,14 @@ PyDoc_STRVAR(pygpu_matrix_translate_doc,
"\n"
" :arg offset: Translate the current stack matrix.\n"
" :type offset: sequence of 2 or 3 floats\n");
static PyObject *pygpu_matrix_translate(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_matrix_translate(PyObject * /*self*/, PyObject *value)
{
float offset[3];
int len;
if ((len = mathutils_array_parse(
offset, 2, 3, value, "gpu.matrix.translate(): invalid vector arg")) == -1)
{
return NULL;
return nullptr;
}
if (len == 2) {
GPU_matrix_translate_2fv(offset);
@@ -402,7 +402,7 @@ PyDoc_STRVAR(pygpu_matrix_reset_doc,
".. function:: reset()\n"
"\n"
" Empty stack and set to identity.\n");
static PyObject *pygpu_matrix_reset(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_reset(PyObject * /*self*/)
{
GPU_matrix_reset();
Py_RETURN_NONE;
@@ -412,7 +412,7 @@ PyDoc_STRVAR(pygpu_matrix_load_identity_doc,
".. function:: load_identity()\n"
"\n"
" Empty stack and set to identity.\n");
static PyObject *pygpu_matrix_load_identity(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_load_identity(PyObject * /*self*/)
{
GPU_matrix_identity_set();
Py_RETURN_NONE;
@@ -425,11 +425,11 @@ PyDoc_STRVAR(pygpu_matrix_load_matrix_doc,
"\n"
" :arg matrix: A 4x4 matrix.\n"
" :type matrix: :class:`mathutils.Matrix`\n");
static PyObject *pygpu_matrix_load_matrix(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_matrix_load_matrix(PyObject * /*self*/, PyObject *value)
{
MatrixObject *pymat;
if (!Matrix_Parse4x4(value, &pymat)) {
return NULL;
return nullptr;
}
GPU_matrix_set(pymat->matrix);
Py_RETURN_NONE;
@@ -442,11 +442,11 @@ PyDoc_STRVAR(pygpu_matrix_load_projection_matrix_doc,
"\n"
" :arg matrix: A 4x4 matrix.\n"
" :type matrix: :class:`mathutils.Matrix`\n");
static PyObject *pygpu_matrix_load_projection_matrix(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_matrix_load_projection_matrix(PyObject * /*self*/, PyObject *value)
{
MatrixObject *pymat;
if (!Matrix_Parse4x4(value, &pymat)) {
return NULL;
return nullptr;
}
GPU_matrix_projection_set(pymat->matrix);
Py_RETURN_NONE;
@@ -465,11 +465,11 @@ PyDoc_STRVAR(pygpu_matrix_get_projection_matrix_doc,
"\n"
" :return: A 4x4 projection matrix.\n"
" :rtype: :class:`mathutils.Matrix`\n");
static PyObject *pygpu_matrix_get_projection_matrix(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_get_projection_matrix(PyObject * /*self*/)
{
float matrix[4][4];
GPU_matrix_projection_get(matrix);
return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL);
return Matrix_CreatePyObject(&matrix[0][0], 4, 4, nullptr);
}
PyDoc_STRVAR(pygpu_matrix_get_model_view_matrix_doc,
@@ -479,11 +479,11 @@ PyDoc_STRVAR(pygpu_matrix_get_model_view_matrix_doc,
"\n"
" :return: A 4x4 view matrix.\n"
" :rtype: :class:`mathutils.Matrix`\n");
static PyObject *pygpu_matrix_get_model_view_matrix(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_get_model_view_matrix(PyObject * /*self*/)
{
float matrix[4][4];
GPU_matrix_model_view_get(matrix);
return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL);
return Matrix_CreatePyObject(&matrix[0][0], 4, 4, nullptr);
}
PyDoc_STRVAR(pygpu_matrix_get_normal_matrix_doc,
@@ -493,11 +493,11 @@ PyDoc_STRVAR(pygpu_matrix_get_normal_matrix_doc,
"\n"
" :return: A 3x3 normal matrix.\n"
" :rtype: :class:`mathutils.Matrix`\n");
static PyObject *pygpu_matrix_get_normal_matrix(PyObject *UNUSED(self))
static PyObject *pygpu_matrix_get_normal_matrix(PyObject * /*self*/)
{
float matrix[3][3];
GPU_matrix_normal_get(matrix);
return Matrix_CreatePyObject(&matrix[0][0], 3, 3, NULL);
return Matrix_CreatePyObject(&matrix[0][0], 3, 3, nullptr);
}
/** \} */
@@ -572,7 +572,7 @@ static PyMethodDef pygpu_matrix__tp_methods[] = {
METH_NOARGS,
pygpu_matrix_get_normal_matrix_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_matrix__tp_doc, "This module provides access to the matrix stack.");
@@ -582,10 +582,10 @@ static PyModuleDef pygpu_matrix_module_def = {
/*m_doc*/ pygpu_matrix__tp_doc,
/*m_size*/ 0,
/*m_methods*/ pygpu_matrix__tp_methods,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
PyObject *bpygpu_matrix_init(void)
@@ -595,7 +595,7 @@ PyObject *bpygpu_matrix_init(void)
submodule = bpygpu_create_module(&pygpu_matrix_module_def);
if (bpygpu_finalize_type(&PyGPUMatrixStackContext_Type) < 0) {
return NULL;
return nullptr;
}
return submodule;

View File

@@ -8,4 +8,12 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
PyObject *bpygpu_matrix_init(void);
#ifdef __cplusplus
}
#endif

View File

@@ -53,12 +53,12 @@ static const struct PyC_StringEnumItems pygpu_framebuffer_color_texture_formats[
{GPU_RGBA16, "RGBA16"},
{GPU_RGBA16F, "RGBA16F"},
{GPU_RGBA32F, "RGBA32F"},
{0, NULL},
{0, nullptr},
};
static int pygpu_offscreen_valid_check(BPyGPUOffScreen *py_ofs)
{
if (UNLIKELY(py_ofs->ofs == NULL)) {
if (UNLIKELY(py_ofs->ofs == nullptr)) {
PyErr_SetString(PyExc_ReferenceError,
#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
"GPU offscreen was freed, no further access is valid"
@@ -74,7 +74,7 @@ static int pygpu_offscreen_valid_check(BPyGPUOffScreen *py_ofs)
#define BPY_GPU_OFFSCREEN_CHECK_OBJ(bpygpu) \
{ \
if (UNLIKELY(pygpu_offscreen_valid_check(bpygpu) == -1)) { \
return NULL; \
return nullptr; \
} \
} \
((void)0)
@@ -88,12 +88,12 @@ static int pygpu_offscreen_valid_check(BPyGPUOffScreen *py_ofs)
*
* \{ */
typedef struct {
struct OffScreenStackContext {
PyObject_HEAD /* Required Python macro. */
BPyGPUOffScreen *py_offscreen;
int level;
bool is_explicitly_bound; /* Bound by "bind" method. */
} OffScreenStackContext;
};
static void pygpu_offscreen_stack_context__tp_dealloc(OffScreenStackContext *self)
{
@@ -108,7 +108,7 @@ static PyObject *pygpu_offscreen_stack_context_enter(OffScreenStackContext *self
if (!self->is_explicitly_bound) {
if (self->level != -1) {
PyErr_SetString(PyExc_RuntimeError, "Already in use");
return NULL;
return nullptr;
}
GPU_offscreen_bind(self->py_offscreen->ofs, true);
@@ -119,13 +119,13 @@ static PyObject *pygpu_offscreen_stack_context_enter(OffScreenStackContext *self
}
static PyObject *pygpu_offscreen_stack_context_exit(OffScreenStackContext *self,
PyObject *UNUSED(args))
PyObject * /*args*/)
{
BPY_GPU_OFFSCREEN_CHECK_OBJ(self->py_offscreen);
if (self->level == -1) {
PyErr_SetString(PyExc_RuntimeError, "Not yet in use\n");
return NULL;
return nullptr;
}
const int level = GPU_framebuffer_stack_level_get();
@@ -141,59 +141,59 @@ static PyObject *pygpu_offscreen_stack_context_exit(OffScreenStackContext *self,
static PyMethodDef pygpu_offscreen_stack_context__tp_methods[] = {
{"__enter__", (PyCFunction)pygpu_offscreen_stack_context_enter, METH_NOARGS},
{"__exit__", (PyCFunction)pygpu_offscreen_stack_context_exit, METH_VARARGS},
{NULL},
{nullptr},
};
static PyTypeObject PyGPUOffscreenStackContext_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUFrameBufferStackContext",
/*tp_basicsize*/ sizeof(OffScreenStackContext),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_offscreen_stack_context__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ NULL,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_doc*/ nullptr,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_offscreen_stack_context__tp_methods,
/*tp_members*/ NULL,
/*tp_getset*/ NULL,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ nullptr,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_new*/ NULL,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ nullptr,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
PyDoc_STRVAR(pygpu_offscreen_bind_doc,
@@ -229,7 +229,7 @@ static PyObject *pygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, P
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
static const char *_keywords[] = {"restore", NULL};
static const char *_keywords[] = {"restore", nullptr};
static _PyArg_Parser _parser = {
"|$" /* Optional keyword only arguments. */
"O&" /* `restore` */
@@ -238,7 +238,7 @@ static PyObject *pygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, P
0,
};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, PyC_ParseBool, &restore)) {
return NULL;
return nullptr;
}
GPU_offscreen_unbind(self->ofs, restore);
@@ -252,16 +252,14 @@ static PyObject *pygpu_offscreen_unbind(BPyGPUOffScreen *self, PyObject *args, P
/** \name GPUOffscreen Type
* \{ */
static PyObject *pygpu_offscreen__tp_new(PyTypeObject *UNUSED(self),
PyObject *args,
PyObject *kwds)
static PyObject *pygpu_offscreen__tp_new(PyTypeObject * /*self*/, PyObject *args, PyObject *kwds)
{
GPUOffScreen *ofs = NULL;
GPUOffScreen *ofs = nullptr;
int width, height;
struct PyC_StringEnum pygpu_textureformat = {pygpu_framebuffer_color_texture_formats, GPU_RGBA8};
char err_out[256];
static const char *_keywords[] = {"width", "height", "format", NULL};
static const char *_keywords[] = {"width", "height", "format", nullptr};
static _PyArg_Parser _parser = {
"i" /* `width` */
"i" /* `height` */
@@ -274,14 +272,14 @@ static PyObject *pygpu_offscreen__tp_new(PyTypeObject *UNUSED(self),
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kwds, &_parser, &width, &height, PyC_ParseStringEnum, &pygpu_textureformat))
{
return NULL;
return nullptr;
}
if (GPU_context_active_get()) {
ofs = GPU_offscreen_create(width,
height,
true,
pygpu_textureformat.value_found,
eGPUTextureFormat(pygpu_textureformat.value_found),
GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_HOST_READ,
err_out);
}
@@ -289,25 +287,25 @@ static PyObject *pygpu_offscreen__tp_new(PyTypeObject *UNUSED(self),
STRNCPY(err_out, "No active GPU context found");
}
if (ofs == NULL) {
if (ofs == nullptr) {
PyErr_Format(PyExc_RuntimeError,
"gpu.offscreen.new(...) failed with '%s'",
err_out[0] ? err_out : "unknown error");
return NULL;
return nullptr;
}
return BPyGPUOffScreen_CreatePyObject(ofs);
}
PyDoc_STRVAR(pygpu_offscreen_width_doc, "Width of the texture.\n\n:type: `int`");
static PyObject *pygpu_offscreen_width_get(BPyGPUOffScreen *self, void *UNUSED(type))
static PyObject *pygpu_offscreen_width_get(BPyGPUOffScreen *self, void * /*type*/)
{
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
return PyLong_FromLong(GPU_offscreen_width(self->ofs));
}
PyDoc_STRVAR(pygpu_offscreen_height_doc, "Height of the texture.\n\n:type: `int`");
static PyObject *pygpu_offscreen_height_get(BPyGPUOffScreen *self, void *UNUSED(type))
static PyObject *pygpu_offscreen_height_get(BPyGPUOffScreen *self, void * /*type*/)
{
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
return PyLong_FromLong(GPU_offscreen_height(self->ofs));
@@ -315,7 +313,7 @@ static PyObject *pygpu_offscreen_height_get(BPyGPUOffScreen *self, void *UNUSED(
PyDoc_STRVAR(pygpu_offscreen_color_texture_doc,
"OpenGL bindcode for the color texture.\n\n:type: `int`");
static PyObject *pygpu_offscreen_color_texture_get(BPyGPUOffScreen *self, void *UNUSED(type))
static PyObject *pygpu_offscreen_color_texture_get(BPyGPUOffScreen *self, void * /*type*/)
{
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
GPUTexture *texture = GPU_offscreen_color_texture(self->ofs);
@@ -326,7 +324,7 @@ PyDoc_STRVAR(pygpu_offscreen_texture_color_doc,
"The color texture attached.\n"
"\n"
":type: :class:`gpu.types.GPUTexture`");
static PyObject *pygpu_offscreen_texture_color_get(BPyGPUOffScreen *self, void *UNUSED(type))
static PyObject *pygpu_offscreen_texture_color_get(BPyGPUOffScreen *self, void * /*type*/)
{
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
GPUTexture *texture = GPU_offscreen_color_texture(self->ofs);
@@ -381,7 +379,7 @@ static PyObject *pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *ar
"projection_matrix",
"do_color_management",
"draw_background",
NULL,
nullptr,
};
static _PyArg_Parser _parser = {
"O" /* `scene` */
@@ -412,12 +410,12 @@ static PyObject *pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *ar
&do_color_management,
PyC_ParseBool,
&draw_background) ||
(!(scene = PyC_RNA_AsPointer(py_scene, "Scene")) ||
!(view_layer = PyC_RNA_AsPointer(py_view_layer, "ViewLayer")) ||
!(v3d = PyC_RNA_AsPointer(py_view3d, "SpaceView3D")) ||
!(region = PyC_RNA_AsPointer(py_region, "Region"))))
(!(scene = static_cast<Scene *>(PyC_RNA_AsPointer(py_scene, "Scene"))) ||
!(view_layer = static_cast<ViewLayer *>(PyC_RNA_AsPointer(py_view_layer, "ViewLayer"))) ||
!(v3d = static_cast<View3D *>(PyC_RNA_AsPointer(py_view3d, "SpaceView3D"))) ||
!(region = static_cast<ARegion *>(PyC_RNA_AsPointer(py_region, "Region")))))
{
return NULL;
return nullptr;
}
BLI_assert(BKE_id_is_in_global_main(&scene->id));
@@ -443,7 +441,7 @@ static PyObject *pygpu_offscreen_draw_view3d(BPyGPUOffScreen *self, PyObject *ar
ED_view3d_draw_offscreen(depsgraph,
scene,
v3d->shading.type,
eDrawType(v3d->shading.type),
v3d,
region,
GPU_offscreen_width(self->ofs),
@@ -479,11 +477,11 @@ static PyObject *pygpu_offscreen_free(BPyGPUOffScreen *self)
if (self->viewport) {
GPU_viewport_free(self->viewport);
self->viewport = NULL;
self->viewport = nullptr;
}
GPU_offscreen_free(self->ofs);
self->ofs = NULL;
self->ofs = nullptr;
Py_RETURN_NONE;
}
#endif
@@ -502,17 +500,25 @@ static void BPyGPUOffScreen__tp_dealloc(BPyGPUOffScreen *self)
static PyGetSetDef pygpu_offscreen__tp_getseters[] = {
{"color_texture",
(getter)pygpu_offscreen_color_texture_get,
(setter)NULL,
(setter) nullptr,
pygpu_offscreen_color_texture_doc,
NULL},
nullptr},
{"texture_color",
(getter)pygpu_offscreen_texture_color_get,
(setter)NULL,
(setter) nullptr,
pygpu_offscreen_texture_color_doc,
NULL},
{"width", (getter)pygpu_offscreen_width_get, (setter)NULL, pygpu_offscreen_width_doc, NULL},
{"height", (getter)pygpu_offscreen_height_get, (setter)NULL, pygpu_offscreen_height_doc, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
nullptr},
{"width",
(getter)pygpu_offscreen_width_get,
(setter) nullptr,
pygpu_offscreen_width_doc,
nullptr},
{"height",
(getter)pygpu_offscreen_height_get,
(setter) nullptr,
pygpu_offscreen_height_doc,
nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
};
static PyMethodDef pygpu_offscreen__tp_methods[] = {
@@ -528,7 +534,7 @@ static PyMethodDef pygpu_offscreen__tp_methods[] = {
#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
{"free", (PyCFunction)pygpu_offscreen_free, METH_NOARGS, pygpu_offscreen_free_doc},
#endif
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_offscreen__tp_doc,
@@ -548,55 +554,55 @@ PyDoc_STRVAR(pygpu_offscreen__tp_doc,
" `RGBA32F`,\n"
" :type format: str\n");
PyTypeObject BPyGPUOffScreen_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUOffScreen",
/*tp_basicsize*/ sizeof(BPyGPUOffScreen),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)BPyGPUOffScreen__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_compare*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_compare*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ pygpu_offscreen__tp_doc,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_offscreen__tp_methods,
/*tp_members*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ pygpu_offscreen__tp_getseters,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_offscreen__tp_new,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */
@@ -611,7 +617,7 @@ PyObject *BPyGPUOffScreen_CreatePyObject(GPUOffScreen *ofs)
self = PyObject_New(BPyGPUOffScreen, &BPyGPUOffScreen_Type);
self->ofs = ofs;
self->viewport = NULL;
self->viewport = nullptr;
return (PyObject *)self;
}

View File

@@ -10,6 +10,10 @@
#include "BLI_compiler_attrs.h"
#ifdef __cplusplus
extern "C" {
#endif
extern PyTypeObject BPyGPUOffScreen_Type;
#define BPyGPUOffScreen_Check(v) (Py_TYPE(v) == &BPyGPUOffScreen_Type)
@@ -23,3 +27,7 @@ typedef struct BPyGPUOffScreen {
} BPyGPUOffScreen;
PyObject *BPyGPUOffScreen_CreatePyObject(struct GPUOffScreen *ofs) ATTR_NONNULL(1);
#ifdef __cplusplus
}
#endif

View File

@@ -30,7 +30,7 @@ PyDoc_STRVAR(pygpu_platform_vendor_get_doc,
"\n"
" :return: Vendor name.\n"
" :rtype: str\n");
static PyObject *pygpu_platform_vendor_get(PyObject *UNUSED(self))
static PyObject *pygpu_platform_vendor_get(PyObject * /*self*/)
{
return PyUnicode_FromString(GPU_platform_vendor());
}
@@ -42,7 +42,7 @@ PyDoc_STRVAR(pygpu_platform_renderer_get_doc,
"\n"
" :return: GPU name.\n"
" :rtype: str\n");
static PyObject *pygpu_platform_renderer_get(PyObject *UNUSED(self))
static PyObject *pygpu_platform_renderer_get(PyObject * /*self*/)
{
return PyUnicode_FromString(GPU_platform_renderer());
}
@@ -54,7 +54,7 @@ PyDoc_STRVAR(pygpu_platform_version_get_doc,
"\n"
" :return: Driver version.\n"
" :rtype: str\n");
static PyObject *pygpu_platform_version_get(PyObject *UNUSED(self))
static PyObject *pygpu_platform_version_get(PyObject * /*self*/)
{
return PyUnicode_FromString(GPU_platform_version());
}
@@ -67,7 +67,7 @@ PyDoc_STRVAR(
"\n"
" :return: Device type ('APPLE', 'NVIDIA', 'AMD', 'INTEL', 'SOFTWARE', 'UNKNOWN').\n"
" :rtype: str\n");
static PyObject *pygpu_platform_device_type_get(PyObject *UNUSED(self))
static PyObject *pygpu_platform_device_type_get(PyObject * /*self*/)
{
if (GPU_type_matches(GPU_DEVICE_APPLE, GPU_OS_ANY, GPU_DRIVER_ANY)) {
return PyUnicode_FromString("APPLE");
@@ -94,7 +94,7 @@ PyDoc_STRVAR(pygpu_platform_backend_type_get_doc,
"\n"
" :return: Backend type ('OPENGL', 'VULKAN', 'METAL', 'NONE', 'UNKNOWN').\n"
" :rtype: str\n");
static PyObject *pygpu_platform_backend_type_get(PyObject *UNUSED(self))
static PyObject *pygpu_platform_backend_type_get(PyObject * /*self*/)
{
switch (GPU_backend_get_type()) {
case GPU_BACKEND_VULKAN:
@@ -138,7 +138,7 @@ static PyMethodDef pygpu_platform__tp_methods[] = {
(PyCFunction)pygpu_platform_backend_type_get,
METH_NOARGS,
pygpu_platform_backend_type_get_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_platform__tp_doc, "This module provides access to GPU Platform definitions.");
@@ -148,10 +148,10 @@ static PyModuleDef pygpu_platform_module_def = {
/*m_doc*/ pygpu_platform__tp_doc,
/*m_size*/ 0,
/*m_methods*/ pygpu_platform__tp_methods,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
PyObject *bpygpu_platform_init(void)

View File

@@ -8,4 +8,12 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
PyObject *bpygpu_platform_init(void);
#ifdef __cplusplus
}
#endif

View File

@@ -36,11 +36,11 @@ PyDoc_STRVAR(pygpu_select_load_id_doc,
"\n"
" :arg id: Number (32-bit uint).\n"
" :type select: int\n");
static PyObject *pygpu_select_load_id(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_select_load_id(PyObject * /*self*/, PyObject *value)
{
uint id;
if ((id = PyC_Long_AsU32(value)) == (uint)-1) {
return NULL;
return nullptr;
}
GPU_select_load_id(id);
Py_RETURN_NONE;
@@ -55,7 +55,7 @@ static PyObject *pygpu_select_load_id(PyObject *UNUSED(self), PyObject *value)
static PyMethodDef pygpu_select__tp_methods[] = {
/* Manage Stack */
{"load_id", (PyCFunction)pygpu_select_load_id, METH_O, pygpu_select_load_id_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_select__tp_doc, "This module provides access to selection.");
@@ -65,10 +65,10 @@ static PyModuleDef pygpu_select_module_def = {
/*m_doc*/ pygpu_select__tp_doc,
/*m_size*/ 0,
/*m_methods*/ pygpu_select__tp_methods,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
PyObject *bpygpu_select_init(void)

View File

@@ -8,4 +8,12 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
PyObject *bpygpu_select_init(void);
#ifdef __cplusplus
}
#endif

View File

@@ -67,13 +67,13 @@ static const struct PyC_StringEnumItems pygpu_shader_builtin_items[] = {
{GPU_SHADER_3D_POLYLINE_FLAT_COLOR, "POLYLINE_FLAT_COLOR"},
{GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR, "POLYLINE_SMOOTH_COLOR"},
{GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, "POLYLINE_UNIFORM_COLOR"},
{0, NULL},
{0, nullptr},
};
static const struct PyC_StringEnumItems pygpu_shader_config_items[] = {
{GPU_SHADER_CFG_DEFAULT, "DEFAULT"},
{GPU_SHADER_CFG_CLIPPED, "CLIPPED"},
{0, NULL},
{0, nullptr},
};
static int pygpu_shader_uniform_location_get(GPUShader *shader,
@@ -95,7 +95,7 @@ static int pygpu_shader_uniform_location_get(GPUShader *shader,
/** \name Shader Type
* \{ */
static PyObject *pygpu_shader__tp_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
static PyObject *pygpu_shader__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds)
{
struct {
const char *vertexcode;
@@ -107,7 +107,7 @@ static PyObject *pygpu_shader__tp_new(PyTypeObject *UNUSED(type), PyObject *args
} params = {0};
static const char *_keywords[] = {
"vertexcode", "fragcode", "geocode", "libcode", "defines", "name", NULL};
"vertexcode", "fragcode", "geocode", "libcode", "defines", "name", nullptr};
static _PyArg_Parser _parser = {
"s" /* `vertexcode` */
"s" /* `fragcode` */
@@ -130,7 +130,7 @@ static PyObject *pygpu_shader__tp_new(PyTypeObject *UNUSED(type), PyObject *args
&params.defines,
&params.name))
{
return NULL;
return nullptr;
}
GPUShader *shader = GPU_shader_create_from_python(params.vertexcode,
@@ -140,9 +140,9 @@ static PyObject *pygpu_shader__tp_new(PyTypeObject *UNUSED(type), PyObject *args
params.defines,
params.name);
if (shader == NULL) {
if (shader == nullptr) {
PyErr_SetString(PyExc_Exception, "Shader Compile Error, see console for more details");
return NULL;
return nullptr;
}
return BPyGPUShader_CreatePyObject(shader, false);
@@ -171,15 +171,15 @@ PyDoc_STRVAR(pygpu_shader_uniform_from_name_doc,
static PyObject *pygpu_shader_uniform_from_name(BPyGPUShader *self, PyObject *arg)
{
const char *name = PyUnicode_AsUTF8(arg);
if (name == NULL) {
return NULL;
if (name == nullptr) {
return nullptr;
}
const int uniform = pygpu_shader_uniform_location_get(
self->shader, name, "GPUShader.get_uniform");
if (uniform == -1) {
return NULL;
return nullptr;
}
return PyLong_FromLong(uniform);
@@ -197,15 +197,15 @@ PyDoc_STRVAR(pygpu_shader_uniform_block_from_name_doc,
static PyObject *pygpu_shader_uniform_block_from_name(BPyGPUShader *self, PyObject *arg)
{
const char *name = PyUnicode_AsUTF8(arg);
if (name == NULL) {
return NULL;
if (name == nullptr) {
return nullptr;
}
const int uniform = GPU_shader_get_uniform_block(self->shader, name);
if (uniform == -1) {
PyErr_Format(PyExc_ValueError, "GPUShader.get_uniform_block: uniform %.32s not found", name);
return NULL;
return nullptr;
}
return PyLong_FromLong(uniform);
@@ -269,11 +269,12 @@ static PyObject *pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject
if (!pygpu_shader_uniform_vector_impl(
args, sizeof(float), &location, &length, &count, &pybuffer)) {
return NULL;
return nullptr;
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_float_ex(self->shader, location, length, count, pybuffer.buf);
GPU_shader_uniform_float_ex(
self->shader, location, length, count, static_cast<const float *>(pybuffer.buf));
PyBuffer_Release(&pybuffer);
@@ -292,11 +293,12 @@ static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *a
if (!pygpu_shader_uniform_vector_impl(args, sizeof(int), &location, &length, &count, &pybuffer))
{
return NULL;
return nullptr;
}
GPU_shader_bind(self->shader);
GPU_shader_uniform_int_ex(self->shader, location, length, count, pybuffer.buf);
GPU_shader_uniform_int_ex(
self->shader, location, length, count, static_cast<const int *>(pybuffer.buf));
PyBuffer_Release(&pybuffer);
@@ -322,7 +324,7 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args)
} params;
if (!PyArg_ParseTuple(args, "sO:GPUShader.uniform_bool", &params.id, &params.seq)) {
return NULL;
return nullptr;
}
int values[4];
@@ -330,7 +332,7 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args)
int ret = -1;
if (PySequence_Check(params.seq)) {
PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix);
if (seq_fast == NULL) {
if (seq_fast == nullptr) {
PyErr_Format(PyExc_TypeError,
"%s: expected a sequence, got %s",
error_prefix,
@@ -361,13 +363,13 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args)
}
if (ret == -1) {
return NULL;
return nullptr;
}
const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix);
if (location == -1) {
return NULL;
return nullptr;
}
GPU_shader_bind(self->shader);
@@ -395,7 +397,7 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args)
} params;
if (!PyArg_ParseTuple(args, "sO:GPUShader.uniform_float", &params.id, &params.seq)) {
return NULL;
return nullptr;
}
float values[16];
@@ -412,11 +414,11 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args)
else if (MatrixObject_Check(params.seq)) {
MatrixObject *mat = (MatrixObject *)params.seq;
if (BaseMath_ReadCallback(mat) == -1) {
return NULL;
return nullptr;
}
if ((mat->row_num != mat->col_num) || !ELEM(mat->row_num, 3, 4)) {
PyErr_SetString(PyExc_ValueError, "Expected 3x3 or 4x4 matrix");
return NULL;
return nullptr;
}
length = mat->row_num * mat->col_num;
memcpy(values, mat->matrix, sizeof(float) * length);
@@ -424,20 +426,20 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args)
else {
length = mathutils_array_parse(values, 2, 16, params.seq, "");
if (length == -1) {
return NULL;
return nullptr;
}
}
if (!ELEM(length, 1, 2, 3, 4, 9, 16)) {
PyErr_SetString(PyExc_TypeError,
"Expected a single float or a sequence of floats of length 1..4, 9 or 16.");
return NULL;
return nullptr;
}
const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix);
if (location == -1) {
return NULL;
return nullptr;
}
GPU_shader_bind(self->shader);
@@ -465,7 +467,7 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args)
} params;
if (!PyArg_ParseTuple(args, "sO:GPUShader.uniform_int", &params.id, &params.seq)) {
return NULL;
return nullptr;
}
int values[4];
@@ -479,7 +481,7 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args)
}
else {
PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix);
if (seq_fast == NULL) {
if (seq_fast == nullptr) {
PyErr_Format(PyExc_TypeError,
"%s: expected a sequence, got %s",
error_prefix,
@@ -503,13 +505,13 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args)
}
}
if (ret == -1) {
return NULL;
return nullptr;
}
const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix);
if (location == -1) {
return NULL;
return nullptr;
}
GPU_shader_bind(self->shader);
@@ -534,7 +536,7 @@ static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args
if (!PyArg_ParseTuple(
args, "sO!:GPUShader.uniform_sampler", &name, &BPyGPUTexture_Type, &py_texture))
{
return NULL;
return nullptr;
}
GPU_shader_bind(self->shader);
@@ -561,7 +563,7 @@ static PyObject *pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args)
BPyGPUUniformBuf *py_ubo;
if (!PyArg_ParseTuple(
args, "sO!:GPUShader.uniform_block", &name, &BPyGPUUniformBuf_Type, &py_ubo)) {
return NULL;
return nullptr;
}
int binding = GPU_shader_get_ubo_binding(self->shader, name);
@@ -569,7 +571,7 @@ static PyObject *pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args)
PyErr_SetString(
PyExc_BufferError,
"GPUShader.uniform_block: uniform block not found, make sure the name is correct");
return NULL;
return nullptr;
}
GPU_shader_bind(self->shader);
@@ -590,15 +592,15 @@ PyDoc_STRVAR(pygpu_shader_attr_from_name_doc,
static PyObject *pygpu_shader_attr_from_name(BPyGPUShader *self, PyObject *arg)
{
const char *name = PyUnicode_AsUTF8(arg);
if (name == NULL) {
return NULL;
if (name == nullptr) {
return nullptr;
}
const int attr = GPU_shader_get_attribute(self->shader, name);
if (attr == -1) {
PyErr_Format(PyExc_ValueError, "GPUShader.attr_from_name: attribute %.32s not found", name);
return NULL;
return nullptr;
}
return PyLong_FromLong(attr);
@@ -611,9 +613,9 @@ PyDoc_STRVAR(pygpu_shader_format_calc_doc,
"\n"
" :return: vertex attribute format for the shader\n"
" :rtype: :class:`gpu.types.GPUVertFormat`\n");
static PyObject *pygpu_shader_format_calc(BPyGPUShader *self, PyObject *UNUSED(arg))
static PyObject *pygpu_shader_format_calc(BPyGPUShader *self, PyObject * /*arg*/)
{
BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(NULL);
BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(nullptr);
GPU_vertformat_from_shader(&ret->fmt, self->shader);
return (PyObject *)ret;
}
@@ -626,7 +628,7 @@ PyDoc_STRVAR(
"\n"
" :return: tuples containing information about the attributes in order (name, type)\n"
" :rtype: tuple\n");
static PyObject *pygpu_shader_attrs_info_get(BPyGPUShader *self, PyObject *UNUSED(arg))
static PyObject *pygpu_shader_attrs_info_get(BPyGPUShader *self, PyObject * /*arg*/)
{
uint attr_len = GPU_shader_get_attribute_len(self->shader);
int location_test = 0, attrs_added = 0;
@@ -706,7 +708,7 @@ static PyMethodDef pygpu_shader__tp_methods[] = {
(PyCFunction)pygpu_shader_attrs_info_get,
METH_NOARGS,
pygpu_shader_attrs_info_get_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_shader_name_doc,
@@ -719,15 +721,19 @@ static PyObject *pygpu_shader_name(BPyGPUShader *self)
PyDoc_STRVAR(
pygpu_shader_program_doc,
"The name of the program object for use by the OpenGL API (read-only).\n\n:type: int");
static PyObject *pygpu_shader_program_get(BPyGPUShader *self, void *UNUSED(closure))
static PyObject *pygpu_shader_program_get(BPyGPUShader *self, void * /*closure*/)
{
return PyLong_FromLong(GPU_shader_get_program(self->shader));
}
static PyGetSetDef pygpu_shader__tp_getseters[] = {
{"program", (getter)pygpu_shader_program_get, (setter)NULL, pygpu_shader_program_doc, NULL},
{"name", (getter)pygpu_shader_name, (setter)NULL, pygpu_shader_name_doc, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
{"program",
(getter)pygpu_shader_program_get,
(setter) nullptr,
pygpu_shader_program_doc,
nullptr},
{"name", (getter)pygpu_shader_name, (setter) nullptr, pygpu_shader_name_doc, nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
};
static void pygpu_shader__tp_dealloc(BPyGPUShader *self)
@@ -771,55 +777,55 @@ PyDoc_STRVAR(
" :arg name: Name of shader code, for debugging purposes.\n"
" :type value: str\n");
PyTypeObject BPyGPUShader_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUShader",
/*tp_basicsize*/ sizeof(BPyGPUShader),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_shader__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ pygpu_shader__tp_doc,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_shader__tp_methods,
/*tp_members*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ pygpu_shader__tp_getseters,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_shader__tp_new,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */
@@ -832,7 +838,7 @@ PyDoc_STRVAR(pygpu_shader_unbind_doc,
".. function:: unbind()\n"
"\n"
" Unbind the bound shader object.\n");
static PyObject *pygpu_shader_unbind(BPyGPUShader *UNUSED(self))
static PyObject *pygpu_shader_unbind(BPyGPUShader * /*self*/)
{
GPU_shader_unbind();
Py_RETURN_NONE;
@@ -859,12 +865,12 @@ PyDoc_STRVAR(
" :type config: str\n"
" :return: Shader object corresponding to the given name.\n"
" :rtype: :class:`bpy.types.GPUShader`\n");
static PyObject *pygpu_shader_from_builtin(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
static PyObject *pygpu_shader_from_builtin(PyObject * /*self*/, PyObject *args, PyObject *kwds)
{
struct PyC_StringEnum pygpu_bultinshader = {pygpu_shader_builtin_items};
struct PyC_StringEnum pygpu_config = {pygpu_shader_config_items, GPU_SHADER_CFG_DEFAULT};
static const char *_keywords[] = {"shader_name", "config", NULL};
static const char *_keywords[] = {"shader_name", "config", nullptr};
static _PyArg_Parser _parser = {
"O&" /* `shader_name` */
"|$" /* Optional keyword only arguments. */
@@ -881,11 +887,12 @@ static PyObject *pygpu_shader_from_builtin(PyObject *UNUSED(self), PyObject *arg
PyC_ParseStringEnum,
&pygpu_config))
{
return NULL;
return nullptr;
}
GPUShader *shader = GPU_shader_get_builtin_shader_with_config(pygpu_bultinshader.value_found,
pygpu_config.value_found);
GPUShader *shader = GPU_shader_get_builtin_shader_with_config(
eGPUBuiltinShader(pygpu_bultinshader.value_found),
eGPUShaderConfig(pygpu_config.value_found));
return BPyGPUShader_CreatePyObject(shader, true);
}
@@ -899,24 +906,23 @@ PyDoc_STRVAR(pygpu_shader_create_from_info_doc,
" :type shader_info: :class:`bpy.types.GPUShaderCreateInfo`\n"
" :return: Shader object corresponding to the given name.\n"
" :rtype: :class:`bpy.types.GPUShader`\n");
static PyObject *pygpu_shader_create_from_info(BPyGPUShader *UNUSED(self),
BPyGPUShaderCreateInfo *o)
static PyObject *pygpu_shader_create_from_info(BPyGPUShader * /*self*/, BPyGPUShaderCreateInfo *o)
{
if (!BPyGPUShaderCreateInfo_Check(o)) {
PyErr_Format(PyExc_TypeError, "Expected a GPUShaderCreateInfo, got %s", Py_TYPE(o)->tp_name);
return NULL;
return nullptr;
}
char error[128];
if (!GPU_shader_create_info_check_error(o->info, error)) {
PyErr_SetString(PyExc_Exception, error);
return NULL;
return nullptr;
}
GPUShader *shader = GPU_shader_create_from_info(o->info);
if (!shader) {
PyErr_SetString(PyExc_Exception, "Shader Compile Error, see console for more details");
return NULL;
return nullptr;
}
return BPyGPUShader_CreatePyObject(shader, false);
@@ -932,7 +938,7 @@ static PyMethodDef pygpu_shader_module__tp_methods[] = {
(PyCFunction)pygpu_shader_create_from_info,
METH_O,
pygpu_shader_create_from_info_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_shader_module__tp_doc,
@@ -952,10 +958,10 @@ static PyModuleDef pygpu_shader_module_def = {
/*m_doc*/ pygpu_shader_module__tp_doc,
/*m_size*/ 0,
/*m_methods*/ pygpu_shader_module__tp_methods,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
/** \} */

View File

@@ -12,6 +12,10 @@
# include "../generic/py_capi_utils.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Make sure that there is always a reference count for PyObjects of type String as the strings are
* passed by reference in the #GPUStageInterfaceInfo and #GPUShaderCreateInfo APIs. */
#define USE_GPU_PY_REFERENCES
@@ -31,10 +35,6 @@ typedef struct BPyGPUShader {
PyObject *BPyGPUShader_CreatePyObject(struct GPUShader *shader, bool is_builtin);
PyObject *bpygpu_shader_init(void);
#ifdef __cplusplus
extern "C" {
#endif
/* gpu_py_shader_create_info.cc */
extern const struct PyC_StringEnumItems pygpu_attrtype_items[];

View File

@@ -42,7 +42,7 @@ static const struct PyC_StringEnumItems pygpu_state_blend_items[] = {
* {GPU_BLEND_BACKGROUND, "BACKGROUND"},
* {GPU_BLEND_CUSTOM, "CUSTOM"},
*/
{0, NULL},
{0, nullptr},
};
static const struct PyC_StringEnumItems pygpu_state_depthtest_items[] = {
@@ -53,14 +53,14 @@ static const struct PyC_StringEnumItems pygpu_state_depthtest_items[] = {
{GPU_DEPTH_EQUAL, "EQUAL"},
{GPU_DEPTH_GREATER, "GREATER"},
{GPU_DEPTH_GREATER_EQUAL, "GREATER_EQUAL"},
{0, NULL},
{0, nullptr},
};
static const struct PyC_StringEnumItems pygpu_state_faceculling_items[] = {
{GPU_CULL_NONE, "NONE"},
{GPU_CULL_FRONT, "FRONT"},
{GPU_CULL_BACK, "BACK"},
{0, NULL},
{0, nullptr},
};
/** \} */
@@ -91,13 +91,13 @@ PyDoc_STRVAR(
//" * ``BACKGROUND`` .\n"
//" * ``CUSTOM`` .\n"
" :type mode: str\n");
static PyObject *pygpu_state_blend_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_blend_set(PyObject * /*self*/, PyObject *value)
{
struct PyC_StringEnum pygpu_blend = {pygpu_state_blend_items};
if (!PyC_ParseStringEnum(value, &pygpu_blend)) {
return NULL;
return nullptr;
}
GPU_blend(pygpu_blend.value_found);
GPU_blend(eGPUBlend(pygpu_blend.value_found));
Py_RETURN_NONE;
}
@@ -106,7 +106,7 @@ PyDoc_STRVAR(pygpu_state_blend_get_doc,
"\n"
" Current blending equation.\n"
"\n");
static PyObject *pygpu_state_blend_get(PyObject *UNUSED(self))
static PyObject *pygpu_state_blend_get(PyObject * /*self*/)
{
eGPUBlend blend = GPU_blend_get();
return PyUnicode_FromString(PyC_StringEnum_FindIDFromValue(pygpu_state_blend_items, blend));
@@ -119,11 +119,11 @@ PyDoc_STRVAR(pygpu_state_clip_distances_set_doc,
"\n"
" :arg distances_enabled: Number of clip distances enabled.\n"
" :type distances_enabled: int\n");
static PyObject *pygpu_state_clip_distances_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_clip_distances_set(PyObject * /*self*/, PyObject *value)
{
int distances_enabled = (int)PyLong_AsUnsignedLong(value);
if (distances_enabled == -1) {
return NULL;
return nullptr;
}
if (distances_enabled > 6) {
@@ -143,13 +143,13 @@ PyDoc_STRVAR(pygpu_state_depth_test_set_doc,
" Possible values are `NONE`, `ALWAYS`, `LESS`, `LESS_EQUAL`, `EQUAL`, "
"`GREATER` and `GREATER_EQUAL`.\n"
" :type mode: str\n");
static PyObject *pygpu_state_depth_test_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_depth_test_set(PyObject * /*self*/, PyObject *value)
{
struct PyC_StringEnum pygpu_depth_test = {pygpu_state_depthtest_items};
if (!PyC_ParseStringEnum(value, &pygpu_depth_test)) {
return NULL;
return nullptr;
}
GPU_depth_test(pygpu_depth_test.value_found);
GPU_depth_test(eGPUDepthTest(pygpu_depth_test.value_found));
Py_RETURN_NONE;
}
@@ -158,7 +158,7 @@ PyDoc_STRVAR(pygpu_state_depth_test_get_doc,
"\n"
" Current depth_test equation.\n"
"\n");
static PyObject *pygpu_state_depth_test_get(PyObject *UNUSED(self))
static PyObject *pygpu_state_depth_test_get(PyObject * /*self*/)
{
eGPUDepthTest test = GPU_depth_test_get();
return PyUnicode_FromString(PyC_StringEnum_FindIDFromValue(pygpu_state_depthtest_items, test));
@@ -171,11 +171,11 @@ PyDoc_STRVAR(pygpu_state_depth_mask_set_doc,
"\n"
" :arg value: True for writing to the depth component.\n"
" :type near: bool\n");
static PyObject *pygpu_state_depth_mask_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_depth_mask_set(PyObject * /*self*/, PyObject *value)
{
bool write_to_depth;
if (!PyC_ParseBool(value, &write_to_depth)) {
return NULL;
return nullptr;
}
GPU_depth_mask(write_to_depth);
Py_RETURN_NONE;
@@ -185,7 +185,7 @@ PyDoc_STRVAR(pygpu_state_depth_mask_get_doc,
".. function:: depth_mask_get()\n"
"\n"
" Writing status in the depth component.\n");
static PyObject *pygpu_state_depth_mask_get(PyObject *UNUSED(self))
static PyObject *pygpu_state_depth_mask_get(PyObject * /*self*/)
{
return PyBool_FromLong(GPU_depth_mask_get());
}
@@ -200,11 +200,11 @@ PyDoc_STRVAR(pygpu_state_viewport_set_doc,
" :type x, y: int\n"
" :arg xsize, ysize: width and height of the viewport_set.\n"
" :type xsize, ysize: int\n");
static PyObject *pygpu_state_viewport_set(PyObject *UNUSED(self), PyObject *args)
static PyObject *pygpu_state_viewport_set(PyObject * /*self*/, PyObject *args)
{
int x, y, xsize, ysize;
if (!PyArg_ParseTuple(args, "iiii:viewport_set", &x, &y, &xsize, &ysize)) {
return NULL;
return nullptr;
}
GPU_viewport(x, y, xsize, ysize);
@@ -215,7 +215,7 @@ PyDoc_STRVAR(pygpu_state_viewport_get_doc,
".. function:: viewport_get()\n"
"\n"
" Viewport of the active framebuffer.\n");
static PyObject *pygpu_state_viewport_get(PyObject *UNUSED(self), PyObject *UNUSED(args))
static PyObject *pygpu_state_viewport_get(PyObject * /*self*/, PyObject * /*args*/)
{
int viewport[4];
GPU_viewport_size_get_i(viewport);
@@ -239,11 +239,11 @@ PyDoc_STRVAR(pygpu_state_scissor_set_doc,
" :type x, y: int\n"
" :arg xsize, ysize: width and height of the scissor rectangle.\n"
" :type xsize, ysize: int\n");
static PyObject *pygpu_state_scissor_set(PyObject *UNUSED(self), PyObject *args)
static PyObject *pygpu_state_scissor_set(PyObject * /*self*/, PyObject *args)
{
int x, y, xsize, ysize;
if (!PyArg_ParseTuple(args, "iiii:scissor_set", &x, &y, &xsize, &ysize)) {
return NULL;
return nullptr;
}
GPU_scissor(x, y, xsize, ysize);
@@ -261,7 +261,7 @@ PyDoc_STRVAR(pygpu_state_scissor_get_doc,
" x, y: lower left corner of the scissor rectangle, in pixels.\n"
" xsize, ysize: width and height of the scissor rectangle.\n"
" :rtype: tuple(int, int, int, int)\n");
static PyObject *pygpu_state_scissor_get(PyObject *UNUSED(self), PyObject *UNUSED(args))
static PyObject *pygpu_state_scissor_get(PyObject * /*self*/, PyObject * /*args*/)
{
int scissor[4];
GPU_scissor_get(scissor);
@@ -284,11 +284,11 @@ PyDoc_STRVAR(pygpu_state_scissor_test_set_doc,
" True - enable scissor testing.\n"
" False - disable scissor testing.\n"
" :type enable: bool\n");
static PyObject *pygpu_state_scissor_test_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_scissor_test_set(PyObject * /*self*/, PyObject *value)
{
bool enabled;
if (!PyC_ParseBool(value, &enabled)) {
return NULL;
return nullptr;
}
GPU_scissor_test(enabled);
@@ -302,11 +302,11 @@ PyDoc_STRVAR(pygpu_state_line_width_set_doc,
"\n"
" :arg size: New width.\n"
" :type mode: float\n");
static PyObject *pygpu_state_line_width_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_line_width_set(PyObject * /*self*/, PyObject *value)
{
float width = (float)PyFloat_AsDouble(value);
if (PyErr_Occurred()) {
return NULL;
return nullptr;
}
GPU_line_width(width);
@@ -317,7 +317,7 @@ PyDoc_STRVAR(pygpu_state_line_width_get_doc,
".. function:: line_width_get()\n"
"\n"
" Current width of rasterized lines.\n");
static PyObject *pygpu_state_line_width_get(PyObject *UNUSED(self))
static PyObject *pygpu_state_line_width_get(PyObject * /*self*/)
{
float width = GPU_line_width_get();
return PyFloat_FromDouble((double)width);
@@ -330,11 +330,11 @@ PyDoc_STRVAR(pygpu_state_point_size_set_doc,
"\n"
" :arg size: New diameter.\n"
" :type mode: float\n");
static PyObject *pygpu_state_point_size_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_point_size_set(PyObject * /*self*/, PyObject *value)
{
float size = (float)PyFloat_AsDouble(value);
if (PyErr_Occurred()) {
return NULL;
return nullptr;
}
GPU_point_size(size);
@@ -348,11 +348,11 @@ PyDoc_STRVAR(pygpu_state_color_mask_set_doc,
"\n"
" :arg r, g, b, a: components red, green, blue, and alpha.\n"
" :type r, g, b, a: bool\n");
static PyObject *pygpu_state_color_mask_set(PyObject *UNUSED(self), PyObject *args)
static PyObject *pygpu_state_color_mask_set(PyObject * /*self*/, PyObject *args)
{
int r, g, b, a;
if (!PyArg_ParseTuple(args, "pppp:color_mask_set", &r, &g, &b, &a)) {
return NULL;
return nullptr;
}
GPU_color_mask((bool)r, (bool)g, (bool)b, (bool)a);
@@ -366,14 +366,14 @@ PyDoc_STRVAR(pygpu_state_face_culling_set_doc,
"\n"
" :arg mode: `NONE`, `FRONT` or `BACK`.\n"
" :type mode: str\n");
static PyObject *pygpu_state_face_culling_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_face_culling_set(PyObject * /*self*/, PyObject *value)
{
struct PyC_StringEnum pygpu_faceculling = {pygpu_state_faceculling_items};
if (!PyC_ParseStringEnum(value, &pygpu_faceculling)) {
return NULL;
return nullptr;
}
GPU_face_culling(pygpu_faceculling.value_found);
GPU_face_culling(eGPUFaceCullTest(pygpu_faceculling.value_found));
Py_RETURN_NONE;
}
@@ -384,11 +384,11 @@ PyDoc_STRVAR(pygpu_state_front_facing_set_doc,
"\n"
" :arg invert: True for clockwise polygons as front-facing.\n"
" :type mode: bool\n");
static PyObject *pygpu_state_front_facing_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_front_facing_set(PyObject * /*self*/, PyObject *value)
{
bool invert;
if (!PyC_ParseBool(value, &invert)) {
return NULL;
return nullptr;
}
GPU_front_facing(invert);
@@ -403,11 +403,11 @@ PyDoc_STRVAR(pygpu_state_program_point_size_set_doc,
"\n"
" :arg enable: True for shader builtin gl_PointSize.\n"
" :type enable: bool\n");
static PyObject *pygpu_state_program_point_size_set(PyObject *UNUSED(self), PyObject *value)
static PyObject *pygpu_state_program_point_size_set(PyObject * /*self*/, PyObject *value)
{
bool enable;
if (!PyC_ParseBool(value, &enable)) {
return NULL;
return nullptr;
}
GPU_program_point_size(enable);
@@ -418,7 +418,7 @@ PyDoc_STRVAR(pygpu_state_framebuffer_active_get_doc,
".. function:: framebuffer_active_get(enable)\n"
"\n"
" Return the active frame-buffer in context.\n");
static PyObject *pygpu_state_framebuffer_active_get(PyObject *UNUSED(self))
static PyObject *pygpu_state_framebuffer_active_get(PyObject * /*self*/)
{
GPUFrameBuffer *fb = GPU_framebuffer_active_get();
return BPyGPUFrameBuffer_CreatePyObject(fb, true);
@@ -506,7 +506,7 @@ static PyMethodDef pygpu_state__tp_methods[] = {
(PyCFunction)pygpu_state_framebuffer_active_get,
METH_NOARGS,
pygpu_state_framebuffer_active_get_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_state__tp_doc, "This module provides access to the gpu state.");
@@ -516,10 +516,10 @@ static PyModuleDef pygpu_state_module_def = {
/*m_doc*/ pygpu_state__tp_doc,
/*m_size*/ 0,
/*m_methods*/ pygpu_state__tp_methods,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
PyObject *bpygpu_state_init(void)

View File

@@ -8,4 +8,12 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
PyObject *bpygpu_state_init(void);
#ifdef __cplusplus
}
#endif

View File

@@ -78,12 +78,12 @@ static const struct PyC_StringEnumItems pygpu_textureformat_items[] = {
{GPU_DEPTH_COMPONENT32F, "DEPTH_COMPONENT32F"},
{GPU_DEPTH_COMPONENT24, "DEPTH_COMPONENT24"},
{GPU_DEPTH_COMPONENT16, "DEPTH_COMPONENT16"},
{0, NULL},
{0, nullptr},
};
static int pygpu_texture_valid_check(BPyGPUTexture *bpygpu_tex)
{
if (UNLIKELY(bpygpu_tex->tex == NULL)) {
if (UNLIKELY(bpygpu_tex->tex == nullptr)) {
PyErr_SetString(PyExc_ReferenceError,
#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
"GPU texture was freed, no further access is valid"
@@ -100,7 +100,7 @@ static int pygpu_texture_valid_check(BPyGPUTexture *bpygpu_tex)
#define BPYGPU_TEXTURE_CHECK_OBJ(bpygpu) \
{ \
if (UNLIKELY(pygpu_texture_valid_check(bpygpu) == -1)) { \
return NULL; \
return nullptr; \
} \
} \
((void)0)
@@ -111,17 +111,17 @@ static int pygpu_texture_valid_check(BPyGPUTexture *bpygpu_tex)
/** \name GPUTexture Type
* \{ */
static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *args, PyObject *kwds)
static PyObject *pygpu_texture__tp_new(PyTypeObject * /*self*/, PyObject *args, PyObject *kwds)
{
PyObject *py_size;
int size[3] = {1, 1, 1};
int layers = 0;
int is_cubemap = false;
struct PyC_StringEnum pygpu_textureformat = {pygpu_textureformat_items, GPU_RGBA8};
BPyGPUBuffer *pybuffer_obj = NULL;
BPyGPUBuffer *pybuffer_obj = nullptr;
char err_out[256] = "unknown error. See console";
static const char *_keywords[] = {"size", "layers", "is_cubemap", "format", "data", NULL};
static const char *_keywords[] = {"size", "layers", "is_cubemap", "format", "data", nullptr};
static _PyArg_Parser _parser = {
"O" /* `size` */
"|$" /* Optional keyword only arguments. */
@@ -144,7 +144,7 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *arg
&BPyGPU_BufferType,
&pybuffer_obj))
{
return NULL;
return nullptr;
}
int len = 1;
@@ -154,10 +154,10 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *arg
PyErr_Format(PyExc_ValueError,
"GPUTexture.__new__: \"size\" must be between 1 and 3 in length (got %d)",
len);
return NULL;
return nullptr;
}
if (PyC_AsArray(size, sizeof(*size), py_size, len, &PyLong_Type, "GPUTexture.__new__") == -1) {
return NULL;
return nullptr;
}
}
else if (PyLong_Check(py_size)) {
@@ -165,18 +165,19 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *arg
}
else {
PyErr_SetString(PyExc_ValueError, "GPUTexture.__new__: Expected an int or tuple as first arg");
return NULL;
return nullptr;
}
void *data = NULL;
void *data = nullptr;
if (pybuffer_obj) {
if (pybuffer_obj->format != GPU_DATA_FLOAT) {
PyErr_SetString(PyExc_ValueError,
"GPUTexture.__new__: Only Buffer of format `FLOAT` is currently supported");
return NULL;
return nullptr;
}
int component_len = GPU_texture_component_len(pygpu_textureformat.value_found);
int component_len = GPU_texture_component_len(
eGPUTextureFormat(pygpu_textureformat.value_found));
int component_size_expected = sizeof(float);
size_t data_space_expected = (size_t)size[0] * size[1] * size[2] * max_ii(1, layers) *
component_len * component_size_expected;
@@ -186,12 +187,12 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *arg
if (bpygpu_Buffer_size(pybuffer_obj) < data_space_expected) {
PyErr_SetString(PyExc_ValueError, "GPUTexture.__new__: Buffer size smaller than requested");
return NULL;
return nullptr;
}
data = pybuffer_obj->buf.as_void;
}
GPUTexture *tex = NULL;
GPUTexture *tex = nullptr;
if (is_cubemap && len != 1) {
STRNCPY(err_out,
"In cubemaps the same dimension represents height, width and depth. No tuple needed");
@@ -210,61 +211,97 @@ static PyObject *pygpu_texture__tp_new(PyTypeObject *UNUSED(self), PyObject *arg
eGPUTextureUsage usage = GPU_TEXTURE_USAGE_GENERAL;
if (is_cubemap) {
if (layers) {
tex = GPU_texture_create_cube_array(
name, size[0], layers, 1, pygpu_textureformat.value_found, usage, data);
tex = GPU_texture_create_cube_array(name,
size[0],
layers,
1,
eGPUTextureFormat(pygpu_textureformat.value_found),
usage,
static_cast<const float *>(data));
}
else {
tex = GPU_texture_create_cube(
name, size[0], 1, pygpu_textureformat.value_found, usage, data);
tex = GPU_texture_create_cube(name,
size[0],
1,
eGPUTextureFormat(pygpu_textureformat.value_found),
usage,
static_cast<const float *>(data));
}
}
else if (layers) {
if (len == 2) {
tex = GPU_texture_create_2d_array(
name, size[0], size[1], layers, 1, pygpu_textureformat.value_found, usage, data);
tex = GPU_texture_create_2d_array(name,
size[0],
size[1],
layers,
1,
eGPUTextureFormat(pygpu_textureformat.value_found),
usage,
static_cast<const float *>(data));
}
else {
tex = GPU_texture_create_1d_array(
name, size[0], layers, 1, pygpu_textureformat.value_found, usage, data);
tex = GPU_texture_create_1d_array(name,
size[0],
layers,
1,
eGPUTextureFormat(pygpu_textureformat.value_found),
usage,
static_cast<const float *>(data));
}
}
else if (len == 3) {
tex = GPU_texture_create_3d(
name, size[0], size[1], size[2], 1, pygpu_textureformat.value_found, usage, data);
tex = GPU_texture_create_3d(name,
size[0],
size[1],
size[2],
1,
eGPUTextureFormat(pygpu_textureformat.value_found),
usage,
data);
}
else if (len == 2) {
tex = GPU_texture_create_2d(
name, size[0], size[1], 1, pygpu_textureformat.value_found, usage, data);
tex = GPU_texture_create_2d(name,
size[0],
size[1],
1,
eGPUTextureFormat(pygpu_textureformat.value_found),
usage,
static_cast<const float *>(data));
}
else {
tex = GPU_texture_create_1d(name, size[0], 1, pygpu_textureformat.value_found, usage, data);
tex = GPU_texture_create_1d(name,
size[0],
1,
eGPUTextureFormat(pygpu_textureformat.value_found),
usage,
static_cast<const float *>(data));
}
}
if (tex == NULL) {
if (tex == nullptr) {
PyErr_Format(PyExc_RuntimeError, "gpu.texture.new(...) failed with '%s'", err_out);
return NULL;
return nullptr;
}
return BPyGPUTexture_CreatePyObject(tex, false);
}
PyDoc_STRVAR(pygpu_texture_width_doc, "Width of the texture.\n\n:type: `int`");
static PyObject *pygpu_texture_width_get(BPyGPUTexture *self, void *UNUSED(type))
static PyObject *pygpu_texture_width_get(BPyGPUTexture *self, void * /*type*/)
{
BPYGPU_TEXTURE_CHECK_OBJ(self);
return PyLong_FromLong(GPU_texture_width(self->tex));
}
PyDoc_STRVAR(pygpu_texture_height_doc, "Height of the texture.\n\n:type: `int`");
static PyObject *pygpu_texture_height_get(BPyGPUTexture *self, void *UNUSED(type))
static PyObject *pygpu_texture_height_get(BPyGPUTexture *self, void * /*type*/)
{
BPYGPU_TEXTURE_CHECK_OBJ(self);
return PyLong_FromLong(GPU_texture_height(self->tex));
}
PyDoc_STRVAR(pygpu_texture_format_doc, "Format of the texture.\n\n:type: `str`");
static PyObject *pygpu_texture_format_get(BPyGPUTexture *self, void *UNUSED(type))
static PyObject *pygpu_texture_format_get(BPyGPUTexture *self, void * /*type*/)
{
BPYGPU_TEXTURE_CHECK_OBJ(self);
eGPUTextureFormat format = GPU_texture_format(self->tex);
@@ -294,7 +331,7 @@ static PyObject *pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObje
PyObject *py_values;
static const char *_keywords[] = {"format", "value", NULL};
static const char *_keywords[] = {"format", "value", nullptr};
static _PyArg_Parser _parser = {
"$" /* Keyword only arguments. */
"O&" /* `format` */
@@ -306,24 +343,24 @@ static PyObject *pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObje
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kwds, &_parser, PyC_ParseStringEnum, &pygpu_dataformat, &py_values))
{
return NULL;
return nullptr;
}
int shape = PySequence_Size(py_values);
if (shape == -1) {
return NULL;
return nullptr;
}
if (shape > 4) {
PyErr_SetString(PyExc_AttributeError, "too many dimensions, max is 4");
return NULL;
return nullptr;
}
if (shape != 1 && ELEM(pygpu_dataformat.value_found, GPU_DATA_UINT_24_8, GPU_DATA_10_11_11_REV))
{
PyErr_SetString(PyExc_AttributeError,
"`UINT_24_8` and `10_11_11_REV` only support single values");
return NULL;
return nullptr;
}
memset(&values, 0, sizeof(values));
@@ -335,7 +372,7 @@ static PyObject *pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObje
(pygpu_dataformat.value_found == GPU_DATA_FLOAT) ? &PyFloat_Type : &PyLong_Type,
"clear") == -1)
{
return NULL;
return nullptr;
}
if (pygpu_dataformat.value_found == GPU_DATA_UBYTE) {
@@ -346,7 +383,7 @@ static PyObject *pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObje
values.c[3] = values.i[3];
}
GPU_texture_clear(self->tex, pygpu_dataformat.value_found, &values);
GPU_texture_clear(self->tex, eGPUDataFormat(pygpu_dataformat.value_found), &values);
Py_RETURN_NONE;
}
@@ -401,7 +438,7 @@ static PyObject *pygpu_texture_read(BPyGPUTexture *self)
void *buf = GPU_texture_read(self->tex, best_data_format, 0);
const Py_ssize_t shape[3] = {GPU_texture_height(self->tex),
GPU_texture_width(self->tex),
GPU_texture_component_len(tex_format)};
Py_ssize_t(GPU_texture_component_len(tex_format))};
int shape_len = (shape[2] == 1) ? 2 : 3;
return (PyObject *)BPyGPU_Buffer_CreatePyObject(best_data_format, shape, shape_len, buf);
@@ -418,7 +455,7 @@ static PyObject *pygpu_texture_free(BPyGPUTexture *self)
BPYGPU_TEXTURE_CHECK_OBJ(self);
GPU_texture_free(self->tex);
self->tex = NULL;
self->tex = nullptr;
Py_RETURN_NONE;
}
#endif
@@ -427,7 +464,7 @@ static void BPyGPUTexture__tp_dealloc(BPyGPUTexture *self)
{
if (self->tex) {
#ifndef GPU_NO_USE_PY_REFERENCES
GPU_texture_py_reference_set(self->tex, NULL);
GPU_texture_py_reference_set(self->tex, nullptr);
#endif
GPU_texture_free(self->tex);
}
@@ -435,10 +472,18 @@ static void BPyGPUTexture__tp_dealloc(BPyGPUTexture *self)
}
static PyGetSetDef pygpu_texture__tp_getseters[] = {
{"width", (getter)pygpu_texture_width_get, (setter)NULL, pygpu_texture_width_doc, NULL},
{"height", (getter)pygpu_texture_height_get, (setter)NULL, pygpu_texture_height_doc, NULL},
{"format", (getter)pygpu_texture_format_get, (setter)NULL, pygpu_texture_format_doc, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
{"width", (getter)pygpu_texture_width_get, (setter) nullptr, pygpu_texture_width_doc, nullptr},
{"height",
(getter)pygpu_texture_height_get,
(setter) nullptr,
pygpu_texture_height_doc,
nullptr},
{"format",
(getter)pygpu_texture_format_get,
(setter) nullptr,
pygpu_texture_format_doc,
nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
};
static PyMethodDef pygpu_texture__tp_methods[] = {
@@ -450,7 +495,7 @@ static PyMethodDef pygpu_texture__tp_methods[] = {
#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
{"free", (PyCFunction)pygpu_texture_free, METH_NOARGS, pygpu_texture_free_doc},
#endif
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(
@@ -514,55 +559,55 @@ PyDoc_STRVAR(
" :arg data: Buffer object to fill the texture.\n"
" :type data: :class:`gpu.types.Buffer`\n");
PyTypeObject BPyGPUTexture_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUTexture",
/*tp_basicsize*/ sizeof(BPyGPUTexture),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)BPyGPUTexture__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ pygpu_texture__tp_doc,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_texture__tp_methods,
/*tp_members*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ pygpu_texture__tp_getseters,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_texture__tp_new,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */
@@ -583,23 +628,23 @@ PyDoc_STRVAR(pygpu_texture_from_image_doc,
" :type image: :class:`bpy.types.Image`\n"
" :return: The GPUTexture used by the image.\n"
" :rtype: :class:`gpu.types.GPUTexture`\n");
static PyObject *pygpu_texture_from_image(PyObject *UNUSED(self), PyObject *arg)
static PyObject *pygpu_texture_from_image(PyObject * /*self*/, PyObject *arg)
{
Image *ima = PyC_RNA_AsPointer(arg, "Image");
if (ima == NULL) {
return NULL;
Image *ima = static_cast<Image *>(PyC_RNA_AsPointer(arg, "Image"));
if (ima == nullptr) {
return nullptr;
}
ImageUser iuser;
BKE_imageuser_default(&iuser);
GPUTexture *tex = BKE_image_get_gpu_texture(ima, &iuser, NULL);
GPUTexture *tex = BKE_image_get_gpu_texture(ima, &iuser, nullptr);
return BPyGPUTexture_CreatePyObject(tex, true);
}
static PyMethodDef pygpu_texture__m_methods[] = {
{"from_image", (PyCFunction)pygpu_texture_from_image, METH_O, pygpu_texture_from_image_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_texture__m_doc, "This module provides utils for textures.");
@@ -609,10 +654,10 @@ static PyModuleDef pygpu_texture_module_def = {
/*m_doc*/ pygpu_texture__m_doc,
/*m_size*/ 0,
/*m_methods*/ pygpu_texture__m_methods,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
/** \} */
@@ -624,7 +669,7 @@ static PyModuleDef pygpu_texture_module_def = {
int bpygpu_ParseTexture(PyObject *o, void *p)
{
if (o == Py_None) {
*(GPUTexture **)p = NULL;
*(GPUTexture **)p = nullptr;
return 1;
}
@@ -679,7 +724,7 @@ PyObject *BPyGPUTexture_CreatePyObject(GPUTexture *tex, bool shared_reference)
self->tex = tex;
#ifndef GPU_NO_USE_PY_REFERENCES
BLI_assert(GPU_texture_py_reference_get(tex) == NULL);
BLI_assert(GPU_texture_py_reference_get(tex) == nullptr);
GPU_texture_py_reference_set(tex, (void **)&self->tex);
#endif

View File

@@ -10,6 +10,10 @@
#include "BLI_compiler_attrs.h"
#ifdef __cplusplus
extern "C" {
#endif
extern PyTypeObject BPyGPUTexture_Type;
#define BPyGPUTexture_Check(v) (Py_TYPE(v) == &BPyGPUTexture_Type)
@@ -24,3 +28,7 @@ PyObject *bpygpu_texture_init(void);
PyObject *BPyGPUTexture_CreatePyObject(struct GPUTexture *tex, bool shared_reference)
ATTR_NONNULL(1);
#ifdef __cplusplus
}
#endif

View File

@@ -23,13 +23,13 @@
static PyModuleDef pygpu_types_module_def = {
/*m_base*/ PyModuleDef_HEAD_INIT,
/*m_name*/ "gpu.types",
/*m_doc*/ NULL,
/*m_doc*/ nullptr,
/*m_size*/ 0,
/*m_methods*/ NULL,
/*m_slots*/ NULL,
/*m_traverse*/ NULL,
/*m_clear*/ NULL,
/*m_free*/ NULL,
/*m_methods*/ nullptr,
/*m_slots*/ nullptr,
/*m_traverse*/ nullptr,
/*m_clear*/ nullptr,
/*m_free*/ nullptr,
};
PyObject *bpygpu_types_init(void)
@@ -39,40 +39,40 @@ PyObject *bpygpu_types_init(void)
submodule = bpygpu_create_module(&pygpu_types_module_def);
if (bpygpu_finalize_type(&BPyGPU_BufferType) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUVertFormat_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUVertBuf_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUIndexBuf_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUBatch_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUOffScreen_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUShader_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUTexture_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUFrameBuffer_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUUniformBuf_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUShaderCreateInfo_Type) < 0) {
return NULL;
return nullptr;
}
if (bpygpu_finalize_type(&BPyGPUStageInterfaceInfo_Type) < 0) {
return NULL;
return nullptr;
}
PyModule_AddType(submodule, &BPyGPU_BufferType);

View File

@@ -20,4 +20,12 @@
#include "gpu_py_vertex_buffer.h"
#include "gpu_py_vertex_format.h"
#ifdef __cplusplus
extern "C" {
#endif
PyObject *bpygpu_types_init(void);
#ifdef __cplusplus
}
#endif

View File

@@ -30,7 +30,7 @@
static int pygpu_uniformbuffer_valid_check(BPyGPUUniformBuf *bpygpu_ub)
{
if (UNLIKELY(bpygpu_ub->ubo == NULL)) {
if (UNLIKELY(bpygpu_ub->ubo == nullptr)) {
PyErr_SetString(PyExc_ReferenceError,
#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
"GPU uniform buffer was freed, no further access is valid");
@@ -46,7 +46,7 @@ static int pygpu_uniformbuffer_valid_check(BPyGPUUniformBuf *bpygpu_ub)
#define BPYGPU_UNIFORMBUF_CHECK_OBJ(bpygpu) \
{ \
if (UNLIKELY(pygpu_uniformbuffer_valid_check(bpygpu) == -1)) { \
return NULL; \
return nullptr; \
} \
} \
((void)0)
@@ -57,15 +57,15 @@ static int pygpu_uniformbuffer_valid_check(BPyGPUUniformBuf *bpygpu_ub)
/** \name GPUUniformBuf Type
* \{ */
static PyObject *pygpu_uniformbuffer__tp_new(PyTypeObject *UNUSED(self),
static PyObject *pygpu_uniformbuffer__tp_new(PyTypeObject * /*self*/,
PyObject *args,
PyObject *kwds)
{
GPUUniformBuf *ubo = NULL;
GPUUniformBuf *ubo = nullptr;
PyObject *pybuffer_obj;
char err_out[256] = "unknown error. See console";
static const char *_keywords[] = {"data", NULL};
static const char *_keywords[] = {"data", nullptr};
static _PyArg_Parser _parser = {
"O" /* `data` */
":GPUUniformBuf.__new__",
@@ -73,7 +73,7 @@ static PyObject *pygpu_uniformbuffer__tp_new(PyTypeObject *UNUSED(self),
0,
};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &pybuffer_obj)) {
return NULL;
return nullptr;
}
if (!GPU_context_active_get()) {
@@ -83,7 +83,7 @@ static PyObject *pygpu_uniformbuffer__tp_new(PyTypeObject *UNUSED(self),
Py_buffer pybuffer;
if (PyObject_GetBuffer(pybuffer_obj, &pybuffer, PyBUF_SIMPLE) == -1) {
/* PyObject_GetBuffer raise a PyExc_BufferError */
return NULL;
return nullptr;
}
if ((pybuffer.len % 16) != 0) {
@@ -95,9 +95,9 @@ static PyObject *pygpu_uniformbuffer__tp_new(PyTypeObject *UNUSED(self),
PyBuffer_Release(&pybuffer);
}
if (ubo == NULL) {
if (ubo == nullptr) {
PyErr_Format(PyExc_RuntimeError, "GPUUniformBuf.__new__(...) failed with '%s'", err_out);
return NULL;
return nullptr;
}
return BPyGPUUniformBuf_CreatePyObject(ubo);
@@ -114,7 +114,7 @@ static PyObject *pygpu_uniformbuffer_update(BPyGPUUniformBuf *self, PyObject *ob
Py_buffer pybuffer;
if (PyObject_GetBuffer(obj, &pybuffer, PyBUF_SIMPLE) == -1) {
/* PyObject_GetBuffer raise a PyExc_BufferError */
return NULL;
return nullptr;
}
GPU_uniformbuf_update(self->ubo, pybuffer.buf);
@@ -133,7 +133,7 @@ static PyObject *pygpu_uniformbuffer_free(BPyGPUUniformBuf *self)
BPYGPU_UNIFORMBUF_CHECK_OBJ(self);
GPU_uniformbuf_free(self->ubo);
self->ubo = NULL;
self->ubo = nullptr;
Py_RETURN_NONE;
}
#endif
@@ -147,7 +147,7 @@ static void BPyGPUUniformBuf__tp_dealloc(BPyGPUUniformBuf *self)
}
static PyGetSetDef pygpu_uniformbuffer__tp_getseters[] = {
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
{nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
};
static PyMethodDef pygpu_uniformbuffer__tp_methods[] = {
@@ -155,7 +155,7 @@ static PyMethodDef pygpu_uniformbuffer__tp_methods[] = {
#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
{"free", (PyCFunction)pygpu_uniformbuffer_free, METH_NOARGS, pygpu_uniformbuffer_free_doc},
#endif
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
PyDoc_STRVAR(pygpu_uniformbuffer__tp_doc,
@@ -166,55 +166,55 @@ PyDoc_STRVAR(pygpu_uniformbuffer__tp_doc,
" :arg data: Data to fill the buffer.\n"
" :type data: object exposing buffer interface\n");
PyTypeObject BPyGPUUniformBuf_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUUniformBuf",
/*tp_basicsize*/ sizeof(BPyGPUUniformBuf),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)BPyGPUUniformBuf__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ pygpu_uniformbuffer__tp_doc,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_uniformbuffer__tp_methods,
/*tp_members*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ pygpu_uniformbuffer__tp_getseters,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_uniformbuffer__tp_new,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */

View File

@@ -10,6 +10,10 @@
#include "BLI_compiler_attrs.h"
#ifdef __cplusplus
extern "C" {
#endif
extern PyTypeObject BPyGPUUniformBuf_Type;
#define BPyGPUUniformBuf_Check(v) (Py_TYPE(v) == &BPyGPUUniformBuf_Type)
@@ -20,3 +24,7 @@ typedef struct BPyGPUUniformBuf {
} BPyGPUUniformBuf;
PyObject *BPyGPUUniformBuf_CreatePyObject(struct GPUUniformBuf *ubo) ATTR_NONNULL(1);
#ifdef __cplusplus
}
#endif

View File

@@ -68,7 +68,7 @@ static void pygpu_fill_format_elem(void *data_dst_void, PyObject *py_src, const
{
#define PY_AS_NATIVE(ty_dst, py_as_native) \
{ \
ty_dst *data_dst = data_dst_void; \
ty_dst *data_dst = static_cast<ty_dst *>(data_dst_void); \
*data_dst = py_as_native(py_src); \
} \
((void)0)
@@ -90,7 +90,7 @@ static void pygpu_fill_format_sequence(void *data_dst_void,
* Args are constants, so range checks will be optimized out if they're no-op's.
*/
#define PY_AS_NATIVE(ty_dst, py_as_native) \
ty_dst *data_dst = data_dst_void; \
ty_dst *data_dst = static_cast<ty_dst *>(data_dst_void); \
for (uint i = 0; i < len; i++) { \
data_dst[i] = py_as_native(value_fast_items[i]); \
} \
@@ -146,7 +146,7 @@ static bool pygpu_vertbuf_fill_impl(GPUVertBuf *vbo,
GPU_vertbuf_attr_get_raw_data(vbo, data_id, &data_step);
PyObject *seq_fast = PySequence_Fast(seq, "Vertex buffer fill");
if (seq_fast == NULL) {
if (seq_fast == nullptr) {
return false;
}
@@ -170,7 +170,7 @@ static bool pygpu_vertbuf_fill_impl(GPUVertBuf *vbo,
uchar *data = (uchar *)GPU_vertbuf_raw_step(&data_step);
PyObject *seq_fast_item = PySequence_Fast(seq_items[i], error_prefix);
if (seq_fast_item == NULL) {
if (seq_fast_item == nullptr) {
ok = false;
goto finally;
}
@@ -212,7 +212,7 @@ static int pygpu_vertbuf_fill(GPUVertBuf *buf,
return 0;
}
if (GPU_vertbuf_get_data(buf) == NULL) {
if (GPU_vertbuf_get_data(buf) == nullptr) {
PyErr_SetString(PyExc_ValueError, "Can't fill, static buffer already in use");
return 0;
}
@@ -230,14 +230,14 @@ static int pygpu_vertbuf_fill(GPUVertBuf *buf,
/** \name VertBuf Type
* \{ */
static PyObject *pygpu_vertbuf__tp_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
static PyObject *pygpu_vertbuf__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds)
{
struct {
PyObject *py_fmt;
uint len;
} params;
static const char *_keywords[] = {"format", "len", NULL};
static const char *_keywords[] = {"format", "len", nullptr};
static _PyArg_Parser _parser = {
"O!" /* `format` */
"I" /* `len` */
@@ -248,7 +248,7 @@ static PyObject *pygpu_vertbuf__tp_new(PyTypeObject *UNUSED(type), PyObject *arg
if (!_PyArg_ParseTupleAndKeywordsFast(
args, kwds, &_parser, &BPyGPUVertFormat_Type, &params.py_fmt, &params.len))
{
return NULL;
return nullptr;
}
const GPUVertFormat *fmt = &((BPyGPUVertFormat *)params.py_fmt)->fmt;
@@ -273,7 +273,7 @@ static PyObject *pygpu_vertbuf_attr_fill(BPyGPUVertBuf *self, PyObject *args, Py
PyObject *data;
PyObject *identifier;
static const char *_keywords[] = {"id", "data", NULL};
static const char *_keywords[] = {"id", "data", nullptr};
static _PyArg_Parser _parser = {
"O" /* `id` */
"O" /* `data` */
@@ -282,7 +282,7 @@ static PyObject *pygpu_vertbuf_attr_fill(BPyGPUVertBuf *self, PyObject *args, Py
0,
};
if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &identifier, &data)) {
return NULL;
return nullptr;
}
int id;
@@ -296,16 +296,16 @@ static PyObject *pygpu_vertbuf_attr_fill(BPyGPUVertBuf *self, PyObject *args, Py
id = GPU_vertformat_attr_id_get(format, name);
if (id == -1) {
PyErr_Format(PyExc_ValueError, "Unknown attribute '%s'", name);
return NULL;
return nullptr;
}
}
else {
PyErr_SetString(PyExc_TypeError, "expected int or str type as identifier");
return NULL;
return nullptr;
}
if (!pygpu_vertbuf_fill(self->buf, id, data, "GPUVertBuf.attr_fill")) {
return NULL;
return nullptr;
}
Py_RETURN_NONE;
@@ -316,7 +316,7 @@ static PyMethodDef pygpu_vertbuf__tp_methods[] = {
(PyCFunction)pygpu_vertbuf_attr_fill,
METH_VARARGS | METH_KEYWORDS,
pygpu_vertbuf_attr_fill_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
static void pygpu_vertbuf__tp_dealloc(BPyGPUVertBuf *self)
@@ -335,55 +335,55 @@ PyDoc_STRVAR(pygpu_vertbuf__tp_doc,
" :arg len: Amount of vertices that will fit into this buffer.\n"
" :type len: int\n");
PyTypeObject BPyGPUVertBuf_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUVertBuf",
/*tp_basicsize*/ sizeof(BPyGPUVertBuf),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_vertbuf__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ pygpu_vertbuf__tp_doc,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_vertbuf__tp_methods,
/*tp_members*/ NULL,
/*tp_getset*/ NULL,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ nullptr,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_vertbuf__tp_new,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */

View File

@@ -10,6 +10,10 @@
#include "BLI_compiler_attrs.h"
#ifdef __cplusplus
extern "C" {
#endif
extern PyTypeObject BPyGPUVertBuf_Type;
#define BPyGPUVertBuf_Check(v) (Py_TYPE(v) == &BPyGPUVertBuf_Type)
@@ -21,3 +25,7 @@ typedef struct BPyGPUVertBuf {
} BPyGPUVertBuf;
PyObject *BPyGPUVertBuf_CreatePyObject(struct GPUVertBuf *buf) ATTR_NONNULL(1);
#ifdef __cplusplus
}
#endif

View File

@@ -31,7 +31,7 @@ static struct PyC_StringEnumItems pygpu_vertcomptype_items[] = {
{GPU_COMP_U32, "U32"},
{GPU_COMP_F32, "F32"},
{GPU_COMP_I10, "I10"},
{0, NULL},
{0, nullptr},
};
static struct PyC_StringEnumItems pygpu_vertfetchmode_items[] = {
@@ -39,7 +39,7 @@ static struct PyC_StringEnumItems pygpu_vertfetchmode_items[] = {
{GPU_FETCH_INT, "INT"},
{GPU_FETCH_INT_TO_FLOAT_UNIT, "INT_TO_FLOAT_UNIT"},
{GPU_FETCH_INT_TO_FLOAT, "INT_TO_FLOAT"},
{0, NULL},
{0, nullptr},
};
/** \} */
@@ -48,15 +48,13 @@ static struct PyC_StringEnumItems pygpu_vertfetchmode_items[] = {
/** \name VertFormat Type
* \{ */
static PyObject *pygpu_vertformat__tp_new(PyTypeObject *UNUSED(type),
PyObject *args,
PyObject *kwds)
static PyObject *pygpu_vertformat__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds)
{
if (PyTuple_GET_SIZE(args) || (kwds && PyDict_Size(kwds))) {
PyErr_SetString(PyExc_ValueError, "This function takes no arguments");
return NULL;
return nullptr;
}
return BPyGPUVertFormat_CreatePyObject(NULL);
return BPyGPUVertFormat_CreatePyObject(nullptr);
}
PyDoc_STRVAR(
@@ -88,10 +86,10 @@ static PyObject *pygpu_vertformat_attr_add(BPyGPUVertFormat *self, PyObject *arg
if (self->fmt.attr_len == GPU_VERT_ATTR_MAX_LEN) {
PyErr_SetString(PyExc_ValueError, "Maximum attr reached " STRINGIFY(GPU_VERT_ATTR_MAX_LEN));
return NULL;
return nullptr;
}
static const char *_keywords[] = {"id", "comp_type", "len", "fetch_mode", NULL};
static const char *_keywords[] = {"id", "comp_type", "len", "fetch_mode", nullptr};
static _PyArg_Parser _parser = {
"$" /* Keyword only arguments. */
"s" /* `id` */
@@ -112,11 +110,14 @@ static PyObject *pygpu_vertformat_attr_add(BPyGPUVertFormat *self, PyObject *arg
PyC_ParseStringEnum,
&fetch_mode))
{
return NULL;
return nullptr;
}
uint attr_id = GPU_vertformat_attr_add(
&self->fmt, id, comp_type.value_found, len, fetch_mode.value_found);
uint attr_id = GPU_vertformat_attr_add(&self->fmt,
id,
GPUVertCompType(comp_type.value_found),
len,
GPUVertFetchMode(fetch_mode.value_found));
return PyLong_FromLong(attr_id);
}
@@ -125,7 +126,7 @@ static PyMethodDef pygpu_vertformat__tp_methods[] = {
(PyCFunction)pygpu_vertformat_attr_add,
METH_VARARGS | METH_KEYWORDS,
pygpu_vertformat_attr_add_doc},
{NULL, NULL, 0, NULL},
{nullptr, nullptr, 0, nullptr},
};
static void pygpu_vertformat__tp_dealloc(BPyGPUVertFormat *self)
@@ -138,55 +139,55 @@ PyDoc_STRVAR(pygpu_vertformat__tp_doc,
"\n"
" This object contains information about the structure of a vertex buffer.\n");
PyTypeObject BPyGPUVertFormat_Type = {
/*ob_base*/ PyVarObject_HEAD_INIT(NULL, 0)
/*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
/*tp_name*/ "GPUVertFormat",
/*tp_basicsize*/ sizeof(BPyGPUVertFormat),
/*tp_itemsize*/ 0,
/*tp_dealloc*/ (destructor)pygpu_vertformat__tp_dealloc,
/*tp_vectorcall_offset*/ 0,
/*tp_getattr*/ NULL,
/*tp_setattr*/ NULL,
/*tp_as_async*/ NULL,
/*tp_repr*/ NULL,
/*tp_as_number*/ NULL,
/*tp_as_sequence*/ NULL,
/*tp_as_mapping*/ NULL,
/*tp_hash*/ NULL,
/*tp_call*/ NULL,
/*tp_str*/ NULL,
/*tp_getattro*/ NULL,
/*tp_setattro*/ NULL,
/*tp_as_buffer*/ NULL,
/*tp_getattr*/ nullptr,
/*tp_setattr*/ nullptr,
/*tp_as_async*/ nullptr,
/*tp_repr*/ nullptr,
/*tp_as_number*/ nullptr,
/*tp_as_sequence*/ nullptr,
/*tp_as_mapping*/ nullptr,
/*tp_hash*/ nullptr,
/*tp_call*/ nullptr,
/*tp_str*/ nullptr,
/*tp_getattro*/ nullptr,
/*tp_setattro*/ nullptr,
/*tp_as_buffer*/ nullptr,
/*tp_flags*/ Py_TPFLAGS_DEFAULT,
/*tp_doc*/ pygpu_vertformat__tp_doc,
/*tp_traverse*/ NULL,
/*tp_clear*/ NULL,
/*tp_richcompare*/ NULL,
/*tp_traverse*/ nullptr,
/*tp_clear*/ nullptr,
/*tp_richcompare*/ nullptr,
/*tp_weaklistoffset*/ 0,
/*tp_iter*/ NULL,
/*tp_iternext*/ NULL,
/*tp_iter*/ nullptr,
/*tp_iternext*/ nullptr,
/*tp_methods*/ pygpu_vertformat__tp_methods,
/*tp_members*/ NULL,
/*tp_getset*/ NULL,
/*tp_base*/ NULL,
/*tp_dict*/ NULL,
/*tp_descr_get*/ NULL,
/*tp_descr_set*/ NULL,
/*tp_members*/ nullptr,
/*tp_getset*/ nullptr,
/*tp_base*/ nullptr,
/*tp_dict*/ nullptr,
/*tp_descr_get*/ nullptr,
/*tp_descr_set*/ nullptr,
/*tp_dictoffset*/ 0,
/*tp_init*/ NULL,
/*tp_alloc*/ NULL,
/*tp_init*/ nullptr,
/*tp_alloc*/ nullptr,
/*tp_new*/ pygpu_vertformat__tp_new,
/*tp_free*/ NULL,
/*tp_is_gc*/ NULL,
/*tp_bases*/ NULL,
/*tp_mro*/ NULL,
/*tp_cache*/ NULL,
/*tp_subclasses*/ NULL,
/*tp_weaklist*/ NULL,
/*tp_del*/ NULL,
/*tp_free*/ nullptr,
/*tp_is_gc*/ nullptr,
/*tp_bases*/ nullptr,
/*tp_mro*/ nullptr,
/*tp_cache*/ nullptr,
/*tp_subclasses*/ nullptr,
/*tp_weaklist*/ nullptr,
/*tp_del*/ nullptr,
/*tp_version_tag*/ 0,
/*tp_finalize*/ NULL,
/*tp_vectorcall*/ NULL,
/*tp_finalize*/ nullptr,
/*tp_vectorcall*/ nullptr,
};
/** \} */

View File

@@ -10,6 +10,10 @@
#include "GPU_vertex_format.h"
#ifdef __cplusplus
extern "C" {
#endif
extern PyTypeObject BPyGPUVertFormat_Type;
#define BPyGPUVertFormat_Check(v) (Py_TYPE(v) == &BPyGPUVertFormat_Type)
@@ -20,3 +24,7 @@ typedef struct BPyGPUVertFormat {
} BPyGPUVertFormat;
PyObject *BPyGPUVertFormat_CreatePyObject(struct GPUVertFormat *fmt);
#ifdef __cplusplus
}
#endif