1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#ifndef VULKAN_UTILS_HPP
#define VULKAN_UTILS_HPP
#include <cstddef>
#include <cstdint>
#include <ostream>
// I don't know if we should directly include vulkan or not
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include "math/vector.hpp"
#include "math/mat4.hpp"
#include "o3d/vertex.hpp"
namespace engine::vk {
struct api { uint32_t raw; };
constexpr std::ostream& operator<<(std::ostream& os, const api& api) {
// this code is unreadable but it amuses me
return (VK_API_VERSION_VARIANT(api.raw) == 0 ? os : os << "(variant "
<< VK_API_VERSION_VARIANT(api.raw) << ") ")
<< VK_API_VERSION_MAJOR (api.raw) << "."
<< VK_API_VERSION_MINOR (api.raw) << "."
<< VK_API_VERSION_PATCH (api.raw);
}
// TODO: we shouldn't have a struct specifically for vulkan vertices, it should be shared with the
// software renderer. But right now, they don't share the same infos, so that would make everything
// more complicated. Additionnaly, the way engine::o3d::Vertex is implemented right now locks
// precisely what can be send to the GPU, which is bad. Maybe we shouldn't have a general class like
// that, and lots of small classes for each specific case
struct Vertex {
static constexpr VkVertexInputBindingDescription get_binding_desc() {
return {
.binding = 0,
.stride = sizeof(Vertex),
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
};
}
static constexpr std::array<VkVertexInputAttributeDescription, 3> get_attr_descs() {
return {
VkVertexInputAttributeDescription {
.location = 0,
.binding = 0,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = offsetof(Vertex, pos),
},
VkVertexInputAttributeDescription {
.location = 1,
.binding = 0,
.format = VK_FORMAT_R32G32B32_SFLOAT,
.offset = offsetof(Vertex, col),
},
VkVertexInputAttributeDescription {
.location = 2,
.binding = 0,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = offsetof(Vertex, uv),
},
};
}
engine::math::Vector2 pos;
engine::math::Vector3 col;
engine::math::Vector2 uv;
};
// TODO: move to a better place. Also, see TODOs for struct Vertex
struct UniformBufferObject {
alignas(16) engine::math::Matrix4 model, view, proj;
};
}
#endif // VULKAN_UTILS_HPP
|