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