| 
									
										
										
										
											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
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2020-09-05 20:15:56 +02:00
										 |  |  |  * GPU index buffer | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 03:34:47 +02:00
										 |  |  | /** Opaque type hiding blender::gpu::IndexBuf. */ | 
					
						
							| 
									
										
										
										
											2020-09-06 02:46:51 +02:00
										 |  |  | typedef struct GPUIndexBuf GPUIndexBuf; | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 01:40:23 +02:00
										 |  |  | GPUIndexBuf *GPU_indexbuf_calloc(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | typedef struct GPUIndexBufBuilder { | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  |   uint max_allowed_index; | 
					
						
							|  |  |  |   uint max_index_len; | 
					
						
							|  |  |  |   uint index_len; | 
					
						
							| 
									
										
										
										
											2021-06-07 08:38:38 -03:00
										 |  |  |   uint index_min; | 
					
						
							|  |  |  |   uint index_max; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  |   GPUPrimType prim_type; | 
					
						
							| 
									
										
										
										
											2020-09-06 02:46:51 +02:00
										 |  |  |   uint32_t *data; | 
					
						
							| 
									
										
										
										
											2021-06-08 16:35:33 +02:00
										 |  |  |   const struct GPUIndexBufBuilder *parent; | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											2021-05-26 16:49:17 +02:00
										 |  |  | GPUIndexBuf *GPU_indexbuf_build_on_device(uint index_len); | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-08 16:35:33 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Thread safe sub builders. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note that `GPU_indexbuf_subbuilder_init` and `GPU_indexbuf_subbuilder_finish` are not thread | 
					
						
							|  |  |  |  * safe and should be called when no threads are active. The pattern is to create a subbuilder for | 
					
						
							|  |  |  |  * each thread/task. Each thread/task would update their sub builder. When all thread are completed | 
					
						
							|  |  |  |  * the sub-builders can then be merged back to the parent builder. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void GPU_indexbuf_subbuilder_init(const GPUIndexBufBuilder *parent_builder, | 
					
						
							|  |  |  |                                   GPUIndexBufBuilder *sub_builder); | 
					
						
							|  |  |  | void GPU_indexbuf_subbuilder_finish(GPUIndexBufBuilder *builder, | 
					
						
							|  |  |  |                                     const GPUIndexBufBuilder *parent_builder); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-26 16:49:17 +02:00
										 |  |  | void GPU_indexbuf_bind_as_ssbo(GPUIndexBuf *elem, int binding); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  | /* Create a sub-range of an existing index-buffer. */ | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  | GPUIndexBuf *GPU_indexbuf_create_subrange(GPUIndexBuf *elem_src, uint start, uint length); | 
					
						
							|  |  |  | void GPU_indexbuf_create_subrange_in_place(GPUIndexBuf *elem, | 
					
						
							|  |  |  |                                            GPUIndexBuf *elem_src, | 
					
						
							| 
									
										
										
										
											2019-12-03 08:27:55 +01:00
										 |  |  |                                            uint start, | 
					
						
							|  |  |  |                                            uint length); | 
					
						
							| 
									
										
										
										
											2019-07-14 16:49:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-26 16:49:17 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * (Download and) return a pointer containing the data of an index buffer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Note that the returned pointer is still owned by the driver. To get an | 
					
						
							|  |  |  |  * local copy, use `GPU_indexbuf_unmap` after calling `GPU_indexbuf_read`. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const uint32_t *GPU_indexbuf_read(GPUIndexBuf *elem); | 
					
						
							| 
									
										
										
										
											2021-05-27 10:46:43 +02:00
										 |  |  | uint32_t *GPU_indexbuf_unmap(const GPUIndexBuf *elem, const uint32_t *mapped_buffer); | 
					
						
							| 
									
										
										
										
											2021-05-26 16:49:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 13:59:22 +02:00
										 |  |  | void GPU_indexbuf_discard(GPUIndexBuf *elem); | 
					
						
							| 
									
										
										
										
											2017-04-13 13:30:53 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-07 13:59:22 +02:00
										 |  |  | bool GPU_indexbuf_is_init(GPUIndexBuf *elem); | 
					
						
							| 
									
										
										
										
											2020-09-06 02:46:51 +02: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 */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | #define GPU_INDEXBUF_DISCARD_SAFE(elem) \
 | 
					
						
							|  |  |  |   do { \ | 
					
						
							| 
									
										
										
										
											2017-04-13 13:30:53 +10:00
										 |  |  |     if (elem != NULL) { \ | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  |       GPU_indexbuf_discard(elem); \ | 
					
						
							| 
									
										
										
										
											2017-04-13 13:30:53 +10:00
										 |  |  |       elem = NULL; \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 15:28:47 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |