| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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 | 
					
						
							| 
									
										
										
										
											2018-06-01 18:19:39 +02:00
										 |  |  |  * of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2006 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: all of this file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Benoit Bolsee. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \file blender/python/intern/gpu.c
 | 
					
						
							|  |  |  |  *  \ingroup pythonintern | 
					
						
							| 
									
										
										
										
											2011-11-05 08:21:12 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This file defines the 'gpu' module, used to get GLSL shader code and data | 
					
						
							|  |  |  |  * from blender materials. | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							|  |  |  | #include "DNA_material_types.h"
 | 
					
						
							|  |  |  | #include "DNA_ID.h"
 | 
					
						
							|  |  |  | #include "DNA_customdata_types.h"
 | 
					
						
							| 
									
										
										
										
											2011-09-09 13:46:47 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | #include "BLI_listbase.h"
 | 
					
						
							| 
									
										
										
										
											2011-09-09 13:46:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "bpy_rna.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-20 22:04:29 +00:00
										 |  |  | #include "../generic/py_capi_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-03 18:55:59 +11:00
										 |  |  | #include "GPU_material.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 08:20:21 +00:00
										 |  |  | #include "gpu.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | #define PY_MODULE_ADD_CONSTANT(module, name) PyModule_AddIntConstant(module, # name, name)
 | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(M_gpu_doc, | 
					
						
							| 
									
										
										
										
											2015-10-20 01:03:00 -02:00
										 |  |  | "This module provides access to the GLSL shader and Offscreen rendering functionalities." | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | static struct PyModuleDef gpumodule = { | 
					
						
							|  |  |  | 	PyModuleDef_HEAD_INIT, | 
					
						
							|  |  |  | 	"gpu",     /* name of module */ | 
					
						
							|  |  |  | 	M_gpu_doc, /* module documentation */ | 
					
						
							|  |  |  | 	-1,        /* size of per-interpreter state of the module,
 | 
					
						
							| 
									
										
										
										
											2012-03-09 18:28:30 +00:00
										 |  |  | 	            *  or -1 if the module keeps state in global variables. */ | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 	NULL, NULL, NULL, NULL, NULL | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-15 01:52:28 +00:00
										 |  |  | static PyObject *PyInit_gpu(void) | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 	PyObject *m; | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	m = PyModule_Create(&gpumodule); | 
					
						
							| 
									
										
										
										
											2011-10-13 01:29:08 +00:00
										 |  |  | 	if (m == NULL) | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Take care to update docs when editing: 'doc/python_api/rst/gpu.rst' */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 	/* GPUDynamicType */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-21 08:08:27 +10:00
										 |  |  | 	/* device constant groups */ | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_MISC); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_LAMP); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_OBJECT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_SAMPLER); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_MIST); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_WORLD); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_MAT); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* device constants */ | 
					
						
							| 
									
										
										
										
											2015-05-21 08:08:27 +10:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_NONE); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 	/* GPU_DYNAMIC_GROUP_OBJECT */ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_VIEWMAT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_MAT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_VIEWIMAT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_IMAT); | 
					
						
							| 
									
										
										
											
												Vector Transform node support for GLSL mode and the internal renderer
