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