evan 2026.1.4
Evan
Loading...
Searching...
No Matches
GPUVertex.hpp
1/*
2** ETIB PROJECT, 2025
3** evan
4** File description:
5** GPUVertex
6*/
7
8#ifndef GPUVERTEX_HPP_
9#define GPUVERTEX_HPP_
10
11#include "evan/EvanPlatform.hpp"
12
13#include <utility/graphic/vertex.hpp>
14
15#include <glm/glm.hpp>
16
17namespace evan
18{
26 struct GPUInstance {
27 glm::mat4 model = glm::mat4(1.0f);
28 };
29
38 struct GPUVertex {
39 glm::vec3 pos;
40 glm::vec3 color;
42
46 glm::vec2 texCoord;
47
58 static VkVertexInputBindingDescription getBindingDescription()
59 {
60 VkVertexInputBindingDescription bindingDescription {};
61 bindingDescription.binding = 0;
62 bindingDescription.stride = sizeof(GPUVertex);
63 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
64
65 return bindingDescription;
66 }
67
79 static std::array<VkVertexInputAttributeDescription, 3>
81 {
82 std::array<VkVertexInputAttributeDescription, 3>
83 attributeDescriptions {};
84
85 attributeDescriptions[0].binding = 0;
86 attributeDescriptions[0].location = 0;
87 attributeDescriptions[0].format = VK_FORMAT_R32G32B32_SFLOAT;
88 attributeDescriptions[0].offset = offsetof(GPUVertex, pos);
89
90 attributeDescriptions[1].binding = 0;
91 attributeDescriptions[1].location = 1;
92 attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
93 attributeDescriptions[1].offset = offsetof(GPUVertex, color);
94
95 attributeDescriptions[2].binding = 0;
96 attributeDescriptions[2].location = 2;
97 attributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
98 attributeDescriptions[2].offset = offsetof(GPUVertex, texCoord);
99
100 return attributeDescriptions;
101 }
102
112 static VkVertexInputBindingDescription getInstanceBindingDescription()
113 {
114 VkVertexInputBindingDescription bindingDescription {};
115 bindingDescription.binding = 1;
116 bindingDescription.stride = sizeof(GPUInstance);
117 bindingDescription.inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
118
119 return bindingDescription;
120 }
121
131 static std::array<VkVertexInputAttributeDescription, 4>
133 {
134 std::array<VkVertexInputAttributeDescription, 4>
135 attributeDescriptions {};
136
137 for (std::size_t i = 0; i < 4; ++i) {
138 attributeDescriptions[i].binding = 1;
139 attributeDescriptions[i].location = static_cast<uint32_t>(3 + i);
140 attributeDescriptions[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
141 attributeDescriptions[i].offset =
142 static_cast<uint32_t>(i * sizeof(glm::vec4));
143 }
144
145 return attributeDescriptions;
146 }
147
160 bool operator==(const GPUVertex &other) const
161 {
162 return pos == other.pos && color == other.color
163 && texCoord == other.texCoord;
164 }
165
181 static GPUVertex
182 createFromVertex(const utility::graphic::VertexF &vertex)
183 {
184 auto color32Bit = vertex.getColor();
185 auto red = color32Bit.getRed() / 255.0f;
186 auto green = color32Bit.getGreen() / 255.0f;
187 auto blue = color32Bit.getBlue() / 255.0f;
188
189 return GPUVertex { glm::vec3(vertex.getPosition().x,
190 vertex.getPosition().y,
191 vertex.getPosition().z),
192 glm::vec3(red, green, blue),
193 glm::vec2(vertex.getTextureCoordinates().x,
194 vertex.getTextureCoordinates().y) };
195 }
196 };
197} // namespace evan
198
199#endif /* !GPUVERTEX_HPP_ */
Per-instance data fed to the vertex shader.
Definition GPUVertex.hpp:26
GPUVertex structure.
Definition GPUVertex.hpp:38
glm::vec2 texCoord
Texture coordinates of the vertex.
Definition GPUVertex.hpp:46
static VkVertexInputBindingDescription getBindingDescription()
Get the binding description for the vertex.
Definition GPUVertex.hpp:58
static std::array< VkVertexInputAttributeDescription, 4 > getInstanceAttributeDescriptions()
Get the attribute descriptions for per-instance data.
static GPUVertex createFromVertex(const utility::graphic::VertexF &vertex)
Create a GPUVertex from a utility::graphic::Vertex object.
glm::vec3 color
Definition GPUVertex.hpp:40
static std::array< VkVertexInputAttributeDescription, 3 > getAttributeDescriptions()
Get the attribute descriptions for the vertex.
Definition GPUVertex.hpp:80
static VkVertexInputBindingDescription getInstanceBindingDescription()
Get the binding description for per-instance data.
bool operator==(const GPUVertex &other) const
Equality operator for GPUVertex.
glm::vec3 pos
Position of the vertex.
Definition GPUVertex.hpp:39