Move vertex input description out of VulkanShader
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "VulkanShader.hpp"
|
||||
#include "Vulkan/Context.hpp"
|
||||
#include "Scene/Vertex.hpp"
|
||||
#include "Scene/Shader.hpp"
|
||||
#include "Vulkan/Resources/IShaderOwner.hpp"
|
||||
|
||||
@@ -33,18 +32,39 @@ namespace openVulkanoCpp::Vulkan
|
||||
|
||||
void VulkanShader::BuildPipeline()
|
||||
{
|
||||
vk::VertexInputBindingDescription vertexBindDesc(0, sizeof(Vertex), vk::VertexInputRate::eVertex);
|
||||
std::vector<vk::VertexInputBindingDescription> vertexBindDesc;
|
||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions;
|
||||
attributeDescriptions.emplace_back(0, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, position));
|
||||
attributeDescriptions.emplace_back(1, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, normal));
|
||||
attributeDescriptions.emplace_back(2, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, tangent));
|
||||
attributeDescriptions.emplace_back(3, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, biTangent));
|
||||
attributeDescriptions.emplace_back(4, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, textureCoordinates));
|
||||
attributeDescriptions.emplace_back(5, 0, vk::Format::eR32G32B32A32Sfloat, offsetof(Vertex, color));
|
||||
vertexBindDesc.reserve(shader->vertexInputDescriptions.size());
|
||||
|
||||
for(const auto& description : shader->vertexInputDescriptions)
|
||||
{
|
||||
vertexBindDesc.emplace_back(description.bindingId, description.vertexSize, vk::VertexInputRate::eVertex);
|
||||
if (shader->vertexInputDescriptions.size() > 1)
|
||||
{
|
||||
for(const auto& param : description.inputParameters)
|
||||
{
|
||||
attributeDescriptions.push_back(reinterpret_cast<const vk::VertexInputAttributeDescription&>(param));
|
||||
}
|
||||
}
|
||||
}
|
||||
uint32_t attributeDescriptionsSize;
|
||||
vk::VertexInputAttributeDescription* attributeDescriptionsData;
|
||||
if (shader->vertexInputDescriptions.size() == 1)
|
||||
{ // Reuse already existing vertex attribute description
|
||||
static_assert(sizeof(VertexInputParameter) == sizeof(vk::VertexInputAttributeDescription));
|
||||
attributeDescriptionsSize = shader->vertexInputDescriptions[0].inputParameters.size();
|
||||
attributeDescriptionsData = reinterpret_cast<vk::VertexInputAttributeDescription*>(shader->vertexInputDescriptions[0].inputParameters.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
attributeDescriptionsSize = attributeDescriptions.size();
|
||||
attributeDescriptionsData = attributeDescriptions.data();
|
||||
}
|
||||
|
||||
vk::PipelineViewportStateCreateInfo viewportStateCreateInfo = { {}, 1, &context->swapChain.GetFullscreenViewport(), 1, &context->swapChain.GetFullscreenScissor() };
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = { {}, 1, &vertexBindDesc,
|
||||
static_cast<uint32_t>(attributeDescriptions.size()), attributeDescriptions.data() };
|
||||
vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = {
|
||||
{}, static_cast<uint32_t>(vertexBindDesc.size()), vertexBindDesc.data(),
|
||||
attributeDescriptionsSize, attributeDescriptionsData };
|
||||
vk::PipelineInputAssemblyStateCreateInfo inputAssembly = { {}, static_cast<vk::PrimitiveTopology>(shader->topology), 0 };
|
||||
vk::PipelineRasterizationStateCreateInfo rasterizer = {};
|
||||
rasterizer.cullMode = vk::CullModeFlagBits::eBack;
|
||||
|
||||
Reference in New Issue
Block a user