Blender V5.3
gpu_py_batch.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2015 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
14
15#include <Python.h>
16
17#include "BLI_utildefines.hh"
18
19#include "GPU_batch.hh"
20#include "GPU_state.hh"
21
23#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
24
25#include "gpu_py.hh"
26#include "gpu_py_element.hh"
27#include "gpu_py_shader.hh"
29
30#include "gpu_py_batch.hh" /* own include */
31
32namespace blender {
33
34/* -------------------------------------------------------------------- */
37
39{
40 if (!self->batch->shader) {
41 PyErr_SetString(PyExc_RuntimeError, "batch does not have any program assigned to it");
42 return false;
43 }
44 return true;
45}
46
48
49/* -------------------------------------------------------------------- */
52
53static PyObject *pygpu_batch__tp_new(PyTypeObject * /*type*/, PyObject *args, PyObject *kwds)
54{
56
57 const char *exc_str_missing_arg = "GPUBatch.__new__() missing required argument '%s' (pos %d)";
58
60 BPyGPUVertBuf *py_vertbuf = nullptr;
61 BPyGPUIndexBuf *py_indexbuf = nullptr;
62 PyC_TypeOrNone py_indexbuf_or_none = PyC_TYPE_OR_NONE_INIT(&BPyGPUIndexBuf_Type, &py_indexbuf);
63
64 static const char *_keywords[] = {"type", "buf", "elem", nullptr};
65 static _PyArg_Parser _parser = {
66 "|$" /* Optional, keyword only arguments. */
67 "O&" /* `type` */
68 "O!" /* `buf` */
69 "O&" /* `elem` */
70 ":GPUBatch.__new__",
71 _keywords,
72 nullptr,
73 };
74 if (!_PyArg_ParseTupleAndKeywordsFast(args,
75 kwds,
76 &_parser,
78 &prim_type,
80 &py_vertbuf,
82 &py_indexbuf_or_none))
83 {
84 return nullptr;
85 }
86
88 if (prim_type.value_found == GPU_PRIM_LINE_LOOP) {
89 PyErr_WarnEx(PyExc_DeprecationWarning,
90 "'LINE_LOOP' is deprecated. Please use 'LINE_STRIP' and close the segment.",
91 1);
92 }
93 else if (prim_type.value_found == GPU_PRIM_TRI_FAN) {
94 PyErr_WarnEx(
95 PyExc_DeprecationWarning,
96 "'TRI_FAN' is deprecated. Please use 'TRI_STRIP' or 'TRIS' and try modifying your "
97 "vertices or indices to match the topology.",
98 1);
99 }
100
101 if (py_vertbuf == nullptr) {
102 PyErr_Format(PyExc_TypeError, exc_str_missing_arg, _keywords[1], 2);
103 return nullptr;
104 }
105
106 gpu::Batch *batch = GPU_batch_create(GPUPrimType(prim_type.value_found),
107 py_vertbuf->buf,
108 py_indexbuf ? py_indexbuf->elem : nullptr);
109
110 BPyGPUBatch *ret = reinterpret_cast<BPyGPUBatch *>(BPyGPUBatch_CreatePyObject(batch));
111
112#ifdef USE_GPU_PY_REFERENCES
113 ret->references = PyList_New(py_indexbuf ? 2 : 1);
114 PyList_SET_ITEM(ret->references, 0, (PyObject *)py_vertbuf);
115 Py_INCREF(py_vertbuf);
116
117 if (py_indexbuf != nullptr) {
118 PyList_SET_ITEM(ret->references, 1, (PyObject *)py_indexbuf);
119 Py_INCREF(py_indexbuf);
120 }
121
122 BLI_assert(!PyObject_GC_IsTracked((PyObject *)ret));
123 PyObject_GC_Track(ret);
124#endif
125
126 return reinterpret_cast<PyObject *>(ret);
127}
128
130 /* Wrap. */
131 pygpu_batch_vertbuf_add_doc, ".. method:: vertbuf_add(buf)\n"
132"\n"
133" Add another vertex buffer to the Batch.\n"
134" It is not possible to add more vertices to the batch using this method.\n"
135" Instead it can be used to add more attributes to the existing vertices.\n"
136" A good use case would be when you have a separate\n"
137" vertex buffer for vertex positions and vertex normals.\n"
138" Current a batch can have at most " STRINGIFY(GPU_BATCH_VBO_MAX_LEN) " vertex buffers.\n"
139"\n"
140" :param buf: The vertex buffer that will be added to the batch.\n"
141" :type buf: :class:`gpu.types.GPUVertBuf`\n"
142);
143static PyObject *pygpu_batch_vertbuf_add(BPyGPUBatch *self, BPyGPUVertBuf *py_buf)
144{
145 if (!BPyGPUVertBuf_Check(py_buf)) {
146 PyErr_Format(PyExc_TypeError, "Expected a GPUVertBuf, got %s", Py_TYPE(py_buf)->tp_name);
147 return nullptr;
148 }
149
150 if (GPU_vertbuf_get_vertex_len(self->batch->verts[0]) != GPU_vertbuf_get_vertex_len(py_buf->buf))
151 {
152 PyErr_Format(PyExc_TypeError,
153 "Expected %d length, got %d",
154 GPU_vertbuf_get_vertex_len(self->batch->verts[0]),
156 return nullptr;
157 }
158
159 if (self->batch->verts[GPU_BATCH_VBO_MAX_LEN - 1] != nullptr) {
160 PyErr_SetString(
161 PyExc_RuntimeError,
162 "Maximum number of vertex buffers exceeded: " STRINGIFY(GPU_BATCH_VBO_MAX_LEN));
163 return nullptr;
164 }
165
166#ifdef USE_GPU_PY_REFERENCES
167 /* Hold user */
168 PyList_Append(self->references, reinterpret_cast<PyObject *>(py_buf));
169#endif
170
171 GPU_batch_vertbuf_add(self->batch, py_buf->buf, false);
172 Py_RETURN_NONE;
173}
174
180{
181#ifdef USE_GPU_PY_REFERENCES
182 /* Remove existing user (if any), hold new user. */
183 int i = PyList_GET_SIZE(self->references);
184 while (--i != -1) {
185 PyObject *py_shader_test = PyList_GET_ITEM(self->references, i);
186 if (BPyGPUShader_Check(py_shader_test)) {
187 PyList_SET_ITEM(self->references, i, reinterpret_cast<PyObject *>(py_shader));
188 Py_INCREF(py_shader);
189 Py_DECREF(py_shader_test);
190 /* Only ever reference one shader. */
191 break;
192 }
193 }
194 if (i == -1) {
195 /* No references set in the loop, so add it here. */
196 PyList_Append(self->references, reinterpret_cast<PyObject *>(py_shader));
197 }
198#else
199 UNUSED_VARS(self, py_shader);
200#endif
201}
202
206static void pygpu_batch_shader_set(BPyGPUBatch *self, BPyGPUShader *py_shader)
207{
208 /* Assign & bind even when unchanged as scripts may rely on the bind side-effect. */
209 const bool shader_changed = self->batch->shader != py_shader->shader;
210
211 GPU_batch_set_shader(self->batch, py_shader->shader);
212
213 if (shader_changed) {
215 }
216}
217
219 /* Wrap. */
220 pygpu_batch_program_set_doc,
221 ".. method:: program_set(program)\n"
222 "\n"
223 " Assign a shader to this batch that will be used for drawing when not overwritten later.\n"
224 " Note: This method has to be called in the draw context that the batch will be drawn in.\n"
225 " This function does not need to be called when you always\n"
226 " set the shader when calling :meth:`gpu.types.GPUBatch.draw`.\n"
227 "\n"
228 " :param program: The program/shader the batch will use in future draw calls.\n"
229 " :type program: :class:`gpu.types.GPUShader`\n");
230static PyObject *pygpu_batch_program_set(BPyGPUBatch *self, BPyGPUShader *py_shader)
231{
232 static bool deprecation_warning_issued = false;
233
234 /* Deprecation warning raised when calling `gpu.types.GPUBatch.program_set`. */
235 if (!deprecation_warning_issued) {
236 PyErr_WarnEx(PyExc_DeprecationWarning,
237 "Calls to GPUBatch.program_set are deprecated."
238 "Please set the shader via the 'program' parameter when calling "
239 "GPUBatch.draw/draw_instanced/draw_range.",
240 1);
241 deprecation_warning_issued = true;
242 }
243
244 if (!BPyGPUShader_Check(py_shader)) {
245 PyErr_Format(PyExc_TypeError, "Expected a GPUShader, got %s", Py_TYPE(py_shader)->tp_name);
246 return nullptr;
247 }
248
249 pygpu_batch_shader_set(self, py_shader);
250
251 Py_RETURN_NONE;
252}
253
258static const char *pygpu_shader_check_compatibility(gpu::Batch *batch)
259{
260 if (!batch->shader) {
261 return nullptr;
262 }
263
264 /* Currently only POLYLINE shaders are checked. */
265 if (!bpygpu_shader_is_polyline(batch->shader)) {
266 return nullptr;
267 }
268
269 /* Check batch compatibility with shader. */
270 for (auto *vert : Span(batch->verts, ARRAY_SIZE(batch->verts))) {
271 if (!vert) {
272 continue;
273 }
274 GPUVertFormat &format = vert->format;
275 if ((format.stride % 4) != 0) {
276 return "For POLYLINE shaders, only 4-byte aligned formats are supported";
277 }
278
279 int pos_attr_id = -1;
280 int col_attr_id = -1;
281 for (uint a_idx = 0; a_idx < format.attr_len; a_idx++) {
282 const GPUVertAttr *a = &format.attrs[a_idx];
283 if ((a->offset % 4) != 0) {
284 return "For POLYLINE shaders, only 4-byte aligned attributes are supported";
285 }
286 const StringRefNull name = GPU_vertformat_attr_name_get(&format, a, 0);
287 if (pos_attr_id == -1 && name == "pos") {
288 if (!ELEM(a->type.comp_type(), GPU_COMP_F32)) {
289 return "For POLYLINE shaders, the 'pos' attribute needs to be 'F32'";
290 }
291 if (!ELEM(a->type.fetch_mode(), GPU_FETCH_FLOAT)) {
292 return "For POLYLINE shaders, the 'pos' attribute must use the 'FLOAT' fetch type";
293 }
294 pos_attr_id = a_idx;
295 }
296 else if (col_attr_id == -1 && name == "color") {
298 return "For POLYLINE shaders, the 'color' attribute needs to be 'F32' or 'U8'";
299 }
300 col_attr_id = a_idx;
301 }
302 if (pos_attr_id != -1 && col_attr_id != -1) {
303 break;
304 }
305 }
306 }
307 return nullptr;
308}
309
311 /* Wrap. */
312 pygpu_batch_draw_doc,
313 ".. method:: draw(shader=None)\n"
314 "\n"
315 " Run the drawing shader with the parameters assigned to the batch.\n"
316 "\n"
317 " :param shader: Shader that performs the drawing operations.\n"
318 " If ``None`` is passed, the last shader set to this batch will run.\n"
319 " :type shader: :class:`gpu.types.GPUShader` | None\n");
320static PyObject *pygpu_batch_draw(BPyGPUBatch *self, PyObject *args, PyObject *kw)
321{
322 static bool deprecation_warning_issued = false;
323
324 BPyGPUShader *py_shader = nullptr;
325 PyC_TypeOrNone py_shader_or_none = PyC_TYPE_OR_NONE_INIT(&BPyGPUShader_Type, &py_shader);
326
327 static const char *_keywords[] = {"shader", nullptr};
328 static _PyArg_Parser _parser = {
329 "|" /* Optional arguments. */
330 "O&" /* `shader` */
331 ":GPUBatch.draw",
332 _keywords,
333 nullptr,
334 };
335 if (!_PyArg_ParseTupleAndKeywordsFast(
336 args, kw, &_parser, PyC_ParseTypeOrNone, &py_shader_or_none))
337 {
338 return nullptr;
339 }
340 if (py_shader == nullptr) {
341 if (!deprecation_warning_issued) {
342 /* Deprecation warning raised when calling gpu.types.GPUBatch.draw without a valid GPUShader.
343 */
344 PyErr_WarnEx(PyExc_DeprecationWarning,
345 "Calling GPUBatch.draw without specifying a shader is deprecated. "
346 "Please provide a valid GPUShader as the 'shader' parameter.",
347 1);
348 deprecation_warning_issued = true;
349 }
350
352 return nullptr;
353 }
354 }
355 else {
356 pygpu_batch_shader_set(self, py_shader);
357 }
358
359 /* Emit a warning when trying to draw wide lines as it is too late to automatically switch to a
360 * polyline shader. */
361 if (py_shader && py_shader->is_builtin &&
363 {
364 gpu::Shader *shader = py_shader->shader;
365 const float line_width = GPU_line_width_get();
366 const bool use_linesmooth = GPU_line_smooth_get();
367 if (line_width > 1.0f || use_linesmooth) {
369 PyErr_WarnEx(PyExc_DeprecationWarning,
370 "Calling GPUBatch.draw to draw wide or smooth lines with "
371 "GPU_SHADER_3D_FLAT_COLOR is deprecated. "
372 "Use GPU_SHADER_3D_POLYLINE_FLAT_COLOR instead.",
373 1);
374 }
376 PyErr_WarnEx(PyExc_DeprecationWarning,
377 "Calling GPUBatch.draw to draw wide or smooth lines with "
378 "GPU_SHADER_3D_SMOOTH_COLOR is deprecated. "
379 "Use GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR instead.",
380 1);
381 }
383 PyErr_WarnEx(PyExc_DeprecationWarning,
384 "Calling GPUBatch.draw to draw wide or smooth lines with "
385 "GPU_SHADER_3D_UNIFORM_COLOR is deprecated. "
386 "Use GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR instead.",
387 1);
388 }
389 }
390 }
391
392 /* Emit a warning when trying to draw points with a regular shader as it is too late to
393 * automatically switch to a point shader. */
394 if (py_shader && py_shader->is_builtin && self->batch->prim_type == GPU_PRIM_POINTS) {
395 gpu::Shader *shader = py_shader->shader;
397 PyErr_WarnEx(PyExc_DeprecationWarning,
398 "Calling GPUBatch.draw to draw points with "
399 "GPU_SHADER_3D_FLAT_COLOR is deprecated. "
400 "Use GPU_SHADER_3D_POINT_FLAT_COLOR instead.",
401 1);
402 }
404 PyErr_WarnEx(PyExc_DeprecationWarning,
405 "Calling GPUBatch.draw to draw points with "
406 "GPU_SHADER_3D_SMOOTH_COLOR is deprecated. "
407 "Use GPU_SHADER_3D_POINT_FLAT_COLOR instead.",
408 1);
409 }
411 PyErr_WarnEx(PyExc_DeprecationWarning,
412 "Calling GPUBatch.draw to draw points with "
413 "GPU_SHADER_3D_UNIFORM_COLOR is deprecated. "
414 "Use GPU_SHADER_3D_POINT_SMOOTH_COLOR instead.",
415 1);
416 }
417 }
418
419 if (const char *error = pygpu_shader_check_compatibility(self->batch)) {
420 PyErr_SetString(PyExc_RuntimeError, error);
421 return nullptr;
422 }
423
424 GPU_batch_draw(self->batch);
425 Py_RETURN_NONE;
426}
427
429 /* Wrap. */
430 pygpu_batch_draw_instanced_doc,
431 ".. method:: draw_instanced(program, *, instance_start=0, instance_count=0)\n"
432 "\n"
433 " Draw multiple instances of the drawing program with the parameters assigned\n"
434 " to the batch. In the vertex shader, ``gpu_InstanceIndex`` will contain the instance\n"
435 " number being drawn including the ``instance_start``.\n"
436 "\n"
437 " :param program: Program that performs the drawing operations.\n"
438 " :type program: :class:`gpu.types.GPUShader`\n"
439 " :param instance_start: Number of the first instance to draw.\n"
440 " :type instance_start: int\n"
441 " :param instance_count: Number of instances to draw. When not provided or set to 0\n"
442 " the number of instances will be determined by the number of rows in the first\n"
443 " vertex buffer.\n"
444 " :type instance_count: int\n");
445static PyObject *pygpu_batch_draw_instanced(BPyGPUBatch *self, PyObject *args, PyObject *kw)
446{
447 BPyGPUShader *py_program = nullptr;
448 int instance_start = 0;
449 int instance_count = 0;
450
451 static const char *_keywords[] = {"program", "instance_start", "instance_count", nullptr};
452 static _PyArg_Parser _parser = {
453 "O!" /* `program` */
454 "|$" /* Optional, keyword only arguments. */
455 "i" /* `instance_start` */
456 "i" /* `instance_count` */
457 ":GPUBatch.draw_instanced",
458 _keywords,
459 nullptr,
460 };
461 if (!_PyArg_ParseTupleAndKeywordsFast(
462 args, kw, &_parser, &BPyGPUShader_Type, &py_program, &instance_start, &instance_count))
463 {
464 return nullptr;
465 }
466
467 pygpu_batch_shader_set(self, py_program);
468 GPU_batch_draw_instance_range(self->batch, instance_start, instance_count);
469 Py_RETURN_NONE;
470}
471
473 /* Wrap. */
474 pygpu_batch_draw_range_doc,
475 ".. method:: draw_range(program, *, elem_start=0, elem_count=0)\n"
476 "\n"
477 " Run the drawing program with the parameters assigned to the batch. "
478 "Only draw the ``elem_count`` elements of the index buffer starting at ``elem_start``.\n"
479 "\n"
480 " :param program: Program that performs the drawing operations.\n"
481 " :type program: :class:`gpu.types.GPUShader`\n"
482 " :param elem_start: First index to draw. When not provided or set to 0 drawing\n"
483 " will start from the first element of the index buffer.\n"
484 " :type elem_start: int\n"
485 " :param elem_count: Number of elements of the index buffer to draw. When not\n"
486 " provided or set to 0 all elements from ``elem_start`` to the end of the\n"
487 " index buffer will be drawn.\n"
488 " :type elem_count: int\n");
489static PyObject *pygpu_batch_draw_range(BPyGPUBatch *self, PyObject *args, PyObject *kw)
490{
491 BPyGPUShader *py_program = nullptr;
492 int elem_start = 0;
493 int elem_count = 0;
494
495 static const char *_keywords[] = {"program", "elem_start", "elem_count", nullptr};
496 static _PyArg_Parser _parser = {
497 "O!" /* `program` */
498 "|$" /* Optional, keyword only arguments. */
499 "i" /* `elem_start` */
500 "i" /* `elem_count` */
501 ":GPUBatch.draw_range",
502 _keywords,
503 nullptr,
504 };
505 if (!_PyArg_ParseTupleAndKeywordsFast(
506 args, kw, &_parser, &BPyGPUShader_Type, &py_program, &elem_start, &elem_count))
507 {
508 return nullptr;
509 }
510
511 pygpu_batch_shader_set(self, py_program);
512 GPU_batch_draw_range(self->batch, elem_start, elem_count);
513 Py_RETURN_NONE;
514}
515
517{
519 return nullptr;
520 }
521 GPU_shader_bind(self->batch->shader);
522 Py_RETURN_NONE;
523}
524
526{
528 return nullptr;
529 }
531 Py_RETURN_NONE;
532}
533
534#ifdef __GNUC__
535# ifdef __clang__
536# pragma clang diagnostic push
537# pragma clang diagnostic ignored "-Wcast-function-type"
538# else
539# pragma GCC diagnostic push
540# pragma GCC diagnostic ignored "-Wcast-function-type"
541# endif
542#endif
543
544static PyMethodDef pygpu_batch__tp_methods[] = {
545 {"vertbuf_add",
546 reinterpret_cast<PyCFunction>(pygpu_batch_vertbuf_add),
547 METH_O,
548 pygpu_batch_vertbuf_add_doc},
549 {"program_set",
550 reinterpret_cast<PyCFunction>(pygpu_batch_program_set),
551 METH_O,
552 pygpu_batch_program_set_doc},
553 {"draw",
554 reinterpret_cast<PyCFunction>(pygpu_batch_draw),
555 METH_VARARGS | METH_KEYWORDS,
556 pygpu_batch_draw_doc},
557 {"draw_instanced",
558 reinterpret_cast<PyCFunction>(pygpu_batch_draw_instanced),
559 METH_VARARGS | METH_KEYWORDS,
560 pygpu_batch_draw_instanced_doc},
561 {"draw_range",
562 reinterpret_cast<PyCFunction>(pygpu_batch_draw_range),
563 METH_VARARGS | METH_KEYWORDS,
564 pygpu_batch_draw_range_doc},
565 {"_program_use_begin",
566 reinterpret_cast<PyCFunction>(pygpu_batch_program_use_begin),
567 METH_NOARGS,
568 ""},
569 {"_program_use_end",
570 reinterpret_cast<PyCFunction>(pygpu_batch_program_use_end),
571 METH_NOARGS,
572 ""},
573 {nullptr, nullptr, 0, nullptr},
574};
575
576#ifdef __GNUC__
577# ifdef __clang__
578# pragma clang diagnostic pop
579# else
580# pragma GCC diagnostic pop
581# endif
582#endif
583
584#ifdef USE_GPU_PY_REFERENCES
585
586static int pygpu_batch__tp_traverse(BPyGPUBatch *self, visitproc visit, void *arg)
587{
588 Py_VISIT(self->references);
589 return 0;
590}
591
593{
594 Py_CLEAR(self->references);
595 return 0;
596}
597
599{
600 return self->references != nullptr;
601}
602
603#endif
604
606{
608
609#ifdef USE_GPU_PY_REFERENCES
610 PyObject_GC_UnTrack(self);
611 if (self->references) {
613 Py_XDECREF(self->references);
614 }
615#endif
616
617 Py_TYPE(self)->tp_free(self);
618}
619
621 /* Wrap. */
622 pygpu_batch__tp_doc,
623 ".. class:: GPUBatch\n"
624 "\n"
625 " Reusable container for drawable geometry.\n"
626 "\n"
627 " .. method:: __init__(type, buf, elem=None)\n"
628 "\n"
629 " :param type: The primitive type of geometry to be drawn.\n"
630 " :type type: " PYDOC_PRIMTYPE_LITERAL
631 "\n"
632 " :param buf: Vertex buffer containing all or some of the attributes required for "
633 "drawing.\n"
634 " :type buf: :class:`gpu.types.GPUVertBuf`\n"
635 " :param elem: An optional index buffer.\n"
636 " :type elem: :class:`gpu.types.GPUIndexBuf` | None\n");
637PyTypeObject BPyGPUBatch_Type = {
638 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
639 /*tp_name*/ "GPUBatch",
640 /*tp_basicsize*/ sizeof(BPyGPUBatch),
641 /*tp_itemsize*/ 0,
642 /*tp_dealloc*/ reinterpret_cast<destructor>(pygpu_batch__tp_dealloc),
643 /*tp_vectorcall_offset*/ 0,
644 /*tp_getattr*/ nullptr,
645 /*tp_setattr*/ nullptr,
646 /*tp_as_async*/ nullptr,
647 /*tp_repr*/ nullptr,
648 /*tp_as_number*/ nullptr,
649 /*tp_as_sequence*/ nullptr,
650 /*tp_as_mapping*/ nullptr,
651 /*tp_hash*/ nullptr,
652 /*tp_call*/ nullptr,
653 /*tp_str*/ nullptr,
654 /*tp_getattro*/ nullptr,
655 /*tp_setattro*/ nullptr,
656 /*tp_as_buffer*/ nullptr,
657#ifdef USE_GPU_PY_REFERENCES
658 /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
659#else
660 /*tp_flags*/ Py_TPFLAGS_DEFAULT,
661#endif
662 /*tp_doc*/ pygpu_batch__tp_doc,
663#ifdef USE_GPU_PY_REFERENCES
664 /*tp_traverse*/ reinterpret_cast<traverseproc>(pygpu_batch__tp_traverse),
665#else
666 /*tp_traverse*/ nullptr,
667#endif
669 /*tp_clear*/ reinterpret_cast<inquiry>(pygpu_batch__tp_clear),
670#else
671 /*tp_clear*/ nullptr,
672#endif
673 /*tp_richcompare*/ nullptr,
674 /*tp_weaklistoffset*/ 0,
675 /*tp_iter*/ nullptr,
676 /*tp_iternext*/ nullptr,
677 /*tp_methods*/ pygpu_batch__tp_methods,
678 /*tp_members*/ nullptr,
679 /*tp_getset*/ nullptr,
680 /*tp_base*/ nullptr,
681 /*tp_dict*/ nullptr,
682 /*tp_descr_get*/ nullptr,
683 /*tp_descr_set*/ nullptr,
684 /*tp_dictoffset*/ 0,
685 /*tp_init*/ nullptr,
686 /*tp_alloc*/ nullptr,
687 /*tp_new*/ pygpu_batch__tp_new,
688 /*tp_free*/ nullptr,
689#ifdef USE_GPU_PY_REFERENCES
690 /*tp_is_gc*/ reinterpret_cast<inquiry>(pygpu_batch__tp_is_gc),
691#else
692 /*tp_is_gc*/ nullptr,
693#endif
694 /*tp_bases*/ nullptr,
695 /*tp_mro*/ nullptr,
696 /*tp_cache*/ nullptr,
697 /*tp_subclasses*/ nullptr,
698 /*tp_weaklist*/ nullptr,
699 /*tp_del*/ nullptr,
700 /*tp_version_tag*/ 0,
701 /*tp_finalize*/ nullptr,
702 /*tp_vectorcall*/ nullptr,
703};
704
706
707/* -------------------------------------------------------------------- */
710
711PyObject *BPyGPUBatch_CreatePyObject(gpu::Batch *batch)
712{
713 BPyGPUBatch *self;
714
715#ifdef USE_GPU_PY_REFERENCES
716 self = reinterpret_cast<BPyGPUBatch *>(_PyObject_GC_New(&BPyGPUBatch_Type));
717 self->references = nullptr;
718#else
719 self = PyObject_New(BPyGPUBatch, &BPyGPUBatch_Type);
720#endif
721
722 self->batch = batch;
723
724 return reinterpret_cast<PyObject *>(self);
725}
726
728
729#undef BPY_GPU_BATCH_CHECK_OBJ
730
731} // namespace blender
#define GPU_batch_create(primitive_type, vertex_buf, index_buf)
Definition GPU_batch.hh:143
#define UNUSED_VARS(...)
#define STRINGIFY(x)
#define ELEM(...)
constexpr Span()=default
#define PYDOC_PRIMTYPE_LITERAL
Definition gpu_py.hh:22
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
Definition gpu_py.hh:45
#define USE_GPU_PY_REFERENCES
#define BPyGPUShader_Check(v)
#define BPyGPUVertBuf_Check(v)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
PyTypeObject BPyGPUBatch_Type
unsigned int uint
Definition BKE_text.h:55
bool bpygpu_shader_is_polyline(gpu::Shader *shader)
static void pygpu_batch__tp_dealloc(BPyGPUBatch *self)
static int pygpu_batch__tp_traverse(BPyGPUBatch *self, visitproc visit, void *arg)
PyTypeObject BPyGPUVertBuf_Type
static PyObject * pygpu_batch_vertbuf_add(BPyGPUBatch *self, BPyGPUVertBuf *py_buf)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
BLI_INLINE const char * GPU_vertformat_attr_name_get(const GPUVertFormat *format, const GPUVertAttr *attr, uint n_idx)
static constexpr int GPU_BATCH_VBO_MAX_LEN
Definition GPU_batch.hh:35
@ GPU_PRIM_LINE_STRIP
@ GPU_PRIM_LINE_LOOP
static int pygpu_batch__tp_is_gc(BPyGPUBatch *self)
void GPU_batch_discard(gpu::Batch *batch)
PyTypeObject BPyGPUIndexBuf_Type
void GPU_batch_set_shader(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_batch_draw_range(gpu::Batch *batch, int vertex_first, int vertex_count)
static PyMethodDef pygpu_batch__tp_methods[]
float GPU_line_width_get()
Definition gpu_state.cc:241
static const char * pygpu_shader_check_compatibility(gpu::Batch *batch)
void GPU_shader_unbind()
static PyObject * pygpu_batch_draw(BPyGPUBatch *self, PyObject *args, PyObject *kw)
void GPU_batch_draw_instance_range(gpu::Batch *batch, int instance_first, int instance_count)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static int pygpu_batch__tp_clear(BPyGPUBatch *self)
void GPU_batch_draw(gpu::Batch *batch)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
static bool pygpu_batch_is_program_or_error(BPyGPUBatch *self)
static PyObject * pygpu_batch__tp_new(PyTypeObject *, PyObject *args, PyObject *kwds)
gpu::Shader * GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
static PyObject * pygpu_batch_draw_range(BPyGPUBatch *self, PyObject *args, PyObject *kw)
PyC_StringEnumItems bpygpu_primtype_items[]
Definition gpu_py.cc:28
bool GPU_line_smooth_get()
Definition gpu_state.cc:247
uint GPU_vertbuf_get_vertex_len(const gpu::VertBuf *verts)
static PyObject * pygpu_batch_program_use_begin(BPyGPUBatch *self)
int PyC_ParseStringEnum(PyObject *o, void *p)
PyTypeObject BPyGPUShader_Type
static PyObject * pygpu_batch_program_use_end(BPyGPUBatch *self)
static void pygpu_batch_shader_set_reference_only(BPyGPUBatch *self, BPyGPUShader *py_shader)
static PyObject * pygpu_batch_draw_instanced(BPyGPUBatch *self, PyObject *args, PyObject *kw)
int PyC_ParseTypeOrNone(PyObject *o, void *p)
static void pygpu_batch_shader_set(BPyGPUBatch *self, BPyGPUShader *py_shader)
PyObject * BPyGPUBatch_CreatePyObject(gpu::Batch *batch)
int GPU_batch_vertbuf_add(gpu::Batch *batch, gpu::VertBuf *vertex_buf, bool own_vbo)
static PyObject * pygpu_batch_program_set(BPyGPUBatch *self, BPyGPUShader *py_shader)
#define PyC_TYPE_OR_NONE_INIT(py_type, value_p)
header-only compatibility defines.
PyObject_HEAD gpu::Batch * batch
PyObject_HEAD gpu::IndexBuf * elem
PyObject_HEAD gpu::Shader * shader
PyObject_HEAD gpu::VertBuf * buf
GPUVertFetchMode fetch_mode() const
GPUVertCompType comp_type() const
struct blender::GPUVertAttr::Type type