32 #include "../generic/py_capi_utils.h"
33 #include "../generic/python_utildefines.h"
46 const char *error_prefix =
"IndexBuf.__new__";
56 static const char *_keywords[] = {
"type",
"seq",
NULL};
57 static _PyArg_Parser _parser = {
"$O&O:IndexBuf.__new__", _keywords, 0};
58 if (!_PyArg_ParseTupleAndKeywordsFast(
64 if (verts_per_prim == -1) {
65 PyErr_Format(PyExc_ValueError,
66 "The argument 'type' must be "
67 "'POINTS', 'LINES', 'TRIS' or 'LINES_ADJ'");
71 if (PyObject_CheckBuffer(seq)) {
74 if (PyObject_GetBuffer(seq, &pybuffer, PyBUF_FORMAT | PyBUF_ND) == -1) {
79 if (pybuffer.ndim != 1 && pybuffer.shape[1] != verts_per_prim) {
80 PyErr_Format(PyExc_ValueError,
"Each primitive must exactly %d indices", verts_per_prim);
84 if (pybuffer.itemsize != 4 ||
86 PyErr_Format(PyExc_ValueError,
"Each index must be an 4-bytes integer value");
90 index_len = pybuffer.shape[0];
91 if (pybuffer.ndim != 1) {
92 index_len *= pybuffer.shape[1];
101 uint *buf = pybuffer.buf;
102 for (
uint i = index_len; i--; buf++) {
106 memcpy(builder.
data, pybuffer.buf, index_len *
sizeof(*builder.
data));
109 PyBuffer_Release(&pybuffer);
112 PyObject *seq_fast = PySequence_Fast(seq, error_prefix);
114 if (seq_fast ==
NULL) {
118 const uint seq_len = PySequence_Fast_GET_SIZE(seq_fast);
120 PyObject **seq_items = PySequence_Fast_ITEMS(seq_fast);
122 index_len = seq_len * verts_per_prim;
129 if (verts_per_prim == 1) {
130 for (
uint i = 0; i < seq_len; i++) {
136 for (
uint i = 0; i < seq_len; i++) {
137 PyObject *seq_fast_item = PySequence_Fast(seq_items[i], error_prefix);
138 if (seq_fast_item ==
NULL) {
139 PyErr_Format(PyExc_TypeError,
140 "%s: expected a sequence, got %s",
142 Py_TYPE(seq_items[i])->tp_name);
148 values, seq_fast_item, verts_per_prim, &PyLong_Type,
false, error_prefix) == 0;
151 for (
uint j = 0; j < verts_per_prim; j++) {
155 Py_DECREF(seq_fast_item);
159 if (PyErr_Occurred()) {
179 Py_TYPE(
self)->tp_free(
self);
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` and `LINE_STRIP_ADJ`.\n"
190 " :param 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: 1D or 2D sequence\n");
195 PyVarObject_HEAD_INIT(
NULL, 0).tp_name =
"GPUIndexBuf",
198 .tp_flags = Py_TPFLAGS_DEFAULT,
199 .tp_doc = pygpu_IndexBuf__tp_doc,
216 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)
int PyC_AsArray_FAST(void *array, PyObject *value_fast, const Py_ssize_t length, const PyTypeObject *type, const bool is_double, const char *error_prefix)
uint32_t PyC_Long_AsU32(PyObject *value)
bool PyC_StructFmt_type_is_float_any(char format)