diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 039fab3eb..3c06f94a6 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -34,18 +34,9 @@ void IndexedMesh::draw() { /* Bind all attributes to this buffer */ for(vector::const_iterator ait = it->second.second.begin(); ait != it->second.second.end(); ++ait) - switch(ait->type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - glVertexAttribIPointer(ait->attribute, ait->size, ait->type, ait->stride, ait->pointer); - break; - default: - glVertexAttribPointer(ait->attribute, ait->size, ait->type, GL_FALSE, ait->stride, ait->pointer); - } + if(TypeInfo::isIntegral(ait->type)) + glVertexAttribIPointer(ait->attribute, ait->size, static_cast(ait->type), ait->stride, ait->pointer); + else glVertexAttribPointer(ait->attribute, ait->size, static_cast(ait->type), GL_FALSE, ait->stride, ait->pointer); } /* Bind index array, draw the elements and unbind */ diff --git a/src/Mesh.cpp b/src/Mesh.cpp index d13ce064d..850102e1c 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -52,18 +52,9 @@ void Mesh::draw() { /* Bind all attributes to this buffer */ for(vector::const_iterator ait = it->second.second.begin(); ait != it->second.second.end(); ++ait) - switch(ait->type) { - case GL_BYTE: - case GL_UNSIGNED_BYTE: - case GL_SHORT: - case GL_UNSIGNED_SHORT: - case GL_INT: - case GL_UNSIGNED_INT: - glVertexAttribIPointer(ait->attribute, ait->size, ait->type, ait->stride, ait->pointer); - break; - default: - glVertexAttribPointer(ait->attribute, ait->size, ait->type, GL_FALSE, ait->stride, ait->pointer); - } + if(TypeInfo::isIntegral(ait->type)) + glVertexAttribIPointer(ait->attribute, ait->size, static_cast(ait->type), ait->stride, ait->pointer); + else glVertexAttribPointer(ait->attribute, ait->size, static_cast(ait->type), GL_FALSE, ait->stride, ait->pointer); } glDrawArrays(_primitive, 0, _vertexCount); @@ -92,7 +83,7 @@ void Mesh::finalize() { ait->pointer = reinterpret_cast(stride); /* Add attribute size (per vertex) to stride */ - stride += ait->size*sizeOf(ait->type); + stride += ait->size*TypeInfo::sizeOf(ait->type); } /* Set computed stride for all attributes */ @@ -108,7 +99,7 @@ void Mesh::finalize() { ait->pointer = reinterpret_cast(position); /* Add attribute size (for all vertices) to position */ - position += ait->size*sizeOf(ait->type)*_vertexCount; + position += ait->size*TypeInfo::sizeOf(ait->type)*_vertexCount; } } } @@ -117,7 +108,7 @@ void Mesh::finalize() { finalized = true; } -void Mesh::bindAttribute(Buffer* buffer, GLuint attribute, GLint size, GLenum type) { +void Mesh::bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type) { /* The mesh is finalized or attribute is already bound, nothing to do */ if(finalized || _attributes.find(attribute) != _attributes.end()) return; @@ -136,18 +127,4 @@ void Mesh::bindAttribute(Buffer* buffer, GLuint attribute, GLint size, GLenum ty _attributes.insert(attribute); } -GLsizei Mesh::sizeOf(GLenum type) { - switch(type) { - case GL_BYTE: return sizeof(GLbyte); - case GL_UNSIGNED_BYTE: return sizeof(GLubyte); - case GL_SHORT: return sizeof(GLshort); - case GL_UNSIGNED_SHORT: return sizeof(GLushort); - case GL_INT: return sizeof(GLint); - case GL_UNSIGNED_INT: return sizeof(GLuint); - case GL_FLOAT: return sizeof(GLfloat); - case GL_DOUBLE: return sizeof(GLdouble); - default: return 0; - } -} - } diff --git a/src/Mesh.h b/src/Mesh.h index 19e48a0fe..7f23c0b78 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -157,7 +157,7 @@ class MAGNUM_EXPORT Mesh { * function does nothing. */ template inline void bindAttribute(Buffer* buffer, GLuint attribute) { - bindAttribute(buffer, attribute, TypeTraits::count(), static_cast(TypeTraits::glType())); + bindAttribute(buffer, attribute, TypeTraits::count(), TypeTraits::glType()); } /** @@ -173,7 +173,7 @@ class MAGNUM_EXPORT Mesh { struct Attribute { GLuint attribute; /**< @brief Attribute ID */ GLint size; /**< @brief How many items of @c type are in the attribute */ - GLenum type; /**< @brief Attribute item type */ + Type type; /**< @brief Attribute item type */ GLsizei stride; /**< @brief Distance of two adjacent attributes of this type in interleaved buffer */ const GLvoid* pointer; /**< @brief Pointer to first attribute of this type in the buffer */ }; @@ -217,9 +217,7 @@ class MAGNUM_EXPORT Mesh { std::map > > _buffers; std::set _attributes; - void bindAttribute(Buffer* buffer, GLuint attribute, GLint size, GLenum type); - - GLsizei sizeOf(GLenum type); + void bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type); }; }