32 const char *error_prefix =
"IndexBuf.__new__";
42 static const char *_keywords[] = {
"type",
"seq",
nullptr};
43 static _PyArg_Parser _parser = {
51 if (!_PyArg_ParseTupleAndKeywordsFast(
58 if (verts_per_prim == -1) {
59 PyErr_Format(PyExc_ValueError,
60 "The argument 'type' must be "
61 "'POINTS', 'LINES', 'TRIS', 'LINES_ADJ' or 'TRIS_ADJ'");
65 if (PyObject_CheckBuffer(seq)) {
68 if (PyObject_GetBuffer(seq, &pybuffer, PyBUF_FORMAT | PyBUF_ND) == -1) {
73 if (pybuffer.ndim != 1 && pybuffer.shape[1] != verts_per_prim) {
74 PyErr_Format(PyExc_ValueError,
"Each primitive must exactly %d indices", verts_per_prim);
75 PyBuffer_Release(&pybuffer);
79 if (pybuffer.itemsize != 4 ||
82 PyErr_Format(PyExc_ValueError,
"Each index must be an 4-bytes integer value");
83 PyBuffer_Release(&pybuffer);
87 index_len = pybuffer.shape[0];
88 if (pybuffer.ndim != 1) {
89 index_len *= pybuffer.shape[1];
97 uint *buf =
static_cast<uint *
>(pybuffer.buf);
98 for (
uint i = index_len; i--; buf++) {
102 PyBuffer_Release(&pybuffer);
105 PyObject *seq_fast = PySequence_Fast(seq, error_prefix);
107 if (seq_fast ==
nullptr) {
111 const uint seq_len = PySequence_Fast_GET_SIZE(seq_fast);
113 PyObject **seq_items = PySequence_Fast_ITEMS(seq_fast);
115 index_len = seq_len * verts_per_prim;
122 if (verts_per_prim == 1) {
123 for (
uint i = 0; i < seq_len; i++) {
129 for (
uint i = 0; i < seq_len; i++) {
130 PyObject *seq_fast_item = PySequence_Fast(seq_items[i], error_prefix);
131 if (seq_fast_item ==
nullptr) {
132 PyErr_Format(PyExc_TypeError,
133 "%s: expected a sequence, got %s",
135 Py_TYPE(seq_items[i])->tp_name);
148 for (
uint j = 0; j < verts_per_prim; j++) {
152 Py_DECREF(seq_fast_item);
156 if (PyErr_Occurred()) {
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")
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)