diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c74e2888..666f1c0d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,6 @@ set(Magnum_SRCS DefaultFramebuffer.cpp Framebuffer.cpp Image.cpp - IndexedMesh.cpp Mesh.cpp Query.cpp Renderbuffer.cpp diff --git a/src/Context.cpp b/src/Context.cpp index 1318757f7..bcc9518ec 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -29,7 +29,6 @@ #include "DefaultFramebuffer.h" #include "Extensions.h" #include "Framebuffer.h" -#include "IndexedMesh.h" #include "Mesh.h" #include "Renderbuffer.h" @@ -355,7 +354,6 @@ Context::Context() { DebugMarker::initializeContextBasedFunctionality(this); DefaultFramebuffer::initializeContextBasedFunctionality(this); Framebuffer::initializeContextBasedFunctionality(this); - IndexedMesh::initializeContextBasedFunctionality(this); Mesh::initializeContextBasedFunctionality(this); Renderbuffer::initializeContextBasedFunctionality(this); } diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp deleted file mode 100644 index f293be19a..000000000 --- a/src/IndexedMesh.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "IndexedMesh.h" - -#include "Buffer.h" -#include "Context.h" -#include "Extensions.h" - -namespace Magnum { - -IndexedMesh::BindIndexedImplementation IndexedMesh::bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationDefault; - -void IndexedMesh::draw() { - if(!_indexCount) return; - - bind(); - - glDrawElements(static_cast(primitive()), _indexCount, static_cast(_indexType), nullptr); - - unbind(); -} - -void IndexedMesh::bind() { - Mesh::bind(); - (this->*bindIndexedImplementation)(); -} - -void IndexedMesh::initializeContextBasedFunctionality(Context* context) { - /** @todo VAOs are in ES 3.0 and as extension in ES 2.0, enable them when some extension wrangler is available */ - #ifndef MAGNUM_TARGET_GLES - if(context->isExtensionSupported()) { - Debug() << "IndexedMesh: using" << Extensions::GL::APPLE::vertex_array_object::string() << "features"; - - bindIndexedImplementation = &IndexedMesh::bindIndexedImplementationVAO; - } - #else - static_cast(context); - #endif -} - -void IndexedMesh::bindIndexedImplementationDefault() { - 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 0c777f9c2..ea06a9513 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -80,29 +80,6 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { * no vertex or index buffers. */ inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {} - - /** - * @brief Draw the mesh - * - * Expects an active shader with all uniforms set. See - * @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" - * for more information. - * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, - * @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray} - * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} - * is available), @fn_gl{DrawElements} - */ - void draw() override; - - private: - static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context* context); - - void MAGNUM_LOCAL bind(); - - typedef void(IndexedMesh::*BindIndexedImplementation)(); - void MAGNUM_LOCAL bindIndexedImplementationDefault(); - void MAGNUM_LOCAL bindIndexedImplementationVAO(); - static MAGNUM_LOCAL BindIndexedImplementation bindIndexedImplementation; }; } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 14e2a73fb..4b4da14da 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -94,13 +94,18 @@ Mesh& Mesh::operator=(Mesh&& other) { } void Mesh::draw() { - if(!_vertexCount) return; + /* Nothing to draw */ + if(!_vertexCount && !_indexCount) return; - bind(); + (this->*bindImplementation)(); + + /* Non-indexed mesh */ + if(!_indexCount) glDrawArrays(static_cast(_primitive), 0, _vertexCount); - glDrawArrays(static_cast(_primitive), 0, _vertexCount); + /* Indexed mesh */ + else glDrawElements(static_cast(_primitive), _indexCount, static_cast(_indexType), nullptr); - unbind(); + (this->*unbindImplementation)(); } void Mesh::bindVAO(GLuint vao) { @@ -113,10 +118,6 @@ void Mesh::bindVAO(GLuint vao) { #endif } -void Mesh::bind() { - (this->*bindImplementation)(); -} - void Mesh::vertexAttribPointer(const Attribute& attribute) { glEnableVertexAttribArray(attribute.location); attribute.buffer->bind(Buffer::Target::Array); @@ -247,6 +248,7 @@ void Mesh::bindIndexBufferImplementationVAO(Buffer* buffer) { } void Mesh::bindImplementationDefault() { + /* Specify vertex attributes */ for(const Attribute& attribute: attributes) vertexAttribPointer(attribute); @@ -259,6 +261,12 @@ void Mesh::bindImplementationDefault() { vertexAttribPointer(attribute); #endif #endif + + /* Bind index buffer, if the mesh is indexed */ + if(_indexCount) { + if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); + else Buffer::unbind(Buffer::Target::ElementArray); + } } void Mesh::bindImplementationVAO() { diff --git a/src/Mesh.h b/src/Mesh.h index d3759c7ab..b3956b716 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -119,7 +119,6 @@ more information. @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. */ class MAGNUM_EXPORT Mesh { - friend class IndexedMesh; friend class Context; Mesh(const Mesh& other) = delete; @@ -396,7 +395,7 @@ class MAGNUM_EXPORT Mesh { * @see @fn_gl{DeleteVertexArrays} (if * @extension{APPLE,vertex_array_object} is available) */ - virtual ~Mesh(); + ~Mesh(); /** @brief Move assignment */ Mesh& operator=(Mesh&& other); @@ -614,9 +613,9 @@ class MAGNUM_EXPORT Mesh { * @see @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, * @fn_gl{VertexAttribPointer}, @fn_gl{DisableVertexAttribArray} * or @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object} - * is available), @fn_gl{DrawArrays} + * is available), @fn_gl{DrawArrays} or @fn_gl{DrawElements} */ - virtual void draw(); + void draw(); private: #ifndef DOXYGEN_GENERATING_OUTPUT @@ -732,12 +731,6 @@ class MAGNUM_EXPORT Mesh { static void MAGNUM_LOCAL bindVAO(GLuint vao); - void MAGNUM_LOCAL bind(); - - inline void unbind() { - (this->*unbindImplementation)(); - } - void MAGNUM_LOCAL vertexAttribPointer(const Attribute& attribute); #ifndef MAGNUM_TARGET_GLES2 void MAGNUM_LOCAL vertexAttribPointer(const IntegerAttribute& attribute);