[Bf-blender-cvs] [a2471d2] blender2.8: Gawain: validate inputs to add_attrib

Mike Erwin noreply at git.blender.org
Sat Oct 8 23:00:29 CEST 2016


Commit: a2471d2b3764ebdedefd41934a22f48bd5d799c8
Author: Mike Erwin
Date:   Sat Oct 8 16:58:06 2016 -0400
Branches: blender2.8
https://developer.blender.org/rBa2471d2b3764ebdedefd41934a22f48bd5d799c8

Gawain: validate inputs to add_attrib

Should help prevent errors when building vertex formats.

===================================================================

M	source/blender/gpu/gawain/vertex_format.c

===================================================================

diff --git a/source/blender/gpu/gawain/vertex_format.c b/source/blender/gpu/gawain/vertex_format.c
index 5222001..a39e3ca 100644
--- a/source/blender/gpu/gawain/vertex_format.c
+++ b/source/blender/gpu/gawain/vertex_format.c
@@ -84,6 +84,31 @@ unsigned add_attrib(VertexFormat* format, const char* name, GLenum comp_type, un
 #if TRUST_NO_ONE
 	assert(format->attrib_ct < MAX_VERTEX_ATTRIBS); // there's room for more
 	assert(!format->packed); // packed means frozen/locked
+	assert(comp_ct >= 1 && comp_ct <= 4);
+	switch (comp_type)
+		{
+		case GL_FLOAT:
+			// 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
+		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
 
 	const unsigned attrib_id = format->attrib_ct++;




More information about the Bf-blender-cvs mailing list