public static VertexInputLayout New(VertexInputElement[] elements) { VertexInputLayout layout; if (layoutCache.TryGetValue(elements, out layout)) { return(layout); } var sortedElements = (VertexInputElement[])elements.Clone(); Array.Sort(sortedElements, CompareVertexInputElement); if (layoutCache.TryGetValue(sortedElements, out layout)) { return(layout); } var attributeMask = 0; foreach (var e in sortedElements) { attributeMask |= 1 << e.Attribute; } layout = new VertexInputLayout { Elements = sortedElements, AttribMask = attributeMask }; layoutCache.Add(sortedElements, layout); return(layout); }
private void UpdateInputLayout() { if (inputLayout == null || (DirtyFlags & MeshDirtyFlags.AttributeLocations) != 0) { var elements = new List <VertexInputElement>(); var stride = Toolbox.SizeOf <T>(); foreach (var elementDescription in GetElementDescriptions()) { elements.Add(new VertexInputElement { Slot = 0, Attribute = AttributeLocations[elements.Count], Stride = stride, Offset = elementDescription.Offset, Format = elementDescription.Format, }); } inputLayout = VertexInputLayout.New(elements.ToArray()); DirtyFlags &= ~MeshDirtyFlags.AttributeLocations; } }
private void UpdateInputLayout() { if (inputLayout == null || (DirtyFlags & MeshDirtyFlags.AttributeLocations) != 0) { var bindings = new[] { new VertexInputLayoutBinding { Slot = 0, Stride = sizeof(T) } }; var attributes = new List <VertexInputLayoutAttribute>(); foreach (var elementDescription in GetElementDescriptions()) { attributes.Add(new VertexInputLayoutAttribute { Slot = 0, Location = AttributeLocations[attributes.Count], Offset = elementDescription.Offset, Format = elementDescription.Format, }); } inputLayout = VertexInputLayout.New(bindings, attributes.ToArray()); DirtyFlags &= ~MeshDirtyFlags.AttributeLocations; } }
public static VertexInputLayout New(VertexInputLayoutBinding[] bindings, VertexInputLayoutAttribute[] attributes) { lock (layoutCache) { if (sortedBindings == null || sortedBindings.Length < bindings.Length) { sortedBindings = new VertexInputLayoutBinding[bindings.Length]; } if (sortedAttributes == null || sortedAttributes.Length < attributes.Length) { sortedAttributes = new VertexInputLayoutAttribute[attributes.Length]; } Array.Copy(bindings, sortedBindings, bindings.Length); Array.Copy(attributes, sortedAttributes, attributes.Length); Array.Sort(sortedBindings, 0, bindings.Length, bindingSortComparer); Array.Sort(sortedAttributes, 0, attributes.Length, attributeSortComparer); var hash = ComputeHash(sortedBindings, bindings.Length, sortedAttributes, attributes.Length); if (!layoutCache.TryGetValue(hash, out var layout)) { layout = new VertexInputLayout(sortedBindings, bindings.Length, sortedAttributes, attributes.Length); layoutCache.Add(hash, layout); } return(layout); } }
public static void SetVertexInputLayout(VertexInputLayout layout) { Context.SetVertexInputLayout(layout?.GetPlatformLayout()); }