Blender V5.3
gpu_py_shader.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#include <Python.h>
13
14#include "BLI_utildefines.hh"
15
16#include "GPU_context.hh"
17#include "GPU_shader.hh"
18#include "GPU_storage_buffer.hh"
19#include "GPU_texture.hh"
20#include "GPU_uniform_buffer.hh"
21
23#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
25
27
28#include "gpu_py.hh"
30#include "gpu_py_texture.hh"
33
34#include "gpu_py_shader.hh" /* own include */
35
36namespace blender {
37
38/* -------------------------------------------------------------------- */
41
42#define PYDOC_BUILTIN_SHADER_DESCRIPTION \
43 "``FLAT_COLOR``\n" \
44 " :Attributes: vec3 pos, vec4 color\n" \
45 " :Uniforms: none\n" \
46 "``IMAGE``\n" \
47 " :Attributes: vec3 pos, vec2 texCoord\n" \
48 " :Uniforms: sampler2D image\n" \
49 "``IMAGE_SCENE_LINEAR_TO_REC709_SRGB``\n" \
50 " :Attributes: vec3 pos, vec2 texCoord\n" \
51 " :Uniforms: sampler2D image\n" \
52 " :Note: Expect texture to be in scene linear color space\n" \
53 "``IMAGE_COLOR``\n" \
54 " :Attributes: vec3 pos, vec2 texCoord\n" \
55 " :Uniforms: sampler2D image, vec4 color\n" \
56 "``IMAGE_COLOR_SCENE_LINEAR_TO_REC709_SRGB``\n" \
57 " :Attributes: vec3 pos, vec2 texCoord\n" \
58 " :Uniforms: sampler2D image, vec4 color\n" \
59 " :Note: Expect texture to be in scene linear color space\n" \
60 "``SMOOTH_COLOR``\n" \
61 " :Attributes: vec3 pos, vec4 color\n" \
62 " :Uniforms: none\n" \
63 "``UNIFORM_COLOR``\n" \
64 " :Attributes: vec3 pos\n" \
65 " :Uniforms: vec4 color\n" \
66 "``POLYLINE_FLAT_COLOR``\n" \
67 " :Attributes: vec3 pos, vec4 color\n" \
68 " :Uniforms: vec2 viewportSize, float lineWidth\n" \
69 "``POLYLINE_SMOOTH_COLOR``\n" \
70 " :Attributes: vec3 pos, vec4 color\n" \
71 " :Uniforms: vec2 viewportSize, float lineWidth\n" \
72 "``POLYLINE_UNIFORM_COLOR``\n" \
73 " :Attributes: vec3 pos\n" \
74 " :Uniforms: vec2 viewportSize, float lineWidth, vec4 color\n" \
75 "``POINT_FLAT_COLOR``\n" \
76 " :Attributes: vec3 pos, vec4 color\n" \
77 " :Uniforms: float size\n" \
78 "``POINT_UNIFORM_COLOR``\n" \
79 " :Attributes: vec3 pos\n" \
80 " :Uniforms: vec4 color, float size\n"
81
83 {GPU_SHADER_3D_FLAT_COLOR, "FLAT_COLOR"},
84 {GPU_SHADER_3D_IMAGE, "IMAGE"},
85 {GPU_SHADER_3D_IMAGE_SCENE_LINEAR_TO_REC709_SRGB, "IMAGE_SCENE_LINEAR_TO_REC709_SRGB"},
86 {GPU_SHADER_3D_IMAGE_COLOR, "IMAGE_COLOR"},
88 "IMAGE_COLOR_SCENE_LINEAR_TO_REC709_SRGB"},
89 {GPU_SHADER_3D_SMOOTH_COLOR, "SMOOTH_COLOR"},
90 {GPU_SHADER_3D_UNIFORM_COLOR, "UNIFORM_COLOR"},
91 {GPU_SHADER_3D_POLYLINE_FLAT_COLOR, "POLYLINE_FLAT_COLOR"},
92 {GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR, "POLYLINE_SMOOTH_COLOR"},
93 {GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, "POLYLINE_UNIFORM_COLOR"},
94 {GPU_SHADER_3D_POINT_FLAT_COLOR, "POINT_FLAT_COLOR"},
95 {GPU_SHADER_3D_POINT_UNIFORM_COLOR, "POINT_UNIFORM_COLOR"},
96 {0, nullptr},
97};
98
100 {GPU_SHADER_CFG_DEFAULT, "DEFAULT"},
101 {GPU_SHADER_CFG_CLIPPED, "CLIPPED"},
102 {0, nullptr},
103};
104
106 const char *name,
107 const char *error_prefix)
108{
109 const int uniform = GPU_shader_get_uniform(shader, name);
110
111 if (uniform == -1) {
112 PyErr_Format(PyExc_ValueError, "%s: uniform %.32s not found", error_prefix, name);
113 }
114
115 return uniform;
116}
117
119
120/* -------------------------------------------------------------------- */
123
125 /* Wrap. */
126 pygpu_shader_bind_doc,
127 ".. method:: bind()\n"
128 "\n"
129 " Bind the shader object. Required to be able to change uniforms of this shader.\n");
130static PyObject *pygpu_shader_bind(BPyGPUShader *self)
131{
132 GPU_shader_bind(self->shader);
133 Py_RETURN_NONE;
134}
135
137 /* Wrap. */
138 pygpu_shader_uniform_from_name_doc,
139 ".. method:: uniform_from_name(name)\n"
140 "\n"
141 " Get uniform location by name.\n"
142 "\n"
143 " :param name: Name of the uniform variable whose location is to be queried.\n"
144 " :type name: str\n"
145 " :return: Location of the uniform variable.\n"
146 " :rtype: int\n");
147static PyObject *pygpu_shader_uniform_from_name(BPyGPUShader *self, PyObject *arg)
148{
149 const char *name = PyUnicode_AsUTF8(arg);
150 if (name == nullptr) {
151 return nullptr;
152 }
153
155 self->shader, name, "GPUShader.get_uniform");
156
157 if (uniform == -1) {
158 return nullptr;
159 }
160
161 return PyLong_FromLong(uniform);
162}
163
165 /* Wrap. */
166 pygpu_shader_uniform_block_from_name_doc,
167 ".. method:: uniform_block_from_name(name)\n"
168 "\n"
169 " Get uniform block location by name.\n"
170 "\n"
171 " :param name: Name of the uniform block variable whose location is to be queried.\n"
172 " :type name: str\n"
173 " :return: The location of the uniform block variable.\n"
174 " :rtype: int\n");
175static PyObject *pygpu_shader_uniform_block_from_name(BPyGPUShader *self, PyObject *arg)
176{
177 const char *name = PyUnicode_AsUTF8(arg);
178 if (name == nullptr) {
179 return nullptr;
180 }
181
182 const int uniform = GPU_shader_get_uniform_block(self->shader, name);
183
184 if (uniform == -1) {
185 PyErr_Format(PyExc_ValueError, "GPUShader.get_uniform_block: uniform %.32s not found", name);
186 return nullptr;
187 }
188
189 return PyLong_FromLong(uniform);
190}
191
192static bool pygpu_shader_uniform_vector_impl(PyObject *args,
193 int elem_size,
194 int *r_location,
195 int *r_length,
196 int *r_count,
197 Py_buffer *r_pybuffer)
198{
199 PyObject *buffer;
200
201 *r_count = 1;
202 if (!PyArg_ParseTuple(args,
203 "i" /* `location` */
204 "O" /* `buffer` */
205 "i" /* `length` */
206 "|" /* Optional arguments. */
207 "i" /* `count` */
208 ":GPUShader.uniform_vector_*",
209 r_location,
210 &buffer,
211 r_length,
212 r_count))
213 {
214 return false;
215 }
216
217 if (PyObject_GetBuffer(buffer, r_pybuffer, PyBUF_SIMPLE) == -1) {
218 /* PyObject_GetBuffer raise a PyExc_BufferError */
219 return false;
220 }
221
222 if (r_pybuffer->len < (*r_length * *r_count * elem_size)) {
223 PyErr_SetString(PyExc_OverflowError,
224 "GPUShader.uniform_vector_*: buffer size smaller than required.");
225 PyBuffer_Release(r_pybuffer);
226 return false;
227 }
228
229 return true;
230}
231
233 /* Wrap. */
234 pygpu_shader_uniform_vector_float_doc,
235 ".. method:: uniform_vector_float(location, buffer, length, count)\n"
236 "\n"
237 " Set the buffer to fill the uniform.\n"
238 "\n"
239 " :param location: Location of the uniform variable to be modified.\n"
240 " :type location: int\n"
241 " :param buffer: The data that should be set. Can support the buffer protocol.\n"
242 " :type buffer: Sequence[float]\n"
243 " :param length: Size of the uniform data type:\n"
244 "\n"
245 " - 1: float\n"
246 " - 2: vec2 or float[2]\n"
247 " - 3: vec3 or float[3]\n"
248 " - 4: vec4 or float[4]\n"
249 " - 9: mat3\n"
250 " - 16: mat4\n"
251 " :type length: int\n"
252 " :param count: Specifies the number of elements, vector or matrices that are to "
253 "be modified.\n"
254 " :type count: int\n");
255static PyObject *pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject *args)
256{
257 int location, length, count;
258
259 Py_buffer pybuffer;
260
262 args, sizeof(float), &location, &length, &count, &pybuffer))
263 {
264 return nullptr;
265 }
266
267 GPU_shader_bind(self->shader);
269 self->shader, location, length, count, static_cast<const float *>(pybuffer.buf));
270
271 PyBuffer_Release(&pybuffer);
272
273 Py_RETURN_NONE;
274}
275
277 /* Wrap. */
278 pygpu_shader_uniform_vector_int_doc,
279 ".. method:: uniform_vector_int(location, buffer, length, count)\n"
280 "\n"
281 " Set the buffer to fill the uniform.\n"
282 "\n"
283 " :param location: Location of the uniform variable to be modified.\n"
284 " :type location: int\n"
285 " :param buffer: Buffer object with format matching the uniform.\n"
286 " :type buffer: Buffer\n"
287 " :param length: Size of the uniform data type.\n"
288 " :type length: int\n"
289 " :param count: Specifies the number of elements that are to be modified.\n"
290 " :type count: int\n");
291static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *args)
292{
293 int location, length, count;
294
295 Py_buffer pybuffer;
296
297 if (!pygpu_shader_uniform_vector_impl(args, sizeof(int), &location, &length, &count, &pybuffer))
298 {
299 return nullptr;
300 }
301
302 GPU_shader_bind(self->shader);
304 self->shader, location, length, count, static_cast<const int *>(pybuffer.buf));
305
306 PyBuffer_Release(&pybuffer);
307
308 Py_RETURN_NONE;
309}
310
312 /* Wrap. */
313 pygpu_shader_uniform_bool_doc,
314 ".. method:: uniform_bool(name, value)\n"
315 "\n"
316 " Specify the value of a uniform variable for the current program object.\n"
317 "\n"
318 " :param name: Name of the uniform variable whose value is to be changed.\n"
319 " :type name: str\n"
320 " :param value: Value that will be used to update the specified uniform variable.\n"
321 " :type value: bool | Sequence[bool]\n");
322static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args)
323{
324 const char *error_prefix = "GPUShader.uniform_bool";
325
326 struct {
327 const char *id;
328 PyObject *seq;
329 } params;
330
331 if (!PyArg_ParseTuple(args,
332 "s" /* `name` */
333 "O" /* `value` */
334 ":GPUShader.uniform_bool",
335 &params.id,
336 &params.seq))
337 {
338 return nullptr;
339 }
340
341 int values[4];
342 int length;
343 int ret = -1;
344 if (PySequence_Check(params.seq)) {
345 PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix);
346 if (seq_fast == nullptr) {
347 PyErr_Format(PyExc_TypeError,
348 "%s: expected a sequence, got %s",
349 error_prefix,
350 Py_TYPE(params.seq)->tp_name);
351 }
352 else {
353 length = PySequence_Fast_GET_SIZE(seq_fast);
354 if (length == 0 || length > 4) {
355 PyErr_Format(PyExc_TypeError,
356 "%s: invalid sequence length. expected 1..4, got %d",
357 error_prefix,
358 length);
359 }
360 else {
362 values, sizeof(*values), seq_fast, length, &PyLong_Type, error_prefix);
363 }
364 Py_DECREF(seq_fast);
365 }
366 }
367 else if (((values[0] = int(PyLong_AsLong(params.seq))) != -1) && ELEM(values[0], 0, 1)) {
368 length = 1;
369 ret = 0;
370 }
371 else {
372 PyErr_Format(
373 PyExc_ValueError, "expected a bool or sequence, got %s", Py_TYPE(params.seq)->tp_name);
374 }
375
376 if (ret == -1) {
377 return nullptr;
378 }
379
380 const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix);
381
382 if (location == -1) {
383 return nullptr;
384 }
385
386 GPU_shader_bind(self->shader);
387 GPU_shader_uniform_int_ex(self->shader, location, length, 1, values);
388
389 Py_RETURN_NONE;
390}
391
393 /* Wrap. */
394 pygpu_shader_uniform_float_doc,
395 ".. method:: uniform_float(name, value)\n"
396 "\n"
397 " Specify the value of a uniform variable for the current program object.\n"
398 "\n"
399 " :param name: Name of the uniform variable whose value is to be changed.\n"
400 " :type name: str\n"
401 " :param value: Value that will be used to update the specified uniform variable.\n"
402 " :type value: float | Sequence[float]\n");
403static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args)
404{
405 const char *error_prefix = "GPUShader.uniform_float";
406
407 struct {
408 const char *id;
409 PyObject *seq;
410 } params;
411
412 if (!PyArg_ParseTuple(args,
413 "s" /* `name` */
414 "O" /* `value` */
415 ":GPUShader.uniform_float",
416 &params.id,
417 &params.seq))
418 {
419 return nullptr;
420 }
421
422 float values[16];
423 int length;
424
425 if (PyFloat_Check(params.seq)) {
426 values[0] = float(PyFloat_AsDouble(params.seq));
427 length = 1;
428 }
429 else if (PyLong_Check(params.seq)) {
430 values[0] = float(PyLong_AsDouble(params.seq));
431 length = 1;
432 }
433 else if (MatrixObject_Check(params.seq)) {
434 MatrixObject *mat = reinterpret_cast<MatrixObject *>(params.seq);
435 if (BaseMath_ReadCallback(mat) == -1) {
436 return nullptr;
437 }
438 if ((mat->row_num != mat->col_num) || !ELEM(mat->row_num, 3, 4)) {
439 PyErr_SetString(PyExc_ValueError, "Expected 3x3 or 4x4 matrix");
440 return nullptr;
441 }
442 length = mat->row_num * mat->col_num;
443 memcpy(values, mat->matrix, sizeof(float) * length);
444 }
445 else {
446 length = mathutils_array_parse(values, 2, 16, params.seq, "");
447 if (length == -1) {
448 return nullptr;
449 }
450 }
451
452 if (!ELEM(length, 1, 2, 3, 4, 9, 16)) {
453 PyErr_SetString(PyExc_TypeError,
454 "Expected a single float or a sequence of floats of length 1..4, 9 or 16.");
455 return nullptr;
456 }
457
458 const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix);
459
460 if (location == -1) {
461 return nullptr;
462 }
463
464 GPU_shader_bind(self->shader);
465 GPU_shader_uniform_float_ex(self->shader, location, length, 1, values);
466
467 Py_RETURN_NONE;
468}
469
471 /* Wrap. */
472 pygpu_shader_uniform_int_doc,
473 ".. method:: uniform_int(name, seq)\n"
474 "\n"
475 " Specify the value of a uniform variable for the current program object.\n"
476 "\n"
477 " :param name: Name of the uniform variable whose value is to be changed.\n"
478 " :type name: str\n"
479 " :param seq: Value that will be used to update the specified uniform variable.\n"
480 " :type seq: int | Sequence[int]\n");
481static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args)
482{
483 const char *error_prefix = "GPUShader.uniform_int";
484
485 struct {
486 const char *id;
487 PyObject *seq;
488 } params;
489
490 if (!PyArg_ParseTuple(args,
491 "s" /* `name` */
492 "O" /* `seq` */
493 ":GPUShader.uniform_int",
494 &params.id,
495 &params.seq))
496 {
497 return nullptr;
498 }
499
500 int values[4];
501 int length;
502 int ret;
503
504 if (PyLong_Check(params.seq)) {
505 values[0] = PyC_Long_AsI32(params.seq);
506 length = 1;
507 ret = 0;
508 }
509 else {
510 PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix);
511 if (seq_fast == nullptr) {
512 PyErr_Format(PyExc_TypeError,
513 "%s: expected a sequence, got %s",
514 error_prefix,
515 Py_TYPE(params.seq)->tp_name);
516 ret = -1;
517 }
518 else {
519 length = PySequence_Fast_GET_SIZE(seq_fast);
520 if (length == 0 || length > 4) {
521 PyErr_Format(PyExc_TypeError,
522 "%s: invalid sequence length. expected 1..4, got %d",
523 error_prefix,
524 length);
525 ret = -1;
526 }
527 else {
529 values, sizeof(*values), seq_fast, length, &PyLong_Type, error_prefix);
530 }
531 Py_DECREF(seq_fast);
532 }
533 }
534 if (ret == -1) {
535 return nullptr;
536 }
537
538 const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix);
539
540 if (location == -1) {
541 return nullptr;
542 }
543
544 GPU_shader_bind(self->shader);
545 GPU_shader_uniform_int_ex(self->shader, location, length, 1, values);
546
547 Py_RETURN_NONE;
548}
549
551 /* Wrap. */
552 pygpu_shader_uniform_sampler_doc,
553 ".. method:: uniform_sampler(name, texture)\n"
554 "\n"
555 " Specify the value of a texture uniform variable for the current GPUShader.\n"
556 "\n"
557 " :param name: Name of the uniform variable whose texture is to be specified.\n"
558 " :type name: str\n"
559 " :param texture: Texture to attach.\n"
560 " :type texture: :class:`gpu.types.GPUTexture`\n");
561static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args)
562{
563 const char *name;
564 BPyGPUTexture *py_texture;
565 if (!PyArg_ParseTuple(args,
566 "s" /* `name` */
567 "O!" /* `texture` */
568 ":GPUShader.uniform_sampler",
569 &name,
571 &py_texture))
572 {
573 return nullptr;
574 }
575
576 GPU_shader_bind(self->shader);
577 int slot = GPU_shader_get_sampler_binding(self->shader, name);
578 GPU_texture_bind(py_texture->tex, slot);
579 GPU_shader_uniform_1i(self->shader, name, slot);
580
581 Py_RETURN_NONE;
582}
583
585 /* Wrap. */
586 pygpu_shader_image_doc,
587 ".. method:: image(name, texture)\n"
588 "\n"
589 " Specify the value of an image variable for the current GPUShader.\n"
590 "\n"
591 " :param name: Name of the image variable to which the texture is to be bound.\n"
592 " :type name: str\n"
593 " :param texture: Texture to attach.\n"
594 " :type texture: :class:`gpu.types.GPUTexture`\n");
595static PyObject *pygpu_shader_image(BPyGPUShader *self, PyObject *args)
596{
597 const char *name;
598 BPyGPUTexture *py_texture;
599 if (!PyArg_ParseTuple(args,
600 "s" /* `name` */
601 "O!" /* `texture` */
602 ":GPUShader.image",
603 &name,
605 &py_texture))
606 {
607 return nullptr;
608 }
609
610 GPU_shader_bind(self->shader);
611 int image_unit = GPU_shader_get_sampler_binding(self->shader, name);
612 if (image_unit == -1) {
613 PyErr_Format(PyExc_ValueError, "Image '%s' not found in shader", name);
614 return nullptr;
615 }
616
617 GPU_texture_image_bind(py_texture->tex, image_unit);
618
619 Py_RETURN_NONE;
620}
621
623 /* Wrap. */
624 pygpu_shader_uniform_block_doc,
625 ".. method:: uniform_block(name, ubo)\n"
626 "\n"
627 " Specify the value of a uniform buffer object variable for the current GPUShader.\n"
628 "\n"
629 " :param name: Name of the uniform variable whose UBO is to be specified.\n"
630 " :type name: str\n"
631 " :param ubo: Uniform Buffer to attach.\n"
632 " :type ubo: :class:`gpu.types.GPUUniformBuf`\n");
633static PyObject *pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args)
634{
635 const char *name;
636 BPyGPUUniformBuf *py_ubo;
637 if (!PyArg_ParseTuple(args,
638 "s" /* `name` */
639 "O!" /* `ubo` */
640 ":GPUShader.uniform_block",
641 &name,
643 &py_ubo))
644 {
645 return nullptr;
646 }
647
648 int binding = GPU_shader_get_ubo_binding(self->shader, name);
649 if (binding == -1) {
650 PyErr_SetString(
651 PyExc_BufferError,
652 "GPUShader.uniform_block: uniform block not found, make sure the name is correct");
653 return nullptr;
654 }
655
656 GPU_shader_bind(self->shader);
657 GPU_uniformbuf_bind(py_ubo->ubo, binding);
658
659 Py_RETURN_NONE;
660}
661
663 /* Wrap. */
664 pygpu_shader_storage_block_doc,
665 ".. method:: storage_block(name, ssbo)\n"
666 "\n"
667 " Specify the value of a storage buffer object variable for the current GPUShader.\n"
668 "\n"
669 " :param name: Name of the storage block variable whose SSBO is to be specified.\n"
670 " :type name: str\n"
671 " :param ssbo: Storage Buffer to attach.\n"
672 " :type ssbo: :class:`gpu.types.GPUStorageBuf`\n");
673static PyObject *pygpu_shader_storage_block(BPyGPUShader *self, PyObject *args)
674{
675 const char *name;
676 BPyGPUStorageBuf *py_ssbo;
677 if (!PyArg_ParseTuple(
678 args, "sO!:GPUShader.storage_block", &name, &BPyGPUStorageBuf_Type, &py_ssbo))
679 {
680 return nullptr;
681 }
682
683 int binding = GPU_shader_get_ssbo_binding(self->shader, name);
684 if (binding == -1) {
685 PyErr_SetString(
686 PyExc_BufferError,
687 "GPUShader.storage_block: storage block not found, make sure the name is correct");
688 return nullptr;
689 }
690
691 GPU_shader_bind(self->shader);
692 GPU_storagebuf_bind(py_ssbo->ssbo, binding);
693
694 Py_RETURN_NONE;
695}
696
698 /* Wrap. */
699 pygpu_shader_attr_from_name_doc,
700 ".. method:: attr_from_name(name)\n"
701 "\n"
702 " Get attribute location by name.\n"
703 "\n"
704 " :param name: The name of the attribute variable whose location is to be queried.\n"
705 " :type name: str\n"
706 " :return: The location of an attribute variable.\n"
707 " :rtype: int\n");
708static PyObject *pygpu_shader_attr_from_name(BPyGPUShader *self, PyObject *arg)
709{
710 const char *name = PyUnicode_AsUTF8(arg);
711 if (name == nullptr) {
712 return nullptr;
713 }
714
715 const int attr = GPU_shader_get_attribute(self->shader, name);
716
717 if (attr == -1) {
718 PyErr_Format(PyExc_ValueError, "GPUShader.attr_from_name: attribute %.32s not found", name);
719 return nullptr;
720 }
721
722 return PyLong_FromLong(attr);
723}
724
726 /* Wrap. */
727 pygpu_shader_format_calc_doc,
728 ".. method:: format_calc()\n"
729 "\n"
730 " Build a new format based on the attributes of the shader.\n"
731 "\n"
732 " :return: vertex attribute format for the shader\n"
733 " :rtype: :class:`gpu.types.GPUVertFormat`\n");
734static PyObject *pygpu_shader_format_calc(BPyGPUShader *self, PyObject * /*arg*/)
735{
736 BPyGPUVertFormat *ret = reinterpret_cast<BPyGPUVertFormat *>(
740
741 /* WORKAROUND: Special case for POLYLINE shader. */
742 if (GPU_shader_get_ssbo_binding(self->shader, "pos") >= 0) {
743 GPU_vertformat_attr_add(&ret->fmt, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
744 }
745 if (GPU_shader_get_ssbo_binding(self->shader, "color") >= 0) {
746 GPU_vertformat_attr_add(&ret->fmt, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
747 }
748 }
749 else {
751 }
752 return reinterpret_cast<PyObject *>(ret);
753}
754
756 /* Wrap. */
757 pygpu_shader_attrs_info_get_doc,
758 ".. method:: attrs_info_get()\n"
759 "\n"
760 " Information about the attributes used in the Shader.\n"
761 "\n"
762 " :return: tuples containing information about the attributes in order (name, type)\n"
763 " :rtype: tuple[tuple[str, str | None], ...]\n");
764static PyObject *pygpu_shader_attrs_info_get(BPyGPUShader *self, PyObject * /*arg*/)
765{
766 using namespace blender::gpu::shader;
767 PyObject *ret;
768 int type;
769 int location_test = 0, attrs_added = 0;
770 char name[256];
771
773 /* WORKAROUND: Special case for POLYLINE shader. Check the SSBO inputs as attributes. */
774 uint input_len = GPU_shader_get_ssbo_input_len(self->shader);
775
776 /* Skip "gpu_index_buf". */
777 input_len -= 1;
778 ret = PyTuple_New(input_len);
779 while (attrs_added < input_len) {
780 if (!GPU_shader_get_ssbo_input_info(self->shader, location_test++, name)) {
781 continue;
782 }
783 if (STREQ(name, "gpu_index_buf")) {
784 continue;
785 }
786
787 type = STREQ(name, "pos") ? int(Type::float3_t) :
788 STREQ(name, "color") ? int(Type::float4_t) :
789 -1;
790 PyObject *py_type;
791 if (type != -1) {
792 py_type = PyUnicode_InternFromString(
794 }
795 else {
796 py_type = Py_None;
797 Py_INCREF(py_type);
798 }
799
800 PyObject *attr_info = PyTuple_New(2);
801 PyTuple_SET_ITEMS(attr_info, PyUnicode_FromString(name), py_type);
802 PyTuple_SetItem(ret, attrs_added, attr_info);
803 attrs_added++;
804 }
805 }
806 else {
807 uint attr_len = GPU_shader_get_attribute_len(self->shader);
808
809 ret = PyTuple_New(attr_len);
810 while (attrs_added < attr_len) {
811 if (!GPU_shader_get_attribute_info(self->shader, location_test++, name, &type)) {
812 continue;
813 }
814 PyObject *py_type;
815 if (type != -1) {
816 py_type = PyUnicode_InternFromString(
818 }
819 else {
820 py_type = Py_None;
821 Py_INCREF(py_type);
822 }
823
824 PyObject *attr_info = PyTuple_New(2);
825 PyTuple_SET_ITEMS(attr_info, PyUnicode_FromString(name), py_type);
826 PyTuple_SetItem(ret, attrs_added, attr_info);
827 attrs_added++;
828 }
829 }
830 return ret;
831}
832
833#ifdef __GNUC__
834# ifdef __clang__
835# pragma clang diagnostic push
836# pragma clang diagnostic ignored "-Wcast-function-type"
837# else
838# pragma GCC diagnostic push
839# pragma GCC diagnostic ignored "-Wcast-function-type"
840# endif
841#endif
842
843static PyMethodDef pygpu_shader__tp_methods[] = {
844 {"bind", reinterpret_cast<PyCFunction>(pygpu_shader_bind), METH_NOARGS, pygpu_shader_bind_doc},
845 {"uniform_from_name",
846 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_from_name),
847 METH_O,
848 pygpu_shader_uniform_from_name_doc},
849 {"uniform_block_from_name",
850 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_block_from_name),
851 METH_O,
852 pygpu_shader_uniform_block_from_name_doc},
853 {"uniform_vector_float",
854 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_vector_float),
855 METH_VARARGS,
856 pygpu_shader_uniform_vector_float_doc},
857 {"uniform_vector_int",
858 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_vector_int),
859 METH_VARARGS,
860 pygpu_shader_uniform_vector_int_doc},
861 {"uniform_bool",
862 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_bool),
863 METH_VARARGS,
864 pygpu_shader_uniform_bool_doc},
865 {"uniform_float",
866 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_float),
867 METH_VARARGS,
868 pygpu_shader_uniform_float_doc},
869 {"uniform_int",
870 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_int),
871 METH_VARARGS,
872 pygpu_shader_uniform_int_doc},
873 {"uniform_sampler",
874 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_sampler),
875 METH_VARARGS,
876 pygpu_shader_uniform_sampler_doc},
877 {"image",
878 reinterpret_cast<PyCFunction>(pygpu_shader_image),
879 METH_VARARGS,
880 pygpu_shader_image_doc},
881 {"uniform_block",
882 reinterpret_cast<PyCFunction>(pygpu_shader_uniform_block),
883 METH_VARARGS,
884 pygpu_shader_uniform_block_doc},
885 {"storage_block",
886 reinterpret_cast<PyCFunction>(pygpu_shader_storage_block),
887 METH_VARARGS,
888 pygpu_shader_storage_block_doc},
889 {"attr_from_name",
890 reinterpret_cast<PyCFunction>(pygpu_shader_attr_from_name),
891 METH_O,
892 pygpu_shader_attr_from_name_doc},
893 {"format_calc",
894 reinterpret_cast<PyCFunction>(pygpu_shader_format_calc),
895 METH_NOARGS,
896 pygpu_shader_format_calc_doc},
897 {"attrs_info_get",
898 reinterpret_cast<PyCFunction>(pygpu_shader_attrs_info_get),
899 METH_NOARGS,
900 pygpu_shader_attrs_info_get_doc},
901 {nullptr, nullptr, 0, nullptr},
902};
903
904#ifdef __GNUC__
905# ifdef __clang__
906# pragma clang diagnostic pop
907# else
908# pragma GCC diagnostic pop
909# endif
910#endif
911
913 /* Wrap. */
914 pygpu_shader_name_doc,
915 "The name of the shader object for debugging purposes (read-only).\n"
916 "\n"
917 ":type: str\n");
918static PyObject *pygpu_shader_name(BPyGPUShader *self, void * /*closure*/)
919{
920 return PyUnicode_FromString(GPU_shader_get_name(self->shader));
921}
922
924 /* Wrap. */
925 pygpu_shader_program_doc,
926 "The name of the program object for use by the OpenGL API (read-only).\n"
927 "This is deprecated and will always return -1.\n"
928 "\n"
929 ":type: int\n");
930static PyObject *pygpu_shader_program_get(BPyGPUShader * /*self*/, void * /*closure*/)
931{
932 PyErr_WarnEx(
933 PyExc_DeprecationWarning, "'program' is deprecated. No valid handle will be returned.", 1);
934 return PyLong_FromLong(-1);
935}
936
937static PyGetSetDef pygpu_shader__tp_getseters[] = {
938 {"program",
939 reinterpret_cast<getter>(pygpu_shader_program_get),
940 static_cast<setter>(nullptr),
941 pygpu_shader_program_doc,
942 nullptr},
943 {"name",
944 reinterpret_cast<getter>(pygpu_shader_name),
945 static_cast<setter>(nullptr),
946 pygpu_shader_name_doc,
947 nullptr},
948 {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */
949};
950
952{
953 if (self->is_builtin == false) {
954 GPU_shader_free(self->shader);
955 }
956 Py_TYPE(self)->tp_free(reinterpret_cast<PyObject *>(self));
957}
958
959PyTypeObject BPyGPUShader_Type = {
960 /*ob_base*/ PyVarObject_HEAD_INIT(nullptr, 0)
961 /*tp_name*/ "GPUShader",
962 /*tp_basicsize*/ sizeof(BPyGPUShader),
963 /*tp_itemsize*/ 0,
964 /*tp_dealloc*/ reinterpret_cast<destructor>(pygpu_shader__tp_dealloc),
965 /*tp_vectorcall_offset*/ 0,
966 /*tp_getattr*/ nullptr,
967 /*tp_setattr*/ nullptr,
968 /*tp_as_async*/ nullptr,
969 /*tp_repr*/ nullptr,
970 /*tp_as_number*/ nullptr,
971 /*tp_as_sequence*/ nullptr,
972 /*tp_as_mapping*/ nullptr,
973 /*tp_hash*/ nullptr,
974 /*tp_call*/ nullptr,
975 /*tp_str*/ nullptr,
976 /*tp_getattro*/ nullptr,
977 /*tp_setattro*/ nullptr,
978 /*tp_as_buffer*/ nullptr,
979 /*tp_flags*/ Py_TPFLAGS_DEFAULT,
980 /*tp_doc*/ nullptr,
981 /*tp_traverse*/ nullptr,
982 /*tp_clear*/ nullptr,
983 /*tp_richcompare*/ nullptr,
984 /*tp_weaklistoffset*/ 0,
985 /*tp_iter*/ nullptr,
986 /*tp_iternext*/ nullptr,
987 /*tp_methods*/ pygpu_shader__tp_methods,
988 /*tp_members*/ nullptr,
989 /*tp_getset*/ pygpu_shader__tp_getseters,
990 /*tp_base*/ nullptr,
991 /*tp_dict*/ nullptr,
992 /*tp_descr_get*/ nullptr,
993 /*tp_descr_set*/ nullptr,
994 /*tp_dictoffset*/ 0,
995 /*tp_init*/ nullptr,
996 /*tp_alloc*/ nullptr,
997 /*tp_new*/ nullptr,
998 /*tp_free*/ nullptr,
999 /*tp_is_gc*/ nullptr,
1000 /*tp_bases*/ nullptr,
1001 /*tp_mro*/ nullptr,
1002 /*tp_cache*/ nullptr,
1003 /*tp_subclasses*/ nullptr,
1004 /*tp_weaklist*/ nullptr,
1005 /*tp_del*/ nullptr,
1006 /*tp_version_tag*/ 0,
1007 /*tp_finalize*/ nullptr,
1008 /*tp_vectorcall*/ nullptr,
1009};
1010
1012
1013/* -------------------------------------------------------------------- */
1016
1018 /* Wrap. */
1019 pygpu_shader_unbind_doc,
1020 ".. function:: unbind()\n"
1021 "\n"
1022 " Unbind the bound shader object.\n");
1023static PyObject *pygpu_shader_unbind(PyObject * /*self*/)
1024{
1026 Py_RETURN_NONE;
1027}
1028
1030 /* Wrap. */
1031 pygpu_shader_from_builtin_doc,
1032 ".. function:: from_builtin(shader_name, *, config='DEFAULT')\n"
1033 "\n"
1034 " Shaders that are embedded in the Blender internal code (see :ref:`built-in-shaders`).\n"
1035 " They all read the uniform ``mat4 ModelViewProjectionMatrix``,\n"
1036 " which can be edited by the :mod:`gpu.matrix` module.\n"
1037 "\n"
1038 " You can also choose a shader configuration that uses clip_planes by setting the "
1039 "``CLIPPED`` value to the config parameter. Note that in this case you also need to "
1040 "manually set the value of ``mat4 ModelMatrix``.\n"
1041 "\n"
1042 " :param shader_name: One of the builtin shader names.\n"
1043 " :type shader_name: str\n"
1044 " :param config: One of these types of shader configuration:\n"
1045 "\n"
1046 " - ``DEFAULT``\n"
1047 " - ``CLIPPED``\n"
1048 " :type config: str\n"
1049 " :return: Shader object corresponding to the given name.\n"
1050 " :rtype: :class:`gpu.types.GPUShader`\n");
1051static PyObject *pygpu_shader_from_builtin(PyObject * /*self*/, PyObject *args, PyObject *kwds)
1052{
1054
1055 PyC_StringEnum pygpu_bultinshader = {pygpu_shader_builtin_items};
1057
1058 static const char *_keywords[] = {"shader_name", "config", nullptr};
1059 static _PyArg_Parser _parser = {
1060 "O&" /* `shader_name` */
1061 "|$" /* Optional, keyword only arguments. */
1062 "O&" /* `config` */
1063 ":from_builtin",
1064 _keywords,
1065 nullptr,
1066 };
1067 if (!_PyArg_ParseTupleAndKeywordsFast(args,
1068 kwds,
1069 &_parser,
1071 &pygpu_bultinshader,
1073 &pygpu_config))
1074 {
1075 return nullptr;
1076 }
1077
1079 GPUBuiltinShader(pygpu_bultinshader.value_found), GPUShaderConfig(pygpu_config.value_found));
1080
1081 if (shader == nullptr) {
1082 PyErr_SetString(PyExc_ValueError, "Builtin shader doesn't exist in the requested config");
1083 return nullptr;
1084 }
1085
1086 return BPyGPUShader_CreatePyObject(shader, true);
1087}
1088
1090 /* Wrap. */
1091 pygpu_shader_create_from_info_doc,
1092 ".. function:: create_from_info(shader_info)\n"
1093 "\n"
1094 " Create shader from a GPUShaderCreateInfo.\n"
1095 "\n"
1096 " :param shader_info: GPUShaderCreateInfo\n"
1097 " :type shader_info: :class:`gpu.types.GPUShaderCreateInfo`\n"
1098 " :return: Shader object corresponding to the given shader info.\n"
1099 " :rtype: :class:`gpu.types.GPUShader`\n");
1101{
1103
1105 PyErr_Format(PyExc_TypeError, "Expected a GPUShaderCreateInfo, got %s", Py_TYPE(o)->tp_name);
1106 return nullptr;
1107 }
1108
1109 char error[128];
1110 if (!GPU_shader_create_info_check_error(o->info, error)) {
1111 PyErr_SetString(PyExc_Exception, error);
1112 return nullptr;
1113 }
1114
1116 if (!shader) {
1117 PyErr_SetString(PyExc_Exception, "Shader Compile Error, see console for more details");
1118 return nullptr;
1119 }
1120
1121 return BPyGPUShader_CreatePyObject(shader, false);
1122}
1123
1124#ifdef __GNUC__
1125# ifdef __clang__
1126# pragma clang diagnostic push
1127# pragma clang diagnostic ignored "-Wcast-function-type"
1128# else
1129# pragma GCC diagnostic push
1130# pragma GCC diagnostic ignored "-Wcast-function-type"
1131# endif
1132#endif
1133
1134static PyMethodDef pygpu_shader_module__tp_methods[] = {
1135 {"unbind",
1136 reinterpret_cast<PyCFunction>(pygpu_shader_unbind),
1137 METH_NOARGS,
1138 pygpu_shader_unbind_doc},
1139 {"from_builtin",
1140 reinterpret_cast<PyCFunction>(pygpu_shader_from_builtin),
1141 METH_VARARGS | METH_KEYWORDS,
1142 pygpu_shader_from_builtin_doc},
1143 {"create_from_info",
1144 reinterpret_cast<PyCFunction>(pygpu_shader_create_from_info),
1145 METH_O,
1146 pygpu_shader_create_from_info_doc},
1147 {nullptr, nullptr, 0, nullptr},
1148};
1149
1150#ifdef __GNUC__
1151# ifdef __clang__
1152# pragma clang diagnostic pop
1153# else
1154# pragma GCC diagnostic pop
1155# endif
1156#endif
1157
1159 /* Wrap. */
1160 pygpu_shader_module__tp_doc,
1161 "This module provides access to GPUShader internal functions.\n"
1162 "\n"
1163 ".. _built-in-shaders:\n"
1164 "\n"
1165 ".. rubric:: Built-in shaders\n"
1166 "\n"
1167 "All built-in shaders have the ``mat4 ModelViewProjectionMatrix`` uniform.\n"
1168 "\n"
1169 "Its value must be modified using the :mod:`gpu.matrix` module.\n"
1170 "\n"
1171 ".. important::\n"
1172 "\n"
1173 " Shader uniforms must be explicitly initialized to avoid retaining values from previous "
1174 "executions.\n"
1176static PyModuleDef pygpu_shader_module_def = {
1177 /*m_base*/ PyModuleDef_HEAD_INIT,
1178 /*m_name*/ "gpu.shader",
1179 /*m_doc*/ pygpu_shader_module__tp_doc,
1180 /*m_size*/ 0,
1181 /*m_methods*/ pygpu_shader_module__tp_methods,
1182 /*m_slots*/ nullptr,
1183 /*m_traverse*/ nullptr,
1184 /*m_clear*/ nullptr,
1185 /*m_free*/ nullptr,
1186};
1187
1189
1190/* -------------------------------------------------------------------- */
1193
1195{
1196 BPyGPUShader *self;
1197
1198 self = PyObject_New(BPyGPUShader, &BPyGPUShader_Type);
1199 self->shader = shader;
1200 self->is_builtin = is_builtin;
1201
1202 return reinterpret_cast<PyObject *>(self);
1203}
1204
1206{
1207 PyObject *submodule;
1208
1209 submodule = PyModule_Create(&pygpu_shader_module_def);
1210
1211 return submodule;
1212}
1213
1221
1223
1224} // namespace blender
#define ELEM(...)
#define STREQ(a, b)
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
Definition gpu_py.hh:45
#define PYDOC_BUILTIN_SHADER_DESCRIPTION
#define BPyGPUShaderCreateInfo_Check(v)
#define uniform(slot)
float length(VecOp< float, D >) RET
#define BaseMath_ReadCallback(_self)
Definition mathutils.hh:147
#define MatrixObject_Check(v)
BMesh Iterators.
static PyObject * pygpu_shader_attrs_info_get(BPyGPUShader *self, PyObject *)
static PyObject * pygpu_shader_unbind(PyObject *)
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)
int GPU_shader_get_sampler_binding(gpu::Shader *shader, const char *name)
unsigned int uint
Definition BKE_text.h:55
static PyObject * pygpu_shader_uniform_from_name(BPyGPUShader *self, PyObject *arg)
bool bpygpu_shader_is_polyline(gpu::Shader *shader)
static const PyC_StringEnumItems pygpu_shader_config_items[]
gpu::Shader * GPU_shader_create_from_info_python(const GPUShaderCreateInfo *_info)
static PyObject * pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args)
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")
static PyObject * pygpu_shader_format_calc(BPyGPUShader *self, PyObject *)
static PyGetSetDef pygpu_shader__tp_getseters[]
static PyObject * pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *args)
void GPU_vertformat_from_shader(GPUVertFormat *format, const gpu::Shader *shader)
static PyObject * pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject *args)
static PyObject * pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args)
int GPU_shader_get_attribute(const gpu::Shader *shader, const char *name)
void GPU_shader_uniform_int_ex(gpu::Shader *shader, int location, int length, int array_size, const int *value)
static PyObject * pygpu_shader_storage_block(BPyGPUShader *self, PyObject *args)
int GPU_shader_get_ssbo_binding(gpu::Shader *shader, const char *name)
static PyModuleDef pygpu_shader_module_def
static void pygpu_shader__tp_dealloc(BPyGPUShader *self)
static PyMethodDef pygpu_shader__tp_methods[]
PyObject * BPyGPUShader_CreatePyObject(gpu::Shader *shader, bool is_builtin)
PyObject * BPyGPUVertFormat_CreatePyObject(GPUVertFormat *fmt)
static PyObject * pygpu_shader_from_builtin(PyObject *, PyObject *args, PyObject *kwds)
bool GPU_shader_get_ssbo_input_info(const gpu::Shader *shader, int ssbo_location, char r_name[256])
static PyObject * pygpu_shader_create_from_info(BPyGPUShader *, BPyGPUShaderCreateInfo *o)
void GPU_shader_unbind()
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
@ GPU_SHADER_3D_POLYLINE_FLAT_COLOR
@ GPU_SHADER_3D_IMAGE_COLOR_SCENE_LINEAR_TO_REC709_SRGB
@ GPU_SHADER_3D_IMAGE_SCENE_LINEAR_TO_REC709_SRGB
@ GPU_SHADER_3D_POINT_UNIFORM_COLOR
@ GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR
@ GPU_SHADER_3D_POINT_FLAT_COLOR
PyTypeObject BPyGPUStorageBuf_Type
void GPU_shader_uniform_float_ex(gpu::Shader *shader, int location, int length, int array_size, const float *value)
const struct PyC_StringEnumItems pygpu_attrtype_items[]
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
Definition mathutils.cc:97
static PyObject * pygpu_shader_attr_from_name(BPyGPUShader *self, PyObject *arg)
static PyMethodDef pygpu_shader_module__tp_methods[]
uint GPU_shader_get_attribute_len(const gpu::Shader *shader)
static PyObject * pygpu_shader_bind(BPyGPUShader *self)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(gpu::Shader *sh, const char *name, int value)
void GPU_storagebuf_bind(gpu::StorageBuf *ssbo, int slot)
void GPU_uniformbuf_bind(gpu::UniformBuf *ubo, int slot)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
PyTypeObject BPyGPUUniformBuf_Type
const char * PyC_StringEnum_FindIDFromValue(const PyC_StringEnumItems *items, const int value)
static bool pygpu_shader_uniform_vector_impl(PyObject *args, int elem_size, int *r_location, int *r_length, int *r_count, Py_buffer *r_pybuffer)
PyObject * bpygpu_shader_init()
int GPU_shader_get_uniform(gpu::Shader *shader, const char *name)
gpu::Shader * GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
uint GPU_shader_get_ssbo_input_len(const gpu::Shader *shader)
static PyObject * pygpu_shader_image(BPyGPUShader *self, PyObject *args)
PyTypeObject BPyGPUTexture_Type
static PyObject * pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args)
static int pygpu_shader_uniform_location_get(gpu::Shader *shader, const char *name, const char *error_prefix)
static PyObject * pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args)
void GPU_texture_bind(gpu::Texture *texture, int unit)
const char * GPU_shader_get_name(gpu::Shader *shader)
static PyObject * pygpu_shader_name(BPyGPUShader *self, void *)
int GPU_shader_get_ubo_binding(gpu::Shader *shader, const char *name)
void GPU_texture_image_bind(gpu::Texture *texture, int unit)
void GPU_vertformat_clear(GPUVertFormat *)
static const PyC_StringEnumItems pygpu_shader_builtin_items[]
gpu::Shader * GPU_shader_get_builtin_shader_with_config(GPUBuiltinShader shader, GPUShaderConfig sh_cfg)
void GPU_shader_free(gpu::Shader *shader)
int PyC_ParseStringEnum(PyObject *o, void *p)
PyTypeObject BPyGPUShader_Type
static PyObject * pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args)
static PyObject * pygpu_shader_uniform_block_from_name(BPyGPUShader *self, PyObject *arg)
bool GPU_shader_get_attribute_info(const gpu::Shader *shader, int attr_location, char r_name[256], int *r_type)
static PyObject * pygpu_shader_program_get(BPyGPUShader *, void *)
bool GPU_shader_create_info_check_error(const GPUShaderCreateInfo *_info, char r_error[128])
int GPU_shader_get_uniform_block(gpu::Shader *shader, const char *name)
header-only compatibility defines.
header-only utilities
#define PyTuple_SET_ITEMS(op_arg,...)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
PyObject_HEAD GPUShaderCreateInfo * info
PyObject_HEAD gpu::Shader * shader
PyObject_HEAD gpu::StorageBuf * ssbo
PyObject_HEAD gpu::Texture * tex
PyObject_HEAD gpu::UniformBuf * ubo