sandbox
Loading...
Searching...
No Matches
vertex3d.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_ANIMATIONS_VERTEX3D_HPP_
3#define LIBSBX_ANIMATIONS_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::animations {
15
16struct alignas(alignof(std::float_t)) vertex3d {
17 math::vector3 position;
18 math::vector3 normal;
20 math::vector4 tangent;
21 math::vector4u bone_ids;
22 math::vector4 bone_weights;
23}; // struct vertex
24
25static_assert(sizeof(vertex3d) == 80, "Incorrect sbx::animations::vertex3d size");
26static_assert(alignof(vertex3d) == 4, "Incorrect sbx::animations::vertex3d alignment");
27
28constexpr auto operator==(const vertex3d& lhs, const vertex3d& rhs) noexcept -> bool {
29 return lhs.position == rhs.position && lhs.normal == rhs.normal && lhs.tangent == rhs.tangent && lhs.uv == rhs.uv && lhs.bone_ids == rhs.bone_ids && lhs.bone_weights == rhs.bone_weights;
30}
31
32} // namespace sbx::animation
33
34template<>
36 static auto description() -> sbx::graphics::vertex_input_description {
37 auto result = vertex_input_description{};
38
39 result.binding_descriptions.push_back(VkVertexInputBindingDescription{
40 .binding = 0,
41 .stride = sizeof(sbx::animations::vertex3d),
42 .inputRate = VK_VERTEX_INPUT_RATE_VERTEX
43 });
44
45 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
46 .location = 0,
47 .binding = 0,
48 .format = VK_FORMAT_R32G32B32_SFLOAT,
49 .offset = offsetof(sbx::animations::vertex3d, position)
50 });
51
52 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
53 .location = 1,
54 .binding = 0,
55 .format = VK_FORMAT_R32G32B32_SFLOAT,
56 .offset = offsetof(sbx::animations::vertex3d, normal)
57 });
58
59 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
60 .location = 2,
61 .binding = 0,
62 .format = VK_FORMAT_R32G32B32A32_SFLOAT,
63 .offset = offsetof(sbx::animations::vertex3d, tangent)
64 });
65
66 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
67 .location = 3,
68 .binding = 0,
69 .format = VK_FORMAT_R32G32_SFLOAT,
70 .offset = offsetof(sbx::animations::vertex3d, uv)
71 });
72
73 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
74 .location = 4,
75 .binding = 0,
76 .format = VK_FORMAT_R32G32B32A32_UINT,
77 .offset = offsetof(sbx::animations::vertex3d, bone_ids)
78 });
79
80 result.attribute_descriptions.push_back(VkVertexInputAttributeDescription{
81 .location = 5,
82 .binding = 0,
83 .format = VK_FORMAT_R32G32B32_SFLOAT,
84 .offset = offsetof(sbx::animations::vertex3d, bone_weights)
85 });
86
87 return result;
88 }
89}; // struct sbx::graphics::vertex_input
90
91template<>
92struct std::hash<sbx::animations::vertex3d> {
93 auto operator()(const sbx::animations::vertex3d& vertex) const noexcept -> std::size_t {
94 auto hash = std::size_t{0};
95 sbx::utility::hash_combine(hash, vertex.position, vertex.normal, vertex.tangent, vertex.uv, vertex.bone_ids, vertex.bone_weights);
96 return hash;
97 }
98}; // struct std::hash<vertex3d>
99
100#endif // LIBSBX_ANIMATIONS_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: vertex3d.hpp:16
Definition: vertex_input_description.hpp:13
Definition: vertex_input_description.hpp:19