Original Post
Hi everyone, I'm currently thinking about an easy way for handling meshes (with OpenGL), but it gives me some headaches, and the solutions I find don't make me happy, so here I am ^^. From now on, I have a Mesh class that encapsulates a vertex array (which is, in my design, all the vertices data - position, normal, uv... - stored in memory) and a vertex buffer, which creates a VBO and initializes it with the data from the vertex array). A Mesh also contains one or several SubMeshes objects. Each SubMesh has an index array, which is quite similar to vertex array but stores only indices in the memory, as well as an index buffer, which is like vertex buffer but for indices. That way, the data that is in the graphics card memory and main memory is well separated. Each SubMesh also has a material object. The problem with that is that if I have several meshes that are shared, I can't use it easily (for instance, with instanced rendering). So what I have basically is : create a mesh, and then create an instance of the mesh. The instance of the mesh contains a reference to the mesh, so the data is not duplicated. The only thing I add to this instance of the mesh is some math data (for instance matrix transformation, because each instance of the mesh has different matrices) as well as different materials. From now on, do you think it is correct ? Or there is a better way to do that ? But the biggest problem is... that I have to use some raytracing. I mean, all the meshes are inserted into a BVH, and then I shoot rays each frame. So, I have to have all the vertices in world space (I think it's quite easy) so that ray shooting is easy, and each time a mesh moves, I update its vertices (I think that with optimized SSE matrix-vector multiplication it can be quite fast) in the main memory, while I keep object space vertices in the VBO that I update in the vertex shader. But I have several problems with that, and I really don't know a good architecture. I think, at the beginning, of something really simple, that is, duplicate everything. Different VBOs, different vertex array... But I don't think it's quite efficient. Second, I thought about keeping this "mesh and instanced", that is to say : - Create a mesh that loads a mesh from a file. Keep vertex data in object space in memory, send everything to the graphics card. - Then each instance of the mesh keep the VBO as well as IBO (because it will reamin the same), but duplicate the vertex data, transform everything into world-space (and then, only update when it moves). - Insert the instance in the BVH. Use also the instance for rendering. But it doesn't look clean anymore :/... Do you have better ideas ? ^^ Thank you very much !