Browse Source

Vk: Add Mesh

Signed-off-by: Squareys <squareys@googlemail.com>
pull/202/head
Squareys 10 years ago committed by Squareys
parent
commit
ef13e7f69f
  1. 1
      src/Magnum/Vk/CMakeLists.txt
  2. 35
      src/Magnum/Vk/Mesh.cpp
  3. 103
      src/Magnum/Vk/Mesh.h

1
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

35
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š <mosra@centrum.cz>
Copyright © 2016 Jonathan Hale <squareys@googlemail.com>
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() {
}
}}

103
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š <mosra@centrum.cz>
Copyright © 2016 Jonathan Hale <squareys@googlemail.com>
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 <vector>
#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<VkBuffer> _vertexBuffers;
VkBuffer _indexBuffer;
int _numIndices;
};
}}
#endif
Loading…
Cancel
Save