diff --git a/src/Magnum/Vk/CMakeLists.txt b/src/Magnum/Vk/CMakeLists.txt index 3c8e81dc2..59e08d79f 100644 --- a/src/Magnum/Vk/CMakeLists.txt +++ b/src/Magnum/Vk/CMakeLists.txt @@ -39,6 +39,7 @@ set(MagnumVk_SRCS Framebuffer.cpp Image.cpp ImageView.cpp + Mesh.cpp PhysicalDevice.cpp Pipeline.cpp Queue.cpp diff --git a/src/Magnum/Vk/Mesh.cpp b/src/Magnum/Vk/Mesh.cpp new file mode 100644 index 000000000..8c8d7b934 --- /dev/null +++ b/src/Magnum/Vk/Mesh.cpp @@ -0,0 +1,35 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + Copyright © 2016 Jonathan Hale + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Mesh.h" + + +namespace Magnum { namespace Vk { + +Mesh::~Mesh() { +} + +}} diff --git a/src/Magnum/Vk/Mesh.h b/src/Magnum/Vk/Mesh.h new file mode 100644 index 000000000..0fd9a9e01 --- /dev/null +++ b/src/Magnum/Vk/Mesh.h @@ -0,0 +1,103 @@ +#ifndef Magnum_Vk_Mesh_h +#define Magnum_Vk_Mesh_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + Copyright © 2016 Jonathan Hale + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class @ref Magnum::Vk::Mesh + */ + +#include + +#include "Magnum/Vk/Buffer.h" +#include "Magnum/Vk/visibility.h" + +#include "vulkan.h" + +namespace Magnum { namespace Vk { + +class MAGNUM_VK_EXPORT Mesh { + public: + + Mesh() { + } + + /** @brief Copying is not allowed */ + Mesh(const Mesh&) = delete; + + /** @brief Move constructor */ + Mesh(Mesh&& other); + + /** + * @brief Destructor + * + * @see @fn_vk{DestroyBuffer} + */ + ~Mesh(); + + /** @brief Copying is not allowed */ + Mesh& operator=(const Mesh&) = delete; + + /** @brief Move assignment is not allowed */ + Mesh& operator=(Mesh&&) = delete; + + auto draw() { + const VkBuffer* vertexBuffers = _vertexBuffers.data(); + const VkBuffer indexBuffer = _indexBuffer; + + const int numVertexBuffers = _vertexBuffers.size(); + const int numIndices = _numIndices; + return [vertexBuffers, indexBuffer, numVertexBuffers, numIndices](VkCommandBuffer cmdBuffer){ + VkDeviceSize offset = 0; + + vkCmdBindVertexBuffers(cmdBuffer, 0, numVertexBuffers, vertexBuffers, &offset); + vkCmdBindIndexBuffer(cmdBuffer, indexBuffer, 0, VK_INDEX_TYPE_UINT32); + + vkCmdDrawIndexed(cmdBuffer, numIndices, 1, 0, 0, 1); + }; + } + + Mesh& addVertexBuffer(VkBuffer buffer) { + _vertexBuffers.push_back(buffer); + return *this; + } + + Mesh& setIndexBuffer(const Buffer& buffer) { + _indexBuffer = buffer; + _numIndices = buffer.size(); + return *this; + } + + private: + std::vector _vertexBuffers; + VkBuffer _indexBuffer; + + int _numIndices; +}; + +}} + +#endif