From dc47958774f253ee40ad705259bb9aca2cfb6d32 Mon Sep 17 00:00:00 2001
From: Alexander Gauggel <agauggel@uni-koblenz.de>
Date: Sat, 29 May 2021 22:57:25 +0200
Subject: [PATCH] [#33] Add VertexInput to vk::Format conversion

---
 include/vkcv/VertexLayout.hpp |  4 +++-
 src/vkcv/PipelineManager.cpp  |  2 +-
 src/vkcv/VertexLayout.cpp     | 14 ++++++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/include/vkcv/VertexLayout.hpp b/include/vkcv/VertexLayout.hpp
index f9579b5d..fceaa9cf 100644
--- a/include/vkcv/VertexLayout.hpp
+++ b/include/vkcv/VertexLayout.hpp
@@ -3,6 +3,7 @@
 #include <unordered_map>
 #include <vector>
 #include <iostream>
+#include <vulkan/vulkan.hpp>
 
 namespace vkcv{
     enum class VertexFormat{
@@ -33,5 +34,6 @@ namespace vkcv{
         uint32_t stride;
     };
 
-
+	// currently assuming default 32 bit formats, no lower precision or normalized variants supported
+	vk::Format vertexFormatToVulkanFormat(const VertexFormat format);
 }
\ No newline at end of file
diff --git a/src/vkcv/PipelineManager.cpp b/src/vkcv/PipelineManager.cpp
index d591d8fb..2385975c 100644
--- a/src/vkcv/PipelineManager.cpp
+++ b/src/vkcv/PipelineManager.cpp
@@ -79,7 +79,7 @@ namespace vkcv
             uint32_t location = attachment.second.location;
             uint32_t binding = attachment.second.binding;
             uint32_t offset = attachment.second.offset;
-            VertexFormat format = attachment.second.format;    // TODO: Format -> Where does this belong? -> This is not compatible with vk::Format
+            vk::Format vertexFormat = vertexFormatToVulkanFormat(attachment.second.format);
             vertexBindingDescriptions.push_back({binding, layout.stride, vk::VertexInputRate::eVertex}); // TODO: What's about the input rate?
             vertexAttributeDescriptions.push_back({location, binding, vk::Format::eR32G32B32Sfloat, offset});
         }
diff --git a/src/vkcv/VertexLayout.cpp b/src/vkcv/VertexLayout.cpp
index 88c9406b..ef2fedf6 100644
--- a/src/vkcv/VertexLayout.cpp
+++ b/src/vkcv/VertexLayout.cpp
@@ -50,4 +50,18 @@ namespace vkcv {
         }
     }
 
+	vk::Format vertexFormatToVulkanFormat(const VertexFormat format) {
+		switch (format) {
+			case VertexFormat::FLOAT	: return vk::Format::eR32Sfloat;
+			case VertexFormat::FLOAT2	: return vk::Format::eR32G32Sfloat;
+			case VertexFormat::FLOAT3	: return vk::Format::eR32G32B32Sfloat;
+			case VertexFormat::FLOAT4	: return vk::Format::eR32G32B32A32Sfloat;
+			case VertexFormat::INT		: return vk::Format::eR32Sint;
+			case VertexFormat::INT2		: return vk::Format::eR32G32Sint;
+			case VertexFormat::INT3		: return vk::Format::eR32G32B32Sint;
+			case VertexFormat::INT4		: return vk::Format::eR32G32B32A32Sint;
+			default: std::cerr << "Warning: Unknown vertex format" << std::endl; return vk::Format::eUndefined;
+		}
+	}
+
 }
\ No newline at end of file
-- 
GitLab