diff options
Diffstat (limited to 'intern/gawain/src/primitive.c')
-rw-r--r-- | intern/gawain/src/primitive.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/intern/gawain/src/primitive.c b/intern/gawain/src/primitive.c new file mode 100644 index 00000000000..da32932c1e5 --- /dev/null +++ b/intern/gawain/src/primitive.c @@ -0,0 +1,63 @@ + +// Gawain geometric primitives +// +// This code is part of the Gawain library, with modifications +// specific to integration with Blender. +// +// Copyright 2017 Mike Erwin +// +// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of +// the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +#include "primitive.h" +#include "primitive_private.h" + +PrimitiveClass prim_class_of_type(PrimitiveType prim_type) + { + static const PrimitiveClass classes[] = + { + [PRIM_POINTS] = PRIM_CLASS_POINT, + [PRIM_LINES] = PRIM_CLASS_LINE, + [PRIM_LINE_STRIP] = PRIM_CLASS_LINE, + [PRIM_LINE_LOOP] = PRIM_CLASS_LINE, + [PRIM_TRIANGLES] = PRIM_CLASS_SURFACE, + [PRIM_TRIANGLE_STRIP] = PRIM_CLASS_SURFACE, + [PRIM_TRIANGLE_FAN] = PRIM_CLASS_SURFACE, + + [PRIM_LINE_STRIP_ADJACENCY] = PRIM_CLASS_LINE, + + [PRIM_NONE] = PRIM_CLASS_NONE + }; + + return classes[prim_type]; + } + +bool prim_type_belongs_to_class(PrimitiveType prim_type, PrimitiveClass prim_class) + { + if (prim_class == PRIM_CLASS_NONE && prim_type == PRIM_NONE) + return true; + + return prim_class & prim_class_of_type(prim_type); + } + +GLenum convert_prim_type_to_gl(PrimitiveType prim_type) + { +#if TRUST_NO_ONE + assert(prim_type != PRIM_NONE); +#endif + + static const GLenum table[] = + { + [PRIM_POINTS] = GL_POINTS, + [PRIM_LINES] = GL_LINES, + [PRIM_LINE_STRIP] = GL_LINE_STRIP, + [PRIM_LINE_LOOP] = GL_LINE_LOOP, + [PRIM_TRIANGLES] = PRIM_CLASS_SURFACE, + [PRIM_TRIANGLE_STRIP] = GL_TRIANGLE_STRIP, + [PRIM_TRIANGLE_FAN] = GL_TRIANGLE_FAN, + + [PRIM_LINE_STRIP_ADJACENCY] = GL_LINE_STRIP_ADJACENCY, + }; + + return table[prim_type]; + } |