diff options
Diffstat (limited to 'source/blender/python/gpu')
-rw-r--r-- | source/blender/python/gpu/gpu_py_api.c | 10 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_batch.c | 13 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_buffer.c | 55 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_capabilities.c | 59 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_element.c | 2 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_framebuffer.c | 26 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_matrix.c | 23 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_platform.c | 40 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_select.c | 13 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_shader.c | 123 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_shader_create_info.cc | 187 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_state.c | 38 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_texture.c | 15 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_types.c | 9 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_vertex_buffer.c | 12 | ||||
-rw-r--r-- | source/blender/python/gpu/gpu_py_vertex_format.c | 8 |
16 files changed, 392 insertions, 241 deletions
diff --git a/source/blender/python/gpu/gpu_py_api.c b/source/blender/python/gpu/gpu_py_api.c index a2075566f31..8f5897be649 100644 --- a/source/blender/python/gpu/gpu_py_api.c +++ b/source/blender/python/gpu/gpu_py_api.c @@ -32,8 +32,14 @@ PyDoc_STRVAR(pygpu_doc, "Some higher level functions can be found in the `gpu_extras` module."); static struct PyModuleDef pygpu_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu", - .m_doc = pygpu_doc, + /*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, }; PyObject *BPyInit_gpu(void) diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c index 533e5154d83..a36b1dfd1b5 100644 --- a/source/blender/python/gpu/gpu_py_batch.c +++ b/source/blender/python/gpu/gpu_py_batch.c @@ -111,6 +111,7 @@ static PyObject *pygpu_batch__tp_new(PyTypeObject *UNUSED(type), PyObject *args, Py_INCREF(py_indexbuf); } + BLI_assert(!PyObject_GC_IsTracked((PyObject *)ret)); PyObject_GC_Track(ret); #endif @@ -127,7 +128,7 @@ PyDoc_STRVAR(pygpu_batch_vertbuf_add_doc, " vertex buffer for vertex positions and vertex normals.\n" " Current a batch can have at most " STRINGIFY(GPU_BATCH_VBO_MAX_LEN) " vertex buffers.\n" "\n" -" :param buf: The vertex buffer that will be added to the batch.\n" +" :arg buf: The vertex buffer that will be added to the batch.\n" " :type buf: :class:`gpu.types.GPUVertBuf`\n" ); static PyObject *pygpu_batch_vertbuf_add(BPyGPUBatch *self, BPyGPUVertBuf *py_buf) @@ -171,7 +172,7 @@ PyDoc_STRVAR( " This function does not need to be called when you always\n" " set the shader when calling :meth:`gpu.types.GPUBatch.draw`.\n" "\n" - " :param program: The program/shader the batch will use in future draw calls.\n" + " :arg program: The program/shader the batch will use in future draw calls.\n" " :type program: :class:`gpu.types.GPUShader`\n"); static PyObject *pygpu_batch_program_set(BPyGPUBatch *self, BPyGPUShader *py_shader) { @@ -209,7 +210,7 @@ PyDoc_STRVAR(pygpu_batch_draw_doc, "\n" " Run the drawing program with the parameters assigned to the batch.\n" "\n" - " :param program: Program that performs the drawing operations.\n" + " :arg program: Program that performs the drawing operations.\n" " If ``None`` is passed, the last program set to this batch will run.\n" " :type program: :class:`gpu.types.GPUShader`\n"); static PyObject *pygpu_batch_draw(BPyGPUBatch *self, PyObject *args) @@ -273,6 +274,11 @@ static int pygpu_batch__tp_clear(BPyGPUBatch *self) return 0; } +static int pygpu_batch__tp_is_gc(BPyGPUBatch *self) +{ + return self->references != NULL; +} + #endif static void pygpu_batch__tp_dealloc(BPyGPUBatch *self) @@ -313,6 +319,7 @@ PyTypeObject BPyGPUBatch_Type = { .tp_doc = pygpu_batch__tp_doc, .tp_traverse = (traverseproc)pygpu_batch__tp_traverse, .tp_clear = (inquiry)pygpu_batch__tp_clear, + .tp_is_gc = (inquiry)pygpu_batch__tp_is_gc, #else .tp_flags = Py_TPFLAGS_DEFAULT, #endif diff --git a/source/blender/python/gpu/gpu_py_buffer.c b/source/blender/python/gpu/gpu_py_buffer.c index 020535d002a..51bda9b4941 100644 --- a/source/blender/python/gpu/gpu_py_buffer.c +++ b/source/blender/python/gpu/gpu_py_buffer.c @@ -61,7 +61,7 @@ static bool pygpu_buffer_pyobj_as_shape(PyObject *shape_obj, Py_ssize_t shape_len = 0; if (PyLong_Check(shape_obj)) { shape_len = 1; - if (((r_shape[0] = PyLong_AsLong(shape_obj)) < 1)) { + if ((r_shape[0] = PyLong_AsLong(shape_obj)) < 1) { PyErr_SetString(PyExc_AttributeError, "dimension must be greater than or equal to 1"); return false; } @@ -100,7 +100,7 @@ static bool pygpu_buffer_pyobj_as_shape(PyObject *shape_obj, } else { PyErr_Format(PyExc_TypeError, - "invalid second argument argument expected a sequence " + "invalid second argument expected a sequence " "or an int, not a %.200s", Py_TYPE(shape_obj)->tp_name); } @@ -153,12 +153,13 @@ static BPyGPUBuffer *pygpu_buffer_make_from_data(PyObject *parent, if (parent) { Py_INCREF(parent); buffer->parent = parent; + BLI_assert(!PyObject_GC_IsTracked((PyObject *)buffer)); PyObject_GC_Track(buffer); } return buffer; } -static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, int i) +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"); @@ -199,10 +200,10 @@ static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, int i) static PyObject *pygpu_buffer_to_list(BPyGPUBuffer *self) { - int i, len = self->shape[0]; + const Py_ssize_t len = self->shape[0]; PyObject *list = PyList_New(len); - for (i = 0; i < len; i++) { + for (Py_ssize_t i = 0; i < len; i++) { PyList_SET_ITEM(list, i, pygpu_buffer__sq_item(self, i)); } @@ -312,7 +313,7 @@ static PyObject *pygpu_buffer__tp_repr(BPyGPUBuffer *self) return repr; } -static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, int i, PyObject *v); +static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, Py_ssize_t i, PyObject *v); static int pygpu_buffer_ass_slice(BPyGPUBuffer *self, Py_ssize_t begin, @@ -422,9 +423,14 @@ static PyObject *pygpu_buffer__tp_new(PyTypeObject *UNUSED(type), PyObject *args return (PyObject *)buffer; } +static int pygpu_buffer__tp_is_gc(BPyGPUBuffer *self) +{ + return self->parent != NULL; +} + /* BPyGPUBuffer sequence methods */ -static int pygpu_buffer__sq_length(BPyGPUBuffer *self) +static Py_ssize_t pygpu_buffer__sq_length(BPyGPUBuffer *self) { return self->shape[0]; } @@ -452,7 +458,7 @@ static PyObject *pygpu_buffer_slice(BPyGPUBuffer *self, Py_ssize_t begin, Py_ssi return list; } -static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, int i, PyObject *v) +static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, Py_ssize_t i, PyObject *v) { if (i >= self->shape[0] || i < 0) { PyErr_SetString(PyExc_IndexError, "array assignment index out of range"); @@ -573,22 +579,22 @@ static PyGetSetDef pygpu_buffer_getseters[] = { }; static PySequenceMethods pygpu_buffer__tp_as_sequence = { - (lenfunc)pygpu_buffer__sq_length, /* sq_length */ - (binaryfunc)NULL, /* sq_concat */ - (ssizeargfunc)NULL, /* sq_repeat */ - (ssizeargfunc)pygpu_buffer__sq_item, /* sq_item */ - (ssizessizeargfunc)NULL, /* sq_slice, deprecated, handled in pygpu_buffer__sq_item */ - (ssizeobjargproc)pygpu_buffer__sq_ass_item, /* sq_ass_item */ - (ssizessizeobjargproc)NULL, /* sq_ass_slice, deprecated handled in pygpu_buffer__sq_ass_item */ - (objobjproc)NULL, /* sq_contains */ - (binaryfunc)NULL, /* sq_inplace_concat */ - (ssizeargfunc)NULL, /* sq_inplace_repeat */ + /*sq_length*/ (lenfunc)pygpu_buffer__sq_length, + /*sq_concat*/ NULL, + /*sq_repeat*/ NULL, + /*sq_item*/ (ssizeargfunc)pygpu_buffer__sq_item, + /*was_sq_slice*/ NULL, /* 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, }; static PyMappingMethods pygpu_buffer__tp_as_mapping = { - (lenfunc)pygpu_buffer__sq_length, - (binaryfunc)pygpu_buffer__mp_subscript, - (objobjargproc)pygpu_buffer__mp_ass_subscript, + /*mp_len*/ (lenfunc)pygpu_buffer__sq_length, + /*mp_subscript*/ (binaryfunc)pygpu_buffer__mp_subscript, + /*mp_ass_subscript*/ (objobjargproc)pygpu_buffer__mp_ass_subscript, }; #ifdef PYGPU_BUFFER_PROTOCOL @@ -642,8 +648,8 @@ static void pygpu_buffer__bf_releasebuffer(PyObject *UNUSED(exporter), Py_buffer } static PyBufferProcs pygpu_buffer__tp_as_buffer = { - (getbufferproc)pygpu_buffer__bf_getbuffer, - (releasebufferproc)pygpu_buffer__bf_releasebuffer, + /*bf_getbuffer*/ (getbufferproc)pygpu_buffer__bf_getbuffer, + /*bf_releasebuffer*/ (releasebufferproc)pygpu_buffer__bf_releasebuffer, }; #endif @@ -655,7 +661,7 @@ PyDoc_STRVAR( "\n" " :arg format: Format type to interpret the buffer.\n" " Possible values are `FLOAT`, `INT`, `UINT`, `UBYTE`, `UINT_24_8` and `10_11_11_REV`.\n" - " :type type: str\n" + " :type format: str\n" " :arg dimensions: Array describing the dimensions.\n" " :type dimensions: int\n" " :arg data: Optional data array.\n" @@ -677,6 +683,7 @@ PyTypeObject BPyGPU_BufferType = { .tp_methods = pygpu_buffer__tp_methods, .tp_getset = pygpu_buffer_getseters, .tp_new = pygpu_buffer__tp_new, + .tp_is_gc = (inquiry)pygpu_buffer__tp_is_gc, }; static size_t pygpu_buffer_calc_size(const int format, diff --git a/source/blender/python/gpu/gpu_py_capabilities.c b/source/blender/python/gpu/gpu_py_capabilities.c index b892167cd76..2345982eb42 100644 --- a/source/blender/python/gpu/gpu_py_capabilities.c +++ b/source/blender/python/gpu/gpu_py_capabilities.c @@ -191,6 +191,40 @@ static PyObject *pygpu_extensions_get(PyObject *UNUSED(self)) return ret; } +PyDoc_STRVAR(pygpu_compute_shader_support_get_doc, + ".. function:: compute_shader_support_get()\n" + "\n" + " Are compute shaders supported.\n" + "\n" + " :return: True when supported, False when not supported.\n" + " :rtype: bool\n"); +static PyObject *pygpu_compute_shader_support_get(PyObject *UNUSED(self)) +{ + return PyBool_FromLong(GPU_compute_shader_support()); +} + +PyDoc_STRVAR(pygpu_shader_storage_buffer_objects_support_get_doc, + ".. function:: shader_storage_buffer_objects_support_get()\n" + "\n" + " Are SSBO's supported.\n" + "\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)) +{ + return PyBool_FromLong(GPU_shader_storage_buffer_objects_support()); +} +PyDoc_STRVAR(pygpu_shader_image_load_store_support_get_doc, + ".. function:: shader_image_load_store_support_get()\n" + "\n" + " Is image load/store supported.\n" + "\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)) +{ + return PyBool_FromLong(GPU_shader_image_load_store_support()); +} /** \} */ /* -------------------------------------------------------------------- */ @@ -247,15 +281,34 @@ static struct PyMethodDef pygpu_capabilities__tp_methods[] = { METH_NOARGS, pygpu_max_varying_floats_get_doc}, {"extensions_get", (PyCFunction)pygpu_extensions_get, METH_NOARGS, pygpu_extensions_get_doc}, + + {"compute_shader_support_get", + (PyCFunction)pygpu_compute_shader_support_get, + METH_NOARGS, + pygpu_compute_shader_support_get_doc}, + {"shader_storage_buffer_objects_support_get", + (PyCFunction)pygpu_shader_storage_buffer_objects_support_get, + METH_NOARGS, + pygpu_shader_storage_buffer_objects_support_get_doc}, + {"shader_image_load_store_support_get", + (PyCFunction)pygpu_shader_image_load_store_support_get, + METH_NOARGS, + pygpu_shader_image_load_store_support_get_doc}, + {NULL, NULL, 0, NULL}, }; PyDoc_STRVAR(pygpu_capabilities__tp_doc, "This module provides access to the GPU capabilities."); static PyModuleDef pygpu_capabilities_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu.capabilities", - .m_doc = pygpu_capabilities__tp_doc, - .m_methods = pygpu_capabilities__tp_methods, + /*m_name*/ "gpu.capabilities", + /*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, }; PyObject *bpygpu_capabilities_init(void) diff --git a/source/blender/python/gpu/gpu_py_element.c b/source/blender/python/gpu/gpu_py_element.c index d52a97c0c84..46f1d4d49eb 100644 --- a/source/blender/python/gpu/gpu_py_element.c +++ b/source/blender/python/gpu/gpu_py_element.c @@ -180,7 +180,7 @@ PyDoc_STRVAR(pygpu_IndexBuf__tp_doc, " :arg type: The primitive type this index buffer is composed of.\n" " Possible values are `POINTS`, `LINES`, `TRIS` and `LINE_STRIP_ADJ`.\n" " :type type: str\n" - " :param seq: Indices this index buffer will contain.\n" + " :arg seq: Indices this index buffer will contain.\n" " Whether a 1D or 2D sequence is required depends on the type.\n" " Optionally the sequence can support the buffer protocol.\n" " :type seq: 1D or 2D sequence\n"); diff --git a/source/blender/python/gpu/gpu_py_framebuffer.c b/source/blender/python/gpu/gpu_py_framebuffer.c index 9bb2a9137f4..2de8c680b23 100644 --- a/source/blender/python/gpu/gpu_py_framebuffer.c +++ b/source/blender/python/gpu/gpu_py_framebuffer.c @@ -421,9 +421,10 @@ PyDoc_STRVAR(pygpu_framebuffer_viewport_set_doc, " Set the viewport for this framebuffer object.\n" " Note: The viewport state is not saved upon framebuffer rebind.\n" "\n" - " :param x, y: lower left corner of the viewport_set rectangle, in pixels.\n" - " :param xsize, ysize: width and height of the viewport_set.\n" - " :type x, y, xsize, ysize: int\n"); + " :arg x, y: lower left corner of the viewport_set rectangle, in pixels.\n" + " :type x, y: int\n" + " :arg xsize, ysize: width and height of the viewport_set.\n" + " :type xsize, ysize: int\n"); static PyObject *pygpu_framebuffer_viewport_set(BPyGPUFrameBuffer *self, PyObject *args, void *UNUSED(type)) @@ -462,16 +463,16 @@ PyDoc_STRVAR( "\n" " Read a block of pixels from the frame buffer.\n" "\n" - " :param x, y: Lower left corner of a rectangular block of pixels.\n" - " :param xsize, ysize: Dimensions of the pixel rectangle.\n" + " :arg x, y: Lower left corner of a rectangular block of pixels.\n" + " :arg xsize, ysize: Dimensions of the pixel rectangle.\n" " :type x, y, xsize, ysize: int\n" - " :param channels: Number of components to read.\n" + " :arg channels: Number of components to read.\n" " :type channels: int\n" - " :param slot: The framebuffer slot to read data from.\n" + " :arg slot: The framebuffer slot to read data from.\n" " :type slot: int\n" - " :param format: The format that describes the content of a single channel.\n" + " :arg format: The format that describes the content of a single channel.\n" " Possible values are `FLOAT`, `INT`, `UINT`, `UBYTE`, `UINT_24_8` and `10_11_11_REV`.\n" - " :type type: str\n" + " :type format: str\n" " :arg data: Optional Buffer object to fill with the pixels values.\n" " :type data: :class:`gpu.types.Buffer`\n" " :return: The Buffer with the read pixels.\n" @@ -569,9 +570,10 @@ PyDoc_STRVAR(pygpu_framebuffer_read_depth_doc, "\n" " Read a pixel depth block from the frame buffer.\n" "\n" - " :param x, y: Lower left corner of a rectangular block of pixels.\n" - " :param xsize, ysize: Dimensions of the pixel rectangle.\n" - " :type x, y, xsize, ysize: int\n" + " :arg x, y: Lower left corner of a rectangular block of pixels.\n" + " :type x, y: int\n" + " :arg xsize, ysize: Dimensions of the pixel rectangle.\n" + " :type xsize, ysize: int\n" " :arg data: Optional Buffer object to fill with the pixels values.\n" " :type data: :class:`gpu.types.Buffer`\n" " :return: The Buffer with the read pixels.\n" diff --git a/source/blender/python/gpu/gpu_py_matrix.c b/source/blender/python/gpu/gpu_py_matrix.c index a47e3dc8a5f..7d80f763162 100644 --- a/source/blender/python/gpu/gpu_py_matrix.c +++ b/source/blender/python/gpu/gpu_py_matrix.c @@ -266,7 +266,7 @@ PyDoc_STRVAR(pygpu_matrix_multiply_matrix_doc, "\n" " Multiply the current stack matrix.\n" "\n" - " :param matrix: A 4x4 matrix.\n" + " :arg matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n"); static PyObject *pygpu_matrix_multiply_matrix(PyObject *UNUSED(self), PyObject *value) { @@ -283,7 +283,7 @@ PyDoc_STRVAR(pygpu_matrix_scale_doc, "\n" " Scale the current stack matrix.\n" "\n" - " :param scale: Scale the current stack matrix.\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) { @@ -305,7 +305,7 @@ static PyObject *pygpu_matrix_scale(PyObject *UNUSED(self), PyObject *value) PyDoc_STRVAR(pygpu_matrix_scale_uniform_doc, ".. function:: scale_uniform(scale)\n" "\n" - " :param scale: Scale the current stack matrix.\n" + " :arg scale: Scale the current stack matrix.\n" " :type scale: float\n"); static PyObject *pygpu_matrix_scale_uniform(PyObject *UNUSED(self), PyObject *value) { @@ -323,7 +323,7 @@ PyDoc_STRVAR(pygpu_matrix_translate_doc, "\n" " Scale the current stack matrix.\n" "\n" - " :param offset: Translate the current stack matrix.\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) { @@ -373,7 +373,7 @@ PyDoc_STRVAR(pygpu_matrix_load_matrix_doc, "\n" " Load a matrix into the stack.\n" "\n" - " :param matrix: A 4x4 matrix.\n" + " :arg matrix: A 4x4 matrix.\n" " :type matrix: :class:`mathutils.Matrix`\n"); static PyObject *pygpu_matrix_load_matrix(PyObject *UNUSED(self), PyObject *value) { @@ -390,7 +390,7 @@ PyDoc_STRVAR(pygpu_matrix_load_projection_matrix_doc, "\n" " Load a projection matrix into the stack.\n" "\n" - " :param matrix: A 4x4 matrix.\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) { @@ -528,9 +528,14 @@ static struct PyMethodDef pygpu_matrix__tp_methods[] = { PyDoc_STRVAR(pygpu_matrix__tp_doc, "This module provides access to the matrix stack."); static PyModuleDef pygpu_matrix_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu.matrix", - .m_doc = pygpu_matrix__tp_doc, - .m_methods = pygpu_matrix__tp_methods, + /*m_name*/ "gpu.matrix", + /*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, }; PyObject *bpygpu_matrix_init(void) diff --git a/source/blender/python/gpu/gpu_py_platform.c b/source/blender/python/gpu/gpu_py_platform.c index b877e3ceb98..5f9f653a3c4 100644 --- a/source/blender/python/gpu/gpu_py_platform.c +++ b/source/blender/python/gpu/gpu_py_platform.c @@ -11,6 +11,7 @@ #include "BLI_utildefines.h" +#include "GPU_context.h" #include "GPU_platform.h" #include "gpu_py_platform.h" /* Own include. */ @@ -83,6 +84,30 @@ static PyObject *pygpu_platform_device_type_get(PyObject *UNUSED(self)) return PyUnicode_FromString("UNKNOWN"); } +PyDoc_STRVAR(pygpu_platform_backend_type_get_doc, + ".. function:: backend_type_get()\n" + "\n" + " Get actuve GPU backend.\n" + "\n" + " :return: Backend type ('OPENGL', 'VULKAN', 'METAL', 'NONE', 'UNKNOWN').\n" + " :rtype: str\n"); +static PyObject *pygpu_platform_backend_type_get(PyObject *UNUSED(self)) +{ + switch (GPU_backend_get_type()) { + case GPU_BACKEND_VULKAN: + return PyUnicode_FromString("VULKAN"); + case GPU_BACKEND_METAL: + return PyUnicode_FromString("METAL"); + case GPU_BACKEND_NONE: + return PyUnicode_FromString("NONE"); + case GPU_BACKEND_OPENGL: + return PyUnicode_FromString("OPENGL"); + case GPU_BACKEND_ANY: + break; + } + return PyUnicode_FromString("UNKNOWN"); +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -106,15 +131,24 @@ static struct PyMethodDef pygpu_platform__tp_methods[] = { (PyCFunction)pygpu_platform_device_type_get, METH_NOARGS, pygpu_platform_device_type_get_doc}, + {"backend_type_get", + (PyCFunction)pygpu_platform_backend_type_get, + METH_NOARGS, + pygpu_platform_backend_type_get_doc}, {NULL, NULL, 0, NULL}, }; PyDoc_STRVAR(pygpu_platform__tp_doc, "This module provides access to GPU Platform definitions."); static PyModuleDef pygpu_platform_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu.platform", - .m_doc = pygpu_platform__tp_doc, - .m_methods = pygpu_platform__tp_methods, + /*m_name*/ "gpu.platform", + /*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, }; PyObject *bpygpu_platform_init(void) diff --git a/source/blender/python/gpu/gpu_py_select.c b/source/blender/python/gpu/gpu_py_select.c index 8869ea38e32..02e06e0ffd5 100644 --- a/source/blender/python/gpu/gpu_py_select.c +++ b/source/blender/python/gpu/gpu_py_select.c @@ -31,7 +31,7 @@ PyDoc_STRVAR(pygpu_select_load_id_doc, "\n" " Set the selection ID.\n" "\n" - " :param id: Number (32-bit uint).\n" + " :arg id: Number (32-bit uint).\n" " :type select: int\n"); static PyObject *pygpu_select_load_id(PyObject *UNUSED(self), PyObject *value) { @@ -58,9 +58,14 @@ static struct PyMethodDef pygpu_select__tp_methods[] = { PyDoc_STRVAR(pygpu_select__tp_doc, "This module provides access to selection."); static PyModuleDef pygpu_select_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu.select", - .m_doc = pygpu_select__tp_doc, - .m_methods = pygpu_select__tp_methods, + /*m_name*/ "gpu.select", + /*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, }; PyObject *bpygpu_select_init(void) diff --git a/source/blender/python/gpu/gpu_py_shader.c b/source/blender/python/gpu/gpu_py_shader.c index fbc45124147..7222cb1696a 100644 --- a/source/blender/python/gpu/gpu_py_shader.c +++ b/source/blender/python/gpu/gpu_py_shader.c @@ -163,7 +163,7 @@ PyDoc_STRVAR(pygpu_shader_uniform_from_name_doc, "\n" " Get uniform location by name.\n" "\n" - " :param name: Name of the uniform variable whose location is to be queried.\n" + " :arg name: Name of the uniform variable whose location is to be queried.\n" " :type name: str\n" " :return: Location of the uniform variable.\n" " :rtype: int\n"); @@ -184,16 +184,15 @@ static PyObject *pygpu_shader_uniform_from_name(BPyGPUShader *self, PyObject *ar return PyLong_FromLong(uniform); } -PyDoc_STRVAR( - pygpu_shader_uniform_block_from_name_doc, - ".. method:: uniform_block_from_name(name)\n" - "\n" - " Get uniform block location by name.\n" - "\n" - " :param name: Name of the uniform block variable whose location is to be queried.\n" - " :type name: str\n" - " :return: The location of the uniform block variable.\n" - " :rtype: int\n"); +PyDoc_STRVAR(pygpu_shader_uniform_block_from_name_doc, + ".. method:: uniform_block_from_name(name)\n" + "\n" + " Get uniform block location by name.\n" + "\n" + " :arg name: Name of the uniform block variable whose location is to be queried.\n" + " :type name: str\n" + " :return: The location of the uniform block variable.\n" + " :rtype: int\n"); static PyObject *pygpu_shader_uniform_block_from_name(BPyGPUShader *self, PyObject *arg) { const char *name = PyUnicode_AsUTF8(arg); @@ -245,11 +244,11 @@ PyDoc_STRVAR(pygpu_shader_uniform_vector_float_doc, "\n" " Set the buffer to fill the uniform.\n" "\n" - " :param location: Location of the uniform variable to be modified.\n" + " :arg location: Location of the uniform variable to be modified.\n" " :type location: int\n" - " :param buffer: The data that should be set. Can support the buffer protocol.\n" + " :arg buffer: The data that should be set. Can support the buffer protocol.\n" " :type buffer: sequence of floats\n" - " :param length: Size of the uniform data type:\n\n" + " :arg length: Size of the uniform data type:\n\n" " - 1: float\n" " - 2: vec2 or float[2]\n" " - 3: vec3 or float[3]\n" @@ -257,7 +256,7 @@ PyDoc_STRVAR(pygpu_shader_uniform_vector_float_doc, " - 9: mat3\n" " - 16: mat4\n" " :type length: int\n" - " :param count: Specifies the number of elements, vector or matrices that are to " + " :arg count: Specifies the number of elements, vector or matrices that are to " "be modified.\n" " :type count: int\n"); static PyObject *pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject *args) @@ -271,6 +270,7 @@ static PyObject *pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject return NULL; } + GPU_shader_bind(self->shader); GPU_shader_uniform_vector(self->shader, location, length, count, pybuffer.buf); PyBuffer_Release(&pybuffer); @@ -293,6 +293,7 @@ static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *a return NULL; } + GPU_shader_bind(self->shader); GPU_shader_uniform_vector_int(self->shader, location, length, count, pybuffer.buf); PyBuffer_Release(&pybuffer); @@ -301,14 +302,14 @@ static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *a } PyDoc_STRVAR(pygpu_shader_uniform_bool_doc, - ".. method:: uniform_bool(name, seq)\n" + ".. method:: uniform_bool(name, value)\n" "\n" " Specify the value of a uniform variable for the current program object.\n" "\n" - " :param name: Name of the uniform variable whose value is to be changed.\n" + " :arg name: Name of the uniform variable whose value is to be changed.\n" " :type name: str\n" - " :param seq: Value that will be used to update the specified uniform variable.\n" - " :type seq: sequence of bools\n"); + " :arg value: Value that will be used to update the specified uniform variable.\n" + " :type value: bool or sequence of bools\n"); static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) { const char *error_prefix = "GPUShader.uniform_bool"; @@ -324,15 +325,14 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) int values[4]; int length; - int ret; - { + int ret = -1; + if (PySequence_Check(params.seq)) { PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix); if (seq_fast == NULL) { PyErr_Format(PyExc_TypeError, "%s: expected a sequence, got %s", error_prefix, Py_TYPE(params.seq)->tp_name); - ret = -1; } else { length = PySequence_Fast_GET_SIZE(seq_fast); @@ -341,7 +341,6 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) "%s: invalid sequence length. expected 1..4, got %d", error_prefix, length); - ret = -1; } else { ret = PyC_AsArray_FAST( @@ -350,6 +349,15 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) Py_DECREF(seq_fast); } } + else if (((values[0] = (int)PyLong_AsLong(params.seq)) != -1) && ELEM(values[0], 0, 1)) { + length = 1; + ret = 0; + } + else { + PyErr_Format( + PyExc_ValueError, "expected a bool or sequence, got %s", Py_TYPE(params.seq)->tp_name); + } + if (ret == -1) { return NULL; } @@ -360,6 +368,7 @@ static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) return NULL; } + GPU_shader_bind(self->shader); GPU_shader_uniform_vector_int(self->shader, location, length, 1, values); Py_RETURN_NONE; @@ -370,9 +379,9 @@ PyDoc_STRVAR(pygpu_shader_uniform_float_doc, "\n" " Specify the value of a uniform variable for the current program object.\n" "\n" - " :param name: Name of the uniform variable whose value is to be changed.\n" + " :arg name: Name of the uniform variable whose value is to be changed.\n" " :type name: str\n" - " :param value: Value that will be used to update the specified uniform variable.\n" + " :arg value: Value that will be used to update the specified uniform variable.\n" " :type value: single number or sequence of numbers\n"); static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args) { @@ -429,6 +438,7 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args) return NULL; } + GPU_shader_bind(self->shader); GPU_shader_uniform_vector(self->shader, location, length, 1, values); Py_RETURN_NONE; @@ -439,9 +449,9 @@ PyDoc_STRVAR(pygpu_shader_uniform_int_doc, "\n" " Specify the value of a uniform variable for the current program object.\n" "\n" - " :param name: name of the uniform variable whose value is to be changed.\n" + " :arg name: name of the uniform variable whose value is to be changed.\n" " :type name: str\n" - " :param seq: Value that will be used to update the specified uniform variable.\n" + " :arg seq: Value that will be used to update the specified uniform variable.\n" " :type seq: sequence of numbers\n"); static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args) { @@ -500,6 +510,7 @@ static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args) return NULL; } + GPU_shader_bind(self->shader); GPU_shader_uniform_vector_int(self->shader, location, length, 1, values); Py_RETURN_NONE; @@ -510,9 +521,9 @@ PyDoc_STRVAR(pygpu_shader_uniform_sampler_doc, "\n" " Specify the value of a texture uniform variable for the current GPUShader.\n" "\n" - " :param name: name of the uniform variable whose texture is to be specified.\n" + " :arg name: name of the uniform variable whose texture is to be specified.\n" " :type name: str\n" - " :param texture: Texture to attach.\n" + " :arg texture: Texture to attach.\n" " :type texture: :class:`gpu.types.GPUTexture`\n"); static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args) { @@ -523,6 +534,7 @@ static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args return NULL; } + GPU_shader_bind(self->shader); int slot = GPU_shader_get_texture_binding(self->shader, name); GPU_texture_bind(py_texture->tex, slot); GPU_shader_uniform_1i(self->shader, name, slot); @@ -536,9 +548,9 @@ PyDoc_STRVAR( "\n" " Specify the value of an uniform buffer object variable for the current GPUShader.\n" "\n" - " :param name: name of the uniform variable whose UBO is to be specified.\n" + " :arg name: name of the uniform variable whose UBO is to be specified.\n" " :type name: str\n" - " :param ubo: Uniform Buffer to attach.\n" + " :arg ubo: Uniform Buffer to attach.\n" " :type texture: :class:`gpu.types.GPUUniformBuf`\n"); static PyObject *pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args) { @@ -557,21 +569,21 @@ static PyObject *pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args) return NULL; } + GPU_shader_bind(self->shader); GPU_uniformbuf_bind(py_ubo->ubo, binding); Py_RETURN_NONE; } -PyDoc_STRVAR( - pygpu_shader_attr_from_name_doc, - ".. method:: attr_from_name(name)\n" - "\n" - " Get attribute location by name.\n" - "\n" - " :param name: The name of the attribute variable whose location is to be queried.\n" - " :type name: str\n" - " :return: The location of an attribute variable.\n" - " :rtype: int\n"); +PyDoc_STRVAR(pygpu_shader_attr_from_name_doc, + ".. method:: attr_from_name(name)\n" + "\n" + " Get attribute location by name.\n" + "\n" + " :arg name: The name of the attribute variable whose location is to be queried.\n" + " :type name: str\n" + " :return: The location of an attribute variable.\n" + " :rtype: int\n"); static PyObject *pygpu_shader_attr_from_name(BPyGPUShader *self, PyObject *arg) { const char *name = PyUnicode_AsUTF8(arg); @@ -743,17 +755,17 @@ PyDoc_STRVAR( " ``fragOutput = blender_srgb_to_framebuffer_space(fragOutput)``\n" " to transform the output sRGB colors to the frame-buffer color-space.\n" "\n" - " :param vertexcode: Vertex shader code.\n" + " :arg vertexcode: Vertex shader code.\n" " :type vertexcode: str\n" - " :param fragcode: Fragment shader code.\n" + " :arg fragcode: Fragment shader code.\n" " :type value: str\n" - " :param geocode: Geometry shader code.\n" + " :arg geocode: Geometry shader code.\n" " :type value: str\n" - " :param libcode: Code with functions and presets to be shared between shaders.\n" + " :arg libcode: Code with functions and presets to be shared between shaders.\n" " :type value: str\n" - " :param defines: Preprocessor directives.\n" + " :arg defines: Preprocessor directives.\n" " :type value: str\n" - " :param name: Name of shader code, for debugging purposes.\n" + " :arg name: Name of shader code, for debugging purposes.\n" " :type value: str\n"); PyTypeObject BPyGPUShader_Type = { PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUShader", @@ -812,9 +824,9 @@ PyDoc_STRVAR( "``CLIPPED`` value to the config parameter. Note that in this case you also need to " "manually set the value of ``mat4 ModelMatrix``.\n" "\n" - " :param shader_name: One of the builtin shader names.\n" + " :arg shader_name: One of the builtin shader names.\n" " :type shader_name: str\n" - " :param config: One of these types of shader configuration:\n" + " :arg config: One of these types of shader configuration:\n" "\n" " - ``DEFAULT``\n" " - ``CLIPPED``\n" @@ -858,7 +870,7 @@ PyDoc_STRVAR(pygpu_shader_create_from_info_doc, "\n" " Create shader from a GPUShaderCreateInfo.\n" "\n" - " :param shader_info: GPUShaderCreateInfo\n" + " :arg shader_info: GPUShaderCreateInfo\n" " :type shader_info: :class:`bpy.types.GPUShaderCreateInfo`\n" " :return: Shader object corresponding to the given name.\n" " :rtype: :class:`bpy.types.GPUShader`\n"); @@ -911,9 +923,14 @@ PyDoc_STRVAR(pygpu_shader_module__tp_doc, "\n" PYDOC_BUILTIN_SHADER_DESCRIPTION); static PyModuleDef pygpu_shader_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu.shader", - .m_doc = pygpu_shader_module__tp_doc, - .m_methods = pygpu_shader_module__tp_methods, + /*m_name*/ "gpu.shader", + /*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, }; /** \} */ diff --git a/source/blender/python/gpu/gpu_py_shader_create_info.cc b/source/blender/python/gpu/gpu_py_shader_create_info.cc index c9e49c5cc4b..6b1be057752 100644 --- a/source/blender/python/gpu/gpu_py_shader_create_info.cc +++ b/source/blender/python/gpu/gpu_py_shader_create_info.cc @@ -35,9 +35,9 @@ using blender::gpu::shader::Qualifier; " - ``READ``\n" \ " - ``WRITE``\n" static const struct PyC_FlagSet pygpu_qualifiers[] = { - {(int)Qualifier::NO_RESTRICT, "NO_RESTRICT"}, - {(int)Qualifier::READ, "READ"}, - {(int)Qualifier::WRITE, "WRITE"}, + {int(Qualifier::NO_RESTRICT), "NO_RESTRICT"}, + {int(Qualifier::READ), "READ"}, + {int(Qualifier::WRITE), "WRITE"}, {0, nullptr}, }; #endif @@ -59,21 +59,21 @@ static const struct PyC_FlagSet pygpu_qualifiers[] = { " - ``IVEC4``\n" \ " - ``BOOL``\n" const struct PyC_StringEnumItems pygpu_attrtype_items[] = { - {(int)Type::FLOAT, "FLOAT"}, - {(int)Type::VEC2, "VEC2"}, - {(int)Type::VEC3, "VEC3"}, - {(int)Type::VEC4, "VEC4"}, - {(int)Type::MAT3, "MAT3"}, - {(int)Type::MAT4, "MAT4"}, - {(int)Type::UINT, "UINT"}, - {(int)Type::UVEC2, "UVEC2"}, - {(int)Type::UVEC3, "UVEC3"}, - {(int)Type::UVEC4, "UVEC4"}, - {(int)Type::INT, "INT"}, - {(int)Type::IVEC2, "IVEC2"}, - {(int)Type::IVEC3, "IVEC3"}, - {(int)Type::IVEC4, "IVEC4"}, - {(int)Type::BOOL, "BOOL"}, + {int(Type::FLOAT), "FLOAT"}, + {int(Type::VEC2), "VEC2"}, + {int(Type::VEC3), "VEC3"}, + {int(Type::VEC4), "VEC4"}, + {int(Type::MAT3), "MAT3"}, + {int(Type::MAT4), "MAT4"}, + {int(Type::UINT), "UINT"}, + {int(Type::UVEC2), "UVEC2"}, + {int(Type::UVEC3), "UVEC3"}, + {int(Type::UVEC4), "UVEC4"}, + {int(Type::INT), "INT"}, + {int(Type::IVEC2), "IVEC2"}, + {int(Type::IVEC3), "IVEC3"}, + {int(Type::IVEC4), "IVEC4"}, + {int(Type::BOOL), "BOOL"}, {0, nullptr}, }; @@ -111,45 +111,45 @@ const struct PyC_StringEnumItems pygpu_attrtype_items[] = { " - ``DEPTH_CUBE``\n" \ " - ``DEPTH_CUBE_ARRAY``\n" static const struct PyC_StringEnumItems pygpu_imagetype_items[] = { - {(int)ImageType::FLOAT_BUFFER, "FLOAT_BUFFER"}, - {(int)ImageType::FLOAT_1D, "FLOAT_1D"}, - {(int)ImageType::FLOAT_1D_ARRAY, "FLOAT_1D_ARRAY"}, - {(int)ImageType::FLOAT_2D, "FLOAT_2D"}, - {(int)ImageType::FLOAT_2D_ARRAY, "FLOAT"}, - {(int)ImageType::FLOAT_3D, "FLOAT_2D_ARRAY"}, - {(int)ImageType::FLOAT_CUBE, "FLOAT_CUBE"}, - {(int)ImageType::FLOAT_CUBE_ARRAY, "FLOAT_CUBE_ARRAY"}, - {(int)ImageType::INT_BUFFER, "INT_BUFFER"}, - {(int)ImageType::INT_1D, "INT_1D"}, - {(int)ImageType::INT_1D_ARRAY, "INT_1D_ARRAY"}, - {(int)ImageType::INT_2D, "INT_2D"}, - {(int)ImageType::INT_2D_ARRAY, "INT_2D_ARRAY"}, - {(int)ImageType::INT_3D, "INT_3D"}, - {(int)ImageType::INT_CUBE, "INT_CUBE"}, - {(int)ImageType::INT_CUBE_ARRAY, "INT_CUBE_ARRAY"}, - {(int)ImageType::UINT_BUFFER, "UINT_BUFFER"}, - {(int)ImageType::UINT_1D, "UINT_1D"}, - {(int)ImageType::UINT_1D_ARRAY, "UINT_1D_ARRAY"}, - {(int)ImageType::UINT_2D, "UINT_2D"}, - {(int)ImageType::UINT_2D_ARRAY, "UINT_2D_ARRAY"}, - {(int)ImageType::UINT_3D, "UINT_3D"}, - {(int)ImageType::UINT_CUBE, "UINT_CUBE"}, - {(int)ImageType::UINT_CUBE_ARRAY, "UINT_CUBE_ARRAY"}, - {(int)ImageType::SHADOW_2D, "SHADOW_2D"}, - {(int)ImageType::SHADOW_2D_ARRAY, "SHADOW_2D_ARRAY"}, - {(int)ImageType::SHADOW_CUBE, "SHADOW_CUBE"}, - {(int)ImageType::SHADOW_CUBE_ARRAY, "SHADOW_CUBE_ARRAY"}, - {(int)ImageType::DEPTH_2D, "DEPTH_2D"}, - {(int)ImageType::DEPTH_2D_ARRAY, "DEPTH_2D_ARRAY"}, - {(int)ImageType::DEPTH_CUBE, "DEPTH_CUBE"}, - {(int)ImageType::DEPTH_CUBE_ARRAY, "DEPTH_CUBE_ARRAY"}, + {int(ImageType::FLOAT_BUFFER), "FLOAT_BUFFER"}, + {int(ImageType::FLOAT_1D), "FLOAT_1D"}, + {int(ImageType::FLOAT_1D_ARRAY), "FLOAT_1D_ARRAY"}, + {int(ImageType::FLOAT_2D), "FLOAT_2D"}, + {int(ImageType::FLOAT_2D_ARRAY), "FLOAT"}, + {int(ImageType::FLOAT_3D), "FLOAT_2D_ARRAY"}, + {int(ImageType::FLOAT_CUBE), "FLOAT_CUBE"}, + {int(ImageType::FLOAT_CUBE_ARRAY), "FLOAT_CUBE_ARRAY"}, + {int(ImageType::INT_BUFFER), "INT_BUFFER"}, + {int(ImageType::INT_1D), "INT_1D"}, + {int(ImageType::INT_1D_ARRAY), "INT_1D_ARRAY"}, + {int(ImageType::INT_2D), "INT_2D"}, + {int(ImageType::INT_2D_ARRAY), "INT_2D_ARRAY"}, + {int(ImageType::INT_3D), "INT_3D"}, + {int(ImageType::INT_CUBE), "INT_CUBE"}, + {int(ImageType::INT_CUBE_ARRAY), "INT_CUBE_ARRAY"}, + {int(ImageType::UINT_BUFFER), "UINT_BUFFER"}, + {int(ImageType::UINT_1D), "UINT_1D"}, + {int(ImageType::UINT_1D_ARRAY), "UINT_1D_ARRAY"}, + {int(ImageType::UINT_2D), "UINT_2D"}, + {int(ImageType::UINT_2D_ARRAY), "UINT_2D_ARRAY"}, + {int(ImageType::UINT_3D), "UINT_3D"}, + {int(ImageType::UINT_CUBE), "UINT_CUBE"}, + {int(ImageType::UINT_CUBE_ARRAY), "UINT_CUBE_ARRAY"}, + {int(ImageType::SHADOW_2D), "SHADOW_2D"}, + {int(ImageType::SHADOW_2D_ARRAY), "SHADOW_2D_ARRAY"}, + {int(ImageType::SHADOW_CUBE), "SHADOW_CUBE"}, + {int(ImageType::SHADOW_CUBE_ARRAY), "SHADOW_CUBE_ARRAY"}, + {int(ImageType::DEPTH_2D), "DEPTH_2D"}, + {int(ImageType::DEPTH_2D_ARRAY), "DEPTH_2D_ARRAY"}, + {int(ImageType::DEPTH_CUBE), "DEPTH_CUBE"}, + {int(ImageType::DEPTH_CUBE_ARRAY), "DEPTH_CUBE_ARRAY"}, {0, nullptr}, }; static const struct PyC_StringEnumItems pygpu_dualblend_items[] = { - {(int)DualBlend::NONE, "NONE"}, - {(int)DualBlend::SRC_0, "SRC_0"}, - {(int)DualBlend::SRC_1, "SRC_1"}, + {int(DualBlend::NONE), "NONE"}, + {int(DualBlend::SRC_0), "SRC_0"}, + {int(DualBlend::SRC_1), "SRC_1"}, {0, nullptr}, }; @@ -189,11 +189,11 @@ PyDoc_STRVAR(pygpu_interface_info_smooth_doc, "\n" " Add an attribute with qualifier of type `smooth` to the interface block.\n" "\n" - " :param type: One of these types:\n" + " :arg type: One of these types:\n" "\n" PYDOC_TYPE_LIST "\n" " :type type: str\n" - " :param name: name of the attribute.\n" + " :arg name: name of the attribute.\n" " :type name: str\n"); static PyObject *pygpu_interface_info_smooth(BPyGPUStageInterfaceInfo *self, PyObject *args) { @@ -213,11 +213,11 @@ PyDoc_STRVAR(pygpu_interface_info_flat_doc, "\n" " Add an attribute with qualifier of type `flat` to the interface block.\n" "\n" - " :param type: One of these types:\n" + " :arg type: One of these types:\n" "\n" PYDOC_TYPE_LIST "\n" " :type type: str\n" - " :param name: name of the attribute.\n" + " :arg name: name of the attribute.\n" " :type name: str\n"); static PyObject *pygpu_interface_info_flat(BPyGPUStageInterfaceInfo *self, PyObject *args) { @@ -238,11 +238,11 @@ PyDoc_STRVAR( "\n" " Add an attribute with qualifier of type `no_perspective` to the interface block.\n" "\n" - " :param type: One of these types:\n" + " :arg type: One of these types:\n" "\n" PYDOC_TYPE_LIST "\n" " :type type: str\n" - " :param name: name of the attribute.\n" + " :arg name: name of the attribute.\n" " :type name: str\n"); static PyObject *pygpu_interface_info_no_perspective(BPyGPUStageInterfaceInfo *self, PyObject *args) @@ -281,8 +281,7 @@ PyDoc_STRVAR(pygpu_interface_info_name_doc, "Name of the interface block.\n" "\n" ":type: str"); -static PyObject *pygpu_interface_info_name_get(BPyGPUStageInterfaceInfo *self, - void *UNUSED(closure)) +static PyObject *pygpu_interface_info_name_get(BPyGPUStageInterfaceInfo *self, void * /*closure*/) { StageInterfaceInfo *interface = reinterpret_cast<StageInterfaceInfo *>(self->interface); return PyUnicode_FromString(interface->name.c_str()); @@ -303,7 +302,7 @@ static PyGetSetDef pygpu_interface_info__tp_getseters[] = { /** \name GPUStageInterfaceInfo Type * \{ */ -static PyObject *pygpu_interface_info__tp_new(PyTypeObject *UNUSED(type), +static PyObject *pygpu_interface_info__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds) { @@ -370,7 +369,7 @@ PyDoc_STRVAR(pygpu_interface_info__tp_doc, "\n" " List of varyings between shader stages.\n\n" "\n" - " :param name: Name of the interface block.\n" + " :arg name: Name of the interface block.\n" " :type value: str\n"); constexpr PyTypeObject pygpu_interface_info_type() { @@ -403,13 +402,13 @@ PyDoc_STRVAR(pygpu_shader_info_vertex_in_doc, "\n" " Add a vertex shader input attribute.\n" "\n" - " :param slot: The attribute index.\n" + " :arg slot: The attribute index.\n" " :type slot: int\n" - " :param type: One of these types:\n" + " :arg type: One of these types:\n" "\n" PYDOC_TYPE_LIST "\n" " :type type: str\n" - " :param name: name of the attribute.\n" + " :arg name: name of the attribute.\n" " :type name: str\n"); static PyObject *pygpu_shader_info_vertex_in(BPyGPUShaderCreateInfo *self, PyObject *args) { @@ -436,7 +435,7 @@ PyDoc_STRVAR(pygpu_shader_info_vertex_out_doc, "\n" " Add a vertex shader output interface block.\n" "\n" - " :param interface: Object describing the block.\n" + " :arg interface: Object describing the block.\n" " :type interface: :class:`gpu.types.GPUStageInterfaceInfo`\n"); static PyObject *pygpu_shader_info_vertex_out(BPyGPUShaderCreateInfo *self, BPyGPUStageInterfaceInfo *o) @@ -462,15 +461,15 @@ PyDoc_STRVAR(pygpu_shader_info_fragment_out_doc, "\n" " Specify a fragment output corresponding to a framebuffer target slot.\n" "\n" - " :param slot: The attribute index.\n" + " :arg slot: The attribute index.\n" " :type slot: int\n" - " :param type: One of these types:\n" + " :arg type: One of these types:\n" "\n" PYDOC_TYPE_LIST "\n" " :type type: str\n" - " :param name: Name of the attribute.\n" + " :arg name: Name of the attribute.\n" " :type name: str\n" - " :param blend: Dual Source Blending Index. It can be 'NONE', 'SRC_0' or 'SRC_1'.\n" + " :arg blend: Dual Source Blending Index. It can be 'NONE', 'SRC_0' or 'SRC_1'.\n" " :type blend: str\n"); static PyObject *pygpu_shader_info_fragment_out(BPyGPUShaderCreateInfo *self, PyObject *args, @@ -479,7 +478,7 @@ static PyObject *pygpu_shader_info_fragment_out(BPyGPUShaderCreateInfo *self, int slot; struct PyC_StringEnum pygpu_type = {pygpu_attrtype_items}; const char *name; - struct PyC_StringEnum blend_type = {pygpu_dualblend_items, (int)DualBlend::NONE}; + struct PyC_StringEnum blend_type = {pygpu_dualblend_items, int(DualBlend::NONE)}; static const char *_keywords[] = {"slot", "type", "name", "blend", nullptr}; static _PyArg_Parser _parser = { @@ -521,12 +520,12 @@ PyDoc_STRVAR( "\n" " Specify a uniform variable whose type can be one of those declared in `typedef_source`.\n" "\n" - " :param slot: The uniform variable index.\n" + " :arg slot: The uniform variable index.\n" " :type slot: int\n" - " :param type_name: Name of the data type. It can be a struct type defined in the source " + " :arg type_name: Name of the data type. It can be a struct type defined in the source " "passed through the :meth:`gpu.types.GPUShaderCreateInfo.typedef_source`.\n" " :type type_name: str\n" - " :param name: The uniform variable name.\n" + " :arg name: The uniform variable name.\n" " :type name: str\n"); static PyObject *pygpu_shader_info_uniform_buf(BPyGPUShaderCreateInfo *self, PyObject *args) { @@ -556,19 +555,19 @@ PyDoc_STRVAR( "\n" " Specify an image resource used for arbitrary load and store operations.\n" "\n" - " :param slot: The image resource index.\n" + " :arg slot: The image resource index.\n" " :type slot: int\n" - " :param format: The GPUTexture format that is passed to the shader. Possible values are:\n" + " :arg format: The GPUTexture format that is passed to the shader. Possible values are:\n" "" PYDOC_TEX_FORMAT_ITEMS " :type format: str\n" - " :param type: The data type describing how the image is to be read in the shader. " + " :arg type: The data type describing how the image is to be read in the shader. " "Possible values are:\n" "\n" PYDOC_IMAGE_TYPES "\n" " :type type: str\n" - " :param name: The image resource name.\n" + " :arg name: The image resource name.\n" " :type name: str\n" - " :param qualifiers: Set containing values that describe how the image resource is to be " + " :arg qualifiers: Set containing values that describe how the image resource is to be " "read or written. Possible values are:\n" "" PYDOC_QUALIFIERS "" @@ -636,14 +635,14 @@ PyDoc_STRVAR( "\n" " Specify an image texture sampler.\n" "\n" - " :param slot: The image texture sampler index.\n" + " :arg slot: The image texture sampler index.\n" " :type slot: int\n" - " :param type: The data type describing the format of each sampler unit. Possible values " + " :arg type: The data type describing the format of each sampler unit. Possible values " "are:\n" "\n" PYDOC_IMAGE_TYPES "\n" " :type type: str\n" - " :param name: The image texture sampler name.\n" + " :arg name: The image texture sampler name.\n" " :type name: str\n"); static PyObject *pygpu_shader_info_sampler(BPyGPUShaderCreateInfo *self, PyObject *args) { @@ -748,13 +747,13 @@ PyDoc_STRVAR(pygpu_shader_info_push_constant_doc, "\n" " Specify a global access constant.\n" "\n" - " :param type: One of these types:\n" + " :arg type: One of these types:\n" "\n" PYDOC_TYPE_LIST "\n" " :type type: str\n" - " :param name: Name of the constant.\n" + " :arg name: Name of the constant.\n" " :type name: str\n" - " :param size: If not zero, indicates that the constant is an array with the " + " :arg size: If not zero, indicates that the constant is an array with the " "specified size.\n" " :type size: uint\n"); static PyObject *pygpu_shader_info_push_constant(BPyGPUShaderCreateInfo *self, @@ -812,7 +811,7 @@ PyDoc_STRVAR( "\n" " \"void main {gl_Position = vec4(pos, 1.0);}\"\n" "\n" - " :param source: The vertex shader source code.\n" + " :arg source: The vertex shader source code.\n" " :type source: str\n" "\n" " .. seealso:: `GLSL Cross Compilation " @@ -853,7 +852,7 @@ PyDoc_STRVAR( "\n" " \"void main {fragColor = vec4(0.0, 0.0, 0.0, 1.0);}\"\n" "\n" - " :param source: The fragment shader source code.\n" + " :arg source: The fragment shader source code.\n" " :type source: str\n" "\n" " .. seealso:: `GLSL Cross Compilation " @@ -894,7 +893,7 @@ PyDoc_STRVAR(pygpu_shader_info_typedef_source_doc, "\n" " \"struct MyType {int foo; float bar;};\"\n" "\n" - " :param source: The source code defining types.\n" + " :arg source: The source code defining types.\n" " :type source: str\n"); static PyObject *pygpu_shader_info_typedef_source(BPyGPUShaderCreateInfo *self, PyObject *o) { @@ -933,9 +932,9 @@ PyDoc_STRVAR(pygpu_shader_info_define_doc, "\n" " #define name value\n" "\n" - " :param name: Token name.\n" + " :arg name: Token name.\n" " :type name: str\n" - " :param value: Text that replaces token occurrences.\n" + " :arg value: Text that replaces token occurrences.\n" " :type value: str\n"); static PyObject *pygpu_shader_info_define(BPyGPUShaderCreateInfo *self, PyObject *args) { @@ -1014,12 +1013,10 @@ static struct PyMethodDef pygpu_shader_info__tp_methods[] = { /** \} */ /* -------------------------------------------------------------------- */ -/** \name GPUShaderCreateInfo Init +/** \name GPUShaderCreateInfo Initialization * \{ */ -static PyObject *pygpu_shader_info__tp_new(PyTypeObject *UNUSED(type), - PyObject *args, - PyObject *kwds) +static PyObject *pygpu_shader_info__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds) { if (PyTuple_Size(args) || kwds) { PyErr_SetString(PyExc_TypeError, "no args or keywords are expected"); diff --git a/source/blender/python/gpu/gpu_py_state.c b/source/blender/python/gpu/gpu_py_state.c index fb69bb316c4..f17a3fecfdd 100644 --- a/source/blender/python/gpu/gpu_py_state.c +++ b/source/blender/python/gpu/gpu_py_state.c @@ -72,7 +72,7 @@ PyDoc_STRVAR( "\n" " Defines the fixed pipeline blending equation.\n" "\n" - " :param mode: The type of blend mode.\n" + " :arg mode: The type of blend mode.\n" " * ``NONE`` No blending.\n" " * ``ALPHA`` The original color channels are interpolated according to the alpha " "value.\n" @@ -114,7 +114,7 @@ PyDoc_STRVAR(pygpu_state_clip_distances_set_doc, "\n" " Sets the number of `gl_ClipDistance` planes used for clip geometry.\n" "\n" - " :param distances_enabled: Number of clip distances enabled.\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) { @@ -136,7 +136,7 @@ PyDoc_STRVAR(pygpu_state_depth_test_set_doc, "\n" " Defines the depth_test equation.\n" "\n" - " :param mode: The depth test equation name.\n" + " :arg mode: The depth test equation name.\n" " Possible values are `NONE`, `ALWAYS`, `LESS`, `LESS_EQUAL`, `EQUAL`, " "`GREATER` and `GREATER_EQUAL`.\n" " :type mode: str\n"); @@ -166,7 +166,7 @@ PyDoc_STRVAR(pygpu_state_depth_mask_set_doc, "\n" " Write to depth component.\n" "\n" - " :param value: True for writing to the depth component.\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) { @@ -193,9 +193,10 @@ PyDoc_STRVAR(pygpu_state_viewport_set_doc, " Specifies the viewport of the active framebuffer.\n" " Note: The viewport state is not saved upon framebuffer rebind.\n" "\n" - " :param x, y: lower left corner of the viewport_set rectangle, in pixels.\n" - " :param width, height: width and height of the viewport_set.\n" - " :type x, y, xsize, ysize: int\n"); + " :arg x, y: lower left corner of the viewport_set rectangle, in pixels.\n" + " :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) { int x, y, xsize, ysize; @@ -230,7 +231,7 @@ PyDoc_STRVAR(pygpu_state_line_width_set_doc, "\n" " Specify the width of rasterized lines.\n" "\n" - " :param size: New width.\n" + " :arg size: New width.\n" " :type mode: float\n"); static PyObject *pygpu_state_line_width_set(PyObject *UNUSED(self), PyObject *value) { @@ -258,7 +259,7 @@ PyDoc_STRVAR(pygpu_state_point_size_set_doc, "\n" " Specify the diameter of rasterized points.\n" "\n" - " :param size: New diameter.\n" + " :arg size: New diameter.\n" " :type mode: float\n"); static PyObject *pygpu_state_point_size_set(PyObject *UNUSED(self), PyObject *value) { @@ -276,7 +277,7 @@ PyDoc_STRVAR(pygpu_state_color_mask_set_doc, "\n" " Enable or disable writing of frame buffer color components.\n" "\n" - " :param r, g, b, a: components red, green, blue, and alpha.\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) { @@ -294,7 +295,7 @@ PyDoc_STRVAR(pygpu_state_face_culling_set_doc, "\n" " Specify whether none, front-facing or back-facing facets can be culled.\n" "\n" - " :param mode: `NONE`, `FRONT` or `BACK`.\n" + " :arg mode: `NONE`, `FRONT` or `BACK`.\n" " :type mode: str\n"); static PyObject *pygpu_state_face_culling_set(PyObject *UNUSED(self), PyObject *value) { @@ -312,7 +313,7 @@ PyDoc_STRVAR(pygpu_state_front_facing_set_doc, "\n" " Specifies the orientation of front-facing polygons.\n" "\n" - " :param invert: True for clockwise polygons as front-facing.\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) { @@ -331,7 +332,7 @@ PyDoc_STRVAR(pygpu_state_program_point_size_set_doc, " If enabled, the derived point size is taken from the (potentially clipped) " "shader builtin gl_PointSize.\n" "\n" - " :param enable: True for shader builtin gl_PointSize.\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) { @@ -430,9 +431,14 @@ static struct PyMethodDef pygpu_state__tp_methods[] = { PyDoc_STRVAR(pygpu_state__tp_doc, "This module provides access to the gpu state."); static PyModuleDef pygpu_state_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu.state", - .m_doc = pygpu_state__tp_doc, - .m_methods = pygpu_state__tp_methods, + /*m_name*/ "gpu.state", + /*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, }; PyObject *bpygpu_state_init(void) diff --git a/source/blender/python/gpu/gpu_py_texture.c b/source/blender/python/gpu/gpu_py_texture.c index 7a23f7ac91f..11b44a2a35e 100644 --- a/source/blender/python/gpu/gpu_py_texture.c +++ b/source/blender/python/gpu/gpu_py_texture.c @@ -280,9 +280,9 @@ PyDoc_STRVAR( "\n" " Fill texture with specific value.\n" "\n" - " :param format: The format that describes the content of a single item.\n" + " :arg format: The format that describes the content of a single item.\n" " Possible values are `FLOAT`, `INT`, `UINT`, `UBYTE`, `UINT_24_8` and `10_11_11_REV`.\n" - " :type type: str\n" + " :type format: str\n" " :arg value: sequence each representing the value to fill.\n" " :type value: sequence of 1, 2, 3 or 4 values\n"); static PyObject *pygpu_texture_clear(BPyGPUTexture *self, PyObject *args, PyObject *kwds) @@ -565,9 +565,14 @@ static struct PyMethodDef pygpu_texture__m_methods[] = { PyDoc_STRVAR(pygpu_texture__m_doc, "This module provides utils for textures."); static PyModuleDef pygpu_texture_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu.texture", - .m_doc = pygpu_texture__m_doc, - .m_methods = pygpu_texture__m_methods, + /*m_name*/ "gpu.texture", + /*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, }; /** \} */ diff --git a/source/blender/python/gpu/gpu_py_types.c b/source/blender/python/gpu/gpu_py_types.c index eccbebbd8dd..b5cabd93b42 100644 --- a/source/blender/python/gpu/gpu_py_types.c +++ b/source/blender/python/gpu/gpu_py_types.c @@ -19,7 +19,14 @@ static struct PyModuleDef pygpu_types_module_def = { PyModuleDef_HEAD_INIT, - .m_name = "gpu.types", + /*m_name*/ "gpu.types", + /*m_doc*/ NULL, + /*m_size*/ 0, + /*m_methods*/ NULL, + /*m_slots*/ NULL, + /*m_traverse*/ NULL, + /*m_clear*/ NULL, + /*m_free*/ NULL, }; PyObject *bpygpu_types_init(void) diff --git a/source/blender/python/gpu/gpu_py_vertex_buffer.c b/source/blender/python/gpu/gpu_py_vertex_buffer.c index ab2ff59a689..fd36c0a2d71 100644 --- a/source/blender/python/gpu/gpu_py_vertex_buffer.c +++ b/source/blender/python/gpu/gpu_py_vertex_buffer.c @@ -261,9 +261,9 @@ PyDoc_STRVAR(pygpu_vertbuf_attr_fill_doc, "\n" " Insert data into the buffer for a single attribute.\n" "\n" - " :param id: Either the name or the id of the attribute.\n" + " :arg id: Either the name or the id of the attribute.\n" " :type id: int or str\n" - " :param data: Sequence of data that should be stored in the buffer\n" + " :arg data: Sequence of data that should be stored in the buffer\n" " :type data: sequence of floats, ints, vectors or matrices\n"); static PyObject *pygpu_vertbuf_attr_fill(BPyGPUVertBuf *self, PyObject *args, PyObject *kwds) { @@ -327,10 +327,10 @@ PyDoc_STRVAR(pygpu_vertbuf__tp_doc, "\n" " Contains a VBO.\n" "\n" - " :param format: Vertex format.\n" - " :type buf: :class:`gpu.types.GPUVertFormat`\n" - " :param len: Amount of vertices that will fit into this buffer.\n" - " :type type: `int`\n"); + " :arg format: Vertex format.\n" + " :type format: :class:`gpu.types.GPUVertFormat`\n" + " :arg len: Amount of vertices that will fit into this buffer.\n" + " :type len: int\n"); PyTypeObject BPyGPUVertBuf_Type = { PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUVertBuf", .tp_basicsize = sizeof(BPyGPUVertBuf), diff --git a/source/blender/python/gpu/gpu_py_vertex_format.c b/source/blender/python/gpu/gpu_py_vertex_format.c index 40a0e5d1e9f..ac0ec6bdc01 100644 --- a/source/blender/python/gpu/gpu_py_vertex_format.c +++ b/source/blender/python/gpu/gpu_py_vertex_format.c @@ -63,15 +63,15 @@ PyDoc_STRVAR( "\n" " Add a new attribute to the format.\n" "\n" - " :param id: Name the attribute. Often `position`, `normal`, ...\n" + " :arg id: Name the attribute. Often `position`, `normal`, ...\n" " :type id: str\n" - " :param comp_type: The data type that will be used store the value in memory.\n" + " :arg comp_type: The data type that will be used store the value in memory.\n" " Possible values are `I8`, `U8`, `I16`, `U16`, `I32`, `U32`, `F32` and `I10`.\n" " :type comp_type: str\n" - " :param len: How many individual values the attribute consists of\n" + " :arg len: How many individual values the attribute consists of\n" " (e.g. 2 for uv coordinates).\n" " :type len: int\n" - " :param fetch_mode: How values from memory will be converted when used in the shader.\n" + " :arg fetch_mode: How values from memory will be converted when used in the shader.\n" " This is mainly useful for memory optimizations when you want to store values with\n" " reduced precision. E.g. you can store a float in only 1 byte but it will be\n" " converted to a normal 4 byte float when used.\n" |