/// <summary>
        /// Construct an ElementBufferObject.
        /// </summary>
        /// <param name="elementType">
        ///
        /// </param>
        /// <param name="hint">
        /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints.
        /// </param>
        protected ElementBufferObject(Type elementType, BufferObjectHint hint)
            : base(BufferTargetARB.ElementArrayBuffer, hint)
        {
            try {
                // Determine ElementsType and default RestartIndexKey
                switch (Type.GetTypeCode(elementType))
                {
                case TypeCode.Byte:
                    ElementsType    = DrawElementsType.UnsignedByte;
                    ItemSize        = 1;
                    RestartIndexKey = 0x000000FF;
                    break;

                case TypeCode.UInt16:
                    ElementsType    = DrawElementsType.UnsignedShort;
                    ItemSize        = 2;
                    RestartIndexKey = 0x0000FFFF;
                    break;

                case TypeCode.UInt32:
                    ElementsType    = DrawElementsType.UnsignedInt;
                    ItemSize        = 4;
                    RestartIndexKey = 0xFFFFFFFF;
                    break;

                default:
                    throw new ArgumentException("type not supported", "elementType");
                }
            } catch {
                // Avoid finalizer assertion failure (don't call dispose since it's virtual)
                GC.SuppressFinalize(this);
                throw;
            }
        }
Example #2
0
        /// <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 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 ElementBufferObject.
		/// </summary>
		/// <param name="elementType">
		/// The <see cref="DrawElementsType"/> that specify how vertices are interpreted.
		/// </param>
		/// <param name="hint">
		/// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints.
		/// </param>
		public ElementBufferObject(DrawElementsType elementType, BufferObjectHint hint)
			: base(BufferTargetARB.ElementArrayBuffer, hint)
		{
			try {
				// Determine ElementsType and default RestartIndexKey
				ElementsType = elementType;
				switch (elementType) {
					case DrawElementsType.UnsignedByte:
						ItemSize = 1;
						RestartIndexKey = 0x000000FF;
						break;
					case DrawElementsType.UnsignedShort:
						ItemSize = 2;
						RestartIndexKey = 0x0000FFFF;
						break;
					case DrawElementsType.UnsignedInt:
						ItemSize = 4;
						RestartIndexKey = 0xFFFFFFFF;
						break;
					default:
						throw new ArgumentException("type not supported", "elementType");
				}
			} catch {
				// Avoid finalizer assertion failure (don't call dispose since it's virtual)
				GC.SuppressFinalize(this);
				throw;
			}
		}
Example #5
0
 /// <summary>
 /// Construct a BufferObject determining its type, data usage and transfer mode.
 /// </summary>
 /// <param name="type">
 /// A <see cref="BufferTargetARB"/> that specify the buffer object type.
 /// </param>
 /// <param name="hint">
 /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints.
 /// </param>
 protected BufferObject(BufferTargetARB type, BufferObjectHint hint)
 {
     // Store the buffer object type
     BufferType = type;
     // Store the buffer data usage hints
     Hint = hint;
     // Automatically dispose client buffer?
     _MemoryBufferAutoDispose = IsClientBufferAutoDisposable(hint);
 }
		/// <summary>
		/// Construct an ArrayBufferObjectAggregated.
		/// </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>
		protected ArrayBufferObjectAggregated(Type arrayItemType, BufferObjectHint hint) :
			base(hint)
		{
			try {
				if (arrayItemType == null)
					throw new ArgumentNullException("arrayItemType");
				if (arrayItemType.IsValueType == false)
					throw new ArgumentException("not a value type", "arrayItemType");
			} catch {
				// Avoid finalizer assertion failure (don't call dispose since it's virtual)
				GC.SuppressFinalize(this);
				throw;
			}
		}
Example #7
0
 /// <summary>
 /// Construct an ArrayBufferObject 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 ArrayBufferObject(ArrayBufferItemType format, BufferObjectHint hint) :
     base(hint)
 {
     try {
         // Store array type
         _ArrayType = format;
         // Determine array item size
         ItemSize = ArrayBufferItem.GetArrayItemSize(format);
     } catch {
         // Avoid finalizer assertion failure (don't call dispose since it's virtual)
         GC.SuppressFinalize(this);
         throw;
     }
 }
        public UniformBufferObject CreateUniformBlock(string uniformBlockName, BufferObjectHint hint)
        {
            UniformBlockBinding uniformBlockBinding = GetUniformBlock(uniformBlockName);

            if (uniformBlockBinding == null)
            {
                throw new ArgumentException("no uniform block with such name", "uniformBlockName");
            }

            UniformBufferObject uniformBuffer = new UniformBufferObject(hint);

            uniformBuffer.Create(uniformBlockBinding.DataSize);

            return(uniformBuffer);
        }
 /// <summary>
 /// Construct an ArrayBufferObjectAggregated.
 /// </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>
 protected ArrayBufferObjectAggregated(Type arrayItemType, BufferObjectHint hint) :
     base(hint)
 {
     try {
         if (arrayItemType == null)
         {
             throw new ArgumentNullException("arrayItemType");
         }
         if (arrayItemType.IsValueType == false)
         {
             throw new ArgumentException("not a value type", "arrayItemType");
         }
     } catch {
         // Avoid finalizer assertion failure (don't call dispose since it's virtual)
         GC.SuppressFinalize(this);
         throw;
     }
 }
