1#ifndef LIBSBX_GRAPHICS_PIPELINE_MESH_HPP_
2#define LIBSBX_GRAPHICS_PIPELINE_MESH_HPP_
8#include <libsbx/graphics/graphics_module.hpp>
10#include <libsbx/graphics/buffers/buffer.hpp>
12#include <libsbx/graphics/pipeline/vertex_input_description.hpp>
14namespace sbx::graphics {
16template<
typename Type>
17using vertex_buffer = basic_buffer<Type, (VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT>;
19template<
typename Type>
20using index_buffer = basic_buffer<Type, (VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT>;
23 std::uint32_t index_count{};
24 std::uint32_t index_offset{};
25 std::uint32_t vertex_offset{};
28template<vertex Vertex>
33 using vertex_type = Vertex;
36 using index_type = std::uint32_t;
39 mesh(std::vector<vertex_type>&& vertices, std::vector<index_type>&& indices) {
40 _submeshes.push_back(
submesh{
static_cast<std::uint32_t
>(indices.size()), 0, 0});
42 _upload_vertices(std::move(vertices), std::move(indices));
51 command_buffer.bind_index_buffer(*_index_buffer, 0, VK_INDEX_TYPE_UINT32);
53 command_buffer.draw_indexed(
static_cast<std::uint32_t
>(_index_buffer->size()), instance_count, 0, 0, 0);
58 command_buffer.bind_index_buffer(*_index_buffer, 0, VK_INDEX_TYPE_UINT32);
60 const auto&
submesh = _submeshes.at(submesh_index);
65 auto submeshes()
const noexcept ->
const std::vector<submesh>& {
72 : _vertex_buffer{
nullptr},
73 _index_buffer{
nullptr} { }
75 auto _upload_vertices(std::vector<vertex_type>&& vertices, std::vector<index_type>&& indices) ->
void {
76 auto vertex_buffer_size =
sizeof(vertex_type) * vertices.size();
77 auto index_buffer_size =
sizeof(index_type) * indices.size();
79 auto staging_buffer_size = vertex_buffer_size + index_buffer_size;
85 staging_buffer.write(indices.data(), index_buffer_size, vertex_buffer_size);
87 _vertex_buffer = std::make_unique<vertex_buffer_type>(vertices.size());
88 _index_buffer = std::make_unique<index_buffer_type>(indices.size());
93 auto copy_region = VkBufferCopy{};
94 copy_region.size = vertex_buffer_size;
95 copy_region.dstOffset = 0;
96 copy_region.srcOffset = 0;
102 auto copy_region = VkBufferCopy{};
103 copy_region.size = index_buffer_size;
104 copy_region.dstOffset = 0;
105 copy_region.srcOffset = vertex_buffer_size;
113 std::unique_ptr<vertex_buffer_type> _vertex_buffer{};
114 std::unique_ptr<index_buffer_type> _index_buffer{};
115 std::vector<submesh> _submeshes{};
Definition: buffer.hpp:51
Definition: command_buffer.hpp:14