/// <summary> /// Function to create a vertex buffer. /// </summary> /// <param name="name">Name of the vertex buffer.</param> /// <param name="settings">The settings for the buffer.</param> /// <param name="initialData">[Optional] Initial data to populate the vertex buffer with.</param> /// <returns>A new vertex buffer.</returns> /// <remarks>This method should only be called from an immediate graphics context, if it is called from a deferred context an exception will be thrown.</remarks> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net). /// <para>-or-</para> /// <para>Thrown when the <paramref name="settings"/> parameter is NULL.</para> /// </exception> /// <exception cref="System.ArgumentException">Thrown when the <paramref name="name"/> parameter is empty.</exception> /// <exception cref="GorgonLibrary.GorgonException">Thrown when the <see cref="GorgonLibrary.Graphics.GorgonBufferSettings.IsOutput">IsOutput</see> property is TRUE and has a usage that is not Default. /// <para>-or-</para> /// <para>Thrown when the <see cref="GorgonLibrary.Graphics.GorgonBufferSettings.SizeInBytes">SizeInBytes</see> property of the <paramref name="settings"/> parameter is less than 4.</para> /// <para>-or-</para> /// <para>Thrown when the usage is set to immutable and the <paramref name="initialData"/> parameter is NULL (Nothing in VB.Net) or has no data.</para> /// </exception> public GorgonVertexBuffer CreateVertexBuffer(string name, GorgonBufferSettings settings, GorgonDataStream initialData = null) { if (_graphics.IsDeferred) { throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_CANNOT_USE_DEFERRED_CONTEXT); } if (settings == null) { throw new ArgumentNullException("settings"); } if ((settings.Usage == BufferUsage.Immutable) && ((initialData == null) || (initialData.Length == 0))) { throw new GorgonException(GorgonResult.CannotCreate, Resources.GORGFX_BUFFER_IMMUTABLE_REQUIRES_DATA); } ValidateGenericBufferSettings(settings); var buffer = new GorgonVertexBuffer(_graphics, name, settings); buffer.Initialize(initialData); _graphics.AddTrackedObject(buffer); return(buffer); }
/// <summary> /// Function to unbind any bindings with the specified vertex buffer. /// </summary> /// <param name="buffer">Buffer to unbind.</param> internal void Unbind(GorgonVertexBuffer buffer) { for (int i = 0; i < _bindings.Length; ++i) { if (_bindings[i].VertexBuffer == buffer) { _bindings[i] = GorgonVertexBufferBinding.Empty; } } }
/// <summary> /// Initializes a new instance of the <see cref="GorgonBufferUnorderedAccessView"/> class. /// </summary> /// <param name="resource">The buffer to bind to the view.</param> /// <param name="format">The format of the view.</param> /// <param name="firstElement">The first element in the buffer.</param> /// <param name="elementCount">The number of elements to view.</param> /// <param name="isRaw">TRUE if the view should be a raw view, FALSE if not.</param> internal GorgonBufferUnorderedAccessView(GorgonResource resource, BufferFormat format, int firstElement, int elementCount, bool isRaw) : base(resource, format) { IsRaw = isRaw; ElementStart = firstElement; ElementCount = elementCount; _buffer = resource as GorgonBuffer; _indexBuffer = resource as GorgonIndexBuffer; _vertexBuffer = resource as GorgonVertexBuffer; }
/// <summary> /// Initializes a new instance of the <see cref="GorgonBufferShaderView"/> class. /// </summary> /// <param name="buffer">The buffer to bind to the view.</param> /// <param name="format">Format of the view.</param> /// <param name="elementStart">The starting element for the view.</param> /// <param name="elementCount">The number of elements in the view.</param> /// <param name="isRaw">TRUE to use a raw view, FALSE to use a normal view.</param> internal GorgonBufferShaderView(GorgonResource buffer, BufferFormat format, int elementStart, int elementCount, bool isRaw) : base(buffer, format) { IsRaw = isRaw; ElementStart = elementStart; ElementCount = elementCount; _buffer = buffer as GorgonBuffer; _structuredBuffer = buffer as GorgonStructuredBuffer; _indexBuffer = buffer as GorgonIndexBuffer; _vertexBuffer = buffer as GorgonVertexBuffer; }
/// <summary> /// Function to find the index of a vertex buffer binding that contains the specified vertex buffer. /// </summary> /// <param name="buffer">Vertex buffer to find.</param> /// <returns>The index of the buffer binding in the list, -1 if not found.</returns> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="buffer"/> parameter is NULL (Nothing in VB.Net).</exception> public int IndexOf(GorgonVertexBuffer buffer) { if (buffer == null) { throw new ArgumentNullException("buffer"); } for (int i = 0; i < _bindings.Length; i++) { if (_bindings[i].VertexBuffer == buffer) { return(i); } } return(-1); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonVertexBufferBinding"/> struct. /// </summary> /// <param name="buffer">The buffer to bind.</param> /// <param name="stride">The stride of the data in the buffer, in bytes.</param> /// <param name="offset">[Optional] The offset within the buffer to start at, in bytes.</param> public GorgonVertexBufferBinding(GorgonVertexBuffer buffer, int stride, int offset = 0) { VertexBuffer = buffer; Stride = stride; Offset = offset; }
/// <summary> /// Function to return whether the vertex buffer specified has a binding in the list. /// </summary> /// <param name="buffer">The buffer to find.</param> /// <returns>TRUE if found, FALSE if not.</returns> /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="buffer"/> parameter is NULL (Nothing in VB.Net).</exception> public bool Contains(GorgonVertexBuffer buffer) { return(IndexOf(buffer) > -1); }