62 lines
1.8 KiB
C++
62 lines
1.8 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
|
|
{
|
|
enum class VertexStepMode : uint32_t { VERTEX = 0, INSTANCE };
|
|
|
|
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(static_cast<uint32_t>(location)), binding(binding), format(format), offset(offset)
|
|
{}
|
|
};
|
|
|
|
struct VertexInputDescription
|
|
{
|
|
uint32_t bindingId;
|
|
uint32_t vertexSize;
|
|
VertexStepMode stepMode = VertexStepMode::VERTEX;
|
|
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)
|
|
, stepMode(vertexDescription.stepMode)
|
|
, 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;
|
|
}
|
|
};
|
|
}
|