/// <summary> /// Creates a buffer object of type T. /// </summary> /// <param name="data">Specifies a pointer to data that will be copied into the data store for initialization.</param> /// <param name="target">Specifies the target buffer object.</param> /// <param name="hint">Specifies the expected usage of the data store.</param> public VBO(T[] data, BufferTarget target = BufferTarget.ArrayBuffer, BufferUsageHint hint = BufferUsageHint.StaticDraw) { vboID = GlUtility.CreateVBO <T>(BufferTarget = target, data, hint); Size = (data is int[] || data is float[] ? 1 : (data is Vector2[] ? 2 : (data is Vector3[] ? 3 : (data is Vector4[] ? 4 : 0)))); PointerType = (data is int[] ? VertexAttribPointerType.Int : VertexAttribPointerType.Float); Count = data.Length; }
/// <summary> /// Creates a buffer object of type T with a specified length. /// This allows the array T[] to be larger than the actual size necessary to buffer. /// Useful for reusing resources and avoiding unnecessary GC action. /// </summary> /// <param name="data">An array of data of type T (which must be a struct) that will be buffered to the GPU.</param> /// <param name="position"></param> /// <param name="length">The length of the valid data in the data array.</param> /// <param name="target">Specifies the target buffer object.</param> /// <param name="hint">Specifies the expected usage of the data store.</param> public VBO(T[] data, int position, int length, BufferTarget target = BufferTarget.ArrayBuffer, BufferUsageHint hint = BufferUsageHint.StaticDraw) { length = Math.Max(0, Math.Min(length, data.Length)); vboID = GlUtility.CreateVBO <T>(BufferTarget = target, data, hint, position, length); this.Size = (data is int[] || data is float[] ? 1 : (data is Vector2[] ? 2 : (data is Vector3[] ? 3 : (data is Vector4[] ? 4 : 0)))); this.PointerType = (data is int[] ? VertexAttribPointerType.Int : VertexAttribPointerType.Float); this.Count = length; }