Gawain: remove GL enum from primitive API
[blender.git] / intern / gawain / src / primitive.c
1
2 // Gawain geometric primitives
3 //
4 // This code is part of the Gawain library, with modifications
5 // specific to integration with Blender.
6 //
7 // Copyright 2017 Mike Erwin
8 //
9 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
10 // the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
11
12 #include "primitive.h"
13
14 PrimitiveClass prim_class_of_type(PrimitiveType prim_type)
15         {
16         static const PrimitiveClass classes[] =
17                 {
18                 [PRIM_POINTS] = PRIM_CLASS_POINT,
19                 [PRIM_LINES] = PRIM_CLASS_LINE,
20                 [PRIM_LINE_STRIP] = PRIM_CLASS_LINE,
21                 [PRIM_LINE_LOOP] = PRIM_CLASS_LINE,
22                 [PRIM_TRIANGLES] = PRIM_CLASS_SURFACE,
23                 [PRIM_TRIANGLE_STRIP] = PRIM_CLASS_SURFACE,
24                 [PRIM_TRIANGLE_FAN] = PRIM_CLASS_SURFACE,
25
26                 [PRIM_LINE_STRIP_ADJACENCY] = PRIM_CLASS_LINE,
27
28 #ifdef WITH_GL_PROFILE_COMPAT
29                 [PRIM_QUADS_XXX] = PRIM_CLASS_SURFACE,
30 #endif
31
32                 [PRIM_NONE] = PRIM_CLASS_NONE
33                 };
34
35         return classes[prim_type];
36         }
37
38 bool prim_type_belongs_to_class(PrimitiveType prim_type, PrimitiveClass prim_class)
39         {
40         if (prim_class == PRIM_CLASS_NONE && prim_type == PRIM_NONE)
41                 return true;
42
43         return prim_class & prim_class_of_type(prim_type);
44         }
45
46 GLenum convert_prim_type_to_gl(PrimitiveType prim_type)
47         {
48 #if TRUST_NO_ONE
49         assert(prim_type != PRIM_NONE);
50 #endif
51
52         static const GLenum table[] =
53                 {
54                 [PRIM_POINTS] = GL_POINTS,
55                 [PRIM_LINES] = GL_LINES,
56                 [PRIM_LINE_STRIP] = GL_LINE_STRIP,
57                 [PRIM_LINE_LOOP] = GL_LINE_LOOP,
58                 [PRIM_TRIANGLES] = PRIM_CLASS_SURFACE,
59                 [PRIM_TRIANGLE_STRIP] = GL_TRIANGLE_STRIP,
60                 [PRIM_TRIANGLE_FAN] = GL_TRIANGLE_FAN,
61
62                 [PRIM_LINE_STRIP_ADJACENCY] = GL_LINE_STRIP_ADJACENCY,
63
64 #ifdef WITH_GL_PROFILE_COMPAT
65                 [PRIM_QUADS_XXX] = GL_QUADS,
66 #endif
67                 };
68
69         return table[prim_type];
70         }