Gorgon
Show / Hide Table of Contents

Class GorgonIndexBuffer

A buffer for indices used to look up vertices within a GorgonVertexBuffer.

Inheritance
object
GorgonGraphicsResource
GorgonBufferCommon
GorgonIndexBuffer
Implements
IGorgonGraphicsObject
IGorgonNativeResource
IDisposable
IGorgonIndexBufferInfo
IGorgonNamedObject
Inherited Members
GorgonBufferCommon.ResourceType
GorgonBufferCommon.SetData<T>(ReadOnlySpan<T>, int, CopyMode)
GorgonBufferCommon.SetData<T>(in T, int, CopyMode)
GorgonBufferCommon.GetData<T>(int, int?)
GorgonBufferCommon.GetData<T>(Span<T>, int, int?)
GorgonBufferCommon.GetData<T>(out T, int)
GorgonBufferCommon.CopyTo(GorgonBufferCommon, int, int, int, CopyMode)
GorgonBufferCommon.Dispose()
GorgonGraphicsResource.IsDisposed
GorgonGraphicsResource.Graphics
GorgonGraphicsResource.EvictionPriority
GorgonGraphicsResource.SetApplicationData(Guid, object)
GorgonGraphicsResource.GetApplicationData(Guid)
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
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.

For example, to send a list of indices to a index buffer:

GorgonGraphics graphics;
ushort[] _indices = new ushort[100];
GorgonIndexBuffer _indexBuffer;

void InitializeIndexBuffer() { _indices = ... // Fill your index array here.

// 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 Source

GorgonIndexBuffer(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 graphics, or the info parameters are null.

| Edit this page View Source

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 graphics, info or the initialData parameters are null.

| Edit this page View Source

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 graphics, info or the initialData parameters are null.

| Edit this page View Source

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 graphics, info or the initialData parameters are null.

| Edit this page View Source

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 graphics, info or the initialData parameters are null.

| Edit this page View Source

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 graphics, info or the initialData parameters are null.

Properties

| Edit this page View Source

Binding

Property to return the binding used to bind this buffer to the GPU.

Declaration
public VertexIndexBufferBinding Binding { get; }
Property Value
Type Description
VertexIndexBufferBinding
| Edit this page View Source

IndexCount

Property to return the number of indices to store.

Declaration
public int IndexCount { get; }
Property Value
Type Description
int
| Edit this page View Source

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
GorgonBufferCommon.IsCpuReadable
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.

information

Any buffer created with a Usage of Staging will always be directly readable by the CPU. Therefore, this value will always return true in that case.

See Also
GetData<T>(Span<T>, int, int?)
GetData<T>(out T, int)
GetData<T>(int, int?)
| Edit this page View Source

Name

Property to return the name of this object.

Declaration
public override string Name { get; }
Property Value
Type Description
string
Overrides
GorgonGraphicsResource.Name
| Edit this page View Source

SizeInBytes

Property to return the size, in bytes, of the resource.

Declaration
public override int SizeInBytes { get; }
Property Value
Type Description
int
Overrides
GorgonGraphicsResource.SizeInBytes
| Edit this page View Source

Usage

Property to return the usage for the resource.

Declaration
public override ResourceUsage Usage { get; }
Property Value
Type Description
ResourceUsage
Overrides
GorgonGraphicsResource.Usage
| Edit this page View Source

Use16BitIndices

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 Source

GetReadWriteView(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.

| Edit this page View Source

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.

| Edit this page View Source

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.

Overrides
GorgonBufferCommon.GetStagingInternal()

Implements

IGorgonGraphicsObject
IGorgonNativeResource
IDisposable
IGorgonIndexBufferInfo
IGorgonNamedObject

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author