[Bf-blender-cvs] [33758c7cb8] blender2.8: Gawain: move PRIM types to new file, classify by geometry
Mike Erwin
noreply at git.blender.org
Thu Mar 2 21:08:40 CET 2017
Commit: 33758c7cb86f6b19183f12464f0256c5a37a2b8b
Author: Mike Erwin
Date: Thu Mar 2 15:07:14 2017 -0500
Branches: blender2.8
https://developer.blender.org/rB33758c7cb86f6b19183f12464f0256c5a37a2b8b
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
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/gawain/common.h
M source/blender/gpu/gawain/element.h
M source/blender/gpu/gawain/immediate.h
A source/blender/gpu/gawain/primitive.c
A source/blender/gpu/gawain/primitive.h
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index b6ec702403..148fb4fcb2 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 90340b94e4..9c16101a0b 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 4e0d5fb064..f22d7c0ffd 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 1e5729e5cc..6a03954206 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 0000000000..95472c289e
--- /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/common.h b/source/blender/gpu/gawain/primitive.h
similarity index 50%
copy from source/blender/gpu/gawain/common.h
copy to source/blender/gpu/gawain/primitive.h
index 90340b94e4..d1b8f5b3ec 100644
--- a/source/blender/gpu/gawain/common.h
+++ b/source/blender/gpu/gawain/primitive.h
@@ -1,44 +1,17 @@
-// Gawain common #defines and #includes
+// Gawain geometric primitives
//
// This code is part of the Gawain library, with modifications
// specific to integration with Blender.
//
-// Copyright 2016 Mike Erwin
+// 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
-// #define TRUST_NO_ONE !defined(NDEBUG)
-#define TRUST_NO_ONE 1
-// strict error checking, always enabled during early development
-
-#include <GL/glew.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#if TRUST_NO_ONE
- #include <assert.h>
-#endif
-
-#define PER_THREAD
-// #define PER_THREAD __thread
-// MSVC uses __declspec(thread) for C code
-
-#define APPLE_LEGACY (defined(__APPLE__) && defined(WITH_GL_PROFILE_COMPAT))
-
-#if APPLE_LEGACY
- #undef glGenVertexArrays
- #define glGenVertexArrays glGenVertexArraysAPPLE
-
- #undef glDeleteVertexArrays
- #define glDeleteVertexArrays glDeleteVertexArraysAPPLE
-
- #undef glBindVertexArray
- #define glBindVertexArray glBindVertexArrayAPPLE
-#endif
+#include "common.h"
typedef enum {
PRIM_POINTS = GL_POINTS,
@@ -56,3 +29,15 @@ typedef enum {
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);
More information about the Bf-blender-cvs
mailing list