| Fling Engine 0.00.1 Fling Engine is a game engine written in Vulkan

Vertex.h
Go to the documentation of this file.
1 #pragma once
2
3 #include "FlingVulkan.h"
4
5 namespace Fling
6 {
10 struct Vertex
11 {
12 glm::vec3 Pos {};
13 glm::vec3 Color {};
14 glm::vec3 Tangent {};
15 glm::vec3 Normal {};
16 glm::vec2 TexCoord {};
17
18 bool operator==(const Vertex& other) const
19 {
20 return Pos == other.Pos && Color == other.Color && TexCoord == other.TexCoord && Tangent == other.Tangent;
21 }
22
26 static VkVertexInputBindingDescription GetBindingDescription()
27 {
28 VkVertexInputBindingDescription bindingDescription = {};
29 bindingDescription.binding = 0;
30 bindingDescription.stride = sizeof(Vertex);
31 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
32
33 return bindingDescription;
34 }
35
36 //#TODO Use shader reflection to get our bindings for this vertex instead
37 static std::array<VkVertexInputAttributeDescription, 5> GetAttributeDescriptions()
38 {
39 std::array<VkVertexInputAttributeDescription, 5> attributeDescriptions = {};
40
41 attributeDescriptions[0].binding = 0;
42 attributeDescriptions[0].location = 0;
43 attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
44 attributeDescriptions[0].offset = offsetof(Vertex, Pos);
45
46 attributeDescriptions[1].binding = 0;
47 attributeDescriptions[1].location = 1;
48 attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
49 attributeDescriptions[1].offset = offsetof(Vertex, Color);
50
51 attributeDescriptions[2].binding = 0;
52 attributeDescriptions[2].location = 2;
53 attributeDescriptions[2].format = VK_FORMAT_R32G32B32_SFLOAT;
54 attributeDescriptions[2].offset = offsetof(Vertex, Tangent);
55
56 attributeDescriptions[3].binding = 0;
57 attributeDescriptions[3].location = 3;
58 attributeDescriptions[3].format = VK_FORMAT_R32G32B32_SFLOAT;
59 attributeDescriptions[3].offset = offsetof(Vertex, Normal);
60
61 attributeDescriptions[4].binding = 0;
62 attributeDescriptions[4].location = 4;
63 attributeDescriptions[4].format = VK_FORMAT_R32G32_SFLOAT;
64 attributeDescriptions[4].offset = offsetof(Vertex, TexCoord);
65
66 return attributeDescriptions;
67 }
68
69 };
70 } // namespace Fling
71
72 // Hash function for a vertex so that we can put thing std::maps and what not
73 // @see https://vulkan-tutorial.com/Loading_models
74 namespace std
75 {
76 template<> struct hash<Fling::Vertex>
77 {
78 size_t operator()(Fling::Vertex const& vertex) const
79 {
80 return ((hash<glm::vec3>()(vertex.Pos) ^
81 (hash<glm::vec3>()(vertex.Color) << 1)) >> 1) ^
82 (hash<glm::vec2>()(vertex.TexCoord) << 1);
83 }
84 };
85 }
FlingVulkan.h
std
Definition: Vertex.h:74
Fling::Vertex::TexCoord
glm::vec2 TexCoord
Definition: Vertex.h:16
Fling::Vertex
Basic Vertex outline for use with our vertex buffers.
Definition: Vertex.h:10
Fling::Vertex::GetBindingDescription
static VkVertexInputBindingDescription GetBindingDescription()
Gets the shader binding of a vertex.
Definition: Vertex.h:26
Fling::Vertex::Normal
glm::vec3 Normal
Definition: Vertex.h:15
Fling::Vertex::Pos
glm::vec3 Pos
Definition: Vertex.h:12
Fling::Vertex::operator==
bool operator==(const Vertex &other) const
Definition: Vertex.h:18
Fling::Vertex::Color
glm::vec3 Color
Definition: Vertex.h:13
Fling::Vertex::GetAttributeDescriptions
static std::array< VkVertexInputAttributeDescription, 5 > GetAttributeDescriptions()
Definition: Vertex.h:37
Fling::Vertex::Tangent
glm::vec3 Tangent
Definition: Vertex.h:14
std::hash< Fling::Vertex >::operator()
size_t operator()(Fling::Vertex const &vertex) const
Definition: Vertex.h:78
Fling
Definition: Engine.h:29