| 
									
										
										
										
											2016-09-22 12:11:40 +02: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 | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2012 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: all of this file. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  |  * Contributor(s): Alexandr Kuznetsov, Jason Wilkins, Mike Erwin | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** \file source/blender/gpu/GPU_matrix.h
 | 
					
						
							|  |  |  |  *  \ingroup gpu | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-15 17:51:08 +10:00
										 |  |  | #ifndef __GPU_MATRIX_H__
 | 
					
						
							|  |  |  | #define __GPU_MATRIX_H__
 | 
					
						
							| 
									
										
										
										
											2017-02-25 21:58:23 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_sys_types.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-21 01:39:03 +10:00
										 |  |  | struct Gwn_ShaderInterface; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-15 01:29:25 -04:00
										 |  |  | void gpuMatrixReset(void); /* to Identity transform & empty stack */ | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | /* ModelView Matrix (2D or 3D) */ | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | void gpuPushMatrix(void); /* TODO: PushCopy vs PushIdentity? */ | 
					
						
							|  |  |  | void gpuPopMatrix(void); | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | void gpuLoadIdentity(void); | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | void gpuScaleUniform(float factor); | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | /* 3D ModelView Matrix */ | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-15 01:29:25 -04:00
										 |  |  | void gpuLoadMatrix(const float m[4][4]); | 
					
						
							|  |  |  | void gpuMultMatrix(const float m[4][4]); | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | void gpuTranslate3f(float x, float y, float z); | 
					
						
							|  |  |  | void gpuTranslate3fv(const float vec[3]); | 
					
						
							|  |  |  | void gpuScale3f(float x, float y, float z); | 
					
						
							|  |  |  | void gpuScale3fv(const float vec[3]); | 
					
						
							| 
									
										
										
										
											2017-02-12 19:23:08 +01:00
										 |  |  | void gpuRotate3f(float deg, float x, float y, float z); /* axis of rotation should be a unit vector */ | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | void gpuRotate3fv(float deg, const float axis[3]); /* axis of rotation should be a unit vector */ | 
					
						
							|  |  |  | void gpuRotateAxis(float deg, char axis); /* TODO: enum for axis? */ | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | void gpuLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ); | 
					
						
							|  |  |  | /* TODO: variant that takes eye[3], center[3], up[3] */ | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | /* 2D ModelView Matrix */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gpuTranslate2f(float x, float y); | 
					
						
							|  |  |  | void gpuTranslate2fv(const float vec[2]); | 
					
						
							|  |  |  | void gpuScale2f(float x, float y); | 
					
						
							|  |  |  | void gpuScale2fv(const float vec[2]); | 
					
						
							|  |  |  | void gpuRotate2D(float deg); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-19 10:13:10 +02:00
										 |  |  | /* Projection Matrix (2D or 3D) */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gpuPushProjectionMatrix(void); | 
					
						
							|  |  |  | void gpuPopProjectionMatrix(void); | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* 3D Projection Matrix */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-19 10:46:05 +02:00
										 |  |  | void gpuLoadIdentityProjectionMatrix(void); | 
					
						
							| 
									
										
										
										
											2017-04-15 01:29:25 -04:00
										 |  |  | void gpuLoadProjectionMatrix(const float m[4][4]); | 
					
						
							| 
									
										
										
										
											2017-03-21 18:10:20 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | void gpuOrtho(float left, float right, float bottom, float top, float near, float far); | 
					
						
							|  |  |  | void gpuFrustum(float left, float right, float bottom, float top, float near, float far); | 
					
						
							|  |  |  | void gpuPerspective(float fovy, float aspect, float near, float far); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-25 21:58:23 +01:00
										 |  |  | /* 3D Projection between Window and World Space */ | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-25 21:58:23 +01:00
										 |  |  | void gpuProject(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float win[3]); | 
					
						
							|  |  |  | bool gpuUnProject(const float win[3], const float model[4][4], const float proj[4][4], const int view[4], float world[3]); | 
					
						
							| 
									
										
										
										
											2016-09-25 19:29:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* 2D Projection Matrix */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void gpuOrtho2D(float left, float right, float bottom, float top); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-09 23:03:35 -04:00
										 |  |  | /* functions to get matrix values */ | 
					
						
							| 
									
										
										
										
											2017-04-15 17:43:48 +10:00
										 |  |  | const float (*gpuGetModelViewMatrix(float m[4][4]))[4]; | 
					
						
							|  |  |  | const float (*gpuGetProjectionMatrix(float m[4][4]))[4]; | 
					
						
							|  |  |  | const float (*gpuGetModelViewProjectionMatrix(float m[4][4]))[4]; | 
					
						
							| 
									
										
										
										
											2016-10-09 23:03:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-15 17:43:48 +10:00
										 |  |  | const float (*gpuGetNormalMatrix(float m[3][3]))[3]; | 
					
						
							|  |  |  | const float (*gpuGetNormalMatrixInverse(float m[3][3]))[3]; | 
					
						
							| 
									
										
										
										
											2016-10-23 23:37:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-11 21:13:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-09 23:03:35 -04:00
										 |  |  | /* set uniform values for currently bound shader */ | 
					
						
							| 
									
										
										
										
											2017-08-21 01:39:03 +10:00
										 |  |  | void gpuBindMatrices(const struct Gwn_ShaderInterface *); | 
					
						
							| 
									
										
										
										
											2016-10-20 14:17:54 -04:00
										 |  |  | bool gpuMatricesDirty(void); /* since last bind */ | 
					
						
							| 
									
										
										
										
											2016-10-09 23:03:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:23:49 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Python API needs to be able to inspect the stack so errors raise exceptions instead of crashing. */ | 
					
						
							|  |  |  | #ifdef USE_GPU_PY_MATRIX_API
 | 
					
						
							|  |  |  | int GPU_matrix_stack_level_get_model_view(void); | 
					
						
							|  |  |  | int GPU_matrix_stack_level_get_projection(void); | 
					
						
							|  |  |  | /* static assert ensures this doesn't change! */ | 
					
						
							|  |  |  | #define GPU_PY_MATRIX_STACK_LEN 31
 | 
					
						
							|  |  |  | #endif  /* USE_GPU_PY_MATRIX_API */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-22 12:11:40 +02:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-21 17:27:17 -04:00
										 |  |  | #ifndef SUPPRESS_GENERIC_MATRIX_API
 | 
					
						
							| 
									
										
										
										
											2017-04-15 17:43:48 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
 | 
					
						
							|  |  |  | #define _GPU_MAT3_CONST_CAST(x) (_Generic((x), \
 | 
					
						
							|  |  |  | 	void *:       (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	float *:      (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	float [9]:    (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	float (*)[4]: (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	float [4][4]: (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	const void *:       (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	const float *:      (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	const float [9]:    (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	const float (*)[3]: (const float (*)[3])(x), \ | 
					
						
							|  |  |  | 	const float [3][3]: (const float (*)[3])(x)) \ | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | #define _GPU_MAT3_CAST(x) (_Generic((x), \
 | 
					
						
							|  |  |  | 	void *:       (float (*)[3])(x), \ | 
					
						
							|  |  |  | 	float *:      (float (*)[3])(x), \ | 
					
						
							|  |  |  | 	float [9]:    (float (*)[3])(x), \ | 
					
						
							|  |  |  | 	float (*)[3]: (float (*)[3])(x), \ | 
					
						
							|  |  |  | 	float [3][3]: (float (*)[3])(x)) \ | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | #define _GPU_MAT4_CONST_CAST(x) (_Generic((x), \
 | 
					
						
							|  |  |  | 	void *:       (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	float *:      (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	float [16]:   (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	float (*)[4]: (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	float [4][4]: (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	const void *:       (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	const float *:      (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	const float [16]:   (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	const float (*)[4]: (const float (*)[4])(x), \ | 
					
						
							|  |  |  | 	const float [4][4]: (const float (*)[4])(x)) \ | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | #define _GPU_MAT4_CAST(x) (_Generic((x), \
 | 
					
						
							|  |  |  | 	void *:       (float (*)[4])(x), \ | 
					
						
							|  |  |  | 	float *:      (float (*)[4])(x), \ | 
					
						
							|  |  |  | 	float [16]:   (float (*)[4])(x), \ | 
					
						
							|  |  |  | 	float (*)[4]: (float (*)[4])(x), \ | 
					
						
							|  |  |  | 	float [4][4]: (float (*)[4])(x)) \ | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #  define _GPU_MAT3_CONST_CAST(x) (const float (*)[3])(x)
 | 
					
						
							|  |  |  | #  define _GPU_MAT3_CAST(x)             (float (*)[3])(x)
 | 
					
						
							|  |  |  | #  define _GPU_MAT4_CONST_CAST(x) (const float (*)[4])(x)
 | 
					
						
							|  |  |  | #  define _GPU_MAT4_CAST(x)             (float (*)[4])(x)
 | 
					
						
							|  |  |  | #endif  /* C11 */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-21 17:27:17 -04:00
										 |  |  | /* make matrix inputs generic, to avoid warnings */ | 
					
						
							| 
									
										
										
										
											2017-04-15 17:43:48 +10:00
										 |  |  | #  define gpuMultMatrix(x)  gpuMultMatrix(_GPU_MAT4_CONST_CAST(x))
 | 
					
						
							|  |  |  | #  define gpuLoadMatrix(x)  gpuLoadMatrix(_GPU_MAT4_CONST_CAST(x))
 | 
					
						
							|  |  |  | #  define gpuLoadProjectionMatrix(x)  gpuLoadProjectionMatrix(_GPU_MAT4_CONST_CAST(x))
 | 
					
						
							|  |  |  | #  define gpuGetModelViewMatrix(x)  gpuGetModelViewMatrix(_GPU_MAT4_CAST(x))
 | 
					
						
							|  |  |  | #  define gpuGetProjectionMatrix(x)  gpuGetProjectionMatrix(_GPU_MAT4_CAST(x))
 | 
					
						
							|  |  |  | #  define gpuGetModelViewProjectionMatrix(x)  gpuGetModelViewProjectionMatrix(_GPU_MAT4_CAST(x))
 | 
					
						
							|  |  |  | #  define gpuGetNormalMatrix(x)  gpuGetNormalMatrix(_GPU_MAT3_CAST(x))
 | 
					
						
							|  |  |  | #  define gpuGetNormalMatrixInverse(x)  gpuGetNormalMatrixInverse(_GPU_MAT3_CAST(x))
 | 
					
						
							| 
									
										
										
										
											2017-03-21 17:27:17 -04:00
										 |  |  | #endif /* SUPPRESS_GENERIC_MATRIX_API */
 | 
					
						
							| 
									
										
										
										
											2017-04-15 17:51:08 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif /* __GPU_MATRIX_H__ */
 |