2022-02-23 05:14:32 +00:00
|
|
|
|
namespace MoonWorks.Graphics
|
2021-01-20 03:33:27 +00:00
|
|
|
|
{
|
2022-02-23 05:14:32 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Specifies how to interpet vertex data in a buffer to be passed to the vertex shader.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public struct VertexInputState
|
|
|
|
|
{
|
|
|
|
|
public VertexBinding[] VertexBindings;
|
|
|
|
|
public VertexAttribute[] VertexAttributes;
|
2022-03-02 21:57:30 +00:00
|
|
|
|
|
2022-06-20 20:04:44 +00:00
|
|
|
|
public static readonly VertexInputState Empty = new VertexInputState
|
2022-05-13 23:26:26 +00:00
|
|
|
|
{
|
2023-01-05 01:34:01 +00:00
|
|
|
|
VertexBindings = System.Array.Empty<VertexBinding>(),
|
|
|
|
|
VertexAttributes = System.Array.Empty<VertexAttribute>()
|
2022-06-20 20:04:44 +00:00
|
|
|
|
};
|
2022-05-13 23:26:26 +00:00
|
|
|
|
|
2022-03-02 21:57:30 +00:00
|
|
|
|
public VertexInputState(
|
|
|
|
|
VertexBinding vertexBinding,
|
2023-01-05 01:34:01 +00:00
|
|
|
|
VertexAttribute[] vertexAttributes
|
2022-03-02 21:57:30 +00:00
|
|
|
|
) {
|
|
|
|
|
VertexBindings = new VertexBinding[] { vertexBinding };
|
|
|
|
|
VertexAttributes = vertexAttributes;
|
|
|
|
|
}
|
2023-01-05 01:34:01 +00:00
|
|
|
|
|
|
|
|
|
public VertexInputState(
|
|
|
|
|
VertexBinding[] vertexBindings,
|
|
|
|
|
VertexAttribute[] vertexAttributes
|
|
|
|
|
) {
|
|
|
|
|
VertexBindings = vertexBindings;
|
|
|
|
|
VertexAttributes = vertexAttributes;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-05 21:41:48 +00:00
|
|
|
|
public VertexInputState(
|
|
|
|
|
VertexBindingAndAttributes bindingAndAttributes
|
|
|
|
|
) {
|
|
|
|
|
VertexBindings = new VertexBinding[] { bindingAndAttributes.VertexBinding };
|
|
|
|
|
VertexAttributes = bindingAndAttributes.VertexAttributes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VertexInputState(
|
|
|
|
|
VertexBindingAndAttributes[] bindingAndAttributesArray
|
|
|
|
|
) {
|
|
|
|
|
VertexBindings = new VertexBinding[bindingAndAttributesArray.Length];
|
|
|
|
|
var attributesLength = 0;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < bindingAndAttributesArray.Length; i += 1)
|
|
|
|
|
{
|
|
|
|
|
VertexBindings[i] = bindingAndAttributesArray[i].VertexBinding;
|
|
|
|
|
attributesLength += bindingAndAttributesArray[i].VertexAttributes.Length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VertexAttributes = new VertexAttribute[attributesLength];
|
|
|
|
|
|
|
|
|
|
var attributeIndex = 0;
|
|
|
|
|
for (var i = 0; i < bindingAndAttributesArray.Length; i += 1)
|
|
|
|
|
{
|
|
|
|
|
for (var j = 0; j < bindingAndAttributesArray[i].VertexAttributes.Length; j += 1)
|
|
|
|
|
{
|
|
|
|
|
VertexAttributes[attributeIndex] = bindingAndAttributesArray[i].VertexAttributes[j];
|
|
|
|
|
attributeIndex += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-05 01:34:01 +00:00
|
|
|
|
public static VertexInputState CreateSingleBinding<T>() where T : unmanaged, IVertexType
|
|
|
|
|
{
|
2023-01-05 21:41:48 +00:00
|
|
|
|
return new VertexInputState(VertexBindingAndAttributes.Create<T>(0));
|
2023-01-05 01:34:01 +00:00
|
|
|
|
}
|
2022-02-23 05:14:32 +00:00
|
|
|
|
}
|
2021-01-20 03:33:27 +00:00
|
|
|
|
}
|