From a2a66803bedb7c69eefb8eb07b1cef974c61d74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 17:21:25 +0100 Subject: [PATCH] Removing IndexedMesh, part 3: moved last remaining setter to Mesh. Now only the drawing mess needs to be merged. --- src/IndexedMesh.cpp | 11 ---------- src/IndexedMesh.h | 50 --------------------------------------------- src/Mesh.cpp | 11 ++++++++++ src/Mesh.h | 18 ++++++++++++++++ 4 files changed, 29 insertions(+), 61 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 99d7ddb3c..f293be19a 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -21,7 +21,6 @@ namespace Magnum { -IndexedMesh::BindIndexBufferImplementation IndexedMesh::bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationDefault; IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; void IndexedMesh::draw() { @@ -45,7 +44,6 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) { if(context->isExtensionSupported()) { Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; - bindIndexBufferImplementation = &IndexedMesh::bindIndexBufferImplementationVAO; bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO; } #else @@ -53,15 +51,6 @@ void IndexedMesh::initializeContextBasedFunctionality(Context* context) { #endif } -void IndexedMesh::bindIndexBufferImplementationDefault(Buffer* buffer) { - _indexBuffer = buffer; -} - -void IndexedMesh::bindIndexBufferImplementationVAO(Buffer* buffer) { - bindVAO(vao); - buffer->bind(Buffer::Target::ElementArray); -} - void IndexedMesh::bindIndexedImplementationDefault() { if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); else Buffer::unbind(Buffer::Target::ElementArray); diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 046a74ae1..0c777f9c2 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -81,19 +81,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { */ inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {} - /** - * @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) - */ - inline IndexedMesh* setIndexBuffer(Buffer* buffer) { - (this->*bindIndexBufferImplementation)(buffer); - return this; - } - /** * @brief Draw the mesh * @@ -107,48 +94,11 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { */ void draw() override; - /* Overloads to remove WTF-factor from method chaining order */ - #ifndef DOXYGEN_GENERATING_OUTPUT - inline IndexedMesh* setPrimitive(Primitive primitive) { - Mesh::setPrimitive(primitive); - return this; - } - inline IndexedMesh* setVertexCount(GLsizei vertexCount) { - Mesh::setVertexCount(vertexCount); - return this; - } - inline IndexedMesh* setIndexCount(GLsizei count) { - Mesh::setIndexCount(count); - return this; - } - inline IndexedMesh* setIndexType(IndexType type) { - Mesh::setIndexType(type); - return this; - } - template inline IndexedMesh* addVertexBuffer(Buffer* buffer, const T&... attributes) { - Mesh::addVertexBuffer(buffer, attributes...); - return this; - } - template inline IndexedMesh* addInterleavedVertexBuffer(Buffer* buffer, GLintptr offset, const T&... attributes) { - Mesh::addInterleavedVertexBuffer(buffer, offset, attributes...); - return this; - } - template inline IndexedMesh* addVertexBufferStride(Buffer* buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute& attribute) { - Mesh::addVertexBufferStride(buffer, offset, stride, attribute); - return this; - } - #endif - private: static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); void MAGNUM_LOCAL bind(); - 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(); void MAGNUM_LOCAL bindIndexedImplementationVAO(); diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 07e5b0dea..14e2a73fb 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -34,6 +34,7 @@ Mesh::AttributeIPointerImplementation Mesh::attributeIPointerImplementation = &M Mesh::AttributeLPointerImplementation Mesh::attributeLPointerImplementation = &Mesh::attributePointerImplementationDefault; #endif #endif +Mesh::BindIndexBufferImplementation Mesh::bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationDefault; Mesh::BindImplementation Mesh::bindImplementation = &Mesh::bindImplementationDefault; Mesh::UnbindImplementation Mesh::unbindImplementation = &Mesh::unbindImplementationDefault; @@ -159,6 +160,7 @@ void Mesh::initializeContextBasedFunctionality(Context* context) { attributeLPointerImplementation = &Mesh::attributePointerImplementationVAO; } + bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationVAO; bindImplementation = &Mesh::bindImplementationVAO; unbindImplementation = &Mesh::unbindImplementationVAO; } @@ -235,6 +237,15 @@ void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) { #endif #endif +void Mesh::bindIndexBufferImplementationDefault(Buffer* buffer) { + _indexBuffer = buffer; +} + +void Mesh::bindIndexBufferImplementationVAO(Buffer* buffer) { + bindVAO(vao); + buffer->bind(Buffer::Target::ElementArray); +} + void Mesh::bindImplementationDefault() { for(const Attribute& attribute: attributes) vertexAttribPointer(attribute); diff --git a/src/Mesh.h b/src/Mesh.h index b4313d2d9..d3759c7ab 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -592,6 +592,19 @@ class MAGNUM_EXPORT Mesh { return this; } + /** + * @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) + */ + inline Mesh* setIndexBuffer(Buffer* buffer) { + (this->*bindIndexBufferImplementation)(buffer); + return this; + } + /** * @brief Draw the mesh * @@ -769,6 +782,11 @@ class MAGNUM_EXPORT Mesh { #endif #endif + typedef void(Mesh::*BindIndexBufferImplementation)(Buffer*); + void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer* buffer); + void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer* buffer); + static BindIndexBufferImplementation bindIndexBufferImplementation; + typedef void(Mesh::*BindImplementation)(); void MAGNUM_LOCAL bindImplementationDefault(); void MAGNUM_LOCAL bindImplementationVAO();