I'm trying to write a map editor for a unity game using openGL. In order to do that, I need to unpack it's resource files to get meshes, textures and other good stuff.
In doing so, I've discovered that unity mesh asset stores vertices, normals, texture data, and any other per-vertex type data in one interleaved array.
I have two choices here. First is to leave the data as is and push it into a single VBO and then use attrib pointer to adjust strides and whatnots to make it work. When I read data from file into memory, I can just read whole array with a single ifstream::read
method call.
Second choice is to unravel all data into it's separate channels and have a separate VBO for each data type. I personally prefer it this way, but this means that I need to deinterleave that array. I'm unsure how to do this efficiently. The most obvious way (and very inefficient) is to read it char by char and store each char in appropriate array, depending on channel structure. I could maybe mess with it a bit and set it up to read it channel per channel (meaning 2-4 chars at once) instead of char by char. This still seems very slow to me.
Maybe I could load the whole array into memory and then deinterleave it there, but I'm still unsure of method that would be fast.
The priority is for the program to be fast while drawing, and deinterleaved multiple VBO setup is said to be faster due to lesser amount of cache misses.
To give you a sense of numbers, the game I'm looking at contains about 2630 different mesh assets, with each containing an estimated average of 500 vertices.
How do I deal with this? I will be loading all this data just once on program startup anyway, so it doesn't have to be super fast, but I don't want to force the user to wait for too long even then. Maybe number of vertices altogether is small enough for it to be very fast regardless, but I don't want to commit to either way before I have some idea of what I'm doing.
Bottom line is, should I just leave it interleaved, or is there some efficient way to deinterleave it? Am I jumping the train here, being scared of leaving it interlaved? I know I should probably benchmark both cases, but both cases are drastically different in my case and would require huge code changes, not to mention I'm nowhere close to actually drawing the scene I need to.