private static List <InterleavedSectionBase> ScanTypeSections() { List <InterleavedSectionBase> typeSections; // Determine array item size uint itemSize = (uint)Marshal.SizeOf(typeof(T)); if (_TypeSections.TryGetValue(typeof(T), out typeSections) == false) { // Cache for type typeSections = new List <InterleavedSectionBase>(); foreach (FieldInfo field in typeof(T).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { InterleavedSectionBase structSection = new InterleavedSectionBase(); structSection.ItemType = ArrayBufferItem.GetArrayType(field.FieldType); structSection.Normalized = false; structSection.Offset = Marshal.OffsetOf(typeof(T), field.Name); structSection.Stride = new IntPtr(itemSize); typeSections.Add(structSection); } _TypeSections.Add(typeof(T), typeSections); } return(typeSections); }
public InterleavedSection(ArrayBufferBase arrayBuffer, InterleavedSectionBase otherSection) { _ParentArray = arrayBuffer; ItemType = otherSection.ItemType; Normalized = otherSection.Normalized; Offset = otherSection.Offset; Stride = otherSection.Stride; }
/// <summary> /// Construct an ArrayBufferObjectInterleaved specifying its item layout on GPU side. /// </summary> /// <param name="format"> /// A <see cref="ArrayBufferItemType"/> describing the item base type on GPU side. /// </param> /// <param name="hint"> /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints. /// </param> public ArrayBufferObjectInterleaved(BufferObjectHint hint) : base(hint) { try { // Determine array item size ItemSize = (uint)Marshal.SizeOf(typeof(T)); // Detect interleaved fields using reflection (cached) List <InterleavedSectionBase> typeSections; if (_TypeSections.TryGetValue(typeof(T), out typeSections) == false) { // Cache for type typeSections = new List <InterleavedSectionBase>(); foreach (FieldInfo field in typeof(T).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { InterleavedSectionBase structSection = new InterleavedSectionBase(); structSection.ItemType = ArrayBufferItem.GetArrayType(field.FieldType); structSection.Normalized = false; structSection.Offset = Marshal.OffsetOf <T>(field.Name); structSection.Stride = new IntPtr(ItemSize); typeSections.Add(structSection); } _TypeSections.Add(typeof(T), typeSections); } // Get array sections for this instance _InterleavedSections = typeSections.ConvertAll(delegate(InterleavedSectionBase item) { return(new InterleavedSection(this, item)); }); } catch { // Avoid finalizer assertion failure (don't call dispose since it's virtual) GC.SuppressFinalize(this); throw; } }