All buffer objects are represented with gls::IBuffer class. Here is the list of supported buffer types:
VERTEX_BUFFER INDEX_BUFFER PIXEL_PACK_BUFFER PIXEL_UNPACK_BUFFER TEXTURE_BUFFER UNIFORM_BUFFER TRANSFORM_FEEDBACK_BUFFER DRAW_INDIRECT_BUFFER DISPATCH_INDIRECT_BUFFER ATOMIC_COUNTER_BUFFER SHADER_STORAGE_BUFFER
For example, a vertex buffer can be created like this:
vertexBuffer = renderContext->CreateBuffer(gls::VERTEX_BUFFER, sizeInBytes, nullptr, gls::USAGE_DYNAMIC_DRAW);
By passing null as data pointer, it will create an uninitialized vertex buffer of specified size. You can specify data later in various ways:
- By calling BufferData() (also respecifies buffer size and usage). This call will create a new buffer.
- By calling BufferSubData(). This is more efficient than the previous, it replaces a part or all the data in the existing buffer.
- Finally, data can be changed by calling Map() or MapRange(). These functions will map the buffer storage to process's address space and return a pointer through which data can be modified. After that, Unmap() must be called before buffer object is used.