As an exercise set to myself, I wanted to make a Mesh loader using modern OpenGL.
However, I have to ways of representing the notion of face of a mesh.
Currently, I am using what seems the most natural. A mesh contains a
std::vector<Triangle>
and a Triangle is simply
struct Triangle
{
unsigned int Vertices[3];
}
(i.e. each triangle stores the three indices of its vertices). NOTE : a mesh contains others things (such as the vertices and the normals but I didn't include them here for simplicity).
However, OpenGL require a different representation for using EBO : only one static array on indices (implicitly grouped by 3).
What I have come up with is a trade-off between these representations : once the mesh is loaded, I generate a static array of size
3 * mesh->Faces.size()
but I assume this is not the best option for memory use and redundancy.
So my questions are :
- If I want to keep my current representation of a mesh (with a vector of faces), how should I set OpenGL to properly render such a mesh ? Is my current solution of generating a new static a good practice ?
- Assuming I can use the representation I want for my mesh. What would you recommand and why ?