sandbox
Loading...
Searching...
No Matches
vertex3d.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_MODELS_VERTEX3D_HPP_
3#define LIBSBX_MODELS_VERTEX3D_HPP_
4
5#include <utility>
6
7#include <libsbx/math/vector2.hpp>
8#include <libsbx/math/vector3.hpp>
9#include <libsbx/math/vector4.hpp>
10#include <libsbx/math/color.hpp>
11
12#include <libsbx/graphics/pipeline/vertex_input_description.hpp>
13
14namespace sbx::models {
15
16struct alignas(alignof(std::float_t)) vertex3d {
17 math::vector3 position;
18 math::vector3 normal;
20 math::vector4 tangent;
21}; // struct vertex
22
23static_assert(sizeof(vertex3d) == 48, "Incorrect sbx::models::vertex3d size");
24static_assert(alignof(vertex3d) == 4, "Incorrect sbx::models::vertex3d alignment");
25
26constexpr auto operator==(const vertex3d& lhs, const vertex3d& rhs) noexcept -> bool {
27 return lhs.position == rhs.position && lhs.normal == rhs.normal && lhs.tangent == rhs.tangent && lhs.uv == rhs.uv;
28}
29
30} // namespace sbx::models
31
32template<>
34 static auto description() -> sbx::graphics::vertex_input_description {
35 auto result = vertex_input_description{};
36
37 result.binding_descriptions.push_back(VkVertexInputBindingDescription{
38 .binding = 0,
39 .stride = sizeof(sbx::models::vertex3d),
40 .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
41 });
42
43 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
44 .location = 0,
45 .binding = 0,
46 .format = VK_FORMAT_R32G32B32_SFLOAT,
47 .offset = offsetof(sbx::models::vertex3d, position)
48 });
49
50 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
51 .location = 1,
52 .binding = 0,
53 .format = VK_FORMAT_R32G32B32_SFLOAT,
54 .offset = offsetof(sbx::models::vertex3d, normal)
55 });
56
57 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
58 .location = 2,
59 .binding = 0,
60 .format = VK_FORMAT_R32G32B32A32_SFLOAT,
61 .offset = offsetof(sbx::models::vertex3d, tangent)
62 });
63
64 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
65 .location = 3,
66 .binding = 0,
67 .format = VK_FORMAT_R32G32_SFLOAT,
68 .offset = offsetof(sbx::models::vertex3d, uv)
69 });
70
71 return result;
72 }
73}; // struct sbx::graphics::vertex_input
74
75template<>
76struct std::hash<sbx::models::vertex3d> {
77 auto operator()(const sbx::models::vertex3d& vertex) const noexcept -> std::size_t {
78 auto hash = std::size_t{0};
79 sbx::utility::hash_combine(hash, vertex.position, vertex.normal, vertex.tangent, vertex.uv);
80 return hash;
81 }
82}; // struct std::hash<vertex3d>
83
84#endif // LIBSBX_MODELS_VERTEX3D_HPP_
A vector in two-dimensional space.
Definition: vector2.hpp:28
Definition: vector3.hpp:23
Definition: vector4.hpp:24
RGBA color representation and utilities.
Definition: vertex_input_description.hpp:13
Definition: vertex_input_description.hpp:19
Definition: vertex3d.hpp:16