32 const char *error_prefix =
"IndexBuf.__new__";
42 static const char *_keywords[] = {
"type",
"seq",
nullptr};
43 static _PyArg_Parser _parser = {
52 if (!_PyArg_ParseTupleAndKeywordsFast(
59 if (verts_per_prim == -1) {
60 PyErr_SetString(PyExc_ValueError,
61 "The argument 'type' must be "
62 "'POINTS', 'LINES', 'TRIS', 'LINES_ADJ' or 'TRIS_ADJ'");
66 if (PyObject_CheckBuffer(seq)) {
69 if (PyObject_GetBuffer(seq, &pybuffer, PyBUF_FORMAT | PyBUF_ND) == -1) {
74 if (pybuffer.ndim != 1 && pybuffer.shape[1] != verts_per_prim) {
75 PyErr_Format(PyExc_ValueError,
"Each primitive must exactly %d indices", verts_per_prim);
76 PyBuffer_Release(&pybuffer);
80 if (pybuffer.itemsize != 4 ||
83 PyErr_SetString(PyExc_ValueError,
"Each index must be an 4-bytes integer value");
84 PyBuffer_Release(&pybuffer);
88 index_len = pybuffer.shape[0];
89 if (pybuffer.ndim != 1) {
90 index_len *= pybuffer.shape[1];
98 uint *buf =
static_cast<uint *
>(pybuffer.buf);
99 for (
uint i = index_len;
i--; buf++) {
103 PyBuffer_Release(&pybuffer);
106 PyObject *seq_fast = PySequence_Fast(seq, error_prefix);
108 if (seq_fast ==
nullptr) {
112 const uint seq_len = PySequence_Fast_GET_SIZE(seq_fast);
114 PyObject **seq_items = PySequence_Fast_ITEMS(seq_fast);
116 index_len = seq_len * verts_per_prim;
123 if (verts_per_prim == 1) {
124 for (
uint i = 0;
i < seq_len;
i++) {
130 for (
uint i = 0;
i < seq_len;
i++) {
131 PyObject *seq_fast_item = PySequence_Fast(seq_items[
i], error_prefix);
132 if (seq_fast_item ==
nullptr) {
133 PyErr_Format(PyExc_TypeError,
134 "%s: expected a sequence, got %s",
136 Py_TYPE(seq_items[
i])->tp_name);
149 for (
uint j = 0; j < verts_per_prim; j++) {
157 if (PyErr_Occurred()) {
182 pygpu_IndexBuf__tp_doc,
183 ".. class:: GPUIndexBuf(type, seq)\n"
185 " Contains an index buffer.\n"
187 " :arg type: The primitive type this index buffer is composed of.\n"
188 " Possible values are [``POINTS``, ``LINES``, ``TRIS``, ``LINES_ADJ``, ``TRIS_ADJ``].\n"
190 " :arg seq: Indices this index buffer will contain.\n"
191 " Whether a 1D or 2D sequence is required depends on the type.\n"
192 " Optionally the sequence can support the buffer protocol.\n"
193 " :type seq: Buffer | Sequence[int] | Sequence[Sequence[int]]\n");
195 PyVarObject_HEAD_INIT(
nullptr, 0)
215 pygpu_IndexBuf__tp_doc,
259 return (PyObject *)
self;
void GPU_indexbuf_discard(blender::gpu::IndexBuf *elem)
int GPU_indexbuf_primitive_len(GPUPrimType prim_type)
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
blender::gpu::IndexBuf * GPU_indexbuf_build(GPUIndexBufBuilder *)
void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *, uint v)
Read Guarded memory(de)allocation.
PyC_StringEnumItems bpygpu_primtype_items[]
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
PyDoc_STRVAR(pygpu_IndexBuf__tp_doc, ".. class:: GPUIndexBuf(type, seq)\n" "\n" " Contains an index buffer.\n" "\n" " :arg type: The primitive type this index buffer is composed of.\n" " Possible values are [``POINTS``, ``LINES``, ``TRIS``, ``LINES_ADJ``, ``TRIS_ADJ``].\n" " :type type: str\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: Buffer | Sequence[int] | Sequence[Sequence[int]]\n")
static void pygpu_IndexBuf__tp_dealloc(BPyGPUIndexBuf *self)
PyObject * BPyGPUIndexBuf_CreatePyObject(blender::gpu::IndexBuf *elem)
static PyObject * pygpu_IndexBuf__tp_new(PyTypeObject *, PyObject *args, PyObject *kwds)
PyTypeObject BPyGPUIndexBuf_Type
void MEM_freeN(void *vmemh)
char PyC_StructFmt_type_from_str(const char *typestr)
int PyC_ParseStringEnum(PyObject *o, void *p)
uint32_t PyC_Long_AsU32(PyObject *value)
int PyC_AsArray_FAST(void *array, const size_t array_item_size, PyObject *value_fast, const Py_ssize_t length, const PyTypeObject *type, const char *error_prefix)
bool PyC_StructFmt_type_is_float_any(char format)
header-only compatibility defines.
#define PY_ARG_PARSER_HEAD_COMPAT()