Add VertexInputDescription

This commit is contained in:
2021-01-22 21:21:21 +01:00
parent 6953ba29c5
commit edb1d7518c

View File

@@ -0,0 +1,54 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "DataFormat.hpp"
namespace openVulkanoCpp
{
struct VertexInputParameter
{
uint32_t location;
uint32_t binding;
DataFormat format;
uint32_t offset;
VertexInputParameter(uint32_t location, uint32_t binding, DataFormat format, uint32_t offset)
: location(location), binding(binding), format(format), offset(offset)
{}
VertexInputParameter(size_t location, uint32_t binding, DataFormat format, uint32_t offset)
: location(location), binding(binding), format(format), offset(offset)
{}
};
struct VertexInputDescription
{
uint32_t bindingId;
uint32_t vertexSize;
std::vector<VertexInputParameter> inputParameters;
VertexInputDescription(uint32_t bindingId, uint32_t vertexSize) : bindingId(bindingId), vertexSize(vertexSize)
{}
VertexInputDescription(uint32_t bindingId, const VertexInputDescription& vertexDescription)
: bindingId(bindingId), vertexSize(vertexDescription.vertexSize), inputParameters(vertexDescription.inputParameters)
{
for (auto& param : inputParameters)
{
param.binding = bindingId;
}
}
VertexInputDescription& AddInputParameter(DataFormat format, uint32_t offset)
{
if (offset >= vertexSize) throw std::runtime_error("VertexInputParameter offset cannot be greater than vertex size");
inputParameters.emplace_back(inputParameters.size(), bindingId, format, offset);
return *this;
}
};
}