| 
									
										
										
										
											2018-07-17 14:46:44 +02: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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2016 by Mike Erwin. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  |  * GPU shader interface (C --> GLSL) | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #ifndef __GPU_SHADER_INTERFACE_H__
 | 
					
						
							|  |  |  | #define __GPU_SHADER_INTERFACE_H__
 | 
					
						
							| 
									
										
										
										
											2017-03-02 21:27:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | #include "GPU_common.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-02 21:27:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 15:28:47 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-02 21:27:51 -05:00
										 |  |  | typedef enum { | 
					
						
							| 
									
										
										
										
											2020-06-04 13:43:28 +02:00
										 |  |  |   GPU_UNIFORM_MODEL = 0,      /* mat4 ModelMatrix */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPU_UNIFORM_VIEW,           /* mat4 ViewMatrix */ | 
					
						
							|  |  |  |   GPU_UNIFORM_MODELVIEW,      /* mat4 ModelViewMatrix */ | 
					
						
							|  |  |  |   GPU_UNIFORM_PROJECTION,     /* mat4 ProjectionMatrix */ | 
					
						
							|  |  |  |   GPU_UNIFORM_VIEWPROJECTION, /* mat4 ViewProjectionMatrix */ | 
					
						
							|  |  |  |   GPU_UNIFORM_MVP,            /* mat4 ModelViewProjectionMatrix */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_UNIFORM_MODEL_INV,          /* mat4 ModelMatrixInverse */ | 
					
						
							|  |  |  |   GPU_UNIFORM_VIEW_INV,           /* mat4 ViewMatrixInverse */ | 
					
						
							|  |  |  |   GPU_UNIFORM_MODELVIEW_INV,      /* mat4 ModelViewMatrixInverse */ | 
					
						
							|  |  |  |   GPU_UNIFORM_PROJECTION_INV,     /* mat4 ProjectionMatrixInverse */ | 
					
						
							|  |  |  |   GPU_UNIFORM_VIEWPROJECTION_INV, /* mat4 ViewProjectionMatrixInverse */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-26 20:36:24 +02:00
										 |  |  |   GPU_UNIFORM_NORMAL,     /* mat3 NormalMatrix */ | 
					
						
							| 
									
										
										
										
											2019-05-31 01:45:41 +02:00
										 |  |  |   GPU_UNIFORM_ORCO,       /* vec4 OrcoTexCoFactors[] */ | 
					
						
							| 
									
										
										
										
											2019-05-26 20:36:24 +02:00
										 |  |  |   GPU_UNIFORM_CLIPPLANES, /* vec4 WorldClipPlanes[] */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 01:45:41 +02:00
										 |  |  |   GPU_UNIFORM_COLOR,          /* vec4 color */ | 
					
						
							|  |  |  |   GPU_UNIFORM_BASE_INSTANCE,  /* int baseInstance */ | 
					
						
							|  |  |  |   GPU_UNIFORM_RESOURCE_CHUNK, /* int resourceChunk */ | 
					
						
							| 
									
										
										
										
											2020-03-09 16:27:24 +01:00
										 |  |  |   GPU_UNIFORM_RESOURCE_ID,    /* int resourceId */ | 
					
						
							| 
									
										
										
										
											2020-04-14 20:44:45 +02:00
										 |  |  |   GPU_UNIFORM_SRGB_TRANSFORM, /* bool srgbTarget */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   GPU_NUM_UNIFORMS, /* Special value, denotes number of builtin uniforms. */ | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUUniformBuiltin; | 
					
						
							| 
									
										
										
										
											2017-03-02 21:27:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 13:43:28 +02:00
										 |  |  | typedef enum { | 
					
						
							|  |  |  |   GPU_UNIFORM_BLOCK_VIEW = 0, /* viewBlock */ | 
					
						
							|  |  |  |   GPU_UNIFORM_BLOCK_MODEL,    /* modelBlock */ | 
					
						
							|  |  |  |   GPU_UNIFORM_BLOCK_INFO,     /* infoBlock */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   GPU_NUM_UNIFORM_BLOCKS, /* Special value, denotes number of builtin uniforms block. */ | 
					
						
							|  |  |  | } GPUUniformBlockBuiltin; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | typedef struct GPUShaderInput { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   uint32_t name_offset; | 
					
						
							| 
									
										
										
										
											2020-06-02 12:11:39 +02:00
										 |  |  |   uint32_t name_hash; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   int32_t location; | 
					
						
							| 
									
										
										
										
											2020-06-02 12:11:39 +02:00
										 |  |  |   /** Defined at interface creation or in shader. Only for Samplers, UBOs and Vertex Attribs. */ | 
					
						
							|  |  |  |   int32_t binding; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUShaderInput; | 
					
						
							| 
									
										
										
										
											2017-03-02 21:27:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #define GPU_SHADERINTERFACE_REF_ALLOC_COUNT 16
 | 
					
						
							| 
									
										
										
										
											2017-10-04 17:36:52 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | typedef struct GPUShaderInterface { | 
					
						
							| 
									
										
										
										
											2020-06-02 12:11:39 +02:00
										 |  |  |   /** Buffer containing all inputs names separated by '\0'. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   char *name_buffer; | 
					
						
							| 
									
										
										
										
											2020-06-02 12:11:39 +02:00
										 |  |  |   /** Reference to GPUBatches using this interface */ | 
					
						
							|  |  |  |   struct GPUBatch **batches; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   uint batches_len; | 
					
						
							| 
									
										
										
										
											2020-06-02 12:11:39 +02:00
										 |  |  |   /** Input counts. */ | 
					
						
							|  |  |  |   uint attribute_len; | 
					
						
							|  |  |  |   uint ubo_len; | 
					
						
							|  |  |  |   uint uniform_len; | 
					
						
							|  |  |  |   /** Enabled bindpoints that needs to be fed with data. */ | 
					
						
							| 
									
										
										
										
											2020-04-03 16:59:34 +11:00
										 |  |  |   uint16_t enabled_attr_mask; | 
					
						
							| 
									
										
										
										
											2020-06-02 12:11:39 +02:00
										 |  |  |   uint16_t enabled_ubo_mask; | 
					
						
							|  |  |  |   uint64_t enabled_tex_mask; | 
					
						
							|  |  |  |   /** Opengl Location of builtin uniforms. Fast access, no lookup needed. */ | 
					
						
							|  |  |  |   /* TODO replace by location only array. */ | 
					
						
							|  |  |  |   GPUShaderInput builtins[GPU_NUM_UNIFORMS]; | 
					
						
							| 
									
										
										
										
											2020-06-04 13:43:28 +02:00
										 |  |  |   GPUShaderInput builtin_blocks[GPU_NUM_UNIFORM_BLOCKS]; | 
					
						
							| 
									
										
										
										
											2020-06-02 12:11:39 +02:00
										 |  |  |   /** Flat array. In this order: Attributes, Ubos, Uniforms. */ | 
					
						
							|  |  |  |   GPUShaderInput inputs[0]; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUShaderInterface; | 
					
						
							| 
									
										
										
										
											2017-03-02 21:27:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | GPUShaderInterface *GPU_shaderinterface_create(int32_t program_id); | 
					
						
							|  |  |  | void GPU_shaderinterface_discard(GPUShaderInterface *); | 
					
						
							| 
									
										
										
										
											2017-04-12 17:56:26 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | const GPUShaderInput *GPU_shaderinterface_uniform(const GPUShaderInterface *, const char *name); | 
					
						
							| 
									
										
										
										
											2020-06-04 13:43:28 +02:00
										 |  |  | const GPUShaderInput *GPU_shaderinterface_uniform_builtin(const GPUShaderInterface *shaderface, | 
					
						
							|  |  |  |                                                           GPUUniformBuiltin builtin); | 
					
						
							|  |  |  | const GPUShaderInput *GPU_shaderinterface_block_builtin(const GPUShaderInterface *shaderface, | 
					
						
							|  |  |  |                                                         GPUUniformBlockBuiltin builtin); | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | const GPUShaderInput *GPU_shaderinterface_ubo(const GPUShaderInterface *, const char *name); | 
					
						
							|  |  |  | const GPUShaderInput *GPU_shaderinterface_attr(const GPUShaderInterface *, const char *name); | 
					
						
							| 
									
										
										
										
											2018-02-20 01:55:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | /* keep track of batches using this interface */ | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_shaderinterface_add_batch_ref(GPUShaderInterface *, struct GPUBatch *); | 
					
						
							|  |  |  | void GPU_shaderinterface_remove_batch_ref(GPUShaderInterface *, struct GPUBatch *); | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 15:28:47 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #endif /* __GPU_SHADER_INTERFACE_H__ */
 |