# StructuredBuffer

### Description

**StructuredBuffer** represent a shader uniform/constant buffer values in array.

Structured buffer is human-readable representation of raw shader buffer array data that stored in **GPU**. This class should be using only for creating a **CPU** buffer (here in C#) with all shaders variables, and send it to **GPU** when rendering is happen, or for setup shader buffers.\
\
In memory **StructuredBuffer** looks something like this: \[`float, float, int, int, int, Matrix4 ..., ..., ...`]. Where for example first two `floats` can represent a [Vector2f](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/vector2f), or middle three `ints` can represent a position or any other [Vector3f](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/vector3f). \
\
**At the moment, this API has a number of limitations, one of them is that we cannot send a certain part of the buffer, but only completely.**

### Constructors

|                                                  |                                                                                                |
| ------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| <mark style="color:red;">StructuredBuffer</mark> | Construct new <mark style="color:red;">StructuredBuffer</mark> from array of `values`.         |
| <mark style="color:red;">StructuredBuffer</mark> | Construct new <mark style="color:red;">StructuredBuffer</mark> from `System.IList` collection. |

### Methods

|                                                 |                                                                                                                                |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| <mark style="color:red;">Set</mark>             | Send the <mark style="color:red;">StructuredBuffer</mark> to shader to **GPU**. All Set the object value at end of the buffer. |
| <mark style="color:red;">Get(int index)</mark>  | Gets the object value by `index` from this <mark style="color:red;">StructuredBuffer</mark>.                                   |
| <mark style="color:red;">Get</mark>             | Gets the `all` elements in sequence array of data.                                                                             |
| <mark style="color:red;">Clear</mark>           | `Removes` all values from this <mark style="color:red;">StructuredBuffer</mark> (on **CPU** side not **GPU**).                 |
| <mark style="color:red;">CountOfElements</mark> | Returns total `count` of all elements in this <mark style="color:red;">StructuredBuffer</mark>.                                |
| <mark style="color:red;">Count</mark>           | Returns `count` of all objects in this <mark style="color:red;">StructuredBuffer</mark> that was initially passed.             |
| <mark style="color:red;">Size</mark>            | Returns the total `size` in bytes of this <mark style="color:red;">StructuredBuffer</mark>.                                    |

### Operators

|                                                    |                                                                                    |
| -------------------------------------------------- | ---------------------------------------------------------------------------------- |
| <mark style="color:red;">operator object\[]</mark> | Convert <mark style="color:red;">StructuredBuffer</mark> to array of raw elements. |

### See Also

[Renderer2D](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/renderer2d), [ShaderBufferBlock](https://danil-dukhovenko.gitbook.io/force/force-scripting-api/force/shaderbufferblock)
