wren
Vulkan-based game engine
Toggle main menu visibility
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>
7
#include <
wren/math/matrix.hpp
>
8
#include <
wren/math/vector.hpp
>
9
#include <
wren/vk/buffer.hpp
>
10
#include <
wren/vk/shader.hpp
>
11
12
#include "
utils/device.hpp
"
13
14
namespace
wren
{
15
16
struct
UBO
{
17
wren::math::Mat4f
model
;
18
};
19
20
struct
Vertex
{
21
wren::math::Vec3f
pos
;
22
wren::math::Vec3f
normal
;
23
wren::math::Vec4f
colour
;
24
};
25
26
const
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
32
const
std::array
kQuadVertices
= {
33
Vertex
{
34
.pos = {-0.5f, -0.5f, 0.0f},
35
.normal = {1.0f, 0.0f, 0.0f},
36
.colour = {1, 1, 1, 1},
37
},
38
Vertex
{
39
.pos = {0.5f, -0.5f, 0.0f},
40
.normal = {0.0f, 1.0f, 0.0f},
41
.colour = {1, 1, 1, 1},
42
},
43
Vertex
{
44
.pos = {0.5f, 0.5f, 0.0f},
45
.normal = {0.0f, 0.0f, 1.0f},
46
.colour = {1, 1, 1, 1},
47
},
48
Vertex
{
49
.pos = {-0.5f, 0.5f, 0.0f},
50
.normal = {1.0f, 1.0f, 1.0f},
51
.colour = {1, 1, 1, 1},
52
},
53
};
54
55
const
std::vector<uint16_t>
kQuadIndices
= {0, 2, 1, 0, 3, 2};
56
57
class
Mesh
{
58
public
:
59
static
auto
create_quad
() ->
Mesh
{
60
return
{std::vector<Vertex>{
kQuadVertices
.begin(),
kQuadVertices
.end()},
61
std::vector<uint16_t>{
kQuadIndices
.begin(),
kQuadIndices
.end()}};
62
}
63
64
Mesh
() =
default
;
65
66
Mesh
(
const
vulkan::Device
& device, VmaAllocator allocator);
67
Mesh
(
const
std::vector<Vertex>& vertices,
68
const
std::vector<uint16_t>& indices);
69
70
void
load
(
const
vulkan::Device
& device, VmaAllocator allocator);
71
72
void
shader
(
const
std::shared_ptr<vk::Shader>&
shader
) {
shader_
=
shader
; }
73
void
draw
(const ::vk::CommandBuffer& cmd)
const
;
74
void
bind
(const ::vk::CommandBuffer& cmd)
const
;
75
76
[[nodiscard]]
auto
loaded
()
const
{
return
loaded_
; }
77
78
private
:
79
bool
loaded_
=
false
;
80
81
std::shared_ptr<vk::Shader>
shader_
;
82
std::vector<Vertex>
vertices_
;
83
std::vector<uint16_t>
indices_
;
84
std::shared_ptr<vk::Buffer>
index_buffer_
;
85
std::shared_ptr<vk::Buffer>
vertex_buffer_
;
86
std::shared_ptr<vk::Buffer>
uniform_buffer_
;
87
};
88
89
}
// namespace wren
buffer.hpp
wren::Mesh::create_quad
static auto create_quad() -> Mesh
Definition
mesh.hpp:59
wren::Mesh::uniform_buffer_
std::shared_ptr< vk::Buffer > uniform_buffer_
Definition
mesh.hpp:86
wren::Mesh::bind
void bind(const ::vk::CommandBuffer &cmd) const
Definition
mesh.cpp:79
wren::Mesh::loaded_
bool loaded_
Definition
mesh.hpp:79
wren::Mesh::shader_
std::shared_ptr< vk::Shader > shader_
Definition
mesh.hpp:81
wren::Mesh::load
void load(const vulkan::Device &device, VmaAllocator allocator)
Definition
mesh.cpp:19
wren::Mesh::index_buffer_
std::shared_ptr< vk::Buffer > index_buffer_
Definition
mesh.hpp:84
wren::Mesh::shader
void shader(const std::shared_ptr< vk::Shader > &shader)
Definition
mesh.hpp:72
wren::Mesh::loaded
auto loaded() const
Definition
mesh.hpp:76
wren::Mesh::vertices_
std::vector< Vertex > vertices_
Definition
mesh.hpp:82
wren::Mesh::draw
void draw(const ::vk::CommandBuffer &cmd) const
Definition
mesh.cpp:75
wren::Mesh::vertex_buffer_
std::shared_ptr< vk::Buffer > vertex_buffer_
Definition
mesh.hpp:85
wren::Mesh::indices_
std::vector< uint16_t > indices_
Definition
mesh.hpp:83
wren::Mesh::Mesh
Mesh()=default
wren::vulkan::Device
Definition
device.hpp:9
device.hpp
matrix.hpp
wren
Definition
editor_scene.hpp:5
wren::kQuadVertices
const std::array kQuadVertices
Definition
mesh.hpp:32
wren::kTriangleVertices
const std::array kTriangleVertices
Definition
mesh.hpp:26
wren::kQuadIndices
const std::vector< uint16_t > kQuadIndices
Definition
mesh.hpp:55
shader.hpp
wren::UBO
Definition
mesh.hpp:16
wren::UBO::model
wren::math::Mat4f model
Definition
mesh.hpp:17
wren::Vertex
Definition
mesh.hpp:20
wren::Vertex::colour
wren::math::Vec4f colour
Definition
mesh.hpp:23
wren::Vertex::normal
wren::math::Vec3f normal
Definition
mesh.hpp:22
wren::Vertex::pos
wren::math::Vec3f pos
Definition
mesh.hpp:21
wren::math::Mat4f
Definition
matrix.hpp:86
wren::math::Vec3f
Definition
vector.hpp:174
wren::math::Vec4f
Definition
vector.hpp:192
vector.hpp
wren
include
wren
mesh.hpp
Generated by
1.17.0