The Vector Transform node is a useful node which is present in the Cycles renderer.
{F144283}
This patch implements the Vector Transform node for GLSL mode and the internal renderer.
Example: {F273060}
Alexander (Blend4Web Team)
Reviewers: brecht, campbellbarton, sergey
Reviewed By: campbellbarton, sergey
Subscribers: psy-fi, duarteframos, RobM, lightbwk, sergey, AlexKowel, valentin_b4w, Evgeny_Rodygin, yurikovelenov
Projects: #bf_blender:_next
Differential Revision: https://developer.blender.org/D909
											
										 
											2016-01-23 15:27:36 +03:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_LOCTOVIEWMAT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_LOCTOVIEWIMAT); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_COLOR); | 
					
						
							| 
									
										
										
										
											2011-12-09 23:26:06 +00:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 	/* GPU_DYNAMIC_GROUP_LAMP */ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNVEC); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNCO); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNIMAT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNPERSMAT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNENERGY); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNCOL); | 
					
						
							| 
									
										
										
										
											2015-05-21 08:08:27 +10:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_ATT1); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_ATT2); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DISTANCE); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_SPOTSIZE); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_SPOTBLEND); | 
					
						
							| 
									
										
										
										
											2015-10-15 22:36:31 +11:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_SPOTSCALE); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 	/* GPU_DYNAMIC_GROUP_SAMPLER */ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DBUFFER); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DIMAGE); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DSHADOW); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 	/* GPU_DYNAMIC_GROUP_MIST */ | 
					
						
							| 
									
										
										
										
											2015-03-23 22:32:49 +01:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_ENABLE); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_START); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_DISTANCE); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_INTENSITY); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_TYPE); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_COLOR); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 	/* GPU_DYNAMIC_GROUP_WORLD */ | 
					
						
							| 
									
										
										
										
											2015-03-23 22:32:49 +01:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_HORIZON_COLOR); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_AMBIENT_COLOR); | 
					
						
							| 
									
										
										
											
												World textures displaying for viewport in BI.
