Merge branch 'blender2.7'
[blender.git] / source / blender / gpu / intern / gpu_primitive.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2016 by Mike Erwin.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup gpu
22  *
23  * GPU geometric primitives
24  */
25
26 #include "GPU_primitive.h"
27 #include "gpu_primitive_private.h"
28
29 GPUPrimClass GPU_primtype_class(GPUPrimType prim_type)
30 {
31         static const GPUPrimClass classes[] = {
32                 [GPU_PRIM_POINTS] = GPU_PRIM_CLASS_POINT,
33                 [GPU_PRIM_LINES] = GPU_PRIM_CLASS_LINE,
34                 [GPU_PRIM_LINE_STRIP] = GPU_PRIM_CLASS_LINE,
35                 [GPU_PRIM_LINE_LOOP] = GPU_PRIM_CLASS_LINE,
36                 [GPU_PRIM_TRIS] = GPU_PRIM_CLASS_SURFACE,
37                 [GPU_PRIM_TRI_STRIP] = GPU_PRIM_CLASS_SURFACE,
38                 [GPU_PRIM_TRI_FAN] = GPU_PRIM_CLASS_SURFACE,
39
40                 [GPU_PRIM_LINES_ADJ] = GPU_PRIM_CLASS_LINE,
41                 [GPU_PRIM_LINE_STRIP_ADJ] = GPU_PRIM_CLASS_LINE,
42                 [GPU_PRIM_TRIS_ADJ] = GPU_PRIM_CLASS_SURFACE,
43
44                 [GPU_PRIM_NONE] = GPU_PRIM_CLASS_NONE,
45         };
46
47         return classes[prim_type];
48 }
49
50 bool GPU_primtype_belongs_to_class(GPUPrimType prim_type, GPUPrimClass prim_class)
51 {
52         if (prim_class == GPU_PRIM_CLASS_NONE && prim_type == GPU_PRIM_NONE) {
53                 return true;
54         }
55         return prim_class & GPU_primtype_class(prim_type);
56 }
57
58 GLenum convert_prim_type_to_gl(GPUPrimType prim_type)
59 {
60 #if TRUST_NO_ONE
61         assert(prim_type != GPU_PRIM_NONE);
62 #endif
63         static const GLenum table[] = {
64                 [GPU_PRIM_POINTS] = GL_POINTS,
65                 [GPU_PRIM_LINES] = GL_LINES,
66                 [GPU_PRIM_LINE_STRIP] = GL_LINE_STRIP,
67                 [GPU_PRIM_LINE_LOOP] = GL_LINE_LOOP,
68                 [GPU_PRIM_TRIS] = GL_TRIANGLES,
69                 [GPU_PRIM_TRI_STRIP] = GL_TRIANGLE_STRIP,
70                 [GPU_PRIM_TRI_FAN] = GL_TRIANGLE_FAN,
71
72                 [GPU_PRIM_LINES_ADJ] = GL_LINES_ADJACENCY,
73                 [GPU_PRIM_LINE_STRIP_ADJ] = GL_LINE_STRIP_ADJACENCY,
74                 [GPU_PRIM_TRIS_ADJ] = GL_TRIANGLES_ADJACENCY,
75         };
76
77         return table[prim_type];
78 }