diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index dbd2cd321..99d7ddb3c 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -24,12 +24,6 @@ namespace Magnum { IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault; IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; -IndexedMesh* IndexedMesh::setIndexBuffer(Buffer* buffer) { - _indexBuffer = buffer; - (this->*bindIndexBufferImplementation)(); - return this; -} - void IndexedMesh::draw() { if(!_indexCount) return; @@ -41,8 +35,6 @@ void IndexedMesh::draw() { } void IndexedMesh::bind() { - CORRADE_ASSERT(!_indexCount || _indexBuffer, "IndexedMesh: index buffer must be added if index count is non-zero", ); - Mesh::bind(); (this->*bindIndexedImplementation)(); } @@ -61,11 +53,13 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) { #endif } -void IndexedMesh::bindIndexBufferImplementationDefault() {} +void IndexedMesh::bindIndexBufferImplementationDefault(Buffer* buffer) { + _indexBuffer = buffer; +} -void IndexedMesh::bindIndexBufferImplementationVAO() { +void IndexedMesh::bindIndexBufferImplementationVAO(Buffer* buffer) { bindVAO(vao); - _indexBuffer->bind(Buffer::Target::ElementArray); + buffer->bind(Buffer::Target::ElementArray); } void IndexedMesh::bindIndexedImplementationDefault() { diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 965438429..046a74ae1 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -83,12 +83,16 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { /** * @brief Set index buffer + * @return Pointer to self (for method chaining) * * @see setIndexCount(), setIndexType(), MeshTools::compressIndices(), * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if * @extension{APPLE,vertex_array_object} is available) */ - IndexedMesh* setIndexBuffer(Buffer* buffer); + inline IndexedMesh* setIndexBuffer(Buffer* buffer) { + (this->*bindIndexBufferImplementation)(buffer); + return this; + } /** * @brief Draw the mesh @@ -140,10 +144,10 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { void MAGNUM_LOCAL bind(); - typedef void(IndexedMesh::*BindIndexBufferImplementation)(); - void MAGNUM_LOCAL bindIndexBufferImplementationDefault(); - void MAGNUM_LOCAL bindIndexBufferImplementationVAO(); - static MAGNUM_LOCAL BindIndexBufferImplementation bindIndexBufferImplementation; + typedef void(IndexedMesh::*BindIndexBufferImplementation)(Buffer*); + void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer* buffer); + void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer* buffer); + static BindIndexBufferImplementation bindIndexBufferImplementation; typedef void(IndexedMesh::*BindIndexedImplementation)(); void MAGNUM_LOCAL bindIndexedImplementationDefault();