diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-10-08 23:58:06 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-10-08 23:58:06 +0300 |
commit | a2471d2b3764ebdedefd41934a22f48bd5d799c8 (patch) | |
tree | c436279c22a8d33cea1014567c3538c268a87115 /source/blender/gpu | |
parent | 187d8f473a16a657505dfb7a2b53606d0631fca8 (diff) |
Gawain: validate inputs to add_attrib
Should help prevent errors when building vertex formats.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/gawain/vertex_format.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/gpu/gawain/vertex_format.c b/source/blender/gpu/gawain/vertex_format.c index 522200134ad..a39e3ca2486 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++; |