Until now, I have been using a vertexData
structure to store data for a Vertex Buffer Object (VBO); vertexData
holds a static array of 6 vertices (2 triangles). I then save them to a vector
of the vertexData
type, before finally using this vertexData
in the buffering method:
struct vertexData {
Vertex vertices[6]; // position, color, UVs
};
std::vector<vertexData> _DATA;
void SpriteBatch::createVBO() {
glBindBuffer(GL_ARRAY_BUFFER,_VBO);
glBufferData(GL_ARRAY_BUFFER,_DATA.size()*sizeof(vertexData),nullptr,GL_DYNAMIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER,0,_DATA.size()*sizeof(vertexData),_DATA.data());
glBindBuffer(GL_ARRAY_BUFFER,0);
}
This works good, as everything in my vector is contiguous. However, I want to work with other vertex sizes, for different shapes. I tried a vector
of vector
types, in oder to work with dynamically allocated arrays, but it did not work, as it was not contiguous.
At first, I thought about using a polymorphic class to be stored as a vector
, where every child would have a different array size; but then I recognized that this vertex buffer does not work with pointers
The second idea was to create a generic SpriteBatch
. For example, a batch for 6 vertices, and then a batch for 2 vertices, etc. etc.
What is the best way to store Vertex Buffer Object data?