| 
									
										
										
										
											2018-07-17 14:46:44 +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) 2016 by Mike Erwin. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Blender Foundation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | /** \file blender/gpu/GPU_vertex_format.h
 | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  |  *  \ingroup gpu | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  |  * GPU vertex format | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #ifndef __GPU_VERTEX_FORMAT_H__
 | 
					
						
							|  |  |  | #define __GPU_VERTEX_FORMAT_H__
 | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | #include "GPU_common.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #define GPU_VERT_ATTR_MAX_LEN 16
 | 
					
						
							|  |  |  | #define GPU_VERT_ATTR_MAX_NAMES 3
 | 
					
						
							|  |  |  | #define GPU_VERT_ATTR_NAME_AVERAGE_LEN 11
 | 
					
						
							|  |  |  | #define GPU_VERT_ATTR_NAMES_BUF_LEN ((GPU_VERT_ATTR_NAME_AVERAGE_LEN + 1) * GPU_VERT_ATTR_MAX_LEN)
 | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-11 19:39:56 -06:00
										 |  |  | typedef enum { | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	GPU_COMP_I8, | 
					
						
							|  |  |  | 	GPU_COMP_U8, | 
					
						
							|  |  |  | 	GPU_COMP_I16, | 
					
						
							|  |  |  | 	GPU_COMP_U16, | 
					
						
							|  |  |  | 	GPU_COMP_I32, | 
					
						
							|  |  |  | 	GPU_COMP_U32, | 
					
						
							| 
									
										
										
										
											2016-11-11 19:39:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	GPU_COMP_F32, | 
					
						
							| 
									
										
										
										
											2016-11-11 19:39:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	GPU_COMP_I10 | 
					
						
							|  |  |  | } GPUVertCompType; | 
					
						
							| 
									
										
										
										
											2016-11-11 19:39:56 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | typedef enum { | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	GPU_FETCH_FLOAT, | 
					
						
							|  |  |  | 	GPU_FETCH_INT, | 
					
						
							|  |  |  | 	GPU_FETCH_INT_TO_FLOAT_UNIT, /* 127 (ubyte) -> 0.5 (and so on for other int types) */ | 
					
						
							|  |  |  | 	GPU_FETCH_INT_TO_FLOAT /* 127 (any int type) -> 127.0 */ | 
					
						
							|  |  |  | } GPUVertFetchMode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct GPUVertAttr { | 
					
						
							|  |  |  | 	GPUVertFetchMode fetch_mode; | 
					
						
							|  |  |  | 	GPUVertCompType comp_type; | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | 	uint gl_comp_type; | 
					
						
							|  |  |  | 	uint comp_len; /* 1 to 4 or 8 or 12 or 16 */ | 
					
						
							|  |  |  | 	uint sz; /* size in bytes, 1 to 64 */ | 
					
						
							|  |  |  | 	uint offset; /* from beginning of vertex, in bytes */ | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	uint name_len; /* up to GPU_VERT_ATTR_MAX_NAMES */ | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | 	const char *name[GPU_VERT_ATTR_MAX_NAMES]; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUVertAttr; | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | typedef struct GPUVertFormat { | 
					
						
							|  |  |  | 	uint attr_len; /* 0 to 16 (GPU_VERT_ATTR_MAX_LEN) */ | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | 	uint name_len; /* total count of active vertex attrib */ | 
					
						
							|  |  |  | 	uint stride; /* stride in bytes, 1 to 256 */ | 
					
						
							|  |  |  | 	uint name_offset; | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 	bool packed; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	char names[GPU_VERT_ATTR_NAMES_BUF_LEN]; | 
					
						
							|  |  |  | 	GPUVertAttr attribs[GPU_VERT_ATTR_MAX_LEN]; /* TODO: variable-size attribs array */ | 
					
						
							|  |  |  | } GPUVertFormat; | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 11:17:29 +02:00
										 |  |  | struct GPUShaderInterface; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_vertformat_clear(GPUVertFormat *); | 
					
						
							|  |  |  | void GPU_vertformat_copy(GPUVertFormat *dest, const GPUVertFormat *src); | 
					
						
							| 
									
										
										
										
											2018-10-09 11:17:29 +02:00
										 |  |  | void GPU_vertformat_from_interface(GPUVertFormat *format, const struct GPUShaderInterface *shaderface); | 
					
						
							| 
									
										
										
										
											2016-09-15 21:45:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | uint GPU_vertformat_attr_add( | 
					
						
							|  |  |  |         GPUVertFormat *, const char *name, | 
					
						
							|  |  |  |         GPUVertCompType, uint comp_len, GPUVertFetchMode); | 
					
						
							|  |  |  | void GPU_vertformat_alias_add(GPUVertFormat *, const char *alias); | 
					
						
							| 
									
										
										
										
											2018-10-05 15:10:56 +02:00
										 |  |  | int GPU_vertformat_attr_id_get(const GPUVertFormat *, const char *name); | 
					
						
							| 
									
										
										
										
											2016-09-13 02:18:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 00:58:17 +01:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * This makes the "virtual" attribs with suffixes "0", "1", "2" to access triangle data in the vertex | 
					
						
							|  |  |  |  * shader. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * IMPORTANT: | 
					
						
							|  |  |  |  * - Call this before creating the vertex buffer and after creating all attributes | 
					
						
							|  |  |  |  * - Only first vertex out of 3 has the correct information. Use flat output with GL_FIRST_VERTEX_CONVENTION. | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | void GPU_vertformat_triple_load(GPUVertFormat *format); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | /* format conversion */ | 
					
						
							| 
									
										
										
										
											2016-11-13 20:18:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | typedef struct GPUPackedNormal { | 
					
						
							| 
									
										
										
										
											2016-11-13 20:18:51 -06:00
										 |  |  | 	int x : 10; | 
					
						
							|  |  |  | 	int y : 10; | 
					
						
							|  |  |  | 	int z : 10; | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | 	int w : 2;  /* 0 by default, can manually set to { -2, -1, 0, 1 } */ | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUPackedNormal; | 
					
						
							| 
									
										
										
										
											2016-11-13 20:18:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | GPUPackedNormal GPU_normal_convert_i10_v3(const float data[3]); | 
					
						
							|  |  |  | GPUPackedNormal GPU_normal_convert_i10_s3(const short data[3]); | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #endif /* __GPU_VERTEX_FORMAT_H__ */
 |