-
-
Notifications
You must be signed in to change notification settings - Fork 938
/
VertexBufferBindingExtensions.cs
56 lines (51 loc) · 2.38 KB
/
VertexBufferBindingExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
namespace Stride.Graphics
{
public static class VertexBufferBindingExtensions
{
public static InputElementDescription[] CreateInputElements(this VertexDeclaration vertexDeclaration)
{
var inputElements = new InputElementDescription[vertexDeclaration.VertexElements.Length];
var inputElementIndex = 0;
foreach (var element in vertexDeclaration.EnumerateWithOffsets())
{
inputElements[inputElementIndex++] = new InputElementDescription
{
SemanticName = element.VertexElement.SemanticName,
SemanticIndex = element.VertexElement.SemanticIndex,
Format = element.VertexElement.Format,
InputSlot = 0,
AlignedByteOffset = element.Offset,
};
}
return inputElements;
}
public static InputElementDescription[] CreateInputElements(this VertexBufferBinding[] vertexBuffers)
{
var inputElementCount = 0;
foreach (var vertexBuffer in vertexBuffers)
{
inputElementCount += vertexBuffer.Declaration.VertexElements.Length;
}
var inputElements = new InputElementDescription[inputElementCount];
var inputElementIndex = 0;
for (int inputSlot = 0; inputSlot < vertexBuffers.Length; inputSlot++)
{
var vertexBuffer = vertexBuffers[inputSlot];
foreach (var element in vertexBuffer.Declaration.EnumerateWithOffsets())
{
inputElements[inputElementIndex++] = new InputElementDescription
{
SemanticName = element.VertexElement.SemanticName,
SemanticIndex = element.VertexElement.SemanticIndex,
Format = element.VertexElement.Format,
InputSlot = inputSlot,
AlignedByteOffset = element.Offset,
};
}
}
return inputElements;
}
}
}