/// <summary> /// Initializes a new instance of the <see cref="GorgonVertexBufferInfo"/> class. /// </summary> /// <param name="info">A <see cref="IGorgonVertexBufferInfo"/> to copy settings from.</param> /// <param name="newName">[Optional] The new name for the buffer.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="info"/> parameter is <b>null</b>.</exception> public GorgonVertexBufferInfo(IGorgonVertexBufferInfo info, string newName = null) { if (info == null) { throw new ArgumentNullException(nameof(info)); } Name = string.IsNullOrEmpty(newName) ? info.Name : newName; SizeInBytes = info.SizeInBytes; Usage = info.Usage; Binding = info.Binding; }
/// <summary> /// Function to create a vertex buffer and its binding. /// </summary> /// <typeparam name="T">The type of data representing a vertex, must be an unmanaged value type.</typeparam> /// <param name="graphics">The graphics interface that will create the buffer.</param> /// <param name="info">Information about the buffer to create.</param> /// <param name="initialData">[Optional] An initial set of vertex data to send to the buffer.</param> /// <param name="bindingIndex">[Optional] The index, in vertices, inside the buffer where binding is to begin.</param> /// <returns>A new <see cref="GorgonVertexBufferBinding"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or the <paramref name="info"/> parameter is <b>null</b>.</exception> /// <remarks> /// <para> /// Use this to quickly create a vertex buffer and its binding based on a known vertex data type. /// </para> /// <para> /// Be aware that the <see cref="VertexBuffer"/> created by this method must be disposed manually after it is no longer of any use. /// </para> /// </remarks> /// <seealso cref="GorgonVertexBuffer"/> public static GorgonVertexBufferBinding CreateVertexBuffer <T>(GorgonGraphics graphics, IGorgonVertexBufferInfo info, GorgonNativeBuffer <T> initialData = null, int bindingIndex = 0) where T : unmanaged { if (graphics == null) { throw new ArgumentNullException(nameof(graphics)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } var buffer = new GorgonVertexBuffer(graphics, info, initialData?.Cast <byte>()); int vertexSize = Unsafe.SizeOf <T>(); return(new GorgonVertexBufferBinding(buffer, vertexSize, bindingIndex * vertexSize)); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonVertexBuffer" /> class. /// </summary> /// <param name="graphics">The <see cref="GorgonGraphics"/> object used to create and manipulate the buffer.</param> /// <param name="info">Information used to create the buffer.</param> /// <param name="initialData">[Optional] The initial data used to populate the buffer.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or the <paramref name="info"/> parameters are <b>null</b>.</exception> public GorgonVertexBuffer(GorgonGraphics graphics, IGorgonVertexBufferInfo info, GorgonNativeBuffer <byte> initialData = null) : base(graphics) { _info = new GorgonVertexBufferInfo(info ?? throw new ArgumentNullException(nameof(info))); Initialize(initialData); }