/// <summary> /// Construct an ArrayBufferObjectInterleaved specifying its item layout on CPU side. /// </summary> /// <param name="arrayItemType"> /// A <see cref="Type"/> describing the type of the array item. /// </param> /// <param name="hint"> /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints. /// </param> public ArrayBufferObjectInterleaved(Type arrayItemType, BufferObjectHint hint) : base(arrayItemType, hint) { // Get fields for defining array item definition FieldInfo[] arrayItemTypeFields = arrayItemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (arrayItemTypeFields.Length == 0) { throw new ArgumentException("no public fields", "arrayItemType"); } // Determine array sections stride int structStride = Marshal.SizeOf(arrayItemType); for (int i = 0; i < arrayItemTypeFields.Length; i++) { FieldInfo arrayItemTypeField = arrayItemTypeFields[i]; ArraySection arraySection = new ArraySection(this, arrayItemTypeField.FieldType); // Determine array section offset arraySection.ItemOffset = Marshal.OffsetOf(arrayItemType, arrayItemTypeField.Name); // Determine array section stride arraySection.ItemStride = new IntPtr(structStride); // Mission Normalized property management: add attributes? arraySection.Normalized = false; ArraySections.Add(arraySection); } // Determine array item size ItemSize = (uint)structStride; }
/// <summary> /// Construct an ArrayBufferObjectInterleaved specifying its item layout on CPU side. /// </summary> /// <param name="arrayItemType"> /// A <see cref="Type"/> describing the type of the array item. /// </param> /// <param name="hint"> /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints. /// </param> public ArrayBufferObjectPacked(Type arrayItemType, BufferObjectHint hint) : base(arrayItemType, hint) { // Get fields for defining array item definition FieldInfo[] arrayItemTypeFields = arrayItemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (arrayItemTypeFields.Length == 0) { throw new ArgumentException("no public fields", "arrayItemType"); } // Allocate type information arrays _FieldsSize = new uint[arrayItemTypeFields.Length]; _FieldsOffset = new IntPtr[arrayItemTypeFields.Length]; _ClientBufferOffsets = new IntPtr[arrayItemTypeFields.Length]; _BufferOffsets = new IntPtr[arrayItemTypeFields.Length]; // Determine array sections stride int structStride = Marshal.SizeOf(arrayItemType); for (int i = 0; i < arrayItemTypeFields.Length; i++) { FieldInfo arrayItemTypeField = arrayItemTypeFields[i]; ArraySection arraySection = new ArraySection(this, arrayItemTypeField.FieldType); // Store field size: used for re-computing section offsets _FieldsSize[i] = (uint)Marshal.SizeOf(arrayItemTypeField.FieldType); // Store field offset: used for locating field in input arrays _FieldsOffset[i] = Marshal.OffsetOf(arrayItemType, arrayItemTypeField.Name); // Array section offset is re-computed each time the item count is defined arraySection.ItemOffset = IntPtr.Zero; // Determine array section stride arraySection.ItemStride = new IntPtr(_FieldsSize[i]); // Mission Normalized property management: add attributes? arraySection.Normalized = false; ArraySections.Add(arraySection); } // Determine array item size ItemSize = (uint)structStride; }