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
25
26const std::array kTriangleVertices = {
27 Vertex{.pos = {0.0f, -0.5f, 0.0f}, .normal = {1.0f, 0.0f, 0.0f}},
28 Vertex{.pos = {0.5f, 0.5f, 0.0f}, .normal = {0.0f, 1.0f, 0.0f}},
29 Vertex{.pos = {-0.5f, 0.5f, 0.0f}, .normal = {0.0f, 0.0f, 1.0f}},
30};
31
32const std::array kQuadVertices = {
33 Vertex{.pos = {-0.5f, -0.5f, 0.0f}, .normal = {1.0f, 0.0f, 0.0f}},
34 Vertex{.pos = {0.5f, -0.5f, 0.0f}, .normal = {0.0f, 1.0f, 0.0f}},
35 Vertex{.pos = {0.5f, 0.5f, 0.0f}, .normal = {0.0f, 0.0f, 1.0f}},
36 Vertex{.pos = {-0.5f, 0.5f, 0.0f}, .normal = {1.0f, 1.0f, 1.0f}}};
37
38const std::vector<uint16_t> kQuadIndices = {0, 1, 2, 2, 3, 0};
39
40class Mesh {
41 public:
42 Mesh() = default;
43
44 Mesh(const vulkan::Device& device, VmaAllocator allocator);
45 Mesh(const std::vector<Vertex>& vertices,
46 const std::vector<uint16_t>& indices);
47
48 void load(const vulkan::Device& device, VmaAllocator allocator);
49
50 void shader(const std::shared_ptr<vk::Shader>& shader) { shader_ = shader; }
51 void draw(const ::vk::CommandBuffer& cmd) const;
52 void bind(const ::vk::CommandBuffer& cmd) const;
53
54 [[nodiscard]] auto loaded() const { return loaded_; }
55
56 private:
57 bool loaded_ = false;
58
59 std::shared_ptr<vk::Shader> shader_;
60 std::vector<Vertex> vertices_;
61 std::vector<uint16_t> indices_;
62 std::shared_ptr<vk::Buffer> index_buffer_;
63 std::shared_ptr<vk::Buffer> vertex_buffer_;
64 std::shared_ptr<vk::Buffer> uniform_buffer_;
65};
66
67} // namespace wren
Definition mesh.hpp:40
std::shared_ptr< vk::Buffer > uniform_buffer_
Definition mesh.hpp:64
void bind(const ::vk::CommandBuffer &cmd) const
Definition mesh.cpp:79
bool loaded_
Definition mesh.hpp:57
std::shared_ptr< vk::Shader > shader_
Definition mesh.hpp:59
void load(const vulkan::Device &device, VmaAllocator allocator)
Definition mesh.cpp:19
std::shared_ptr< vk::Buffer > index_buffer_
Definition mesh.hpp:62
void shader(const std::shared_ptr< vk::Shader > &shader)
Definition mesh.hpp:50
auto loaded() const
Definition mesh.hpp:54
std::vector< Vertex > vertices_
Definition mesh.hpp:60
void draw(const ::vk::CommandBuffer &cmd) const
Definition mesh.cpp:75
std::shared_ptr< vk::Buffer > vertex_buffer_
Definition mesh.hpp:63
std::vector< uint16_t > indices_
Definition mesh.hpp:61
Mesh()=default
Definition device.hpp:9
Definition editor_scene.hpp:5
const std::array kQuadVertices
Definition mesh.hpp:32
const std::array kTriangleVertices
Definition mesh.hpp:26
const std::vector< uint16_t > kQuadIndices
Definition mesh.hpp:38
Definition mesh.hpp:16
wren::math::Mat4f model
Definition mesh.hpp:17
Definition mesh.hpp:20
wren::math::Vec4f colour
Definition mesh.hpp:23
wren::math::Vec3f normal
Definition mesh.hpp:22
wren::math::Vec3f pos
Definition mesh.hpp:21
Definition matrix.hpp:86
Definition vector.hpp:133
Definition vector.hpp:154