wren
Vulkan-based game engine
Loading...
Searching...
No Matches
mesh.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <vk_mem_alloc.h>
4#include <vulkan/vulkan_core.h>
5
6#include <vulkan/vulkan.hpp>
9#include <wren/vk/buffer.hpp>
10#include <wren/vk/shader.hpp>
11
12#include "utils/device.hpp"
13
14namespace wren {
15
19
24
25const std::array kTriangleVertices = {
26 Vertex{{0.0f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}},
27 Vertex{{0.5f, 0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}},
28 Vertex{{-0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}},
29};
30
31const std::array kQuadVertices = {
32 Vertex{{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}},
33 Vertex{{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}},
34 Vertex{{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}},
35 Vertex{{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}}};
36
37const std::vector<uint16_t> kQuadIndices = {0, 1, 2, 2, 3, 0};
38
39class Mesh {
40 public:
41 Mesh() = default;
42
43 Mesh(const vulkan::Device& device, VmaAllocator allocator);
44 Mesh(const std::vector<Vertex>& vertices,
45 const std::vector<uint16_t>& indices);
46
47 void load(const vulkan::Device& device, VmaAllocator allocator);
48
49 void shader(const std::shared_ptr<vk::Shader>& shader) { shader_ = shader; }
50 void draw(const ::vk::CommandBuffer& cmd) const;
51 void bind(const ::vk::CommandBuffer& cmd) const;
52
53 [[nodiscard]] auto loaded() const { return loaded_; }
54
55 private:
56 bool loaded_ = false;
57
58 std::shared_ptr<vk::Shader> shader_;
59 std::vector<Vertex> vertices_;
60 std::vector<uint16_t> indices_;
61 std::shared_ptr<vk::Buffer> index_buffer_;
62 std::shared_ptr<vk::Buffer> vertex_buffer_;
63 std::shared_ptr<vk::Buffer> uniform_buffer_;
64};
65
66} // namespace wren
Definition mesh.hpp:39
void bind(const ::vk::CommandBuffer &cmd) const
Definition mesh.cpp:79
void load(const vulkan::Device &device, VmaAllocator allocator)
Definition mesh.cpp:19
void shader(const std::shared_ptr< vk::Shader > &shader)
Definition mesh.hpp:49
auto loaded() const
Definition mesh.hpp:53
void draw(const ::vk::CommandBuffer &cmd) const
Definition mesh.cpp:75
Mesh()=default
Definition device.hpp:9
Definition editor.hpp:14
const std::array kQuadVertices
Definition mesh.hpp:31
const std::array kTriangleVertices
Definition mesh.hpp:25
const std::vector< uint16_t > kQuadIndices
Definition mesh.hpp:37
Definition mesh.hpp:16
wren::math::Mat4f model
Definition mesh.hpp:17
Definition mesh.hpp:20
wren::math::Vec3f pos
Definition mesh.hpp:21
wren::math::Vec3f colour
Definition mesh.hpp:22
Definition matrix.hpp:86
Definition vector.hpp:128