This patch supports "Image or Movie" and "Environment map" types of world texture for the viewport.
It supports:
  - "View", "AngMap" and "Equirectangular" types of mapping.
  - Different types of texture blending (according to BI world render).
  - Same color blending as when it lacked textures (but render via glsl).
{F207734}
{F207735}
Example: {F275180}
Original author: @valentin_b4w
Regards,
Alexander (Blend4Web Team).
Reviewers: sergey, valentin_b4w, brecht, merwin
Reviewed By: merwin
Subscribers: campbellbarton, merwin, blueprintrandom, youle, a.romanov, yurikovelenov, AlexKowel, Evgeny_Rodygin
Projects: #rendering, #opengl_gfx, #bf_blender:_next
Differential Revision: https://developer.blender.org/D1414
											
										 
											2016-01-27 12:06:57 +03:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_ZENITH_COLOR); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 	/* GPU_DYNAMIC_GROUP_MAT */ | 
					
						
							| 
									
										
										
										
											2015-05-21 08:08:27 +10:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_DIFFRGB); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_REF); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_SPECRGB); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_SPEC); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_HARD); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_EMIT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_AMB); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_ALPHA); | 
					
						
							| 
									
										
										
										
											2017-02-02 03:59:21 +01:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_MIR); | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 	/* GPUDataType */ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DATA_1I); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DATA_1F); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DATA_2F); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DATA_3F); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DATA_4F); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DATA_9F); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DATA_16F); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, GPU_DATA_4UB); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-07 16:01:25 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 	/* CustomDataType
 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Intentionally only include the subset used by the GPU API. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	PY_MODULE_ADD_CONSTANT(m, CD_MTFACE); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, CD_ORCO); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, CD_TANGENT); | 
					
						
							|  |  |  | 	PY_MODULE_ADD_CONSTANT(m, CD_MCOL); | 
					
						
							|  |  |  | 	return m; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | #define PY_DICT_ADD_STRING(d, s, f)      \
 | 
					
						
							|  |  |  | 	val = PyUnicode_FromString(s->f);    \ | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, # f, val);   \ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	Py_DECREF(val) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | #define PY_DICT_ADD_LONG(d, s, f)        \
 | 
					
						
							|  |  |  | 	val = PyLong_FromLong(s->f);         \ | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, # f, val);   \ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	Py_DECREF(val) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | #define PY_DICT_ADD_ID(d, s, f)                      \
 | 
					
						
							|  |  |  | 	RNA_id_pointer_create((struct ID *)s->f, &tptr); \ | 
					
						
							|  |  |  | 	val = pyrna_struct_CreatePyObject(&tptr);        \ | 
					
						
							|  |  |  | 	PyDict_SetItemString(d, # f, val);               \ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	Py_DECREF(val) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-22 14:31:03 +00:00
										 |  |  | #if 0  /* UNUSED */
 | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | #define PY_OBJ_ADD_ID(d, s, f)                      \
 | 
					
						
							|  |  |  | 	val = PyUnicode_FromString(&s->f->id.name[2]);  \ | 
					
						
							|  |  |  | 	PyObject_SetAttrString(d, # f, val);            \ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	Py_DECREF(val) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | #define PY_OBJ_ADD_LONG(d, s, f)         \
 | 
					
						
							|  |  |  | 	val = PyLong_FromLong(s->f);         \ | 
					
						
							|  |  |  | 	PyObject_SetAttrString(d, # f, val); \ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	Py_DECREF(val) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | #define PY_OBJ_ADD_STRING(d, s, f)       \
 | 
					
						
							|  |  |  | 	val = PyUnicode_FromString(s->f);    \ | 
					
						
							|  |  |  | 	PyObject_SetAttrString(d, # f, val); \ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	Py_DECREF(val) | 
					
						
							| 
									
										
										
										
											2013-03-22 14:31:03 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 22:56:06 +00:00
										 |  |  | PyDoc_STRVAR(GPU_export_shader_doc, | 
					
						
							|  |  |  | "export_shader(scene, material)\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   Returns the GLSL shader that produces the visual effect of material in scene.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "   :return: Dictionary defining the shader, uniforms and attributes.\n" | 
					
						
							|  |  |  | "   :rtype: Dict" | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2017-10-05 10:52:18 +11:00
										 |  |  | static PyObject *GPU_export_shader(PyObject *UNUSED(self), PyObject *args, PyObject *kw) | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 	PyObject *pyscene; | 
					
						
							|  |  |  | 	PyObject *pymat; | 
					
						
							|  |  |  | 	PyObject *result; | 
					
						
							|  |  |  | 	PyObject *dict; | 
					
						
							|  |  |  | 	PyObject *val; | 
					
						
							|  |  |  | 	PyObject *seq; | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	Scene *scene; | 
					
						
							|  |  |  | 	PointerRNA tptr; | 
					
						
							|  |  |  | 	Material *material; | 
					
						
							|  |  |  | 	GPUShaderExport *shader; | 
					
						
							|  |  |  | 	GPUInputUniform *uniform; | 
					
						
							|  |  |  | 	GPUInputAttribute *attribute; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-05 10:52:18 +11:00
										 |  |  | 	static const char *_keywords[] = {"scene", "material", NULL}; | 
					
						
							|  |  |  | 	static _PyArg_Parser _parser = {"OO:export_shader", _keywords, 0}; | 
					
						
							|  |  |  | 	if (!_PyArg_ParseTupleAndKeywordsFast( | 
					
						
							|  |  |  | 	        args, kw, &_parser, | 
					
						
							|  |  |  | 	        &pyscene, &pymat)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2017-10-05 10:52:18 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-20 22:04:29 +00:00
										 |  |  | 	scene = (Scene *)PyC_RNA_AsPointer(pyscene, "Scene"); | 
					
						
							|  |  |  | 	if (scene == NULL) { | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-20 22:04:29 +00:00
										 |  |  | 	material = (Material *)PyC_RNA_AsPointer(pymat, "Material"); | 
					
						
							|  |  |  | 	if (material == NULL) { | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-20 22:04:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* we can call our internal function at last: */ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	shader = GPU_shader_export(scene, material); | 
					
						
							|  |  |  | 	if (!shader) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_RuntimeError, "cannot export shader"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 	/* build a dictionary */ | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	result = PyDict_New(); | 
					
						
							|  |  |  | 	if (shader->fragment) { | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 		PY_DICT_ADD_STRING(result, shader, fragment); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (shader->vertex) { | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 		PY_DICT_ADD_STRING(result, shader, vertex); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-11-16 13:57:58 +01:00
										 |  |  | 	seq = PyList_New(BLI_listbase_count(&shader->uniforms)); | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 	for (i = 0, uniform = shader->uniforms.first; uniform; uniform = uniform->next, i++) { | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		dict = PyDict_New(); | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 		PY_DICT_ADD_STRING(dict, uniform, varname); | 
					
						
							|  |  |  | 		PY_DICT_ADD_LONG(dict, uniform, datatype); | 
					
						
							|  |  |  | 		PY_DICT_ADD_LONG(dict, uniform, type); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		if (uniform->lamp) { | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 			PY_DICT_ADD_ID(dict, uniform, lamp); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-21 16:13:09 +02:00
										 |  |  | 		if (uniform->material) { | 
					
						
							|  |  |  | 			PY_DICT_ADD_ID(dict, uniform, material); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		if (uniform->image) { | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 			PY_DICT_ADD_ID(dict, uniform, image); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (uniform->type == GPU_DYNAMIC_SAMPLER_2DBUFFER || | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 		    uniform->type == GPU_DYNAMIC_SAMPLER_2DIMAGE || | 
					
						
							|  |  |  | 		    uniform->type == GPU_DYNAMIC_SAMPLER_2DSHADOW) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			PY_DICT_ADD_LONG(dict, uniform, texnumber); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (uniform->texpixels) { | 
					
						
							| 
									
										
										
										
											2011-10-28 08:53:00 +00:00
										 |  |  | 			val = PyByteArray_FromStringAndSize((const char *)uniform->texpixels, uniform->texsize * 4); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 			PyDict_SetItemString(dict, "texpixels", val); | 
					
						
							|  |  |  | 			Py_DECREF(val); | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 			PY_DICT_ADD_LONG(dict, uniform, texsize); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		PyList_SET_ITEM(seq, i, dict); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	PyDict_SetItemString(result, "uniforms", seq); | 
					
						
							|  |  |  | 	Py_DECREF(seq); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-16 13:57:58 +01:00
										 |  |  | 	seq = PyList_New(BLI_listbase_count(&shader->attributes)); | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | 	for (i = 0, attribute = shader->attributes.first; attribute; attribute = attribute->next, i++) { | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		dict = PyDict_New(); | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 		PY_DICT_ADD_STRING(dict, attribute, varname); | 
					
						
							|  |  |  | 		PY_DICT_ADD_LONG(dict, attribute, datatype); | 
					
						
							|  |  |  | 		PY_DICT_ADD_LONG(dict, attribute, type); | 
					
						
							|  |  |  | 		PY_DICT_ADD_LONG(dict, attribute, number); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 		if (attribute->name) { | 
					
						
							|  |  |  | 			if (attribute->name[0] != 0) { | 
					
						
							| 
									
										
										
										
											2012-03-26 20:41:54 +00:00
										 |  |  | 				PY_DICT_ADD_STRING(dict, attribute, name); | 
					
						
							| 
									
										
										
										
											2011-12-18 08:50:06 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 				val = PyLong_FromLong(0); | 
					
						
							|  |  |  | 				PyDict_SetItemString(dict, "name", val); | 
					
						
							|  |  |  | 				Py_DECREF(val); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		PyList_SET_ITEM(seq, i, dict); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	PyDict_SetItemString(result, "attributes", seq); | 
					
						
							|  |  |  | 	Py_DECREF(seq); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	GPU_free_shader_export(shader); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-21 22:56:06 +00:00
										 |  |  | static PyMethodDef meth_export_shader[] = { | 
					
						
							|  |  |  | 	{"export_shader", (PyCFunction)GPU_export_shader, METH_VARARGS | METH_KEYWORDS, GPU_export_shader_doc} | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-20 01:03:00 -02:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Initialize Module */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-16 21:39:56 +00:00
										 |  |  | PyObject *GPU_initPython(void) | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-20 01:03:00 -02:00
										 |  |  | 	PyObject *module; | 
					
						
							|  |  |  | 	PyObject *submodule; | 
					
						
							|  |  |  | 	PyObject *sys_modules = PyThreadState_GET()->interp->modules; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	module = PyInit_gpu(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-20 01:03:00 -02:00
										 |  |  | 	/* gpu.offscreen */ | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "offscreen", (submodule = BPyInit_gpu_offscreen())); | 
					
						
							| 
									
										
										
										
											2016-07-14 15:51:56 +10:00
										 |  |  | 	PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); | 
					
						
							| 
									
										
										
										
											2015-10-20 01:03:00 -02:00
										 |  |  | 	Py_INCREF(submodule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-14 15:51:56 +10:00
										 |  |  | 	PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module); | 
					
						
							| 
									
										
										
										
											2011-09-09 11:55:38 +00:00
										 |  |  | 	return module; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |