Hi,
I was making a simple game in C++ and OpenGL with what I learned from a bunch of pretty old tutorials (which I discovered later), and now I'm in the process of updating everything and I've got some questions about the VBO implementation.
I had this code:
class Vertex
{
public:
float posX, posY, posZ;
};
class Face
{
public:
Vertex** vertexes;
//bunch of functions to get and set the vertexes and their values
};
class Object3D : public Object
{
public:
Face* faces;
Vertex* vertexes;
//bunch of functions to initialize the vertexes and faces
};
So my Object3D had an array of all vertexes informations, each with their X, Y and Z, and another array for Faces, which gave me the addresses of 3 Vertexes that composed 1 Face of the object.
It worked fine since I was calling:
void Game::Draw(Object3D* object)
{
for(int i = 0; i < object->totalFaces; i++)
{
glVertex3f(object->faces.GetVertex[0]->posX, object->faces.GetVertex[0]->posY, object->faces.GetVertex[0]->posZ);
glVertex3f(object->faces.GetVertex[1]->posX, object->faces.GetVertex[1]->posY, object->faces.GetVertex[1]->posZ);
glVertex3f(object->faces.GetVertex[2]->posX, object->faces.GetVertex[2]->posY, object->faces.GetVertex[2]->posZ);
}
}
But now that I'm going to turn everything into VBOs, I need a single array with the sequential float values of each of the object's faces, so it means I'll even have to repeat some vertex's values sometime when they share the same point.
This is where I'm at, I'm trying to figure what would be the best way to do this.
My animation code (unfinished) moved the vertexes according to the bone's movement and weight, and all I had to do was to change the values in my "vertexes[]" array of the Object3D, and I didn't had to worry about it's faces.
Now, I will have to change the new vertex data array I'll be buffering as VBO, and I'd like to get some ideas on how.
I have no experience releasing games, and I never seen a professional/released engine code before, so I've got literally no idea what's the common approach to this.
For now I'm thinking in getting something like this:
class Object3D : public class Object
{
public:
float* vertexData; // = new float[totalVertexes]; - this will be what I'll send/map to the VBO as data
//same as before, vertex and faces arrays
};
And everytime there's a change in the model, I'll change the vertexes array as usual, and then update the values in "vertexData" and finally update the VBO.
This seems a bad idea as I'll be doing this for every animated object in the screen... and I'd be using twice as much memory for every model since I have two variables with the same values.
Isn't there a way to send the VBO data in a different manner? If it searched by index, I think I could create a class and override the brackets operator to send the address that I want, but since it's function asks for the size, I'm guessing it moves by memory size...
Is there any good approaches to this, or what's the best way to do this? (I'd like to totally scrap the vertexes array and only work with the vertexData I've sent/mapped to the VBO)