Example #10
0
        /// <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;
        }
        /// <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;
            }
        }
Example #12
0
 /// <summary>
 /// Determine the default value of <see cref="AutoDisposeClientBuffer"/>.
 /// </summary>
 /// <param name="hint">
 /// A <see cref="BufferObjectHint"/> that hints the buffer usage.
 /// </param>
 /// <returns></returns>
 protected static bool IsClientBufferAutoDisposable(BufferObjectHint hint)
 {
     return(hint == BufferObjectHint.StaticCpuDraw);
 }
Example #13
0
 /// <summary>
 /// Construct an UniformBufferObject.
 /// </summary>
 /// <param name="hint">
 /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hint.
 /// </param>
 public UniformBufferObject(BufferObjectHint hint) :
     base(BufferTargetARB.UniformBuffer, hint)
 {
 }
 /// <summary>
 /// Construct an ArrayBufferObjectBase.
 /// </summary>
 /// <param name="bufferTarget">
 /// A <see cref="BufferTargetARB"/> that specify the buffer target.
 /// </param>
 /// <param name="hint">
 /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints.
 /// </param>
 protected ArrayBufferObjectBase(BufferTargetARB bufferTarget, BufferObjectHint hint) :
     base(bufferTarget, hint)
 {
 }
Example #15
0
 /// <summary>
 /// Construct an ArrayBufferObject specifying its item layout on CPU side.
 /// </summary>
 /// <param name="vertexBaseType">
 /// A <see cref="VertexBaseType"/> describing the item components base type on CPU side.
 /// </param>
 /// <param name="vertexLength">
 /// A <see cref="UInt32"/> that specify how many components have the array item.
 /// </param>
 /// <param name="vertexRank">
 /// A <see cref="UInt32"/> that specify how many columns have the array item of matrix type.
 /// </param>
 /// <param name="hint">
 /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints.
 /// </param>
 public ArrayBufferObject(VertexBaseType vertexBaseType, uint vertexLength, uint vertexRank, BufferObjectHint hint) :
     this(ArrayBufferItem.GetArrayType(vertexBaseType, vertexLength, vertexRank), hint)
 {
 }
