My drawing code currently draws by calling glVertex3f(x, y, z) for each of my object's vertexes, and I've been suggested to use VBO as it'd enhance the performance of my drawing code.
After checking how VBOs works, it seems I need to pass a float array of the vertexes I'm going to draw, and this is a problem.
My object class looks like this:
class Vertex
{
public:
float positionX, positionY, positionZ;
//more stuff
}
class Object3D
{
public:
//bunch of stuff
private:
Vertex* vertexes;
}
So when I create and load a new Object3D, I have an array of Vertex with the positions. If I were to pass a float array, I would need to:
void Graphics::Draw(Object3D* object)
{
float* vertexArray = new float[object->totalVertexes];
//fill vertexArray, send it to the card
delete[] vertexArray;
}
Do I need to do this every frame, or just once (and I just call glDrawArrays() after it's loaded)?
Do I use VBOs on models that will be constantly changing, such as a character, or just for static objects? (If I were to use, I'd have to call the above code every frame, wouldn't it be a bad idea?)
Also, should I separate VBOs by objects, or just group them up by what's changing or not? (For example, I create 1 VBO ID that holds all my terrain and non-animated objects, or should I create 1 VBO ID for each object on my screen?)