Class GorgonIndexBuffer
A buffer for indices used to look up vertices within a GorgonVertexBuffer.
Implements
Inherited Members
Namespace: Gorgon.Graphics.Core
Assembly: Gorgon.Graphics.Core.dll
Syntax
public sealed class GorgonIndexBuffer : GorgonBufferCommon, IGorgonGraphicsObject, IGorgonNativeResource, IDisposable, IGorgonIndexBufferInfo, IGorgonNamedObject
Remarks
This buffer allows the use of indices to allow for smaller vertex buffers and providing a faster means of finding vertices to draw on the GPU.
To send indices to the GPU using a index buffer, an application can upload a value type values, representing the indices, to the buffer using one of the SetData<T>(ReadOnlySpan<T>, int, CopyMode) overloads. For best performance, it is recommended to upload index data only once, or rarely. However, in some scenarios, and with the correct Usage flag, indices can be updated regularly for things like dynamic tesselation of surface.
void InitializeIndexBuffer()
{
_indices = ... // Fill your index array here. }GorgonGraphics graphics;
ushort[] _indices = new ushort[100];
GorgonIndexBuffer _indexBuffer;
// Create the index buffer large enough so that it'll hold all 100 indices.
// Unlike other buffers, we're passing the number of indices instead of bytes.
// This is because we can determine the number of bytes by whether we're using
// 16 bit indices (we are) and the index count.
_indexBuffer = new GorgonIndexBuffer("MyIB", graphics, new GorgonIndexBufferInfo
{
IndexCount = _indices.Length
});
// Copy our data to the index buffer.
graphics.SetData<ushort>(_indices);
Constructors
| Edit this page View SourceGorgonIndexBuffer(GorgonGraphics, GorgonIndexBufferInfo)
Initializes a new instance of the GorgonIndexBuffer class.
Declaration
public GorgonIndexBuffer(GorgonGraphics graphics, GorgonIndexBufferInfo info)
Parameters
Type | Name | Description |
---|---|---|
GorgonGraphics | graphics | The GorgonGraphics object used to create and manipulate the buffer. |
GorgonIndexBufferInfo | info | Information used to create the buffer. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
GorgonIndexBuffer(GorgonGraphics, GorgonIndexBufferInfo, ReadOnlySpan<byte>)
Initializes a new instance of the GorgonIndexBuffer class, initialized with byte values.
Declaration
public GorgonIndexBuffer(GorgonGraphics graphics, GorgonIndexBufferInfo info, ReadOnlySpan<byte> initialData)
Parameters
Type | Name | Description |
---|---|---|
GorgonGraphics | graphics | The GorgonGraphics object used to create and manipulate the buffer. |
GorgonIndexBufferInfo | info | Information used to create the buffer. |
ReadOnlySpan<byte> | initialData | The initial data used to populate the buffer. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
GorgonIndexBuffer(GorgonGraphics, GorgonIndexBufferInfo, ReadOnlySpan<short>)
Initializes a new instance of the GorgonIndexBuffer class, initialized with short values for 16 bit index buffers.
Declaration
public GorgonIndexBuffer(GorgonGraphics graphics, GorgonIndexBufferInfo info, ReadOnlySpan<short> initialData)
Parameters
Type | Name | Description |
---|---|---|
GorgonGraphics | graphics | The GorgonGraphics object used to create and manipulate the buffer. |
GorgonIndexBufferInfo | info | Information used to create the buffer. |
ReadOnlySpan<short> | initialData | The initial data used to populate the buffer. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
GorgonIndexBuffer(GorgonGraphics, GorgonIndexBufferInfo, ReadOnlySpan<int>)
Initializes a new instance of the GorgonIndexBuffer class, initialized with int values for 32 bit index buffers.
Declaration
public GorgonIndexBuffer(GorgonGraphics graphics, GorgonIndexBufferInfo info, ReadOnlySpan<int> initialData)
Parameters
Type | Name | Description |
---|---|---|
GorgonGraphics | graphics | The GorgonGraphics object used to create and manipulate the buffer. |
GorgonIndexBufferInfo | info | Information used to create the buffer. |
ReadOnlySpan<int> | initialData | The initial data used to populate the buffer. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
GorgonIndexBuffer(GorgonGraphics, GorgonIndexBufferInfo, ReadOnlySpan<ushort>)
Initializes a new instance of the GorgonIndexBuffer class, initialized with ushort values for 16 bit index buffers.
Declaration
public GorgonIndexBuffer(GorgonGraphics graphics, GorgonIndexBufferInfo info, ReadOnlySpan<ushort> initialData)
Parameters
Type | Name | Description |
---|---|---|
GorgonGraphics | graphics | The GorgonGraphics object used to create and manipulate the buffer. |
GorgonIndexBufferInfo | info | Information used to create the buffer. |
ReadOnlySpan<ushort> | initialData | The initial data used to populate the buffer. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
GorgonIndexBuffer(GorgonGraphics, GorgonIndexBufferInfo, ReadOnlySpan<uint>)
Initializes a new instance of the GorgonIndexBuffer class, initialized with uint values for 32 bit index buffers.
Declaration
public GorgonIndexBuffer(GorgonGraphics graphics, GorgonIndexBufferInfo info, ReadOnlySpan<uint> initialData)
Parameters
Type | Name | Description |
---|---|---|
GorgonGraphics | graphics | The GorgonGraphics object used to create and manipulate the buffer. |
GorgonIndexBufferInfo | info | Information used to create the buffer. |
ReadOnlySpan<uint> | initialData | The initial data used to populate the buffer. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown when the |
Properties
| Edit this page View SourceBinding
Property to return the binding used to bind this buffer to the GPU.
Declaration
public VertexIndexBufferBinding Binding { get; }
Property Value
Type | Description |
---|---|
VertexIndexBufferBinding |
IndexCount
Property to return the number of indices to store.
Declaration
public int IndexCount { get; }
Property Value
Type | Description |
---|---|
int |
IsCpuReadable
Property to return whether or not the buffer is directly readable by the CPU via one of the GetData<T>(Span<T>, int, int?) methods.
Declaration
public override bool IsCpuReadable { get; }
Property Value
Type | Description |
---|---|
bool |
Overrides
Remarks
Buffers must meet the following criteria in order to qualify for direct CPU read:
- Must have a Usage of Default (or Staging).
- Must be bindable to a shader resource view (Default only).
If this value is false, then the buffer can still be read, but it will take a slower path by copying to a staging buffer.
See Also
| Edit this page View SourceName
Property to return the name of this object.
Declaration
public override string Name { get; }
Property Value
Type | Description |
---|---|
string |
Overrides
| Edit this page View SourceSizeInBytes
Property to return the size, in bytes, of the resource.
Declaration
public override int SizeInBytes { get; }
Property Value
Type | Description |
---|---|
int |
Overrides
| Edit this page View SourceUsage
Property to return the usage for the resource.
Declaration
public override ResourceUsage Usage { get; }
Property Value
Type | Description |
---|---|
ResourceUsage |
Overrides
| Edit this page View SourceUse16BitIndices
Property to return whether to use 16 bit values for indices.
Declaration
public bool Use16BitIndices { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
| Edit this page View SourceGetReadWriteView(int, int)
Function to create a new GorgonIndexBufferReadWriteView for this buffer.
Declaration
public GorgonIndexBufferReadWriteView GetReadWriteView(int startElement = 0, int elementCount = 0)
Parameters
Type | Name | Description |
---|---|---|
int | startElement | [Optional] The first element to start viewing from. |
int | elementCount | [Optional] The number of elements to view. |
Returns
Type | Description |
---|---|
GorgonIndexBufferReadWriteView | A GorgonIndexBufferReadWriteView used to bind the buffer to a shader. |
Remarks
This will create an unordered access view that makes a buffer accessible to shaders using unordered access to the data. This allows viewing of the buffer data in a different format, or even a subsection of the buffer from within the shader.
The format of the view is based on whether the buffer uses 16 bit indices or 32 bit indices.
The startElement
parameter defines the starting data element to allow access to within the shader. If this value falls outside of the range of available elements, then it
will be clipped to the upper and lower bounds of the element range. If this value is left at 0, then first element is viewed.
To determine how many elements are in a buffer, use the IndexCount property.
The elementCount
parameter defines how many elements to allow access to inside of the view. If this value falls outside of the range of available elements, then it will be
clipped to the upper or lower bounds of the element range. If this value is left at 0, then the entire buffer is viewed.
Exceptions
Type | Condition |
---|---|
GorgonException | Thrown when this buffer does not have a Binding of UnorderedAccess. -or- Thrown when this buffer has a usage of Staging. |
GetStaging()
Function to retrieve a copy of this buffer as a staging resource.
Declaration
public GorgonIndexBuffer GetStaging()
Returns
Type | Description |
---|---|
GorgonIndexBuffer | The staging buffer to retrieve. |
GetStagingInternal()
Function to retrieve a copy of this buffer as a staging resource.
Declaration
protected override GorgonBufferCommon GetStagingInternal()
Returns
Type | Description |
---|---|
GorgonBufferCommon | The staging buffer to retrieve. |