Example #16
0
        /// <summary>
        /// Create an array buffer object, using the generic class <see cref="ArrayBufferObject{T}"/>, depending on a <see cref="ArrayBufferItemType"/>.
        /// </summary>
        /// <param name="vertexArrayType">
        /// A <see cref="ArrayBufferItemType"/> that determine the generic argument of the created array buffer object.
        /// </param>
        /// <param name="hint">
        /// A <see cref="BufferObjectHint"/> required for creating a <see cref="ArrayBufferObject"/>.
        /// </param>
        /// <returns>
        ///
        /// </returns>
        public static ArrayBufferObject CreateArrayObject(ArrayBufferItemType vertexArrayType, BufferObjectHint hint)
        {
            switch (vertexArrayType)
            {
            case ArrayBufferItemType.Byte:
                return(new ArrayBufferObject <sbyte>(hint));

            case ArrayBufferItemType.Byte2:
                return(new ArrayBufferObject <Vertex2b>(hint));

            case ArrayBufferItemType.Byte3:
                return(new ArrayBufferObject <Vertex3b>(hint));

            case ArrayBufferItemType.Byte4:
                return(new ArrayBufferObject <Vertex4b>(hint));

            case ArrayBufferItemType.UByte:
                return(new ArrayBufferObject <byte>(hint));

            case ArrayBufferItemType.UByte2:
                return(new ArrayBufferObject <Vertex2ub>(hint));

            case ArrayBufferItemType.UByte3:
                return(new ArrayBufferObject <Vertex3ub>(hint));

            case ArrayBufferItemType.UByte4:
                return(new ArrayBufferObject <Vertex4ub>(hint));

            case ArrayBufferItemType.Short:
                return(new ArrayBufferObject <short>(hint));

            case ArrayBufferItemType.Short2:
                return(new ArrayBufferObject <Vertex2s>(hint));

            case ArrayBufferItemType.Short3:
                return(new ArrayBufferObject <Vertex3s>(hint));

            case ArrayBufferItemType.Short4:
                return(new ArrayBufferObject <Vertex4s>(hint));

            case ArrayBufferItemType.UShort:
                return(new ArrayBufferObject <ushort>(hint));

            case ArrayBufferItemType.UShort2:
                return(new ArrayBufferObject <Vertex2us>(hint));

            case ArrayBufferItemType.UShort3:
                return(new ArrayBufferObject <Vertex3us>(hint));

            case ArrayBufferItemType.UShort4:
                return(new ArrayBufferObject <Vertex4us>(hint));

            case ArrayBufferItemType.Int:
                return(new ArrayBufferObject <Int32>(hint));

            case ArrayBufferItemType.Int2:
                return(new ArrayBufferObject <Vertex2i>(hint));

            case ArrayBufferItemType.Int3:
                return(new ArrayBufferObject <Vertex3i>(hint));

            case ArrayBufferItemType.Int4:
                return(new ArrayBufferObject <Vertex4i>(hint));

            case ArrayBufferItemType.UInt:
                return(new ArrayBufferObject <UInt32>(hint));

            case ArrayBufferItemType.UInt2:
                return(new ArrayBufferObject <Vertex2ui>(hint));

            case ArrayBufferItemType.UInt3:
                return(new ArrayBufferObject <Vertex3ui>(hint));

            case ArrayBufferItemType.UInt4:
                return(new ArrayBufferObject <Vertex4ui>(hint));

            case ArrayBufferItemType.Float:
                return(new ArrayBufferObject <Single>(hint));

            case ArrayBufferItemType.Float2:
                return(new ArrayBufferObject <Vertex2f>(hint));

            case ArrayBufferItemType.Float3:
                return(new ArrayBufferObject <Vertex3f>(hint));

            case ArrayBufferItemType.Float4:
                return(new ArrayBufferObject <Vertex4f>(hint));

            case ArrayBufferItemType.Float2x4:
                return(new ArrayBufferObject <Matrix2x4>(hint));

            case ArrayBufferItemType.Float4x4:
                return(new ArrayBufferObject <Matrix4>(hint));

            case ArrayBufferItemType.Double:
                return(new ArrayBufferObject <Double>(hint));

            case ArrayBufferItemType.Double2:
                return(new ArrayBufferObject <Vertex2d>(hint));

            case ArrayBufferItemType.Double3:
                return(new ArrayBufferObject <Vertex3d>(hint));

            case ArrayBufferItemType.Double4:
                return(new ArrayBufferObject <Vertex4d>(hint));

            case ArrayBufferItemType.Half:
                return(new ArrayBufferObject <HalfFloat>(hint));

            case ArrayBufferItemType.Half2:
                return(new ArrayBufferObject <Vertex2hf>(hint));

            case ArrayBufferItemType.Half3:
                return(new ArrayBufferObject <Vertex3hf>(hint));

            case ArrayBufferItemType.Half4:
                return(new ArrayBufferObject <Vertex4hf>(hint));

            default:
                throw new ArgumentException(String.Format("vertex array type {0} not supported", vertexArrayType));
            }
        }
Example #17
0
 /// <summary>
 /// Construct an ArrayBufferObjectInterleaved.
 /// </summary>
 /// <param name="hint">
 /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints.
 /// </param>
 public PackedArrayBufferObject(BufferObjectHint hint) :
     base(typeof(T), hint)
 {
 }
 /// <summary>
 /// Construct an ArrayBufferObjectBase.
 /// </summary>
 /// <param name="hint">
 /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints.
 /// </param>
 protected ArrayBufferObjectBase(BufferObjectHint hint) :
     base(BufferTargetARB.ArrayBuffer, hint)
 {
 }
Example #19
0
 /// <summary>
 /// Construct an ArrayBufferObject specifying its item layout on CPU side.
 /// </summary>
 /// <param name="vertexBaseType">
 /// A <see cref="VertexBaseType"/> describing the item components base type on CPU side.
 /// </param>
 /// <param name="vertexLength">
 /// A <see cref="UInt32"/> that specify how many components have the array item.
 /// </param>
 /// <param name="hint">
 /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints.
 /// </param>
 public ArrayBufferObject(VertexBaseType vertexBaseType, uint vertexLength, BufferObjectHint hint) :
     this(vertexBaseType, vertexLength, 1, hint)
 {
 }