2023-01-05 21:41:48 +00:00
|
|
|
namespace MoonWorks.Graphics
|
|
|
|
{
|
2023-09-19 20:19:41 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A convenience structure for pairing a vertex binding with its associated attributes.
|
|
|
|
/// </summary>
|
2023-01-05 21:41:48 +00:00
|
|
|
public struct VertexBindingAndAttributes
|
|
|
|
{
|
|
|
|
public VertexBinding VertexBinding { get; }
|
|
|
|
public VertexAttribute[] VertexAttributes { get; }
|
|
|
|
|
|
|
|
public VertexBindingAndAttributes(VertexBinding binding, VertexAttribute[] attributes)
|
|
|
|
{
|
|
|
|
VertexBinding = binding;
|
|
|
|
VertexAttributes = attributes;
|
|
|
|
}
|
|
|
|
|
2024-01-27 03:44:19 +00:00
|
|
|
public static VertexBindingAndAttributes Create<T>(uint bindingIndex, uint locationOffset = 0, VertexInputRate inputRate = VertexInputRate.Vertex) where T : unmanaged, IVertexType
|
2023-01-05 21:41:48 +00:00
|
|
|
{
|
2024-01-27 03:44:19 +00:00
|
|
|
VertexBinding binding = VertexBinding.Create<T>(bindingIndex, inputRate);
|
2023-01-05 21:41:48 +00:00
|
|
|
VertexAttribute[] attributes = new VertexAttribute[T.Formats.Length];
|
|
|
|
uint offset = 0;
|
|
|
|
|
|
|
|
for (uint i = 0; i < T.Formats.Length; i += 1)
|
|
|
|
{
|
|
|
|
var format = T.Formats[i];
|
|
|
|
|
|
|
|
attributes[i] = new VertexAttribute
|
|
|
|
{
|
|
|
|
Binding = bindingIndex,
|
2024-01-27 03:44:19 +00:00
|
|
|
Location = locationOffset + i,
|
2023-01-05 21:41:48 +00:00
|
|
|
Format = format,
|
|
|
|
Offset = offset
|
|
|
|
};
|
|
|
|
|
|
|
|
offset += Conversions.VertexElementFormatSize(format);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new VertexBindingAndAttributes(binding, attributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|