/// <summary> /// Initializes a new instance of the <see cref="VertexInputLayout" />. /// </summary> /// <param name="layouts">A set of description of input layout for each slots in input-assembler stage.</param> /// <returns>A new instance of <see cref="VertexInputLayout"/>.</returns> public static VertexInputLayout New(params VertexBufferLayout[] layouts) { // Make sure that the original buffer won't be modified, so we make a copy. var layoutCopy = new VertexBufferLayout[layouts.Length]; Array.Copy(layouts, layoutCopy, layouts.Length); // Create a readonly array. var vertexBufferLayouts = new ReadOnlyArray <VertexBufferLayout>(layoutCopy); // Register a unique VertexInputLayout. lock (VertexBufferBindingCache) { VertexInputLayout vertexInputLayout; if (!VertexBufferBindingCache.TryGetValue(vertexBufferLayouts, out vertexInputLayout)) { vertexInputLayout = new VertexInputLayout(VertexBufferBindingCache.Count, vertexBufferLayouts); VertexBufferBindingCache.Add(vertexBufferLayouts, vertexInputLayout); } return(vertexInputLayout); } }
/// <summary> /// Initializes a new instance of the <see cref="VertexInputLayout" /> with a single slot from a structure that is using <see cref="VertexElementAttribute"/>. /// </summary> /// <typeparam name="T">Type of a structure that is using <see cref="VertexElementAttribute" />.</typeparam> /// <param name="slot">The slot index in the input-assembler stage.</param> /// <returns>A new instance of <see cref="VertexInputLayout"/>.</returns> public static VertexInputLayout FromBuffer <T>(int slot, Buffer <T> buffer) where T : struct { return(New(VertexBufferLayout.New(slot, typeof(T)))); }
/// <summary> /// Initializes a new instance of the <see cref="VertexInputLayout" /> with a single slot. /// </summary> /// <param name="slot">The slot index in the input-assembler stage.</param> /// <param name="vertexElements">Description of vertex elements.</param> /// <returns>A new instance of <see cref="VertexInputLayout"/>.</returns> public static VertexInputLayout New(int slot, params VertexElement[] vertexElements) { return(New(VertexBufferLayout.New(slot, vertexElements))); }
/// <summary> /// Initializes a new instance of the <see cref="VertexInputLayout" /> with a single slot from a structure that is using <see cref="VertexElementAttribute"/>. /// </summary> /// <param name="slot">The slot index in the input-assembler stage.</param> /// <param name="structType">Type of a structure that is using <see cref="VertexElementAttribute" />.</param> /// <returns>A new instance of <see cref="VertexInputLayout"/>.</returns> public static VertexInputLayout New(int slot, Type structType) { return(New(VertexBufferLayout.New(slot, structType))); }