From 6e84ab3ad178f6a759e1ea2f99c9e64cdc284186 Mon Sep 17 00:00:00 2001 From: Mark Oliver Mints <mmints@uni-koblenz.de> Date: Tue, 10 Aug 2021 16:29:23 +0200 Subject: [PATCH] [#71] Refactor: implement a filling funtion for vertex binding description --- src/vkcv/PipelineManager.cpp | 50 +++++++++++++++++++++--------------- src/vkcv/PipelineManager.hpp | 5 ++++ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/vkcv/PipelineManager.cpp b/src/vkcv/PipelineManager.cpp index 0f53c1e5..f79e0e96 100644 --- a/src/vkcv/PipelineManager.cpp +++ b/src/vkcv/PipelineManager.cpp @@ -243,27 +243,7 @@ namespace vkcv // Fill up VertexInputBindingDescription and VertexInputAttributeDescription Containers std::vector<vk::VertexInputAttributeDescription> vertexAttributeDescriptions; std::vector<vk::VertexInputBindingDescription> vertexBindingDescriptions; - - if (existsVertexShader) { - const VertexLayout& layout = config.m_VertexLayout; - - // iterate over the layout's specified, mutually exclusive buffer bindings that make up a vertex buffer - for (const auto& vertexBinding : layout.vertexBindings) - { - vertexBindingDescriptions.emplace_back(vertexBinding.bindingLocation, - vertexBinding.stride, - vk::VertexInputRate::eVertex); - - // iterate over the bindings' specified, mutually exclusive vertex input attachments that make up a vertex - for (const auto& vertexAttachment : vertexBinding.vertexAttachments) - { - vertexAttributeDescriptions.emplace_back(vertexAttachment.inputLocation, - vertexBinding.bindingLocation, - vertexFormatToVulkanFormat(vertexAttachment.format), - vertexAttachment.offset % vertexBinding.stride); - } - } - } + fillVertexInputDescription(vertexAttributeDescriptions, vertexBindingDescriptions, existsVertexShader, config); // Handover Containers to PipelineVertexInputStateCreateIngo Struct vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( @@ -562,4 +542,32 @@ namespace vkcv vk::ShaderModuleCreateInfo moduleInfo({}, code.size(), reinterpret_cast<uint32_t*>(code.data())); return m_Device.createShaderModule(&moduleInfo, nullptr, &module); } + + void PipelineManager::fillVertexInputDescription( + std::vector<vk::VertexInputAttributeDescription> &vertexAttributeDescriptions, + std::vector<vk::VertexInputBindingDescription> &vertexBindingDescriptions, + const bool existsVertexShader, + const PipelineConfig &config) { + + if (existsVertexShader) { + const VertexLayout& layout = config.m_VertexLayout; + + // iterate over the layout's specified, mutually exclusive buffer bindings that make up a vertex buffer + for (const auto& vertexBinding : layout.vertexBindings) + { + vertexBindingDescriptions.emplace_back(vertexBinding.bindingLocation, + vertexBinding.stride, + vk::VertexInputRate::eVertex); + + // iterate over the bindings' specified, mutually exclusive vertex input attachments that make up a vertex + for (const auto& vertexAttachment : vertexBinding.vertexAttachments) + { + vertexAttributeDescriptions.emplace_back(vertexAttachment.inputLocation, + vertexBinding.bindingLocation, + vertexFormatToVulkanFormat(vertexAttachment.format), + vertexAttachment.offset % vertexBinding.stride); + } + } + } + } } diff --git a/src/vkcv/PipelineManager.hpp b/src/vkcv/PipelineManager.hpp index d3745bd9..94325566 100644 --- a/src/vkcv/PipelineManager.hpp +++ b/src/vkcv/PipelineManager.hpp @@ -23,6 +23,11 @@ namespace vkcv void destroyPipelineById(uint64_t id); vk::Result createShaderModule(vk::ShaderModule &module, const ShaderProgram &shaderProgram, ShaderStage stage); + void fillVertexInputDescription( + std::vector<vk::VertexInputAttributeDescription> &vertexAttributeDescriptions, + std::vector<vk::VertexInputBindingDescription> &vertexBindingDescriptions, + const bool existsVertexShader, + const PipelineConfig &config); public: PipelineManager() = delete; // no default ctor -- GitLab