| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup bpygpu | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  |  * Experimental Python API, not considered public yet (called '_gpu'), | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  |  * we may re-expose as public later. | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-07-20 22:52:31 +10:00
										 |  |  |  * - Use `bpygpu_` for local API. | 
					
						
							|  |  |  |  * - Use `BPyGPU` for public API. | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "../generic/python_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-14 11:15:00 -03:00
										 |  |  | #include "gpu_py_capabilities.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  | #include "gpu_py_matrix.h"
 | 
					
						
							| 
									
										
										
										
											2021-05-14 11:15:00 -03:00
										 |  |  | #include "gpu_py_platform.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  | #include "gpu_py_select.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_state.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  | #include "gpu_py_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 00:55:07 +11:00
										 |  |  | #include "gpu_py_api.h" /* own include */
 | 
					
						
							| 
									
										
										
										
											2019-01-02 10:01:46 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name GPU Module
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | PyDoc_STRVAR(pygpu_doc, | 
					
						
							| 
									
										
										
										
											2020-10-09 11:56:11 +11:00
										 |  |  |              "This module provides Python wrappers for the GPU implementation in Blender.\n" | 
					
						
							|  |  |  |              "Some higher level functions can be found in the `gpu_extras` module."); | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  | static struct PyModuleDef pygpu_module_def = { | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  |     PyModuleDef_HEAD_INIT, | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |     .m_name = "gpu", | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |     .m_doc = pygpu_doc, | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | PyObject *BPyInit_gpu(void) | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-13 17:08:58 +10:00
										 |  |  |   PyObject *sys_modules = PyImport_GetModuleDict(); | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  |   PyObject *submodule; | 
					
						
							|  |  |  |   PyObject *mod; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-17 10:16:41 -03:00
										 |  |  |   mod = PyModule_Create(&pygpu_module_def); | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 13:53:20 -03:00
										 |  |  |   PyModule_AddObject(mod, "types", (submodule = bpygpu_types_init())); | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  |   PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-14 11:15:00 -03:00
										 |  |  |   PyModule_AddObject(mod, "capabilities", (submodule = bpygpu_capabilities_init())); | 
					
						
							|  |  |  |   PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 13:53:20 -03:00
										 |  |  |   PyModule_AddObject(mod, "matrix", (submodule = bpygpu_matrix_init())); | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |   PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-14 11:15:00 -03:00
										 |  |  |   PyModule_AddObject(mod, "platform", (submodule = bpygpu_platform_init())); | 
					
						
							|  |  |  |   PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 13:53:20 -03:00
										 |  |  |   PyModule_AddObject(mod, "select", (submodule = bpygpu_select_init())); | 
					
						
							| 
									
										
										
										
											2018-09-05 21:10:42 -03:00
										 |  |  |   PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-11 13:53:20 -03:00
										 |  |  |   PyModule_AddObject(mod, "shader", (submodule = bpygpu_shader_init())); | 
					
						
							| 
									
										
										
										
											2018-09-14 09:32:19 -03:00
										 |  |  |   PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
											
												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
										 |  |  |   PyModule_AddObject(mod, "state", (submodule = bpygpu_state_init())); | 
					
						
							|  |  |  |   PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-01 17:35:10 -03:00
										 |  |  |   PyModule_AddObject(mod, "texture", (submodule = bpygpu_texture_init())); | 
					
						
							|  |  |  |   PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-17 20:32:42 +10:00
										 |  |  |   return mod; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-01-02 10:01:46 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** \} */ |