| 
									
										
										
										
											2022-02-11 09:07:11 +11:00
										 |  |  | /* SPDX-License-Identifier: GPL-2.0-or-later */ | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup bpygpu | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-07-20 22:52:31 +10:00
										 |  |  |  * - Use `bpygpu_` for local API. | 
					
						
							|  |  |  |  * - Use `BPyGPU` for public API. | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "GPU_shader.h"
 | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | #include "GPU_texture.h"
 | 
					
						
							|  |  |  | #include "GPU_uniform_buffer.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-23 10:17:38 +02:00
										 |  |  | #include "../mathutils/mathutils.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-22 09:44:57 -03:00
										 |  |  | #include "gpu_py.h"
 | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | #include "gpu_py_texture.h"
 | 
					
						
							|  |  |  | #include "gpu_py_uniformbuffer.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-09 11:17:29 +02:00
										 |  |  | #include "gpu_py_vertex_format.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | #include "gpu_py_shader.h" /* own include */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Enum Conversion.
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-19 11:15:22 -03:00
										 |  |  | #define PYDOC_BUILTIN_SHADER_DESCRIPTION \
 | 
					
						
							|  |  |  |   "``2D_FLAT_COLOR``\n" \ | 
					
						
							| 
									
										
										
										
											2022-07-28 14:34:42 -03:00
										 |  |  |   "   :Attributes: vec2 pos, vec4 color\n" \ | 
					
						
							| 
									
										
										
										
											2022-04-19 11:15:22 -03:00
										 |  |  |   "   :Uniforms: none\n" \ | 
					
						
							|  |  |  |   "``2D_IMAGE``\n" \ | 
					
						
							| 
									
										
										
										
											2022-07-28 14:34:42 -03:00
										 |  |  |   "   :Attributes: vec2 pos, vec2 texCoord\n" \ | 
					
						
							| 
									
										
										
										
											2022-04-19 11:15:22 -03:00
										 |  |  |   "   :Uniforms: sampler2D image\n" \ | 
					
						
							|  |  |  |   "``2D_SMOOTH_COLOR``\n" \ | 
					
						
							| 
									
										
										
										
											2022-07-28 14:34:42 -03:00
										 |  |  |   "   :Attributes: vec2 pos, vec4 color\n" \ | 
					
						
							| 
									
										
										
										
											2022-04-19 11:15:22 -03:00
										 |  |  |   "   :Uniforms: none\n" \ | 
					
						
							|  |  |  |   "``2D_UNIFORM_COLOR``\n" \ | 
					
						
							| 
									
										
										
										
											2022-07-28 14:34:42 -03:00
										 |  |  |   "   :Attributes: vec2 pos\n" \ | 
					
						
							| 
									
										
										
										
											2022-04-19 11:15:22 -03:00
										 |  |  |   "   :Uniforms: vec4 color\n" \ | 
					
						
							|  |  |  |   "``3D_FLAT_COLOR``\n" \ | 
					
						
							|  |  |  |   "   :Attributes: vec3 pos, vec4 color\n" \ | 
					
						
							|  |  |  |   "   :Uniforms: none\n" \ | 
					
						
							| 
									
										
											  
											
												EEVEE & Viewport: Add a built-in shader called 3D_IMAGE, and expose to the python API
Adds an example python script to the documentation for the 3D_IMAGE shader.
The **use-case** is to draw textures with 3D vertex positions, in XR views as well as non-XR views (in a simpler manner).
**Testing**: I've tested that this compiles and works on my Macbook (with the example python script included in this change). I don't have access to a Windows or Linux machine right now, but this change doesn't look platform-specific and no new glsl shaders have been added or edited by this change. I'll try to get access to a Windows machine, but if someone does have one, I'd be really grateful if they could try this change. Thanks!
**Problem addressed**: The existing 2D_IMAGE shader (exposed in the python API) gets near-clipped when drawn in the
XR view, regardless of the near-clip settings. Additionally, the 2D_IMAGE shader only accepts 2D
positions for the image vertices, which means drawing textures in 3D requires providing
2D coordinates and then pushing a transform-rotate-scale matrix to the GPU, even for
non-XR (i.e. WINDOW) views. The 3D_IMAGE shader is simpler: it accepts 3D vertex positions, and doesn't require
any additional work by the scripter.
**Workaround**: The current workaround is to use custom shaders in the python script.
**Non-intrusive change**: No new glsl shaders were added. This change just bundles two existing shaders: the vertex shader used
by the 3D_IMAGE_MODULATE_ALPHA shader, and the fragment shader used by the 2D_IMAGE shader.
Reviewed By: #eevee_viewport, jbakker
Differential Revision: https://developer.blender.org/D14832
											
										 
											2022-05-09 08:07:28 +02:00
										 |  |  |   "``3D_IMAGE``\n" \ | 
					
						
							|  |  |  |   "   :Attributes: vec3 pos, vec2 texCoord\n" \ | 
					
						
							|  |  |  |   "   :Uniforms: sampler2D image\n" \ | 
					
						
							| 
									
										
										
										
											2022-04-19 11:15:22 -03:00
										 |  |  |   "``3D_SMOOTH_COLOR``\n" \ | 
					
						
							|  |  |  |   "   :Attributes: vec3 pos, vec4 color\n" \ | 
					
						
							|  |  |  |   "   :Uniforms: none\n" \ | 
					
						
							|  |  |  |   "``3D_UNIFORM_COLOR``\n" \ | 
					
						
							|  |  |  |   "   :Attributes: vec3 pos\n" \ | 
					
						
							|  |  |  |   "   :Uniforms: vec4 color\n" \ | 
					
						
							|  |  |  |   "``3D_POLYLINE_FLAT_COLOR``\n" \ | 
					
						
							|  |  |  |   "   :Attributes: vec3 pos, vec4 color\n" \ | 
					
						
							|  |  |  |   "   :Uniforms: vec2 viewportSize, float lineWidth\n" \ | 
					
						
							|  |  |  |   "``3D_POLYLINE_SMOOTH_COLOR``\n" \ | 
					
						
							|  |  |  |   "   :Attributes: vec3 pos, vec4 color\n" \ | 
					
						
							|  |  |  |   "   :Uniforms: vec2 viewportSize, float lineWidth\n" \ | 
					
						
							|  |  |  |   "``3D_POLYLINE_UNIFORM_COLOR``\n" \ | 
					
						
							|  |  |  |   "   :Attributes: vec3 pos\n" \ | 
					
						
							|  |  |  |   "   :Uniforms: vec2 viewportSize, float lineWidth\n" | 
					
						
							| 
									
										
										
										
											2021-08-11 11:38:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static const struct PyC_StringEnumItems pygpu_shader_builtin_items[] = { | 
					
						
							| 
									
										
										
										
											2020-12-11 15:35:55 -03:00
										 |  |  |     {GPU_SHADER_2D_FLAT_COLOR, "2D_FLAT_COLOR"}, | 
					
						
							|  |  |  |     {GPU_SHADER_2D_IMAGE, "2D_IMAGE"}, | 
					
						
							| 
									
										
										
										
											2021-08-11 11:38:34 -03:00
										 |  |  |     {GPU_SHADER_2D_SMOOTH_COLOR, "2D_SMOOTH_COLOR"}, | 
					
						
							|  |  |  |     {GPU_SHADER_2D_UNIFORM_COLOR, "2D_UNIFORM_COLOR"}, | 
					
						
							| 
									
										
										
										
											2020-12-11 15:35:55 -03:00
										 |  |  |     {GPU_SHADER_3D_FLAT_COLOR, "3D_FLAT_COLOR"}, | 
					
						
							| 
									
										
											  
											
												EEVEE & Viewport: Add a built-in shader called 3D_IMAGE, and expose to the python API
Adds an example python script to the documentation for the 3D_IMAGE shader.
The **use-case** is to draw textures with 3D vertex positions, in XR views as well as non-XR views (in a simpler manner).
**Testing**: I've tested that this compiles and works on my Macbook (with the example python script included in this change). I don't have access to a Windows or Linux machine right now, but this change doesn't look platform-specific and no new glsl shaders have been added or edited by this change. I'll try to get access to a Windows machine, but if someone does have one, I'd be really grateful if they could try this change. Thanks!
**Problem addressed**: The existing 2D_IMAGE shader (exposed in the python API) gets near-clipped when drawn in the
XR view, regardless of the near-clip settings. Additionally, the 2D_IMAGE shader only accepts 2D
positions for the image vertices, which means drawing textures in 3D requires providing
2D coordinates and then pushing a transform-rotate-scale matrix to the GPU, even for
non-XR (i.e. WINDOW) views. The 3D_IMAGE shader is simpler: it accepts 3D vertex positions, and doesn't require
any additional work by the scripter.
**Workaround**: The current workaround is to use custom shaders in the python script.
**Non-intrusive change**: No new glsl shaders were added. This change just bundles two existing shaders: the vertex shader used
by the 3D_IMAGE_MODULATE_ALPHA shader, and the fragment shader used by the 2D_IMAGE shader.
Reviewed By: #eevee_viewport, jbakker
Differential Revision: https://developer.blender.org/D14832
											
										 
											2022-05-09 08:07:28 +02:00
										 |  |  |     {GPU_SHADER_3D_IMAGE, "3D_IMAGE"}, | 
					
						
							| 
									
										
										
										
											2020-12-11 15:35:55 -03:00
										 |  |  |     {GPU_SHADER_3D_SMOOTH_COLOR, "3D_SMOOTH_COLOR"}, | 
					
						
							| 
									
										
										
										
											2021-08-11 11:38:34 -03:00
										 |  |  |     {GPU_SHADER_3D_UNIFORM_COLOR, "3D_UNIFORM_COLOR"}, | 
					
						
							|  |  |  |     {GPU_SHADER_3D_POLYLINE_FLAT_COLOR, "3D_POLYLINE_FLAT_COLOR"}, | 
					
						
							|  |  |  |     {GPU_SHADER_3D_POLYLINE_SMOOTH_COLOR, "3D_POLYLINE_SMOOTH_COLOR"}, | 
					
						
							| 
									
										
										
										
											2020-12-11 15:35:55 -03:00
										 |  |  |     {GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR, "3D_POLYLINE_UNIFORM_COLOR"}, | 
					
						
							|  |  |  |     {0, NULL}, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-26 13:02:52 -03:00
										 |  |  | static const struct PyC_StringEnumItems pygpu_shader_config_items[] = { | 
					
						
							|  |  |  |     {GPU_SHADER_CFG_DEFAULT, "DEFAULT"}, | 
					
						
							|  |  |  |     {GPU_SHADER_CFG_CLIPPED, "CLIPPED"}, | 
					
						
							|  |  |  |     {0, NULL}, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static int pygpu_shader_uniform_location_get(GPUShader *shader, | 
					
						
							|  |  |  |                                              const char *name, | 
					
						
							|  |  |  |                                              const char *error_prefix) | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |   const int uniform = GPU_shader_get_uniform(shader, name); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 15:48:22 -03:00
										 |  |  |   if (uniform == -1) { | 
					
						
							| 
									
										
										
										
											2019-06-05 08:44:24 -03:00
										 |  |  |     PyErr_Format(PyExc_ValueError, "%s: uniform %.32s not found", error_prefix, name); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-12 15:48:22 -03:00
										 |  |  |   return uniform; | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Shader Type
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader__tp_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-03 01:08:26 +11:00
										 |  |  |   BPYGPU_IS_INIT_OR_ERROR_OBJ; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   struct { | 
					
						
							|  |  |  |     const char *vertexcode; | 
					
						
							|  |  |  |     const char *fragcode; | 
					
						
							|  |  |  |     const char *geocode; | 
					
						
							|  |  |  |     const char *libcode; | 
					
						
							|  |  |  |     const char *defines; | 
					
						
							| 
									
										
										
										
											2021-09-13 16:12:12 +10:00
										 |  |  |     const char *name; | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   } params = {0}; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 00:22:57 -03:00
										 |  |  |   static const char *_keywords[] = { | 
					
						
							| 
									
										
										
										
											2021-09-13 16:12:12 +10:00
										 |  |  |       "vertexcode", "fragcode", "geocode", "libcode", "defines", "name", NULL}; | 
					
						
							| 
									
										
										
										
											2022-04-08 09:41:28 +10:00
										 |  |  |   static _PyArg_Parser _parser = { | 
					
						
							|  |  |  |       "s"  /* `vertexcode` */ | 
					
						
							|  |  |  |       "s"  /* `fragcode` */ | 
					
						
							|  |  |  |       "|$" /* Optional keyword only arguments. */ | 
					
						
							|  |  |  |       "s"  /* `geocode` */ | 
					
						
							|  |  |  |       "s"  /* `libcode` */ | 
					
						
							|  |  |  |       "s"  /* `defines` */ | 
					
						
							|  |  |  |       "s"  /* `name` */ | 
					
						
							|  |  |  |       ":GPUShader.__new__", | 
					
						
							|  |  |  |       _keywords, | 
					
						
							|  |  |  |       0, | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2019-01-03 01:08:26 +11:00
										 |  |  |   if (!_PyArg_ParseTupleAndKeywordsFast(args, | 
					
						
							| 
									
										
										
										
											2018-09-27 00:22:57 -03:00
										 |  |  |                                         kwds, | 
					
						
							|  |  |  |                                         &_parser, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |                                         ¶ms.vertexcode, | 
					
						
							|  |  |  |                                         ¶ms.fragcode, | 
					
						
							|  |  |  |                                         ¶ms.geocode, | 
					
						
							|  |  |  |                                         ¶ms.libcode, | 
					
						
							| 
									
										
										
										
											2021-09-13 16:12:12 +10:00
										 |  |  |                                         ¶ms.defines, | 
					
						
							|  |  |  |                                         ¶ms.name)) { | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 16:12:12 +10:00
										 |  |  |   GPUShader *shader = GPU_shader_create_from_python(params.vertexcode, | 
					
						
							|  |  |  |                                                     params.fragcode, | 
					
						
							|  |  |  |                                                     params.geocode, | 
					
						
							|  |  |  |                                                     params.libcode, | 
					
						
							|  |  |  |                                                     params.defines, | 
					
						
							|  |  |  |                                                     params.name); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   if (shader == NULL) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_Exception, "Shader Compile Error, see console for more details"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-20 15:21:59 -03:00
										 |  |  |   return BPyGPUShader_CreatePyObject(shader, false); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     pygpu_shader_bind_doc, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     ".. method:: bind()\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2018-11-14 09:04:24 +11:00
										 |  |  |     "   Bind the shader object. Required to be able to change uniforms of this shader.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_bind(BPyGPUShader *self) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   GPU_shader_bind(self->shader); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_uniform_from_name_doc, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |              ".. method:: uniform_from_name(name)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Get uniform location by name.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param name: Name of the uniform variable whose location is to be queried.\n" | 
					
						
							| 
									
										
										
										
											2021-03-16 12:48:00 -03:00
										 |  |  |              "   :type name: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :return: Location of the uniform variable.\n" | 
					
						
							| 
									
										
										
										
											2021-03-16 12:48:00 -03:00
										 |  |  |              "   :rtype: int\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_uniform_from_name(BPyGPUShader *self, PyObject *arg) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   const char *name = PyUnicode_AsUTF8(arg); | 
					
						
							|  |  |  |   if (name == NULL) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   const int uniform = pygpu_shader_uniform_location_get( | 
					
						
							|  |  |  |       self->shader, name, "GPUShader.get_uniform"); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (uniform == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return PyLong_FromLong(uniform); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     pygpu_shader_uniform_block_from_name_doc, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     ".. method:: uniform_block_from_name(name)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Get uniform block location by name.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :param name: Name of the uniform block variable whose location is to be queried.\n" | 
					
						
							| 
									
										
										
										
											2021-03-16 12:48:00 -03:00
										 |  |  |     "   :type name: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :return: The location of the uniform block variable.\n" | 
					
						
							| 
									
										
										
										
											2021-03-16 12:48:00 -03:00
										 |  |  |     "   :rtype: int\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_uniform_block_from_name(BPyGPUShader *self, PyObject *arg) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   const char *name = PyUnicode_AsUTF8(arg); | 
					
						
							|  |  |  |   if (name == NULL) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |   const int uniform = GPU_shader_get_uniform_block(self->shader, name); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (uniform == -1) { | 
					
						
							| 
									
										
										
										
											2018-10-12 15:48:22 -03:00
										 |  |  |     PyErr_Format(PyExc_ValueError, "GPUShader.get_uniform_block: uniform %.32s not found", name); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return PyLong_FromLong(uniform); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | 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) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   PyObject *buffer; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   *r_count = 1; | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple( | 
					
						
							|  |  |  |           args, "iOi|i:GPUShader.uniform_vector_*", r_location, &buffer, r_length, r_count)) { | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   if (PyObject_GetBuffer(buffer, r_pybuffer, PyBUF_SIMPLE) == -1) { | 
					
						
							|  |  |  |     /* PyObject_GetBuffer raise a PyExc_BufferError */ | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-16 13:53:56 -03:00
										 |  |  |   if (r_pybuffer->len < (*r_length * *r_count * elem_size)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_OverflowError, | 
					
						
							|  |  |  |                     "GPUShader.uniform_vector_*: buffer size smaller than required."); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_uniform_vector_float_doc, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |              ".. method:: uniform_vector_float(location, buffer, length, count)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Set the buffer to fill the uniform.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param location: Location of the uniform variable to be modified.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |              "   :type location: int\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param buffer:  The data that should be set. Can support the buffer protocol.\n" | 
					
						
							|  |  |  |              "   :type buffer: sequence of floats\n" | 
					
						
							| 
									
										
										
										
											2020-10-11 18:19:42 -04:00
										 |  |  |              "   :param length: Size of the uniform data type:\n\n" | 
					
						
							| 
									
										
										
										
											2018-09-15 08:00:47 +10:00
										 |  |  |              "      - 1: float\n" | 
					
						
							|  |  |  |              "      - 2: vec2 or float[2]\n" | 
					
						
							|  |  |  |              "      - 3: vec3 or float[3]\n" | 
					
						
							|  |  |  |              "      - 4: vec4 or float[4]\n" | 
					
						
							|  |  |  |              "      - 9: mat3\n" | 
					
						
							|  |  |  |              "      - 16: mat4\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |              "   :type length: int\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param count: Specifies the number of elements, vector or matrices that are to " | 
					
						
							|  |  |  |              "be modified.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |              "   :type count: int\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_uniform_vector_float(BPyGPUShader *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   int location, length, count; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_buffer pybuffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   if (!pygpu_shader_uniform_vector_impl( | 
					
						
							|  |  |  |           args, sizeof(float), &location, &length, &count, &pybuffer)) { | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_shader_uniform_vector(self->shader, location, length, count, pybuffer.buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PyBuffer_Release(&pybuffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_uniform_vector_int_doc, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |              ".. method:: uniform_vector_int(location, buffer, length, count)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-09-15 08:00:47 +10:00
										 |  |  |              "   See GPUShader.uniform_vector_float(...) description.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_uniform_vector_int(BPyGPUShader *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   int location, length, count; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_buffer pybuffer; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   if (!pygpu_shader_uniform_vector_impl( | 
					
						
							|  |  |  |           args, sizeof(int), &location, &length, &count, &pybuffer)) { | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_shader_uniform_vector_int(self->shader, location, length, count, pybuffer.buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PyBuffer_Release(&pybuffer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_uniform_bool_doc, | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |              ".. method:: uniform_bool(name, seq)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Specify the value of a uniform variable for the current program object.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param name: Name of the uniform variable whose value is to be changed.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |              "   :type name: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param seq: Value that will be used to update the specified uniform variable.\n" | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |              "   :type seq: sequence of bools\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_uniform_bool(BPyGPUShader *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   const char *error_prefix = "GPUShader.uniform_bool"; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   struct { | 
					
						
							|  |  |  |     const char *id; | 
					
						
							|  |  |  |     PyObject *seq; | 
					
						
							|  |  |  |   } params; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   if (!PyArg_ParseTuple(args, "sO:GPUShader.uniform_bool", ¶ms.id, ¶ms.seq)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   int values[4]; | 
					
						
							|  |  |  |   int length; | 
					
						
							|  |  |  |   int ret; | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix); | 
					
						
							|  |  |  |     if (seq_fast == NULL) { | 
					
						
							| 
									
										
										
										
											2018-10-04 13:48:08 -03:00
										 |  |  |       PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  |                    "%s: expected a sequence, got %s", | 
					
						
							|  |  |  |                    error_prefix, | 
					
						
							|  |  |  |                    Py_TYPE(params.seq)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |       ret = -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2018-10-04 13:48:08 -03:00
										 |  |  |       length = PySequence_Fast_GET_SIZE(seq_fast); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |       if (length == 0 || length > 4) { | 
					
						
							|  |  |  |         PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  |                      "%s: invalid sequence length. expected 1..4, got %d", | 
					
						
							|  |  |  |                      error_prefix, | 
					
						
							|  |  |  |                      length); | 
					
						
							|  |  |  |         ret = -1; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2021-07-27 22:26:33 +10:00
										 |  |  |         ret = PyC_AsArray_FAST( | 
					
						
							|  |  |  |             values, sizeof(*values), seq_fast, length, &PyLong_Type, error_prefix); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |       } | 
					
						
							|  |  |  |       Py_DECREF(seq_fast); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (ret == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   if (location == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   GPU_shader_uniform_vector_int(self->shader, location, length, 1, values); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_uniform_float_doc, | 
					
						
							| 
									
										
										
										
											2018-10-23 10:17:38 +02:00
										 |  |  |              ".. method:: uniform_float(name, value)\n" | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Specify the value of a uniform variable for the current program object.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param name: Name of the uniform variable whose value is to be changed.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |              "   :type name: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param value: Value that will be used to update the specified uniform variable.\n" | 
					
						
							| 
									
										
										
										
											2018-10-23 10:17:38 +02:00
										 |  |  |              "   :type value: single number or sequence of numbers\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2018-09-20 19:51:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   const char *error_prefix = "GPUShader.uniform_float"; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   struct { | 
					
						
							|  |  |  |     const char *id; | 
					
						
							|  |  |  |     PyObject *seq; | 
					
						
							|  |  |  |   } params; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   if (!PyArg_ParseTuple(args, "sO:GPUShader.uniform_float", ¶ms.id, ¶ms.seq)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   float values[16]; | 
					
						
							|  |  |  |   int length; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 10:17:38 +02:00
										 |  |  |   if (PyFloat_Check(params.seq)) { | 
					
						
							|  |  |  |     values[0] = (float)PyFloat_AsDouble(params.seq); | 
					
						
							|  |  |  |     length = 1; | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-10-23 10:17:38 +02:00
										 |  |  |   else if (PyLong_Check(params.seq)) { | 
					
						
							|  |  |  |     values[0] = (float)PyLong_AsDouble(params.seq); | 
					
						
							|  |  |  |     length = 1; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-10-24 18:45:47 +11:00
										 |  |  |   else if (MatrixObject_Check(params.seq)) { | 
					
						
							|  |  |  |     MatrixObject *mat = (MatrixObject *)params.seq; | 
					
						
							|  |  |  |     if (BaseMath_ReadCallback(mat) == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-03-28 11:06:01 +11:00
										 |  |  |     if ((mat->row_num != mat->col_num) || !ELEM(mat->row_num, 3, 4)) { | 
					
						
							| 
									
										
										
										
											2018-10-24 18:45:47 +11:00
										 |  |  |       PyErr_SetString(PyExc_ValueError, "Expected 3x3 or 4x4 matrix"); | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-03-28 11:06:01 +11:00
										 |  |  |     length = mat->row_num * mat->col_num; | 
					
						
							| 
									
										
										
										
											2018-10-24 18:45:47 +11:00
										 |  |  |     memcpy(values, mat->matrix, sizeof(float) * length); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-10-23 10:17:38 +02:00
										 |  |  |   else { | 
					
						
							|  |  |  |     length = mathutils_array_parse(values, 2, 16, params.seq, ""); | 
					
						
							| 
									
										
										
										
											2018-10-24 18:45:47 +11:00
										 |  |  |     if (length == -1) { | 
					
						
							|  |  |  |       return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-10-23 10:17:38 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 10:17:38 +02:00
										 |  |  |   if (!ELEM(length, 1, 2, 3, 4, 9, 16)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_TypeError, | 
					
						
							|  |  |  |                     "Expected a single float or a sequence of floats of length 1..4, 9 or 16."); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   if (location == -1) { | 
					
						
							| 
									
										
										
										
											2018-09-20 19:51:02 +00:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   GPU_shader_uniform_vector(self->shader, location, length, 1, values); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-20 19:51:02 +00:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_uniform_int_doc, | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |              ".. method:: uniform_int(name, seq)\n" | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |              "   Specify the value of a uniform variable for the current program object.\n" | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param name: name of the uniform variable whose value is to be changed.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |              "   :type name: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |              "   :param seq: Value that will be used to update the specified uniform variable.\n" | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |              "   :type seq: sequence of numbers\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_uniform_int(BPyGPUShader *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   const char *error_prefix = "GPUShader.uniform_int"; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   struct { | 
					
						
							|  |  |  |     const char *id; | 
					
						
							|  |  |  |     PyObject *seq; | 
					
						
							|  |  |  |   } params; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   if (!PyArg_ParseTuple(args, "sO:GPUShader.uniform_int", ¶ms.id, ¶ms.seq)) { | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   int values[4]; | 
					
						
							|  |  |  |   int length; | 
					
						
							|  |  |  |   int ret; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 11:59:49 +11:00
										 |  |  |   if (PyLong_Check(params.seq)) { | 
					
						
							|  |  |  |     values[0] = PyC_Long_AsI32(params.seq); | 
					
						
							|  |  |  |     length = 1; | 
					
						
							| 
									
										
										
										
											2018-10-28 17:22:26 +01:00
										 |  |  |     ret = 0; | 
					
						
							| 
									
										
										
										
											2018-10-26 11:59:49 +11:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |     PyObject *seq_fast = PySequence_Fast(params.seq, error_prefix); | 
					
						
							|  |  |  |     if (seq_fast == NULL) { | 
					
						
							| 
									
										
										
										
											2018-10-04 13:48:08 -03:00
										 |  |  |       PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  |                    "%s: expected a sequence, got %s", | 
					
						
							|  |  |  |                    error_prefix, | 
					
						
							|  |  |  |                    Py_TYPE(params.seq)->tp_name); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |       ret = -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2018-10-04 13:48:08 -03:00
										 |  |  |       length = PySequence_Fast_GET_SIZE(seq_fast); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |       if (length == 0 || length > 4) { | 
					
						
							|  |  |  |         PyErr_Format(PyExc_TypeError, | 
					
						
							|  |  |  |                      "%s: invalid sequence length. expected 1..4, got %d", | 
					
						
							|  |  |  |                      error_prefix, | 
					
						
							|  |  |  |                      length); | 
					
						
							|  |  |  |         ret = -1; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2021-07-27 22:26:33 +10:00
										 |  |  |         ret = PyC_AsArray_FAST( | 
					
						
							|  |  |  |             values, sizeof(*values), seq_fast, length, &PyLong_Type, error_prefix); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |       } | 
					
						
							|  |  |  |       Py_DECREF(seq_fast); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (ret == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   const int location = pygpu_shader_uniform_location_get(self->shader, params.id, error_prefix); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   if (location == -1) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |   GPU_shader_uniform_vector_int(self->shader, location, length, 1, values); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_uniform_sampler_doc, | 
					
						
							| 
									
										
										
										
											2021-09-02 10:18:44 -03:00
										 |  |  |              ".. method:: uniform_sampler(name, texture)\n" | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2021-09-02 10:18:44 -03:00
										 |  |  |              "   Specify the value of a texture uniform variable for the current GPUShader.\n" | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   :param name: name of the uniform variable whose texture is to be specified.\n" | 
					
						
							|  |  |  |              "   :type name: str\n" | 
					
						
							|  |  |  |              "   :param texture: Texture to attach.\n" | 
					
						
							| 
									
										
										
										
											2021-09-02 10:18:44 -03:00
										 |  |  |              "   :type texture: :class:`gpu.types.GPUTexture`\n"); | 
					
						
							|  |  |  | static PyObject *pygpu_shader_uniform_sampler(BPyGPUShader *self, PyObject *args) | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   const char *name; | 
					
						
							|  |  |  |   BPyGPUTexture *py_texture; | 
					
						
							| 
									
										
										
										
											2021-09-02 10:18:44 -03:00
										 |  |  |   if (!PyArg_ParseTuple( | 
					
						
							|  |  |  |           args, "sO!:GPUShader.uniform_sampler", &name, &BPyGPUTexture_Type, &py_texture)) { | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   int slot = GPU_shader_get_texture_binding(self->shader, name); | 
					
						
							| 
									
										
										
										
											2021-09-02 10:18:44 -03:00
										 |  |  |   GPU_texture_bind(py_texture->tex, slot); | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |   GPU_shader_uniform_1i(self->shader, name, slot); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							| 
									
										
										
										
											2021-02-17 13:22:54 -03:00
										 |  |  |     pygpu_shader_uniform_block_doc, | 
					
						
							|  |  |  |     ".. method:: uniform_block(name, ubo)\n" | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |     "\n" | 
					
						
							|  |  |  |     "   Specify the value of an uniform buffer object variable for the current GPUShader.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :param name: name of the uniform variable whose UBO is to be specified.\n" | 
					
						
							|  |  |  |     "   :type name: str\n" | 
					
						
							|  |  |  |     "   :param ubo: Uniform Buffer to attach.\n" | 
					
						
							|  |  |  |     "   :type texture: :class:`gpu.types.GPUUniformBuf`\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 13:22:54 -03:00
										 |  |  | static PyObject *pygpu_shader_uniform_block(BPyGPUShader *self, PyObject *args) | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   const char *name; | 
					
						
							|  |  |  |   BPyGPUUniformBuf *py_ubo; | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple( | 
					
						
							| 
									
										
										
										
											2021-02-17 13:22:54 -03:00
										 |  |  |           args, "sO!:GPUShader.uniform_block", &name, &BPyGPUUniformBuf_Type, &py_ubo)) { | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-13 02:38:52 -03:00
										 |  |  |   int binding = GPU_shader_get_uniform_block_binding(self->shader, name); | 
					
						
							|  |  |  |   if (binding == -1) { | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |     PyErr_SetString( | 
					
						
							|  |  |  |         PyExc_BufferError, | 
					
						
							| 
									
										
										
										
											2022-04-13 02:38:52 -03:00
										 |  |  |         "GPUShader.uniform_block: uniform block not found, make sure the name is correct"); | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-13 02:38:52 -03:00
										 |  |  |   GPU_uniformbuf_bind(py_ubo->ubo, binding); | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     pygpu_shader_attr_from_name_doc, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     ".. method:: attr_from_name(name)\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Get attribute location by name.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :param name: The name of the attribute variable whose location is to be queried.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |     "   :type name: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :return: The location of an attribute variable.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |     "   :rtype: int\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_attr_from_name(BPyGPUShader *self, PyObject *arg) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   const char *name = PyUnicode_AsUTF8(arg); | 
					
						
							|  |  |  |   if (name == NULL) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 16:10:13 +10:00
										 |  |  |   const int attr = GPU_shader_get_attribute(self->shader, name); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 10:49:36 +11:00
										 |  |  |   if (attr == -1) { | 
					
						
							| 
									
										
										
										
											2018-10-12 15:48:22 -03:00
										 |  |  |     PyErr_Format(PyExc_ValueError, "GPUShader.attr_from_name: attribute %.32s not found", name); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-23 10:49:36 +11:00
										 |  |  |   return PyLong_FromLong(attr); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-18 09:32:49 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_format_calc_doc, | 
					
						
							|  |  |  |              ".. method:: format_calc()\n" | 
					
						
							| 
									
										
										
										
											2018-10-09 11:17:29 +02:00
										 |  |  |              "\n" | 
					
						
							|  |  |  |              "   Build a new format based on the attributes of the shader.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :return: vertex attribute format for the shader\n" | 
					
						
							| 
									
										
										
										
											2021-03-16 12:48:00 -03:00
										 |  |  |              "   :rtype: :class:`gpu.types.GPUVertFormat`\n"); | 
					
						
							| 
									
										
										
										
											2022-08-18 09:32:49 -03:00
										 |  |  | static PyObject *pygpu_shader_format_calc(BPyGPUShader *self, PyObject *UNUSED(arg)) | 
					
						
							| 
									
										
										
										
											2018-10-09 11:17:29 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   BPyGPUVertFormat *ret = (BPyGPUVertFormat *)BPyGPUVertFormat_CreatePyObject(NULL); | 
					
						
							| 
									
										
										
										
											2020-06-02 12:11:39 +02:00
										 |  |  |   GPU_vertformat_from_shader(&ret->fmt, self->shader); | 
					
						
							| 
									
										
										
										
											2018-10-09 11:17:29 +02:00
										 |  |  |   return (PyObject *)ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static struct PyMethodDef pygpu_shader__tp_methods[] = { | 
					
						
							|  |  |  |     {"bind", (PyCFunction)pygpu_shader_bind, METH_NOARGS, pygpu_shader_bind_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     {"uniform_from_name", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_shader_uniform_from_name, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |      METH_O, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_shader_uniform_from_name_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     {"uniform_block_from_name", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_shader_uniform_block_from_name, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |      METH_O, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_shader_uniform_block_from_name_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     {"uniform_vector_float", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_shader_uniform_vector_float, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |      METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_shader_uniform_vector_float_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     {"uniform_vector_int", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_shader_uniform_vector_int, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |      METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_shader_uniform_vector_int_doc}, | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |     {"uniform_bool", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_shader_uniform_bool, | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |      METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_shader_uniform_bool_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-20 19:51:02 +00:00
										 |  |  |     {"uniform_float", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_shader_uniform_float, | 
					
						
							| 
									
										
										
										
											2018-09-20 19:51:02 +00:00
										 |  |  |      METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_shader_uniform_float_doc}, | 
					
						
							|  |  |  |     {"uniform_int", | 
					
						
							|  |  |  |      (PyCFunction)pygpu_shader_uniform_int, | 
					
						
							|  |  |  |      METH_VARARGS, | 
					
						
							|  |  |  |      pygpu_shader_uniform_int_doc}, | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |     {"uniform_sampler", | 
					
						
							|  |  |  |      (PyCFunction)pygpu_shader_uniform_sampler, | 
					
						
							| 
									
										
										
										
											2021-09-02 10:18:44 -03:00
										 |  |  |      METH_VARARGS, | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |      pygpu_shader_uniform_sampler_doc}, | 
					
						
							| 
									
										
										
										
											2021-02-17 13:22:54 -03:00
										 |  |  |     {"uniform_block", | 
					
						
							|  |  |  |      (PyCFunction)pygpu_shader_uniform_block, | 
					
						
							| 
									
										
										
											
												Python: gpu module: add new submodules and types
This commit extends the gpu python API with:
```
gpu.types.Buffer         #"__init__", "to_list"
gpu.types.GPUTexture     #"__init__", "clear", "read", "format"
gpu.types.GPUFrameBuffer #"__init__", "bind", "clear", "is_bound", "viewport", ("__enter__",  "__exit__" with "GPUFrameBufferStackContext")
gpu.types.GPUUniformBuf  #"__init__", "update"
gpu.state                #"blend_set",  "blend_get",  "depth_test_set",  "depth_test_get",  "depth_mask_set",  "depth_mask_get",  "viewport_set",  "viewport_get",  "line_width_set",  "line_width_get",  "point_size_set",  "color_mask_set",  "face_culling_set", "front_facing_set",  "program_point_size_set"
```
Add these methods to existing objects:
```
gpu.types.GPUShader  #"uniform_sample", "uniform_buffer"
```
Maniphest Tasks: T80481
Differential Revision: https://developer.blender.org/D8826
											
										 
											2021-02-17 10:48:08 -03:00
										 |  |  |      METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2021-02-17 13:22:54 -03:00
										 |  |  |      pygpu_shader_uniform_block_doc}, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     {"attr_from_name", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      (PyCFunction)pygpu_shader_attr_from_name, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |      METH_O, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_shader_attr_from_name_doc}, | 
					
						
							|  |  |  |     {"format_calc", | 
					
						
							| 
									
										
										
										
											2022-08-18 09:32:49 -03:00
										 |  |  |      (PyCFunction)pygpu_shader_format_calc, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2022-08-18 09:32:49 -03:00
										 |  |  |      pygpu_shader_format_calc_doc}, | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  |     {NULL, NULL, 0, NULL}, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-13 16:12:12 +10:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_name_doc, | 
					
						
							|  |  |  |              "The name of the shader object for debugging purposes (read-only).\n\n:type: str"); | 
					
						
							|  |  |  | static PyObject *pygpu_shader_name(BPyGPUShader *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return PyUnicode_FromString(GPU_shader_get_name(self->shader)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     pygpu_shader_program_doc, | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  |     "The name of the program object for use by the OpenGL API (read-only).\n\n:type: int"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_program_get(BPyGPUShader *self, void *UNUSED(closure)) | 
					
						
							| 
									
										
										
										
											2018-10-03 23:34:27 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   return PyLong_FromLong(GPU_shader_get_program(self->shader)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyGetSetDef pygpu_shader__tp_getseters[] = { | 
					
						
							|  |  |  |     {"program", (getter)pygpu_shader_program_get, (setter)NULL, pygpu_shader_program_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2021-09-13 16:12:12 +10:00
										 |  |  |     {"name", (getter)pygpu_shader_name, (setter)NULL, pygpu_shader_name_doc, NULL}, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static void pygpu_shader__tp_dealloc(BPyGPUShader *self) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-20 15:21:59 -03:00
										 |  |  |   if (self->is_builtin == false) { | 
					
						
							|  |  |  |     GPU_shader_free(self->shader); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   Py_TYPE(self)->tp_free((PyObject *)self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR( | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     pygpu_shader__tp_doc, | 
					
						
							| 
									
										
										
										
											2021-09-13 16:12:12 +10:00
										 |  |  |     ".. class:: GPUShader(vertexcode, fragcode, geocode=None, libcode=None, defines=None, " | 
					
						
							|  |  |  |     "name='pyGPUShader')\n" | 
					
						
							| 
									
										
										
										
											2018-09-15 08:00:47 +10:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   GPUShader combines multiple GLSL shaders into a program used for drawing.\n" | 
					
						
							| 
									
										
										
										
											2021-08-30 15:12:57 -03:00
										 |  |  |     "   It must contain at least a vertex and fragment shaders.\n" | 
					
						
							| 
									
										
										
										
											2018-09-15 08:00:47 +10:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2020-10-11 18:19:42 -04:00
										 |  |  |     "   The GLSL ``#version`` directive is automatically included at the top of shaders,\n" | 
					
						
							|  |  |  |     "   and set to 330. Some preprocessor directives are automatically added according to\n" | 
					
						
							|  |  |  |     "   the Operating System or availability: ``GPU_ATI``, ``GPU_NVIDIA`` and ``GPU_INTEL``.\n" | 
					
						
							| 
									
										
										
										
											2018-09-15 08:00:47 +10:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   The following extensions are enabled by default if supported by the GPU:\n" | 
					
						
							| 
									
										
										
										
											2020-10-11 18:19:42 -04:00
										 |  |  |     "   ``GL_ARB_texture_gather``, ``GL_ARB_texture_cube_map_array``\n" | 
					
						
							|  |  |  |     "   and ``GL_ARB_shader_draw_parameters``.\n" | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2020-10-11 18:19:42 -04:00
										 |  |  |     "   For drawing user interface elements and gizmos, use\n" | 
					
						
							|  |  |  |     "   ``fragOutput = blender_srgb_to_framebuffer_space(fragOutput)``\n" | 
					
						
							|  |  |  |     "   to transform the output sRGB colors to the frame-buffer color-space.\n" | 
					
						
							| 
									
										
										
										
											2020-04-14 20:44:45 +02:00
										 |  |  |     "\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :param vertexcode: Vertex shader code.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |     "   :type vertexcode: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :param fragcode: Fragment shader code.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |     "   :type value: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :param geocode: Geometry shader code.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |     "   :type value: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :param libcode: Code with functions and presets to be shared between shaders.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |     "   :type value: str\n" | 
					
						
							| 
									
										
										
										
											2018-11-13 14:55:15 +01:00
										 |  |  |     "   :param defines: Preprocessor directives.\n" | 
					
						
							| 
									
										
										
										
											2021-09-13 16:12:12 +10:00
										 |  |  |     "   :type value: str\n" | 
					
						
							|  |  |  |     "   :param name: Name of shader code, for debugging purposes.\n" | 
					
						
							| 
									
										
										
										
											2018-10-04 13:08:04 +10:00
										 |  |  |     "   :type value: str\n"); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | PyTypeObject BPyGPUShader_Type = { | 
					
						
							|  |  |  |     PyVarObject_HEAD_INIT(NULL, 0).tp_name = "GPUShader", | 
					
						
							|  |  |  |     .tp_basicsize = sizeof(BPyGPUShader), | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     .tp_dealloc = (destructor)pygpu_shader__tp_dealloc, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     .tp_flags = Py_TPFLAGS_DEFAULT, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     .tp_doc = pygpu_shader__tp_doc, | 
					
						
							|  |  |  |     .tp_methods = pygpu_shader__tp_methods, | 
					
						
							|  |  |  |     .tp_getset = pygpu_shader__tp_getseters, | 
					
						
							|  |  |  |     .tp_new = pygpu_shader__tp_new, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name gpu.shader Module API
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_unbind_doc, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |              ".. function:: unbind()\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Unbind the bound shader object.\n"); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyObject *pygpu_shader_unbind(BPyGPUShader *UNUSED(self)) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   GPU_shader_unbind(); | 
					
						
							|  |  |  |   Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-25 13:35:39 +10:00
										 |  |  | PyDoc_STRVAR( | 
					
						
							|  |  |  |     pygpu_shader_from_builtin_doc, | 
					
						
							|  |  |  |     ".. function:: from_builtin(shader_name, config='DEFAULT')\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   Shaders that are embedded in the blender internal code (see :ref:`built-in-shaders`).\n" | 
					
						
							|  |  |  |     "   They all read the uniform ``mat4 ModelViewProjectionMatrix``,\n" | 
					
						
							|  |  |  |     "   which can be edited by the :mod:`gpu.matrix` module.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   You can also choose a shader configuration that uses clip_planes by setting the " | 
					
						
							|  |  |  |     "``CLIPPED`` value to the config parameter. Note that in this case you also need to " | 
					
						
							|  |  |  |     "manually set the value of ``mat4 ModelMatrix``.\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "   :param shader_name: One of the builtin shader names.\n" | 
					
						
							|  |  |  |     "   :type shader_name: str\n" | 
					
						
							|  |  |  |     "   :param config: One of these types of shader configuration:\n" | 
					
						
							|  |  |  |     "\n" | 
					
						
							|  |  |  |     "      - ``DEFAULT``\n" | 
					
						
							|  |  |  |     "      - ``CLIPPED``\n" | 
					
						
							|  |  |  |     "   :type config: str\n" | 
					
						
							|  |  |  |     "   :return: Shader object corresponding to the given name.\n" | 
					
						
							|  |  |  |     "   :rtype: :class:`bpy.types.GPUShader`\n"); | 
					
						
							| 
									
										
										
										
											2021-08-26 13:02:52 -03:00
										 |  |  | static PyObject *pygpu_shader_from_builtin(PyObject *UNUSED(self), PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-03 01:08:26 +11:00
										 |  |  |   BPYGPU_IS_INIT_OR_ERROR_OBJ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   struct PyC_StringEnum pygpu_bultinshader = {pygpu_shader_builtin_items}; | 
					
						
							| 
									
										
										
										
											2021-08-26 13:02:52 -03:00
										 |  |  |   struct PyC_StringEnum pygpu_config = {pygpu_shader_config_items, GPU_SHADER_CFG_DEFAULT}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   static const char *_keywords[] = {"shader_name", "config", NULL}; | 
					
						
							| 
									
										
										
										
											2022-04-08 09:41:28 +10:00
										 |  |  |   static _PyArg_Parser _parser = { | 
					
						
							|  |  |  |       "O&" /* `shader_name` */ | 
					
						
							|  |  |  |       "|$" /* Optional keyword only arguments. */ | 
					
						
							|  |  |  |       "O&" /* `config` */ | 
					
						
							|  |  |  |       ":from_builtin", | 
					
						
							|  |  |  |       _keywords, | 
					
						
							|  |  |  |       0, | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2021-08-26 13:02:52 -03:00
										 |  |  |   if (!_PyArg_ParseTupleAndKeywordsFast(args, | 
					
						
							|  |  |  |                                         kwds, | 
					
						
							|  |  |  |                                         &_parser, | 
					
						
							|  |  |  |                                         PyC_ParseStringEnum, | 
					
						
							|  |  |  |                                         &pygpu_bultinshader, | 
					
						
							|  |  |  |                                         PyC_ParseStringEnum, | 
					
						
							|  |  |  |                                         &pygpu_config)) { | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-26 13:02:52 -03:00
										 |  |  |   GPUShader *shader = GPU_shader_get_builtin_shader_with_config(pygpu_bultinshader.value_found, | 
					
						
							|  |  |  |                                                                 pygpu_config.value_found); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-20 15:21:59 -03:00
										 |  |  |   return BPyGPUShader_CreatePyObject(shader, true); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-12 18:28:27 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_create_from_info_doc, | 
					
						
							|  |  |  |              ".. function:: create_from_info(shader_info)\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   Create shader from a GPUShaderCreateInfo.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "   :param shader_info: GPUShaderCreateInfo\n" | 
					
						
							|  |  |  |              "   :type shader_info: :class:`bpy.types.GPUShaderCreateInfo`\n" | 
					
						
							|  |  |  |              "   :return: Shader object corresponding to the given name.\n" | 
					
						
							|  |  |  |              "   :rtype: :class:`bpy.types.GPUShader`\n"); | 
					
						
							|  |  |  | static PyObject *pygpu_shader_create_from_info(BPyGPUShader *UNUSED(self), | 
					
						
							|  |  |  |                                                BPyGPUShaderCreateInfo *o) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if (!BPyGPUShaderCreateInfo_Check(o)) { | 
					
						
							|  |  |  |     PyErr_Format(PyExc_TypeError, "Expected a GPUShaderCreateInfo, got %s", Py_TYPE(o)->tp_name); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   char error[128]; | 
					
						
							|  |  |  |   if (!GPU_shader_create_info_check_error(o->info, error)) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_Exception, error); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPUShader *shader = GPU_shader_create_from_info(o->info); | 
					
						
							|  |  |  |   if (!shader) { | 
					
						
							|  |  |  |     PyErr_SetString(PyExc_Exception, "Shader Compile Error, see console for more details"); | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return BPyGPUShader_CreatePyObject(shader, false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static struct PyMethodDef pygpu_shader_module__tp_methods[] = { | 
					
						
							|  |  |  |     {"unbind", (PyCFunction)pygpu_shader_unbind, METH_NOARGS, pygpu_shader_unbind_doc}, | 
					
						
							|  |  |  |     {"from_builtin", | 
					
						
							|  |  |  |      (PyCFunction)pygpu_shader_from_builtin, | 
					
						
							| 
									
										
										
										
											2021-08-26 13:02:52 -03:00
										 |  |  |      METH_VARARGS | METH_KEYWORDS, | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |      pygpu_shader_from_builtin_doc}, | 
					
						
							| 
									
										
										
										
											2022-04-12 18:28:27 -03:00
										 |  |  |     {"create_from_info", | 
					
						
							|  |  |  |      (PyCFunction)pygpu_shader_create_from_info, | 
					
						
							|  |  |  |      METH_O, | 
					
						
							|  |  |  |      pygpu_shader_create_from_info_doc}, | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  |     {NULL, NULL, 0, NULL}, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_shader_module__tp_doc, | 
					
						
							| 
									
										
										
										
											2020-10-11 18:21:28 -04:00
										 |  |  |              "This module provides access to GPUShader internal functions.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2022-05-25 13:35:39 +10:00
										 |  |  |              ".. _built-in-shaders:\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2020-10-11 18:21:28 -04:00
										 |  |  |              ".. rubric:: Built-in shaders\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							|  |  |  |              "All built-in shaders have the ``mat4 ModelViewProjectionMatrix`` uniform.\n" | 
					
						
							|  |  |  |              "\n" | 
					
						
							| 
									
										
										
										
											2021-08-30 15:12:57 -03:00
										 |  |  |              "Its value must be modified using the :class:`gpu.matrix` module.\n" | 
					
						
							| 
									
										
										
										
											2022-04-19 11:15:22 -03:00
										 |  |  |              "\n" PYDOC_BUILTIN_SHADER_DESCRIPTION); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static PyModuleDef pygpu_shader_module_def = { | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |     PyModuleDef_HEAD_INIT, | 
					
						
							|  |  |  |     .m_name = "gpu.shader", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     .m_doc = pygpu_shader_module__tp_doc, | 
					
						
							|  |  |  |     .m_methods = pygpu_shader_module__tp_methods, | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name Public API
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-20 15:21:59 -03:00
										 |  |  | PyObject *BPyGPUShader_CreatePyObject(GPUShader *shader, bool is_builtin) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   BPyGPUShader *self; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   self = PyObject_New(BPyGPUShader, &BPyGPUShader_Type); | 
					
						
							|  |  |  |   self->shader = shader; | 
					
						
							| 
									
										
										
										
											2018-09-20 15:21:59 -03:00
										 |  |  |   self->is_builtin = is_builtin; | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return (PyObject *)self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 13:53:20 -03:00
										 |  |  | PyObject *bpygpu_shader_init(void) | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | { | 
					
						
							|  |  |  |   PyObject *submodule; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   submodule = PyModule_Create(&pygpu_shader_module_def); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return submodule; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \} */ |