74 lines
2.7 KiB
C++
74 lines
2.7 KiB
C++
#include "vertex.hpp"
|
|
|
|
#include <vulkan/vulkan_core.h>
|
|
#include <gz-util/util/string_conversion.hpp>
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
namespace gz::vk {
|
|
const uint32_t BINDING = 0;
|
|
|
|
template<GLM_vec2_or_3 PosVec>
|
|
VkFormat getVkFormat() {
|
|
if (std::same_as<PosVec, glm::vec3>) {
|
|
return VK_FORMAT_R32G32B32_SFLOAT;
|
|
}
|
|
else if (std::same_as<PosVec, glm::vec2>) {
|
|
return VK_FORMAT_R32G32_SFLOAT;
|
|
}
|
|
}
|
|
|
|
|
|
//
|
|
// 3D VERTEX
|
|
//
|
|
template<GLM_vec2_or_3 PosVec>
|
|
std::string Vertex<PosVec>::toString() const {
|
|
return "pos: <" + gz::toString(pos) + ", color: " + gz::toString(color) + ", texCoords: " + gz::toString(texCoord) + ">";
|
|
};
|
|
|
|
|
|
template<GLM_vec2_or_3 PosVec>
|
|
VkVertexInputBindingDescription Vertex<PosVec>::getBindingDescription() {
|
|
VkVertexInputBindingDescription bindingD{};
|
|
bindingD.binding = BINDING;
|
|
bindingD.stride = sizeof(Vertex<PosVec>);
|
|
bindingD.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
|
|
return bindingD;
|
|
}
|
|
|
|
template<GLM_vec2_or_3 PosVec>
|
|
std::array<VkVertexInputAttributeDescription, 3> Vertex<PosVec>::getAttributeDescriptions() {
|
|
std::array<VkVertexInputAttributeDescription, 3> inputAttributeD{};
|
|
inputAttributeD[0].binding = BINDING;
|
|
inputAttributeD[0].location = 0;
|
|
inputAttributeD[0].format = getVkFormat<PosVec>();
|
|
inputAttributeD[0].offset = offsetof(Vertex, pos);
|
|
inputAttributeD[1].binding = BINDING;
|
|
inputAttributeD[1].location = 1;
|
|
inputAttributeD[1].format = VK_FORMAT_R32G32B32_SFLOAT;
|
|
inputAttributeD[1].offset = offsetof(Vertex, color);
|
|
inputAttributeD[2].binding = BINDING;
|
|
inputAttributeD[2].location = 2;
|
|
inputAttributeD[2].format = VK_FORMAT_R32G32_SFLOAT;
|
|
inputAttributeD[2].offset = offsetof(Vertex, texCoord);
|
|
|
|
return inputAttributeD;
|
|
}
|
|
|
|
template<GLM_vec2_or_3 PosVec>
|
|
bool Vertex<PosVec>::operator==(const Vertex<PosVec>& other) const {
|
|
return pos == other.pos and color == other.color and texCoord == other.texCoord;
|
|
}
|
|
|
|
template std::string Vertex<glm::vec2>::toString() const;
|
|
template std::string Vertex<glm::vec3>::toString() const;
|
|
template VkVertexInputBindingDescription Vertex<glm::vec2>::getBindingDescription();
|
|
template VkVertexInputBindingDescription Vertex<glm::vec3>::getBindingDescription();
|
|
template std::array<VkVertexInputAttributeDescription, 3> Vertex<glm::vec2>::getAttributeDescriptions();
|
|
template std::array<VkVertexInputAttributeDescription, 3> Vertex<glm::vec3>::getAttributeDescriptions();
|
|
template bool Vertex<glm::vec2>::operator==(const Vertex<glm::vec2>& other) const;
|
|
template bool Vertex<glm::vec3>::operator==(const Vertex<glm::vec3>& other) const;
|
|
|
|
} // namespace gz::vk
|