| 
									
										
										
										
											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. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-02 15:07:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 geometric primitives | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-03-02 15:07:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | #include "GPU_primitive.h"
 | 
					
						
							|  |  |  | #include "gpu_primitive_private.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-02 15:07:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | GPUPrimClass GPU_primtype_class(GPUPrimType prim_type) | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	static const GPUPrimClass classes[] = { | 
					
						
							|  |  |  | 		[GPU_PRIM_POINTS] = GPU_PRIM_CLASS_POINT, | 
					
						
							|  |  |  | 		[GPU_PRIM_LINES] = GPU_PRIM_CLASS_LINE, | 
					
						
							|  |  |  | 		[GPU_PRIM_LINE_STRIP] = GPU_PRIM_CLASS_LINE, | 
					
						
							|  |  |  | 		[GPU_PRIM_LINE_LOOP] = GPU_PRIM_CLASS_LINE, | 
					
						
							|  |  |  | 		[GPU_PRIM_TRIS] = GPU_PRIM_CLASS_SURFACE, | 
					
						
							|  |  |  | 		[GPU_PRIM_TRI_STRIP] = GPU_PRIM_CLASS_SURFACE, | 
					
						
							|  |  |  | 		[GPU_PRIM_TRI_FAN] = GPU_PRIM_CLASS_SURFACE, | 
					
						
							| 
									
										
										
										
											2017-03-02 15:07:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 		[GPU_PRIM_LINES_ADJ] = GPU_PRIM_CLASS_LINE, | 
					
						
							|  |  |  | 		[GPU_PRIM_LINE_STRIP_ADJ] = GPU_PRIM_CLASS_LINE, | 
					
						
							|  |  |  | 		[GPU_PRIM_TRIS_ADJ] = GPU_PRIM_CLASS_SURFACE, | 
					
						
							| 
									
										
										
										
											2017-04-08 01:19:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-03 14:01:45 +11:00
										 |  |  | 		[GPU_PRIM_NONE] = GPU_PRIM_CLASS_NONE, | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-03-02 15:07:14 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return classes[prim_type]; | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-02 15:07:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | bool GPU_primtype_belongs_to_class(GPUPrimType prim_type, GPUPrimClass prim_class) | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	if (prim_class == GPU_PRIM_CLASS_NONE && prim_type == GPU_PRIM_NONE) { | 
					
						
							| 
									
										
										
										
											2017-03-02 15:07:14 -05:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	return prim_class & GPU_primtype_class(prim_type); | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-08 01:19:25 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | GLenum convert_prim_type_to_gl(GPUPrimType prim_type) | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-08 01:19:25 -04:00
										 |  |  | #if TRUST_NO_ONE
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 	assert(prim_type != GPU_PRIM_NONE); | 
					
						
							| 
									
										
										
										
											2017-04-08 01:19:25 -04:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | 	static const GLenum table[] = { | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 		[GPU_PRIM_POINTS] = GL_POINTS, | 
					
						
							|  |  |  | 		[GPU_PRIM_LINES] = GL_LINES, | 
					
						
							|  |  |  | 		[GPU_PRIM_LINE_STRIP] = GL_LINE_STRIP, | 
					
						
							|  |  |  | 		[GPU_PRIM_LINE_LOOP] = GL_LINE_LOOP, | 
					
						
							|  |  |  | 		[GPU_PRIM_TRIS] = GL_TRIANGLES, | 
					
						
							|  |  |  | 		[GPU_PRIM_TRI_STRIP] = GL_TRIANGLE_STRIP, | 
					
						
							|  |  |  | 		[GPU_PRIM_TRI_FAN] = GL_TRIANGLE_FAN, | 
					
						
							| 
									
										
										
										
											2017-06-19 20:18:04 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | 		[GPU_PRIM_LINES_ADJ] = GL_LINES_ADJACENCY, | 
					
						
							|  |  |  | 		[GPU_PRIM_LINE_STRIP_ADJ] = GL_LINE_STRIP_ADJACENCY, | 
					
						
							|  |  |  | 		[GPU_PRIM_TRIS_ADJ] = GL_TRIANGLES_ADJACENCY, | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-04-08 01:19:25 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return table[prim_type]; | 
					
						
							| 
									
										
										
										
											2018-07-17 14:46:44 +02:00
										 |  |  | } |