| 
									
										
										
										
											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 element list (AKA index buffer) | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #ifndef __GPU_ELEMENT_H__
 | 
					
						
							|  |  |  | #define __GPU_ELEMENT_H__
 | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | #include "GPU_primitive.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 15:28:47 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #define GPU_TRACK_INDEX_RANGE 1
 | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-16 16:03:15 -05:00
										 |  |  | typedef enum { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPU_INDEX_U16, | 
					
						
							|  |  |  |   GPU_INDEX_U32, | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUIndexBufType; | 
					
						
							| 
									
										
										
										
											2016-11-16 16:03:15 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | typedef struct GPUIndexBuf { | 
					
						
							| 
									
										
										
										
											2019-07-14 16:49:44 +02:00
										 |  |  |   uint index_start; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   uint index_len; | 
					
						
							| 
									
										
										
										
											2019-07-14 16:49:44 +02:00
										 |  |  |   bool is_subrange; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #if GPU_TRACK_INDEX_RANGE
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPUIndexBufType index_type; | 
					
						
							|  |  |  |   uint32_t gl_index_type; | 
					
						
							|  |  |  |   uint base_index; | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   uint32_t ibo_id; /* 0 indicates not yet sent to VRAM */ | 
					
						
							| 
									
										
										
										
											2019-07-14 16:49:44 +02:00
										 |  |  |   union { | 
					
						
							|  |  |  |     void *data;              /* non-NULL indicates not yet sent to VRAM */ | 
					
						
							|  |  |  |     struct GPUIndexBuf *src; /* if is_subrange is true, this is the source buffer. */ | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUIndexBuf; | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_indexbuf_use(GPUIndexBuf *); | 
					
						
							|  |  |  | uint GPU_indexbuf_size_get(const GPUIndexBuf *); | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | typedef struct GPUIndexBufBuilder { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   uint max_allowed_index; | 
					
						
							|  |  |  |   uint max_index_len; | 
					
						
							|  |  |  |   uint index_len; | 
					
						
							|  |  |  |   GPUPrimType prim_type; | 
					
						
							|  |  |  |   uint *data; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUIndexBufBuilder; | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | /* supports all primitive types. */ | 
					
						
							| 
									
										
										
										
											2019-05-29 00:08:10 +02:00
										 |  |  | void GPU_indexbuf_init_ex(GPUIndexBufBuilder *, GPUPrimType, uint index_len, uint vertex_len); | 
					
						
							| 
									
										
										
										
											2018-03-14 22:06:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | /* supports only GPU_PRIM_POINTS, GPU_PRIM_LINES and GPU_PRIM_TRIS. */ | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len); | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_indexbuf_add_generic_vert(GPUIndexBufBuilder *, uint v); | 
					
						
							|  |  |  | void GPU_indexbuf_add_primitive_restart(GPUIndexBufBuilder *); | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_indexbuf_add_point_vert(GPUIndexBufBuilder *, uint v); | 
					
						
							|  |  |  | void GPU_indexbuf_add_line_verts(GPUIndexBufBuilder *, uint v1, uint v2); | 
					
						
							|  |  |  | void GPU_indexbuf_add_tri_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3); | 
					
						
							|  |  |  | void GPU_indexbuf_add_line_adj_verts(GPUIndexBufBuilder *, uint v1, uint v2, uint v3, uint v4); | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-14 16:49:44 +02:00
										 |  |  | void GPU_indexbuf_set_point_vert(GPUIndexBufBuilder *builder, uint elem, uint v1); | 
					
						
							|  |  |  | void GPU_indexbuf_set_line_verts(GPUIndexBufBuilder *builder, uint elem, uint v1, uint v2); | 
					
						
							|  |  |  | void GPU_indexbuf_set_tri_verts(GPUIndexBufBuilder *builder, uint elem, uint v1, uint v2, uint v3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Skip primitive rendering at the given index. */ | 
					
						
							|  |  |  | void GPU_indexbuf_set_point_restart(GPUIndexBufBuilder *builder, uint elem); | 
					
						
							|  |  |  | void GPU_indexbuf_set_line_restart(GPUIndexBufBuilder *builder, uint elem); | 
					
						
							|  |  |  | void GPU_indexbuf_set_tri_restart(GPUIndexBufBuilder *builder, uint elem); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | GPUIndexBuf *GPU_indexbuf_build(GPUIndexBufBuilder *); | 
					
						
							|  |  |  | void GPU_indexbuf_build_in_place(GPUIndexBufBuilder *, GPUIndexBuf *); | 
					
						
							| 
									
										
										
										
											2016-10-23 23:16:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-14 16:49:44 +02:00
										 |  |  | /* Create a subrange of an existing indexbuffer. */ | 
					
						
							|  |  |  | GPUIndexBuf *GPU_indexbuf_create_subrange(GPUIndexBuf *ibo, uint start, uint length); | 
					
						
							| 
									
										
										
										
											2019-12-03 08:27:55 +01:00
										 |  |  | void GPU_indexbuf_create_subrange_in_place(GPUIndexBuf *r_ibo, | 
					
						
							|  |  |  |                                            GPUIndexBuf *ibo, | 
					
						
							|  |  |  |                                            uint start, | 
					
						
							|  |  |  |                                            uint length); | 
					
						
							| 
									
										
										
										
											2019-07-14 16:49:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_indexbuf_discard(GPUIndexBuf *); | 
					
						
							| 
									
										
										
										
											2017-04-13 13:30:53 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 00:53:45 -03:00
										 |  |  | int GPU_indexbuf_primitive_len(GPUPrimType prim_type); | 
					
						
							| 
									
										
										
										
											2017-04-13 13:30:53 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Macros */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define GPU_INDEXBUF_DISCARD_SAFE(elem) \
 | 
					
						
							|  |  |  |   do { \ | 
					
						
							|  |  |  |     if (elem != NULL) { \ | 
					
						
							|  |  |  |       GPU_indexbuf_discard(elem); \ | 
					
						
							|  |  |  |       elem = NULL; \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							| 
									
										
										
										
											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_ELEMENT_H__ */
 |