[Bf-blender-cvs] [8fd510f] blender2.8: Gawain: new enum type for vertex attrib components
Mike Erwin
noreply at git.blender.org
Sat Nov 12 02:41:21 CET 2016
Commit: 8fd510f4b84a1cdcdd484948afc2087cf28cb1c5
Author: Mike Erwin
Date: Fri Nov 11 19:39:56 2016 -0600
Branches: blender2.8
https://developer.blender.org/rB8fd510f4b84a1cdcdd484948afc2087cf28cb1c5
Gawain: new enum type for vertex attrib components
Motivations:
1) GLenum is too broad; tightly-defined enum just for this is safer.
2) enable a Vulkan future
New code should use these instead of GL_FLOAT etc. When all existing code has been updated to use new enum, we can drop compatibility with GLenum values.
Early work towards 10_10_10 format, more to come soon.
===================================================================
M source/blender/gpu/gawain/vertex_format.c
M source/blender/gpu/gawain/vertex_format.h
===================================================================
diff --git a/source/blender/gpu/gawain/vertex_format.c b/source/blender/gpu/gawain/vertex_format.c
index 20a4d7d..8947855 100644
--- a/source/blender/gpu/gawain/vertex_format.c
+++ b/source/blender/gpu/gawain/vertex_format.c
@@ -36,7 +36,7 @@ void VertexFormat_copy(VertexFormat* dest, const VertexFormat* src)
memcpy(dest, src, sizeof(VertexFormat));
}
-static unsigned comp_sz(GLenum type)
+static unsigned comp_sz(VertexCompType type)
{
#if TRUST_NO_ONE
assert(type >= GL_BYTE && type <= GL_FLOAT);
@@ -48,11 +48,21 @@ static unsigned comp_sz(GLenum type)
static unsigned attrib_sz(const Attrib *a)
{
+#if USE_10_10_10
+ if (a->comp_type == COMP_I10)
+ return 4; // always packed as 10_10_10_2
+#endif
+
return a->comp_ct * comp_sz(a->comp_type);
}
static unsigned attrib_align(const Attrib *a)
{
+#if USE_10_10_10
+ if (a->comp_type == COMP_I10)
+ return 4; // always packed as 10_10_10_2
+#endif
+
unsigned c = comp_sz(a->comp_type);
if (a->comp_ct == 3 && c <= 2)
return 4 * c; // AMD HW can't fetch these well, so pad it out (other vendors too?)
@@ -96,7 +106,7 @@ static const char* copy_attrib_name(VertexFormat* format, const char* name)
return name_copy;
}
-unsigned add_attrib(VertexFormat* format, const char* name, GLenum comp_type, unsigned comp_ct, VertexFetchMode fetch_mode)
+unsigned add_attrib(VertexFormat* format, const char* name, VertexCompType comp_type, unsigned comp_ct, VertexFetchMode fetch_mode)
{
#if TRUST_NO_ONE
assert(format->attrib_ct < MAX_VERTEX_ATTRIBS); // there's room for more
@@ -104,27 +114,19 @@ unsigned add_attrib(VertexFormat* format, const char* name, GLenum comp_type, un
assert(comp_ct >= 1 && comp_ct <= 4);
switch (comp_type)
{
- case GL_FLOAT:
+ case COMP_F32:
// float type can only kept as float
assert(fetch_mode == KEEP_FLOAT);
break;
- #if 0 // enable this after switching to our own enum for comp_type
+ #if USE_10_10_10
+ case COMP_I10:
+ assert(comp_ct == 3); // 10_10_10 format intended for normals (xyz) or colors (rgb)
+ assert(fetch_mode == NORMALIZE_INT_TO_FLOAT);
+ break;
+ #endif
default:
// integer types can be kept as int or converted/normalized to float
assert(fetch_mode != KEEP_FLOAT);
- #else
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_INT:
- case GL_UNSIGNED_INT:
- // integer types can be converted, normalized, or kept as int
- assert(fetch_mode != KEEP_FLOAT);
- break;
- default:
- assert(false); // invalid comp_type
- #endif
}
#endif
diff --git a/source/blender/gpu/gawain/vertex_format.h b/source/blender/gpu/gawain/vertex_format.h
index 09c7960..8bf20d5 100644
--- a/source/blender/gpu/gawain/vertex_format.h
+++ b/source/blender/gpu/gawain/vertex_format.h
@@ -17,6 +17,25 @@
#define AVG_VERTEX_ATTRIB_NAME_LEN 5
#define VERTEX_ATTRIB_NAMES_BUFFER_LEN ((AVG_VERTEX_ATTRIB_NAME_LEN + 1) * MAX_VERTEX_ATTRIBS)
+#define USE_10_10_10 0
+// (GLEW_VERSION_3_3 || GLEW_ARB_vertex_type_2_10_10_10_rev)
+// ^-- this is only guaranteed on Windows right now, will be true on all platforms soon
+
+typedef enum {
+ COMP_I8 = GL_BYTE,
+ COMP_U8 = GL_UNSIGNED_BYTE,
+ COMP_I16 = GL_SHORT,
+ COMP_U16 = GL_UNSIGNED_SHORT,
+ COMP_I32 = GL_INT,
+ COMP_U32 = GL_UNSIGNED_INT,
+
+ COMP_F32 = GL_FLOAT, // TODO: drop the GL_ equivalence here, use a private lookup table
+
+#if USE_10_10_10
+ COMP_I10 = GL_INT_2_10_10_10_REV
+#endif
+} VertexCompType;
+
typedef enum {
KEEP_FLOAT,
KEEP_INT,
@@ -25,7 +44,7 @@ typedef enum {
} VertexFetchMode;
typedef struct {
- GLenum comp_type;
+ VertexCompType comp_type;
unsigned comp_ct; // 1 to 4
unsigned sz; // size in bytes, 1 to 16
unsigned offset; // from beginning of vertex, in bytes
@@ -45,7 +64,7 @@ typedef struct {
void VertexFormat_clear(VertexFormat*);
void VertexFormat_copy(VertexFormat* dest, const VertexFormat* src);
-unsigned add_attrib(VertexFormat*, const char* name, GLenum comp_type, unsigned comp_ct, VertexFetchMode);
+unsigned add_attrib(VertexFormat*, const char* name, VertexCompType, unsigned comp_ct, VertexFetchMode);
// for internal use
void VertexFormat_pack(VertexFormat*);
More information about the Bf-blender-cvs
mailing list