I decided to use a class for the mesh, as I wanted the mesh to have some member methods and also because I am more comfortable using C++ classes instead of C structs. The class contains:
- The platform dependent vertex format.
- For OpenGL
- For Direct3D:
- Vertex Declaration
- Vertex Buffer
- Index Buffer
- Direct3D device (more on that later)
In my code, I decided to move all the code from Graphics.**.cpp to Mesh.**.cpp. After some discussions with some of my classmates, I realized that none of them had moved the complete code from the old file to the new one. But to defend what I did, I thought that we would have different vertex buffers and index buffers for each new mesh. Even though it will cost us some more computation time at the start and extra memory while initializing, it will save some time during rendering. The only concern was either Direct3D or OpenGL not allowing me to create multiple buffers. But after some testing and creating new mesh with same data, I was relieved that it caused no problems. I agree that it is a bit of excessive memory allocation and depending on what JP thinks, I might have to change it back. Some other thoughts about this was creating a singular vertex and index buffer and storing the starting positions of each in the mesh. I do not know how to do this in either OpenGL or Direct3D or whether it allows me to do so. Hence I decided to keep how it was.