diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 3b531a55f..2a71d3238 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -21,18 +21,15 @@ using namespace std; namespace Magnum { Mesh::~Mesh() { - for(map > >::iterator it = _buffers.begin(); it != _buffers.end(); ++it) - delete it->first; + for(auto it: _buffers) + delete it.first; glDeleteVertexArrays(1, &vao); } -Buffer* Mesh::addBuffer(bool interleaved) { +Buffer* Mesh::addBuffer(BufferType interleaved) { Buffer* buffer = new Buffer(Buffer::Target::Array); - _buffers.insert(pair > >( - buffer, - pair >(interleaved, vector()) - )); + _buffers.insert(make_pair(buffer, make_pair(interleaved, vector()))); return buffer; } @@ -60,10 +57,10 @@ void Mesh::finalize() { glEnableVertexAttribArray(*it); /* Finalize attribute positions for every buffer */ - for(map > >::iterator it = _buffers.begin(); it != _buffers.end(); ++it) { + for(auto it: _buffers) { /* Avoid confustion */ - bool interleaved = it->second.first; - vector& attributes = it->second.second; + bool interleaved = it.second.first == BufferType::Interleaved; + vector& attributes = it.second.second; /* Interleaved buffer, set stride and position of first attribute */ if(interleaved) { @@ -95,7 +92,7 @@ void Mesh::finalize() { } /* Bind buffer */ - it->first->bind(); + it.first->bind(); /* Bind all attributes to this buffer */ for(vector::const_iterator ait = attributes.begin(); ait != attributes.end(); ++ait) @@ -113,7 +110,7 @@ void Mesh::bindAttribute(Buffer* buffer, GLuint attribute, GLint size, Type type if(finalized || _attributes.find(attribute) != _attributes.end()) return; /* If buffer is not managed by this mesh, nothing to do */ - map > >::iterator found = _buffers.find(buffer); + auto found = _buffers.find(buffer); if(found == _buffers.end()) return; Attribute a; diff --git a/src/Mesh.h b/src/Mesh.h index c61079c3f..903131c61 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -120,6 +120,20 @@ class MAGNUM_EXPORT Mesh { TriangleFan = GL_TRIANGLE_FAN }; + /** + * @brief Buffer type + * + * If storing more than one attribute data in the buffer, the data of + * one attribute can be either kept together or interleaved with data + * for another attributes, so data for every vertex will be in one + * continuous place. + * @see addBuffer() + */ + enum class BufferType: bool { + Interleaved, /**< Interleaved buffer */ + NonInterleaved /**< Non-interleaved buffer */ + }; + /** * @brief Set polygon drawing mode * @@ -214,17 +228,14 @@ class MAGNUM_EXPORT Mesh { /** * @brief Add buffer - * @param interleaved If storing more than one attribute data in the - * buffer, the data of one attribute can be either kept together - * or interleaved with data for another attributes, so data for - * every vertex will be in one continuous place. + * @param interleaved Whether the buffer is interleaved * * Adds new buffer to the mesh. The buffer can be then filled with * Buffer::setData(). See also isInterleaved(). * * @todo Move interleaveability to Buffer itself? */ - Buffer* addBuffer(bool interleaved); + Buffer* addBuffer(BufferType interleaved); /** * @brief Whether given buffer is interleaved @@ -235,7 +246,7 @@ class MAGNUM_EXPORT Mesh { */ inline bool isInterleaved(Buffer* buffer) const { auto found = _buffers.find(buffer); - return found != _buffers.end() && found->second.first; + return found != _buffers.end() && found->second.first == BufferType::Interleaved; } /** @@ -298,7 +309,7 @@ class MAGNUM_EXPORT Mesh { * - boolean value which signalizes whether the buffer is interleaved * - list of bound attributes */ - std::map > > _buffers; + std::map > > _buffers; /** * @brief List of all bound attributes