From 8abc836ae48aabe8744c1874ab20d97148e85baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 19 Nov 2012 12:10:51 +0100 Subject: [PATCH] Allow passing nullptr to IndexedMesh::setIndexBuffer(). Similar functionality should be in Mesh itself for unbinding vertex buffers. --- src/IndexedMesh.cpp | 8 +++++--- src/IndexedMesh.h | 3 +++ src/Mesh.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index e91453f74..4ef22584d 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -42,7 +42,7 @@ void IndexedMesh::draw() { } void IndexedMesh::bind() { - CORRADE_ASSERT(_indexCount, "IndexedMesh: the mesh has zero index count!", ); + CORRADE_ASSERT(!_indexCount || _indexBuffer, "IndexedMesh: index buffer must be added if index count is non-zero", ); Mesh::bind(); (this->*bindIndexedImplementation)(); @@ -66,11 +66,13 @@ void IndexedMesh::bindIndexBufferImplementationDefault() {} void IndexedMesh::bindIndexBufferImplementationVAO() { bindVAO(vao); - _indexBuffer->bind(Buffer::Target::ElementArray); + if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); + else Buffer::unbind(Buffer::Target::ElementArray); } void IndexedMesh::bindIndexedImplementationDefault() { - _indexBuffer->bind(Buffer::Target::ElementArray); + if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); + else Buffer::unbind(Buffer::Target::ElementArray); } void IndexedMesh::bindIndexedImplementationVAO() {} diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 06af7e492..bac40636e 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -68,6 +68,9 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { /** * @brief Set index buffer * + * By default there is no index buffer. Parameter @p buffer can be + * `nullptr`, in that case current index buffer is unbound from the + * mesh. * @see MeshTools::compressIndices(), @fn_gl{BindVertexArray}, * @fn_gl{BindBuffer} (if @extension{APPLE,vertex_array_object} * is available) diff --git a/src/Mesh.h b/src/Mesh.h index d33c94115..d90687956 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -112,6 +112,8 @@ more information. @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. +@todo Allow unbinding all vertex buffers with some function (not as side effect), + similarly to unbinding index buffer in IndexedMesh */ class MAGNUM_EXPORT Mesh { friend class IndexedMesh;