Files
OpenVulkano/openVulkanoCpp/Scene/Shader/VertexInputDescription.hpp
2023-10-03 19:52:23 +02:00

57 lines
1.6 KiB
C++

/*
* 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"
#include <stdexcept>
#include <vector>
namespace OpenVulkano
{
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;
}
};
}