18 #include "../generic/py_capi_utils.h"
31 const char *error_prefix =
"IndexBuf.__new__";
41 static const char *_keywords[] = {
"type",
"seq",
NULL};
42 static _PyArg_Parser _parser = {
49 if (!_PyArg_ParseTupleAndKeywordsFast(
55 if (verts_per_prim == -1) {
56 PyErr_Format(PyExc_ValueError,
57 "The argument 'type' must be "
58 "'POINTS', 'LINES', 'TRIS' or 'LINES_ADJ'");
62 if (PyObject_CheckBuffer(seq)) {
65 if (PyObject_GetBuffer(seq, &pybuffer, PyBUF_FORMAT | PyBUF_ND) == -1) {
70 if (pybuffer.ndim != 1 && pybuffer.shape[1] != verts_per_prim) {
71 PyErr_Format(PyExc_ValueError,
"Each primitive must exactly %d indices", verts_per_prim);
72 PyBuffer_Release(&pybuffer);
76 if (pybuffer.itemsize != 4 ||
78 PyErr_Format(PyExc_ValueError,
"Each index must be an 4-bytes integer value");
79 PyBuffer_Release(&pybuffer);
83 index_len = pybuffer.shape[0];
84 if (pybuffer.ndim != 1) {
85 index_len *= pybuffer.shape[1];
93 uint *buf = pybuffer.buf;
94 for (
uint i = index_len; i--; buf++) {
98 PyBuffer_Release(&pybuffer);
101 PyObject *seq_fast = PySequence_Fast(seq, error_prefix);
103 if (seq_fast ==
NULL) {
107 const uint seq_len = PySequence_Fast_GET_SIZE(seq_fast);
109 PyObject **seq_items = PySequence_Fast_ITEMS(seq_fast);
111 index_len = seq_len * verts_per_prim;
118 if (verts_per_prim == 1) {
119 for (
uint i = 0; i < seq_len; i++) {
125 for (
uint i = 0; i < seq_len; i++) {
126 PyObject *seq_fast_item = PySequence_Fast(seq_items[i], error_prefix);
127 if (seq_fast_item ==
NULL) {
128 PyErr_Format(PyExc_TypeError,
129 "%s: expected a sequence, got %s",
131 Py_TYPE(seq_items[i])->tp_name);
144 for (
uint j = 0; j < verts_per_prim; j++) {
148 Py_DECREF(seq_fast_item);
152 if (PyErr_Occurred()) {
172 Py_TYPE(
self)->tp_free(
self);
176 ".. class:: GPUIndexBuf(type, seq)\n"
178 " Contains an index buffer.\n"
180 " :arg type: The primitive type this index buffer is composed of.\n"
181 " Possible values are `POINTS`, `LINES`, `TRIS` and `LINE_STRIP_ADJ`.\n"
183 " :param seq: Indices this index buffer will contain.\n"
184 " Whether a 1D or 2D sequence is required depends on the type.\n"
185 " Optionally the sequence can support the buffer protocol.\n"
186 " :type seq: 1D or 2D sequence\n");
188 PyVarObject_HEAD_INIT(
NULL, 0).tp_name =
"GPUIndexBuf",
191 .tp_flags = Py_TPFLAGS_DEFAULT,
192 .tp_doc = pygpu_IndexBuf__tp_doc,
209 return (PyObject *)
self;
struct GPUIndexBuf GPUIndexBuf
int GPU_indexbuf_primitive_len(GPUPrimType prim_type)
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
GPUIndexBuf * GPU_indexbuf_build(GPUIndexBufBuilder *)
void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *, uint v)
void GPU_indexbuf_discard(GPUIndexBuf *elem)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
struct PyC_StringEnumItems bpygpu_primtype_items[]
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
static void pygpu_IndexBuf__tp_dealloc(BPyGPUIndexBuf *self)
PyObject * BPyGPUIndexBuf_CreatePyObject(GPUIndexBuf *elem)
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` and `LINE_STRIP_ADJ`.\n" " :type type: str\n" " :param 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")
PyTypeObject BPyGPUIndexBuf_Type
static PyObject * pygpu_IndexBuf__tp_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
struct BPyGPUIndexBuf BPyGPUIndexBuf
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)