This is a helper class for creating a vertex buffer for a specific vertex data struct. An example on usage can be found in [[Vertex Buffers]]. ## Constructors The first constructor you must implement is an empty constructor: ```cs public unsafe class ExampleVertexBuffer : TypedVertexBuffer<ExampleVertex> { public ExampleVertexBuffer() : base() { } } ``` `base()` doesn't create any actual OpenGL resources (VBO, VAO). The purpose of this constructor is to allow [[VertexAttribStrings]] to create an instance of this class, so that it can calculate its vertex attribute string. This means you don't need to create an instance of a vertex buffer before creating a shader. The second constructor takes in 3 parameters: ```cs public unsafe class ExampleVertexBuffer : TypedVertexBuffer<ExampleVertex> { public ExampleVertexBuffer(int size, ExampleVertex* data, bool allocate) : base(size, data, allocate) { } } ``` `size` is the size of the OpenGL buffer, i.e. how many ExampleVertex it can store `data` contains the data you would like to store in this buffer. Provide null if you'll populate the data later `allocate` indicates whether or not to allocate an array on the CPU for you See [[#Examples]] for examples of using this constructor ## Methods ```cs // Append data from another buffer, to this buffer's CPU data public void Append(TypedVertexBuffer<T> svb, bool resize = true) // Increase the size of the data on the CPU public void SetLength(int newLength) // Map the buffer public T* MapBuffer() // TODO - Many more ... ``` ## Fields See also: [[VertexBuffer#Fields]] ```cs // The CPU-side buffer data public T* data; // The size of data public int dataLength; // If true, automatically free the CPU-side data after buffering public bool clearDataAfterBuffering = true; // If false, will forget about data after buffering public bool takeOwnershipOfData = true; ``` ## Examples This class implements all required constructors and methods for a `TypedVertexBuffer`: ```cs public unsafe class ExampleVertexBuffer : TypedVertexBuffer<ExampleVertex> { public ExampleVertexBuffer() : base() { } public ExampleVertexBuffer(int size, ExampleVertex* data, bool allocate) : base(size, data, allocate) { primitiveType = PrimitiveType.TriangleStrip; } public override void SetupAttributes() { SetAttrib(3, VertexAttribPointerType.Float, "aPosition"); SetAttrib(4, VertexAttribPointerType.UnsignedByte, "aColour", true); } } ```