Skip to content

Creating buffers

Adam Gorski edited this page Aug 17, 2021 · 4 revisions

Creating buffers

GLBuffer's are used to store vertex data for rendering objects, or for being sampled by a sampler1D. You can create a empty (non-zeroed) GLBuffer, or import a float or Vector3 array:

GLBuffer myBuffer;
int stride = 3;

//with floats
myBuffer = new GLBuffer(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9}, stride);

//with vectors
myBuffer = new GLBuffer(new Vector3[] { new Vector3(1,2,3), new Vector3(4,5,6), new Vector3(7,8,9)}, 3);

//10 element float size, note that this array may not be zeroed.
myBuffer = new GLBuffer(sizeof(float) * 9, 3);

Note that you will be required to have a appropriate stride value. The element count % stride must be zero. The GLBuffer values must be floats of groups of floats (Vector2 or Vector3).

You can also resize the buffer:

myBuffer.Resize(sizeof(float) * floatCount, stride);

Please make sure to have the correct stride value. There are built in primitives to help speed up development:

GLBuffer cubeUV = GLPrimitives.Cube;
GLBuffer planeUV = GLPrimitives.PlaneXZ;