From 33758c7cb86f6b19183f12464f0256c5a37a2b8b Mon Sep 17 00:00:00 2001 From: Mike Erwin Date: Thu, 2 Mar 2017 15:07:14 -0500 Subject: Gawain: move PRIM types to new file, classify by geometry PrimitiveClass will help match shaders to draw calls & detect usage errors. For example a point sprite shader only makes sense with PRIM_POINTS. Updated other files to include new primitive.h --- source/blender/gpu/CMakeLists.txt | 2 ++ source/blender/gpu/gawain/common.h | 17 -------------- source/blender/gpu/gawain/element.h | 2 +- source/blender/gpu/gawain/immediate.h | 1 + source/blender/gpu/gawain/primitive.c | 41 +++++++++++++++++++++++++++++++++ source/blender/gpu/gawain/primitive.h | 43 +++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 source/blender/gpu/gawain/primitive.c create mode 100644 source/blender/gpu/gawain/primitive.h (limited to 'source') diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index b6ec702403a..148fb4fcb2f 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -81,6 +81,8 @@ set(SRC gawain/immediate.h gawain/imm_util.c gawain/imm_util.h + gawain/primitive.h + gawain/primitive.c gawain/vertex_buffer.c gawain/vertex_buffer.h gawain/vertex_format.c diff --git a/source/blender/gpu/gawain/common.h b/source/blender/gpu/gawain/common.h index 90340b94e4d..9c16101a0be 100644 --- a/source/blender/gpu/gawain/common.h +++ b/source/blender/gpu/gawain/common.h @@ -39,20 +39,3 @@ #undef glBindVertexArray #define glBindVertexArray glBindVertexArrayAPPLE #endif - -typedef enum { - PRIM_POINTS = GL_POINTS, - PRIM_LINES = GL_LINES, - PRIM_TRIANGLES = GL_TRIANGLES, - -#ifdef WITH_GL_PROFILE_COMPAT - PRIM_QUADS = GL_QUADS, // legacy GL has this, modern GL & Vulkan do not -#endif - - PRIM_LINE_STRIP = GL_LINE_STRIP, - PRIM_LINE_LOOP = GL_LINE_LOOP, // GL has this, Vulkan does not - PRIM_TRIANGLE_STRIP = GL_TRIANGLE_STRIP, - PRIM_TRIANGLE_FAN = GL_TRIANGLE_FAN, - - PRIM_NONE = 0xF -} PrimitiveType; diff --git a/source/blender/gpu/gawain/element.h b/source/blender/gpu/gawain/element.h index 4e0d5fb0649..f22d7c0ffda 100644 --- a/source/blender/gpu/gawain/element.h +++ b/source/blender/gpu/gawain/element.h @@ -11,7 +11,7 @@ #pragma once -#include "common.h" +#include "primitive.h" #define TRACK_INDEX_RANGE 1 diff --git a/source/blender/gpu/gawain/immediate.h b/source/blender/gpu/gawain/immediate.h index 1e5729e5cce..6a039542065 100644 --- a/source/blender/gpu/gawain/immediate.h +++ b/source/blender/gpu/gawain/immediate.h @@ -12,6 +12,7 @@ #pragma once #include "vertex_format.h" +#include "primitive.h" #define IMM_BATCH_COMBO 1 diff --git a/source/blender/gpu/gawain/primitive.c b/source/blender/gpu/gawain/primitive.c new file mode 100644 index 00000000000..95472c289e8 --- /dev/null +++ b/source/blender/gpu/gawain/primitive.c @@ -0,0 +1,41 @@ + +// 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" + +PrimitiveClass prim_class_of_type(PrimitiveType prim_type) + { + static const PrimitiveClass classes[] = + { + [PRIM_NONE] = PRIM_CLASS_NONE, + [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, + +#ifdef WITH_GL_PROFILE_COMPAT + [PRIM_QUADS] = PRIM_CLASS_SURFACE, +#endif + }; + + 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); + } diff --git a/source/blender/gpu/gawain/primitive.h b/source/blender/gpu/gawain/primitive.h new file mode 100644 index 00000000000..d1b8f5b3ec7 --- /dev/null +++ b/source/blender/gpu/gawain/primitive.h @@ -0,0 +1,43 @@ + +// 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/. + +#pragma once + +#include "common.h" + +typedef enum { + PRIM_POINTS = GL_POINTS, + PRIM_LINES = GL_LINES, + PRIM_TRIANGLES = GL_TRIANGLES, + +#ifdef WITH_GL_PROFILE_COMPAT + PRIM_QUADS = GL_QUADS, // legacy GL has this, modern GL & Vulkan do not +#endif + + PRIM_LINE_STRIP = GL_LINE_STRIP, + PRIM_LINE_LOOP = GL_LINE_LOOP, // GL has this, Vulkan does not + PRIM_TRIANGLE_STRIP = GL_TRIANGLE_STRIP, + PRIM_TRIANGLE_FAN = GL_TRIANGLE_FAN, + + PRIM_NONE = 0xF +} PrimitiveType; + +// what types of primitives does each shader expect? +typedef enum { + PRIM_CLASS_NONE = 0, + PRIM_CLASS_POINT = (1 << 0), + PRIM_CLASS_LINE = (1 << 1), + PRIM_CLASS_SURFACE = (1 << 2), + PRIM_CLASS_ANY = PRIM_CLASS_POINT | PRIM_CLASS_LINE | PRIM_CLASS_SURFACE +} PrimitiveClass; + +PrimitiveClass prim_class_of_type(PrimitiveType); +bool prim_type_belongs_to_class(PrimitiveType, PrimitiveClass); -- cgit v1.2.3